com.ibm.jusb
Class UsbPipeImp

java.lang.Object
  extended by com.ibm.jusb.UsbPipeImp
All Implemented Interfaces:
UsbIrpImp.UsbIrpImpListener, EventListener, UsbPipe
Direct Known Subclasses:
UsbControlPipeImp

public class UsbPipeImp
extends Object
implements UsbPipe, UsbIrpImp.UsbIrpImpListener

UsbPipe platform-independent implementation.

This must be set up before use.

Author:
Dan Streetman

Field Summary
protected  boolean abortInProgress
           
static String CREATE_SHORT_PACKET_EXCEPTION_POLICY_KEY
           
protected  boolean createShortPacketException
           
protected  UsbPipeListenerImp listenerImp
           
protected  Hashtable listTable
           
static String PIPE_BULK_QUEUE_POLICY_KEY
           
static String PIPE_CONTROL_QUEUE_POLICY_KEY
           
static String PIPE_INTERRUPT_QUEUE_POLICY_KEY
           
static String PIPE_ISOCHRONOUS_QUEUE_POLICY_KEY
           
protected  RunnableManager queueManager
           
protected  boolean queueSubmissions
           
protected  List submissionList
           
 
Constructor Summary
UsbPipeImp()
          Constructor.
UsbPipeImp(UsbEndpointImp ep)
          Constructor.
UsbPipeImp(UsbEndpointImp ep, UsbPipeOsImp pipe)
          Constructor.
UsbPipeImp(UsbPipeOsImp pipe)
          Constructor.
 
Method Summary
 void abortAllSubmissions()
          Stop all submissions in progress.
protected  void addRunnable(Runnable r)
          Add a Runnable to the queueManager.
 void addUsbPipeListener(UsbPipeListener listener)
          Register's the listener object for UsbPipeEvent
 UsbIrp asyncSubmit(byte[] data)
          Asynchonously submits this byte[] array to the UsbPipe.
 void asyncSubmit(List list)
          Asynchronous submission using a List of UsbIrps.
 void asyncSubmit(UsbIrp usbIrp)
          Asynchronous submission using a UsbIrp.
protected  void checkActive()
          Check if this pipe is active.
protected  void checkDisconnected()
          Check if this device is disconnected.
protected  void checkOpen()
          Check if this pipe is open.
 void close()
          Closes this UsbPipe.
 UsbControlIrp createUsbControlIrp(byte bmRequestType, byte bRequest, short wValue, short wIndex)
          Create a UsbControlIrp.
 UsbIrp createUsbIrp()
          Create a UsbIrp.
protected  UsbIrpImp createUsbIrpImp()
          Get a uniquely-numbered UsbIrpImp
protected  void fireEvent(UsbIrpImp usbIrpImp)
          Fire an event for the specified UsbIrpImp.
 UsbEndpoint getUsbEndpoint()
          Get this pipe's UsbEndpoint.
 UsbEndpointImp getUsbEndpointImp()
           
 UsbPipeOsImp getUsbPipeOsImp()
           
 boolean isActive()
          If this pipe is active.
protected  boolean isDisconnected()
           
protected  boolean isInDirection(UsbIrpImp irp)
          Return if this is an in-direction pipe (or UsbIrp in the case of control pipes).
 boolean isOpen()
          If this pipe is open.
 void open()
          Opens this UsbPipe.
protected  void queueList(List list)
          Queue a List of UsbIrpImps.
protected  void queueUsbIrpImp(UsbIrpImp usbIrpImp)
          Queue a UsbIrpImp
 void removeUsbPipeListener(UsbPipeListener listener)
          Removes the listener object from the listener list
protected  void setPolicies()
          Set the policies, if defined
 void setupUsbIrpImp(UsbIrpImp irp)
           
 void setUsbEndpointImp(UsbEndpointImp ep)
          Set the UsbEndpointImp.
 void setUsbPipeOsImp(UsbPipeOsImp pipe)
           
protected  void submitUsbIrpImpFromQueue(UsbIrpImp usbIrpImp)
          Submit a UsbIrpImp from the queueManager.
 int syncSubmit(byte[] data)
          Synchonously submits this byte[] array to the UsbPipe.
 void syncSubmit(List list)
          Synchronous submission using a List of UsbIrps.
 void syncSubmit(UsbIrp usbIrp)
          Synchronous submission using a UsbIrp.
 void usbIrpImpComplete(UsbIrpImp irp)
          Indicate that a specific UsbIrpImp has completed.
protected  List usbIrpListToUsbIrpImpList(List list)
           
