*/
#include "config.h"
-#include <sigrokdecode.h> /* First, so we avoid a _POSIX_C_SOURCE warning. */
+#include "sigrokdecode.h" /* First, so we avoid a _POSIX_C_SOURCE warning. */
+#include "sigrokdecode-internal.h"
#include <dirent.h>
/* The list of protocol decoders. */
-GSList *list_pds = NULL;
-GSList *decoders = NULL;
+GSList *pd_list = NULL;
+GSList *di_list = NULL;
/**
GSList *srd_list_decoders(void)
{
- return list_pds;
+ return pd_list;
}
/**
- * 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);
if (!(d = malloc(sizeof(struct srd_decoder))))
return SRD_ERR_MALLOC;
- if ((r = h_str(py_res, py_mod, "id", &(d->id))) < 0)
+ if ((r = h_str(py_res, "id", &(d->id))) < 0)
return r;
- if ((r = h_str(py_res, py_mod, "name", &(d->name))) < 0)
+ if ((r = h_str(py_res, "name", &(d->name))) < 0)
return r;
- if ((r = h_str(py_res, py_mod, "longname",
- &(d->longname))) < 0)
+ if ((r = h_str(py_res, "longname", &(d->longname))) < 0)
return r;
- if ((r = h_str(py_res, py_mod, "desc", &(d->desc))) < 0)
+ if ((r = h_str(py_res, "desc", &(d->desc))) < 0)
return r;
- if ((r = h_str(py_res, py_mod, "longdesc",
- &(d->longdesc))) < 0)
+ if ((r = h_str(py_res, "longdesc", &(d->longdesc))) < 0)
return r;
- if ((r = h_str(py_res, py_mod, "author", &(d->author))) < 0)
+ if ((r = h_str(py_res, "author", &(d->author))) < 0)
return r;
- if ((r = h_str(py_res, py_mod, "email", &(d->email))) < 0)
+ if ((r = h_str(py_res, "email", &(d->email))) < 0)
return r;
- if ((r = h_str(py_res, py_mod, "license", &(d->license))) < 0)
+ if ((r = h_str(py_res, "license", &(d->license))) < 0)
return r;
d->py_mod = py_mod;
d->inputformats = NULL;
d->outputformats = NULL;
+ /* Convert class annotation attribute to GSList of **char */
+ d->annotation = NULL;
+ if (PyObject_HasAttrString(py_res, "annotation")) {
+ 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;
/* TODO: Warning if loading fails for a decoder. */
if ((ret = srd_load_decoder(decodername, &dec)) == SRD_OK) {
/* Append it to the list of supported/loaded decoders. */
- list_pds = g_slist_append(list_pds, dec);
+ pd_list = g_slist_append(pd_list, dec);
}
}
closedir(dir);