]> sigrok.org Git - libsigrok.git/commitdiff
drivers: Add and use STD_CONFIG_LIST().
authorUwe Hermann <redacted>
Thu, 13 Jul 2017 19:14:04 +0000 (21:14 +0200)
committerUwe Hermann <redacted>
Wed, 19 Jul 2017 13:11:01 +0000 (15:11 +0200)
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.

62 files changed:
src/hardware/agilent-dmm/api.c
src/hardware/appa-55ii/api.c
src/hardware/arachnid-labs-re-load-pro/api.c
src/hardware/asix-sigma/api.c
src/hardware/atten-pps3xxx/api.c
src/hardware/baylibre-acme/api.c
src/hardware/beaglelogic/api.c
src/hardware/brymen-bm86x/api.c
src/hardware/brymen-dmm/api.c
src/hardware/cem-dt-885x/api.c
src/hardware/center-3xx/api.c
src/hardware/chronovu-la/api.c
src/hardware/colead-slm/api.c
src/hardware/conrad-digi-35-cpu/api.c
src/hardware/demo/api.c
src/hardware/dreamsourcelab-dslogic/api.c
src/hardware/fluke-dmm/api.c
src/hardware/ftdi-la/api.c
src/hardware/fx2lafw/api.c
src/hardware/gmc-mh-1x-2x/api.c
src/hardware/gwinstek-gds-800/api.c
src/hardware/hantek-6xxx/api.c
src/hardware/hantek-dso/api.c
src/hardware/hp-3457a/api.c
src/hardware/hung-chang-dso-2100/api.c
src/hardware/ikalogic-scanalogic2/api.c
src/hardware/ikalogic-scanaplus/api.c
src/hardware/kecheng-kc-330b/api.c
src/hardware/kern-scale/api.c
src/hardware/korad-kaxxxxp/api.c
src/hardware/lascar-el-usb/api.c
src/hardware/lecroy-logicstudio/api.c
src/hardware/lecroy-xstream/api.c
src/hardware/link-mso19/api.c
src/hardware/manson-hcs-3xxx/api.c
src/hardware/maynuo-m97/api.c
src/hardware/mic-985xx/api.c
src/hardware/motech-lps-30x/api.c
src/hardware/norma-dmm/api.c
src/hardware/openbench-logic-sniffer/api.c
src/hardware/pce-322a/api.c
src/hardware/pipistrello-ols/api.c
src/hardware/rigol-ds/api.c
src/hardware/rohde-schwarz-sme-0x/api.c
src/hardware/saleae-logic-pro/api.c
src/hardware/saleae-logic16/api.c
src/hardware/scpi-pps/api.c
src/hardware/serial-dmm/api.c
src/hardware/sysclk-lwla/api.c
src/hardware/teleinfo/api.c
src/hardware/testo/api.c
src/hardware/tondaj-sl-814/api.c
src/hardware/uni-t-dmm/api.c
src/hardware/uni-t-ut32x/api.c
src/hardware/victor-dmm/api.c
src/hardware/yokogawa-dlm/api.c
src/hardware/zeroplus-logic-cube/api.c
src/hwdriver.c
src/lcr/es51919.c
src/libsigrok-internal.h
src/session_driver.c
src/std.c

