]> sigrok.org Git - pulseview.git/commitdiff
Update to new configuration API.
authorMartin Ling <redacted>
Tue, 3 Nov 2015 10:54:17 +0000 (10:54 +0000)
committerUwe Hermann <redacted>
Thu, 31 Dec 2015 17:20:06 +0000 (18:20 +0100)
pv/binding/device.cpp
pv/binding/device.hpp
pv/devices/device.cpp
pv/dialogs/connect.cpp
pv/toolbars/mainbar.cpp
pv/view/logicsignal.cpp

index 77c772c088b07dabcbba1ed782339560527dae09..026ca16c6b49354f5e51cbbe89b59a1c09f5bf86 100644 (file)
@@ -56,17 +56,12 @@ namespace binding {
 Device::Device(shared_ptr<sigrok::Configurable> configurable) :
        configurable_(configurable)
 {
-       std::map< const ConfigKey*, std::set<Capability> > keys;
 
-       try {
-               keys = configurable->config_keys(ConfigKey::DEVICE_OPTIONS);
-       } catch (const Error) {
-               return;
-       }
+       auto keys = configurable->config_keys();
+
+       for (auto key : keys) {
 
-       for (auto entry : keys) {
-               auto key = entry.first;
-               auto capabilities = entry.second;
+               auto capabilities = configurable->config_capabilities(key);
 
                if (!capabilities.count(Capability::GET) ||
                        !capabilities.count(Capability::SET))
@@ -146,7 +141,7 @@ void Device::bind_bool(const QString &name,
 }
 
 void Device::bind_enum(const QString &name,
-       const ConfigKey *key, std::set<Capability> capabilities,
+       const ConfigKey *key, std::set<const Capability *> capabilities,
        Property::Getter getter,
        Property::Setter setter, function<QString (Glib::VariantBase)> printer)
 {
index 7dfe02465322b4c5a8c718724bf302922e52783d..563132a205699427ad1903cfab5fd78b1b0e1fe6 100644 (file)
@@ -50,7 +50,8 @@ private:
        void bind_bool(const QString &name,
                prop::Property::Getter getter, prop::Property::Setter setter);
        void bind_enum(const QString &name,
-               const sigrok::ConfigKey *key, std::set<sigrok::Capability> capabilities,
+               const sigrok::ConfigKey *key,
+               std::set<const sigrok::Capability *> capabilities,
                prop::Property::Getter getter, prop::Property::Setter setter,
                std::function<QString (Glib::VariantBase)> printer = print_gvariant);
        void bind_int(const QString &name, QString suffix,
index 4edc1d10e11cbb3be3e1b5ae1e79760da47fc4cb..403acc4896c684d82d3ee35cf279bc2c945c700e 100644 (file)
@@ -28,6 +28,7 @@ using std::map;
 using std::set;
 
 using sigrok::ConfigKey;
+using sigrok::Capability;
 using sigrok::Error;
 
 using Glib::VariantBase;
@@ -64,20 +65,11 @@ template<typename T>
 T Device::read_config(const ConfigKey *key, const T default_value)
 {
        assert(key);
-       map< const ConfigKey*, set<sigrok::Capability> > keys;
 
        if (!device_)
                return default_value;
 
-       try {
-               keys = device_->config_keys(ConfigKey::DEVICE_OPTIONS);
-       } catch (const Error) {
-               return default_value;
-       }
-
-       const auto iter = keys.find(key);
-       if (iter == keys.end() ||
-               (*iter).second.find(sigrok::GET) == (*iter).second.end())
+       if (!device_->config_check(key, Capability::GET))
                return default_value;
 
        return VariantBase::cast_dynamic<Glib::Variant<guint64>>(
index bf92998b9b9e65fd7cd1ecf0d1d1c1564914f347..4d33cc9f3b6d1d2e1ebbc798147f53e307d80744 100644 (file)
@@ -106,10 +106,10 @@ void Connect::populate_drivers()
                 * @todo Add support for non-monotonic devices i.e. DMMs
                 * and sensors.
                 */
-               bool supported_device = driver->config_check(
-                       ConfigKey::LOGIC_ANALYZER, ConfigKey::DEVICE_OPTIONS) |
-                                       driver->config_check(
-                       ConfigKey::OSCILLOSCOPE, ConfigKey::DEVICE_OPTIONS);
+               const auto keys = driver->config_keys();
+
+               bool supported_device = keys.count(ConfigKey::LOGIC_ANALYZER) |
+                       keys.count(ConfigKey::OSCILLOSCOPE);
 
                if (supported_device)
                        drivers_.addItem(QString("%1 (%2)").arg(
@@ -197,7 +197,7 @@ void Connect::device_selected(int index)
 
        unset_connection();
 
-       if (driver->config_check(ConfigKey::SERIALCOMM, ConfigKey::SCAN_OPTIONS))
+       if (driver->scan_options().count(ConfigKey::SERIALCOMM))
                set_serial_connection(driver);
 }
 
index 30cff789a3436abdd1216f94d25e4abca6668bc1..b437b4d1152618b01d6c8defc04f834617e9daa5 100644 (file)
@@ -269,22 +269,9 @@ void MainBar::update_sample_rate_selector()
 
        const shared_ptr<sigrok::Device> sr_dev = device->device();
 
-       try {
-               keys = sr_dev->config_keys(ConfigKey::DEVICE_OPTIONS);
-       } catch (Error) {}
-
-       const auto iter = keys.find(ConfigKey::SAMPLERATE);
-       if (iter != keys.end() &&
-               (*iter).second.find(sigrok::LIST) != (*iter).second.end()) {
-               try {
-                       gvar_dict = sr_dev->config_list(ConfigKey::SAMPLERATE);
-               } catch (const sigrok::Error &e) {
-                       // Failed to enunmerate samplerate
-                       (void)e;
-               }
-       }
-
-       if (!gvar_dict.gobj()) {
+       if (sr_dev->config_check(ConfigKey::SAMPLERATE, Capability::LIST)) {
+               gvar_dict = sr_dev->config_list(ConfigKey::SAMPLERATE);
+       } else {
                sample_rate_.show_none();
                updating_sample_rate_ = false;
                return;
@@ -379,20 +366,11 @@ void MainBar::update_sample_count_selector()
        if (sample_count == 0)
                sample_count = DefaultSampleCount;
 
-       const auto keys = sr_dev->config_keys(ConfigKey::DEVICE_OPTIONS);
-       const auto iter = keys.find(ConfigKey::LIMIT_SAMPLES);
-       if (iter != keys.end() &&
-               (*iter).second.find(sigrok::LIST) != (*iter).second.end()) {
-               try {
-                       auto gvar =
-                               sr_dev->config_list(ConfigKey::LIMIT_SAMPLES);
-                       if (gvar.gobj())
-                               g_variant_get(gvar.gobj(), "(tt)",
-                                       &min_sample_count, &max_sample_count);
-               } catch (const sigrok::Error &e) {
-                       // Failed to query sample limit
-                       (void)e;
-               }
+       if (sr_dev->config_check(ConfigKey::LIMIT_SAMPLES, Capability::LIST)) {
+               auto gvar = sr_dev->config_list(ConfigKey::LIMIT_SAMPLES);
+               if (gvar.gobj())
+                       g_variant_get(gvar.gobj(), "(tt)",
+                               &min_sample_count, &max_sample_count);
        }
 
        min_sample_count = min(max(min_sample_count, MinSampleCount),
@@ -401,14 +379,14 @@ void MainBar::update_sample_count_selector()
        sample_count_.show_125_list(
                min_sample_count, max_sample_count);
 
-       try {
+       if (sr_dev->config_check(ConfigKey::LIMIT_SAMPLES, Capability::GET)) {
                auto gvar = sr_dev->config_get(ConfigKey::LIMIT_SAMPLES);
                sample_count = g_variant_get_uint64(gvar.gobj());
                if (sample_count == 0)
                        sample_count = DefaultSampleCount;
                sample_count = min(max(sample_count, MinSampleCount),
                        max_sample_count);
-       } catch (Error error) {}
+       }
 
        sample_count_.set_value(sample_count);
 
@@ -449,27 +427,14 @@ void MainBar::update_device_config_widgets()
        // Update supported options.
        sample_count_supported_ = false;
 
-       try {
-               for (auto entry : sr_dev->config_keys(ConfigKey::DEVICE_OPTIONS)) {
-                       auto key = entry.first;
-                       auto capabilities = entry.second;
-                       switch (key->id()) {
-                       case SR_CONF_LIMIT_SAMPLES:
-                               if (capabilities.count(Capability::SET))
-                                       sample_count_supported_ = true;
-                               break;
-                       case SR_CONF_LIMIT_FRAMES:
-                               if (capabilities.count(Capability::SET)) {
-                                       sr_dev->config_set(ConfigKey::LIMIT_FRAMES,
-                                               Glib::Variant<guint64>::create(1));
-                                       on_config_changed();
-                               }
-                               break;
-                       default:
-                               break;
-                       }
-               }
-       } catch (Error error) {}
+       if (sr_dev->config_check(ConfigKey::LIMIT_SAMPLES, Capability::SET))
+               sample_count_supported_ = true;
+
+       if (sr_dev->config_check(ConfigKey::LIMIT_FRAMES, Capability::SET)) {
+               sr_dev->config_set(ConfigKey::LIMIT_FRAMES,
+                       Glib::Variant<guint64>::create(1));
+                       on_config_changed();
+       }
 
        // Add notification of reconfigure events
        disconnect(this, SLOT(on_config_changed()));
index 5d3ac102164375ae9aae4c5b30284ee89853eb8e..78bfdec517667646c35f87c212d5cc4ab5ca2f7d 100644 (file)
@@ -51,6 +51,7 @@ using std::vector;
 
 using sigrok::Channel;
 using sigrok::ConfigKey;
+using sigrok::Capability;
 using sigrok::Error;
 using sigrok::Trigger;
 using sigrok::TriggerStage;
@@ -332,22 +333,14 @@ void LogicSignal::init_trigger_actions(QWidget *parent)
 const vector<int32_t> LogicSignal::get_trigger_types() const
 {
        const auto sr_dev = device_->device();
-       const auto keys = sr_dev->config_keys(ConfigKey::DEVICE_OPTIONS);
-       const auto iter = keys.find(ConfigKey::TRIGGER_MATCH);
-       if (iter != keys.end() &&
-               (*iter).second.find(sigrok::LIST) != (*iter).second.end()) {
-               try {
-                       const Glib::VariantContainerBase gvar =
-                               sr_dev->config_list(ConfigKey::TRIGGER_MATCH);
-                       return Glib::VariantBase::cast_dynamic<
-                               Glib::Variant<vector<int32_t>>>(gvar).get();
-               } catch (Error e) {
-                       // Failed to enumerate triggers
-                       (void)e;
-               }
+       if (sr_dev->config_check(ConfigKey::TRIGGER_MATCH, Capability::LIST)) {
+               const Glib::VariantContainerBase gvar =
+                       sr_dev->config_list(ConfigKey::TRIGGER_MATCH);
+               return Glib::VariantBase::cast_dynamic<
+                       Glib::Variant<vector<int32_t>>>(gvar).get();
+       } else {
+               return vector<int32_t>();
        }
-
-       return vector<int32_t>();
 }
 
 QAction* LogicSignal::action_from_trigger_type(const TriggerMatchType *type)