|
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 |
|
19 #include "ssmcommandparameters.h" |
|
20 #include <ssm/ssmloadamastart.h> |
|
21 #include "cmdamastarter.h" |
|
22 #include "ssmdebug.h" |
|
23 #include "ssmpanic.h" |
|
24 |
|
25 _LIT( KAmaStartDLL, "loadamastart.dll" ); |
|
26 typedef CSsmLoadAmaStart* (*TFuncLoadAmaCreateL)(void); |
|
27 |
|
28 #ifdef SYMBIAN_SSM_FLEXIBLE_MERGE |
|
29 /** |
|
30 Used to create an instance of CCmdAmaStarter class from given parameters. |
|
31 This method is used by SsmCommandFactory to create a command. |
|
32 |
|
33 @param aSeverity The severity of the command |
|
34 @param aExecutionBehaviour Execution behaviour of this command |
|
35 @param aDscId DSC id to start the AMA |
|
36 @param aPriority Priority of the command |
|
37 @return A pointer to an object of type CCmdAmaStarter. |
|
38 */ |
|
39 CCmdAmaStarter* CCmdAmaStarter::NewL(TCmdErrorSeverity aSeverity, TSsmExecutionBehaviour aExecutionBehaviour, TUid aDscId, const TUint16 aPriority) |
|
40 { |
|
41 SSMLOGLEAVEIFTRUE(aDscId == KNullUid, KErrArgument); //aDscId shouldn't be NULL |
|
42 CCmdAmaStarter* self = new (ELeave) CCmdAmaStarter(aSeverity, aExecutionBehaviour, aDscId, aPriority); |
|
43 CleanupStack::PushL(self); |
|
44 self->ConstructL(); |
|
45 CleanupStack::Pop(self); |
|
46 return self; |
|
47 } |
|
48 #endif |
|
49 |
|
50 /** |
|
51 Used to create an instance of CCmdAmaStarter class from given parameters. |
|
52 This method is used by SsmCommandFactory to create a command. |
|
53 |
|
54 @param aSeverity The severity of the command |
|
55 @param aExecutionBehaviour Execution behaviour of this command |
|
56 @param aDscId DSC id to start the AMA |
|
57 @return A pointer to an object of type CCmdAmaStarter. |
|
58 */ |
|
59 CCmdAmaStarter* CCmdAmaStarter::NewL(TCmdErrorSeverity aSeverity, TSsmExecutionBehaviour aExecutionBehaviour, TUid aDscId) |
|
60 { |
|
61 SSMLOGLEAVEIFTRUE(aDscId == KNullUid, KErrArgument); //aDscId shouldn't be NULL |
|
62 CCmdAmaStarter* self = new (ELeave) CCmdAmaStarter(aSeverity, aExecutionBehaviour, aDscId); |
|
63 CleanupStack::PushL(self); |
|
64 self->ConstructL(); |
|
65 CleanupStack::Pop(self); |
|
66 return self; |
|
67 } |
|
68 |
|
69 /** |
|
70 Used to create an instance of CCmdAmaStarter class from a read stream. |
|
71 CSsmCommandList::InternalizeL() uses this method to construct a command from stream. |
|
72 |
|
73 @param aReadStream Read stream containing data through which object can be created |
|
74 @return A pointer to an object of type CCmdAmaStarter. |
|
75 */ |
|
76 CCmdAmaStarter* CCmdAmaStarter::NewL(RReadStream& aReadStream) |
|
77 { |
|
78 CCmdAmaStarter* self = new (ELeave) CCmdAmaStarter(); |
|
79 CleanupStack::PushL(self); |
|
80 self->ConstructL(aReadStream); |
|
81 CleanupStack::Pop(self); |
|
82 return self; |
|
83 } |
|
84 |
|
85 /** |
|
86 Used to create an instance of CCmdAmaStarter class from resource. |
|
87 |
|
88 @param aCommandParameters Object data from a resource file |
|
89 @return A pointer to an object of type CCmdAmaStarter. |
|
90 */ |
|
91 CCmdAmaStarter* CCmdAmaStarter::NewL(TSsmCommandParameters& aCommandParameters) |
|
92 { |
|
93 CCmdAmaStarter* self = new (ELeave) CCmdAmaStarter(); |
|
94 CleanupStack::PushL(self); |
|
95 self->ConstructL(aCommandParameters); |
|
96 CleanupStack::Pop(self); |
|
97 return self; |
|
98 } |
|
99 |
|
100 /** |
|
101 Used to create an instance of CCmdAmaStarter class from CCmdAmaStarter object |
|
102 Must be used only by CLE |
|
103 @param aCmdAmaStarter CCmdAmaStarter reference |
|
104 @return A pointer to an object of type CCmdAmaStarter. |
|
105 */ |
|
106 CCmdAmaStarter* CCmdAmaStarter::NewLC(const CCmdAmaStarter& aCmdAmaStarter) |
|
107 { |
|
108 #ifdef SYMBIAN_SSM_FLEXIBLE_MERGE |
|
109 CCmdAmaStarter* self = new (ELeave) CCmdAmaStarter(aCmdAmaStarter.Severity(),aCmdAmaStarter.ExecutionBehaviour(), |
|
110 aCmdAmaStarter.DscId(),aCmdAmaStarter.Priority()); |
|
111 #else |
|
112 CCmdAmaStarter* self = new (ELeave) CCmdAmaStarter(aCmdAmaStarter.Severity(),aCmdAmaStarter.ExecutionBehaviour(), |
|
113 aCmdAmaStarter.DscId()); |
|
114 #endif |
|
115 CleanupStack::PushL(self); |
|
116 self->ConstructL(aCmdAmaStarter); |
|
117 return self; |
|
118 } |
|
119 |
|
120 void CCmdAmaStarter::ConstructL(const CCmdAmaStarter& aCmdAmaStarter) |
|
121 { |
|
122 iConditionalResourceId = aCmdAmaStarter.ConditionalInformation(); |
|
123 #ifdef SYMBIAN_SSM_FLEXIBLE_MERGE |
|
124 if (iConditionalResourceId != 0) |
|
125 { |
|
126 SetCommandResourceFileNameL(aCmdAmaStarter.GetCommandResourceFileName()); |
|
127 } |
|
128 #endif |
|
129 } |
|
130 /** |
|
131 Returns the version of the BIC |
|
132 @return The version of BIC |
|
133 */ |
|
134 TInt CCmdAmaStarter::MaxSupportedVersion() |
|
135 { |
|
136 #ifdef SYMBIAN_SSM_FLEXIBLE_MERGE |
|
137 return (static_cast<TInt>(ECmdAmaStarterVersionWithPriority)); |
|
138 #else |
|
139 return (static_cast<TInt>(ECmdAmaStarterInitialVersion)); |
|
140 #endif |
|
141 } |
|
142 |
|
143 /** |
|
144 Destructor |
|
145 */ |
|
146 CCmdAmaStarter::~CCmdAmaStarter() |
|
147 { |
|
148 Cancel(); |
|
149 delete iAmaStart; |
|
150 iAmaStartLib.Close(); |
|
151 } |
|
152 |
|
153 /** |
|
154 Execute this command |
|
155 @param aStatus The TRequestStatus which is completed when value is set either |
|
156 with KErrNone or with error value. |
|
157 */ |
|
158 void CCmdAmaStarter::Execute(TRequestStatus& aStatus) |
|
159 { |
|
160 aStatus = KRequestPending; |
|
161 iExecuteRequest = &aStatus; |
|
162 DEBUGPRINT3(_L("Starting AMA with DSC Id = 0x%x and execution behaviour = %d"), iDscId.iUid, iExecutionBehaviour); |
|
163 if (iExecutionBehaviour != ESsmWaitForSignal) |
|
164 { |
|
165 // complete the command request and initiate execution of next command |
|
166 CompleteExecuteRequest(KErrNone); |
|
167 } |
|
168 |
|
169 TRAPD(err, LoadAmaStartLibraryL()); |
|
170 if(KErrNone != err) |
|
171 { |
|
172 // complete the command request with error |
|
173 CompleteDeferredExecuteRequest(err); |
|
174 return; |
|
175 } |
|
176 SetActive(); |
|
177 iAmaStart->Start(iDscId, iStatus); |
|
178 } |
|
179 |
|
180 /** |
|
181 Load loadamastart.dll |
|
182 */ |
|
183 void CCmdAmaStarter::LoadAmaStartLibraryL() |
|
184 { |
|
185 SSMLOGLEAVEIFERROR(iAmaStartLib.Load(KAmaStartDLL)); |
|
186 TFuncLoadAmaCreateL amaStart = reinterpret_cast<TFuncLoadAmaCreateL>(iAmaStartLib.Lookup(1)); |
|
187 SSMLOGLEAVEIFTRUE(amaStart == NULL, KErrArgument); |
|
188 iAmaStart = amaStart(); |
|
189 SSMLOGLEAVEIFNULL(iAmaStart); |
|
190 } |
|
191 |
|
192 /** |
|
193 Releases resources associated with this BIC |
|
194 */ |
|
195 void CCmdAmaStarter::Release() |
|
196 { |
|
197 delete this; |
|
198 } |
|
199 |
|
200 /** |
|
201 Cancels the BIC |
|
202 */ |
|
203 void CCmdAmaStarter::ExecuteCancel() |
|
204 { |
|
205 //cancel the outstanding request |
|
206 Cancel(); |
|
207 //and complete the request with KErrCancel |
|
208 CompleteDeferredExecuteRequest(KErrCancel); |
|
209 } |
|
210 |
|
211 /** |
|
212 Returns the type of the BIC |
|
213 @return Type of BIC |
|
214 */ |
|
215 TSsmCommandType CCmdAmaStarter::Type() const |
|
216 { |
|
217 return (ESsmCmdAMAStarter); |
|
218 } |
|
219 |
|
220 /** |
|
221 Externalises the configuration of the BIC |
|
222 |
|
223 @param aWriteStream A write stream to write BIC data to |
|
224 */ |
|
225 void CCmdAmaStarter::ExternalizeL(RWriteStream& aWriteStream) const |
|
226 { |
|
227 aWriteStream.WriteInt16L(iSeverity); |
|
228 aWriteStream.WriteUint8L(iExecutionBehaviour); |
|
229 aWriteStream.WriteUint32L(iDscId.iUid); |
|
230 #ifdef SYMBIAN_SSM_FLEXIBLE_MERGE |
|
231 aWriteStream.WriteUint16L(iPriority); |
|
232 #endif |
|
233 } |
|
234 |
|
235 /** |
|
236 Handles command's request completion event. |
|
237 */ |
|
238 void CCmdAmaStarter::RunL() |
|
239 { |
|
240 CompleteDeferredExecuteRequest(iStatus.Int()); |
|
241 } |
|
242 |
|
243 /** |
|
244 cancellation of an outstanding request. |
|
245 */ |
|
246 void CCmdAmaStarter::DoCancel() |
|
247 { |
|
248 iAmaStart->StartCancel(); |
|
249 } |
|
250 |
|
251 /** |
|
252 Complete the command request with aError. It gets called when RunL leaves. |
|
253 |
|
254 @param aError Error code with which RunL has left. |
|
255 @return KErrNone as error is handled in this function. |
|
256 */ |
|
257 TInt CCmdAmaStarter::RunError(TInt aError) |
|
258 { |
|
259 DEBUGPRINT2A("CCmdAmaStarter::RunError called with error %d", aError); |
|
260 CompleteDeferredExecuteRequest(aError); |
|
261 return KErrNone; |
|
262 } |
|
263 |
|
264 #ifdef SYMBIAN_SSM_FLEXIBLE_MERGE |
|
265 /** |
|
266 Overloaded constructor |
|
267 |
|
268 @param aSeverity The severity of the command |
|
269 @param aExecutionBehaviour Execution behaviour for this command |
|
270 @param aDscId DSC id to start the AMA |
|
271 @param aPriority Indicating the priority of the command |
|
272 */ |
|
273 CCmdAmaStarter::CCmdAmaStarter(TCmdErrorSeverity aSeverity, TSsmExecutionBehaviour aExecutionBehaviour, const TUid& aDscId, const TUint16 aPriority) |
|
274 :CSsmDeferrableCommand(aSeverity, aExecutionBehaviour, aPriority), iDscId(aDscId) |
|
275 { |
|
276 } |
|
277 #endif |
|
278 |
|
279 /** |
|
280 Overloaded constructor |
|
281 |
|
282 @param aSeverity The severity of the command |
|
283 @param aExecutionBehaviour Execution behaviour for this command |
|
284 @param aDscId DSC id to start the AMA |
|
285 */ |
|
286 CCmdAmaStarter::CCmdAmaStarter(TCmdErrorSeverity aSeverity, TSsmExecutionBehaviour aExecutionBehaviour, const TUid& aDscId) |
|
287 :CSsmDeferrableCommand(aSeverity, aExecutionBehaviour), iDscId(aDscId) |
|
288 { |
|
289 } |
|
290 |
|
291 /** |
|
292 Default constructor. |
|
293 */ |
|
294 CCmdAmaStarter::CCmdAmaStarter() |
|
295 { |
|
296 } |
|
297 |
|
298 /** |
|
299 Constructs the object through read stream. |
|
300 @param aReadStream A read stream containing BIC data |
|
301 */ |
|
302 void CCmdAmaStarter::ConstructL(RReadStream& aReadStream) |
|
303 { |
|
304 InternalizeL(aReadStream); |
|
305 ConstructL(); //validate the commands data |
|
306 } |
|
307 |
|
308 /** |
|
309 Constructs an object from resource file. |
|
310 |
|
311 @param aCommandParameters Object data from a resource file |
|
312 */ |
|
313 void CCmdAmaStarter::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, CCmdAmaStarter::MaxSupportedVersion()), KErrNotSupported); |
|
320 iSeverity = static_cast<TCmdErrorSeverity>(reader.ReadInt16L()); |
|
321 iExecutionBehaviour = static_cast<TSsmExecutionBehaviour>(reader.ReadUint8L()); |
|
322 iDscId.iUid = reader.ReadUint32L(); |
|
323 #ifdef SYMBIAN_SSM_FLEXIBLE_MERGE |
|
324 iPriority = (version > ECmdAmaStarterInitialVersion) ? reader.ReadUint16L() : KDefaultCommandPriority; |
|
325 #endif |
|
326 ConstructL(); //validate the commands data |
|
327 } |
|
328 |
|
329 /** |
|
330 Validate data. |
|
331 */ |
|
332 void CCmdAmaStarter::ConstructL() |
|
333 { |
|
334 ValidateL(); |
|
335 } |
|
336 |
|
337 /** |
|
338 Configures the BIC using data contained in a ReadStream |
|
339 |
|
340 @param aReadStream A read stream containing BIC data |
|
341 */ |
|
342 void CCmdAmaStarter::InternalizeL(RReadStream& aReadStream) |
|
343 { |
|
344 iSeverity = static_cast<TCmdErrorSeverity>(aReadStream.ReadInt16L()); |
|
345 iExecutionBehaviour = static_cast<TSsmExecutionBehaviour>(aReadStream.ReadUint8L()); |
|
346 iDscId.iUid = aReadStream.ReadUint32L(); |
|
347 #ifdef SYMBIAN_SSM_FLEXIBLE_MERGE |
|
348 iPriority = aReadStream.ReadUint16L(); |
|
349 #endif |
|
350 } |
|
351 |
|
352 /** |
|
353 Validate commands data |
|
354 */ |
|
355 void CCmdAmaStarter::ValidateL() |
|
356 { |
|
357 CSsmDeferrableCommand::ValidateL(); |
|
358 SSMLOGLEAVEIFTRUE(iDscId == KNullUid, KErrArgument); //iDscId shouldn't be NULL |
|
359 } |