localconnectivityservice/dun/atext/src/DunAtSpecialCmdHandler.cpp
branchRCL_3
changeset 20 2553637c2525
parent 12 031b9cffe6e4
equal deleted inserted replaced
19:2702348f1fe7 20:2553637c2525
     1 /*
     1 /*
     2 * Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies).
     2 * Copyright (c) 2010 Nokia Corporation and/or its subsidiary(-ies).
     3 * All rights reserved.
     3 * All rights reserved.
     4 * This component and the accompanying materials are made available
     4 * This component and the accompanying materials are made available
     5 * under the terms of "Eclipse Public License v1.0"
     5 * under the terms of "Eclipse Public License v1.0"
     6 * which accompanies this distribution, and is available
     6 * which accompanies this distribution, and is available
     7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
     7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
    16 */
    16 */
    17 
    17 
    18 #include "DunAtSpecialCmdHandler.h"
    18 #include "DunAtSpecialCmdHandler.h"
    19 #include "DunDebug.h"
    19 #include "DunDebug.h"
    20 
    20 
       
    21 const TInt KDefaultGranularity = 1;
       
    22 
    21 // AT command(s) below is part of the AT&FE0Q0V1&C1&D2+IFC=3,1. command which
    23 // AT command(s) below is part of the AT&FE0Q0V1&C1&D2+IFC=3,1. command which
    22 // is sent by MAC
    24 // is sent by MAC. There is no delimiter between "AT&F" and "E0".
    23 _LIT8(KSpecialATCmd1, "AT&F");
    25 // Only list those commands where alphabetical boundary detection is needed
    24 // Number of special commands
    26 // (i.e. "AT&F0" is not needed as "AT&F0E0" has non-alphabetical boundary)
    25 const TInt KDefaultGranularity = 1;
    27 _LIT8( KSpecialATCmd1, "AT&F" );
    26 
    28 
    27 // ---------------------------------------------------------------------------
    29 // ---------------------------------------------------------------------------
    28 // Two-phased constructor.
    30 // Two-phased constructor.
    29 // ---------------------------------------------------------------------------
    31 // ---------------------------------------------------------------------------
    30 //
    32 //
    40 // ---------------------------------------------------------------------------
    42 // ---------------------------------------------------------------------------
    41 // CDunAtSpecialCmdHandler::CDunAtSpecialCmdHandler
    43 // CDunAtSpecialCmdHandler::CDunAtSpecialCmdHandler
    42 // ---------------------------------------------------------------------------
    44 // ---------------------------------------------------------------------------
    43 //
    45 //
    44 CDunAtSpecialCmdHandler::CDunAtSpecialCmdHandler()
    46 CDunAtSpecialCmdHandler::CDunAtSpecialCmdHandler()
    45     {    
    47     {
    46     }
    48     }
    47 
    49 
    48 // ---------------------------------------------------------------------------
    50 // ---------------------------------------------------------------------------
    49 // CDunAtSpecialCmdHandler::ConstructL
    51 // CDunAtSpecialCmdHandler::ConstructL
    50 // ---------------------------------------------------------------------------
    52 // ---------------------------------------------------------------------------
    51 //
    53 //
    52 void CDunAtSpecialCmdHandler::ConstructL()
    54 void CDunAtSpecialCmdHandler::ConstructL()
    53     {
    55     {
    54     iSpecialCmds = new (ELeave) CDesC8ArrayFlat(KDefaultGranularity);
    56     iSpecialCmds = new (ELeave) CDesC8ArrayFlat( KDefaultGranularity );
    55     // Add here all special commands which need to be handled    
    57     // Add here all special commands which need to be handled
    56     iSpecialCmds->AppendL(KSpecialATCmd1);
    58     iSpecialCmds->AppendL( KSpecialATCmd1 );
    57     }
    59     }
    58 
    60 
    59 // ---------------------------------------------------------------------------
    61 // ---------------------------------------------------------------------------
    60 // Destructor.
    62 // Destructor.
    61 // ---------------------------------------------------------------------------
    63 // ---------------------------------------------------------------------------
    66     delete iSpecialCmds;
    68     delete iSpecialCmds;
    67     FTRACE(FPrint( _L("CDunAtSpecialCmdHandler::~CDunAtSpecialCmdHandler() complete") ));
    69     FTRACE(FPrint( _L("CDunAtSpecialCmdHandler::~CDunAtSpecialCmdHandler() complete") ));
    68     }
    70     }
    69 
    71 
    70 // ---------------------------------------------------------------------------
    72 // ---------------------------------------------------------------------------
    71 // Checks if the command has to be treated special way
    73 // 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.
    74 // 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.
    75 // 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
    76 // In case of MAC we try to search AT&F (sub command) string from the beginning
    75 // of the command. 
    77 // of the command.
    76 // Search is done character by character basis.
    78 // Search is done character by character basis.
    77 // ---------------------------------------------------------------------------
    79 // ---------------------------------------------------------------------------
    78 //
    80 //
    79 TBool CDunAtSpecialCmdHandler::IsCompleteSubCommand (TChar aCharacter)
    81 TBool CDunAtSpecialCmdHandler::IsCompleteSubCommand( TChar aCharacter )
    80     {
    82     {
    81     FTRACE(FPrint( _L("CDunAtSpecialCmdHandler::IsCompleteSubCommand()") ));
    83     FTRACE(FPrint( _L("CDunAtSpecialCmdHandler::IsCompleteSubCommand()") ));
    82     iBuffer.Append(aCharacter);
    84     iBuffer.Append( aCharacter );
    83     TBool completeSubCmd = EFalse;
    85     TBool completeSubCmd = EFalse;
    84     
    86 
    85     if( !IsDataReadyForComparison( iBuffer.Length()) )
    87     if( !IsDataReadyForComparison(iBuffer.Length()) )
    86         {
    88         {
    87         // No need to do comparison because we don't have correct amount of data
    89         // No need to do comparison because we don't have correct amount of data
    88         FTRACE(FPrint( _L("CDunAtSpecialCmdHandler::IsCompleteSubCommand(), no need to compare") ));
    90         FTRACE(FPrint( _L("CDunAtSpecialCmdHandler::IsCompleteSubCommand(), no need to compare") ));
    89         return completeSubCmd;
    91         return completeSubCmd;
    90         }   
    92         }
    91     
    93 
    92     TInt count = iSpecialCmds->Count();
    94     TInt count = iSpecialCmds->Count();
    93     for( TInt i = 0 ; i < count ; i++ )
    95     for ( TInt i=0; i<count; i++ )
    94         {
    96         {
    95         if( iSpecialCmds->MdcaPoint(i).Compare(iBuffer) == 0 )
    97         if( iSpecialCmds->MdcaPoint(i).Compare(iBuffer) == 0 )
    96             {
    98             {
    97             FTRACE(FPrint( _L("CDunAtSpecialCmdHandler::IsCompleteSubCommand(), match found, cmd index %d"), i ));
    99             FTRACE(FPrint( _L("CDunAtSpecialCmdHandler::IsCompleteSubCommand(), match found, cmd index %d"), i ));
    98             // Reset internal buffer for next comparison.
   100             // Reset internal buffer for next comparison.
    99             iBuffer.FillZ();
   101             ResetComparisonBuffer();
   100             iBuffer.Zero();            
       
   101             completeSubCmd = ETrue;
   102             completeSubCmd = ETrue;
   102             break;
   103             break;
   103             }
   104             }
   104         }
   105         }
   105     FTRACE(FPrint( _L("CDunAtSpecialCmdHandler::IsCompleteSubCommand() complete") ));
   106     FTRACE(FPrint( _L("CDunAtSpecialCmdHandler::IsCompleteSubCommand() complete") ));
   106     return completeSubCmd;
   107     return completeSubCmd;
   107     }
   108     }
   108 
   109 
   109 // ---------------------------------------------------------------------------
   110 // ---------------------------------------------------------------------------
   110 // Checks if the command has to be treated special way
   111 // Resets the buffer used for comparisons
   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 // ---------------------------------------------------------------------------
   112 // ---------------------------------------------------------------------------
   117 //
   113 //
   118 TBool CDunAtSpecialCmdHandler::IsCompleteSubCommand(TDesC8& aDes, TInt aStartIndex, TInt& aEndIndex)
   114 void CDunAtSpecialCmdHandler::ResetComparisonBuffer()
   119     {
   115     {
   120     FTRACE(FPrint( _L("CDunAtSpecialCmdHandler::IsCompleteSubCommand()") ));
   116     FTRACE(FPrint( _L("CDunAtSpecialCmdHandler::ResetComparisonBuffer()") ));
   121     TBool completeSubCmd = EFalse;
   117     iBuffer.FillZ();
   122     if( aDes.Length() <  MinimumLength() || aStartIndex != 0 )
   118     iBuffer.Zero();
   123         {
   119     FTRACE(FPrint( _L("CDunAtSpecialCmdHandler::ResetComparisonBuffer() complete") ));
   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     }
   120     }
   146 
   121 
   147 // ---------------------------------------------------------------------------
   122 // ---------------------------------------------------------------------------
   148 // Defines when comparison is excecuted, checks if the data lengths are equal.
   123 // Defines when comparison is excecuted, checks if the data lengths are equal.
   149 // ---------------------------------------------------------------------------
   124 // ---------------------------------------------------------------------------
   150 //
   125 //
   151 TBool CDunAtSpecialCmdHandler::IsDataReadyForComparison(TInt aLength)
   126 TBool CDunAtSpecialCmdHandler::IsDataReadyForComparison( TInt aLength )
   152     {
   127     {
       
   128     FTRACE(FPrint( _L("CDunAtSpecialCmdHandler::IsDataReadyForComparison()") ));
   153     TInt count = iSpecialCmds->Count();
   129     TInt count = iSpecialCmds->Count();
   154     for( TInt i = 0 ; i < count ; i++ )
   130     for ( TInt i=0; i<count; i++ )
   155         {
   131         {
   156         if( iSpecialCmds->MdcaPoint(i).Length() == aLength )
   132         if( iSpecialCmds->MdcaPoint(i).Length() == aLength )
   157             {
   133             {
       
   134             FTRACE(FPrint( _L("CDunAtSpecialCmdHandler::IsDataReadyForComparison() (ready) complete") ));
   158             return ETrue;
   135             return ETrue;
   159             }
   136             }
   160         }
   137         }
       
   138     FTRACE(FPrint( _L("CDunAtSpecialCmdHandler::IsDataReadyForComparison() (not ready) complete") ));
   161     return EFalse;
   139     return EFalse;
   162     }
   140     }
   163 
   141 
   164 // ---------------------------------------------------------------------------
   142 // ---------------------------------------------------------------------------
   165 // Defines minimum length of the special commands.
   143 // Defines minimum length of the special commands.
   166 // ---------------------------------------------------------------------------
   144 // ---------------------------------------------------------------------------
   167 //
   145 //
   168 TInt CDunAtSpecialCmdHandler::MinimumLength()
   146 TInt CDunAtSpecialCmdHandler::MinimumLength()
   169     {
   147     {
       
   148     FTRACE(FPrint( _L("CDunAtSpecialCmdHandler::MinimumLength()") ));
   170     TInt length = iSpecialCmds->MdcaPoint(0).Length();
   149     TInt length = iSpecialCmds->MdcaPoint(0).Length();
   171     TInt count = iSpecialCmds->Count();
   150     TInt count = iSpecialCmds->Count();
   172     for( TInt i = 1 ; i < count ; i++ )
   151     for ( TInt i=1; i<count; i++ )
   173         {
   152         {
   174         if( iSpecialCmds->MdcaPoint(i).Length() < length )
   153         if( iSpecialCmds->MdcaPoint(i).Length() < length )
   175             {
   154             {
   176             length = iSpecialCmds->MdcaPoint(i).Length();
   155             length = iSpecialCmds->MdcaPoint(i).Length();
   177             break;
   156             break;
   178             }
   157             }
   179         }
   158         }
       
   159     FTRACE(FPrint( _L("CDunAtSpecialCmdHandler::MinimumLength() complete") ));
   180     return length;
   160     return length;
   181     }
   161     }