com.ibm.jusb
Class UsbHubImp

java.lang.Object
  extended by com.ibm.jusb.UsbDeviceImp
      extended by com.ibm.jusb.UsbHubImp
All Implemented Interfaces:
UsbIrpImp.UsbIrpImpListener, java.util.EventListener, UsbDevice, UsbHub
Direct Known Subclasses:
VirtualRootUsbHubImp

public class UsbHubImp
extends UsbDeviceImp
implements UsbHub

UsbHub implementation.

This must be set up before use and/or connection to the topology tree. To set up, see UsbDeviceImp documentation. The number of ports may be set in the constructor, or it will default to 1. The number of ports can be dynamically resized if needed.

The port numbering is 1-based, not 0-based.

Author:
Dan Streetman

Field Summary
static int USB_HUB_MAX_PORTS
           
static int USB_HUB_MIN_PORTS
           
 
Fields inherited from class com.ibm.jusb.UsbDeviceImp
CREATE_SHORT_PACKET_EXCEPTION_POLICY_KEY, DCP_QUEUE_POLICY_KEY
 
Constructor Summary
UsbHubImp()
          Constructor.
UsbHubImp(int ports)
          Constructor.
UsbHubImp(int ports, UsbDeviceDescriptor desc)
          Constructor.
UsbHubImp(int ports, UsbDeviceDescriptor desc, UsbDeviceOsImp device)
          Constructor.
UsbHubImp(int ports, UsbDeviceOsImp device)
          Constructor.
UsbHubImp(UsbDeviceDescriptor desc)
          Constructor.
UsbHubImp(UsbDeviceDescriptor desc, UsbDeviceOsImp device)
          Constructor.
UsbHubImp(UsbDeviceOsImp device)
          Constructor.
 
Method Summary
 void addUsbDeviceImp(UsbDeviceImp usbDeviceImp, byte portNumber)
          Attach this device to this hub at the specified port.
 java.util.List getAttachedUsbDevices()
          Get all attached UsbDevices.
 byte getNumberOfPorts()
          Get the number of (downstream) ports this hub has.
 UsbPort getUsbPort(byte number)
          Get the specified port.
 UsbPortImp getUsbPortImp(byte number)
          Get the specified port.
 java.util.List getUsbPorts()
          Get all the ports this hub has.
 boolean isRootUsbHub()
          If this is the virtual root hub.
 boolean isUsbHub()
          If this is a UsbHub.
 void removeUsbDeviceImp(UsbDeviceImp usbDeviceImp, byte portNumber)
          Remove the device from this hub at the specified port.
 void resize(int ports)
          Resizes to the specified number of ports.
 
Methods inherited from class com.ibm.jusb.UsbDeviceImp
addUsbConfigurationImp, addUsbDeviceListener, asyncSubmit, asyncSubmit, connect, containsUsbConfiguration, createUsbControlIrp, disconnect, getActiveUsbConfiguration, getActiveUsbConfigurationImp, getActiveUsbConfigurationNumber, getCachedUsbStringDescriptor, getManufacturerString, getParentUsbPort, getParentUsbPortImp, getProductString, getSerialNumberString, getSpeed, getString, getUsbConfiguration, getUsbConfigurationImp, getUsbConfigurations, getUsbDeviceDescriptor, getUsbDeviceOsImp, getUsbStringDescriptor, isConfigured, removeUsbDeviceListener, setActiveUsbConfigurationNumber, setCachedUsbStringDescriptor, setParentUsbPortImp, setSpeed, setUsbDeviceDescriptor, setUsbDeviceOsImp, syncSubmit, syncSubmit, usbIrpImpComplete
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface javax.usb.UsbDevice
addUsbDeviceListener, asyncSubmit, asyncSubmit, containsUsbConfiguration, createUsbControlIrp, getActiveUsbConfiguration, getActiveUsbConfigurationNumber, getManufacturerString, getParentUsbPort, getProductString, getSerialNumberString, getSpeed, getString, getUsbConfiguration, getUsbConfigurations, getUsbDeviceDescriptor, getUsbStringDescriptor, isConfigured, removeUsbDeviceListener, syncSubmit, syncSubmit
 

Field Detail

USB_HUB_MIN_PORTS

public static final int USB_HUB_MIN_PORTS
See Also:
Constant Field Values

USB_HUB_MAX_PORTS

public static final int USB_HUB_MAX_PORTS
See Also:
Constant Field Values
Constructor Detail

UsbHubImp

public UsbHubImp()
Constructor.

This creates a hub with a initial number of ports set to 1. The the number of ports is adjustable at runtime via the resize method.


UsbHubImp

public UsbHubImp(int ports)
Constructor.

This creates a hub with the specified number of ports. The number of ports is not adjustable at runtime via the resize method; it will throw UnsupportedOperationException.

Parameters:
ports - The initial number of ports.

UsbHubImp

public UsbHubImp(UsbDeviceDescriptor desc)
Constructor.

This creates a hub with a initial number of ports set to 1. The the number of ports is adjustable at runtime via the resize method.

Parameters:
desc - This device's descriptor.

