|
From: Mike C. <mc...@us...> - 2008-08-18 21:31:11
|
Update of /cvsroot/javax-usb/javax-usb-libusb/src/com/mcreations/usb/windows In directory sc8-pr-cvs17.sourceforge.net:/tmp/cvs-serv12959/src/com/mcreations/usb/windows Modified Files: JavaxUsb.java WindowsUsbServices.java Log Message: better, but still not perfect port enumeration during hot plugging. Needs better release of ports when disconnected Index: WindowsUsbServices.java =================================================================== RCS file: /cvsroot/javax-usb/javax-usb-libusb/src/com/mcreations/usb/windows/WindowsUsbServices.java,v retrieving revision 1.4 retrieving revision 1.5 diff -C2 -d -r1.4 -r1.5 *** WindowsUsbServices.java 18 Aug 2008 18:52:04 -0000 1.4 --- WindowsUsbServices.java 18 Aug 2008 21:31:07 -0000 1.5 *************** *** 320,323 **** --- 320,324 ---- device.disconnect(); listenerImp.usbDeviceDetached(new UsbServicesEvent(this, (UsbDevice)device )); + } *************** *** 330,342 **** // is really needed in libusb implementation // setActiveConfigAndInterfaceSettings(device); ! try ! { ! device.getParentUsbPortImp().attachUsbDeviceImp(device); ! } ! catch (IllegalArgumentException iae) ! { ! // device is already attached ! continue; ! } // Let's wait a bit before each new device's event, so its driver can have some time to --- 331,345 ---- // is really needed in libusb implementation // setActiveConfigAndInterfaceSettings(device); ! // attachUsbDeviceImp now occures in JavaUsb.java ! // try ! // { ! // device.getParentUsbPortImp().attachUsbDeviceImp(device); ! // } ! // catch (IllegalArgumentException iae) ! // { ! // if(log.isDebugEnabled()) log.debug( "updateTopology() while attaching UsbDeviceImp "+iae ); ! // // device is already attached ! // continue; ! // } // Let's wait a bit before each new device's event, so its driver can have some time to *************** *** 344,348 **** try { ! if(!device.isUsbHub()) Thread.sleep(topologyUpdateNewDeviceDelay); } catch (InterruptedException iE) --- 347,356 ---- try { ! // if(!device.isUsbHub()) ! if( !(device instanceof WindowsHubOsImp) ) ! { ! if(log.isDebugEnabled()) log.debug( "sleeping to let new device settle" ); ! Thread.sleep(topologyUpdateNewDeviceDelay); ! } } catch (InterruptedException iE) Index: JavaxUsb.java =================================================================== RCS file: /cvsroot/javax-usb/javax-usb-libusb/src/com/mcreations/usb/windows/JavaxUsb.java,v retrieving revision 1.6 retrieving revision 1.7 diff -C2 -d -r1.6 -r1.7 *** JavaxUsb.java 18 Aug 2008 18:52:04 -0000 1.6 --- JavaxUsb.java 18 Aug 2008 21:31:07 -0000 1.7 *************** *** 511,515 **** * an existing device, the old device is retained in the disconnected list, and the new device is returned. * @param hub The parent UsbHubImp. - * @param p The parent port number. * @param device The UsbDeviceImp to add. * @param currentDevices - the list of devices that were connected before this call to topology update --- 511,514 ---- *************** *** 518,534 **** * @return The new UsbDeviceImp or existing UsbDeviceImp. */ ! private static void checkUsbDeviceImp(UsbHubImp hub, int p, UsbDeviceImp device, List currentDevices, List connected) { String meth = "checkUsbDeviceImp"; ! byte port = (byte)p; ! if(log.isDebugEnabled()) log.debug( meth +"Entered with port" + p+" our port num "+port ); ! UsbPortImp usbPortImp = hub.getUsbPortImp((byte)port); ! if (null == usbPortImp) ! { ! log.debug(meth+" WARNING resizing port"); ! hub.resize((byte)port); ! usbPortImp = hub.getUsbPortImp((byte)port); ! } if(log.isDebugEnabled()) log.debug( meth+ " Hub now has " + hub.getNumberOfPorts() + " ports"); --- 517,533 ---- * @return The new UsbDeviceImp or existing UsbDeviceImp. */ ! private static void checkUsbDeviceImp(UsbHubImp hub, UsbDeviceImp device, List currentDevices, List connected) { String meth = "checkUsbDeviceImp"; ! // byte port = (byte)p; ! // if(log.isDebugEnabled()) log.debug( meth +" Entered with port" + p+" our port num "+port ); ! // UsbPortImp usbPortImp = hub.getUsbPortImp((byte)port); ! // if (null == usbPortImp) ! // { ! // log.debug(meth+" WARNING resizing port"); ! // hub.resize((byte)port); ! // usbPortImp = hub.getUsbPortImp((byte)port); ! // } if(log.isDebugEnabled()) log.debug( meth+ " Hub now has " + hub.getNumberOfPorts() + " ports"); *************** *** 552,556 **** if(log.isDebugEnabled()) log.debug(meth+" adding new device"); connected.add(device); ! device.setParentUsbPortImp(usbPortImp); } --- 551,556 ---- if(log.isDebugEnabled()) log.debug(meth+" adding new device"); connected.add(device); ! // device.setParentUsbPortImp(usbPortImp); ! attachParentUsbPort(hub,device); } *************** *** 558,561 **** --- 558,589 ---- } + private static void attachParentUsbPort(UsbHubImp hub, UsbDeviceImp device) + { + if(log.isDebugEnabled()) log.debug("attachParentUsbPort"); + List ports = hub.getUsbPorts(); + Iterator iterator = ports.iterator(); + while(iterator.hasNext()) + { + UsbPortImp usbPortImp = (UsbPortImp)iterator.next(); + if(usbPortImp.isUsbDeviceAttached()) continue; + if(log.isDebugEnabled()) log.debug("attachParentUsbPort(), found empty port"); + device.setParentUsbPortImp(usbPortImp); + usbPortImp.attachUsbDeviceImp(device); + return; + } + + byte port = hub.getNumberOfPorts(); + log.debug("attachParentUsbPort(), no empty ports found, out of "+ port+" ports"); + port++; + UsbPortImp usbPortImp = hub.getUsbPortImp((byte)port); + if (null == usbPortImp) + { + log.debug("attachParentUsbPort(), WARNING resizing port"); + hub.resize((byte)port); + usbPortImp = hub.getUsbPortImp((byte)port); + } + device.setParentUsbPortImp(usbPortImp); + usbPortImp.attachUsbDeviceImp(device); + } private static void buildConfig(UsbDeviceImp usbDev,usb_config_descriptor config) *************** *** 717,724 **** * @param dev * @param bus - * @param parentHub - * @param parentport */ ! static UsbDeviceImp buildDevice( usb_device dev, usb_bus bus, UsbHubImp parentHub, int parentport) { String meth = "buildDevice"; --- 745,750 ---- * @param dev * @param bus */ ! static UsbDeviceImp buildDevice( usb_device dev, usb_bus bus) { String meth = "buildDevice"; *************** *** 753,758 **** if(log.isDebugEnabled()) { ! log.debug("Leaving buildDevice with device " + dev.getFilename()); ! log.debug(""); } return(usbDev); --- 779,783 ---- if(log.isDebugEnabled()) { ! log.debug("buildDevice() Leaving buildDevice with device " + dev.getFilename()); } return(usbDev); *************** *** 809,817 **** log.debug(" disconnectedDevices size: "+disconnectedDevices.size()); - int portNum = 1; while (libusb_bus != null) { msg = "Scanning bus " + libusb_bus.getDirname(); log(LOG_HOTPLUG, DEBUG, CLASS, method, msg); --- 834,843 ---- log.debug(" disconnectedDevices size: "+disconnectedDevices.size()); while (libusb_bus != null) { msg = "Scanning bus " + libusb_bus.getDirname(); + log.debug(""); + log.debug(""); log(LOG_HOTPLUG, DEBUG, CLASS, method, msg); *************** *** 823,826 **** --- 849,853 ---- if(log.isDebugEnabled()) { + log.debug(""); msg = "Device: " + libusb_dev.getFilename(); log(LOG_HOTPLUG, DEBUG, CLASS, method, msg); *************** *** 842,856 **** // if( devDesc.getBDeviceClass() == Libusb.USB_CLASS_HUB) // { ! // UsbDeviceImp usbDev = buildDevice(libusb_dev, libusb_bus, rootHub, portNum++ ); ! // portNum++; // log.debug(method+" device is Hub, skipping"); // } // else { ! UsbDeviceImp usbDev = buildDevice(libusb_dev, libusb_bus, rootHub, portNum ); // usbDev is a device that is being reported as existing by libusb // if it is found in our list of disconnectedDevices, remove it and add it to // connected devices. ! checkUsbDeviceImp(rootHub, portNum++, usbDev, disconnectedDevices, connectedDevices); } libusb_dev = libusb_dev.getNext(); --- 869,882 ---- // if( devDesc.getBDeviceClass() == Libusb.USB_CLASS_HUB) // { ! // UsbDeviceImp usbDev = buildDevice(libusb_dev, libusb_bus ); // log.debug(method+" device is Hub, skipping"); // } // else { ! UsbDeviceImp usbDev = buildDevice(libusb_dev, libusb_bus ); // usbDev is a device that is being reported as existing by libusb // if it is found in our list of disconnectedDevices, remove it and add it to // connected devices. ! checkUsbDeviceImp(rootHub, usbDev, disconnectedDevices, connectedDevices); } libusb_dev = libusb_dev.getNext(); *************** *** 859,862 **** --- 885,889 ---- } log.debug(" disconnectedDevices size: "+disconnectedDevices.size()); + log.debug(" connectedDevices size: "+connectedDevices.size()); } finally |