]> sigrok.org Git - pulseview.git/commitdiff
Moved config getting/setting into DevInst
authorJoel Holdsworth <redacted>
Sun, 9 Feb 2014 15:08:12 +0000 (15:08 +0000)
committerJoel Holdsworth <redacted>
Sun, 9 Feb 2014 19:22:17 +0000 (19:22 +0000)
pv/devinst.cpp
pv/devinst.h
pv/prop/binding/deviceoptions.cpp
pv/prop/binding/deviceoptions.h
pv/toolbars/samplingbar.cpp
pv/view/logicsignal.cpp

index 4a152e0c6b6d119d53d7608db2817157403eff73..8f57bbd2cf2a310778fade65a5b896098108f1dc 100644 (file)
@@ -21,6 +21,8 @@
 #include <cassert>
 #include <sstream>
 
+#include <QDebug>
+
 #include <libsigrok/libsigrok.h>
 
 #include "devinst.h"
@@ -66,4 +68,25 @@ string DevInst::format_device_title() const
        return s.str();
 }
 
+GVariant* DevInst::get_config(const sr_probe_group *group, int key)
+{
+       GVariant *data = NULL;
+       if (sr_config_get(_sdi->driver, _sdi, group, key, &data) != SR_OK)
+               return NULL;
+       return data;
+}
+
+bool DevInst::set_config(const sr_probe_group *group, int key, GVariant *data)
+{
+       return sr_config_set(_sdi, group, key, data) == SR_OK;
+}
+
+GVariant* DevInst::list_config(const sr_probe_group *group, int key)
+{
+       GVariant *data = NULL;
+       if (sr_config_list(_sdi->driver, _sdi, group, key, &data) != SR_OK)
+               return NULL;
+       return data;
+}
+
 } // pv
index 64d27583b24e08e8226bb14121dddb0454805ceb..4b61810933bf5c6a1ab2b571a8032093bc09b2ec 100644 (file)
 
 #include <boost/shared_ptr.hpp>
 
+#include <glib.h>
+
 struct sr_dev_inst;
+struct sr_probe_group;
 
 namespace pv {
 
@@ -38,6 +41,12 @@ public:
 
        std::string format_device_title() const;
 
+       GVariant* get_config(const sr_probe_group *group, int key);
+
+       bool set_config(const sr_probe_group *group, int key, GVariant *data);
+
+       GVariant* list_config(const sr_probe_group *group, int key);
+
 private:
        sr_dev_inst *const _sdi;
 };
index 6da16652f2cc0dca814491b46c30e384fa29bc30..016486922d86a95dcc1282684d2695d3f828c585 100644 (file)
@@ -20,9 +20,6 @@
 
 #include <boost/bind.hpp>
 
-#include <QDebug>
-#include <QObject>
-
 #include <stdint.h>
 
 #include "deviceoptions.h"