protected  UsbIrpImp usbIrpToUsbIrpImp(UsbIrp irp)
          Convert a UsbIrp to UsbIrpImp.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

listenerImp

protected UsbPipeListenerImp listenerImp

queueManager

protected RunnableManager queueManager

queueSubmissions

protected boolean queueSubmissions

abortInProgress

protected boolean abortInProgress

createShortPacketException

protected boolean createShortPacketException

listTable

protected Hashtable listTable

submissionList

protected List submissionList

PIPE_CONTROL_QUEUE_POLICY_KEY

public static final String PIPE_CONTROL_QUEUE_POLICY_KEY
See Also:
Constant Field Values

PIPE_INTERRUPT_QUEUE_POLICY_KEY

public static final String PIPE_INTERRUPT_QUEUE_POLICY_KEY
See Also:
Constant Field Values

PIPE_ISOCHRONOUS_QUEUE_POLICY_KEY

public static final String PIPE_ISOCHRONOUS_QUEUE_POLICY_KEY
See Also:
Constant Field Values

PIPE_BULK_QUEUE_POLICY_KEY

public static final String PIPE_BULK_QUEUE_POLICY_KEY
See Also:
Constant Field Values

CREATE_SHORT_PACKET_EXCEPTION_POLICY_KEY

public static final String CREATE_SHORT_PACKET_EXCEPTION_POLICY_KEY
See Also:
Constant Field Values
Constructor Detail

UsbPipeImp

public UsbPipeImp()
Constructor.


UsbPipeImp

public UsbPipeImp(UsbEndpointImp ep)
Constructor.

Parameters:
ep - The UsbEndpointImp.

UsbPipeImp

public UsbPipeImp(UsbPipeOsImp pipe)
Constructor.

Parameters:
pipe - The platform-dependent pipe implementation.

UsbPipeImp

public UsbPipeImp(UsbEndpointImp ep,
                  UsbPipeOsImp pipe)
Constructor.

Parameters:
ep - The UsbEndpointImp.
pipe - The platform-dependent pipe implementation.
Method Detail

getUsbPipeOsImp

public UsbPipeOsImp getUsbPipeOsImp()
Returns:
the UsbPipeOsImp object

setUsbPipeOsImp

public void setUsbPipeOsImp(UsbPipeOsImp pipe)
Parameters:
pipe - The UsbPipeOsImp to use

isActive

public boolean isActive()
Description copied from interface: UsbPipe
If this pipe is active.

This pipe is active only if it belongs to an active configuration and interface setting, otherwise it is inactive. This UsbPipe cannot be used if inactive.

Specified by:
isActive in interface UsbPipe
Returns:
if this UsbPipe is active

isOpen

public boolean isOpen()
Description copied from interface: UsbPipe
If this pipe is open.

This is true after a sucessful open until a successful close.

If this pipe is not active, this returns false.

Specified by:
isOpen in interface UsbPipe
Returns:
if this UsbPipe is open

getUsbEndpoint

public UsbEndpoint getUsbEndpoint()
Description copied from interface: UsbPipe
Get this pipe's UsbEndpoint.

Specified by:
getUsbEndpoint in interface UsbPipe
Returns:
the UsbEndpoint associated with this UsbPipe

getUsbEndpointImp

public UsbEndpointImp getUsbEndpointImp()
Returns:
the UsbEndpointImp associated with this UsbPipeImp

setUsbEndpointImp

public void setUsbEndpointImp(UsbEndpointImp ep)
Set the UsbEndpointImp.

This will also set this on the parent UsbEndpointImp. This also sets up this pipe's queueing policy if the user defined one in the properties file.

Parameters:
ep - The UsbEndpointImp

open

public void open()
          throws UsbException,
                 UsbNotActiveException,
                 UsbNotClaimedException,
                 UsbDisconnectedException
Opens this UsbPipe.

Specified by:
open in interface UsbPipe
Throws:
UsbException - If the UsbPipe could not be opened.
UsbNotActiveException - If the config or interface setting is not active.
UsbNotClaimedException - If the interface is not claimed.
UsbDisconnectedException - If this pipe (device) has been disconnected.

close

public void close()
           throws UsbException,
                  UsbNotActiveException,
                  UsbNotOpenException,
                  UsbDisconnectedException
Closes this UsbPipe.

Specified by:
close in interface UsbPipe
Throws:
UsbException - If the UsbPipe could not be closed.
UsbNotActiveException - If the UsbPipe is not active.
UsbNotOpenException - If the UsbPipe is not open.
UsbDisconnectedException - If this pipe (device) has been disconnected.

syncSubmit

