Symbian Developer Library

SYMBIAN OS V6.1 EDITION FOR C++

[Index] [Glossary] [Previous] [Next]



How to query for a remote service

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.

A service search returns the record handles of services that are of a specified class or classes (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.

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

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.

Example

// 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(0x0100);

// 3. Set the search pattern on the agent
agent->SetRecordFilterL(*list);

// 4. Get first search result: results in call back to rcvr
agent->NextRecordRequestL();