2424
2525/**
2626 * Manages the USB devices.
27- *
27+ *
2828 * @author Klaus Reimer (k@ailis.de)
2929 */
3030final class DeviceManager
@@ -47,20 +47,19 @@ final class DeviceManager
4747
4848 /**
4949 * Constructs a new device manager.
50- *
50+ *
5151 * @param rootHub
5252 * The root hub. Must not be null.
53- * @param scanInterval
54- * The scan interval in milliseconds .
53+ * @param config
54+ * The configuration .
5555 * @throws UsbException
5656 * When USB initialization fails.
5757 */
58- DeviceManager (final RootHub rootHub , final int scanInterval )
59- throws UsbException
58+ DeviceManager (final RootHub rootHub , final Config config ) throws UsbException
6059 {
6160 if (rootHub == null )
6261 throw new IllegalArgumentException ("rootHub must be set" );
63- this .scanInterval = scanInterval ;
62+ this .scanInterval = config . getScanInterval () ;
6463 this .rootHub = rootHub ;
6564 this .context = new Context ();
6665 final int result = LibUsb .init (this .context );
@@ -69,6 +68,14 @@ final class DeviceManager
6968 throw ExceptionUtils .createPlatformException (
7069 "Unable to initialize libusb" , result );
7170 }
71+ if (config .isUseUSBDK ())
72+ {
73+ final int usbdkResult = LibUsb .setOption (this .context , LibUsb .OPTION_USE_USBDK );
74+ if (usbdkResult != LibUsb .SUCCESS && usbdkResult != LibUsb .ERROR_NOT_SUPPORTED )
75+ {
76+ throw ExceptionUtils .createPlatformException ("Unable to set USE_USBDK option" , usbdkResult );
77+ }
78+ }
7279 }
7380
7481 /**
@@ -79,10 +86,10 @@ public void dispose()
7986 {
8087 LibUsb .exit (this .context );
8188 }
82-
89+
8390 /**
8491 * Creates a device ID from the specified device.
85- *
92+ *
8693 * @param device
8794 * The libusb device. Must not be null.
8895 * @return The device id.
@@ -111,7 +118,7 @@ private DeviceId createId(final Device device) throws UsbPlatformException
111118
112119 /**
113120 * Scans the specified ports for removed devices.
114- *
121+ *
115122 * @param ports
116123 * The ports to scan for removals.
117124 */
@@ -130,7 +137,7 @@ private void scanRemovedDevices(final UsbPorts<Port, AbstractDevice> ports)
130137
131138 /**
132139 * Scans the specified ports for new devices.
133- *
140+ *
134141 * @param ports
135142 * The ports to scan for new devices.
136143 * @param hubId
@@ -165,7 +172,7 @@ private void scanNewDevices(final UsbPorts<Port, AbstractDevice> ports,
165172
166173 /**
167174 * Scans the specified hub for changes.
168- *
175+ *
169176 * @param hub
170177 * The hub to scan.
171178 */
@@ -197,7 +204,7 @@ public void scan(final UsbHub hub)
197204 /**
198205 * Updates the device list by adding newly connected devices to it and by
199206 * removing no longer connected devices.
200- *
207+ *
201208 * @throws UsbPlatformException
202209 * When libusb reported an error which we can't ignore during
203210 * scan.
@@ -211,7 +218,7 @@ private void updateDeviceList() throws UsbPlatformException
211218 final int result = LibUsb .getDeviceList (this .context , devices );
212219 if (result < 0 )
213220 {
214- throw ExceptionUtils .createPlatformException (
221+ throw ExceptionUtils .createPlatformException (
215222 "Unable to get USB device list" , result );
216223 }
217224
@@ -228,7 +235,7 @@ private void updateDeviceList() throws UsbPlatformException
228235 if (device == null )
229236 {
230237 final Device parent = LibUsb .getParent (libUsbDevice );
231- final DeviceId parentId = parent == null ? null :
238+ final DeviceId parentId = parent == null ? null :
232239 createId (parent );
233240 final int speed = LibUsb .getDeviceSpeed (libUsbDevice );
234241 final boolean isHub = id .getDeviceDescriptor ()
@@ -278,7 +285,7 @@ public synchronized void scan()
278285 /**
279286 * Returns the libusb device for the specified id. The device must be freed
280287 * after use.
281- *
288+ *
282289 * @param id
283290 * The id of the device to return. Must not be null.
284291 * @return device The libusb device. Never null.
@@ -327,7 +334,7 @@ public Device getLibUsbDevice(final DeviceId id) throws UsbPlatformException
327334
328335 /**
329336 * Releases the specified device.
330- *
337+ *
331338 * @param device
332339 * The device to release. Must not be null.
333340 */
@@ -346,7 +353,7 @@ public void start()
346353 // Do not start the scan thread when interval is set to 0
347354 final int scanInterval = this .scanInterval ;
348355 if (scanInterval == 0 ) return ;
349-
356+
350357 final Thread thread = new Thread (new Runnable ()
351358 {
352359 @ Override
0 commit comments