drivers: Factor out std_gvar_samplerates{,_steps}().

This commit is contained in:
Uwe Hermann 2017-07-20 21:54:00 +02:00
parent db944f1622
commit 463160cbca
23 changed files with 54 additions and 164 deletions

View 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));

View 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:

View 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;

View 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,

View 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)

View 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;

View 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,

View 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;

View 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,

View 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;

View 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));

View 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,

View 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;

View 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,

View 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);

View 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,

View 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,

View 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;

View 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);

View 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,

View 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,

View 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 ------------------------------------------------------------*/

View File

@ -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");
}