#include <cassert>
#include <sstream>
+#include <QDebug>
+
#include <libsigrok/libsigrok.h>
#include "devinst.h"
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
#include <boost/shared_ptr.hpp>
+#include <glib.h>
+
struct sr_dev_inst;
+struct sr_probe_group;
namespace pv {
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;
};
#include <boost/bind.hpp>
-#include <QDebug>
-#include <QObject>
-
#include <stdint.h>
#include "deviceoptions.h"
_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;
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);
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,
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)
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,
#include <boost/foreach.hpp>
-#include <libsigrok/libsigrok.h>
-
#include <QAction>
#include <QDebug>
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;
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);
if (!dev_inst)
return;
- const sr_dev_inst *const sdi = dev_inst->dev_inst();
- assert(sdi);
-
_updating_sample_count = true;
if (_sample_count_supported)
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);
_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)
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;
}
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;
}
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
// 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]) {
_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;
}
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);