drivers: Add and use STD_CONFIG_LIST().

This ensures consistent handling of the SR_CONF_SCAN_OPTIONS and
SR_CONF_DEVICE_OPTIONS (with sdi NULL or non-NULL) config keys
and also reduces copy-pasted boilerplate in the drivers a bit.

This function does not handle channel-group specific items, that's
very driver-specific and thus left to the individual drivers.

Also move some generic checks and error messages from the drivers into
the sr_config_list() wrapper.
This commit is contained in:
Uwe Hermann 2017-07-13 21:14:04 +02:00
parent 13d2ac54f4
commit e66d1892d0
62 changed files with 273 additions and 1080 deletions

View File

@ -266,26 +266,10 @@ static int config_list(uint32_t key, GVariant **data, const struct sr_dev_inst *
GVariant *gvar;
GVariantBuilder gvb;
if (key == SR_CONF_SCAN_OPTIONS) {
*data = g_variant_new_fixed_array(G_VARIANT_TYPE_UINT32,
scanopts, ARRAY_SIZE(scanopts), sizeof(uint32_t));
return SR_OK;
}
if (key == SR_CONF_DEVICE_OPTIONS && !sdi) {
*data = g_variant_new_fixed_array(G_VARIANT_TYPE_UINT32,
drvopts, ARRAY_SIZE(drvopts), sizeof(uint32_t));
return SR_OK;
}
if (!sdi || cg)
return SR_ERR_ARG;
switch (key) {
case SR_CONF_SCAN_OPTIONS:
case SR_CONF_DEVICE_OPTIONS:
*data = g_variant_new_fixed_array(G_VARIANT_TYPE_UINT32,
devopts, ARRAY_SIZE(devopts), sizeof(uint32_t));
break;
return STD_CONFIG_LIST(key, data, sdi, cg, scanopts, drvopts, devopts);
case SR_CONF_SAMPLERATE:
g_variant_builder_init(&gvb, G_VARIANT_TYPE("a{sv}"));
gvar = g_variant_new_fixed_array(G_VARIANT_TYPE("t"), samplerates,

View File

@ -166,21 +166,10 @@ static int config_set(uint32_t key, GVariant *data, const struct sr_dev_inst *sd
static int config_list(uint32_t key, GVariant **data, const struct sr_dev_inst *sdi,
const struct sr_channel_group *cg)
{
(void)cg;
switch (key) {
case SR_CONF_SCAN_OPTIONS:
*data = g_variant_new_fixed_array(G_VARIANT_TYPE_UINT32,
scanopts, ARRAY_SIZE(scanopts), sizeof(uint32_t));
break;
case SR_CONF_DEVICE_OPTIONS:
if (!sdi)
*data = g_variant_new_fixed_array(G_VARIANT_TYPE_UINT32,
drvopts, ARRAY_SIZE(drvopts), sizeof(uint32_t));
else
*data = g_variant_new_fixed_array(G_VARIANT_TYPE_UINT32,
devopts, ARRAY_SIZE(devopts), sizeof(uint32_t));
break;
return STD_CONFIG_LIST(key, data, sdi, cg, scanopts, drvopts, devopts);
case SR_CONF_DATA_SOURCE:
*data = g_variant_new_strv(data_sources, ARRAY_SIZE(data_sources));
break;

View File

@ -152,32 +152,9 @@ static int config_list(uint32_t key, GVariant **data,
{
GVariantBuilder gvb;
/* Always available. */
if (key == SR_CONF_SCAN_OPTIONS) {
*data = g_variant_new_fixed_array(G_VARIANT_TYPE_UINT32,
scanopts, ARRAY_SIZE(scanopts), sizeof(uint32_t));
return SR_OK;
}
if (key == SR_CONF_DEVICE_OPTIONS && !sdi) {
*data = g_variant_new_fixed_array(G_VARIANT_TYPE_UINT32,
drvopts, ARRAY_SIZE(drvopts), sizeof(uint32_t));
return SR_OK;
}
if (!sdi)
return SR_ERR_ARG;
if (!cg) {
/* No channel group: global options. */
switch (key) {
case SR_CONF_DEVICE_OPTIONS:
*data = g_variant_new_fixed_array(G_VARIANT_TYPE_UINT32,
devopts, ARRAY_SIZE(devopts), sizeof(uint32_t));
break;
default:
return SR_ERR_NA;
}
return STD_CONFIG_LIST(key, data, sdi, cg, scanopts, drvopts, devopts);
} else {
switch (key) {
case SR_CONF_DEVICE_OPTIONS:

View File

@ -246,17 +246,9 @@ static int config_list(uint32_t key, GVariant **data, const struct sr_dev_inst *
GVariant *gvar;
GVariantBuilder gvb;
(void)cg;
switch (key) {
case SR_CONF_DEVICE_OPTIONS:
if (!sdi)
*data = g_variant_new_fixed_array(G_VARIANT_TYPE_UINT32,
drvopts, ARRAY_SIZE(drvopts), sizeof(uint32_t));
else
*data = g_variant_new_fixed_array(G_VARIANT_TYPE_UINT32,
devopts, ARRAY_SIZE(devopts), sizeof(uint32_t));
break;
return STD_CONFIG_LIST(key, data, sdi, cg, NULL, drvopts, devopts);
case SR_CONF_SAMPLERATE:
g_variant_builder_init(&gvb, G_VARIANT_TYPE("a{sv}"));
gvar = g_variant_new_fixed_array(G_VARIANT_TYPE("t"), samplerates,

View File

@ -339,31 +339,14 @@ static int config_list(uint32_t key, GVariant **data, const struct sr_dev_inst *
GVariantBuilder gvb;
int channel, i;
/* Always available. */
if (key == SR_CONF_SCAN_OPTIONS) {
*data = g_variant_new_fixed_array(G_VARIANT_TYPE_UINT32,
scanopts, ARRAY_SIZE(scanopts), sizeof(uint32_t));
return SR_OK;
}
if (key == SR_CONF_DEVICE_OPTIONS && !sdi) {
*data = g_variant_new_fixed_array(G_VARIANT_TYPE_UINT32,
drvopts, ARRAY_SIZE(drvopts), sizeof(uint32_t));
return SR_OK;
}
if (!sdi)
return SR_ERR_ARG;
devc = sdi->priv;
devc = (sdi) ? sdi->priv : NULL;
if (!cg) {
/* No channel group: global options. */
switch (key) {
case SR_CONF_SCAN_OPTIONS:
case SR_CONF_DEVICE_OPTIONS:
*data = g_variant_new_fixed_array(G_VARIANT_TYPE_UINT32,
devopts, ARRAY_SIZE(devopts), sizeof(uint32_t));
break;
return STD_CONFIG_LIST(key, data, sdi, cg, scanopts, drvopts, devopts);
case SR_CONF_CHANNEL_CONFIG:
if (devc->model->channel_modes == CHANMODE_INDEPENDENT) {
/* The 1-channel models. */
@ -378,8 +361,7 @@ static int config_list(uint32_t key, GVariant **data, const struct sr_dev_inst *
}
} else {
/* Channel group specified: per-channel options. */
if (!sdi)
return SR_ERR_ARG;
/* We only ever have one channel per channel group in this driver. */
ch = cg->channels->data;
channel = ch->index;

View File

@ -219,15 +219,10 @@ static int config_list(uint32_t key, GVariant **data,
GVariantBuilder gvb;
int num_devopts_cg = 0;
(void)sdi;
(void)cg;
if (!cg) {
switch (key) {
case SR_CONF_DEVICE_OPTIONS:
*data = g_variant_new_fixed_array(G_VARIANT_TYPE_UINT32,
devopts, ARRAY_SIZE(devopts), sizeof(uint32_t));
break;
return STD_CONFIG_LIST(key, data, sdi, cg, NULL, NULL, devopts);
case SR_CONF_SAMPLERATE:
g_variant_builder_init(&gvb, G_VARIANT_TYPE("a{sv}"));
gvar = g_variant_new_fixed_array(G_VARIANT_TYPE("t"),

View File

@ -245,18 +245,10 @@ static int config_list(uint32_t key, GVariant **data, const struct sr_dev_inst *
GVariant *gvar;
GVariantBuilder gvb;
(void)sdi;
(void)cg;
switch (key) {
case SR_CONF_SCAN_OPTIONS:
*data = g_variant_new_fixed_array(G_VARIANT_TYPE_UINT32,
scanopts, ARRAY_SIZE(scanopts), sizeof(uint32_t));
break;
case SR_CONF_DEVICE_OPTIONS:
*data = g_variant_new_fixed_array(G_VARIANT_TYPE_UINT32,
devopts, ARRAY_SIZE(devopts), sizeof(uint32_t));
break;
return STD_CONFIG_LIST(key, data, sdi, cg, scanopts, NULL, devopts);
case SR_CONF_SAMPLERATE:
g_variant_builder_init(&gvb, G_VARIANT_TYPE("a{sv}"));
gvar = g_variant_new_fixed_array(G_VARIANT_TYPE("t"),

View File

@ -169,23 +169,7 @@ static int config_set(uint32_t key, GVariant *data, const struct sr_dev_inst *sd
static int config_list(uint32_t key, GVariant **data, const struct sr_dev_inst *sdi,
const struct sr_channel_group *cg)
{
(void)sdi;
(void)cg;
switch (key) {
case SR_CONF_SCAN_OPTIONS:
*data = g_variant_new_fixed_array(G_VARIANT_TYPE_UINT32,
scanopts, ARRAY_SIZE(scanopts), sizeof(uint32_t));
break;
case SR_CONF_DEVICE_OPTIONS:
*data = g_variant_new_fixed_array(G_VARIANT_TYPE_UINT32,
devopts, ARRAY_SIZE(devopts), sizeof(uint32_t));
break;
default:
return SR_ERR_NA;
}
return SR_OK;
return STD_CONFIG_LIST(key, data, sdi, cg, scanopts, NULL, devopts);
}
static int dev_acquisition_start(const struct sr_dev_inst *sdi)

View File

@ -133,23 +133,7 @@ static int config_set(uint32_t key, GVariant *data, const struct sr_dev_inst *sd
static int config_list(uint32_t key, GVariant **data, const struct sr_dev_inst *sdi,
const struct sr_channel_group *cg)
{
(void)sdi;
(void)cg;
switch (key) {
case SR_CONF_SCAN_OPTIONS:
*data = g_variant_new_fixed_array(G_VARIANT_TYPE_UINT32,
scanopts, ARRAY_SIZE(scanopts), sizeof(uint32_t));
break;
case SR_CONF_DEVICE_OPTIONS:
*data = g_variant_new_fixed_array(G_VARIANT_TYPE_UINT32,
devopts, ARRAY_SIZE(devopts), sizeof(uint32_t));
break;
default:
return SR_ERR_NA;
}
return SR_OK;
return STD_CONFIG_LIST(key, data, sdi, cg, scanopts, NULL, devopts);
}
static int dev_acquisition_start(const struct sr_dev_inst *sdi)

View File

@ -288,49 +288,31 @@ static int config_list(uint32_t key, GVariant **data, const struct sr_dev_inst *
GVariantBuilder gvb;
unsigned int i;
(void)cg;
if (!sdi) {
switch (key) {
case SR_CONF_SCAN_OPTIONS:
*data = g_variant_new_fixed_array(G_VARIANT_TYPE_UINT32,
scanopts, ARRAY_SIZE(scanopts), sizeof(uint32_t));
break;
case SR_CONF_DEVICE_OPTIONS:
*data = g_variant_new_fixed_array(G_VARIANT_TYPE_UINT32,
drvopts, ARRAY_SIZE(drvopts), sizeof(uint32_t));
break;
default:
return SR_ERR_NA;
}
} else {
switch (key) {
case SR_CONF_DEVICE_OPTIONS:
*data = g_variant_new_fixed_array(G_VARIANT_TYPE_UINT32,
devopts, ARRAY_SIZE(devopts), sizeof(uint32_t));
break;
case SR_CONF_SPL_WEIGHT_FREQ:
*data = g_variant_new_strv(weight_freq, ARRAY_SIZE(weight_freq));
break;
case SR_CONF_SPL_WEIGHT_TIME:
*data = g_variant_new_strv(weight_time, ARRAY_SIZE(weight_time));
break;
case SR_CONF_SPL_MEASUREMENT_RANGE:
g_variant_builder_init(&gvb, G_VARIANT_TYPE_ARRAY);
for (i = 0; i < ARRAY_SIZE(meas_ranges); i++) {
range[0] = g_variant_new_uint64(meas_ranges[i][0]);
range[1] = g_variant_new_uint64(meas_ranges[i][1]);
tuple = g_variant_new_tuple(range, 2);
g_variant_builder_add_value(&gvb, tuple);
}
*data = g_variant_builder_end(&gvb);
break;
case SR_CONF_DATA_SOURCE:
*data = g_variant_new_strv(data_sources, ARRAY_SIZE(data_sources));
break;
default:
return SR_ERR_NA;
switch (key) {
case SR_CONF_SCAN_OPTIONS:
case SR_CONF_DEVICE_OPTIONS:
return STD_CONFIG_LIST(key, data, sdi, cg, scanopts, drvopts, devopts);
case SR_CONF_SPL_WEIGHT_FREQ:
*data = g_variant_new_strv(weight_freq, ARRAY_SIZE(weight_freq));
break;
case SR_CONF_SPL_WEIGHT_TIME:
*data = g_variant_new_strv(weight_time, ARRAY_SIZE(weight_time));
break;
case SR_CONF_SPL_MEASUREMENT_RANGE:
g_variant_builder_init(&gvb, G_VARIANT_TYPE_ARRAY);
for (i = 0; i < ARRAY_SIZE(meas_ranges); i++) {
range[0] = g_variant_new_uint64(meas_ranges[i][0]);
range[1] = g_variant_new_uint64(meas_ranges[i][1]);
tuple = g_variant_new_tuple(range, 2);
g_variant_builder_add_value(&gvb, tuple);
}
*data = g_variant_builder_end(&gvb);
break;
case SR_CONF_DATA_SOURCE:
*data = g_variant_new_strv(data_sources, ARRAY_SIZE(data_sources));
break;
default:
return SR_ERR_NA;
}
return SR_OK;

View File

@ -135,26 +135,7 @@ static int config_set(uint32_t key, GVariant *data, const struct sr_dev_inst *sd
static int config_list(uint32_t key, GVariant **data, const struct sr_dev_inst *sdi,
const struct sr_channel_group *cg)
{
(void)cg;
switch (key) {
case SR_CONF_SCAN_OPTIONS:
*data = g_variant_new_fixed_array(G_VARIANT_TYPE_UINT32,
scanopts, ARRAY_SIZE(scanopts), sizeof(uint32_t));
break;
case SR_CONF_DEVICE_OPTIONS:
if (!sdi)
*data = g_variant_new_fixed_array(G_VARIANT_TYPE_UINT32,
drvopts, ARRAY_SIZE(drvopts), sizeof(uint32_t));
else
*data = g_variant_new_fixed_array(G_VARIANT_TYPE_UINT32,
devopts, ARRAY_SIZE(devopts), sizeof(uint32_t));
break;
default:
return SR_ERR_NA;
}
return SR_OK;
return STD_CONFIG_LIST(key, data, sdi, cg, scanopts, drvopts, devopts);
}
static int dev_acquisition_start(const struct sr_dev_inst *sdi, int idx)

View File

@ -357,25 +357,13 @@ static int config_list(uint32_t key, GVariant **data, const struct sr_dev_inst *
GVariantBuilder gvb;
struct dev_context *devc;
(void)cg;
devc = (sdi) ? sdi->priv : NULL;
switch (key) {
case SR_CONF_SCAN_OPTIONS:
*data = g_variant_new_fixed_array(G_VARIANT_TYPE_UINT32,
scanopts, ARRAY_SIZE(scanopts), sizeof(uint32_t));
break;
case SR_CONF_DEVICE_OPTIONS:
if (!sdi)
*data = g_variant_new_fixed_array(G_VARIANT_TYPE_UINT32,
drvopts, ARRAY_SIZE(drvopts), sizeof(uint32_t));
else
*data = g_variant_new_fixed_array(G_VARIANT_TYPE_UINT32,
devopts, ARRAY_SIZE(devopts), sizeof(uint32_t));
break;
return STD_CONFIG_LIST(key, data, sdi, cg, scanopts, drvopts, devopts);
case SR_CONF_SAMPLERATE:
if (!sdi)
return SR_ERR_BUG;
devc = sdi->priv;
cv_fill_samplerates_if_needed(sdi);
g_variant_builder_init(&gvb, G_VARIANT_TYPE("a{sv}"));
gvar = g_variant_new_fixed_array(G_VARIANT_TYPE("t"),
@ -386,7 +374,7 @@ static int config_list(uint32_t key, GVariant **data, const struct sr_dev_inst *
*data = g_variant_builder_end(&gvb);
break;
case SR_CONF_LIMIT_SAMPLES:
if (!sdi || !sdi->priv || !(devc = sdi->priv) || !devc->prof)
if (!devc->prof)
return SR_ERR_BUG;
grange[0] = g_variant_new_uint64(0);
if (devc->prof->model == CHRONOVU_LA8)
@ -396,7 +384,7 @@ static int config_list(uint32_t key, GVariant **data, const struct sr_dev_inst *
*data = g_variant_new_tuple(grange, 2);
break;
case SR_CONF_TRIGGER_MATCH:
if (!sdi || !sdi->priv || !(devc = sdi->priv) || !devc->prof)
if (!devc->prof)
return SR_ERR_BUG;
*data = g_variant_new_fixed_array(G_VARIANT_TYPE_INT32,
trigger_matches, devc->prof->num_trigger_matches,

View File

@ -96,23 +96,7 @@ static int config_set(uint32_t key, GVariant *data, const struct sr_dev_inst *sd
static int config_list(uint32_t key, GVariant **data, const struct sr_dev_inst *sdi,
const struct sr_channel_group *cg)
{
(void)sdi;
(void)cg;
switch (key) {
case SR_CONF_SCAN_OPTIONS:
*data = g_variant_new_fixed_array(G_VARIANT_TYPE_UINT32,
scanopts, ARRAY_SIZE(scanopts), sizeof(uint32_t));
break;
case SR_CONF_DEVICE_OPTIONS:
*data = g_variant_new_fixed_array(G_VARIANT_TYPE_UINT32,
devopts, ARRAY_SIZE(devopts), sizeof(uint32_t));
break;
default:
return SR_ERR_NA;
}
return SR_OK;
return STD_CONFIG_LIST(key, data, sdi, cg, scanopts, NULL, devopts);
}
static int dev_acquisition_start(const struct sr_dev_inst *sdi)

View File

@ -136,23 +136,7 @@ static int config_set(uint32_t key, GVariant *data, const struct sr_dev_inst *sd
static int config_list(uint32_t key, GVariant **data, const struct sr_dev_inst *sdi,
const struct sr_channel_group *cg)
{
(void)sdi;
(void)cg;
switch (key) {
case SR_CONF_SCAN_OPTIONS:
*data = g_variant_new_fixed_array(G_VARIANT_TYPE_UINT32,
scanopts, ARRAY_SIZE(scanopts), sizeof(uint32_t));
break;
case SR_CONF_DEVICE_OPTIONS:
*data = g_variant_new_fixed_array(G_VARIANT_TYPE_UINT32,
devopts, ARRAY_SIZE(devopts), sizeof(uint32_t));
break;
default:
return SR_ERR_NA;
}
return SR_OK;
return STD_CONFIG_LIST(key, data, sdi, cg, scanopts, NULL, devopts);
}
static struct sr_dev_driver conrad_digi_35_cpu_driver_info = {

View File

@ -358,27 +358,11 @@ static int config_list(uint32_t key, GVariant **data, const struct sr_dev_inst *
GVariant *gvar;
GVariantBuilder gvb;
if (key == SR_CONF_SCAN_OPTIONS) {
*data = g_variant_new_fixed_array(G_VARIANT_TYPE_UINT32,
scanopts, ARRAY_SIZE(scanopts), sizeof(uint32_t));
return SR_OK;
}
if (key == SR_CONF_DEVICE_OPTIONS && !sdi) {
*data = g_variant_new_fixed_array(G_VARIANT_TYPE_UINT32,
drvopts, ARRAY_SIZE(drvopts), sizeof(uint32_t));
return SR_OK;
}
if (!sdi)
return SR_ERR_ARG;
if (!cg) {
switch (key) {
case SR_CONF_SCAN_OPTIONS:
case SR_CONF_DEVICE_OPTIONS:
*data = g_variant_new_fixed_array(G_VARIANT_TYPE_UINT32,
devopts, ARRAY_SIZE(devopts), sizeof(uint32_t));
break;
return STD_CONFIG_LIST(key, data, sdi, cg, scanopts, drvopts, devopts);
case SR_CONF_SAMPLERATE:
g_variant_builder_init(&gvb, G_VARIANT_TYPE("a{sv}"));
gvar = g_variant_new_fixed_array(G_VARIANT_TYPE("t"), samplerates,

View File

@ -553,34 +553,21 @@ static int config_set(uint32_t key, GVariant *data,
static int config_list(uint32_t key, GVariant **data,
const struct sr_dev_inst *sdi, const struct sr_channel_group *cg)
{
struct dev_context *devc = NULL;
struct dev_context *devc;
GVariant *gvar, *range[2];
GVariantBuilder gvb;
unsigned int i;
double v;
(void)cg;
devc = (sdi) ? sdi->priv : NULL;
switch (key) {
case SR_CONF_SCAN_OPTIONS:
*data = g_variant_new_fixed_array(G_VARIANT_TYPE_UINT32,
scanopts, ARRAY_SIZE(scanopts), sizeof(uint32_t));
break;
case SR_CONF_DEVICE_OPTIONS:
if (!sdi) {
*data = g_variant_new_fixed_array(G_VARIANT_TYPE_UINT32,
drvopts, ARRAY_SIZE(drvopts), sizeof(uint32_t));
} else {
devc = sdi->priv;
*data = g_variant_new_fixed_array(G_VARIANT_TYPE_UINT32,
devopts, ARRAY_SIZE(devopts), sizeof(uint32_t));
}
break;
return STD_CONFIG_LIST(key, data, sdi, cg, scanopts, drvopts, devopts);
case SR_CONF_VOLTAGE_THRESHOLD:
if (sdi->priv)
devc = sdi->priv;
g_variant_builder_init(&gvb, G_VARIANT_TYPE_ARRAY);
if (devc && !strcmp(devc->profile->model, "DSLogic")) {
if (!strcmp(devc->profile->model, "DSLogic")) {
for (i = 0; i < ARRAY_SIZE(voltage_thresholds); i++) {
range[0] = g_variant_new_double(voltage_thresholds[i].low);
range[1] = g_variant_new_double(voltage_thresholds[i].high);
@ -598,7 +585,6 @@ static int config_list(uint32_t key, GVariant **data,
*data = g_variant_builder_end(&gvb);
break;
case SR_CONF_SAMPLERATE:
devc = sdi->priv;
g_variant_builder_init(&gvb, G_VARIANT_TYPE("a{sv}"));
gvar = g_variant_new_fixed_array(G_VARIANT_TYPE("t"), devc->samplerates,
devc->num_samplerates, sizeof(uint64_t));

View File

@ -194,23 +194,7 @@ static int config_set(uint32_t key, GVariant *data, const struct sr_dev_inst *sd
static int config_list(uint32_t key, GVariant **data, const struct sr_dev_inst *sdi,
const struct sr_channel_group *cg)
{
(void)sdi;
(void)cg;
switch (key) {
case SR_CONF_SCAN_OPTIONS:
*data = g_variant_new_fixed_array(G_VARIANT_TYPE_UINT32,
scanopts, ARRAY_SIZE(scanopts), sizeof(uint32_t));
break;
case SR_CONF_DEVICE_OPTIONS:
*data = g_variant_new_fixed_array(G_VARIANT_TYPE_UINT32,
devopts, ARRAY_SIZE(devopts), sizeof(uint32_t));
break;
default:
return SR_ERR_NA;
}
return SR_OK;
return STD_CONFIG_LIST(key, data, sdi, cg, scanopts, NULL, devopts);
}
static int dev_acquisition_start(const struct sr_dev_inst *sdi)

View File

@ -388,18 +388,10 @@ static int config_list(uint32_t key, GVariant **data,
GVariant *gvar;
GVariantBuilder gvb;
(void)sdi;
(void)cg;
switch (key) {
case SR_CONF_SCAN_OPTIONS:
*data = g_variant_new_fixed_array(G_VARIANT_TYPE_UINT32,
scanopts, ARRAY_SIZE(scanopts), sizeof(uint32_t));
break;
case SR_CONF_DEVICE_OPTIONS:
*data = g_variant_new_fixed_array(G_VARIANT_TYPE_UINT32,
devopts, ARRAY_SIZE(devopts), sizeof(uint32_t));
break;
return STD_CONFIG_LIST(key, data, sdi, cg, scanopts, NULL, devopts);
case SR_CONF_SAMPLERATE:
g_variant_builder_init(&gvb, G_VARIANT_TYPE("a{sv}"));
gvar = g_variant_new_fixed_array(G_VARIANT_TYPE("t"),

View File

@ -536,25 +536,13 @@ static int config_list(uint32_t key, GVariant **data,
GVariant *gvar;
GVariantBuilder gvb;
(void)cg;
devc = (sdi) ? sdi->priv : NULL;
switch (key) {
case SR_CONF_SCAN_OPTIONS:
*data = g_variant_new_fixed_array(G_VARIANT_TYPE_UINT32,
scanopts, ARRAY_SIZE(scanopts), sizeof(uint32_t));
break;
case SR_CONF_DEVICE_OPTIONS:
if (!sdi) {
*data = g_variant_new_fixed_array(G_VARIANT_TYPE_UINT32,
drvopts, ARRAY_SIZE(drvopts), sizeof(uint32_t));
} else {
devc = sdi->priv;
*data = g_variant_new_fixed_array(G_VARIANT_TYPE_UINT32,
devopts, ARRAY_SIZE(devopts), sizeof(uint32_t));
}
break;
return STD_CONFIG_LIST(key, data, sdi, cg, scanopts, drvopts, devopts);
case SR_CONF_SAMPLERATE:
devc = sdi->priv;
g_variant_builder_init(&gvb, G_VARIANT_TYPE("a{sv}"));
gvar = g_variant_new_fixed_array(G_VARIANT_TYPE("t"), devc->samplerates,
devc->num_samplerates, sizeof(uint64_t));

View File

@ -361,55 +361,18 @@ static int config_get(uint32_t key, GVariant **data, const struct sr_dev_inst *s
return SR_OK;
}
/** Implementation of config_list, auxiliary function for common parts. */
static int config_list_common(uint32_t key, GVariant **data, const struct sr_dev_inst *sdi,
const struct sr_channel_group *cg)
{
(void)sdi;
(void)cg;
switch (key) {
case SR_CONF_SCAN_OPTIONS:
*data = g_variant_new_fixed_array(G_VARIANT_TYPE_UINT32,
scanopts, ARRAY_SIZE(scanopts), sizeof(uint32_t));
break;
default:
return SR_ERR_NA;
}
return SR_OK;
}
/** Implementation of config_list for Metrahit 1x/2x send mode */
static int config_list_sm(uint32_t key, GVariant **data, const struct sr_dev_inst *sdi,
const struct sr_channel_group *cg)
{
switch (key) {
case SR_CONF_DEVICE_OPTIONS:
*data = g_variant_new_fixed_array(G_VARIANT_TYPE_UINT32,
devopts_sm, ARRAY_SIZE(devopts_sm), sizeof(uint32_t));
break;
default:
return config_list_common(key, data, sdi, cg);
}
return SR_OK;
return STD_CONFIG_LIST(key, data, sdi, cg, scanopts, NULL, devopts_sm);
}
/** Implementation of config_list for Metrahit 2x bidirectional mode */
static int config_list_bd(uint32_t key, GVariant **data, const struct sr_dev_inst *sdi,
const struct sr_channel_group *cg)
{
switch (key) {
case SR_CONF_DEVICE_OPTIONS:
*data = g_variant_new_fixed_array(G_VARIANT_TYPE_UINT32,
devopts_bd, ARRAY_SIZE(devopts_bd), sizeof(uint32_t));
break;
default:
return config_list_common(key, data, sdi, cg);
}
return SR_OK;
return STD_CONFIG_LIST(key, data, sdi, cg, scanopts, NULL, devopts_bd);
}
static int dev_acquisition_start_1x_2x_rs232(const struct sr_dev_inst *sdi)

View File

@ -162,23 +162,7 @@ static int config_set(uint32_t key, GVariant *data, const struct sr_dev_inst *sd
static int config_list(uint32_t key, GVariant **data, const struct sr_dev_inst *sdi,
const struct sr_channel_group *cg)
{
(void)sdi;
(void)cg;
switch (key) {
case SR_CONF_SCAN_OPTIONS:
*data = g_variant_new_fixed_array(G_VARIANT_TYPE_UINT32,
scanopts, ARRAY_SIZE(scanopts), sizeof(uint32_t));
return SR_OK;
case SR_CONF_DEVICE_OPTIONS:
*data = g_variant_new_fixed_array(G_VARIANT_TYPE_UINT32,
devopts, ARRAY_SIZE(devopts), sizeof(uint32_t));
return SR_OK;
default:
return SR_ERR_NA;
}
return SR_OK;
return STD_CONFIG_LIST(key, data, sdi, cg, scanopts, NULL, devopts);
}
static int dev_acquisition_start(const struct sr_dev_inst *sdi)

View File

@ -462,27 +462,15 @@ static int config_list(uint32_t key, GVariant **data, const struct sr_dev_inst *
GVariantBuilder gvb;
unsigned int i;
GVariant *gvar;
struct dev_context *devc = NULL;
struct dev_context *devc;
if (key == SR_CONF_SCAN_OPTIONS) {
*data = g_variant_new_fixed_array(G_VARIANT_TYPE_UINT32,
scanopts, ARRAY_SIZE(scanopts), sizeof(uint32_t));
return SR_OK;
} else if (key == SR_CONF_DEVICE_OPTIONS && !sdi) {
*data = g_variant_new_fixed_array(G_VARIANT_TYPE_UINT32,
drvopts, ARRAY_SIZE(drvopts), sizeof(uint32_t));
return SR_OK;
}
if (sdi)
devc = sdi->priv;
devc = (sdi) ? sdi->priv : NULL;
if (!cg) {
switch (key) {
case SR_CONF_SCAN_OPTIONS:
case SR_CONF_DEVICE_OPTIONS:
*data = g_variant_new_fixed_array(G_VARIANT_TYPE_UINT32,
devopts, ARRAY_SIZE(devopts), sizeof(uint32_t));
break;
return STD_CONFIG_LIST(key, data, sdi, cg, scanopts, drvopts, devopts);
case SR_CONF_SAMPLERATE:
g_variant_builder_init(&gvb, G_VARIANT_TYPE("a{sv}"));
gvar = g_variant_new_fixed_array(G_VARIANT_TYPE("t"),
@ -501,8 +489,6 @@ static int config_list(uint32_t key, GVariant **data, const struct sr_dev_inst *
devopts_cg, ARRAY_SIZE(devopts_cg), sizeof(uint32_t));
break;
case SR_CONF_COUPLING:
if (!devc)
return SR_ERR_NA;
*data = g_variant_new_strv(devc->coupling_vals, devc->coupling_tab_size);
break;
case SR_CONF_VDIV:

View File

@ -599,25 +599,11 @@ static int config_list(uint32_t key, GVariant **data, const struct sr_dev_inst *
GVariantBuilder gvb;
unsigned int i;
if (key == SR_CONF_SCAN_OPTIONS) {
*data = g_variant_new_fixed_array(G_VARIANT_TYPE_UINT32,
scanopts, ARRAY_SIZE(scanopts), sizeof(uint32_t));
return SR_OK;
} else if (key == SR_CONF_DEVICE_OPTIONS && !sdi) {
*data = g_variant_new_fixed_array(G_VARIANT_TYPE_UINT32,
drvopts, ARRAY_SIZE(drvopts), sizeof(uint32_t));
return SR_OK;
}
if (!sdi)
return SR_ERR_ARG;
if (!cg) {
switch (key) {
case SR_CONF_SCAN_OPTIONS:
case SR_CONF_DEVICE_OPTIONS:
*data = g_variant_new_fixed_array(G_VARIANT_TYPE_UINT32,
devopts, ARRAY_SIZE(devopts), sizeof(uint32_t));
break;
return STD_CONFIG_LIST(key, data, sdi, cg, scanopts, drvopts, devopts);
case SR_CONF_BUFFERSIZE:
if (!sdi)
return SR_ERR_ARG;

View File

@ -282,35 +282,12 @@ static int config_set(uint32_t key, GVariant *data,
static int config_list(uint32_t key, GVariant **data,
const struct sr_dev_inst *sdi, const struct sr_channel_group *cg)
{
if (key == SR_CONF_SCAN_OPTIONS) {
*data = g_variant_new_fixed_array(G_VARIANT_TYPE_UINT32,
scanopts, ARRAY_SIZE(scanopts), sizeof(uint32_t));
return SR_OK;
} else if ((key == SR_CONF_DEVICE_OPTIONS) && !sdi) {
*data = g_variant_new_fixed_array(G_VARIANT_TYPE_UINT32,
drvopts, ARRAY_SIZE(drvopts), sizeof(uint32_t));
return SR_OK;
} else if ((key == SR_CONF_DEVICE_OPTIONS) && !cg) {
*data = g_variant_new_fixed_array(G_VARIANT_TYPE_UINT32,
devopts, ARRAY_SIZE(devopts), sizeof(uint32_t));
return SR_OK;
}
/* From here on, we're only concerned with channel group config. */
if (!cg)
return SR_ERR_NA;
/*
* TODO: Implement channel group configuration when adding support for
* plug-in cards.
*/
switch (key) {
default:
return SR_ERR_NA;
}
return SR_OK;
return STD_CONFIG_LIST(key, data, sdi, cg, scanopts, drvopts, devopts);
}
static void create_channel_index_list(GSList *channels, GArray **arr)

View File

@ -565,7 +565,7 @@ static int config_list(uint32_t key, GVariant **data, const struct sr_dev_inst *
int i;
switch (key) {
case SR_CONF_SCAN_OPTIONS:
case SR_CONF_SCAN_OPTIONS:
case SR_CONF_DEVICE_OPTIONS:
break;
case SR_CONF_SAMPLERATE:
@ -591,19 +591,12 @@ static int config_list(uint32_t key, GVariant **data, const struct sr_dev_inst *
switch (key) {
case SR_CONF_SCAN_OPTIONS:
*data = g_variant_new_fixed_array(G_VARIANT_TYPE_UINT32,
scanopts, ARRAY_SIZE(scanopts), sizeof(uint32_t));
break;
return STD_CONFIG_LIST(key, data, sdi, cg, scanopts, NULL, NULL);
case SR_CONF_DEVICE_OPTIONS:
if (!sdi)
*data = g_variant_new_fixed_array(G_VARIANT_TYPE_UINT32,
drvopts, ARRAY_SIZE(drvopts), sizeof(uint32_t));
else if (!cg)
*data = g_variant_new_fixed_array(G_VARIANT_TYPE_UINT32,
devopts, ARRAY_SIZE(devopts), sizeof(uint32_t));
else
*data = g_variant_new_fixed_array(G_VARIANT_TYPE_UINT32,
cgopts, ARRAY_SIZE(cgopts), sizeof(uint32_t));
if (!cg)
return STD_CONFIG_LIST(key, data, sdi, cg, NULL, drvopts, devopts);
*data = g_variant_new_fixed_array(G_VARIANT_TYPE_UINT32,
cgopts, ARRAY_SIZE(cgopts), sizeof(uint32_t));
break;
case SR_CONF_SAMPLERATE:
g_variant_builder_init(&gvb, G_VARIANT_TYPE("a{sv}"));

View File

@ -304,14 +304,9 @@ static int config_list(uint32_t key, GVariant **data, const struct sr_dev_inst *
GVariant *gvar, *grange[2];
GVariantBuilder gvb;
(void)sdi;
(void)cg;
switch (key) {
case SR_CONF_DEVICE_OPTIONS:
*data = g_variant_new_fixed_array(G_VARIANT_TYPE_UINT32,
devopts, ARRAY_SIZE(devopts), sizeof(uint32_t));
break;
return STD_CONFIG_LIST(key, data, sdi, cg, NULL, NULL, devopts);
case SR_CONF_SAMPLERATE:
g_variant_builder_init(&gvb, G_VARIANT_TYPE("a{sv}"));
gvar = g_variant_new_fixed_array(G_VARIANT_TYPE("t"),

View File

@ -270,14 +270,9 @@ static int config_list(uint32_t key, GVariant **data, const struct sr_dev_inst *
GVariant *gvar;
GVariantBuilder gvb;
(void)sdi;
(void)cg;
switch (key) {
case SR_CONF_DEVICE_OPTIONS:
*data = g_variant_new_fixed_array(G_VARIANT_TYPE_UINT32,
devopts, ARRAY_SIZE(devopts), sizeof(uint32_t));
break;
return STD_CONFIG_LIST(key, data, sdi, cg, NULL, NULL, devopts);
case SR_CONF_SAMPLERATE:
g_variant_builder_init(&gvb, G_VARIANT_TYPE("a{sv}"));
gvar = g_variant_new_fixed_array(G_VARIANT_TYPE("t"),

View File

@ -325,14 +325,9 @@ static int config_list(uint32_t key, GVariant **data, const struct sr_dev_inst *
GVariantBuilder gvb;
unsigned int i;
(void)sdi;
(void)cg;
switch (key) {
case SR_CONF_DEVICE_OPTIONS:
*data = g_variant_new_fixed_array(G_VARIANT_TYPE_UINT32,
devopts, ARRAY_SIZE(devopts), sizeof(uint32_t));
break;
return STD_CONFIG_LIST(key, data, sdi, cg, NULL, NULL, devopts);
case SR_CONF_SAMPLE_INTERVAL:
g_variant_builder_init(&gvb, G_VARIANT_TYPE_ARRAY);
for (i = 0; i < ARRAY_SIZE(kecheng_kc_330b_sample_intervals); i++) {

View File

@ -125,23 +125,7 @@ static int config_set(uint32_t key, GVariant *data, const struct sr_dev_inst *sd
static int config_list(uint32_t key, GVariant **data, const struct sr_dev_inst *sdi,
const struct sr_channel_group *cg)
{
(void)sdi;
(void)cg;
switch (key) {
case SR_CONF_SCAN_OPTIONS:
*data = g_variant_new_fixed_array(G_VARIANT_TYPE_UINT32,
scanopts, ARRAY_SIZE(scanopts), sizeof(uint32_t));
break;
case SR_CONF_DEVICE_OPTIONS:
*data = g_variant_new_fixed_array(G_VARIANT_TYPE_UINT32,
devopts, ARRAY_SIZE(devopts), sizeof(uint32_t));
break;
default:
return SR_ERR_NA;
}
return SR_OK;
return STD_CONFIG_LIST(key, data, sdi, cg, scanopts, NULL, devopts);
}
static int dev_acquisition_start(const struct sr_dev_inst *sdi)

View File

@ -282,33 +282,12 @@ static int config_list(uint32_t key, GVariant **data,
double dval;
int idx;
(void)cg;
/* Always available (with or without sdi). */
if (key == SR_CONF_SCAN_OPTIONS) {
*data = g_variant_new_fixed_array(G_VARIANT_TYPE_UINT32,
scanopts, ARRAY_SIZE(scanopts), sizeof(uint32_t));
return SR_OK;
}
/* Return drvopts without sdi (and devopts with sdi, see below). */
if (key == SR_CONF_DEVICE_OPTIONS && !sdi) {
*data = g_variant_new_fixed_array(G_VARIANT_TYPE_UINT32,
drvopts, ARRAY_SIZE(drvopts), sizeof(uint32_t));
return SR_OK;
}
/* Every other key needs an sdi. */
if (!sdi)
return SR_ERR_ARG;
devc = sdi->priv;
devc = (sdi) ? sdi->priv : NULL;
switch (key) {
case SR_CONF_SCAN_OPTIONS:
case SR_CONF_DEVICE_OPTIONS:
*data = g_variant_new_fixed_array(G_VARIANT_TYPE_UINT32,
devopts, ARRAY_SIZE(devopts), sizeof(uint32_t));
break;
return STD_CONFIG_LIST(key, data, sdi, cg, scanopts, drvopts, devopts);
case SR_CONF_VOLTAGE_TARGET:
g_variant_builder_init(&gvb, G_VARIANT_TYPE_ARRAY);
/* Min, max, step. */

View File

@ -183,23 +183,7 @@ static int config_set(uint32_t key, GVariant *data, const struct sr_dev_inst *sd
static int config_list(uint32_t key, GVariant **data, const struct sr_dev_inst *sdi,
const struct sr_channel_group *cg)
{
(void)sdi;
(void)cg;
switch (key) {
case SR_CONF_SCAN_OPTIONS:
*data = g_variant_new_fixed_array(G_VARIANT_TYPE_UINT32,
scanopts, ARRAY_SIZE(scanopts), sizeof(uint32_t));
break;
case SR_CONF_DEVICE_OPTIONS:
*data = g_variant_new_fixed_array(G_VARIANT_TYPE_UINT32,
devopts, ARRAY_SIZE(devopts), sizeof(uint32_t));
break;
default:
return SR_ERR_NA;
}
return SR_OK;
return STD_CONFIG_LIST(key, data, sdi, cg, scanopts, NULL, devopts);
}
static void LIBUSB_CALL mark_xfer(struct libusb_transfer *xfer)

View File

@ -406,15 +406,9 @@ static int config_list(uint32_t key, GVariant **data,
GVariantBuilder vb;
GVariant *var;
(void)sdi;
(void)cg;
switch (key) {
case SR_CONF_DEVICE_OPTIONS:
*data = g_variant_new_fixed_array(G_VARIANT_TYPE_UINT32,
devopts, ARRAY_SIZE(devopts),
sizeof(uint32_t));
break;
return STD_CONFIG_LIST(key, data, sdi, cg, NULL, NULL, devopts);
case SR_CONF_SAMPLERATE:
g_variant_builder_init(&vb, G_VARIANT_TYPE("a{sv}"));
var = g_variant_new_fixed_array(G_VARIANT_TYPE("t"),

View File

@ -388,41 +388,18 @@ static int config_set(uint32_t key, GVariant *data,
static int config_list(uint32_t key, GVariant **data,
const struct sr_dev_inst *sdi, const struct sr_channel_group *cg)
{
struct dev_context *devc = NULL;
const struct scope_config *model = NULL;
struct dev_context *devc;
const struct scope_config *model;
(void)cg;
/* SR_CONF_SCAN_OPTIONS is always valid, regardless of sdi or channel group. */
if (key == SR_CONF_SCAN_OPTIONS) {
*data = g_variant_new_fixed_array(G_VARIANT_TYPE_UINT32,
scanopts, ARRAY_SIZE(scanopts), sizeof(uint32_t));
return SR_OK;
}
/* If sdi is NULL, nothing except SR_CONF_DEVICE_OPTIONS can be provided. */
if (key == SR_CONF_DEVICE_OPTIONS && !sdi) {
*data = g_variant_new_fixed_array(G_VARIANT_TYPE_UINT32,
drvopts, ARRAY_SIZE(drvopts), sizeof(uint32_t));
return SR_OK;
}
/* Every other option requires a valid device instance. */
if (!sdi)
return SR_ERR_ARG;
devc = sdi->priv;
model = devc->model_config;
devc = (sdi) ? sdi->priv : NULL;
model = (devc) ? devc->model_config : NULL;
switch (key) {
case SR_CONF_SCAN_OPTIONS:
return STD_CONFIG_LIST(key, data, sdi, cg, scanopts, NULL, NULL);
case SR_CONF_DEVICE_OPTIONS:
if (!cg) {
/* If cg is NULL, only the SR_CONF_DEVICE_OPTIONS that are not
* specific to a channel group must be returned. */
*data = g_variant_new_fixed_array(G_VARIANT_TYPE_UINT32,
devopts, ARRAY_SIZE(devopts), sizeof(uint32_t));
return SR_OK;
}
if (!cg)
return STD_CONFIG_LIST(key, data, sdi, cg, NULL, drvopts, devopts);
*data = g_variant_new_fixed_array(G_VARIANT_TYPE_UINT32,
analog_devopts, ARRAY_SIZE(analog_devopts),
sizeof(uint32_t));

View File

@ -288,14 +288,9 @@ static int config_list(int key, GVariant **data, const struct sr_dev_inst *sdi,
GVariant *gvar;
GVariantBuilder gvb;
(void)cg;
(void)sdi;
switch (key) {
case SR_CONF_DEVICE_OPTIONS:
*data = g_variant_new_fixed_array(G_VARIANT_TYPE_UINT32,
devopts, ARRAY_SIZE(devopts), sizeof(uint32_t));
break;
return STD_CONFIG_LIST(key, data, sdi, cg, NULL, NULL, devopts);
case SR_CONF_SAMPLERATE:
g_variant_builder_init(&gvb, G_VARIANT_TYPE("a{sv}"));
gvar = g_variant_new_fixed_array(G_VARIANT_TYPE("t"), samplerates,

View File

@ -286,32 +286,12 @@ static int config_list(uint32_t key, GVariant **data, const struct sr_dev_inst *
double dval;
int idx;
(void)cg;
/* Always available (with or without sdi). */
if (key == SR_CONF_SCAN_OPTIONS) {
*data = g_variant_new_fixed_array(G_VARIANT_TYPE_UINT32,
scanopts, ARRAY_SIZE(scanopts), sizeof(uint32_t));
return SR_OK;
}
/* Return drvopts without sdi (and devopts with sdi, see below). */
if (key == SR_CONF_DEVICE_OPTIONS && !sdi) {
*data = g_variant_new_fixed_array(G_VARIANT_TYPE_UINT32,
drvopts, ARRAY_SIZE(drvopts), sizeof(uint32_t));
return SR_OK;
}
/* Every other key needs an sdi. */
if (!sdi)
return SR_ERR_ARG;
devc = sdi->priv;
devc = (sdi) ? sdi->priv : NULL;
switch (key) {
case SR_CONF_SCAN_OPTIONS:
case SR_CONF_DEVICE_OPTIONS:
*data = g_variant_new_fixed_array(G_VARIANT_TYPE_UINT32,
devopts, ARRAY_SIZE(devopts), sizeof(uint32_t));
break;
return STD_CONFIG_LIST(key, data, sdi, cg, scanopts, drvopts, devopts);
case SR_CONF_VOLTAGE_TARGET:
g_variant_builder_init(&gvb, G_VARIANT_TYPE_ARRAY);
/* Min, max, step. */

View File

@ -362,31 +362,11 @@ static int config_list(uint32_t key, GVariant **data, const struct sr_dev_inst *
struct dev_context *devc;
GVariantBuilder gvb;
/* Always available, even without sdi. */
if (key == SR_CONF_SCAN_OPTIONS) {
*data = g_variant_new_fixed_array(G_VARIANT_TYPE_UINT32,
scanopts, ARRAY_SIZE(scanopts), sizeof(uint32_t));
return SR_OK;
} else if (key == SR_CONF_DEVICE_OPTIONS && !sdi) {
*data = g_variant_new_fixed_array(G_VARIANT_TYPE_UINT32,
drvopts, ARRAY_SIZE(drvopts), sizeof(uint32_t));
return SR_OK;
}
if (!sdi)
return SR_ERR_ARG;
devc = sdi->priv;
devc = (sdi) ? sdi->priv : NULL;
if (!cg) {
/* No channel group: global options. */
switch (key) {
case SR_CONF_DEVICE_OPTIONS:
*data = g_variant_new_fixed_array(G_VARIANT_TYPE_UINT32,
devopts, ARRAY_SIZE(devopts), sizeof(uint32_t));
break;
default:
return SR_ERR_NA;
}
return STD_CONFIG_LIST(key, data, sdi, cg, scanopts, drvopts, devopts);
} else {
switch (key) {
case SR_CONF_DEVICE_OPTIONS:

View File

@ -142,32 +142,18 @@ static int config_set(uint32_t key, GVariant *data, const struct sr_dev_inst *sd
static int config_list(uint32_t key, GVariant **data, const struct sr_dev_inst *sdi,
const struct sr_channel_group *cg, int idx)
{
(void)cg;
switch (key) {
case SR_CONF_SCAN_OPTIONS:
*data = g_variant_new_fixed_array(G_VARIANT_TYPE_UINT32,
scanopts, ARRAY_SIZE(scanopts), sizeof(uint32_t));
break;
case SR_CONF_DEVICE_OPTIONS:
if (!sdi && !mic_devs[idx].has_humidity) {
*data = g_variant_new_fixed_array(G_VARIANT_TYPE_UINT32,
drvopts_temp, ARRAY_SIZE(drvopts_temp),
sizeof(uint32_t));
} else if (!sdi && mic_devs[idx].has_humidity) {
*data = g_variant_new_fixed_array(G_VARIANT_TYPE_UINT32,
drvopts_temp_hum, ARRAY_SIZE(drvopts_temp_hum),
sizeof(uint32_t));
} else {
*data = g_variant_new_fixed_array(G_VARIANT_TYPE_UINT32,
devopts, ARRAY_SIZE(devopts), sizeof(uint32_t));
}
break;
default:
return SR_ERR_NA;
}
return SR_OK;
/*
* We can't use the ternary operator here! The result would contain
* sizeof((cond) ? A : B) where A/B are arrays of different type/size.
* The ternary operator always returns the "common" type of A and B,
* which would be a pointer instead of either the A or B arrays.
* Thus, sizeof() would yield the size of a pointer, not the size
* of either the A or B array, which is not what we want.
*/
if (mic_devs[idx].has_humidity)
return STD_CONFIG_LIST(key, data, sdi, cg, scanopts, drvopts_temp_hum, devopts);
else
return STD_CONFIG_LIST(key, data, sdi, cg, scanopts, drvopts_temp, devopts);
}
static int dev_acquisition_start(const struct sr_dev_inst *sdi, int idx)

View File

@ -677,32 +677,14 @@ static int config_list(uint32_t key, GVariant **data, const struct sr_dev_inst *
GVariant *gvar;
GVariantBuilder gvb;
/* Driver options, no device instance necessary. */
switch (key) {
case SR_CONF_SCAN_OPTIONS:
*data = g_variant_new_fixed_array(G_VARIANT_TYPE_UINT32,
scanopts, ARRAY_SIZE(scanopts), sizeof(uint32_t));
return SR_OK;
case SR_CONF_DEVICE_OPTIONS:
if (sdi)
break;
*data = g_variant_new_fixed_array(G_VARIANT_TYPE_UINT32,
drvopts, ARRAY_SIZE(drvopts), sizeof(uint32_t));
return SR_OK;
default:
if (!sdi)
return SR_ERR_ARG;
devc = sdi->priv;
break;
}
devc = (sdi) ? sdi->priv : NULL;
/* Device options, independent from channel groups. */
if (!cg) {
switch (key) {
case SR_CONF_SCAN_OPTIONS:
case SR_CONF_DEVICE_OPTIONS:
*data = g_variant_new_fixed_array(G_VARIANT_TYPE_UINT32,
devopts, ARRAY_SIZE(devopts), sizeof(uint32_t));
return SR_OK;
return STD_CONFIG_LIST(key, data, sdi, cg, scanopts, drvopts, devopts);
case SR_CONF_CHANNEL_CONFIG:
if (devc->model->modelid <= LPS_303) {
/* The 1-channel models. */

View File

@ -176,23 +176,7 @@ static int config_set(uint32_t key, GVariant *data, const struct sr_dev_inst *sd
static int config_list(uint32_t key, GVariant **data, const struct sr_dev_inst *sdi,
const struct sr_channel_group *cg)
{
(void)sdi;
(void)cg;
switch (key) {
case SR_CONF_SCAN_OPTIONS:
*data = g_variant_new_fixed_array(G_VARIANT_TYPE_UINT32,
scanopts, ARRAY_SIZE(scanopts), sizeof(uint32_t));
break;
case SR_CONF_DEVICE_OPTIONS:
*data = g_variant_new_fixed_array(G_VARIANT_TYPE_UINT32,
devopts, ARRAY_SIZE(devopts), sizeof(uint32_t));
break;
default:
return SR_ERR_NA;
}
return SR_OK;
return STD_CONFIG_LIST(key, data, sdi, cg, scanopts, NULL, devopts);
}
static int dev_acquisition_start(const struct sr_dev_inst *sdi)

View File

@ -327,21 +327,10 @@ static int config_list(uint32_t key, GVariant **data, const struct sr_dev_inst *
GVariantBuilder gvb;
int num_ols_changrp, i;
(void)cg;
switch (key) {
case SR_CONF_SCAN_OPTIONS:
*data = g_variant_new_fixed_array(G_VARIANT_TYPE_UINT32,
scanopts, ARRAY_SIZE(scanopts), sizeof(uint32_t));
break;
case SR_CONF_DEVICE_OPTIONS:
if (!sdi)
*data = g_variant_new_fixed_array(G_VARIANT_TYPE_UINT32,
drvopts, ARRAY_SIZE(drvopts), sizeof(uint32_t));
else
*data = g_variant_new_fixed_array(G_VARIANT_TYPE_UINT32,
devopts, ARRAY_SIZE(devopts), sizeof(uint32_t));
break;
return STD_CONFIG_LIST(key, data, sdi, cg, scanopts, drvopts, devopts);
case SR_CONF_SAMPLERATE:
g_variant_builder_init(&gvb, G_VARIANT_TYPE("a{sv}"));
gvar = g_variant_new_fixed_array(G_VARIANT_TYPE("t"), samplerates,

View File

@ -242,55 +242,35 @@ static int config_list(uint32_t key, GVariant **data,
GVariant *tuple, *range[2];
GVariantBuilder gvb;
unsigned int i;
int ret;
(void)cg;
ret = SR_OK;
if (!sdi) {
switch (key) {
case SR_CONF_SCAN_OPTIONS:
*data = g_variant_new_fixed_array(G_VARIANT_TYPE_UINT32,
scanopts, ARRAY_SIZE(scanopts), sizeof(uint32_t));
break;
case SR_CONF_DEVICE_OPTIONS:
*data = g_variant_new_fixed_array(G_VARIANT_TYPE_UINT32,
drvopts, ARRAY_SIZE(drvopts), sizeof(uint32_t));
break;
default:
return SR_ERR_NA;
}
} else {
switch (key) {
case SR_CONF_DEVICE_OPTIONS:
*data = g_variant_new_fixed_array(G_VARIANT_TYPE_UINT32,
devopts, ARRAY_SIZE(devopts), sizeof(uint32_t));
break;
case SR_CONF_SPL_WEIGHT_FREQ:
*data = g_variant_new_strv(weight_freq, ARRAY_SIZE(weight_freq));
break;
case SR_CONF_SPL_WEIGHT_TIME:
*data = g_variant_new_strv(weight_time, ARRAY_SIZE(weight_time));
break;
case SR_CONF_SPL_MEASUREMENT_RANGE:
g_variant_builder_init(&gvb, G_VARIANT_TYPE_ARRAY);
for (i = 0; i < ARRAY_SIZE(meas_ranges); i++) {
range[0] = g_variant_new_uint64(meas_ranges[i][0]);
range[1] = g_variant_new_uint64(meas_ranges[i][1]);
tuple = g_variant_new_tuple(range, 2);
g_variant_builder_add_value(&gvb, tuple);
}
*data = g_variant_builder_end(&gvb);
break;
case SR_CONF_DATA_SOURCE:
*data = g_variant_new_strv(data_sources, ARRAY_SIZE(data_sources));
break;
default:
return SR_ERR_NA;
switch (key) {
case SR_CONF_SCAN_OPTIONS:
case SR_CONF_DEVICE_OPTIONS:
return STD_CONFIG_LIST(key, data, sdi, cg, scanopts, drvopts, devopts);
case SR_CONF_SPL_WEIGHT_FREQ:
*data = g_variant_new_strv(weight_freq, ARRAY_SIZE(weight_freq));
break;
case SR_CONF_SPL_WEIGHT_TIME:
*data = g_variant_new_strv(weight_time, ARRAY_SIZE(weight_time));
break;
case SR_CONF_SPL_MEASUREMENT_RANGE:
g_variant_builder_init(&gvb, G_VARIANT_TYPE_ARRAY);
for (i = 0; i < ARRAY_SIZE(meas_ranges); i++) {
range[0] = g_variant_new_uint64(meas_ranges[i][0]);
range[1] = g_variant_new_uint64(meas_ranges[i][1]);
tuple = g_variant_new_tuple(range, 2);
g_variant_builder_add_value(&gvb, tuple);
}
*data = g_variant_builder_end(&gvb);
break;
case SR_CONF_DATA_SOURCE:
*data = g_variant_new_strv(data_sources, ARRAY_SIZE(data_sources));
break;
default:
return SR_ERR_NA;
}
return ret;
return SR_OK;
}
static int dev_open(struct sr_dev_inst *sdi)

View File

@ -343,13 +343,9 @@ static int config_list(uint32_t key, GVariant **data, const struct sr_dev_inst *
GVariantBuilder gvb;
int num_pols_changrp, i;
(void)cg;
switch (key) {
case SR_CONF_DEVICE_OPTIONS:
*data = g_variant_new_fixed_array(G_VARIANT_TYPE_UINT32,
devopts, ARRAY_SIZE(devopts), sizeof(uint32_t));
break;
return STD_CONFIG_LIST(key, data, sdi, cg, NULL, NULL, devopts);
case SR_CONF_SAMPLERATE:
g_variant_builder_init(&gvb, G_VARIANT_TYPE("a{sv}"));
gvar = g_variant_new_fixed_array(G_VARIANT_TYPE("t"), samplerates,

View File

@ -843,42 +843,15 @@ static int config_list(uint32_t key, GVariant **data, const struct sr_dev_inst *
GVariant *tuple, *rational[2];
GVariantBuilder gvb;
unsigned int i;
struct dev_context *devc = NULL;
struct dev_context *devc;
/* SR_CONF_SCAN_OPTIONS is always valid, regardless of sdi or channel group. */
if (key == SR_CONF_SCAN_OPTIONS) {
*data = g_variant_new_fixed_array(G_VARIANT_TYPE_UINT32,
scanopts, ARRAY_SIZE(scanopts), sizeof(uint32_t));
return SR_OK;
}
/* If sdi is NULL, nothing except SR_CONF_DEVICE_OPTIONS can be provided. */
if (key == SR_CONF_DEVICE_OPTIONS && !sdi) {
*data = g_variant_new_fixed_array(G_VARIANT_TYPE_UINT32,
drvopts, ARRAY_SIZE(drvopts), sizeof(uint32_t));
return SR_OK;
}
/* Every other option requires a valid device instance. */
if (!sdi)
return SR_ERR_ARG;
devc = sdi->priv;
/* If a channel group is specified, it must be a valid one. */
if (cg && !g_slist_find(sdi->channel_groups, cg)) {
sr_err("Invalid channel group specified.");
return SR_ERR;
}
devc = (sdi) ? sdi->priv : NULL;
switch (key) {
case SR_CONF_SCAN_OPTIONS:
case SR_CONF_DEVICE_OPTIONS:
if (!cg) {
/* If cg is NULL, only the SR_CONF_DEVICE_OPTIONS that are not
* specific to a channel group must be returned. */
*data = g_variant_new_fixed_array(G_VARIANT_TYPE_UINT32,
devopts, ARRAY_SIZE(devopts), sizeof(uint32_t));
return SR_OK;
}
if (!cg)
return STD_CONFIG_LIST(key, data, sdi, cg, scanopts, drvopts, devopts);
if (cg == devc->digital_group) {
*data = g_variant_new_fixed_array(G_VARIANT_TYPE_UINT32,
NULL, 0, sizeof(uint32_t));
@ -895,17 +868,13 @@ static int config_list(uint32_t key, GVariant **data, const struct sr_dev_inst *
}
break;
case SR_CONF_COUPLING:
if (!cg) {
sr_err("No channel group specified.");
if (!cg)
return SR_ERR_CHANNEL_GROUP;
}
*data = g_variant_new_strv(coupling, ARRAY_SIZE(coupling));
break;
case SR_CONF_PROBE_FACTOR:
if (!cg) {
sr_err("No channel group specified.");
if (!cg)
return SR_ERR_CHANNEL_GROUP;
}
*data = g_variant_new_fixed_array(G_VARIANT_TYPE_UINT64,
probe_factor, ARRAY_SIZE(probe_factor), sizeof(uint64_t));
break;
@ -913,10 +882,8 @@ static int config_list(uint32_t key, GVariant **data, const struct sr_dev_inst *
if (!devc)
/* Can't know this until we have the exact model. */
return SR_ERR_ARG;
if (!cg) {
sr_err("No channel group specified.");
if (!cg)
return SR_ERR_CHANNEL_GROUP;
}
g_variant_builder_init(&gvb, G_VARIANT_TYPE_ARRAY);
for (i = 0; i < devc->num_vdivs; i++) {
rational[0] = g_variant_new_uint64(devc->vdivs[i][0]);

View File

@ -217,30 +217,7 @@ static int config_set(uint32_t key, GVariant *data,
static int config_list(uint32_t key, GVariant **data,
const struct sr_dev_inst *sdi, const struct sr_channel_group *cg)
{
(void)sdi;
(void)cg;
/* Return drvopts without sdi (and devopts with sdi, see below). */
if (key == SR_CONF_DEVICE_OPTIONS && !sdi) {
*data = g_variant_new_fixed_array(G_VARIANT_TYPE_UINT32,
drvopts, ARRAY_SIZE(drvopts), sizeof(uint32_t));
return SR_OK;
}
switch (key) {
case SR_CONF_SCAN_OPTIONS:
*data = g_variant_new_fixed_array(G_VARIANT_TYPE_UINT32,
scanopts, ARRAY_SIZE(scanopts), sizeof(uint32_t));
break;
case SR_CONF_DEVICE_OPTIONS:
*data = g_variant_new_fixed_array(G_VARIANT_TYPE_UINT32,
devopts, ARRAY_SIZE(devopts), sizeof(uint32_t));
break;
default:
return SR_ERR_NA;
}
return SR_OK;
return STD_CONFIG_LIST(key, data, sdi, cg, scanopts, drvopts, devopts);
}
SR_PRIV struct sr_dev_driver rohde_schwarz_sme_0x_driver_info = {

View File

@ -353,23 +353,10 @@ static int config_list(uint32_t key, GVariant **data,
GVariant *gvar;
GVariantBuilder gvb;
(void)sdi;
(void)cg;
switch (key) {
case SR_CONF_SCAN_OPTIONS:
*data = g_variant_new_fixed_array(G_VARIANT_TYPE_UINT32,
scanopts, ARRAY_SIZE(scanopts), sizeof(uint32_t));
break;
case SR_CONF_DEVICE_OPTIONS:
if (!sdi) {
*data = g_variant_new_fixed_array(G_VARIANT_TYPE_UINT32,
drvopts, ARRAY_SIZE(drvopts), sizeof(uint32_t));
} else {
*data = g_variant_new_fixed_array(G_VARIANT_TYPE_UINT32,
devopts, ARRAY_SIZE(devopts), sizeof(uint32_t));
}
break;
return STD_CONFIG_LIST(key, data, sdi, cg, scanopts, drvopts, devopts);
case SR_CONF_SAMPLERATE:
g_variant_builder_init(&gvb, G_VARIANT_TYPE("a{sv}"));
gvar = g_variant_new_fixed_array(G_VARIANT_TYPE("t"),

View File

@ -503,18 +503,10 @@ static int config_list(uint32_t key, GVariant **data, const struct sr_dev_inst *
GVariantBuilder gvb;
unsigned int i;
(void)sdi;
(void)cg;
switch (key) {
case SR_CONF_SCAN_OPTIONS:
*data = g_variant_new_fixed_array(G_VARIANT_TYPE_UINT32,
scanopts, ARRAY_SIZE(scanopts), sizeof(uint32_t));
break;
case SR_CONF_DEVICE_OPTIONS:
*data = g_variant_new_fixed_array(G_VARIANT_TYPE_UINT32,
devopts, ARRAY_SIZE(devopts), sizeof(uint32_t));
break;
return STD_CONFIG_LIST(key, data, sdi, cg, scanopts, NULL, devopts);
case SR_CONF_SAMPLERATE:
g_variant_builder_init(&gvb, G_VARIANT_TYPE("a{sv}"));
gvar = g_variant_new_fixed_array(G_VARIANT_TYPE("t"),

View File

@ -520,28 +520,18 @@ static int config_list(uint32_t key, GVariant **data, const struct sr_dev_inst *
int i;
const char *s[16];
/* Always available, even without sdi. */
if (key == SR_CONF_SCAN_OPTIONS) {
*data = g_variant_new_fixed_array(G_VARIANT_TYPE_UINT32,
scanopts, ARRAY_SIZE(scanopts), sizeof(uint32_t));
return SR_OK;
} else if (key == SR_CONF_DEVICE_OPTIONS && !sdi) {
*data = g_variant_new_fixed_array(G_VARIANT_TYPE_UINT32,
drvopts, ARRAY_SIZE(drvopts), sizeof(uint32_t));
return SR_OK;
}
if (!sdi)
return SR_ERR_ARG;
devc = sdi->priv;
devc = (sdi) ? sdi->priv : NULL;
if (!cg) {
/* No channel group: global options. */
switch (key) {
case SR_CONF_SCAN_OPTIONS:
case SR_CONF_DEVICE_OPTIONS:
*data = g_variant_new_fixed_array(G_VARIANT_TYPE_UINT32,
devc->device->devopts, devc->device->num_devopts,
sizeof(uint32_t));
return std_opts_config_list(key, data, sdi, cg,
scanopts, ARRAY_SIZE(scanopts),
drvopts, ARRAY_SIZE(drvopts),
(devc) ? devc->device->devopts : NULL,
(devc) ? devc->device->num_devopts : 0);
break;
case SR_CONF_CHANNEL_CONFIG:
/* Not used. */

View File

@ -152,23 +152,7 @@ static int config_set(uint32_t key, GVariant *data, const struct sr_dev_inst *sd
static int config_list(uint32_t key, GVariant **data, const struct sr_dev_inst *sdi,
const struct sr_channel_group *cg)
{
(void)sdi;
(void)cg;
switch (key) {
case SR_CONF_SCAN_OPTIONS:
*data = g_variant_new_fixed_array(G_VARIANT_TYPE_UINT32,
scanopts, ARRAY_SIZE(scanopts), sizeof(uint32_t));
break;
case SR_CONF_DEVICE_OPTIONS:
*data = g_variant_new_fixed_array(G_VARIANT_TYPE_UINT32,
devopts, ARRAY_SIZE(devopts), sizeof(uint32_t));
break;
default:
return SR_ERR_NA;
}
return SR_OK;
return STD_CONFIG_LIST(key, data, sdi, cg, scanopts, NULL, devopts);
}
static int dev_acquisition_start(const struct sr_dev_inst *sdi)

View File

@ -625,8 +625,6 @@ static int config_commit(const struct sr_dev_inst *sdi)
return SR_OK;
}
/* List available choices for a configuration setting.
*/
static int config_list(uint32_t key, GVariant **data,
const struct sr_dev_inst *sdi,
const struct sr_channel_group *cg)
@ -635,31 +633,16 @@ static int config_list(uint32_t key, GVariant **data,
GVariant *gvar;
GVariantBuilder gvb;
(void)cg;
devc = (sdi) ? sdi->priv : NULL;
if (key == SR_CONF_SCAN_OPTIONS) {
*data = g_variant_new_fixed_array(G_VARIANT_TYPE_UINT32,
scanopts, ARRAY_SIZE(scanopts), sizeof(scanopts[0]));
return SR_OK;
}
if (!sdi) {
if (key != SR_CONF_DEVICE_OPTIONS)
return SR_ERR_ARG;
/* List driver capabilities. */
*data = g_variant_new_fixed_array(G_VARIANT_TYPE_UINT32,
drvopts, ARRAY_SIZE(drvopts), sizeof(drvopts[0]));
return SR_OK;
}
devc = sdi->priv;
/* List the model's device options. */
if (key == SR_CONF_DEVICE_OPTIONS) {
*data = g_variant_new_fixed_array(G_VARIANT_TYPE_UINT32,
devc->model->devopts, devc->model->num_devopts,
sizeof(devc->model->devopts[0]));
return SR_OK;
switch (key) {
case SR_CONF_SCAN_OPTIONS:
case SR_CONF_DEVICE_OPTIONS:
return std_opts_config_list(key, data, sdi, cg,
scanopts, ARRAY_SIZE(scanopts),
drvopts, ARRAY_SIZE(drvopts),
(devc) ? devc->model->devopts : NULL,
(devc) ? devc->model->num_devopts : 0);
}
if (!has_devopt(devc->model, key | SR_CONF_LIST))

View File

@ -136,23 +136,7 @@ static int config_set(uint32_t key, GVariant *data, const struct sr_dev_inst *sd
static int config_list(uint32_t key, GVariant **data, const struct sr_dev_inst *sdi,
const struct sr_channel_group *cg)
{
(void)sdi;
(void)cg;
switch (key) {
case SR_CONF_SCAN_OPTIONS:
*data = g_variant_new_fixed_array(G_VARIANT_TYPE_UINT32,
scanopts, ARRAY_SIZE(scanopts), sizeof(uint32_t));
break;
case SR_CONF_DEVICE_OPTIONS:
*data = g_variant_new_fixed_array(G_VARIANT_TYPE_UINT32,
devopts, ARRAY_SIZE(devopts), sizeof(uint32_t));
break;
default:
return SR_ERR_NA;
}
return SR_OK;
return STD_CONFIG_LIST(key, data, sdi, cg, scanopts, NULL, devopts);
}
static int dev_acquisition_start(const struct sr_dev_inst *sdi)

View File

@ -222,23 +222,7 @@ static int config_set(uint32_t key, GVariant *data, const struct sr_dev_inst *sd
static int config_list(uint32_t key, GVariant **data, const struct sr_dev_inst *sdi,
const struct sr_channel_group *cg)
{
(void)sdi;
(void)cg;
switch (key) {
case SR_CONF_SCAN_OPTIONS:
*data = g_variant_new_fixed_array(G_VARIANT_TYPE_UINT32,
scanopts, ARRAY_SIZE(scanopts), sizeof(uint32_t));
break;
case SR_CONF_DEVICE_OPTIONS:
*data = g_variant_new_fixed_array(G_VARIANT_TYPE_UINT32,
devopts, ARRAY_SIZE(devopts), sizeof(uint32_t));
break;
default:
return SR_ERR_NA;
}
return SR_OK;
return STD_CONFIG_LIST(key, data, sdi, cg, scanopts, NULL, devopts);
}
static void receive_data(struct sr_dev_inst *sdi, unsigned char *data, int len)

View File

@ -106,23 +106,7 @@ static int config_set(uint32_t key, GVariant *data, const struct sr_dev_inst *sd
static int config_list(uint32_t key, GVariant **data, const struct sr_dev_inst *sdi,
const struct sr_channel_group *cg)
{
(void)sdi;
(void)cg;
switch (key) {
case SR_CONF_SCAN_OPTIONS:
*data = g_variant_new_fixed_array(G_VARIANT_TYPE_UINT32,
scanopts, ARRAY_SIZE(scanopts), sizeof(uint32_t));
break;
case SR_CONF_DEVICE_OPTIONS:
*data = g_variant_new_fixed_array(G_VARIANT_TYPE_UINT32,
devopts, ARRAY_SIZE(devopts), sizeof(uint32_t));
break;
default:
return SR_ERR_NA;
}
return SR_OK;
return STD_CONFIG_LIST(key, data, sdi, cg, scanopts, NULL, devopts);
}
static int dev_acquisition_start(const struct sr_dev_inst *sdi)

View File

@ -121,23 +121,7 @@ static int config_set(uint32_t key, GVariant *data, const struct sr_dev_inst *sd
static int config_list(uint32_t key, GVariant **data, const struct sr_dev_inst *sdi,
const struct sr_channel_group *cg)
{
(void)sdi;
(void)cg;
switch (key) {
case SR_CONF_SCAN_OPTIONS:
*data = g_variant_new_fixed_array(G_VARIANT_TYPE_UINT32,
scanopts, ARRAY_SIZE(scanopts), sizeof(uint32_t));
break;
case SR_CONF_DEVICE_OPTIONS:
*data = g_variant_new_fixed_array(G_VARIANT_TYPE_UINT32,
devopts, ARRAY_SIZE(devopts), sizeof(uint32_t));
break;
default:
return SR_ERR_NA;
}
return SR_OK;
return STD_CONFIG_LIST(key, data, sdi, cg, scanopts, NULL, devopts);
}
static int dev_acquisition_start(const struct sr_dev_inst *sdi)

View File

@ -205,18 +205,10 @@ static int config_set(uint32_t key, GVariant *data, const struct sr_dev_inst *sd
static int config_list(uint32_t key, GVariant **data, const struct sr_dev_inst *sdi,
const struct sr_channel_group *cg)
{
(void)sdi;
(void)cg;
switch (key) {
case SR_CONF_SCAN_OPTIONS:
*data = g_variant_new_fixed_array(G_VARIANT_TYPE_UINT32,
scanopts, ARRAY_SIZE(scanopts), sizeof(uint32_t));
break;
case SR_CONF_DEVICE_OPTIONS:
*data = g_variant_new_fixed_array(G_VARIANT_TYPE_UINT32,
devopts, ARRAY_SIZE(devopts), sizeof(uint32_t));
break;
return STD_CONFIG_LIST(key, data, sdi, cg, scanopts, NULL, devopts);
case SR_CONF_DATA_SOURCE:
*data = g_variant_new_strv(data_sources, ARRAY_SIZE(data_sources));
break;

View File

@ -182,27 +182,7 @@ static int config_set(uint32_t key, GVariant *data, const struct sr_dev_inst *sd
static int config_list(uint32_t key, GVariant **data, const struct sr_dev_inst *sdi,
const struct sr_channel_group *cg)
{
(void)sdi;
(void)cg;
switch (key) {
case SR_CONF_SCAN_OPTIONS:
*data = g_variant_new_fixed_array(G_VARIANT_TYPE_UINT32,
scanopts, ARRAY_SIZE(scanopts), sizeof(uint32_t));
break;
case SR_CONF_DEVICE_OPTIONS:
if (!sdi)
*data = g_variant_new_fixed_array(G_VARIANT_TYPE_UINT32,
drvopts, ARRAY_SIZE(drvopts), sizeof(uint32_t));
else
*data = g_variant_new_fixed_array(G_VARIANT_TYPE_UINT32,
devopts, ARRAY_SIZE(devopts), sizeof(uint32_t));
break;
default:
return SR_ERR_NA;
}
return SR_OK;
return STD_CONFIG_LIST(key, data, sdi, cg, scanopts, drvopts, devopts);
}
static void LIBUSB_CALL receive_transfer(struct libusb_transfer *transfer)

View File

@ -470,28 +470,11 @@ static int config_list(uint32_t key, GVariant **data, const struct sr_dev_inst *
const struct sr_channel_group *cg)
{
int cg_type = CG_NONE;
struct dev_context *devc = NULL;
const struct scope_config *model = NULL;
struct dev_context *devc;
const struct scope_config *model;
/* SR_CONF_SCAN_OPTIONS is always valid, regardless of sdi or channel group. */
if (key == SR_CONF_SCAN_OPTIONS) {
*data = g_variant_new_fixed_array(G_VARIANT_TYPE_UINT32,
dlm_scanopts, ARRAY_SIZE(dlm_scanopts), sizeof(uint32_t));
return SR_OK;
}
/* If sdi is NULL, nothing except SR_CONF_DEVICE_OPTIONS can be provided. */
if (key == SR_CONF_DEVICE_OPTIONS && !sdi) {
*data = g_variant_new_fixed_array(G_VARIANT_TYPE_UINT32,
dlm_drvopts, ARRAY_SIZE(dlm_drvopts), sizeof(uint32_t));
return SR_OK;
}
if (!sdi)
return SR_ERR_ARG;
devc = sdi->priv;
model = devc->model_config;
devc = (sdi) ? sdi->priv : NULL;
model = (devc) ? devc->model_config : NULL;
/*
* If cg is NULL, only the SR_CONF_DEVICE_OPTIONS that are not
@ -499,10 +482,9 @@ static int config_list(uint32_t key, GVariant **data, const struct sr_dev_inst *
*/
if (!cg) {
switch (key) {
case SR_CONF_SCAN_OPTIONS:
case SR_CONF_DEVICE_OPTIONS:
*data = g_variant_new_fixed_array(G_VARIANT_TYPE_UINT32,
dlm_devopts, ARRAY_SIZE(dlm_devopts), sizeof(uint32_t));
return SR_OK;
return STD_CONFIG_LIST(key, data, sdi, cg, dlm_scanopts, dlm_drvopts, dlm_devopts);
case SR_CONF_TIMEBASE:
*data = build_tuples(&dlm_timebases, ARRAY_SIZE(dlm_timebases));
return SR_OK;

View File

@ -399,18 +399,9 @@ static int config_list(uint32_t key, GVariant **data, const struct sr_dev_inst *
double v;
GVariant *range[2];
(void)cg;
switch (key) {
case SR_CONF_DEVICE_OPTIONS:
if (!sdi) {
*data = g_variant_new_fixed_array(G_VARIANT_TYPE_UINT32,
drvopts, ARRAY_SIZE(drvopts), sizeof(uint32_t));
} else {
*data = g_variant_new_fixed_array(G_VARIANT_TYPE_UINT32,
devopts, ARRAY_SIZE(devopts), sizeof(uint32_t));
}
break;
return STD_CONFIG_LIST(key, data, sdi, cg, NULL, drvopts, devopts);
case SR_CONF_SAMPLERATE:
devc = sdi->priv;
g_variant_builder_init(&gvb, G_VARIANT_TYPE("a{sv}"));

View File

@ -853,18 +853,19 @@ SR_API int sr_config_commit(const struct sr_dev_inst *sdi)
* List all possible values for a configuration key.
*
* @param[in] driver The sr_dev_driver struct to query. Must not be NULL.
* @param[in] sdi (optional) If the key is specific to a device, this must
* contain a pointer to the struct sr_dev_inst to be checked.
* @param[in] sdi (optional) If the key is specific to a device instance, this
* must contain a pointer to the struct sr_dev_inst to be checked.
* Otherwise it must be NULL. If sdi is != NULL, sdi->priv must
* also be != NULL.
* @param[in] cg The channel group on the device for which to list the
* values, or NULL.
* @param[in] cg The channel group on the device instance for which to list
* the values, or NULL. If this device instance doesn't
* have channel groups, this must not be != NULL.
* @param[in] key The configuration key (SR_CONF_*).
* @param[in,out] data A pointer to a GVariant where the list will be stored.
* The caller is given ownership of the GVariant and must thus
* unref the GVariant after use. However if this function
* returns an error code, the field should be considered
* unused, and should not be unreferenced.
* The caller is given ownership of the GVariant and must thus
* unref the GVariant after use. However if this function
* returns an error code, the field should be considered
* unused, and should not be unreferenced.
*
* @retval SR_OK Success.
* @retval SR_ERR Error.
@ -883,21 +884,50 @@ SR_API int sr_config_list(const struct sr_dev_driver *driver,
if (!driver || !data)
return SR_ERR;
else if (!driver->config_list)
if (!driver->config_list)
return SR_ERR_ARG;
else if (key != SR_CONF_SCAN_OPTIONS && key != SR_CONF_DEVICE_OPTIONS) {
if (key != SR_CONF_SCAN_OPTIONS && key != SR_CONF_DEVICE_OPTIONS) {
if (check_key(driver, sdi, cg, key, SR_CONF_LIST, NULL) != SR_OK)
return SR_ERR_ARG;
}
if (sdi && !sdi->priv) {
sr_err("Can't list config (sdi != NULL, sdi->priv == NULL).");
return SR_ERR;
}
if (key != SR_CONF_SCAN_OPTIONS && key != SR_CONF_DEVICE_OPTIONS && !sdi) {
sr_err("Config keys other than SR_CONF_SCAN_OPTIONS and "
"SR_CONF_DEVICE_OPTIONS always need an sdi.");
return SR_ERR_ARG;
}
if (cg && sdi && !sdi->channel_groups) {
sr_err("Can't list config for channel group, there are none.");
return SR_ERR_ARG;
}
if (cg && sdi && !g_slist_find(sdi->channel_groups, cg)) {
sr_err("If a channel group is specified, it must be a valid one.");
return SR_ERR_ARG;
}
if (cg && !sdi) {
sr_err("Need sdi when a channel group is specified.");
return SR_ERR_ARG;
}
if ((ret = driver->config_list(key, data, sdi, cg)) == SR_OK) {
log_key(sdi, cg, key, SR_CONF_LIST, *data);
g_variant_ref_sink(*data);
}
if (ret == SR_ERR_CHANNEL_GROUP)
sr_err("%s: No channel group specified.",
(sdi) ? sdi->driver->name : "unknown");
return ret;
}

View File

@ -251,32 +251,6 @@ static int serial_stream_check(struct sr_serial_dev_inst *serial,
is_valid, timeout_ms, baudrate);
}
struct std_opt_desc {
const uint32_t *scanopts;
const int num_scanopts;
const uint32_t *devopts;
const int num_devopts;
};
static int std_config_list(uint32_t key, GVariant **data,
const struct std_opt_desc *d)
{
switch (key) {
case SR_CONF_SCAN_OPTIONS:
*data = g_variant_new_fixed_array(G_VARIANT_TYPE_UINT32,
d->scanopts, d->num_scanopts, sizeof(uint32_t));
break;
case SR_CONF_DEVICE_OPTIONS:
*data = g_variant_new_fixed_array(G_VARIANT_TYPE_UINT32,
d->devopts, d->num_devopts, sizeof(uint32_t));
break;
default:
return SR_ERR_NA;
}
return SR_OK;
}
static int send_config_update(struct sr_dev_inst *sdi, struct sr_config *cfg)
{
struct sr_datafeed_packet packet;
@ -874,22 +848,14 @@ static const uint32_t devopts[] = {
SR_CONF_EQUIV_CIRCUIT_MODEL | SR_CONF_GET | SR_CONF_LIST,
};
static const struct std_opt_desc opts = {
scanopts, ARRAY_SIZE(scanopts),
devopts, ARRAY_SIZE(devopts),
};
SR_PRIV int es51919_serial_config_list(uint32_t key, GVariant **data,
const struct sr_dev_inst *sdi,
const struct sr_channel_group *cg)
{
(void)sdi;
(void)cg;
if (std_config_list(key, data, &opts) == SR_OK)
return SR_OK;
switch (key) {
case SR_CONF_SCAN_OPTIONS:
case SR_CONF_DEVICE_OPTIONS:
return STD_CONFIG_LIST(key, data, sdi, cg, scanopts, NULL, devopts);
case SR_CONF_OUTPUT_FREQUENCY:
*data = g_variant_new_fixed_array(G_VARIANT_TYPE_DOUBLE,
frequencies, ARRAY_SIZE(frequencies), sizeof(double));

View File

@ -947,6 +947,15 @@ SR_PRIV GSList *std_dev_list(const struct sr_dev_driver *di);
SR_PRIV int std_serial_dev_close(struct sr_dev_inst *sdi);
SR_PRIV GSList *std_scan_complete(struct sr_dev_driver *di, GSList *devices);
SR_PRIV int std_opts_config_list(uint32_t key, GVariant **data,
const struct sr_dev_inst *sdi, const struct sr_channel_group *cg,
const uint32_t scanopts[], size_t scansize, const uint32_t drvopts[],
size_t drvsize, const uint32_t devopts[], size_t devsize);
#define STD_CONFIG_LIST(key, data, sdi, cg, scanopts, drvopts, devopts) \
std_opts_config_list(key, data, sdi, cg, ARRAY_AND_SIZE(scanopts), \
ARRAY_AND_SIZE(drvopts), ARRAY_AND_SIZE(devopts))
/*--- resource.c ------------------------------------------------------------*/
SR_PRIV int64_t sr_file_get_size(FILE *file);

View File

@ -319,19 +319,7 @@ static int config_set(uint32_t key, GVariant *data, const struct sr_dev_inst *sd
static int config_list(uint32_t key, GVariant **data, const struct sr_dev_inst *sdi,
const struct sr_channel_group *cg)
{
(void)sdi;
(void)cg;
switch (key) {
case SR_CONF_DEVICE_OPTIONS:
*data = g_variant_new_fixed_array(G_VARIANT_TYPE_UINT32,
devopts, ARRAY_SIZE(devopts), sizeof(uint32_t));
break;
default:
return SR_ERR_NA;
}
return SR_OK;
return STD_CONFIG_LIST(key, data, sdi, cg, NULL, NULL, devopts);
}
static int dev_acquisition_start(const struct sr_dev_inst *sdi)

View File

@ -497,3 +497,46 @@ SR_PRIV GSList *std_scan_complete(struct sr_dev_driver *di, GSList *devices)
return devices;
}
SR_PRIV int std_opts_config_list(uint32_t key, GVariant **data,
const struct sr_dev_inst *sdi, const struct sr_channel_group *cg,
const uint32_t scanopts[], size_t scansize, const uint32_t drvopts[],
size_t drvsize, const uint32_t devopts[], size_t devsize)
{
switch (key) {
case SR_CONF_SCAN_OPTIONS:
/* Always return scanopts, regardless of sdi or cg. */
if (!scanopts)
return SR_ERR_ARG;
*data = g_variant_new_fixed_array(G_VARIANT_TYPE_UINT32,
scanopts, scansize, sizeof(uint32_t));
break;
case SR_CONF_DEVICE_OPTIONS:
if (!sdi) {
/* sdi == NULL: return drvopts. */
if (!drvopts)
return SR_ERR_ARG;
*data = g_variant_new_fixed_array(G_VARIANT_TYPE_UINT32,
drvopts, drvsize, sizeof(uint32_t));
} else if (sdi && !cg) {
/* sdi != NULL, cg == NULL: return devopts. */
if (!devopts)
return SR_ERR_ARG;
*data = g_variant_new_fixed_array(G_VARIANT_TYPE_UINT32,
devopts, devsize, sizeof(uint32_t));
} else {
/*
* Note: sdi != NULL, cg != NULL is not handled by
* this function since it's very driver-specific.
*/
sr_err("%s: %s: sdi/cg != NULL: not handling.",
sdi->driver->name, __func__);
return SR_ERR_ARG;
}
break;
default:
return SR_ERR_NA;
}
return SR_OK;
}