sysstatemgmt/ssmcustcmds/ssmsystemcmds/src/ssmsashutdown.cpp
changeset 0 4e1aa6a622a0
equal deleted inserted replaced
-1:000000000000 0:4e1aa6a622a0
       
     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:
       
    15 * Implementation of CSsmSaShutdown class.
       
    16 *
       
    17 */
       
    18 
       
    19 #include "ssmsashutdown.h"
       
    20 #include "ssmmapperutilitystatic.h"
       
    21 #include "trace.h"
       
    22 
       
    23 #include <starterdomaincrkeys.h>
       
    24 #include <ssm/startupadaptationcommands.h>
       
    25 
       
    26 // ======== LOCAL FUNCTIONS ========
       
    27 
       
    28 // ---------------------------------------------------------------------------
       
    29 // ReadStartupReasonL
       
    30 // ---------------------------------------------------------------------------
       
    31 //
       
    32 static void ReadStartupReasonL( TInt& aReasonCode )
       
    33     {
       
    34     FUNC_LOG;
       
    35 
       
    36     TInt err = SsmMapperUtility::CrValue( KCRUidStartup, KStartupReason, 
       
    37                                           aReasonCode );
       
    38     ERROR( err, "Failed to get KStartupReason CenRep key" );
       
    39     User::LeaveIfError( err );
       
    40     }
       
    41 
       
    42 
       
    43 // ---------------------------------------------------------------------------
       
    44 // FromCenRepReasonToAdaptation
       
    45 // ---------------------------------------------------------------------------
       
    46 //
       
    47 static TInt FromCenRepReasonToAdaptation( const TInt aReasonCode )
       
    48     {
       
    49     FUNC_LOG;
       
    50     INFO_1( "Startup reason from CentRep = %d", aReasonCode );
       
    51 
       
    52     switch ( aReasonCode )
       
    53         {
       
    54         case ELanguageSwitchReset:      return StartupAdaptation::ELanguageSwitchReset;
       
    55         case ENormalRFSReset:           return StartupAdaptation::ENormalRFSReset;
       
    56         case EDeepRFSReset:             return StartupAdaptation::EDeepRFSReset;
       
    57         case EOperatorSettingReset:     return StartupAdaptation::EOperatorSettingReset;
       
    58         case ENetworkModeChangeReset:   return StartupAdaptation::ENetworkModeChangeReset;
       
    59         case ESIMStatusChangeReset:     return StartupAdaptation::ESIMStatusChangeReset;
       
    60         case EDRMReset:                 return StartupAdaptation::EDRMReset;
       
    61         case EFirmwareUpdate:           return StartupAdaptation::EFirmwareUpdate;
       
    62         case EDataRestoreReset:         return StartupAdaptation::EDataRestoreReset;
       
    63         case EFieldTestReset:           return StartupAdaptation::EFieldTestReset;
       
    64         case EUnknownReset:
       
    65         default:
       
    66             return StartupAdaptation::EUnknownReset;
       
    67         }
       
    68     }
       
    69 
       
    70 // ======== MEMBER FUNCTIONS ========
       
    71 
       
    72 // ---------------------------------------------------------------------------
       
    73 // CSsmSaShutdown::NewL
       
    74 // ---------------------------------------------------------------------------
       
    75 //
       
    76 CSsmSaShutdown* CSsmSaShutdown::NewL()
       
    77 	{
       
    78     FUNC_LOG;
       
    79 	return new ( ELeave ) CSsmSaShutdown();
       
    80 	}
       
    81 
       
    82 
       
    83 // ---------------------------------------------------------------------------
       
    84 // CSsmSaShutdown::~CSsmSaShutdown
       
    85 // ---------------------------------------------------------------------------
       
    86 //
       
    87 CSsmSaShutdown::~CSsmSaShutdown()
       
    88     {
       
    89     FUNC_LOG;
       
    90     
       
    91     Cancel();
       
    92     Close();
       
    93     }
       
    94 
       
    95 
       
    96 // ---------------------------------------------------------------------------
       
    97 // CSsmSaShutdown::Initialize
       
    98 // ---------------------------------------------------------------------------
       
    99 //
       
   100 TInt CSsmSaShutdown::Initialize( CSsmCustomCommandEnv* /*aCmdEnv*/ )
       
   101     {
       
   102     FUNC_LOG;
       
   103 
       
   104     TInt errorCode = iAdaptation.Connect();
       
   105     ERROR( errorCode, "Failed to connect to RSsmStateAdaptation" );
       
   106     return errorCode;
       
   107     }
       
   108 
       
   109 
       
   110 // ---------------------------------------------------------------------------
       
   111 // CSsmSaShutdown::Execute
       
   112 // ---------------------------------------------------------------------------
       
   113 //
       
   114 void CSsmSaShutdown::Execute( const TDesC8& /*aParams*/, 
       
   115                               TRequestStatus& aRequest )
       
   116     {
       
   117     FUNC_LOG;
       
   118 
       
   119     aRequest = KRequestPending;
       
   120     iClientStatus = &aRequest;
       
   121 
       
   122     TInt reasonCode( ENormalStartup );
       
   123     TRAPD_ERR( errorCode, ReadStartupReasonL( reasonCode ) );
       
   124     ERROR( errorCode, "Failed to read startup reason, using default" );
       
   125 
       
   126     if ( reasonCode == ENormalStartup )
       
   127         {
       
   128         iAdaptation.RequestCoopSysPerformShutdownActions( 0, iStatus );
       
   129         }
       
   130     else
       
   131         {
       
   132         reasonCode = FromCenRepReasonToAdaptation( reasonCode );
       
   133         INFO_1( "Startup Adaptation reset reason = %d", reasonCode );
       
   134         iAdaptation.RequestCoopSysPerformRestartActions(
       
   135             reasonCode, iStatus );
       
   136         }
       
   137 
       
   138     SetActive();
       
   139     }
       
   140 
       
   141 
       
   142 // ---------------------------------------------------------------------------
       
   143 // CSsmSaShutdown::ExecuteCancel
       
   144 // ---------------------------------------------------------------------------
       
   145 //
       
   146 void CSsmSaShutdown::ExecuteCancel()
       
   147     {
       
   148     FUNC_LOG;
       
   149 
       
   150     Cancel();
       
   151     }
       
   152 
       
   153 
       
   154 // ---------------------------------------------------------------------------
       
   155 // CSsmSaShutdown::Close
       
   156 // ---------------------------------------------------------------------------
       
   157 //
       
   158 void CSsmSaShutdown::Close()
       
   159     {
       
   160     FUNC_LOG;
       
   161 
       
   162     iAdaptation.Close();
       
   163     }
       
   164 
       
   165 
       
   166 // ---------------------------------------------------------------------------
       
   167 // CSsmSaShutdown::Release
       
   168 // ---------------------------------------------------------------------------
       
   169 //
       
   170 void CSsmSaShutdown::Release()
       
   171     {
       
   172     FUNC_LOG;
       
   173 
       
   174 	delete this;
       
   175     }
       
   176 
       
   177 // ---------------------------------------------------------------------------
       
   178 // CSsmSaShutdown::CSsmSaShutdown
       
   179 // ---------------------------------------------------------------------------
       
   180 //
       
   181 CSsmSaShutdown::CSsmSaShutdown() : CActive( EPriorityNormal )
       
   182     {
       
   183     FUNC_LOG;
       
   184 
       
   185     CActiveScheduler::Add( this );
       
   186     }
       
   187 
       
   188 // ---------------------------------------------------------------------------
       
   189 // CSsmSaShutdown::RunL
       
   190 // ---------------------------------------------------------------------------
       
   191 //
       
   192 void CSsmSaShutdown::RunL()
       
   193     {
       
   194     FUNC_LOG;
       
   195     ERROR( iStatus.Int(), "CSsmSaShutdown::RunL" );
       
   196 
       
   197     User::RequestComplete( iClientStatus, iStatus.Int() );
       
   198     }
       
   199 
       
   200 
       
   201 // ---------------------------------------------------------------------------
       
   202 // CSsmSaShutdown::DoCancel
       
   203 //
       
   204 // ---------------------------------------------------------------------------
       
   205 //
       
   206 void CSsmSaShutdown::DoCancel()
       
   207     {
       
   208     FUNC_LOG;
       
   209 
       
   210     iAdaptation.RequestCancel();
       
   211     User::RequestComplete( iClientStatus, KErrCancel );
       
   212     }
       
   213