}
/* If the probe has a name, remove it. */
- if (p->name) {
- g_free(p->name);
- p->name = NULL;
- }
+ g_free(p->name);
+ p->name = NULL;
/* If the probe has a trigger, remove it. */
- if (p->trigger) {
- g_free(p->trigger);
- p->trigger = NULL;
- }
+ g_free(p->trigger);
+ p->trigger = NULL;
return SR_OK;
}
/* TODO: Sanity check on 'name'. */
/* If the probe already has a name, kill it first. */
- if (p->name)
- g_free(p->name);
+ g_free(p->name);
p->name = g_strdup(name);
for (pnum = 1; pnum <= g_slist_length(device->probes); pnum++) {
p = sr_device_probe_find(device, pnum);
/* TODO: Silently ignore probes which cannot be found? */
- if (p && p->trigger) {
+ if (p) {
g_free(p->trigger);
p->trigger = NULL;
}
}
/* If the probe already has a trigger, kill it first. */
- if (p->trigger)
- g_free(p->trigger);
+ g_free(p->trigger);
p->trigger = g_strdup(trigger);
return FALSE;
}
+
+/**
+ * Returns information about the given device.
+ *
+ * @param device Pointer to the device to be checked. Must not be NULL.
+ * The device's 'plugin' field must not be NULL either.
+ * @param id The type of information.
+ * @param data The return value. Must not be NULL.
+ *
+ * @return SR_OK upon success, SR_ERR_ARG upon invalid arguments, or SR_ERR
+ * upon other errors.
+ */
+int sr_device_get_info(const struct sr_device *device, int id,
+ const void **data)
+{
+ if ((device == NULL) || (device->plugin == NULL))
+ return SR_ERR_ARG;
+
+ if (data == NULL)
+ return SR_ERR_ARG;
+
+ *data = device->plugin->get_device_info(device->plugin_index, id);
+
+ if (*data == NULL)
+ return SR_ERR;
+
+ return SR_OK;
+}
+