]> sigrok.org Git - libsigrok.git/commitdiff
sr: change sr_dev_probe_name_set() to use sdi
authorBert Vermeulen <redacted>
Sun, 22 Jul 2012 18:05:36 +0000 (20:05 +0200)
committerBert Vermeulen <redacted>
Fri, 3 Aug 2012 09:28:59 +0000 (11:28 +0200)
device.c
proto.h
session_file.c

index 566a665d066b96be86ff83c46284eeb68f6b4d72..cfa5492f179a7ec5e3f2a14fc2ec997917b47849 100644 (file)
--- a/device.c
+++ b/device.c
  * If the probe already has a different name assigned to it, it will be
  * 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.
- *                 Note that the probe numbers start at 1 (not 0!).
- * @param name The new name that the specified probe should get.
+ *                 Note that the probe numbers start at 0.
+ * @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
- *         upon other errors.
- *         If something other than SR_OK is returned, 'dev' is unchanged.
+ * @return SR_OK on success, or SR_ERR_ARG on invalid arguments.
  */
-SR_API int sr_dev_probe_name_set(struct sr_dev *dev, int probenum,
-                                const char *name)
+SR_API int sr_dev_probe_name_set(const struct sr_dev_inst *sdi,
+               int probenum, const char *name)
 {
-       struct sr_probe *p;
+       GSList *l;
+       struct sr_probe *probe;
+       int ret;
 
-       if (!dev) {
-               sr_err("dev: %s: dev was NULL", __func__);
+       if (!sdi) {
+               sr_err("%s: sdi was NULL", __func__);
                return SR_ERR_ARG;
        }
 
-       p = sr_dev_probe_find(dev, probenum);
-       if (!p) {
-               sr_err("dev: %s: probe %d not found", __func__, probenum);
-               return SR_ERR; /* TODO: More specific error? */
+       ret = SR_ERR_ARG;
+       for (l = sdi->probes; l; l = l->next) {
+               probe = l->data;
+               if (probe->index == probenum) {
+                       g_free(probe->name);
+                       probe->name = g_strdup(name);
+                       ret = SR_OK;
+                       break;
+               }
        }
 
-       /* TODO: Sanity check on 'name'. */
-
-       /* If the probe already has a name, kill it first. */
-       g_free(p->name);
-
-       p->name = g_strdup(name);
-
-       return SR_OK;
+       return ret;
 }
 
 /**
diff --git a/proto.h b/proto.h
index f8651a124858733c44bab8661c7a343bc2bb9583..5b30cf052a7bec9bda8c8df0b0fc3e9c2558a1a7 100644 (file)
--- a/proto.h
+++ b/proto.h
@@ -47,8 +47,8 @@ SR_API int sr_datastore_put(struct sr_datastore *ds, void *data,
 
 /*--- device.c --------------------------------------------------------------*/
 
-SR_API int sr_dev_probe_name_set(struct sr_dev *dev, int probenum,
-                                const char *name);
+SR_API int sr_dev_probe_name_set(const struct sr_dev_inst *sdi,
+               int probenum, const char *name);
 SR_API int sr_dev_probe_enable(const struct sr_dev_inst *sdi, int probenum,
                gboolean state);
 SR_API int sr_dev_trigger_set(const struct sr_dev_inst *sdi, int probenum,
index d90595eb4d31fe9aa5e899e906ad893a6bebd5c3..0d455971fa4f1306310b6ceffe23e6f646eec397 100644 (file)
@@ -144,7 +144,7 @@ SR_API int sr_session_load(const char *filename)
                                                continue;
                                        enabled_probes++;
                                        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)) {
                                        probenum = strtoul(keys[j]+7, NULL, 10);
                                        sr_dev_trigger_set(sdi, probenum, val);