S60 3rd Edition SDK for Symbian OS
Example Applications Guide

CChatBtServiceSearcher Class Reference

#include <ChatBtServiceSearcher.h>

Inheritance diagram for CChatBtServiceSearcher:

MChatSdpAttributeNotifier CChatServiceSearcher List of all members.

Public Member Functions

virtual ~CChatBtServiceSearcher ()
void SelectDeviceByDiscoveryL (TRequestStatus &aObserverRequestStatus)
void FindServiceL (TRequestStatus &aObserverRequestStatus)
const TBTDevAddr & BTDevAddr ()
const TBTDeviceResponseParams & ResponseParams ()
void NextRecordRequestComplete (TInt aError, TSdpServRecordHandle aHandle, TInt aTotalRecordsCount)
void AttributeRequestResult (TSdpServRecordHandle aHandle, TSdpAttributeID aAttrID, CSdpAttrValue *aAttrValue)
void AttributeRequestComplete (TSdpServRecordHandle aHandle, TInt aError)

Protected Member Functions

 CChatBtServiceSearcher (MLog &aLog)
virtual void Finished (TInt aError=KErrNone)
virtual TBool HasFinishedSearching () const
TBool HasFoundService () const
virtual RArray< TChatSdpAttributeParser::TChatSdpAttributeNode > & ProtocolList ()=0
virtual const TUUID & ServiceClass () const =0
virtual void FoundElementL (TInt aKey, CSdpAttrValue &aValue)=0

Private Member Functions

void NextRecordRequestCompleteL (TInt aError, TSdpServRecordHandle aHandle, TInt aTotalRecordsCount)
void AttributeRequestResultL (TSdpServRecordHandle aHandle, TSdpAttributeID aAttrID, CSdpAttrValue *aAttrValue)
void AttributeRequestCompleteL (TSdpServRecordHandle, TInt aError)

Private Attributes

TRequestStatus * iStatusObserver
TBool iIsDeviceSelectorConnected
RNotifier iDeviceSelector
TBTDeviceResponseParamsPckg iResponse
TBTDeviceSelectionParamsPckg iSelectionFilter
CSdpAgent * iAgent
CSdpSearchPattern * iSdpSearchPattern
TBool iHasFoundService
MLog & iLog

Detailed Description

CChatBtServiceSearcher Searches for a service on a remote machine

Definition at line 39 of file ChatBtServiceSearcher.h.


Constructor & Destructor Documentation

CChatBtServiceSearcher::~CChatBtServiceSearcher (   )  [virtual]
 

~CChatBtServiceSearcher() Destroy the object and release all memory objects

Definition at line 40 of file ChatBtServiceSearcher.cpp.

References iAgent, iDeviceSelector, iIsDeviceSelectorConnected, and iSdpSearchPattern.

00041     {
00042     if ( iIsDeviceSelectorConnected )
00043         {
00044         iDeviceSelector.CancelNotifier( KDeviceSelectionNotifierUid );
00045         iDeviceSelector.Close();
00046         }
00047     delete iSdpSearchPattern;
00048     iSdpSearchPattern = NULL;
00049 
00050     delete iAgent;
00051     iAgent = NULL;
00052     }

CChatBtServiceSearcher::CChatBtServiceSearcher (  MLog &  aLog  )  [protected]
 

CChatBtServiceSearcher() Constructs this object

Parameters:
aLog the log to send output to

Definition at line 29 of file ChatBtServiceSearcher.cpp.

00030     : iIsDeviceSelectorConnected( EFalse ),
00031     iLog( aLog )
00032     {
00033     }


Member Function Documentation

void CChatBtServiceSearcher::SelectDeviceByDiscoveryL (  TRequestStatus &  aObserverRequestStatus  ) 
 

SelectDeviceByDiscoveryL() Select a device

Parameters:
aObserverRequestStatus the observer that is to be notified when the device selection is complete.

Definition at line 59 of file ChatBtServiceSearcher.cpp.

References iDeviceSelector, iIsDeviceSelectorConnected, iResponse, iSelectionFilter, and ServiceClass().

