sysstatemgmt/ssmpolicyplugins/ssmshutdownpolicy/src/ssmshutdownpolicy.cpp
changeset 0 4e1aa6a622a0
child 7 1fc153c72b60
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: Implementation of CSsmShutdownPolicy class.
       
    15 *
       
    16 */
       
    17 
       
    18 #include <centralrepository.h>
       
    19 #include <ssm/ssmclayer.h>
       
    20 #include <ssm/ssmstate.h>
       
    21 #include <ssm/ssmstatetransition.h>
       
    22 #include <ssm/starterclient.h>
       
    23 #include <ssm/starterdomaincrkeys.h>
       
    24 
       
    25 #include "ssmsubstateext.hrh"
       
    26 #include "ssmmapperutility.h"
       
    27 #include "ssmshutdownpolicy.h"
       
    28 #include "trace.h"
       
    29 
       
    30 /**
       
    31 * Shutdown state policy resource file path format :
       
    32 * "\private\<SID of SSM>\shutdown\"
       
    33 */
       
    34 _LIT( KCommandListPath, "Z:\\private\\2000D75B\\shutdown\\" );
       
    35 
       
    36 // ======== LOCAL FUNCTIONS ========
       
    37 
       
    38 // ---------------------------------------------------------------------------
       
    39 // FromStarterReasonToCenRep
       
    40 // ---------------------------------------------------------------------------
       
    41 //
       
    42 static TInt FromStarterReasonToCenRep( const TInt aReasonCode )
       
    43     {
       
    44     FUNC_LOG;
       
    45     INFO_1( "Startup reason from RStarterSession %d", aReasonCode );
       
    46 
       
    47     switch ( aReasonCode )
       
    48         {
       
    49         case KSsmCLayerPowerOffReason:                   return ENormalStartup;
       
    50         case RStarterSession::ELanguageSwitchReset:      return ELanguageSwitchReset;
       
    51         case RStarterSession::ENormalRFSReset:           return ENormalRFSReset;
       
    52         case RStarterSession::EDeepRFSReset:             return EDeepRFSReset;
       
    53         case RStarterSession::EOperatorSettingReset:     return EOperatorSettingReset;
       
    54         case RStarterSession::ENetworkModeChangeReset:   return ENetworkModeChangeReset;
       
    55         case RStarterSession::ESIMStatusChangeReset:     return ESIMStatusChangeReset;
       
    56         case RStarterSession::EDRMReset:                 return EDRMReset;
       
    57         case RStarterSession::EFirmwareUpdate:           return EFirmwareUpdate;
       
    58         case RStarterSession::EDataRestoreReset:         return EDataRestoreReset;
       
    59         case RStarterSession::EFieldTestReset:           return EFieldTestReset;
       
    60         case RStarterSession::EUnknownReset:
       
    61         default:
       
    62             return EUnknownReset;
       
    63         }
       
    64     }
       
    65 
       
    66 
       
    67 // ======== MEMBER FUNCTIONS ========
       
    68 
       
    69 // ---------------------------------------------------------------------------
       
    70 // CSsmShutdownPolicy::NewL
       
    71 // ---------------------------------------------------------------------------
       
    72 //
       
    73 EXPORT_C MSsmStatePolicy* CSsmShutdownPolicy::NewL()
       
    74     {
       
    75     CSsmShutdownPolicy* self = new( ELeave ) CSsmShutdownPolicy;
       
    76     CleanupStack::PushL( self );
       
    77     self->BaseConstructL();
       
    78     CleanupStack::Pop( self );
       
    79     return self;
       
    80     }
       
    81 
       
    82 
       
    83 // ---------------------------------------------------------------------------
       
    84 // CSsmShutdownPolicy::~CSsmShutdownPolicy
       
    85 // ---------------------------------------------------------------------------
       
    86 //
       
    87 CSsmShutdownPolicy::~CSsmShutdownPolicy()
       
    88     {
       
    89     FUNC_LOG;
       
    90     }
       
    91 
       
    92 
       
    93 // ---------------------------------------------------------------------------
       
    94 // CSsmShutdownPolicy::GetNextState
       
    95 // ---------------------------------------------------------------------------
       
    96 //
       
    97 TBool CSsmShutdownPolicy::GetNextState(
       
    98     TSsmState aCurrentTransition,
       
    99     TInt aReason,
       
   100     TInt ERROR_PARAM( aError ),
       
   101     TInt ERROR_PARAM( aSeverity ),
       
   102     TSsmState& aNextState )
       
   103     {
       
   104     FUNC_LOG;
       
   105     INFO_3( "Current state %04x.%04x, reason %d",
       
   106         aCurrentTransition.MainState(), aCurrentTransition.SubState(), aReason );
       
   107     ERROR_1( aError, "State transition resulted in an error, severity %d", aSeverity );
       
   108 	ASSERT_TRACE( aCurrentTransition.MainState() == ESsmShutdown );
       
   109 
       
   110 	TBool moreToCome = EFalse;
       
   111     switch( aCurrentTransition.SubState() )
       
   112 	    {
       
   113         case ESsmErrorShutdown:
       
   114         case KSsmAnySubState:
       
   115         case ESsmNormalShutdown: // Fall through
       
   116             aNextState = TSsmState( ESsmShutdown, ESsmShutdownSubStateCritical );
       
   117 			moreToCome = ETrue;
       
   118 			break;
       
   119 		case ESsmShutdownSubStateCritical:
       
   120             aNextState = TSsmState( ESsmShutdown, ESsmShutdownSubStateNonCritical );
       
   121 			moreToCome = ETrue;
       
   122 			break;
       
   123         case ESsmShutdownSubStateNonCritical:
       
   124             aNextState = TSsmState( ESsmShutdown, ESsmShutdownSubStatePowerOff );
       
   125 			moreToCome = ETrue;
       
   126 			break;
       
   127         default:
       
   128 		    break;
       
   129 		}
       
   130 
       
   131     if ( aCurrentTransition.SubState() == ESsmErrorShutdown )
       
   132         {
       
   133         TRAPD_ERR( errorCode, StoreStartupReasonL( EUnknownReset ) );
       
   134         ERROR( errorCode, "Failed to store startup reason" );
       
   135         }
       
   136     else if ( aCurrentTransition.SubState() == KSsmAnySubState ||
       
   137               aCurrentTransition.SubState() == ESsmNormalShutdown )
       
   138         {
       
   139         // This needs to be done before Startup adaptation shutdown command
       
   140         TRAPD_ERR( errorCode, StoreStartupReasonL(
       
   141             FromStarterReasonToCenRep( aReason ) ) );
       
   142         ERROR( errorCode, "Failed to store startup reason" );
       
   143         }
       
   144 
       
   145 	return moreToCome;
       
   146     }
       
   147 
       
   148 
       
   149 // ---------------------------------------------------------------------------
       
   150 // CSsmShutdownPolicy::CSsmShutdownPolicy
       
   151 // ---------------------------------------------------------------------------
       
   152 //
       
   153 CSsmShutdownPolicy::CSsmShutdownPolicy()
       
   154     {
       
   155     FUNC_LOG;
       
   156     }
       
   157 
       
   158 
       
   159 // ---------------------------------------------------------------------------
       
   160 // CSsmShutdownPolicy::GetCommandListPathL
       
   161 // ---------------------------------------------------------------------------
       
   162 //
       
   163 void CSsmShutdownPolicy::GetCommandListPathL( TDes& aCmdListPath )
       
   164     {
       
   165     FUNC_LOG;
       
   166 
       
   167 	aCmdListPath.Format( KCommandListPath );
       
   168 	iUtil->GetCommandListPath( aCmdListPath );
       
   169     }
       
   170 
       
   171 
       
   172 // ---------------------------------------------------------------------------
       
   173 // CSsmShutdownPolicy::IsAllowedTargetState
       
   174 // ---------------------------------------------------------------------------
       
   175 //
       
   176 TBool CSsmShutdownPolicy::IsAllowedTargetState(
       
   177     const TSsmStateTransition& INFO_PARAM(aRequest) ) const
       
   178     {
       
   179     FUNC_LOG;
       
   180 
       
   181     INFO_2( "Requested target state = %04x.%04x", 
       
   182         aRequest.State().MainState(), aRequest.State().SubState() );
       
   183 
       
   184     return EFalse;
       
   185     }
       
   186 
       
   187 
       
   188 // ---------------------------------------------------------------------------
       
   189 // CSsmShutdownPolicy::TargetSubState
       
   190 // ---------------------------------------------------------------------------
       
   191 //
       
   192 TUint16 CSsmShutdownPolicy::TargetSubState( const TUint16 aRequestedSubState )
       
   193     {
       
   194     FUNC_LOG;
       
   195     INFO_1( "Requested sub state %04x", aRequestedSubState );
       
   196 
       
   197 	TUint16 subState = ( aRequestedSubState == KSsmAnySubState ) ?
       
   198         ESsmNormalShutdown : aRequestedSubState;
       
   199 
       
   200     INFO_1( "Target sub state %04x", subState );
       
   201     return subState;
       
   202     }
       
   203 
       
   204 
       
   205 // ---------------------------------------------------------------------------
       
   206 // CSsmShutdownPolicy::StoreStartupReasonL
       
   207 // ---------------------------------------------------------------------------
       
   208 //
       
   209 void CSsmShutdownPolicy::StoreStartupReasonL( const TInt aReasonCode )
       
   210     {
       
   211     FUNC_LOG;
       
   212     INFO_1( "Storing startup reason %d", aReasonCode );
       
   213 
       
   214     CRepository* repository =
       
   215         CRepository::NewLC( iUtil->CrUid( KCRUidStartup ) );
       
   216     TInt errorCode = repository->Set( KStartupReason, aReasonCode );
       
   217     ERROR( errorCode, "Failed to set KStartupReason CenRep key" );
       
   218     CleanupStack::PopAndDestroy( repository );
       
   219     User::LeaveIfError( errorCode );
       
   220     }