bluetoothengine/headsetsimulator/profiles/hfpprofile/src/dataprocessing/hfpdatahandler.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 #include "hfpdatahandler.h"
       
    21 #include "hfpcommandparser.h"
       
    22 #include "hfpcommand.h"
       
    23 #include "hfpfeaturemanager.h"
       
    24 #include "hfpsettings.h"
       
    25 #include "debug.h"
       
    26 
       
    27 CHsHFPDataHandler* CHsHFPDataHandler::NewL()
       
    28     {
       
    29 
       
    30     CHsHFPDataHandler *self = CHsHFPDataHandler::NewLC();
       
    31     CleanupStack::Pop( self );
       
    32 
       
    33     return self;
       
    34     }
       
    35 
       
    36 CHsHFPDataHandler* CHsHFPDataHandler::NewLC()
       
    37     {
       
    38 
       
    39     CHsHFPDataHandler *self = new ( ELeave ) CHsHFPDataHandler();
       
    40     CleanupStack::PushL( self );
       
    41     self->ConstructL();
       
    42     return self;
       
    43     }
       
    44 
       
    45 CHsHFPDataHandler::~CHsHFPDataHandler()
       
    46     {
       
    47     TRACE_FUNC_ENTRY
       
    48     if ( iFeatureManager )
       
    49         {
       
    50         delete iFeatureManager;
       
    51         }
       
    52 
       
    53     if ( iParser )
       
    54         {
       
    55         delete iParser;
       
    56         }
       
    57     TRACE_FUNC_EXIT
       
    58     }
       
    59 
       
    60 void CHsHFPDataHandler::ProcessDataL( const TDesC8& aDataIn,
       
    61         const TBool aFromAG, TDes8& aDataOut )
       
    62     {
       
    63     TRACE_FUNC_ENTRY
       
    64     if ( aDataIn.Compare( KNullDesC8 ) == 0 )
       
    65         {
       
    66         User::Leave( KErrArgument );
       
    67         }
       
    68 
       
    69     aDataOut.Zero();
       
    70 
       
    71     CDesC8ArrayFlat* cmdArr = SplitCommandsL( aDataIn );
       
    72     CleanupStack::PushL( cmdArr );
       
    73 
       
    74     CHsHFPCommand* cmdIn = CHsHFPCommand::NewL();
       
    75     CleanupStack::PushL( cmdIn );
       
    76 
       
    77     CHsHFPCommand* cmdOut = CHsHFPCommand::NewL();
       
    78     CleanupStack::PushL( cmdOut );
       
    79 
       
    80     RBuf8 buf, tmpOut;
       
    81 
       
    82     tmpOut.CreateL( KTmpBufferLength );
       
    83     tmpOut.CleanupClosePushL();
       
    84 
       
    85     for ( TInt i = 0; i < cmdArr->Count(); i++ )
       
    86         {
       
    87         buf.CreateL( cmdArr->MdcaPoint( i ) );
       
    88         buf.CleanupClosePushL();
       
    89         TRACE_INFO((_L8("DATA RETRIEVED FROM ARRAY: %S") , &buf))
       
    90 
       
    91         iParser->ParseL( buf, aFromAG, *cmdIn );
       
    92 
       
    93         iFeatureManager->PerformDataProcessingL( cmdIn, *cmdOut );
       
    94 
       
    95         cmdOut->ToDes8( tmpOut );
       
    96         aDataOut.Append( tmpOut );
       
    97         CleanupStack::PopAndDestroy( &buf );
       
    98         }    
       
    99     CleanupStack::PopAndDestroy( &tmpOut );
       
   100     CleanupStack::PopAndDestroy( cmdOut );
       
   101     CleanupStack::PopAndDestroy( cmdIn );
       
   102     CleanupStack::PopAndDestroy( cmdArr );
       
   103     
       
   104     TRACE_FUNC_EXIT
       
   105     }
       
   106 
       
   107 void CHsHFPDataHandler::HandleClientDisconnected( TInt aErr )
       
   108     {
       
   109     TRACE_FUNC_ENTRY
       
   110     iFeatureManager->HandleClientDisconnected( aErr );
       
   111     TRACE_FUNC_EXIT
       
   112     }
       
   113 
       
   114 void CHsHFPDataHandler::HandleClientConnected( TDes8& aCommandOut )
       
   115     {
       
   116     TRACE_FUNC_ENTRY
       
   117     TRAP_IGNORE( iFeatureManager->HandleClientConnectedL( aCommandOut ) );
       
   118     TRACE_FUNC_EXIT
       
   119     }
       
   120 
       
   121 void CHsHFPDataHandler::HandleAcceptCallL( TDes8& aCommandOut )
       
   122     {
       
   123     TRACE_FUNC_ENTRY
       
   124 
       
   125     PerformRequestL( _L8("ATA\r\n"), aCommandOut );
       
   126     TRACE_FUNC_EXIT
       
   127     }
       
   128 
       
   129 void CHsHFPDataHandler::HandleReleaseCallL( TDes8& aCommandOut )
       
   130     {
       
   131     TRACE_FUNC_ENTRY
       
   132     PerformRequestL( _L8("AT+CHUP\r\n"), aCommandOut );
       
   133     TRACE_FUNC_EXIT
       
   134     }
       
   135 
       
   136 CHsHFPDataHandler::CHsHFPDataHandler()
       
   137     {
       
   138 
       
   139     }
       
   140 
       
   141 void CHsHFPDataHandler::ConstructL()
       
   142     {
       
   143     TRACE_FUNC_ENTRY
       
   144     iFeatureManager = CHsHFPFeatureManager::NewL();
       
   145 
       
   146     iParser = CHsHFPParser::NewL();
       
   147     TRACE_FUNC_EXIT
       
   148     }
       
   149 
       
   150 CDesC8ArrayFlat* CHsHFPDataHandler::SplitCommandsL( const TDesC8 &aCommands )
       
   151     {
       
   152     TRACE_FUNC_ENTRY
       
   153     CDesC8ArrayFlat* array = new ( ELeave ) CDesC8ArrayFlat(
       
   154             KCommandArrayGranularity );
       
   155 
       
   156     RBuf8 buf;
       
   157     buf.CreateL( aCommands );
       
   158     buf.CleanupClosePushL();
       
   159 
       
   160     const TInt offset = 2;
       
   161 
       
   162     while ( buf.Size() > 0 )
       
   163         {
       
   164         TInt pos = buf.Find( KHsHFPCommandSeparator );
       
   165 
       
   166         if ( pos == KErrNotFound )
       
   167             {
       
   168             array->AppendL( buf );
       
   169             buf.Zero();
       
   170             }
       
   171         else
       
   172             {
       
   173 
       
   174             TPtrC8 ptr = buf.Left( pos + offset );
       
   175             array->AppendL( ptr );
       
   176             buf.Delete( 0, pos + offset );
       
   177             }
       
   178         }
       
   179     CleanupStack::PopAndDestroy( &buf );
       
   180 
       
   181     TRACE_FUNC_EXIT
       
   182     return array;
       
   183     }
       
   184 
       
   185 void CHsHFPDataHandler::PerformRequestL( const TDesC8& aCommand,
       
   186         TDes8& aResponse )
       
   187     {
       
   188     TRACE_FUNC_ENTRY
       
   189     CHsHFPCommand* cmdIn = CHsHFPCommand::NewL();
       
   190     CleanupStack::PushL( cmdIn );
       
   191     CHsHFPCommand* cmdOut = CHsHFPCommand::NewL();
       
   192     CleanupStack::PushL( cmdOut );
       
   193 
       
   194     RBuf8 buf;
       
   195     buf.CreateL( aCommand );
       
   196     buf.CleanupClosePushL();
       
   197 
       
   198     iParser->ParseL( buf, EFalse, *cmdIn );
       
   199 
       
   200     iFeatureManager->PerformDataProcessingL( cmdIn, *cmdOut );
       
   201     cmdOut->ToDes8( aResponse );
       
   202 
       
   203     CleanupStack::PopAndDestroy( &buf );
       
   204     CleanupStack::PopAndDestroy( &cmdOut );
       
   205     CleanupStack::PopAndDestroy( &cmdIn );
       
   206     TRACE_FUNC_EXIT
       
   207     }
       
   208