if not self._initialized:
check(sr_driver_init(self.context.struct, self.struct))
self._initialized = True
- devices = []
device_list = sr_driver_scan(self.struct, None)
- device_list_item = device_list
- while device_list_item:
- ptr = device_list_item.data
- device_ptr = gpointer_to_sr_dev_inst_ptr(ptr)
- devices.append(Device(self, device_ptr))
- device_list_item = device_list_item.next
+ devices = [Device(self, gpointer_to_sr_dev_inst_ptr(ptr))
+ for ptr in gslist_to_python(device_list)]
g_slist_free(device_list)
return devices
#endif
}
+GSList *python_to_gslist(PyObject *pylist)
+{
+ if (PyList_Check(pylist)) {
+ GSList *gslist = NULL;
+ int size = PyList_Size(pylist);
+ int i;
+ for (i = size - 1; i >= 0; i--) {
+ SwigPyObject *o = (SwigPyObject *)PyList_GetItem(pylist, i);
+ void *data = o->ptr;
+ gslist = g_slist_prepend(gslist, data);
+ }
+ return gslist;
+ }
+ return NULL;
+}
+
+PyObject *gslist_to_python(GSList *gslist)
+{
+ PyObject *pylist = PyList_New(0);
+ GSList *l;
+ for (l = gslist; l; l = l->next)
+ PyList_Append(pylist, SWIG_NewPointerObj(l->data, SWIGTYPE_p_void, 0));
+ return pylist;
+}
+
%}
int sr_session_datafeed_python_callback_add(PyObject *cb);
PyObject *cdata(const void *data, unsigned long size);
+
+GSList *python_to_gslist(PyObject *pylist);
+PyObject *gslist_to_python(GSList *gslist);