UsbHubImp

public UsbHubImp(UsbDeviceOsImp device)
Constructor.

This creates a hub with a initial number of ports set to 1. The the number of ports is adjustable at runtime via the resize method.

Parameters:
device - The platform device implementaiton.

UsbHubImp

public UsbHubImp(int ports,
                 UsbDeviceDescriptor desc)
Constructor.

This creates a hub with the specified number of ports. The number of ports is not adjustable at runtime via the resize method; it will throw UnsupportedOperationException.

Parameters:
ports - The initial number of ports.
desc - This device's descriptor.

UsbHubImp

public UsbHubImp(int ports,
                 UsbDeviceOsImp device)
Constructor.

This creates a hub with the specified number of ports. The number of ports is not adjustable at runtime via the resize method; it will throw UnsupportedOperationException.

Parameters:
ports - The initial number of ports.
device - The platform device implementation.

UsbHubImp

public UsbHubImp(UsbDeviceDescriptor desc,
                 UsbDeviceOsImp device)
Constructor.

This creates a hub with a initial number of ports set to 1. The the number of ports is adjustable at runtime via the resize method.

Parameters:
desc - This device's descriptor.
device - The platform device implementaiton.

UsbHubImp

public UsbHubImp(int ports,
                 UsbDeviceDescriptor desc,
                 UsbDeviceOsImp device)
Constructor.

This creates a hub with the specified number of ports. The number of ports is not adjustable at runtime via the resize method; it will throw UnsupportedOperationException.

Parameters:
ports - The initial number of ports.
desc - This device's descriptor.
device - The platform device implementation.
Method Detail

resize

public void resize(int ports)
            throws java.lang.UnsupportedOperationException
Resizes to the specified number of ports.

If resizing decreases the number of ports and there are devices attached to lost ports, this will remove only down to the port with a device attached. The device(s) need to be removed before the port(s)!

Parameters:
ports - The total number of ports to resize to.
Throws:
java.lang.UnsupportedOperationException

addUsbDeviceImp

public void addUsbDeviceImp(UsbDeviceImp usbDeviceImp,
                            byte portNumber)
                     throws UsbException
Attach this device to this hub at the specified port.

Parameters:
usbDeviceImp - the UsbDeviceImp to attach.
portNumber - the number (1-based) of the port to attach the device to.
Throws:
UsbException - If the port is already occupied.

removeUsbDeviceImp

public void removeUsbDeviceImp(UsbDeviceImp usbDeviceImp,
                               byte portNumber)
                        throws java.lang.IllegalArgumentException
Remove the device from this hub at the specified port.

Parameters:
usbDeviceImp - The UsbDeviceImp to remove.
portNumber - The number (1-based) of the port the device is attached to.
Throws:
java.lang.IllegalArgumentException - if the device is not already attached to the port it is being removed from, or the port number is invalid.

isUsbHub

public boolean isUsbHub()
Description copied from interface: UsbDevice
If this is a UsbHub.

Specified by:
isUsbHub in interface UsbDevice
Overrides:
isUsbHub in class UsbDeviceImp
Returns:
true if this is a UsbHub and false otherwise

isRootUsbHub

public boolean isRootUsbHub()
Description copied from interface: UsbHub
If this is the virtual root hub.

Specified by:
isRootUsbHub in interface UsbHub
Returns:
true if this is the virtual root hub

getNumberOfPorts

public byte getNumberOfPorts()
Description copied from interface: UsbHub
Get the number of (downstream) ports this hub has.

This is only the number of ports on the hub, not all ports are necessarily enabled, available, usable, or in some cases physically present. This only represents the number of downstream ports the hub claims to have. Note that all hubs have exactly one upstream port, which allows it to connect to the system (or another upstream hub). There is also a internal port which is generally only used by the hub itself. See the USB 1.1 specification sec 11.4 for details on the internal port, sec 11.5 for details on the downstream ports, and sec 11.6 for details on the upstream port.

Specified by:
getNumberOfPorts in interface UsbHub
Returns:
the number of ports for this hub

getUsbPorts

public java.util.List getUsbPorts()
Description copied from interface: UsbHub
Get all the ports this hub has.

The port numbering is 1-based.

The List will be unmodifiable.

Specified by:
getUsbPorts in interface UsbHub
Returns:
an iteration of UsbPort objects attached to this hub
See Also:
UsbHub.getUsbPort( byte number )

getUsbPort

public UsbPort getUsbPort(byte number)
Get the specified port.

Specified by:
getUsbPort in interface UsbHub
Parameters:
number - The number (1-based) of the port to get.
Returns:
The port with the specified number, or null.

getUsbPortImp

public UsbPortImp getUsbPortImp(byte number)
Get the specified port.

Parameters:
number - The number (1-based) of the port to get.
Returns:
The port with the specified number, or null.

getAttachedUsbDevices

public java.util.List getAttachedUsbDevices()
Description copied from interface: UsbHub
Get all attached UsbDevices.

The List will be unmodifiable.

Specified by:
getAttachedUsbDevices in interface UsbHub
Returns:
an iteration of devices currently attached to this hub