]> sigrok.org Git - libsigrok.git/commitdiff
drivers: Factor out std_gvar_samplerates{,_steps}().
authorUwe Hermann <redacted>
Thu, 20 Jul 2017 19:54:00 +0000 (21:54 +0200)
committerUwe Hermann <redacted>
Fri, 21 Jul 2017 14:49:01 +0000 (16:49 +0200)
23 files changed:
src/hardware/agilent-dmm/api.c
src/hardware/asix-sigma/api.c
src/hardware/baylibre-acme/api.c
src/hardware/beaglelogic/api.c
src/hardware/chronovu-la/api.c
src/hardware/demo/api.c
src/hardware/dreamsourcelab-dslogic/api.c
src/hardware/ftdi-la/api.c
src/hardware/fx2lafw/api.c
src/hardware/hantek-6xxx/api.c
src/hardware/hung-chang-dso-2100/api.c
src/hardware/ikalogic-scanalogic2/api.c
src/hardware/ikalogic-scanaplus/api.c
src/hardware/lecroy-logicstudio/api.c
src/hardware/link-mso19/api.c
src/hardware/openbench-logic-sniffer/api.c
src/hardware/pipistrello-ols/api.c
src/hardware/saleae-logic-pro/api.c
src/hardware/saleae-logic16/api.c
src/hardware/sysclk-lwla/api.c
src/hardware/zeroplus-logic-cube/api.c
src/libsigrok-internal.h
src/std.c

