|
1 /* |
|
2 * Copyright (c) 2005-2009 Nokia Corporation and/or its subsidiary(-ies). |
|
3 * All rights reserved. |
|
4 * This component and the accompanying materials are made available |
|
5 * under the terms of "Eclipse Public License v1.0" |
|
6 * which accompanies this distribution, and is available |
|
7 * at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
8 * |
|
9 * Initial Contributors: |
|
10 * Nokia Corporation - initial contribution. |
|
11 * |
|
12 * Contributors: |
|
13 * |
|
14 * Description: |
|
15 * |
|
16 */ |
|
17 |
|
18 #include "t_chwrmlightsdata.h" |
|
19 #include <hwrmlight.h> |
|
20 |
|
21 /*@{*/ |
|
22 //LIT's for reading params from ini file |
|
23 _LIT(KTarget, "target"); |
|
24 _LIT(KLight, "light"); |
|
25 _LIT(KDuration, "duration"); |
|
26 _LIT(KOnDuration, "onduration"); |
|
27 _LIT(KOffDuration, "offduration"); |
|
28 _LIT(KIntensity, "intensity"); |
|
29 _LIT(KRestoreState, "restoreState"); |
|
30 _LIT(KForceNoCCoeEnv, "forceNoCCoeEnv"); |
|
31 _LIT(KFadein, "fadein"); |
|
32 _LIT(KFadeout, "fadeout"); |
|
33 _LIT(KStatus, "status"); |
|
34 _LIT(KObserver, "observer"); |
|
35 /*@}*/ |
|
36 |
|
37 |
|
38 /*@{*/ |
|
39 //LIT's for commands |
|
40 _LIT(KCmdNewL, "NewL"); |
|
41 _LIT(KCmdReserveLightL, "ReserveLightL"); |
|
42 _LIT(KCmdLightBlinkL, "LightBlinkL"); |
|
43 _LIT(KCmdLightOnL, "LightOnL"); |
|
44 _LIT(KCmdLightOffL, "LightOffL"); |
|
45 _LIT(KCmdLightStatus, "LightStatus"); |
|
46 _LIT(KCmdDestructor, "~"); |
|
47 /*@}*/ |
|
48 |
|
49 /*@{*/ |
|
50 _LIT(KLogError, "Error=%d"); |
|
51 _LIT(KLogMissingParameter, "Missing parameter '%S'"); |
|
52 _LIT(KLogDefaultValueUsed, "Missing parameter '%S'. Using default value of '%d'"); |
|
53 /*@}*/ |
|
54 |
|
55 //*@{*/ |
|
56 /*LIT's for TLightStatus enumeration*/ |
|
57 _LIT(KELightStatusUnknown, "ELightStatusUnknown"); |
|
58 _LIT(KELightOn, "ELightOn"); |
|
59 _LIT(KELightOff, "ELightOff"); |
|
60 _LIT(KELightBlink, "ELightBlink"); |
|
61 /*@}*/ |
|
62 |
|
63 const CDataWrapperBase::TEnumEntryTable CT_CHWRMLightsData::iEnumLightStatus[] = |
|
64 { |
|
65 { KELightStatusUnknown, CHWRMLight::ELightStatusUnknown }, |
|
66 { KELightOn, CHWRMLight::ELightOn }, |
|
67 { KELightOff, CHWRMLight::ELightOff }, |
|
68 { KELightBlink, CHWRMLight::ELightBlink } |
|
69 }; |
|
70 |
|
71 |
|
72 /** |
|
73 * Two phase constructor |
|
74 * |
|
75 * @leave system wide error |
|
76 */ |
|
77 CT_CHWRMLightsData* CT_CHWRMLightsData::NewL() |
|
78 { |
|
79 CT_CHWRMLightsData* ret = new (ELeave) CT_CHWRMLightsData(); |
|
80 CleanupStack::PushL(ret); |
|
81 ret->ConstructL(); |
|
82 CleanupStack::Pop(ret); |
|
83 return ret; |
|
84 } |
|
85 |
|
86 |
|
87 /** |
|
88 * Protected constructor. First phase construction |
|
89 */ |
|
90 CT_CHWRMLightsData::CT_CHWRMLightsData() |
|
91 : iLight(NULL) |
|
92 { |
|
93 } |
|
94 |
|
95 /** |
|
96 * Second phase construction |
|
97 * |
|
98 * @internalComponent |
|
99 * |
|
100 * @return N/A |
|
101 * |
|
102 * @pre None |
|
103 * @post None |
|
104 * |
|
105 * @leave system wide error |
|
106 */ |
|
107 void CT_CHWRMLightsData::ConstructL() |
|
108 { |
|
109 } |
|
110 |
|
111 /** |
|
112 * Public destructor |
|
113 */ |
|
114 CT_CHWRMLightsData::~CT_CHWRMLightsData() |
|
115 { |
|
116 DestroyData(); |
|
117 } |
|
118 |
|
119 /** |
|
120 * Return a pointer to the object that the data wraps |
|
121 * |
|
122 * @return pointer to the object that the data wraps |
|
123 */ |
|
124 TAny* CT_CHWRMLightsData::GetObject() |
|
125 { |
|
126 return iLight; |
|
127 } |
|
128 |
|
129 |
|
130 /** |
|
131 * Process a command read from the ini file |
|
132 * |
|
133 * @param aCommand The command to process |
|
134 * @param aSection The section in the ini containing data for the command |
|
135 * @param aAsyncErrorIndex Command index for async calls to return errors to |
|
136 * |
|
137 * @return ETrue if the command is processed |
|
138 * |
|
139 * @leave System wide error |
|
140 */ |
|
141 TBool CT_CHWRMLightsData::DoCommandL(const TTEFFunction& aCommand, const TTEFSectionName& aSection, const TInt /*aAsyncErrorIndex*/) |
|
142 { |
|
143 TBool ret = ETrue; |
|
144 TInt err=KErrNone; |
|
145 |
|
146 if (aCommand == KCmdNewL) |
|
147 { |
|
148 err = DoCmdNewL(aSection); |
|
149 } |
|
150 else if (aCommand == KCmdReserveLightL) |
|
151 { |
|
152 err = DoCmdReserveLightL(aSection); |
|
153 } |
|
154 else if (aCommand == KCmdLightBlinkL) |
|
155 { |
|
156 err = DoCmdLightBlinkL(aSection); |
|
157 } |
|
158 else if (aCommand == KCmdLightOnL) |
|
159 { |
|
160 err = DoCmdLightOnL(aSection); |
|
161 } |
|
162 else if (aCommand == KCmdLightOffL) |
|
163 { |
|
164 err = DoCmdLightOffL(aSection); |
|
165 } |
|
166 else if (aCommand == KCmdLightStatus) |
|
167 { |
|
168 err = DoCmdLightStatus(aSection); |
|
169 } |
|
170 else if (aCommand == KCmdDestructor) |
|
171 { |
|
172 err = DoCmdDestructor(); |
|
173 } |
|
174 else |
|
175 { |
|
176 ret=EFalse; |
|
177 } |
|
178 |
|
179 if ( err != KErrNone ) |
|
180 { |
|
181 ERR_PRINTF2(KLogError, err); |
|
182 SetError(err); |
|
183 } |
|
184 |
|
185 return ret; |
|
186 } |
|
187 |
|
188 /** |
|
189 * Command NewL |
|
190 * |
|
191 * @param aSection: observer |
|
192 * |
|
193 * @return |
|
194 */ |
|
195 TInt CT_CHWRMLightsData::DoCmdNewL(const TTEFSectionName& aSection) |
|
196 { |
|
197 INFO_PRINTF1(_L("*START* CT_CHWRMLightsData::DoCmdNewL")); |
|
198 DestroyData(); |
|
199 |
|
200 TInt observer = 0; |
|
201 TInt err = KErrNone; |
|
202 if (!GetIntFromConfig(aSection, KObserver(), observer)) |
|
203 { |
|
204 // Empty NewL |
|
205 TRAP(err, iLight = CHWRMLight::NewL()); |
|
206 } |
|
207 else |
|
208 { |
|
209 CHWRMLight* client = NULL; |
|
210 // Call NewL with null parameter |
|
211 TRAP(err, client = CHWRMLight::NewL(NULL)); |
|
212 delete client; |
|
213 client = NULL; |
|
214 } |
|
215 |
|
216 |
|
217 INFO_PRINTF1(_L("*END* CT_CHWRMLightsData::DoCmdNewL")); |
|
218 return err; |
|
219 } |
|
220 |
|
221 /** |
|
222 * Reserves light target exclusively for this client... |
|
223 * |
|
224 * @param aSection: light Defines which light should be reserved. |
|
225 * restoreState If ETrue, the state frozen on last release will be restored upon successful reservation. I.e. if light was blinking when it was released by this |
|
226 * client the last time, it would start blinking again upon successful reservation. For the first reservation of each session this parameter is |
|
227 * always considered EFalse regardless of what is supplied, as there is no previous frozen state to restore. |
|
228 * forceNoCCoeEnv If EFalse, then reservation requires that this client is on the foreground at the time of reservation and light target will be automatically |
|
229 * released and re-reserved based on background/foreground status of the this client. This also implies that CCoeEnv::Static() != NULL is |
|
230 * required. If ETrue, the client will not require CCoeEnv to be present nor does it automatically reserve/release light by depending on |
|
231 * foreground/background status of the client. Only trusted clients are allowed to set this flag to ETrue. Client is considered trusted if it has |
|
232 * nonstandard priority defined in the lights policy. |
|
233 */ |
|
234 TInt CT_CHWRMLightsData::DoCmdReserveLightL(const TTEFSectionName& aSection) |
|
235 { |
|
236 INFO_PRINTF1(_L("*START* CT_CHWRMLightsData::DoCmdReserveLightL")); |
|
237 TBool dataOk = ETrue; |
|
238 |
|
239 // Required parameters |
|
240 TInt light; |
|
241 GETFROMCONFIGMANDATORY(Int, aSection, KTarget, light, KLogMissingParameter, dataOk); |
|
242 |
|
243 // Optional parameters |
|
244 TBool restoreState = EFalse; |
|
245 GETFROMCONFIGOPTIONAL(Bool, aSection, KRestoreState, restoreState, KLogDefaultValueUsed); |
|
246 |
|
247 TBool forceNoCCoeEnv = ETrue; |
|
248 GETFROMCONFIGOPTIONAL(Bool, aSection, KForceNoCCoeEnv, forceNoCCoeEnv, KLogDefaultValueUsed); |
|
249 |
|
250 // API Method Call |
|
251 TInt err = KErrNone; |
|
252 if ( dataOk ) |
|
253 { |
|
254 TRAP(err, iLight->ReserveLightL(light, restoreState, forceNoCCoeEnv)); |
|
255 } |
|
256 |
|
257 INFO_PRINTF1(_L("*END* CT_CHWRMLightsData::DoCmdReserveLightL")); |
|
258 return err; |
|
259 } |
|
260 |
|
261 /** |
|
262 * The command blinks the target light(s) of the device for specified duration |
|
263 * using specified intensity. On- and Off-cycle times of the blinking can also be controlled. |
|
264 * |
|
265 * @param aSection: light Defines which light should be controlled. |
|
266 * duration Duration of the time the light is set to blink measured in milliseconds. |
|
267 * interval Value in milliseconds to initialize onDuration and offDuration parameters. |
|
268 * intensity Intensity of the light. |
|
269 */ |
|
270 TInt CT_CHWRMLightsData::DoCmdLightBlinkL(const TTEFSectionName& aSection) |
|
271 { |
|
272 INFO_PRINTF1(_L("*START* CT_CHWRMLightsData::DoCmdLightBlinkL")); |
|
273 TBool dataOk=ETrue; |
|
274 |
|
275 // Required parameters |
|
276 |
|
277 TInt light; |
|
278 GETFROMCONFIGMANDATORY(Int, aSection, KLight, light, KLogMissingParameter, dataOk); |
|
279 |
|
280 // Optional parameters |
|
281 |
|
282 TInt duration = KHWRMInfiniteDuration; |
|
283 GETFROMCONFIGOPTIONAL(Int, aSection, KDuration, duration, KLogDefaultValueUsed); |
|
284 |
|
285 TInt onDuration = KHWRMDefaultCycleTime; |
|
286 GETFROMCONFIGOPTIONAL(Int, aSection, KOnDuration, onDuration, KLogDefaultValueUsed); |
|
287 |
|
288 TInt offDuration = KHWRMDefaultCycleTime; |
|
289 GETFROMCONFIGOPTIONAL(Int, aSection, KOffDuration, offDuration, KLogDefaultValueUsed); |
|
290 |
|
291 TInt intensity = KHWRMDefaultIntensity; |
|
292 GETFROMCONFIGOPTIONAL(Int, aSection, KIntensity, intensity, KLogDefaultValueUsed); |
|
293 |
|
294 // API Method Call |
|
295 TInt err=KErrNone; |
|
296 if ( dataOk ) |
|
297 { |
|
298 TRAP(err, iLight->LightBlinkL(light, duration, onDuration, offDuration, intensity)); |
|
299 } |
|
300 |
|
301 INFO_PRINTF1(_L("*END* CT_CHWRMLightsData::DoCmdLightBlinkL")); |
|
302 return err; |
|
303 } |
|
304 |
|
305 /** |
|
306 * The command switches the specified target light on for the specified |
|
307 * duration using specified intensity. |
|
308 * |
|
309 * @param aSection: light Defines which light should be controlled. |
|
310 * duration Duration of the time the light is switched on measured in milliseconds. |
|
311 * intensity Intensity of the light. |
|
312 * fadein If ETrue, lights will not turn on instantly but instead smoothly fade-in. Note: All devices will not support fade-in, |
|
313 * in which case device will behave in its default fashion. |
|
314 */ |
|
315 TInt CT_CHWRMLightsData::DoCmdLightOnL(const TTEFSectionName& aSection) |
|
316 { |
|
317 INFO_PRINTF1(_L("*START* CT_CHWRMLightsData::DoCmdLightOnL")); |
|
318 TBool dataOk = ETrue; |
|
319 |
|
320 // Required parameters |
|
321 |
|
322 TInt light; |
|
323 GETFROMCONFIGMANDATORY(Int, aSection, KLight, light, KLogMissingParameter, dataOk); |
|
324 |
|
325 // Optional parameters |
|
326 |
|
327 TInt duration = KHWRMInfiniteDuration; |
|
328 GETFROMCONFIGOPTIONAL(Int, aSection, KDuration, duration, KLogDefaultValueUsed); |
|
329 |
|
330 TInt intensity = KHWRMDefaultIntensity; |
|
331 GETFROMCONFIGOPTIONAL(Int, aSection, KIntensity, intensity, KLogDefaultValueUsed); |
|
332 |
|
333 TBool fadein = EFalse; |
|
334 GETFROMCONFIGOPTIONAL(Bool, aSection, KFadein, fadein, KLogDefaultValueUsed); |
|
335 |
|
336 // API Method Call |
|
337 TInt err=KErrNone; |
|
338 if ( dataOk ) |
|
339 { |
|
340 TRAP(err, iLight->LightOnL(light, duration, intensity, fadein)); |
|
341 } |
|
342 |
|
343 INFO_PRINTF1(_L("*END* CT_CHWRMLightsData::DoCmdLightOnL")); |
|
344 return err; |
|
345 } |
|
346 |
|
347 /** |
|
348 * The command switches the device light off for the specified |
|
349 * target for the specified duration time. |
|
350 * |
|
351 * @param aSection: light Defines which light should be controlled. |
|
352 * duration Duration of the time the light is switched off measured in milliseconds. |
|
353 * fadeout If ETrue, lights will not turn off instantly but instead smoothly fade-out Note: All devices will not support fade-out, |
|
354 * in which case device will behave in its default fashion. |
|
355 */ |
|
356 TInt CT_CHWRMLightsData::DoCmdLightOffL(const TTEFSectionName& aSection) |
|
357 { |
|
358 INFO_PRINTF1(_L("*START* CT_CHWRMLightsData::DoCmdLightOffL")); |
|
359 TBool dataOk = ETrue; |
|
360 |
|
361 // Required parameters. |
|
362 |
|
363 TInt light; |
|
364 GETFROMCONFIGMANDATORY(Int, aSection, KLight, light, KLogMissingParameter, dataOk); |
|
365 |
|
366 // Optional parameters. |
|
367 |
|
368 TInt duration = KHWRMInfiniteDuration; |
|
369 GETFROMCONFIGOPTIONAL(Int, aSection, KDuration, duration, KLogDefaultValueUsed); |
|
370 |
|
371 TBool fadeout = EFalse; |
|
372 GETFROMCONFIGOPTIONAL(Bool, aSection, KFadeout, fadeout, KLogDefaultValueUsed); |
|
373 |
|
374 // API Method Call |
|
375 TInt err = KErrNone; |
|
376 if ( dataOk ) |
|
377 { |
|
378 TRAP(err, iLight->LightOffL(light, duration, fadeout)); |
|
379 } |
|
380 |
|
381 INFO_PRINTF1(_L("*END* CT_CHWRMLightsData::DoCmdLightOffL")); |
|
382 return err; |
|
383 } |
|
384 |
|
385 /** |
|
386 * This method compares the current light status with the expected status. |
|
387 * Light status: ELightStatusUnknown, ELightOn, ELightOff, ELightBlink |
|
388 * |
|
389 * @param aSection: expectedStatus Light status that is expected. |
|
390 * |
|
391 * @return |
|
392 */ |
|
393 TInt CT_CHWRMLightsData::DoCmdLightStatus(const TTEFSectionName& aSection) |
|
394 { |
|
395 INFO_PRINTF1(_L("*START* CT_CHWRMLightData::DoCmdLightStatus")); |
|
396 TBool dataOk = ETrue; |
|
397 TInt err = KErrNone; |
|
398 |
|
399 // Required parameters. |
|
400 |
|
401 TInt light; |
|
402 GETFROMCONFIGMANDATORY(Int, aSection, KLight, light, KLogMissingParameter, dataOk); |
|
403 |
|
404 TInt expectedStatus = CHWRMLight::ELightStatusUnknown; |
|
405 if(!GetEnumFromConfig(aSection, KStatus, iEnumLightStatus, expectedStatus)) |
|
406 { |
|
407 ERR_PRINTF2(_L("Error in getting parameter %S from INI file"), &KStatus); |
|
408 SetBlockResult(EFail); |
|
409 } |
|
410 |
|
411 if (dataOk) |
|
412 { |
|
413 TInt status = iLight->LightStatus(light); |
|
414 |
|
415 INFO_PRINTF2(_L("Current status is %d"), status); |
|
416 INFO_PRINTF2(_L("Expected status status is %d"), expectedStatus); |
|
417 |
|
418 if (status != expectedStatus) |
|
419 { |
|
420 err = KErrCorrupt; |
|
421 } |
|
422 } |
|
423 |
|
424 INFO_PRINTF1(_L("*END* CT_CHWRMLightData::DoCmdLightStatus")); |
|
425 return err; |
|
426 } |
|
427 |
|
428 /** |
|
429 * Command destructor. |
|
430 */ |
|
431 TInt CT_CHWRMLightsData::DoCmdDestructor() |
|
432 { |
|
433 INFO_PRINTF1(_L("*START* CT_CHWRMLightsData::DoCmdDestructor")); |
|
434 DestroyData(); |
|
435 INFO_PRINTF1(_L("*END* CT_CHWRMLightsData::DoCmdDestructor")); |
|
436 return KErrNone; |
|
437 } |
|
438 |
|
439 /** |
|
440 * Destroy an instance of CHWRMLight. |
|
441 */ |
|
442 void CT_CHWRMLightsData::DestroyData() |
|
443 { |
|
444 if(iLight) |
|
445 { |
|
446 delete iLight; |
|
447 iLight = NULL; |
|
448 } |
|
449 } |