diff options
author | Nathan Hjelm <hjelmn@me.com> | 2013-05-16 20:48:56 -0600 |
---|---|---|
committer | Nathan Hjelm <hjelmn@me.com> | 2013-06-06 10:45:24 -0600 |
commit | 83331a1182d71d4bcd23304229a8c6ec530f6229 (patch) | |
tree | 770a8657adfe9f297b22b9484017a19c7d5d85ee /libusb/os/darwin_usb.h | |
parent | c35629939bde68ea7ee520ae8577288a36f0a9b7 (diff) | |
download | libusb-83331a1182d71d4bcd23304229a8c6ec530f6229.tar.gz |
darwin: avoid enumerating devices more than once
This patch attempts to avoid enumerating devices multiple times by
keeping a cache of device information (IOUSBDeviceInterface pointers,
device descriptors, etc) between calls to libusb_init(). This should
avoid two potential problems:
1) Devices that respond slowly to DeviceRequest. These devices can
take multiple seconds to respond and they usually respond with
a failure (on older versions of OSX at least). By keeping track
of these devices the penalty for enumerating them will be paid
only once.
2) Repeated enumeration of the same device may cause
IOCreatePlugInInterfaceForService() to fail. The root cause of
this problem is not well understood but might be a leak in
IOUSBFamily.
To clean up the cached device information an atexit() function is
used.
Diffstat (limited to 'libusb/os/darwin_usb.h')
-rw-r--r-- | libusb/os/darwin_usb.h | 65 |
1 files changed, 26 insertions, 39 deletions
diff --git a/libusb/os/darwin_usb.h b/libusb/os/darwin_usb.h index a80aa8b..53b8542 100644 --- a/libusb/os/darwin_usb.h +++ b/libusb/os/darwin_usb.h @@ -28,7 +28,19 @@ #include <IOKit/IOCFPlugIn.h> /* IOUSBInterfaceInferface */ -#if defined (kIOUSBInterfaceInterfaceID300) +#if defined (kIOUSBInterfaceInterfaceID550) + +#define usb_interface_t IOUSBInterfaceInterface550 +#define InterfaceInterfaceID kIOUSBInterfaceInterfaceID550 +#define InterfaceVersion 550 + +#elif defined (kIOUSBInterfaceInterfaceID500) + +#define usb_interface_t IOUSBInterfaceInterface500 +#define InterfaceInterfaceID kIOUSBInterfaceInterfaceID500 +#define InterfaceVersion 500 + +#elif defined (kIOUSBInterfaceInterfaceID300) #define usb_interface_t IOUSBInterfaceInterface300 #define InterfaceInterfaceID kIOUSBInterfaceInterfaceID300 @@ -46,24 +58,6 @@ #define InterfaceInterfaceID kIOUSBInterfaceInterfaceID220 #define InterfaceVersion 220 -#elif defined (kIOUSBInterfaceInterfaceID197) - -#define usb_interface_t IOUSBInterfaceInterface197 -#define InterfaceInterfaceID kIOUSBInterfaceInterfaceID197 -#define InterfaceVersion 197 - -#elif defined (kIOUSBInterfaceInterfaceID190) - -#define usb_interface_t IOUSBInterfaceInterface190 -#define InterfaceInterfaceID kIOUSBInterfaceInterfaceID190 -#define InterfaceVersion 190 - -#elif defined (kIOUSBInterfaceInterfaceID182) - -#define usb_interface_t IOUSBInterfaceInterface182 -#define InterfaceInterfaceID kIOUSBInterfaceInterfaceID182 -#define InterfaceVersion 182 - #else #error "IOUSBFamily is too old. Please upgrade your OS" @@ -95,24 +89,11 @@ #define DeviceInterfaceID kIOUSBDeviceInterfaceID245 #define DeviceVersion 245 -#elif defined (kIOUSBDeviceInterfaceID197) - +#elif defined (kIOUSBDeviceInterfaceID220) #define usb_device_t IOUSBDeviceInterface197 #define DeviceInterfaceID kIOUSBDeviceInterfaceID197 #define DeviceVersion 197 -#elif defined (kIOUSBDeviceInterfaceID187) - -#define usb_device_t IOUSBDeviceInterface187 -#define DeviceInterfaceID kIOUSBDeviceInterfaceID187 -#define DeviceVersion 187 - -#elif defined (kIOUSBDeviceInterfaceID182) - -#define usb_device_t IOUSBDeviceInterface182 -#define DeviceInterfaceID kIOUSBDeviceInterfaceID182 -#define DeviceVersion 182 - #else #error "IOUSBFamily is too old. Please upgrade your OS" @@ -127,13 +108,23 @@ typedef IOCFPlugInInterface *io_cf_plugin_ref_t; typedef IONotificationPortRef io_notification_port_t; /* private structures */ -struct darwin_device_priv { +struct darwin_cached_device { + struct list_head list; IOUSBDeviceDescriptor dev_descriptor; UInt32 location; + UInt64 parent_session; + UInt64 session; + UInt16 address; char sys_path[21]; usb_device_t **device; int open_count; - UInt8 first_config, active_config; + UInt8 first_config, active_config, port; + int can_enumerate; + int refcount; +}; + +struct darwin_device_priv { + struct darwin_cached_device *dev; }; struct darwin_device_handle_priv { @@ -156,11 +147,7 @@ struct darwin_transfer_priv { int num_iso_packets; /* Control */ -#if !defined (LIBUSB_NO_TIMEOUT_DEVICE) IOUSBDevRequestTO req; -#else - IOUSBDevRequest req; -#endif /* Bulk */ }; |