diff options
author | Bert Vermeulen <bert@biot.com> | 2013-12-11 18:31:56 +0100 |
---|---|---|
committer | Bert Vermeulen <bert@biot.com> | 2013-12-11 18:31:56 +0100 |
commit | ea81b49a3ca4fff4994693d30045d51b86181e32 (patch) | |
tree | a939623fa1ecc88115875f97c2566a796328cd7f /decoder.c | |
parent | 820bf44828745e7d0a7bb0974164acd899c3c113 (diff) | |
download | libsigrokdecode-ea81b49a3ca4fff4994693d30045d51b86181e32.tar.gz libsigrokdecode-ea81b49a3ca4fff4994693d30045d51b86181e32.zip |
Load decoders from all search paths, not just the default.
srd_decoder_load_all() was really only getting a list of decoders
from the default (installation) path, so could not find uninstalled
decoders, or those in a custom added search path.
This broke development of new PDs when using the SIGROKDECODE_DIR
environment variable, and broke many of the unit tests in the tests/
directory -- those actually tested against the already-installed
decoders, not the ones about to be installed.
Diffstat (limited to 'decoder.c')
-rw-r--r-- | decoder.c | 39 |
1 files changed, 27 insertions, 12 deletions
@@ -42,6 +42,10 @@ /* The list of protocol decoders. */ SRD_PRIV GSList *pd_list = NULL; +/* srd.c */ +extern GSList *searchpaths; + +/* session.c */ extern GSList *sessions; /* module_sigrokdecode.c */ @@ -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,22 +589,13 @@ SRD_API int srd_decoder_unload(struct srd_decoder *dec) */ SRD_API int srd_decoder_load_all(void) { - GDir *dir; - const gchar *direntry; + GSList *l; if (!srd_check_init()) return SRD_ERR; - if (!(dir = g_dir_open(DECODERS_DIR, 0, NULL))) { - 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; } |