index 2707976415be6f558c901c84367f93992b9ea0dd..052e503cd297fe2a20855b368522f575e36600f0 100644 (file)
@@ -266,26 +266,10 @@ static int config_list(uint32_t key, GVariant **data, const struct sr_dev_inst *
        GVariant *gvar;
        GVariantBuilder gvb;
 
-       if (key == SR_CONF_SCAN_OPTIONS) {
-               *data = g_variant_new_fixed_array(G_VARIANT_TYPE_UINT32,
-                               scanopts, ARRAY_SIZE(scanopts), sizeof(uint32_t));
-               return SR_OK;
-       }
-
-       if (key == SR_CONF_DEVICE_OPTIONS && !sdi) {
-               *data = g_variant_new_fixed_array(G_VARIANT_TYPE_UINT32,
-                               drvopts, ARRAY_SIZE(drvopts), sizeof(uint32_t));
-               return SR_OK;
-       }
-
-       if (!sdi || cg)
-               return SR_ERR_ARG;
-
        switch (key) {
+       case SR_CONF_SCAN_OPTIONS:
        case SR_CONF_DEVICE_OPTIONS:
-               *data = g_variant_new_fixed_array(G_VARIANT_TYPE_UINT32,
-                               devopts, ARRAY_SIZE(devopts), sizeof(uint32_t));
-               break;
+               return STD_CONFIG_LIST(key, data, sdi, cg, scanopts, drvopts, devopts);
        case SR_CONF_SAMPLERATE:
                g_variant_builder_init(&gvb, G_VARIANT_TYPE("a{sv}"));
                gvar = g_variant_new_fixed_array(G_VARIANT_TYPE("t"), samplerates,
index 05024f9683818d97ce8155b5795d3e9bd7e39a85..eab203dd09ac418b36d723f218b5f6c6ce62ad37 100644 (file)
@@ -166,21 +166,10 @@ static int config_set(uint32_t key, GVariant *data, const struct sr_dev_inst *sd
 static int config_list(uint32_t key, GVariant **data, const struct sr_dev_inst *sdi,
                const struct sr_channel_group *cg)
 {
-       (void)cg;
-
        switch (key) {
        case SR_CONF_SCAN_OPTIONS:
-               *data = g_variant_new_fixed_array(G_VARIANT_TYPE_UINT32,
-                               scanopts, ARRAY_SIZE(scanopts), sizeof(uint32_t));
-               break;
        case SR_CONF_DEVICE_OPTIONS:
-               if (!sdi)
-                       *data = g_variant_new_fixed_array(G_VARIANT_TYPE_UINT32,
-                                       drvopts, ARRAY_SIZE(drvopts), sizeof(uint32_t));
-               else
-                       *data = g_variant_new_fixed_array(G_VARIANT_TYPE_UINT32,
-                                       devopts, ARRAY_SIZE(devopts), sizeof(uint32_t));
-               break;
+               return STD_CONFIG_LIST(key, data, sdi, cg, scanopts, drvopts, devopts);
        case SR_CONF_DATA_SOURCE:
                *data = g_variant_new_strv(data_sources, ARRAY_SIZE(data_sources));
                break;
index bfbdd7d477a54bd4da7daf6db7ca04192fa506a6..9c1fe532b28cda007df115a20ef7294213f730f9 100644 (file)
@@ -152,32 +152,9 @@ static int config_list(uint32_t key, GVariant **data,
 {
        GVariantBuilder gvb;
 
-       /* Always available. */
-       if (key == SR_CONF_SCAN_OPTIONS) {
-               *data = g_variant_new_fixed_array(G_VARIANT_TYPE_UINT32,
-                       scanopts, ARRAY_SIZE(scanopts), sizeof(uint32_t));
-               return SR_OK;
-       }
-
-       if (key == SR_CONF_DEVICE_OPTIONS && !sdi) {
-               *data = g_variant_new_fixed_array(G_VARIANT_TYPE_UINT32,
-                       drvopts, ARRAY_SIZE(drvopts), sizeof(uint32_t));
-               return SR_OK;
-       }
-
-       if (!sdi)
-               return SR_ERR_ARG;
-
        if (!cg) {
                /* No channel group: global options. */
-               switch (key) {
-               case SR_CONF_DEVICE_OPTIONS:
-                       *data = g_variant_new_fixed_array(G_VARIANT_TYPE_UINT32,
-                               devopts, ARRAY_SIZE(devopts), sizeof(uint32_t));
-                       break;
-               default:
-                       return SR_ERR_NA;
-               }
+               return STD_CONFIG_LIST(key, data, sdi, cg, scanopts, drvopts, devopts);
        } else {
                switch (key) {
                case SR_CONF_DEVICE_OPTIONS:
index 98d5180bd2de156a302d26864bd526e64fa5b6e2..bc6c87e86ebd51baf49e5c710f7daa587416b48b 100644 (file)
@@ -246,17 +246,9 @@ static int config_list(uint32_t key, GVariant **data, const struct sr_dev_inst *
        GVariant *gvar;
        GVariantBuilder gvb;
 
-       (void)cg;
-
        switch (key) {
        case SR_CONF_DEVICE_OPTIONS:
-               if (!sdi)
-                       *data = g_variant_new_fixed_array(G_VARIANT_TYPE_UINT32,
-                                       drvopts, ARRAY_SIZE(drvopts), sizeof(uint32_t));
-               else
-                       *data = g_variant_new_fixed_array(G_VARIANT_TYPE_UINT32,
-                                       devopts, ARRAY_SIZE(devopts), sizeof(uint32_t));
-               break;
+               return STD_CONFIG_LIST(key, data, sdi, cg, NULL, drvopts, devopts);
        case SR_CONF_SAMPLERATE:
                g_variant_builder_init(&gvb, G_VARIANT_TYPE("a{sv}"));
                gvar = g_variant_new_fixed_array(G_VARIANT_TYPE("t"), samplerates,
index a685c89c6d53fca8069ad7b9bcefe596703b43f7..c88914f9139aca7bd077abcf4eee83b062219170 100644 (file)
@@ -339,31 +339,14 @@ static int config_list(uint32_t key, GVariant **data, const struct sr_dev_inst *
        GVariantBuilder gvb;
        int channel, i;
 
-       /* Always available. */
-       if (key == SR_CONF_SCAN_OPTIONS) {
-               *data = g_variant_new_fixed_array(G_VARIANT_TYPE_UINT32,
-                               scanopts, ARRAY_SIZE(scanopts), sizeof(uint32_t));
-               return SR_OK;
-       }
-
-       if (key == SR_CONF_DEVICE_OPTIONS && !sdi) {
-               *data = g_variant_new_fixed_array(G_VARIANT_TYPE_UINT32,
-                               drvopts, ARRAY_SIZE(drvopts), sizeof(uint32_t));
-               return SR_OK;
-       }
-
-       if (!sdi)
-               return SR_ERR_ARG;
-
-       devc = sdi->priv;
+       devc = (sdi) ? sdi->priv : NULL;
 
        if (!cg) {
                /* No channel group: global options. */
                switch (key) {
+               case SR_CONF_SCAN_OPTIONS:
                case SR_CONF_DEVICE_OPTIONS:
-                       *data = g_variant_new_fixed_array(G_VARIANT_TYPE_UINT32,
-                                       devopts, ARRAY_SIZE(devopts), sizeof(uint32_t));
-                       break;
+                       return STD_CONFIG_LIST(key, data, sdi, cg, scanopts, drvopts, devopts);
                case SR_CONF_CHANNEL_CONFIG:
                        if (devc->model->channel_modes == CHANMODE_INDEPENDENT) {
                                /* The 1-channel models. */
@@ -378,8 +361,7 @@ static int config_list(uint32_t key, GVariant **data, const struct sr_dev_inst *
                }
        } else {
                /* Channel group specified: per-channel options. */
-               if (!sdi)
-                       return SR_ERR_ARG;
+
                /* We only ever have one channel per channel group in this driver. */
                ch = cg->channels->data;
                channel = ch->index;
index c467991de3d993294c419f9151fa7dc72bd25cd7..bc93ae7520cebf446f3d7349d00696521fb2c80b 100644 (file)
@@ -219,15 +219,10 @@ static int config_list(uint32_t key, GVariant **data,
        GVariantBuilder gvb;
        int num_devopts_cg = 0;
 
-       (void)sdi;
-       (void)cg;
-
        if (!cg) {
                switch (key) {
                case SR_CONF_DEVICE_OPTIONS:
-                       *data = g_variant_new_fixed_array(G_VARIANT_TYPE_UINT32,
-                               devopts, ARRAY_SIZE(devopts), sizeof(uint32_t));
-                       break;
+                       return STD_CONFIG_LIST(key, data, sdi, cg, NULL, NULL, devopts);
                case SR_CONF_SAMPLERATE:
                        g_variant_builder_init(&gvb, G_VARIANT_TYPE("a{sv}"));
                        gvar = g_variant_new_fixed_array(G_VARIANT_TYPE("t"),
index 64eb2c9268fc1811ff8b9c94fa8ea69974de45e6..f2cfce3dfd219118592a1ebeb125fcef53dfb85a 100644 (file)
@@ -245,18 +245,10 @@ static int config_list(uint32_t key, GVariant **data, const struct sr_dev_inst *
        GVariant *gvar;
        GVariantBuilder gvb;
 
-       (void)sdi;
-       (void)cg;
-
        switch (key) {
        case SR_CONF_SCAN_OPTIONS:
-               *data = g_variant_new_fixed_array(G_VARIANT_TYPE_UINT32,
-                               scanopts, ARRAY_SIZE(scanopts), sizeof(uint32_t));
-               break;
        case SR_CONF_DEVICE_OPTIONS:
-               *data = g_variant_new_fixed_array(G_VARIANT_TYPE_UINT32,
-                               devopts, ARRAY_SIZE(devopts), sizeof(uint32_t));
-               break;
+               return STD_CONFIG_LIST(key, data, sdi, cg, scanopts, NULL, devopts);
        case SR_CONF_SAMPLERATE:
                g_variant_builder_init(&gvb, G_VARIANT_TYPE("a{sv}"));
                gvar = g_variant_new_fixed_array(G_VARIANT_TYPE("t"),
index c3c1ea621ff5f5a6e1005cdb271eb078de62f7a8..7316e362dd8e4ea12ad2ab09bb94e396dbcc1b31 100644 (file)
@@ -169,23 +169,7 @@ static int config_set(uint32_t key, GVariant *data, const struct sr_dev_inst *sd
 static int config_list(uint32_t key, GVariant **data, const struct sr_dev_inst *sdi,
                const struct sr_channel_group *cg)
 {
-       (void)sdi;
-       (void)cg;
-
-       switch (key) {
-       case SR_CONF_SCAN_OPTIONS:
-               *data = g_variant_new_fixed_array(G_VARIANT_TYPE_UINT32,
-                               scanopts, ARRAY_SIZE(scanopts), sizeof(uint32_t));
-               break;
-       case SR_CONF_DEVICE_OPTIONS:
-               *data = g_variant_new_fixed_array(G_VARIANT_TYPE_UINT32,
-                               devopts, ARRAY_SIZE(devopts), sizeof(uint32_t));
-               break;
-       default:
-               return SR_ERR_NA;
-       }
-
-       return SR_OK;
+       return STD_CONFIG_LIST(key, data, sdi, cg, scanopts, NULL, devopts);
 }
 
 static int dev_acquisition_start(const struct sr_dev_inst *sdi)
index 2bf9154b446f00d22dc466d2d16e638ef347da99..fdb0e6006c5fd70f6602a9b0a1f846feb4023875 100644 (file)
@@ -133,23 +133,7 @@ static int config_set(uint32_t key, GVariant *data, const struct sr_dev_inst *sd
 static int config_list(uint32_t key, GVariant **data, const struct sr_dev_inst *sdi,
                const struct sr_channel_group *cg)
 {
-       (void)sdi;
-       (void)cg;
-
-       switch (key) {
-       case SR_CONF_SCAN_OPTIONS:
-               *data = g_variant_new_fixed_array(G_VARIANT_TYPE_UINT32,
-                               scanopts, ARRAY_SIZE(scanopts), sizeof(uint32_t));
-               break;
-       case SR_CONF_DEVICE_OPTIONS:
-               *data = g_variant_new_fixed_array(G_VARIANT_TYPE_UINT32,
-                               devopts, ARRAY_SIZE(devopts), sizeof(uint32_t));
-               break;
-       default:
-               return SR_ERR_NA;
-       }
-
-       return SR_OK;
+       return STD_CONFIG_LIST(key, data, sdi, cg, scanopts, NULL, devopts);
 }
 
 static int dev_acquisition_start(const struct sr_dev_inst *sdi)
index 33dd5c754c66c82cd78caa70eb0ec547bfb06ec2..4bdbc076c212df008b086220766b43a7b2455dce 100644 (file)
@@ -288,49 +288,31 @@ static int config_list(uint32_t key, GVariant **data, const struct sr_dev_inst *
        GVariantBuilder gvb;
        unsigned int i;
 
-       (void)cg;
-
-       if (!sdi) {
-               switch (key) {
-               case SR_CONF_SCAN_OPTIONS:
-                       *data = g_variant_new_fixed_array(G_VARIANT_TYPE_UINT32,
-                                       scanopts, ARRAY_SIZE(scanopts), sizeof(uint32_t));
-                       break;
-               case SR_CONF_DEVICE_OPTIONS:
-                       *data = g_variant_new_fixed_array(G_VARIANT_TYPE_UINT32,
-                                       drvopts, ARRAY_SIZE(drvopts), sizeof(uint32_t));
-                       break;
-               default:
-                       return SR_ERR_NA;
-               }
-       } else {
-               switch (key) {
-               case SR_CONF_DEVICE_OPTIONS:
-                       *data = g_variant_new_fixed_array(G_VARIANT_TYPE_UINT32,
-                                       devopts, ARRAY_SIZE(devopts), sizeof(uint32_t));
-                       break;
-               case SR_CONF_SPL_WEIGHT_FREQ:
-                       *data = g_variant_new_strv(weight_freq, ARRAY_SIZE(weight_freq));
-                       break;
-               case SR_CONF_SPL_WEIGHT_TIME:
-                       *data = g_variant_new_strv(weight_time, ARRAY_SIZE(weight_time));
-                       break;
-               case SR_CONF_SPL_MEASUREMENT_RANGE:
-                       g_variant_builder_init(&gvb, G_VARIANT_TYPE_ARRAY);
-                       for (i = 0; i < ARRAY_SIZE(meas_ranges); i++) {
-                               range[0] = g_variant_new_uint64(meas_ranges[i][0]);
-                               range[1] = g_variant_new_uint64(meas_ranges[i][1]);
-                               tuple = g_variant_new_tuple(range, 2);
-                               g_variant_builder_add_value(&gvb, tuple);
-                       }
-                       *data = g_variant_builder_end(&gvb);
-                       break;
-               case SR_CONF_DATA_SOURCE:
-                       *data = g_variant_new_strv(data_sources, ARRAY_SIZE(data_sources));
-                       break;
-               default:
-                       return SR_ERR_NA;
+       switch (key) {
+       case SR_CONF_SCAN_OPTIONS:
+       case SR_CONF_DEVICE_OPTIONS:
+               return STD_CONFIG_LIST(key, data, sdi, cg, scanopts, drvopts, devopts);
+       case SR_CONF_SPL_WEIGHT_FREQ:
+               *data = g_variant_new_strv(weight_freq, ARRAY_SIZE(weight_freq));
+               break;
+       case SR_CONF_SPL_WEIGHT_TIME:
+               *data = g_variant_new_strv(weight_time, ARRAY_SIZE(weight_time));
+               break;
+       case SR_CONF_SPL_MEASUREMENT_RANGE:
+               g_variant_builder_init(&gvb, G_VARIANT_TYPE_ARRAY);
+               for (i = 0; i < ARRAY_SIZE(meas_ranges); i++) {
+                       range[0] = g_variant_new_uint64(meas_ranges[i][0]);
+                       range[1] = g_variant_new_uint64(meas_ranges[i][1]);
+                       tuple = g_variant_new_tuple(range, 2);
+                       g_variant_builder_add_value(&gvb, tuple);
                }
+               *data = g_variant_builder_end(&gvb);
+               break;
+       case SR_CONF_DATA_SOURCE:
+               *data = g_variant_new_strv(data_sources, ARRAY_SIZE(data_sources));
+               break;
+       default:
+               return SR_ERR_NA;
        }
 
        return SR_OK;
index 97869bce395056ce10995940dd190519b3e299ca..5e34f696c1f7fc43273c8a07a01a25a84b851ef4 100644 (file)
@@ -135,26 +135,7 @@ static int config_set(uint32_t key, GVariant *data, const struct sr_dev_inst *sd
 static int config_list(uint32_t key, GVariant **data, const struct sr_dev_inst *sdi,
                const struct sr_channel_group *cg)
 {
-       (void)cg;
-
-       switch (key) {
-       case SR_CONF_SCAN_OPTIONS:
-               *data = g_variant_new_fixed_array(G_VARIANT_TYPE_UINT32,
-                               scanopts, ARRAY_SIZE(scanopts), sizeof(uint32_t));
-               break;
-       case SR_CONF_DEVICE_OPTIONS:
-               if (!sdi)
-                       *data = g_variant_new_fixed_array(G_VARIANT_TYPE_UINT32,
-                               drvopts, ARRAY_SIZE(drvopts), sizeof(uint32_t));
-               else
-                       *data = g_variant_new_fixed_array(G_VARIANT_TYPE_UINT32,
-                               devopts, ARRAY_SIZE(devopts), sizeof(uint32_t));
-               break;
-       default:
-               return SR_ERR_NA;
-       }
-
-       return SR_OK;
+       return STD_CONFIG_LIST(key, data, sdi, cg, scanopts, drvopts, devopts);
 }
 
 static int dev_acquisition_start(const struct sr_dev_inst *sdi, int idx)
index 2c4ec3db60e42aedac74981b5fbacaa33205e099..d9913adbc619244c8381eedbc83ec011387ae00e 100644 (file)
@@ -357,25 +357,13 @@ static int config_list(uint32_t key, GVariant **data, const struct sr_dev_inst *
        GVariantBuilder gvb;
        struct dev_context *devc;
 
-       (void)cg;
+       devc = (sdi) ? sdi->priv : NULL;
 
        switch (key) {
        case SR_CONF_SCAN_OPTIONS:
-               *data = g_variant_new_fixed_array(G_VARIANT_TYPE_UINT32,
-                               scanopts, ARRAY_SIZE(scanopts), sizeof(uint32_t));
-               break;
        case SR_CONF_DEVICE_OPTIONS:
-               if (!sdi)
-                       *data = g_variant_new_fixed_array(G_VARIANT_TYPE_UINT32,
-                                       drvopts, ARRAY_SIZE(drvopts), sizeof(uint32_t));
-               else
-                       *data = g_variant_new_fixed_array(G_VARIANT_TYPE_UINT32,
-                                       devopts, ARRAY_SIZE(devopts), sizeof(uint32_t));
-               break;
+               return STD_CONFIG_LIST(key, data, sdi, cg, scanopts, drvopts, devopts);
        case SR_CONF_SAMPLERATE:
-               if (!sdi)
-                       return SR_ERR_BUG;
-               devc = sdi->priv;
                cv_fill_samplerates_if_needed(sdi);
                g_variant_builder_init(&gvb, G_VARIANT_TYPE("a{sv}"));
                gvar = g_variant_new_fixed_array(G_VARIANT_TYPE("t"),
@@ -386,7 +374,7 @@ static int config_list(uint32_t key, GVariant **data, const struct sr_dev_inst *
                *data = g_variant_builder_end(&gvb);
                break;
        case SR_CONF_LIMIT_SAMPLES:
-               if (!sdi || !sdi->priv || !(devc = sdi->priv) || !devc->prof)
+               if (!devc->prof)
                        return SR_ERR_BUG;
                grange[0] = g_variant_new_uint64(0);
                if (devc->prof->model == CHRONOVU_LA8)
@@ -396,7 +384,7 @@ static int config_list(uint32_t key, GVariant **data, const struct sr_dev_inst *
                *data = g_variant_new_tuple(grange, 2);
                break;
        case SR_CONF_TRIGGER_MATCH:
-               if (!sdi || !sdi->priv || !(devc = sdi->priv) || !devc->prof)
+               if (!devc->prof)
                        return SR_ERR_BUG;
                *data = g_variant_new_fixed_array(G_VARIANT_TYPE_INT32,
                                trigger_matches, devc->prof->num_trigger_matches,
index c2f0ac08a5b62c7c47d096f3ceb60e2dd7fab659..5055056a44616384b311bf421e399c99ccd5ce17 100644 (file)
@@ -96,23 +96,7 @@ static int config_set(uint32_t key, GVariant *data, const struct sr_dev_inst *sd
 static int config_list(uint32_t key, GVariant **data, const struct sr_dev_inst *sdi,
                const struct sr_channel_group *cg)
 {
-       (void)sdi;
-       (void)cg;
-
-       switch (key) {
-       case SR_CONF_SCAN_OPTIONS:
-               *data = g_variant_new_fixed_array(G_VARIANT_TYPE_UINT32,
-                               scanopts, ARRAY_SIZE(scanopts), sizeof(uint32_t));
-               break;
-       case SR_CONF_DEVICE_OPTIONS:
-               *data = g_variant_new_fixed_array(G_VARIANT_TYPE_UINT32,
-                               devopts, ARRAY_SIZE(devopts), sizeof(uint32_t));
-               break;
-       default:
-               return SR_ERR_NA;
-       }
-
-       return SR_OK;
+       return STD_CONFIG_LIST(key, data, sdi, cg, scanopts, NULL, devopts);
 }
 
 static int dev_acquisition_start(const struct sr_dev_inst *sdi)
index 60eb46c1932ec1402c36c9a1fceebd7e4e5eee70..38ae352d65e3216be6a4cc116702ce851e0ba152 100644 (file)
@@ -136,23 +136,7 @@ static int config_set(uint32_t key, GVariant *data, const struct sr_dev_inst *sd
 static int config_list(uint32_t key, GVariant **data, const struct sr_dev_inst *sdi,
                const struct sr_channel_group *cg)
 {
-       (void)sdi;
-       (void)cg;
-
-       switch (key) {
-       case SR_CONF_SCAN_OPTIONS:
-               *data = g_variant_new_fixed_array(G_VARIANT_TYPE_UINT32,
-                               scanopts, ARRAY_SIZE(scanopts), sizeof(uint32_t));
-               break;
-       case SR_CONF_DEVICE_OPTIONS:
-               *data = g_variant_new_fixed_array(G_VARIANT_TYPE_UINT32,
-                               devopts, ARRAY_SIZE(devopts), sizeof(uint32_t));
-               break;
-       default:
-               return SR_ERR_NA;
-       }
-
-       return SR_OK;
+       return STD_CONFIG_LIST(key, data, sdi, cg, scanopts, NULL, devopts);
 }
 
 static struct sr_dev_driver conrad_digi_35_cpu_driver_info = {
index 4d95ddda3f13776ee30973445ed6e3e95d8fc521..55e342d81d01063c4f5e93b104229d491fed4097 100644 (file)
@@ -358,27 +358,11 @@ static int config_list(uint32_t key, GVariant **data, const struct sr_dev_inst *
        GVariant *gvar;
        GVariantBuilder gvb;
 
-       if (key == SR_CONF_SCAN_OPTIONS) {
-               *data = g_variant_new_fixed_array(G_VARIANT_TYPE_UINT32,
-                               scanopts, ARRAY_SIZE(scanopts), sizeof(uint32_t));
-               return SR_OK;
-       }
-
-       if (key == SR_CONF_DEVICE_OPTIONS && !sdi) {
-               *data = g_variant_new_fixed_array(G_VARIANT_TYPE_UINT32,
-                               drvopts, ARRAY_SIZE(drvopts), sizeof(uint32_t));
-               return SR_OK;
-       }
-
-       if (!sdi)
-               return SR_ERR_ARG;
-
        if (!cg) {
                switch (key) {
+               case SR_CONF_SCAN_OPTIONS:
                case SR_CONF_DEVICE_OPTIONS:
-                       *data = g_variant_new_fixed_array(G_VARIANT_TYPE_UINT32,
-                                       devopts, ARRAY_SIZE(devopts), sizeof(uint32_t));
-                       break;
+                       return STD_CONFIG_LIST(key, data, sdi, cg, scanopts, drvopts, devopts);
                case SR_CONF_SAMPLERATE:
                        g_variant_builder_init(&gvb, G_VARIANT_TYPE("a{sv}"));
                        gvar = g_variant_new_fixed_array(G_VARIANT_TYPE("t"), samplerates,
index 7e099f49a82b8fb121fc9559877e2278ea495248..d37768e4ea50698388ad5f3a826b17ef1bc77fda 100644 (file)
@@ -553,34 +553,21 @@ static int config_set(uint32_t key, GVariant *data,
 static int config_list(uint32_t key, GVariant **data,
        const struct sr_dev_inst *sdi, const struct sr_channel_group *cg)
 {
-       struct dev_context *devc = NULL;
+       struct dev_context *devc;
        GVariant *gvar, *range[2];
        GVariantBuilder gvb;
        unsigned int i;
        double v;
 
-       (void)cg;
+       devc = (sdi) ? sdi->priv : NULL;
 
        switch (key) {
        case SR_CONF_SCAN_OPTIONS:
-               *data = g_variant_new_fixed_array(G_VARIANT_TYPE_UINT32,
-                               scanopts, ARRAY_SIZE(scanopts), sizeof(uint32_t));
-               break;
        case SR_CONF_DEVICE_OPTIONS:
-               if (!sdi) {
-                       *data = g_variant_new_fixed_array(G_VARIANT_TYPE_UINT32,
-                               drvopts, ARRAY_SIZE(drvopts), sizeof(uint32_t));
-               } else {
-                       devc = sdi->priv;
-                       *data = g_variant_new_fixed_array(G_VARIANT_TYPE_UINT32,
-                                                         devopts, ARRAY_SIZE(devopts), sizeof(uint32_t));
-               }
-               break;
+               return STD_CONFIG_LIST(key, data, sdi, cg, scanopts, drvopts, devopts);
        case SR_CONF_VOLTAGE_THRESHOLD:
-               if (sdi->priv)
-                       devc = sdi->priv;
                g_variant_builder_init(&gvb, G_VARIANT_TYPE_ARRAY);
-               if (devc && !strcmp(devc->profile->model, "DSLogic")) {
+               if (!strcmp(devc->profile->model, "DSLogic")) {
                        for (i = 0; i < ARRAY_SIZE(voltage_thresholds); i++) {
                                range[0] = g_variant_new_double(voltage_thresholds[i].low);
                                range[1] = g_variant_new_double(voltage_thresholds[i].high);
@@ -598,7 +585,6 @@ static int config_list(uint32_t key, GVariant **data,
                *data = g_variant_builder_end(&gvb);
                break;
        case SR_CONF_SAMPLERATE:
-               devc = sdi->priv;
                g_variant_builder_init(&gvb, G_VARIANT_TYPE("a{sv}"));
                gvar = g_variant_new_fixed_array(G_VARIANT_TYPE("t"), devc->samplerates,
                                devc->num_samplerates, sizeof(uint64_t));
index 022a2ca9c621c76aff8fe29fbdfc0b91889b0f6d..09f71d1fc0b3c52248c06fb04aeb3df81ce5a3fd 100644 (file)
@@ -194,23 +194,7 @@ static int config_set(uint32_t key, GVariant *data, const struct sr_dev_inst *sd
 static int config_list(uint32_t key, GVariant **data, const struct sr_dev_inst *sdi,
                const struct sr_channel_group *cg)
 {
-       (void)sdi;
-       (void)cg;
-
-       switch (key) {
-       case SR_CONF_SCAN_OPTIONS:
-               *data = g_variant_new_fixed_array(G_VARIANT_TYPE_UINT32,
-                               scanopts, ARRAY_SIZE(scanopts), sizeof(uint32_t));
-               break;
-       case SR_CONF_DEVICE_OPTIONS:
-               *data = g_variant_new_fixed_array(G_VARIANT_TYPE_UINT32,
-                               devopts, ARRAY_SIZE(devopts), sizeof(uint32_t));
-               break;
-       default:
-               return SR_ERR_NA;
-       }
-
-       return SR_OK;
+       return STD_CONFIG_LIST(key, data, sdi, cg, scanopts, NULL, devopts);
 }
 
 static int dev_acquisition_start(const struct sr_dev_inst *sdi)
index 27415ae3ec0389a08994497632cbaf6a7f516cb9..31195e20e77aa1a71e153b0a87bd2e76afd0be1c 100644 (file)
@@ -388,18 +388,10 @@ static int config_list(uint32_t key, GVariant **data,
        GVariant *gvar;
        GVariantBuilder gvb;
 
-       (void)sdi;
-       (void)cg;
-
        switch (key) {
        case SR_CONF_SCAN_OPTIONS:
-               *data = g_variant_new_fixed_array(G_VARIANT_TYPE_UINT32,
-                       scanopts, ARRAY_SIZE(scanopts), sizeof(uint32_t));
-               break;
        case SR_CONF_DEVICE_OPTIONS:
-               *data = g_variant_new_fixed_array(G_VARIANT_TYPE_UINT32,
-                       devopts, ARRAY_SIZE(devopts), sizeof(uint32_t));
-               break;
+               return STD_CONFIG_LIST(key, data, sdi, cg, scanopts, NULL, devopts);
        case SR_CONF_SAMPLERATE:
                g_variant_builder_init(&gvb, G_VARIANT_TYPE("a{sv}"));
                gvar = g_variant_new_fixed_array(G_VARIANT_TYPE("t"),
index 48df729e3164ca103269f73ce85df063513207c8..cc1a7c499ededf8d5073f47470b4dfb3024e324b 100644 (file)
@@ -536,25 +536,13 @@ static int config_list(uint32_t key, GVariant **data,
        GVariant *gvar;
        GVariantBuilder gvb;
 
-       (void)cg;
+       devc = (sdi) ? sdi->priv : NULL;
 
        switch (key) {
        case SR_CONF_SCAN_OPTIONS:
-               *data = g_variant_new_fixed_array(G_VARIANT_TYPE_UINT32,
-                               scanopts, ARRAY_SIZE(scanopts), sizeof(uint32_t));
-               break;
        case SR_CONF_DEVICE_OPTIONS:
-               if (!sdi) {
-                       *data = g_variant_new_fixed_array(G_VARIANT_TYPE_UINT32,
-                               drvopts, ARRAY_SIZE(drvopts), sizeof(uint32_t));
-               } else {
-                       devc = sdi->priv;
-                       *data = g_variant_new_fixed_array(G_VARIANT_TYPE_UINT32,
-                                                         devopts, ARRAY_SIZE(devopts), sizeof(uint32_t));
-               }
-               break;
+               return STD_CONFIG_LIST(key, data, sdi, cg, scanopts, drvopts, devopts);
        case SR_CONF_SAMPLERATE:
-               devc = sdi->priv;
                g_variant_builder_init(&gvb, G_VARIANT_TYPE("a{sv}"));
                gvar = g_variant_new_fixed_array(G_VARIANT_TYPE("t"), devc->samplerates,
                                devc->num_samplerates, sizeof(uint64_t));
index bc3ac2f94fe5aa105e091594bbd1aba289a53be7..0b6c411ccf2c98f4b1e5088a33bfea246727a973 100644 (file)
@@ -361,55 +361,18 @@ static int config_get(uint32_t key, GVariant **data, const struct sr_dev_inst *s
        return SR_OK;
 }
 
-/** Implementation of config_list, auxiliary function for common parts. */
-static int config_list_common(uint32_t key, GVariant **data, const struct sr_dev_inst *sdi,
-               const struct sr_channel_group *cg)
-{
-       (void)sdi;
-       (void)cg;
-
-       switch (key) {
-       case SR_CONF_SCAN_OPTIONS:
-               *data = g_variant_new_fixed_array(G_VARIANT_TYPE_UINT32,
-                               scanopts, ARRAY_SIZE(scanopts), sizeof(uint32_t));
-               break;
-       default:
-               return SR_ERR_NA;
-       }
-
-       return SR_OK;
-}
-
 /** Implementation of config_list for Metrahit 1x/2x send mode */
 static int config_list_sm(uint32_t key, GVariant **data, const struct sr_dev_inst *sdi,
                          const struct sr_channel_group *cg)
 {
-       switch (key) {
-       case SR_CONF_DEVICE_OPTIONS:
-               *data = g_variant_new_fixed_array(G_VARIANT_TYPE_UINT32,
-                               devopts_sm, ARRAY_SIZE(devopts_sm), sizeof(uint32_t));
-               break;
-       default:
-               return config_list_common(key, data, sdi, cg);
-       }
-
-       return SR_OK;
+       return STD_CONFIG_LIST(key, data, sdi, cg, scanopts, NULL, devopts_sm);
 }
 
 /** Implementation of config_list for Metrahit 2x bidirectional mode */
 static int config_list_bd(uint32_t key, GVariant **data, const struct sr_dev_inst *sdi,
                          const struct sr_channel_group *cg)
 {
-       switch (key) {
-       case SR_CONF_DEVICE_OPTIONS:
-               *data = g_variant_new_fixed_array(G_VARIANT_TYPE_UINT32,
-                               devopts_bd, ARRAY_SIZE(devopts_bd), sizeof(uint32_t));
-               break;
-       default:
-               return config_list_common(key, data, sdi, cg);
-       }
-
-       return SR_OK;
+       return STD_CONFIG_LIST(key, data, sdi, cg, scanopts, NULL, devopts_bd);
 }
 
 static int dev_acquisition_start_1x_2x_rs232(const struct sr_dev_inst *sdi)
index 249074b891834ba10cb90559bd47473f1af2811e..82fbf958cef0f5451ab8f23a09a50edf916051a2 100644 (file)
@@ -162,23 +162,7 @@ static int config_set(uint32_t key, GVariant *data, const struct sr_dev_inst *sd
 static int config_list(uint32_t key, GVariant **data, const struct sr_dev_inst *sdi,
                const struct sr_channel_group *cg)
 {
-       (void)sdi;
-       (void)cg;
-
-       switch (key) {
-       case SR_CONF_SCAN_OPTIONS:
-               *data = g_variant_new_fixed_array(G_VARIANT_TYPE_UINT32,
-                       scanopts, ARRAY_SIZE(scanopts), sizeof(uint32_t));
-               return SR_OK;
-       case SR_CONF_DEVICE_OPTIONS:
-               *data = g_variant_new_fixed_array(G_VARIANT_TYPE_UINT32,
-                       devopts, ARRAY_SIZE(devopts), sizeof(uint32_t));
-               return SR_OK;
-       default:
-               return SR_ERR_NA;
-       }
-
-       return SR_OK;
+       return STD_CONFIG_LIST(key, data, sdi, cg, scanopts, NULL, devopts);
 }
 
 static int dev_acquisition_start(const struct sr_dev_inst *sdi)
index dd995952d30062806daa86f739fcd193303bd872..d88f4c6847bef4316bda03a08d3fb8d6f1b69e19 100644 (file)
@@ -462,27 +462,15 @@ static int config_list(uint32_t key, GVariant **data, const struct sr_dev_inst *
        GVariantBuilder gvb;
        unsigned int i;
        GVariant *gvar;
-       struct dev_context *devc = NULL;
-
-       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:
index dc94f033c806c527e8277964dd3b83a983f15597..772500ec0a9d8a795c55e02d3662c0184abbe7d1 100644 (file)
@@ -599,25 +599,11 @@ static int config_list(uint32_t key, GVariant **data, const struct sr_dev_inst *
        GVariantBuilder gvb;
        unsigned int i;
 
-       if (key == SR_CONF_SCAN_OPTIONS) {
-               *data = g_variant_new_fixed_array(G_VARIANT_TYPE_UINT32,
-                               scanopts, ARRAY_SIZE(scanopts), sizeof(uint32_t));
-               return SR_OK;
-       } else if (key == SR_CONF_DEVICE_OPTIONS && !sdi) {
-               *data = g_variant_new_fixed_array(G_VARIANT_TYPE_UINT32,
-                               drvopts, ARRAY_SIZE(drvopts), sizeof(uint32_t));
-               return SR_OK;
-       }
-
-       if (!sdi)
-               return SR_ERR_ARG;
-
        if (!cg) {
                switch (key) {
+               case SR_CONF_SCAN_OPTIONS:
                case SR_CONF_DEVICE_OPTIONS:
-                       *data = g_variant_new_fixed_array(G_VARIANT_TYPE_UINT32,
-                                       devopts, ARRAY_SIZE(devopts), sizeof(uint32_t));
-                       break;
+                       return STD_CONFIG_LIST(key, data, sdi, cg, scanopts, drvopts, devopts);
                case SR_CONF_BUFFERSIZE:
                        if (!sdi)
                                return SR_ERR_ARG;
index 5c6ea7121e18ae4ba719e156998536e0bfdacb78..23ac98517fbcc94c06744cea82ee45e66cf76714 100644 (file)
@@ -282,35 +282,12 @@ static int config_set(uint32_t key, GVariant *data,
 static int config_list(uint32_t key, GVariant **data,
        const struct sr_dev_inst *sdi, const struct sr_channel_group *cg)
 {
-       if (key == SR_CONF_SCAN_OPTIONS) {
-               *data = g_variant_new_fixed_array(G_VARIANT_TYPE_UINT32,
-                       scanopts, ARRAY_SIZE(scanopts), sizeof(uint32_t));
-               return SR_OK;
-       } else if ((key == SR_CONF_DEVICE_OPTIONS) && !sdi) {
-               *data = g_variant_new_fixed_array(G_VARIANT_TYPE_UINT32,
-                       drvopts, ARRAY_SIZE(drvopts), sizeof(uint32_t));
-               return SR_OK;
-       } else if ((key == SR_CONF_DEVICE_OPTIONS) && !cg) {
-               *data = g_variant_new_fixed_array(G_VARIANT_TYPE_UINT32,
-                       devopts, ARRAY_SIZE(devopts), sizeof(uint32_t));
-               return SR_OK;
-       }
-
-       /* From here on, we're only concerned with channel group config. */
-       if (!cg)
-               return SR_ERR_NA;
-
        /*
         * TODO: Implement channel group configuration when adding support for
         * plug-in cards.
         */
 
-       switch (key) {
-       default:
-               return SR_ERR_NA;
-       }
-
-       return SR_OK;
+       return STD_CONFIG_LIST(key, data, sdi, cg, scanopts, drvopts, devopts);
 }
 
 static void create_channel_index_list(GSList *channels, GArray **arr)
index a3aee05f18458eb401f8983b3d5699a233d487e4..655b11c871d9552da27269943ad481c34e3072d2 100644 (file)
@@ -565,7 +565,7 @@ static int config_list(uint32_t key, GVariant **data, const struct sr_dev_inst *
        int i;
 
        switch (key) {
-               case SR_CONF_SCAN_OPTIONS:
+       case SR_CONF_SCAN_OPTIONS:
        case SR_CONF_DEVICE_OPTIONS:
                break;
        case SR_CONF_SAMPLERATE:
@@ -591,19 +591,12 @@ static int config_list(uint32_t key, GVariant **data, const struct sr_dev_inst *
 
        switch (key) {
        case SR_CONF_SCAN_OPTIONS:
-               *data = g_variant_new_fixed_array(G_VARIANT_TYPE_UINT32,
-                               scanopts, ARRAY_SIZE(scanopts), sizeof(uint32_t));
-               break;
+               return STD_CONFIG_LIST(key, data, sdi, cg, scanopts, NULL, NULL);
        case SR_CONF_DEVICE_OPTIONS:
-               if (!sdi)
-                       *data = g_variant_new_fixed_array(G_VARIANT_TYPE_UINT32,
-                                       drvopts, ARRAY_SIZE(drvopts), sizeof(uint32_t));
-               else if (!cg)
-                       *data = g_variant_new_fixed_array(G_VARIANT_TYPE_UINT32,
-                                       devopts, ARRAY_SIZE(devopts), sizeof(uint32_t));
-               else
-                       *data = g_variant_new_fixed_array(G_VARIANT_TYPE_UINT32,
-                                       cgopts, ARRAY_SIZE(cgopts), sizeof(uint32_t));
+               if (!cg)
+                       return STD_CONFIG_LIST(key, data, sdi, cg, NULL, drvopts, devopts);
+               *data = g_variant_new_fixed_array(G_VARIANT_TYPE_UINT32,
+                               cgopts, ARRAY_SIZE(cgopts), sizeof(uint32_t));
                break;
        case SR_CONF_SAMPLERATE:
                g_variant_builder_init(&gvb, G_VARIANT_TYPE("a{sv}"));
index 4afaf30a9f5b42495c7eb66df7b6f07b9721cf8a..be20dfa87fb84627b98d92a33b358a2bd07f5e8d 100644 (file)
@@ -304,14 +304,9 @@ static int config_list(uint32_t key, GVariant **data, const struct sr_dev_inst *
        GVariant *gvar, *grange[2];
        GVariantBuilder gvb;
 
-       (void)sdi;
-       (void)cg;
-
        switch (key) {
        case SR_CONF_DEVICE_OPTIONS:
-               *data = g_variant_new_fixed_array(G_VARIANT_TYPE_UINT32,
-                               devopts, ARRAY_SIZE(devopts), sizeof(uint32_t));
-               break;
+               return STD_CONFIG_LIST(key, data, sdi, cg, NULL, NULL, devopts);
        case SR_CONF_SAMPLERATE:
                g_variant_builder_init(&gvb, G_VARIANT_TYPE("a{sv}"));
                gvar = g_variant_new_fixed_array(G_VARIANT_TYPE("t"),
index e9c6af04c22f04c8a1b0436e6fafd5d0d7b058e8..ab07171c06210dc419d55661d1386c43bb2a1407 100644 (file)
@@ -270,14 +270,9 @@ static int config_list(uint32_t key, GVariant **data, const struct sr_dev_inst *
        GVariant *gvar;
        GVariantBuilder gvb;
 
-       (void)sdi;
-       (void)cg;
-
        switch (key) {
        case SR_CONF_DEVICE_OPTIONS:
-               *data = g_variant_new_fixed_array(G_VARIANT_TYPE_UINT32,
-                               devopts, ARRAY_SIZE(devopts), sizeof(uint32_t));
-               break;
+               return STD_CONFIG_LIST(key, data, sdi, cg, NULL, NULL, devopts);
        case SR_CONF_SAMPLERATE:
                g_variant_builder_init(&gvb, G_VARIANT_TYPE("a{sv}"));
                gvar = g_variant_new_fixed_array(G_VARIANT_TYPE("t"),
index b294b8073bce09e63dc724bca7386f96e2c5cf9f..b3ca2bb39ee2324d0871bfffc4ef658d5451eabe 100644 (file)
@@ -325,14 +325,9 @@ static int config_list(uint32_t key, GVariant **data, const struct sr_dev_inst *
        GVariantBuilder gvb;
        unsigned int i;
 
-       (void)sdi;
-       (void)cg;
-
        switch (key) {
        case SR_CONF_DEVICE_OPTIONS:
-               *data = g_variant_new_fixed_array(G_VARIANT_TYPE_UINT32,
-                               devopts, ARRAY_SIZE(devopts), sizeof(uint32_t));
-               break;
+               return STD_CONFIG_LIST(key, data, sdi, cg, NULL, NULL, devopts);
        case SR_CONF_SAMPLE_INTERVAL:
                g_variant_builder_init(&gvb, G_VARIANT_TYPE_ARRAY);
                for (i = 0; i < ARRAY_SIZE(kecheng_kc_330b_sample_intervals); i++) {
index 7b65a4d67c2f9e0b835c3413cc24fc2c7f736019..bbaacc154b86d6989a051b4e4f193c6891f1e850 100644 (file)
@@ -125,23 +125,7 @@ static int config_set(uint32_t key, GVariant *data, const struct sr_dev_inst *sd
 static int config_list(uint32_t key, GVariant **data, const struct sr_dev_inst *sdi,
                const struct sr_channel_group *cg)
 {
-       (void)sdi;
-       (void)cg;
-
-       switch (key) {
-       case SR_CONF_SCAN_OPTIONS:
-               *data = g_variant_new_fixed_array(G_VARIANT_TYPE_UINT32,
-                       scanopts, ARRAY_SIZE(scanopts), sizeof(uint32_t));
-               break;
-       case SR_CONF_DEVICE_OPTIONS:
-               *data = g_variant_new_fixed_array(G_VARIANT_TYPE_UINT32,
-                       devopts, ARRAY_SIZE(devopts), sizeof(uint32_t));
-               break;
-       default:
-               return SR_ERR_NA;
-       }
-
-       return SR_OK;
+       return STD_CONFIG_LIST(key, data, sdi, cg, scanopts, NULL, devopts);
 }
 
 static int dev_acquisition_start(const struct sr_dev_inst *sdi)
index 5ab95c7fbaebaac438c699e36fa4809040d22229..a28bc1e234dd9214cfa9192851c72d7a3ff1c3bd 100644 (file)
@@ -282,33 +282,12 @@ static int config_list(uint32_t key, GVariant **data,
        double dval;
        int idx;
 
-       (void)cg;
-
-       /* Always available (with or without sdi). */
-       if (key == SR_CONF_SCAN_OPTIONS) {
-               *data = g_variant_new_fixed_array(G_VARIANT_TYPE_UINT32,
-                       scanopts, ARRAY_SIZE(scanopts), sizeof(uint32_t));
-               return SR_OK;
-       }
-
-       /* Return drvopts without sdi (and devopts with sdi, see below). */
-       if (key == SR_CONF_DEVICE_OPTIONS && !sdi) {
-               *data = g_variant_new_fixed_array(G_VARIANT_TYPE_UINT32,
-                       drvopts, ARRAY_SIZE(drvopts), sizeof(uint32_t));
-               return SR_OK;
-       }
-
-       /* Every other key needs an sdi. */
-       if (!sdi)
-               return SR_ERR_ARG;
-
-       devc = sdi->priv;
+       devc = (sdi) ? sdi->priv : NULL;
 
        switch (key) {
+       case SR_CONF_SCAN_OPTIONS:
        case SR_CONF_DEVICE_OPTIONS:
-               *data = g_variant_new_fixed_array(G_VARIANT_TYPE_UINT32,
-                       devopts, ARRAY_SIZE(devopts), sizeof(uint32_t));
-               break;
+               return STD_CONFIG_LIST(key, data, sdi, cg, scanopts, drvopts, devopts);
        case SR_CONF_VOLTAGE_TARGET:
                g_variant_builder_init(&gvb, G_VARIANT_TYPE_ARRAY);
                /* Min, max, step. */
index 7f741280758d47fd00014a533482981d405a98cb..5f92d99a33cc68fa6e80e6876a2cee9aa6d22958 100644 (file)
@@ -183,23 +183,7 @@ static int config_set(uint32_t key, GVariant *data, const struct sr_dev_inst *sd
 static int config_list(uint32_t key, GVariant **data, const struct sr_dev_inst *sdi,
                const struct sr_channel_group *cg)
 {
-       (void)sdi;
-       (void)cg;
-
-       switch (key) {
-       case SR_CONF_SCAN_OPTIONS:
-               *data = g_variant_new_fixed_array(G_VARIANT_TYPE_UINT32,
-                               scanopts, ARRAY_SIZE(scanopts), sizeof(uint32_t));
-               break;
-       case SR_CONF_DEVICE_OPTIONS:
-               *data = g_variant_new_fixed_array(G_VARIANT_TYPE_UINT32,
-                               devopts, ARRAY_SIZE(devopts), sizeof(uint32_t));
-               break;
-       default:
-               return SR_ERR_NA;
-       }
-
-       return SR_OK;
+       return STD_CONFIG_LIST(key, data, sdi, cg, scanopts, NULL, devopts);
 }
 
 static void LIBUSB_CALL mark_xfer(struct libusb_transfer *xfer)
index a372d2c79ac9a80c5bef4c078838ee1de27ebc72..a97112cc5a966c1479708cfaf36bcd6ed1b91f20 100644 (file)
@@ -406,15 +406,9 @@ static int config_list(uint32_t key, GVariant **data,
        GVariantBuilder vb;
        GVariant *var;
 
-       (void)sdi;
-       (void)cg;
-
        switch (key) {
        case SR_CONF_DEVICE_OPTIONS:
-               *data = g_variant_new_fixed_array(G_VARIANT_TYPE_UINT32,
-                               devopts, ARRAY_SIZE(devopts),
-                               sizeof(uint32_t));
-               break;
+               return STD_CONFIG_LIST(key, data, sdi, cg, NULL, NULL, devopts);
        case SR_CONF_SAMPLERATE:
                g_variant_builder_init(&vb, G_VARIANT_TYPE("a{sv}"));
                var = g_variant_new_fixed_array(G_VARIANT_TYPE("t"),
index 1f150faeb6281c9e0850ce094fe1147ca27d0f0e..281a3871bf0050d74414fdc381770bf63d7bb15d 100644 (file)
@@ -388,41 +388,18 @@ static int config_set(uint32_t key, GVariant *data,
 static int config_list(uint32_t key, GVariant **data,
        const struct sr_dev_inst *sdi, const struct sr_channel_group *cg)
 {
-       struct dev_context *devc = NULL;
-       const struct scope_config *model = NULL;
-
-       (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));
index bd33d9f2c2ad451fad18236b444f82f8a866670d..5658ececa9e8d233829db82640e3a77e47b78329 100644 (file)
@@ -288,14 +288,9 @@ static int config_list(int key, GVariant **data, const struct sr_dev_inst *sdi,
        GVariant *gvar;
        GVariantBuilder gvb;
 
-       (void)cg;
-       (void)sdi;
-
        switch (key) {
        case SR_CONF_DEVICE_OPTIONS:
-               *data = g_variant_new_fixed_array(G_VARIANT_TYPE_UINT32,
-                               devopts, ARRAY_SIZE(devopts), sizeof(uint32_t));
-               break;
+               return STD_CONFIG_LIST(key, data, sdi, cg, NULL, NULL, devopts);
        case SR_CONF_SAMPLERATE:
                g_variant_builder_init(&gvb, G_VARIANT_TYPE("a{sv}"));
                gvar = g_variant_new_fixed_array(G_VARIANT_TYPE("t"), samplerates,
index 5d289c3065a832cd0a42829c0e8116dc9ec78f34..8102ba9aaca3c2022d185f6a4085cace2212bdca 100644 (file)
@@ -286,32 +286,12 @@ static int config_list(uint32_t key, GVariant **data, const struct sr_dev_inst *
        double dval;
        int idx;
 
-       (void)cg;
-
-       /* Always available (with or without sdi). */
-       if (key == SR_CONF_SCAN_OPTIONS) {
-               *data = g_variant_new_fixed_array(G_VARIANT_TYPE_UINT32,
-                       scanopts, ARRAY_SIZE(scanopts), sizeof(uint32_t));
-               return SR_OK;
-       }
-
-       /* Return drvopts without sdi (and devopts with sdi, see below). */
-       if (key == SR_CONF_DEVICE_OPTIONS && !sdi) {
-               *data = g_variant_new_fixed_array(G_VARIANT_TYPE_UINT32,
-                               drvopts, ARRAY_SIZE(drvopts), sizeof(uint32_t));
-               return SR_OK;
-       }
-
-       /* Every other key needs an sdi. */
-       if (!sdi)
-               return SR_ERR_ARG;
-       devc = sdi->priv;
+       devc = (sdi) ? sdi->priv : NULL;
 
        switch (key) {
+       case SR_CONF_SCAN_OPTIONS:
        case SR_CONF_DEVICE_OPTIONS:
-               *data = g_variant_new_fixed_array(G_VARIANT_TYPE_UINT32,
-                               devopts, ARRAY_SIZE(devopts), sizeof(uint32_t));
-               break;
+               return STD_CONFIG_LIST(key, data, sdi, cg, scanopts, drvopts, devopts);
        case SR_CONF_VOLTAGE_TARGET:
                g_variant_builder_init(&gvb, G_VARIANT_TYPE_ARRAY);
                /* Min, max, step. */
index 45bcf9700167e3ba5702c17267ab56fa7d57ee58..effa1b0bede4cc2c9424daf7dbe7f70b67aa3ebe 100644 (file)
@@ -362,31 +362,11 @@ static int config_list(uint32_t key, GVariant **data, const struct sr_dev_inst *
        struct dev_context *devc;
        GVariantBuilder gvb;
 
-       /* Always available, even without sdi. */
-       if (key == SR_CONF_SCAN_OPTIONS) {
-               *data = g_variant_new_fixed_array(G_VARIANT_TYPE_UINT32,
-                               scanopts, ARRAY_SIZE(scanopts), sizeof(uint32_t));
-               return SR_OK;
-       } else if (key == SR_CONF_DEVICE_OPTIONS && !sdi) {
-               *data = g_variant_new_fixed_array(G_VARIANT_TYPE_UINT32,
-                               drvopts, ARRAY_SIZE(drvopts), sizeof(uint32_t));
-               return SR_OK;
-       }
-
-       if (!sdi)
-               return SR_ERR_ARG;
-       devc = sdi->priv;
+       devc = (sdi) ? sdi->priv : NULL;
 
        if (!cg) {
                /* No channel group: global options. */
-               switch (key) {
-               case SR_CONF_DEVICE_OPTIONS:
-                       *data = g_variant_new_fixed_array(G_VARIANT_TYPE_UINT32,
-                                       devopts, ARRAY_SIZE(devopts), sizeof(uint32_t));
-                       break;
-               default:
-                       return SR_ERR_NA;
-               }
+               return STD_CONFIG_LIST(key, data, sdi, cg, scanopts, drvopts, devopts);
        } else {
                switch (key) {
                case SR_CONF_DEVICE_OPTIONS:
index 8be5cbef03cc6b1819d547ad8c48b5e60e5cf18f..3af30a2add2c45945719ba34837de3f476e0fead 100644 (file)
@@ -142,32 +142,18 @@ static int config_set(uint32_t key, GVariant *data, const struct sr_dev_inst *sd
 static int config_list(uint32_t key, GVariant **data, const struct sr_dev_inst *sdi,
                const struct sr_channel_group *cg, int idx)
 {
-       (void)cg;
-
-       switch (key) {
-       case SR_CONF_SCAN_OPTIONS:
-               *data = g_variant_new_fixed_array(G_VARIANT_TYPE_UINT32,
-                               scanopts, ARRAY_SIZE(scanopts), sizeof(uint32_t));
-               break;
-       case SR_CONF_DEVICE_OPTIONS:
-               if (!sdi && !mic_devs[idx].has_humidity) {
-                       *data = g_variant_new_fixed_array(G_VARIANT_TYPE_UINT32,
-                               drvopts_temp, ARRAY_SIZE(drvopts_temp),
-                               sizeof(uint32_t));
-               } else if (!sdi && mic_devs[idx].has_humidity) {
-                       *data = g_variant_new_fixed_array(G_VARIANT_TYPE_UINT32,
-                               drvopts_temp_hum, ARRAY_SIZE(drvopts_temp_hum),
-                               sizeof(uint32_t));
-               } else {
-                       *data = g_variant_new_fixed_array(G_VARIANT_TYPE_UINT32,
-                               devopts, ARRAY_SIZE(devopts), sizeof(uint32_t));
-               }
-               break;
-       default:
-               return SR_ERR_NA;
-       }
-
-       return SR_OK;
+       /*
+        * We can't use the ternary operator here! The result would contain
+        * sizeof((cond) ? A : B) where A/B are arrays of different type/size.
+        * The ternary operator always returns the "common" type of A and B,
+        * which would be a pointer instead of either the A or B arrays.
+        * Thus, sizeof() would yield the size of a pointer, not the size
+        * of either the A or B array, which is not what we want.
+        */
+       if (mic_devs[idx].has_humidity)
+               return STD_CONFIG_LIST(key, data, sdi, cg, scanopts, drvopts_temp_hum, devopts);
+       else
+               return STD_CONFIG_LIST(key, data, sdi, cg, scanopts, drvopts_temp, devopts);
 }
 
 static int dev_acquisition_start(const struct sr_dev_inst *sdi, int idx)
index 84d298b3fe8c66b193ba98f8a116ea71a30b59b7..45677b42d967ca5fabb6a9be4b56595ca3405c43 100644 (file)
@@ -677,32 +677,14 @@ static int config_list(uint32_t key, GVariant **data, const struct sr_dev_inst *
        GVariant *gvar;
        GVariantBuilder gvb;
 
-       /* Driver options, no device instance necessary. */
-       switch (key) {
-       case SR_CONF_SCAN_OPTIONS:
-               *data = g_variant_new_fixed_array(G_VARIANT_TYPE_UINT32,
-                       scanopts, ARRAY_SIZE(scanopts), sizeof(uint32_t));
-               return SR_OK;
-       case SR_CONF_DEVICE_OPTIONS:
-               if (sdi)
-                       break;
-               *data = g_variant_new_fixed_array(G_VARIANT_TYPE_UINT32,
-                       drvopts, ARRAY_SIZE(drvopts), sizeof(uint32_t));
-               return SR_OK;
-       default:
-               if (!sdi)
-                       return SR_ERR_ARG;
-               devc = sdi->priv;
-               break;
-       }
+       devc = (sdi) ? sdi->priv : NULL;
 
        /* Device options, independent from channel groups. */
        if (!cg) {
                switch (key) {
+               case SR_CONF_SCAN_OPTIONS:
                case SR_CONF_DEVICE_OPTIONS:
-                       *data = g_variant_new_fixed_array(G_VARIANT_TYPE_UINT32,
-                                       devopts, ARRAY_SIZE(devopts), sizeof(uint32_t));
-                       return SR_OK;
+                       return STD_CONFIG_LIST(key, data, sdi, cg, scanopts, drvopts, devopts);
                case SR_CONF_CHANNEL_CONFIG:
                        if (devc->model->modelid <= LPS_303) {
                                /* The 1-channel models. */
index 29cdbccdb92d2a37baf9aaa7842a418747a5536d..719eac6bc65da78aec5b3cfe1d2c1012c743f697 100644 (file)
@@ -176,23 +176,7 @@ static int config_set(uint32_t key, GVariant *data, const struct sr_dev_inst *sd
 static int config_list(uint32_t key, GVariant **data, const struct sr_dev_inst *sdi,
                const struct sr_channel_group *cg)
 {
-       (void)sdi;
-       (void)cg;
-
-       switch (key) {
-       case SR_CONF_SCAN_OPTIONS:
-               *data = g_variant_new_fixed_array(G_VARIANT_TYPE_UINT32,
-                               scanopts, ARRAY_SIZE(scanopts), sizeof(uint32_t));
-               break;
-       case SR_CONF_DEVICE_OPTIONS:
-               *data = g_variant_new_fixed_array(G_VARIANT_TYPE_UINT32,
-                               devopts, ARRAY_SIZE(devopts), sizeof(uint32_t));
-               break;
-       default:
-               return SR_ERR_NA;
-       }
-
-       return SR_OK;
+       return STD_CONFIG_LIST(key, data, sdi, cg, scanopts, NULL, devopts);
 }
 
 static int dev_acquisition_start(const struct sr_dev_inst *sdi)
index e3bb1fa5b228e78dccb501f8acf1e2521e8cd34e..ec22fd4572d0e12e4996ba4db6bda00fd09ecf9e 100644 (file)
@@ -327,21 +327,10 @@ static int config_list(uint32_t key, GVariant **data, const struct sr_dev_inst *
        GVariantBuilder gvb;
        int num_ols_changrp, i;
 
-       (void)cg;
-
        switch (key) {
        case SR_CONF_SCAN_OPTIONS:
-               *data = g_variant_new_fixed_array(G_VARIANT_TYPE_UINT32,
-                               scanopts, ARRAY_SIZE(scanopts), sizeof(uint32_t));
-               break;
        case SR_CONF_DEVICE_OPTIONS:
-               if (!sdi)
-                       *data = g_variant_new_fixed_array(G_VARIANT_TYPE_UINT32,
-                                       drvopts, ARRAY_SIZE(drvopts), sizeof(uint32_t));
-               else
-                       *data = g_variant_new_fixed_array(G_VARIANT_TYPE_UINT32,
-                                       devopts, ARRAY_SIZE(devopts), sizeof(uint32_t));
-               break;
+               return STD_CONFIG_LIST(key, data, sdi, cg, scanopts, drvopts, devopts);
        case SR_CONF_SAMPLERATE:
                g_variant_builder_init(&gvb, G_VARIANT_TYPE("a{sv}"));
                gvar = g_variant_new_fixed_array(G_VARIANT_TYPE("t"), samplerates,
index 14534e2ad9991f4af384483c295018bb30a55d8b..1ac30aed0cf5a771571fb9f0da76dca064bc05f8 100644 (file)
@@ -242,55 +242,35 @@ static int config_list(uint32_t key, GVariant **data,
        GVariant *tuple, *range[2];
        GVariantBuilder gvb;
        unsigned int i;
-       int ret;
-
-       (void)cg;
 
-       ret = SR_OK;
-       if (!sdi) {
-               switch (key) {
-               case SR_CONF_SCAN_OPTIONS:
-                       *data = g_variant_new_fixed_array(G_VARIANT_TYPE_UINT32,
-                               scanopts, ARRAY_SIZE(scanopts), sizeof(uint32_t));
-                       break;
-               case SR_CONF_DEVICE_OPTIONS:
-                       *data = g_variant_new_fixed_array(G_VARIANT_TYPE_UINT32,
-                               drvopts, ARRAY_SIZE(drvopts), sizeof(uint32_t));
-                       break;
-               default:
-                       return SR_ERR_NA;
-               }
-       } else {
-               switch (key) {
-               case SR_CONF_DEVICE_OPTIONS:
-                       *data = g_variant_new_fixed_array(G_VARIANT_TYPE_UINT32,
-                               devopts, ARRAY_SIZE(devopts), sizeof(uint32_t));
-                       break;
-               case SR_CONF_SPL_WEIGHT_FREQ:
-                       *data = g_variant_new_strv(weight_freq, ARRAY_SIZE(weight_freq));
-                       break;
-               case SR_CONF_SPL_WEIGHT_TIME:
-                       *data = g_variant_new_strv(weight_time, ARRAY_SIZE(weight_time));
-                       break;
-               case SR_CONF_SPL_MEASUREMENT_RANGE:
-                       g_variant_builder_init(&gvb, G_VARIANT_TYPE_ARRAY);
-                       for (i = 0; i < ARRAY_SIZE(meas_ranges); i++) {
-                               range[0] = g_variant_new_uint64(meas_ranges[i][0]);
-                               range[1] = g_variant_new_uint64(meas_ranges[i][1]);
-                               tuple = g_variant_new_tuple(range, 2);
-                               g_variant_builder_add_value(&gvb, tuple);
-                       }
-                       *data = g_variant_builder_end(&gvb);
-                       break;
-               case SR_CONF_DATA_SOURCE:
-                       *data = g_variant_new_strv(data_sources, ARRAY_SIZE(data_sources));
-                       break;
-               default:
-                       return SR_ERR_NA;
+       switch (key) {
+       case SR_CONF_SCAN_OPTIONS:
+       case SR_CONF_DEVICE_OPTIONS:
+               return STD_CONFIG_LIST(key, data, sdi, cg, scanopts, drvopts, devopts);
+       case SR_CONF_SPL_WEIGHT_FREQ:
+               *data = g_variant_new_strv(weight_freq, ARRAY_SIZE(weight_freq));
+               break;
+       case SR_CONF_SPL_WEIGHT_TIME:
+               *data = g_variant_new_strv(weight_time, ARRAY_SIZE(weight_time));
+               break;
+       case SR_CONF_SPL_MEASUREMENT_RANGE:
+               g_variant_builder_init(&gvb, G_VARIANT_TYPE_ARRAY);
+               for (i = 0; i < ARRAY_SIZE(meas_ranges); i++) {
+                       range[0] = g_variant_new_uint64(meas_ranges[i][0]);
+                       range[1] = g_variant_new_uint64(meas_ranges[i][1]);
+                       tuple = g_variant_new_tuple(range, 2);
+                       g_variant_builder_add_value(&gvb, tuple);
                }
+               *data = g_variant_builder_end(&gvb);
+               break;
+       case SR_CONF_DATA_SOURCE:
+               *data = g_variant_new_strv(data_sources, ARRAY_SIZE(data_sources));
+               break;
+       default:
+               return SR_ERR_NA;
        }
 
-       return ret;
+       return SR_OK;
 }
 
 static int dev_open(struct sr_dev_inst *sdi)
index 545dcd14c870896e19e4a4f98905a89125322fbc..a9a137beafdfb345dd423250ae3e8133eb7a06a5 100644 (file)
@@ -343,13 +343,9 @@ static int config_list(uint32_t key, GVariant **data, const struct sr_dev_inst *
        GVariantBuilder gvb;
        int num_pols_changrp, i;
 
-       (void)cg;
-
        switch (key) {
        case SR_CONF_DEVICE_OPTIONS:
-               *data = g_variant_new_fixed_array(G_VARIANT_TYPE_UINT32,
-                               devopts, ARRAY_SIZE(devopts), sizeof(uint32_t));
-               break;
+               return STD_CONFIG_LIST(key, data, sdi, cg, NULL, NULL, devopts);
        case SR_CONF_SAMPLERATE:
                g_variant_builder_init(&gvb, G_VARIANT_TYPE("a{sv}"));
                gvar = g_variant_new_fixed_array(G_VARIANT_TYPE("t"), samplerates,
index 37a1984d631280a6e820f2b8ca4bd849c45f4700..5e1e9ec7ce9ec11fc3db0e9ee64995d269346288 100644 (file)
@@ -843,42 +843,15 @@ static int config_list(uint32_t key, GVariant **data, const struct sr_dev_inst *
        GVariant *tuple, *rational[2];
        GVariantBuilder gvb;
        unsigned int i;
-       struct dev_context *devc = NULL;
-
-       /* 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]);
index 21ff6334c081e2209bd5ab3cc35fc4eec51731f9..866ab3c74690c980bb44cfbd2dbe7dfa46373ed8 100644 (file)
@@ -217,30 +217,7 @@ static int config_set(uint32_t key, GVariant *data,
 static int config_list(uint32_t key, GVariant **data,
        const struct sr_dev_inst *sdi, const struct sr_channel_group *cg)
 {
-       (void)sdi;
-       (void)cg;
-
-       /* Return drvopts without sdi (and devopts with sdi, see below). */
-       if (key == SR_CONF_DEVICE_OPTIONS && !sdi) {
-               *data = g_variant_new_fixed_array(G_VARIANT_TYPE_UINT32,
-                               drvopts, ARRAY_SIZE(drvopts), sizeof(uint32_t));
-               return SR_OK;
-       }
-
-       switch (key) {
-       case SR_CONF_SCAN_OPTIONS:
-               *data = g_variant_new_fixed_array(G_VARIANT_TYPE_UINT32,
-                       scanopts, ARRAY_SIZE(scanopts), sizeof(uint32_t));
-               break;
-       case SR_CONF_DEVICE_OPTIONS:
-               *data = g_variant_new_fixed_array(G_VARIANT_TYPE_UINT32,
-                       devopts, ARRAY_SIZE(devopts), sizeof(uint32_t));
-               break;
-       default:
-               return SR_ERR_NA;
-       }
-
-       return SR_OK;
+       return STD_CONFIG_LIST(key, data, sdi, cg, scanopts, drvopts, devopts);
 }
 
 SR_PRIV struct sr_dev_driver rohde_schwarz_sme_0x_driver_info = {
index c981931546d298e84adce24710b2486d7ccbe2ae..9c257d2c6060d28f7664a04ed66b1988768ce128 100644 (file)
@@ -353,23 +353,10 @@ static int config_list(uint32_t key, GVariant **data,
        GVariant *gvar;
        GVariantBuilder gvb;
 
-       (void)sdi;
-       (void)cg;
-
        switch (key) {
        case SR_CONF_SCAN_OPTIONS:
-               *data = g_variant_new_fixed_array(G_VARIANT_TYPE_UINT32,
-                       scanopts, ARRAY_SIZE(scanopts), sizeof(uint32_t));
-               break;
        case SR_CONF_DEVICE_OPTIONS:
-               if (!sdi) {
-                       *data = g_variant_new_fixed_array(G_VARIANT_TYPE_UINT32,
-                               drvopts, ARRAY_SIZE(drvopts), sizeof(uint32_t));
-               } else {
-                       *data = g_variant_new_fixed_array(G_VARIANT_TYPE_UINT32,
-                               devopts, ARRAY_SIZE(devopts), sizeof(uint32_t));
-               }
-               break;
+               return STD_CONFIG_LIST(key, data, sdi, cg, scanopts, drvopts, devopts);
        case SR_CONF_SAMPLERATE:
                g_variant_builder_init(&gvb, G_VARIANT_TYPE("a{sv}"));
                gvar = g_variant_new_fixed_array(G_VARIANT_TYPE("t"),
index 721f15a540628f629aad397f5f428e26aff431d0..9562ac91b1729b3111b291d5b2da885acc3f8799 100644 (file)
@@ -503,18 +503,10 @@ static int config_list(uint32_t key, GVariant **data, const struct sr_dev_inst *
        GVariantBuilder gvb;
        unsigned int i;
 
-       (void)sdi;
-       (void)cg;
-
        switch (key) {
        case SR_CONF_SCAN_OPTIONS:
-               *data = g_variant_new_fixed_array(G_VARIANT_TYPE_UINT32,
-                               scanopts, ARRAY_SIZE(scanopts), sizeof(uint32_t));
-               break;
        case SR_CONF_DEVICE_OPTIONS:
-               *data = g_variant_new_fixed_array(G_VARIANT_TYPE_UINT32,
-                               devopts, ARRAY_SIZE(devopts), sizeof(uint32_t));
-               break;
+               return STD_CONFIG_LIST(key, data, sdi, cg, scanopts, NULL, devopts);
        case SR_CONF_SAMPLERATE:
                g_variant_builder_init(&gvb, G_VARIANT_TYPE("a{sv}"));
                gvar = g_variant_new_fixed_array(G_VARIANT_TYPE("t"),
index 5d2488252aa0a5e154ea9a096f7cc1cdce5fd075..7448796298ddb082a777d123ed75b428e303bb0e 100644 (file)
@@ -520,28 +520,18 @@ static int config_list(uint32_t key, GVariant **data, const struct sr_dev_inst *
        int i;
        const char *s[16];
 
-       /* Always available, even without sdi. */
-       if (key == SR_CONF_SCAN_OPTIONS) {
-               *data = g_variant_new_fixed_array(G_VARIANT_TYPE_UINT32,
-                               scanopts, ARRAY_SIZE(scanopts), sizeof(uint32_t));
-               return SR_OK;
-       } else if (key == SR_CONF_DEVICE_OPTIONS && !sdi) {
-               *data = g_variant_new_fixed_array(G_VARIANT_TYPE_UINT32,
-                               drvopts, ARRAY_SIZE(drvopts), sizeof(uint32_t));
-               return SR_OK;
-       }
-
-       if (!sdi)
-               return SR_ERR_ARG;
-       devc = sdi->priv;
+       devc = (sdi) ? sdi->priv : NULL;
 
        if (!cg) {
                /* No channel group: global options. */
                switch (key) {
+               case SR_CONF_SCAN_OPTIONS:
                case SR_CONF_DEVICE_OPTIONS:
-                       *data = g_variant_new_fixed_array(G_VARIANT_TYPE_UINT32,
-                                       devc->device->devopts, devc->device->num_devopts,
-                                       sizeof(uint32_t));
+                       return std_opts_config_list(key, data, sdi, cg,
+                               scanopts, ARRAY_SIZE(scanopts),
+                               drvopts, ARRAY_SIZE(drvopts),
+                               (devc) ? devc->device->devopts : NULL,
+                               (devc) ? devc->device->num_devopts : 0);
                        break;
                case SR_CONF_CHANNEL_CONFIG:
                        /* Not used. */
index 99b2a717672da9e50ebff03fe7d713d95c6dcaf5..5c0e63051dc6a03bfb75e9efa54dbbfe72ae84a4 100644 (file)
@@ -152,23 +152,7 @@ static int config_set(uint32_t key, GVariant *data, const struct sr_dev_inst *sd
 static int config_list(uint32_t key, GVariant **data, const struct sr_dev_inst *sdi,
                const struct sr_channel_group *cg)
 {
-       (void)sdi;
-       (void)cg;
-
-       switch (key) {
-       case SR_CONF_SCAN_OPTIONS:
-               *data = g_variant_new_fixed_array(G_VARIANT_TYPE_UINT32,
-                               scanopts, ARRAY_SIZE(scanopts), sizeof(uint32_t));
-               break;
-       case SR_CONF_DEVICE_OPTIONS:
-               *data = g_variant_new_fixed_array(G_VARIANT_TYPE_UINT32,
-                               devopts, ARRAY_SIZE(devopts), sizeof(uint32_t));
-               break;
-       default:
-               return SR_ERR_NA;
-       }
-
-       return SR_OK;
+       return STD_CONFIG_LIST(key, data, sdi, cg, scanopts, NULL, devopts);
 }
 
 static int dev_acquisition_start(const struct sr_dev_inst *sdi)
index ea98a234eb388f1a3456ac0f629b8a8d5ff52de1..1ff70eeb8dce3eba523dc9793963f9bf0c6e14c8 100644 (file)
@@ -625,8 +625,6 @@ static int config_commit(const struct sr_dev_inst *sdi)
        return SR_OK;
 }
 
-/* List available choices for a configuration setting.
- */
 static int config_list(uint32_t key, GVariant **data,
                       const struct sr_dev_inst *sdi,
                       const struct sr_channel_group *cg)
@@ -635,31 +633,16 @@ static int config_list(uint32_t key, GVariant **data,
        GVariant *gvar;
        GVariantBuilder gvb;
 
-       (void)cg;
+       devc = (sdi) ? sdi->priv : NULL;
 
-       if (key == SR_CONF_SCAN_OPTIONS) {
-               *data = g_variant_new_fixed_array(G_VARIANT_TYPE_UINT32,
-                       scanopts, ARRAY_SIZE(scanopts), sizeof(scanopts[0]));
-               return SR_OK;
-       }
-       if (!sdi) {
-               if (key != SR_CONF_DEVICE_OPTIONS)
-                       return SR_ERR_ARG;
-
-               /* List driver capabilities. */
-               *data = g_variant_new_fixed_array(G_VARIANT_TYPE_UINT32,
-                       drvopts, ARRAY_SIZE(drvopts), sizeof(drvopts[0]));
-               return SR_OK;
-       }
-
-       devc = sdi->priv;
-
-       /* List the model's device options. */
-       if (key == SR_CONF_DEVICE_OPTIONS) {
-               *data = g_variant_new_fixed_array(G_VARIANT_TYPE_UINT32,
-                       devc->model->devopts, devc->model->num_devopts,
-                       sizeof(devc->model->devopts[0]));
-               return SR_OK;
+       switch (key) {
+       case SR_CONF_SCAN_OPTIONS:
+       case SR_CONF_DEVICE_OPTIONS:
+               return std_opts_config_list(key, data, sdi, cg,
+                       scanopts, ARRAY_SIZE(scanopts),
+                       drvopts, ARRAY_SIZE(drvopts),
+                       (devc) ? devc->model->devopts : NULL,
+                       (devc) ? devc->model->num_devopts : 0);
        }
 
        if (!has_devopt(devc->model, key | SR_CONF_LIST))
index 980b5b3e6195dbad6c7560c0aed42c5a9eb39340..eb9dd3e0698efd57dceb10355a0fde8c35e476ca 100644 (file)
@@ -136,23 +136,7 @@ static int config_set(uint32_t key, GVariant *data, const struct sr_dev_inst *sd
 static int config_list(uint32_t key, GVariant **data, const struct sr_dev_inst *sdi,
                const struct sr_channel_group *cg)
 {
-       (void)sdi;
-       (void)cg;
-
-       switch (key) {
-       case SR_CONF_SCAN_OPTIONS:
-               *data = g_variant_new_fixed_array(G_VARIANT_TYPE_UINT32,
-                               scanopts, ARRAY_SIZE(scanopts), sizeof(uint32_t));
-               break;
-       case SR_CONF_DEVICE_OPTIONS:
-               *data = g_variant_new_fixed_array(G_VARIANT_TYPE_UINT32,
-                               devopts, ARRAY_SIZE(devopts), sizeof(uint32_t));
-               break;
-       default:
-               return SR_ERR_NA;
-       }
-
-       return SR_OK;
+       return STD_CONFIG_LIST(key, data, sdi, cg, scanopts, NULL, devopts);
 }
 
 static int dev_acquisition_start(const struct sr_dev_inst *sdi)
index 062849bfd5e320c80bc36500565fdabaee3f1b2f..6c975eed61d6f9e5b56eb298fe9dabb93d97f4ad 100644 (file)
@@ -222,23 +222,7 @@ static int config_set(uint32_t key, GVariant *data, const struct sr_dev_inst *sd
 static int config_list(uint32_t key, GVariant **data, const struct sr_dev_inst *sdi,
                const struct sr_channel_group *cg)
 {
-       (void)sdi;
-       (void)cg;
-
-       switch (key) {
-       case SR_CONF_SCAN_OPTIONS:
-               *data = g_variant_new_fixed_array(G_VARIANT_TYPE_UINT32,
-                               scanopts, ARRAY_SIZE(scanopts), sizeof(uint32_t));
-               break;
-       case SR_CONF_DEVICE_OPTIONS:
-               *data = g_variant_new_fixed_array(G_VARIANT_TYPE_UINT32,
-                               devopts, ARRAY_SIZE(devopts), sizeof(uint32_t));
-               break;
-       default:
-               return SR_ERR_NA;
-       }
-
-       return SR_OK;
+       return STD_CONFIG_LIST(key, data, sdi, cg, scanopts, NULL, devopts);
 }
 
 static void receive_data(struct sr_dev_inst *sdi, unsigned char *data, int len)
index 4330d960a81327060903ded5f2e7c7f961b59962..d14f0e6edb0b100e2210fdc591ffa4c607f4c6b6 100644 (file)
@@ -106,23 +106,7 @@ static int config_set(uint32_t key, GVariant *data, const struct sr_dev_inst *sd
 static int config_list(uint32_t key, GVariant **data, const struct sr_dev_inst *sdi,
                const struct sr_channel_group *cg)
 {
-       (void)sdi;
-       (void)cg;
-
-       switch (key) {
-       case SR_CONF_SCAN_OPTIONS:
-               *data = g_variant_new_fixed_array(G_VARIANT_TYPE_UINT32,
-                               scanopts, ARRAY_SIZE(scanopts), sizeof(uint32_t));
-               break;
-       case SR_CONF_DEVICE_OPTIONS:
-               *data = g_variant_new_fixed_array(G_VARIANT_TYPE_UINT32,
-                               devopts, ARRAY_SIZE(devopts), sizeof(uint32_t));
-               break;
-       default:
-               return SR_ERR_NA;
-       }
-
-       return SR_OK;
+       return STD_CONFIG_LIST(key, data, sdi, cg, scanopts, NULL, devopts);
 }
 
 static int dev_acquisition_start(const struct sr_dev_inst *sdi)
index eccff3cf1c3f97105a84b6e9b30431f0acd75703..aeb695530536c5c942e4548c620aa70c859ccb9d 100644 (file)
@@ -121,23 +121,7 @@ static int config_set(uint32_t key, GVariant *data, const struct sr_dev_inst *sd
 static int config_list(uint32_t key, GVariant **data, const struct sr_dev_inst *sdi,
                const struct sr_channel_group *cg)
 {
-       (void)sdi;
-       (void)cg;
-
-       switch (key) {
-       case SR_CONF_SCAN_OPTIONS:
-               *data = g_variant_new_fixed_array(G_VARIANT_TYPE_UINT32,
-                               scanopts, ARRAY_SIZE(scanopts), sizeof(uint32_t));
-               break;
-       case SR_CONF_DEVICE_OPTIONS:
-               *data = g_variant_new_fixed_array(G_VARIANT_TYPE_UINT32,
-                               devopts, ARRAY_SIZE(devopts), sizeof(uint32_t));
-               break;
-       default:
-               return SR_ERR_NA;
-       }
-
-       return SR_OK;
+       return STD_CONFIG_LIST(key, data, sdi, cg, scanopts, NULL, devopts);
 }
 
 static int dev_acquisition_start(const struct sr_dev_inst *sdi)
index 7d4ca62813f24cabc59fa2270c204b0056eda2da..1f4830e45d6abe10b00aaaa8af70eb02af820548 100644 (file)
@@ -205,18 +205,10 @@ static int config_set(uint32_t key, GVariant *data, const struct sr_dev_inst *sd
 static int config_list(uint32_t key, GVariant **data, const struct sr_dev_inst *sdi,
                const struct sr_channel_group *cg)
 {
-       (void)sdi;
-       (void)cg;
-
        switch (key) {
        case SR_CONF_SCAN_OPTIONS:
-               *data = g_variant_new_fixed_array(G_VARIANT_TYPE_UINT32,
-                               scanopts, ARRAY_SIZE(scanopts), sizeof(uint32_t));
-               break;
        case SR_CONF_DEVICE_OPTIONS:
-               *data = g_variant_new_fixed_array(G_VARIANT_TYPE_UINT32,
-                               devopts, ARRAY_SIZE(devopts), sizeof(uint32_t));
-               break;
+               return STD_CONFIG_LIST(key, data, sdi, cg, scanopts, NULL, devopts);
        case SR_CONF_DATA_SOURCE:
                *data = g_variant_new_strv(data_sources, ARRAY_SIZE(data_sources));
                break;
index ebe56feae536c12f4467dd2ab52c92cfddab8739..5ed70c80faaa2476e6edd30847d725c4099ad5b4 100644 (file)
@@ -182,27 +182,7 @@ static int config_set(uint32_t key, GVariant *data, const struct sr_dev_inst *sd
 static int config_list(uint32_t key, GVariant **data, const struct sr_dev_inst *sdi,
                const struct sr_channel_group *cg)
 {
-       (void)sdi;
-       (void)cg;
-
-       switch (key) {
-       case SR_CONF_SCAN_OPTIONS:
-               *data = g_variant_new_fixed_array(G_VARIANT_TYPE_UINT32,
-                               scanopts, ARRAY_SIZE(scanopts), sizeof(uint32_t));
-               break;
-       case SR_CONF_DEVICE_OPTIONS:
-               if (!sdi)
-                       *data = g_variant_new_fixed_array(G_VARIANT_TYPE_UINT32,
-                                       drvopts, ARRAY_SIZE(drvopts), sizeof(uint32_t));
-               else
-                       *data = g_variant_new_fixed_array(G_VARIANT_TYPE_UINT32,
-                                       devopts, ARRAY_SIZE(devopts), sizeof(uint32_t));
-               break;
-       default:
-               return SR_ERR_NA;
-       }
-
-       return SR_OK;
+       return STD_CONFIG_LIST(key, data, sdi, cg, scanopts, drvopts, devopts);
 }
 
 static void LIBUSB_CALL receive_transfer(struct libusb_transfer *transfer)
index 76703d867f3de3584a0e42eb972ac3ce74cb8305..650174a09234ae7ee1a52a82fe33f822b8655e36 100644 (file)
@@ -470,28 +470,11 @@ static int config_list(uint32_t key, GVariant **data, const struct sr_dev_inst *
                const struct sr_channel_group *cg)
 {
        int cg_type = CG_NONE;
-       struct dev_context *devc = NULL;
-       const struct scope_config *model = NULL;
-
-       /* 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;
index e8e7d4fb8d681a04ff3dae6162247d0cf713ebba..4ffcced83489a054c847790db46c66f8e5b0c924 100644 (file)
@@ -399,18 +399,9 @@ static int config_list(uint32_t key, GVariant **data, const struct sr_dev_inst *
        double v;
        GVariant *range[2];
 
-       (void)cg;
-
        switch (key) {
        case SR_CONF_DEVICE_OPTIONS:
-               if (!sdi) {
-                       *data = g_variant_new_fixed_array(G_VARIANT_TYPE_UINT32,
-                               drvopts, ARRAY_SIZE(drvopts), sizeof(uint32_t));
-               } else {
-                       *data = g_variant_new_fixed_array(G_VARIANT_TYPE_UINT32,
-                               devopts, ARRAY_SIZE(devopts), sizeof(uint32_t));
-               }
-               break;
+               return STD_CONFIG_LIST(key, data, sdi, cg, NULL, drvopts, devopts);
        case SR_CONF_SAMPLERATE:
                devc = sdi->priv;
                g_variant_builder_init(&gvb, G_VARIANT_TYPE("a{sv}"));
index 3e6b00126488ef58dd562cef0f7d12f124ce742b..96b6cfac0d48b4d24c67c61e88cc8074599f5fe9 100644 (file)
@@ -853,18 +853,19 @@ SR_API int sr_config_commit(const struct sr_dev_inst *sdi)
  * List all possible values for a configuration key.
  *
  * @param[in] driver The sr_dev_driver struct to query. Must not be NULL.
- * @param[in] sdi (optional) If the key is specific to a device, this must
- *            contain a pointer to the struct sr_dev_inst to be checked.
+ * @param[in] sdi (optional) If the key is specific to a device instance, this
+ *            must contain a pointer to the struct sr_dev_inst to be checked.
  *            Otherwise it must be NULL. If sdi is != NULL, sdi->priv must
  *            also be != NULL.
- * @param[in] cg The channel group on the device for which to list the
- *                    values, or NULL.
+ * @param[in] cg The channel group on the device instance for which to list
+ *            the values, or NULL. If this device instance doesn't
+ *            have channel groups, this must not be != NULL.
  * @param[in] key The configuration key (SR_CONF_*).
  * @param[in,out] data A pointer to a GVariant where the list will be stored.
- *             The caller is given ownership of the GVariant and must thus
- *             unref the GVariant after use. However if this function
- *             returns an error code, the field should be considered
- *             unused, and should not be unreferenced.
+ *                The caller is given ownership of the GVariant and must thus
+ *                unref the GVariant after use. However if this function
+ *                returns an error code, the field should be considered
+ *                unused, and should not be unreferenced.
  *
  * @retval SR_OK Success.
  * @retval SR_ERR Error.
@@ -883,21 +884,50 @@ SR_API int sr_config_list(const struct sr_dev_driver *driver,
 
        if (!driver || !data)
                return SR_ERR;
-       else if (!driver->config_list)
+
+       if (!driver->config_list)
                return SR_ERR_ARG;
-       else if (key != SR_CONF_SCAN_OPTIONS && key != SR_CONF_DEVICE_OPTIONS) {
+
+       if (key != SR_CONF_SCAN_OPTIONS && key != SR_CONF_DEVICE_OPTIONS) {
                if (check_key(driver, sdi, cg, key, SR_CONF_LIST, NULL) != SR_OK)
                        return SR_ERR_ARG;
        }
+
        if (sdi && !sdi->priv) {
                sr_err("Can't list config (sdi != NULL, sdi->priv == NULL).");
                return SR_ERR;
        }
+
+       if (key != SR_CONF_SCAN_OPTIONS && key != SR_CONF_DEVICE_OPTIONS && !sdi) {
+               sr_err("Config keys other than SR_CONF_SCAN_OPTIONS and "
+                      "SR_CONF_DEVICE_OPTIONS always need an sdi.");
+               return SR_ERR_ARG;
+       }
+
+       if (cg && sdi && !sdi->channel_groups) {
+               sr_err("Can't list config for channel group, there are none.");
+               return SR_ERR_ARG;
+       }
+
+       if (cg && sdi && !g_slist_find(sdi->channel_groups, cg)) {
+               sr_err("If a channel group is specified, it must be a valid one.");
+               return SR_ERR_ARG;
+       }
+
+       if (cg && !sdi) {
+               sr_err("Need sdi when a channel group is specified.");
+               return SR_ERR_ARG;
+       }
+
        if ((ret = driver->config_list(key, data, sdi, cg)) == SR_OK) {
                log_key(sdi, cg, key, SR_CONF_LIST, *data);
                g_variant_ref_sink(*data);
        }
 
+       if (ret == SR_ERR_CHANNEL_GROUP)
+               sr_err("%s: No channel group specified.",
+                       (sdi) ? sdi->driver->name : "unknown");
+
        return ret;
 }
 
index fd26fd9e48df23a4f2de7c399cfc50b031aada10..7947431e6d32275ea08b7b70866d35c5aee829f0 100644 (file)
@@ -251,32 +251,6 @@ static int serial_stream_check(struct sr_serial_dev_inst *serial,
                                       is_valid, timeout_ms, baudrate);
 }
 
-struct std_opt_desc {
-       const uint32_t *scanopts;
-       const int num_scanopts;
-       const uint32_t *devopts;
-       const int num_devopts;
-};
-
-static int std_config_list(uint32_t key, GVariant **data,
-                          const struct std_opt_desc *d)
-{
-       switch (key) {
-       case SR_CONF_SCAN_OPTIONS:
-               *data = g_variant_new_fixed_array(G_VARIANT_TYPE_UINT32,
-                       d->scanopts, d->num_scanopts, sizeof(uint32_t));
-               break;
-       case SR_CONF_DEVICE_OPTIONS:
-               *data = g_variant_new_fixed_array(G_VARIANT_TYPE_UINT32,
-                       d->devopts, d->num_devopts, sizeof(uint32_t));
-               break;
-       default:
-               return SR_ERR_NA;
-       }
-
-       return SR_OK;
-}
-
 static int send_config_update(struct sr_dev_inst *sdi, struct sr_config *cfg)
 {
        struct sr_datafeed_packet packet;
@@ -874,22 +848,14 @@ static const uint32_t devopts[] = {
        SR_CONF_EQUIV_CIRCUIT_MODEL | SR_CONF_GET | SR_CONF_LIST,
 };
 
-static const struct std_opt_desc opts = {
-       scanopts, ARRAY_SIZE(scanopts),
-       devopts, ARRAY_SIZE(devopts),
-};
-
 SR_PRIV int es51919_serial_config_list(uint32_t key, GVariant **data,
                                       const struct sr_dev_inst *sdi,
                                       const struct sr_channel_group *cg)
 {
-       (void)sdi;
-       (void)cg;
-
-       if (std_config_list(key, data, &opts) == SR_OK)
-               return SR_OK;
-
        switch (key) {
+       case SR_CONF_SCAN_OPTIONS:
+       case SR_CONF_DEVICE_OPTIONS:
+               return STD_CONFIG_LIST(key, data, sdi, cg, scanopts, NULL, devopts);
        case SR_CONF_OUTPUT_FREQUENCY:
                *data = g_variant_new_fixed_array(G_VARIANT_TYPE_DOUBLE,
                        frequencies, ARRAY_SIZE(frequencies), sizeof(double));
index fe2544fa3a90ed0a03a7d8fa268888b67056e372..d4533c9fd639b7aacf782e929449bbe3744baa0f 100644 (file)
@@ -947,6 +947,15 @@ SR_PRIV GSList *std_dev_list(const struct sr_dev_driver *di);
 SR_PRIV int std_serial_dev_close(struct sr_dev_inst *sdi);
 SR_PRIV GSList *std_scan_complete(struct sr_dev_driver *di, GSList *devices);
 
+SR_PRIV int std_opts_config_list(uint32_t key, GVariant **data,
+       const struct sr_dev_inst *sdi, const struct sr_channel_group *cg,
+       const uint32_t scanopts[], size_t scansize, const uint32_t drvopts[],
+       size_t drvsize, const uint32_t devopts[], size_t devsize);
+
+#define STD_CONFIG_LIST(key, data, sdi, cg, scanopts, drvopts, devopts) \
+       std_opts_config_list(key, data, sdi, cg, ARRAY_AND_SIZE(scanopts), \
+               ARRAY_AND_SIZE(drvopts), ARRAY_AND_SIZE(devopts))
+
 /*--- resource.c ------------------------------------------------------------*/
 
 SR_PRIV int64_t sr_file_get_size(FILE *file);
index f54ea54f088a3999f7508acb0e30aad8ba4f0ccc..a5f2e36862681511518e5e9d77603f7edb129ae8 100644 (file)
@@ -319,19 +319,7 @@ static int config_set(uint32_t key, GVariant *data, const struct sr_dev_inst *sd
 static int config_list(uint32_t key, GVariant **data, const struct sr_dev_inst *sdi,
                const struct sr_channel_group *cg)
 {
-       (void)sdi;
-       (void)cg;
-
-       switch (key) {
-       case SR_CONF_DEVICE_OPTIONS:
-               *data = g_variant_new_fixed_array(G_VARIANT_TYPE_UINT32,
-                               devopts, ARRAY_SIZE(devopts), sizeof(uint32_t));
-               break;
-       default:
-               return SR_ERR_NA;
-       }
-
-       return SR_OK;
+       return STD_CONFIG_LIST(key, data, sdi, cg, NULL, NULL, devopts);
 }
 
 static int dev_acquisition_start(const struct sr_dev_inst *sdi)
index a4f5d8835e25b0026e29693f6bf7e9eca58300d5..bd9c62860cccd9ccf15e7e383a8fa6c1ea49aa7f 100644 (file)
--- 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;
+}