2 * This file is part of the sigrok project.
4 * Copyright (C) 2013 Martin Ling <martin-sigrok@earth.li>
6 * This program is free software: you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation, either version 3 of the License, or
9 * (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program. If not, see <http://www.gnu.org/licenses/>.
22 %include "../../../swig/libsigrok.i"
26 void sr_datafeed_python_callback(const struct sr_dev_inst *sdi,
27 const struct sr_datafeed_packet *packet, void *cb_data)
33 PyGILState_STATE gstate;
34 PyObject *python_callback;
36 python_callback = (PyObject *) cb_data;
37 gstate = PyGILState_Ensure();
39 sdi_obj = SWIG_NewPointerObj(SWIG_as_voidptr(sdi),
40 SWIGTYPE_p_sr_dev_inst, 0);
42 packet_obj = SWIG_NewPointerObj(SWIG_as_voidptr(packet),
43 SWIGTYPE_p_sr_datafeed_packet, 0);
45 arglist = Py_BuildValue("(OO)", sdi_obj, packet_obj);
47 result = PyEval_CallObject(python_callback, arglist);
51 Py_XDECREF(packet_obj);
54 PyGILState_Release(gstate);
57 int sr_session_datafeed_python_callback_add(PyObject *cb)
61 if (!PyCallable_Check(cb))
64 ret = sr_session_datafeed_callback_add(
65 sr_datafeed_python_callback, cb);
74 int sr_session_datafeed_python_callback_add(PyObject *cb);