com.intel.bluetooth.btl2cap
Class Connection

java.lang.Object
  extended by com.intel.bluetooth.BluetoothConnectionAccessAdapter
      extended by com.intel.bluetooth.btl2cap.Connection
All Implemented Interfaces:
CreateConnection, BluetoothConnectionAccess, BluetoothConnectionNotifierServiceRecordAccess, L2CAPConnection, L2CAPConnectionNotifier, Connection
Direct Known Subclasses:
Connection

public class Connection
extends BluetoothConnectionAccessAdapter
implements CreateConnection, L2CAPConnection, L2CAPConnectionNotifier, BluetoothConnectionNotifierServiceRecordAccess

This class is Proxy for btl2cap (L2CAP) Connection implementations for IBM J9 support

You need to configure -Dmicroedition.connection.pkgs=com.intel.bluetooth if not installing bluecove.jar to "%J9_HOME%\lib\jclMidp20\ext\

Your application should not use this class directly.

Rating red

Field Summary
 
Fields inherited from interface javax.bluetooth.L2CAPConnection
DEFAULT_MTU, MINIMUM_MTU
 
Constructor Summary
Connection()
           
 
Method Summary
 L2CAPConnection acceptAndOpen()
          Waits for a client to connect to this L2CAP service.
 void close()
           
protected  BluetoothConnectionAccess getImpl()
           
 int getReceiveMTU()
          Returns the ReceiveMTU that the connection supports.
 ServiceRecord getServiceRecord()
           
 int getTransmitMTU()
          Returns the MTU that the remote device supports.
 boolean ready()
          Determines if there is a packet that can be read via a call to receive().
 int receive(byte[] inBuf)
          Reads a packet of data.
 void send(byte[] data)
          Requests that data be sent to the remote device.
 void setParameters(String spec, int access, boolean timeout)
          Passes the parameters from the Connector.open() method to this object.
 Connection setParameters2(String spec, int access, boolean timeout)
          Passes the parameters from the Connector.open() method to this object.
 void updateServiceRecord(boolean acceptAndOpen)
           
 
Methods inherited from class com.intel.bluetooth.BluetoothConnectionAccessAdapter
encrypt, getBluetoothStack, getRemoteAddress, getRemoteDevice, getSecurityOpt, isClosed, markAuthenticated, setRemoteDevice, shutdown
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

Connection

public Connection()
Method Detail

getImpl

protected BluetoothConnectionAccess getImpl()
Specified by:
getImpl in class BluetoothConnectionAccessAdapter

setParameters

public void setParameters(String spec,
                          int access,
                          boolean timeout)
                   throws IOException
Description copied from interface: CreateConnection
Passes the parameters from the Connector.open() method to this object. Protocol used by MIDP 1.0

Specified by:
setParameters in interface CreateConnection
Parameters:
spec - String The address passed to Connector.open()
access - int The type of access this Connection is granted (READ, WRITE, READ_WRITE)
timeout - boolean A boolean indicating wether or not the caller to Connector.open() wants timeout exceptions or not
Throws:
IOException - If an error occured opening and configuring serial port.
See Also:
Connector

setParameters2

public Connection setParameters2(String spec,
                                 int access,
                                 boolean timeout)
                          throws IOException
Description copied from interface: CreateConnection
Passes the parameters from the Connector.open() method to this object. Protocol used by MIDP 2.0

Specified by:
setParameters2 in interface CreateConnection
Parameters:
spec - String The address passed to Connector.open()
access - int The type of access this Connection is granted (READ, WRITE, READ_WRITE)
timeout - boolean A boolean indicating wether or not the caller to Connector.open() wants timeout exceptions or not
Throws:
IOException - If an error occured opening and configuring serial port.
See Also:
Connector

close

public void close()
           throws IOException
Specified by:
close in interface Connection
Throws:
IOException

getReceiveMTU

public int getReceiveMTU()
                  throws IOException
Description copied from interface: L2CAPConnection
Returns the ReceiveMTU that the connection supports. If the connection string did not specify a ReceiveMTU, the value returned will be less than or equal to the DEFAULT_MTU. Also, if the connection string did specify an MTU, this value will be less than or equal to the value specified in the connection string.

Specified by:
getReceiveMTU in interface L2CAPConnection
Returns:
the maximum number of bytes that can be read in a single call to receive()
Throws:
IOException - if the connection is closed

getTransmitMTU

public int getTransmitMTU()
                   throws IOException
