Skip to content

Commit

Permalink
Update for configuration API changes.
Browse files Browse the repository at this point in the history
  • Loading branch information
martinling committed Nov 3, 2015
1 parent 1ef118a commit c7639c1
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 73 deletions.
37 changes: 5 additions & 32 deletions main.c
Original file line number Diff line number Diff line change
Expand Up @@ -74,40 +74,11 @@ int select_channels(struct sr_dev_inst *sdi)
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;
gboolean result;

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));
result = FALSE;
for (i = 0; i < num_opts; i++) {
if ((opts[i] & SR_CONF_MASK) == key) {
if ((opts[i] & capability) == capability)
result = TRUE;
else
result = FALSE;
break;
}
}
g_variant_unref(gvar_opts);

return result;
}

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))
if (sr_dev_config_capabilities(sdi, cg, key) & SR_CONF_GET)
return sr_config_get(driver, sdi, cg, key, gvar);

return SR_ERR_NA;
Expand All @@ -117,7 +88,9 @@ 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))
(void)driver;

if (sr_dev_config_capabilities(sdi, cg, key) & SR_CONF_SET)
return sr_config_set(sdi, cg, key, gvar);

return SR_ERR_NA;
Expand All @@ -127,7 +100,7 @@ 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))
if (sr_dev_config_capabilities(sdi, cg, key) & SR_CONF_LIST)
return sr_config_list(driver, sdi, cg, key, gvar);

return SR_ERR_NA;
Expand Down
21 changes: 10 additions & 11 deletions session.c
Original file line number Diff line number Diff line change
Expand Up @@ -45,14 +45,15 @@ static int set_limit_time(const struct sr_dev_inst *sdi)
return SR_ERR;
}

