Symbian
Symbian Developer Library

SYMBIAN OS V9.4

Feedback

[Index] [Previous] [Next]


Querying the SDP Database

The Service Discovery Agent is used to perform queries about the Bluetooth services that are available on a specified remote device. It is typically used after the suitable devices that are in range have been identified through the Bluetooth Sockets API.

[Top]


How to query for a remote service

A service search returns the record handles of services that are of a specified class or classes (identified by UUID numbers). If the search is for more than one UUID, then all the UUIDs must exist in a service record for it to be considered a match. See "Service Discovery Protocol Assigned Numbers" for the common UUIDs.

Service search results are returned through asynchronous callbacks to an MSdpAgentNotifier interface, which the querier must implement, as discussed later.


Basic Procedure

The steps to perform a service search are as follows:

  1. Create a CSdpAgent object, supplying it with an MSdpAgentNotifier and the device address of the remote Bluetooth device.

  2. Create a CSdpSearchPattern object to specify the service classes to search for. Classes can be added through CSdpSearchPattern::AddL().

  3. Set the search pattern on the agent object using CSdpAgent::SetRecordFilterL().

  4. Call CSdpAgent::NextRecordRequestL() to get search results until results are exhausted, or sufficient results have been obtained.


Querying for a service

The following code fragements may be used, in an appropriate context, to query a remote device's SDP database for Obex file transfer support (for example). The steps are given here:

  1. Create agent. (Assume rcvr implements MSdpAgentNotifier and devAddr is the address of the remote device.)

    CSdpAgent* agent = CSdpAgent::NewLC(rcvr, devAddr);
  2. Create a search pattern and add a service classes to it.

    CSdpSearchPattern* list = CSdpSearchPattern::NewL();
    list->AddL(0x1106);

    The UUID 0x1106 represents the OBEXFileTransfer service class.

  3. Set the search pattern on the agent.

    agent->SetRecordFilterL(*list);
  4. Get first search result: results in call back to rcvr.

    agent->NextRecordRequestL();

A positive match indicates a device has been found that supports OBEX file transfer. The above code may serve as a template to search for any service class for which you have the UUID value.

[Top]


Where next?

The complete set of Service Discovery Agent tutorials are shown below:

Also refer to the Bluetooth Service Discovery Agent Overview and the Bluetooth SDP Overview for additional background information.