|
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 <s32strm.h> |
|
17 #include <barsread2.h> |
|
18 #include <ssm/ssmstate.h> |
|
19 #include <domaindefs.h> |
|
20 |
|
21 #include "cmdpublishsystemstate.h" |
|
22 #include "ssmdebug.h" |
|
23 #include "ssmpanic.h" |
|
24 #include "ssmcommandparameters.h" |
|
25 |
|
26 /** |
|
27 Used to create an instance of CCmdPublishSystemState class from a read stream. |
|
28 CSsmCommandList::InternalizeL() uses this method to construct a command from stream. |
|
29 |
|
30 @param aReadStream Read stream containing data through which object can be created |
|
31 @return A pointer to an object of type CCmdPublishSystemState. |
|
32 */ |
|
33 CCmdPublishSystemState* CCmdPublishSystemState::NewL(RReadStream& aReadStream) |
|
34 { |
|
35 CCmdPublishSystemState* self = new (ELeave) CCmdPublishSystemState(); |
|
36 CleanupStack::PushL(self); |
|
37 self->ConstructL(aReadStream); |
|
38 CleanupStack::Pop(self); |
|
39 return self; |
|
40 } |
|
41 |
|
42 #ifdef SYMBIAN_SSM_FLEXIBLE_MERGE |
|
43 /** |
|
44 Used to create an instance of CCmdPublishSystemState class from given parameters. |
|
45 This method is used by SsmCommandFactory to create a command. |
|
46 |
|
47 @param aSeverity The severity of the command |
|
48 @param aExecutionBehaviour The execution behaviour of the command |
|
49 @param aInfo System state settings |
|
50 @param aPriority The priority of the command in the list |
|
51 @return A pointer to an object of type CCmdPublishSystemState. |
|
52 */ |
|
53 CCmdPublishSystemState* CCmdPublishSystemState::NewL(TCmdErrorSeverity aSeverity, TSsmExecutionBehaviour aExecutionBehaviour, const TSsmPublishSystemStateInfo& aInfo, const TUint16 aPriority) |
|
54 { |
|
55 CCmdPublishSystemState* self = new (ELeave) CCmdPublishSystemState(aSeverity, aExecutionBehaviour, aInfo, aPriority); |
|
56 CleanupStack::PushL(self); |
|
57 self->ConstructL(); |
|
58 CleanupStack::Pop(self); |
|
59 return self; |
|
60 } |
|
61 #endif |
|
62 |
|
63 /** |
|
64 Used to create an instance of CCmdPublishSystemState class from given parameters. |
|
65 This method is used by SsmCommandFactory to create a command. |
|
66 |
|
67 @param aSeverity The severity of the command |
|
68 @param aExecutionBehaviour The execution behaviour of the command |
|
69 @param aInfo System state settings |
|
70 @return A pointer to an object of type CCmdPublishSystemState. |
|
71 */ |
|
72 CCmdPublishSystemState* CCmdPublishSystemState::NewL(TCmdErrorSeverity aSeverity, TSsmExecutionBehaviour aExecutionBehaviour, const TSsmPublishSystemStateInfo& aInfo) |
|
73 { |
|
74 CCmdPublishSystemState* self = new (ELeave) CCmdPublishSystemState(aSeverity, aExecutionBehaviour, aInfo); |
|
75 CleanupStack::PushL(self); |
|
76 self->ConstructL(); |
|
77 CleanupStack::Pop(self); |
|
78 return self; |
|
79 } |
|
80 |
|
81 /** |
|
82 Used to create an instance of CCmdPublishSystemState class from resource. |
|
83 |
|
84 @param aCommandParameters Object data from a resource file |
|
85 @return A pointer to an object of type CCmdPublishSystemState. |
|
86 */ |
|
87 CCmdPublishSystemState* CCmdPublishSystemState::NewL(TSsmCommandParameters& aCommandParameters) |
|
88 { |
|
89 CCmdPublishSystemState* self = new (ELeave) CCmdPublishSystemState(); |
|
90 CleanupStack::PushL(self); |
|
91 self->ConstructL(aCommandParameters); |
|
92 CleanupStack::Pop(self); |
|
93 return self; |
|
94 } |
|
95 |
|
96 /** |
|
97 Used to create an instance of CCmdPublishSystemState class from CCmdPublishSystemState object |
|
98 Must be used only by CLE |
|
99 @param aCmdPublishSystemState CCmdPublishSystemState reference |
|
100 @return A pointer to an object of type CCmdPublishSystemState. |
|
101 */ |
|
102 CCmdPublishSystemState* CCmdPublishSystemState::NewLC(const CCmdPublishSystemState& aCmdPublishSystemState) |
|
103 { |
|
104 #ifdef SYMBIAN_SSM_FLEXIBLE_MERGE |
|
105 CCmdPublishSystemState* self = new (ELeave) CCmdPublishSystemState(aCmdPublishSystemState.Severity(),aCmdPublishSystemState.ExecutionBehaviour(), |
|
106 aCmdPublishSystemState.PublishSystemStateInfo(),aCmdPublishSystemState.Priority()); |
|
107 #else |
|
108 CCmdPublishSystemState* self = new (ELeave) CCmdPublishSystemState(aCmdPublishSystemState.Severity(),aCmdPublishSystemState.ExecutionBehaviour(), |
|
109 aCmdPublishSystemState.PublishSystemStateInfo()); |
|
110 #endif |
|
111 CleanupStack::PushL(self); |
|
112 self->ConstructL(aCmdPublishSystemState); |
|
113 return self; |
|
114 } |
|
115 |
|
116 void CCmdPublishSystemState::ConstructL(const CCmdPublishSystemState& aCmdPublishSystemState) |
|
117 { |
|
118 iConditionalResourceId = aCmdPublishSystemState.ConditionalInformation(); |
|
119 #ifdef SYMBIAN_SSM_FLEXIBLE_MERGE |
|
120 if (iConditionalResourceId != 0) |
|
121 { |
|
122 SetCommandResourceFileNameL(aCmdPublishSystemState.GetCommandResourceFileName()); |
|
123 } |
|
124 #endif |
|
125 } |
|
126 /** |
|
127 Destructor |
|
128 */ |
|
129 CCmdPublishSystemState::~CCmdPublishSystemState() |
|
130 { |
|
131 ExecuteCancel(); |
|
132 iDomainManager.Close(); |
|
133 } |
|
134 |
|
135 /** |
|
136 Execute this command |
|
137 |
|
138 @param aStatus the TRequestStatus of the active object calling this BIC |
|
139 */ |
|
140 void CCmdPublishSystemState::Execute(TRequestStatus& aStatus) |
|
141 { |
|
142 aStatus = KRequestPending; |
|
143 iExecuteRequest = &aStatus; |
|
144 iConnected = EFalse; |
|
145 |
|
146 if (iExecutionBehaviour != ESsmWaitForSignal) |
|
147 { |
|
148 // complete the execute request with KErrNone so that CLE can execute next command |
|
149 CompleteExecuteRequest(KErrNone); |
|
150 } |
|
151 // try to connect and request the transition |
|
152 TInt err = ConnectAndRequestTransition(); |
|
153 if (KErrNone != err) |
|
154 { |
|
155 // we need to retry in case of failures otherwise we have successfully requested for transition |
|
156 CompleteRequest(iStatus, err); |
|
157 } |
|
158 SetActive(); |
|
159 } |
|
160 |
|
161 /** |
|
162 Releases resources associated with this BIC |
|
163 */ |
|
164 void CCmdPublishSystemState::Release() |
|
165 { |
|
166 delete this; |
|
167 } |
|
168 |
|
169 /** |
|
170 Initiates a Cancel on the object. |
|
171 */ |
|
172 void CCmdPublishSystemState::ExecuteCancel() |
|
173 { |
|
174 //cancel the outstanding request |
|
175 Cancel(); |
|
176 //and complete the request with KErrCancel |
|
177 CompleteDeferredExecuteRequest(KErrCancel); |
|
178 } |
|
179 |
|
180 /** |
|
181 Returns the Type of the BIC |
|
182 |
|
183 @return The Type of the BIC |
|
184 */ |
|
185 TSsmCommandType CCmdPublishSystemState::Type() const |
|
186 { |
|
187 return ESsmCmdPublishSystemState; |
|
188 } |
|
189 |
|
190 /** |
|
191 Returns the Version of the BIC |
|
192 |
|
193 @return The maximum supported version of the BIC |
|
194 */ |
|
195 TInt CCmdPublishSystemState::MaxSupportedVersion() |
|
196 { |
|
197 #ifdef SYMBIAN_SSM_FLEXIBLE_MERGE |
|
198 return (static_cast<TInt>(ECmdPublishSystemStateVersionWithPriority)); |
|
199 #else |
|
200 return (static_cast<TInt>(ECmdPublishSystemStateInitialVersion)); |
|
201 #endif |
|
202 } |
|
203 |
|
204 /** |
|
205 Configures the BIC using data contained in a ReadStream |
|
206 |
|
207 @param aReadStream A read stream containing BIC data |
|
208 */ |
|
209 void CCmdPublishSystemState::InternalizeL(RReadStream& aReadStream) |
|
210 { |
|
211 iSeverity = static_cast<TCmdErrorSeverity>(aReadStream.ReadInt16L()); |
|
212 iExecutionBehaviour = static_cast<TSsmExecutionBehaviour>(aReadStream.ReadUint8L()); |
|
213 TSsmState state; |
|
214 state.SetFromInt(aReadStream.ReadUint32L()); |
|
215 #ifndef SYMBIAN_ENABLE_SPLIT_HEADERS |
|
216 const TDmTraverseDirection direction = static_cast<TDmTraverseDirection>(aReadStream.ReadInt32L()); |
|
217 #else |
|
218 const TSsmDmTraverseDirection direction = static_cast<TSsmDmTraverseDirection>(aReadStream.ReadInt32L()); |
|
219 #endif //SYMBIAN_ENABLE_SPLIT_HEADERS |
|
220 const TInt16 retries = aReadStream.ReadInt16L(); |
|
221 #ifdef SYMBIAN_SSM_FLEXIBLE_MERGE |
|
222 iPriority = aReadStream.ReadUint16L(); |
|
223 #endif |
|
224 TSsmPublishSystemStateInfo info; |
|
225 info.Set(state, direction, retries); |
|
226 iStateInfo = info; |
|
227 } |
|
228 |
|
229 /** |
|
230 Externalises the configuration of the BIC |
|
231 |
|
232 @param aWriteStream A write stream to write BIC data to |
|
233 */ |
|
234 void CCmdPublishSystemState::ExternalizeL(RWriteStream& aWriteStream) const |
|
235 { |
|
236 aWriteStream.WriteInt16L(iSeverity); |
|
237 aWriteStream.WriteUint8L(iExecutionBehaviour); |
|
238 aWriteStream.WriteInt32L(iStateInfo.State().Int()); |
|
239 aWriteStream.WriteInt32L(iStateInfo.Direction()); |
|
240 aWriteStream.WriteInt16L(iStateInfo.Retries()); |
|
241 #ifdef SYMBIAN_SSM_FLEXIBLE_MERGE |
|
242 aWriteStream.WriteUint16L(iPriority); |
|
243 #endif |
|
244 } |
|
245 |
|
246 /** |
|
247 Completes the tasks of the BIC |
|
248 */ |
|
249 void CCmdPublishSystemState::RunL() |
|
250 { |
|
251 DEBUGPRINT5A("CCmdPublishSystemState::RunL: Error %d Retry attempt %d of %d Connected %d", iStatus.Int(), iAttempts+1, iStateInfo.Retries(), iConnected); |
|
252 if (iStatus.Int() != KErrNone) |
|
253 { |
|
254 if (++iAttempts >= iStateInfo.Retries()) |
|
255 { |
|
256 SSMLOGLEAVE(iStatus.Int()); // exhausted retries |
|
257 } |
|
258 |
|
259 // try to connect and request the transition |
|
260 TInt err = ConnectAndRequestTransition(); |
|
261 if (KErrNone != err) |
|
262 { |
|
263 // we need to retry in case of failures otherwise we have successfully requested for transition |
|
264 CompleteRequest(iStatus, err); |
|
265 } |
|
266 SetActive(); |
|
267 } |
|
268 else |
|
269 { |
|
270 CompleteDeferredExecuteRequest(KErrNone); // success |
|
271 // Close domain manager connection |
|
272 iDomainManager.Close(); |
|
273 iConnected = EFalse; |
|
274 } |
|
275 } |
|
276 |
|
277 /** |
|
278 Called to handle any cleanup if RunL leaves |
|
279 |
|
280 @param aError The error to finish with |
|
281 @return KErrNone |
|
282 */ |
|
283 TInt CCmdPublishSystemState::RunError(TInt aError) |
|
284 { |
|
285 CompleteDeferredExecuteRequest(aError); |
|
286 return KErrNone; |
|
287 } |
|
288 |
|
289 /** |
|
290 Called during cancellation of the active BIC |
|
291 */ |
|
292 void CCmdPublishSystemState::DoCancel() |
|
293 { |
|
294 if(iConnected) |
|
295 { |
|
296 iDomainManager.CancelTransition(); |
|
297 } |
|
298 } |
|
299 |
|
300 CCmdPublishSystemState::CCmdPublishSystemState() |
|
301 { |
|
302 } |
|
303 |
|
304 void CCmdPublishSystemState::ConstructL(RReadStream& aReadStream) |
|
305 { |
|
306 InternalizeL(aReadStream); |
|
307 ValidateL(); |
|
308 } |
|
309 |
|
310 /** |
|
311 @leave KErrNotSupported If command type or version of the command does not match. |
|
312 */ |
|
313 void CCmdPublishSystemState::ConstructL(TSsmCommandParameters& aCommandParameters) |
|
314 { |
|
315 RResourceReader& reader = aCommandParameters.MainReader(); |
|
316 const TSsmCommandType type = static_cast<TSsmCommandType>(reader.ReadInt16L()); |
|
317 SSMLOGLEAVEIFFALSE(type == Type(), KErrNotSupported); |
|
318 const TInt version = reader.ReadInt16L(); |
|
319 SSMLOGLEAVEIFFALSE(__COMPARE_VERSION(version, CCmdPublishSystemState::MaxSupportedVersion()), KErrNotSupported); |
|
320 iSeverity = static_cast<TCmdErrorSeverity>(reader.ReadInt16L()); |
|
321 iExecutionBehaviour = static_cast<TSsmExecutionBehaviour>(reader.ReadUint8L()); |
|
322 #ifndef SYMBIAN_ENABLE_SPLIT_HEADERS |
|
323 const TDmTraverseDirection direction = static_cast<TDmTraverseDirection>(reader.ReadInt8L()); |
|
324 #else |
|
325 const TSsmDmTraverseDirection direction = static_cast<TSsmDmTraverseDirection>(reader.ReadInt8L()); |
|
326 #endif //SYMBIAN_ENABLE_SPLIT_HEADERS |
|
327 const TInt retries = reader.ReadInt16L(); |
|
328 const TInt8 failurePolicy = reader.ReadInt8L();// just to make sure priority is handled properly |
|
329 #ifdef SYMBIAN_SSM_FLEXIBLE_MERGE |
|
330 iPriority = (version > ECmdPublishSystemStateInitialVersion) ? reader.ReadUint16L() : KDefaultCommandPriority; |
|
331 #endif |
|
332 const TSsmState state = aCommandParameters.StateL(); |
|
333 TSsmPublishSystemStateInfo stateInfo; |
|
334 stateInfo.Set(state, direction, retries); |
|
335 iStateInfo = stateInfo; |
|
336 |
|
337 ValidateL(); |
|
338 } |
|
339 |
|
340 void CCmdPublishSystemState::ConstructL() |
|
341 { |
|
342 ValidateL(); |
|
343 } |
|
344 |
|
345 #ifdef SYMBIAN_SSM_FLEXIBLE_MERGE |
|
346 CCmdPublishSystemState::CCmdPublishSystemState(TCmdErrorSeverity aSeverity, TSsmExecutionBehaviour aExecutionBehaviour, const TSsmPublishSystemStateInfo& aInfo, const TUint16 aPriority) |
|
347 : CSsmDeferrableCommand(aSeverity, aExecutionBehaviour, aPriority), iStateInfo(aInfo) |
|
348 { |
|
349 } |
|
350 #endif |
|
351 |
|
352 CCmdPublishSystemState::CCmdPublishSystemState(TCmdErrorSeverity aSeverity, TSsmExecutionBehaviour aExecutionBehaviour, const TSsmPublishSystemStateInfo& aInfo) |
|
353 : CSsmDeferrableCommand(aSeverity, aExecutionBehaviour), iStateInfo(aInfo) |
|
354 { |
|
355 } |
|
356 |
|
357 /** |
|
358 @leave KErrArgument If arguments are wrong. |
|
359 */ |
|
360 void CCmdPublishSystemState::ValidateL() |
|
361 { |
|
362 CSsmDeferrableCommand::ValidateL(); |
|
363 SSMLOGLEAVEIFFALSE(iStateInfo.State().Int() <= 0xffffff, KErrArgument); // only allowed lower 24 bits to use |
|
364 SSMLOGLEAVEIFFALSE(iStateInfo.Direction() >= ETraverseParentsFirst, KErrArgument); |
|
365 SSMLOGLEAVEIFFALSE(iStateInfo.Direction() <= ETraverseMax , KErrArgument); |
|
366 SSMLOGLEAVEIFFALSE(iStateInfo.Retries() >= 0, KErrArgument); |
|
367 } |
|
368 |
|
369 /** |
|
370 @return KErrNone if connect is successful and RequestSystemTransition() is called, |
|
371 otherwise return one of the system wide error codes |
|
372 */ |
|
373 TInt CCmdPublishSystemState::ConnectAndRequestTransition() |
|
374 { |
|
375 if (!iConnected) |
|
376 { |
|
377 TInt err = iDomainManager.Connect(KDmHierarchyIdStartup); |
|
378 if (KErrNone != err) |
|
379 { |
|
380 return err; |
|
381 } |
|
382 iConnected = ETrue; |
|
383 } |
|
384 |
|
385 const TDmDomainState state = static_cast<TDmDomainState>(iStateInfo.State().Int()); |
|
386 DEBUGPRINT3A("Requesting state transition %04x %04x...", iStateInfo.State().MainState(), iStateInfo.State().SubState()); |
|
387 #ifndef SYMBIAN_ENABLE_SPLIT_HEADERS |
|
388 iDomainManager.RequestSystemTransition(state, iStateInfo.Direction(), iStatus); |
|
389 #else |
|
390 const TDmTraverseDirection direction = static_cast<TDmTraverseDirection>(iStateInfo.Direction()); |
|
391 iDomainManager.RequestSystemTransition(state, direction, iStatus); |
|
392 #endif |
|
393 |
|
394 return KErrNone; |
|
395 } |
|
396 |