Description copied from interface: L2CAPConnection
Returns the MTU that the remote device supports. This value is obtained after the connection has been configured. If the application had specified TransmitMTU in the Connector.open() string then this value should be equal to that. If the application did not specify any TransmitMTU, then this value should be less than or equal to the ReceiveMTU the remote device advertised during channel configuration.

Specified by:
getTransmitMTU in interface L2CAPConnection
Returns:
the maximum number of bytes that can be sent in a single call to send() without losing any data
Throws:
IOException - if the connection is closed

ready

public boolean ready()
              throws IOException
Description copied from interface: L2CAPConnection
Determines if there is a packet that can be read via a call to receive(). If true, a call to receive() will not block the application.

Specified by:
ready in interface L2CAPConnection
Returns:
true if there is data to read; false if there is no data to read
Throws:
IOException - if the connection is closed
See Also:
L2CAPConnection.receive(byte[])

receive

public int receive(byte[] inBuf)
            throws IOException
Description copied from interface: L2CAPConnection
Reads a packet of data. The amount of data received in this operation is related to the value of ReceiveMTU. If the size of inBuf is greater than or equal to ReceiveMTU, then no data will be lost. Unlike read() on an java.io.InputStream, if the size of inBuf is smaller than ReceiveMTU, then the portion of the L2CAP payload that will fit into inBuf will be placed in inBuf, the rest will be discarded. If the application is aware of the number of bytes (less than ReceiveMTU) it will receive in any transaction, then the size of inBuf can be less than ReceiveMTU and no data will be lost. If inBuf is of length 0, all data sent in one packet is lost unless the length of the packet is 0.

Specified by:
receive in interface L2CAPConnection
Parameters:
inBuf - byte array to store the received data
Returns:
the actual number of bytes read; 0 if a zero length packet is received; 0 if inBuf length is zero
Throws:
IOException - if an I/O error occurs or the connection has been closed

send

public void send(byte[] data)
          throws IOException
Description copied from interface: L2CAPConnection
Requests that data be sent to the remote device. The TransmitMTU determines the amount of data that can be successfully sent in a single send operation. If the size of data is greater than the TransmitMTU, then only the first TransmitMTU bytes of the packet are sent, and the rest will be discarded. If data is of length 0, an empty L2CAP packet will be sent.

Specified by:
send in interface L2CAPConnection
Parameters:
data - data to be sent
Throws:
IOException - if data cannot be sent successfully or if the connection is closed

acceptAndOpen

public L2CAPConnection acceptAndOpen()
                              throws IOException
Description copied from interface: L2CAPConnectionNotifier
Waits for a client to connect to this L2CAP service. Upon connection returns an L2CAPConnection that can be used to communicate with this client.

A service record associated with this connection will be added to the SDDB associated with this L2CAPConnectionNotifier object if one does not exist in the SDDB. This method will put the local device in connectable mode so that it may respond to connection attempts by clients.

The following checks are done to verify that any modifications made by the application to the service record after it was created by Connector.open() have not created an invalid service record. If any of these checks fail, then a ServiceRegistrationException is thrown.

This method will not ensure that the service record created is a completely valid service record. It is the responsibility of the application to ensure that the service record follows all of the applicable syntactic and semantic rules for service record correctness.

Note : once an application invokes close() on any L2CAPConnectionNotifier, SessionNotifier, or StreamConnectionNotifer instance, all pending acceptAndOpen() methods that have been invoked previously on that instance MUST throw InterruptedIOException. This mechanism provides an application with the means to cancel any outstanding acceptAndOpen() method calls.

Specified by:
acceptAndOpen in interface L2CAPConnectionNotifier
Returns:
a connection to communicate with the client
Throws:
IOException - if the notifier is closed before acceptAndOpen() is called
ServiceRegistrationException - if the structure of the associated service record is invalid or if the service record could not be added successfully to the local SDDB. The structure of service record is invalid if the service record is missing any mandatory service attributes, or has changed any of the values described above which are fixed and cannot be changed. Failures to add the record to the SDDB could be due to insufficient disk space, database locks, etc.
BluetoothStateException - if the server device could not be placed in connectable mode because the device user has configured the device to be non-connectable.

getServiceRecord

public ServiceRecord getServiceRecord()
Specified by:
getServiceRecord in interface BluetoothConnectionNotifierServiceRecordAccess

updateServiceRecord

public void updateServiceRecord(boolean acceptAndOpen)
                         throws ServiceRegistrationException
Specified by:
updateServiceRecord in interface BluetoothConnectionNotifierServiceRecordAccess
Parameters:
acceptAndOpen - wrap validation in ServiceRegistrationException
Throws:
ServiceRegistrationException