|
|||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object | +--usb.jphoto.NameFactory | +--usb.jphoto.BaselineInitiator
This initiates interactions with USB devices, supporting only mandatory PTP-over-USB operations; both "push" and "pull" modes are supported. Note that there are some operations that are mandatory for "push" responders and not "pull" ones, and vice versa. A subclass adds additional standardized operations, which some PTP devices won't support. All low level interactions with the device are done by this class, including especially error recovery.
The basic sequence of operations for any PTP or ISO 15470
initiator (client) is: acquire the device; wrap it with this
driver class (or a subclass); issue operations;
close device. PTP has the notion
of a (single) session with the device, and until you have an open
session you may only invoke getDeviceInfo()
and
openSession()
operations. Moreover, devices may be used
both for reading images (as from a camera) and writing them
(as to a digital picture frame), depending on mode support.
Note that many of the IOExceptions thrown here are actually
going to be usb.core.USBException
values. That may
help your application level recovery processing. You should
assume that when any IOException is thrown, your current session
has been terminated.
Initiator
Constructor Summary | |
BaselineInitiator(usb.core.Device dev)
Constructs a class driver object, if the device supports operations according to Annex D of the PTP specification. |
|
BaselineInitiator(usb.core.Interface intf_arg)
Constructs a class driver from an interface asserted to conform fully to Annex D of the PTP specification. |
Method Summary | |
void |
close()
Releases USB resources so that some other program can access the interface this class previously interacted with. |
void |
closeSession()
Issues a CloseSession command to the device; may be used with all responders. |
void |
fillObject(int handle,
Data data)
Fills the data object using the object identified by a given handle. |
protected void |
finalize()
Tries to clean up if you forget to call close. |
DeviceInfo |
getDeviceInfo()
Returns the last cached copy of the device info, or returns a newly cached copy. |
DeviceInfo |
getDeviceInfoUncached()
Issues a GetDeviceInfo command to the device; may be used with all responders. |
int |
getNumObjects(int storageID,
int typeFilter,
int association)
Returns the number of objects in the specified association on the specified store. |
Data |
getObject(int handle)
Returns the data for the object identified by a given handle. |
int[] |
getObjectHandles(int store,
int code,
int association)
Returns an array of object handles in the store (or stores) specified. |
ObjectInfo |
getObjectInfo(int handle)
Returns information about the object identified by a given handle. |
java.lang.String |
getPortIdentifier()
Returns a port identifier string for this device; use these to address devices, they correspond to the hub port to which a device is attached. |
static usb.core.Interface |
getPtpInterface(usb.core.Device dev)
This function returns a PTP interface for a device, or null if the device has none. |
int |
getSessionId()
Returns the ID of the PTP sesssion in use; initiator only keep one open session at a time, or zero if there's no session. |
int[] |
getStorageIDs()
Returns an array of storage ids for the device; may be used with all responders. |
StorageInfo |
getStorageInfo(int store)
Issues a GetStorageInfo command to the device; may be used with all responders. |
Data |
getThumb(int handle)
Returns the thumbnail for the image identified by a given handle. |
boolean |
isPull()
Returns true iff the associated responder supports "pull mode", reading objects from the device. |
boolean |
isPush()
Returns true iff the associated responder supports "push mode", sending objects to the device. |
void |
openSession()
Issues an OpenSession command to the device; may be used with all responders. |
void |
reset()
Sends a USB level CLASS_DEVICE_RESET control message. |
void |
run()
Makes the invoking Thread read and report events reported by the PTP responder, until the Initiator is closed. |
void |
sendObject(Data obj)
Sends the object identified in a successful preceding sendObjectInfo call. |
Response |
sendObjectInfo(ObjectInfo info,
int storage,
int parent)
Sends object metadata, in preparation for sending the object described by this data. |
protected Response |
transact(Command command,
Data data)
Performs a PTP transaction. |
protected Response |
transact0(int code,
Data data)
Performs a PTP transaction, passing zero command parameters. |
protected Response |
transact1(int code,
Data data,
int p1)
Performs a PTP transaction, passing one command parameter. |
protected Response |
transact2(int code,
Data data,
int p1,
int p2)
Performs a PTP transaction, passing two command parameters. |
protected Response |
transact3(int code,
Data data,
int p1,
int p2,
int p3)
Performs a PTP transaction, passing three command parameters. |
Methods inherited from class usb.jphoto.NameFactory |
getEventString, getFormatString, getOpcodeString, getPropertyName, getResponseString |
Methods inherited from class java.lang.Object |
clone, equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Constructor Detail |
public BaselineInitiator(usb.core.Device dev) throws java.io.IOException
dev
- the first PTP interface will be usedjava.lang.IllegalArgumentException
- if the device has no
Digital Still Imaging Class or PTP interfacespublic BaselineInitiator(usb.core.Interface intf_arg) throws java.io.IOException
intf_arg
- the PTP interface to be usedjava.lang.IllegalArgumentException
- if the interface is
null or doesn't provide the necessary endpoints.Method Detail |
public static usb.core.Interface getPtpInterface(usb.core.Device dev)
public void close() throws java.io.IOException
protected void finalize()
finalize
in class java.lang.Object
public java.lang.String getPortIdentifier()
public boolean isPull()
public boolean isPush()
public DeviceInfo getDeviceInfo() throws java.io.IOException
getDeviceInfoUncached()
public int getSessionId()
public void reset() throws java.io.IOException
TO BE DETERMINED: How does this differ from a bulk
protocol ResetDevice
command? That
command is documented as very similar to this class operation.
Ideally, only this control request will ever be used, since it
works even when the bulk channels are halted.
public void run()
run
in interface java.lang.Runnable
public DeviceInfo getDeviceInfoUncached() throws java.io.IOException
public void openSession() throws java.io.IOException
public void closeSession() throws java.io.IOException
public int[] getStorageIDs() throws java.io.IOException
public StorageInfo getStorageInfo(int store) throws java.io.IOException
store
- either ~0 to indicate all media, or the
ID for some particular store.public int getNumObjects(int storageID, int typeFilter, int association) throws java.io.IOException
storageID
- either ~0 to indicate all media, or the
ID for some particular store.typeFilter
- either ~0 to indicate all image objects, zero
to indicate all objects, or some specific object format code.
Not all responders support such filtering.association
- zero, or the object handle for some associationpublic int[] getObjectHandles(int store, int code, int association) throws java.io.IOException
store
- identifies the storage ID; or ~0 to identify
all accessible storage.code
- either zero, or ~0 to request only images be
returned, or else some format code to be used to filter
the handles before they are returned.association
- either zero, or ~0 to specify the root
of a store; or else an association handle.public ObjectInfo getObjectInfo(int handle) throws java.io.IOException
handle
- object handle from the current sessionpublic Data getObject(int handle) throws java.io.IOException
handle
- object handle from the current sessionfillObject(int, usb.jphoto.Data)
public void fillObject(int handle, Data data) throws java.io.IOException
This differs from getObject in that the data object is supplied by the caller. Such objects may specialized behaviors, including in particular reducing in-memory buffering for large objects.
handle
- object handle from the current sessionpublic Data getThumb(int handle) throws java.io.IOException
handle
- object handle from the current sessionpublic Response sendObjectInfo(ObjectInfo info, int storage, int parent) throws java.io.IOException
info
- information about the object; fields in this
dataset are interpreted with respect to the initiator
(for example, initiator's storage id)storage
- desired responder storage id for the object;
or zero indicating the responder should choose oneparent
- responder object handle for object's parent;
~0 indicating the root of that object store;
or zero indicating the responder should choose.sendObject(usb.jphoto.Data)
public void sendObject(Data obj) throws java.io.IOException
sendObjectInfo(usb.jphoto.ObjectInfo, int, int)
protected Response transact0(int code, Data data) throws java.io.IOException
code
- the command codedata
- data to be sent or received; or nullprotected Response transact1(int code, Data data, int p1) throws java.io.IOException
code
- the command codedata
- data to be sent or received; or nullp1
- the first positional parameterprotected Response transact2(int code, Data data, int p1, int p2) throws java.io.IOException
code
- the command codedata
- data to be sent or received; or nullp1
- the first positional parameterp2
- the second positional parameterprotected Response transact3(int code, Data data, int p1, int p2, int p3) throws java.io.IOException
code
- the command codedata
- data to be sent or received; or nullp1
- the first positional parameterp2
- the second positional parameterp3
- the third positional parameterprotected Response transact(Command command, Data data) throws java.io.IOException
command
- the command blockdata
- data to be sent or received; or null
|
|||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |