Nokia N97 SDK
Example Applications Guide

CChatServiceSearcher Class Reference

#include <ChatServiceSearcher.h>

Inheritance diagram for CChatServiceSearcher:

CChatBtServiceSearcher MChatSdpAttributeNotifier List of all members.

Detailed Description

CChatServiceSearcher Searches for a chat service.

Definition at line 29 of file ChatServiceSearcher.h.


Public Member Functions

virtual  ~CChatServiceSearcher ()
TInt  Port ()
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)

Static Public Member Functions

static CChatServiceSearcher *  NewL (MLog &aLog)
static CChatServiceSearcher *  NewLC (MLog &aLog)

Protected Member Functions

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

Private Member Functions

  CChatServiceSearcher (MLog &aLog)
void  ConstructL ()

Private Attributes

TUUID  iServiceClass
TInt  iPort
RArray< TChatSdpAttributeParser::TChatSdpAttributeNode >  iProtocolArray


Constructor & Destructor Documentation

CChatServiceSearcher::~CChatServiceSearcher (   )  [virtual]
 

~CMessageServiceSearcher() Destroy the object and release all memory objects.

Definition at line 66 of file ChatServiceSearcher.cpp.

References iProtocolArray.

00067     {
00068     iProtocolArray.Close();
00069     }

CChatServiceSearcher::CChatServiceSearcher (  MLog &  aLog  )  [private]
 

CChatServiceSearcher() Constructs this object

Parameters:
aLog  the log to send output to

Definition at line 54 of file ChatServiceSearcher.cpp.

Referenced by NewLC().

00055 : CChatBtServiceSearcher( aLog ),
00056   iServiceClass( KServiceClass ),
00057   iPort( -1 )
00058     {
00059     }


Member Function Documentation

CChatServiceSearcher * CChatServiceSearcher::NewLC (  MLog &  aLog  )  [static]
 

NewLC() Create a CChatServiceSearcher object

Parameters:
aLog  the log to send output to
Returns:
a pointer to the created instance of CChatServiceSearcher

Definition at line 41 of file ChatServiceSearcher.cpp.

References CChatServiceSearcher().

Referenced by NewL().

00042     {
00043     CChatServiceSearcher* self = new ( ELeave ) CChatServiceSearcher( aLog );
00044     CleanupStack::PushL( self );
00045     self->ConstructL();
00046     return self;
00047     }

TInt CChatServiceSearcher::Port (   ) 
 

Port() Retrieve the port on which the service is installed

Returns:
the port number

Definition at line 159 of file ChatServiceSearcher.cpp.

References iPort.

Referenced by CChatBt::ConnectToServerL().

00160     {
00161     return iPort;
00162     }

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

ServiceClass()

Returns:
the service class uid.

Implements CChatBtServiceSearcher.

Definition at line 86 of file ChatServiceSearcher.cpp.

References iServiceClass.

00087     {
00088     return iServiceClass;
00089     }

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

FoundElementL() Read the data element

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

Implements CChatBtServiceSearcher.

Definition at line 147 of file ChatServiceSearcher.cpp.

References iPort.

00148     {
00149     __ASSERT_ALWAYS( aKey == static_cast<TInt>( KRfcommChannel ), 
00150         Panic( EChatBtServiceSearcherProtocolRead ) );
00151     iPort = aValue.Uint();
00152     }

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

ProtocolList()

Returns:
the attribute list.

Implements CChatBtServiceSearcher.

Definition at line 97 of file ChatServiceSearcher.cpp.

References TChatSdpAttributeParser::TChatSdpAttributeNode::SetCommand(), TChatSdpAttributeParser::TChatSdpAttributeNode::SetType(), and TChatSdpAttributeParser::TChatSdpAttributeNode::SetValue().

00098     {
00099     TChatSdpAttributeParser::TChatSdpAttributeNode attrib;
00100     attrib.SetCommand( TChatSdpAttributeParser::ECheckType );
00101     attrib.SetType( ETypeDES );
00102     iProtocolArray.Append( attrib );
00103 
00104     attrib.SetCommand( TChatSdpAttributeParser::ECheckType );
00105     attrib.SetType( ETypeDES );
00106     iProtocolArray.Append( attrib );
00107 
00108     attrib.SetCommand( TChatSdpAttributeParser::ECheckValue );
00109     attrib.SetType( ETypeUUID );
00110     attrib.SetValue( KL2CAP );
00111     iProtocolArray.Append( attrib );
00112 
00113     attrib.SetCommand( TChatSdpAttributeParser::ECheckEnd );
00114     iProtocolArray.Append( attrib );
00115   
00116     attrib.SetCommand( TChatSdpAttributeParser::ECheckType );
00117     attrib.SetType( ETypeDES );
00118     iProtocolArray.Append( attrib );
00119 
00120     attrib.SetCommand( TChatSdpAttributeParser::ECheckValue );
00121     attrib.SetType( ETypeUUID );
00122     attrib.SetValue( KRFCOMM );
00123     iProtocolArray.Append( attrib );
00124   
00125     attrib.SetCommand( TChatSdpAttributeParser::EReadValue );
00126     attrib.SetType( ETypeUint );
00127     attrib.SetValue( KRfcommChannel );
00128     iProtocolArray.Append( attrib );
00129 
00130     attrib.SetCommand( TChatSdpAttributeParser::ECheckEnd );
00131     iProtocolArray.Append( attrib );
00132   
00133     attrib.SetCommand( TChatSdpAttributeParser::ECheckEnd );
00134     iProtocolArray.Append( attrib );
00135 
00136     attrib.SetCommand( TChatSdpAttributeParser::EFinished );
00137     iProtocolArray.Append( attrib );
00138   
00139     return iProtocolArray;
00140     }

