localconnectivityservice/legacymodemplugin/src/monitorspeakerparser.cpp
changeset 0 c3e98f10fcf4
equal deleted inserted replaced
-1:000000000000 0:c3e98f10fcf4
       
     1 /*
       
     2 * Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies).
       
     3 * All rights reserved.
       
     4 * This component and the accompanying materials are made available
       
     5 * under the terms of "Eclipse Public License v1.0"
       
     6 * which accompanies this distribution, and is available
       
     7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     8 *
       
     9 * Initial Contributors:
       
    10 * Nokia Corporation - initial contribution.
       
    11 *
       
    12 * Contributors:
       
    13 *
       
    14 * Description: Handles commands "ATL", "ATL0", "ATL1", "ATL2", "ATL3", "ATM",
       
    15 *              "ATM0", "ATM1" and "ATM2"
       
    16 *
       
    17 */
       
    18 
       
    19 #include "monitorspeakerparser.h"
       
    20 #include "debug.h"
       
    21 
       
    22 _LIT8( KAtlCmd,  "ATL"  );
       
    23 _LIT8( KAtl0Cmd, "ATL0" );
       
    24 _LIT8( KAtl1Cmd, "ATL1" );
       
    25 _LIT8( KAtl2Cmd, "ATL2" );
       
    26 _LIT8( KAtl3Cmd, "ATL3" );
       
    27 _LIT8( KAtmCmd,  "ATM"  );
       
    28 _LIT8( KAtm0Cmd, "ATM0" );
       
    29 _LIT8( KAtm1Cmd, "ATM1" );
       
    30 _LIT8( KAtm2Cmd, "ATM2" );
       
    31 
       
    32 // ---------------------------------------------------------------------------
       
    33 // Two-phased constructor.
       
    34 // ---------------------------------------------------------------------------
       
    35 //
       
    36 CMonitorSpeakerParser* CMonitorSpeakerParser::NewL(
       
    37     MLegacyModemPlugin* aCallback )
       
    38     {
       
    39     CMonitorSpeakerParser* self = new (ELeave) CMonitorSpeakerParser( aCallback );
       
    40     CleanupStack::PushL( self );
       
    41     self->ConstructL();
       
    42     CleanupStack::Pop( self );
       
    43     return self;
       
    44     }
       
    45 
       
    46 // ---------------------------------------------------------------------------
       
    47 // Destructor.
       
    48 // ---------------------------------------------------------------------------
       
    49 //
       
    50 CMonitorSpeakerParser::~CMonitorSpeakerParser()
       
    51     {
       
    52     }
       
    53 
       
    54 // ---------------------------------------------------------------------------
       
    55 // CHfpExtParserMisc::CHfpExtParserMisc
       
    56 // ---------------------------------------------------------------------------
       
    57 //
       
    58 CMonitorSpeakerParser::CMonitorSpeakerParser( MLegacyModemPlugin* aCallback ) :
       
    59     iCallback( aCallback )
       
    60     {
       
    61     iCmdHandlerType = ECmdHandlerTypeUndefined;
       
    62     iDetectedCmd = EDetectedCmdUndefined;
       
    63     }
       
    64 
       
    65 // ---------------------------------------------------------------------------
       
    66 // CHfpExtParserMisc::ConstructL
       
    67 // ---------------------------------------------------------------------------
       
    68 //
       
    69 void CMonitorSpeakerParser::ConstructL()
       
    70     {
       
    71     if ( !iCallback )
       
    72         {
       
    73         User::Leave( KErrGeneral );
       
    74         }
       
    75     }
       
    76 
       
    77 // ---------------------------------------------------------------------------
       
    78 // Checks if the command is speaker loudness command
       
    79 // ---------------------------------------------------------------------------
       
    80 //
       
    81 TBool CMonitorSpeakerParser::CheckSpeakerLoudnessCommand( const TDesC8& aCmd )
       
    82     {
       
    83     TRACE_FUNC_ENTRY
       
    84     // The ATL command only supports one type: base
       
    85     // The ATL0 command only supports one type: base
       
    86     // The ATL1 command only supports one type: base
       
    87     // The ATL2 command only supports one type: base
       
    88     // The ATL3 command only supports one type: base
       
    89     iCmdHandlerType = iCallback->CheckCommandType( KAtlCmd, aCmd );
       
    90     if ( iCmdHandlerType == ECmdHandlerTypeBase )
       
    91         {
       
    92         iDetectedCmd = EDetectedCmdATL;
       
    93         TRACE_FUNC_EXIT
       
    94         return ETrue;
       
    95         }
       
    96     iCmdHandlerType = iCallback->CheckCommandType( KAtl0Cmd, aCmd );
       
    97     if ( iCmdHandlerType == ECmdHandlerTypeBase )
       
    98         {
       
    99         iDetectedCmd = EDetectedCmdATL0;
       
   100         TRACE_FUNC_EXIT
       
   101         return ETrue;
       
   102         }
       
   103     iCmdHandlerType = iCallback->CheckCommandType( KAtl1Cmd, aCmd );
       
   104     if ( iCmdHandlerType == ECmdHandlerTypeBase )
       
   105         {
       
   106         iDetectedCmd = EDetectedCmdATL1;
       
   107         TRACE_FUNC_EXIT
       
   108         return ETrue;
       
   109         }
       
   110     iCmdHandlerType = iCallback->CheckCommandType( KAtl2Cmd, aCmd );
       
   111     if ( iCmdHandlerType == ECmdHandlerTypeBase )
       
   112         {
       
   113         iDetectedCmd = EDetectedCmdATL2;
       
   114         TRACE_FUNC_EXIT
       
   115         return ETrue;
       
   116         }
       
   117     iCmdHandlerType = iCallback->CheckCommandType( KAtl3Cmd, aCmd );
       
   118     if ( iCmdHandlerType == ECmdHandlerTypeBase )
       
   119         {
       
   120         iDetectedCmd = EDetectedCmdATL3;
       
   121         TRACE_FUNC_EXIT
       
   122         return ETrue;
       
   123         }
       
   124     TRACE_FUNC_EXIT
       
   125     return EFalse;
       
   126     }
       
   127 
       
   128 // ---------------------------------------------------------------------------
       
   129 // Checks if the command is speaker mode command
       
   130 // ---------------------------------------------------------------------------
       
   131 //
       
   132 TBool CMonitorSpeakerParser::CheckSpeakerModeCommand( const TDesC8& aCmd )
       
   133     {
       
   134     TRACE_FUNC_ENTRY
       
   135     // The ATM command only supports one type: base
       
   136     // The ATM0 command only supports one type: base
       
   137     // The ATM1 command only supports one type: base
       
   138     // The ATM2 command only supports one type: base
       
   139     iCmdHandlerType = iCallback->CheckCommandType( KAtmCmd, aCmd );
       
   140     if ( iCmdHandlerType == ECmdHandlerTypeBase )
       
   141         {
       
   142         iDetectedCmd = EDetectedCmdATM;
       
   143         TRACE_FUNC_EXIT
       
   144         return ETrue;
       
   145         }
       
   146     iCmdHandlerType = iCallback->CheckCommandType( KAtm0Cmd, aCmd );
       
   147     if ( iCmdHandlerType == ECmdHandlerTypeBase )
       
   148         {
       
   149         iDetectedCmd = EDetectedCmdATM0;
       
   150         TRACE_FUNC_EXIT
       
   151         return ETrue;
       
   152         }
       
   153     iCmdHandlerType = iCallback->CheckCommandType( KAtm1Cmd, aCmd );
       
   154     if ( iCmdHandlerType == ECmdHandlerTypeBase )
       
   155         {
       
   156         iDetectedCmd = EDetectedCmdATM1;
       
   157         TRACE_FUNC_EXIT
       
   158         return ETrue;
       
   159         }
       
   160     iCmdHandlerType = iCallback->CheckCommandType( KAtm2Cmd, aCmd );
       
   161     if ( iCmdHandlerType == ECmdHandlerTypeBase )
       
   162         {
       
   163         iDetectedCmd = EDetectedCmdATM2;
       
   164         TRACE_FUNC_EXIT
       
   165         return ETrue;
       
   166         }
       
   167     TRACE_FUNC_EXIT
       
   168     return EFalse;
       
   169     }
       
   170 
       
   171 // ---------------------------------------------------------------------------
       
   172 // Main command handler (leaving version)
       
   173 // ---------------------------------------------------------------------------
       
   174 //
       
   175 TBool CMonitorSpeakerParser::HandleCommandL()
       
   176     {
       
   177     TRACE_FUNC_ENTRY
       
   178     TBool cmdUnderstood = EFalse;
       
   179     // Just return "OK" for all detected commands
       
   180     if ( iDetectedCmd != EDetectedCmdUndefined )
       
   181         {
       
   182         iCallback->CreateReplyAndComplete( EReplyTypeOk );
       
   183         cmdUnderstood = ETrue;
       
   184         }
       
   185     TRACE_FUNC_EXIT
       
   186     return cmdUnderstood;
       
   187     }
       
   188 
       
   189 // ---------------------------------------------------------------------------
       
   190 // From CLegacyModemPluginBase.
       
   191 // Reports the support status of an AT command. This is a synchronous API.
       
   192 // ---------------------------------------------------------------------------
       
   193 //
       
   194 TBool CMonitorSpeakerParser::IsCommandSupported( const TDesC8& aCmd )
       
   195     {
       
   196     TRACE_FUNC_ENTRY
       
   197     TBool cmdUnderstood = EFalse;
       
   198     // Set all to undefined if either the command or its type is unknown
       
   199     // HandleCommand() should be round only when both are set
       
   200     cmdUnderstood = CheckSpeakerLoudnessCommand( aCmd );
       
   201     if ( cmdUnderstood )
       
   202         {
       
   203         TRACE_FUNC_EXIT
       
   204         return ETrue;
       
   205         }
       
   206     cmdUnderstood = CheckSpeakerModeCommand( aCmd );
       
   207     if ( cmdUnderstood )
       
   208         {
       
   209         TRACE_FUNC_EXIT
       
   210         return ETrue;
       
   211         }
       
   212     iCmdHandlerType = ECmdHandlerTypeUndefined;
       
   213     iDetectedCmd = EDetectedCmdUndefined;
       
   214     TRACE_FUNC_EXIT
       
   215     return EFalse;
       
   216     }
       
   217 
       
   218 // ---------------------------------------------------------------------------
       
   219 // From CLegacyModemPluginBase.
       
   220 // Handles an AT command. Cancelling of the pending request is done by
       
   221 // HandleCommandCancel(). The implementation in the extension plugin should
       
   222 // be asynchronous.
       
   223 // ---------------------------------------------------------------------------
       
   224 //
       
   225 void CMonitorSpeakerParser::HandleCommand( const TDesC8& /*aCmd*/,
       
   226                                            RBuf8& /*aReply*/,
       
   227                                            TBool aReplyNeeded )
       
   228     {
       
   229     TRACE_FUNC_ENTRY
       
   230     if ( !aReplyNeeded )
       
   231         {
       
   232         TRACE_FUNC_EXIT
       
   233         return;
       
   234         }
       
   235     // Checking the iDetectedCmd here means that the failure is the
       
   236     // failing cmd type (set/read/test) for the command, not the command
       
   237     // itself (when cmdUnderstood is EFalse)
       
   238     TBool cmdUnderstood = EFalse;
       
   239     TRAPD( retTrap, cmdUnderstood=HandleCommandL() )
       
   240     if ( !cmdUnderstood || retTrap!=KErrNone )
       
   241         {
       
   242         iCallback->CreateReplyAndComplete( EReplyTypeError );
       
   243         }
       
   244     TRACE_FUNC_EXIT
       
   245     }
       
   246 
       
   247 // ---------------------------------------------------------------------------
       
   248 // From CLegacyModemPluginBase.
       
   249 // Cancels a pending HandleCommand request.
       
   250 // ---------------------------------------------------------------------------
       
   251 //
       
   252 void CMonitorSpeakerParser::HandleCommandCancel()
       
   253     {
       
   254     TRACE_FUNC_ENTRY
       
   255     TRACE_FUNC_EXIT
       
   256     }