]> sigrok.org Git - libsigrok.git/blame - bindings/python/libsigrok_python.i
hantek-dso: Mark connection as USB
[libsigrok.git] / bindings / python / libsigrok_python.i
CommitLineData
758b01ad
ML
1/*
2 * This file is part of the sigrok project.
3 *
4 * Copyright (C) 2013 Martin Ling <martin-sigrok@earth.li>
5 *
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.
10 *
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.
15 *
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/>.
18 */
19
20%include "../swig/libsigrok.i"
0849c7d3
ML
21
22%{
23
24void sr_datafeed_python_callback(const struct sr_dev_inst *sdi,
25 const struct sr_datafeed_packet *packet, void *cb_data)
26{
27 PyObject *sdi_obj;
28 PyObject *packet_obj;
29 PyObject *arglist;
30 PyObject *result;
31 PyGILState_STATE gstate;
32 PyObject *python_callback;
33
34 python_callback = (PyObject *) cb_data;
35 gstate = PyGILState_Ensure();
36
37 sdi_obj = SWIG_NewPointerObj(SWIG_as_voidptr(sdi),
38 SWIGTYPE_p_sr_dev_inst, 0);
39
40 packet_obj = SWIG_NewPointerObj(SWIG_as_voidptr(packet),
41 SWIGTYPE_p_sr_datafeed_packet, 0);
42
43 arglist = Py_BuildValue("(OO)", sdi_obj, packet_obj);
44
45 result = PyEval_CallObject(python_callback, arglist);
46
47 Py_XDECREF(arglist);
48 Py_XDECREF(sdi_obj);
49 Py_XDECREF(packet_obj);
50 Py_XDECREF(result);
51
52 PyGILState_Release(gstate);
53}
54
55void sr_session_datafeed_python_callback_add(PyObject *cb)
56{
57 if (!PyCallable_Check(cb))
58 PyErr_SetString(PyExc_TypeError, "Object passed is not callable");
59 else
60 sr_session_datafeed_callback_add(
61 sr_datafeed_python_callback, cb);
62}
63
64%}
65
66void sr_session_datafeed_python_callback_add(PyObject *cb);