]> sigrok.org Git - libsigrokdecode.git/blobdiff - decoder.c
uart: Use human-readable names for annotation classes.
[libsigrokdecode.git] / decoder.c
index 7374b779453e015025b59ae6dc4b5f16e5416e09..cef4f299aea927d76d64adbb8ba9dcc39a2bf927 100644 (file)
--- a/decoder.c
+++ b/decoder.c
@@ -171,6 +171,7 @@ static void decoder_free(struct srd_decoder *dec)
 
        g_slist_free_full(dec->outputs, g_free);
        g_slist_free_full(dec->inputs, g_free);
+       g_slist_free_full(dec->tags, g_free);
        g_free(dec->license);
        g_free(dec->desc);
        g_free(dec->longname);
@@ -751,6 +752,11 @@ SRD_API int srd_decoder_load(const char *module_name)
 
        /* Check Decoder class for required methods. */
 
+       if (check_method(d->py_dec, module_name, "reset") != SRD_OK) {
+               fail_txt = "no 'reset()' method";
+               goto err_out;
+       }
+
        if (check_method(d->py_dec, module_name, "start") != SRD_OK) {
                fail_txt = "no 'start()' method";
                goto err_out;
@@ -797,6 +803,11 @@ SRD_API int srd_decoder_load(const char *module_name)
                goto err_out;
        }
 
+       if (py_attr_as_strlist(d->py_dec, "tags", &(d->tags)) != SRD_OK) {
+               fail_txt = "missing or malformed 'tags' attribute";
+               goto err_out;
+       }
+
        /* All options and their default values. */
        if (get_options(d) != SRD_OK) {
                fail_txt = "cannot get options";
@@ -858,7 +869,7 @@ err_out:
 /**
  * Return a protocol decoder's docstring.
  *
- * @param dec The loaded protocol decoder.
+ * @param dec The loaded protocol decoder. Must not be NULL.
  *
  * @return A newly allocated buffer containing the protocol decoder's
  *         documentation. The caller is responsible for free'ing the buffer.
@@ -874,7 +885,7 @@ SRD_API char *srd_decoder_doc_get(const struct srd_decoder *dec)
        if (!srd_check_init())
                return NULL;
 
-       if (!dec)
+       if (!dec || !dec->py_mod)
                return NULL;
 
        gstate = PyGILState_Ensure();
@@ -1068,6 +1079,13 @@ SRD_API int srd_decoder_load_all(void)
        return SRD_OK;
 }
 
+static void srd_decoder_unload_cb(void *arg, void *ignored)
+{
+       (void)ignored;
+
+       srd_decoder_unload((struct srd_decoder *)arg);
+}
+
 /**
  * Unload all loaded protocol decoders.
  *
@@ -1077,8 +1095,7 @@ SRD_API int srd_decoder_load_all(void)
  */
 SRD_API int srd_decoder_unload_all(void)
 {
-       for (GSList *l = pd_list; l; l = l->next)
-               srd_decoder_unload(l->data);
+       g_slist_foreach(pd_list, srd_decoder_unload_cb, NULL);
        g_slist_free(pd_list);
        pd_list = NULL;