00061     {
00062     if ( ! iIsDeviceSelectorConnected )
00063         {
00064         User::LeaveIfError( iDeviceSelector.Connect() );
00065         iIsDeviceSelectorConnected = ETrue;
00066         }
00067 
00068 
00069     iSelectionFilter().SetUUID( ServiceClass() );
00070 
00071     iDeviceSelector.StartNotifierAndGetResponse( 
00072         aObserverRequestStatus, 
00073         KDeviceSelectionNotifierUid, 
00074         iSelectionFilter, 
00075         iResponse );
00076     }

void CChatBtServiceSearcher::FindServiceL (  TRequestStatus &  aObserverRequestStatus  ) 
 

FindServiceL() Find a service on the specified device

Parameters:
aObserverRequestStatus the observer that is to be notified when the service search is complete

Definition at line 83 of file ChatBtServiceSearcher.cpp.

References BTDevAddr(), iAgent, iHasFoundService, iResponse, iSdpSearchPattern, iStatusObserver, and ServiceClass().

00084     {
00085     if ( !iResponse().IsValidBDAddr() )
00086         {
00087         User::Leave( KErrNotFound );
00088         }
00089     iHasFoundService = EFalse;
00090 
00091     // delete any existing agent and search pattern
00092     delete iSdpSearchPattern;
00093     iSdpSearchPattern = NULL;
00094 
00095     delete iAgent;
00096     iAgent = NULL;
00097 
00098     iAgent = CSdpAgent::NewL( *this, BTDevAddr() );
00099 
00100     iSdpSearchPattern = CSdpSearchPattern::NewL();
00101    
00102     iSdpSearchPattern->AddL( ServiceClass() );
00103     // return code is the position in the list that the UUID is inserted at 
00104     // and is intentionally ignored
00105   
00106     iAgent->SetRecordFilterL( *iSdpSearchPattern );
00107 
00108     iStatusObserver = &aObserverRequestStatus;
00109 
00110     iAgent->NextRecordRequestL();
00111     }

const TBTDevAddr & CChatBtServiceSearcher::BTDevAddr (   ) 
 

BTDevAddr()

Returns:
the bluetooth device address

Definition at line 289 of file ChatBtServiceSearcher.cpp.

References iResponse.

00290     {
00291     return iResponse().BDAddr();
00292     }

const TBTDeviceResponseParams & CChatBtServiceSearcher::ResponseParams (   ) 
 

ResponseParams()

Returns:
Information about the device selected by the user

Definition at line 299 of file ChatBtServiceSearcher.cpp.

References iResponse.

00300     {
00301     return iResponse();
00302     }

void CChatBtServiceSearcher::Finished (  TInt  aError = KErrNone  )  [protected, virtual]
 

Finished() The search has finished. Notify the observer that the process is complete.

Definition at line 265 of file ChatBtServiceSearcher.cpp.

References HasFoundService(), and iStatusObserver.

00266     {
00267     if ( aError == KErrNone && !HasFoundService() )
00268         {
00269         aError = KErrNotFound;
00270         }
00271     User::RequestComplete( iStatusObserver, aError );
00272     }

TBool CChatBtServiceSearcher::HasFinishedSearching (   )  const [protected, virtual]
 

HasFinishedSearching() Is the instance still wanting to search.

Returns:
EFalse if the instance wants searching to continue.

Definition at line 279 of file ChatBtServiceSearcher.cpp.

00280     {
00281     return EFalse;
00282     }

TBool CChatBtServiceSearcher::HasFoundService (   )  const [protected]
 

HasFoundService()

Returns:
ETrue if a service has been found

Definition at line 309 of file ChatBtServiceSearcher.cpp.

References iHasFoundService.

00310     {
00311     return iHasFoundService;
00312     }

virtual RArray<TChatSdpAttributeParser::TChatSdpAttributeNode>& CChatBtServiceSearcher::ProtocolList (   )  [protected, pure virtual]
 

ProtocolList() The list of Protocols required by the service.

Implemented in CChatServiceSearcher.

virtual const TUUID& CChatBtServiceSearcher::ServiceClass (   )  const [protected, pure virtual]
 

ServiceClass() The service class to search for

Returns:
the service class UUID

Implemented in CChatServiceSearcher.

