Symbian3/Examples/guid-6013a680-57f9-415b-8851-c4fa63356636/gsastatepolicynormal_8cpp_source.html
author Dominic Pinkman <dominic.pinkman@nokia.com>
Fri, 13 Aug 2010 16:47:46 +0100
changeset 14 578be2adaf3e
parent 6 43e37759235e
permissions -rw-r--r--
Week 32 contribution of PDK documentation content. See release notes for details. Fixes bug Bug 3582

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
<title>TB9.2 Example Applications: examples/AppFramework/ssmanager/policies/sysstates/gsastatepolicynormal.cpp Source File</title>
<link href="tabs.css" rel="stylesheet" type="text/css"/>
<link href="doxygen.css" rel="stylesheet" type="text/css"/>
</head>
<body>
<!-- Generated by Doxygen 1.6.2 -->
<h1>examples/AppFramework/ssmanager/policies/sysstates/gsastatepolicynormal.cpp</h1><div class="fragment"><pre class="fragment"><a name="l00001"></a>00001 <span class="comment">// gsastatepolicynormal.cpp</span>
<a name="l00002"></a>00002 <span class="comment">//</span>
<a name="l00003"></a>00003 <span class="comment">// Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies).</span>
<a name="l00004"></a>00004 <span class="comment">// All rights reserved.</span>
<a name="l00005"></a>00005 <span class="comment">// This component and the accompanying materials are made available</span>
<a name="l00006"></a>00006 <span class="comment">// under the terms of &quot;Eclipse Public License v1.0&quot;</span>
<a name="l00007"></a>00007 <span class="comment">// which accompanies this distribution, and is available</span>
<a name="l00008"></a>00008 <span class="comment">// at the URL &quot;http://www.eclipse.org/legal/epl-v10.html&quot;.</span>
<a name="l00009"></a>00009 <span class="comment">//</span>
<a name="l00010"></a>00010 <span class="comment">// Initial Contributors:</span>
<a name="l00011"></a>00011 <span class="comment">// Nokia Corporation - initial contribution.</span>
<a name="l00012"></a>00012 <span class="comment">//</span>
<a name="l00013"></a>00013 <span class="comment">// Contributors:</span>
<a name="l00014"></a>00014 <span class="comment">//</span>
<a name="l00015"></a>00015 <span class="comment">// Extends the GSA (Generic Startup Architecture) normal policy to  </span>
<a name="l00016"></a>00016 <span class="comment">// to support the dummy backup and restore states added as part of this example. </span>
<a name="l00017"></a>00017 <span class="comment">// The default Normal state policy supports only the states start up, shut down, and fail.</span>
<a name="l00018"></a>00018 <span class="comment">// The example uses this extended normal state, which replaces the existing normal policy.</span>
<a name="l00019"></a>00019 <span class="comment">//  </span>
<a name="l00020"></a>00020 <span class="comment">// This example Normal State policy creates and registers a SwP (ssm.swp.policy.dummy.diskstatus.dll)</span>
<a name="l00021"></a>00021 <span class="comment">// with key KExampleSwPKey and KExampleSwPValue.</span>
<a name="l00022"></a>00022 
<a name="l00023"></a>00023 <span class="preprocessor">#include &lt;barsread2.h&gt;</span>
<a name="l00024"></a>00024 <span class="preprocessor">#include &lt;e32debug.h&gt;</span>
<a name="l00025"></a>00025 <span class="preprocessor">#include &lt;ssm/ssmcmd.hrh&gt;</span>
<a name="l00026"></a>00026 <span class="preprocessor">#include &lt;ssm/ssmsubstates.hrh&gt;</span>
<a name="l00027"></a>00027 
<a name="l00028"></a>00028 <span class="preprocessor">#include &lt;ssm/ssmstatetransition.h&gt;</span>
<a name="l00029"></a>00029 <span class="preprocessor">#include &lt;ssm/ssmcommandlistresourcereader.h&gt;</span>
<a name="l00030"></a>00030 
<a name="l00031"></a>00031 <span class="preprocessor">#include &quot;gsastatepolicynormal.h&quot;</span>
<a name="l00032"></a>00032 
<a name="l00036"></a>00036 <a class="code" href="secureclientandserver_8h.html#a5eadd4429627d82193b37536d4faa03a">_LIT</a>(KPanicGsaNormalState, <span class="stringliteral">&quot;NormalStatePolicy&quot;</span>);
<a name="l00037"></a>00037 
<a name="l00043"></a>00043 EXPORT_C MSsmStatePolicy* CEgGsaStatePolicyNormal::NewL()
<a name="l00044"></a>00044         {
<a name="l00045"></a>00045         CEgGsaStatePolicyNormal* <span class="keyword">self</span> = <span class="keyword">new</span> (ELeave) CEgGsaStatePolicyNormal;
<a name="l00046"></a>00046         CleanupStack::PushL(<span class="keyword">self</span>);
<a name="l00047"></a>00047         <span class="keyword">self</span>-&gt;ConstructL();
<a name="l00048"></a>00048         CleanupStack::Pop(<span class="keyword">self</span>);
<a name="l00049"></a>00049         <span class="keywordflow">return</span> <span class="keyword">self</span>;
<a name="l00050"></a>00050         }
<a name="l00051"></a>00051  
<a name="l00055"></a>00055 CEgGsaStatePolicyNormal::CEgGsaStatePolicyNormal()
<a name="l00056"></a>00056         {
<a name="l00057"></a>00057         }
<a name="l00058"></a>00058 
<a name="l00062"></a>00062 CEgGsaStatePolicyNormal::~CEgGsaStatePolicyNormal()
<a name="l00063"></a>00063         {
<a name="l00064"></a>00064         <span class="keyword">delete</span> iCommandListResourceReader;
<a name="l00065"></a>00065         iCurrentlySupportedTransitions.Close();
<a name="l00066"></a>00066         iFs.Close();    
<a name="l00067"></a>00067         }
<a name="l00068"></a>00068 
<a name="l00074"></a>00074 <span class="keywordtype">void</span> CEgGsaStatePolicyNormal::ConstructL()
<a name="l00075"></a>00075         {
<a name="l00076"></a>00076         User::LeaveIfError(iFs.Connect());
<a name="l00077"></a>00077         
<a name="l00078"></a>00078         <span class="comment">// Add supported transitions from Normal &#39;ESsmNormal&#39;</span>
<a name="l00079"></a>00079         iCurrentlySupportedTransitions.AppendL(TSsmState(ESsmShutdown, KSsmAnySubState));
<a name="l00080"></a>00080         iCurrentlySupportedTransitions.AppendL(TSsmState(ESsmFail, KSsmAnySubState));
<a name="l00081"></a>00081         iCurrentlySupportedTransitions.AppendL(TSsmState(ESsmShutdown, ESsmShutdownSubStateCritical));
<a name="l00082"></a>00082         iCurrentlySupportedTransitions.AppendL(TSsmState(ESsmBackup, ESsmBackupSubState));
<a name="l00083"></a>00083         iCurrentlySupportedTransitions.AppendL(TSsmState(ESsmRestore, ESsmRestoreSubState));
<a name="l00084"></a>00084         
<a name="l00085"></a>00085         <span class="comment">/*</span>
<a name="l00086"></a>00086 <span class="comment">    Normal state policy resource file path (&quot;z:\private&lt;SID of SSM&gt;\normal\&quot;).</span>
<a name="l00087"></a>00087 <span class="comment">    This resource file is already being generated by the production code, hence its not re-generated.</span>
<a name="l00088"></a>00088 <span class="comment">        */</span>
<a name="l00089"></a>00089         <a class="code" href="secureclientandserver_8h.html#a5eadd4429627d82193b37536d4faa03a">_LIT</a>(KCommandListPath, <span class="stringliteral">&quot;z:\\private\\2000D75B\\normal\\&quot;</span>);
<a name="l00090"></a>00090         
<a name="l00091"></a>00091         <span class="comment">// Create a resource reader</span>
<a name="l00092"></a>00092         iCommandListResourceReader = CSsmCommandListResourceReader::NewL(iFs, KCommandListPath(), *<span class="keyword">this</span>);
<a name="l00093"></a>00093         }
<a name="l00094"></a>00094 
<a name="l00103"></a>00103 <span class="keywordtype">void</span> CEgGsaStatePolicyNormal::Initialize(TRequestStatus&amp; aStatus)
<a name="l00104"></a>00104         {
<a name="l00105"></a>00105         __ASSERT_DEBUG(iCommandListResourceReader, User::Panic(KPanicGsaNormalState, EInvalidResourceReader));
<a name="l00106"></a>00106 
<a name="l00107"></a>00107         <span class="comment">// initialise command list resource reader.</span>
<a name="l00108"></a>00108         iCommandListResourceReader-&gt;Initialise(aStatus);
<a name="l00109"></a>00109         }
<a name="l00110"></a>00110 
<a name="l00116"></a>00116 <span class="keywordtype">void</span> CEgGsaStatePolicyNormal::InitializeCancel()
<a name="l00117"></a>00117         {
<a name="l00118"></a>00118         __ASSERT_DEBUG(iCommandListResourceReader, User::Panic(KPanicGsaNormalState, EInvalidResourceReader));
<a name="l00119"></a>00119         iCommandListResourceReader-&gt;InitialiseCancel();
<a name="l00120"></a>00120         }
<a name="l00121"></a>00121 
<a name="l00127"></a>00127 <span class="keywordtype">void</span> CEgGsaStatePolicyNormal::Release()
<a name="l00128"></a>00128         {
<a name="l00129"></a>00129         <span class="keyword">delete</span> <span class="keyword">this</span>;
<a name="l00130"></a>00130         }
<a name="l00131"></a>00131 
<a name="l00149"></a>00149 MSsmStatePolicy::TResponse CEgGsaStatePolicyNormal::TransitionAllowed(<span class="keyword">const</span> TSsmStateTransition&amp; aRequest, TSsmStateTransition <span class="keyword">const</span>* aCurrent, 
<a name="l00150"></a>00150                                                                                                                         TSsmStateTransition <span class="keyword">const</span>* aQueued, <span class="keyword">const</span> RMessagePtr2&amp; aMessage)
<a name="l00151"></a>00151         {
<a name="l00152"></a>00152         TResponse response = ENotAllowed;
<a name="l00153"></a>00153         <span class="keywordflow">if</span> (!aMessage.HasCapability(ECapabilityPowerMgmt))
<a name="l00154"></a>00154                 {
<a name="l00155"></a>00155                 <span class="keywordflow">return</span> response;
<a name="l00156"></a>00156                 }
<a name="l00157"></a>00157 
<a name="l00158"></a>00158         <span class="comment">// Check if the requested transition is supported from the current state</span>
<a name="l00159"></a>00159         <span class="keywordflow">if</span> (TransitionSupported(aRequest.State()))
<a name="l00160"></a>00160                 {
<a name="l00161"></a>00161                 <span class="keywordflow">if</span>((NULL == aCurrent) &amp;&amp; (NULL == aQueued))
<a name="l00162"></a>00162                         {
<a name="l00163"></a>00163                         <span class="comment">// SsmServer is idle</span>
<a name="l00164"></a>00164                         response = EDefinitelyAllowed;
<a name="l00165"></a>00165                         }
<a name="l00166"></a>00166                 <span class="keywordflow">else</span> <span class="keywordflow">if</span>(aRequest.State().MainState() == ESsmFail)
<a name="l00167"></a>00167                         {
<a name="l00168"></a>00168                         <span class="comment">// Going into failed state will override anything currently ongoing or queued</span>
<a name="l00169"></a>00169                         response = EReplaceCurrentClearQueue;
<a name="l00170"></a>00170                         }
<a name="l00171"></a>00171                 }
<a name="l00172"></a>00172         TSsmStateName name = aRequest.State().Name();
<a name="l00173"></a>00173         <span class="keywordflow">return</span> response;                
<a name="l00174"></a>00174         }
<a name="l00175"></a>00175 
<a name="l00187"></a>00187 <span class="keywordtype">void</span> CEgGsaStatePolicyNormal::PrepareCommandList(TSsmState aState, TInt <span class="comment">/*aReason*/</span>, TRequestStatus&amp; aStatus)
<a name="l00188"></a>00188         {
<a name="l00189"></a>00189         __ASSERT_DEBUG( iCommandListResourceReader , User::Panic(KPanicGsaNormalState, EInvalidResourceReader));
<a name="l00190"></a>00190 
<a name="l00191"></a>00191         <span class="comment">// Start from the beginning if no specific substate is selected</span>
<a name="l00192"></a>00192         <span class="keyword">const</span> TUint16 substate = aState.SubState();
<a name="l00193"></a>00193         <span class="keyword">const</span> TSsmState state(aState.MainState(), (substate==KSsmAnySubState) ? ESsmNormalSubState : substate);
<a name="l00194"></a>00194         <span class="keyword">const</span> TInt commandListId = state.SubState();
<a name="l00195"></a>00195 
<a name="l00196"></a>00196         <span class="comment">// Build the command list from the resource</span>
<a name="l00197"></a>00197         iCommandListResourceReader-&gt;PrepareCommandList(commandListId, state, aStatus);
<a name="l00198"></a>00198         } 
<a name="l00199"></a>00199 
<a name="l00205"></a>00205 <span class="keywordtype">void</span> CEgGsaStatePolicyNormal::PrepareCommandListCancel()
<a name="l00206"></a>00206         {
<a name="l00207"></a>00207         iCommandListResourceReader-&gt;PrepareCommandListCancel();
<a name="l00208"></a>00208         }
<a name="l00209"></a>00209 
<a name="l00216"></a>00216 CSsmCommandList* CEgGsaStatePolicyNormal::CommandList()
<a name="l00217"></a>00217         {
<a name="l00218"></a>00218         __ASSERT_DEBUG( iCommandListResourceReader , User::Panic(KPanicGsaNormalState, EInvalidResourceReader));
<a name="l00219"></a>00219 
<a name="l00220"></a>00220         <span class="keywordflow">return</span> iCommandListResourceReader-&gt;GetCommandList();
<a name="l00221"></a>00221         }
<a name="l00222"></a>00222 
<a name="l00235"></a>00235 TBool CEgGsaStatePolicyNormal::GetNextState(TSsmState aCurrentTransition, TInt <span class="comment">/*aReason*/</span>, TInt aError, TInt <span class="comment">/*aSeverity*/</span>, TSsmState&amp; aNextState)
<a name="l00236"></a>00236         {
<a name="l00237"></a>00237         __ASSERT_ALWAYS(aCurrentTransition.MainState() == ESsmNormal, User::Panic(KPanicGsaNormalState, EInvalidNormalState));
<a name="l00238"></a>00238         <span class="keywordflow">if</span> (KErrNone != aError)
<a name="l00239"></a>00239                 {
<a name="l00240"></a>00240                 aNextState = TSsmState(ESsmFail, KSsmAnySubState);
<a name="l00241"></a>00241                 TSsmStateName name = aNextState.Name();
<a name="l00242"></a>00242                 <span class="keywordflow">return</span> ETrue;
<a name="l00243"></a>00243                 }
<a name="l00244"></a>00244 
<a name="l00245"></a>00245         <span class="keywordflow">return</span> EFalse;  <span class="comment">// no more substates to execute</span>
<a name="l00246"></a>00246         } 
<a name="l00247"></a>00247 
<a name="l00258"></a>00258 TBool CEgGsaStatePolicyNormal::ConditionalCommandAllowedL(CResourceFile&amp; <span class="comment">/*aResourceFile*/</span>, TInt <span class="comment">/*aResourceId*/</span>)
<a name="l00259"></a>00259         {
<a name="l00260"></a>00260         <span class="comment">// no commands use &#39;conditional_information&#39; in Normal state command list.</span>
<a name="l00261"></a>00261         User::Panic(KPanicGsaNormalState, EConditionalInfoNotImplemented);
<a name="l00262"></a>00262         <span class="keywordflow">return</span> EFalse;  <span class="comment">// avoid a compiler warning.</span>
<a name="l00263"></a>00263         }
<a name="l00264"></a>00264 
<a name="l00265"></a>00265 <span class="comment">/*</span>
<a name="l00266"></a>00266 <span class="comment">Helper function to check whether requested transition is supported or not.</span>
<a name="l00267"></a>00267 <span class="comment">@param aRequestedState Requested transition</span>
<a name="l00268"></a>00268 <span class="comment">@return         ETrue if transition is supported</span>
<a name="l00269"></a>00269 <span class="comment">                EFalse if transition is not supported</span>
<a name="l00270"></a>00270 <span class="comment">*/</span>
<a name="l00271"></a>00271 TBool CEgGsaStatePolicyNormal::TransitionSupported(<span class="keyword">const</span> TSsmState&amp; aRequestedState)<span class="keyword"> const</span>
<a name="l00272"></a>00272 <span class="keyword">        </span>{
<a name="l00273"></a>00273         <span class="keywordflow">return</span> (iCurrentlySupportedTransitions.Find(aRequestedState) &gt; KErrNotFound);
<a name="l00274"></a>00274         }
</pre></div></div>
<hr size="1"/><address style="text-align: right;"><small>Generated by&nbsp;
<a href="http://www.doxygen.org/index.html">
<img class="footer" src="doxygen.png" alt="doxygen"/></a> 1.6.2 </small></address>
</body>
</html>