]> sigrok.org Git - libsigrok.git/commitdiff
probe names: Fix cosmetics, add docs, fix off-by-one.
authorUwe Hermann <redacted>
Thu, 29 Dec 2011 18:50:14 +0000 (19:50 +0100)
committerUwe Hermann <redacted>
Thu, 29 Dec 2011 18:50:14 +0000 (19:50 +0100)
device.c
hardware/alsa/alsa.c
hardware/asix-sigma/asix-sigma.c
hardware/chronovu-la8/chronovu-la8.c
hardware/openbench-logic-sniffer/ols.c
hardware/saleae-logic/saleae-logic.c
hardware/zeroplus-logic-cube/zeroplus.c
hwplugin.c
input/input_binary.c
input/input_chronovu_la8.c
session_file.c

index ac170ac33c3b3a0bd8cfa2821294843439548986..72cba33873fba72fe74a112df3d05ec4aebfad99 100644 (file)
--- a/device.c
+++ b/device.c
@@ -102,7 +102,12 @@ GSList *sr_device_list(void)
 /**
  * Create a new device.
  *
- * TODO: num_probes should be uint16_t.
+ * The device is added to the (libsigrok-internal) list of devices, but
+ * additionally a pointer to the newly created device is also returned.
+ *
+ * The device has no probes attached to it yet after this call. You can
+ * use sr_device_probe_add() to add one or more probes.
+ *
  * TODO: Should return int, so that we can return SR_OK, SR_ERR_* etc.
  *
  * It is the caller's responsibility to g_free() the allocated memory when
@@ -111,8 +116,6 @@ GSList *sr_device_list(void)
  * @param plugin TODO.
  *               If 'plugin' is NULL, the created device is a "virtual" one.
  * @param plugin_index TODO
- * @param num_probes The number of probes (>= 1) this device has.
- *                   TODO: 0 allowed?
  *
  * @return Pointer to the newly allocated device, or NULL upon errors.
  */
