24
|
1 |
// Copyright (c) 2001-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 |
// Implements the functionality required to provide clients with
|
|
15 |
// Battery charging information.
|
|
16 |
//
|
|
17 |
//
|
|
18 |
|
|
19 |
/**
|
|
20 |
@file
|
|
21 |
*/
|
|
22 |
|
|
23 |
#include <testconfigfileparser.h>
|
|
24 |
#include "CSimBatteryCharger.h"
|
|
25 |
#include "CSimPhone.h"
|
|
26 |
#include "Simlog.h"
|
|
27 |
|
|
28 |
const TInt KChargerGranularity=5; // < Granularity for Battery Charger list array
|
|
29 |
|
|
30 |
|
|
31 |
CSimBatteryCharger* CSimBatteryCharger::NewL(CSimPhone* aPhone)
|
|
32 |
/**
|
|
33 |
* Standard two-phase constructor.
|
|
34 |
* @param aPhone The parent phone object.
|
|
35 |
* @return CSimBatteryCharger The new Ondicator class class.
|
|
36 |
*/
|
|
37 |
{
|
|
38 |
CSimBatteryCharger* self=new(ELeave) CSimBatteryCharger(aPhone);
|
|
39 |
CleanupStack::PushL(self);
|
|
40 |
self->ConstructL();
|
|
41 |
CleanupStack::Pop();
|
|
42 |
return self;
|
|
43 |
}
|
|
44 |
|
|
45 |
CSimBatteryCharger::CSimBatteryCharger(CSimPhone* aPhone)
|
|
46 |
: iPhone(aPhone)
|
|
47 |
/**
|
|
48 |
* Trivial first phase construction.
|
|
49 |
* @param aPhone The parent phone object.
|
|
50 |
*/
|
|
51 |
{
|
|
52 |
}
|
|
53 |
|
|
54 |
|
|
55 |
void CSimBatteryCharger::ConstructL()
|
|
56 |
/**
|
|
57 |
* Second phase construction. Create instances of the necessary heap-based
|
|
58 |
* objects and read in the Battery Charger information from the configuration file.
|
|
59 |
* Finally, if any Battery Charger tags have been read, the initial values
|
|
60 |
* will be loaded and the timer started.
|
|
61 |
*
|
|
62 |
* Entries in the configuration file will take the following format:
|
|
63 |
* "BatteryCharger= <duration>, <Status> <battery level> <error code>"
|
|
64 |
* A number of these entries may be included to create an battery charger profile
|
|
65 |
* for the duration of the test.
|
|
66 |
*/
|
|
67 |
{
|
|
68 |
iTimer=CSimTimer::NewL(iPhone);
|
|
69 |
iBatteryChargerInfo=new(ELeave) CArrayFixFlat<TBatteryChargerInfo>(KChargerGranularity);
|
|
70 |
|
|
71 |
LOGMISC1("Starting to parse Battery Charger config parameters...");
|
|
72 |
TInt count=CfgFile()->ItemCount(KBatteryCharger);
|
|
73 |
const CTestConfigItem* item=NULL;
|
|
74 |
TInt ret=KErrNone;
|
|
75 |
|
|
76 |
TInt i;
|
|
77 |
for(i=0;i<count;i++)
|
|
78 |
{
|
|
79 |
item=CfgFile()->Item(KBatteryCharger,i);
|
|
80 |
if(!item)
|
|
81 |
break;
|
|
82 |
|
|
83 |
TInt duration, status, level, error;
|
|
84 |
|
|
85 |
ret=CTestConfig::GetElement(item->Value(),KStdDelimiter,0,duration);
|
|
86 |
if(ret!=KErrNone)
|
|
87 |
{
|
|
88 |
LOGPARSERR("duration",ret,0,&KBatteryCharger);
|
|
89 |
continue;
|
|
90 |
}
|
|
91 |
ret=CTestConfig::GetElement(item->Value(),KStdDelimiter,1,status);
|
|
92 |
if(ret!=KErrNone)
|
|
93 |
{
|
|
94 |
LOGPARSERR("status",ret,1,&KBatteryCharger);
|
|
95 |
continue;
|
|
96 |
}
|
|
97 |
|
|
98 |
ret=CTestConfig::GetElement(item->Value(),KStdDelimiter,2,level);
|
|
99 |
if(ret!=KErrNone)
|
|
100 |
{
|
|
101 |
LOGPARSERR("level",ret,2,&KBatteryCharger);
|
|
102 |
continue;
|
|
103 |
}
|
|
104 |
|
|
105 |
ret=CTestConfig::GetElement(item->Value(),KStdDelimiter,3,error);
|
|
106 |
if(ret!=KErrNone)
|
|
107 |
error = KErrNone;
|
|
108 |
|
|
109 |
TBatteryChargerInfo chargerInfo;
|
|
110 |
chargerInfo.iDuration=duration;
|
|
111 |
chargerInfo.iStatus = RMobilePhone::TMobilePhoneBatteryStatus(status);
|
|
112 |
chargerInfo.iChargeLevel = level;
|
|
113 |
chargerInfo.iError = error;
|
|
114 |
iBatteryChargerInfo->AppendL(chargerInfo);
|
|
115 |
}
|
|
116 |
|
|
117 |
LOGMISC2("Finished parsing Battery Charger config parameters...%d items found",count);
|
|
118 |
|
|
119 |
if(iBatteryChargerInfo->Count()!=0)
|
|
120 |
{
|
|
121 |
iBatteryChargerIndex = 0;
|
|
122 |
iCurrentBatteryCharger = iBatteryChargerInfo->At(0).iChargeLevel;
|
|
123 |
iCurrentStatus = iBatteryChargerInfo->At(0).iStatus;
|
|
124 |
iCurrentErr = iBatteryChargerInfo->At(0).iError;
|
|
125 |
iTimer->Start(iBatteryChargerInfo->At(0).iDuration,this);
|
|
126 |
}
|
|
127 |
}
|
|
128 |
|
|
129 |
|
|
130 |
|
|
131 |
|
|
132 |
CSimBatteryCharger::~CSimBatteryCharger()
|
|
133 |
/**
|
|
134 |
* Standard destructor. Destroy the heap-based object owned by this object.
|
|
135 |
*/
|
|
136 |
{
|
|
137 |
if (iTimer)
|
|
138 |
delete iTimer;
|
|
139 |
|
|
140 |
if (iBatteryChargerInfo)
|
|
141 |
{
|
|
142 |
iBatteryChargerInfo->Delete(0,iBatteryChargerInfo->Count());
|
|
143 |
delete iBatteryChargerInfo;//todo check ptr
|
|
144 |
}
|
|
145 |
}
|
|
146 |
|
|
147 |
|
|
148 |
TInt CSimBatteryCharger::GetBatteryCaps(TTsyReqHandle aReqHandle,TDes8* aCaps)
|
|
149 |
/**
|
|
150 |
* Retrieve Battery Charger capability information. This function completes the
|
|
151 |
* client's request synchronously. If the configuration file contains any
|
|
152 |
* indicator profile information, then it indicates support for indicator
|
|
153 |
* requests, otherwise it does not.
|
|
154 |
*
|
|
155 |
* @param aReqHandle The request handle associated with this request.
|
|
156 |
* @param aPckg1 The first parameter package. This will be populated with the action caps(methods supported)
|
|
157 |
* .
|
|
158 |
* @param aPckg2 the second parameter package. This will be populated with the Indicator caps(wich indicator(s) are supported)
|
|
159 |
* @return TInt Standard error value.
|
|
160 |
*/
|
|
161 |
{
|
|
162 |
TPckg<TUint32>* batteryChargerCapsPckg=(TPckg<TUint32>*)aCaps;
|
|
163 |
TUint32& batteryChargerCaps=(*batteryChargerCapsPckg)();
|
|
164 |
|
|
165 |
if(iBatteryChargerInfo->Count()==0)
|
|
166 |
{
|
|
167 |
batteryChargerCaps=0;
|
|
168 |
}
|
|
169 |
else if((iBatteryChargerInfo->Count()-1) <= iBatteryChargerIndex)
|
|
170 |
batteryChargerCaps= RMobilePhone::KCapsGetBatteryInfo;
|
|
171 |
else
|
|
172 |
{
|
|
173 |
batteryChargerCaps= RMobilePhone::KCapsGetBatteryInfo | RMobilePhone::KCapsNotifyBatteryInfoChange;
|
|
174 |
}
|
|
175 |
iPhone->ReqCompleted(aReqHandle,KErrNone);
|
|
176 |
return KErrNone;
|
|
177 |
}
|
|
178 |
|
|
179 |
|
|
180 |
TInt CSimBatteryCharger::GetBatteryInfo(TTsyReqHandle aReqHandle, TDes8* aInfo)
|
|
181 |
/**
|
|
182 |
* Return the current Battery Charger information. This function completes synchronously.
|
|
183 |
* If the configuration file contains any Battery Charger profile information, the
|
|
184 |
* request completes successfully, otherwise it completes with KErrNotSupported.
|
|
185 |
*
|
|
186 |
* @param aReqHandle The request handle associated with this request.
|
|
187 |
* @param aPckg1 This is populated with the Battery Charger flags.
|
|
188 |
* @return TInt Standard error value.
|
|
189 |
*/
|
|
190 |
{
|
|
191 |
LOGMISC1(">>CSimBatteryCharger::GetBatteryInfo");
|
|
192 |
TPckg<RMobilePhone::TMobilePhoneBatteryInfoV1>* batteryInfoPckg = (TPckg<RMobilePhone::TMobilePhoneBatteryInfoV1>*)aInfo;
|
|
193 |
RMobilePhone::TMobilePhoneBatteryInfoV1& batteryInfo = (*batteryInfoPckg)();
|
|
194 |
|
|
195 |
// Check that the data structure is supported by the simulated TSY version
|
|
196 |
TInt err = iPhone->CheckSimTsyVersion(batteryInfo);
|
|
197 |
if(err != KErrNone)
|
|
198 |
{
|
|
199 |
iPhone->ReqCompleted(aReqHandle, err);
|
|
200 |
return KErrNone;
|
|
201 |
}
|
|
202 |
|
|
203 |
if(iBatteryChargerInfo->Count()==0)
|
|
204 |
{
|
|
205 |
iPhone->ReqCompleted(aReqHandle,KErrNotSupported);
|
|
206 |
return KErrNone;
|
|
207 |
}
|
|
208 |
|
|
209 |
batteryInfo.iChargeLevel=iCurrentBatteryCharger;
|
|
210 |
batteryInfo.iStatus = iCurrentStatus;
|
|
211 |
LOGMISC3("<<CSimBatteryCharger::GetBatteryInfo with level=%d and status=%d",iCurrentBatteryCharger,iCurrentStatus);
|
|
212 |
iPhone->ReqCompleted(aReqHandle,iCurrentErr);
|
|
213 |
return KErrNone;
|
|
214 |
}
|
|
215 |
|
|
216 |
TInt CSimBatteryCharger::NotifyBatteryInfoChange(TTsyReqHandle aReqHandle, TDes8* aInfo)
|
|
217 |
/**
|
|
218 |
* Register a client's interest in being notified when the Battery Charger change.
|
|
219 |
* This function records the request's parameters and awaits a change in
|
|
220 |
* Battery Charger before completing.
|
|
221 |
*
|
|
222 |
* @param aPckg1 The first parameter package. This is populated with the Battery Charger flags.
|
|
223 |
* @return TInt Standard error value.
|
|
224 |
*/
|
|
225 |
{
|
|
226 |
LOGMISC1(">>CSimBatteryCharger::NotifyBatteryInfoChange");
|
|
227 |
TPckg<RMobilePhone::TMobilePhoneBatteryInfoV1>* batteryInfoPckg=(TPckg<RMobilePhone::TMobilePhoneBatteryInfoV1>*)aInfo;
|
|
228 |
RMobilePhone::TMobilePhoneBatteryInfoV1& batteryInfo=(*batteryInfoPckg)();
|
|
229 |
|
|
230 |
// Check that the data structure is supported by the simulated TSY version
|
|
231 |
TInt err = iPhone->CheckSimTsyVersion(batteryInfo);
|
|
232 |
if(err != KErrNone)
|
|
233 |
{
|
|
234 |
iPhone->ReqCompleted(aReqHandle, err);
|
|
235 |
return KErrNone;
|
|
236 |
}
|
|
237 |
|
|
238 |
if(iBatteryChargerInfo->Count()==0)
|
|
239 |
{
|
|
240 |
iPhone->ReqCompleted(aReqHandle,KErrNotSupported);
|
|
241 |
return KErrNone;
|
|
242 |
}
|
|
243 |
|
|
244 |
__ASSERT_ALWAYS(!iBatteryChargerNotificationPending,SimPanic(ENotificationReqAlreadyOutstanding));
|
|
245 |
iBatteryChargerNotificationPending=ETrue;
|
|
246 |
iBatteryChargerNotificationReqHandle=aReqHandle;
|
|
247 |
iBatteryChargerNofificationValue=&batteryInfo;
|
|
248 |
return KErrNone;
|
|
249 |
}
|
|
250 |
|
|
251 |
void CSimBatteryCharger::NotifyBatteryInfoCancel()
|
|
252 |
/**
|
|
253 |
* Cancel a previous request to be notified of a change in Battery Charger.
|
|
254 |
*/
|
|
255 |
{
|
|
256 |
if(iBatteryChargerNotificationPending)
|
|
257 |
{
|
|
258 |
LOGMISC1("CSimBatteryCharger::NotifyBatteryInfoChange has been cancelled");
|
|
259 |
iBatteryChargerNotificationPending=EFalse;
|
|
260 |
iPhone->ReqCompleted(iBatteryChargerNotificationReqHandle,KErrCancel);
|
|
261 |
}
|
|
262 |
else
|
|
263 |
LOGMISC1("CSimBatteryCharger::NotifyBatteryInfoChange was not outstanding and hasn't been cancelled");
|
|
264 |
}
|
|
265 |
|
|
266 |
|
|
267 |
|
|
268 |
void CSimBatteryCharger::TimerCallBack(TInt /*aId*/)
|
|
269 |
/**
|
|
270 |
* The timer callback function. This function will be called when the timer
|
|
271 |
* completes. It indicates a change in Battery Charger. So, the new
|
|
272 |
* Battery Charger settings must be loaded into the member variables representing
|
|
273 |
* the current settings and any pending Battery Charger notification requests must
|
|
274 |
* be completed. Finally, the next timer is started.
|
|
275 |
*
|
|
276 |
* @param aId This parameter is unused. It is only required for CSimXxx classes
|
|
277 |
* that have more than one timer instance and need to identify which
|
|
278 |
* timer has expired.
|
|
279 |
*/
|
|
280 |
{
|
|
281 |
iBatteryChargerIndex++;
|
|
282 |
if(iBatteryChargerInfo->Count()<=iBatteryChargerIndex)
|
|
283 |
return;
|
|
284 |
|
|
285 |
iCurrentBatteryCharger=iBatteryChargerInfo->At(iBatteryChargerIndex).iChargeLevel;
|
|
286 |
iCurrentStatus = iBatteryChargerInfo->At(iBatteryChargerIndex).iStatus;
|
|
287 |
iCurrentErr = iBatteryChargerInfo->At(iBatteryChargerIndex).iError;
|
|
288 |
|
|
289 |
// Ask phone to check if indicator notification needs to be triggered
|
|
290 |
iPhone->CheckIndicatorNotification();
|
|
291 |
|
|
292 |
if(iBatteryChargerNotificationPending)
|
|
293 |
{
|
|
294 |
iBatteryChargerNotificationPending=EFalse;
|
|
295 |
(*iBatteryChargerNofificationValue).iChargeLevel=iCurrentBatteryCharger;
|
|
296 |
(*iBatteryChargerNofificationValue).iStatus=iCurrentStatus;
|
|
297 |
LOGMISC3("<<CSimBatteryCharger::NotifyBatteryInfoChange with level=%d and status=%d",iCurrentBatteryCharger,iCurrentStatus);
|
|
298 |
iPhone->ReqCompleted(iBatteryChargerNotificationReqHandle,iCurrentErr);
|
|
299 |
}
|
|
300 |
iTimer->Start(iBatteryChargerInfo->At(iBatteryChargerIndex).iDuration,this);
|
|
301 |
}
|
|
302 |
|
|
303 |
const CTestConfigSection* CSimBatteryCharger::CfgFile()
|
|
304 |
/**
|
|
305 |
* Returns a pointer to the current configuration file section.
|
|
306 |
*
|
|
307 |
* @return CTestConfigSection A pointer to the current configuration file section.
|
|
308 |
*/
|
|
309 |
{
|
|
310 |
return iPhone->CfgFile();
|
|
311 |
}
|
|
312 |
|