author | Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com> |
Tue, 24 Nov 2009 08:56:33 +0200 | |
changeset 33 | 50974a8b132e |
parent 19 | 989d2f495d90 |
permissions | -rw-r--r-- |
19 | 1 |
/* |
2 |
* Copyright (c) 2002 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 the License "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: ?Description |
|
15 |
* |
|
16 |
*/ |
|
17 |
||
18 |
||
19 |
||
33
50974a8b132e
Revision: 200945
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
20 |
#include "tsysbattery.h" |
19 | 21 |
#include "sysinfoservice.h" |
22 |
#include "entitykeys.h" |
|
23 |
#include "tbatterystrengthasyn.h" |
|
24 |
||
25 |
using namespace SysInfo; |
|
26 |
||
27 |
CBatteryStrengthAsync* CBatteryStrengthAsync::NewL(CStifLogger* aLog) |
|
28 |
{ |
|
29 |
CBatteryStrengthAsync* self = new(ELeave) CBatteryStrengthAsync(aLog); |
|
30 |
self->ConstructL(); |
|
31 |
return self; |
|
32 |
} |
|
33 |
||
34 |
CBatteryStrengthAsync::~CBatteryStrengthAsync() |
|
35 |
{ |
|
36 |
Cancel(); |
|
37 |
||
38 |
if(iWaitSchedular->IsStarted()) |
|
39 |
iWaitSchedular->AsyncStop(); |
|
40 |
||
41 |
delete iSysInfoService; |
|
42 |
delete iWaitSchedular; |
|
43 |
delete iTimer; |
|
44 |
} |
|
45 |
||
46 |
void CBatteryStrengthAsync::ConstructL() |
|
47 |
{ |
|
48 |
iSysInfoService = CSysInfoService::NewL(); |
|
49 |
iWaitSchedular = new(ELeave) CActiveSchedulerWait(); |
|
50 |
iTimer = CWatchTimer::NewL(EPriorityNormal,this); |
|
51 |
CActiveScheduler::Add(this); |
|
52 |
} |
|
53 |
||
54 |
CBatteryStrengthAsync::CBatteryStrengthAsync(CStifLogger* aLog) |
|
55 |
:CActive(EPriorityStandard), |
|
56 |
iLog(aLog) |
|
57 |
{ |
|
58 |
} |
|
59 |
||
60 |
void CBatteryStrengthAsync::DoCancel() |
|
61 |
{ |
|
62 |
} |
|
63 |
||
64 |
void CBatteryStrengthAsync::RunL() |
|
65 |
{ |
|
66 |
TestFuncL(); |
|
67 |
} |
|
68 |
||
69 |
void CBatteryStrengthAsync::Start() |
|
70 |
{ |
|
71 |
SetActive(); |
|
72 |
TRequestStatus* temp = &iStatus; |
|
73 |
User::RequestComplete(temp, KErrNone); |
|
74 |
iWaitSchedular->Start(); |
|
75 |
} |
|
76 |
||
77 |
TInt CBatteryStrengthAsync::Result() |
|
78 |
{ |
|
79 |
return iResult; |
|
80 |
} |
|
81 |
||
82 |
void CBatteryStrengthAsync::TestFuncL() |
|
83 |
{ |
|
84 |
const TTimeIntervalMicroSeconds32 OneMinute(60000000); |
|
85 |
iSysInfoService->GetInfoL(KBattery,KBatteryStrength,1,this); |
|
86 |
iTimer->After(OneMinute); |
|
87 |
} |
|
88 |
||
89 |
void CBatteryStrengthAsync::HandleResponseL(const TDesC& aEntity,const TDesC& aKey, |
|
90 |
CSysData* aOutput, TInt32 aTransID, TSysRequest::TRequestType /*aType*/,TInt aError) |
|
91 |
{ |
|
92 |
delete iTimer; |
|
93 |
iTimer = NULL; |
|
94 |
||
95 |
iLog->Log(_L("Entity: %s, Key: %s "),aEntity.Ptr(),aKey.Ptr()); |
|
96 |
||
97 |
if(aEntity.Compare(KBattery) || aKey.Compare(KBatteryStrength)) |
|
98 |
iLog->Log(_L("Incorrect Entity,Key..")); |
|
99 |
||
100 |
iLog->Log(_L("Battery Strength read..")); |
|
101 |
||
102 |
if(!aError) |
|
103 |
{ |
|
104 |
TInt32 tid = aTransID; |
|
105 |
if(tid != 1) |
|
106 |
{ |
|
107 |
iResult = FAIL; |
|
108 |
iLog->Log(_L("Incorrect TID Retured.. %d"),tid); |
|
109 |
} |
|
110 |
||
111 |
TInt BatteryStrength = ((CStatus*)aOutput)->Status(); |
|
112 |
||
113 |
iLog->Log(_L("Battery Strength: %d "),BatteryStrength); |
|
114 |
||
115 |
if( BatteryStrength > 0 && BatteryStrength <= 100 ) |
|
116 |
{ |
|
117 |
iResult = PASS; |
|
118 |
iLog->Log(_L("Battery strength is with in expected range")); |
|
119 |
} |
|
120 |
else |
|
121 |
{ |
|
122 |
iResult = FAIL; |
|
123 |
iLog->Log(_L("Battery strength is out of range")); |
|
124 |
} |
|
125 |
delete aOutput; |
|
126 |
} |
|
127 |
else |
|
128 |
{ |
|
129 |
iLog->Log(_L("ERROR SET")); |
|
130 |
iResult = FAIL; |
|
131 |
} |
|
132 |
iWaitSchedular->AsyncStop(); |
|
133 |
} |
|
134 |
||
135 |
void CBatteryStrengthAsync::HandleTimeOut() |
|
136 |
{ |
|
137 |
iLog->Log(_L("CBatteryStrengthAsync TimeOut reached...")); |
|
138 |
iSysInfoService->Cancel(1); |
|
139 |
iResult = FAIL; |
|
140 |
iWaitSchedular->AsyncStop(); |
|
141 |
} |