localconnectivityservice/lccustomplugin/src/lccustomplugin.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:  Main handler for incoming requests
    14 * Description:  Main handler for incoming requests
    15 *
    15 *
    16 */
    16 */
    17 
    17 
    18 
       
    19 #include "lccustomplugin.h"
    18 #include "lccustomplugin.h"
    20 #include "lclistallcmd.h"
    19 #include "lclistallcmd.h"
    21 #include "debug.h"
    20 #include "debug.h"
    22 
    21 
    23 const TInt KErrorReplyLength = 9;  // CR+LF+"ERROR"+CR+LF
    22 const TInt KErrorReplyLength = 9;  // CR+LF+"ERROR"+CR+LF
    51 // ---------------------------------------------------------------------------
    50 // ---------------------------------------------------------------------------
    52 //
    51 //
    53 CLcCustomPlugin::CLcCustomPlugin() : CATExtPluginBase()
    52 CLcCustomPlugin::CLcCustomPlugin() : CATExtPluginBase()
    54     {
    53     {
    55     iHandler = NULL;
    54     iHandler = NULL;
       
    55     iHcCmd = NULL;
       
    56     iHcReply = NULL;
    56     }
    57     }
    57 
    58 
    58 // ---------------------------------------------------------------------------
    59 // ---------------------------------------------------------------------------
    59 // CLcCustomPlugin::ConstructL
    60 // CLcCustomPlugin::ConstructL
    60 // ---------------------------------------------------------------------------
    61 // ---------------------------------------------------------------------------
    81 // ---------------------------------------------------------------------------
    82 // ---------------------------------------------------------------------------
    82 //
    83 //
    83 TBool CLcCustomPlugin::IsCommandSupported( const TDesC8& aCmd )
    84 TBool CLcCustomPlugin::IsCommandSupported( const TDesC8& aCmd )
    84     {
    85     {
    85     TRACE_FUNC_ENTRY
    86     TRACE_FUNC_ENTRY
       
    87     iHcCmd = NULL;
       
    88     iHcReply = NULL;
    86     TInt i;
    89     TInt i;
    87     TInt count = iHandlers.Count();
    90     TInt count = iHandlers.Count();
    88     for ( i=0; i<count; i++ )
    91     for ( i=0; i<count; i++ )
    89         {
    92         {
    90         CLcCustomPluginBase* handler = iHandlers[i];
    93         CLcCustomPluginBase* handler = iHandlers[i];
   112                                      TBool aReplyNeeded )
   115                                      TBool aReplyNeeded )
   113 	{
   116 	{
   114 	TRACE_FUNC_ENTRY
   117 	TRACE_FUNC_ENTRY
   115 	if ( iHandler )
   118 	if ( iHandler )
   116 	    {
   119 	    {
       
   120 	    iHcCmd = &aCmd;
       
   121 	    iHcReply = &aReply;
   117 	    iHandler->HandleCommand( aCmd, aReply, aReplyNeeded );
   122 	    iHandler->HandleCommand( aCmd, aReply, aReplyNeeded );
   118 	    }
   123 	    }
   119 	TRACE_FUNC_EXIT
   124 	TRACE_FUNC_EXIT
   120     }
   125     }
   121 
   126 
   199 
   204 
   200 // ---------------------------------------------------------------------------
   205 // ---------------------------------------------------------------------------
   201 // Reports about external handle command error condition.
   206 // Reports about external handle command error condition.
   202 // This is for cases when for example DUN decided the reply contained an
   207 // This is for cases when for example DUN decided the reply contained an
   203 // error condition but the plugin is still handling the command internally.
   208 // error condition but the plugin is still handling the command internally.
   204 // Example: in command line "AT+TEST;ATDT1234" was given. "AT+TEST" returns
   209 // Example: "AT+TEST;+TEST2" was given in command line; "AT+TEST" returns
   205 // "OK" and "ATDT" returns "CONNECT". Because "OK" and "CONNECT" are
   210 // non-EReplyTypeError condition and "AT+TEST2" returns EReplyTypeError.
   206 // different reply types the condition is "ERROR" and DUN ends processing.
   211 // As the plugin(s) returning the non-EReplyTypeError may still have some
   207 // This solution keeps the pointer to the last AT command handling plugin
   212 // ongoing operation then these plugins are notified about the external
   208 // inside ATEXT and calls this function there to report the error.
   213 // EReplyTypeError in command line processing. It is to be noted that
   209 // It is to be noted that HandleCommandCancel() is not sufficient to stop
   214 // HandleCommandCancel() is not sufficient to stop the processing as the
   210 // the processing as the command handling has already finished.
   215 // command handling has already finished.
   211 // ---------------------------------------------------------------------------
   216 // ---------------------------------------------------------------------------
   212 //
   217 //
   213 void CLcCustomPlugin::ReportExternalHandleCommandError()
   218 void CLcCustomPlugin::ReportExternalHandleCommandError()
   214     {
   219     {
   215     TRACE_FUNC_ENTRY
   220     TRACE_FUNC_ENTRY
   250 // Creates an AT command reply based on the reply type and completes the
   255 // Creates an AT command reply based on the reply type and completes the
   251 // request to ATEXT. Uses iReplyBuffer for reply storage.
   256 // request to ATEXT. Uses iReplyBuffer for reply storage.
   252 // ---------------------------------------------------------------------------
   257 // ---------------------------------------------------------------------------
   253 //
   258 //
   254 TInt CLcCustomPlugin::CreateReplyAndComplete( TATExtensionReplyType aReplyType,
   259 TInt CLcCustomPlugin::CreateReplyAndComplete( TATExtensionReplyType aReplyType,
   255                                               RBuf8& aDstBuffer,
       
   256                                               const TDesC8& aSrcBuffer,
   260                                               const TDesC8& aSrcBuffer,
   257                                               TInt aError )
   261 											  TInt aError )
   258     {
   262     {
   259     TRACE_FUNC_ENTRY
   263     TRACE_FUNC_ENTRY
   260     iReplyBuffer.Close();
   264     iReplyBuffer.Close();
   261     if ( aError != KErrNone )
   265     if ( aError != KErrNone )
   262         {
   266         {
   263         HandleCommandCompleted( aError, EReplyTypeUndefined );
   267         HandleCommandCompleted( aError, EReplyTypeUndefined );
       
   268         iHcCmd = NULL;
       
   269         iHcReply = NULL;
   264         TRACE_FUNC_EXIT
   270         TRACE_FUNC_EXIT
   265         return KErrNone;
   271         return KErrNone;
   266         }
   272         }
   267     TInt retVal = KErrNone;
   273     if ( !iHcReply )
       
   274         {
       
   275         TRACE_FUNC_EXIT
       
   276         return KErrGeneral;
       
   277         }
   268     switch ( aReplyType )
   278     switch ( aReplyType )
   269         {
   279         {
   270         case EReplyTypeOther:
   280         case EReplyTypeOther:
   271             if ( iQuietMode || !iVerboseMode )
   281             if ( iQuietMode )
   272                 {
   282                 {
   273                 iReplyBuffer.Create( KNullDesC8 );
   283                 iReplyBuffer.Create( KNullDesC8 );
   274                 }
   284                 }
   275             else
   285             else
   276                 {
   286                 {
   277                 iReplyBuffer.Create( aSrcBuffer );
   287                 iReplyBuffer.Create( aSrcBuffer );
   278                 }
   288                 }
   279             CreatePartOfReply( aDstBuffer );
       
   280             HandleCommandCompleted( KErrNone, aReplyType );
       
   281             break;
   289             break;
   282         case EReplyTypeOk:
   290         case EReplyTypeOk:
   283             CreateOkOrErrorReply( iReplyBuffer, ETrue );
   291             CreateOkOrErrorReply( iReplyBuffer, ETrue );
   284             CreatePartOfReply( aDstBuffer );
       
   285             HandleCommandCompleted( KErrNone, aReplyType );
       
   286             break;
   292             break;
   287         case EReplyTypeError:
   293         case EReplyTypeError:
   288             CreateOkOrErrorReply( iReplyBuffer, EFalse );
   294             CreateOkOrErrorReply( iReplyBuffer, EFalse );
   289             CreatePartOfReply( aDstBuffer );
       
   290             HandleCommandCompleted( KErrNone, aReplyType );
       
   291             break;
   295             break;
   292         default:
   296         default:
   293             retVal = KErrGeneral;
   297             TRACE_FUNC_EXIT
   294             break;
   298             return KErrGeneral;
   295         }
   299         }
   296     TRACE_FUNC_EXIT
   300     CreatePartOfReply( *iHcReply );
   297     return retVal;
   301     HandleCommandCompleted( KErrNone, aReplyType );
       
   302     iHcCmd = NULL;
       
   303     iHcReply = NULL;
       
   304     TRACE_FUNC_EXIT
       
   305     return KErrNone;
   298     }
   306     }
   299 
   307 
   300 // ---------------------------------------------------------------------------
   308 // ---------------------------------------------------------------------------
   301 // Creates a buffer for "OK" or "ERROR" reply based on the line settings
   309 // Creates a buffer for "OK" or "ERROR" reply based on the line settings
   302 // ---------------------------------------------------------------------------
   310 // ---------------------------------------------------------------------------
   347     return retVal;
   355     return retVal;
   348     }
   356     }
   349 
   357 
   350 // ---------------------------------------------------------------------------
   358 // ---------------------------------------------------------------------------
   351 // From MLcCustomPlugin.
   359 // From MLcCustomPlugin.
       
   360 // Checks if the command is a base, set, read or test type of command
       
   361 // ---------------------------------------------------------------------------
       
   362 //
       
   363 TCmdHandlerType CLcCustomPlugin::CheckCommandType(
       
   364     const TDesC8& aCmdBase,
       
   365     const TDesC8& aCmdFull )
       
   366     {
       
   367     TRACE_FUNC_ENTRY
       
   368     TInt retTemp = KErrNone;
       
   369     TBuf8<KDefaultCmdBufLength> atCmdBuffer;
       
   370     atCmdBuffer.Copy( aCmdBase );
       
   371     // Check "base" command ("AT+COMMAND")
       
   372     retTemp = aCmdFull.Compare( atCmdBuffer );
       
   373     if ( retTemp == 0 )
       
   374         {
       
   375         TRACE_FUNC_EXIT
       
   376         return ECmdHandlerTypeBase;
       
   377         }
       
   378     // Check "read" command ("AT+COMMAND?")
       
   379     // Add last question mark
       
   380     atCmdBuffer.Append( '?' );
       
   381     retTemp = aCmdFull.Compare( atCmdBuffer );
       
   382     if ( retTemp == 0 )
       
   383         {
       
   384         TRACE_FUNC_EXIT
       
   385         return ECmdHandlerTypeRead;
       
   386         }
       
   387     // Check "test" command ("AT+COMMAND=?")
       
   388     // Add "=" before the question mark
       
   389     _LIT8( KAssignmentMark, "=" );
       
   390     atCmdBuffer.Insert( atCmdBuffer.Length()-1, KAssignmentMark );
       
   391     retTemp = aCmdFull.Compare( atCmdBuffer );
       
   392     if ( retTemp == 0 )
       
   393         {
       
   394         TRACE_FUNC_EXIT
       
   395         return ECmdHandlerTypeTest;
       
   396         }
       
   397     // Check "set" command ("AT+COMMAND=")
       
   398     // Remove last question mark
       
   399     atCmdBuffer.SetLength( atCmdBuffer.Length() - 1 );
       
   400     retTemp = aCmdFull.Compare( atCmdBuffer );
       
   401     if ( retTemp == 0 )
       
   402         {
       
   403         TRACE_FUNC_EXIT
       
   404         return ECmdHandlerTypeSet;
       
   405         }
       
   406     TRACE_FUNC_EXIT
       
   407     return ECmdHandlerTypeUndefined;
       
   408     }
       
   409 
       
   410 // ---------------------------------------------------------------------------
       
   411 // From MLcCustomPlugin.
   352 // Returns the array of supported commands
   412 // Returns the array of supported commands
   353 // ---------------------------------------------------------------------------
   413 // ---------------------------------------------------------------------------
   354 //
   414 //
   355 TInt CLcCustomPlugin::GetSupportedCommands( RPointerArray<HBufC8>& aCmds )
   415 TInt CLcCustomPlugin::GetSupportedCommands( RPointerArray<HBufC8>& aCmds )
   356     {
   416     {