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,
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;
{
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:
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,
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. */
}
} 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;
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"),
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"),
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)
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)
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;
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)
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"),
*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)
*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,
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)
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 = {
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,
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);
*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));
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)
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"),
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));
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)
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)
GVariantBuilder gvb;
unsigned int i;
GVariant *gvar;
- struct dev_context *devc = NULL;
-
- 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;
- }
+ struct dev_context *devc;
- 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"),
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:
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;
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)
int i;
switch (key) {
- case SR_CONF_SCAN_OPTIONS:
+ case SR_CONF_SCAN_OPTIONS:
case SR_CONF_DEVICE_OPTIONS:
break;
case SR_CONF_SAMPLERATE:
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}"));
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"),
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"),
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++) {
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)
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. */
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)
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"),
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;
-
- (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;
+ struct dev_context *devc;
+ const struct scope_config *model;
- 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));
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,
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. */
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:
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)
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. */
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)
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,
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)
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,
GVariant *tuple, *rational[2];
GVariantBuilder gvb;
unsigned int i;
- struct dev_context *devc = NULL;
-
- /* 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;
+ struct dev_context *devc;
- /* 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));
}
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;
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]);
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 = {
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"),
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"),
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. */
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)
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)
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))
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)
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)
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)
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)
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;
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)
const struct sr_channel_group *cg)
{
int cg_type = CG_NONE;
- struct dev_context *devc = NULL;
- const struct scope_config *model = NULL;
-
- /* 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;
+ struct dev_context *devc;
+ const struct scope_config *model;
- 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
*/
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;
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}"));
* 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.
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;
}
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;
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));
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);
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)
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;
+}