diff -r 02103bf20ee5 -r 90dbfc0435e3 bluetoothengine/headsetsimulator/core/src/RemoteControl/hsremotecontrolparser.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/bluetoothengine/headsetsimulator/core/src/RemoteControl/hsremotecontrolparser.cpp Wed Sep 15 15:59:44 2010 +0200 @@ -0,0 +1,114 @@ +/* + * Component Name: Headset Simulator + * Author: Comarch S.A. + * Version: 1.0 + * Copyright (c) 2010 Comarch S.A. + * + * This Software is submitted by Comarch S.A. to Symbian Foundation Limited on + * the basis of the Member Contribution Agreement entered between Comarch S.A. + * and Symbian Foundation Limited on 5th June 2009 (“Agreement”) and may be + * used only in accordance with the terms and conditions of the Agreement. + * Any other usage, duplication or redistribution of this Software is not + * allowed without written permission of Comarch S.A. + * + */ + +#include "hsremotecontroltools.h" +#include "debug.h" + +CHsRemoteControlParser* CHsRemoteControlParser::NewL() + { + CHsRemoteControlParser *self = CHsRemoteControlParser::NewLC(); + CleanupStack::Pop( self ); + return self; + } + +CHsRemoteControlParser* CHsRemoteControlParser::NewLC() + { + CHsRemoteControlParser *self = new ( ELeave ) CHsRemoteControlParser; + CleanupStack::PushL( self ); + self->ConstructL(); + return self; + } + +CHsRemoteControlParser::~CHsRemoteControlParser() + { + + } + +void CHsRemoteControlParser::ConstructL() + { + + } + +CHsRemoteControlParser::CHsRemoteControlParser() + { + + } + +void CHsRemoteControlParser::ParseL( const TDesC8 &aText, + THsRemoteControlCommand &aCommand ) + { + TRACE_FUNC_ENTRY + if ( !IsPackageValid( aText ) ) + { + User::Leave( KErrArgument ); + } + + TBuf8 typeBuf; + TBuf8 + dataBuf; + + User::LeaveIfError( SplitPackage( aText, typeBuf, dataBuf ) ); + + THsRemoteControlCommandType cmdType = EHsLast; + User::LeaveIfError( RecognizeType( typeBuf, cmdType ) ); + + THsControlCommandData cmdData( dataBuf ); + + THsRemoteControlCommand tmpCommand( cmdData, cmdType ); + + THsRemoteControlCommand::Copy( tmpCommand, aCommand ); + TRACE_FUNC_EXIT + } + +TBool CHsRemoteControlParser::IsPackageValid( const TDesC8 &aData ) + { + return ( aData.Size() <= KHsRemoteControlPackageLength ) && ( aData.Find( + KHsRemoteControllerPackageDelim ) != KErrNotFound ); + } + +TInt CHsRemoteControlParser::SplitPackage( const TDesC8 &aData, + TDes8 &aTypePart, TDes8 &aDataPart ) + { + TRACE_FUNC_ENTRY + TInt err = KErrNone; + + TInt delimPos = aData.Find( KHsRemoteControllerPackageDelim ); + if ( delimPos != KErrNotFound ) + { + aTypePart.Copy( aData.Left( delimPos ) ); + aDataPart.Copy( aData.Right( aData.Length() - delimPos - 1 ) ); + } + else + { + err = KErrNotFound; + } + + TRACE_FUNC_EXIT + return err; + } + +TInt CHsRemoteControlParser::RecognizeType( const TDesC8 &aTypePart, + THsRemoteControlCommandType& aCommandType ) + { + TRACE_FUNC_ENTRY + TLex8 lex( aTypePart ); + TInt val; + TInt err = lex.Val( val ); + + aCommandType = (THsRemoteControlCommandType) val; + TRACE_FUNC_EXIT + return err; + } +