?? deviceimpl.java
字號:
public String getDriverKeyName(){ return this.driverKeyName; } /** * Returns the name of an external Hub */ private native String getExternalHubName(int hubHandle,int portIndex); /** * Returns the byte stream for the DeviceDescriptor */ public native byte[] getDeviceDescriptor(int hubHandle,int portIndex); /** * Returns the byte stream for the DeviceDescriptor */ public native byte[] getConfigurationDescriptor(int hubHandle,int portIndex); /** * Returns identifier which is unique to a usbdevice * This string is only valid for usb devices! It is not * used for roothub and hubs. */ private native String getUniqueDeviceID(int hubHandle,int portIndex); /** Returns the device connected to this hub's specific port(origin one), or null * @param port The port number of the hub beginning at one to the number of ports the hub * provides */ public Device getChild(int port) throws java.io.IOException { if(children == null) return null; else return children[port-1]; } /** Returns the default configuration from the device. The default configuration is * is always configuration at index zero. */ public Configuration getConfiguration() throws java.io.IOException { return this.configuration; } /** Not implemented for all devices. So far it will return always null! * @return Always null! */ public Configuration getConfiguration(int index) throws java.io.IOException { return null; } /** Returns the device dscriptor of the device */ public DeviceDescriptor getDeviceDescriptor() { return this.descriptor; } /** Returns the hub the device is connected to */ public Device getHub() { return this.hub; } /** Returns the port number of the hub where the device is connected to * @return The port number; value between 1..126 */ public int getHubPortNum() { return this.hubPortNumber; } /** Returns the number of port the hub provides. * @return The number of ports this hub supports<br> * 0 if it is a device */ public int getNumPorts() { return (children == null) ? 0 : children.length; } /** The friendly device name of this device * @return The frinedly device name or null if it does not exist */ public String getFriendlyDeviceName(){ return this.friendlyDeviceName; } // enumerate the hub /** EnumerateHubPorts does iterates over all the ports of this hub and creates * depending on the driver the device uses either a NonJusb or a JUSB object * @param bus The bus the device is conected to * @param hubHandle The Windows OS hub handle for this hub * @param hub The hub device itself * @param numPorts The number of ports this hub supports */ synchronized void enumerateHubPorts(USB bus, int hubHandle,DeviceImpl hub, int numPorts) throws IOException, USBException{ DeviceImpl oldDev; DeviceImpl [] oldChildren = null; if(hub != null){ if(hub.getAddress() != 0){ if(Windows.debugEnum) System.out.println("DeviceImpl.enumerateHubPorts() >>> oldChildren of an external hub"); oldChildren = hub.getChildren(); if(Windows.debugEnum) printDevices(oldChildren); } else{ if( this.oldDevices != null) { if(this.oldDevices[0] != null){ if(Windows.debugEnum) System.out.println("DeviceImpl.enumerateHubPorts() >>> oldChildren of the root hub"); oldChildren = oldDevices[0].getChildren(); if(Windows.debugEnum) printDevices(oldChildren); } } else if(Windows.debugEnum) System.out.println("DeviceImpl.enumerateHubPorts() >>> no oldDevices: This happens when running the first time"); } } else if(Windows.debugEnum) System.out.println("DeviceImpl.enumerateHubPorts() >>> we have no children, because we do not have a hub"); //iterate over the port to discover what is connected to each one if(numPorts > 0) hub.children = new DeviceImpl[numPorts]; else children = null; if(Windows.debugDeviceImpl) System.out.println("DeviceImpl.enumerateHubPorts() >>> hubHandle=" + hubHandle +" address=" + this.getAddress() + " numPorts=" + numPorts); DeviceImpl dev; // caution: Ports are numbered from 1 to n and not 0 to n!!! for(int portIndex=1; portIndex < numPorts + 1; portIndex++){ if(Windows.debugEnum && this.oldDevices != null && bus.getBusNum()==1){ System.out.println("DeviceImpl.enumerateHubPorts() >>> oldDevices:" ); printDevices(this.oldDevices); } int devType = getAttachedDeviceType(hubHandle,portIndex); if(Windows.debugDeviceImpl){ System.out.print("DeviceImpl.enumerateHubPorts() >>> getAttachedDeviceType: portIndex:" + portIndex + " Device Type:"); if(devType == USB_DEVICE) System.out.println(" USB Device"); else if(devType == EXTERNAL_HUB) System.out.println(" External Hub"); else if(devType == NO_DEVICE_CONNECTED) System.out.println(" No device connected"); else System.out.println(" Somethibg else --> " + devType); } // get some information about the attached device String driverKeyName = null; String friendlyDeviceName = null; String uniqueID = null; if(devType == USB_DEVICE || devType == EXTERNAL_HUB){ driverKeyName = getDriverKeyNameOfDeviceOnPort(hubHandle,portIndex); if(driverKeyName == null){ // we have an external hub friendlyDeviceName = null; } else { // we have a device friendlyDeviceName = getFriendlyDeviceName(driverKeyName); } uniqueID = this.getUniqueDeviceID(hubHandle, portIndex); if(Windows.debugDeviceImpl) System.out.println("DeviceImpl.enumerateHubPorts() >>> on Port["+portIndex+"]<< Device connected" ); if(Windows.debugDeviceImpl) System.out.println("--- DriverKeyName : " + driverKeyName ); if(Windows.debugDeviceImpl) System.out.println("--- friendlyDeviceName : " + friendlyDeviceName ); if(Windows.debugDeviceImpl) System.out.println("--- UniqueID : " + uniqueID ); } if(devType == USB_DEVICE){ // the device on portIndex is a USB Device if(Windows.debugEnum) System.out.print("DeviceImpl.enumerateHubPorts() >>> NOW on Port["+portIndex+"]<< Device connected" ); //String driverKeyName = getDriverKeyNameOfDeviceOnPort(hubHandle,portIndex); //String uniqueID = this.getUniqueDeviceID(hubHandle, portIndex); if(uniqueID == null) throw new USBException("Could not get the uniqueID of the device! May be Error in native jusb.cpp::getUniqueDeviceID --> DeviceIoControl (check with external debugger: Sysinternals)"); int devAddress = Integer.parseInt(uniqueID.substring(8,uniqueID.indexOf('&'))); if(Windows.debugDeviceImpl) System.out.println("DeviceImpl.enumerateHubPorts() >>> USB_DEVICE:Port:" + portIndex + " Address:" + this.getAddress() + " DriverKeyName:" + driverKeyName + " <<<<<<<<<< deviceAddress = " + devAddress); // check if this device was already on the bus if(this.oldDevices != null) oldDev = this.oldDevices[devAddress]; else oldDev = null; if(oldDev != null ){ if(!oldDev.getUniqueDeviceID().equals(uniqueID)){ // we have a devive, but it is not identical to // that device we just found on the bus if(Windows.debugEnum) System.out.println(" >> BEFORE << a different DEVICE was connected to this (root)hub. Former Device ID:" + oldDev.getUniqueDeviceID()); if(Windows.debugEnum) System.out.println("DeviceImpl.enumerateHubPorts() >>> TO DO << remove the former device. Add the new device."); bus.removeDevice(oldDev); // add the new one to the bus // depending on the friendlyDeviceName we create either a JSUB instance or a NonJUSB instance if(friendlyDeviceName != null && friendlyDeviceName.startsWith(Windows.A_JUSB_DRIVER)) dev = new JUSB(usb,this,null,devAddress,driverKeyName,friendlyDeviceName,uniqueID,portIndex); else dev = new NonJUSB(usb,this,null,devAddress,driverKeyName,friendlyDeviceName,uniqueID,portIndex); hub.children[portIndex-1] = dev; bus.addDevice(dev, devAddress); } else{ // the device is still the same one // add it again as a child of this hub. if(Windows.debugEnum) System.out.println("DeviceImpl.enumerateHubPorts() >>> BEFORE << the same one"); hub.children[portIndex-1] = oldDev; } } else{ // there was no device attached before // add this new device now to the bus if(Windows.debugEnum) System.out.println(" >> BEFORE << no connection"); if(Windows.debugEnum) System.out.println("DeviceImpl.enumerateHubPorts() >>> TO DO << Add the new device."); // depending on the friendlyDeviceName we create either a JSUB instance or a NonJUSB instance if(friendlyDeviceName != null && friendlyDeviceName.startsWith(Windows.A_JUSB_DRIVER)) dev = new JUSB(usb,this,null,devAddress,driverKeyName,friendlyDeviceName,uniqueID,portIndex); else dev = new NonJUSB(usb,this,null,devAddress,driverKeyName,friendlyDeviceName,uniqueID,portIndex); hub.children[portIndex-1] = dev; bus.addDevice(dev, devAddress); } }else if(devType == EXTERNAL_HUB){ //this device is an external hub // add this external hub to the bus if(Windows.debugEnum) System.out.print("DeviceImpl.enumerateHubPorts() >>> NOW on Port["+portIndex+"]<< External hub connected" ); String hubName = getExternalHubName(hubHandle,portIndex); //String uniqueID = this.getUniqueDeviceID(hubHandle, portIndex); if(uniqueID == null) throw new USBException("Could not get the uniqueID of the device! May be Error in native jusb.cpp::getUniqueDeviceID --> DeviceIoControl (check with external debugger: Sysinternals)"); int devAddress = Integer.parseInt(uniqueID.substring(8,uniqueID.indexOf('&'))); if(Windows.debugDeviceImpl) System.out.println("DeviceImpl.enumerateHubPorts() >>> EXTERNAL_HUB:Port:" + portIndex + " Address:" + this.getAddress() + " <<<<<<<<<< deviceAddress = " + devAddress); String devPath = "\\\\.\\" + hubName; if(Windows.debugDeviceImpl) System.out.println("DeviceImpl.enumerateHubPorts() >>> External Hub Name:" + devPath); // check if this hub was already on the bus if(this.oldDevices != null) oldDev = this.oldDevices[devAddress]; else oldDev = null; if(oldDev != null ){ if(!oldDev.getUniqueDeviceID().equals(uniqueID)){ // we have a hub, but it is not identical to // that device we just found on the bus. // Therefore we have to remove the hub and all its
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -