author | Pat Downey <patd@symbian.org> |
Wed, 01 Sep 2010 12:28:47 +0100 | |
branch | RCL_3 |
changeset 45 | a9c0808a1095 |
parent 44 | 0b68a1b0c15e |
permissions | -rw-r--r-- |
5 | 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 |
||
23
50974a8b132e
Revision: 200945
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
5
diff
changeset
|
18 |
#include <liwcommon.h> |
50974a8b132e
Revision: 200945
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
5
diff
changeset
|
19 |
#include<liwservicehandler.h> |
5 | 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 CTestAsync1 : public CActive ,public MLiwNotifyCallback, public MTimeOutCallBack |
|
34 |
{ |
|
35 |
public: |
|
36 |
static CTestAsync1* NewL(CStifLogger* aLog); |
|
37 |
~CTestAsync1(); |
|
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 |
CTestAsync1(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 |
||
69 |
CTestAsync1* CTestAsync1::NewL(CStifLogger* aLog) |
|
70 |
{ |
|
71 |
CTestAsync1* self = new(ELeave) CTestAsync1(aLog); |
|
72 |
self->ConstructL(); |
|
73 |
return self; |
|
74 |
} |
|
75 |
||
76 |
CTestAsync1::~CTestAsync1() |
|
77 |
{ |
|
78 |
Cancel(); |
|
79 |
||
80 |
interface->Close(); |
|
81 |
||
82 |
delete iServiceHandler; |
|
83 |
||
84 |
if(iWaitSchedular->IsStarted()) |
|
85 |
iWaitSchedular->AsyncStop(); |
|
86 |
||
87 |
if(iWaitSchedular) |
|
88 |
delete iWaitSchedular; |
|
89 |
delete iTimer; |
|
90 |
} |
|
91 |
||
92 |
void CTestAsync1::ConstructL() |
|
93 |
{ |
|
94 |
CActiveScheduler::Add(this); |
|
95 |
iWaitSchedular = new(ELeave) CActiveSchedulerWait(); |
|
96 |
iTimer = CWatchTimer::NewL(EPriorityNormal,this); |
|
97 |
} |
|
98 |
||
99 |
CTestAsync1::CTestAsync1(CStifLogger* aLog) : |
|
100 |
CActive(EPriorityStandard),iResult(-1),iLog(aLog) |
|
101 |
{ |
|
102 |
} |
|
103 |
||
104 |
void CTestAsync1::DoCancel() |
|
105 |
{ |
|
106 |
||
107 |
} |
|
108 |
||
109 |
void CTestAsync1::RunL() |
|
110 |
{ |
|
111 |
TestFunc(); |
|
112 |
} |
|
113 |
||
114 |
void CTestAsync1::Start() |
|
115 |
{ |
|
116 |
||
117 |
SetActive(); |
|
118 |
TRequestStatus* temp = &iStatus; |
|
119 |
User::RequestComplete(temp, KErrNone); |
|
120 |
iWaitSchedular->Start(); |
|
121 |
} |
|
122 |
||
123 |
TInt CTestAsync1::Result() |
|
124 |
{ |
|
125 |
return iResult; |
|
126 |
} |
|
127 |
||
128 |
void CTestAsync1::TestFunc() |
|
129 |
{ |
|
130 |
||
131 |
const TTimeIntervalMicroSeconds32 OneMinute(60000); |
|
132 |
||
133 |
iServiceHandler = CLiwServiceHandler::NewL(); |
|
134 |
CLiwGenericParamList* inparam = &(iServiceHandler->InParamListL()); |
|
135 |
CLiwGenericParamList* outparam = &(iServiceHandler->OutParamListL()); |
|
136 |
||
137 |
TInt err = KErrNone; |
|
138 |
||
139 |
CLiwCriteriaItem* crit = CLiwCriteriaItem::NewL(1, KIDataSource,KService); |
|
140 |
crit->SetServiceClass(TUid::Uid(KLiwClassBase)); |
|
141 |
||
142 |
RCriteriaArray a; |
|
143 |
a.AppendL(crit); |
|
144 |
||
145 |
iServiceHandler->AttachL(a); |
|
146 |
||
147 |
iServiceHandler->ExecuteServiceCmdL(*crit, *inparam, *outparam); |
|
148 |
||
149 |
delete crit; |
|
150 |
a.Reset(); |
|
151 |
||
152 |
TInt pos = 0; |
|
153 |
||
154 |
outparam->FindFirst( pos, KIDataSource ); |
|
155 |
if(pos != KErrNotFound) |
|
156 |
{ |
|
157 |
//getting the interface handle |
|
158 |
interface = (*outparam)[pos].Value().AsInterface(); |
|
159 |
} |
|
160 |
||
161 |
outparam->Reset(); |
|
162 |
inparam->Reset(); |
|
163 |
||
164 |
if(interface) |
|
165 |
{ |
|
166 |
TLiwGenericParam entity; |
|
167 |
TLiwVariant entityname; |
|
168 |
TLiwGenericParam key; |
|
169 |
TLiwVariant keyname; |
|
170 |
||
171 |
entityname.Set(KGeneral); |
|
172 |
entity.SetNameAndValueL(KEntity,entityname); |
|
173 |
||
174 |
keyname.Set(KVibraActive); |
|
175 |
key.SetNameAndValueL(KKey,keyname); |
|
176 |
||
177 |
inparam->AppendL(entity); |
|
178 |
||
179 |
inparam->AppendL(key); |
|
180 |
||
181 |
entity.Reset(); |
|
182 |
entityname.Reset(); |
|
183 |
key.Reset(); |
|
184 |
keyname.Reset(); |
|
185 |
||
186 |
iLog->Log(_L("before getnotification vibra Active:")); |
|
187 |
||
188 |
//get notification vibra Active |
|
189 |
TRAPD(err1, interface->ExecuteCmdL(KGetNotification,*inparam,*outparam,NULL,this)); |
|
190 |
iTimer->After(OneMinute); |
|
191 |
||
192 |
iResult = err1; |
|
193 |
if(err1 == KErrNone) |
|
194 |
{ |
|
195 |
pos = 0 ; |
|
196 |
const TLiwGenericParam* output = outparam->FindFirst( pos,KErrorCode ); |
|
197 |
iResult = output->Value().AsTInt32(); |
|
198 |
if(iResult != SErrBadArgumentType) |
|
199 |
{ |
|
200 |
iResult = -1; |
|
201 |
} |
|
202 |
else |
|
203 |
{ |
|
204 |
iResult = 0; |
|
205 |
CLiwGenericParamList* outparam1 = CLiwGenericParamList::NewL(); |
|
206 |
inparam->Reset(); |
|
207 |
||
208 |
entityname.Set(KGeneral); |
|
209 |
entity.SetNameAndValueL(KEntity,entityname); |
|
210 |
||
211 |
keyname.Set(KVibraActive); |
|
212 |
key.SetNameAndValueL(KKey,keyname); |
|
213 |
||
214 |
inparam->AppendL(entity); |
|
215 |
||
216 |
inparam->AppendL(key); |
|
217 |
||
218 |
entity.Reset(); |
|
219 |
entityname.Reset(); |
|
220 |
key.Reset(); |
|
221 |
keyname.Reset(); |
|
222 |
||
223 |
//get current display language |
|
224 |
TRAPD(err2, interface->ExecuteCmdL(KGetInfo,*inparam,*outparam1,KLiwOptASyncronous,this)); |
|
225 |
||
226 |
iResult = err2; |
|
227 |
if(err2 == KErrNone) |
|
228 |
{ |
|
229 |
pos =0 ; |
|
230 |
const TLiwGenericParam* output1 = outparam1->FindFirst( pos,KErrorCode ); |
|
231 |
iResult = output1->Value().AsTInt32(); |
|
232 |
if(iResult != SErrServiceNotSupported) |
|
233 |
{ |
|
234 |
iResult = -1; |
|
235 |
} |
|
236 |
else |
|
237 |
{ |
|
238 |
iResult = 0; |
|
239 |
pos = 0 ; |
|
240 |
const TLiwGenericParam* output1 = outparam1->FindFirst( pos,KReturnValue ); |
|
241 |
if(output1) |
|
242 |
{ |
|
243 |
const CLiwMap* Map = output1->Value().AsMap(); |
|
244 |
if ( Map ) |
|
245 |
{ |
|
246 |
TLiwVariant data; |
|
247 |
if(EFalse!=Map->FindL(KStatus,data)) |
|
248 |
{ |
|
249 |
vibrastatus=data.AsTInt32(); |
|
250 |
} |
|
251 |
}//map |
|
252 |
}//output |
|
253 |
||
254 |
inparam->Reset(); |
|
255 |
outparam1->Reset(); |
|
256 |
outparam->Reset(); |
|
257 |
||
258 |
entityname.Set(KGeneral); |
|
259 |
entity.SetNameAndValueL(KEntity,entityname); |
|
260 |
||
261 |
keyname.Set(KVibraActive); |
|
262 |
key.SetNameAndValueL(KKey,keyname); |
|
263 |
||
264 |
||
265 |
//sysdata as map |
|
266 |
CLiwDefaultMap* map = CLiwDefaultMap::NewL(); |
|
267 |
CleanupStack::PushL(map); |
|
268 |
||
269 |
TLiwVariant sysdata((TInt32)!vibrastatus); |
|
270 |
map->InsertL(KStatus,sysdata); |
|
271 |
sysdata.Reset(); |
|
272 |
||
273 |
||
274 |
TLiwVariant sysparam(map); |
|
275 |
TLiwGenericParam element ; |
|
276 |
element.SetNameAndValueL(KSysData,sysparam); |
|
277 |
||
278 |
||
279 |
inparam->AppendL(entity); |
|
280 |
inparam->AppendL(key); |
|
281 |
||
282 |
inparam->AppendL(element); |
|
283 |
element.Reset(); |
|
284 |
sysparam.Reset(); |
|
285 |
||
286 |
map->DecRef(); |
|
287 |
CleanupStack::Pop(map); |
|
288 |
inparam->AppendL(entity); |
|
289 |
inparam->AppendL(key); |
|
290 |
||
291 |
entity.Reset(); |
|
292 |
entityname.Reset(); |
|
293 |
key.Reset(); |
|
294 |
keyname.Reset(); |
|
295 |
sysdata.Reset(); |
|
296 |
||
297 |
//set new display language |
|
298 |
TRAPD(err3, interface->ExecuteCmdL(KSetInfo,*inparam,*outparam1)); |
|
299 |
||
300 |
inparam->Reset(); |
|
301 |
outparam1->Reset(); |
|
302 |
} |
|
303 |
}//err2 |
|
304 |
} |
|
305 |
}//err1 |
|
306 |
||
307 |
}//interface |
|
308 |
return ; |
|
309 |
} |
|
310 |
||
311 |
||
312 |
TInt CTestAsync1::HandleNotifyL(TInt /*aCmdId*/, |
|
313 |
TInt /*aEventId*/, |
|
314 |
CLiwGenericParamList& aEventParamList, |
|
315 |
const CLiwGenericParamList& /*aInParamList*/) |
|
316 |
{ |
|
317 |
TInt pos = 0; |
|
318 |
aEventParamList.FindFirst( pos, KErrorCode ); |
|
319 |
if(pos != KErrNotFound) |
|
320 |
{ |
|
321 |
iResult = (TInt)((aEventParamList)[pos].Value().AsTInt32()); |
|
322 |
} |
|
323 |
||
324 |
pos = 0 ; |
|
325 |
const TLiwGenericParam* output2 = aEventParamList.FindFirst( pos,KReturnValue ); |
|
326 |
if(output2) |
|
327 |
{ |
|
328 |
const CLiwMap* Map = output2->Value().AsMap(); |
|
329 |
if ( Map ) |
|
330 |
{ |
|
331 |
||
332 |
TLiwVariant data; |
|
333 |
if(EFalse!=Map->FindL(KStatus,data)) |
|
334 |
{ |
|
335 |
TInt32 changedvibrastatus=data.AsTInt32(); |
|
336 |
||
337 |
if(changedvibrastatus == (!vibrastatus)) |
|
338 |
{ |
|
339 |
iResult = KErrNone; |
|
340 |
} |
|
341 |
else |
|
342 |
{ |
|
343 |
iResult = KErrGeneral; |
|
344 |
} |
|
345 |
} |
|
346 |
||
347 |
}//map |
|
348 |
}//output |
|
349 |
iWaitSchedular->AsyncStop(); |
|
350 |
return 0; |
|
351 |
} |
|
352 |
||
353 |
void CTestAsync1::HandleTimeOut() |
|
354 |
{ |
|
355 |
iWaitSchedular->AsyncStop(); |
|
356 |
} |
|
357 |
int VibraNotification(CStifLogger* aLog) |
|
358 |
{ |
|
359 |
__UHEAP_MARK; |
|
360 |
||
361 |
CTestAsync1* test = CTestAsync1::NewL(aLog); |
|
362 |
||
363 |
test->Start(); |
|
364 |
TInt retval = test->Result(); |
|
365 |
delete test; |
|
45 | 366 |
__UHEAP_MARKEND; |
44
0b68a1b0c15e
Revision: 201033
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
38
diff
changeset
|
367 |
return retval; |
5 | 368 |
|
369 |
||
370 |
} |
|
371 |