X-Git-Url: https://sigrok.org/gitweb/?p=libsigrokdecode.git;a=blobdiff_plain;f=decoder.c;h=6dfeecae7fa1fa5a5ca6e1c55eb7e27641ffcc49;hp=0aa1c5f8474a11b105983dd36eaf58c65c09d291;hb=3f302d519e813af30a796a16f84e688550827ae0;hpb=5a2c4dc462310a8a031abda7e6cbb0532873ec55 diff --git a/decoder.c b/decoder.c index 0aa1c5f..6dfeeca 100644 --- a/decoder.c +++ b/decoder.c @@ -124,7 +124,7 @@ err_out: /** * Load a protocol decoder module into the embedded Python interpreter. * - * @param name The module name to be loaded. + * @param module_name The module name to be loaded. * * @return SRD_OK upon success, a (negative) error code otherwise. */ @@ -134,6 +134,8 @@ SRD_API int srd_decoder_load(const char *module_name) struct srd_decoder *d; int alen, ret, i; char **ann; + struct srd_probe *p; + GSList *l; srd_dbg("Loading protocol decoder '%s'.", module_name); @@ -149,7 +151,7 @@ SRD_API int srd_decoder_load(const char *module_name) /* Import the Python module. */ if (!(d->py_mod = PyImport_ImportModule(module_name))) { - catch_exception("Import of '%s' failed.", module_name); + srd_exception_catch("Import of '%s' failed.", module_name); goto err_out; } @@ -222,6 +224,19 @@ SRD_API int srd_decoder_load(const char *module_name) if (get_probes(d, "optional_probes", &d->opt_probes) != SRD_OK) goto err_out; + /* + * Fix order numbers for the optional probes. + * + * Example: + * Required probes: r1, r2, r3. Optional: o1, o2, o3, o4. + * 'order' fields in the d->probes list = 0, 1, 2. + * 'order' fields in the d->opt_probes list = 3, 4, 5, 6. + */ + for (l = d->opt_probes; l; l = l->next) { + p = l->data; + p->order += g_slist_length(d->probes); + } + /* Store required fields in newly allocated strings. */ if (py_attr_as_str(d->py_dec, "id", &(d->id)) != SRD_OK) goto err_out; @@ -238,10 +253,6 @@ SRD_API int srd_decoder_load(const char *module_name) if (py_attr_as_str(d->py_dec, "license", &(d->license)) != SRD_OK) goto err_out; - /* TODO: Handle inputformats, outputformats. */ - d->inputformats = NULL; - d->outputformats = NULL; - /* Convert class annotation attribute to GSList of **char. */ d->annotations = NULL; if (PyObject_HasAttrString(d->py_dec, "annotations")) { @@ -293,7 +304,7 @@ err_out: * @return A newly allocated buffer containing the protocol decoder's * documentation. The caller is responsible for free'ing the buffer. */ -SRD_API char *srd_decoder_doc(const struct srd_decoder *dec) +SRD_API char *srd_decoder_doc_get(const struct srd_decoder *dec) { PyObject *py_str; char *doc; @@ -302,7 +313,7 @@ SRD_API char *srd_decoder_doc(const struct srd_decoder *dec) return NULL; if (!(py_str = PyObject_GetAttrString(dec->py_mod, "__doc__"))) { - catch_exception(""); + srd_exception_catch(""); return NULL; } @@ -359,12 +370,6 @@ SRD_API int srd_decoder_unload(struct srd_decoder *dec) g_free(dec->desc); g_free(dec->license); - /* TODO: Free everything in inputformats and outputformats. */ - if (dec->inputformats != NULL) - g_slist_free(dec->inputformats); - if (dec->outputformats != NULL) - g_slist_free(dec->outputformats); - /* The module's Decoder class. */ Py_XDECREF(dec->py_dec); /* The module itself. */