ipdbg-la: Simplify config_get/_set/_list.

This commit is contained in:
Uwe Hermann 2018-08-30 00:47:03 +02:00
parent 1f9652a861
commit 77b6b98d1c
1 changed files with 10 additions and 35 deletions

View File

@ -190,12 +190,10 @@ static int dev_close(struct sr_dev_inst *sdi)
static int config_get(uint32_t key, GVariant **data, static int config_get(uint32_t key, GVariant **data,
const struct sr_dev_inst *sdi, const struct sr_channel_group *cg) const struct sr_dev_inst *sdi, const struct sr_channel_group *cg)
{ {
int ret = SR_OK; struct dev_context *devc = sdi->priv;
(void)cg; (void)cg;
struct dev_context *devc = sdi->priv;
switch (key) { switch (key) {
case SR_CONF_CAPTURE_RATIO: case SR_CONF_CAPTURE_RATIO:
*data = g_variant_new_uint64(devc->capture_ratio); *data = g_variant_new_uint64(devc->capture_ratio);
@ -204,68 +202,45 @@ static int config_get(uint32_t key, GVariant **data,
*data = g_variant_new_uint64(devc->limit_samples); *data = g_variant_new_uint64(devc->limit_samples);
break; break;
default: default:
ret = SR_ERR_NA; return SR_ERR_NA;
} }
return ret; return SR_OK;
} }
static int config_set(uint32_t key, GVariant *data, static int config_set(uint32_t key, GVariant *data,
const struct sr_dev_inst *sdi, const struct sr_channel_group *cg) const struct sr_dev_inst *sdi, const struct sr_channel_group *cg)
{ {
int ret = SR_OK; struct dev_context *devc = sdi->priv;
uint64_t value;
(void)cg; (void)cg;
if (sdi->status != SR_ST_ACTIVE) if (sdi->status != SR_ST_ACTIVE)
return SR_ERR_DEV_CLOSED; return SR_ERR_DEV_CLOSED;
struct dev_context *devc = sdi->priv;
switch (key) { switch (key) {
case SR_CONF_CAPTURE_RATIO: case SR_CONF_CAPTURE_RATIO:
value = g_variant_get_uint64(data); devc->capture_ratio = g_variant_get_uint64(data);
if (value <= 100)
devc->capture_ratio = value;
else
ret = SR_ERR;
break; break;
case SR_CONF_LIMIT_SAMPLES: case SR_CONF_LIMIT_SAMPLES:
value = g_variant_get_uint64(data); devc->limit_samples = g_variant_get_uint64(data);
if (value <= devc->limit_samples_max)
devc->limit_samples = value;
else
ret = SR_ERR;
break; break;
default: default:
ret = SR_ERR_NA; return SR_ERR_NA;
} }
return ret; return SR_OK;
} }
static int config_list(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) const struct sr_dev_inst *sdi, const struct sr_channel_group *cg)
{ {
(void)cg;
switch (key) { switch (key) {
case SR_CONF_SCAN_OPTIONS: 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: case SR_CONF_DEVICE_OPTIONS:
if (!sdi) return STD_CONFIG_LIST(key, data, sdi, cg, scanopts, drvopts, devopts);
*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;
case SR_CONF_TRIGGER_MATCH: case SR_CONF_TRIGGER_MATCH:
*data = g_variant_new_fixed_array(G_VARIANT_TYPE_INT32, *data = std_gvar_array_i32(ARRAY_AND_SIZE(trigger_matches));
trigger_matches, ARRAY_SIZE(trigger_matches), sizeof(int32_t));
break; break;
default: default:
return SR_ERR_NA; return SR_ERR_NA;