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 |
child 58 | ea43c23d28d2 |
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 |
#include"tsysinfoprovidertests.h" |
21 |
#include"watchtimer.h" |
|
22 |
||
23 |
#include "sysinfointerface.h" |
|
24 |
#include"entitykeys.h" |
|
25 |
#include "sysinfoaiwparams.hrh" |
|
26 |
#include "serviceerrno.h" |
|
27 |
||
28 |
using namespace LIW ; |
|
29 |
using namespace SysInfo; |
|
30 |
using namespace sysinfoaiwparams; |
|
31 |
||
32 |
||
33 |
class CTestAsync : public CActive ,public MLiwNotifyCallback, public MTimeOutCallBack |
|
34 |
{ |
|
35 |
public: |
|
36 |
static CTestAsync* NewL(CStifLogger* aLog); |
|
37 |
~CTestAsync(); |
|
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 |
||
49 |
private: |
|
50 |
void ConstructL(); |
|
51 |
CTestAsync(CStifLogger* aLog); |
|
52 |
||
53 |
virtual void DoCancel(); |
|
54 |
virtual void RunL(); |
|
55 |
||
56 |
void TestFunc(); |
|
57 |
||
58 |
private: |
|
59 |
CActiveSchedulerWait* iWaitSchedular; |
|
60 |
CLiwServiceHandler* iServiceHandler; |
|
61 |
MLiwInterface* interface ; |
|
62 |
TInt32 vibrastatus ; |
|
63 |
TInt iResult; |
|
64 |
CStifLogger* iLog; |
|
65 |
CWatchTimer* iTimer; |
|
66 |
}; |
|
67 |
||
68 |
CTestAsync* CTestAsync::NewL(CStifLogger* aLog) |
|
69 |
{ |
|
70 |
CTestAsync* self = new(ELeave) CTestAsync(aLog); |
|
71 |
self->ConstructL(); |
|
72 |
return self; |
|
73 |
} |
|
74 |
||
75 |
CTestAsync::~CTestAsync() |
|
76 |
{ |
|
77 |
Cancel(); |
|
78 |
||
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 CTestAsync::ConstructL() |
|
92 |
{ |
|
93 |
CActiveScheduler::Add(this); |
|
94 |
iWaitSchedular = new(ELeave) CActiveSchedulerWait(); |
|
95 |
iTimer = CWatchTimer::NewL(EPriorityNormal,this); |
|
96 |
} |
|
97 |
||
98 |
CTestAsync::CTestAsync(CStifLogger* aLog) : |
|
99 |
CActive(EPriorityStandard),iResult(-1),iLog(aLog) |
|
100 |
{ |
|
101 |
} |
|
102 |
||
103 |
void CTestAsync::DoCancel() |
|
104 |
{ |
|
105 |
||
106 |
} |
|
107 |
||
108 |
void CTestAsync::RunL() |
|
109 |
{ |
|
110 |
TestFunc(); |
|
111 |
} |
|
112 |
||
113 |
void CTestAsync::Start() |
|
114 |
{ |
|
115 |
||
116 |
SetActive(); |
|
117 |
TRequestStatus* temp = &iStatus; |
|
118 |
User::RequestComplete(temp, KErrNone); |
|
119 |
iWaitSchedular->Start(); |
|
120 |
} |
|
121 |
||
122 |
TInt CTestAsync::Result() |
|
123 |
{ |
|
124 |
return iResult; |
|
125 |
} |
|
126 |
||
127 |
void CTestAsync::TestFunc() |
|
128 |
{ |
|
129 |
const TTimeIntervalMicroSeconds32 OneMinute(60000); |
|
130 |
||
131 |
iServiceHandler = CLiwServiceHandler::NewL(); |
|
132 |
CLiwGenericParamList* inparam = &(iServiceHandler->InParamListL()); |
|
133 |
CLiwGenericParamList* outparam = &(iServiceHandler->OutParamListL()); |
|
134 |
||
135 |
TInt err = KErrNone; |
|
136 |
||
137 |
CLiwCriteriaItem* crit = CLiwCriteriaItem::NewL(1, KIDataSource,KService); |
|
138 |
crit->SetServiceClass(TUid::Uid(KLiwClassBase)); |
|
139 |
||
140 |
RCriteriaArray a; |
|
141 |
a.AppendL(crit); |
|
142 |
||
143 |
iServiceHandler->AttachL(a); |
|
144 |
||
145 |
iServiceHandler->ExecuteServiceCmdL(*crit, *inparam, *outparam); |
|
146 |
||
147 |
delete crit; |
|
148 |
a.Reset(); |
|
149 |
||
150 |
TInt pos = 0; |
|
151 |
||
152 |
outparam->FindFirst( pos, KIDataSource ); |
|
153 |
if(pos != KErrNotFound) |
|
154 |
{ |
|
155 |
//getting the interface handle |
|
156 |
interface = (*outparam)[pos].Value().AsInterface(); |
|
157 |
} |
|
158 |
||
159 |
outparam->Reset(); |
|
160 |
inparam->Reset(); |
|
161 |
||
162 |
if(interface) |
|
163 |
{ |
|
164 |
TLiwGenericParam entity; |
|
165 |
TLiwVariant entityname; |
|
166 |
TLiwGenericParam key; |
|
167 |
TLiwVariant keyname; |
|
168 |
||
169 |
entityname.Set(KGeneral); |
|
170 |
entity.SetNameAndValueL(KEntity,entityname); |
|
171 |
||
172 |
keyname.Set(KVibraActive); |
|
173 |
key.SetNameAndValueL(KKey,keyname); |
|
174 |
||
175 |
inparam->AppendL(entity); |
|
176 |
||
177 |
inparam->AppendL(key); |
|
178 |
||
179 |
entity.Reset(); |
|
180 |
entityname.Reset(); |
|
181 |
key.Reset(); |
|
182 |
keyname.Reset(); |
|
183 |
||
184 |
iLog->Log(_L("before getnotification vibra Active:")); |
|
185 |
||
186 |
//get notification vibra Active |
|
187 |
TRAPD(err1, interface->ExecuteCmdL(KGetNotification,*inparam,*outparam,KLiwOptASyncronous,NULL)); |
|
188 |
iTimer->After(OneMinute); |
|
189 |
||
190 |
iResult = err1; |
|
191 |
if(err1 == KErrNone) |
|
192 |
{ |
|
193 |
iLog->Log(_L("after getnotification vibra Active:")); |
|
194 |
pos = 0 ; |
|
195 |
const TLiwGenericParam* output = outparam->FindFirst( pos,KErrorCode ); |
|
196 |
iResult = output->Value().AsTInt32(); |
|
197 |
if(iResult != SErrBadArgumentType) |
|
198 |
{ |
|
199 |
iResult = -1; |
|
200 |
} |
|
201 |
else |
|
202 |
{ |
|
203 |
iLog->Log(_L("after getnotification SErrBadArgumentType:")); |
|
204 |
||
205 |
iResult = 0; |
|
206 |
CLiwGenericParamList* outparam1 = CLiwGenericParamList::NewL(); |
|
207 |
inparam->Reset(); |
|
208 |
||
209 |
entityname.Set(KGeneral); |
|
210 |
entity.SetNameAndValueL(KEntity,entityname); |
|
211 |
||
212 |
keyname.Set(KVibraActive); |
|
213 |
key.SetNameAndValueL(KKey,keyname); |
|
214 |
||
215 |
inparam->AppendL(entity); |
|
216 |
||
217 |
inparam->AppendL(key); |
|
218 |
||
219 |
entity.Reset(); |
|
220 |
entityname.Reset(); |
|
221 |
key.Reset(); |
|
222 |
keyname.Reset(); |
|
223 |
||
224 |
//get current vibra status |
|
225 |
TRAPD(err2, interface->ExecuteCmdL(KGetInfo,*inparam,*outparam1,KLiwOptASyncronous,NULL)); |
|
226 |
||
227 |
iResult = err2; |
|
228 |
if(err2 == KErrNone) |
|
229 |
{ |
|
230 |
iLog->Log(_L("after getinfo :")); |
|
231 |
pos =0 ; |
|
232 |
const TLiwGenericParam* output1 = outparam1->FindFirst( pos,KErrorCode ); |
|
233 |
iResult = output1->Value().AsTInt32(); |
|
234 |
if(iResult != SErrBadArgumentType) |
|
235 |
{ |
|
236 |
iResult = -1; |
|
237 |
} |
|
238 |
else |
|
239 |
{ |
|
240 |
iLog->Log(_L("after getinfo SErrBadArgumentType:")); |
|
241 |
iResult = 0; |
|
242 |
pos = 0 ; |
|
243 |
const TLiwGenericParam* output1 = outparam1->FindFirst( pos,KReturnValue ); |
|
244 |
if(output1) |
|
245 |
{ |
|
246 |
const CLiwMap* Map = output1->Value().AsMap(); |
|
247 |
if ( Map ) |
|
248 |
{ |
|
249 |
TLiwVariant data; |
|
250 |
if(EFalse!=Map->FindL(KStatus,data)) |
|
251 |
{ |
|
252 |
vibrastatus=data.AsTInt32(); |
|
253 |
} |
|
254 |
}//map |
|
255 |
}//output |
|
256 |
||
257 |
inparam->Reset(); |
|
258 |
outparam1->Reset(); |
|
259 |
outparam->Reset(); |
|
260 |
||
261 |
entityname.Set(KGeneral); |
|
262 |
entity.SetNameAndValueL(KEntity,entityname); |
|
263 |
||
264 |
keyname.Set(KVibraActive); |
|
265 |
key.SetNameAndValueL(KKey,keyname); |
|
266 |
||
267 |
||
268 |
//sysdata as map |
|
269 |
CLiwDefaultMap* map = CLiwDefaultMap::NewL(); |
|
270 |
CleanupStack::PushL(map); |
|
271 |
||
272 |
TLiwVariant sysdata((TInt32)!vibrastatus); |
|
273 |
map->InsertL(KStatus,sysdata); |
|
274 |
sysdata.Reset(); |
|
275 |
||
276 |
||
277 |
TLiwVariant sysparam(map); |
|
278 |
TLiwGenericParam element ; |
|
279 |
element.SetNameAndValueL(KSysData,sysparam); |
|
280 |
||
281 |
||
282 |
inparam->AppendL(entity); |
|
283 |
inparam->AppendL(key); |
|
284 |
||
285 |
inparam->AppendL(element); |
|
286 |
element.Reset(); |
|
287 |
sysparam.Reset(); |
|
288 |
||
289 |
map->DecRef(); |
|
290 |
CleanupStack::Pop(map); |
|
291 |
inparam->AppendL(entity); |
|
292 |
inparam->AppendL(key); |
|
293 |
||
294 |
entity.Reset(); |
|
295 |
entityname.Reset(); |
|
296 |
key.Reset(); |
|
297 |
keyname.Reset(); |
|
298 |
sysdata.Reset(); |
|
299 |
||
300 |
iLog->Log(_L("before setinfo Vibra:")); |
|
301 |
//set new display language |
|
302 |
TRAPD(err3, interface->ExecuteCmdL(KSetInfo,*inparam,*outparam1)); |
|
303 |
iLog->Log(_L("after setinfo Vibra:")); |
|
304 |
||
305 |
inparam->Reset(); |
|
306 |
outparam1->Reset(); |
|
307 |
} |
|
308 |
}//err2 |
|
309 |
} |
|
310 |
}//err1 |
|
311 |
||
312 |
}//interface |
|
313 |
return ; |
|
314 |
} |
|
315 |
||
316 |
||
317 |
TInt CTestAsync::HandleNotifyL(TInt /*aCmdId*/, |
|
318 |
TInt /*aEventId*/, |
|
319 |
CLiwGenericParamList& aEventParamList, |
|
320 |
const CLiwGenericParamList& /*aInParamList*/) |
|
321 |
{ |
|
322 |
TInt pos = 0; |
|
323 |
aEventParamList.FindFirst( pos, KErrorCode ); |
|
324 |
if(pos != KErrNotFound) |
|
325 |
{ |
|
326 |
iResult = (TInt)((aEventParamList)[pos].Value().AsTInt32()); |
|
327 |
} |
|
328 |
||
329 |
pos = 0 ; |
|
330 |
const TLiwGenericParam* output2 = aEventParamList.FindFirst( pos,KReturnValue ); |
|
331 |
if(output2) |
|
332 |
{ |
|
333 |
const CLiwMap* Map = output2->Value().AsMap(); |
|
334 |
if ( Map ) |
|
335 |
{ |
|
336 |
||
337 |
TLiwVariant data; |
|
338 |
if(EFalse!=Map->FindL(KStatus,data)) |
|
339 |
{ |
|
340 |
TInt32 changedvibrastatus=data.AsTInt32(); |
|
341 |
||
342 |
if(changedvibrastatus == (!vibrastatus)) |
|
343 |
{ |
|
344 |
iResult = KErrNone; |
|
345 |
} |
|
346 |
else |
|
347 |
{ |
|
348 |
iResult = KErrGeneral; |
|
349 |
} |
|
350 |
} |
|
351 |
||
352 |
}//map |
|
353 |
}//output |
|
354 |
iWaitSchedular->AsyncStop(); |
|
355 |
return 0; |
|
356 |
} |
|
357 |
||
358 |
void CTestAsync::HandleTimeOut() |
|
359 |
{ |
|
360 |
iWaitSchedular->AsyncStop(); |
|
361 |
} |
|
362 |
||
363 |
||
364 |
int VibraNotification1(CStifLogger* aLog) |
|
365 |
{ |
|
366 |
__UHEAP_MARK; |
|
367 |
||
368 |
CTestAsync* test = CTestAsync::NewL(aLog); |
|
369 |
||
370 |
test->Start(); |
|
371 |
TInt retval = test->Result(); |
|
372 |
aLog->Log(_L("after test->Result() Vibra:")); |
|
373 |
||
374 |
delete test; |
|
375 |
return retval; |
|
376 |
__UHEAP_MARKEND; |
|
377 |
||
378 |
||
379 |
} |
|
380 |