static GHashTable *map_to_hash_variant(map<string, Glib::VariantBase> input)
{
auto output = g_hash_table_new_full(
- g_variant_hash, g_variant_equal, g_free,
- (void (*)(void *))g_variant_unref);
+ g_str_hash, g_str_equal, g_free, (GDestroyNotify) g_variant_unref);
for (auto entry : input)
g_hash_table_insert(output,
g_strdup(entry.first.c_str()),
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());
}
vector<shared_ptr<Channel>> result;
for (auto entry : channels)
result.push_back(static_pointer_cast<Channel>(
- entry.second->get_shared_pointer(this)));
+ entry.second->get_shared_pointer(get_shared_from_this())));
return result;
}
shared_ptr<Channel> Device::get_channel(struct sr_channel *ptr)
{
return static_pointer_cast<Channel>(
- channels[ptr]->get_shared_pointer(this));
+ channels[ptr]->get_shared_pointer(get_shared_from_this()));
}
map<string, shared_ptr<ChannelGroup>>
auto name = entry.first;
auto channel_group = entry.second;
result[name] = static_pointer_cast<ChannelGroup>(
- channel_group->get_shared_pointer(this));
+ channel_group->get_shared_pointer(get_shared_from_this()));
}
return result;
}
{
}
+shared_ptr<Device> HardwareDevice::get_shared_from_this()
+{
+ return static_pointer_cast<Device>(
+ static_pointer_cast<HardwareDevice>(shared_from_this()));
+}
+
shared_ptr<Driver> HardwareDevice::get_driver()
{
return static_pointer_cast<Driver>(driver->get_shared_pointer(parent));
for (GSList *dev = dev_list; dev; dev = dev->next)
{
auto sdi = (struct sr_dev_inst *) dev->data;
- if (devices.count(sdi) == 0)
- devices[sdi] = shared_ptr<Device>(
- new Device(sdi), Device::Deleter());
result.push_back(devices[sdi]);
}
return result;
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)
{
{
}
+shared_ptr<Device> InputDevice::get_shared_from_this()
+{
+ return static_pointer_cast<Device>(
+ static_pointer_cast<InputDevice>(shared_from_this()));
+}
+
Option::Option(const struct sr_option *structure,
shared_ptr<const struct sr_option *> structure_array) :
structure(structure),