@@ -54,14 +51,11 @@ DeviceOptions::DeviceOptions(shared_ptr<pv::DevInst> dev_inst,
        _group(group)
 {
        assert(dev_inst);
-       sr_dev_inst *const sdi = dev_inst->dev_inst();
-       assert(sdi);
 
-       GVariant *gvar_opts, *gvar_list;
+       GVariant *gvar_opts;
        gsize num_opts;
 
-       if ((sr_config_list(sdi->driver, sdi, group, SR_CONF_DEVICE_OPTIONS,
-               &gvar_opts) != SR_OK))
+       if (!(gvar_opts = dev_inst->list_config(group, SR_CONF_DEVICE_OPTIONS)))
                /* Driver supports no device instance options. */
                return;
 
@@ -75,10 +69,7 @@ DeviceOptions::DeviceOptions(shared_ptr<pv::DevInst> dev_inst,
                        continue;
 
                const int key = info->key;
-
-               if (sr_config_list(sdi->driver, sdi, group,
-                       key, &gvar_list) != SR_OK)
-                       gvar_list = NULL;
+               GVariant *const gvar_list = dev_inst->list_config(group, key);
 
                const QString name = QString::fromUtf8(info->name);
 
@@ -127,34 +118,12 @@ DeviceOptions::DeviceOptions(shared_ptr<pv::DevInst> dev_inst,
        g_variant_unref(gvar_opts);
 }
 
-GVariant* DeviceOptions::config_getter(
-       const sr_dev_inst *sdi, const sr_probe_group *group, int key)
-{
-       GVariant *data = NULL;
-       if (sr_config_get(sdi->driver, sdi, group, key, &data) != SR_OK) {
-               qDebug() <<
-                       "WARNING: Failed to get value of config id" << key;
-               return NULL;
-       }
-       return data;
-}
-
-void DeviceOptions::config_setter(
-       const struct sr_dev_inst *sdi, const sr_probe_group *group, int key,
-       GVariant* value)
-{
-       if (sr_config_set(sdi, group, key, value) != SR_OK)
-               qDebug() << "WARNING: Failed to set value of sample rate";
-}
-
 void DeviceOptions::bind_bool(const QString &name, int key)
 {
-       sr_dev_inst *const sdi = _dev_inst->dev_inst();
-       assert(sdi);
-
-       _properties.push_back(shared_ptr<Property>(
-               new Bool(name, bind(config_getter, sdi, _group, key),
-                       bind(config_setter, sdi, _group, key, _1))));
+       assert(_dev_inst);
+       _properties.push_back(shared_ptr<Property>(new Bool(name,
+               bind(&DevInst::get_config, _dev_inst, _group, key),
+               bind(&DevInst::set_config, _dev_inst, _group, key, _1))));
 }
 
 void DeviceOptions::bind_enum(const QString &name, int key,
@@ -164,31 +133,26 @@ void DeviceOptions::bind_enum(const QString &name, int key,
        GVariantIter iter;
        vector< pair<GVariant*, QString> > values;
 
+       assert(_dev_inst);
        assert(gvar_list);
 
-       sr_dev_inst *const sdi = _dev_inst->dev_inst();
-       assert(sdi);
-
        g_variant_iter_init (&iter, gvar_list);
        while ((gvar = g_variant_iter_next_value (&iter)))
                values.push_back(make_pair(gvar, printer(gvar)));
 
-       _properties.push_back(shared_ptr<Property>(
-               new Enum(name, values,
-                       bind(config_getter, sdi, _group, key),
-                       bind(config_setter, sdi, _group, key, _1))));
+       _properties.push_back(shared_ptr<Property>(new Enum(name, values,
+               bind(&DevInst::get_config, _dev_inst, _group, key),
+               bind(&DevInst::set_config, _dev_inst, _group, key, _1))));
 }
 
 void DeviceOptions::bind_int(const QString &name, int key, QString suffix,
        optional< std::pair<int64_t, int64_t> > range)
 {
-       sr_dev_inst *const sdi = _dev_inst->dev_inst();
-       assert(sdi);
+       assert(_dev_inst);
 
-       _properties.push_back(shared_ptr<Property>(
-               new Int(name, suffix, range,
-                       bind(config_getter, sdi, _group, key),
-                       bind(config_setter, sdi, _group, key, _1))));
+       _properties.push_back(shared_ptr<Property>(new Int(name, suffix, range,
+               bind(&DevInst::get_config, _dev_inst, _group, key),
+               bind(&DevInst::set_config, _dev_inst, _group, key, _1))));
 }
 
 QString DeviceOptions::print_gvariant(GVariant *const gvar)
index ca27a5b7fc69590654316bf08645eb4cf638d1e1..8814dc344015dbf748d27b746e29bb3a435a3919 100644 (file)
@@ -47,13 +47,6 @@ public:
                const sr_probe_group *group = NULL);
 
 private:
-
-       static GVariant* config_getter(
-               const sr_dev_inst *sdi, const sr_probe_group *group, int key);
-       static void config_setter(
-               const sr_dev_inst *sdi, const sr_probe_group *group, int key,
-               GVariant* value);
-
        void bind_bool(const QString &name, int key);
        void bind_enum(const QString &name, int key,
                GVariant *const gvar_list,
index 59d190d427792db64221feb338d166257dfbe2ec..35de916b6ef76465535f9852c65a4dc88437960c 100644 (file)
@@ -24,8 +24,6 @@
 
 #include <boost/foreach.hpp>
 
-#include <libsigrok/libsigrok.h>
-
 #include <QAction>
 #include <QDebug>
 
@@ -170,13 +168,9 @@ void SamplingBar::update_sample_rate_selector()
        if (!dev_inst)
                return;
 
-       const sr_dev_inst *const sdi = dev_inst->dev_inst();
-       assert(sdi);
-
        _updating_sample_rate = true;
 
-       if (sr_config_list(sdi->driver, sdi, NULL,
-                       SR_CONF_SAMPLERATE, &gvar_dict) != SR_OK)
+       if (!(gvar_dict = dev_inst->list_config(NULL, SR_CONF_SAMPLERATE)))
        {
                _sample_rate.show_none();
                _updating_sample_rate = false;
@@ -234,13 +228,8 @@ void SamplingBar::update_sample_rate_selector_value()
        if (!dev_inst)
                return;
 
-       const sr_dev_inst *const sdi = dev_inst->dev_inst();
-       assert(sdi);
-
-       if (sr_config_get(sdi->driver, sdi, NULL,
-               SR_CONF_SAMPLERATE, &gvar) != SR_OK) {
-               qDebug() <<
-                               "WARNING: Failed to get value of sample rate";
+       if (!(gvar = dev_inst->get_config(NULL, SR_CONF_SAMPLERATE))) {
+               qDebug() << "WARNING: Failed to get value of sample rate";
                return;
        }
        samplerate = g_variant_get_uint64(gvar);
@@ -259,9 +248,6 @@ void SamplingBar::update_sample_count_selector()
        if (!dev_inst)
                return;
 
-       const sr_dev_inst *const sdi = dev_inst->dev_inst();
-       assert(sdi);
-
        _updating_sample_count = true;
 
        if (_sample_count_supported)
@@ -270,8 +256,8 @@ void SamplingBar::update_sample_count_selector()
                uint64_t min_sample_count = 0;
                uint64_t max_sample_count = MaxSampleCount;
 
-               if (sr_config_list(sdi->driver, sdi, NULL,
-                       SR_CONF_LIMIT_SAMPLES, &gvar) == SR_OK) {
+               if ((gvar = dev_inst->list_config(NULL, SR_CONF_LIMIT_SAMPLES)))
+               {
                        g_variant_get(gvar, "(tt)",
                                &min_sample_count, &max_sample_count);
                        g_variant_unref(gvar);
@@ -283,8 +269,7 @@ void SamplingBar::update_sample_count_selector()
                _sample_count.show_125_list(
                        min_sample_count, max_sample_count);
 
-               if (sr_config_get(sdi->driver, sdi, NULL,
-                       SR_CONF_LIMIT_SAMPLES, &gvar) == SR_OK)
+               if ((gvar = dev_inst->get_config(NULL, SR_CONF_LIMIT_SAMPLES)))
                {
                        sample_count = g_variant_get_uint64(gvar);
                        if (sample_count == 0)
@@ -311,14 +296,11 @@ void SamplingBar::commit_sample_count()
        if (!dev_inst)
                return;
 
-       const sr_dev_inst *const sdi = dev_inst->dev_inst();
-       assert(sdi);
-
        sample_count = _sample_count.value();
 
        // Set the sample count
-       if (sr_config_set(sdi, NULL, SR_CONF_LIMIT_SAMPLES,
-               g_variant_new_uint64(sample_count)) != SR_OK) {
+       if (!dev_inst->set_config(NULL, SR_CONF_LIMIT_SAMPLES,
+               g_variant_new_uint64(sample_count))) {
                qDebug() << "Failed to configure sample count.";
                return;
        }
@@ -332,16 +314,13 @@ void SamplingBar::commit_sample_rate()
        if (!dev_inst)
                return;
 
-       const sr_dev_inst *const sdi = dev_inst->dev_inst();
-       assert(sdi);
-
        sample_rate = _sample_rate.value();
        if (sample_rate == 0)
                return;
 
        // Set the samplerate
-       if (sr_config_set(sdi, NULL, SR_CONF_SAMPLERATE,
-               g_variant_new_uint64(sample_rate)) != SR_OK) {
+       if (!dev_inst->set_config(NULL, SR_CONF_SAMPLERATE,
+               g_variant_new_uint64(sample_rate))) {
                qDebug() << "Failed to configure samplerate.";
                return;
        }
@@ -360,9 +339,6 @@ void SamplingBar::on_device_selected()
        if (!dev_inst)
                return;
 
-       const sr_dev_inst *const sdi = dev_inst->dev_inst();
-       assert(sdi);
-
        _session.set_device(dev_inst);
 
        // Update the configure popup
@@ -378,12 +354,12 @@ void SamplingBar::on_device_selected()
        // Update supported options.
        _sample_count_supported = false;
 
-       if (sr_config_list(sdi->driver, sdi, NULL,
-               SR_CONF_DEVICE_OPTIONS, &gvar) == SR_OK)
+       if ((gvar = dev_inst->list_config(NULL, SR_CONF_DEVICE_OPTIONS)))
        {
                gsize num_opts;
-               const int *const options = (const int32_t *)g_variant_get_fixed_array(
-               gvar, &num_opts, sizeof(int32_t));
+               const int *const options =
+                       (const int32_t *)g_variant_get_fixed_array(
+                               gvar, &num_opts, sizeof(int32_t));
                for (unsigned int i = 0; i < num_opts; i++)
                {
                        switch (options[i]) {
@@ -391,7 +367,7 @@ void SamplingBar::on_device_selected()
                                _sample_count_supported = true;
                                break;
                        case SR_CONF_LIMIT_FRAMES:
-                               sr_config_set(sdi, NULL, SR_CONF_LIMIT_FRAMES,
+                               dev_inst->set_config(NULL, SR_CONF_LIMIT_FRAMES,
                                        g_variant_new_uint64(1));
                                break;
                        }
index bc6e09fa2aaf9e63adad840686ec7d3cdd634e98..8e0ea27d43f775c687cab6a2b09ad7ee0e1b0b80 100644 (file)
@@ -250,11 +250,7 @@ void LogicSignal::populate_popup_form(QWidget *parent, QFormLayout *form)
        boost::shared_ptr<DevInst> dev_inst = _session.get_device();
        assert(dev_inst);
 
-       const sr_dev_inst *const sdi = dev_inst->dev_inst();
-       assert(sdi);
-
-       if (sr_config_list(sdi->driver, sdi, NULL, SR_CONF_TRIGGER_TYPE,
-               &gvar) == SR_OK)
+       if (!(gvar = dev_inst->list_config(NULL, SR_CONF_TRIGGER_TYPE)))
        {
                const char *const trig_types =
                        g_variant_get_string(gvar, NULL);