-#include <sigrok.h>
-
-extern struct sigrok_global *global;
-
-GSList *devices = NULL;
-
-void device_scan(void)
-{
- GSList *plugins, *l;
- struct device_plugin *plugin;
- int num_devices, num_probes, i;
-
- plugins = list_hwplugins();
-
- /*
- * Initialize all plugins first. Since the init() call may involve
- * a firmware upload and associated delay, we may as well get all
- * of these out of the way first.
- */
- for (l = plugins; l; l = l->next) {
- plugin = l->data;
- g_message("initializing %s plugin", plugin->name);
- num_devices = plugin->init(NULL);
- for (i = 0; i < num_devices; i++) {
- num_probes
- = (int)(unsigned long)plugin->get_device_info(i,
- DI_NUM_PROBES);
- device_new(plugin, i, num_probes);
- }
+#include "config.h" /* Needed for HAVE_LIBUSB_1_0 and others. */
+#include "libsigrok.h"
+#include "libsigrok-internal.h"
+
+/** @cond PRIVATE */
+#define LOG_PREFIX "device"
+/** @endcond */
+
+/**
+ * @file
+ *
+ * Device handling in libsigrok.
+ */
+
+/**
+ * @defgroup grp_devices Devices
+ *
+ * Device handling in libsigrok.
+ *
+ * @{
+ */
+
+/** @private
+ * Allocate and initialize new struct sr_channel
+ * @param[in] index @copydoc sr_channel::index
+ * @param[in] type @copydoc sr_channel::type
+ * @param[in] enabled @copydoc sr_channel::enabled
+ * @param[in] name @copydoc sr_channel::name
+ *
+ * @return NULL (failure) or new struct sr_channel*.
+ */
+SR_PRIV struct sr_channel *sr_channel_new(int index, int type,
+ gboolean enabled, const char *name)
+{
+ struct sr_channel *ch;
+
+ if (!(ch = g_try_malloc0(sizeof(struct sr_channel)))) {
+ sr_err("Channel malloc failed.");
+ return NULL;