26 static const char *OUTPUT_TYPES[] = {
33 int *ann_format,
char ***ann)
40 if (!PyList_Check(obj) && !PyTuple_Check(obj)) {
41 srd_err(
"Protocol decoder %s submitted %s instead of list.",
47 if (PyList_Size(obj) != 2) {
48 srd_err(
"Protocol decoder %s submitted annotation list with "
58 py_tmp = PyList_GetItem(obj, 0);
59 if (!PyLong_Check(py_tmp)) {
60 srd_err(
"Protocol decoder %s submitted annotation list, but "
61 "first element was not an integer.", di->
decoder->
name);
65 ann_id = PyLong_AsLong(py_tmp);
67 srd_err(
"Protocol decoder %s submitted data to unregistered "
68 "annotation format %d.", di->
decoder->
name, ann_id);
74 py_tmp = PyList_GetItem(obj, 1);
75 if (!PyList_Check(py_tmp)) {
76 srd_err(
"Protocol decoder %s submitted annotation list, but "
77 "second element was not a list.", di->
decoder->
name);
81 srd_err(
"Protocol decoder %s submitted annotation list, but "
82 "second element was malformed.", di->
decoder->
name);
89 static PyObject *Decoder_put(PyObject *
self, PyObject *args)
92 PyObject *data, *py_res;
102 srd_dbg(
"put(): self instance not found.");
106 if (!PyArg_ParseTuple(args,
"KKiO", &start_sample, &end_sample,
107 &output_id, &data)) {
116 if (!(l = g_slist_nth(di->
pd_output, output_id))) {
117 srd_err(
"Protocol decoder %s submitted invalid output ID %d.",
123 srd_spew(
"Instance %s put %" PRIu64
"-%" PRIu64
" %s on oid %d.",
124 di->
inst_id, start_sample, end_sample,
128 srd_err(
"Failed to g_malloc() struct srd_proto_data.");
140 if (convert_pyobj(di, data, &pdata->
ann_format,
149 for (l = di->
next_di; l; l = l->next) {
153 srd_spew(
"Sending %d-%d to instance %s",
154 start_sample, end_sample,
156 if (!(py_res = PyObject_CallMethod(
157 next_di->
py_inst,
"decode",
"KKO", start_sample,
158 end_sample, data))) {
166 srd_err(
"SRD_OUTPUT_BINARY not yet supported.");
169 srd_err(
"Protocol decoder %s submitted invalid output type %d.",
179 static PyObject *Decoder_add(PyObject *
self, PyObject *args)
184 int output_type, pdo_id;
187 PyErr_SetString(PyExc_Exception,
"decoder instance not found");
191 if (!PyArg_ParseTuple(args,
"is", &output_type, &proto_id)) {
200 ret = Py_BuildValue(
"i", pdo_id);
205 static PyMethodDef Decoder_methods[] = {
206 {
"put", Decoder_put, METH_VARARGS,
207 "Accepts a dictionary with the following keys: startsample, endsample, data"},
208 {
"add", Decoder_add, METH_VARARGS,
"Create a new output stream"},
209 {NULL, NULL, 0, NULL}
213 PyVarObject_HEAD_INIT(NULL, 0)
214 .tp_name =
"sigrokdecode.Decoder",
216 .tp_flags = Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE,
217 .tp_doc =
"sigrok Decoder base class",
218 .tp_methods = Decoder_methods,