]> sigrok.org Git - libsigrok.git/blobdiff - src/std.c
Introduce standard implementation of the dev_list() callback
[libsigrok.git] / src / std.c
index d741c80928a62f0a549d5efbe9305f7a69a33454..aadf8236a790a3f79c38ece2cf6ebd191166991c 100644 (file)
--- a/src/std.c
+++ b/src/std.c
@@ -63,6 +63,28 @@ SR_PRIV int std_init(struct sr_context *sr_ctx, struct sr_dev_driver *di,
        return SR_OK;
 }
 
+/**
+ * Standard driver cleanup() callback API helper
+ *
+ * @param di The driver instance to use.
+ *
+ * Frees all device instances by calling sr_dev_clear() and then releases any
+ * resources allocated by std_init().
+ *
+ * @retval SR_OK Success
+ * @retval SR_ERR_ARG Invalid driver
+ *
+*/
+SR_PRIV int std_cleanup(const struct sr_dev_driver *di)
+{
+       int ret;
+
+       ret = sr_dev_clear(di);
+       g_free(di->context);
+
+       return ret;
+}
+
 /**
  * Standard API helper for sending an SR_DF_HEADER packet.
  *
@@ -315,3 +337,22 @@ SR_PRIV int std_dev_clear(const struct sr_dev_driver *driver,
 
        return ret;
 }
+
+/**
+ * Standard implementation for the driver dev_list() callback
+ *
+ * This function can be used as the dev_list callback by most drivers that use
+ * the standard helper functions. It returns the devices contained in the driver
+ * context instances list.
+ *
+ * @param di The driver instance to use.
+ *
+ * @return The list of devices/instances of this driver, or NULL upon errors
+ *         or if the list is empty.
+ */
+SR_PRIV GSList *std_dev_list(const struct sr_dev_driver *di)
+{
+       struct drv_context *drvc = di->context;
+
+       return drvc->instances;
+}