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) 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 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: |
|
15 |
* |
|
16 |
*/ |
|
17 |
||
33
50974a8b132e
Revision: 200945
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
18 |
#include <liwcommon.h> |
50974a8b132e
Revision: 200945
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
19 |
#include<liwservicehandler.h> |
19 | 20 |
|
21 |
#include "tsysinfoprovidergeneraltests.h" |
|
22 |
#include "sysinfointerface.h" |
|
23 |
#include"entitykeys.h" |
|
24 |
#include "sysinfoaiwparams.hrh" |
|
25 |
#include "serviceerrno.h" |
|
26 |
#include"watchtimer.h" |
|
27 |
||
28 |
using namespace LIW ; |
|
29 |
using namespace SysInfo; |
|
30 |
using namespace sysinfoaiwparams; |
|
31 |
||
32 |
||
33 |
class CTestAccIter : public CActive ,public MLiwNotifyCallback, public MTimeOutCallBack |
|
34 |
{ |
|
35 |
public: |
|
36 |
static CTestAccIter* NewL(CStifLogger* aLog); |
|
37 |
~CTestAccIter(); |
|
38 |
void Start(); |
|
39 |
TInt Result(); |
|
40 |
||
41 |
TInt HandleNotifyL(TInt aCmdId, |
|
42 |
TInt aEventId, |
|
43 |
CLiwGenericParamList& aEventParamList, |
|
44 |
const CLiwGenericParamList& aInParamList); |
|
45 |
||
46 |
IMPORT_C static TInt32 GetTransactionID(); |
|
47 |
void HandleTimeOut (); |
|
48 |
private: |
|
49 |
void ConstructL(); |
|
50 |
CTestAccIter(CStifLogger* aLog); |
|
51 |
||
52 |
virtual void DoCancel(); |
|
53 |
virtual void RunL(); |
|
54 |
||
55 |
void TestFunc(); |
|
56 |
||
57 |
private: |
|
58 |
CActiveSchedulerWait* iWaitSchedular; |
|
59 |
CLiwServiceHandler* iServiceHandler; |
|
60 |
MLiwInterface* interface ; |
|
61 |
TInt32 btstatus ; |
|
62 |
TInt iResult; |
|
63 |
CStifLogger* iLog; |
|
64 |
CWatchTimer* iTimer; |
|
65 |
}; |
|
66 |
||
67 |
CTestAccIter* CTestAccIter::NewL(CStifLogger* aLog) |
|
68 |
{ |
|
69 |
CTestAccIter* self = new(ELeave) CTestAccIter(aLog); |
|
70 |
self->ConstructL(); |
|
71 |
return self; |
|
72 |
} |
|
73 |
||
74 |
CTestAccIter::~CTestAccIter() |
|
75 |
{ |
|
76 |
Cancel(); |
|
77 |
||
78 |
if(interface) |
|
79 |
interface->Close(); |
|
80 |
||
81 |
delete iServiceHandler; |
|
82 |
||
83 |
if(iWaitSchedular->IsStarted()) |
|
84 |
iWaitSchedular->AsyncStop(); |
|
85 |
||
86 |
if(iWaitSchedular) |
|
87 |
delete iWaitSchedular; |
|
88 |
delete iTimer; |
|
89 |
} |
|
90 |
||
91 |
void CTestAccIter::ConstructL() |
|
92 |
{ |
|
93 |
CActiveScheduler::Add(this); |
|
94 |
iWaitSchedular = new(ELeave) CActiveSchedulerWait(); |
|
95 |
iTimer = CWatchTimer::NewL(EPriorityNormal,this); |
|
96 |
} |
|
97 |
||
98 |
CTestAccIter::CTestAccIter(CStifLogger* aLog) : |
|
99 |
CActive(EPriorityStandard),iResult(-1),iLog(aLog) |
|
100 |
{ |
|
101 |
} |
|
102 |
||
103 |
void CTestAccIter::DoCancel() |
|
104 |
{ |
|
105 |
||
106 |
//TRAPD(err1,iSysInfoService->GetInfoL(req1)); |
|
107 |
||
108 |
} |
|
109 |
||
110 |
void CTestAccIter::RunL() |
|
111 |
{ |
|
112 |
TestFunc(); |
|
113 |
} |
|
114 |
||
115 |
void CTestAccIter::Start() |
|
116 |
{ |
|
117 |
||
118 |
SetActive(); |
|
119 |
TRequestStatus* temp = &iStatus; |
|
120 |
User::RequestComplete(temp, KErrNone); |
|
121 |
iWaitSchedular->Start(); |
|
122 |
} |
|
123 |
||
124 |
TInt CTestAccIter::Result() |
|
125 |
{ |
|
126 |
return iResult; |
|
127 |
} |
|
128 |
||
129 |
void CTestAccIter::TestFunc() |
|
130 |
{ |
|
131 |
// On Emulator this is not supported. |
|
132 |
#if (! (defined(__WINS__) || defined(__WINSCW__)) ) |
|
133 |
||
134 |
iLog->Log(_L("Test Function:")); |
|
135 |
||
136 |
const TTimeIntervalMicroSeconds32 OneMinute(60000000); |
|
137 |
iServiceHandler = CLiwServiceHandler::NewL(); |
|
138 |
CLiwGenericParamList* inparam = &(iServiceHandler->InParamListL()); |
|
139 |
CLiwGenericParamList* outparam = &(iServiceHandler->OutParamListL()); |
|
140 |
||
141 |
TInt err = KErrNone; |
|
142 |
||
143 |
CLiwCriteriaItem* crit = CLiwCriteriaItem::NewL(1, KIDataSource,KService); |
|
144 |
crit->SetServiceClass(TUid::Uid(KLiwClassBase)); |
|
145 |
||
146 |
RCriteriaArray a; |
|
147 |
a.AppendL(crit); |
|
148 |
||
149 |
iServiceHandler->AttachL(a); |
|
150 |
||
151 |
iServiceHandler->ExecuteServiceCmdL(*crit, *inparam, *outparam); |
|
152 |
||
153 |
delete crit; |
|
154 |
a.Reset(); |
|
155 |
||
156 |
TInt pos = 0; |
|
157 |
||
158 |
outparam->FindFirst( pos, KIDataSource ); |
|
159 |
if(pos != KErrNotFound) |
|
160 |
{ |
|
161 |
//getting the interface handle |
|
162 |
interface = (*outparam)[pos].Value().AsInterface(); |
|
163 |
} |
|
164 |
||
165 |
iLog->Log(_L("Interface loaded successfully")); |
|
166 |
||
167 |
outparam->Reset(); |
|
168 |
inparam->Reset(); |
|
169 |
||
170 |
if(interface) |
|
171 |
{ |
|
172 |
TLiwGenericParam entity; |
|
173 |
TLiwVariant entityname; |
|
174 |
TLiwGenericParam key; |
|
175 |
TLiwVariant keyname; |
|
176 |
||
177 |
entityname.Set(KGeneral); |
|
178 |
entity.SetNameAndValueL(KEntity,entityname); |
|
179 |
||
180 |
keyname.Set(KConnectedAccessories); |
|
181 |
key.SetNameAndValueL(KKey,keyname); |
|
182 |
||
183 |
inparam->AppendL(entity); |
|
184 |
||
185 |
inparam->AppendL(key); |
|
186 |
||
187 |
entity.Reset(); |
|
188 |
entityname.Reset(); |
|
189 |
key.Reset(); |
|
190 |
keyname.Reset(); |
|
191 |
iLog->Log( _L("Calling getinfo for accessory list") ); |
|
192 |
TRAPD(err1, interface->ExecuteCmdL(KGetInfo,*inparam,*outparam,KLiwOptASyncronous,this)); |
|
193 |
iTimer->After(OneMinute); |
|
194 |
||
195 |
iResult = err1; |
|
196 |
if(err1 == KErrNone) |
|
197 |
{ |
|
198 |
pos = 0 ; |
|
199 |
outparam->FindFirst( pos, KErrorCode ); |
|
200 |
if(pos != KErrNotFound) |
|
201 |
{ |
|
202 |
iResult = (TInt)((*outparam)[pos].Value().AsTInt32()); |
|
203 |
if(iResult != KErrNone) |
|
204 |
{ |
|
205 |
iLog->Log(_L("Error Code: %d"),iResult); |
|
206 |
iResult = err; |
|
207 |
iWaitSchedular->AsyncStop(); |
|
208 |
} |
|
209 |
} |
|
210 |
else |
|
211 |
{ |
|
212 |
iLog->Log(_L("Error Code not found")); |
|
213 |
} |
|
214 |
iLog->Log(_L("Error Code: %d"),iResult); |
|
215 |
}//err1 |
|
216 |
outparam->Reset(); |
|
217 |
inparam->Reset(); |
|
218 |
}//interface |
|
219 |
else |
|
220 |
{ |
|
221 |
iLog->Log( _L("API returned error") ); |
|
222 |
iResult = err; |
|
223 |
iWaitSchedular->AsyncStop(); |
|
224 |
} |
|
225 |
||
226 |
#else |
|
227 |
iResult = 0; |
|
228 |
iWaitSchedular->AsyncStop(); |
|
229 |
||
230 |
#endif |
|
231 |
return ; |
|
232 |
} |
|
233 |
||
234 |
TInt CTestAccIter::HandleNotifyL(TInt /*aCmdId*/, |
|
235 |
TInt /*aEventId*/, |
|
236 |
CLiwGenericParamList& aEventParamList, |
|
237 |
const CLiwGenericParamList& /*aInParamList*/) |
|
238 |
{ |
|
239 |
iLog->Log(_L("In HandleNotifyL")); |
|
240 |
TInt pos = 0; |
|
241 |
aEventParamList.FindFirst( pos, KErrorCode ); |
|
242 |
if(pos != KErrNotFound) |
|
243 |
{ |
|
244 |
if( (aEventParamList)[pos].Value().AsTInt32() != KErrNone ) |
|
245 |
iResult = (TInt)((aEventParamList)[pos].Value().AsTInt32()); |
|
246 |
TBuf<50> buf; |
|
247 |
buf.AppendNum(iResult); |
|
248 |
iLog->Log(_L("err")); |
|
249 |
iLog->Log(buf); |
|
250 |
||
251 |
} |
|
252 |
||
253 |
pos = 0 ; |
|
254 |
const TLiwGenericParam* output2 = aEventParamList.FindFirst( pos,KReturnValue ); |
|
255 |
if(output2) |
|
256 |
{ |
|
257 |
iLog->Log(_L("inside output2:")); |
|
258 |
||
259 |
const CLiwMap* Map = output2->Value().AsMap(); |
|
260 |
if ( Map ) |
|
261 |
{ |
|
262 |
iLog->Log(_L("inside Map:")); |
|
263 |
TLiwVariant data; |
|
264 |
||
265 |
Map->FindL(KConnectionList,data); |
|
266 |
CLiwIterable* iterlist=data.AsIterable(); |
|
267 |
||
268 |
if(iterlist) |
|
269 |
{ |
|
270 |
iLog->Log(_L("inside iterlist:")); |
|
271 |
TLiwVariant iterdata;int countlist = 0; |
|
272 |
while(iterlist->NextL(iterdata)) |
|
273 |
{ |
|
274 |
iLog->Log(_L("inside iterlist->NextL:")); |
|
275 |
const CLiwMap* Map = iterdata.AsMap(); |
|
276 |
if ( Map ) |
|
277 |
{ |
|
278 |
iLog->Log(_L("inside Map2:")); |
|
279 |
TLiwVariant accessoryTypeVar; |
|
280 |
Map->FindL(KAccessoryType,accessoryTypeVar); |
|
281 |
TInt accessoryType = accessoryTypeVar.AsTInt32(); |
|
282 |
TBuf<50> buf; |
|
283 |
buf.AppendNum(accessoryType); |
|
284 |
iLog->Log(_L("accessoryType")); |
|
285 |
iLog->Log(buf); |
|
286 |
accessoryTypeVar.Reset(); |
|
287 |
||
288 |
||
289 |
TLiwVariant AccessoryStateVar; |
|
290 |
Map->FindL(KAccessoryState,AccessoryStateVar); |
|
291 |
TInt32 AccessoryState = AccessoryStateVar.AsTInt32(); |
|
292 |
buf.Zero(); |
|
293 |
buf.AppendNum(AccessoryState); |
|
294 |
iLog->Log(_L("AccessoryState:")); |
|
295 |
iLog->Log(buf); |
|
296 |
AccessoryStateVar.Reset(); |
|
297 |
||
298 |
} |
|
299 |
||
300 |
countlist++; |
|
301 |
if(countlist < 2) |
|
302 |
iterlist->Reset(); |
|
303 |
||
304 |
iterdata.Reset(); |
|
305 |
} |
|
306 |
} |
|
307 |
iterlist->DecRef(); |
|
308 |
}//map |
|
309 |
aEventParamList.Reset(); |
|
310 |
}//output |
|
311 |
iWaitSchedular->AsyncStop(); |
|
312 |
return KErrNone; |
|
313 |
} |
|
314 |
||
315 |
void CTestAccIter::HandleTimeOut() |
|
316 |
{ |
|
317 |
iLog->Log( _L("Timeout reached..") ); |
|
318 |
iWaitSchedular->AsyncStop(); |
|
319 |
} |
|
320 |
||
321 |
||
322 |
int AccIter(CStifLogger* aLog) |
|
323 |
{ |
|
324 |
__UHEAP_MARK; |
|
325 |
||
326 |
CTestAccIter* test = CTestAccIter::NewL(aLog); |
|
327 |
||
328 |
test->Start(); |
|
329 |
TInt retval = test->Result(); |
|
330 |
delete test; |
|
331 |
__UHEAP_MARKEND; |
|
332 |
||
333 |
return retval; |
|
334 |
} |
|
335 |