return "";
}
-/** Helper function to convert between map<string, string> and GHashTable */
-static GHashTable *map_to_hash_string(map<string, string> 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<string, VariantBase> and GHashTable */
static GHashTable *map_to_hash_variant(map<string, Glib::VariantBase> input)
{
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)
new Trigger(shared_from_this(), name), Trigger::Deleter());
}
+shared_ptr<Input> Context::open_file(string filename)
+{
+ auto input = sr_input_scan_file(filename.c_str());
+ if (!input)
+ throw Error(SR_ERR_NA);
+ return shared_ptr<Input>(
+ new Input(shared_from_this(), input), Input::Deleter());
+}
+
+shared_ptr<Input> Context::open_stream(string header)
+{
+ 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);
+ return shared_ptr<Input>(
+ new Input(shared_from_this(), input), Input::Deleter());
+}
+
Driver::Driver(struct sr_dev_driver *structure) :
StructureWrapper<Context, struct sr_dev_driver>(structure),
initialized(false)
return QuantityFlag::flags_from_mask(structure->mqflags);
}
-InputFormat::InputFormat(struct sr_input_format *structure) :
- StructureWrapper<Context, struct sr_input_format>(structure)
+InputFormat::InputFormat(const struct sr_input_module *structure) :
+ StructureWrapper<Context, const struct sr_input_module>(structure)
{
}
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));
+}
+
+shared_ptr<Input> InputFormat::create_input(
+ map<string, Glib::VariantBase> options)
+{
+ auto input = sr_input_new(structure, map_to_hash_variant(options));
+ if (!input)
+ throw Error(SR_ERR_ARG);
+ return shared_ptr<Input>(
+ new Input(parent->shared_from_this(), input), Input::Deleter());
}
-bool InputFormat::format_match(string filename)
+Input::Input(shared_ptr<Context> context, const struct sr_input *structure) :
+ structure(structure),
+ context(context),
+ device(nullptr)
{
- return structure->format_match(filename.c_str());
}
-shared_ptr<InputFileDevice> InputFormat::open_file(string filename,
- map<string, string> options)
+shared_ptr<InputDevice> Input::get_device()
{
- auto input = g_new(struct sr_input, 1);
- input->param = map_to_hash_string(options);
+ if (!device)
+ {
+ auto sdi = sr_input_dev_inst_get(structure);
+ if (!sdi)
+ throw Error(SR_ERR_NA);
+ device = new InputDevice(shared_from_this(), sdi);
+ }
- /** Run initialisation. */
- check(structure->init(input, filename.c_str()));
+ return static_pointer_cast<InputDevice>(
+ device->get_shared_pointer(context->shared_from_this()));
+}
- /** Create virtual device. */
- return shared_ptr<InputFileDevice>(new InputFileDevice(
- static_pointer_cast<InputFormat>(shared_from_this()), input, filename),
- InputFileDevice::Deleter());
+void Input::send(string data)
+{
+ auto gstr = g_string_new(data.c_str());
+ auto ret = sr_input_send(structure, gstr);
+ g_string_free(gstr, false);
+ check(ret);
}
-InputFileDevice::InputFileDevice(shared_ptr<InputFormat> format,
- struct sr_input *input, string filename) :
- Device(input->sdi),
- input(input),
- format(format),
- filename(filename)
+Input::~Input()
{
+ if (device)
+ delete device;
+ check(sr_input_free(structure));
}
-InputFileDevice::~InputFileDevice()
+InputDevice::InputDevice(shared_ptr<Input> input, struct sr_dev_inst *sdi) :
+ Device(sdi),
+ input(input)
{
- g_hash_table_unref(input->param);
- g_free(input);
}
-void InputFileDevice::load()
+InputDevice::~InputDevice()
{
- check(format->structure->loadfile(input, filename.c_str()));
}
Option::Option(const struct sr_option *structure,