public int syncSubmit(byte[] data)
               throws UsbException,
                      IllegalArgumentException,
                      UsbNotActiveException,
                      UsbNotOpenException,
                      UsbDisconnectedException
Synchonously submits this byte[] array to the UsbPipe.

Specified by:
syncSubmit in interface UsbPipe
Parameters:
data - The buffer to use.
Returns:
The number of bytes actually transferred.
Throws:
UsbException - If an error occurs.
IllegalArgumentException - If the data is null.
UsbNotActiveException - If the pipe is not active.
UsbNotOpenException - If the pipe is not open.
UsbDisconnectedException - If this pipe (device) has been disconnected.

asyncSubmit

public UsbIrp asyncSubmit(byte[] data)
                   throws UsbException,
                          IllegalArgumentException,
                          UsbNotActiveException,
                          UsbNotOpenException,
                          UsbDisconnectedException
Asynchonously submits this byte[] array to the UsbPipe.

Specified by:
asyncSubmit in interface UsbPipe
Parameters:
data - The buffer to use.
Returns:
A UsbIrp representing the submission.
Throws:
UsbException - If an error occurs.
IllegalArgumentException - If the data is null.
UsbNotActiveException - If the pipe is not active.
UsbNotOpenException - If the pipe is not open.
UsbDisconnectedException - If this pipe (device) has been disconnected.

syncSubmit

public void syncSubmit(UsbIrp usbIrp)
                throws UsbException,
                       IllegalArgumentException,
                       UsbNotActiveException,
                       UsbNotOpenException,
                       UsbDisconnectedException
Synchronous submission using a UsbIrp.

Specified by:
syncSubmit in interface UsbPipe
Parameters:
usbIrp - A UsbIrp to use for the submission.
Throws:
UsbException - If an error occurs.
IllegalArgumentException - If the UsbIrp is not valid.
UsbNotActiveException - If the pipe is not active.
UsbNotOpenException - If the pipe is not open.
UsbDisconnectedException - If this pipe (device) has been disconnected.

asyncSubmit

public void asyncSubmit(UsbIrp usbIrp)
                 throws UsbException,
                        IllegalArgumentException,
                        UsbNotActiveException,
                        UsbNotOpenException,
                        UsbDisconnectedException
Asynchronous submission using a UsbIrp.

Specified by:
asyncSubmit in interface UsbPipe
Parameters:
usbIrp - The UsbIrp to use for the submission.
Throws:
UsbException - If an error occurs.
IllegalArgumentException - If the UsbIrp is not valid.
UsbNotActiveException - If the pipe is not active.
UsbNotOpenException - If the pipe is not open.
UsbDisconnectedException - If this pipe (device) has been disconnected.

syncSubmit

public void syncSubmit(List list)
                throws UsbException,
                       IllegalArgumentException,
                       UsbNotActiveException,
                       UsbNotOpenException,
                       UsbDisconnectedException
Synchronous submission using a List of UsbIrps.

Specified by:
syncSubmit in interface UsbPipe
Parameters:
list - The List of UsbIrps.
Throws:
UsbException - If an error occurs.
IllegalArgumentException - If the list is empty or contains any non-UsbIrp objects, or those UsbIrp(s) are invalid.
UsbNotActiveException - If the pipe is not active.
UsbNotOpenException - If the pipe is not open.
UsbDisconnectedException - If this pipe (device) has been disconnected.

asyncSubmit

public void asyncSubmit(List list)
                 throws UsbException,
                        IllegalArgumentException,
                        UsbNotActiveException,
                        UsbNotOpenException,
                        UsbDisconnectedException
Asynchronous submission using a List of UsbIrps.

Specified by:
asyncSubmit in interface UsbPipe
Parameters:
list - The List of UsbIrps.
Throws:
UsbException - If an error occurs.
IllegalArgumentException - If the list is empty or contains any non-UsbIrp objects, or those UsbIrp(s) are invalid.
UsbNotActiveException - If the pipe is not active.
UsbNotOpenException - If the pipe is not open.
UsbDisconnectedException - If this pipe (device) has been disconnected.

abortAllSubmissions

public void abortAllSubmissions()
                         throws UsbNotActiveException,
                                UsbNotOpenException,
                                UsbDisconnectedException
Stop all submissions in progress.

Specified by:
abortAllSubmissions in interface UsbPipe
Throws:
UsbNotActiveException - If the pipe is not active.
UsbNotOpenException - If the pipe is not open.
UsbDisconnectedException - If this pipe (device) has been disconnected.

createUsbIrp

public UsbIrp createUsbIrp()
Create a UsbIrp.

Specified by:
createUsbIrp in interface UsbPipe
Returns:
A UsbIrp ready for use.