virtual void CChatBtServiceSearcher::FoundElementL (  TInt  aKey,
CSdpAttrValue &  aValue
)  [protected, pure virtual]
 

FoundElementL() Read the data element

Parameters:
aKey a key that identifies the element
aValue the data element

Implements MChatSdpAttributeNotifier.

Implemented in CChatServiceSearcher.

void CChatBtServiceSearcher::NextRecordRequestComplete (  TInt  aError,
TSdpServRecordHandle  aHandle,
TInt  aTotalRecordsCount
) 
 

NextRecordRequestComplete() Process the result of the next record request

Parameters:
aError the error code
aHandle the handle of the service record
aTotalRecordsCount the total number of matching service records

Definition at line 118 of file ChatBtServiceSearcher.cpp.

References NextRecordRequestCompleteL().

00122     {
00123     TRAPD( error, 
00124         NextRecordRequestCompleteL( aError, aHandle, aTotalRecordsCount ) );
00125 
00126     if ( error != KErrNone ) 
00127         {
00128         Panic( EChatBtServiceSearcherNextRecordRequestComplete );
00129         }
00130     }

void CChatBtServiceSearcher::AttributeRequestResult (  TSdpServRecordHandle  aHandle,
TSdpAttributeID  aAttrID,
CSdpAttrValue *  aAttrValue
) 
 

AttributeRequestResult() Process the next attribute requested

Parameters:
aHandle the handle of the service record
aAttrID the id of the attribute
aAttrValue the value of the attribute

Definition at line 174 of file ChatBtServiceSearcher.cpp.

References AttributeRequestResultL().

00178     {
00179     TRAPD( error, AttributeRequestResultL( aHandle, aAttrID, aAttrValue ) );
00180     if ( error != KErrNone )
00181         {
00182         Panic( EChatBtServiceSearcherAttributeRequestResult );
00183         }
00184     // Delete obsolete local atribute pointer. 
00185     delete aAttrValue;
00186     aAttrValue = NULL;
00187     }

void CChatBtServiceSearcher::AttributeRequestComplete (  TSdpServRecordHandle  aHandle,
TInt  aError
) 
 

AttributeRequestComplete() Process the arrtibute request completion

Parameters:
aHandle the handle of the service record
aError the error code

Definition at line 218 of file ChatBtServiceSearcher.cpp.

References AttributeRequestCompleteL().

00220     {
00221     TRAPD( error, AttributeRequestCompleteL( aHandle, aError ) );
00222     if ( error != KErrNone )
00223         {
00224         Panic( EChatBtServiceSearcherAttributeRequestComplete );
00225         }
00226     }

void CChatBtServiceSearcher::NextRecordRequestCompleteL (  TInt  aError,
TSdpServRecordHandle  aHandle,
TInt  aTotalRecordsCount
)  [private]
 

NextRecordRequestCompleteL() Process the result of the next record request

Parameters:
aError the error code
aHandle the handle of the service record
aTotalRecordsCount the total number of matching service records

Definition at line 137 of file ChatBtServiceSearcher.cpp.

References Finished(), iAgent, iLog, and MLog::LogL().

00141     {
00142     if ( aError == KErrEof )
00143         {
00144         Finished();
00145         return;
00146         }
00147 
00148     if ( aError != KErrNone )
00149         {
00150         iLog.LogL( KErrNRRCErr, aError );
00151         Finished( aError );
00152         return;
00153         }
00154 
00155     if ( aTotalRecordsCount == 0 )
00156         {
00157         HBufC* errNRRCNoRecords = StringLoader
00158             ::LoadLC ( R_CHAT_ERR_NRRC_NO_RECORDS );
00159         iLog.LogL( *errNRRCNoRecords );
00160         CleanupStack::PopAndDestroy ( errNRRCNoRecords );
00161         Finished( KErrNotFound );
00162         return;
00163         }
00164 
00165     //  Request its attributes
00166     iAgent->AttributeRequestL( aHandle, KSdpAttrIdProtocolDescriptorList );
00167     }

void CChatBtServiceSearcher::AttributeRequestResultL (  TSdpServRecordHandle  aHandle,
TSdpAttributeID  aAttrID,
CSdpAttrValue *  aAttrValue
)  [private]
 

