X-Git-Url: http://sigrok.org/gitweb/?a=blobdiff_plain;f=bindings%2Fcxx%2Fclasses.cpp;h=2b26f1a88d90f6aa20c614216da9be293d020d6b;hb=f88c73732cbef5dad58788d1555bd66742001192;hp=67d490861b94503aacfd2298b01cda22bab93a5b;hpb=58aa1f8359007804f48a4f881e6782a06e1b729a;p=libsigrok.git diff --git a/bindings/cxx/classes.cpp b/bindings/cxx/classes.cpp index 67d49086..2b26f1a8 100644 --- a/bindings/cxx/classes.cpp +++ b/bindings/cxx/classes.cpp @@ -40,18 +40,6 @@ static const char *valid_string(const char *input) return ""; } -/** Helper function to convert between map and GHashTable */ -static GHashTable *map_to_hash_string(map input) -{ - auto output = g_hash_table_new_full( - g_str_hash, g_str_equal, g_free, g_free); - for (auto entry : input) - g_hash_table_insert(output, - g_strdup(entry.first.c_str()), - g_strdup(entry.second.c_str())); - return output; -} - /** Helper function to convert between map and GHashTable */ static GHashTable *map_to_hash_variant(map input) { @@ -92,10 +80,10 @@ Context::Context() : for (int i = 0; driver_list[i]; i++) drivers[driver_list[i]->name] = new Driver(driver_list[i]); - struct sr_input_format **input_list = sr_input_list(); + const struct sr_input_module **input_list = sr_input_list(); if (input_list) for (int i = 0; input_list[i]; i++) - input_formats[input_list[i]->id] = + input_formats[sr_input_id_get(input_list[i])] = new InputFormat(input_list[i]); const struct sr_output_module **output_list = sr_output_list(); if (output_list) @@ -239,6 +227,27 @@ shared_ptr Context::create_trigger(string name) new Trigger(shared_from_this(), name), Trigger::Deleter()); } +shared_ptr Context::open_file(string filename) +{ + const struct sr_input *input; + + check( sr_input_scan_file(filename.c_str(), &input)); + return shared_ptr( + new Input(shared_from_this(), input), Input::Deleter()); +} + +shared_ptr Context::open_stream(string header) +{ + const struct sr_input *input; + + auto gstr = g_string_new(header.c_str()); + auto ret = sr_input_scan_buffer(gstr, &input); + g_string_free(gstr, true); + check(ret); + return shared_ptr( + new Input(shared_from_this(), input), Input::Deleter()); +} + Driver::Driver(struct sr_dev_driver *structure) : StructureWrapper(structure), initialized(false) @@ -353,7 +362,7 @@ Glib::VariantContainerBase Configurable::config_list(const ConfigKey *key) Device::Device(struct sr_dev_inst *structure) : Configurable(structure->driver, structure, NULL), - StructureWrapper(structure) + structure(structure) { for (GSList *entry = structure->channels; entry; entry = entry->next) { @@ -445,6 +454,7 @@ void Device::close() } HardwareDevice::HardwareDevice(Driver *driver, struct sr_dev_inst *structure) : + StructureWrapper(structure), Device(structure), driver(driver) { @@ -1100,8 +1110,8 @@ vector Analog::get_mq_flags() return QuantityFlag::flags_from_mask(structure->mqflags); } -InputFormat::InputFormat(struct sr_input_format *structure) : - StructureWrapper(structure) +InputFormat::InputFormat(const struct sr_input_module *structure) : + StructureWrapper(structure) { } @@ -1111,56 +1121,86 @@ InputFormat::~InputFormat() string InputFormat::get_name() { - return valid_string(structure->id); + return valid_string(sr_input_id_get(structure)); } string InputFormat::get_description() { - return valid_string(structure->description); + return valid_string(sr_input_description_get(structure)); } -bool InputFormat::format_match(string filename) +map> InputFormat::get_options() +{ + const struct sr_option **options = sr_input_options_get(structure); + auto option_array = shared_ptr( + options, sr_input_options_free); + map> result; + for (int i = 0; options[i]; i++) + result[options[i]->id] = shared_ptr