localconnectivityservice/lccustomplugin/src/lclistallcmd.cpp
branchRCL_3
changeset 7 a2f12998bb04
parent 0 c3e98f10fcf4
equal deleted inserted replaced
5:11d83199e2d9 7:a2f12998bb04
     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".
    13 *
    13 *
    14 * Description:  Handles the commands "AT+CLAC?" and "AT+CLAC"
    14 * Description:  Handles the commands "AT+CLAC?" and "AT+CLAC"
    15 *
    15 *
    16 */
    16 */
    17 
    17 
    18 
       
    19 #include "lclistallcmd.h"
    18 #include "lclistallcmd.h"
    20 #include "debug.h"
    19 #include "debug.h"
    21 
    20 
    22 _LIT8( KListAllQueryCmd, "AT+CLAC=?" );
       
    23 _LIT8( KListAllCmd,      "AT+CLAC"   );
       
    24 
       
    25 const TInt KCrLfLength    = 2;  // CR+LF
    21 const TInt KCrLfLength    = 2;  // CR+LF
    26 const TInt KOkReplyLength = 6;  // CR+LF+"OK"+CR+LF
    22 const TInt KOkReplyLength = 6;  // CR+LF+"OK"+CR+LF
       
    23 
       
    24 _LIT8( KClacCmd, "AT+CLAC" );
    27 
    25 
    28 // ---------------------------------------------------------------------------
    26 // ---------------------------------------------------------------------------
    29 // Two-phased constructor.
    27 // Two-phased constructor.
    30 // ---------------------------------------------------------------------------
    28 // ---------------------------------------------------------------------------
    31 //
    29 //
    67         User::Leave( KErrGeneral );
    65         User::Leave( KErrGeneral );
    68         }
    66         }
    69     }
    67     }
    70 
    68 
    71 // ---------------------------------------------------------------------------
    69 // ---------------------------------------------------------------------------
       
    70 // Checks command types
       
    71 // ---------------------------------------------------------------------------
       
    72 //
       
    73 TBool CLcListAllCmd::CheckCommand( const TDesC8& aCmd )
       
    74     {
       
    75     TRACE_FUNC_ENTRY
       
    76     // The AT+CLAC command supports two types: base and test
       
    77     iCmdHandlerType = iCallback->CheckCommandType( KClacCmd, aCmd );
       
    78     if ( iCmdHandlerType==ECmdHandlerTypeBase ||
       
    79          iCmdHandlerType==ECmdHandlerTypeTest )
       
    80         {
       
    81         iDetectedCmd = EDetectedCmdCLAC;
       
    82         TRACE_FUNC_EXIT
       
    83         return ETrue;
       
    84         }
       
    85     TRACE_FUNC_EXIT
       
    86     return EFalse;
       
    87     }
       
    88 
       
    89 // ---------------------------------------------------------------------------
    72 // Reports the support status of an AT command. This is a synchronous API.
    90 // Reports the support status of an AT command. This is a synchronous API.
    73 // ---------------------------------------------------------------------------
    91 // ---------------------------------------------------------------------------
    74 //
    92 //
    75 TBool CLcListAllCmd::IsCommandSupported( const TDesC8& aCmd )
    93 TBool CLcListAllCmd::IsCommandSupported( const TDesC8& aCmd )
    76     {
    94     {
    77     TRACE_FUNC_ENTRY
    95     TRACE_FUNC_ENTRY
    78     TInt retTemp = KErrNone;
    96     // Set all to undefined if either the command or its type is unknown
    79     retTemp = aCmd.Compare( KListAllQueryCmd );
    97     // HandleCommand() should be round only when both are set
    80     if ( retTemp == 0 )
    98     TBool cmdUnderstood = CheckCommand( aCmd );
    81         {
    99     if ( cmdUnderstood )
    82         iCmdHandlerType = ECmdHandlerTypeQuery;
   100         {
    83         TRACE_FUNC_EXIT
   101         TRACE_FUNC_EXIT
    84         return ETrue;
   102         return ETrue;
    85         }
   103         }
    86     retTemp = aCmd.Compare( KListAllCmd );
       
    87     if ( retTemp == 0 )
       
    88         {
       
    89         iCmdHandlerType = ECmdHandlerTypeList;
       
    90         TRACE_FUNC_EXIT
       
    91         return ETrue;
       
    92         }
       
    93     iCmdHandlerType = ECmdHandlerTypeUndefined;
   104     iCmdHandlerType = ECmdHandlerTypeUndefined;
       
   105     iDetectedCmd = EDetectedCmdUndefined;
    94     TRACE_FUNC_EXIT
   106     TRACE_FUNC_EXIT
    95     return EFalse;
   107     return EFalse;
    96     }
   108     }
    97 
   109 
    98 // ---------------------------------------------------------------------------
   110 // ---------------------------------------------------------------------------
   100 // HandleCommandCancel(). The implementation in the extension plugin should
   112 // HandleCommandCancel(). The implementation in the extension plugin should
   101 // be asynchronous.
   113 // be asynchronous.
   102 // ---------------------------------------------------------------------------
   114 // ---------------------------------------------------------------------------
   103 //
   115 //
   104 void CLcListAllCmd::HandleCommand( const TDesC8& /*aCmd*/,
   116 void CLcListAllCmd::HandleCommand( const TDesC8& /*aCmd*/,
   105                                    RBuf8& aReply,
   117                                    RBuf8& /*aReply*/,
   106                                    TBool aReplyNeeded )
   118                                    TBool aReplyNeeded )
   107     {
   119     {
   108     TRACE_FUNC_ENTRY
   120     TRACE_FUNC_ENTRY
   109     if ( !aReplyNeeded )
   121     if ( !aReplyNeeded )
   110         {
   122         {
   111         TRACE_FUNC_EXIT
   123         TRACE_FUNC_EXIT
   112         return;
   124         return;
   113         }
   125         }
   114     if ( iCmdHandlerType == ECmdHandlerTypeQuery )
   126     if ( iCmdHandlerType == ECmdHandlerTypeTest )
   115         {
   127         {
   116         iCallback->CreateReplyAndComplete( EReplyTypeOk,
   128         iCallback->CreateReplyAndComplete( EReplyTypeOk );
   117                                            aReply );
   129         TRACE_FUNC_EXIT
   118         TRACE_FUNC_EXIT
   130         return;
   119         return;
   131         }
   120         }
   132     // Else here means ECmdHandlerTypeBase
   121     // Else here means ECmdHandlerTypeList
       
   122     // First check the quiet mode and verbose mode.
   133     // First check the quiet mode and verbose mode.
   123     // These are handled in CreateReplyAndComplete()
   134     // These are handled in CreateReplyAndComplete()
   124     TInt retTemp;
   135     TInt retTemp;
   125     TBool quietMode = EFalse;
   136     TBool quietMode = EFalse;
   126     TBool verboseMode = EFalse;
       
   127     retTemp  = iCallback->GetModeValue( EModeTypeQuiet, quietMode );
   137     retTemp  = iCallback->GetModeValue( EModeTypeQuiet, quietMode );
   128     retTemp |= iCallback->GetModeValue( EModeTypeVerbose, verboseMode );
       
   129     if ( retTemp != KErrNone )
   138     if ( retTemp != KErrNone )
   130         {
   139         {
   131         iCallback->CreateReplyAndComplete( EReplyTypeError,
   140         iCallback->CreateReplyAndComplete( EReplyTypeError );
   132                                            aReply );
       
   133         TRACE_FUNC_EXIT
       
   134         return;
       
   135         }
       
   136     if ( quietMode || !verboseMode )
       
   137         {
       
   138         iCallback->CreateReplyAndComplete( EReplyTypeOther,
       
   139                                            aReply );
       
   140         TRACE_FUNC_EXIT
   141         TRACE_FUNC_EXIT
   141         return;
   142         return;
   142         }
   143         }
   143     RBuf8 reply;
   144     RBuf8 reply;
       
   145     if ( quietMode )
       
   146         {
       
   147         iCallback->CreateReplyAndComplete( EReplyTypeOther, reply );
       
   148         reply.Close();
       
   149         TRACE_FUNC_EXIT
       
   150         return;
       
   151         }
   144     TBool error = CreateSupportedList( reply );
   152     TBool error = CreateSupportedList( reply );
   145     if ( error )
   153     if ( error )
   146         {
   154         {
   147         iCallback->CreateReplyAndComplete( EReplyTypeError,
   155         iCallback->CreateReplyAndComplete( EReplyTypeError );
   148                                            aReply );
       
   149         reply.Close();
   156         reply.Close();
   150         TRACE_FUNC_EXIT
   157         TRACE_FUNC_EXIT
   151         return;
   158         return;
   152         }
   159         }
   153     RBuf8 okReply;
   160     RBuf8 okReply;
   154     iCallback->CreateOkOrErrorReply( okReply, ETrue );
   161     iCallback->CreateOkOrErrorReply( okReply, ETrue );
   155     reply.Append( okReply);
   162     reply.Append( okReply );
   156     okReply.Close();
   163     okReply.Close();
   157     iCallback->CreateReplyAndComplete( EReplyTypeOther,
   164     iCallback->CreateReplyAndComplete( EReplyTypeOther, reply );
   158                                        aReply,
       
   159                                        reply );
       
   160     reply.Close();
   165     reply.Close();
   161     TRACE_FUNC_EXIT
   166     TRACE_FUNC_EXIT
   162     }
   167     }
   163 
   168 
   164 // ---------------------------------------------------------------------------
   169 // ---------------------------------------------------------------------------
   197         if ( i < count-1 )
   202         if ( i < count-1 )
   198             {
   203             {
   199             linearSize += KCrLfLength;
   204             linearSize += KCrLfLength;
   200             }
   205             }
   201         }
   206         }
       
   207     linearSize += KCrLfLength;
   202     // Now we have the length of the linear region,
   208     // Now we have the length of the linear region,
   203     // use that to create the reply
   209     // use that to create the reply
   204     TChar carriageReturn;
   210     TChar carriageReturn;
   205     TChar lineFeed;
   211     TChar lineFeed;
   206     TInt retTemp;
   212     TInt retTemp;
   221             {
   227             {
   222             aReply.Append( carriageReturn );
   228             aReply.Append( carriageReturn );
   223             aReply.Append( lineFeed );
   229             aReply.Append( lineFeed );
   224             }
   230             }
   225         }
   231         }
       
   232     aReply.Append( carriageReturn );
       
   233     aReply.Append( lineFeed );
   226     // Delete the array as it is no longer needed
   234     // Delete the array as it is no longer needed
   227     commands.ResetAndDestroy();
   235     commands.ResetAndDestroy();
   228     commands.Close();
   236     commands.Close();
   229     TRACE_FUNC_EXIT
   237     TRACE_FUNC_EXIT
   230     return EFalse;
   238     return EFalse;