From: Gerhard Sittig Date: Sun, 13 May 2018 06:54:48 +0000 (+0200) Subject: input: provide accessor routine for (struct sr_input *)->module X-Git-Url: https://sigrok.org/gitaction?a=commitdiff_plain;h=c83bdde9da1ec1760b5bd7810f41ce992990a00b;p=libsigrok.git input: provide accessor routine for (struct sr_input *)->module Add a public API routine which allows applications to query the sr_input_module from an sr_input. --- diff --git a/include/libsigrok/proto.h b/include/libsigrok/proto.h index 350cffa3..2017f712 100644 --- a/include/libsigrok/proto.h +++ b/include/libsigrok/proto.h @@ -170,6 +170,7 @@ SR_API struct sr_input *sr_input_new(const struct sr_input_module *imod, GHashTable *options); SR_API int sr_input_scan_buffer(GString *buf, const struct sr_input **in); SR_API int sr_input_scan_file(const char *filename, const struct sr_input **in); +SR_API const struct sr_input_module *sr_input_module_get(const struct sr_input *in); SR_API struct sr_dev_inst *sr_input_dev_inst_get(const struct sr_input *in); SR_API int sr_input_send(const struct sr_input *in, GString *buf); SR_API int sr_input_end(const struct sr_input *in); diff --git a/src/input/input.c b/src/input/input.c index ee19d661..2a23aec2 100644 --- a/src/input/input.c +++ b/src/input/input.c @@ -532,6 +532,22 @@ SR_API int sr_input_scan_file(const char *filename, const struct sr_input **in) return SR_ERR; } +/** + * Return the input instance's module "class". This can be used to find out + * which input module handles a specific input file. This is especially + * useful when an application did not create the input stream by specifying + * an input module, but instead some shortcut or convenience wrapper did. + * + * @since 0.6.0 + */ +SR_API const struct sr_input_module *sr_input_module_get(const struct sr_input *in) +{ + if (!in) + return NULL; + + return in->module; +} + /** * Return the input instance's (virtual) device instance. This can be * used to find out the number of channels and other information.