diff -r 89d6a7a84779 -r 25a17d01db0c Symbian3/Examples/guid-6013a680-57f9-415b-8851-c4fa63356636/gsastatepolicynormal_8cpp-source.html --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Symbian3/Examples/guid-6013a680-57f9-415b-8851-c4fa63356636/gsastatepolicynormal_8cpp-source.html Fri Jan 22 18:26:19 2010 +0000 @@ -0,0 +1,188 @@ + + +TB10.1 Example Applications: examples/AppFramework/ssmanager/policies/sysstates/gsastatepolicynormal.cpp Source File + + + + +

examples/AppFramework/ssmanager/policies/sysstates/gsastatepolicynormal.cpp

00001 // gsastatepolicynormal.cpp
+00002 //
+00003 // Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies).
+00004 // All rights reserved.
+00005 // This component and the accompanying materials are made available
+00006 // under the terms of "Eclipse Public License v1.0"
+00007 // which accompanies this distribution, and is available
+00008 // at the URL "http://www.eclipse.org/legal/epl-v10.html".
+00009 //
+00010 // Initial Contributors:
+00011 // Nokia Corporation - initial contribution.
+00012 //
+00013 // Contributors:
+00014 //
+00015 // Extends the GSA (Generic Startup Architecture) normal policy to  
+00016 // to support the dummy backup and restore states added as part of this example. 
+00017 // The default Normal state policy supports only the states start up, shut down, and fail.
+00018 // The example uses this extended normal state, which replaces the existing normal policy.
+00019 //  
+00020 // This example Normal State policy creates and registers a SwP (ssm.swp.policy.dummy.diskstatus.dll)
+00021 // with key KExampleSwPKey and KExampleSwPValue.
+00022 
+00023 #include <barsread2.h>
+00024 #include <e32debug.h>
+00025 #include <ssm/ssmcmd.hrh>
+00026 #include <ssm/ssmsubstates.hrh>
+00027 
+00028 #include <ssm/ssmstatetransition.h>
+00029 #include <ssm/ssmcommandlistresourcereader.h>
+00030 
+00031 #include "gsastatepolicynormal.h"
+00032 
+00036 _LIT(KPanicGsaNormalState, "NormalStatePolicy");
+00037 
+00043 EXPORT_C MSsmStatePolicy* CEgGsaStatePolicyNormal::NewL()
+00044         {
+00045         CEgGsaStatePolicyNormal* self = new (ELeave) CEgGsaStatePolicyNormal;
+00046         CleanupStack::PushL(self);
+00047         self->ConstructL();
+00048         CleanupStack::Pop(self);
+00049         return self;
+00050         }
+00051  
+00055 CEgGsaStatePolicyNormal::CEgGsaStatePolicyNormal()
+00056         {
+00057         }
+00058 
+00062 CEgGsaStatePolicyNormal::~CEgGsaStatePolicyNormal()
+00063         {
+00064         delete iCommandListResourceReader;
+00065         iCurrentlySupportedTransitions.Close();
+00066         iFs.Close();    
+00067         }
+00068 
+00074 void CEgGsaStatePolicyNormal::ConstructL()
+00075         {
+00076         User::LeaveIfError(iFs.Connect());
+00077         
+00078         // Add supported transitions from Normal 'ESsmNormal'
+00079         iCurrentlySupportedTransitions.AppendL(TSsmState(ESsmShutdown, KSsmAnySubState));
+00080         iCurrentlySupportedTransitions.AppendL(TSsmState(ESsmFail, KSsmAnySubState));
+00081         iCurrentlySupportedTransitions.AppendL(TSsmState(ESsmShutdown, ESsmShutdownSubStateCritical));
+00082         iCurrentlySupportedTransitions.AppendL(TSsmState(ESsmBackup, ESsmBackupSubState));
+00083         iCurrentlySupportedTransitions.AppendL(TSsmState(ESsmRestore, ESsmRestoreSubState));
+00084         
+00085         /*
+00086     Normal state policy resource file path ("z:\private<SID of SSM>\normal\").
+00087     This resource file is already being generated by the production code, hence its not re-generated.
+00088         */
+00089         _LIT(KCommandListPath, "z:\\private\\2000D75B\\normal\\");
+00090         
+00091         // Create a resource reader
+00092         iCommandListResourceReader = CSsmCommandListResourceReader::NewL(iFs, KCommandListPath(), *this);
+00093         }
+00094 
+00103 void CEgGsaStatePolicyNormal::Initialize(TRequestStatus& aStatus)
+00104         {
+00105         __ASSERT_DEBUG(iCommandListResourceReader, User::Panic(KPanicGsaNormalState, EInvalidResourceReader));
+00106 
+00107         // initialise command list resource reader.
+00108         iCommandListResourceReader->Initialise(aStatus);
+00109         }
+00110 
+00116 void CEgGsaStatePolicyNormal::InitializeCancel()
+00117         {
+00118         __ASSERT_DEBUG(iCommandListResourceReader, User::Panic(KPanicGsaNormalState, EInvalidResourceReader));
+00119         iCommandListResourceReader->InitialiseCancel();
+00120         }
+00121 
+00127 void CEgGsaStatePolicyNormal::Release()
+00128         {
+00129         delete this;
+00130         }
+00131 
+00149 MSsmStatePolicy::TResponse CEgGsaStatePolicyNormal::TransitionAllowed(const TSsmStateTransition& aRequest, TSsmStateTransition const* aCurrent, 
+00150                                                                                                                         TSsmStateTransition const* aQueued, const RMessagePtr2& aMessage)
+00151         {
+00152         TResponse response = ENotAllowed;
+00153         if (!aMessage.HasCapability(ECapabilityPowerMgmt))
+00154                 {
+00155                 return response;
+00156                 }
+00157 
+00158         // Check if the requested transition is supported from the current state
+00159         if (TransitionSupported(aRequest.State()))
+00160                 {
+00161                 if((NULL == aCurrent) && (NULL == aQueued))
+00162                         {
+00163                         // SsmServer is idle
+00164                         response = EDefinitelyAllowed;
+00165                         }
+00166                 else if(aRequest.State().MainState() == ESsmFail)
+00167                         {
+00168                         // Going into failed state will override anything currently ongoing or queued
+00169                         response = EReplaceCurrentClearQueue;
+00170                         }
+00171                 }
+00172         TSsmStateName name = aRequest.State().Name();
+00173         return response;                
+00174         }
+00175 
+00187 void CEgGsaStatePolicyNormal::PrepareCommandList(TSsmState aState, TInt /*aReason*/, TRequestStatus& aStatus)
+00188         {
+00189         __ASSERT_DEBUG( iCommandListResourceReader , User::Panic(KPanicGsaNormalState, EInvalidResourceReader));
+00190 
+00191         // Start from the beginning if no specific substate is selected
+00192         const TUint16 substate = aState.SubState();
+00193         const TSsmState state(aState.MainState(), (substate==KSsmAnySubState) ? ESsmNormalSubState : substate);
+00194         const TInt commandListId = state.SubState();
+00195 
+00196         // Build the command list from the resource
+00197         iCommandListResourceReader->PrepareCommandList(commandListId, state, aStatus);
+00198         } 
+00199 
+00205 void CEgGsaStatePolicyNormal::PrepareCommandListCancel()
+00206         {
+00207         iCommandListResourceReader->PrepareCommandListCancel();
+00208         }
+00209 
+00216 CSsmCommandList* CEgGsaStatePolicyNormal::CommandList()
+00217         {
+00218         __ASSERT_DEBUG( iCommandListResourceReader , User::Panic(KPanicGsaNormalState, EInvalidResourceReader));
+00219 
+00220         return iCommandListResourceReader->GetCommandList();
+00221         }
+00222 
+00235 TBool CEgGsaStatePolicyNormal::GetNextState(TSsmState aCurrentTransition, TInt /*aReason*/, TInt aError, TInt /*aSeverity*/, TSsmState& aNextState)
+00236         {
+00237         __ASSERT_ALWAYS(aCurrentTransition.MainState() == ESsmNormal, User::Panic(KPanicGsaNormalState, EInvalidNormalState));
+00238         if (KErrNone != aError)
+00239                 {
+00240                 aNextState = TSsmState(ESsmFail, KSsmAnySubState);
+00241                 TSsmStateName name = aNextState.Name();
+00242                 return ETrue;
+00243                 }
+00244 
+00245         return EFalse;  // no more substates to execute
+00246         } 
+00247 
+00258 TBool CEgGsaStatePolicyNormal::ConditionalCommandAllowedL(CResourceFile& /*aResourceFile*/, TInt /*aResourceId*/)
+00259         {
+00260         // no commands use 'conditional_information' in Normal state command list.
+00261         User::Panic(KPanicGsaNormalState, EConditionalInfoNotImplemented);
+00262         return EFalse;  // avoid a compiler warning.
+00263         }
+00264 
+00265 /*
+00266 Helper function to check whether requested transition is supported or not.
+00267 @param aRequestedState Requested transition
+00268 @return         ETrue if transition is supported
+00269                 EFalse if transition is not supported
+00270 */
+00271 TBool CEgGsaStatePolicyNormal::TransitionSupported(const TSsmState& aRequestedState) const
+00272         {
+00273         return (iCurrentlySupportedTransitions.Find(aRequestedState) > KErrNotFound);
+00274         }
+

Generated on Thu Jan 21 10:32:54 2010 for TB10.1 Example Applications by  + +doxygen 1.5.3
+ +