X-Git-Url: http://sigrok.org/gitweb/?a=blobdiff_plain;f=bindings%2Fcxx%2Fclasses.cpp;h=d5477847653f85acb6f637b48de4a3ce677a9659;hb=HEAD;hp=d25c53cf13e4a909809faacf73e6ffe46d1df514;hpb=79034d4f39f76415e463f02d6b60f5269481da9f;p=libsigrok.git diff --git a/bindings/cxx/classes.cpp b/bindings/cxx/classes.cpp index d25c53cf..d5477847 100644 --- a/bindings/cxx/classes.cpp +++ b/bindings/cxx/classes.cpp @@ -32,6 +32,8 @@ namespace sigrok { +using namespace std; + /** Helper function to translate C errors to C++ exceptions. */ static void check(int result) { @@ -177,6 +179,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 +241,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; } @@ -259,12 +287,12 @@ shared_ptr Context::create_user_device( default_delete{}}; } -shared_ptr Context::create_header_packet(Glib::TimeVal start_time) +shared_ptr Context::create_header_packet(Glib::DateTime start_time) { auto header = g_new(struct sr_datafeed_header, 1); header->feed_version = 1; - header->starttime.tv_sec = start_time.tv_sec; - header->starttime.tv_usec = start_time.tv_usec; + header->starttime.tv_sec = start_time.to_unix(); + header->starttime.tv_usec = start_time.get_microsecond(); auto packet = g_new(struct sr_datafeed_packet, 1); packet->type = SR_DF_HEADER; packet->payload = header; @@ -351,6 +379,14 @@ shared_ptr Context::create_analog_packet( return shared_ptr{new Packet{nullptr, packet}, default_delete{}}; } +shared_ptr Context::create_end_packet() +{ + auto packet = g_new(struct sr_datafeed_packet, 1); + packet->type = SR_DF_END; + return shared_ptr{new Packet{nullptr, packet}, + default_delete{}}; +} + shared_ptr Context::load_session(string filename) { return shared_ptr{ @@ -910,6 +946,7 @@ Session::Session(shared_ptr context, string filename) : _owned_devices.emplace(sdi, move(device)); } _context->_session = this; + g_slist_free(dev_list); } Session::~Session() @@ -944,6 +981,7 @@ vector> Session::devices() auto *const sdi = static_cast(dev->data); result.push_back(get_device(sdi)); } + g_slist_free(dev_list); return result; } @@ -1116,11 +1154,10 @@ int Header::feed_version() const return _structure->feed_version; } -Glib::TimeVal Header::start_time() const +Glib::DateTime Header::start_time() const { - return Glib::TimeVal( - _structure->starttime.tv_sec, - _structure->starttime.tv_usec); + Glib::DateTime time = Glib::DateTime::create_now_utc(_structure->starttime.tv_sec); + return time.add_seconds(_structure->starttime.tv_usec / 1.0e6); } Meta::Meta(const struct sr_datafeed_meta *structure) : @@ -1528,6 +1565,8 @@ Glib::VariantBase Option::parse_string(string value) dt = SR_T_FLOAT; } else if (g_variant_is_of_type(tmpl, G_VARIANT_TYPE_INT32)) { dt = SR_T_INT32; + } else if (g_variant_is_of_type(tmpl, G_VARIANT_TYPE_UINT32)) { + dt = SR_T_UINT32; } else { throw Error(SR_ERR_BUG); } @@ -1625,6 +1664,11 @@ Output::~Output() check(sr_output_free(_structure)); } +shared_ptr Output::format() +{ + return _format; +} + string Output::receive(shared_ptr packet) { GString *out;