summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMike Lockwood <lockwood@android.com>2010-07-19 20:15:15 -0400
committerMike Lockwood <lockwood@android.com>2010-07-20 09:50:56 -0400
commita805519ceedc53afa5453a6d8a7d80038d885d9f (patch)
treeb01636a009cd39592e9989fa8b552e89a79edebb
parentd5c4d2ae3af12f13f1d6700b395fcac13143d01c (diff)
downloadsystem_core-a805519ceedc53afa5453a6d8a7d80038d885d9f.zip
system_core-a805519ceedc53afa5453a6d8a7d80038d885d9f.tar.gz
system_core-a805519ceedc53afa5453a6d8a7d80038d885d9f.tar.bz2
libusbhost: Add callback to usb_host_run to notify when initial device discovery is done
This can be used to eliminate race conditions in clients that operate immediately on the currently connected device list. Signed-off-by: Mike Lockwood <lockwood@android.com> Change-Id: I14954b9fcc84239950ead6bdc1a0a888882c2226
-rw-r--r--include/usbhost/usbhost.h8
-rw-r--r--libusbhost/usbhost.c3
2 files changed, 11 insertions, 0 deletions
diff --git a/include/usbhost/usbhost.h b/include/usbhost/usbhost.h
index c6a443c..7432277 100644
--- a/include/usbhost/usbhost.h
+++ b/include/usbhost/usbhost.h
@@ -42,6 +42,11 @@ typedef int (* usb_device_added_cb)(const char *dev_name, void *client_data);
*/
typedef int (* usb_device_removed_cb)(const char *dev_name, void *client_data);
+/* Callback indicating that initial device discovery is done.
+ * Return true to exit from usb_host_run.
+ */
+typedef int (* usb_discovery_done_cb)(void *client_data);
+
/* Call this to initialize the USB host library. */
struct usb_host_context *usb_host_init(void);
@@ -54,10 +59,13 @@ void usb_host_cleanup(struct usb_host_context *context);
* added_cb will be called immediately for each existing USB device,
* and subsequently each time a new device is added.
* removed_cb is called when USB devices are removed from the bus.
+ * discovery_done_cb is called after the initial discovery of already
+ * connected devices is complete.
*/
void usb_host_run(struct usb_host_context *context,
usb_device_added_cb added_cb,
usb_device_removed_cb removed_cb,
+ usb_discovery_done_cb discovery_done_cb,
void *client_data);
/* Creates a usb_device object for a USB device */
diff --git a/libusbhost/usbhost.c b/libusbhost/usbhost.c
index efd3103..f5ec140 100644
--- a/libusbhost/usbhost.c
+++ b/libusbhost/usbhost.c
@@ -144,6 +144,7 @@ void usb_host_cleanup(struct usb_host_context *context)
void usb_host_run(struct usb_host_context *context,
usb_device_added_cb added_cb,
usb_device_removed_cb removed_cb,
+ usb_discovery_done_cb discovery_done_cb,
void *client_data)
{
struct inotify_event* event;
@@ -174,6 +175,8 @@ void usb_host_run(struct usb_host_context *context,
/* check for existing devices first, after we have inotify set up */
done = find_existing_devices(added_cb, removed_cb, client_data);
+ if (discovery_done_cb)
+ done |= discovery_done_cb(client_data);
while (!done) {
ret = read(context->fd, event_buf, sizeof(event_buf));