×
Namespaces

Variants
Actions
(Difference between revisions)

Advertising Bluetooth services using Symbian C++

From Nokia Developer Wiki
Jump to: navigation, search
ivey (Talk | contribs)
m (Fixed a broken link)
hamishwillee (Talk | contribs)
m (Hamishwillee - Adding missing translation link)
(9 intermediate revisions by 3 users not shown)
Line 1: Line 1:
__NOTOC__
+
[[Category:Symbian C++]][[Category:Code Snippet]][[Category:Bluetooth]][[Category:Code Snippet]][[Category:S60 3rd Edition FP1]]
__NOEDITSECTION__
+
{{Archived|timestamp=20120817133322|user=[[User:Lpvalente|Lpvalente]]}}
{{KBCS}}
+
 
{{CodeSnippet
+
 
|id=CS000938
+
{{ArticleMetaData <!-- v1.2 -->
|platform=S60 3rd Edition, MR
+
|sourcecode= <!-- Link to example source code (e.g. [[Media:The Code Example ZIP.zip]]) -->
|devices=Nokia N95
+
|installfile= <!-- Link to installation file (e.g. [[Media:The Installation File.sis]]) -->
|category=Symbian C++
+
|devices= Nokia N95
|subcategory=Bluetooth
+
|sdk= <!-- SDK(s) built and tested against (e.g. [http://linktosdkdownload/ Nokia Qt SDK 1.1]) -->
|creationdate=May 2, 2008
+
|platform= S60 3rd Edition, MR
|keywords=RSdp, RSdpDatabase, TSdpServRecordHandle, RSdpDatabase::CreateServiceRecordL(), RSdpDatabase::UpdateAttributeL()
+
|devicecompatability= <!-- Compatible devices (e.g.: All* (must have GPS) ) -->
 +
|dependencies= <!-- Any other/external dependencies e.g.: Google Maps Api v1.0 -->
 +
|signing= <!-- Empty or one of Self-Signed, DevCert, Manufacturer -->
 +
|capabilities= <!-- Capabilities required by the article/code example (e.g. Location, NetworkServices. -->
 +
|keywords= RSdp, RSdpDatabase, TSdpServRecordHandle, RSdpDatabase::CreateServiceRecordL(), RSdpDatabase::UpdateAttributeL()
 +
|language= <!-- Language category code for non-English topics - e.g. Lang-Chinese -->
 +
|translated-by= <!-- [[User:XXXX]] -->
 +
|translated-from-title= <!-- Title only -->
 +
|translated-from-id= <!-- Id of translated revision -->
 +
|review-by= <!-- After re-review: [[User:username]] -->
 +
|review-timestamp= <!-- After re-review: YYYYMMDD -->
 +
|update-by= <!-- After significant update: [[User:username]]-->
 +
|update-timestamp= <!-- After significant update: YYYYMMDD -->
 +
|creationdate= 20080425
 +
|author= [[User:Tepaa]]
 +
<!-- The following are not in current metadata -->
 +
|subcategory= Bluetooth
 +
|id= CS000938
 
}}
 
}}
  
 
==Overview==
 
==Overview==
<tt>RSdp</tt> provides a session to the Service Discovery Database. It is used to create subsessions to database functionality. A client must create and connect a session before using a RSdpDatabase subsession to access the database.
+
{{Icode|RSdp}} provides a session to the Service Discovery Database. It is used to create subsessions to database functionality. A client must create and connect a session before using a RSdpDatabase subsession to access the database.
  
<tt>RSdpDatabase</tt> is a subsession of the SDP through which service records and their attributes can be added, deleted, and updated.
+
{{Icode|RSdpDatabase}} is a subsession of the SDP through which service records and their attributes can be added, deleted, and updated.
  
The following example shows how to advertise a certain (KBT_serviceID 0x10ff) Bluetooth service. Discovering this particular service is explained in [[CS000937 - Discovering Bluetooth services]].
+
{{Abstract|The following example shows how to advertise a certain (KBT_serviceID 0x10ff) Bluetooth service. Discovering this particular service is explained in [[Archived:Discovering Bluetooth services using Symbian C++]].}}
  
Listening to the Bluetooth connection is explained in [[CS000939 - Establishing a Bluetooth connection]]. The channel number parameter in <tt>CMyServiceAdvertiser::StartAdvertiserL(TInt aChannel)</tt> method comes there.
+
Listening to the Bluetooth connection is explained in [[Archived:Establishing a Bluetooth connection using Symbian C++]]. The channel number parameter in {{Icode|CMyServiceAdvertiser::StartAdvertiserL(TInt aChannel)}} method comes there.
  
 
==MMP file==
 
==MMP file==
 
The following capabilities and libraries are required:
 
The following capabilities and libraries are required:
 
<code cpp>
 
<code cpp>
CAPABILITY     LocalServices
+
CAPABILITY LocalServices
LIBRARY         sdpagent.lib
+
LIBRARY sdpagent.lib
LIBRARY         sdpdatabase.lib
+
LIBRARY sdpdatabase.lib
 
</code>
 
</code>
  
Line 149: Line 166:
 
==Postconditions==  
 
==Postconditions==  
 
The Bluetooth service is advertised and can be discovered as explained in  
 
The Bluetooth service is advertised and can be discovered as explained in  
[[CS000937 - Discovering Bluetooth services]].
+
[[Archived:Discovering Bluetooth services using Symbian C++]].
  
 
==See also==
 
==See also==
[[CS000936 - Discovering Bluetooth devices]]
+
[[Archived:Discovering Bluetooth devices using Symbian C++]]
  
[[CS000937 - Discovering Bluetooth services]]
+
[[Archived:Discovering Bluetooth services using Symbian C++]]
  
[[CS000939 - Establishing a Bluetooth connection]]
+
[[Archived:Establishing a Bluetooth connection using Symbian C++]]
  
[[KIS000330 - RHostResolver and redundant display of access point selection dialog]]
+
[[Archived:RHostResolver and redundant display of access point selection dialog (Known Issue)]]
  
 
==Example application==
 
==Example application==
This code snippet has been used in the [http://www.forum.nokia.com/info/sw.nokia.com/id/e56fccb6-2d70-4a02-9008-7b3e97927057/S60_Platform_Bluetooth_Point_to_Multipoint_Example.html S60 Platform: Bluetooth Point-to-multipoint Example application].
+
This code snippet has been used in the [http://www.developer.nokia.com/info/sw.nokia.com/id/e56fccb6-2d70-4a02-9008-7b3e97927057/S60_Platform_Bluetooth_Point_to_Multipoint_Example.html S60 Platform: Bluetooth Point-to-multipoint Example application].
 
+
<!-- Translation --> [[zh-hans:广播蓝牙服务]]
[[Category:Symbian C++]][[Category:Code Examples]][[Category:Bluetooth]]
+

Revision as of 08:21, 18 September 2012

Archived.pngArchived: This article is archived because it is not considered relevant for third-party developers creating commercial solutions today. If you think this article is still relevant, let us know by adding the template {{ReviewForRemovalFromArchive|user=~~~~|write your reason here}}.

The article is believed to be still valid for the original topic scope.


Article Metadata
Tested with
Devices(s): Nokia N95
Compatibility
Platform(s): S60 3rd Edition, MR
S60 3rd Edition FP1
Article
Keywords: RSdp, RSdpDatabase, TSdpServRecordHandle, RSdpDatabase::CreateServiceRecordL(), RSdpDatabase::UpdateAttributeL()
Created: tepaa (25 Apr 2008)
Last edited: hamishwillee (18 Sep 2012)

Contents

Overview

RSdp provides a session to the Service Discovery Database. It is used to create subsessions to database functionality. A client must create and connect a session before using a RSdpDatabase subsession to access the database.

RSdpDatabase is a subsession of the SDP through which service records and their attributes can be added, deleted, and updated.

The following example shows how to advertise a certain (KBT_serviceID 0x10ff) Bluetooth service. Discovering this particular service is explained in Archived:Discovering Bluetooth services using Symbian C++.

Listening to the Bluetooth connection is explained in Archived:Establishing a Bluetooth connection using Symbian C++. The channel number parameter in CMyServiceAdvertiser::StartAdvertiserL(TInt aChannel) method comes there.

MMP file

The following capabilities and libraries are required:

CAPABILITY LocalServices
LIBRARY sdpagent.lib
LIBRARY sdpdatabase.lib

Header file

#include <btsdp.h>
#include <bt_sock.h>
 
// The service id that identifies the service. This id will be
// used when advertising the service and discovering the service.
#define KBT_serviceID 0x10ff
 
// Service name and description for our service
_LIT(KBTServiceName, "BTpmp");
_LIT(KBTServiceDesc, "BTpmp");
 
// Service discovery protocol session
RSdp iSdp;
 
// Service discovery database (sdp)
RSdpDatabase iSdpDB;
 
// Service record
TSdpServRecordHandle iRecord;
 
// Service record state
TInt iRecordState;

Source file

Start the service advertiser on a given channel. Entry to service discovery database will be entered describing the advertised service.

void CMyServiceAdvertiser::StartAdvertiserL(TInt aChannel)
{
// Open sdp session
User::LeaveIfError(iSdp.Connect());
// Open sdp database session
User::LeaveIfError(iSdpDB.Open(iSdp));
 
// Create a record of the correct service class
TUUID serviceUUID(KBT_serviceID);
iSdpDB.CreateServiceRecordL(serviceUUID, iRecord);
 
// Add a protocol to the record
CSdpAttrValueDES* protocolDescriptorList = CSdpAttrValueDES::NewDESL(NULL);
CleanupStack::PushL(protocolDescriptorList);
 
TBuf8<1> channel;
channel.Append((TChar)aChannel);
 
// Create protocol list for our service
protocolDescriptorList
->StartListL() // list of protocols required for this method
->BuildDESL()
->StartListL()
->BuildUUIDL(KL2CAP)
->EndListL()
 
->BuildDESL()
->StartListL()
->BuildUUIDL(KRFCOMM)
->BuildUintL(channel)
->EndListL()
->EndListL();
 
// Set protocol list to the record
iSdpDB.UpdateAttributeL(iRecord, KSdpAttrIdProtocolDescriptorList,
*protocolDescriptorList);
CleanupStack::PopAndDestroy(protocolDescriptorList);
 
// Add a name to the record
iSdpDB.UpdateAttributeL(iRecord,
KSdpAttrIdBasePrimaryLanguage +
KSdpAttrIdOffsetServiceName,
KBTServiceName);
 
// Add a description to the record
iSdpDB.UpdateAttributeL(iRecord,
KSdpAttrIdBasePrimaryLanguage +
KSdpAttrIdOffsetServiceDescription,
KBTServiceDesc);
 
// Set service available
UpdateAvailabilityL(ETrue);
}

Set the availability of the advertised service. The service record on the service discovery database will be updated accordingly.

void CMyServiceAdvertiser::UpdateAvailabilityL(TBool aAvailable)
{
TInt state = aAvailable ? 0xFF : 0x00;
 
// Set availability
iSdpDB.UpdateAttributeL(iRecord, KSdpAttrIdServiceAvailability, state);
 
// Mark record changed
iSdpDB.UpdateAttributeL(iRecord, KSdpAttrIdServiceRecordState,
++iRecordState);
}

Stop advertising the service

void CMyServiceAdvertiser::StopAdvertiserL()
{
if ( iRecord!=NULL )
{
// Delete record from service discovery database
iSdpDB.DeleteRecordL(iRecord);
 
// Close sdp and sdp db sessions
iSdpDB.Close();
iSdp.Close();
iRecord=NULL;
}
}


Postconditions

The Bluetooth service is advertised and can be discovered as explained in Archived:Discovering Bluetooth services using Symbian C++.

See also

Archived:Discovering Bluetooth devices using Symbian C++

Archived:Discovering Bluetooth services using Symbian C++

Archived:Establishing a Bluetooth connection using Symbian C++

Archived:RHostResolver and redundant display of access point selection dialog (Known Issue)

Example application

This code snippet has been used in the S60 Platform: Bluetooth Point-to-multipoint Example application.

134 page views in the last 30 days.
×