]> sigrok.org Git - libsigrokdecode.git/blobdiff - decoder.c
Drop obsolete report() method.
[libsigrokdecode.git] / decoder.c
index 3716537c82e4337084cb0086e2e70a0ab7903489..01dcf0a823b6da56a798d646750e355bfdd3de52 100644 (file)
--- a/decoder.c
+++ b/decoder.c
@@ -19,8 +19,8 @@
  */
 
 #include "config.h"
-#include "sigrokdecode.h" /* First, so we avoid a _POSIX_C_SOURCE warning. */
-#include "sigrokdecode-internal.h"
+#include "libsigrokdecode.h" /* First, so we avoid a _POSIX_C_SOURCE warning. */
+#include "libsigrokdecode-internal.h"
 #include <glib.h>
 
 /**
@@ -42,6 +42,8 @@
 /* The list of protocol decoders. */
 SRD_PRIV GSList *pd_list = NULL;
 
+extern GSList *sessions;
+
 /* module_sigrokdecode.c */
 extern SRD_PRIV PyObject *mod_sigrokdecode;
 
@@ -53,6 +55,8 @@ extern SRD_PRIV PyObject *mod_sigrokdecode;
  * This is a GSList containing the names of the decoders as strings.
  *
  * @return List of decoders, NULL if none are supported or loaded.
+ *
+ * @since 0.1.0 (but the API changed in 0.2.0)
  */
 SRD_API const GSList *srd_decoder_list(void)
 {
@@ -65,6 +69,8 @@ SRD_API const GSList *srd_decoder_list(void)
  * @param id The ID string of the decoder to return.
  *
  * @return The decoder with the specified ID, or NULL if not found.
+ *
+ * @since 0.1.0
  */
 SRD_API struct srd_decoder *srd_decoder_get_by_id(const char *id)
 {
@@ -213,6 +219,8 @@ static int get_options(struct srd_decoder *d)
                }
                g_variant_ref_sink(o->def);
                d->options = g_slist_append(d->options, o);
+               g_free(key);
+               key = NULL;
        }
        Py_DecRef(py_keys);
        Py_DecRef(py_values);
@@ -232,6 +240,8 @@ err_out:
  * @param module_name The module name to be loaded.
  *
  * @return SRD_OK upon success, a (negative) error code otherwise.
+ *
+ * @since 0.1.0
  */
 SRD_API int srd_decoder_load(const char *module_name)
 {
@@ -242,6 +252,9 @@ SRD_API int srd_decoder_load(const char *module_name)
        struct srd_probe *p;
        GSList *l;
 
+       if (!module_name)
+               return SRD_ERR_ARG;
+
        srd_dbg("Loading protocol decoder '%s'.", module_name);
 
        py_basedec = py_method = py_attr = NULL;
@@ -399,6 +412,8 @@ err_out:
  *
  * @return A newly allocated buffer containing the protocol decoder's
  *         documentation. The caller is responsible for free'ing the buffer.
+ *
+ * @since 0.1.0
  */
 SRD_API char *srd_decoder_doc_get(const struct srd_decoder *dec)
 {
@@ -440,15 +455,18 @@ static void free_probes(GSList *probelist)
 }
 
 /**
- * Unload decoder module.
+ * Unload the specified protocol decoder.
  *
  * @param dec The struct srd_decoder to be unloaded.
  *
  * @return SRD_OK upon success, a (negative) error code otherwise.
+ *
+ * @since 0.1.0
  */
 SRD_API int srd_decoder_unload(struct srd_decoder *dec)
 {
        struct srd_decoder_option *o;
+       struct srd_session *sess;
        GSList *l;
 
        srd_dbg("Unloading protocol decoder '%s'.", dec->name);
@@ -459,7 +477,10 @@ SRD_API int srd_decoder_unload(struct srd_decoder *dec)
         * stack. A frontend reloading a decoder thus has to restart all
         * instances, and rebuild the stack.
         */
-       srd_inst_free_all(NULL);
+       for (l = sessions; l; l = l->next) {
+               sess = l->data;
+               srd_inst_free_all(sess, NULL);
+       }
 
        for (l = dec->options; l; l = l->next) {
                o = l->data;
@@ -483,7 +504,7 @@ SRD_API int srd_decoder_unload(struct srd_decoder *dec)
        /* The module itself. */
        Py_XDECREF(dec->py_mod);
 
-       /* TODO: (g_)free dec itself? */
+       g_free(dec);
 
        return SRD_OK;
 }
@@ -492,6 +513,8 @@ SRD_API int srd_decoder_unload(struct srd_decoder *dec)
  * Load all installed protocol decoders.
  *
  * @return SRD_OK upon success, a (negative) error code otherwise.
+ *
+ * @since 0.1.0
  */
 SRD_API int srd_decoder_load_all(void)
 {
@@ -517,6 +540,8 @@ SRD_API int srd_decoder_load_all(void)
  * Unload all loaded protocol decoders.
  *
  * @return SRD_OK upon success, a (negative) error code otherwise.
+ *
+ * @since 0.1.0
  */
 SRD_API int srd_decoder_unload_all(void)
 {