drivers: Factor out std_gvar_tuple_{array,rational}().
This commit is contained in:
parent
6b82c3e57a
commit
db944f1622
|
@ -284,10 +284,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)
|
||||
{
|
||||
GVariant *tuple, *range[2];
|
||||
GVariantBuilder gvb;
|
||||
unsigned int i;
|
||||
|
||||
switch (key) {
|
||||
case SR_CONF_SCAN_OPTIONS:
|
||||
case SR_CONF_DEVICE_OPTIONS:
|
||||
|
@ -299,14 +295,7 @@ static int config_list(uint32_t key, GVariant **data, const struct sr_dev_inst *
|
|||
*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);
|
||||
*data = std_gvar_tuple_array(&meas_ranges, ARRAY_SIZE(meas_ranges));
|
||||
break;
|
||||
case SR_CONF_DATA_SOURCE:
|
||||
*data = g_variant_new_strv(data_sources, ARRAY_SIZE(data_sources));
|
||||
|
|
|
@ -269,25 +269,6 @@ static int config_get(uint32_t key, GVariant **data, const struct sr_dev_inst *s
|
|||
return ret;
|
||||
}
|
||||
|
||||
static GVariant *build_tuples(const uint64_t (*array)[][2], unsigned int n)
|
||||
{
|
||||
unsigned int i;
|
||||
GVariant *rational[2];
|
||||
GVariantBuilder gvb;
|
||||
|
||||
g_variant_builder_init(&gvb, G_VARIANT_TYPE_ARRAY);
|
||||
|
||||
for (i = 0; i < n; i++) {
|
||||
rational[0] = g_variant_new_uint64((*array)[i][0]);
|
||||
rational[1] = g_variant_new_uint64((*array)[i][1]);
|
||||
|
||||
/* FIXME: Valgrind reports a memory leak here. */
|
||||
g_variant_builder_add_value(&gvb, g_variant_new_tuple(rational, 2));
|
||||
}
|
||||
|
||||
return g_variant_builder_end(&gvb);
|
||||
}
|
||||
|
||||
static int config_set(uint32_t key, GVariant *data, const struct sr_dev_inst *sdi,
|
||||
const struct sr_channel_group *cg)
|
||||
{
|
||||
|
@ -520,12 +501,12 @@ static int config_list(uint32_t key, GVariant **data, const struct sr_dev_inst *
|
|||
case SR_CONF_TIMEBASE:
|
||||
if (!model)
|
||||
return SR_ERR_ARG;
|
||||
*data = build_tuples(model->timebases, model->num_timebases);
|
||||
*data = std_gvar_tuple_array(model->timebases, model->num_timebases);
|
||||
break;
|
||||
case SR_CONF_VDIV:
|
||||
if (cg_type == CG_NONE)
|
||||
return SR_ERR_CHANNEL_GROUP;
|
||||
*data = build_tuples(model->vdivs, model->num_vdivs);
|
||||
*data = std_gvar_tuple_array(model->vdivs, model->num_vdivs);
|
||||
break;
|
||||
default:
|
||||
return SR_ERR_NA;
|
||||
|
|
|
@ -458,9 +458,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 *tuple, *rational[2];
|
||||
GVariantBuilder gvb;
|
||||
unsigned int i;
|
||||
GVariant *gvar;
|
||||
struct dev_context *devc;
|
||||
|
||||
|
@ -492,14 +490,7 @@ static int config_list(uint32_t key, GVariant **data, const struct sr_dev_inst *
|
|||
*data = g_variant_new_strv(devc->coupling_vals, devc->coupling_tab_size);
|
||||
break;
|
||||
case SR_CONF_VDIV:
|
||||
g_variant_builder_init(&gvb, G_VARIANT_TYPE_ARRAY);
|
||||
for (i = 0; i < ARRAY_SIZE(vdivs); i++) {
|
||||
rational[0] = g_variant_new_uint64(vdivs[i][0]);
|
||||
rational[1] = g_variant_new_uint64(vdivs[i][1]);
|
||||
tuple = g_variant_new_tuple(rational, 2);
|
||||
g_variant_builder_add_value(&gvb, tuple);
|
||||
}
|
||||
*data = g_variant_builder_end(&gvb);
|
||||
*data = std_gvar_tuple_array(&vdivs, ARRAY_SIZE(vdivs));
|
||||
break;
|
||||
default:
|
||||
return SR_ERR_NA;
|
||||
|
|
|
@ -595,9 +595,6 @@ 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 *tuple, *rational[2];
|
||||
GVariantBuilder gvb;
|
||||
unsigned int i;
|
||||
|
||||
if (!cg) {
|
||||
switch (key) {
|
||||
|
@ -612,14 +609,7 @@ static int config_list(uint32_t key, GVariant **data, const struct sr_dev_inst *
|
|||
devc->profile->buffersizes, NUM_BUFFER_SIZES, sizeof(uint64_t));
|
||||
break;
|
||||
case SR_CONF_TIMEBASE:
|
||||
g_variant_builder_init(&gvb, G_VARIANT_TYPE_ARRAY);
|
||||
for (i = 0; i < ARRAY_SIZE(timebases); i++) {
|
||||
rational[0] = g_variant_new_uint64(timebases[i][0]);
|
||||
rational[1] = g_variant_new_uint64(timebases[i][1]);
|
||||
tuple = g_variant_new_tuple(rational, 2);
|
||||
g_variant_builder_add_value(&gvb, tuple);
|
||||
}
|
||||
*data = g_variant_builder_end(&gvb);
|
||||
*data = std_gvar_tuple_array(&timebases, ARRAY_SIZE(timebases));
|
||||
break;
|
||||
case SR_CONF_TRIGGER_SOURCE:
|
||||
*data = g_variant_new_strv(trigger_sources,
|
||||
|
@ -642,14 +632,7 @@ static int config_list(uint32_t key, GVariant **data, const struct sr_dev_inst *
|
|||
*data = g_variant_new_strv(coupling, ARRAY_SIZE(coupling));
|
||||
break;
|
||||
case SR_CONF_VDIV:
|
||||
g_variant_builder_init(&gvb, G_VARIANT_TYPE_ARRAY);
|
||||
for (i = 0; i < ARRAY_SIZE(vdivs); i++) {
|
||||
rational[0] = g_variant_new_uint64(vdivs[i][0]);
|
||||
rational[1] = g_variant_new_uint64(vdivs[i][1]);
|
||||
tuple = g_variant_new_tuple(rational, 2);
|
||||
g_variant_builder_add_value(&gvb, tuple);
|
||||
}
|
||||
*data = g_variant_builder_end(&gvb);
|
||||
*data = std_gvar_tuple_array(&vdivs, ARRAY_SIZE(vdivs));
|
||||
break;
|
||||
default:
|
||||
return SR_ERR_NA;
|
||||
|
|
|
@ -560,9 +560,8 @@ static int config_list(uint32_t key, GVariant **data, const struct sr_dev_inst *
|
|||
const struct sr_channel_group *cg)
|
||||
{
|
||||
GVariantBuilder gvb;
|
||||
GVariant *gvar, *rational[2];
|
||||
GVariant *gvar;
|
||||
GSList *l;
|
||||
int i;
|
||||
|
||||
switch (key) {
|
||||
case SR_CONF_SCAN_OPTIONS:
|
||||
|
@ -616,14 +615,7 @@ static int config_list(uint32_t key, GVariant **data, const struct sr_dev_inst *
|
|||
buffersizes, ARRAY_SIZE(buffersizes), sizeof(uint64_t));
|
||||
break;
|
||||
case SR_CONF_VDIV:
|
||||
g_variant_builder_init(&gvb, G_VARIANT_TYPE_ARRAY);
|
||||
for (i = 0; i < (int)ARRAY_SIZE(vdivs); i++) {
|
||||
rational[0] = g_variant_new_uint64(vdivs[i][0]);
|
||||
rational[1] = g_variant_new_uint64(vdivs[i][1]);
|
||||
gvar = g_variant_new_tuple(rational, 2);
|
||||
g_variant_builder_add_value(&gvb, gvar);
|
||||
}
|
||||
*data = g_variant_builder_end(&gvb);
|
||||
*data = std_gvar_tuple_array(&vdivs, ARRAY_SIZE(vdivs));
|
||||
break;
|
||||
case SR_CONF_COUPLING:
|
||||
*data = g_variant_new_strv(coupling, ARRAY_SIZE(coupling));
|
||||
|
|
|
@ -324,22 +324,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 *tuple, *rational[2];
|
||||
GVariantBuilder gvb;
|
||||
unsigned int i;
|
||||
|
||||
switch (key) {
|
||||
case SR_CONF_DEVICE_OPTIONS:
|
||||
return STD_CONFIG_LIST(key, data, sdi, cg, NULL, drvopts, 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++) {
|
||||
rational[0] = g_variant_new_uint64(kecheng_kc_330b_sample_intervals[i][0]);
|
||||
rational[1] = g_variant_new_uint64(kecheng_kc_330b_sample_intervals[i][1]);
|
||||
tuple = g_variant_new_tuple(rational, 2);
|
||||
g_variant_builder_add_value(&gvb, tuple);
|
||||
}
|
||||
*data = g_variant_builder_end(&gvb);
|
||||
*data = std_gvar_tuple_array(&kecheng_kc_330b_sample_intervals,
|
||||
ARRAY_SIZE(kecheng_kc_330b_sample_intervals));
|
||||
break;
|
||||
case SR_CONF_SPL_WEIGHT_FREQ:
|
||||
*data = g_variant_new_strv(weight_freq, ARRAY_SIZE(weight_freq));
|
||||
|
|
|
@ -213,25 +213,6 @@ static int config_get(uint32_t key, GVariant **data,
|
|||
return SR_OK;
|
||||
}
|
||||
|
||||
static GVariant *build_tuples(const struct sr_rational *array, unsigned int n)
|
||||
{
|
||||
unsigned int i;
|
||||
GVariant *rational[2];
|
||||
GVariantBuilder gvb;
|
||||
|
||||
g_variant_builder_init(&gvb, G_VARIANT_TYPE_ARRAY);
|
||||
|
||||
for (i = 0; i < n; i++) {
|
||||
rational[0] = g_variant_new_uint64(array[i].p);
|
||||
rational[1] = g_variant_new_uint64(array[i].q);
|
||||
|
||||
/* FIXME: Valgrind reports a memory leak here. */
|
||||
g_variant_builder_add_value(&gvb, g_variant_new_tuple(rational, 2));
|
||||
}
|
||||
|
||||
return g_variant_builder_end(&gvb);
|
||||
}
|
||||
|
||||
static int config_set(uint32_t key, GVariant *data,
|
||||
const struct sr_dev_inst *sdi, const struct sr_channel_group *cg)
|
||||
{
|
||||
|
@ -423,12 +404,12 @@ static int config_list(uint32_t key, GVariant **data,
|
|||
case SR_CONF_TIMEBASE:
|
||||
if (!model)
|
||||
return SR_ERR_ARG;
|
||||
*data = build_tuples(model->timebases, model->num_timebases);
|
||||
*data = std_gvar_tuple_rational(model->timebases, model->num_timebases);
|
||||
break;
|
||||
case SR_CONF_VDIV:
|
||||
if (!model)
|
||||
return SR_ERR_ARG;
|
||||
*data = build_tuples(model->vdivs, model->num_vdivs);
|
||||
*data = std_gvar_tuple_rational(model->vdivs, model->num_vdivs);
|
||||
break;
|
||||
default:
|
||||
return SR_ERR_NA;
|
||||
|
|
|
@ -239,10 +239,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)
|
||||
{
|
||||
GVariant *tuple, *range[2];
|
||||
GVariantBuilder gvb;
|
||||
unsigned int i;
|
||||
|
||||
switch (key) {
|
||||
case SR_CONF_SCAN_OPTIONS:
|
||||
case SR_CONF_DEVICE_OPTIONS:
|
||||
|
@ -254,14 +250,7 @@ static int config_list(uint32_t key, GVariant **data,
|
|||
*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);
|
||||
*data = std_gvar_tuple_array(&meas_ranges, ARRAY_SIZE(meas_ranges));
|
||||
break;
|
||||
case SR_CONF_DATA_SOURCE:
|
||||
*data = g_variant_new_strv(data_sources, ARRAY_SIZE(data_sources));
|
||||
|
|
|
@ -840,8 +840,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)
|
||||
{
|
||||
GVariant *tuple, *rational[2];
|
||||
GVariantBuilder gvb;
|
||||
unsigned int i;
|
||||
struct dev_context *devc;
|
||||
|
||||
|
@ -884,14 +882,7 @@ static int config_list(uint32_t key, GVariant **data, const struct sr_dev_inst *
|
|||
return SR_ERR_ARG;
|
||||
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]);
|
||||
rational[1] = g_variant_new_uint64(devc->vdivs[i][1]);
|
||||
tuple = g_variant_new_tuple(rational, 2);
|
||||
g_variant_builder_add_value(&gvb, tuple);
|
||||
}
|
||||
*data = g_variant_builder_end(&gvb);
|
||||
*data = std_gvar_tuple_array((const uint64_t (*)[][2])devc->vdivs, devc->num_vdivs);
|
||||
break;
|
||||
case SR_CONF_TIMEBASE:
|
||||
if (!devc)
|
||||
|
@ -899,14 +890,7 @@ static int config_list(uint32_t key, GVariant **data, const struct sr_dev_inst *
|
|||
return SR_ERR_ARG;
|
||||
if (devc->num_timebases <= 0)
|
||||
return SR_ERR_NA;
|
||||
g_variant_builder_init(&gvb, G_VARIANT_TYPE_ARRAY);
|
||||
for (i = 0; i < devc->num_timebases; i++) {
|
||||
rational[0] = g_variant_new_uint64(devc->timebases[i][0]);
|
||||
rational[1] = g_variant_new_uint64(devc->timebases[i][1]);
|
||||
tuple = g_variant_new_tuple(rational, 2);
|
||||
g_variant_builder_add_value(&gvb, tuple);
|
||||
}
|
||||
*data = g_variant_builder_end(&gvb);
|
||||
*data = std_gvar_tuple_array((const uint64_t (*)[][2])devc->timebases, devc->num_timebases);
|
||||
break;
|
||||
case SR_CONF_TRIGGER_SOURCE:
|
||||
if (!devc)
|
||||
|
|
|
@ -283,25 +283,6 @@ static int config_get(uint32_t key, GVariant **data, const struct sr_dev_inst *s
|
|||
return ret;
|
||||
}
|
||||
|
||||
static GVariant *build_tuples(const uint64_t (*array)[][2], unsigned int n)
|
||||
{
|
||||
unsigned int i;
|
||||
GVariant *rational[2];
|
||||
GVariantBuilder gvb;
|
||||
|
||||
g_variant_builder_init(&gvb, G_VARIANT_TYPE_ARRAY);
|
||||
|
||||
for (i = 0; i < n; i++) {
|
||||
rational[0] = g_variant_new_uint64((*array)[i][0]);
|
||||
rational[1] = g_variant_new_uint64((*array)[i][1]);
|
||||
|
||||
/* FIXME: Valgrind reports a memory leak here. */
|
||||
g_variant_builder_add_value(&gvb, g_variant_new_tuple(rational, 2));
|
||||
}
|
||||
|
||||
return g_variant_builder_end(&gvb);
|
||||
}
|
||||
|
||||
static int config_set(uint32_t key, GVariant *data, const struct sr_dev_inst *sdi,
|
||||
const struct sr_channel_group *cg)
|
||||
{
|
||||
|
@ -482,7 +463,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_TIMEBASE:
|
||||
*data = build_tuples(&dlm_timebases, ARRAY_SIZE(dlm_timebases));
|
||||
*data = std_gvar_tuple_array(&dlm_timebases, ARRAY_SIZE(dlm_timebases));
|
||||
return SR_OK;
|
||||
case SR_CONF_TRIGGER_SOURCE:
|
||||
if (!model)
|
||||
|
@ -527,7 +508,7 @@ static int config_list(uint32_t key, GVariant **data, const struct sr_dev_inst *
|
|||
case SR_CONF_VDIV:
|
||||
if (cg_type == CG_NONE)
|
||||
return SR_ERR_CHANNEL_GROUP;
|
||||
*data = build_tuples(&dlm_vdivs, ARRAY_SIZE(dlm_vdivs));
|
||||
*data = std_gvar_tuple_array(&dlm_vdivs, ARRAY_SIZE(dlm_vdivs));
|
||||
break;
|
||||
default:
|
||||
return SR_ERR_NA;
|
||||
|
|
|
@ -956,6 +956,10 @@ SR_PRIV int std_opts_config_list(uint32_t key, GVariant **data,
|
|||
std_opts_config_list(key, data, sdi, cg, ARRAY_AND_SIZE(scanopts), \
|
||||
ARRAY_AND_SIZE(drvopts), ARRAY_AND_SIZE(devopts))
|
||||
|
||||
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);
|
||||
|
||||
|
||||
/*--- resource.c ------------------------------------------------------------*/
|
||||
|
||||
SR_PRIV int64_t sr_file_get_size(FILE *file);
|
||||
|
|
38
src/std.c
38
src/std.c
|
@ -540,3 +540,41 @@ SR_PRIV int std_opts_config_list(uint32_t key, GVariant **data,
|
|||
|
||||
return SR_OK;
|
||||
}
|
||||
|
||||
SR_PRIV GVariant *std_gvar_tuple_array(const uint64_t (*a)[][2], unsigned int n)
|
||||
{
|
||||
unsigned int i;
|
||||
GVariant *rational[2];
|
||||
GVariantBuilder gvb;
|
||||
|
||||
g_variant_builder_init(&gvb, G_VARIANT_TYPE_ARRAY);
|
||||
|
||||
for (i = 0; i < n; i++) {
|
||||
rational[0] = g_variant_new_uint64((*a)[i][0]);
|
||||
rational[1] = g_variant_new_uint64((*a)[i][1]);
|
||||
|
||||
/* FIXME: Valgrind reports a memory leak here. */
|
||||
g_variant_builder_add_value(&gvb, g_variant_new_tuple(rational, 2));
|
||||
}
|
||||
|
||||
return g_variant_builder_end(&gvb);
|
||||
}
|
||||
|
||||
SR_PRIV GVariant *std_gvar_tuple_rational(const struct sr_rational *r, unsigned int n)
|
||||
{
|
||||
unsigned int i;
|
||||
GVariant *rational[2];
|
||||
GVariantBuilder gvb;
|
||||
|
||||
g_variant_builder_init(&gvb, G_VARIANT_TYPE_ARRAY);
|
||||
|
||||
for (i = 0; i < n; i++) {
|
||||
rational[0] = g_variant_new_uint64(r[i].p);
|
||||
rational[1] = g_variant_new_uint64(r[i].q);
|
||||
|
||||
/* FIXME: Valgrind reports a memory leak here. */
|
||||
g_variant_builder_add_value(&gvb, g_variant_new_tuple(rational, 2));
|
||||
}
|
||||
|
||||
return g_variant_builder_end(&gvb);
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue