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