From: Joel Holdsworth Date: Sun, 9 Feb 2014 15:08:12 +0000 (+0000) Subject: Moved config getting/setting into DevInst X-Git-Tag: pulseview-0.2.0~80 X-Git-Url: https://sigrok.org/gitaction?a=commitdiff_plain;h=8dd4419097191563045396946f0dcff5ac9714b2;p=pulseview.git Moved config getting/setting into DevInst --- diff --git a/pv/devinst.cpp b/pv/devinst.cpp index 4a152e0c..8f57bbd2 100644 --- a/pv/devinst.cpp +++ b/pv/devinst.cpp @@ -21,6 +21,8 @@ #include #include +#include + #include #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 diff --git a/pv/devinst.h b/pv/devinst.h index 64d27583..4b618109 100644 --- a/pv/devinst.h +++ b/pv/devinst.h @@ -25,7 +25,10 @@ #include +#include + 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; }; diff --git a/pv/prop/binding/deviceoptions.cpp b/pv/prop/binding/deviceoptions.cpp index 6da16652..01648692 100644 --- a/pv/prop/binding/deviceoptions.cpp +++ b/pv/prop/binding/deviceoptions.cpp @@ -20,9 +20,6 @@ #include -#include -#include - #include #include "deviceoptions.h" @@ -54,14 +51,11 @@ DeviceOptions::DeviceOptions(shared_ptr 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 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 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( - new Bool(name, bind(config_getter, sdi, _group, key), - bind(config_setter, sdi, _group, key, _1)))); + assert(_dev_inst); + _properties.push_back(shared_ptr(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 > 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( - new Enum(name, values, - bind(config_getter, sdi, _group, key), - bind(config_setter, sdi, _group, key, _1)))); + _properties.push_back(shared_ptr(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 > range) { - sr_dev_inst *const sdi = _dev_inst->dev_inst(); - assert(sdi); + assert(_dev_inst); - _properties.push_back(shared_ptr( - new Int(name, suffix, range, - bind(config_getter, sdi, _group, key), - bind(config_setter, sdi, _group, key, _1)))); + _properties.push_back(shared_ptr(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) diff --git a/pv/prop/binding/deviceoptions.h b/pv/prop/binding/deviceoptions.h index ca27a5b7..8814dc34 100644 --- a/pv/prop/binding/deviceoptions.h +++ b/pv/prop/binding/deviceoptions.h @@ -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, diff --git a/pv/toolbars/samplingbar.cpp b/pv/toolbars/samplingbar.cpp index 59d190d4..35de916b 100644 --- a/pv/toolbars/samplingbar.cpp +++ b/pv/toolbars/samplingbar.cpp @@ -24,8 +24,6 @@ #include -#include - #include #include @@ -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; } diff --git a/pv/view/logicsignal.cpp b/pv/view/logicsignal.cpp index bc6e09fa..8e0ea27d 100644 --- a/pv/view/logicsignal.cpp +++ b/pv/view/logicsignal.cpp @@ -250,11 +250,7 @@ void LogicSignal::populate_popup_form(QWidget *parent, QFormLayout *form) boost::shared_ptr 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);