bluetoothengine/headsetsimulator/profiles/hspprofile/src/dataprocessing/hspcommand.cpp
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/bluetoothengine/headsetsimulator/profiles/hspprofile/src/dataprocessing/hspcommand.cpp Wed Sep 15 15:59:44 2010 +0200
@@ -0,0 +1,231 @@
+/*
+ *
+ * Copyright (c) <2010> Comarch S.A. and/or its subsidiary(-ies).
+ * All rights reserved.
+ * This component and the accompanying materials are made available
+ * under the terms of the License "Eclipse Public License v1.0"
+ * which accompanies this distribution, and is available
+ * at the URL "http://www.eclipse.org/legal/epl-v10.html".
+ *
+ * Original Contributors:
+ * Comarch S.A. - original contribution.
+ *
+ * Contributors:
+ *
+ * Description:
+ *
+ */
+
+#include <badesca.h>
+
+#include "hspcommand.h"
+#include "debug.h"
+
+TATParam::TATParam( const TDesC8& aValue )
+
+ {
+ iValue.Copy( aValue );
+ }
+
+const TDesC8& TATParam::Des() const
+ {
+ return iValue;
+ }
+
+TInt TATParam::IntL() const
+ {
+ TLex8 lex( iValue );
+ TInt res = KErrNotFound;
+ User::LeaveIfError( lex.Val( res ) );
+
+ return res;
+
+ }
+
+CHsHSPCommand* CHsHSPCommand::NewL()
+ {
+ CHsHSPCommand *self = CHsHSPCommand::NewLC();
+ CleanupStack::Pop( self );
+
+ return self;
+ }
+
+CHsHSPCommand* CHsHSPCommand::NewLC()
+ {
+
+ CHsHSPCommand *self = new ( ELeave ) CHsHSPCommand();
+ CleanupStack::PushL( self );
+ self->ConstructL();
+ return self;
+ }
+
+CHsHSPCommand::~CHsHSPCommand()
+ {
+ iParams.Close();
+ iModeDes.Close();
+ iParamsDes.Close();
+ iTypeDes.Close();
+ }
+
+TInt CHsHSPCommand::SetType( const THsHSPCommandType aType )
+ {
+ iType = aType;
+
+ switch ( iType )
+ {
+ case EHSPCmdRING:
+ iTypeDes.Copy( KHsHSPRINGCommand );
+ break;
+ case EHSPCmdVGS:
+ iTypeDes.Copy( KHsHSPVGSCommand );
+ break;
+ case EHSPCmdVGM:
+ iTypeDes.Copy( KHsHSPVGMCommand );
+ break;
+ case EHSPCmdCKPD:
+ iTypeDes.Copy( KHsHSPCKPDCommand );
+ break;
+ default:
+ return KErrArgument;
+
+ }
+ return KErrNone;
+ }
+
+TInt CHsHSPCommand::SetMode( const THsHSPCommandMode aMode )
+ {
+ iMode = aMode;
+ switch ( iMode )
+ {
+ case ECmdModeRead:
+ iModeDes.Copy( KHsHSPATReadModeDes );
+ break;
+ case ECmdModeWrite:
+ iModeDes.Copy( KHsHSPATWriteModeDes );
+ break;
+ case ECmdModeTest:
+ iModeDes.Copy( KHsHSPATTestModeDes );
+ break;
+ case ECmdModeNormal:
+ iModeDes.Copy( KNullDesC8 );
+ break;
+ case ECmdModeOther:
+ iModeDes.Copy( KNullDesC8 );
+ break;
+ default:
+ return KErrArgument;
+ }
+
+ return KErrNone;
+ }
+
+TInt CHsHSPCommand::SetParams( const RATParamArray& aParams )
+ {
+ TRACE_FUNC_ENTRY
+
+ TInt res = KErrNone;
+ if ( aParams.Count() > 0 )
+ {
+ iParams.Reset();
+ iParams = aParams;
+
+ for ( TInt i = 0; i < iParams.Count() - 1; i++ )
+ {
+
+ iParamsDes.Append( iParams[i].Des() );
+ iParamsDes.Append( KHsHSPParamsSeparator );
+ }
+
+ iParamsDes.Append( iParams[iParams.Count() - 1].Des() );
+
+ }
+ else
+ res = KErrArgument;
+
+ TRACE_FUNC_EXIT
+ return res;
+ }
+
+void CHsHSPCommand::SetSource( const TBool aFromAG )
+ {
+ iFromAG = aFromAG;
+ }
+
+void CHsHSPCommand::ToDes8( TDes8& aBuf ) const
+ {
+
+ if ( iMode == ECmdModeNormal )
+ {
+ aBuf.Copy( KHsHSPCommandPrefix );
+ aBuf.Append( iTypeDes );
+ aBuf.Append( KHsHSPCommandSuffix );
+ }
+
+ else if ( iType != EHSPCmdUnknown )
+ {
+ aBuf.Copy( KHsHSPCommandPrefix );
+ aBuf.Append( iTypeDes );
+ aBuf.Append( iModeDes );
+ aBuf.Append( iParamsDes );
+ aBuf.Append( KHsHSPCommandSuffix );
+ }
+ else
+ {
+ aBuf.Zero();
+ }
+
+ TRACE_INFO((_L8("COMMAND TO DES: %S"),&aBuf));
+ }
+
+THsHSPCommandType CHsHSPCommand::Type() const
+ {
+ return iType;
+ }
+
+THsHSPCommandMode CHsHSPCommand::Mode() const
+ {
+ return iMode;
+ }
+
+TBool CHsHSPCommand::FromAG() const
+ {
+ return iFromAG;
+ }
+
+const RATParamArray CHsHSPCommand::Params() const
+ {
+ return iParams;
+ }
+
+void CHsHSPCommand::CopyL( const CHsHSPCommand* aCmdFrom, CHsHSPCommand& aCmdTo )
+ {
+ aCmdTo.iMode = aCmdFrom->iMode;
+ aCmdTo.iType = aCmdFrom->iType;
+
+ aCmdTo.iParams.Reset();
+ for ( TInt i = 0; i < aCmdFrom->iParams.Count(); i++ )
+ {
+ aCmdTo.iParams.AppendL( aCmdFrom->iParams[i] );
+ }
+
+ aCmdTo.iFromAG = aCmdFrom->iFromAG;
+
+ aCmdTo.iModeDes.Copy( aCmdFrom->iModeDes );
+ aCmdTo.iTypeDes.Copy( aCmdFrom->iTypeDes );
+ aCmdTo.iParamsDes.Copy( aCmdFrom->iParamsDes );
+
+ }
+
+CHsHSPCommand::CHsHSPCommand() :
+ iType( EHSPCmdUnknown ), iParams( KParamArrayGranularity )
+ {
+
+ }
+
+void CHsHSPCommand::ConstructL()
+ {
+ iModeDes.CreateL( KModeDesMaxLength );
+ iTypeDes.CreateL( KTypeDesMaxLength );
+ iParamsDes.CreateL( KParamsDesMaxLength );
+
+ }