summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorlibdlo <libdlo@displaylink.com>2009-06-09 18:47:21 -0700
committerlibdlo <libdlo@displaylink.com>2009-06-09 18:47:21 -0700
commit1327f841a3bb407df447c6e8d05491fae03204e5 (patch)
tree226e0d5751588872c699f318e0c8887f2004e831
parentf5673eb2765d72718b961ae76899e37932a89fe0 (diff)
Restore claim_first_device as an option until device ownership is rationalized.
Keeps existing programs working, lets users play without having to configure, yet keeps claim_default_device deterministic for serious apps. Will likely be more shifts yet to come in how device ownership is handled, especially with the rise in importance of the kernel framebuffer driver.
-rw-r--r--src/libdlo.c29
-rw-r--r--src/libdlo.h24
2 files changed, 53 insertions, 0 deletions
diff --git a/src/libdlo.c b/src/libdlo.c
index 19f7b1e..a202e00 100644
--- a/src/libdlo.c
+++ b/src/libdlo.c
@@ -497,6 +497,35 @@ static const char* parse_cmdline(int *argc_p, char *argv[])
return display;
}
+
+dlo_dev_t dlo_claim_first_device(const dlo_claim_t flags, const uint32_t timeout)
+{
+ dlo_devlist_t *node;
+ dlo_devlist_t *next;
+ dlo_dev_t uid = 0;
+
+ /* Look for a DisplayLink device to connect to - note the first one which is unclaimed */
+ node = dlo_enumerate_devices();
+
+ // dlo_enumerate_devices allocates memory for each node, which we must free
+ while (node)
+ {
+ dlo_device_t *dev = (dlo_device_t *)node->dev.uid;
+
+ if (!uid && !dev->claimed)
+ {
+ uid = dlo_claim_device(node->dev.uid, flags, timeout);
+ }
+
+ /* If we haven't claimed a device, move on to the next one */
+ next = node->next;
+ dlo_free(node);
+ node = next;
+ }
+ return uid;
+}
+
+
dlo_dev_t dlo_claim_default_device(int *argc_p, char *argv[],
const dlo_claim_t flags, const uint32_t timeout)
{
diff --git a/src/libdlo.h b/src/libdlo.h
index 08cdc69..525e383 100644
--- a/src/libdlo.h
+++ b/src/libdlo.h
@@ -575,6 +575,30 @@ extern dlo_dev_t dlo_lookup_device(struct usb_device *udev);
extern dlo_devlist_t *dlo_enumerate_devices(void);
+/** Claim the first available (unclaimed) device.
+ *
+ * @param flags Flags word describing how the device is to be accessed.
+ * @param timeout Timeout in milliseconds (zero for infinite).
+ *
+ * @return Unique ID of the claimed device (or NULL if failed).
+ *
+ * This call performs a very similar function to @c dlo_claim_device() except
+ * that it performs the enumeration of connected devices on behalf of the caller
+ * and returns the unique ID of the first available (unclaimed device). This
+ * device is claimed automatically.
+ *
+ * Both because users will wish to use specific displays for specific purposes
+ * And because kernel framebuffer drivers and other device users aren't always
+ * counted as "claiming" the device, this interface is a bit dangerous.
+ * For "real" apps, use dlo_claim_default_device. This API kept for the
+ * time being to provide an interface that "just works" if any DisplayLink
+ * device is present.
+ *
+ * If no unclaimed devices are found, or if the claim operation itself fails in
+ * some way, the function will return a device handle of zero.
+ */
+extern dlo_dev_t dlo_claim_first_device(const dlo_claim_t flags, const uint32_t timeout);
+
/** Claim the specified device.
*
* @param uid Unique ID of the device to claim.