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

ServiceSelector

public class ServiceSelector extends ServiceSearcherBase
This class provides functionality of DiscoveryAgent.selectService() (see JSR 82 texts for details) using SDP serviceAttribute request.

Fields Summary
private static final boolean
DEBUG
Set to false in RR version - then the javac skip the code.
private static final String
cn
this class name for debug.
private javax.bluetooth.DataElement[]
attrValues
Keeps attributes values retrieved from SDP_ServiceAttributeResponse.
private IOException
ioExcpt
Keeps an IOException if any occured or SDP_ErrorResponceRecieved.
Constructors Summary
ServiceSelector(int[] attrSet, javax.bluetooth.UUID[] uuidSet, javax.bluetooth.RemoteDevice btDev)
Creates ServiceDiscoverer and save all required info in it.


                  
          
        super(attrSet, uuidSet, btDev);
    
Methods Summary
public voiderrorResponse(int errorCode, java.lang.String info, int transactionID)
Recieves error information retrieved from SDP_ErrorResponse and copmpletes the request activity by error reason.

        if (DEBUG) {
            System.out.println(cn + ".errorResponse: called");
        }

        synchronized (this) {
            ioExcpt = new IOException(info);
            notify();
        }
    
javax.bluetooth.ServiceRecordgetServiceRecord()
Performs SERVICESEARCHATTRIBUTE transaction and returns newly created ServiceRecordImpl instance with attributes and values returned by server within SDP_serviceSearchAttributeResponse.

return
newly created ServiceRecordImpl instance with attributes and values returned by server if the transaction has completed successfully and attributes list retrieved is not empty, null otherwise.

        SDPClient sdp = null;
        short transactionID = SDPClient.newTransactionID();
        
        try {
            sdp = new SDPClient(btDev.getBluetoothAddress());

            if (sdp != null) {
                sdp.serviceSearchAttributeRequest(attrSet, uuidSet,
                        transactionID, this);
            }
        } catch (IOException ioe) {
            if (DEBUG) {
                ioe.printStackTrace();
            }
            ioExcpt = ioe;
        }

        synchronized (this) {
            if (ioExcpt == null && attrValues == null && sdp != null) {
                try {
                    wait();
                } catch (InterruptedException ie) {
                    // ignore (break waiting)
                }
            }
        }
        SDPClient.freeTransactionID(transactionID);

        try {
            if (sdp != null) {
                sdp.close();
            }
        } catch (IOException ioe) {
            if (DEBUG) {
                ioe.printStackTrace();
            }
            // ignore
        }

        if (ioExcpt != null) {
            return null;
        } else if (attrValues == null) {
            return null;
        } else if (attrValues.length == 0) {
            return null;
        } else {
            return new ServiceRecordImpl(btDev, attrSet, attrValues);
        }
    
public voidserviceAttributeResponse(int[] attrIDs, javax.bluetooth.DataElement[] attributeValues, int transactionID)
Base class method not relevant to this subclass, it must never be called.

        if (DEBUG) {
            System.out.println(cn +
                    ".serviceAttributeResponse: unexpected call");
        }
        throw new RuntimeException("unexpected call");
    
public voidserviceSearchAttributeResponse(int[] attrIDs, javax.bluetooth.DataElement[] attributeValues, int transactionID)
Receives arrays of service record attributes and their values retrieved from SDP_ServiceSearchAttributeResponse.

        if (DEBUG) {
            System.out.println(cn + ".serviceSearchAttributeResponse: called");
        }
        synchronized (this) {
            attrSet = attrIDs;
            attrValues = attributeValues;
            notify();
        }
    
public voidserviceSearchResponse(int[] handleList, int transactionID)
Base class method not relevant to this subclass, it must never be called.

        if (DEBUG) {
            System.out.println(cn + ".serviceSearchResponse: unexpected call");
        }
        throw new RuntimeException("unexpected call");