localconnectivityservice/dun/atext/src/DunAtSpecialCmdHandler.cpp
branchRCL_3
changeset 39 4096754ee773
parent 38 3dcb815346df
child 40 52a167391590
equal deleted inserted replaced
38:3dcb815346df 39:4096754ee773
     1 /*
       
     2 * Copyright (c) 2010 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:  Special AT command handler
       
    15 *
       
    16 */
       
    17 
       
    18 #include "DunAtSpecialCmdHandler.h"
       
    19 #include "DunDebug.h"
       
    20 
       
    21 const TInt KDefaultGranularity = 1;
       
    22 
       
    23 // AT command(s) below is part of the AT&FE0Q0V1&C1&D2+IFC=3,1. command which
       
    24 // is sent by MAC. There is no delimiter between "AT&F" and "E0".
       
    25 // Only list those commands where alphabetical boundary detection is needed
       
    26 // (i.e. "AT&F0" is not needed as "AT&F0E0" has non-alphabetical boundary)
       
    27 _LIT8( KSpecialATCmd1, "AT&F" );
       
    28 
       
    29 // ---------------------------------------------------------------------------
       
    30 // Two-phased constructor.
       
    31 // ---------------------------------------------------------------------------
       
    32 //
       
    33 CDunAtSpecialCmdHandler* CDunAtSpecialCmdHandler::NewL()
       
    34     {
       
    35     CDunAtSpecialCmdHandler* self = new (ELeave) CDunAtSpecialCmdHandler();
       
    36     CleanupStack::PushL( self );
       
    37     self->ConstructL();
       
    38     CleanupStack::Pop( self );
       
    39     return self;
       
    40     }
       
    41 
       
    42 // ---------------------------------------------------------------------------
       
    43 // CDunAtSpecialCmdHandler::CDunAtSpecialCmdHandler
       
    44 // ---------------------------------------------------------------------------
       
    45 //
       
    46 CDunAtSpecialCmdHandler::CDunAtSpecialCmdHandler()
       
    47     {
       
    48     }
       
    49 
       
    50 // ---------------------------------------------------------------------------
       
    51 // CDunAtSpecialCmdHandler::ConstructL
       
    52 // ---------------------------------------------------------------------------
       
    53 //
       
    54 void CDunAtSpecialCmdHandler::ConstructL()
       
    55     {
       
    56     iSpecialCmds = new (ELeave) CDesC8ArrayFlat( KDefaultGranularity );
       
    57     // Add here all special commands which need to be handled
       
    58     iSpecialCmds->AppendL( KSpecialATCmd1 );
       
    59     }
       
    60 
       
    61 // ---------------------------------------------------------------------------
       
    62 // Destructor.
       
    63 // ---------------------------------------------------------------------------
       
    64 //
       
    65 CDunAtSpecialCmdHandler::~CDunAtSpecialCmdHandler()
       
    66     {
       
    67     FTRACE(FPrint( _L("CDunAtSpecialCmdHandler::~CDunAtSpecialCmdHandler()") ));
       
    68     delete iSpecialCmds;
       
    69     FTRACE(FPrint( _L("CDunAtSpecialCmdHandler::~CDunAtSpecialCmdHandler() complete") ));
       
    70     }
       
    71 
       
    72 // ---------------------------------------------------------------------------
       
    73 // Checks if the command has to be treated special way.
       
    74 // For example in case of MAC, it sends command AT&FE0Q0V1&C1&D2+IFC=3,1.
       
    75 // meaning there is no delimiters in the command.
       
    76 // In case of MAC we try to search AT&F (sub command) string from the beginning
       
    77 // of the command.
       
    78 // Search is done character by character basis.
       
    79 // ---------------------------------------------------------------------------
       
    80 //
       
    81 TBool CDunAtSpecialCmdHandler::IsCompleteSubCommand( TChar aCharacter )
       
    82     {
       
    83     FTRACE(FPrint( _L("CDunAtSpecialCmdHandler::IsCompleteSubCommand()") ));
       
    84     iBuffer.Append( aCharacter );
       
    85     TBool completeSubCmd = EFalse;
       
    86 
       
    87     if( !IsDataReadyForComparison(iBuffer.Length()) )
       
    88         {
       
    89         // No need to do comparison because we don't have correct amount of data
       
    90         FTRACE(FPrint( _L("CDunAtSpecialCmdHandler::IsCompleteSubCommand(), no need to compare") ));
       
    91         return completeSubCmd;
       
    92         }
       
    93 
       
    94     TInt count = iSpecialCmds->Count();
       
    95     for ( TInt i=0; i<count; i++ )
       
    96         {
       
    97         if( iSpecialCmds->MdcaPoint(i).Compare(iBuffer) == 0 )
       
    98             {
       
    99             FTRACE(FPrint( _L("CDunAtSpecialCmdHandler::IsCompleteSubCommand(), match found, cmd index %d"), i ));
       
   100             // Reset internal buffer for next comparison.
       
   101             ResetComparisonBuffer();
       
   102             completeSubCmd = ETrue;
       
   103             break;
       
   104             }
       
   105         }
       
   106     FTRACE(FPrint( _L("CDunAtSpecialCmdHandler::IsCompleteSubCommand() complete") ));
       
   107     return completeSubCmd;
       
   108     }
       
   109 
       
   110 // ---------------------------------------------------------------------------
       
   111 // Resets the buffer used for comparisons
       
   112 // ---------------------------------------------------------------------------
       
   113 //
       
   114 void CDunAtSpecialCmdHandler::ResetComparisonBuffer()
       
   115     {
       
   116     FTRACE(FPrint( _L("CDunAtSpecialCmdHandler::ResetComparisonBuffer()") ));
       
   117     iBuffer.FillZ();
       
   118     iBuffer.Zero();
       
   119     FTRACE(FPrint( _L("CDunAtSpecialCmdHandler::ResetComparisonBuffer() complete") ));
       
   120     }
       
   121 
       
   122 // ---------------------------------------------------------------------------
       
   123 // Defines when comparison is excecuted, checks if the data lengths are equal.
       
   124 // ---------------------------------------------------------------------------
       
   125 //
       
   126 TBool CDunAtSpecialCmdHandler::IsDataReadyForComparison( TInt aLength )
       
   127     {
       
   128     FTRACE(FPrint( _L("CDunAtSpecialCmdHandler::IsDataReadyForComparison()") ));
       
   129     TInt count = iSpecialCmds->Count();
       
   130     for ( TInt i=0; i<count; i++ )
       
   131         {
       
   132         if( iSpecialCmds->MdcaPoint(i).Length() == aLength )
       
   133             {
       
   134             FTRACE(FPrint( _L("CDunAtSpecialCmdHandler::IsDataReadyForComparison() (ready) complete") ));
       
   135             return ETrue;
       
   136             }
       
   137         }
       
   138     FTRACE(FPrint( _L("CDunAtSpecialCmdHandler::IsDataReadyForComparison() (not ready) complete") ));
       
   139     return EFalse;
       
   140     }
       
   141 
       
   142 // ---------------------------------------------------------------------------
       
   143 // Defines minimum length of the special commands.
       
   144 // ---------------------------------------------------------------------------
       
   145 //
       
   146 TInt CDunAtSpecialCmdHandler::MinimumLength()
       
   147     {
       
   148     FTRACE(FPrint( _L("CDunAtSpecialCmdHandler::MinimumLength()") ));
       
   149     TInt length = iSpecialCmds->MdcaPoint(0).Length();
       
   150     TInt count = iSpecialCmds->Count();
       
   151     for ( TInt i=1; i<count; i++ )
       
   152         {
       
   153         if( iSpecialCmds->MdcaPoint(i).Length() < length )
       
   154             {
       
   155             length = iSpecialCmds->MdcaPoint(i).Length();
       
   156             break;
       
   157             }
       
   158         }
       
   159     FTRACE(FPrint( _L("CDunAtSpecialCmdHandler::MinimumLength() complete") ));
       
   160     return length;
       
   161     }