localconnectivityservice/lccustomplugin/src/lclistallcmd.cpp
changeset 0 c3e98f10fcf4
child 9 a2f12998bb04
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 the commands "AT+CLAC?" and "AT+CLAC"
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 #include "lclistallcmd.h"
       
    20 #include "debug.h"
       
    21 
       
    22 _LIT8( KListAllQueryCmd, "AT+CLAC=?" );
       
    23 _LIT8( KListAllCmd,      "AT+CLAC"   );
       
    24 
       
    25 const TInt KCrLfLength    = 2;  // CR+LF
       
    26 const TInt KOkReplyLength = 6;  // CR+LF+"OK"+CR+LF
       
    27 
       
    28 // ---------------------------------------------------------------------------
       
    29 // Two-phased constructor.
       
    30 // ---------------------------------------------------------------------------
       
    31 //
       
    32 CLcListAllCmd* CLcListAllCmd::NewL( MLcCustomPlugin* aCallback )
       
    33     {
       
    34     CLcListAllCmd* self = new (ELeave) CLcListAllCmd( aCallback );
       
    35     CleanupStack::PushL( self );
       
    36     self->ConstructL();
       
    37     CleanupStack::Pop( self );
       
    38     return self;
       
    39     }
       
    40 
       
    41 // ---------------------------------------------------------------------------
       
    42 // Destructor.
       
    43 // ---------------------------------------------------------------------------
       
    44 //
       
    45 CLcListAllCmd::~CLcListAllCmd()
       
    46     {
       
    47     }
       
    48 
       
    49 // ---------------------------------------------------------------------------
       
    50 // CLcListAllCmd::CLcListAllCmd
       
    51 // ---------------------------------------------------------------------------
       
    52 //
       
    53 CLcListAllCmd::CLcListAllCmd( MLcCustomPlugin* aCallback ) :
       
    54     iCallback( aCallback )
       
    55     {
       
    56     iCmdHandlerType = ECmdHandlerTypeUndefined;
       
    57     }
       
    58 
       
    59 // ---------------------------------------------------------------------------
       
    60 // CLcListAllCmd::ConstructL
       
    61 // ---------------------------------------------------------------------------
       
    62 //
       
    63 void CLcListAllCmd::ConstructL()
       
    64     {
       
    65     if ( !iCallback )
       
    66         {
       
    67         User::Leave( KErrGeneral );
       
    68         }
       
    69     }
       
    70 
       
    71 // ---------------------------------------------------------------------------
       
    72 // Reports the support status of an AT command. This is a synchronous API.
       
    73 // ---------------------------------------------------------------------------
       
    74 //
       
    75 TBool CLcListAllCmd::IsCommandSupported( const TDesC8& aCmd )
       
    76     {
       
    77     TRACE_FUNC_ENTRY
       
    78     TInt retTemp = KErrNone;
       
    79     retTemp = aCmd.Compare( KListAllQueryCmd );
       
    80     if ( retTemp == 0 )
       
    81         {
       
    82         iCmdHandlerType = ECmdHandlerTypeQuery;
       
    83         TRACE_FUNC_EXIT
       
    84         return ETrue;
       
    85         }
       
    86     retTemp = aCmd.Compare( KListAllCmd );
       
    87     if ( retTemp == 0 )
       
    88         {
       
    89         iCmdHandlerType = ECmdHandlerTypeList;
       
    90         TRACE_FUNC_EXIT
       
    91         return ETrue;
       
    92         }
       
    93     iCmdHandlerType = ECmdHandlerTypeUndefined;
       
    94     TRACE_FUNC_EXIT
       
    95     return EFalse;
       
    96     }
       
    97 
       
    98 // ---------------------------------------------------------------------------
       
    99 // Handles an AT command. Cancelling of the pending request is done by
       
   100 // HandleCommandCancel(). The implementation in the extension plugin should
       
   101 // be asynchronous.
       
   102 // ---------------------------------------------------------------------------
       
   103 //
       
   104 void CLcListAllCmd::HandleCommand( const TDesC8& /*aCmd*/,
       
   105                                    RBuf8& aReply,
       
   106                                    TBool aReplyNeeded )
       
   107     {
       
   108     TRACE_FUNC_ENTRY
       
   109     if ( !aReplyNeeded )
       
   110         {
       
   111         TRACE_FUNC_EXIT
       
   112         return;
       
   113         }
       
   114     if ( iCmdHandlerType == ECmdHandlerTypeQuery )
       
   115         {
       
   116         iCallback->CreateReplyAndComplete( EReplyTypeOk,
       
   117                                            aReply );
       
   118         TRACE_FUNC_EXIT
       
   119         return;
       
   120         }
       
   121     // Else here means ECmdHandlerTypeList
       
   122     // First check the quiet mode and verbose mode.
       
   123     // These are handled in CreateReplyAndComplete()
       
   124     TInt retTemp;
       
   125     TBool quietMode = EFalse;
       
   126     TBool verboseMode = EFalse;
       
   127     retTemp  = iCallback->GetModeValue( EModeTypeQuiet, quietMode );
       
   128     retTemp |= iCallback->GetModeValue( EModeTypeVerbose, verboseMode );
       
   129     if ( retTemp != KErrNone )
       
   130         {
       
   131         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         return;
       
   142         }
       
   143     RBuf8 reply;
       
   144     TBool error = CreateSupportedList( reply );
       
   145     if ( error )
       
   146         {
       
   147         iCallback->CreateReplyAndComplete( EReplyTypeError,
       
   148                                            aReply );
       
   149         reply.Close();
       
   150         TRACE_FUNC_EXIT
       
   151         return;
       
   152         }
       
   153     RBuf8 okReply;
       
   154     iCallback->CreateOkOrErrorReply( okReply, ETrue );
       
   155     reply.Append( okReply);
       
   156     okReply.Close();
       
   157     iCallback->CreateReplyAndComplete( EReplyTypeOther,
       
   158                                        aReply,
       
   159                                        reply );
       
   160     reply.Close();
       
   161     TRACE_FUNC_EXIT
       
   162     }
       
   163 
       
   164 // ---------------------------------------------------------------------------
       
   165 // Cancels a pending HandleCommand request.
       
   166 // ---------------------------------------------------------------------------
       
   167 //
       
   168 void CLcListAllCmd::HandleCommandCancel()
       
   169     {
       
   170     TRACE_FUNC_ENTRY
       
   171     TRACE_FUNC_EXIT
       
   172     }
       
   173 
       
   174 // ---------------------------------------------------------------------------
       
   175 // Creates a linearized list of supported commands
       
   176 // ---------------------------------------------------------------------------
       
   177 //
       
   178 TBool CLcListAllCmd::CreateSupportedList( RBuf8& aReply )
       
   179     {
       
   180     TRACE_FUNC_ENTRY
       
   181     // First get the unsorted list from ATEXT
       
   182     RPointerArray<HBufC8> commands;
       
   183     iCallback->GetSupportedCommands( commands );
       
   184     // Next linearize the list for a reply
       
   185     if ( commands.Count() <= 0 )
       
   186         {
       
   187         commands.Close();
       
   188         TRACE_FUNC_EXIT
       
   189         return EFalse;
       
   190         }
       
   191     TInt i;
       
   192     TInt linearSize = KOkReplyLength;
       
   193     TInt count = commands.Count();
       
   194     for ( i=0; i<count; i++ )
       
   195         {
       
   196         linearSize += (*commands[i]).Length();
       
   197         if ( i < count-1 )
       
   198             {
       
   199             linearSize += KCrLfLength;
       
   200             }
       
   201         }
       
   202     // Now we have the length of the linear region,
       
   203     // use that to create the reply
       
   204     TChar carriageReturn;
       
   205     TChar lineFeed;
       
   206     TInt retTemp;
       
   207     retTemp  = aReply.Create( linearSize );
       
   208     retTemp |= iCallback->GetCharacterValue( ECharTypeCR, carriageReturn );
       
   209     retTemp |= iCallback->GetCharacterValue( ECharTypeLF, lineFeed );
       
   210     if ( retTemp != KErrNone )
       
   211         {
       
   212         commands.ResetAndDestroy();
       
   213         commands.Close();
       
   214         TRACE_FUNC_EXIT
       
   215         return ETrue;
       
   216         }
       
   217     for ( i=0; i<count; i++ )
       
   218         {
       
   219         aReply.Append( *commands[i] );
       
   220         if ( i < count-1 )
       
   221             {
       
   222             aReply.Append( carriageReturn );
       
   223             aReply.Append( lineFeed );
       
   224             }
       
   225         }
       
   226     // Delete the array as it is no longer needed
       
   227     commands.ResetAndDestroy();
       
   228     commands.Close();
       
   229     TRACE_FUNC_EXIT
       
   230     return EFalse;
       
   231     }