com.ibm.jusb
Class UsbInterfaceImp

java.lang.Object
  extended by com.ibm.jusb.UsbInterfaceImp
All Implemented Interfaces:
UsbInterface

public class UsbInterfaceImp
extends java.lang.Object
implements UsbInterface

UsbInterface platform-independent implementation.

This must be set up before use.

When changing the active alternate setting, call the setActiveSettingNumber method. This will update the parent config's active interface setting map.

Author:
Dan Streetman

Constructor Summary
UsbInterfaceImp(UsbConfigurationImp config, UsbInterfaceDescriptor desc)
          Constructor.
UsbInterfaceImp(UsbConfigurationImp config, UsbInterfaceDescriptor desc, UsbInterfaceOsImp osImp)
          Constructor.
 
Method Summary
 void addUsbEndpointImp(UsbEndpointImp ep)
           
 void claim()
          Claim this interface.
 void claim(UsbInterfacePolicy policy)
          Claim this interface using a UsbInterfacePolicy.
 boolean containsSetting(byte number)
          If the specified alternate setting exists.
 boolean containsUsbEndpoint(byte address)
          If the specified UsbEndpoint is contained in this UsbInterface.
 UsbInterface getActiveSetting()
          Get the active alternate setting.
 UsbInterfaceImp getActiveSettingImp()
          Get the active alternate setting.
 byte getActiveSettingNumber()
          Get the number of the active alternate setting for this interface
 java.lang.String getInterfaceString()
          Get the interface String.
 int getNumSettings()
          Get the number of alternate settings for this interface.
 UsbInterface getSetting(byte number)
          Get the alternate setting with the specified number.
 UsbInterfaceImp getSettingImp(byte number)
          Get the alternate setting with the specified number.
 java.util.List getSettings()
          Get all alternate settings for this interface.
 UsbConfiguration getUsbConfiguration()
          Get the parent UsbConfiguration that this UsbInterface belongs to.
 UsbConfigurationImp getUsbConfigurationImp()
           
 UsbEndpoint getUsbEndpoint(byte address)
          Get a specific UsbEndpoint.
 UsbEndpointImp getUsbEndpointImp(byte address)
           
 java.util.List getUsbEndpoints()
          Get all endpoints for this interface setting.
 UsbInterfaceDescriptor getUsbInterfaceDescriptor()
          Get the interface descriptor.
 UsbInterfaceOsImp getUsbInterfaceOsImp()
           
 boolean isActive()
          If this interface setting is active.
 boolean isClaimed()
          If this interface is claimed.
 boolean isJavaClaimed()
          If this is claimed in java.
 void release()
          Release this interface.
 void setActiveSettingNumber(byte number)
          Set the active alternate setting number for ALL UsbInterfaces on the AlternateSettings list
 void setUsbConfigurationImp(UsbConfigurationImp config)
          Set the UsbConfigurationImp.
 void setUsbInterfaceDescriptor(UsbInterfaceDescriptor desc)
           
 void setUsbInterfaceOsImp(UsbInterfaceOsImp iface)
           
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

UsbInterfaceImp

public UsbInterfaceImp(UsbConfigurationImp config,
                       UsbInterfaceDescriptor desc)
Constructor.

Parameters:
config - The parent config. If this is not null, the UsbInterfaceDescriptor cannot be null.
desc - This interface's descriptor. This cannot be null if the parent config is not null.

UsbInterfaceImp

public UsbInterfaceImp(UsbConfigurationImp config,
                       UsbInterfaceDescriptor desc,
                       UsbInterfaceOsImp osImp)
Constructor.

Parameters:
config - The parent config. If this is not null, the UsbInterfaceDescriptor cannot be null.
desc - This interface's descriptor. This cannot be null if the parent config is not null.
osImp - The UsbInterfaceOsImp.
Method Detail

claim

public void claim()
           throws UsbClaimException,
                  UsbException,
                  UsbNotActiveException,
                  UsbDisconnectedException
