From: Uwe Hermann Date: Thu, 13 Jul 2017 19:14:04 +0000 (+0200) Subject: drivers: Add and use STD_CONFIG_LIST(). X-Git-Url: https://sigrok.org/gitaction?a=commitdiff_plain;h=e66d1892d0dd16ed166fc8f13493f95de0607362;p=libsigrok.git 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. --- diff --git a/src/hardware/agilent-dmm/api.c b/src/hardware/agilent-dmm/api.c index 27079764..052e503c 100644 --- a/src/hardware/agilent-dmm/api.c +++ b/src/hardware/agilent-dmm/api.c @@ -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, diff --git a/src/hardware/appa-55ii/api.c b/src/hardware/appa-55ii/api.c index 05024f96..eab203dd 100644 --- a/src/hardware/appa-55ii/api.c +++ b/src/hardware/appa-55ii/api.c @@ -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; diff --git a/src/hardware/arachnid-labs-re-load-pro/api.c b/src/hardware/arachnid-labs-re-load-pro/api.c index bfbdd7d4..9c1fe532 100644 --- a/src/hardware/arachnid-labs-re-load-pro/api.c +++ b/src/hardware/arachnid-labs-re-load-pro/api.c @@ -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: diff --git a/src/hardware/asix-sigma/api.c b/src/hardware/asix-sigma/api.c index 98d5180b..bc6c87e8 100644 --- a/src/hardware/asix-sigma/api.c +++ b/src/hardware/asix-sigma/api.c @@ -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, diff --git a/src/hardware/atten-pps3xxx/api.c b/src/hardware/atten-pps3xxx/api.c index a685c89c..c88914f9 100644 --- a/src/hardware/atten-pps3xxx/api.c +++ b/src/hardware/atten-pps3xxx/api.c @@ -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; diff --git a/src/hardware/baylibre-acme/api.c b/src/hardware/baylibre-acme/api.c index c467991d..bc93ae75 100644 --- a/src/hardware/baylibre-acme/api.c +++ b/src/hardware/baylibre-acme/api.c @@ -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"), diff --git a/src/hardware/beaglelogic/api.c b/src/hardware/beaglelogic/api.c index 64eb2c92..f2cfce3d 100644 --- a/src/hardware/beaglelogic/api.c +++ b/src/hardware/beaglelogic/api.c @@ -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"), diff --git a/src/hardware/brymen-bm86x/api.c b/src/hardware/brymen-bm86x/api.c index c3c1ea62..7316e362 100644 --- a/src/hardware/brymen-bm86x/api.c +++ b/src/hardware/brymen-bm86x/api.c @@ -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) diff --git a/src/hardware/brymen-dmm/api.c b/src/hardware/brymen-dmm/api.c index 2bf9154b..fdb0e600 100644 --- a/src/hardware/brymen-dmm/api.c +++ b/src/hardware/brymen-dmm/api.c @@ -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) diff --git a/src/hardware/cem-dt-885x/api.c b/src/hardware/cem-dt-885x/api.c index 33dd5c75..4bdbc076 100644 --- a/src/hardware/cem-dt-885x/api.c +++ b/src/hardware/cem-dt-885x/api.c @@ -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; diff --git a/src/hardware/center-3xx/api.c b/src/hardware/center-3xx/api.c index 97869bce..5e34f696 100644 --- a/src/hardware/center-3xx/api.c +++ b/src/hardware/center-3xx/api.c @@ -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) diff --git a/src/hardware/chronovu-la/api.c b/src/hardware/chronovu-la/api.c index 2c4ec3db..d9913adb 100644 --- a/src/hardware/chronovu-la/api.c +++ b/src/hardware/chronovu-la/api.c @@ -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, diff --git a/src/hardware/colead-slm/api.c b/src/hardware/colead-slm/api.c index c2f0ac08..5055056a 100644 --- a/src/hardware/colead-slm/api.c +++ b/src/hardware/colead-slm/api.c @@ -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) diff --git a/src/hardware/conrad-digi-35-cpu/api.c b/src/hardware/conrad-digi-35-cpu/api.c index 60eb46c1..38ae352d 100644 --- a/src/hardware/conrad-digi-35-cpu/api.c +++ b/src/hardware/conrad-digi-35-cpu/api.c @@ -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 = { diff --git a/src/hardware/demo/api.c b/src/hardware/demo/api.c index 4d95ddda..55e342d8 100644 --- a/src/hardware/demo/api.c +++ b/src/hardware/demo/api.c @@ -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, diff --git a/src/hardware/dreamsourcelab-dslogic/api.c b/src/hardware/dreamsourcelab-dslogic/api.c index 7e099f49..d37768e4 100644 --- a/src/hardware/dreamsourcelab-dslogic/api.c +++ b/src/hardware/dreamsourcelab-dslogic/api.c @@ -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)); diff --git a/src/hardware/fluke-dmm/api.c b/src/hardware/fluke-dmm/api.c index 022a2ca9..09f71d1f 100644 --- a/src/hardware/fluke-dmm/api.c +++ b/src/hardware/fluke-dmm/api.c @@ -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) diff --git a/src/hardware/ftdi-la/api.c b/src/hardware/ftdi-la/api.c index 27415ae3..31195e20 100644 --- a/src/hardware/ftdi-la/api.c +++ b/src/hardware/ftdi-la/api.c @@ -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"), diff --git a/src/hardware/fx2lafw/api.c b/src/hardware/fx2lafw/api.c index 48df729e..cc1a7c49 100644 --- a/src/hardware/fx2lafw/api.c +++ b/src/hardware/fx2lafw/api.c @@ -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)); diff --git a/src/hardware/gmc-mh-1x-2x/api.c b/src/hardware/gmc-mh-1x-2x/api.c index bc3ac2f9..0b6c411c 100644 --- a/src/hardware/gmc-mh-1x-2x/api.c +++ b/src/hardware/gmc-mh-1x-2x/api.c @@ -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) diff --git a/src/hardware/gwinstek-gds-800/api.c b/src/hardware/gwinstek-gds-800/api.c index 249074b8..82fbf958 100644 --- a/src/hardware/gwinstek-gds-800/api.c +++ b/src/hardware/gwinstek-gds-800/api.c @@ -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) diff --git a/src/hardware/hantek-6xxx/api.c b/src/hardware/hantek-6xxx/api.c index dd995952..d88f4c68 100644 --- a/src/hardware/hantek-6xxx/api.c +++ b/src/hardware/hantek-6xxx/api.c @@ -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; - - 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"), @@ -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: diff --git a/src/hardware/hantek-dso/api.c b/src/hardware/hantek-dso/api.c index dc94f033..772500ec 100644 --- a/src/hardware/hantek-dso/api.c +++ b/src/hardware/hantek-dso/api.c @@ -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; diff --git a/src/hardware/hp-3457a/api.c b/src/hardware/hp-3457a/api.c index 5c6ea712..23ac9851 100644 --- a/src/hardware/hp-3457a/api.c +++ b/src/hardware/hp-3457a/api.c @@ -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) diff --git a/src/hardware/hung-chang-dso-2100/api.c b/src/hardware/hung-chang-dso-2100/api.c index a3aee05f..655b11c8 100644 --- a/src/hardware/hung-chang-dso-2100/api.c +++ b/src/hardware/hung-chang-dso-2100/api.c @@ -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}")); diff --git a/src/hardware/ikalogic-scanalogic2/api.c b/src/hardware/ikalogic-scanalogic2/api.c index 4afaf30a..be20dfa8 100644 --- a/src/hardware/ikalogic-scanalogic2/api.c +++ b/src/hardware/ikalogic-scanalogic2/api.c @@ -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"), diff --git a/src/hardware/ikalogic-scanaplus/api.c b/src/hardware/ikalogic-scanaplus/api.c index e9c6af04..ab07171c 100644 --- a/src/hardware/ikalogic-scanaplus/api.c +++ b/src/hardware/ikalogic-scanaplus/api.c @@ -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"), diff --git a/src/hardware/kecheng-kc-330b/api.c b/src/hardware/kecheng-kc-330b/api.c index b294b807..b3ca2bb3 100644 --- a/src/hardware/kecheng-kc-330b/api.c +++ b/src/hardware/kecheng-kc-330b/api.c @@ -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++) { diff --git a/src/hardware/kern-scale/api.c b/src/hardware/kern-scale/api.c index 7b65a4d6..bbaacc15 100644 --- a/src/hardware/kern-scale/api.c +++ b/src/hardware/kern-scale/api.c @@ -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) diff --git a/src/hardware/korad-kaxxxxp/api.c b/src/hardware/korad-kaxxxxp/api.c index 5ab95c7f..a28bc1e2 100644 --- a/src/hardware/korad-kaxxxxp/api.c +++ b/src/hardware/korad-kaxxxxp/api.c @@ -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. */ diff --git a/src/hardware/lascar-el-usb/api.c b/src/hardware/lascar-el-usb/api.c index 7f741280..5f92d99a 100644 --- a/src/hardware/lascar-el-usb/api.c +++ b/src/hardware/lascar-el-usb/api.c @@ -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) diff --git a/src/hardware/lecroy-logicstudio/api.c b/src/hardware/lecroy-logicstudio/api.c index a372d2c7..a97112cc 100644 --- a/src/hardware/lecroy-logicstudio/api.c +++ b/src/hardware/lecroy-logicstudio/api.c @@ -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"), diff --git a/src/hardware/lecroy-xstream/api.c b/src/hardware/lecroy-xstream/api.c index 1f150fae..281a3871 100644 --- a/src/hardware/lecroy-xstream/api.c +++ b/src/hardware/lecroy-xstream/api.c @@ -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; - - (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)); diff --git a/src/hardware/link-mso19/api.c b/src/hardware/link-mso19/api.c index bd33d9f2..5658ecec 100644 --- a/src/hardware/link-mso19/api.c +++ b/src/hardware/link-mso19/api.c @@ -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, diff --git a/src/hardware/manson-hcs-3xxx/api.c b/src/hardware/manson-hcs-3xxx/api.c index 5d289c30..8102ba9a 100644 --- a/src/hardware/manson-hcs-3xxx/api.c +++ b/src/hardware/manson-hcs-3xxx/api.c @@ -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. */ diff --git a/src/hardware/maynuo-m97/api.c b/src/hardware/maynuo-m97/api.c index 45bcf970..effa1b0b 100644 --- a/src/hardware/maynuo-m97/api.c +++ b/src/hardware/maynuo-m97/api.c @@ -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: diff --git a/src/hardware/mic-985xx/api.c b/src/hardware/mic-985xx/api.c index 8be5cbef..3af30a2a 100644 --- a/src/hardware/mic-985xx/api.c +++ b/src/hardware/mic-985xx/api.c @@ -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) diff --git a/src/hardware/motech-lps-30x/api.c b/src/hardware/motech-lps-30x/api.c index 84d298b3..45677b42 100644 --- a/src/hardware/motech-lps-30x/api.c +++ b/src/hardware/motech-lps-30x/api.c @@ -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. */ diff --git a/src/hardware/norma-dmm/api.c b/src/hardware/norma-dmm/api.c index 29cdbccd..719eac6b 100644 --- a/src/hardware/norma-dmm/api.c +++ b/src/hardware/norma-dmm/api.c @@ -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) diff --git a/src/hardware/openbench-logic-sniffer/api.c b/src/hardware/openbench-logic-sniffer/api.c index e3bb1fa5..ec22fd45 100644 --- a/src/hardware/openbench-logic-sniffer/api.c +++ b/src/hardware/openbench-logic-sniffer/api.c @@ -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, diff --git a/src/hardware/pce-322a/api.c b/src/hardware/pce-322a/api.c index 14534e2a..1ac30aed 100644 --- a/src/hardware/pce-322a/api.c +++ b/src/hardware/pce-322a/api.c @@ -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) diff --git a/src/hardware/pipistrello-ols/api.c b/src/hardware/pipistrello-ols/api.c index 545dcd14..a9a137be 100644 --- a/src/hardware/pipistrello-ols/api.c +++ b/src/hardware/pipistrello-ols/api.c @@ -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, diff --git a/src/hardware/rigol-ds/api.c b/src/hardware/rigol-ds/api.c index 37a1984d..5e1e9ec7 100644 --- a/src/hardware/rigol-ds/api.c +++ b/src/hardware/rigol-ds/api.c @@ -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; - - /* 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)); @@ -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]); diff --git a/src/hardware/rohde-schwarz-sme-0x/api.c b/src/hardware/rohde-schwarz-sme-0x/api.c index 21ff6334..866ab3c7 100644 --- a/src/hardware/rohde-schwarz-sme-0x/api.c +++ b/src/hardware/rohde-schwarz-sme-0x/api.c @@ -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 = { diff --git a/src/hardware/saleae-logic-pro/api.c b/src/hardware/saleae-logic-pro/api.c index c9819315..9c257d2c 100644 --- a/src/hardware/saleae-logic-pro/api.c +++ b/src/hardware/saleae-logic-pro/api.c @@ -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"), diff --git a/src/hardware/saleae-logic16/api.c b/src/hardware/saleae-logic16/api.c index 721f15a5..9562ac91 100644 --- a/src/hardware/saleae-logic16/api.c +++ b/src/hardware/saleae-logic16/api.c @@ -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"), diff --git a/src/hardware/scpi-pps/api.c b/src/hardware/scpi-pps/api.c index 5d248825..74487962 100644 --- a/src/hardware/scpi-pps/api.c +++ b/src/hardware/scpi-pps/api.c @@ -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. */ diff --git a/src/hardware/serial-dmm/api.c b/src/hardware/serial-dmm/api.c index 99b2a717..5c0e6305 100644 --- a/src/hardware/serial-dmm/api.c +++ b/src/hardware/serial-dmm/api.c @@ -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) diff --git a/src/hardware/sysclk-lwla/api.c b/src/hardware/sysclk-lwla/api.c index ea98a234..1ff70eeb 100644 --- a/src/hardware/sysclk-lwla/api.c +++ b/src/hardware/sysclk-lwla/api.c @@ -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)) diff --git a/src/hardware/teleinfo/api.c b/src/hardware/teleinfo/api.c index 980b5b3e..eb9dd3e0 100644 --- a/src/hardware/teleinfo/api.c +++ b/src/hardware/teleinfo/api.c @@ -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) diff --git a/src/hardware/testo/api.c b/src/hardware/testo/api.c index 062849bf..6c975eed 100644 --- a/src/hardware/testo/api.c +++ b/src/hardware/testo/api.c @@ -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) diff --git a/src/hardware/tondaj-sl-814/api.c b/src/hardware/tondaj-sl-814/api.c index 4330d960..d14f0e6e 100644 --- a/src/hardware/tondaj-sl-814/api.c +++ b/src/hardware/tondaj-sl-814/api.c @@ -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) diff --git a/src/hardware/uni-t-dmm/api.c b/src/hardware/uni-t-dmm/api.c index eccff3cf..aeb69553 100644 --- a/src/hardware/uni-t-dmm/api.c +++ b/src/hardware/uni-t-dmm/api.c @@ -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) diff --git a/src/hardware/uni-t-ut32x/api.c b/src/hardware/uni-t-ut32x/api.c index 7d4ca628..1f4830e4 100644 --- a/src/hardware/uni-t-ut32x/api.c +++ b/src/hardware/uni-t-ut32x/api.c @@ -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; diff --git a/src/hardware/victor-dmm/api.c b/src/hardware/victor-dmm/api.c index ebe56fea..5ed70c80 100644 --- a/src/hardware/victor-dmm/api.c +++ b/src/hardware/victor-dmm/api.c @@ -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) diff --git a/src/hardware/yokogawa-dlm/api.c b/src/hardware/yokogawa-dlm/api.c index 76703d86..650174a0 100644 --- a/src/hardware/yokogawa-dlm/api.c +++ b/src/hardware/yokogawa-dlm/api.c @@ -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; - - /* 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 @@ -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; diff --git a/src/hardware/zeroplus-logic-cube/api.c b/src/hardware/zeroplus-logic-cube/api.c index e8e7d4fb..4ffcced8 100644 --- a/src/hardware/zeroplus-logic-cube/api.c +++ b/src/hardware/zeroplus-logic-cube/api.c @@ -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}")); diff --git a/src/hwdriver.c b/src/hwdriver.c index 3e6b0012..96b6cfac 100644 --- a/src/hwdriver.c +++ b/src/hwdriver.c @@ -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; } diff --git a/src/lcr/es51919.c b/src/lcr/es51919.c index fd26fd9e..7947431e 100644 --- a/src/lcr/es51919.c +++ b/src/lcr/es51919.c @@ -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)); diff --git a/src/libsigrok-internal.h b/src/libsigrok-internal.h index fe2544fa..d4533c9f 100644 --- a/src/libsigrok-internal.h +++ b/src/libsigrok-internal.h @@ -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); diff --git a/src/session_driver.c b/src/session_driver.c index f54ea54f..a5f2e368 100644 --- a/src/session_driver.c +++ b/src/session_driver.c @@ -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) diff --git a/src/std.c b/src/std.c index a4f5d883..bd9c6286 100644 --- a/src/std.c +++ b/src/std.c @@ -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; +}