]> sigrok.org Git - libsigrok.git/blobdiff - hwdriver.c
Made sr_config_get driver argument a const pointer
[libsigrok.git] / hwdriver.c
index 439d4c78e9ac6ecdf2a4ef1ead932f288febf798..bf473da6c63fcea781a8b638a557660e74c3f65f 100644 (file)
@@ -307,79 +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_info_get(struct sr_dev_driver *driver, int id,
+SR_API int sr_config_get(const 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,
-               const void **data, const struct sr_dev_inst *sdi)
+/**
+ * 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 (driver == NULL || data == NULL)
+       if (!sdi || !sdi->driver)
                return SR_ERR;
 
-       if (!driver->config_list)
-               return SR_ERR;
+       if (!sdi->driver->config_set)
+               return SR_ERR_ARG;
 
-       ret = driver->config_list(id, data, sdi);
+       ret = sdi->driver->config_set(key, value, sdi);
 
        return ret;
 }
 
 /**
- * Find out if a hardware driver has a specific capability.
+ * List all possible values for a configuration key.
  *
- * @param driver The hardware driver in which to search for the capability.
- * @param hwcap The capability to find in the list.
+ * @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 TRUE if the specified capability exists in the specified driver,
- *         FALSE otherwise. Also, if 'driver' is NULL or the respective driver
- *         returns an invalid capability list, FALSE is returned.
+ * @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 gboolean sr_driver_hwcap_exists(struct sr_dev_driver *driver, int hwcap)
+SR_API int sr_config_list(struct sr_dev_driver *driver, int key,
+               const void **data, const struct sr_dev_inst *sdi)
 {
-       const int *hwcaps;
-       int i;
+       int ret;
 
-       if (!driver) {
-               sr_err("hwdriver: %s: driver was NULL", __func__);
-               return FALSE;
-       }
+       if (!driver || !data)
+               return SR_ERR;
 
-       if (driver->config_get(SR_DI_HWCAPS, (const void **)&hwcaps, NULL) != SR_OK)
-               return FALSE;
+       if (!driver->config_list)
+               return SR_ERR_ARG;
 
-       for (i = 0; hwcaps[i]; i++) {
-               if (hwcaps[i] == hwcap)
-                       return TRUE;
-       }
+       ret = driver->config_list(key, data, sdi);
 
-       return FALSE;
+       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.
@@ -397,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.