]> sigrok.org Git - libsigrok.git/blobdiff - bindings/cxx/classes.cpp
C++: Add spaces in Device::description().
[libsigrok.git] / bindings / cxx / classes.cpp
index 7a6daa92df7c664c8251f18133fc69586a5aa740..66b79a93a1f31b6f29f421eebc2a99c27b0dfe43 100644 (file)
@@ -352,12 +352,12 @@ Glib::VariantContainerBase Configurable::config_list(const ConfigKey *key)
        return Glib::VariantContainerBase(data);
 }
 
-vector<const ConfigKey *> Configurable::config_keys(const ConfigKey *key)
+map<const ConfigKey *, set<Capability>> Configurable::config_keys(const ConfigKey *key)
 {
        GVariant *gvar_opts;
        gsize num_opts;
        const uint32_t *opts;
-       vector<const ConfigKey *> result;
+       map<const ConfigKey *, set<Capability>> result;
 
        check(sr_config_list(
                config_driver, config_sdi, config_channel_group,
@@ -367,7 +367,17 @@ vector<const ConfigKey *> Configurable::config_keys(const ConfigKey *key)
                gvar_opts, &num_opts, sizeof(uint32_t));
 
        for (gsize i = 0; i < num_opts; i++)
-               result.push_back(ConfigKey::get(opts[i] & SR_CONF_MASK));
+       {
+               auto key = ConfigKey::get(opts[i] & SR_CONF_MASK);
+               set<Capability> capabilities;
+               if (opts[i] & SR_CONF_GET)
+                       capabilities.insert(GET);
+               if (opts[i] & SR_CONF_SET)
+                       capabilities.insert(SET);
+               if (opts[i] & SR_CONF_LIST)
+                       capabilities.insert(LIST);
+               result[key] = capabilities;
+       }
 
        g_variant_unref(gvar_opts);
 
@@ -432,11 +442,20 @@ string Device::description()
        ostringstream s;
 
        vector<string> parts =
-               {vendor(), model(), version()};
+               {vendor(), model(), version(), serial_number()};
+
+       for (size_t i = 0; i < parts.size(); i++)
+       {
+               if (parts[i].length() > 0)
+               {
+                       if (i != 0)
+                               s << " ";
+                       s << parts[i];
+               }
+       }
 
-       for (string part : parts)
-               if (part.length() > 0)
-                       s << part;
+       if (serial_number().length() == 0 && connection_id().length() > 0)
+               s << " " << connection_id();
 
        return s.str();
 }
@@ -456,6 +475,16 @@ string Device::version()
        return valid_string(_structure->version);
 }
 
+string Device::serial_number()
+{
+       return valid_string(_structure->serial_num);
+}
+
+string Device::connection_id()
+{
+       return valid_string(_structure->connection_id);
+}
+
 vector<shared_ptr<Channel>> Device::channels()
 {
        vector<shared_ptr<Channel>> result;
@@ -1289,11 +1318,16 @@ void Input::send(string data)
        check(ret);
 }
 
+void Input::end()
+{
+       check(sr_input_end(_structure));
+}
+
 Input::~Input()
 {
        if (_device)
                delete _device;
-       check(sr_input_free(_structure));
+       sr_input_free(_structure);
 }
 
 InputDevice::InputDevice(shared_ptr<Input> input,