sr_config_set(): Factor out SR_ERR_DEV_CLOSED check.

This ensures consistent checks and log messages across all drivers
and reduces the per-driver boilerplate.
This commit is contained in:
Uwe Hermann 2017-07-06 20:05:43 +02:00
parent f670835f1f
commit c3cd66a00c
54 changed files with 5 additions and 159 deletions

View File

@ -227,9 +227,6 @@ static int config_set(uint32_t key, GVariant *data, const struct sr_dev_inst *sd
(void)cg;
if (sdi->status != SR_ST_ACTIVE)
return SR_ERR_DEV_CLOSED;
devc = sdi->priv;
ret = SR_OK;

View File

@ -139,9 +139,6 @@ static int config_set(uint32_t key, GVariant *data, const struct sr_dev_inst *sd
(void)cg;
if (sdi->status != SR_ST_ACTIVE)
return SR_ERR_DEV_CLOSED;
devc = sdi->priv;
switch (key) {

View File

@ -278,9 +278,6 @@ static int config_set(uint32_t key, GVariant *data,
(void)cg;
if (sdi->status != SR_ST_ACTIVE)
return SR_ERR_DEV_CLOSED;
devc = sdi->priv;
ret = SR_OK;

View File

@ -212,9 +212,6 @@ static int config_set(uint32_t key, GVariant *data, const struct sr_dev_inst *sd
(void)cg;
if (sdi->status != SR_ST_ACTIVE)
return SR_ERR_DEV_CLOSED;
devc = sdi->priv;
ret = SR_OK;

View File

@ -261,9 +261,6 @@ static int config_set(uint32_t key, GVariant *data, const struct sr_dev_inst *sd
const char *sval;
gboolean bval;
if (sdi->status != SR_ST_ACTIVE)
return SR_ERR_DEV_CLOSED;
ret = SR_OK;
devc = sdi->priv;
if (!cg) {

View File

@ -193,9 +193,6 @@ static int config_set(uint32_t key, GVariant *data,
uint64_t samplerate;
int ret;
if (sdi->status != SR_ST_ACTIVE)
return SR_ERR_DEV_CLOSED;
devc = sdi->priv;
ret = SR_OK;

View File

@ -210,9 +210,6 @@ static int config_set(uint32_t key, GVariant *data, const struct sr_dev_inst *sd
(void)cg;
if (sdi->status != SR_ST_ACTIVE)
return SR_ERR_DEV_CLOSED;
switch (key) {
case SR_CONF_SAMPLERATE:
devc->cur_samplerate = g_variant_get_uint64(data);

View File

@ -176,9 +176,6 @@ static int config_set(uint32_t key, GVariant *data, const struct sr_dev_inst *sd
(void)cg;
if (sdi->status != SR_ST_ACTIVE)
return SR_ERR_DEV_CLOSED;
devc = sdi->priv;
return sr_sw_limits_config_set(&devc->sw_limits, key, data);

View File

@ -125,9 +125,6 @@ static int config_set(uint32_t key, GVariant *data, const struct sr_dev_inst *sd
(void)cg;
if (sdi->status != SR_ST_ACTIVE)
return SR_ERR_DEV_CLOSED;
devc = sdi->priv;
return sr_sw_limits_config_set(&devc->sw_limits, key, data);

View File

@ -208,9 +208,6 @@ static int config_set(uint32_t key, GVariant *data, const struct sr_dev_inst *sd
(void)cg;
if (sdi->status != SR_ST_ACTIVE)
return SR_ERR_DEV_CLOSED;
devc = sdi->priv;
ret = SR_OK;

View File

@ -127,9 +127,6 @@ static int config_set(uint32_t key, GVariant *data, const struct sr_dev_inst *sd
(void)cg;
if (sdi->status != SR_ST_ACTIVE)
return SR_ERR_DEV_CLOSED;
devc = sdi->priv;
return sr_sw_limits_config_set(&devc->sw_limits, key, data);

View File

@ -337,9 +337,6 @@ static int config_set(uint32_t key, GVariant *data, const struct sr_dev_inst *sd
(void)cg;
if (sdi->status != SR_ST_ACTIVE)
return SR_ERR_DEV_CLOSED;
devc = sdi->priv;
switch (key) {

View File

@ -88,9 +88,6 @@ static int config_set(uint32_t key, GVariant *data, const struct sr_dev_inst *sd
(void)cg;
if (sdi->status != SR_ST_ACTIVE)
return SR_ERR_DEV_CLOSED;
devc = sdi->priv;
return sr_sw_limits_config_set(&devc->limits, key, data);

View File

@ -103,9 +103,6 @@ static int config_set(uint32_t key, GVariant *data, const struct sr_dev_inst *sd
(void)cg;
if (sdi->status != SR_ST_ACTIVE)
return SR_ERR_DEV_CLOSED;
switch (key) {
case SR_CONF_VOLTAGE:
dblval = g_variant_get_double(data);

View File

@ -288,9 +288,6 @@ static int config_set(uint32_t key, GVariant *data, const struct sr_dev_inst *sd
devc = sdi->priv;
if (sdi->status != SR_ST_ACTIVE)
return SR_ERR_DEV_CLOSED;
ret = SR_OK;
switch (key) {
case SR_CONF_SAMPLERATE:

View File

@ -505,9 +505,6 @@ static int config_set(uint32_t key, GVariant *data,
if (!sdi)
return SR_ERR_ARG;
if (sdi->status != SR_ST_ACTIVE)
return SR_ERR;
devc = sdi->priv;
ret = SR_OK;

View File

@ -186,9 +186,6 @@ static int config_set(uint32_t key, GVariant *data, const struct sr_dev_inst *sd
(void)cg;
if (sdi->status != SR_ST_ACTIVE)
return SR_ERR_DEV_CLOSED;
devc = sdi->priv;
return sr_sw_limits_config_set(&devc->limits, key, data);

View File

@ -369,9 +369,6 @@ static int config_set(uint32_t key, GVariant *data,
(void)cg;
if (sdi->status != SR_ST_ACTIVE)
return SR_ERR_DEV_CLOSED;
devc = sdi->priv;
ret = SR_OK;

View File

@ -504,9 +504,6 @@ static int config_set(uint32_t key, GVariant *data,
if (!sdi)
return SR_ERR_ARG;
if (sdi->status != SR_ST_ACTIVE)
return SR_ERR;
devc = sdi->priv;
ret = SR_OK;

View File

@ -1505,9 +1505,6 @@ SR_PRIV int config_set(uint32_t key, GVariant *data, const struct sr_dev_inst *s
(void)cg;
if (sdi->status != SR_ST_ACTIVE)
return SR_ERR_DEV_CLOSED;
devc = sdi->priv;
switch (key) {

View File

@ -153,9 +153,6 @@ static int config_set(uint32_t key, GVariant *data, const struct sr_dev_inst *sd
if (!sdi)
return SR_ERR_ARG;
if (sdi->status != SR_ST_ACTIVE)
return SR_ERR_DEV_CLOSED;
devc = sdi->priv;
switch (key) {

View File

@ -401,9 +401,6 @@ static int config_set(uint32_t key, GVariant *data, const struct sr_dev_inst *sd
unsigned int i;
const char *tmp_str;
if (sdi->status != SR_ST_ACTIVE)
return SR_ERR_DEV_CLOSED;
ret = SR_OK;
devc = sdi->priv;
if (!cg) {

View File

@ -491,9 +491,6 @@ static int config_set(uint32_t key, GVariant *data, const struct sr_dev_inst *sd
unsigned int i;
const char *tmp_str;
if (sdi->status != SR_ST_ACTIVE)
return SR_ERR_DEV_CLOSED;
ret = SR_OK;
devc = sdi->priv;
if (!cg) {

View File

@ -263,9 +263,6 @@ static int config_set(uint32_t key, GVariant *data,
(void)cg;
if (sdi->status != SR_ST_ACTIVE)
return SR_ERR_DEV_CLOSED;
devc = sdi->priv;
ret = SR_OK;

View File

@ -434,9 +434,6 @@ static int config_set(uint32_t key, GVariant *data, const struct sr_dev_inst *sd
if (cg) /* sr_config_set will validate cg using config_list */
ch = ((struct sr_channel *)cg->channels->data)->index;
if (sdi->status != SR_ST_ACTIVE)
return SR_ERR_DEV_CLOSED;
ret = SR_OK;
switch (key) {
case SR_CONF_LIMIT_FRAMES:

View File

@ -288,9 +288,6 @@ static int config_set(uint32_t key, GVariant *data, const struct sr_dev_inst *sd
(void)cg;
if (sdi->status != SR_ST_ACTIVE)
return SR_ERR_DEV_CLOSED;
switch (key) {
case SR_CONF_LIMIT_SAMPLES:
limit_samples = g_variant_get_uint64(data);

View File

@ -261,9 +261,6 @@ static int config_set(uint32_t key, GVariant *data, const struct sr_dev_inst *sd
(void)cg;
if (sdi->status != SR_ST_ACTIVE)
return SR_ERR_DEV_CLOSED;
devc = sdi->priv;
switch (key) {

View File

@ -261,9 +261,6 @@ static int config_set(uint32_t key, GVariant *data, const struct sr_dev_inst *sd
(void)cg;
if (sdi->status != SR_ST_ACTIVE)
return SR_ERR_DEV_CLOSED;
devc = sdi->priv;
ret = SR_OK;
switch (key) {

View File

@ -117,9 +117,6 @@ static int config_set(uint32_t key, GVariant *data, const struct sr_dev_inst *sd
(void)cg;
if (sdi->status != SR_ST_ACTIVE)
return SR_ERR_DEV_CLOSED;
devc = sdi->priv;
return sr_sw_limits_config_set(&devc->limits, key, data);

View File

@ -220,9 +220,6 @@ static int config_set(uint32_t key, GVariant *data,
(void)cg;
if (sdi->status != SR_ST_ACTIVE)
return SR_ERR_DEV_CLOSED;
devc = sdi->priv;
switch (key) {

View File

@ -164,9 +164,6 @@ static int config_set(uint32_t key, GVariant *data, const struct sr_dev_inst *sd
(void)cg;
if (sdi->status != SR_ST_ACTIVE)
return SR_ERR_DEV_CLOSED;
devc = sdi->priv;
ret = SR_OK;
switch (key) {

View File

@ -390,9 +390,6 @@ static int config_set(uint32_t key, GVariant *data,
devc = sdi->priv;
if (sdi->status != SR_ST_ACTIVE)
return SR_ERR_DEV_CLOSED;
switch (key) {
case SR_CONF_SAMPLERATE:
return lls_set_samplerate(sdi, g_variant_get_uint64(data));

View File

@ -238,9 +238,6 @@ static int config_set(int key, GVariant *data, const struct sr_dev_inst *sdi,
devc = sdi->priv;
if (sdi->status != SR_ST_ACTIVE)
return SR_ERR_DEV_CLOSED;
switch (key) {
case SR_CONF_SAMPLERATE:
// FIXME

View File

@ -233,9 +233,6 @@ static int config_set(uint32_t key, GVariant *data, const struct sr_dev_inst *sd
(void)cg;
if (sdi->status != SR_ST_ACTIVE)
return SR_ERR_DEV_CLOSED;
devc = sdi->priv;
switch (key) {

View File

@ -332,9 +332,6 @@ static int config_set(uint32_t key, GVariant *data, const struct sr_dev_inst *sd
(void)cg;
if (sdi->status != SR_ST_ACTIVE)
return SR_ERR_DEV_CLOSED;
modbus = sdi->conn;
devc = sdi->priv;

View File

@ -134,9 +134,6 @@ static int config_set(uint32_t key, GVariant *data, const struct sr_dev_inst *sd
(void)cg;
if (sdi->status != SR_ST_ACTIVE)
return SR_ERR_DEV_CLOSED;
devc = sdi->priv;
return sr_sw_limits_config_set(&devc->limits, key, data);

View File

@ -576,9 +576,6 @@ static int config_set(uint32_t key, GVariant *data, const struct sr_dev_inst *sd
int idx;
gboolean found;
if (sdi->status != SR_ST_ACTIVE)
return SR_ERR_DEV_CLOSED;
devc = sdi->priv;
/* Cannot change settings while acquisition active, would cause a mess with commands.

View File

@ -168,9 +168,6 @@ static int config_set(uint32_t key, GVariant *data, const struct sr_dev_inst *sd
(void)cg;
if (sdi->status != SR_ST_ACTIVE)
return SR_ERR_DEV_CLOSED;
devc = sdi->priv;
return sr_sw_limits_config_set(&devc->limits, key, data);

View File

@ -237,9 +237,6 @@ static int config_set(uint32_t key, GVariant *data, const struct sr_dev_inst *sd
(void)cg;
if (sdi->status != SR_ST_ACTIVE)
return SR_ERR_DEV_CLOSED;
devc = sdi->priv;
switch (key) {

View File

@ -180,9 +180,6 @@ static int config_set(uint32_t key, GVariant *data, const struct sr_dev_inst *sd
(void)cg;
if (sdi->status != SR_ST_ACTIVE)
return SR_ERR_DEV_CLOSED;
devc = sdi->priv;
ret = SR_OK;

View File

@ -257,9 +257,6 @@ static int config_set(uint32_t key, GVariant *data, const struct sr_dev_inst *sd
(void)cg;
if (sdi->status != SR_ST_ACTIVE)
return SR_ERR_DEV_CLOSED;
devc = sdi->priv;
switch (key) {

View File

@ -670,9 +670,6 @@ static int config_set(uint32_t key, GVariant *data, const struct sr_dev_inst *sd
devc = sdi->priv;
if (sdi->status != SR_ST_ACTIVE)
return SR_ERR_DEV_CLOSED;
/* If a channel group is specified, it must be a valid one. */
if (cg && !g_slist_find(sdi->channel_groups, cg)) {
sr_err("Invalid channel group specified.");

View File

@ -215,9 +215,6 @@ static int config_set(uint32_t key, GVariant *data,
if (!sdi)
return SR_ERR_ARG;
if (sdi->status != SR_ST_ACTIVE)
return SR_ERR_DEV_CLOSED;
switch (key) {
case SR_CONF_OUTPUT_FREQUENCY:
value_f = g_variant_get_double(data);

View File

@ -259,8 +259,6 @@ static int config_set(uint32_t key, GVariant *data,
(void)cg;
if (sdi->status != SR_ST_ACTIVE)
return SR_ERR_DEV_CLOSED;
devc = sdi->priv;
ret = SR_OK;

View File

@ -460,9 +460,6 @@ static int config_set(uint32_t key, GVariant *data, const struct sr_dev_inst *sd
(void)cg;
if (sdi->status != SR_ST_ACTIVE)
return SR_ERR_DEV_CLOSED;
devc = sdi->priv;
ret = SR_OK;

View File

@ -450,9 +450,6 @@ static int config_set(uint32_t key, GVariant *data, const struct sr_dev_inst *sd
if (!sdi)
return SR_ERR_ARG;
if (sdi->status != SR_ST_ACTIVE)
return SR_ERR_DEV_CLOSED;
if (cg)
/* Channel group specified. */
select_channel(sdi, cg->channels->data);

View File

@ -144,9 +144,6 @@ static int config_set(uint32_t key, GVariant *data, const struct sr_dev_inst *sd
(void)cg;
if (sdi->status != SR_ST_ACTIVE)
return SR_ERR_DEV_CLOSED;
devc = sdi->priv;
return sr_sw_limits_config_set(&devc->limits, key, data);

View File

@ -128,9 +128,6 @@ static int config_set(uint32_t key, GVariant *data, const struct sr_dev_inst *sd
(void)cg;
if (sdi->status != SR_ST_ACTIVE)
return SR_ERR_DEV_CLOSED;
devc = sdi->priv;
return sr_sw_limits_config_set(&devc->sw_limits, key, data);

View File

@ -218,9 +218,6 @@ static int config_set(uint32_t key, GVariant *data, const struct sr_dev_inst *sd
(void)cg;
if (sdi->status != SR_ST_ACTIVE)
return SR_ERR_DEV_CLOSED;
return sr_sw_limits_config_set(&devc->sw_limits, key, data);
}

View File

@ -98,9 +98,6 @@ static int config_set(uint32_t key, GVariant *data, const struct sr_dev_inst *sd
(void)cg;
if (sdi->status != SR_ST_ACTIVE)
return SR_ERR_DEV_CLOSED;
devc = sdi->priv;
return sr_sw_limits_config_set(&devc->limits, key, data);

View File

@ -182,9 +182,6 @@ static int config_set(uint32_t key, GVariant *data, const struct sr_dev_inst *sd
(void)cg;
if (sdi->status != SR_ST_ACTIVE)
return SR_ERR_DEV_CLOSED;
devc = sdi->priv;
switch (key) {

View File

@ -177,9 +177,6 @@ static int config_set(uint32_t key, GVariant *data, const struct sr_dev_inst *sd
(void)cg;
if (sdi->status != SR_ST_ACTIVE)
return SR_ERR_DEV_CLOSED;
devc = sdi->priv;
return sr_sw_limits_config_set(&devc->limits, key, data);

View File

@ -376,9 +376,6 @@ static int config_set(uint32_t key, GVariant *data, const struct sr_dev_inst *sd
(void)cg;
if (sdi->status != SR_ST_ACTIVE)
return SR_ERR_DEV_CLOSED;
devc = sdi->priv;
switch (key) {

View File

@ -805,7 +805,11 @@ SR_API int sr_config_set(const struct sr_dev_inst *sdi,
ret = SR_ERR;
else if (!sdi->driver->config_set)
ret = SR_ERR_ARG;
else if (check_key(sdi->driver, sdi, cg, key, SR_CONF_SET, data) != SR_OK)
else if (sdi->status != SR_ST_ACTIVE) {
sr_err("%s: Device instance not active, can't set config.",
sdi->driver->name);
ret = SR_ERR_DEV_CLOSED;
} else if (check_key(sdi->driver, sdi, cg, key, SR_CONF_SET, data) != SR_OK)
return SR_ERR_ARG;
else if ((ret = sr_variant_type_check(key, data)) == SR_OK) {
log_key(sdi, cg, key, SR_CONF_SET, data);