From: Uwe Hermann Date: Thu, 20 Jul 2017 19:54:00 +0000 (+0200) Subject: drivers: Factor out std_gvar_samplerates{,_steps}(). X-Git-Url: https://sigrok.org/gitaction?a=commitdiff_plain;h=463160cbca37367ef94dfead0c64531d82b83ab8;p=libsigrok.git drivers: Factor out std_gvar_samplerates{,_steps}(). --- diff --git a/src/hardware/agilent-dmm/api.c b/src/hardware/agilent-dmm/api.c index d38cdf0c..76ee21c4 100644 --- a/src/hardware/agilent-dmm/api.c +++ b/src/hardware/agilent-dmm/api.c @@ -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)); diff --git a/src/hardware/asix-sigma/api.c b/src/hardware/asix-sigma/api.c index 163032c3..aaefb450 100644 --- a/src/hardware/asix-sigma/api.c +++ b/src/hardware/asix-sigma/api.c @@ -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: diff --git a/src/hardware/baylibre-acme/api.c b/src/hardware/baylibre-acme/api.c index 40a2a4c8..44169a1b 100644 --- a/src/hardware/baylibre-acme/api.c +++ b/src/hardware/baylibre-acme/api.c @@ -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; diff --git a/src/hardware/beaglelogic/api.c b/src/hardware/beaglelogic/api.c index e450a094..e904833d 100644 --- a/src/hardware/beaglelogic/api.c +++ b/src/hardware/beaglelogic/api.c @@ -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, diff --git a/src/hardware/chronovu-la/api.c b/src/hardware/chronovu-la/api.c index 3bf56095..95aee39e 100644 --- a/src/hardware/chronovu-la/api.c +++ b/src/hardware/chronovu-la/api.c @@ -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) diff --git a/src/hardware/demo/api.c b/src/hardware/demo/api.c index ed3d0c35..e9c504a2 100644 --- a/src/hardware/demo/api.c +++ b/src/hardware/demo/api.c @@ -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; diff --git a/src/hardware/dreamsourcelab-dslogic/api.c b/src/hardware/dreamsourcelab-dslogic/api.c index 6427cfdc..c8bdb6d1 100644 --- a/src/hardware/dreamsourcelab-dslogic/api.c +++ b/src/hardware/dreamsourcelab-dslogic/api.c @@ -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, diff --git a/src/hardware/ftdi-la/api.c b/src/hardware/ftdi-la/api.c index c59ff9ad..d435c64a 100644 --- a/src/hardware/ftdi-la/api.c +++ b/src/hardware/ftdi-la/api.c @@ -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; diff --git a/src/hardware/fx2lafw/api.c b/src/hardware/fx2lafw/api.c index 078b9c5c..b1909428 100644 --- a/src/hardware/fx2lafw/api.c +++ b/src/hardware/fx2lafw/api.c @@ -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, diff --git a/src/hardware/hantek-6xxx/api.c b/src/hardware/hantek-6xxx/api.c index aed2b970..4f8e0112 100644 --- a/src/hardware/hantek-6xxx/api.c +++ b/src/hardware/hantek-6xxx/api.c @@ -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; diff --git a/src/hardware/hung-chang-dso-2100/api.c b/src/hardware/hung-chang-dso-2100/api.c index 607ce20c..7ddc8787 100644 --- a/src/hardware/hung-chang-dso-2100/api.c +++ b/src/hardware/hung-chang-dso-2100/api.c @@ -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)); diff --git a/src/hardware/ikalogic-scanalogic2/api.c b/src/hardware/ikalogic-scanalogic2/api.c index 8005fe07..3b832866 100644 --- a/src/hardware/ikalogic-scanalogic2/api.c +++ b/src/hardware/ikalogic-scanalogic2/api.c @@ -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, diff --git a/src/hardware/ikalogic-scanaplus/api.c b/src/hardware/ikalogic-scanaplus/api.c index 86c1402e..ffec385c 100644 --- a/src/hardware/ikalogic-scanaplus/api.c +++ b/src/hardware/ikalogic-scanaplus/api.c @@ -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; diff --git a/src/hardware/lecroy-logicstudio/api.c b/src/hardware/lecroy-logicstudio/api.c index 4e76dccf..6f7eec94 100644 --- a/src/hardware/lecroy-logicstudio/api.c +++ b/src/hardware/lecroy-logicstudio/api.c @@ -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, diff --git a/src/hardware/link-mso19/api.c b/src/hardware/link-mso19/api.c index 47ace67d..ae1a7f68 100644 --- a/src/hardware/link-mso19/api.c +++ b/src/hardware/link-mso19/api.c @@ -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); diff --git a/src/hardware/openbench-logic-sniffer/api.c b/src/hardware/openbench-logic-sniffer/api.c index a3fb54e8..3fd34c6d 100644 --- a/src/hardware/openbench-logic-sniffer/api.c +++ b/src/hardware/openbench-logic-sniffer/api.c @@ -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, diff --git a/src/hardware/pipistrello-ols/api.c b/src/hardware/pipistrello-ols/api.c index 8dd474cf..4923d677 100644 --- a/src/hardware/pipistrello-ols/api.c +++ b/src/hardware/pipistrello-ols/api.c @@ -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, diff --git a/src/hardware/saleae-logic-pro/api.c b/src/hardware/saleae-logic-pro/api.c index 269ca5e9..bd96e3de 100644 --- a/src/hardware/saleae-logic-pro/api.c +++ b/src/hardware/saleae-logic-pro/api.c @@ -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; diff --git a/src/hardware/saleae-logic16/api.c b/src/hardware/saleae-logic16/api.c index 607fb7bf..9d28a9b3 100644 --- a/src/hardware/saleae-logic16/api.c +++ b/src/hardware/saleae-logic16/api.c @@ -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); diff --git a/src/hardware/sysclk-lwla/api.c b/src/hardware/sysclk-lwla/api.c index 71a358b9..3d8f0979 100644 --- a/src/hardware/sysclk-lwla/api.c +++ b/src/hardware/sysclk-lwla/api.c @@ -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, diff --git a/src/hardware/zeroplus-logic-cube/api.c b/src/hardware/zeroplus-logic-cube/api.c index e0124ed8..e8cdefdb 100644 --- a/src/hardware/zeroplus-logic-cube/api.c +++ b/src/hardware/zeroplus-logic-cube/api.c @@ -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, diff --git a/src/libsigrok-internal.h b/src/libsigrok-internal.h index 8f6ec2af..8c7e35dd 100644 --- a/src/libsigrok-internal.h +++ b/src/libsigrok-internal.h @@ -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 ------------------------------------------------------------*/ diff --git a/src/std.c b/src/std.c index c6ff4cce..e36b7ccc 100644 --- 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"); +}