]> sigrok.org Git - libsigrokdecode.git/blobdiff - controller.c
code cleanup
[libsigrokdecode.git] / controller.c
index de9b00aa30a570f0c614b21e87760b2bc03fb371..a0e8bfe8d13b240a16dee82c66b4d564d58c323d 100644 (file)
@@ -24,6 +24,8 @@
 #include <inttypes.h>
 
 
+static GSList *callbacks = NULL;
+
 /* TODO
 static GSList *pipelines = NULL;
 struct srd_pipeline {
@@ -136,8 +138,6 @@ struct srd_decoder_instance *srd_instance_new(const char *id)
        struct srd_decoder_instance *di;
        PyObject *py_args;
 
-       fprintf(stdout, "%s: %s\n", __func__, id);
-
        if (!(dec = srd_get_decoder_by_id(id)))
                return NULL;
 
@@ -200,8 +200,6 @@ int srd_session_start(int num_probes, int unitsize, uint64_t samplerate)
        GSList *d;
        struct srd_decoder_instance *di;
 
-       fprintf(stdout, "%s\n", __func__);
-
        for (d = di_list; d; d = d->next) {
                di = d->data;
                di->num_probes = num_probes;
@@ -279,8 +277,6 @@ int srd_session_feed(uint64_t timeoffset, uint64_t duration, uint8_t *inbuf,
        GSList *d;
        int ret;
 
-//     fprintf(stdout, "%s: %d bytes\n", __func__, inbuflen);
-
        for (d = di_list; d; d = d->next) {
                if ((ret = srd_run_decoder(timeoffset, duration, d->data, inbuf,
                                inbuflen)) != SRD_OK)
@@ -291,34 +287,22 @@ int srd_session_feed(uint64_t timeoffset, uint64_t duration, uint8_t *inbuf,
 }
 
 
-int pd_output_new(struct srd_decoder_instance *di, int output_type,
-               char *protocol_id, char *description)
+int pd_add(struct srd_decoder_instance *di, int output_type,
+               char *protocol_id)
 {
-       GSList *l;
        struct srd_pd_output *pdo;
-       int pdo_id;
-
-       fprintf(stdout, "%s: output type %d, protocol_id %s, description %s\n",
-                       __func__, output_type, protocol_id, description);
-
-       pdo_id = -1;
-       for (l = di->pd_output; l; l = l->next) {
-               pdo = l->data;
-               if (pdo->pdo_id > pdo_id)
-                       pdo_id = pdo->pdo_id;
-       }
-       pdo_id++;
 
        if (!(pdo = g_try_malloc(sizeof(struct srd_pd_output))))
                return -1;
 
-       pdo->pdo_id = pdo_id;
+       /* pdo_id is just a simple index, nothing is deleted from this list anyway. */
+       pdo->pdo_id = g_slist_length(di->pd_output);
        pdo->output_type = output_type;
+       pdo->decoder = di->decoder;
        pdo->protocol_id = g_strdup(protocol_id);
-       pdo->description = g_strdup(description);
        di->pd_output = g_slist_append(di->pd_output, pdo);
 
-       return pdo_id;
+       return pdo->pdo_id;
 }
 
 struct srd_decoder_instance *get_di_by_decobject(void *decobject)
@@ -335,6 +319,37 @@ struct srd_decoder_instance *get_di_by_decobject(void *decobject)
        return NULL;
 }
 
+int srd_register_callback(int output_type, void *cb)
+{
+       struct srd_pd_callback *pd_cb;
+
+       if (!(pd_cb = g_try_malloc(sizeof(struct srd_pd_callback))))
+               return SRD_ERR_MALLOC;
+
+       pd_cb->output_type = output_type;
+       pd_cb->callback = cb;
+       callbacks = g_slist_append(callbacks, pd_cb);
+
+       return SRD_OK;
+}
+
+void *srd_find_callback(int output_type)
+{
+       GSList *l;
+       struct srd_pd_callback *pd_cb;
+       void *(cb);
+
+       cb = NULL;
+       for (l = callbacks; l; l = l->next) {
+               pd_cb = l->data;
+               if (pd_cb->output_type == output_type) {
+                       cb = pd_cb->callback;
+                       break;
+               }
+       }
+
+       return cb;
+}
 
 //int srd_pipeline_new(int plid)
 //{