static int get_probes(struct srd_decoder *d, char *attr, GSList **pl)
{
PyObject *py_probelist, *py_entry;
static int get_probes(struct srd_decoder *d, char *attr, GSList **pl)
{
PyObject *py_probelist, *py_entry;
py_probelist = PyObject_GetAttrString(d->py_dec, attr);
if (!PyList_Check(py_probelist)) {
srd_err("Protocol decoder %s %s attribute is not "
py_probelist = PyObject_GetAttrString(d->py_dec, attr);
if (!PyList_Check(py_probelist)) {
srd_err("Protocol decoder %s %s attribute is not "
py_entry = PyList_GetItem(py_probelist, i);
if (!PyDict_Check(py_entry)) {
srd_err("Protocol decoder %s %s attribute is not "
py_entry = PyList_GetItem(py_probelist, i);
if (!PyDict_Check(py_entry)) {
srd_err("Protocol decoder %s %s attribute is not "
* Load a protocol decoder module into the embedded Python interpreter.
*
* @param name The module name to be loaded.
* Load a protocol decoder module into the embedded Python interpreter.
*
* @param name The module name to be loaded.
{
PyObject *py_basedec, *py_method, *py_attr, *py_annlist, *py_ann;
struct srd_decoder *d;
int alen, ret, i;
char **ann;
{
PyObject *py_basedec, *py_method, *py_attr, *py_annlist, *py_ann;
struct srd_decoder *d;
int alen, ret, i;
char **ann;
- if (!(d->py_mod = PyImport_ImportModule(name))) {
- catch_exception("import of '%s' failed.", name);
+ if (!(d->py_mod = PyImport_ImportModule(module_name))) {
+ catch_exception("import of '%s' failed.", module_name);
if (!(d->py_dec = PyObject_GetAttrString(d->py_mod, "Decoder"))) {
/* This generated an AttributeError exception. */
PyErr_Clear();
if (!(d->py_dec = PyObject_GetAttrString(d->py_mod, "Decoder"))) {
/* This generated an AttributeError exception. */
PyErr_Clear();
if (!PyObject_IsSubclass(d->py_dec, py_basedec)) {
srd_err("Decoder class in protocol decoder module %s is not "
if (!PyObject_IsSubclass(d->py_dec, py_basedec)) {
srd_err("Decoder class in protocol decoder module %s is not "
/* Check for a proper start() method. */
if (!PyObject_HasAttrString(d->py_dec, "start")) {
srd_err("Protocol decoder %s has no start() method Decoder "
/* Check for a proper start() method. */
if (!PyObject_HasAttrString(d->py_dec, "start")) {
srd_err("Protocol decoder %s has no start() method Decoder "
goto err_out;
}
py_method = PyObject_GetAttrString(d->py_dec, "start");
if (!PyFunction_Check(py_method)) {
srd_err("Protocol decoder %s Decoder class attribute 'start' "
goto err_out;
}
py_method = PyObject_GetAttrString(d->py_dec, "start");
if (!PyFunction_Check(py_method)) {
srd_err("Protocol decoder %s Decoder class attribute 'start' "
/* Check for a proper decode() method. */
if (!PyObject_HasAttrString(d->py_dec, "decode")) {
srd_err("Protocol decoder %s has no decode() method Decoder "
/* Check for a proper decode() method. */
if (!PyObject_HasAttrString(d->py_dec, "decode")) {
srd_err("Protocol decoder %s has no decode() method Decoder "
goto err_out;
}
py_method = PyObject_GetAttrString(d->py_dec, "decode");
if (!PyFunction_Check(py_method)) {
srd_err("Protocol decoder %s Decoder class attribute 'decode' "
goto err_out;
}
py_method = PyObject_GetAttrString(d->py_dec, "decode");
if (!PyFunction_Check(py_method)) {
srd_err("Protocol decoder %s Decoder class attribute 'decode' "
py_attr = PyObject_GetAttrString(d->py_dec, "options");
if (!PyDict_Check(py_attr)) {
srd_err("Protocol decoder %s options attribute is not "
py_attr = PyObject_GetAttrString(d->py_dec, "options");
if (!PyDict_Check(py_attr)) {
srd_err("Protocol decoder %s options attribute is not "
if (PyObject_HasAttrString(d->py_dec, "annotations")) {
py_annlist = PyObject_GetAttrString(d->py_dec, "annotations");
if (!PyList_Check(py_annlist)) {
if (PyObject_HasAttrString(d->py_dec, "annotations")) {
py_annlist = PyObject_GetAttrString(d->py_dec, "annotations");
if (!PyList_Check(py_annlist)) {
goto err_out;
}
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) {
goto err_out;
}
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);
+ srd_err("Protocol decoder module %s "
+ "annotation %d should be a list with "
+ "two elements.", module_name, i + 1);
-char *srd_decoder_doc(struct srd_decoder *dec)
+/**
+ * Return a protocol decoder's docstring.
+ *
+ * @param dec The loaded protocol decoder.
+ *
+ * @return A newly allocated buffer containing the docstring. The caller should
+ * free this after use.
+ */
+SRD_API char *srd_decoder_doc(struct srd_decoder *dec)
srd_dbg("unloading decoder %s", dec->name);
/* Since any instances of this decoder need to be released as well,
* but they could be anywhere in the stack, just free the entire
* stack. A frontend reloading a decoder thus has to restart all
* instances, and rebuild the stack. */
srd_dbg("unloading decoder %s", dec->name);
/* Since any instances of this decoder need to be released as well,
* but they could be anywhere in the stack, just free the entire
* stack. A frontend reloading a decoder thus has to restart all
* instances, and rebuild the stack. */
-int srd_load_all_decoders(void)
+/**
+ * Load all installed protocol decoders.
+ *
+ * @return SRD_OK upon success, a (negative) error code otherwise.
+ */
+SRD_API int srd_decoders_load_all(void)
- /* The decoder name is the PD directory name (e.g. "i2c"). */
- decodername = g_strdup(direntry);
-
- if ((ret = srd_load_decoder(decodername, &dec)) == SRD_OK) {
- /* Append it to the list of supported/loaded decoders. */
- pd_list = g_slist_append(pd_list, dec);
- }
+ /* The directory name is the module name (e.g. "i2c"). */
+ srd_decoder_load(direntry);