|
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 <s32strm.h> |
|
18 #include <ssm/ssmstartupproperties.h> |
|
19 #include "ssmdebug.h" |
|
20 #include "ssmpanic.h" |
|
21 |
|
22 /** |
|
23 * Constructs and returns a blank CSsmStartupProperties. |
|
24 * |
|
25 * @publishedPartner |
|
26 * @released |
|
27 */ |
|
28 EXPORT_C CSsmStartupProperties* CSsmStartupProperties::NewL() |
|
29 { |
|
30 CSsmStartupProperties* self = CSsmStartupProperties::NewLC(); |
|
31 CleanupStack::Pop(self); |
|
32 return self; |
|
33 } |
|
34 |
|
35 /** |
|
36 * Constructs and returns a blank CSsmStartupProperties. |
|
37 * |
|
38 * Pushes the returned object onto the cleanup stack. |
|
39 * |
|
40 * @publishedPartner |
|
41 * @released |
|
42 */ |
|
43 EXPORT_C CSsmStartupProperties* CSsmStartupProperties::NewLC() |
|
44 { |
|
45 CSsmStartupProperties* self = new(ELeave) CSsmStartupProperties(); |
|
46 CleanupStack::PushL(self); |
|
47 return self; |
|
48 } |
|
49 |
|
50 /** |
|
51 * Constructs and returns a CSsmStartupProperties. |
|
52 * |
|
53 * @param aFileName The filename to use for the returned object. |
|
54 * @param aArgs The arguments to use for the returned object. |
|
55 * |
|
56 * @publishedPartner |
|
57 * @released |
|
58 */ |
|
59 EXPORT_C CSsmStartupProperties* CSsmStartupProperties::NewL(const TDesC& aFileName, const TDesC& aArgs) |
|
60 { |
|
61 CSsmStartupProperties* self = CSsmStartupProperties::NewLC(aFileName, aArgs); |
|
62 CleanupStack::Pop(self); |
|
63 return self; |
|
64 } |
|
65 |
|
66 /** |
|
67 * Constructs and returns a CSsmStartupProperties. |
|
68 * |
|
69 * Pushes the returned object onto the cleanup stack. |
|
70 * |
|
71 * @param aFileName The filename to use for the returned object. |
|
72 * @param aArgs The arguments to use for the returned object. |
|
73 * |
|
74 * @publishedPartner |
|
75 * @released |
|
76 */ |
|
77 EXPORT_C CSsmStartupProperties* CSsmStartupProperties::NewLC(const TDesC& aFileName, const TDesC& aArgs) |
|
78 { |
|
79 CSsmStartupProperties* self = CSsmStartupProperties::NewLC(); |
|
80 self->SetFileParamsL(aFileName, aArgs); |
|
81 return self; |
|
82 } |
|
83 |
|
84 /** |
|
85 * Constructs and returns a CSsmStartupProperties from a resource file. |
|
86 * |
|
87 * @param aReader A reader at the location of the startup properties to be read. |
|
88 * @param aResourceFile The resource file containing the information to be read. |
|
89 * @param aCommandType The command type for the properties being constructed. |
|
90 * |
|
91 * @publishedPartner |
|
92 * @released |
|
93 */ |
|
94 EXPORT_C CSsmStartupProperties* CSsmStartupProperties::NewL(RResourceReader& aReader, CResourceFile* aResourceFile, TSsmCommandType aCommandType) |
|
95 { |
|
96 CSsmStartupProperties* self = CSsmStartupProperties::NewLC(aReader, aResourceFile, aCommandType); |
|
97 CleanupStack::Pop(self); |
|
98 return self; |
|
99 } |
|
100 |
|
101 /** |
|
102 * Constructs and returns a CSsmStartupProperties from a resource file. |
|
103 * |
|
104 * Pushes the returned object onto the cleanup stack. |
|
105 * |
|
106 * @param aReader A reader at the location of the startup properties to be read. |
|
107 * @param aResourceFile The resource file containing the information to be read. |
|
108 * @param aCommandType The command type for the properties being constructed. |
|
109 * |
|
110 * @publishedPartner |
|
111 * @released |
|
112 */ |
|
113 EXPORT_C CSsmStartupProperties* CSsmStartupProperties::NewLC(RResourceReader& aReader, CResourceFile* aResourceFile, TSsmCommandType aCommandType) |
|
114 { |
|
115 CSsmStartupProperties* self = CSsmStartupProperties::NewLC(); |
|
116 self->ConstructFromResourceL(aReader, aResourceFile, aCommandType); |
|
117 return self; |
|
118 } |
|
119 |
|
120 /** |
|
121 * Constructs and returns a copied CSsmStartupProperties. |
|
122 * |
|
123 * @param aStartupProperties The CSsmStartupProperties object to copy. |
|
124 * |
|
125 * @publishedPartner |
|
126 * @released |
|
127 */ |
|
128 EXPORT_C CSsmStartupProperties* CSsmStartupProperties::NewL(const CSsmStartupProperties& aStartupProperties) |
|
129 { |
|
130 CSsmStartupProperties* self = CSsmStartupProperties::NewLC(); |
|
131 self->ConstructL(aStartupProperties); |
|
132 CleanupStack::Pop(self); |
|
133 return self; |
|
134 } |
|
135 |
|
136 /** |
|
137 * @internalTechnology |
|
138 */ |
|
139 void CSsmStartupProperties::ConstructFromResourceL(RResourceReader& aReader, CResourceFile* aResourceFile, TSsmCommandType aCommandType) |
|
140 { |
|
141 TPtrC fileName = aReader.ReadTPtrCL(); //LTEXT name |
|
142 TPtrC arguments = aReader.ReadTPtrCL(); //LTEXT args |
|
143 SetFileParamsL(fileName, arguments); |
|
144 iCommandType = aCommandType; |
|
145 iExecutionBehaviour = static_cast<TSsmExecutionBehaviour>(aReader.ReadUint8L()); //BYTE execution_behaviour |
|
146 iTimeout = aReader.ReadInt32L(); //LONG timeout |
|
147 iRetries = aReader.ReadInt16L(); //WORD retries |
|
148 if (ESsmCmdStartApp == aCommandType) |
|
149 { |
|
150 iViewless = aReader.ReadUint8L(); //BYTE viewless |
|
151 iStartInBackground = aReader.ReadUint8L(); //BYTE startInBackground |
|
152 } |
|
153 |
|
154 const TInt monitorResourceId = aReader.ReadUint32L(); //LLINK monitor_info |
|
155 if (monitorResourceId < 0) |
|
156 { |
|
157 SSMLOGLEAVE(KErrArgument); |
|
158 } |
|
159 else if (monitorResourceId > 0) |
|
160 { |
|
161 // open a new reader |
|
162 RResourceReader tempReader; |
|
163 // move reader to monitorResourceId |
|
164 tempReader.OpenL(aResourceFile, monitorResourceId); |
|
165 CleanupClosePushL(tempReader); |
|
166 const TSsmCommandType type = static_cast<TSsmCommandType>(tempReader.ReadInt16L()); |
|
167 SSMLOGLEAVEIFFALSE(type == ESsmMonitorInfo, KErrNotSupported); |
|
168 const TInt version = tempReader.ReadInt16L(); |
|
169 SSMLOGLEAVEIFFALSE((version <= ESsmMonitorInfoInitialVersion) && (version > 0), KErrNotSupported); |
|
170 iMonitoringRequired = ETrue; |
|
171 iMonitorInfo.iRestartPolicy = static_cast<TSsmRecoveryMethod>(tempReader.ReadUint8L()); //BYTE restart_policy |
|
172 iMonitorInfo.iRestartMode = tempReader.ReadUint8L(); //BYTE restart_mode |
|
173 iMonitorInfo.iTimeout = tempReader.ReadInt32L(); //LONG timeout |
|
174 iMonitorInfo.iRetries = tempReader.ReadInt16L(); //WORD retries |
|
175 CleanupStack::PopAndDestroy(&tempReader); |
|
176 } |
|
177 } |
|
178 |
|
179 /** |
|
180 * Frees any resources allocated to this object. |
|
181 * |
|
182 * @publishedPartner |
|
183 * @released |
|
184 */ |
|
185 EXPORT_C CSsmStartupProperties::~CSsmStartupProperties() |
|
186 { |
|
187 delete iArgs; |
|
188 delete iFileName; |
|
189 } |
|
190 |
|
191 /** |
|
192 Sets file parameters that is file name and arguments |
|
193 @param aFileName A file name containing full path to be used to start up a component. |
|
194 @param aArgs A string that is used as an argument to the component when starting a process or application |
|
195 */ |
|
196 EXPORT_C void CSsmStartupProperties::SetFileParamsL(const TDesC& aFileName, const TDesC& aArgs) |
|
197 { |
|
198 HBufC* fname = aFileName.AllocL(); |
|
199 delete iFileName; |
|
200 iFileName = fname; |
|
201 TPtr writeableFilename = iFileName->Des(); |
|
202 writeableFilename.TrimAll(); // remove leading and trailing whitespace characters from filename |
|
203 |
|
204 HBufC* args = aArgs.AllocL(); |
|
205 delete iArgs; |
|
206 iArgs = args; |
|
207 TPtr writeableArgs = iArgs->Des(); |
|
208 writeableArgs.TrimAll(); // remove leading and trailing whitespace characters from arguments |
|
209 } |
|
210 |
|
211 /** |
|
212 Sets the command type for startup properties. It can be ESsmCmdStartProcess or ESsmCmdStartApp. |
|
213 @param aType startup type of TSsmCommandType |
|
214 @leave KErrArgument If aCommandType is not ESsmCmdStartProcess or ESsmCmdStartApp. |
|
215 @see TSsmCommandType |
|
216 */ |
|
217 EXPORT_C void CSsmStartupProperties::SetCommandTypeL(TSsmCommandType aCommandType) |
|
218 { |
|
219 SSMLOGLEAVEIFFALSE(((aCommandType == ESsmCmdStartProcess) || (aCommandType == ESsmCmdStartApp)), KErrArgument); |
|
220 iCommandType = aCommandType; |
|
221 } |
|
222 |
|
223 /** |
|
224 Sets the execution behaviour. |
|
225 @param aExecutionBehaviour Execution behaviour of type TSsmExecutionBehaviour. |
|
226 @see TSsmExecutionBehaviour |
|
227 */ |
|
228 EXPORT_C void CSsmStartupProperties::SetExecutionBehaviour(TSsmExecutionBehaviour aExecutionBehaviour) |
|
229 { |
|
230 iExecutionBehaviour = aExecutionBehaviour; |
|
231 } |
|
232 |
|
233 /** |
|
234 Sets number of retries. These retries are used to launch application or process. |
|
235 @param aRetries Number of retries to set. |
|
236 */ |
|
237 EXPORT_C void CSsmStartupProperties::SetRetries(TInt aRetries) |
|
238 { |
|
239 iRetries = aRetries; |
|
240 } |
|
241 |
|
242 /** |
|
243 Sets the value of timeout |
|
244 @param aTimeout Timeout to set |
|
245 */ |
|
246 EXPORT_C void CSsmStartupProperties::SetTimeout(TInt32 aTimeout) |
|
247 { |
|
248 iTimeout = aTimeout; |
|
249 } |
|
250 |
|
251 /** |
|
252 Sets the monitor information. This monitoring information is used by RSysMonSession::MonitorL() |
|
253 @param aMonitorInfo |
|
254 @see RSysMonSession::MonitorL |
|
255 */ |
|
256 EXPORT_C void CSsmStartupProperties::SetMonitorInfoL(TSsmMonitorInfo aMonitorInfo) |
|
257 { |
|
258 iMonitoringRequired = ETrue; |
|
259 iMonitorInfo.iRestartPolicy = aMonitorInfo.iRestartPolicy; |
|
260 iMonitorInfo.iRestartMode = aMonitorInfo.iRestartMode; |
|
261 iMonitorInfo.iTimeout = aMonitorInfo.iTimeout; |
|
262 iMonitorInfo.iRetries = aMonitorInfo.iRetries; |
|
263 } |
|
264 |
|
265 /** |
|
266 Set the value of member Viewless |
|
267 @param aViewless Boolean value to set. |
|
268 */ |
|
269 EXPORT_C void CSsmStartupProperties::SetViewless(TBool aViewless) |
|
270 { |
|
271 iViewless = aViewless; |
|
272 } |
|
273 |
|
274 /** |
|
275 Sets an extra startup in background (used only for applications) |
|
276 @param aStartInBackground ETrue if the application should start in the background. |
|
277 */ |
|
278 EXPORT_C void CSsmStartupProperties::SetStartInBackground(TBool aStartInBackground) |
|
279 { |
|
280 iStartInBackground = aStartInBackground; |
|
281 } |
|
282 |
|
283 /** |
|
284 Returns file name specified in startup properties. |
|
285 @return Return file name specified, or KNullDesC empty file name is given. |
|
286 */ |
|
287 EXPORT_C TPtrC CSsmStartupProperties::FileName() const |
|
288 { |
|
289 return (iFileName) ? *iFileName : KNullDesC(); |
|
290 } |
|
291 |
|
292 /** |
|
293 Returns argument spcified in startup properties. |
|
294 @return Return argument specified, or KNullDesC empty argument is given. |
|
295 */ |
|
296 EXPORT_C TPtrC CSsmStartupProperties::Args() const |
|
297 { |
|
298 return (iArgs) ? *iArgs : KNullDesC(); |
|
299 } |
|
300 |
|
301 /** |
|
302 Returns command type i.e. ESsmCmdStartApp/ESsmCmdStartProcess |
|
303 @return Command type. |
|
304 */ |
|
305 EXPORT_C TSsmCommandType CSsmStartupProperties::CommandType() const |
|
306 { |
|
307 return iCommandType; |
|
308 } |
|
309 |
|
310 /** |
|
311 Returns execution behaviour of process/application. |
|
312 @return Execution behaviour of type TSsmExecutionBehaviour. |
|
313 @see TSsmExecutionBehaviour |
|
314 */ |
|
315 EXPORT_C TSsmExecutionBehaviour CSsmStartupProperties::ExecutionBehaviour() const |
|
316 { |
|
317 return iExecutionBehaviour; |
|
318 } |
|
319 |
|
320 /** |
|
321 Returns number of retries. |
|
322 @return Number of retries. |
|
323 */ |
|
324 EXPORT_C TInt CSsmStartupProperties::Retries() const |
|
325 { |
|
326 return iRetries; |
|
327 } |
|
328 |
|
329 /** |
|
330 Returns the timeout value. |
|
331 @return Timeout value |
|
332 */ |
|
333 EXPORT_C TInt32 CSsmStartupProperties::Timeout() const |
|
334 { |
|
335 return iTimeout; |
|
336 } |
|
337 |
|
338 /** |
|
339 Function returns monitored property. |
|
340 @return ETrue if monitor info is set, EFalse otherwise. |
|
341 */ |
|
342 EXPORT_C TBool CSsmStartupProperties::IsMonitoringRequired() const |
|
343 { |
|
344 return iMonitoringRequired; |
|
345 } |
|
346 |
|
347 /** |
|
348 Function returns viewless property. |
|
349 @return Viewless property. |
|
350 */ |
|
351 EXPORT_C TBool CSsmStartupProperties::Viewless() const |
|
352 { |
|
353 return iViewless; |
|
354 } |
|
355 |
|
356 /** |
|
357 Function returns start in background property. |
|
358 @return Start in background property. |
|
359 */ |
|
360 EXPORT_C TBool CSsmStartupProperties::StartInBackground() const |
|
361 { |
|
362 return iStartInBackground; |
|
363 } |
|
364 |
|
365 /** |
|
366 Externalises the values of startup properties to write stream. |
|
367 |
|
368 @param aWriteStream A write stream to write startup properties. |
|
369 */ |
|
370 EXPORT_C void CSsmStartupProperties::ExternalizeL(RWriteStream& aWriteStream) const |
|
371 { |
|
372 aWriteStream.WriteUint16L(iCommandType); |
|
373 aWriteStream << FileName(); |
|
374 aWriteStream << Args(); |
|
375 aWriteStream.WriteUint8L(iExecutionBehaviour); |
|
376 aWriteStream.WriteInt32L(iTimeout); |
|
377 aWriteStream.WriteInt16L(iRetries); |
|
378 aWriteStream.WriteUint8L(iViewless); |
|
379 aWriteStream.WriteUint8L(iStartInBackground); |
|
380 |
|
381 aWriteStream.WriteUint8L(iMonitoringRequired ? ETrue : EFalse); |
|
382 if (iMonitoringRequired) |
|
383 { |
|
384 aWriteStream.WriteUint8L(iMonitorInfo.iRestartPolicy); |
|
385 aWriteStream.WriteUint8L(iMonitorInfo.iRestartMode); |
|
386 aWriteStream.WriteInt32L(iMonitorInfo.iTimeout); |
|
387 aWriteStream.WriteInt16L(iMonitorInfo.iRetries); |
|
388 } |
|
389 } |
|
390 |
|
391 /** |
|
392 Configures startup property using read stream. |
|
393 @leave EInvalidCmdType If command type is not ESsmCmdStartProcess / ESsmCmdStartApp |
|
394 @param aReadStream A read stream containing startup property. |
|
395 */ |
|
396 EXPORT_C void CSsmStartupProperties::InternalizeL(RReadStream& aReadStream) |
|
397 { |
|
398 iCommandType = static_cast<TSsmCommandType>(aReadStream.ReadUint16L()); |
|
399 |
|
400 __ASSERT_DEBUG(((iCommandType == ESsmCmdStartApp) || (iCommandType == ESsmCmdStartProcess)), PanicNow(KPanicStartupProperties, EInvalidCmdType)); |
|
401 iFileName = HBufC::NewL(aReadStream, KMaxFileName); |
|
402 iArgs = HBufC::NewL(aReadStream, KMaxFileName); |
|
403 iExecutionBehaviour = static_cast<TSsmExecutionBehaviour>(aReadStream.ReadUint8L()); |
|
404 iTimeout = aReadStream.ReadInt32L(); |
|
405 iRetries = aReadStream.ReadInt16L(); |
|
406 iViewless = aReadStream.ReadUint8L(); |
|
407 iStartInBackground = aReadStream.ReadUint8L(); |
|
408 |
|
409 iMonitoringRequired = aReadStream.ReadUint8L(); |
|
410 if (iMonitoringRequired) |
|
411 { |
|
412 iMonitorInfo.iRestartPolicy = static_cast<TSsmRecoveryMethod>(aReadStream.ReadUint8L()); |
|
413 iMonitorInfo.iRestartMode = aReadStream.ReadUint8L(); |
|
414 iMonitorInfo.iTimeout = aReadStream.ReadInt32L(); |
|
415 iMonitorInfo.iRetries = aReadStream.ReadInt16L(); |
|
416 } |
|
417 } |
|
418 /** |
|
419 Reset all the values to default. |
|
420 */ |
|
421 EXPORT_C void CSsmStartupProperties::Reset() |
|
422 { |
|
423 iCommandType = ESsmCmdStartProcess; |
|
424 delete iFileName; |
|
425 iFileName = NULL; |
|
426 delete iArgs; |
|
427 iArgs = NULL; |
|
428 iExecutionBehaviour = ESsmFireAndForget; |
|
429 iTimeout = 0; |
|
430 iRetries = 0; |
|
431 iViewless = EFalse; |
|
432 iStartInBackground = EFalse; |
|
433 iMonitoringRequired = EFalse; |
|
434 } |
|
435 |
|
436 /** |
|
437 Default CTOR |
|
438 */ |
|
439 CSsmStartupProperties::CSsmStartupProperties() |
|
440 : iCommandType(ESsmCmdStartProcess), iExecutionBehaviour(ESsmFireAndForget), iMonitoringRequired(EFalse) |
|
441 { |
|
442 } |
|
443 |
|
444 /** |
|
445 Construct startup properties from the given properties |
|
446 */ |
|
447 void CSsmStartupProperties::ConstructL(const CSsmStartupProperties& aStartupProperties) |
|
448 { |
|
449 iCommandType = aStartupProperties.CommandType(); |
|
450 SetFileParamsL(aStartupProperties.FileName(), aStartupProperties.Args()); |
|
451 iExecutionBehaviour = aStartupProperties.ExecutionBehaviour(); |
|
452 iTimeout = aStartupProperties.Timeout(); |
|
453 iRetries = aStartupProperties.Retries(); |
|
454 iViewless = aStartupProperties.Viewless(); //this value is used only for applications |
|
455 iStartInBackground = aStartupProperties.StartInBackground();//this value is used only for applications |
|
456 |
|
457 if (aStartupProperties.IsMonitoringRequired()) |
|
458 { |
|
459 iMonitoringRequired = ETrue; |
|
460 iMonitorInfo.iRestartPolicy = aStartupProperties.iMonitorInfo.iRestartPolicy; |
|
461 iMonitorInfo.iRestartMode = aStartupProperties.iMonitorInfo.iRestartMode; |
|
462 iMonitorInfo.iTimeout = aStartupProperties.iMonitorInfo.iTimeout; |
|
463 iMonitorInfo.iRetries = aStartupProperties.iMonitorInfo.iRetries; |
|
464 } |
|
465 else |
|
466 { |
|
467 iMonitoringRequired = EFalse; |
|
468 } |
|
469 } |
|
470 |
|
471 /** |
|
472 Gets the monitor information. |
|
473 @return Pointer to monitor info object if Monitoring is set to True otherwise NULL. |
|
474 */ |
|
475 EXPORT_C TSsmMonitorInfo CSsmStartupProperties::MonitorInfo() const |
|
476 { |
|
477 return iMonitorInfo; |
|
478 } |
|
479 |