From: Gerhard Sittig Date: Sun, 13 May 2018 06:56:09 +0000 (+0200) Subject: bindings: wrap sr_input_scan_file() in the C++ language binding X-Git-Url: https://sigrok.org/gitweb/?p=libsigrok.git;a=commitdiff_plain;h=092843eb4286885be8801592cfffb449cb23ddea bindings: wrap sr_input_scan_file() in the C++ language binding Allow C++ applications to have the input format automatically detected, and get a corresponding InputFormat instance. This makes the format match logic available to PulseView. --- diff --git a/bindings/cxx/classes.cpp b/bindings/cxx/classes.cpp index d25c53cf..bf826e3c 100644 --- a/bindings/cxx/classes.cpp +++ b/bindings/cxx/classes.cpp @@ -177,6 +177,32 @@ map> Context::input_formats() return result; } +shared_ptr Context::input_format_match(string filename) +{ + const struct sr_input *input; + const struct sr_input_module *imod; + int rc; + + /* + * Have the input module looked up for the specified file. + * Failed lookup (or "successful lookup" with an empty result) + * are non-fatal. Free the sr_input that was created by the + * lookup routine, but grab the input module kind and return an + * InputFormat instance to the application. This works because + * the application passes a filename, no input data got buffered + * in the sr_input that we release. + */ + input = NULL; + rc = sr_input_scan_file(filename.c_str(), &input); + if (rc != SR_OK) + return nullptr; + if (!input) + return nullptr; + imod = sr_input_module_get(input); + sr_input_free(input); + return shared_ptr{new InputFormat{imod}, default_delete{}}; +} + map> Context::output_formats() { map> result; diff --git a/bindings/cxx/include/libsigrokcxx/libsigrokcxx.hpp b/bindings/cxx/include/libsigrokcxx/libsigrokcxx.hpp index de54630f..80888af6 100644 --- a/bindings/cxx/include/libsigrokcxx/libsigrokcxx.hpp +++ b/bindings/cxx/include/libsigrokcxx/libsigrokcxx.hpp @@ -252,6 +252,8 @@ public: map > drivers(); /** Available input formats, indexed by name. */ map > input_formats(); + /** Lookup the responsible input module for an input file. */ + shared_ptr input_format_match(string filename); /** Available output formats, indexed by name. */ map > output_formats(); /** Current log level. */