summaryrefslogtreecommitdiffstats
path: root/src/vpp-api
diff options
context:
space:
mode:
authorOle Troan <ot@cisco.com>2017-11-01 10:49:03 +0100
committerOle Trøan <otroan@employees.org>2017-11-01 16:43:51 +0000
commita74b7419bd6c7c5b23f59253b0b0b6c0d683794d (patch)
treea2e407c723a1bb62969fae88f110f4db9d398dff /src/vpp-api
parent6e3b5a2b682851285ca304ad5648207bd2cdd68f (diff)
VPP-959: Support old version of CFFI
Change-Id: I3d3e5dff5b22fca58a50da6a9d0aaf1182e736dd Signed-off-by: Ole Troan <ot@cisco.com>
Diffstat (limited to 'src/vpp-api')
-rw-r--r--src/vpp-api/python/setup.py2
-rw-r--r--src/vpp-api/python/vpp_papi.py18
2 files changed, 17 insertions, 3 deletions
diff --git a/src/vpp-api/python/setup.py b/src/vpp-api/python/setup.py
index 626dddeeda2..abda43de606 100644
--- a/src/vpp-api/python/setup.py
+++ b/src/vpp-api/python/setup.py
@@ -26,7 +26,7 @@ setup (name = 'vpp_papi',
python_requires='>=2.7, >=3.3',
license = 'Apache-2.0',
test_suite = 'tests',
- install_requires=['cffi >= 1.10'],
+ install_requires=['cffi >= 1.6'],
py_modules=['vpp_papi'],
long_description = '''VPP Python language binding.''',
zip_safe = True,
diff --git a/src/vpp-api/python/vpp_papi.py b/src/vpp-api/python/vpp_papi.py
index 67ac22a4d32..e7e1707c435 100644
--- a/src/vpp-api/python/vpp_papi.py
+++ b/src/vpp-api/python/vpp_papi.py
@@ -25,6 +25,7 @@ import threading
import glob
import atexit
from cffi import FFI
+import cffi
if sys.version[0] == '2':
import Queue as queue
@@ -54,7 +55,6 @@ void vac_set_error_handler(vac_error_callback_t);
# Barfs on failure, no need to check success.
vpp_api = ffi.dlopen('libvppapiclient.so')
-
def vpp_atexit(self):
"""Clean up VPP connection on shutdown."""
if self.connected:
@@ -166,6 +166,14 @@ class VPP():
# Register error handler
vpp_api.vac_set_error_handler(vac_error_handler)
+ # Support legacy CFFI
+ # from_buffer supported from 1.8.0
+ (major, minor, patch) = [int(s) for s in cffi.__version__.split('.', 3)]
+ if major >= 1 and minor >= 8:
+ self._write = self._write_new_cffi
+ else:
+ self._write = self._write_legacy_cffi
+
class ContextId(object):
"""Thread-safe provider of unique context IDs."""
def __init__(self):
@@ -469,12 +477,18 @@ class VPP():
self.logger.debug(
'No such message type or failed CRC checksum: %s', n)
- def _write(self, buf):
+ def _write_new_cffi(self, buf):
"""Send a binary-packed message to VPP."""
if not self.connected:
raise IOError(1, 'Not connected')
return vpp_api.vac_write(ffi.from_buffer(buf), len(buf))
+ def _write_legacy_cffi(self, buf):
+ """Send a binary-packed message to VPP."""
+ if not self.connected:
+ raise IOError(1, 'Not connected')
+ return vpp_api.vac_write(str(buf), len(buf))
+
def _read(self):
if not self.connected:
raise IOError(1, 'Not connected')