Skip to content

Commit

Permalink
up
Browse files Browse the repository at this point in the history
  • Loading branch information
moonlight83340 committed Aug 29, 2024
1 parent 254d19d commit 7cf87cd
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 25 deletions.
2 changes: 0 additions & 2 deletions examples/python_bindings_example_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,9 +49,7 @@ def get_options():
if options.zmq:
# add ZMQ interface - (address, host)
# creates publish and subrcribe endpoints from the host
iface = None
libcsp.zmqhub_init(options.address, options.zmq)
libcsp.iface_set_is_default(iface,1)

if options.kiss:
libcsp.kiss_init(options.kiss, options.address)
Expand Down
4 changes: 1 addition & 3 deletions examples/python_bindings_example_server.py
Original file line number Diff line number Diff line change
Expand Up @@ -116,9 +116,7 @@ def csp_server():
if options.zmq:
# add ZMQ interface - (address, host)
# creates publish and subrcribe endpoints from the host
iface = None
libcsp.zmqhub_init(options.address, options.zmq, iface)
libcsp.iface_set_is_default(iface,1)
libcsp.zmqhub_init(options.address, options.zmq)

if options.kiss:
libcsp.kiss_init(options.kiss, options.address)
Expand Down
23 changes: 3 additions & 20 deletions src/bindings/python/pycsp.c
Original file line number Diff line number Diff line change
Expand Up @@ -852,6 +852,8 @@ static PyObject * pycsp_zmqhub_init(PyObject * self, PyObject * args) {

if(iface == NULL){
is_default = true;
}else{
return PyErr_Error("iface not NULL !");
}

int res = csp_zmqhub_init(addr, host, 0, &iface);
Expand Down Expand Up @@ -986,7 +988,7 @@ static PyObject * pycsp_add_iface(PyObject * self, PyObject * args) {
const char * name;
uint8_t is_default;

if (!PyArg_ParseTuple(args, "|HHSb", &addr, &netmask, &name, &is_default)) {
if (!PyArg_ParseTuple(args, "HHSb", &addr, &netmask, &name, &is_default)) {
PyMem_RawFree(iface);
return NULL; // TypeError is thrown
}
Expand All @@ -999,24 +1001,6 @@ static PyObject * pycsp_add_iface(PyObject * self, PyObject * args) {
return PyCapsule_New(iface, "csp_iface_t", NULL);
}

static PyObject * pycsp_iface_set_is_default(PyObject * self, PyObject * args) {
PyObject * iface_capsule = NULL;
int is_default;

if (!PyArg_ParseTuple(args, "Oi", &iface_capsule, &is_default)) {
return NULL; // TypeError is thrown
}

csp_iface_t * iface = get_capsule_pointer(iface_capsule, IFACE_CAPSULE, true);
if (iface == NULL) {
return NULL; // Handle error if iface is NULL
}

iface->is_default = (uint8_t)is_default;

Py_RETURN_NONE;
}

static PyMethodDef methods[] = {

/* csp/csp.h */
Expand Down Expand Up @@ -1090,7 +1074,6 @@ static PyMethodDef methods[] = {

/* csp/csp_interface.h */
{"add_iface", pycsp_add_iface, METH_VARARGS, "Setup iface"},
{"iface_set_is_default", pycsp_iface_set_is_default, METH_VARARGS, "Set is_default flag in csp_iface_t"},

/* sentinel */
{NULL, NULL, 0, NULL}};
Expand Down

0 comments on commit 7cf87cd

Please sign in to comment.