sr: change sr_dev_probe_name_set() to use sdi
This commit is contained in:
parent
a10ddf9ba0
commit
37e8b4c4f7
45
device.c
45
device.c
|
@ -28,39 +28,38 @@
|
||||||
* If the probe already has a different name assigned to it, it will be
|
* If the probe already has a different name assigned to it, it will be
|
||||||
* removed, and the new name will be saved instead.
|
* removed, and the new name will be saved instead.
|
||||||
*
|
*
|
||||||
* @param dev TODO
|
* @param sdi The device instance the probe is connected to.
|
||||||
* @param probenum The number of the probe whose name to set.
|
* @param probenum The number of the probe whose name to set.
|
||||||
* Note that the probe numbers start at 1 (not 0!).
|
* Note that the probe numbers start at 0.
|
||||||
* @param name The new name that the specified probe should get.
|
* @param name The new name that the specified probe should get. A copy
|
||||||
|
* of the string is made.
|
||||||
*
|
*
|
||||||
* @return SR_OK upon success, SR_ERR_ARG upon invalid arguments, or SR_ERR
|
* @return SR_OK on success, or SR_ERR_ARG on invalid arguments.
|
||||||
* upon other errors.
|
|
||||||
* If something other than SR_OK is returned, 'dev' is unchanged.
|
|
||||||
*/
|
*/
|
||||||
SR_API int sr_dev_probe_name_set(struct sr_dev *dev, int probenum,
|
SR_API int sr_dev_probe_name_set(const struct sr_dev_inst *sdi,
|
||||||
const char *name)
|
int probenum, const char *name)
|
||||||
{
|
{
|
||||||
struct sr_probe *p;
|
GSList *l;
|
||||||
|
struct sr_probe *probe;
|
||||||
|
int ret;
|
||||||
|
|
||||||
if (!dev) {
|
if (!sdi) {
|
||||||
sr_err("dev: %s: dev was NULL", __func__);
|
sr_err("%s: sdi was NULL", __func__);
|
||||||
return SR_ERR_ARG;
|
return SR_ERR_ARG;
|
||||||
}
|
}
|
||||||
|
|
||||||
p = sr_dev_probe_find(dev, probenum);
|
ret = SR_ERR_ARG;
|
||||||
if (!p) {
|
for (l = sdi->probes; l; l = l->next) {
|
||||||
sr_err("dev: %s: probe %d not found", __func__, probenum);
|
probe = l->data;
|
||||||
return SR_ERR; /* TODO: More specific error? */
|
if (probe->index == probenum) {
|
||||||
|
g_free(probe->name);
|
||||||
|
probe->name = g_strdup(name);
|
||||||
|
ret = SR_OK;
|
||||||
|
break;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/* TODO: Sanity check on 'name'. */
|
return ret;
|
||||||
|
|
||||||
/* If the probe already has a name, kill it first. */
|
|
||||||
g_free(p->name);
|
|
||||||
|
|
||||||
p->name = g_strdup(name);
|
|
||||||
|
|
||||||
return SR_OK;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
4
proto.h
4
proto.h
|
@ -47,8 +47,8 @@ SR_API int sr_datastore_put(struct sr_datastore *ds, void *data,
|
||||||
|
|
||||||
/*--- device.c --------------------------------------------------------------*/
|
/*--- device.c --------------------------------------------------------------*/
|
||||||
|
|
||||||
SR_API int sr_dev_probe_name_set(struct sr_dev *dev, int probenum,
|
SR_API int sr_dev_probe_name_set(const struct sr_dev_inst *sdi,
|
||||||
const char *name);
|
int probenum, const char *name);
|
||||||
SR_API int sr_dev_probe_enable(const struct sr_dev_inst *sdi, int probenum,
|
SR_API int sr_dev_probe_enable(const struct sr_dev_inst *sdi, int probenum,
|
||||||
gboolean state);
|
gboolean state);
|
||||||
SR_API int sr_dev_trigger_set(const struct sr_dev_inst *sdi, int probenum,
|
SR_API int sr_dev_trigger_set(const struct sr_dev_inst *sdi, int probenum,
|
||||||
|
|
|
@ -144,7 +144,7 @@ SR_API int sr_session_load(const char *filename)
|
||||||
continue;
|
continue;
|
||||||
enabled_probes++;
|
enabled_probes++;
|
||||||
tmp_u64 = strtoul(keys[j]+5, NULL, 10);
|
tmp_u64 = strtoul(keys[j]+5, NULL, 10);
|
||||||
sr_dev_probe_name_set(dev, tmp_u64, val);
|
sr_dev_probe_name_set(sdi, tmp_u64, val);
|
||||||
} else if (!strncmp(keys[j], "trigger", 7)) {
|
} else if (!strncmp(keys[j], "trigger", 7)) {
|
||||||
probenum = strtoul(keys[j]+7, NULL, 10);
|
probenum = strtoul(keys[j]+7, NULL, 10);
|
||||||
sr_dev_trigger_set(sdi, probenum, val);
|
sr_dev_trigger_set(sdi, probenum, val);
|
||||||
|
|
Loading…
Reference in New Issue