S60 3rd Edition SDK for Symbian OS
Example Applications Guide

CChatBtServiceAdvertiser Class Reference

#include <ChatBtServiceAdvertiser.h>

Inheritance diagram for CChatBtServiceAdvertiser:

CChatServiceAdvertiser List of all members.

Public Member Functions

virtual ~CChatBtServiceAdvertiser ()
void StartAdvertisingL (TInt aPort)
void StopAdvertisingL ()
TBool IsAdvertising ()
void UpdateAvailabilityL (TBool aIsAvailable)

Protected Member Functions

 CChatBtServiceAdvertiser ()
virtual void BuildProtocolDescriptionL (CSdpAttrValueDES *aProtocolDescriptor, TInt aPort)=0
virtual TInt ServiceClass ()=0
virtual const TDesC & ServiceName ()=0
virtual const TDesC & ServiceDescription ()=0

Private Member Functions

void ConnectL ()

Private Attributes

RSdp iSdpSession
RSdpDatabase iSdpDatabase
TSdpServRecordHandle iRecord
TInt iRecordState
TBool iIsConnected

Detailed Description

CChatBtServiceAdvertiser Advertises a service in the SDP database.

Definition at line 32 of file ChatBtServiceAdvertiser.h.


Constructor & Destructor Documentation

CChatBtServiceAdvertiser::~CChatBtServiceAdvertiser (   )  [virtual]
 

~CChatBtServiceAdvertiser Destroy the object, close all open handles and remove the advertised service.

Definition at line 40 of file ChatBtServiceAdvertiser.cpp.

References IsAdvertising(), iSdpDatabase, iSdpSession, and StopAdvertisingL().

00041     {
00042     if ( IsAdvertising() )
00043         {
00044         TRAPD( err,StopAdvertisingL() );
00045         if ( err != KErrNone )
00046             {
00047             User::Panic( KPanicBTServiceAdvertiser, err );
00048             }
00049         }
00050 
00051     iSdpDatabase.Close();
00052     iSdpSession.Close();
00053     }

CChatBtServiceAdvertiser::CChatBtServiceAdvertiser (   )  [protected]
 

CChatBtServiceAdvertiser Construct this object

Definition at line 28 of file ChatBtServiceAdvertiser.cpp.

00028                                                    :
00029     iRecord( 0 ), 
00030     iIsConnected( EFalse )
00031     {
00032     // no implementation required
00033     }


Member Function Documentation

void CChatBtServiceAdvertiser::StartAdvertisingL (  TInt  aPort  ) 
 

StartAdvertisingL Start the advertising of this service

Parameters:
aPort the port being used by the service

Definition at line 75 of file ChatBtServiceAdvertiser.cpp.

References BuildProtocolDescriptionL(), ConnectL(), iIsConnected, iRecord, IsAdvertising(), iSdpDatabase, ServiceClass(), ServiceDescription(), ServiceName(), and StopAdvertisingL().

00076     {
00077     if ( IsAdvertising() )
00078         {
00079         // could be advertising on a different port
00080         StopAdvertisingL(); 
00081         }
00082     if ( ! iIsConnected )
00083         {
00084         ConnectL();
00085         }
00086     iSdpDatabase.CreateServiceRecordL( ServiceClass(), iRecord );
00087 
00088     // add a Protocol to the record
00089     CSdpAttrValueDES* vProtocolDescriptor = CSdpAttrValueDES::NewDESL( NULL );
00090     CleanupStack::PushL( vProtocolDescriptor );
00091  
00092     BuildProtocolDescriptionL( vProtocolDescriptor,aPort );
00093 
00094     iSdpDatabase.UpdateAttributeL( iRecord, KSdpAttrIdProtocolDescriptorList, 
00095         *vProtocolDescriptor );
00096 
00097     CleanupStack::PopAndDestroy( vProtocolDescriptor );
00098 
00099     // Add a name to the record
00100     iSdpDatabase.UpdateAttributeL( iRecord, 
00101         KSdpAttrIdBasePrimaryLanguage + 
00102         KSdpAttrIdOffsetServiceName, 
00103         ServiceName() );
00104 
00105     // Add a description to the record
00106     iSdpDatabase.UpdateAttributeL( iRecord, 
00107         KSdpAttrIdBasePrimaryLanguage + 
00108         KSdpAttrIdOffsetServiceDescription, 
00109         ServiceDescription() );
00110 
00111     }

