cbsatplugin/atmisccmdplugin/src/cfuncommandhandler.cpp
changeset 32 19bd632b5100
parent 26 b78e66e88238
child 41 0b2439c3e397
equal deleted inserted replaced
31:a0ea99b6fa53 32:19bd632b5100
    15 
    15 
    16 #include "cfuncommandhandler.h"
    16 #include "cfuncommandhandler.h"
    17 
    17 
    18 #include <MProfileEngine.h>
    18 #include <MProfileEngine.h>
    19 #include <starterclient.h>
    19 #include <starterclient.h>
       
    20 #include <ssm/startupdomainpskeys.h>
    20 
    21 
    21 #include <Profile.hrh>
    22 #include <Profile.hrh>
    22 
    23 
    23 #include "atmisccmdpluginconsts.h"
    24 #include "atmisccmdpluginconsts.h"
    24 #include "debug.h"
    25 #include "debug.h"
    51 
    52 
    52 CCFUNCommandHandler::~CCFUNCommandHandler()
    53 CCFUNCommandHandler::~CCFUNCommandHandler()
    53     {
    54     {
    54     TRACE_FUNC_ENTRY
    55     TRACE_FUNC_ENTRY
    55     Cancel();
    56     Cancel();
       
    57     iProperty.Close();
    56     if (iProfileEngine != NULL)
    58     if (iProfileEngine != NULL)
    57         {
    59         {
    58         iProfileEngine->Release();
    60         iProfileEngine->Release();
    59         }
    61         }
    60     TRACE_FUNC_EXIT
    62     TRACE_FUNC_EXIT
    61     }
    63     }
    62 
    64 
    63 void CCFUNCommandHandler::HandleCommand(const TDesC8& /*aCmd*/, RBuf8& /*aReply*/, TBool /*aReplyNeeded*/)
    65 void CCFUNCommandHandler::HandleCommand(const TDesC8& /*aCmd*/, RBuf8& /*aReply*/, TBool /*aReplyNeeded*/)
    64     {
    66     {
       
    67     TRACE_FUNC_ENTRY
       
    68     
       
    69     if (IsActive())
       
    70         {
       
    71         iCallback->CreateReplyAndComplete(EReplyTypeError);
       
    72         TRACE_FUNC_EXIT
       
    73         return;
       
    74         }
       
    75     
    65     TInt ret = KErrNone;
    76     TInt ret = KErrNone;
    66     iReply.Zero();
    77     iReply.Zero();
    67     TAtCommandParser::TCommandHandlerType cmdHandlerType = iATCmdParser.CommandHandlerType();
    78     TAtCommandParser::TCommandHandlerType cmdHandlerType = iATCmdParser.CommandHandlerType();
    68     
    79     
    69     switch (cmdHandlerType)
    80     switch (cmdHandlerType)
    92             break;
   103             break;
    93             }
   104             }
    94         case (TAtCommandParser::ECmdHandlerTypeSet):
   105         case (TAtCommandParser::ECmdHandlerTypeSet):
    95             {
   106             {
    96             TInt func = 0;
   107             TInt func = 0;
    97             TInt reset = 0; // default 0 - do not reset the MT before setting it to <fun> power level
   108 
    98             
       
    99             ret = iATCmdParser.NextIntParam(func);
   109             ret = iATCmdParser.NextIntParam(func);
   100             if (ret != KErrNone && ret != KErrNotFound)
   110             if (ret != KErrNone && ret != KErrNotFound)
   101                 {
   111                 {
   102                 iCallback->CreateReplyAndComplete(EReplyTypeError);
   112                 iCallback->CreateReplyAndComplete(EReplyTypeError);
   103                 TRACE_FUNC_EXIT
   113                 TRACE_FUNC_EXIT
   104                 return;
   114                 return;
   105                 }
   115                 }
   106             ret = iATCmdParser.NextIntParam(reset);
   116 			iReset = 0; // default 0 - do not reset the MT before setting it to <fun> power level
       
   117             ret = iATCmdParser.NextIntParam(iReset);
   107             
   118             
   108             // second parameter is optional, but only 0 and 1 are valid if it is specified
   119             // 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))
   120             if (!(ret == KErrNone || ret == KErrNotFound) || !(iReset == 0 || iReset == 1))
   110                 {
   121                 {
   111                 iCallback->CreateReplyAndComplete(EReplyTypeError);
   122                 iCallback->CreateReplyAndComplete(EReplyTypeError);
   112                 TRACE_FUNC_EXIT
   123                 TRACE_FUNC_EXIT
   113                 return;
   124                 return;
   114                 }
   125                 }
   115             ret = ActivateProfile(func, reset);
   126             
   116            
   127             ret = ActivateProfile(func);       
   117             break;
   128             break;
   118             }
   129             }
   119         default:
   130         default:
   120             {
   131             {
   121             iCallback->CreateReplyAndComplete(EReplyTypeError);
   132             iCallback->CreateReplyAndComplete(EReplyTypeError);
   122             }
   133             break;
   123         }
   134             }
   124     
   135         }
       
   136     
       
   137     if (!IsActive())
       
   138         {
       
   139         if (ret != KErrNone)
       
   140             {
       
   141             iCallback->CreateReplyAndComplete(EReplyTypeError);
       
   142             }
       
   143         else
       
   144             {
       
   145             iCallback->CreateReplyAndComplete( EReplyTypeOther, iReply );
       
   146             }
       
   147         }
       
   148     TRACE_FUNC_EXIT
       
   149     }
       
   150 
       
   151 void CCFUNCommandHandler::RunL()
       
   152     {
       
   153     TRACE_FUNC_ENTRY
       
   154     TInt systemState;
       
   155     
       
   156     TInt ret = iProperty.Get(systemState);
   125     if (ret != KErrNone)
   157     if (ret != KErrNone)
   126         {
   158         {
   127         iCallback->CreateReplyAndComplete(EReplyTypeError);
   159         if (systemState != iExpectedState)
   128         }
   160             {
   129     else
   161             iProperty.Subscribe(iStatus);
   130         {
   162             SetActive();
   131         iCallback->CreateReplyAndComplete( EReplyTypeOther, iReply );
   163             }
   132         }
   164         else if (iReset == 1)
   133     TRACE_FUNC_EXIT
   165             {
   134     }
   166             ret = RestartDevice();
   135 
   167             }
   136 void CCFUNCommandHandler::HandleCommandCancel()
   168         }
   137     {
   169     if (!IsActive())
   138     TRACE_FUNC_ENTRY
   170         {
   139     // no asyc requests are made in when using AT+CFUN
   171         if (ret != KErrNone)
   140     TRACE_FUNC_EXIT
   172             {
   141     }
   173             iCallback->CreateReplyAndComplete(EReplyTypeError);
   142 
   174             }
   143 
   175         else
   144 void CCFUNCommandHandler::RunL()
   176             {
   145     {
   177             iCallback->CreateReplyAndComplete( EReplyTypeOther, iReply );
   146     TRACE_FUNC_ENTRY
   178             }
   147     // no asyc requests are made in when using AT+CFUN
   179         }
   148     TRACE_FUNC_EXIT
   180     TRACE_FUNC_EXIT
   149     }
   181     }
   150 
   182 
   151 void CCFUNCommandHandler::DoCancel()
   183 void CCFUNCommandHandler::DoCancel()
   152     {
   184     {
   153     TRACE_FUNC_ENTRY
   185     TRACE_FUNC_ENTRY
   154     // no asyc requests are made in when using AT+CFUN
   186     iProperty.Cancel();
   155     TRACE_FUNC_EXIT
   187     TRACE_FUNC_EXIT
   156     }
   188     }
   157 
   189 
   158 TInt CCFUNCommandHandler::ActivateProfile(TInt aFunc, TInt aReset)
   190 TInt CCFUNCommandHandler::ActivateProfile(TInt aFunc)
   159     {
   191     {
   160     TInt err = KErrNone;
   192     TRACE_FUNC_ENTRY
       
   193     TInt systemState;
       
   194     
       
   195     //Listen to the property KPSGlobalSystemState for profile change.
       
   196     TInt err = iProperty.Attach(KPSUidStartup, KPSGlobalSystemState);
       
   197     if (err != KErrNone)
       
   198         {
       
   199         TRACE_FUNC_EXIT
       
   200         return err;
       
   201         }
       
   202 
       
   203     err = iProperty.Get(systemState);
       
   204     if (err != KErrNone)
       
   205         {
       
   206         TRACE_FUNC_EXIT
       
   207         return err;
       
   208         }
   161     
   209     
   162     switch (aFunc)
   210     switch (aFunc)
   163         {
   211         {
   164         case (0):
   212         case (0):
   165         case (4):
   213         case (4):
   166             {
   214             {
   167             err = SetActiveProfile(KOfflineProfileId);
   215             // check of KPSGlobalSystemState is not already set to ESwStateNormalRfOff,
       
   216             // issue the profile change request and start monitoring the property
       
   217             if (systemState != ESwStateNormalRfOff)
       
   218                 {
       
   219                 err = SetActiveProfile(KOfflineProfileId);
       
   220                 
       
   221                 
       
   222                 if (err == KErrNone)
       
   223                     {
       
   224                     iExpectedState = ESwStateNormalRfOff;
       
   225                     iProperty.Subscribe(iStatus);
       
   226                     SetActive();
       
   227                     }           
       
   228                 }
   168             break;
   229             break;
   169             }
   230             }
   170         case (1):
   231         case (1):
   171             {
   232             {
   172             err = SetActiveProfile(KGeneralProfileId);
   233             // check of KPSGlobalSystemState is not already set to ESwStateNormalRfOn,
       
   234             // issue the profile change request and start monitoring the property
       
   235             if (systemState != ESwStateNormalRfOn)
       
   236                 {
       
   237                 err = SetActiveProfile(KGeneralProfileId);
       
   238                 
       
   239                 if (err == KErrNone)
       
   240                     {
       
   241                     iExpectedState = ESwStateNormalRfOn;
       
   242                     iProperty.Subscribe(iStatus);
       
   243                     SetActive();
       
   244                     }
       
   245                 }
   173             break;
   246             break;
   174             }
   247             }
   175         default:
   248         default:
   176             {
   249             {
   177             err = KErrArgument;
   250             err = KErrArgument;
   178             break;
   251             break;
   179             }
   252             }
   180         }
   253         }
   181     
   254     TRACE_FUNC_EXIT
   182     if (err == KErrNone && aReset == 1)
       
   183         {
       
   184         err = RestartDevice();
       
   185         }
       
   186     
       
   187     return err;
   255     return err;
   188     }
   256     }
   189 
   257 
   190 TInt CCFUNCommandHandler::SetActiveProfile(TInt aProfileId)
   258 TInt CCFUNCommandHandler::SetActiveProfile(TInt aProfileId)
   191     {
   259     {
       
   260     TRACE_FUNC_ENTRY
   192     TInt err = KErrNone;
   261     TInt err = KErrNone;
   193 
   262 
   194     if(iProfileEngine)
   263     if(iProfileEngine)
   195         {
   264         {
   196         TRAP(err, iProfileEngine->SetActiveProfileL( aProfileId ));
   265         TRAP(err, iProfileEngine->SetActiveProfileL( aProfileId ));
   197         }
   266         }
   198 
   267     TRACE_FUNC_EXIT
   199     return err;
   268     return err;
   200     }
   269     }
   201 
   270 
   202 TInt CCFUNCommandHandler::RestartDevice()
   271 TInt CCFUNCommandHandler::RestartDevice()
   203     {
   272     {
       
   273     TRACE_FUNC_ENTRY
   204     RStarterSession session;
   274     RStarterSession session;
   205     TInt err = session.Connect();
   275     TInt err = session.Connect();
   206 
   276 
   207     if( err == KErrNone )
   277     if( err == KErrNone )
   208         {
   278         {
   209         session.Reset(RStarterSession::EUnknownReset);
   279         session.Reset(RStarterSession::EUnknownReset);
   210         session.Close();
   280         session.Close();
   211         }
   281         }
   212 
   282     TRACE_FUNC_EXIT
   213     return err;
   283     return err;
   214     }
   284     }