createUsbControlIrp

public UsbControlIrp createUsbControlIrp(byte bmRequestType,
                                         byte bRequest,
                                         short wValue,
                                         short wIndex)
Create a UsbControlIrp.

Specified by:
createUsbControlIrp in interface UsbPipe
Parameters:
bmRequestType - The bmRequestType.
bRequest - The bRequest.
wValue - The wValue.
wIndex - The wIndex.
Returns:
A UsbControlIrp ready for use.

usbIrpImpComplete

public void usbIrpImpComplete(UsbIrpImp irp)
Indicate that a specific UsbIrpImp has completed.

This is called after isComplete() is set to true.

Specified by:
usbIrpImpComplete in interface UsbIrpImp.UsbIrpImpListener
Parameters:
irp - The UsbIrpImp that completed.

addUsbPipeListener

public void addUsbPipeListener(UsbPipeListener listener)
Register's the listener object for UsbPipeEvent

Specified by:
addUsbPipeListener in interface UsbPipe
Parameters:
listener - the UsbPipeListener instance

removeUsbPipeListener

public void removeUsbPipeListener(UsbPipeListener listener)
Removes the listener object from the listener list

Specified by:
removeUsbPipeListener in interface UsbPipe
Parameters:
listener - the UsbPipeListener instance

setupUsbIrpImp

public void setupUsbIrpImp(UsbIrpImp irp)

fireEvent

protected void fireEvent(UsbIrpImp usbIrpImp)
Fire an event for the specified UsbIrpImp.

Note that any submission of a byte[] will not have a wrapped UsbIrp, but to ease implementation, the UsbIrpImp generated by this implementation to manage the byte[] will be included in the event. This means this implementation will never use the non-UsbIrp constructors from the UsbPipeEvent classes.

Parameters:
usbIrpImp - The UsbIrpImp to fire an event for.

usbIrpToUsbIrpImp

protected UsbIrpImp usbIrpToUsbIrpImp(UsbIrp irp)
                               throws UsbException,
                                      IllegalArgumentException
Convert a UsbIrp to UsbIrpImp.

Parameters:
irp - The UsbIrp to convert.
Throws:
UsbException - If the UsbIrp is not ready for submission.
IllegalArgumentException - If the UsbIrp is not valid.

usbIrpListToUsbIrpImpList

protected List usbIrpListToUsbIrpImpList(List list)
                                  throws UsbException,
                                         IllegalArgumentException
Throws:
UsbException
IllegalArgumentException

checkDisconnected

protected void checkDisconnected()
                          throws UsbDisconnectedException
Check if this device is disconnected.

Throws:
UsbDisconnectedException - If this device is disconnected.

isDisconnected

protected boolean isDisconnected()
Returns:
If this device is disconnected.

checkActive

protected void checkActive()
                    throws UsbNotActiveException,
                           UsbDisconnectedException
Check if this pipe is active.

Throws:
UsbNotActiveException - If the pipe is not active.
UsbDisconnectedException - If this device is disconnected.

checkOpen

protected void checkOpen()
                  throws UsbNotActiveException,
                         UsbNotOpenException,
                         UsbDisconnectedException
Check if this pipe is open.

A pipe must be active to be open.

Throws:
UsbNotActiveException - If the pipe is not active.
UsbNotOpenException - If the pipe is not open.
UsbDisconnectedException - If this device is disconnected.

createUsbIrpImp

protected UsbIrpImp createUsbIrpImp()
Get a uniquely-numbered UsbIrpImp


addRunnable

protected void addRunnable(Runnable r)
Add a Runnable to the queueManager.

Parameters:
r - The Runnable to add.

submitUsbIrpImpFromQueue

protected void submitUsbIrpImpFromQueue(UsbIrpImp usbIrpImp)
Submit a UsbIrpImp from the queueManager.

Parameters:
usbIrpImp - The UsbIrpImp to submit.

queueUsbIrpImp

protected void queueUsbIrpImp(UsbIrpImp usbIrpImp)
Queue a UsbIrpImp

Parameters:
usbIrpImp - The UsbIrpImp to queue.

queueList

protected void queueList(List list)
Queue a List of UsbIrpImps.

Parameters:
list - The List of UsbIrpImps to queue.

setPolicies

protected void setPolicies()
Set the policies, if defined


isInDirection

protected boolean isInDirection(UsbIrpImp irp)
Return if this is an in-direction pipe (or UsbIrp in the case of control pipes).

Parameters:
irp - The UsbIrpImp.
Returns:
If this is an in-direction transfer.


Copyright © 2012 LSST. All Rights Reserved.