]> sigrok.org Git - libsigrokdecode.git/blobdiff - controller.c
srd: rename extra_probes to optional_probes
[libsigrokdecode.git] / controller.c
index e325e0a6208cf98248101673c0c9714c27ffdfc0..d7d3faf2999e074567e6ce9a60ab26d82fae7e70 100644 (file)
@@ -272,8 +272,7 @@ err_out:
        Py_XDECREF(py_di_options);
        Py_XDECREF(py_dec_optkeys);
        Py_XDECREF(py_dec_options);
-       if (key)
-               g_free(key);
+       g_free(key);
        if (PyErr_Occurred())
                catch_exception("Stray exception in srd_instance_set_options().");
 
@@ -306,6 +305,9 @@ int srd_instance_set_probes(struct srd_decoder_instance *di,
        int *new_probemap, new_probenum;
        char *probe_id, *probenum_str;
 
+       srd_dbg("set probes called for instance %s with list of %d probes",
+                       di->instance_id, g_hash_table_size(new_probes));
+
        if (g_hash_table_size(new_probes) == 0)
                /* No probes provided. */
                return SRD_OK;
@@ -337,7 +339,7 @@ int srd_instance_set_probes(struct srd_decoder_instance *di,
                if (!(sl = g_slist_find_custom(di->decoder->probes, probe_id,
                                (GCompareFunc)compare_probe_id))) {
                        /* Fall back on optional probes. */
-                       if (!(sl = g_slist_find_custom(di->decoder->extra_probes,
+                       if (!(sl = g_slist_find_custom(di->decoder->opt_probes,
                                        probe_id, (GCompareFunc)compare_probe_id))) {
                                srd_err("Protocol decoder %s has no probe '%s'.",
                                                di->decoder->name, probe_id);
@@ -347,6 +349,7 @@ int srd_instance_set_probes(struct srd_decoder_instance *di,
                }
                p = sl->data;
                new_probemap[p->order] = new_probenum;
+               srd_dbg("setting probe mapping for %d = probe %d", p->order, new_probenum);
        }
        g_free(di->dec_probemap);
        di->dec_probemap = new_probemap;
@@ -392,7 +395,7 @@ struct srd_decoder_instance *srd_instance_new(const char *decoder_id,
         * order in which the decoder class defined them.
         */
        di->dec_num_probes = g_slist_length(di->decoder->probes) +
-                       g_slist_length(di->decoder->extra_probes);
+                       g_slist_length(di->decoder->opt_probes);
        if (di->dec_num_probes) {
                if (!(di->dec_probemap = g_try_malloc(sizeof(int) * di->dec_num_probes))) {
                        srd_err("Failed to malloc probe map.");
@@ -596,6 +599,44 @@ int srd_instance_decode(uint64_t start_samplenum,
        return SRD_OK;
 }
 
+void srd_instance_free(struct srd_decoder_instance *di)
+{
+       GSList *l;
+       struct srd_pd_output *pdo;
+
+       srd_dbg("Freeing instance %s", di->instance_id);
+
+       Py_DecRef(di->py_instance);
+       g_free(di->instance_id);
+       g_free(di->dec_probemap);
+       g_slist_free(di->next_di);
+       for (l = di->pd_output; l; l = l->next) {
+               pdo = l->data;
+               g_free(pdo->proto_id);
+               g_free(pdo);
+       }
+       g_slist_free(di->pd_output);
+
+}
+
+void srd_instance_free_all(GSList *stack)
+{
+       GSList *l;
+       struct srd_decoder_instance *di;
+
+       di = NULL;
+       for (l = stack ? stack : di_list; di == NULL && l != NULL; l = l->next) {
+               di = l->data;
+               if (di->next_di)
+                       srd_instance_free_all(di->next_di);
+               srd_instance_free(di);
+       }
+       if (!stack) {
+               g_slist_free(di_list);
+               di_list = NULL;
+       }
+
+}
 
 int srd_session_start(int num_probes, int unitsize, uint64_t samplerate)
 {