cbsatplugin/atmisccmdplugin/src/cfuncommandhandler.cpp
branchRCL_3
changeset 16 b23265fb36da
child 32 19bd632b5100
equal deleted inserted replaced
14:f7fbeaeb166a 16:b23265fb36da
       
     1 /*
       
     2  * Copyright (c) 2010 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  * Initial Contributors:
       
     9  * Nokia Corporation - initial contribution.
       
    10  *
       
    11  * Contributors:
       
    12  * Description :
       
    13  *
       
    14  */
       
    15 
       
    16 #include "cfuncommandhandler.h"
       
    17 
       
    18 #include <MProfileEngine.h>
       
    19 #include <starterclient.h>
       
    20 
       
    21 #include <Profile.hrh>
       
    22 
       
    23 #include "atmisccmdpluginconsts.h"
       
    24 #include "debug.h"
       
    25 
       
    26 CCFUNCommandHandler* CCFUNCommandHandler::NewL(MATMiscCmdPlugin* aCallback, TAtCommandParser& aATCmdParser, RMobilePhone& aPhone)
       
    27     {
       
    28     TRACE_FUNC_ENTRY
       
    29     CCFUNCommandHandler* self = new (ELeave) CCFUNCommandHandler(aCallback, aATCmdParser, aPhone);
       
    30     CleanupStack::PushL(self);
       
    31     self->ConstructL();
       
    32     CleanupStack::Pop(self);
       
    33     TRACE_FUNC_EXIT
       
    34     return self;
       
    35     }
       
    36 
       
    37 CCFUNCommandHandler::CCFUNCommandHandler(MATMiscCmdPlugin* aCallback, TAtCommandParser& aATCmdParser, RMobilePhone& aPhone) :
       
    38     CATCmdAsyncBase(aCallback, aATCmdParser, aPhone)
       
    39     {
       
    40     TRACE_FUNC_ENTRY
       
    41     TRACE_FUNC_EXIT
       
    42     }
       
    43 
       
    44 void CCFUNCommandHandler::ConstructL()
       
    45     {
       
    46     TRACE_FUNC_ENTRY
       
    47     iReply.CreateL(KDefaultCmdBufLength);
       
    48     iProfileEngine = CreateProfileEngineL();
       
    49     TRACE_FUNC_EXIT
       
    50     }
       
    51 
       
    52 CCFUNCommandHandler::~CCFUNCommandHandler()
       
    53     {
       
    54     TRACE_FUNC_ENTRY
       
    55     Cancel();
       
    56     if (iProfileEngine != NULL)
       
    57         {
       
    58         iProfileEngine->Release();
       
    59         }
       
    60     TRACE_FUNC_EXIT
       
    61     }
       
    62 
       
    63 void CCFUNCommandHandler::HandleCommand(const TDesC8& /*aCmd*/, RBuf8& /*aReply*/, TBool /*aReplyNeeded*/)
       
    64     {
       
    65     TInt ret = KErrNone;
       
    66     iReply.Zero();
       
    67     TAtCommandParser::TCommandHandlerType cmdHandlerType = iATCmdParser.CommandHandlerType();
       
    68     
       
    69     switch (cmdHandlerType)
       
    70         {
       
    71         case (TAtCommandParser::ECmdHandlerTypeTest):
       
    72             {
       
    73             iCallback->CreateReplyAndComplete( EReplyTypeOther, KCFUNSupportedCmdsList);
       
    74             break;
       
    75             }
       
    76         case (TAtCommandParser::ECmdHandlerTypeRead):
       
    77             {
       
    78             TInt profileId = iProfileEngine->ActiveProfileId();
       
    79             
       
    80             iReply.Append( KAtCFUN );
       
    81     
       
    82             if( profileId == EProfileOffLineId )
       
    83                 {
       
    84                 iReply.Append( '0' );
       
    85                 }
       
    86             else
       
    87                 {
       
    88                 iReply.Append( '1' );
       
    89                 }
       
    90             iReply.Append( KOKCRLF );
       
    91             iCallback->CreateReplyAndComplete( EReplyTypeOther, iReply);
       
    92             break;
       
    93             }
       
    94         case (TAtCommandParser::ECmdHandlerTypeSet):
       
    95             {
       
    96             TInt func = 0;
       
    97             TInt reset = 0; // default 0 - do not reset the MT before setting it to <fun> power level
       
    98             
       
    99             ret = iATCmdParser.NextIntParam(func);
       
   100             if (ret != KErrNone && ret != KErrNotFound)
       
   101                 {
       
   102                 iCallback->CreateReplyAndComplete(EReplyTypeError);
       
   103                 TRACE_FUNC_EXIT
       
   104                 return;
       
   105                 }
       
   106             ret = iATCmdParser.NextIntParam(reset);
       
   107             
       
   108             // second parameter is optional, but only 0 and 1 are valid if it is specified
       
   109             if (ret != KErrNone && ret != KErrNotFound && (reset != 0 || reset != 1))
       
   110                 {
       
   111                 iCallback->CreateReplyAndComplete(EReplyTypeError);
       
   112                 TRACE_FUNC_EXIT
       
   113                 return;
       
   114                 }
       
   115             ret = ActivateProfile(func, reset);
       
   116            
       
   117             break;
       
   118             }
       
   119         default:
       
   120             {
       
   121             iCallback->CreateReplyAndComplete(EReplyTypeError);
       
   122             }
       
   123         }
       
   124     
       
   125     if (ret != KErrNone)
       
   126         {
       
   127         iCallback->CreateReplyAndComplete(EReplyTypeError);
       
   128         }
       
   129     else
       
   130         {
       
   131         iCallback->CreateReplyAndComplete( EReplyTypeOther, iReply );
       
   132         }
       
   133     TRACE_FUNC_EXIT
       
   134     }
       
   135 
       
   136 void CCFUNCommandHandler::HandleCommandCancel()
       
   137     {
       
   138     TRACE_FUNC_ENTRY
       
   139     // no asyc requests are made in when using AT+CFUN
       
   140     TRACE_FUNC_EXIT
       
   141     }
       
   142 
       
   143 
       
   144 void CCFUNCommandHandler::RunL()
       
   145     {
       
   146     TRACE_FUNC_ENTRY
       
   147     // no asyc requests are made in when using AT+CFUN
       
   148     TRACE_FUNC_EXIT
       
   149     }
       
   150 
       
   151 void CCFUNCommandHandler::DoCancel()
       
   152     {
       
   153     TRACE_FUNC_ENTRY
       
   154     // no asyc requests are made in when using AT+CFUN
       
   155     TRACE_FUNC_EXIT
       
   156     }
       
   157 
       
   158 TInt CCFUNCommandHandler::ActivateProfile(TInt aFunc, TInt aReset)
       
   159     {
       
   160     TInt err = KErrNone;
       
   161     
       
   162     switch (aFunc)
       
   163         {
       
   164         case (0):
       
   165         case (4):
       
   166             {
       
   167             err = SetActiveProfile(KOfflineProfileId);
       
   168             break;
       
   169             }
       
   170         case (1):
       
   171             {
       
   172             err = SetActiveProfile(KGeneralProfileId);
       
   173             break;
       
   174             }
       
   175         default:
       
   176             {
       
   177             err = KErrArgument;
       
   178             break;
       
   179             }
       
   180         }
       
   181     
       
   182     if (err == KErrNone && aReset == 1)
       
   183         {
       
   184         err = RestartDevice();
       
   185         }
       
   186     
       
   187     return err;
       
   188     }
       
   189 
       
   190 TInt CCFUNCommandHandler::SetActiveProfile(TInt aProfileId)
       
   191     {
       
   192     TInt err = KErrNone;
       
   193 
       
   194     if(iProfileEngine)
       
   195         {
       
   196         TRAP(err, iProfileEngine->SetActiveProfileL( aProfileId ));
       
   197         }
       
   198 
       
   199     return err;
       
   200     }
       
   201 
       
   202 TInt CCFUNCommandHandler::RestartDevice()
       
   203     {
       
   204     RStarterSession session;
       
   205     TInt err = session.Connect();
       
   206 
       
   207     if( err == KErrNone )
       
   208         {
       
   209         session.Reset(RStarterSession::EUnknownReset);
       
   210         session.Close();
       
   211         }
       
   212 
       
   213     return err;
       
   214     }