X-Git-Url: https://sigrok.org/gitweb/?a=blobdiff_plain;f=bindings%2Fcxx%2Fclasses.cpp;h=5bc5dc2fed78f594d0605f4a58bdd644ccfb0239;hb=3bae09ab9fc3681e0ae3d2f16e862c831d43efc3;hp=d25c53cf13e4a909809faacf73e6ffe46d1df514;hpb=79034d4f39f76415e463f02d6b60f5269481da9f;p=libsigrok.git diff --git a/bindings/cxx/classes.cpp b/bindings/cxx/classes.cpp index d25c53cf..5bc5dc2f 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; @@ -213,7 +239,7 @@ static int call_log_callback(void *cb_data, int loglevel, try { (*callback)(LogLevel::get(loglevel), message.get()); - } catch (Error e) { + } catch (Error &e) { return e.result; }