From: Bert Vermeulen Date: Sat, 26 Jan 2013 00:18:19 +0000 (+0100) Subject: Code cleanup. X-Git-Tag: dsupstream~301 X-Git-Url: http://sigrok.org/gitweb/?a=commitdiff_plain;h=cbadb856d6d833f2822cf63e4884abb409da6172;p=libsigrok.git Code cleanup. --- diff --git a/device.c b/device.c index b51af2ba..3214a078 100644 --- a/device.c +++ b/device.c @@ -329,21 +329,6 @@ SR_PRIV void sr_serial_dev_inst_free(struct sr_serial_dev_inst *serial) } -SR_API int sr_config_set(const struct sr_dev_inst *sdi, int hwcap, - const void *value) -{ - int ret; - - if (!sdi || !sdi->driver || !sdi->driver->config_set) { - sr_err("Unable to set config option."); - return SR_ERR; - } - - ret = sdi->driver->config_set(hwcap, value, sdi); - - return ret; -} - SR_API GSList *sr_dev_inst_list(const struct sr_dev_driver *driver) { diff --git a/hwdriver.c b/hwdriver.c index 189b0331..9535b053 100644 --- a/hwdriver.c +++ b/hwdriver.c @@ -307,48 +307,96 @@ SR_PRIV struct sr_config *sr_config_make(int key, const void *value) * Returns information about the given driver or device instance. * * @param driver The sr_dev_driver struct to query. - * @param id The type of information, in the form of an SR_CONF_* option. - * @param data Pointer where the value. will be stored. Must not be NULL. - * @param sdi Pointer to the struct sr_dev_inst to be checked. Must not be NULL. + * @param key The configuration key (SR_CONF_*). + * @param data Pointer where the value will be stored. Must not be NULL. + * @param sdi If the key is specific to a device, this must contain a + * pointer to the struct sr_dev_inst to be checked. * * @return SR_OK upon success or SR_ERR in case of error. Note SR_ERR_ARG - * may be returned by the driver indicating it doesn't know that id, + * may be returned by the driver indicating it doesn't know that key, * but this is not to be flagged as an error by the caller; merely * as an indication that it's not applicable. */ -SR_API int sr_config_get(struct sr_dev_driver *driver, int id, +SR_API int sr_config_get(struct sr_dev_driver *driver, int key, const void **data, const struct sr_dev_inst *sdi) { int ret; - if (driver == NULL || data == NULL) + if (!driver || !data) return SR_ERR; - ret = driver->config_get(id, data, sdi); + if (!driver->config_get) + return SR_ERR_ARG; + + ret = driver->config_get(key, data, sdi); return ret; } -SR_API int sr_config_list(struct sr_dev_driver *driver, int id, +/** + * Set a configuration key in a device instance. + * + * @param sdi The device instance. + * @param key The configuration key (SR_CONF_*). + * @param value The new value for the key, as a pointer to whatever type + * is appropriate for that key. + * + * @return SR_OK upon success or SR_ERR in case of error. Note SR_ERR_ARG + * may be returned by the driver indicating it doesn't know that key, + * but this is not to be flagged as an error by the caller; merely + * as an indication that it's not applicable. + */ +SR_API int sr_config_set(const struct sr_dev_inst *sdi, int key, + const void *value) +{ + int ret; + + if (!sdi || !sdi->driver) + return SR_ERR; + + if (!sdi->driver->config_set) + return SR_ERR_ARG; + + ret = sdi->driver->config_set(key, value, sdi); + + return ret; +} + +/** + * List all possible values for a configuration key. + * + * @param driver The sr_dev_driver struct to query. + * @param key The configuration key (SR_CONF_*). + * @param data A pointer to a list of values, in whatever format is + * appropriate for that key. + * @param sdi If the key is specific to a device, this must contain a + * pointer to the struct sr_dev_inst to be checked. + * + * @return SR_OK upon success or SR_ERR in case of error. Note SR_ERR_ARG + * may be returned by the driver indicating it doesn't know that key, + * but this is not to be flagged as an error by the caller; merely + * as an indication that it's not applicable. + */ +SR_API int sr_config_list(struct sr_dev_driver *driver, int key, const void **data, const struct sr_dev_inst *sdi) { int ret; - if (driver == NULL || data == NULL) + if (!driver || !data) return SR_ERR; if (!driver->config_list) - return SR_ERR; + return SR_ERR_ARG; - ret = driver->config_list(id, data, sdi); + ret = driver->config_list(key, data, sdi); return ret; } /** - * Get information about an sr_config key. + * Get information about a configuration key. * - * @param opt The sr_config key. + * @param opt The configuration key. * * @return A pointer to a struct sr_config_info, or NULL if the key * was not found. @@ -366,9 +414,9 @@ SR_API const struct sr_config_info *sr_config_info_get(int key) } /** - * Get information about an sr_config key, by name. + * Get information about an configuration key, by name. * - * @param optname The sr_config key. + * @param optname The configuration key. * * @return A pointer to a struct sr_config_info, or NULL if the key * was not found. diff --git a/proto.h b/proto.h index b906197d..bed62698 100644 --- a/proto.h +++ b/proto.h @@ -52,8 +52,6 @@ SR_API int sr_dev_probe_enable(const struct sr_dev_inst *sdi, int probenum, SR_API int sr_dev_trigger_set(const struct sr_dev_inst *sdi, int probenum, const char *trigger); SR_API gboolean sr_dev_has_option(const struct sr_dev_inst *sdi, int key); -SR_API int sr_config_set(const struct sr_dev_inst *sdi, int hwcap, - const void *value); SR_API GSList *sr_dev_inst_list(const struct sr_dev_driver *driver); SR_API int sr_dev_inst_clear(const struct sr_dev_driver *driver); @@ -70,9 +68,11 @@ SR_API struct sr_dev_driver **sr_driver_list(void); SR_API int sr_driver_init(struct sr_context *ctx, struct sr_dev_driver *driver); SR_API GSList *sr_driver_scan(struct sr_dev_driver *driver, GSList *options); -SR_API int sr_config_get(struct sr_dev_driver *driver, int id, +SR_API int sr_config_get(struct sr_dev_driver *driver, int key, const void **data, const struct sr_dev_inst *sdi); -SR_API int sr_config_list(struct sr_dev_driver *driver, int id, +SR_API int sr_config_set(const struct sr_dev_inst *sdi, int key, + const void *value); +SR_API int sr_config_list(struct sr_dev_driver *driver, int key, const void **data, const struct sr_dev_inst *sdi); SR_API const struct sr_config_info *sr_config_info_get(int key); SR_API const struct sr_config_info *sr_config_info_name_get(const char *optname);