|
From: Mike C. <mc...@us...> - 2008-08-13 21:08:43
|
Update of /cvsroot/javax-usb/javax-usb-libusb/src/com/mcreations/usb/windows In directory sc8-pr-cvs17.sourceforge.net:/tmp/cvs-serv12844 Modified Files: JavaxUsb.java WindowsUsbServices.java Log Message: changed from indexes to Iterators to remove subtle errors with .remove Index: WindowsUsbServices.java =================================================================== RCS file: /cvsroot/javax-usb/javax-usb-libusb/src/com/mcreations/usb/windows/WindowsUsbServices.java,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** WindowsUsbServices.java 5 Aug 2008 16:26:52 -0000 1.2 --- WindowsUsbServices.java 13 Aug 2008 21:08:39 -0000 1.3 *************** *** 294,298 **** topologyListener.setName(threadName); ! // topologyListenerError = 0; topologyListener.start(); } --- 294,298 ---- topologyListener.setName(threadName); ! // topologyListenerError = 0; topologyListener.start(); } *************** *** 306,320 **** fillDeviceList(getRootUsbHubImp(),disconnectedDevices); ! disconnectedDevices.remove(getRootUsbHubImp()); ! // topologyUpdateResult = ! JavaxUsb.nativeTopologyUpdater(this, connectedDevices, disconnectedDevices); ! for (int i = 0; i < disconnectedDevices.size(); i++) ! ((UsbDeviceImp) disconnectedDevices.get(i)).disconnect(); ! for (int i = 0; i < connectedDevices.size(); i++) { ! UsbDeviceImp device = (UsbDeviceImp) connectedDevices.get(i); // fixme: setActiveConfig... is omitted to find out, whether it --- 306,326 ---- fillDeviceList(getRootUsbHubImp(),disconnectedDevices); ! while(disconnectedDevices.remove(getRootUsbHubImp())); ! JavaxUsb.nativeTopologyUpdater(this, connectedDevices, disconnectedDevices); ! Iterator iterator = disconnectedDevices.iterator(); ! while(iterator.hasNext()) ! { ! UsbDeviceImp device = (UsbDeviceImp) iterator.next(); ! if(log.isDebugEnabled()) log.debug( "updateTopology() disconnecting device: "+device ); ! device.disconnect(); ! listenerImp.usbDeviceDetached(new UsbServicesEvent(this, (UsbDevice)device )); ! } ! iterator = connectedDevices.iterator(); ! while(iterator.hasNext()) { ! UsbDeviceImp device = (UsbDeviceImp) iterator.next(); // fixme: setActiveConfig... is omitted to find out, whether it *************** *** 331,353 **** } ! for (int k = 0; k < connectedDevices.size(); k++) { ! /* Let's wait a bit before each new device's event, so its driver can have some time to ! * talk to it without interruptions. ! */ ! try ! { ! Thread.sleep(topologyUpdateNewDeviceDelay); ! } ! catch (InterruptedException iE) ! { ! } ! ! listenerImp.usbDeviceAttached(new UsbServicesEvent(this, (UsbDevice) connectedDevices.get(k))); } ! } ! for (int i = 0; i < disconnectedDevices.size(); i++) ! listenerImp.usbDeviceDetached(new UsbServicesEvent(this, (UsbDevice) disconnectedDevices.get(i))); synchronized (topologyLock) --- 337,353 ---- } ! // Let's wait a bit before each new device's event, so its driver can have some time to ! // talk to it without interruptions. FIXME, why is this delay here? ! try { ! Thread.sleep(topologyUpdateNewDeviceDelay); } ! catch (InterruptedException iE) ! { ! } ! if(log.isDebugEnabled()) log.debug( "updateTopology() connected device: "+device ); ! listenerImp.usbDeviceAttached(new UsbServicesEvent(this, (UsbDevice) device)); ! } synchronized (topologyLock) Index: JavaxUsb.java =================================================================== RCS file: /cvsroot/javax-usb/javax-usb-libusb/src/com/mcreations/usb/windows/JavaxUsb.java,v retrieving revision 1.4 retrieving revision 1.5 diff -C2 -d -r1.4 -r1.5 *** JavaxUsb.java 5 Aug 2008 20:53:24 -0000 1.4 --- JavaxUsb.java 13 Aug 2008 21:08:39 -0000 1.5 *************** *** 37,40 **** --- 37,41 ---- import java.util.Hashtable; import java.util.List; + import java.util.Iterator; import javax.usb.UsbConst; *************** *** 799,806 **** // were present before (they are in disconnectedDevices) // are still present, now ! for (int i = 0; i < disconnectedDevices.size(); i++) { ! connectedDevices.add(disconnectedDevices.get(i)); ! disconnectedDevices.remove(i); } return 0; --- 800,808 ---- // were present before (they are in disconnectedDevices) // are still present, now ! Iterator iterator = disconnectedDevices.iterator(); ! while(iterator.hasNext()) { ! connectedDevices.add(iterator.next()); ! iterator.remove(); } return 0; |