]> sigrok.org Git - libsigrok.git/blobdiff - bindings/cxx/classes.cpp
C++: Use sr_input_scan_*() API changes.
[libsigrok.git] / bindings / cxx / classes.cpp
index 986b2c1e1da3fe60daa96ffbb0b15f9d71434f6d..2b26f1a88d90f6aa20c614216da9be293d020d6b 100644 (file)
@@ -229,20 +229,21 @@ shared_ptr<Trigger> Context::create_trigger(string name)
 
 shared_ptr<Input> Context::open_file(string filename)
 {
-       auto input = sr_input_scan_file(filename.c_str());
-       if (!input)
-               throw Error(SR_ERR_NA);
+       const struct sr_input *input;
+
+       check( sr_input_scan_file(filename.c_str(), &input));
        return shared_ptr<Input>(
                new Input(shared_from_this(), input), Input::Deleter());
 }
 
 shared_ptr<Input> Context::open_stream(string header)
 {
+       const struct sr_input *input;
+
        auto gstr = g_string_new(header.c_str());
-       auto input = sr_input_scan_buffer(gstr);
-       g_string_free(gstr, false);
-       if (!input)
-               throw Error(SR_ERR_NA);
+       auto ret = sr_input_scan_buffer(gstr, &input);
+       g_string_free(gstr, true);
+       check(ret);
        return shared_ptr<Input>(
                new Input(shared_from_this(), input), Input::Deleter());
 }
@@ -361,7 +362,7 @@ Glib::VariantContainerBase Configurable::config_list(const ConfigKey *key)
 
 Device::Device(struct sr_dev_inst *structure) :
        Configurable(structure->driver, structure, NULL),
-       StructureWrapper<Context, struct sr_dev_inst>(structure)
+       structure(structure)
 {
        for (GSList *entry = structure->channels; entry; entry = entry->next)
        {
@@ -453,6 +454,7 @@ void Device::close()
 }
 
 HardwareDevice::HardwareDevice(Driver *driver, struct sr_dev_inst *structure) :
+       StructureWrapper(structure),
        Device(structure),
        driver(driver)
 {
@@ -1127,6 +1129,18 @@ string InputFormat::get_description()
        return valid_string(sr_input_description_get(structure));
 }
 
+map<string, shared_ptr<Option>> InputFormat::get_options()
+{
+       const struct sr_option **options = sr_input_options_get(structure);
+       auto option_array = shared_ptr<const struct sr_option *>(
+               options, sr_input_options_free);
+       map<string, shared_ptr<Option>> result;
+       for (int i = 0; options[i]; i++)
+               result[options[i]->id] = shared_ptr<Option>(
+                       new Option(options[i], option_array), Option::Deleter());
+       return result;
+}
+
 shared_ptr<Input> InputFormat::create_input(
        map<string, Glib::VariantBase> options)
 {
@@ -1155,7 +1169,7 @@ shared_ptr<InputDevice> Input::get_device()
        }
 
        return static_pointer_cast<InputDevice>(
-               device->get_shared_pointer(context->shared_from_this()));
+               device->get_shared_pointer(shared_from_this()));
 }
 
 void Input::send(string data)
@@ -1173,8 +1187,10 @@ Input::~Input()
        check(sr_input_free(structure));
 }
 
-InputDevice::InputDevice(shared_ptr<Input> input, struct sr_dev_inst *sdi) :
-       Device(sdi),
+InputDevice::InputDevice(shared_ptr<Input> input,
+               struct sr_dev_inst *structure) :
+       StructureWrapper(structure),
+       Device(structure),
        input(input)
 {
 }