From: Martin Ling Date: Tue, 3 Nov 2015 11:42:30 +0000 (+0000) Subject: Update for configuration API changes. X-Git-Tag: sigrok-cli-0.6.0~2 X-Git-Url: https://sigrok.org/gitaction?a=commitdiff_plain;h=c7639c1d63d85687618087acdbf5279b94c24117;p=sigrok-cli.git Update for configuration API changes. --- diff --git a/main.c b/main.c index 51053bc..4305096 100644 --- a/main.c +++ b/main.c @@ -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; @@ -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; @@ -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; diff --git a/session.c b/session.c index f71f999..edf3d12 100644 --- a/session.c +++ b/session.c @@ -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); @@ -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; @@ -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); diff --git a/show.c b/show.c index e207058..39db85f 100644 --- a/show.c +++ b/show.c @@ -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); } } @@ -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; @@ -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; @@ -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; @@ -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 @@ -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);