00001 // 00002 // Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies). 00003 // All rights reserved. 00004 // This component and the accompanying materials are made available 00005 // under the terms of "Eclipse Public License v1.0" 00006 // which accompanies this distribution, and is available 00007 // at the URL "http://www.eclipse.org/legal/epl-v10.html". 00008 // 00009 // Initial Contributors: 00010 // Nokia Corporation - initial contribution. 00011 // 00012 // Contributors: 00013 // 00014 // Description: A dummy back up state policy is provided to demonstrate the utility 00015 // of System State Manager framework. 00016 // 00017 00032 #include <ssm/ssmcommandlist.h> 00033 #include <ssm/ssmcommandlistresourcereader.h> 00034 #include <ssm/ssmsubstates.hrh> 00035 #include "dummy_backup_statepolicy.h" 00036 00040 _LIT(KCommandListPath, "z:\\private\\2000d75b\\ssmaeg\\state_dummy_backup\\"); 00041 00045 _LIT(KExamplePolicyPanic,"Dummy Back up State Policy"); 00046 00052 EXPORT_C MSsmStatePolicy* CSsmDummyBackUpStatePolicy::NewL() 00053 { 00054 CSsmDummyBackUpStatePolicy* self = new (ELeave) CSsmDummyBackUpStatePolicy; 00055 CleanupStack::PushL(self); 00056 self->ConstructL(); 00057 CleanupStack::Pop(self); 00058 return self; 00059 } 00060 00064 CSsmDummyBackUpStatePolicy::CSsmDummyBackUpStatePolicy() 00065 { 00066 } 00067 00071 CSsmDummyBackUpStatePolicy::~CSsmDummyBackUpStatePolicy() 00072 { 00073 delete iCommandListResourceReader; 00074 iFs.Close(); 00075 iCurrentlySupportedTransitions.Close(); 00076 } 00077 00083 void CSsmDummyBackUpStatePolicy::ConstructL() 00084 { 00085 User::LeaveIfError(iFs.Connect()); 00086 00087 // Add supported transitions from Backup 'ESsmBackupSubState' 00088 iCurrentlySupportedTransitions.AppendL(TSsmState(ESsmShutdown, KSsmAnySubState)); 00089 iCurrentlySupportedTransitions.AppendL(TSsmState(ESsmFail, KSsmAnySubState)); 00090 iCurrentlySupportedTransitions.AppendL(TSsmState(ESsmShutdown, ESsmShutdownSubStateCritical)); 00091 iCurrentlySupportedTransitions.AppendL(TSsmState(ESsmNormal, KSsmAnySubState)); 00092 iCurrentlySupportedTransitions.AppendL(TSsmState(ESsmRestore, ESsmRestoreSubState)); 00093 // create resource reader 00094 iCommandListResourceReader = CSsmCommandListResourceReader::NewL(iFs, KCommandListPath(), *this); 00095 } 00096 00105 void CSsmDummyBackUpStatePolicy::Initialize(TRequestStatus& aStatus) 00106 { 00107 __ASSERT_ALWAYS(iCommandListResourceReader, User::Panic(KExamplePolicyPanic, EInvalidResourceReader)); 00108 // initialise command list resource reader. 00109 iCommandListResourceReader->Initialise(aStatus); 00110 } 00111 00119 void CSsmDummyBackUpStatePolicy::InitializeCancel() 00120 { 00121 __ASSERT_ALWAYS(iCommandListResourceReader, User::Panic(KExamplePolicyPanic, EInvalidResourceReader)); 00122 iCommandListResourceReader->InitialiseCancel(); 00123 } 00124 00130 void CSsmDummyBackUpStatePolicy::Release() 00131 { 00132 delete this; 00133 } 00134 00153 MSsmStatePolicy::TResponse CSsmDummyBackUpStatePolicy::TransitionAllowed(const TSsmStateTransition& aRequest, TSsmStateTransition const* aCurrent, TSsmStateTransition const* aQueued, const RMessagePtr2& aMessage) 00154 { 00155 TResponse response = ENotAllowed; 00156 if (!aMessage.HasCapability(ECapabilityPowerMgmt)) 00157 { 00158 return response; 00159 } 00160 00161 //Check if the requested transition is supported from current state 00162 if (TransitionSupported(aRequest.State())) 00163 { 00164 if((NULL == aCurrent) && (NULL == aQueued)) 00165 { 00166 // SsmServer is idle 00167 response = EDefinitelyAllowed; 00168 } 00169 else if(aRequest.State().MainState() == ESsmFail || aRequest.State().MainState() == ESsmShutdown) 00170 { 00171 // Going into failed state will override anything currently ongoing or queued 00172 response = EReplaceCurrentClearQueue; 00173 } 00174 } 00175 return response; 00176 } 00186 void CSsmDummyBackUpStatePolicy::PrepareCommandList(TSsmState aState, TInt /*aReason*/, TRequestStatus& aStatus) 00187 { 00188 __ASSERT_ALWAYS(iCommandListResourceReader, User::Panic(KExamplePolicyPanic, EInvalidResourceReader)); 00189 //Let's start from the beginning if no specific sub state is selected 00190 const TUint16 substate = aState.SubState(); 00191 //Build the command list from a resource for this substate 00192 iCommandListResourceReader->PrepareCommandList(substate, aState, aStatus); 00193 } 00194 00200 void CSsmDummyBackUpStatePolicy::PrepareCommandListCancel() 00201 { 00202 __ASSERT_ALWAYS(iCommandListResourceReader, User::Panic(KExamplePolicyPanic, EInvalidResourceReader)); 00203 iCommandListResourceReader->PrepareCommandListCancel(); 00204 } 00205 00212 CSsmCommandList* CSsmDummyBackUpStatePolicy::CommandList() 00213 { 00214 __ASSERT_ALWAYS(iCommandListResourceReader, User::Panic(KExamplePolicyPanic, EInvalidResourceReader)); 00215 return iCommandListResourceReader->GetCommandList(); 00216 } 00217 00229 TBool CSsmDummyBackUpStatePolicy::GetNextState(TSsmState /*aCurrentTransition*/, TInt /*aReason*/, TInt /*aError*/, TInt /*aSeverity*/, TSsmState& /*aNextState*/) 00230 { 00231 return EFalse; 00232 } 00233 00244 TBool CSsmDummyBackUpStatePolicy::ConditionalCommandAllowedL(CResourceFile& /*aResourceFile*/, TInt /*aResourceId*/) 00245 { 00246 return EFalse; //command list doesn't contains commands which have conditions and hence returning EFalse 00247 } 00248 00249 /* 00250 Helper function to check whether a requested transition is supported or not. 00251 @param aRequestedState Requested transition 00252 @return ETrue if transition is supported 00253 EFalse if transition is not supported 00254 */ 00255 TBool CSsmDummyBackUpStatePolicy::TransitionSupported(const TSsmState& aRequestedState) const 00256 { 00257 return (iCurrentlySupportedTransitions.Find(aRequestedState) > KErrNotFound); 00258 }
Copyright ©2010 Nokia Corporation and/or its subsidiary(-ies).
All rights
reserved. Unless otherwise stated, these materials are provided under the terms of the Eclipse Public License
v1.0.