return SR_OK;
}
+gboolean config_key_has_cap(struct sr_dev_driver *driver,
+ const struct sr_dev_inst *sdi, struct sr_channel_group *cg,
+ uint32_t key, uint32_t capability)
+{
+ GVariant *gvar_opts;
+ const uint32_t *opts;
+ gsize num_opts, i;
+
+ if (sr_config_list(driver, sdi, cg, SR_CONF_DEVICE_OPTIONS,
+ &gvar_opts) != SR_OK)
+ return FALSE;
+
+ opts = g_variant_get_fixed_array(gvar_opts, &num_opts, sizeof(uint32_t));
+ for (i = 0; i < num_opts; i++) {
+ if ((opts[i] & SR_CONF_MASK) == key) {
+ if ((opts[i] & capability) == capability)
+ return TRUE;
+ else
+ return FALSE;
+ }
+ }
+
+ return FALSE;
+}
+
+int maybe_config_get(struct sr_dev_driver *driver,
+ const struct sr_dev_inst *sdi, struct sr_channel_group *cg,
+ uint32_t key, GVariant **gvar)
+{
+ if (config_key_has_cap(driver, sdi, cg, key, SR_CONF_GET))
+ return sr_config_get(driver, sdi, cg, key, gvar);
+
+ return SR_ERR_NA;
+}
+
+int maybe_config_set(struct sr_dev_driver *driver,
+ const struct sr_dev_inst *sdi, struct sr_channel_group *cg,
+ uint32_t key, GVariant *gvar)
+{
+ if (config_key_has_cap(driver, sdi, cg, key, SR_CONF_SET))
+ return sr_config_set(sdi, cg, key, gvar);
+
+ return SR_ERR_NA;
+}
+
+int maybe_config_list(struct sr_dev_driver *driver,
+ const struct sr_dev_inst *sdi, struct sr_channel_group *cg,
+ uint32_t key, GVariant **gvar)
+{
+ if (config_key_has_cap(driver, sdi, cg, key, SR_CONF_LIST))
+ return sr_config_list(driver, sdi, cg, key, gvar);
+
+ return SR_ERR_NA;
+}
+
static void get_option(void)
{
struct sr_dev_inst *sdi;
set_dev_options(sdi, devargs);
else devargs = NULL;
- if ((ret = sr_config_get(driver, sdi, cg, ci->key, &gvar)) != SR_OK)
+ if ((ret = maybe_config_get(driver, sdi, cg, ci->key, &gvar)) != SR_OK)
g_critical("Failed to get '%s': %s", opt_get, sr_strerror(ret));
s = g_variant_print(gvar, FALSE);
printf("%s\n", s);
return SR_ERR;
}
- if (sr_dev_has_option(sdi, SR_CONF_LIMIT_MSEC)) {
+ if (config_key_has_cap(driver, sdi, NULL, SR_CONF_LIMIT_MSEC, SR_CONF_SET)) {
gvar = g_variant_new_uint64(time_msec);
if (sr_config_set(sdi, NULL, SR_CONF_LIMIT_MSEC, gvar) != SR_OK) {
g_critical("Failed to configure time limit.");
return SR_ERR;
}
- } else if (sr_dev_has_option(sdi, SR_CONF_SAMPLERATE)) {
+ } else if (config_key_has_cap(driver, sdi, NULL, SR_CONF_SAMPLERATE,
+ SR_CONF_GET | SR_CONF_SET)) {
/* Convert to samples based on the samplerate. */
sr_config_get(driver, sdi, NULL, SR_CONF_SAMPLERATE, &gvar);
samplerate = g_variant_get_uint64(gvar);
rcvd_samples_logic = rcvd_samples_analog = 0;
- if (sr_config_get(driver, sdi, NULL, SR_CONF_SAMPLERATE,
+ if (maybe_config_get(driver, sdi, NULL, SR_CONF_SAMPLERATE,
&gvar) == SR_OK) {
samplerate = g_variant_get_uint64(gvar);
g_variant_unref(gvar);
if ((ret = opt_to_gvar(key, value, &src)) != 0)
return ret;
cg = select_channel_group(sdi);
- ret = sr_config_set(sdi, cg, src.key, src.data);
- if (ret != SR_OK) {
+ if ((ret = maybe_config_set(sr_dev_inst_driver_get(sdi), sdi, cg,
+ src.key, src.data)) != SR_OK) {
g_critical("Failed to set device option '%s'.", (char *)key);
return ret;
}
driver = sr_dev_inst_driver_get(sdi);
if (sr_config_list(driver, sdi, NULL, SR_CONF_DEVICE_OPTIONS, &gvar) != SR_OK) {
- g_critical("Failed to query sr_config_list(SR_CONF_DEVICE_OPTIONS).");
+ g_critical("Failed to query list device options.");
return;
}
sr_session_destroy(session);
return;
}
- if (sr_config_list(driver, sdi, NULL,
- SR_CONF_LIMIT_SAMPLES, &gvar) == SR_OK) {
+ if (maybe_config_list(driver, sdi, NULL, SR_CONF_LIMIT_SAMPLES,
+ &gvar) == SR_OK) {
/* The device has no compression, or compression is turned
* off, and publishes its sample memory size. */
g_variant_get(gvar, "(tt)", &min_samples, &max_samples);
}
}
gvar = g_variant_new_uint64(limit_samples);
- if (sr_config_set(sdi, NULL, SR_CONF_LIMIT_SAMPLES, gvar) != SR_OK) {
+ if (maybe_config_set(sr_dev_inst_driver_get(sdi), sdi, NULL, SR_CONF_LIMIT_SAMPLES, gvar) != SR_OK) {
g_critical("Failed to configure sample limit.");
sr_session_destroy(session);
return;
return;
}
gvar = g_variant_new_uint64(limit_frames);
- if (sr_config_set(sdi, NULL, SR_CONF_LIMIT_FRAMES, gvar) != SR_OK) {
+ if (maybe_config_set(sr_dev_inst_driver_get(sdi), sdi, NULL, SR_CONF_LIMIT_FRAMES, gvar) != SR_OK) {
g_critical("Failed to configure frame limit.");
sr_session_destroy(session);
return;
return pa->index - pb->index;
}
-static gboolean config_key_has_cap(const struct sr_dev_inst *sdi,
- struct sr_channel_group *cg, uint32_t key, uint32_t capability)
-{
- struct sr_dev_driver *driver;
- GVariant *gvar_opts;
- const uint32_t *opts;
- gsize num_opts, i;
-
- driver = sr_dev_inst_driver_get(sdi);
- if (sr_config_list(driver, sdi, cg, SR_CONF_DEVICE_OPTIONS,
- &gvar_opts) != SR_OK)
- return FALSE;
-
- opts = g_variant_get_fixed_array(gvar_opts, &num_opts, sizeof(uint32_t));
- for (i = 0; i < num_opts; i++) {
- if ((opts[i] & SR_CONF_MASK) == key) {
- if (opts[i] & capability)
- return TRUE;
- else
- return FALSE;
- }
- }
-
- return FALSE;
-}
-
-
static void print_dev_line(const struct sr_dev_inst *sdi)
{
struct sr_channel *ch;
s = g_string_sized_new(128);
g_string_assign(s, driver->name);
- if (config_key_has_cap(sdi, NULL, SR_CONF_CONN, SR_CONF_GET)
- && sr_config_get(driver, sdi, NULL, SR_CONF_CONN, &gvar) == SR_OK) {
+ if (maybe_config_get(driver, sdi, NULL, SR_CONF_CONN, &gvar) == SR_OK) {
g_string_append(s, ":conn=");
g_string_append(s, g_variant_get_string(gvar, NULL));
g_variant_unref(gvar);
continue;
if (key == SR_CONF_TRIGGER_MATCH) {
- if (sr_config_list(driver, sdi, channel_group, key,
+ if (maybe_config_list(driver, sdi, channel_group, key,
&gvar_list) != SR_OK) {
printf("\n");
continue;
printf("\n");
g_variant_unref(gvar_list);
- } else if (key == SR_CONF_LIMIT_SAMPLES) {
+ } else if (key == SR_CONF_LIMIT_SAMPLES
+ && config_key_has_cap(driver, sdi, cg, key, SR_CONF_LIST)) {
/* If implemented in config_list(), this denotes the
* maximum number of samples a device can send. This
* really applies only to logic analyzers, and then
* have it turned off by default. The values returned
* are the low/high limits. */
if (sr_config_list(driver, sdi, channel_group, key,
- &gvar) != SR_OK) {
- continue;
+ &gvar) == SR_OK) {
+ g_variant_get(gvar, "(tt)", &low, &high);
+ g_variant_unref(gvar);
+ printf(" Maximum number of samples: %"PRIu64"\n", high);
}
- g_variant_get(gvar, "(tt)", &low, &high);
- g_variant_unref(gvar);
- printf(" Maximum number of samples: %"PRIu64"\n", high);
} else if (key == SR_CONF_SAMPLERATE) {
/* Supported samplerates */
printf(" %s", srci->id);
- if (sr_config_list(driver, sdi, channel_group, SR_CONF_SAMPLERATE,
+ if (maybe_config_list(driver, sdi, channel_group, SR_CONF_SAMPLERATE,
&gvar_dict) != SR_OK) {
printf("\n");
continue;
g_variant_unref(gvar_dict);
} else if (srci->datatype == SR_T_UINT64) {
- printf(" %s", srci->id);
+ printf(" %s: ", srci->id);
gvar = NULL;
- if (sr_config_get(driver, sdi, channel_group, key,
+ if (maybe_config_get(driver, sdi, channel_group, key,
&gvar) == SR_OK) {
tmp_uint64 = g_variant_get_uint64(gvar);
g_variant_unref(gvar);
} else
tmp_uint64 = 0;
- if (sr_config_list(driver, sdi, channel_group,
- SR_CONF_BUFFERSIZE, &gvar_list) != SR_OK) {
+ if (maybe_config_list(driver, sdi, channel_group,
+ key, &gvar_list) != SR_OK) {
if (gvar) {
/* Can't list it, but we have a value to show. */
printf("%"PRIu64" (current)", tmp_uint64);
} else if (srci->datatype == SR_T_STRING) {
printf(" %s: ", srci->id);
- if (sr_config_get(driver, sdi, channel_group, key,
+ if (maybe_config_get(driver, sdi, channel_group, key,
&gvar) == SR_OK) {
tmp_str = g_strdup(g_variant_get_string(gvar, NULL));
g_variant_unref(gvar);
} else
tmp_str = NULL;
- if (sr_config_list(driver, sdi, channel_group, key,
+ if (maybe_config_list(driver, sdi, channel_group, key,
&gvar) != SR_OK) {
if (tmp_str) {
/* Can't list it, but we have a value to show. */
} else if (srci->datatype == SR_T_UINT64_RANGE) {
printf(" %s: ", srci->id);
- if (sr_config_list(driver, sdi, channel_group, key,
+ if (maybe_config_list(driver, sdi, channel_group, key,
&gvar_list) != SR_OK) {
printf("\n");
continue;
}
- if (sr_config_get(driver, sdi, channel_group, key, &gvar) == SR_OK) {
+ if (maybe_config_get(driver, sdi, channel_group, key, &gvar) == SR_OK) {
g_variant_get(gvar, "(tt)", &cur_low, &cur_high);
g_variant_unref(gvar);
} else {
} else if (srci->datatype == SR_T_BOOL) {
printf(" %s: ", srci->id);
- if (sr_config_get(driver, sdi, channel_group, key,
+ if (maybe_config_get(driver, sdi, channel_group, key,
&gvar) == SR_OK) {
if (g_variant_get_boolean(gvar))
printf("on (current), off\n");
} else if (srci->datatype == SR_T_DOUBLE_RANGE) {
printf(" %s: ", srci->id);
- if (sr_config_list(driver, sdi, channel_group, key,
+ if (maybe_config_list(driver, sdi, channel_group, key,
&gvar_list) != SR_OK) {
printf("\n");
continue;
}
- if (sr_config_get(driver, sdi, channel_group, key, &gvar) == SR_OK) {
+ if (maybe_config_get(driver, sdi, channel_group, key, &gvar) == SR_OK) {
g_variant_get(gvar, "(dd)", &dcur_low, &dcur_high);
g_variant_unref(gvar);
} else {
} else if (srci->datatype == SR_T_FLOAT) {
printf(" %s: ", srci->id);
- if (sr_config_get(driver, sdi, channel_group, key,
+ if (maybe_config_get(driver, sdi, channel_group, key,
&gvar) == SR_OK) {
printf("%f\n", g_variant_get_double(gvar));
g_variant_unref(gvar);
} else if (srci->datatype == SR_T_RATIONAL_PERIOD
|| srci->datatype == SR_T_RATIONAL_VOLT) {
printf(" %s", srci->id);
- if (sr_config_get(driver, sdi, channel_group, key,
+ if (maybe_config_get(driver, sdi, channel_group, key,
&gvar) == SR_OK) {
g_variant_get(gvar, "(tt)", &cur_p, &cur_q);
g_variant_unref(gvar);
} else
cur_p = cur_q = 0;
- if (sr_config_list(driver, sdi, channel_group,
+ if (maybe_config_list(driver, sdi, channel_group,
key, &gvar_list) != SR_OK) {
printf("\n");
continue;