|
1 // Copyright (c) 2007-2009 Nokia Corporation and/or its subsidiary(-ies). |
|
2 // All rights reserved. |
|
3 // This component and the accompanying materials are made available |
|
4 // under the terms of "Eclipse Public License v1.0" |
|
5 // which accompanies this distribution, and is available |
|
6 // at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
7 // |
|
8 // Initial Contributors: |
|
9 // Nokia Corporation - initial contribution. |
|
10 // |
|
11 // Contributors: |
|
12 // |
|
13 // Description: |
|
14 // |
|
15 |
|
16 #include <barsread2.h> |
|
17 #include <e32property.h> |
|
18 #include <e32uid.h> |
|
19 |
|
20 #include <ssm/ssmcmd.hrh> |
|
21 #include <ssm/ssmsubstates.hrh> |
|
22 #include <ssm/ssmcommandlistresourcereader.h> |
|
23 |
|
24 #include "gsastatepolicyfail.h" |
|
25 #include "ssmdebug.h" |
|
26 #include "ssmpanic.h" |
|
27 |
|
28 /** |
|
29 Panic used by Fail policy plug-in when resource reader is invalid. |
|
30 Strings must not be longer than 16 characters or they will be truncated by User::Panic() |
|
31 */ |
|
32 _LIT(KPanicGsaFailState, "FailStatePolicy"); |
|
33 |
|
34 /** |
|
35 Fail state policy resource file path. "z:/private/<SID of SSM>/fail/" |
|
36 */ |
|
37 _LIT(KCommandListPath, "z:\\private\\2000D75B\\fail\\"); |
|
38 |
|
39 /** |
|
40 Used to create an instance of MSsmStatePolicy class. |
|
41 |
|
42 @return A pointer to an instance of MSsmStatePolicy |
|
43 */ |
|
44 EXPORT_C MSsmStatePolicy* CGsaStatePolicyFail::NewL() |
|
45 { |
|
46 CGsaStatePolicyFail* self = new (ELeave) CGsaStatePolicyFail; |
|
47 CleanupStack::PushL(self); |
|
48 self->ConstructL(); |
|
49 CleanupStack::Pop(self); |
|
50 return self; |
|
51 } |
|
52 |
|
53 /** |
|
54 default CTOR |
|
55 */ |
|
56 CGsaStatePolicyFail::CGsaStatePolicyFail() |
|
57 { |
|
58 } |
|
59 |
|
60 /** |
|
61 DTOR |
|
62 */ |
|
63 CGsaStatePolicyFail::~CGsaStatePolicyFail() |
|
64 { |
|
65 delete iCommandListResourceReader; |
|
66 iFs.Close(); |
|
67 } |
|
68 |
|
69 /** |
|
70 Makes a RFs connection. |
|
71 Creates Command list path and the resource reader. |
|
72 |
|
73 @leave One of the error value returned by RFs::Connect() or NewL() |
|
74 @see RFs::Connect() |
|
75 */ |
|
76 void CGsaStatePolicyFail::ConstructL() |
|
77 { |
|
78 User::LeaveIfError(iFs.Connect()); |
|
79 |
|
80 // create resource reader |
|
81 iCommandListResourceReader = CSsmCommandListResourceReader::NewL(iFs, KCommandListPath(), *this); |
|
82 } |
|
83 |
|
84 /** |
|
85 Initializes command list resource reader. |
|
86 |
|
87 @param aStatus to complete when the initialization operation has finished |
|
88 |
|
89 @panic EInvalidResourceReader if the command list resource reader is invalid |
|
90 |
|
91 @see MSsmStatePolicy::Initialize |
|
92 */ |
|
93 void CGsaStatePolicyFail::Initialize(TRequestStatus& aStatus) |
|
94 { |
|
95 __ASSERT_DEBUG(iCommandListResourceReader, PanicNow(KPanicGsaFailState, EInvalidResourceReader)); |
|
96 |
|
97 // initialise command list resource reader. |
|
98 iCommandListResourceReader->Initialise(aStatus); |
|
99 } |
|
100 |
|
101 /** |
|
102 Cancels an asynchronous Initialize operation. |
|
103 |
|
104 @see MSsmStatePolicy::InitializeCancel |
|
105 */ |
|
106 void CGsaStatePolicyFail::InitializeCancel() |
|
107 { |
|
108 iCommandListResourceReader->InitialiseCancel(); |
|
109 } |
|
110 |
|
111 /** |
|
112 Deletes all resources and frees itself. |
|
113 |
|
114 @see MSsmStatePolicy::Release |
|
115 */ |
|
116 void CGsaStatePolicyFail::Release() |
|
117 { |
|
118 delete this; |
|
119 } |
|
120 |
|
121 /** |
|
122 No transition is allowed from Fail state. Requests for transition to any state is returned as ENotAllowed. |
|
123 |
|
124 @param aRequest Contains information about the new request |
|
125 @param aCurrent Contains NULL or the first accepted but not yet completed transition request |
|
126 @param aQueued Contains NULL or a second accepted but not yet started transition request |
|
127 @param aMessage Message sent by SSM server |
|
128 |
|
129 @return always ENotAllowed |
|
130 @see MSsmStatePolicy::TransitionAllowed |
|
131 */ |
|
132 MSsmStatePolicy::TResponse CGsaStatePolicyFail::TransitionAllowed(const TSsmStateTransition& /*aRequest*/, TSsmStateTransition const* /*aCurrent*/, |
|
133 TSsmStateTransition const* /*aQueued*/, const RMessagePtr2& /*aMessage*/) |
|
134 { |
|
135 return ENotAllowed; |
|
136 } |
|
137 |
|
138 /** |
|
139 Create the command list associated with a sub state transition. |
|
140 |
|
141 @param aState Contains the state and substate that identifies the command list to create |
|
142 @param aReason Contains the reason as given by the request |
|
143 @param aStatus to complete when the operation has finished |
|
144 @panic EInvalidResourceReader if the command list resource reader is invalid |
|
145 @see MSsmStatePolicy::PrepareCommandList |
|
146 */ |
|
147 void CGsaStatePolicyFail::PrepareCommandList(TSsmState aState, TInt /*aReason*/, TRequestStatus& aStatus) |
|
148 { |
|
149 __ASSERT_DEBUG( iCommandListResourceReader , PanicNow(KPanicGsaFailState, EInvalidResourceReader)); |
|
150 |
|
151 //Let's start from the beginning if no specific sub state is selected |
|
152 const TUint16 substate = aState.SubState(); |
|
153 const TSsmState state(aState.MainState(), (substate==KSsmAnySubState) ? ESsmFailSubStateRestart : substate); |
|
154 const TInt commandListId = state.SubState(); |
|
155 |
|
156 //Build the commandlist from resource |
|
157 iCommandListResourceReader->PrepareCommandList(commandListId, state, aStatus); |
|
158 } //lint !e1746 Suppress parameter 'aState' could be made const reference |
|
159 |
|
160 /** |
|
161 Cancels asynchronous PrepareCommandList operation. |
|
162 |
|
163 @see MSsmStatePolicy::PrepareCommandListCancel |
|
164 */ |
|
165 void CGsaStatePolicyFail::PrepareCommandListCancel() |
|
166 { |
|
167 iCommandListResourceReader->PrepareCommandListCancel(); |
|
168 } |
|
169 |
|
170 /** |
|
171 Return the command list once the PrepareCommandList has completed. |
|
172 Ownership of the returned command list is transferred to the caller. |
|
173 @panic EInvalidResourceReader if the command list resource reader is invalid |
|
174 @return The command list created during the preceding PrepareCommandList step |
|
175 */ |
|
176 CSsmCommandList* CGsaStatePolicyFail::CommandList() |
|
177 { |
|
178 __ASSERT_DEBUG( iCommandListResourceReader , PanicNow(KPanicGsaFailState, EInvalidResourceReader)); |
|
179 |
|
180 return iCommandListResourceReader->GetCommandList(); |
|
181 } |
|
182 |
|
183 /** |
|
184 Determines the next sub state transition. |
|
185 Will never reach GetNextState() if transition to Fail is sucessful as the device would be shutdown/restarted. |
|
186 Only case when GetNextState is executed is due to a failure in executing Fail transition. |
|
187 This would cause a panic and thereby causing a device restart. |
|
188 |
|
189 @param aCurrentTransition Contains the last executed state |
|
190 @param aReason Contains the reason as given by the request |
|
191 @param aError Contains the completion code from the last executed sub-state transition |
|
192 @param aSeverity Contains the severity of the failed command in case the sub-state transition ended with an error |
|
193 @param aNextState The next System State to head for, if there is one |
|
194 @panic EInvalidFailState if the main state is not Fail |
|
195 @panic ERestartDevice if the value returned by CLE is null |
|
196 @return ETrue if aNextState contains another System State to head for, or |
|
197 EFalse if there is no further transitions to do. |
|
198 @see MSsmStatePolicy::GetNextState |
|
199 */ |
|
200 TBool CGsaStatePolicyFail::GetNextState(TSsmState aCurrentTransition, TInt /*aReason*/, TInt aError, TInt /*aSeverity*/, TSsmState& /*aNextState*/) |
|
201 { |
|
202 DEBUGPRINT2(_L("Fail Policy : CLE returned completion code : %d after executing the Fail command list."), aError); |
|
203 __ASSERT_ALWAYS(aCurrentTransition.MainState() == ESsmFail, PanicNow(KPanicGsaFailState, EInvalidFailState)); |
|
204 __ASSERT_ALWAYS((KErrNone == aError), PanicNow(KPanicGsaFailState, ERestartDevice)); |
|
205 |
|
206 |
|
207 return EFalse; // no more substates to execute |
|
208 |
|
209 } //lint !e1746 Suppress parameter 'aCurrentTransition' could be made const reference |
|
210 |
|
211 /** |
|
212 Callback used by CSsmCommandListResourceReader when a decision needs to be made |
|
213 on whether to include a command in a command list or not. |
|
214 |
|
215 @param aResourceFile Instance of CResourceFile |
|
216 @param aResourceId Resource id of SSM_SYMBIAN_CONDITIONAL_INFORMATION struct for command |
|
217 @return ETrue in case the command needs to be included in command list, else EFalse. |
|
218 |
|
219 @see MSsmConditionalCallback::ConditionalCommandAllowedL |
|
220 */ |
|
221 TBool CGsaStatePolicyFail::ConditionalCommandAllowedL(CResourceFile& /*aResourceFile*/, TInt /*aResourceId*/) |
|
222 { |
|
223 // no commands use 'conditional_information' in Fail state command list. |
|
224 PanicNow(KPanicGsaFailState, EConditionalInfoNotImplemented); |
|
225 return EFalse; // keeping compiler happy |
|
226 } |