From 7a96ba436c9a2bacc64e712bdb53bd7accc5c3a9 Mon Sep 17 00:00:00 2001 From: Mike Lockwood Date: Thu, 1 Jul 2010 11:33:41 -0400 Subject: libusbhost: The client is now responsible for creating the thread that monitors the bus This is to allow using a thread that is capable of calling through JNI to Java code to report USB device attached/removed events. Change-Id: Ia58592607a2c1f4357b31072044f5db5617d7f5b Signed-off-by: Mike Lockwood --- include/usbhost/usbhost.h | 26 ++++++++++++++++++++------ 1 file changed, 20 insertions(+), 6 deletions(-) (limited to 'include/usbhost') diff --git a/include/usbhost/usbhost.h b/include/usbhost/usbhost.h index d67437b..c6a443c 100644 --- a/include/usbhost/usbhost.h +++ b/include/usbhost/usbhost.h @@ -23,6 +23,7 @@ extern "C" { #include +struct usb_host_context; struct usb_endpoint_descriptor; struct usb_descriptor_iter { @@ -31,18 +32,31 @@ struct usb_descriptor_iter { unsigned char* curr_desc; }; -/* callback for notification when new USB devices are attached */ -typedef void (* usb_device_added_cb)(const char *dev_name, void *client_data); +/* Callback for notification when new USB devices are attached. + * Return true to exit from usb_host_run. + */ +typedef int (* usb_device_added_cb)(const char *dev_name, void *client_data); + +/* Callback for notification when USB devices are removed. + * Return true to exit from usb_host_run. + */ +typedef int (* usb_device_removed_cb)(const char *dev_name, void *client_data); + +/* Call this to initialize the USB host library. */ +struct usb_host_context *usb_host_init(void); -/* callback for notification when USB devices are removed */ -typedef void (* usb_device_removed_cb)(const char *dev_name, void *client_data); +/* Call this to cleanup the USB host library. */ +void usb_host_cleanup(struct usb_host_context *context); -/* Call this to start monitoring the USB bus. +/* Call this to monitor the USB bus for new and removed devices. + * This is intended to be called from a dedicated thread, + * as it will not return until one of the callbacks returns true. * 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. */ -int usb_host_init(usb_device_added_cb added_cb, +void usb_host_run(struct usb_host_context *context, + usb_device_added_cb added_cb, usb_device_removed_cb removed_cb, void *client_data); -- cgit v1.1