+
+/**
+ * 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;
+}
+
+/**
+ * Standard scan() callback API helper.
+ *
+ * This function can be used to perform common tasks required by a driver's
+ * scan() callback. It will initialize the driver for each device on the list
+ * and add the devices on the list to the driver's device instance list.
+ * Usually it should be used as the last step in the scan() callback, right
+ * before returning.
+ *
+ * Note: This function can only be used if std_init() has been called
+ * previously by the driver.
+ *
+ * Example:
+ * @code{c}
+ * static GSList *scan(struct sr_dev_driver *di, GSList *options)
+ * {
+ * struct GSList *device;
+ * struct sr_dev_inst *sdi;
+ *
+ * sdi = g_new0(sr_dev_inst, 1);
+ * sdi->vendor = ...;
+ * ...
+ * devices = g_slist_append(devices, sdi);
+ * ...
+ * return std_scan_complete(di, devices);
+ * }
+ * @endcode
+ *
+ * @param di The driver instance to use. Must not be NULL.
+ * @param devices List of newly discovered devices (struct sr_dev_inst).
+ *
+ * @return The @p devices list.
+ */
+SR_PRIV GSList *std_scan_complete(struct sr_dev_driver *di, GSList *devices)
+{
+ struct drv_context *drvc;
+ GSList *l;
+
+ if (!di) {
+ sr_err("Invalid driver instance (di), cannot complete scan.");
+ return NULL;
+ }
+
+ drvc = di->context;
+
+ for (l = devices; l; l = l->next) {
+ struct sr_dev_inst *sdi = l->data;
+ if (!sdi) {
+ sr_err("Invalid driver instance, cannot complete scan.");
+ return NULL;
+ }
+ sdi->driver = di;
+ }
+
+ drvc->instances = g_slist_concat(drvc->instances, g_slist_copy(devices));
+
+ return devices;
+}