if (config_key_has_cap(driver, sdi, NULL, SR_CONF_LIMIT_MSEC, SR_CONF_SET)) {
if (sr_dev_config_capabilities(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 (config_key_has_cap(driver, sdi, NULL, SR_CONF_SAMPLERATE,
SR_CONF_GET | SR_CONF_SET)) {
} else if (sr_dev_config_capabilities(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);
Expand Down Expand Up @@ -526,8 +527,8 @@ void run_session(void)
struct sr_trigger *trigger;
struct sr_dev_inst *sdi;
uint64_t min_samples, max_samples;
gsize n_elements, i;
const uint32_t *dev_opts;
GArray *dev_opts;
guint i;
int is_demo_dev;
struct sr_dev_driver *driver;
const struct sr_transform *t;
Expand All @@ -545,20 +546,18 @@ void run_session(void)

driver = sr_dev_inst_driver_get(sdi);

if (sr_config_list(driver, sdi, NULL, SR_CONF_DEVICE_OPTIONS, &gvar) != SR_OK) {
if (!(dev_opts = sr_dev_options(driver, sdi, NULL))) {
g_critical("Failed to query list device options.");
return;
}

dev_opts = g_variant_get_fixed_array(gvar, &n_elements, sizeof(uint32_t));

is_demo_dev = 0;
for (i = 0; i < n_elements; i++) {
if (dev_opts[i] == SR_CONF_DEMO_DEV)
for (i = 0; i < dev_opts->len; i++) {
if (g_array_index(dev_opts, uint32_t, i) == SR_CONF_DEMO_DEV)
is_demo_dev = 1;
}

g_variant_unref(gvar);
g_array_free(dev_opts, TRUE);

if (!is_demo_dev)
real_devices = g_slist_append(real_devices, sdi);
Expand Down
54 changes: 24 additions & 30 deletions show.c
Original file line number Diff line number Diff line change
Expand Up @@ -225,38 +225,33 @@ void show_dev_list(void)
void show_drv_detail(struct sr_dev_driver *driver)
{
const struct sr_key_info *srci;
GVariant *gvar_opts;
const uint32_t *opts;
gsize num_elements, i;

if (sr_config_list(driver, NULL, NULL, SR_CONF_DEVICE_OPTIONS,
&gvar_opts) == SR_OK) {
opts = g_variant_get_fixed_array(gvar_opts, &num_elements,
sizeof(uint32_t));
if (num_elements) {
GArray *opts;
guint i;

if ((opts = sr_dev_options(driver, NULL, NULL))) {
if (opts->len > 0) {
printf("Driver functions:\n");
for (i = 0; i < num_elements; i++) {
if (!(srci = sr_key_info_get(SR_KEY_CONFIG, opts[i] & SR_CONF_MASK)))
for (i = 0; i < opts->len; i++) {
if (!(srci = sr_key_info_get(SR_KEY_CONFIG,
g_array_index(opts, uint32_t, i))))
continue;
printf(" %s\n", srci->name);
}
}
g_variant_unref(gvar_opts);
g_array_free(opts, TRUE);
}

if (sr_config_list(driver, NULL, NULL, SR_CONF_SCAN_OPTIONS,
&gvar_opts) == SR_OK) {
opts = g_variant_get_fixed_array(gvar_opts, &num_elements,
sizeof(uint32_t));
if (num_elements) {
if ((opts = sr_driver_scan_options(driver))) {
if (opts->len > 0) {
printf("Scan options:\n");
for (i = 0; i < num_elements; i++) {
if (!(srci = sr_key_info_get(SR_KEY_CONFIG, opts[i] & SR_CONF_MASK)))
for (i = 0; i < opts->len; i++) {
if (!(srci = sr_key_info_get(SR_KEY_CONFIG,
g_array_index(opts, uint32_t, i))))
continue;
printf(" %s\n", srci->id);
}
}
g_variant_unref(gvar_opts);
g_array_free(opts, TRUE);
}
}

Expand All @@ -268,12 +263,12 @@ void show_dev_detail(void)
struct sr_channel *ch;
struct sr_channel_group *channel_group, *cg;
GSList *devices, *cgl, *chl, *channel_groups;
GVariant *gvar_opts, *gvar_dict, *gvar_list, *gvar;
gsize num_opts, num_elements;
GVariant *gvar_dict, *gvar_list, *gvar;
gsize num_elements;
double dlow, dhigh, dcur_low, dcur_high;
const uint64_t *uint64, p, q, low, high;
uint64_t tmp_uint64, mask, cur_low, cur_high, cur_p, cur_q;
const uint32_t *opts;
GArray *opts;
const int32_t *int32;
uint32_t key, o, cur_mq, mq;
uint64_t cur_mqflags, mqflags;
Expand Down Expand Up @@ -317,8 +312,7 @@ void show_dev_detail(void)
select_channels(sdi);
channel_group = select_channel_group(sdi);

if (sr_config_list(driver, sdi, channel_group, SR_CONF_DEVICE_OPTIONS,
&gvar_opts) != SR_OK)
if (!(opts = sr_dev_options(driver, sdi, channel_group)))
/* Driver supports no device instance options. */
return;

Expand All @@ -344,9 +338,8 @@ void show_dev_detail(void)
printf(" on channel group %s", channel_group->name);
}
printf(":\n");
opts = g_variant_get_fixed_array(gvar_opts, &num_opts, sizeof(uint32_t));
for (o = 0; o < num_opts; o++) {
key = opts[o] & SR_CONF_MASK;
for (o = 0; o < opts->len; o++) {
key = g_array_index(opts, uint32_t, o);
if (!(srci = sr_key_info_get(SR_KEY_CONFIG, key)))
continue;

Expand Down Expand Up @@ -393,7 +386,8 @@ void show_dev_detail(void)
g_variant_unref(gvar_list);

} else if (key == SR_CONF_LIMIT_SAMPLES
&& config_key_has_cap(driver, sdi, NULL, key, SR_CONF_LIST)) {
&& (sr_dev_config_capabilities(sdi, NULL, key)
& SR_CONF_LIST)) {
/*
* If implemented in config_list(), this denotes the
* maximum number of samples a device can send. This
Expand Down Expand Up @@ -673,7 +667,7 @@ void show_dev_detail(void)
printf(" %s\n", srci->id);
}
}
g_variant_unref(gvar_opts);
g_array_free(opts, TRUE);

sr_dev_close(sdi);

Expand Down

0 comments on commit c7639c1

Please sign in to comment.