From: Martin Ling Date: Mon, 2 Nov 2015 00:23:23 +0000 (+0000) Subject: Add new sr_driver_scan_options() helper function. X-Git-Tag: libsigrok-0.4.0~52 X-Git-Url: https://sigrok.org/gitaction?a=commitdiff_plain;h=8f3168b89bcd79b555d86601270d81e5c8e3bdfe;p=libsigrok.git Add new sr_driver_scan_options() helper function. This function replaces the pattern of calling config_list() with SR_CONF_SCAN_OPTIONS to obtain a list of scan options. --- diff --git a/include/libsigrok/proto.h b/include/libsigrok/proto.h index fc63ae23..9dc12827 100644 --- a/include/libsigrok/proto.h +++ b/include/libsigrok/proto.h @@ -83,6 +83,7 @@ SR_API int sr_dev_inst_channel_add(struct sr_dev_inst *sdi, int index, int type, SR_API struct sr_dev_driver **sr_driver_list(const struct sr_context *ctx); SR_API int sr_driver_init(struct sr_context *ctx, struct sr_dev_driver *driver); +SR_API GArray *sr_driver_scan_options(const struct sr_dev_driver *driver); SR_API GSList *sr_driver_scan(struct sr_dev_driver *driver, GSList *options); SR_API int sr_config_get(const struct sr_dev_driver *driver, const struct sr_dev_inst *sdi, diff --git a/src/hwdriver.c b/src/hwdriver.c index a676d026..5a4b1b01 100644 --- a/src/hwdriver.c +++ b/src/hwdriver.c @@ -392,6 +392,43 @@ SR_API int sr_driver_init(struct sr_context *ctx, struct sr_dev_driver *driver) return ret; } +/** + * Enumerate scan options supported by this driver. + * + * Before calling sr_driver_scan_options(), the user must have previously + * initialized the driver by calling sr_driver_init(). + * + * @param driver The driver to enumerate options for. This must be a pointer + * to one of the entries returned by sr_driver_list(). Must not + * be NULL. + * + * @return A GArray * of uint32_t entries, or NULL on invalid arguments. Each + * entry is a configuration key that is supported as a scan option. + * The array must be freed by the caller using g_array_free(). + * + * @since 0.4.0 + */ +SR_API GArray *sr_driver_scan_options(const struct sr_dev_driver *driver) +{ + GVariant *gvar; + const uint32_t *opts; + gsize num_opts; + GArray *result; + + if (sr_config_list(driver, NULL, NULL, SR_CONF_SCAN_OPTIONS, &gvar) != SR_OK) + return NULL; + + opts = g_variant_get_fixed_array(gvar, &num_opts, sizeof(uint32_t)); + + result = g_array_sized_new(FALSE, FALSE, sizeof(uint32_t), num_opts); + + g_array_insert_vals(result, 0, opts, num_opts); + + g_variant_unref(gvar); + + return result; +} + static int check_options(struct sr_dev_driver *driver, GSList *options, uint32_t optlist_key, struct sr_dev_inst *sdi, struct sr_channel_group *cg)