]> sigrok.org Git - libsigrok.git/blobdiff - src/device.c
Make 'struct sr_dev_inst' opaque.
[libsigrok.git] / src / device.c
index e7a0c4ffd277bf72c9a85b8946f37c13886df7ff..8e06fc180359689016f43f66c9bf947d7f109d69 100644 (file)
@@ -242,7 +242,7 @@ SR_PRIV struct sr_dev_inst *sr_dev_inst_new(int status,
 
 /** @private
  *  Free device instance struct created by sr_dev_inst().
- *  @param sdi  struct* to free.
+ *  @param sdi device instance to free.
  */
 SR_PRIV void sr_dev_inst_free(struct sr_dev_inst *sdi)
 {
@@ -260,7 +260,10 @@ SR_PRIV void sr_dev_inst_free(struct sr_dev_inst *sdi)
 
        for (l = sdi->channel_groups; l; l = l->next) {
                cg = l->data;
+               g_free(cg->name);
+               g_slist_free(cg->channels);
                g_free(cg->priv);
+               g_free(cg);
        }
        g_slist_free(sdi->channel_groups);
 
@@ -554,7 +557,6 @@ SR_API const char *sr_dev_inst_sernum_get(struct sr_dev_inst *sdi)
        return sdi->serial_num;
 }
 
-#ifdef HAVE_LIBUSB_1_0
 /**
  * Queries a device instances' connection identifier.
  *
@@ -566,16 +568,19 @@ SR_API const char *sr_dev_inst_sernum_get(struct sr_dev_inst *sdi)
 SR_API const char *sr_dev_inst_connid_get(struct sr_dev_inst *sdi)
 {
        struct drv_context *drvc;
+       int r, cnt, i, a, b;
+       char connection_id[64];
+
+#ifdef HAVE_LIBUSB_1_0
        struct sr_usb_dev_inst *usb;
        struct libusb_device **devlist;
        struct libusb_device_descriptor des;
-       int r, cnt, i, a, b;
-       char connection_id[64];
+#endif
 
        if (!sdi)
                return NULL;
 
-       #ifdef HAVE_LIBSERIALPORT
+#ifdef HAVE_LIBSERIALPORT
        struct sr_serial_dev_inst *serial;
 
        if ((!sdi->connection_id) && (sdi->inst_type == SR_INST_SERIAL)) {
@@ -584,9 +589,10 @@ SR_API const char *sr_dev_inst_connid_get(struct sr_dev_inst *sdi)
                serial = sdi->conn;
                sdi->connection_id = g_strdup(serial->port);
        }
-       #endif
+#endif
 
 
+#ifdef HAVE_LIBUSB_1_0
        if ((!sdi->connection_id) && (sdi->inst_type == SR_INST_USB)) {
                /* connection_id isn't populated, let's do that here. */
 
@@ -619,9 +625,39 @@ SR_API const char *sr_dev_inst_connid_get(struct sr_dev_inst *sdi)
 
                libusb_free_device_list(devlist, 1);
        }
+#endif
 
        return sdi->connection_id;
 }
-#endif
+
+/**
+ * Queries a device instances' channel list.
+ *
+ * @param sdi Device instance to use. Must not be NULL.
+ *
+ * @return The GSList of channels or NULL.
+ */
+SR_API GSList *sr_dev_inst_channels_get(struct sr_dev_inst *sdi)
+{
+       if (!sdi)
+               return NULL;
+
+       return sdi->channels;
+}
+
+/**
+ * Queries a device instances' channel groups list.
+ *
+ * @param sdi Device instance to use. Must not be NULL.
+ *
+ * @return The GSList of channel groups or NULL.
+ */
+SR_API GSList *sr_dev_inst_channel_groups_get(struct sr_dev_inst *sdi)
+{
+       if (!sdi)
+               return NULL;
+
+       return sdi->channel_groups;
+}
 
 /** @} */