]> sigrok.org Git - libsigrok.git/blobdiff - bindings/cxx/classes.cpp
C++: Whitespace fix.
[libsigrok.git] / bindings / cxx / classes.cpp
index 68124b5a39cd50938a827d10e5154105b5050f0e..8ecffd720677cb4abff40610f3d37512adf5c655 100644 (file)
@@ -229,7 +229,7 @@ shared_ptr<Input> Context::open_file(string filename)
 {
        const struct sr_input *input;
 
-       check( sr_input_scan_file(filename.c_str(), &input));
+       check(sr_input_scan_file(filename.c_str(), &input));
        return shared_ptr<Input>(
                new Input(shared_from_this(), input), Input::Deleter());
 }
@@ -380,6 +380,34 @@ vector<const ConfigKey *> Configurable::config_keys(const ConfigKey *key)
        return result;
 }
 
+bool Configurable::config_check(const ConfigKey *key,
+       const ConfigKey *index_key)
+{
+       GVariant *gvar_opts;
+       gsize num_opts;
+       const int32_t *opts;
+
+       if (sr_config_list(config_driver, config_sdi, config_channel_group,
+                       index_key->get_id(), &gvar_opts) != SR_OK)
+               return false;
+
+       opts = (const int32_t *) g_variant_get_fixed_array(
+               gvar_opts, &num_opts, sizeof(int32_t));
+
+       for (gsize i = 0; i < num_opts; i++)
+       {
+               if (opts[i] == key->get_id())
+               {
+                       g_variant_unref(gvar_opts);
+                       return true;
+               }
+       }
+
+       g_variant_unref(gvar_opts);
+
+       return false;
+}
+
 Device::Device(struct sr_dev_inst *structure) :
        Configurable(structure->driver, structure, NULL),
        structure(structure)
@@ -437,8 +465,10 @@ string Device::get_version()
 vector<shared_ptr<Channel>> Device::get_channels()
 {
        vector<shared_ptr<Channel>> result;
-       for (auto entry : channels)
-               result.push_back(entry.second->get_shared_pointer(get_shared_from_this()));
+       for (auto channel = structure->channels; channel; channel = channel->next)
+               result.push_back(
+                       channels[(struct sr_channel *) channel->data]->get_shared_pointer(
+                               get_shared_from_this()));
        return result;
 }
 
@@ -715,6 +745,21 @@ EventSource::~EventSource()
 {
 }
 
+SessionDevice::SessionDevice(struct sr_dev_inst *structure) :
+       ParentOwned(structure),
+       Device(structure)
+{
+}
+
+SessionDevice::~SessionDevice()
+{
+}
+
+shared_ptr<Device> SessionDevice::get_shared_from_this()
+{
+       return static_pointer_cast<Device>(shared_from_this());
+}
+
 Session::Session(shared_ptr<Context> context) :
        UserOwned(structure),
        context(context), saving(false)
@@ -728,6 +773,15 @@ Session::Session(shared_ptr<Context> context, string filename) :
        context(context), saving(false)
 {
        check(sr_session_load(filename.c_str(), &structure));
+       GSList *dev_list;
+       check(sr_session_dev_list(structure, &dev_list));
+       for (GSList *dev = dev_list; dev; dev = dev->next)
+       {
+               auto sdi = (struct sr_dev_inst *) dev->data;
+               auto device = new SessionDevice(sdi);
+               devices[sdi] = shared_ptr<SessionDevice>(device,
+                       SessionDevice::Deleter());
+       }
        context->session = this;
 }