probe names: Fix cosmetics, add docs, fix off-by-one.

This commit is contained in:
Uwe Hermann 2011-12-29 19:50:14 +01:00
parent 464d12c72a
commit c37d2b1ba1
11 changed files with 29 additions and 27 deletions

View File

@ -102,7 +102,12 @@ GSList *sr_device_list(void)
/** /**
* Create a new device. * 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. * 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 * 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. * @param plugin TODO.
* If 'plugin' is NULL, the created device is a "virtual" one. * If 'plugin' is NULL, the created device is a "virtual" one.
* @param plugin_index TODO * @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. * @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 plugin_index valid? */
/* TODO: Check if num_probes valid? */
if (!(device = g_try_malloc0(sizeof(struct sr_device)))) { if (!(device = g_try_malloc0(sizeof(struct sr_device)))) {
sr_err("dev: %s: device malloc failed", __func__); sr_err("dev: %s: device malloc failed", __func__);
return NULL; return NULL;
@ -266,9 +267,7 @@ int sr_device_probe_add(struct sr_device *device, const char *name)
p->index = probenum; p->index = probenum;
p->enabled = TRUE; p->enabled = TRUE;
if (name) {
p->name = g_strdup(name); p->name = g_strdup(name);
}
p->trigger = NULL; p->trigger = NULL;
device->probes = g_slist_append(device->probes, p); device->probes = g_slist_append(device->probes, p);

View File

@ -36,7 +36,7 @@ static int capabilities[] = {
SR_HWCAP_CONTINUOUS, SR_HWCAP_CONTINUOUS,
}; };
static const char* probe_names[NUM_PROBES + 1] = { static const char *probe_names[NUM_PROBES + 1] = {
"0", "0",
"1", "1",
NULL, NULL,

View File

@ -58,7 +58,7 @@ static uint64_t supported_samplerates[] = {
0, 0,
}; };
static const char* probe_names[NUM_PROBES + 1] = { static const char *probe_names[NUM_PROBES + 1] = {
"0", "0",
"1", "1",
"2", "2",

View File

@ -41,7 +41,7 @@
static GSList *device_instances = NULL; static GSList *device_instances = NULL;
static const char* probe_names[NUM_PROBES + 1] = { static const char *probe_names[NUM_PROBES + 1] = {
"0", "0",
"1", "1",
"2", "2",

View File

@ -55,7 +55,7 @@ static int capabilities[] = {
0, 0,
}; };
static const char* probe_names[NUM_PROBES + 1] = { static const char *probe_names[NUM_PROBES + 1] = {
"0", "0",
"1", "1",
"2", "2",

View File

@ -46,7 +46,7 @@ static int capabilities[] = {
0, 0,
}; };
static const char* probe_names[] = { static const char *probe_names[] = {
"0", "0",
"1", "1",
"2", "2",

View File

@ -73,7 +73,7 @@ static int capabilities[] = {
0, 0,
}; };
static const char* probe_names[] = { static const char *probe_names[] = {
"0", "0",
"1", "1",
"2", "2",

View File

@ -118,17 +118,18 @@ int sr_init_hwplugins(struct sr_device_plugin *plugin)
for (i = 0; i < num_devices; i++) { for (i = 0; i < num_devices; i++) {
num_probes = GPOINTER_TO_INT( num_probes = GPOINTER_TO_INT(
plugin->get_device_info(i, SR_DI_NUM_PROBES)); 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) { 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; continue;
} }
device = sr_device_new(plugin, i); 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]); sr_device_probe_add(device, probe_names[j]);
}
num_initialized_devices++; num_initialized_devices++;
} }

View File

@ -40,22 +40,23 @@ static int format_match(const char *filename)
static int init(struct sr_input *in) static int init(struct sr_input *in)
{ {
int num_probes, i; int num_probes, i;
char name[SR_MAX_PROBENAME_LEN]; char name[SR_MAX_PROBENAME_LEN + 1];
if (in->param && in->param[0]) { if (in->param && in->param[0]) {
num_probes = strtoul(in->param, NULL, 10); num_probes = strtoul(in->param, NULL, 10);
if (num_probes < 1) if (num_probes < 1)
return SR_ERR; return SR_ERR;
} else } else {
num_probes = DEFAULT_NUM_PROBES; num_probes = DEFAULT_NUM_PROBES;
}
/* create a virtual device */ /* Create a virtual device. */
in->vdevice = sr_device_new(NULL, 0); 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); 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; return SR_OK;

View File

@ -78,7 +78,7 @@ static int format_match(const char *filename)
static int init(struct sr_input *in) static int init(struct sr_input *in)
{ {
int num_probes, i; int num_probes, i;
char name[SR_MAX_PROBENAME_LEN]; char name[SR_MAX_PROBENAME_LEN + 1];
if (in->param && in->param[0]) { if (in->param && in->param[0]) {
num_probes = strtoul(in->param, NULL, 10); 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++) { for (i = 0; i < num_probes; i++) {
snprintf(name, SR_MAX_PROBENAME_LEN, "%d", 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; return SR_OK;

View File

@ -43,7 +43,7 @@ int sr_session_load(const char *filename)
int ret, err, probenum, devcnt, i, j; int ret, err, probenum, devcnt, i, j;
uint64_t tmp_u64, total_probes, enabled_probes, p; uint64_t tmp_u64, total_probes, enabled_probes, p;
char **sections, **keys, *metafile, *val, c; 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))) { if (!(archive = zip_open(filename, 0, &err))) {
sr_dbg("Failed to open session file: zip error %d", err); sr_dbg("Failed to open session file: zip error %d", err);