www.pudn.com > ExampleBluetoothChat.rar > TBluetoothAttributeParser.cpp
/** * * @brief Definition of TBluetoothAttributeParser * * Copyright (c) EMCC Software Ltd 2003 * @version 1.0 */ // System include #include// User include #include "BluetoothDefinitions.h" #include "BluetoothAttributeObserver.h" #include "TBluetoothAttributeParser.h" /** * Constructor * * Set observer and flag to indicate success / failure * * @param aObserver an Observer that will get called iff a value service & port are found * @param aContinueSearching flag set to indicate success / failure. * **/ TBluetoothAttributeParser::TBluetoothAttributeParser(MBluetoothAttributeObserver& aObserver, TBool& aContinueSearching) : iObserver(aObserver), iContinueSearching(aContinueSearching) { iProcessingState = EStartOfDesOne; iFinished = EFalse; } /** * VisitAttributeValueL * * Called for every member of the Data Element Sequence of this attribute. * Only interested in the RFCOMM and Port information * * An OS defined function * * @param aValue the attrubute's value * @param aType the type of data encapsulated by aValue **/ void TBluetoothAttributeParser::VisitAttributeValueL(CSdpAttrValue& aValue, TSdpElementType /*aType*/) { switch ( iProcessingState ) { case EStartOfDesOne: case EStartOfDesTwo: case EL2Cap: case EEndOfDesTwo: case EStartDesThree: break; // check nothing case ERFComm: CompareRFCOMM( aValue ); break; case ERFCommPort: GetPort( aValue ); break; case EEndOfDesThree: case EEndOfDesOne: break; // check nothing default: // unexpected output -- panic Panic(EBadAttributeValue); break; } Next(); } /** * Called at the start of a list. OS Specified function * * @param aList the list your starting on * @return none */ void TBluetoothAttributeParser::StartListL(CSdpAttrValueList& /*aList*/) { } /** * Called at the end of list. OS Specified function * * @param none * @return none */ void TBluetoothAttributeParser::EndListL() { switch ( iProcessingState ) { // are we at the end of a list case EEndOfDesOne: case EEndOfDesTwo: case EEndOfDesThree: break; default: User::Leave(KErrGeneral); break; } Next(); } /** * CompareRFCOMM * * Check to see if RFCOMM is an advertised service * * @param aAttrValue the attribute value **/ void TBluetoothAttributeParser::CompareRFCOMM( CSdpAttrValue& aAttrValue ) { TBool success = EFalse; if ( aAttrValue.Type() == ETypeUUID ) { if ( aAttrValue.UUID() == KRFCOMM ) { success = ETrue; } } if (!success) iContinueSearching = EFalse; } /** * GetPort * * Obtain Port information and return to the observer * * @param aAttrValue the attribute value * @return none **/ void TBluetoothAttributeParser::GetPort( CSdpAttrValue& aAttrValue ) { TBool success = EFalse; if ( aAttrValue.Type() == ETypeUint ) { iPort = aAttrValue.Uint(); iObserver.SetPort(iPort); success = ETrue; } if (!success) iContinueSearching = EFalse; } /** * Next * * Move the State flag on to the next member of the Data Element Sequence * * @param none * @return none **/ void TBluetoothAttributeParser::Next() { __ASSERT_DEBUG(iProcessingState != EFinished, Panic(EBadAttributeValue)); // move to the next item iProcessingState = static_cast ( static_cast (iProcessingState) + 1 ); }