Claim this interface.

This calls the other claim with a default policy.

Specified by:
claim in interface UsbInterface
Throws:
UsbClaimException - If the interface is already claimed.
UsbException - if the interface could not be claimed.
UsbNotActiveException - if the interface setting is not active.
UsbDisconnectedException - If this device has been disconnected.

claim

public void claim(UsbInterfacePolicy policy)
           throws UsbClaimException,
                  UsbException,
                  UsbNotActiveException,
                  UsbDisconnectedException
Claim this interface using a UsbInterfacePolicy.

This will claim all alternate settings using the provided UsbInterfacePolicy. If the interface is already claimed this will fail.

This can only be called from an active alternate setting.

Specified by:
claim in interface UsbInterface
Parameters:
policy - The UsbInterfacePolicy to use.
Throws:
UsbClaimException - If the interface is already claimed.
UsbException - if the interface could not be claimed.
UsbNotActiveException - if the interface setting is not active.
UsbDisconnectedException - If this device has been disconnected.

release

public void release()
             throws UsbClaimException,
                    UsbException,
                    UsbNotActiveException,
                    UsbDisconnectedException
Release this interface.

Specified by:
release in interface UsbInterface
Throws:
UsbClaimException - If the interface is already claimed.
UsbException - if the interface could not be released.
UsbNotActiveException - if the interface setting is not active.
UsbDisconnectedException - If this device has been disconnected.

isClaimed

public boolean isClaimed()
Description copied from interface: UsbInterface
If this interface is claimed.

This will return true if claimed in Java. This may, depending on implementation, return true if claimed natively (outside of Java)

If this UsbInterface is not active, this will return if the active alternate setting is active.

Specified by:
isClaimed in interface UsbInterface
Returns:
if this interface is claimed.

isJavaClaimed

public boolean isJavaClaimed()
If this is claimed in java.

This should only be used by javax.usb implementations; this is not part of the javax.usb API.

Returns:
if this is claimed in java.

isActive

public boolean isActive()
If this interface setting is active.

Specified by:
isActive in interface UsbInterface
Returns:
if this UsbInterface setting is active.

getUsbEndpoints

public java.util.List getUsbEndpoints()
Description copied from interface: UsbInterface
Get all endpoints for this interface setting.

Specified by:
getUsbEndpoints in interface UsbInterface
Returns:
The endpoints.

getUsbEndpoint

public UsbEndpoint getUsbEndpoint(byte address)
Description copied from interface: UsbInterface
Get a specific UsbEndpoint.

If this does not contain the specified endpoint, this returns null.

Specified by:
getUsbEndpoint in interface UsbInterface
Parameters:
address - The address of the UsbEndpoint to get.
Returns:
The UsbEndpoint with the specified address.

getUsbEndpointImp

public UsbEndpointImp getUsbEndpointImp(byte address)
Parameters:
address - The address of the UsbEndpointImp to get.
Returns:
The UsbEndpointImp with the specified address, or null.

containsUsbEndpoint

public boolean containsUsbEndpoint(byte address)
Description copied from interface: UsbInterface
If the specified UsbEndpoint is contained in this UsbInterface.

Specified by:
containsUsbEndpoint in interface UsbInterface
Parameters:
address - the address of the UsbEndpoint to check.
Returns:
if this UsbInterface contains the specified UsbEndpoint.

getUsbConfiguration

public UsbConfiguration getUsbConfiguration()
Description copied from interface: UsbInterface
Get the parent UsbConfiguration that this UsbInterface belongs to.

Specified by:
getUsbConfiguration in interface UsbInterface
Returns:
The parent configuration

getUsbConfigurationImp

public UsbConfigurationImp getUsbConfigurationImp()
Returns:
The parent config

setUsbConfigurationImp

public void setUsbConfigurationImp(UsbConfigurationImp config)
Set the UsbConfigurationImp.

This also adds this to the parent UsbConfigurationImp. The UsbInterfaceDescriptor must be set before calling this.

