X-Git-Url: https://sigrok.org/gitweb/?p=libsigrokdecode.git;a=blobdiff_plain;f=controller.c;h=2355deea96a8ca651d9f55a34dfefae082a36aad;hp=0cad3f544fd3002fb03c0b3c0825fc7fb8d61cbd;hb=fa12a21e3c779df4e33dcfe394e2ded3f96028ce;hpb=2072ae0c89fec6b06cc579a6c584e67e2a59f7ec diff --git a/controller.c b/controller.c index 0cad3f5..2355dee 100644 --- a/controller.c +++ b/controller.c @@ -68,7 +68,7 @@ int srd_init(void) { int ret; - srd_dbg("srd: initializing"); + srd_dbg("Initializing libsigrokdecode."); /* Add our own module to the list of built-in modules. */ PyImport_AppendInittab("sigrokdecode", PyInit_sigrokdecode); @@ -105,7 +105,7 @@ int srd_init(void) int srd_exit(void) { - srd_dbg("srd: exiting"); + srd_dbg("Exiting libsigrokdecode."); srd_unload_all_decoders(); g_slist_free(pd_list); @@ -272,10 +272,9 @@ 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("srd: stray exception in srd_instance_set_options()"); + catch_exception("Stray exception in srd_instance_set_options()."); return ret; } @@ -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; @@ -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; @@ -371,7 +374,7 @@ struct srd_decoder_instance *srd_instance_new(const char *decoder_id, int i; char *instance_id; - srd_dbg("srd: creating new %s instance", decoder_id); + srd_dbg("Creating new %s instance.", decoder_id); if (!(dec = srd_get_decoder_by_id(decoder_id))) { srd_err("Protocol decoder %s not found.", decoder_id); @@ -506,8 +509,8 @@ int srd_instance_start(struct srd_decoder_instance *di, PyObject *args) GSList *l; struct srd_decoder_instance *next_di; - srd_dbg("srd: calling start() method on protocol decoder instance %s", - di->instance_id); + srd_dbg("Calling start() method on protocol decoder instance %s.", + di->instance_id); if (!(py_name = PyUnicode_FromString("start"))) { srd_err("Unable to build python object for 'start'."); @@ -540,34 +543,34 @@ int srd_instance_start(struct srd_decoder_instance *di, PyObject *args) * Run the specified decoder function. * * @param start_samplenum The starting sample number for the buffer's sample - * set, relative to the start of capture. - * @param di The decoder instance to call. - * @param inbuf The buffer to decode. - * @param inbuflen Length of the buffer. + * set, relative to the start of capture. + * @param di The decoder instance to call. Must not be NULL. + * @param inbuf The buffer to decode. Must not be NULL. + * @param inbuflen Length of the buffer. Must be > 0. * * @return SRD_OK upon success, a (negative) error code otherwise. */ int srd_instance_decode(uint64_t start_samplenum, - struct srd_decoder_instance *di, uint8_t *inbuf, uint64_t inbuflen) + struct srd_decoder_instance *di, uint8_t *inbuf, uint64_t inbuflen) { PyObject *py_res; srd_logic *logic; uint64_t end_samplenum; - srd_dbg("srd: calling decode() on instance %s with %d bytes starting " - "at sample %d", di->instance_id, inbuflen, start_samplenum); + srd_dbg("Calling decode() on instance %s with %d bytes starting " + "at sample %d.", di->instance_id, inbuflen, start_samplenum); /* Return an error upon unusable input. */ - if (di == NULL) { - srd_dbg("srd: empty decoder instance"); + if (!di) { + srd_dbg("empty decoder instance"); return SRD_ERR_ARG; } - if (inbuf == NULL) { - srd_dbg("srd: NULL buffer pointer"); + if (!inbuf) { + srd_dbg("NULL buffer pointer"); return SRD_ERR_ARG; } if (inbuflen == 0) { - srd_dbg("srd: empty buffer"); + srd_dbg("empty buffer"); return SRD_ERR_ARG; } @@ -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) { @@ -604,8 +645,8 @@ int srd_session_start(int num_probes, int unitsize, uint64_t samplerate) struct srd_decoder_instance *di; int ret; - srd_dbg("srd: calling start() on all instances with %d probes, " - "unitsize %d samplerate %d", num_probes, unitsize, samplerate); + srd_dbg("Calling start() on all instances with %d probes, " + "unitsize %d samplerate %d.", num_probes, unitsize, samplerate); /* Currently only one item of metadata is passed along to decoders, * samplerate. This can be extended as needed. @@ -636,9 +677,9 @@ int srd_session_feed(uint64_t start_samplenum, uint8_t *inbuf, uint64_t inbuflen GSList *d; int ret; - srd_dbg("srd: calling decode() on all instances with starting sample " - "number %"PRIu64", %"PRIu64" bytes at 0x%p", start_samplenum, - inbuflen, inbuf); + srd_dbg("Calling decode() on all instances with starting sample " + "number %"PRIu64", %"PRIu64" bytes at 0x%p", start_samplenum, + inbuflen, inbuf); for (d = di_list; d; d = d->next) { if ((ret = srd_instance_decode(start_samplenum, d->data, inbuf, @@ -654,7 +695,7 @@ int srd_register_callback(int output_type, void *cb) { struct srd_pd_callback *pd_cb; - srd_dbg("srd: registering new callback for output type %d", output_type); + srd_dbg("Registering new callback for output type %d.", output_type); if (!(pd_cb = g_try_malloc(sizeof(struct srd_pd_callback)))) return SRD_ERR_MALLOC; @@ -686,13 +727,12 @@ void *srd_find_callback(int output_type) /* This is the backend function to python sigrokdecode.add() call. */ -int pd_add(struct srd_decoder_instance *di, int output_type, - char *proto_id) +int pd_add(struct srd_decoder_instance *di, int output_type, char *proto_id) { struct srd_pd_output *pdo; - srd_dbg("srd: instance %s creating new output type %d for %s", - di->instance_id, output_type, proto_id); + srd_dbg("Instance %s creating new output type %d for %s.", + di->instance_id, output_type, proto_id); if (!(pdo = g_try_malloc(sizeof(struct srd_pd_output)))) return -1;