1 /* |
|
2 * Copyright (c) 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 "PwrPlugin.h" |
|
19 #include <piprofiler/ProfilerTraces.h> |
|
20 |
|
21 #include <centralrepository.h> |
|
22 #include <HWRMPower.h> |
|
23 #include <HWRMLight.h> |
|
24 #include <hwrm/hwrmpowerdomaincrkeys.h> |
|
25 |
|
26 |
|
27 // texts for notes |
|
28 _LIT(KPowerTextLine1, "Power sampler:"); |
|
29 _LIT(KPowerTextLine2, "Failed to start power measurement"); |
|
30 _LIT(KPowerTextErrorSampling, "Error receiving measurement data"); |
|
31 _LIT(KButtonOk, "Ok"); |
|
32 |
|
33 // LITERALS |
|
34 |
|
35 _LIT8(KSamplingPeriodMs, "sampling_period_ms"); |
|
36 |
|
37 // CONSTANTS |
|
38 // Use this UID if plugin is PwrPlugin: |
|
39 const TUid KSamplerPwrPluginUid = { 0x2001E5B9 }; |
|
40 |
|
41 /* |
|
42 * |
|
43 * class CPwrPlugin implementation |
|
44 * |
|
45 */ |
|
46 |
|
47 CPwrPlugin* CPwrPlugin::NewL(const TUid /*aImplementationUid*/, TAny* aInitParams) |
|
48 { |
|
49 LOGTEXT(_L("CPwrPlugin::NewL() - entry")); |
|
50 CPwrPlugin* self = new (ELeave) CPwrPlugin(); |
|
51 CleanupStack::PushL( self ); |
|
52 self->ConstructL(); |
|
53 CleanupStack::Pop(); |
|
54 LOGTEXT(_L("CPwrPlugin::NewL() - exit")); |
|
55 return self; |
|
56 } |
|
57 |
|
58 CPwrPlugin::CPwrPlugin() : |
|
59 iVersionDescriptor(&(this->iVersion[1]),0,19), |
|
60 iSamplerType(PROFILER_USER_MODE_SAMPLER) |
|
61 { |
|
62 iPeriod = 250; |
|
63 iSamplerId = PROFILER_PWR_SAMPLER_ID; |
|
64 iEnabled = EFalse; |
|
65 iPowerListener = NULL; |
|
66 LOGTEXT(_L("CPwrPlugin::CPwrPlugin() - konstruktori")); |
|
67 |
|
68 } |
|
69 |
|
70 void CPwrPlugin::ConstructL() |
|
71 { |
|
72 LOGTEXT(_L("CPwrPlugin::ConstructL() - entry")); |
|
73 // initiate sampler attributes array |
|
74 iSamplerAttributes = new(ELeave) CArrayFixFlat<TSamplerAttributes>(1); // only one sampler |
|
75 |
|
76 // insert default attributes to array |
|
77 InitiateSamplerAttributesL(); |
|
78 |
|
79 LOGTEXT(_L("CPwrPlugin::ConstructL() - exit")); |
|
80 } |
|
81 |
|
82 CPwrPlugin::~CPwrPlugin() |
|
83 { |
|
84 LOGTEXT(_L("CPwrPlugin::~CPwrPlugin() - entry")); |
|
85 if(iPowerListener) |
|
86 { |
|
87 if(Enabled()) |
|
88 { |
|
89 iPowerListener->Stop(); |
|
90 } |
|
91 delete iPowerListener; |
|
92 iPowerListener = NULL; |
|
93 } |
|
94 |
|
95 if(iSamplerAttributes) |
|
96 { |
|
97 iSamplerAttributes->Reset(); |
|
98 delete iSamplerAttributes; |
|
99 iSamplerAttributes = NULL; |
|
100 } |
|
101 |
|
102 LOGTEXT(_L("CPwrPlugin::~CPwrPlugin() - exit")); |
|
103 } |
|
104 |
|
105 TUid CPwrPlugin::Id(TInt /*aSubId*/) const |
|
106 { |
|
107 LOGSTRING2( "CPwrPlugin::Id():0x%X", KSamplerPwrPluginUid.iUid ); |
|
108 return KSamplerPwrPluginUid; |
|
109 } |
|
110 |
|
111 void CPwrPlugin::InitiateSamplerAttributesL() |
|
112 { |
|
113 // create TSamplerAttributes |
|
114 TSamplerAttributes attr(KSamplerPwrPluginUid.iUid, |
|
115 KPWRShortName(), |
|
116 KPWRLongName(), |
|
117 KPWRDescription(), |
|
118 250, |
|
119 EFalse, |
|
120 EFalse, |
|
121 0); |
|
122 this->iSamplerAttributes->AppendL(attr); |
|
123 } |
|
124 |
|
125 void CPwrPlugin::SetEnabled(TBool aEnabled) |
|
126 { |
|
127 iEnabled = aEnabled; |
|
128 } |
|
129 |
|
130 // returns setting array |
|
131 void CPwrPlugin::GetAttributesL(CArrayFixFlat<TSamplerAttributes>* aAttributes) |
|
132 { |
|
133 aAttributes->AppendL(iSamplerAttributes->At(0)); |
|
134 } |
|
135 |
|
136 TInt CPwrPlugin::SetAttributesL(TSamplerAttributes aAttributes) |
|
137 { |
|
138 TSamplerAttributes attr; |
|
139 |
|
140 attr = iSamplerAttributes->At(0); |
|
141 // replace the old attribute container |
|
142 iSamplerAttributes->Delete(0); |
|
143 iSamplerAttributes->InsertL(0, aAttributes); |
|
144 return KErrNone; |
|
145 } |
|
146 |
|
147 /* |
|
148 * Method for parsing and transforming text array settings into TSamplerAttributes (per each sub sampler), |
|
149 * called by CSamplerController class |
|
150 * |
|
151 * @param array of raw text setting lines, e.g. [gpp]\nenabled=true\nsampling_period_ms=1\n |
|
152 */ |
|
153 TInt CPwrPlugin::ConvertRawSettingsToAttributes(CDesC8ArrayFlat* aAllSettingsArray) |
|
154 { |
|
155 // local literals |
|
156 _LIT8(KPWRShort, "pwr"); |
|
157 |
|
158 TInt err(KErrNone); |
|
159 TBuf8<16> samplerSearchName; |
|
160 samplerSearchName.Copy(KPWRShort); |
|
161 |
|
162 // get sampler specific settings |
|
163 err = DoSetSamplerSettings(aAllSettingsArray, samplerSearchName, 0); |
|
164 |
|
165 // returns KErrNone if settings found, otherwise KErrNotFound |
|
166 return err; |
|
167 } |
|
168 |
|
169 TInt CPwrPlugin::DoSetSamplerSettings(CDesC8ArrayFlat* aAllSettings, TDesC8& aSamplerName, TInt aIndex) |
|
170 { |
|
171 // |
|
172 TBuf8<16> samplerSearch; |
|
173 samplerSearch.Copy(KBracketOpen); |
|
174 samplerSearch.Append(aSamplerName); |
|
175 samplerSearch.Append(KBracketClose); |
|
176 |
|
177 // read a line |
|
178 for (TInt i(0); i<aAllSettings->MdcaCount(); i++) |
|
179 { |
|
180 // check if this line has a setting block start, i.e. contains [xxx] in it |
|
181 if (aAllSettings->MdcaPoint(i).CompareF(samplerSearch) == 0) |
|
182 { |
|
183 // right settings block found, now loop until the next block is found |
|
184 for(TInt j(i+1);j<aAllSettings->MdcaCount();j++) |
|
185 { |
|
186 // check if the next settings block was found |
|
187 if(aAllSettings->MdcaPoint(j).Left(1).CompareF(KBracketOpen) != 0) |
|
188 { |
|
189 // save found setting value directly to its owners attributes |
|
190 SaveSettingToAttributes(aAllSettings->MdcaPoint(j), aIndex); |
|
191 } |
|
192 else |
|
193 { |
|
194 // next block found, return KErrNone |
|
195 return KErrNone; |
|
196 } |
|
197 } |
|
198 } |
|
199 } |
|
200 |
|
201 return KErrNotFound; |
|
202 } |
|
203 |
|
204 /** |
|
205 * Method for setting a specific descriptor (from settings file) to attribute structure |
|
206 * |
|
207 * @param aSetting |
|
208 * @param aName |
|
209 */ |
|
210 void CPwrPlugin::SaveSettingToAttributes(const TDesC8& aSetting, TInt aIndex) |
|
211 { |
|
212 // find the equal mark from the setting line |
|
213 TInt sepPos = aSetting.Find(KSettingItemSeparator); |
|
214 // check that '=' is found |
|
215 if (sepPos > 0) |
|
216 { |
|
217 // check that the element matches |
|
218 if (aSetting.Left(sepPos).CompareF(KEnabled) == 0) |
|
219 { |
|
220 TBool en; |
|
221 CSamplerPluginInterface::Str2Bool(aSetting.Right(aSetting.Length()-sepPos-1), en); |
|
222 if(en != iSamplerAttributes->At(aIndex).iEnabled) |
|
223 { |
|
224 iSamplerAttributes->At(aIndex).iEnabled = en; |
|
225 } |
|
226 } |
|
227 else if (aSetting.Left(sepPos).CompareF(KSamplingPeriodMs) == 0) |
|
228 { |
|
229 TInt sr; |
|
230 CSamplerPluginInterface::Str2Int(aSetting.Right(aSetting.Length()-sepPos-1), sr); |
|
231 if(sr != iSamplerAttributes->At(aIndex).iSampleRate) |
|
232 { |
|
233 iSamplerAttributes->At(aIndex).iSampleRate = sr; |
|
234 } |
|
235 } |
|
236 } |
|
237 } |
|
238 |
|
239 TInt CPwrPlugin::GetSamplerType() |
|
240 { |
|
241 return iSamplerType; |
|
242 } |
|
243 |
|
244 TInt CPwrPlugin::ResetAndActivateL(CProfilerSampleStream& aStream) |
|
245 { |
|
246 LOGTEXT(_L("CPwrPlugin::ResetAndActivate() - entry")); |
|
247 // check if sampler enabled |
|
248 if(iSamplerAttributes->At(0).iEnabled) |
|
249 { |
|
250 // create a new listener instance for every trace, destroy it on stop |
|
251 iPowerListener = CProfilerPowerListener::NewL(this); |
|
252 |
|
253 iStream = &aStream; |
|
254 TInt length = this->CreateFirstSample(); |
|
255 iVersion[0] = (TUint8)length; |
|
256 LOGSTRING2("CPwrPlugin::ResetAndActivate() - AddSample, length %d", length); |
|
257 TInt ret = this->AddSample(iVersion, length+1, 0); |
|
258 |
|
259 LOGSTRING2("CPwrPlugin::ConstructL() - sampling period %d", this->iPeriod); |
|
260 |
|
261 HBufC8* iBufRes = HBufC8::NewMaxLC(10); |
|
262 TPtr8 iPtrRes = iBufRes->Des(); |
|
263 |
|
264 // check if sampling rate set to something reasonable, relevant only in SYNC case |
|
265 if(iSamplerAttributes->At(0).iSampleRate != -1) |
|
266 { |
|
267 iPtrRes.Num(iSamplerAttributes->At(0).iSampleRate); |
|
268 } |
|
269 else |
|
270 { |
|
271 iPtrRes.Append(KNullDesC8); |
|
272 } |
|
273 |
|
274 // set disabled |
|
275 SetEnabled(ETrue); |
|
276 |
|
277 // activate power listener |
|
278 ret = iPowerListener->StartL(iPtrRes); |
|
279 LOGTEXT(_L("CPwrPlugin::ResetAndActivate() - exit")); |
|
280 |
|
281 CleanupStack::PopAndDestroy(); |
|
282 |
|
283 if(ret != KErrNone) |
|
284 return ret; |
|
285 } |
|
286 return KErrNone; |
|
287 } |
|
288 |
|
289 TInt CPwrPlugin::CreateFirstSample() |
|
290 { |
|
291 LOGTEXT(_L("CPwrPlugin::CreateFirstSample - entry")); |
|
292 this->iVersionDescriptor.Zero(); |
|
293 this->iVersionDescriptor.Append(_L8("Bappea_PWR_V")); |
|
294 this->iVersionDescriptor.Append(PROFILER_PWR_SAMPLER_VERSION); |
|
295 LOGTEXT(_L("CPwrPlugin::CreateFirstSample - exit")); |
|
296 return (TInt)(this->iVersionDescriptor.Length()); |
|
297 } |
|
298 |
|
299 TInt CPwrPlugin::StopSampling() |
|
300 { |
|
301 if(iPowerListener) |
|
302 { |
|
303 iPowerListener->Stop(); |
|
304 delete iPowerListener; |
|
305 iPowerListener = NULL; |
|
306 } |
|
307 |
|
308 // set disabled |
|
309 SetEnabled(EFalse); |
|
310 |
|
311 return KErrNone; |
|
312 } |
|
313 |
|
314 |
|
315 /* |
|
316 * |
|
317 * class CProfilerPowerListener implementation |
|
318 * |
|
319 */ |
|
320 |
|
321 CProfilerPowerListener::CProfilerPowerListener(CPwrPlugin* aSampler) : |
|
322 iPwrSamplingPeriod(0), |
|
323 iOriginalReportingPeriod(0), |
|
324 iNominalCapa(0), |
|
325 iVoltage(0), |
|
326 iCurrent(0), |
|
327 iPowerAPI(0) |
|
328 #ifdef PWR_SAMPLER_BACKLIGHT |
|
329 ,iLightAPI(0), |
|
330 iBackLightStatus(CHWRMLight::ELightStatusUnknown) |
|
331 #endif |
|
332 |
|
333 { |
|
334 LOGTEXT(_L("CProfilerPowerListener::CProfilerPowerListener() - konstuktori")); |
|
335 this->iSampler = aSampler; |
|
336 LOGTEXT(_L("CProfilerPowerListener::CProfilerPowerListener() - konstuktori exit")); |
|
337 } |
|
338 |
|
339 CProfilerPowerListener* CProfilerPowerListener::NewL(CPwrPlugin* aSampler) |
|
340 { |
|
341 LOGTEXT(_L("CProfilerPowerListener::NewL() - entry")); |
|
342 CProfilerPowerListener* self = new (ELeave) CProfilerPowerListener(aSampler); |
|
343 CleanupStack::PushL( self ); |
|
344 self->ConstructL(); |
|
345 CleanupStack::Pop(); |
|
346 LOGTEXT(_L("CProfilerPowerListener::NewL() - exit")); |
|
347 return self; |
|
348 } |
|
349 |
|
350 void CProfilerPowerListener::ConstructL() |
|
351 { |
|
352 LOGTEXT(_L("CProfilerPowerListener::ConstructL() - entry")); |
|
353 iSampleStartTime = 0; |
|
354 LOGTEXT(_L("CProfilerPowerListener::ConstructL() - exit")); |
|
355 } |
|
356 |
|
357 CProfilerPowerListener::~CProfilerPowerListener() |
|
358 { |
|
359 LOGTEXT(_L("CProfilerPowerListener::~CProfilerPowerListener() - entry")); |
|
360 |
|
361 if (iPowerAPI) |
|
362 { |
|
363 delete iPowerAPI; |
|
364 iPowerAPI = 0; |
|
365 } |
|
366 #ifdef PWR_SAMPLER_BACKLIGHT |
|
367 if (iLightAPI) |
|
368 { |
|
369 delete iLightAPI; |
|
370 iLightAPI = 0; |
|
371 } |
|
372 #endif |
|
373 |
|
374 LOGTEXT(_L("CProfilerPowerListener::~CProfilerPowerListener() - exit")); |
|
375 } |
|
376 |
|
377 TInt CProfilerPowerListener::DisplayNotifierL(const TDesC& aLine1, const TDesC& aLine2, const TDesC& aButton1, const TDesC& aButton2) |
|
378 { |
|
379 RNotifier notifier; |
|
380 TRequestStatus stat; |
|
381 |
|
382 TInt buttonValue(0); |
|
383 |
|
384 User::LeaveIfError(notifier.Connect()); |
|
385 |
|
386 notifier.Notify(aLine1, aLine2, aButton1, aButton2, buttonValue, stat); |
|
387 User::WaitForRequest(stat); |
|
388 |
|
389 notifier.Close(); |
|
390 return buttonValue; |
|
391 } |
|
392 |
|
393 |
|
394 TInt CProfilerPowerListener::StartL(const TDesC8& aBuf) |
|
395 { |
|
396 LOGTEXT(_L("CProfilerPowerListener::StartL() - entry")); |
|
397 |
|
398 // get the property value |
|
399 TInt r = RProperty::Get(KGppPropertyCat, EGppPropertySyncSampleNumber, iSampleStartTime); |
|
400 if(r != KErrNone) |
|
401 { |
|
402 LOGSTRING2("CProfilerPowerListener::StartL() - getting iSyncOffset failed, error %d", r); |
|
403 } |
|
404 |
|
405 // check if given sampling period is valid |
|
406 if(aBuf.CompareF(KNullDesC8)!= 0) |
|
407 { |
|
408 TLex8* lex = new TLex8(aBuf); |
|
409 lex->Val(iPwrSamplingPeriod); |
|
410 delete lex; |
|
411 } |
|
412 else |
|
413 { |
|
414 // set default period |
|
415 iPwrSamplingPeriod = 250; |
|
416 } |
|
417 |
|
418 // Check that sampling period is in allowed range |
|
419 if (KMinSampleInterval > 0 && iPwrSamplingPeriod < KMinSampleInterval) |
|
420 { |
|
421 iPwrSamplingPeriod = KMinSampleInterval; |
|
422 } |
|
423 |
|
424 LOGSTRING2("CProfilerPowerListener::StartL() - Sampling period %d", iPwrSamplingPeriod); |
|
425 |
|
426 // Start monitoring voltage and current |
|
427 iPowerAPI = CHWRMPower::NewL(); |
|
428 iPowerAPI->SetPowerReportObserver(this); |
|
429 |
|
430 // Read HWRM reporting settings from central repository |
|
431 CRepository* centRep = CRepository::NewL(KCRUidPowerSettings); |
|
432 TInt baseInterval(0); |
|
433 User::LeaveIfError(centRep->Get(KPowerBaseTimeInterval, baseInterval)); |
|
434 User::LeaveIfError(centRep->Get(KPowerMaxReportingPeriod, iOriginalReportingPeriod)); |
|
435 |
|
436 LOGSTRING2("CProfilerPowerListener::StartL() - HWRM base power report interval: %d", baseInterval); |
|
437 LOGSTRING2("CProfilerPowerListener::StartL() - Original HWRM max power reporting period: %d", iOriginalReportingPeriod); |
|
438 |
|
439 User::LeaveIfError(centRep->Set(KPowerMaxReportingPeriod, KReportingPeriodInfinite)); |
|
440 |
|
441 // Power reporting interval reading may return too low value sometimes. Minimum value expected to be 250ms. |
|
442 if ( baseInterval < KMinSampleInterval ) |
|
443 { |
|
444 baseInterval = KMinSampleInterval; |
|
445 LOGSTRING2("CProfilerPowerListener::StartL() - Power report interval too low. Changed to: %d", baseInterval); |
|
446 } |
|
447 |
|
448 // Power reporting period is multiplier of HWRM base period |
|
449 TInt intervalMultiplier = iPwrSamplingPeriod / baseInterval; |
|
450 |
|
451 if (intervalMultiplier < 1) |
|
452 { |
|
453 intervalMultiplier = 1; |
|
454 } |
|
455 |
|
456 LOGSTRING2("CProfilerPowerListener::StartL() - Reporting period multiplier: %d", intervalMultiplier); |
|
457 |
|
458 TRequestStatus status(KRequestPending); |
|
459 iPowerAPI->StartAveragePowerReporting(status, intervalMultiplier); |
|
460 User::WaitForRequest(status); |
|
461 |
|
462 if (status.Int() != KErrNone) |
|
463 { |
|
464 LOGTEXT(_L("CProfilerPowerListener::StartL() - Failed to initialize power reporting")); |
|
465 |
|
466 DisplayNotifierL(KPowerTextLine1, KPowerTextLine2, KButtonOk, KNullDesC); |
|
467 |
|
468 return status.Int(); |
|
469 } |
|
470 |
|
471 #ifdef PWR_SAMPLER_BACKLIGHT |
|
472 // Start monitoring backlight status |
|
473 iLightAPI = CHWRMLight::NewL(this); |
|
474 #endif |
|
475 |
|
476 LOGTEXT(_L("CProfilerPowerListener::StartL() - exit")); |
|
477 return KErrNone; |
|
478 } |
|
479 |
|
480 void CProfilerPowerListener::Sample() |
|
481 { |
|
482 LOGTEXT(_L("CProfilerPowerListener::Sample() - entry")); |
|
483 |
|
484 TRequestStatus status; |
|
485 CHWRMPower::TBatteryConsumptionData consumptionData; |
|
486 |
|
487 iPowerAPI->GetBatteryInfo(status, consumptionData); |
|
488 User::WaitForRequest(status); |
|
489 |
|
490 // Data is valid only if status == KErrNone |
|
491 if (status.Int() != KErrNone) |
|
492 { |
|
493 LOGSTRING2("CProfilerPowerListener::Sample() - Getting battery info failed with code: ", status.Int()); |
|
494 iNominalCapa = 0; |
|
495 } |
|
496 else |
|
497 { |
|
498 iNominalCapa = consumptionData.iNominalCapacity; |
|
499 } |
|
500 |
|
501 // Space for GPP sample time |
|
502 //TUint32 sampleTime = iSampler->iStream->iSampler->GetSampleTime(); |
|
503 TUint32 sampleTime = User::NTickCount() - iSampleStartTime; |
|
504 LOGSTRING2("CProfilerPowerListener::Sample() - Sample time: %d", sampleTime); |
|
505 LOGSTRING2("CProfilerPowerListener::Sample() - Nominal capacitance: %d", iNominalCapa); |
|
506 LOGSTRING2("CProfilerPowerListener::Sample() - Voltage: %d", iVoltage); |
|
507 LOGSTRING2("CProfilerPowerListener::Sample() - Current: %d", iCurrent); |
|
508 #ifdef PWR_SAMPLER_BACKLIGHT |
|
509 LOGSTRING2("CProfilerPowerListener::Sample() - Backlight status: %d", (TUint8)iBackLightStatus); |
|
510 #endif |
|
511 |
|
512 iSample[0] = iNominalCapa; |
|
513 iSample[1] = iNominalCapa >> 8; |
|
514 iSample[2] = iVoltage; |
|
515 iSample[3] = iVoltage >> 8; |
|
516 iSample[4] = iCurrent; |
|
517 iSample[5] = iCurrent >> 8; |
|
518 iSample[6] = iCurrent >> 16; |
|
519 iSample[7] = iCurrent >> 24; |
|
520 #ifdef PWR_SAMPLER_BACKLIGHT |
|
521 iSample[8] = (TUint8)iBackLightStatus; |
|
522 iSample[9] = sampleTime; |
|
523 iSample[10] = sampleTime >> 8; |
|
524 iSample[11] = sampleTime >> 16; |
|
525 iSample[12] = sampleTime >> 24; |
|
526 |
|
527 iSampler->AddSample(iSample, 13, 0); |
|
528 #else |
|
529 iSample[8] = sampleTime; |
|
530 iSample[9] = sampleTime >> 8; |
|
531 iSample[10] = sampleTime >> 16; |
|
532 iSample[11] = sampleTime >> 24; |
|
533 |
|
534 iSampler->AddSample(iSample, 12, 0); |
|
535 #endif |
|
536 |
|
537 LOGTEXT(_L("CProfilerPowerListener::Sample() - exit")); |
|
538 } |
|
539 |
|
540 TInt CProfilerPowerListener::Stop() |
|
541 { |
|
542 LOGTEXT(_L("CProfilerPowerListener::Stop() - entry")); |
|
543 |
|
544 if (iPowerAPI) |
|
545 { |
|
546 TRAPD(err, iPowerAPI->StopAveragePowerReportingL()); |
|
547 if(err != KErrNone) |
|
548 { |
|
549 LOGSTRING2("CProfilerPowerListener::Stop() - Failed to stop power reporting: %d", err); |
|
550 } |
|
551 else |
|
552 { |
|
553 LOGTEXT(_L("CProfilerPowerListener::Stop() - Stopped power monitoring")); |
|
554 } |
|
555 delete iPowerAPI; |
|
556 iPowerAPI = 0; |
|
557 |
|
558 // Restore original value to max sampling period |
|
559 CRepository* centRep = 0; |
|
560 TRAP(err, centRep = CRepository::NewL(KCRUidPowerSettings)); |
|
561 if (err != KErrNone) |
|
562 { |
|
563 LOGSTRING2("CProfilerPowerListener::Stop() - Failed to open Central Repository: %d", err); |
|
564 } |
|
565 else |
|
566 { |
|
567 err = centRep->Set(KPowerMaxReportingPeriod, iOriginalReportingPeriod); |
|
568 if(err != KErrNone) |
|
569 { |
|
570 LOGSTRING2("CProfilerPowerListener::Stop() - Failed to restore max sampling period: %d", err); |
|
571 } |
|
572 } |
|
573 } |
|
574 #ifdef PWR_SAMPLER_BACKLIGHT |
|
575 if (iLightAPI) |
|
576 { |
|
577 delete iLightAPI; |
|
578 iLightAPI = 0; |
|
579 } |
|
580 #endif |
|
581 |
|
582 LOGTEXT(_L("CProfilerPowerListener::Stop() - exit")); |
|
583 return KErrNone; |
|
584 } |
|
585 |
|
586 void CProfilerPowerListener::PowerMeasurement(TInt aErr, CHWRMPower::TBatteryPowerMeasurementData& aMeasurement) |
|
587 { |
|
588 LOGTEXT(_L("CProfilerPowerListener::PowerMeasurement - entry")); |
|
589 |
|
590 if (aErr == KErrNone) |
|
591 { |
|
592 LOGSTRING3("CProfilerPowerListener::PowerMeasurement - Previous values - Voltage: %d Current: %d", iVoltage, iCurrent); |
|
593 iVoltage = aMeasurement.iAverageVoltage; |
|
594 iCurrent = aMeasurement.iAverageCurrent; |
|
595 LOGSTRING3("CProfilerPowerListener::PowerMeasurement - New values - Voltage: %d Current: %d", iVoltage, iCurrent); |
|
596 |
|
597 this->Sample(); |
|
598 } |
|
599 else |
|
600 { |
|
601 LOGSTRING2("CProfilerPowerListener::PowerMeasurement - Failed with error code: %d", aErr); |
|
602 DisplayNotifierL(KPowerTextLine1, KPowerTextErrorSampling, KButtonOk, KNullDesC); |
|
603 } |
|
604 LOGTEXT(_L("CProfilerPowerListener::PowerMeasurement - exit")); |
|
605 } |
|
606 |
|
607 #ifdef PWR_SAMPLER_BACKLIGHT |
|
608 void CProfilerPowerListener::LightStatusChanged(TInt aTarget, CHWRMLight::TLightStatus aStatus) |
|
609 { |
|
610 LOGTEXT(_L("CProfilerPowerListener::LightStatusChanged - entry")); |
|
611 LOGSTRING3("CProfilerPowerListener::LightStatusChanged - Target: %d Status: %d", aTarget, aStatus); |
|
612 |
|
613 if (aTarget == CHWRMLight::EPrimaryDisplay) |
|
614 { |
|
615 LOGSTRING2("CProfilerPowerListener::LightStatusChanged - Previous light status: %d", iBackLightStatus); |
|
616 iBackLightStatus = aStatus; |
|
617 LOGSTRING2("CProfilerPowerListener::LightStatusChanged - New light status: %d", iBackLightStatus); |
|
618 |
|
619 this->Sample(); |
|
620 } |
|
621 LOGTEXT(_L("CProfilerPowerListener::LightStatusChanged - exit")); |
|
622 } |
|
623 #endif |
|