bluetoothengine/headsetsimulator/profiles/hspprofile/src/dataprocessing/hspdatahandler.cpp
branchheadsetsimulator
changeset 60 90dbfc0435e3
equal deleted inserted replaced
59:02103bf20ee5 60:90dbfc0435e3
       
     1 /* 
       
     2  *
       
     3  * Copyright (c) <2010> Comarch S.A. and/or its subsidiary(-ies).
       
     4  * All rights reserved.
       
     5  * This component and the accompanying materials are made available
       
     6  * under the terms of the License "Eclipse Public License v1.0"
       
     7  * which accompanies this distribution, and is available
       
     8  * at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     9  *
       
    10  * Original Contributors:
       
    11  * Comarch S.A. - original contribution.
       
    12  *
       
    13  * Contributors:
       
    14  *
       
    15  * Description:
       
    16  *
       
    17  */
       
    18 
       
    19 #include <badesca.h>
       
    20 
       
    21 #include "hspdatahandler.h"
       
    22 #include "hspcommandparser.h"
       
    23 #include "hspcommand.h"
       
    24 #include "hspfeaturemanager.h"
       
    25 #include "hspsettings.h"
       
    26 #include "debug.h"
       
    27 
       
    28 CHsHSPDataHandler* CHsHSPDataHandler::NewL()
       
    29     {
       
    30 
       
    31     CHsHSPDataHandler *self = CHsHSPDataHandler::NewLC();
       
    32     CleanupStack::Pop( self );
       
    33 
       
    34     return self;
       
    35     }
       
    36 
       
    37 CHsHSPDataHandler* CHsHSPDataHandler::NewLC()
       
    38     {
       
    39 
       
    40     CHsHSPDataHandler *self = new ( ELeave ) CHsHSPDataHandler();
       
    41     CleanupStack::PushL( self );
       
    42     self->ConstructL();
       
    43     return self;
       
    44     }
       
    45 
       
    46 CHsHSPDataHandler::~CHsHSPDataHandler()
       
    47     {
       
    48     TRACE_FUNC_ENTRY
       
    49     if ( iFeatureManager )
       
    50         {
       
    51         delete iFeatureManager;
       
    52         }
       
    53 
       
    54     if ( iParser )
       
    55         {
       
    56         delete iParser;
       
    57         }
       
    58     
       
    59     TRACE_FUNC_EXIT
       
    60     }
       
    61 
       
    62 void CHsHSPDataHandler::ProcessDataL( const TDesC8& aDataIn,
       
    63         const TBool aFromAG, TDes8& aDataOut )
       
    64     {
       
    65     TRACE_FUNC_ENTRY
       
    66     if ( aDataIn.Compare( KNullDesC8 ) == 0 )
       
    67         {
       
    68         User::Leave( KErrArgument );
       
    69         }
       
    70 
       
    71     aDataOut.Zero();
       
    72 
       
    73     CDesC8ArrayFlat* cmdArr = SplitCommandsL( aDataIn );
       
    74     CleanupStack::PushL( cmdArr );
       
    75 
       
    76     CHsHSPCommand* cmdIn = CHsHSPCommand::NewL();
       
    77     CleanupStack::PushL( cmdIn );
       
    78 
       
    79     CHsHSPCommand* cmdOut = CHsHSPCommand::NewL();
       
    80     CleanupStack::PushL( cmdOut );
       
    81 
       
    82     RBuf8 buf, tmpOut;
       
    83     tmpOut.CreateL( KTmpBufferLength );
       
    84     buf.CleanupClosePushL();
       
    85     tmpOut.CleanupClosePushL();
       
    86 
       
    87     for ( TInt i = 0; i < cmdArr->Count(); i++ )
       
    88         {
       
    89         buf.CreateL( cmdArr->MdcaPoint( i ) );
       
    90 
       
    91         iParser->ParseL( buf, aFromAG, *cmdIn );
       
    92 
       
    93         iFeatureManager->PerformDataProcessingL( cmdIn, *cmdOut );
       
    94 
       
    95         cmdOut->ToDes8( tmpOut );
       
    96         aDataOut.Append( tmpOut );
       
    97         buf.Close();
       
    98         }
       
    99 
       
   100     CleanupStack::PopAndDestroy( &tmpOut );
       
   101     CleanupStack::PopAndDestroy( &buf );
       
   102     CleanupStack::PopAndDestroy( cmdOut );
       
   103     CleanupStack::PopAndDestroy( cmdIn );
       
   104     CleanupStack::PopAndDestroy( cmdArr );
       
   105 
       
   106     TRACE_FUNC_EXIT
       
   107     }
       
   108 
       
   109 void CHsHSPDataHandler::HandleClientDisconnected( TInt aErr )
       
   110     {
       
   111     iFeatureManager->HandleClientDisconnected( aErr );
       
   112     }
       
   113 
       
   114 void CHsHSPDataHandler::HandleClientConnected( TDes8& aCommandOut )
       
   115     {
       
   116     TRACE_FUNC_ENTRY
       
   117     iFeatureManager->HandleClientConnected( aCommandOut );
       
   118     TRACE_FUNC_EXIT
       
   119     }
       
   120 
       
   121 void CHsHSPDataHandler::HandleAcceptCallL( TDes8& aCommandOut )
       
   122     {
       
   123     TRACE_FUNC_ENTRY
       
   124 
       
   125     PerformRequestL( KHSPCallAcceptCmd, aCommandOut );
       
   126     TRACE_FUNC_EXIT
       
   127     }
       
   128 
       
   129 void CHsHSPDataHandler::HandleReleaseCallL( TDes8& aCommandOut )
       
   130     {
       
   131     TRACE_FUNC_ENTRY
       
   132     PerformRequestL( KHSPCallReleaseCmd, aCommandOut );
       
   133     TRACE_FUNC_EXIT
       
   134     }
       
   135 
       
   136 CHsHSPDataHandler::CHsHSPDataHandler()
       
   137     {
       
   138 
       
   139     }
       
   140 
       
   141 void CHsHSPDataHandler::ConstructL()
       
   142     {
       
   143     TRACE_FUNC_ENTRY
       
   144     iFeatureManager = CHsHSPFeatureManager::NewL();
       
   145     iParser = CHsHSPParser::NewL();
       
   146     TRACE_FUNC_EXIT
       
   147     }
       
   148 
       
   149 CDesC8ArrayFlat* CHsHSPDataHandler::SplitCommandsL( const TDesC8 &aCommands )
       
   150     {
       
   151     CDesC8ArrayFlat* array = new ( ELeave ) CDesC8ArrayFlat(
       
   152             KCommandArrayGranularity );
       
   153     CleanupStack::PushL( array );
       
   154     RBuf8 buf;
       
   155     buf.CreateL( aCommands );
       
   156     buf.CleanupClosePushL();
       
   157 
       
   158     const TInt offset = 2;
       
   159 
       
   160     while ( buf.Size() > 0 )
       
   161         {
       
   162         TInt pos = buf.Find( KHsHSPCommandSeparator );
       
   163 
       
   164         if ( pos == KErrNotFound )
       
   165             {
       
   166             array->AppendL( buf );
       
   167             buf.Zero();
       
   168             }
       
   169         else
       
   170             {
       
   171 
       
   172             TPtrC8 ptr = ( buf.Left( pos + offset ) );
       
   173             array->AppendL( ptr );
       
   174             buf.Delete( 0, pos + offset );
       
   175             }
       
   176         }
       
   177 
       
   178     CleanupStack::PopAndDestroy( &buf );
       
   179     CleanupStack::Pop( array );
       
   180 
       
   181     return array;
       
   182     }
       
   183 
       
   184 void CHsHSPDataHandler::PerformRequestL( const TDesC8& aCommand,
       
   185         TDes8& aResponse )
       
   186     {
       
   187     CHsHSPCommand* cmdIn = CHsHSPCommand::NewL();
       
   188     CleanupStack::PushL( cmdIn );
       
   189     CHsHSPCommand* cmdOut = CHsHSPCommand::NewL();
       
   190     CleanupStack::PushL( cmdOut );
       
   191 
       
   192     RBuf8 buf;
       
   193     buf.CreateL( aCommand );
       
   194     buf.CleanupClosePushL();
       
   195 
       
   196     iParser->ParseL( buf, EFalse, *cmdIn );
       
   197 
       
   198     iFeatureManager->PerformDataProcessingL( cmdIn, *cmdOut );
       
   199     cmdOut->ToDes8( aResponse );
       
   200 
       
   201     CleanupStack::PopAndDestroy( &buf );
       
   202     CleanupStack::PopAndDestroy( cmdOut );
       
   203     CleanupStack::PopAndDestroy( cmdIn );
       
   204     }
       
   205