From: Uwe Hermann Date: Tue, 10 Feb 2015 21:55:41 +0000 (+0100) Subject: backend: Add basic transform module sanity checks. X-Git-Tag: libsigrok-0.4.0~651 X-Git-Url: https://sigrok.org/gitaction?a=commitdiff_plain;h=187cfc604e51ee534fef8dc33278caa8eb1ff66d;p=libsigrok.git backend: Add basic transform module sanity checks. --- diff --git a/src/backend.c b/src/backend.c index 637f7de9..49ea9cd5 100644 --- a/src/backend.c +++ b/src/backend.c @@ -306,6 +306,55 @@ static int sanity_check_all_output_modules(void) return ret; } +/** + * Sanity-check all libsigrok transform modules. + * + * @retval SR_OK All modules are OK + * @retval SR_ERR One or more modules have issues. + */ +static int sanity_check_all_transform_modules(void) +{ + int i, errors, ret = SR_OK; + const struct sr_transform_module **transforms; + const char *d; + + sr_spew("Sanity-checking all transform modules."); + + transforms = sr_transform_list(); + for (i = 0; transforms[i]; i++) { + errors = 0; + + d = (transforms[i]->id) ? transforms[i]->id : "NULL"; + + if (!transforms[i]->id) { + sr_err("No ID in module %d ('%s').", i, d); + errors++; + } + if (!transforms[i]->name) { + sr_err("No name in module %d ('%s').", i, d); + errors++; + } + if (!transforms[i]->desc) { + sr_err("No description in module '%s'.", d); + errors++; + } + /* Note: options() is optional. */ + /* Note: init() is optional. */ + if (!transforms[i]->receive) { + sr_err("No receive in module '%s'.", d); + errors++; + } + /* Note: cleanup() is optional. */ + + if (errors == 0) + continue; + + ret = SR_ERR; + } + + return ret; +} + /** * Initialize libsigrok. * @@ -347,6 +396,11 @@ SR_API int sr_init(struct sr_context **ctx) return ret; } + if (sanity_check_all_transform_modules() < 0) { + sr_err("Internal transform module error(s), aborting."); + return ret; + } + /* + 1 to handle when struct sr_context has no members. */ context = g_malloc0(sizeof(struct sr_context) + 1);