Symbian3/SDK/Source/GUID-275D7892-EEBD-5DBD-A9D7-F6A715B79659.dita
author Dominic Pinkman <dominic.pinkman@nokia.com>
Tue, 20 Jul 2010 12:00:49 +0100
changeset 13 48780e181b38
parent 0 89d6a7a84779
permissions -rw-r--r--
Week 28 contribution of SDK documentation content. See release notes for details. Fixes bugs Bug 1897 and Bug 1522.

<?xml version="1.0" encoding="utf-8"?>
<!-- Copyright (c) 2007-2010 Nokia Corporation and/or its subsidiary(-ies) All rights reserved. -->
<!-- This component and the accompanying materials are made available under the terms of the License 
"Eclipse Public License v1.0" which accompanies this distribution, 
and is available at the URL "http://www.eclipse.org/legal/epl-v10.html". -->
<!-- Initial Contributors:
    Nokia Corporation - initial contribution.
Contributors: 
-->
<!DOCTYPE concept
  PUBLIC "-//OASIS//DTD DITA Concept//EN" "concept.dtd">
<concept xml:lang="en" id="GUID-275D7892-EEBD-5DBD-A9D7-F6A715B79659"><title>Querying the SDP Database</title><prolog><metadata><keywords/></metadata></prolog><conbody><p>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 <xref href="GUID-5FE7D4DB-B853-57C4-8A90-16DF92F6231A.dita">Bluetooth Sockets</xref> API. </p> <section><title>How to query for a remote service</title> <p>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 "<xref scope="external" href="https://www.bluetooth.org/assigned-numbers/service_discovery.php">Service Discovery Protocol Assigned Numbers</xref> " for the common UUIDs. </p> <p>Service search results are returned through asynchronous callbacks to an <xref href="GUID-AD76DB7F-CD45-3903-A07A-E94BE583CDB0.dita"><apiname>MSdpAgentNotifier</apiname></xref> interface, which the querier must implement, as discussed later. </p> <p><b>Basic Procedure</b> </p> <p>The steps to perform a service search are as follows: </p> <ol id="GUID-26256320-1DDC-56FC-A8F7-D31A31935EAB"><li id="GUID-39DE1A9A-DA85-53A4-B377-8C49DB4F9461"><p>Create a <xref href="GUID-6A33D6A1-63C8-3A15-A2BC-5D08F07C5AB6.dita"><apiname>CSdpAgent</apiname></xref> object, supplying it with an <xref href="GUID-AD76DB7F-CD45-3903-A07A-E94BE583CDB0.dita"><apiname>MSdpAgentNotifier</apiname></xref> and the device address of the remote Bluetooth device. </p> </li> <li id="GUID-68A80DA4-46AC-5401-9D81-C111BE3F401C"><p>Create a <xref href="GUID-745D8374-1012-356B-A15E-6CBC96E64E95.dita"><apiname>CSdpSearchPattern</apiname></xref> object to specify the service classes to search for. Classes can be added through <xref href="GUID-745D8374-1012-356B-A15E-6CBC96E64E95.dita#GUID-745D8374-1012-356B-A15E-6CBC96E64E95/GUID-9258B4ED-D93C-32F7-BF9B-62D82311CBDE"><apiname>CSdpSearchPattern::AddL()</apiname></xref>. </p> </li> <li id="GUID-934248A1-5D75-56CC-876B-13154C220A95"><p>Set the search pattern on the agent object using <xref href="GUID-6A33D6A1-63C8-3A15-A2BC-5D08F07C5AB6.dita#GUID-6A33D6A1-63C8-3A15-A2BC-5D08F07C5AB6/GUID-971093EE-8913-3E1D-9D2A-3E462E8538FC"><apiname>CSdpAgent::SetRecordFilterL()</apiname></xref>. </p> </li> <li id="GUID-CAB33ADA-BB1C-51E5-B7D1-1FBE37161934"><p>Call <xref href="GUID-6A33D6A1-63C8-3A15-A2BC-5D08F07C5AB6.dita#GUID-6A33D6A1-63C8-3A15-A2BC-5D08F07C5AB6/GUID-1BC85E8A-3F98-37BF-B775-63AC51ABF5D7"><apiname>CSdpAgent::NextRecordRequestL()</apiname></xref> to get search results until results are exhausted, or sufficient results have been obtained. </p> </li> </ol> <p><b>Querying for a service</b> </p> <p>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: </p> <ol id="GUID-24853096-35F5-57A6-879F-3270717B7A4F"><li id="GUID-57D61594-1495-5CB1-98D5-4D5066DB200F"><p>Create agent. (Assume rcvr implements <xref href="GUID-AD76DB7F-CD45-3903-A07A-E94BE583CDB0.dita"><apiname>MSdpAgentNotifier</apiname></xref> and <codeph>devAddr</codeph> is the address of the remote device.) </p> <codeblock id="GUID-A4727E40-3316-548C-B982-031F5E47B641" xml:space="preserve">CSdpAgent* agent = CSdpAgent::NewLC(rcvr, devAddr);</codeblock> </li> <li id="GUID-2B4552ED-8D5C-5ED4-9CF2-BAE23CCFCD11"><p>Create a search pattern and add a service classes to it. </p> <codeblock id="GUID-10D1B740-8EFE-5C62-9539-25E934F6485E" xml:space="preserve">CSdpSearchPattern* list = CSdpSearchPattern::NewL();
list-&gt;AddL(0x1106);</codeblock> <p>The UUID 0x1106 represents the OBEXFileTransfer service class. </p> </li> <li id="GUID-9AA7ABA8-5EB5-5F04-8A1B-DE38771D9745"><p>Set the search pattern on the agent. </p> <codeblock id="GUID-1F0A13CD-6CCE-5570-895C-81322BA008E0" xml:space="preserve">agent-&gt;SetRecordFilterL(*list);</codeblock> </li> <li id="GUID-CF07DE05-DECA-56F2-9350-BDD55818148B"><p>Get first search result: results in call back to <codeph>rcvr</codeph>. </p> <codeblock id="GUID-1A46411E-9782-5C76-9920-3DF60A6699A7" xml:space="preserve">agent-&gt;NextRecordRequestL();</codeblock> </li> </ol> <p>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. </p> </section> <section><title>Where next?</title> <p>The complete set of Service Discovery Agent tutorials are shown below: </p> <ul><li id="GUID-DFC9F42A-AB8F-56A1-ADBF-8BDCCC90D9E8"><p> <b>Querying the SDP database</b> - This document </p> </li> <li id="GUID-6E8CA7F2-1B54-5D2E-8B48-054913523995"><p> <xref href="GUID-1EA7B3A5-7A94-5E8F-A0A8-9CA417E14032.dita">Reading remote SDP service attributes</xref>  </p> </li> <li id="GUID-629F4F05-E622-5423-91C7-6D7A5A98FBF3"><p> <xref href="GUID-65F8675F-FF08-5707-BA5B-BF3B4B779393.dita">Handling SDP query results</xref>  </p> </li> </ul> <p>Also refer to the <xref href="GUID-2F1C6B4C-2C23-5A35-A0D2-223EC6238F7D.dita">Bluetooth Service Discovery Agent Overview</xref> and the <xref href="GUID-8451102A-8E68-5C86-9E40-D53183E32261.dita">Bluetooth SDP Overview</xref> for additional background information. </p> </section> </conbody></concept>