diff options
author | Bert Vermeulen <bert@biot.com> | 2012-01-07 02:50:14 +0100 |
---|---|---|
committer | Bert Vermeulen <bert@biot.com> | 2012-01-07 02:54:43 +0100 |
commit | 159699490ea4bf2495e99dcd5fb18b240d7499df (patch) | |
tree | 9e6f497a2b078e25918fd478d9b0cc41b86bb8da /decoder.c | |
parent | 721501bf4267db27bd6b848c8a0d4b5016b1f1c0 (diff) | |
download | libsigrokdecode-159699490ea4bf2495e99dcd5fb18b240d7499df.tar.gz libsigrokdecode-159699490ea4bf2495e99dcd5fb18b240d7499df.zip |
convert data coming in from a PD to C structs
This is in preparation for passing annotation data back to the calling
frontend, and python data up to the next protocol in the stack.
Diffstat (limited to 'decoder.c')
-rw-r--r-- | decoder.c | 39 |
1 files changed, 31 insertions, 8 deletions
@@ -20,6 +20,7 @@ #include "config.h" #include "sigrokdecode.h" /* First, so we avoid a _POSIX_C_SOURCE warning. */ +#include "sigrokdecode-internal.h" #include <dirent.h> /* The list of protocol decoders. */ @@ -63,17 +64,19 @@ struct srd_decoder *srd_get_decoder_by_id(const char *id) /** - * TODO + * Load a protocol decoder module into the embedded python interpreter. * - * @param name TODO + * @param name The module name to be loaded. + * @param dec Pointer to the struct srd_decoder filled with the loaded module. * * @return SRD_OK upon success, a (negative) error code otherwise. */ int srd_load_decoder(const char *name, struct srd_decoder **dec) { + PyObject *py_mod, *py_res, *py_annlist, *py_ann; struct srd_decoder *d; - PyObject *py_mod, *py_res; - int r; + int alen, r, i; + char **ann; fprintf(stdout, "%s: %s\n", __func__, name); @@ -102,15 +105,13 @@ int srd_load_decoder(const char *name, struct srd_decoder **dec) if ((r = h_str(py_res, "name", &(d->name))) < 0) return r; - if ((r = h_str(py_res, "longname", - &(d->longname))) < 0) + if ((r = h_str(py_res, "longname", &(d->longname))) < 0) return r; if ((r = h_str(py_res, "desc", &(d->desc))) < 0) return r; - if ((r = h_str(py_res, "longdesc", - &(d->longdesc))) < 0) + if ((r = h_str(py_res, "longdesc", &(d->longdesc))) < 0) return r; if ((r = h_str(py_res, "author", &(d->author))) < 0) @@ -131,6 +132,28 @@ int srd_load_decoder(const char *name, struct srd_decoder **dec) d->inputformats = NULL; d->outputformats = NULL; + /* Convert class annotation attribute to GSList of **char */ + d->annotation = NULL; + if ((py_annlist = PyObject_GetAttrString(py_res, "annotation"))) { + if (!PyList_Check(py_annlist)) { + srd_err("Protocol decoder module %s annotation should be a list", name); + return SRD_ERR_PYTHON; + } + alen = PyList_Size(py_annlist); + for (i = 0; i < alen; i++) { + py_ann = PyList_GetItem(py_annlist, i); + if (!PyList_Check(py_ann) || PyList_Size(py_ann) != 2) { + srd_err("Protocol decoder module %s annotation %d should be a list with two elements", + name, i+1); + return SRD_ERR_PYTHON; + } + + if (py_strlist_to_char(py_ann, &ann) != SRD_OK) + return SRD_ERR_PYTHON; + d->annotation = g_slist_append(d->annotation, ann); + } + } + *dec = d; return SRD_OK; |