hwdriver: Introduce sr_config_commit() API call.
(sr_dev_driver.config_probe_set): New optional callback enabling drivers to be notified upon changes to probe settings. (sr_dev_probe_enable, sr_dev_trigger_set): Invoke new driver callback on changes. (sr_dev_driver.config_commit): New optional callback allowing drivers to defer application of configuration settings until an explicit call to config_commit(). (sr_config_commit): New public wrapper function.
This commit is contained in:
parent
2b0e4a468a
commit
2a854d7139
39
device.c
39
device.c
|
@ -116,7 +116,9 @@ SR_API int sr_dev_probe_name_set(const struct sr_dev_inst *sdi,
|
|||
* @param probenum The probe number, starting from 0.
|
||||
* @param state TRUE to enable the probe, FALSE to disable.
|
||||
*
|
||||
* @return SR_OK on success, or SR_ERR_ARG on invalid arguments.
|
||||
* @return SR_OK on success or SR_ERR on failure. In case of invalid
|
||||
* arguments, SR_ERR_ARG is returned and the probe enabled state
|
||||
* remains unchanged.
|
||||
*
|
||||
* @since 0.2.0
|
||||
*/
|
||||
|
@ -126,6 +128,7 @@ SR_API int sr_dev_probe_enable(const struct sr_dev_inst *sdi, int probenum,
|
|||
GSList *l;
|
||||
struct sr_probe *probe;
|
||||
int ret;
|
||||
gboolean was_enabled;
|
||||
|
||||
if (!sdi)
|
||||
return SR_ERR_ARG;
|
||||
|
@ -134,8 +137,17 @@ SR_API int sr_dev_probe_enable(const struct sr_dev_inst *sdi, int probenum,
|
|||
for (l = sdi->probes; l; l = l->next) {
|
||||
probe = l->data;
|
||||
if (probe->index == probenum) {
|
||||
was_enabled = probe->enabled;
|
||||
probe->enabled = state;
|
||||
ret = SR_OK;
|
||||
if (!state != !was_enabled && sdi->driver
|
||||
&& sdi->driver->config_probe_set) {
|
||||
ret = sdi->driver->config_probe_set(
|
||||
sdi, probe, SR_PROBE_SET_ENABLED);
|
||||
/* Roll back change if it wasn't applicable. */
|
||||
if (ret == SR_ERR_ARG)
|
||||
probe->enabled = was_enabled;
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
@ -153,7 +165,9 @@ SR_API int sr_dev_probe_enable(const struct sr_dev_inst *sdi, int probenum,
|
|||
* @param[in] probenum Number of probe, starting at 0.
|
||||
* @param[in] trigger Trigger string, in the format used by sigrok-cli
|
||||
*
|
||||
* @return SR_OK on success, or SR_ERR_ARG on invalid arguments.
|
||||
* @return SR_OK on success or SR_ERR on failure. In case of invalid
|
||||
* arguments, SR_ERR_ARG is returned and the trigger settings
|
||||
* remain unchanged.
|
||||
*
|
||||
* @since 0.2.0
|
||||
*/
|
||||
|
@ -162,6 +176,7 @@ SR_API int sr_dev_trigger_set(const struct sr_dev_inst *sdi, int probenum,
|
|||
{
|
||||
GSList *l;
|
||||
struct sr_probe *probe;
|
||||
char *old_trigger;
|
||||
int ret;
|
||||
|
||||
if (!sdi)
|
||||
|
@ -171,10 +186,24 @@ SR_API int sr_dev_trigger_set(const struct sr_dev_inst *sdi, int probenum,
|
|||
for (l = sdi->probes; l; l = l->next) {
|
||||
probe = l->data;
|
||||
if (probe->index == probenum) {
|
||||
/* If the probe already has a trigger, kill it first. */
|
||||
g_free(probe->trigger);
|
||||
probe->trigger = g_strdup(trigger);
|
||||
old_trigger = probe->trigger;
|
||||
ret = SR_OK;
|
||||
if (g_strcmp0(trigger, old_trigger) == 0)
|
||||
break;
|
||||
/* Set new trigger if it has changed. */
|
||||
probe->trigger = g_strdup(trigger);
|
||||
|
||||
if (sdi->driver && sdi->driver->config_probe_set) {
|
||||
ret = sdi->driver->config_probe_set(
|
||||
sdi, probe, SR_PROBE_SET_TRIGGER);
|
||||
/* Roll back change if it wasn't applicable. */
|
||||
if (ret == SR_ERR_ARG) {
|
||||
g_free(probe->trigger);
|
||||
probe->trigger = old_trigger;
|
||||
break;
|
||||
}
|
||||
}
|
||||
g_free(old_trigger);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
|
21
hwdriver.c
21
hwdriver.c
|
@ -633,6 +633,27 @@ SR_API int sr_config_set(const struct sr_dev_inst *sdi,
|
|||
return ret;
|
||||
}
|
||||
|
||||
/**
|
||||
* Apply configuration settings to the device hardware.
|
||||
*
|
||||
* @param sdi The device instance.
|
||||
*
|
||||
* @return SR_OK upon success or SR_ERR in case of error.
|
||||
*/
|
||||
SR_API int sr_config_commit(const struct sr_dev_inst *sdi)
|
||||
{
|
||||
int ret;
|
||||
|
||||
if (!sdi || !sdi->driver)
|
||||
ret = SR_ERR;
|
||||
else if (!sdi->driver->config_commit)
|
||||
ret = SR_OK;
|
||||
else
|
||||
ret = sdi->driver->config_commit(sdi);
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
/**
|
||||
* List all possible values for a configuration key.
|
||||
*
|
||||
|
|
|
@ -174,6 +174,14 @@ SR_PRIV int sr_err(const char *format, ...);
|
|||
|
||||
/*--- device.c --------------------------------------------------------------*/
|
||||
|
||||
/** Values for the changes argument of sr_dev_driver.config_probe_set. */
|
||||
enum {
|
||||
/** The enabled state of the probe has been changed. */
|
||||
SR_PROBE_SET_ENABLED = 1 << 0,
|
||||
/** The trigger setup of the probe has been changed. */
|
||||
SR_PROBE_SET_TRIGGER = 1 << 1,
|
||||
};
|
||||
|
||||
SR_PRIV struct sr_probe *sr_probe_new(int index, int type,
|
||||
gboolean enabled, const char *name);
|
||||
|
||||
|
|
|
@ -975,6 +975,9 @@ struct sr_dev_driver {
|
|||
int (*config_set) (int id, GVariant *data,
|
||||
const struct sr_dev_inst *sdi,
|
||||
const struct sr_probe_group *probe_group);
|
||||
int (*config_probe_set) (const struct sr_dev_inst *sdi,
|
||||
struct sr_probe *probe, unsigned int changes);
|
||||
int (*config_commit) (const struct sr_dev_inst *sdi);
|
||||
int (*config_list) (int info_id, GVariant **data,
|
||||
const struct sr_dev_inst *sdi,
|
||||
const struct sr_probe_group *probe_group);
|
||||
|
|
1
proto.h
1
proto.h
|
@ -77,6 +77,7 @@ SR_API int sr_config_get(const struct sr_dev_driver *driver,
|
|||
SR_API int sr_config_set(const struct sr_dev_inst *sdi,
|
||||
const struct sr_probe_group *probe_group,
|
||||
int key, GVariant *data);
|
||||
SR_API int sr_config_commit(const struct sr_dev_inst *sdi);
|
||||
SR_API int sr_config_list(const struct sr_dev_driver *driver,
|
||||
const struct sr_dev_inst *sdi,
|
||||
const struct sr_probe_group *probe_group,
|
||||
|
|
Loading…
Reference in New Issue