void CChatServiceSearcher::ConstructL (   )  [private]
 

ConstructL() Performs second phase construction of this object

Definition at line 76 of file ChatServiceSearcher.cpp.

00077     {
00078     // no implementation required
00079     }

void CChatBtServiceSearcher::SelectDeviceByDiscoveryL (  TRequestStatus &  aObserverRequestStatus  )  [inherited]
 

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 CChatBtServiceSearcher::iDeviceSelector, CChatBtServiceSearcher::iIsDeviceSelectorConnected, CChatBtServiceSearcher::iResponse, CChatBtServiceSearcher::iSelectionFilter, and CChatBtServiceSearcher::ServiceClass().

Referenced by CChatBt::ConnectL().

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  )  [inherited]
 

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 CChatBtServiceSearcher::BTDevAddr(), CChatBtServiceSearcher::iAgent, CChatBtServiceSearcher::iHasFoundService, CChatBtServiceSearcher::iResponse, CChatBtServiceSearcher::iSdpSearchPattern, CChatBtServiceSearcher::iStatusObserver, and CChatBtServiceSearcher::ServiceClass().

Referenced by CChatBt::RunL().

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 (   )  [inherited]
 

BTDevAddr()

Returns:
the bluetooth device address

Definition at line 289 of file ChatBtServiceSearcher.cpp.

References CChatBtServiceSearcher::iResponse.

Referenced by CChatBt::ConnectToServerL(), and CChatBtServiceSearcher::FindServiceL().

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

const TBTDeviceResponseParams & CChatBtServiceSearcher::ResponseParams (   )  [inherited]
 

ResponseParams()

Returns:
Information about the device selected by the user

Definition at line 299 of file ChatBtServiceSearcher.cpp.

References CChatBtServiceSearcher::iResponse.

Referenced by CChatBt::RunL().

00300     {
00301     return iResponse();
00302     }

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

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

Definition at line 265 of file ChatBtServiceSearcher.cpp.

References CChatBtServiceSearcher::HasFoundService(), and CChatBtServiceSearcher::iStatusObserver.

Referenced by CChatBtServiceSearcher::AttributeRequestCompleteL(), and CChatBtServiceSearcher::NextRecordRequestCompleteL().

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

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

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.

Referenced by CChatBtServiceSearcher::AttributeRequestCompleteL().

00280     {
00281     return EFalse;
00282     }

TBool CChatBtServiceSearcher::HasFoundService (   )  const [protected, inherited]
 

HasFoundService()

Returns:
ETrue if a service has been found

Definition at line 309 of file ChatBtServiceSearcher.cpp.

References CChatBtServiceSearcher::iHasFoundService.

Referenced by CChatBtServiceSearcher::Finished().

00310     {
00311     return iHasFoundService;
00312     }

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

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 CChatBtServiceSearcher::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
)  [inherited]
 

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 CChatBtServiceSearcher::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
)  [inherited]
 

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 CChatBtServiceSearcher::AttributeRequestCompleteL().

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


Member Data Documentation

TUUID CChatServiceSearcher::iServiceClass [private]
 

iServiceClass the service class UUID to search for

Definition at line 110 of file ChatServiceSearcher.h.

Referenced by ServiceClass().

TInt CChatServiceSearcher::iPort [private]
 

iPort the port number that the remote service is installed

Definition at line 116 of file ChatServiceSearcher.h.

Referenced by FoundElementL(), and Port().

RArray<TChatSdpAttributeParser::TChatSdpAttributeNode> CChatServiceSearcher::iProtocolArray [private]
 

iProtocolArray the attribute list

Definition at line 122 of file ChatServiceSearcher.h.

Referenced by ~CChatServiceSearcher().


The documentation for this class was generated from the following files:

© Nokia 2009

Back to top