From: Uwe Hermann Date: Thu, 29 Dec 2011 18:50:14 +0000 (+0100) Subject: probe names: Fix cosmetics, add docs, fix off-by-one. X-Git-Tag: libsigrok-0.1.0~205 X-Git-Url: https://sigrok.org/gitaction?a=commitdiff_plain;h=c37d2b1ba12b62d63590509879bf58adf842896d;p=libsigrok.git probe names: Fix cosmetics, add docs, fix off-by-one. --- diff --git a/device.c b/device.c index ac170ac3..72cba338 100644 --- 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); diff --git a/hardware/alsa/alsa.c b/hardware/alsa/alsa.c index db41072c..527a7e5d 100644 --- a/hardware/alsa/alsa.c +++ b/hardware/alsa/alsa.c @@ -36,7 +36,7 @@ static int capabilities[] = { SR_HWCAP_CONTINUOUS, }; -static const char* probe_names[NUM_PROBES + 1] = { +static const char *probe_names[NUM_PROBES + 1] = { "0", "1", NULL, diff --git a/hardware/asix-sigma/asix-sigma.c b/hardware/asix-sigma/asix-sigma.c index 557557e9..723b2445 100644 --- a/hardware/asix-sigma/asix-sigma.c +++ b/hardware/asix-sigma/asix-sigma.c @@ -58,7 +58,7 @@ static uint64_t supported_samplerates[] = { 0, }; -static const char* probe_names[NUM_PROBES + 1] = { +static const char *probe_names[NUM_PROBES + 1] = { "0", "1", "2", diff --git a/hardware/chronovu-la8/chronovu-la8.c b/hardware/chronovu-la8/chronovu-la8.c index d2a88922..18357827 100644 --- a/hardware/chronovu-la8/chronovu-la8.c +++ b/hardware/chronovu-la8/chronovu-la8.c @@ -41,7 +41,7 @@ static GSList *device_instances = NULL; -static const char* probe_names[NUM_PROBES + 1] = { +static const char *probe_names[NUM_PROBES + 1] = { "0", "1", "2", diff --git a/hardware/openbench-logic-sniffer/ols.c b/hardware/openbench-logic-sniffer/ols.c index acc9a922..724aa43b 100644 --- a/hardware/openbench-logic-sniffer/ols.c +++ b/hardware/openbench-logic-sniffer/ols.c @@ -55,7 +55,7 @@ static int capabilities[] = { 0, }; -static const char* probe_names[NUM_PROBES + 1] = { +static const char *probe_names[NUM_PROBES + 1] = { "0", "1", "2", diff --git a/hardware/saleae-logic/saleae-logic.c b/hardware/saleae-logic/saleae-logic.c index c346b3d1..70721ea5 100644 --- a/hardware/saleae-logic/saleae-logic.c +++ b/hardware/saleae-logic/saleae-logic.c @@ -46,7 +46,7 @@ static int capabilities[] = { 0, }; -static const char* probe_names[] = { +static const char *probe_names[] = { "0", "1", "2", diff --git a/hardware/zeroplus-logic-cube/zeroplus.c b/hardware/zeroplus-logic-cube/zeroplus.c index 2a5952b4..066d4c76 100644 --- a/hardware/zeroplus-logic-cube/zeroplus.c +++ b/hardware/zeroplus-logic-cube/zeroplus.c @@ -73,7 +73,7 @@ static int capabilities[] = { 0, }; -static const char* probe_names[] = { +static const char *probe_names[] = { "0", "1", "2", diff --git a/hwplugin.c b/hwplugin.c index fcaaba93..6b5cd7af 100644 --- a/hwplugin.c +++ b/hwplugin.c @@ -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++; } diff --git a/input/input_binary.c b/input/input_binary.c index fd23bfc1..b83ea6f5 100644 --- a/input/input_binary.c +++ b/input/input_binary.c @@ -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; diff --git a/input/input_chronovu_la8.c b/input/input_chronovu_la8.c index 241b7a0c..adab9226 100644 --- a/input/input_chronovu_la8.c +++ b/input/input_chronovu_la8.c @@ -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; diff --git a/session_file.c b/session_file.c index d6d3d822..b739f908 100644 --- a/session_file.c +++ b/session_file.c @@ -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);