index d38cdf0c56a0dbcd65611231fedc3a25757a2fc6..76ee21c4d0a53db18b046d89feac82212d5fc872 100644 (file)
@@ -263,19 +263,12 @@ 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)
 {
-       GVariant *gvar;
-       GVariantBuilder gvb;
-
        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_SAMPLERATE:
-               g_variant_builder_init(&gvb, G_VARIANT_TYPE("a{sv}"));
-               gvar = g_variant_new_fixed_array(G_VARIANT_TYPE("t"), samplerates,
-                               ARRAY_SIZE(samplerates), sizeof(uint64_t));
-               g_variant_builder_add(&gvb, "{sv}", "samplerate-steps", gvar);
-               *data = g_variant_builder_end(&gvb);
+               *data = std_gvar_samplerates_steps(samplerates, ARRAY_SIZE(samplerates));
                break;
        case SR_CONF_DATA_SOURCE:
                *data = g_variant_new_strv(data_sources, ARRAY_SIZE(data_sources));
index 163032c335079dc730300ee35894ffab18cc3ba5..aaefb450e77bec56e4be068fdad3d6a1721ed3f5 100644 (file)
@@ -235,18 +235,11 @@ 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)
 {
-       GVariant *gvar;
-       GVariantBuilder gvb;
-
        switch (key) {
        case SR_CONF_DEVICE_OPTIONS:
                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,
-                               samplerates_count, sizeof(samplerates[0]));
-               g_variant_builder_add(&gvb, "{sv}", "samplerates", gvar);
-               *data = g_variant_builder_end(&gvb);
+               *data = std_gvar_samplerates(samplerates, samplerates_count);
                break;
 #if ASIX_SIGMA_WITH_TRIGGER
        case SR_CONF_TRIGGER_MATCH:
index 40a2a4c84a8236f90e7bbd1f563a13d3f8e36257..44169a1b830b69e8ab3ede1e902b43245766efb2 100644 (file)
@@ -220,8 +220,6 @@ static int config_list(uint32_t key, GVariant **data,
                       const struct sr_channel_group *cg)
 {
        uint32_t devopts_cg[MAX_DEVOPTS_CG];
-       GVariant *gvar;
-       GVariantBuilder gvb;
        int num_devopts_cg = 0;
 
        if (!cg) {
@@ -229,12 +227,7 @@ static int config_list(uint32_t key, GVariant **data,
                case SR_CONF_DEVICE_OPTIONS:
                        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, ARRAY_SIZE(samplerates), sizeof(uint64_t));
-                       g_variant_builder_add(&gvb, "{sv}",
-                                             "samplerate-steps", gvar);
-                       *data = g_variant_builder_end(&gvb);
+                       *data = std_gvar_samplerates_steps(samplerates, ARRAY_SIZE(samplerates));
                        break;
                default:
                        return SR_ERR_NA;
index e450a094027317bd06551aeb2b64cee0fe037adc..e904833da69d3095e4131b8e30bbdae697862692 100644 (file)
@@ -240,19 +240,12 @@ 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)
 {
-       GVariant *gvar;
-       GVariantBuilder gvb;
-
        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_SAMPLERATE:
-               g_variant_builder_init(&gvb, G_VARIANT_TYPE("a{sv}"));
-               gvar = g_variant_new_fixed_array(G_VARIANT_TYPE("t"),
-                       samplerates, ARRAY_SIZE(samplerates), sizeof(uint64_t));
-               g_variant_builder_add(&gvb, "{sv}", "samplerate-steps", gvar);
-               *data = g_variant_builder_end(&gvb);
+               *data = std_gvar_samplerates_steps(samplerates, ARRAY_SIZE(samplerates));
                break;
        case SR_CONF_TRIGGER_MATCH:
                *data = g_variant_new_fixed_array(G_VARIANT_TYPE_INT32,
index 3bf5609544763b13f37d7aff975083eac1cdbc54..95aee39e1ffc56393179c645443ba093f62104e7 100644 (file)
@@ -346,8 +346,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)
 {
-       GVariant *gvar, *grange[2];
-       GVariantBuilder gvb;
+       GVariant *grange[2];
        struct dev_context *devc;
 
        devc = (sdi) ? sdi->priv : NULL;
@@ -358,13 +357,7 @@ static int config_list(uint32_t key, GVariant **data, const struct sr_dev_inst *
                return STD_CONFIG_LIST(key, data, sdi, cg, scanopts, drvopts, devopts);
        case SR_CONF_SAMPLERATE:
                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"),
-                               devc->samplerates,
-                               ARRAY_SIZE(devc->samplerates),
-                               sizeof(uint64_t));
-               g_variant_builder_add(&gvb, "{sv}", "samplerates", gvar);
-               *data = g_variant_builder_end(&gvb);
+               *data = std_gvar_samplerates(devc->samplerates, ARRAY_SIZE(devc->samplerates));
                break;
        case SR_CONF_LIMIT_SAMPLES:
                if (!devc->prof)
index ed3d0c352398f359e30e8e36180c5cd0a74820ee..e9c504a2aca826c5afb35b9f0022827297c23d2b 100644 (file)
@@ -355,8 +355,6 @@ static int config_list(uint32_t key, GVariant **data, const struct sr_dev_inst *
                const struct sr_channel_group *cg)
 {
        struct sr_channel *ch;
-       GVariant *gvar;
-       GVariantBuilder gvb;
 
        if (!cg) {
                switch (key) {
@@ -364,11 +362,7 @@ static int config_list(uint32_t key, GVariant **data, const struct sr_dev_inst *
                case SR_CONF_DEVICE_OPTIONS:
                        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,
-                                       ARRAY_SIZE(samplerates), sizeof(uint64_t));
-                       g_variant_builder_add(&gvb, "{sv}", "samplerate-steps", gvar);
-                       *data = g_variant_builder_end(&gvb);
+                       *data = std_gvar_samplerates_steps(samplerates, ARRAY_SIZE(samplerates));
                        break;
                default:
                        return SR_ERR_NA;
index 6427cfdc7c5cb579d834fb43fab2ad7fc2faf9db..c8bdb6d123fdb25102b27efa165ea0c04d3af2cf 100644 (file)
@@ -583,11 +583,7 @@ static int config_list(uint32_t key, GVariant **data,
                *data = g_variant_builder_end(&gvb);
                break;
        case SR_CONF_SAMPLERATE:
-               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));
-               g_variant_builder_add(&gvb, "{sv}", "samplerates", gvar);
-               *data = g_variant_builder_end(&gvb);
+               *data = std_gvar_samplerates(devc->samplerates, devc->num_samplerates);
                break;
        case SR_CONF_CLOCK_EDGE:
                *data = g_variant_new_strv(signal_edge_names,
index c59ff9ad493e0572ef950fa918eb9bc185fcd268..d435c64a8bab49d5cbea94fc3e001c84123a753a 100644 (file)
@@ -383,19 +383,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)
 {
-       GVariant *gvar;
-       GVariantBuilder gvb;
-
        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_SAMPLERATE:
-               g_variant_builder_init(&gvb, G_VARIANT_TYPE("a{sv}"));
-               gvar = g_variant_new_fixed_array(G_VARIANT_TYPE("t"),
-                       samplerates, ARRAY_SIZE(samplerates), sizeof(uint64_t));
-               g_variant_builder_add(&gvb, "{sv}", "samplerate-steps", gvar);
-               *data = g_variant_builder_end(&gvb);
+               *data = std_gvar_samplerates_steps(samplerates, ARRAY_SIZE(samplerates));
                break;
        default:
                return SR_ERR_NA;
index 078b9c5c54a3a85f624baf32313de66924687d45..b1909428692144ac9f12d9c3c33b0d801d919b37 100644 (file)
@@ -532,8 +532,6 @@ 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;
-       GVariant *gvar;
-       GVariantBuilder gvb;
 
        devc = (sdi) ? sdi->priv : NULL;
 
@@ -542,11 +540,7 @@ static int config_list(uint32_t key, GVariant **data,
        case SR_CONF_DEVICE_OPTIONS:
                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"), devc->samplerates,
-                               devc->num_samplerates, sizeof(uint64_t));
-               g_variant_builder_add(&gvb, "{sv}", "samplerates", gvar);
-               *data = g_variant_builder_end(&gvb);
+               *data = std_gvar_samplerates(devc->samplerates, devc->num_samplerates);
                break;
        case SR_CONF_TRIGGER_MATCH:
                *data = g_variant_new_fixed_array(G_VARIANT_TYPE_INT32,
index aed2b970ae37489acac83bad492c03221e9f2a06..4f8e011285dd95b199f4c2b1bd751616252b77d5 100644 (file)
@@ -458,8 +458,6 @@ 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)
 {
-       GVariantBuilder gvb;
-       GVariant *gvar;
        struct dev_context *devc;
 
        devc = (sdi) ? sdi->priv : NULL;
@@ -470,12 +468,7 @@ static int config_list(uint32_t key, GVariant **data, const struct sr_dev_inst *
                case SR_CONF_DEVICE_OPTIONS:
                        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, ARRAY_SIZE(samplerates),
-                               sizeof(uint64_t));
-                       g_variant_builder_add(&gvb, "{sv}", "samplerates", gvar);
-                       *data = g_variant_builder_end(&gvb);
+                       *data = std_gvar_samplerates(samplerates, ARRAY_SIZE(samplerates));
                        break;
                default:
                        return SR_ERR_NA;
index 607ce20c9afae871b410a4dff5528828dba55583..7ddc878799cc4557e86a4983fad35f763f9c8502 100644 (file)
@@ -559,8 +559,6 @@ static int config_commit(const struct sr_dev_inst *sdi)
 static int config_list(uint32_t key, GVariant **data, const struct sr_dev_inst *sdi,
                const struct sr_channel_group *cg)
 {
-       GVariantBuilder gvb;
-       GVariant *gvar;
        GSList *l;
 
        switch (key) {
@@ -598,11 +596,7 @@ 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_SAMPLERATE:
-               g_variant_builder_init(&gvb, G_VARIANT_TYPE("a{sv}"));
-               gvar = g_variant_new_fixed_array(G_VARIANT_TYPE("t"),
-                               samplerates, ARRAY_SIZE(samplerates), sizeof(uint64_t));
-               g_variant_builder_add(&gvb, "{sv}", "samplerates", gvar);
-               *data = g_variant_builder_end(&gvb);
+               *data = std_gvar_samplerates(samplerates, ARRAY_SIZE(samplerates));
                break;
        case SR_CONF_TRIGGER_SOURCE:
                *data = g_variant_new_strv(trigger_sources, ARRAY_SIZE(trigger_sources));
index 8005fe074332062936d1a3643bdefe2266e1e910..3b832866e4de40030ac73b2022a0f742e5ea4cfc 100644 (file)
@@ -300,19 +300,13 @@ 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)
 {
-       GVariant *gvar, *grange[2];
-       GVariantBuilder gvb;
+       GVariant *grange[2];
 
        switch (key) {
        case SR_CONF_DEVICE_OPTIONS:
                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"),
-                       sl2_samplerates, ARRAY_SIZE(sl2_samplerates),
-                       sizeof(uint64_t));
-               g_variant_builder_add(&gvb, "{sv}", "samplerates", gvar);
-               *data = g_variant_builder_end(&gvb);
+               *data = std_gvar_samplerates(sl2_samplerates, ARRAY_SIZE(sl2_samplerates));
                break;
        case SR_CONF_TRIGGER_MATCH:
                *data = g_variant_new_fixed_array(G_VARIANT_TYPE_INT32,
index 86c1402e511e635ec2fe4538140f143d555befe3..ffec385cd3b15210c1f7dd9ecb9429268cecf777 100644 (file)
@@ -257,19 +257,11 @@ 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)
 {
-       GVariant *gvar;
-       GVariantBuilder gvb;
-
        switch (key) {
        case SR_CONF_DEVICE_OPTIONS:
                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, ARRAY_SIZE(samplerates),
-                               sizeof(uint64_t));
-               g_variant_builder_add(&gvb, "{sv}", "samplerates", gvar);
-               *data = g_variant_builder_end(&gvb);
+               *data = std_gvar_samplerates(samplerates, ARRAY_SIZE(samplerates));
                break;
        default:
                return SR_ERR_NA;
index 4e76dccf4fdfd4e504fcd0f39e7545242af3b27b..6f7eec94ae59c64053b965438ce74d07d9dd6eae 100644 (file)
@@ -406,19 +406,11 @@ 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)
 {
-       GVariantBuilder vb;
-       GVariant *var;
-
        switch (key) {
        case SR_CONF_DEVICE_OPTIONS:
                return STD_CONFIG_LIST(key, data, sdi, cg, NULL, drvopts, 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"),
-                               samplerates, ARRAY_SIZE(samplerates),
-                               sizeof(uint64_t));
-               g_variant_builder_add(&vb, "{sv}", "samplerates", var);
-               *data = g_variant_builder_end(&vb);
+               *data = std_gvar_samplerates(samplerates, ARRAY_SIZE(samplerates));
                break;
        case SR_CONF_TRIGGER_MATCH:
                *data = g_variant_new_fixed_array(G_VARIANT_TYPE_INT32,
index 47ace67db499065df25161660bbad1b1f6d8ba2a..ae1a7f6861d2af2452f450ebee49a9ef5ec7eaf7 100644 (file)
@@ -288,18 +288,11 @@ static int config_set(int key, GVariant *data, const struct sr_dev_inst *sdi,
 static int config_list(int key, GVariant **data, const struct sr_dev_inst *sdi,
                const struct sr_channel_group *cg)
 {
-       GVariant *gvar;
-       GVariantBuilder gvb;
-
        switch (key) {
        case SR_CONF_DEVICE_OPTIONS:
                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,
-                               ARRAY_SIZE(samplerates), sizeof(uint64_t));
-               g_variant_builder_add(&gvb, "{sv}", "samplerate-steps", gvar);
-               *data = g_variant_builder_end(&gvb);
+               *data = std_gvar_samplerates_steps(samplerates, ARRAY_SIZE(samplerates));
                break;
        case SR_CONF_TRIGGER_TYPE:
                *data = g_variant_new_string(TRIGGER_TYPE);
index a3fb54e8027641fc78e36e22c3e8f7ca78ac1505..3fd34c6d3650198a8a802b815dd8d3b9b69094bc 100644 (file)
@@ -323,8 +323,7 @@ static int config_list(uint32_t key, GVariant **data, const struct sr_dev_inst *
                const struct sr_channel_group *cg)
 {
        struct dev_context *devc;
-       GVariant *gvar, *grange[2];
-       GVariantBuilder gvb;
+       GVariant *grange[2];
        int num_ols_changrp, i;
 
        switch (key) {
@@ -332,11 +331,7 @@ static int config_list(uint32_t key, GVariant **data, const struct sr_dev_inst *
        case SR_CONF_DEVICE_OPTIONS:
                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,
-                               ARRAY_SIZE(samplerates), sizeof(uint64_t));
-               g_variant_builder_add(&gvb, "{sv}", "samplerate-steps", gvar);
-               *data = g_variant_builder_end(&gvb);
+               *data = std_gvar_samplerates_steps(samplerates, ARRAY_SIZE(samplerates));
                break;
        case SR_CONF_TRIGGER_MATCH:
                *data = g_variant_new_fixed_array(G_VARIANT_TYPE_INT32,
index 8dd474cf478bf3dc0c21ed3169aa1b8ccb964032..4923d67717171929d1819994b2147383d898ee19 100644 (file)
@@ -334,19 +334,14 @@ static int config_list(uint32_t key, GVariant **data, const struct sr_dev_inst *
                const struct sr_channel_group *cg)
 {
        struct dev_context *devc;
-       GVariant *gvar, *grange[2];
-       GVariantBuilder gvb;
+       GVariant *grange[2];
        int num_pols_changrp, i;
 
        switch (key) {
        case SR_CONF_DEVICE_OPTIONS:
                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,
-                               ARRAY_SIZE(samplerates), sizeof(uint64_t));
-               g_variant_builder_add(&gvb, "{sv}", "samplerate-steps", gvar);
-               *data = g_variant_builder_end(&gvb);
+               *data = std_gvar_samplerates_steps(samplerates, ARRAY_SIZE(samplerates));
                break;
        case SR_CONF_TRIGGER_MATCH:
                *data = g_variant_new_fixed_array(G_VARIANT_TYPE_INT32,
index 269ca5e9e7ead7b5b870282db308c3aaa1ccc403..bd96e3de051b54f0dba011edb97cd70fffa65b59 100644 (file)
@@ -350,19 +350,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)
 {
-       GVariant *gvar;
-       GVariantBuilder gvb;
-
        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_SAMPLERATE:
-               g_variant_builder_init(&gvb, G_VARIANT_TYPE("a{sv}"));
-               gvar = g_variant_new_fixed_array(G_VARIANT_TYPE("t"),
-                       samplerates, ARRAY_SIZE(samplerates), sizeof(uint64_t));
-               g_variant_builder_add(&gvb, "{sv}", "samplerates", gvar);
-               *data = g_variant_builder_end(&gvb);
+               *data = std_gvar_samplerates(samplerates, ARRAY_SIZE(samplerates));
                break;
        default:
                return SR_ERR_NA;
index 607fb7bffa04c30ca90adad4d9621f35c84fede8..9d28a9b3621bdaa341f5acf8ac3173f320087d15 100644 (file)
@@ -511,11 +511,7 @@ static int config_list(uint32_t key, GVariant **data, const struct sr_dev_inst *
        case SR_CONF_DEVICE_OPTIONS:
                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, ARRAY_SIZE(samplerates), sizeof(uint64_t));
-               g_variant_builder_add(&gvb, "{sv}", "samplerates", gvar);
-               *data = g_variant_builder_end(&gvb);
+               *data = std_gvar_samplerates(samplerates, ARRAY_SIZE(samplerates));
                break;
        case SR_CONF_VOLTAGE_THRESHOLD:
                g_variant_builder_init(&gvb, G_VARIANT_TYPE_ARRAY);
index 71a358b98a05e122c089cabf4264c4948d4c9c40..3d8f0979606c40178de1cab84e3c3bc2bf89e779 100644 (file)
@@ -600,8 +600,6 @@ static int config_list(uint32_t key, GVariant **data,
                       const struct sr_channel_group *cg)
 {
        struct dev_context *devc;
-       GVariant *gvar;
-       GVariantBuilder gvb;
 
        devc = (sdi) ? sdi->priv : NULL;
 
@@ -620,12 +618,7 @@ static int config_list(uint32_t key, GVariant **data,
 
        switch (key) {
        case SR_CONF_SAMPLERATE:
-               g_variant_builder_init(&gvb, G_VARIANT_TYPE_VARDICT);
-               gvar = g_variant_new_fixed_array(G_VARIANT_TYPE_UINT64,
-                       devc->model->samplerates, devc->model->num_samplerates,
-                       sizeof(devc->model->samplerates[0]));
-               g_variant_builder_add(&gvb, "{sv}", "samplerates", gvar);
-               *data = g_variant_builder_end(&gvb);
+               *data = std_gvar_samplerates(devc->model->samplerates, devc->model->num_samplerates);
                break;
        case SR_CONF_TRIGGER_MATCH:
                *data = g_variant_new_fixed_array(G_VARIANT_TYPE_INT32,
index e0124ed8ba5eb49422819303bdb17265bc57da9e..e8cdefdb18cf8555994a7aa019a137672ba65458 100644 (file)
@@ -401,22 +401,15 @@ static int config_list(uint32_t key, GVariant **data, const struct sr_dev_inst *
                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}"));
-               if (devc->prof->max_sampling_freq == 100) {
-                       gvar = g_variant_new_fixed_array(G_VARIANT_TYPE("t"),
-                                       samplerates_100, ARRAY_SIZE(samplerates_100),
-                                       sizeof(uint64_t));
-               } else if (devc->prof->max_sampling_freq == 200) {
-                       gvar = g_variant_new_fixed_array(G_VARIANT_TYPE("t"),
-                                       samplerates_200, ARRAY_SIZE(samplerates_200),
-                                       sizeof(uint64_t));
-               } else {
+               if (devc->prof->max_sampling_freq == 100)
+                       *data = std_gvar_samplerates(samplerates_100, ARRAY_SIZE(samplerates_100));
+               else if (devc->prof->max_sampling_freq == 200)
+                       *data = std_gvar_samplerates(samplerates_200, ARRAY_SIZE(samplerates_200));
+               else {
                        sr_err("Internal error: Unknown max. samplerate: %d.",
                               devc->prof->max_sampling_freq);
                        return SR_ERR_ARG;
                }
-               g_variant_builder_add(&gvb, "{sv}", "samplerates", gvar);
-               *data = g_variant_builder_end(&gvb);
                break;
        case SR_CONF_TRIGGER_MATCH:
                *data = g_variant_new_fixed_array(G_VARIANT_TYPE_INT32,
index 8f6ec2af44b17f2630cdf845a59d2f3d9e133b04..8c7e35ddbf2ec3d0339354bd48afd62244b73fe6 100644 (file)
@@ -958,6 +958,8 @@ SR_PRIV int std_opts_config_list(uint32_t key, GVariant **data,
 
 SR_PRIV GVariant *std_gvar_tuple_array(const uint64_t (*a)[][2], unsigned int n);
 SR_PRIV GVariant *std_gvar_tuple_rational(const struct sr_rational *r, unsigned int n);
+SR_PRIV GVariant *std_gvar_samplerates(const uint64_t samplerates[], unsigned int n);
+SR_PRIV GVariant *std_gvar_samplerates_steps(const uint64_t samplerates[], unsigned int n);
 
 
 /*--- resource.c ------------------------------------------------------------*/
index c6ff4ccef96cc07d758b13f4936db374eb2631f2..e36b7ccc77910637dd0e0bbc484d3150e40b66a2 100644 (file)
--- a/src/std.c
+++ b/src/std.c
@@ -578,3 +578,26 @@ SR_PRIV GVariant *std_gvar_tuple_rational(const struct sr_rational *r, unsigned
 
        return g_variant_builder_end(&gvb);
 }
+
+static GVariant *samplerate_helper(const uint64_t samplerates[], unsigned int n, const char *str)
+{
+       GVariant *gvar;
+       GVariantBuilder gvb;
+
+       g_variant_builder_init(&gvb, G_VARIANT_TYPE("a{sv}"));
+       gvar = g_variant_new_fixed_array(G_VARIANT_TYPE("t"), samplerates,
+                       n, sizeof(uint64_t));
+       g_variant_builder_add(&gvb, "{sv}", str, gvar);
+
+       return g_variant_builder_end(&gvb);
+}
+
+SR_PRIV GVariant *std_gvar_samplerates(const uint64_t samplerates[], unsigned int n)
+{
+       return samplerate_helper(samplerates, n, "samplerates");
+}
+
+SR_PRIV GVariant *std_gvar_samplerates_steps(const uint64_t samplerates[], unsigned int n)
+{
+       return samplerate_helper(samplerates, n, "samplerate-steps");
+}