AttributeRequestResultL() Process the next attribute requested

Parameters:
aHandle the handle of the service record
aAttrID the id of the attribute
aAttrValue the value of the attribute

Definition at line 194 of file ChatBtServiceSearcher.cpp.

References TChatSdpAttributeParser::HasFinished(), iHasFoundService, and ProtocolList().

00198     {
00199     __ASSERT_ALWAYS( aAttrID == KSdpAttrIdProtocolDescriptorList, 
00200                      User::Leave( KErrNotFound ) );
00201     TChatSdpAttributeParser parser( ProtocolList(), *this );
00202 
00203     // Validate the attribute value, and extract the RFCOMM channel
00204     aAttrValue->AcceptVisitorL( parser );
00205 
00206     if ( parser.HasFinished() )
00207         {
00208         // Found a suitable record so change state
00209         iHasFoundService = ETrue;
00210         }
00211     }

void CChatBtServiceSearcher::AttributeRequestCompleteL (  TSdpServRecordHandle  ,
TInt  aError
)  [private]
 

AttributeRequestCompleteL() Process the arrtibute request completion

Parameters:
aHandle the handle of the service record
aError the error code

Definition at line 233 of file ChatBtServiceSearcher.cpp.

References Finished(), HasFinishedSearching(), iAgent, iLog, and MLog::LogL().

00236     {
00237     if ( aError != KErrNone )
00238         {
00239         HBufC* errCantGetAttribute = StringLoader
00240             ::LoadLC ( R_CHAT_ERR_CANT_GET_ATTRIBUTE );
00241         iLog.LogL( *errCantGetAttribute, aError );
00242         CleanupStack::PopAndDestroy ( errCantGetAttribute );
00243         }
00244     else if ( !HasFinishedSearching() )
00245         {
00246         // have not found a suitable record so request another
00247         iAgent->NextRecordRequestL();
00248         }
00249     else
00250         {
00251         HBufC* errAttrReqCom = StringLoader
00252             ::LoadLC ( R_CHAT_ERR_ATTR_REQ_COM );
00253         iLog.LogL( *errAttrReqCom );
00254         CleanupStack::PopAndDestroy ( errAttrReqCom );
00255         Finished();
00256         }
00257     }


Member Data Documentation

TRequestStatus* CChatBtServiceSearcher::iStatusObserver [private]
 

iStatusObserver pointer to the request status observer Not owned by CChatBtServiceSearcher

Definition at line 209 of file ChatBtServiceSearcher.h.

TBool CChatBtServiceSearcher::iIsDeviceSelectorConnected [private]
 

iIsDeviceSelectorConnected is the device selector connected?

Definition at line 215 of file ChatBtServiceSearcher.h.

RNotifier CChatBtServiceSearcher::iDeviceSelector [private]
 

iDeviceSelector a handle to the bluetooth device selector notifier

Definition at line 221 of file ChatBtServiceSearcher.h.

TBTDeviceResponseParamsPckg CChatBtServiceSearcher::iResponse [private]
 

iResponse the response of the device selection.

Definition at line 227 of file ChatBtServiceSearcher.h.

TBTDeviceSelectionParamsPckg CChatBtServiceSearcher::iSelectionFilter [private]
 

iSelectionFilter Request a device selection

Definition at line 233 of file ChatBtServiceSearcher.h.

CSdpAgent* CChatBtServiceSearcher::iAgent [private]
 

iAgent a connetction to the SDP client Owned by CChatBtServiceSearcher

Definition at line 238 of file ChatBtServiceSearcher.h.

CSdpSearchPattern* CChatBtServiceSearcher::iSdpSearchPattern [private]
 

iSdpSearchPattern a search pattern Owned by CChatBtServiceSearcher

Definition at line 244 of file ChatBtServiceSearcher.h.

TBool CChatBtServiceSearcher::iHasFoundService [private]
 

iHasFoundService has the service been found ?

Definition at line 249 of file ChatBtServiceSearcher.h.

MLog& CChatBtServiceSearcher::iLog [private]
 

iLog the log to send output to

Definition at line 254 of file ChatBtServiceSearcher.h.


© Nokia 2006

Back to top