]> sigrok.org Git - libsigrokdecode.git/blobdiff - type_decoder.c
edid: move PD docstring to __init__.py
[libsigrokdecode.git] / type_decoder.c
index ab5182f0112a3cc522f594b0846847fa4bfe06ad..bbf1f64c2a8dfd6ec369f44dea84aba44148aac9 100644 (file)
 #include "config.h"
 
 
 #include "config.h"
 
 
+/* This is only used for nicer srd_dbg() output. */
+char *OUTPUT_TYPES[] = {
+       "OUTPUT_ANN",
+       "OUTPUT_PROTO",
+       "OUTPUT_BINARY",
+};
+
+
 static int convert_pyobj(struct srd_decoder_instance *di, PyObject *obj,
                int *ann_format, char ***ann)
 {
 static int convert_pyobj(struct srd_decoder_instance *di, PyObject *obj,
                int *ann_format, char ***ann)
 {
@@ -87,10 +95,16 @@ static PyObject *Decoder_put(PyObject *self, PyObject *args)
        int output_id;
        void (*cb)();
 
        int output_id;
        void (*cb)();
 
-       if (!(di = get_di_by_decobject(self)))
+       if (!(di = srd_instance_find_by_obj(NULL, self))) {
+               /* Shouldn't happen. */
+               srd_dbg("put(): self instance not found.");
                return NULL;
                return NULL;
+       }
 
        if (!PyArg_ParseTuple(args, "KKiO", &start_sample, &end_sample, &output_id, &data))
 
        if (!PyArg_ParseTuple(args, "KKiO", &start_sample, &end_sample, &output_id, &data))
+               /* This throws an exception, but by returning NULL here we let python
+                * raise it. This results in a much better trace in controller.c
+                * on the decode() method call. */
                return NULL;
 
        if (!(l = g_slist_nth(di->pd_output, output_id))) {
                return NULL;
 
        if (!(l = g_slist_nth(di->pd_output, output_id))) {
@@ -100,6 +114,10 @@ static PyObject *Decoder_put(PyObject *self, PyObject *args)
        }
        pdo = l->data;
 
        }
        pdo = l->data;
 
+       srd_spew("Instance %s put %" PRIu64 "-%" PRIu64 " %s on oid %d.",
+                di->instance_id, start_sample, end_sample,
+                OUTPUT_TYPES[pdo->output_type], output_id);
+
        if (!(pdata = g_try_malloc0(sizeof(struct srd_proto_data))))
                return NULL;
        pdata->start_sample = start_sample;
        if (!(pdata = g_try_malloc0(sizeof(struct srd_proto_data))))
                return NULL;
        pdata->start_sample = start_sample;
@@ -124,10 +142,11 @@ static PyObject *Decoder_put(PyObject *self, PyObject *args)
                        next_di = l->data;
                        /* TODO: is this needed? */
                        Py_XINCREF(next_di->py_instance);
                        next_di = l->data;
                        /* TODO: is this needed? */
                        Py_XINCREF(next_di->py_instance);
+                       srd_spew("Sending %d-%d to instance %s",
+                                start_sample, end_sample, next_di->instance_id);
                        if (!(py_res = PyObject_CallMethod(next_di->py_instance, "decode",
                                        "KKO", start_sample, end_sample, data))) {
                        if (!(py_res = PyObject_CallMethod(next_di->py_instance, "decode",
                                        "KKO", start_sample, end_sample, data))) {
-                               if (PyErr_Occurred())
-                                       PyErr_Print();
+                               catch_exception("calling %s decode(): ", next_di->instance_id);
                        }
                        Py_XDECREF(py_res);
                }
                        }
                        Py_XDECREF(py_res);
                }
@@ -154,15 +173,13 @@ static PyObject *Decoder_add(PyObject *self, PyObject *args)
        char *proto_id;
        int output_type, pdo_id;
 
        char *proto_id;
        int output_type, pdo_id;
 
-       if (!(di = get_di_by_decobject(self))) {
-               srd_dbg("srd: %s():%d decoder instance not found", __func__, __LINE__);
+       if (!(di = srd_instance_find_by_obj(NULL, self))) {
                PyErr_SetString(PyExc_Exception, "decoder instance not found");
                return NULL;
        }
 
        if (!PyArg_ParseTuple(args, "is", &output_type, &proto_id)) {
                PyErr_SetString(PyExc_Exception, "decoder instance not found");
                return NULL;
        }
 
        if (!PyArg_ParseTuple(args, "is", &output_type, &proto_id)) {
-               if (PyErr_Occurred())
-                       PyErr_Print();
+               /* Let python raise this exception. */
                return NULL;
        }
 
                return NULL;
        }