]> sigrok.org Git - libsigrokdecode.git/blobdiff - decoder.c
Easier access to sequences of strings, not just lists.
[libsigrokdecode.git] / decoder.c
index e3ffb01288015d19e80b8cdba20fb3bdbd222325..858b56ad2233c0fe76e0a40248873eee1d188e3d 100644 (file)
--- a/decoder.c
+++ b/decoder.c
 /* The list of protocol decoders. */
 SRD_PRIV GSList *pd_list = NULL;
 
+/* srd.c */
+extern GSList *searchpaths;
+
+/* session.c */
 extern GSList *sessions;
 
 /* module_sigrokdecode.c */
@@ -391,7 +395,7 @@ SRD_API int srd_decoder_load(const char *module_name)
                                goto err_out;
                        }
 
-                       if (py_strlist_to_char(py_ann, &ann) != SRD_OK) {
+                       if (py_strseq_to_char(py_ann, &ann) != SRD_OK) {
                                goto err_out;
                        }
                        d->annotations = g_slist_append(d->annotations, ann);
@@ -556,6 +560,26 @@ SRD_API int srd_decoder_unload(struct srd_decoder *dec)
        return SRD_OK;
 }
 
+static void srd_decoder_load_all_path(char *path)
+{
+       GDir *dir;
+       const gchar *direntry;
+
+       if (!(dir = g_dir_open(path, 0, NULL)))
+               /* Not really fatal */
+               return;
+
+       /* This ignores errors returned by srd_decoder_load(). That
+        * function will have logged the cause, but in any case we
+        * want to continue anyway. */
+       while ((direntry = g_dir_read_name(dir)) != NULL) {
+               /* The directory name is the module name (e.g. "i2c"). */
+               srd_decoder_load(direntry);
+       }
+       g_dir_close(dir);
+
+}
+
 /**
  * Load all installed protocol decoders.
  *
@@ -565,23 +589,13 @@ SRD_API int srd_decoder_unload(struct srd_decoder *dec)
  */
 SRD_API int srd_decoder_load_all(void)
 {
-       GDir *dir;
-       GError *error;
-       const gchar *direntry;
+       GSList *l;
 
        if (!srd_check_init())
                return SRD_ERR;
 
-       if (!(dir = g_dir_open(DECODERS_DIR, 0, &error))) {
-               srd_err("Unable to open %s for reading.", DECODERS_DIR);
-               return SRD_ERR_DECODERS_DIR;
-       }
-
-       while ((direntry = g_dir_read_name(dir)) != NULL) {
-               /* The directory name is the module name (e.g. "i2c"). */
-               srd_decoder_load(direntry);
-       }
-       g_dir_close(dir);
+       for (l = searchpaths; l; l = l->next)
+               srd_decoder_load_all_path(l->data);
 
        return SRD_OK;
 }
@@ -602,6 +616,8 @@ SRD_API int srd_decoder_unload_all(void)
                dec = l->data;
                srd_decoder_unload(dec);
        }
+       g_slist_free(pd_list);
+       pd_list = NULL;
 
        return SRD_OK;
 }