/**
* 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
* @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.
*/
/* 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;
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);
SR_HWCAP_CONTINUOUS,
};
-static const char* probe_names[NUM_PROBES + 1] = {
+static const char *probe_names[NUM_PROBES + 1] = {
"0",
"1",
NULL,
0,
};
-static const char* probe_names[NUM_PROBES + 1] = {
+static const char *probe_names[NUM_PROBES + 1] = {
"0",
"1",
"2",
static GSList *device_instances = NULL;
-static const char* probe_names[NUM_PROBES + 1] = {
+static const char *probe_names[NUM_PROBES + 1] = {
"0",
"1",
"2",
0,
};
-static const char* probe_names[NUM_PROBES + 1] = {
+static const char *probe_names[NUM_PROBES + 1] = {
"0",
"1",
"2",
0,
};
-static const char* probe_names[] = {
+static const char *probe_names[] = {
"0",
"1",
"2",
0,
};
-static const char* probe_names[] = {
+static const char *probe_names[] = {
"0",
"1",
"2",
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++;
}
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;
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);
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;
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);