void CChatBtServiceAdvertiser::StopAdvertisingL (   ) 
 

StopAdvertisingL Stop advertising this service. Remove the record from the sdp database

Definition at line 146 of file ChatBtServiceAdvertiser.cpp.

References iRecord, IsAdvertising(), and iSdpDatabase.

00147     {
00148     if ( IsAdvertising() )
00149         {
00150         iSdpDatabase.DeleteRecordL( iRecord );
00151         iRecord = 0;
00152         }
00153     }

TBool CChatBtServiceAdvertiser::IsAdvertising (   ) 
 

IsAdvertising Does the SDP database contain a record for this service

Returns:
ETrue whether the service is being advertised

Definition at line 160 of file ChatBtServiceAdvertiser.cpp.

References iRecord.

00161     {
00162     return iRecord != 0;
00163     }

void CChatBtServiceAdvertiser::UpdateAvailabilityL (  TBool  aIsAvailable  ) 
 

UpdateAvailabilityL Update the service availability field of the service record

Parameters:
aIsAvailable ETrue is the service is not busy.

Definition at line 118 of file ChatBtServiceAdvertiser.cpp.

References iRecord, iRecordState, and iSdpDatabase.

00119     {
00120     TUint state;
00121     if ( aIsAvailable )
00122         {
00123         state = 0xFF;  //  Fully unused
00124         }
00125     else
00126         {
00127         state = 0x00;  //  Fully used -> can't connect
00128         }
00129 
00130     //  Update the availibility attribute field
00131     iSdpDatabase.UpdateAttributeL( iRecord, 
00132         KSdpAttrIdServiceAvailability, 
00133         state );
00134 
00135     //  Mark the record as changed - by increasing its state number (version)
00136     iSdpDatabase.UpdateAttributeL( iRecord, 
00137         KSdpAttrIdServiceRecordState, 
00138         ++iRecordState );
00139     }

virtual void CChatBtServiceAdvertiser::BuildProtocolDescriptionL (  CSdpAttrValueDES *  aProtocolDescriptor,
TInt  aPort
)  [protected, pure virtual]
 

BuildProtocolDescriptionL Builds the protocol description

Parameters:
aProtocolDescriptor the protocol descriptor
aPort the service port

Implemented in CChatServiceAdvertiser.

virtual TInt CChatBtServiceAdvertiser::ServiceClass (   )  [protected, pure virtual]
 

ServiceClass

Returns:
the service class

Implemented in CChatServiceAdvertiser.

virtual const TDesC& CChatBtServiceAdvertiser::ServiceName (   )  [protected, pure virtual]
 

ServiceName

Returns:
the service name

Implemented in CChatServiceAdvertiser.

virtual const TDesC& CChatBtServiceAdvertiser::ServiceDescription (   )  [protected, pure virtual]
 

ServiceDescription

Returns:
the service description

Implemented in CChatServiceAdvertiser.

void CChatBtServiceAdvertiser::ConnectL (   )  [private]
 

ConnectL Connect to the SDP database

Definition at line 60 of file ChatBtServiceAdvertiser.cpp.

References iIsConnected, iSdpDatabase, and iSdpSession.

00061     {
00062     if ( !iIsConnected )
00063         {
00064         User::LeaveIfError( iSdpSession.Connect() );
00065         User::LeaveIfError( iSdpDatabase.Open( iSdpSession ) );
00066         iIsConnected = ETrue;
00067         }
00068     }


Member Data Documentation

RSdp CChatBtServiceAdvertiser::iSdpSession [private]
 

iSdpSession a handle to the SDP session

Definition at line 121 of file ChatBtServiceAdvertiser.h.

RSdpDatabase CChatBtServiceAdvertiser::iSdpDatabase [private]
 

iSdpDatabase a connection to the SDP database

Definition at line 127 of file ChatBtServiceAdvertiser.h.

TSdpServRecordHandle CChatBtServiceAdvertiser::iRecord [private]
 

iRecord the record handle of the service record for this server

Definition at line 133 of file ChatBtServiceAdvertiser.h.

TInt CChatBtServiceAdvertiser::iRecordState [private]
 

iRecordState the current record state - change number

Definition at line 139 of file ChatBtServiceAdvertiser.h.

TBool CChatBtServiceAdvertiser::iIsConnected [private]
 

iIsConnected has a connection been made to the SDP Database

Definition at line 145 of file ChatBtServiceAdvertiser.h.


© Nokia 2006

Back to top