17 #include "../pneum/pneum.h" 25 PyGILState_STATE gstate;
28 gstate = PyGILState_Ensure();
31 #if PY_VERSION_HEX >= 0x03000000 32 result = PyObject_CallFunction(pneum_callback,
"y#", data, len);
34 result = PyObject_CallFunction(pneum_callback,
"s#", data, len);
41 PyGILState_Release(gstate);
47 char * name, * chroot_prefix =
NULL;
49 PyObject * temp =
NULL;
52 if (!PyArg_ParseTuple(args,
"s|Os:wrap_connect",
53 &name, &temp, &chroot_prefix))
58 if (!PyCallable_Check(temp))
60 PyErr_SetString(PyExc_TypeError,
"parameter must be callable");
65 Py_XDECREF(pneum_callback);
66 pneum_callback = temp;
69 Py_BEGIN_ALLOW_THREADS
72 return PyLong_FromLong(rv);
79 Py_BEGIN_ALLOW_THREADS
82 return PyLong_FromLong(rv);
90 if (!PyArg_ParseTuple(args,
"s#", &data, &len))
92 Py_BEGIN_ALLOW_THREADS
96 return PyLong_FromLong(rv);
105 Py_BEGIN_ALLOW_THREADS
109 if (rv != 0) { Py_RETURN_NONE; }
110 #if PY_VERSION_HEX >= 0x03000000 111 PyObject *ret = Py_BuildValue(
"y#", data, len);
113 PyObject *ret = Py_BuildValue(
"s#", data, len);
115 if (!ret) { Py_RETURN_NONE; }
128 if (!ret)
goto error;
131 PyObject *item = PyTuple_New(2);
132 if (!item)
goto error;
133 rv = PyTuple_SetItem(item, 0, PyLong_FromLong((
u32)hp->
value[0]));
135 rv = PyTuple_SetItem(item, 1, PyString_FromString((
char *)hp->
key));
137 PyList_SetItem(ret, i, item);
145 printf(
"msg_table failed");
150 {
"connect",
wrap_connect, METH_VARARGS,
"Connect to the VPP API."},
151 {
"disconnect",
wrap_disconnect, METH_VARARGS,
"Disconnect from the VPP API."},
152 {
"write",
wrap_write, METH_VARARGS,
"Write data to the VPP API."},
153 {
"read",
wrap_read, METH_VARARGS,
"Read data from the VPP API."},
154 {
"msg_table",
wrap_msg_table, METH_VARARGS,
"Get API dictionary."},
158 #if PY_VERSION_HEX >= 0x03000000 160 PyInit_vpp_api (
void)
166 #if PY_VERSION_HEX >= 0x03000000 167 static struct PyModuleDef vpp_api_module = {
168 #if PY_VERSION_HEX >= 0x03020000 169 PyModuleDef_HEAD_INIT,
172 PyObject_HEAD_INIT(NULL)
190 if (!PyEval_ThreadsInitialized()) {
191 PyEval_InitThreads();
194 #if PY_VERSION_HEX >= 0x03000000 195 return PyModule_Create(&vpp_api_module);
197 Py_InitModule((
char *)
"vpp_api", vpp_api_Methods);
sll srl srl sll sra u16x4 i
static PyObject * wrap_disconnect(PyObject *self, PyObject *args)
int pneum_read(char **p, int *l)
void(* pneum_callback_t)(unsigned char *data, int len)
int pneum_connect(char *name, char *chroot_prefix, pneum_callback_t cb)
int pneum_disconnect(void)
static void wrap_pneum_callback(unsigned char *data, int len)
static PyObject * wrap_write(PyObject *self, PyObject *args)
static PyObject * wrap_read(PyObject *self, PyObject *args)
static PyObject * wrap_msg_table(PyObject *self, PyObject *args)
static PyMethodDef vpp_api_Methods[]
void pneum_free(void *msg)
#define hash_foreach_pair(p, v, body)
Iterate over hash pairs.
static PyObject * pneum_callback
uword * pneum_msg_table_get_hash(void)
int pneum_msg_table_size(void)
int pneum_write(char *p, int l)
static PyObject * wrap_connect(PyObject *self, PyObject *args)