@@ -49,7 +49,13 @@ public class WindowsUSBDevice extends USBDeviceImpl {
4949 private static final int SUCCESS = 2 ;
5050
5151 private final WindowsAsyncTask asyncTask ;
52+ /**
53+ * Indicates if the device is a composite device
54+ */
55+ private final boolean isComposite ;
56+
5257 private List <InterfaceHandle > interfaceHandles ;
58+
5359 // device paths by interface number (first interface of function)
5460 private Map <Integer , String > devicePaths ;
5561
@@ -59,9 +65,12 @@ public class WindowsUSBDevice extends USBDeviceImpl {
5965 */
6066 private boolean showAsOpen ;
6167
62- WindowsUSBDevice (String devicePath , int vendorId , int productId , MemorySegment configDesc ) {
68+ WindowsUSBDevice (String devicePath , int vendorId , int productId , MemorySegment configDesc , boolean isComposite ) {
6369 super (devicePath , vendorId , productId );
6470 asyncTask = WindowsAsyncTask .INSTANCE ;
71+ this .isComposite = isComposite ;
72+ if (isComposite )
73+ devicePaths = new HashMap <>();
6574 readDescription (configDesc );
6675 }
6776
@@ -238,14 +247,7 @@ public synchronized void releaseInterface(int interfaceNumber) {
238247 WinUSB .WinUsb_Free (firstIntfHandle .winusbHandle );
239248 firstIntfHandle .winusbHandle = null ;
240249
241- var path = (String )getUniqueId ();
242- if (firstIntfHandle .interfaceNumber != 0 ) {
243- if (devicePaths != null )
244- path = devicePaths .get (firstIntfHandle .interfaceNumber );
245- else
246- path = null ;
247- }
248- LOG .log (DEBUG , "closing device {0}" , path );
250+ LOG .log (DEBUG , "closing device {0}" , getCachedInterfaceDevicePath (interfaceNumber ));
249251
250252 Kernel32 .CloseHandle (firstIntfHandle .deviceHandle );
251253 firstIntfHandle .deviceHandle = null ;
@@ -516,20 +518,13 @@ private InterfaceHandle findControlTransferInterface(USBControlTransfer setup) {
516518 }
517519
518520 private String getInterfaceDevicePath (int interfaceNumber ) {
519- var parentDevicePath = (String ) getUniqueId (); // device path is id
520- if (interfaceNumber == 0 )
521- return parentDevicePath ;
522-
523- if (devicePaths != null ) {
524- var devicePath = devicePaths .get (interfaceNumber );
525- if (devicePath != null )
526- return devicePath ;
527- }
521+ var devicePath = getCachedInterfaceDevicePath (interfaceNumber );
522+ if (devicePath != null )
523+ return devicePath ;
528524
529- try (var deviceInfoSet = DeviceInfoSet .ofPath (parentDevicePath )) {
530- if (!deviceInfoSet .isCompositeDevice ())
531- throwException ("internal error: interface belongs to a composite function but device is not composite" );
525+ var parentDevicePath = (String ) getUniqueId ();
532526
527+ try (var deviceInfoSet = DeviceInfoSet .ofPath (parentDevicePath )) {
533528 var childrenInstanceIDs = deviceInfoSet .getStringListProperty (Children );
534529 if (childrenInstanceIDs == null ) {
535530 LOG .log (DEBUG , "missing children instance IDs for device {0}" , parentDevicePath );
@@ -551,6 +546,12 @@ private String getInterfaceDevicePath(int interfaceNumber) {
551546 return null ; // retry later
552547 }
553548
549+ private String getCachedInterfaceDevicePath (int interfaceNumber ) {
550+ if (!isComposite )
551+ return (String ) getUniqueId ();
552+ return devicePaths .get (interfaceNumber );
553+ }
554+
554555 private int fetchChildDevicePath (String instanceId , int interfaceNumber ) {
555556 try (var deviceInfoSet = DeviceInfoSet .ofInstance (instanceId )) {
556557
0 commit comments