# A transport class. With two implementations.
# One for socket and one for shared memory.
#
+import logging
from cffi import FFI
import cffi
+logger = logging.getLogger('vpp_papi.transport')
+logger.addHandler(logging.NullHandler())
+
ffi = FFI()
ffi.cdef("""
typedef void (*vac_callback_t)(unsigned char * data, int len);
vpp_object = None
-# Barfs on failure, no need to check success.
-vpp_api = ffi.dlopen('libvppapiclient.so')
+# allow file to be imported so it can be mocked in tests.
+# If the shared library fails, VppTransport cannot be initialized.
+try:
+ vpp_api = ffi.dlopen('libvppapiclient.so')
+except OSError:
+ vpp_api = None
@ffi.callback("void(unsigned char *, int)")
super(VppTransportShmemIOError, self).__init__(rv, descr)
-class VppTransport(object):
+class VppTransport:
VppTransportShmemIOError = VppTransportShmemIOError
def __init__(self, parent, read_timeout, server_address):
global vpp_object
vpp_object = parent
- vpp_api.vac_mem_init(0);
+ vpp_api.vac_mem_init(0)
# Register error handler
vpp_api.vac_set_error_handler(vac_error_handler)