@@ -123,8 +126,6 @@ struct sr_device *sr_device_new(const struct sr_device_plugin *plugin,
 
        /* TODO: Check if plugin_index valid? */
 
-       /* TODO: Check if num_probes valid? */
-
        if (!(device = g_try_malloc0(sizeof(struct sr_device)))) {
                sr_err("dev: %s: device malloc failed", __func__);
                return NULL;
@@ -266,9 +267,7 @@ int sr_device_probe_add(struct sr_device *device, const char *name)
 
        p->index = probenum;
        p->enabled = TRUE;
-       if (name) {
-               p->name = g_strdup(name);
-       }
+       p->name = g_strdup(name);
        p->trigger = NULL;
        device->probes = g_slist_append(device->probes, p);
 
index db41072c9739b94a388b0a815ae1a4b6d345f885..527a7e5de49fa992521e61360e403475379f2b78 100644 (file)
@@ -36,7 +36,7 @@ static int capabilities[] = {
        SR_HWCAP_CONTINUOUS,
 };
 
-static const charprobe_names[NUM_PROBES + 1] = {
+static const char *probe_names[NUM_PROBES + 1] = {
        "0",
        "1",
        NULL,
index 557557e9aae61d2fead33d1f87da1fae0ecf106b..723b2445f454a77cd7b1d4772d60b54a985996f8 100644 (file)
@@ -58,7 +58,7 @@ static uint64_t supported_samplerates[] = {
        0,
 };
 
-static const charprobe_names[NUM_PROBES + 1] = {
+static const char *probe_names[NUM_PROBES + 1] = {
        "0",
        "1",
        "2",
index d2a88922c28fcf7f8e6381d82b9b5dd33f108797..18357827dadd1b919e6fac69ff0b621fc30fc405 100644 (file)
@@ -41,7 +41,7 @@
 
 static GSList *device_instances = NULL;
 
-static const charprobe_names[NUM_PROBES + 1] = {
+static const char *probe_names[NUM_PROBES + 1] = {
        "0",
        "1",
        "2",
index acc9a922248a3c6e0259a8b0592e9fd3facba65b..724aa43b613dcb89d7180ebea9cc026bcbb1d3ac 100644 (file)
@@ -55,7 +55,7 @@ static int capabilities[] = {
        0,
 };
 
-static const charprobe_names[NUM_PROBES + 1] = {
+static const char *probe_names[NUM_PROBES + 1] = {
        "0",
        "1",
        "2",
index c346b3d16b63d43be10931f78cb01c5adf2cc3d5..70721ea5213755d7caf8e44836e3e2b8cc6225f8 100644 (file)
@@ -46,7 +46,7 @@ static int capabilities[] = {
        0,
 };
 
-static const charprobe_names[] = {
+static const char *probe_names[] = {
        "0",
        "1",
        "2",
index 2a5952b45d45094dc6c948031b04efca3b9a4d1f..066d4c7697e47cec83a50c8de793740b5aa1e788 100644 (file)
@@ -73,7 +73,7 @@ static int capabilities[] = {
        0,
 };
 
-static const charprobe_names[] = {
+static const char *probe_names[] = {
        "0",
        "1",
        "2",
index fcaaba9351a8bf1cb0128a98c4819bd055b478f3..6b5cd7af6027e16eeb4e0a7da3c6fa8ea162f819 100644 (file)
@@ -118,17 +118,18 @@ int sr_init_hwplugins(struct sr_device_plugin *plugin)
        for (i = 0; i < num_devices; i++) {
                num_probes = GPOINTER_TO_INT(
                                plugin->get_device_info(i, SR_DI_NUM_PROBES));
-               probe_names = (char**)plugin->get_device_info(i, SR_DI_PROBE_NAMES);
+               probe_names = (char **)plugin->get_device_info(i,
+                                                       SR_DI_PROBE_NAMES);
 
                if (!probe_names) {
-                       sr_warn("Plugin %s does not return a list of probe names.", plugin->name);
+                       sr_warn("hwplugin: %s: plugin %s does not return a "
+                               "list of probe names", __func__, plugin->name);
                        continue;
                }
 
                device = sr_device_new(plugin, i);
-               for (j = 0; j < num_probes; j++) {
+               for (j = 0; j < num_probes; j++)
                        sr_device_probe_add(device, probe_names[j]);
-               }
                num_initialized_devices++;
        }
 
index fd23bfc1b3898cd71d4dc5be2db35afa47b4de2f..b83ea6f5ea58ed46aad482c19031f2b47fe94416 100644 (file)
@@ -40,22 +40,23 @@ static int format_match(const char *filename)
 static int init(struct sr_input *in)
 {
        int num_probes, i;
-       char name[SR_MAX_PROBENAME_LEN];
+       char name[SR_MAX_PROBENAME_LEN + 1];
 
        if (in->param && in->param[0]) {
                num_probes = strtoul(in->param, NULL, 10);
                if (num_probes < 1)
                        return SR_ERR;
-       } else
+       } else {
                num_probes = DEFAULT_NUM_PROBES;
+       }
 
-       /* create a virtual device */
+       /* Create a virtual device. */
        in->vdevice = sr_device_new(NULL, 0);
 
-       for (i = 0; i < num_probes; i++)
-       {
+       for (i = 0; i < num_probes; i++) {
                snprintf(name, SR_MAX_PROBENAME_LEN, "%d", i);
-               sr_device_probe_add(in->vdevice, name); /* TODO: Check return value. */
+               /* TODO: Check return value. */
+               sr_device_probe_add(in->vdevice, name);
        }
 
        return SR_OK;
index 241b7a0cf6e7b2e6cd14581c8771e1efdcf91c87..adab9226c93627d6c61c6f5071db78b53a848132 100644 (file)
@@ -78,7 +78,7 @@ static int format_match(const char *filename)
 static int init(struct sr_input *in)
 {
        int num_probes, i;
-       char name[SR_MAX_PROBENAME_LEN];
+       char name[SR_MAX_PROBENAME_LEN + 1];
 
        if (in->param && in->param[0]) {
                num_probes = strtoul(in->param, NULL, 10);
@@ -95,7 +95,8 @@ static int init(struct sr_input *in)
 
        for (i = 0; i < num_probes; i++) {
                snprintf(name, SR_MAX_PROBENAME_LEN, "%d", i);
-               sr_device_probe_add(in->vdevice, name); /* TODO: Check return value. */
+               /* TODO: Check return value. */
+               sr_device_probe_add(in->vdevice, name);
        }
 
        return SR_OK;
index d6d3d8228901c93f6709c5a571c7fb65ffa05126..b739f9089de5737a795eff5e690c406e082dbf87 100644 (file)
@@ -43,7 +43,7 @@ int sr_session_load(const char *filename)
        int ret, err, probenum, devcnt, i, j;
        uint64_t tmp_u64, total_probes, enabled_probes, p;
        char **sections, **keys, *metafile, *val, c;
-       char probename[SR_MAX_PROBENAME_LEN];
+       char probename[SR_MAX_PROBENAME_LEN + 1];
 
        if (!(archive = zip_open(filename, 0, &err))) {
                sr_dbg("Failed to open session file: zip error %d", err);