FileDocCategorySizeDatePackage
SDPClient.javaAPI DocphoneME MR2 API (J2ME)34534Wed May 02 18:00:32 BST 2007com.sun.kvem.jsr082.bluetooth

SDPClient

public class SDPClient extends Object
SDPClient class provides a client side of SDP connection as described in Bluetooth Specification version 1.2.

Fields Summary
private static final int
MAX_SERVICE_RECORD_COUNT
Max retrievable service record handles. Maybe defined via property.
private static final int
MAX_ATTRIBUTE_BYTE_COUNT
Max total size of retrievable attributes. Maybe defined via property.
private static final int
firstTransactionID
The lowest possible value of transaction ID. The number must be positive.
private static final int
maxTransactionID
The maximum possible value of transaction ID.
private static int
effectiveTransactionID
Next transaction ID.
private static Hashtable
transportStorage
Maps Bluetooth addresses to transport connections.
private SDPTransport
transport
Transport connection for this client.
private String
address
Bluetooth address this client is connected to.
Constructors Summary
SDPClient(String bluetoothAddress)
Constructs an SDPClient object and opens SDP connection to the remote device with the specified Bluetooth address.

param
bluetoothAddress bluetooth address of SDP server


                                 
        
        address = bluetoothAddress;
        synchronized (transportStorage) {
            transport = (SDPTransport)transportStorage.get(address);
            if (transport == null) {
                transport = new SDPTransport(address);
                transportStorage.put(address, transport);
            }
        }
        transport.addRef();
    
Methods Summary
booleancancelServiceSearch(int transactionID)
Cancels transaction with given ID.

        return transport.cancelServiceSearch(transactionID);
    
voidclose()
Closes connection of this client to the specified server.

throws
IOException if no connection is open

        if (transport == null) {
            throw new IOException("Connection is already closed.");
        }
        transport.release();
        transport = null;
    
static synchronized voidfreeTransactionID(short transactionID)
Frees transaction ID.

param
transactionID the ID to free.

        // empty in this implementation
    
static synchronized shortnewTransactionID()
Retrieves next new transaction ID.

return
new transaction ID.

        int transactionID = effectiveTransactionID++;
        if (effectiveTransactionID > maxTransactionID) {
            // strictly speaking, this is not quite safe,
            // need revisit : if we have a pending
            // transaction after 64K of subsequent calls
            effectiveTransactionID = firstTransactionID;
        }
        return (short)transactionID;
    
voidserviceAttributeRequest(int serviceRecordHandle, int[] attrSet, int transactionID, SDPResponseListener listener)
Initiates ServiceAttribute transaction that retrieves specified attribute values from a specific service record.

        try {
            transport.serviceAttributeRequest(serviceRecordHandle, attrSet,
                transactionID, listener);
        } catch (IOException e) {
            transport.cancelAll(SDPResponseListener.IO_ERROR);
            throw e;
        }
    
voidserviceSearchAttributeRequest(int[] attrSet, javax.bluetooth.UUID[] uuidSet, int transactionID, SDPResponseListener listener)
Initiates ServiceSearchAttribute transaction that searches for services on a server by UUIDs specified and retrieves values of specified parameters for service records found.

        try {
            transport.serviceSearchAttributeRequest(attrSet, uuidSet,
                transactionID, listener);
        } catch (IOException e) {
            transport.cancelAll(SDPResponseListener.IO_ERROR);
            throw e;
        }
    
voidserviceSearchRequest(javax.bluetooth.UUID[] uuidSet, int transactionID, SDPResponseListener listener)
Initiates ServiceSearch transaction that is used to search for services that have all the UUIDs specified on a server.

        try {
            transport.serviceSearchRequest(uuidSet, transactionID, listener);
        } catch (IOException ioe) {
            transport.cancelAll(SDPResponseListener.IO_ERROR);
            throw ioe;
        }