Parameters:
config - The parent config

getNumSettings

public int getNumSettings()
Description copied from interface: UsbInterface
Get the number of alternate settings for this interface.

Specified by:
getNumSettings in interface UsbInterface
Returns:
the number of alternate settings

getActiveSettingNumber

public byte getActiveSettingNumber()
                            throws UsbNotActiveException
Get the number of the active alternate setting for this interface

Specified by:
getActiveSettingNumber in interface UsbInterface
Returns:
the active setting for this interface
Throws:
UsbNotActiveException - if the interface is inactive.

getActiveSetting

public UsbInterface getActiveSetting()
                              throws UsbNotActiveException
Get the active alternate setting.

Specified by:
getActiveSetting in interface UsbInterface
Returns:
the active setting UsbInterface object for this interface
Throws:
UsbNotActiveException - if the interface (not setting) is inactive.

getActiveSettingImp

public UsbInterfaceImp getActiveSettingImp()
                                    throws UsbNotActiveException
Get the active alternate setting.

Returns:
the active setting UsbInterface object for this interface
Throws:
UsbNotActiveException - if the interface (not setting) is inactive.

getSetting

public UsbInterface getSetting(byte number)
Get the alternate setting with the specified number.

Specified by:
getSetting in interface UsbInterface
Returns:
the alternate setting with the specified number.

getSettingImp

public UsbInterfaceImp getSettingImp(byte number)
Get the alternate setting with the specified number.

Returns:
the alternate setting with the specified number, or null.

containsSetting

public boolean containsSetting(byte number)
Description copied from interface: UsbInterface
If the specified alternate setting exists.

Specified by:
containsSetting in interface UsbInterface
Parameters:
number - the number of the alternate setting to check.
Returns:
if the alternate setting exists.

getSettings

public java.util.List getSettings()
Get all alternate settings for this interface.

Specified by:
getSettings in interface UsbInterface
Returns:
All of this interface's alternate settings (including this setting).

getUsbInterfaceDescriptor

public UsbInterfaceDescriptor getUsbInterfaceDescriptor()
Description copied from interface: UsbInterface
Get the interface descriptor.

The descriptor may be cached.

Specified by:
getUsbInterfaceDescriptor in interface UsbInterface
Returns:
the interface descriptor for this interface

getInterfaceString

public java.lang.String getInterfaceString()
                                    throws UsbException,
                                           java.io.UnsupportedEncodingException,
                                           UsbDisconnectedException
Description copied from interface: UsbInterface
Get the interface String.

This is a convienence method. The String may be cached. If the device does not support strings or does not define the interface string, this returns null.

Specified by:
getInterfaceString in interface UsbInterface
Returns:
the String description of this interface
Throws:
UsbException - If there was an error getting the UsbStringDescriptor.
java.io.UnsupportedEncodingException - If the string encoding is not supported.
UsbDisconnectedException - If this interface (device) has been disconnected.

getUsbInterfaceOsImp

public UsbInterfaceOsImp getUsbInterfaceOsImp()
Returns:
the associated UsbInterfaceOsImp

setUsbInterfaceOsImp

public void setUsbInterfaceOsImp(UsbInterfaceOsImp iface)
Parameters:
iface - The UsbInterfaceOsImp to use

setUsbInterfaceDescriptor

public void setUsbInterfaceDescriptor(UsbInterfaceDescriptor desc)
Parameters:
desc - the new interface descriptor

setActiveSettingNumber

public void setActiveSettingNumber(byte number)
                            throws java.lang.IllegalArgumentException
Set the active alternate setting number for ALL UsbInterfaces on the AlternateSettings list

Parameters:
number - The number of the active alternate setting
Throws:
java.lang.IllegalArgumentException - If the specified setting does not exist in this interface.

addUsbEndpointImp

public void addUsbEndpointImp(UsbEndpointImp ep)
Parameters:
ep - the endpoint to add