]> sigrok.org Git - libsigrok.git/blobdiff - device.c
Add sr_device_get_info
[libsigrok.git] / device.c
index 72cba33873fba72fe74a112df3d05ec4aebfad99..30649cd4f64b0ac8165b452a599f1544c867c6a9 100644 (file)
--- a/device.c
+++ b/device.c
@@ -205,16 +205,12 @@ int sr_device_probe_clear(struct sr_device *device, int probenum)
        }
 
        /* 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;
 }
@@ -351,8 +347,7 @@ int sr_device_probe_name(struct sr_device *device, int probenum,
        /* 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);
 
@@ -387,7 +382,7 @@ int sr_device_trigger_clear(struct sr_device *device)
        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;
                }
@@ -433,8 +428,7 @@ int sr_device_trigger_set(struct sr_device *device, int probenum,
        }
 
        /* 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);
 
@@ -487,3 +481,32 @@ gboolean sr_device_has_hwcap(const struct sr_device *device, int hwcap)
 
        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;
+}
+