bluetoothengine/headsetsimulator/profiles/hspprofile/src/dataprocessing/hspdatahandler.cpp
branchheadsetsimulator
changeset 60 90dbfc0435e3
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/bluetoothengine/headsetsimulator/profiles/hspprofile/src/dataprocessing/hspdatahandler.cpp	Wed Sep 15 15:59:44 2010 +0200
@@ -0,0 +1,205 @@
+/* 
+ *
+ * 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 "hspdatahandler.h"
+#include "hspcommandparser.h"
+#include "hspcommand.h"
+#include "hspfeaturemanager.h"
+#include "hspsettings.h"
+#include "debug.h"
+
+CHsHSPDataHandler* CHsHSPDataHandler::NewL()
+    {
+
+    CHsHSPDataHandler *self = CHsHSPDataHandler::NewLC();
+    CleanupStack::Pop( self );
+
+    return self;
+    }
+
+CHsHSPDataHandler* CHsHSPDataHandler::NewLC()
+    {
+
+    CHsHSPDataHandler *self = new ( ELeave ) CHsHSPDataHandler();
+    CleanupStack::PushL( self );
+    self->ConstructL();
+    return self;
+    }
+
+CHsHSPDataHandler::~CHsHSPDataHandler()
+    {
+    TRACE_FUNC_ENTRY
+    if ( iFeatureManager )
+        {
+        delete iFeatureManager;
+        }
+
+    if ( iParser )
+        {
+        delete iParser;
+        }
+    
+    TRACE_FUNC_EXIT
+    }
+
+void CHsHSPDataHandler::ProcessDataL( const TDesC8& aDataIn,
+        const TBool aFromAG, TDes8& aDataOut )
+    {
+    TRACE_FUNC_ENTRY
+    if ( aDataIn.Compare( KNullDesC8 ) == 0 )
+        {
+        User::Leave( KErrArgument );
+        }
+
+    aDataOut.Zero();
+
+    CDesC8ArrayFlat* cmdArr = SplitCommandsL( aDataIn );
+    CleanupStack::PushL( cmdArr );
+
+    CHsHSPCommand* cmdIn = CHsHSPCommand::NewL();
+    CleanupStack::PushL( cmdIn );
+
+    CHsHSPCommand* cmdOut = CHsHSPCommand::NewL();
+    CleanupStack::PushL( cmdOut );
+
+    RBuf8 buf, tmpOut;
+    tmpOut.CreateL( KTmpBufferLength );
+    buf.CleanupClosePushL();
+    tmpOut.CleanupClosePushL();
+
+    for ( TInt i = 0; i < cmdArr->Count(); i++ )
+        {
+        buf.CreateL( cmdArr->MdcaPoint( i ) );
+
+        iParser->ParseL( buf, aFromAG, *cmdIn );
+
+        iFeatureManager->PerformDataProcessingL( cmdIn, *cmdOut );
+
+        cmdOut->ToDes8( tmpOut );
+        aDataOut.Append( tmpOut );
+        buf.Close();
+        }
+
+    CleanupStack::PopAndDestroy( &tmpOut );
+    CleanupStack::PopAndDestroy( &buf );
+    CleanupStack::PopAndDestroy( cmdOut );
+    CleanupStack::PopAndDestroy( cmdIn );
+    CleanupStack::PopAndDestroy( cmdArr );
+
+    TRACE_FUNC_EXIT
+    }
+
+void CHsHSPDataHandler::HandleClientDisconnected( TInt aErr )
+    {
+    iFeatureManager->HandleClientDisconnected( aErr );
+    }
+
+void CHsHSPDataHandler::HandleClientConnected( TDes8& aCommandOut )
+    {
+    TRACE_FUNC_ENTRY
+    iFeatureManager->HandleClientConnected( aCommandOut );
+    TRACE_FUNC_EXIT
+    }
+
+void CHsHSPDataHandler::HandleAcceptCallL( TDes8& aCommandOut )
+    {
+    TRACE_FUNC_ENTRY
+
+    PerformRequestL( KHSPCallAcceptCmd, aCommandOut );
+    TRACE_FUNC_EXIT
+    }
+
+void CHsHSPDataHandler::HandleReleaseCallL( TDes8& aCommandOut )
+    {
+    TRACE_FUNC_ENTRY
+    PerformRequestL( KHSPCallReleaseCmd, aCommandOut );
+    TRACE_FUNC_EXIT
+    }
+
+CHsHSPDataHandler::CHsHSPDataHandler()
+    {
+
+    }
+
+void CHsHSPDataHandler::ConstructL()
+    {
+    TRACE_FUNC_ENTRY
+    iFeatureManager = CHsHSPFeatureManager::NewL();
+    iParser = CHsHSPParser::NewL();
+    TRACE_FUNC_EXIT
+    }
+
+CDesC8ArrayFlat* CHsHSPDataHandler::SplitCommandsL( const TDesC8 &aCommands )
+    {
+    CDesC8ArrayFlat* array = new ( ELeave ) CDesC8ArrayFlat(
+            KCommandArrayGranularity );
+    CleanupStack::PushL( array );
+    RBuf8 buf;
+    buf.CreateL( aCommands );
+    buf.CleanupClosePushL();
+
+    const TInt offset = 2;
+
+    while ( buf.Size() > 0 )
+        {
+        TInt pos = buf.Find( KHsHSPCommandSeparator );
+
+        if ( pos == KErrNotFound )
+            {
+            array->AppendL( buf );
+            buf.Zero();
+            }
+        else
+            {
+
+            TPtrC8 ptr = ( buf.Left( pos + offset ) );
+            array->AppendL( ptr );
+            buf.Delete( 0, pos + offset );
+            }
+        }
+
+    CleanupStack::PopAndDestroy( &buf );
+    CleanupStack::Pop( array );
+
+    return array;
+    }
+
+void CHsHSPDataHandler::PerformRequestL( const TDesC8& aCommand,
+        TDes8& aResponse )
+    {
+    CHsHSPCommand* cmdIn = CHsHSPCommand::NewL();
+    CleanupStack::PushL( cmdIn );
+    CHsHSPCommand* cmdOut = CHsHSPCommand::NewL();
+    CleanupStack::PushL( cmdOut );
+
+    RBuf8 buf;
+    buf.CreateL( aCommand );
+    buf.CleanupClosePushL();
+
+    iParser->ParseL( buf, EFalse, *cmdIn );
+
+    iFeatureManager->PerformDataProcessingL( cmdIn, *cmdOut );
+    cmdOut->ToDes8( aResponse );
+
+    CleanupStack::PopAndDestroy( &buf );
+    CleanupStack::PopAndDestroy( cmdOut );
+    CleanupStack::PopAndDestroy( cmdIn );
+    }
+