-#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"
+
+/* Message logging helpers with subsystem-specific prefix string. */
+#define LOG_PREFIX "device: "
+#define sr_log(l, s, args...) sr_log(l, LOG_PREFIX s, ## args)
+#define sr_spew(s, args...) sr_spew(LOG_PREFIX s, ## args)
+#define sr_dbg(s, args...) sr_dbg(LOG_PREFIX s, ## args)
+#define sr_info(s, args...) sr_info(LOG_PREFIX s, ## args)
+#define sr_warn(s, args...) sr_warn(LOG_PREFIX s, ## args)
+#define sr_err(s, args...) sr_err(LOG_PREFIX s, ## args)
+
+/**
+ * @file
+ *
+ * Device handling in libsigrok.
+ */
+
+/**
+ * @defgroup grp_devices Devices
+ *
+ * Device handling in libsigrok.
+ *
+ * @{
+ */
+
+/** @private
+ * Allocate and initialize new struct sr_probe
+ * @param[in] index @copydoc sr_probe::index
+ * @param[in] type @copydoc sr_probe::type
+ * @param[in] enabled @copydoc sr_probe::enabled
+ * @param[in] name @copydoc sr_probe::name
+ *
+ * @return NULL (failure) or new struct sr_probe*.
+ */
+SR_PRIV struct sr_probe *sr_probe_new(int index, int type,
+ gboolean enabled, const char *name)
+{
+ struct sr_probe *probe;
+
+ if (!(probe = g_try_malloc0(sizeof(struct sr_probe)))) {
+ sr_err("Probe malloc failed.");
+ return NULL;