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 |
|
21 |
#include "sysinfointerface.h" |
|
22 |
#include"entitykeys.h" |
|
23 |
#include "sysinfoaiwparams.hrh" |
|
24 |
||
25 |
using namespace LIW ; |
|
26 |
using namespace SysInfo; |
|
27 |
using namespace sysinfoaiwparams; |
|
28 |
||
29 |
||
30 |
class CTestAsync1 : public CActive ,public MLiwNotifyCallback |
|
31 |
{ |
|
32 |
public: |
|
33 |
static CTestAsync1* NewL(); |
|
34 |
~CTestAsync1(); |
|
35 |
void Start(); |
|
36 |
TInt Result(); |
|
37 |
||
38 |
TInt HandleNotifyL(TInt aCmdId, |
|
39 |
TInt aEventId, |
|
40 |
CLiwGenericParamList& aEventParamList, |
|
41 |
const CLiwGenericParamList& aInParamList); |
|
42 |
||
43 |
IMPORT_C static TInt32 GetTransactionID(); |
|
44 |
||
45 |
private: |
|
46 |
void ConstructL(); |
|
47 |
CTestAsync1(); |
|
48 |
||
49 |
virtual void DoCancel(); |
|
50 |
virtual void RunL(); |
|
51 |
||
52 |
void TestFunc(); |
|
53 |
||
54 |
private: |
|
55 |
CActiveSchedulerWait* iWaitSchedular; |
|
56 |
CLiwServiceHandler* iServiceHandler; |
|
57 |
MLiwInterface* interface ; |
|
58 |
TInt32 vibrastatus ; |
|
59 |
TInt iResult; |
|
60 |
}; |
|
61 |
||
62 |
CTestAsync1* CTestAsync1::NewL() |
|
63 |
{ |
|
64 |
CTestAsync1* self = new(ELeave) CTestAsync1(); |
|
65 |
self->ConstructL(); |
|
66 |
return self; |
|
67 |
} |
|
68 |
||
69 |
CTestAsync1::~CTestAsync1() |
|
70 |
{ |
|
71 |
Cancel(); |
|
72 |
Cancel(); |
|
73 |
||
74 |
interface->Close(); |
|
75 |
||
76 |
delete iServiceHandler; |
|
77 |
||
78 |
if(iWaitSchedular->IsStarted()) |
|
79 |
iWaitSchedular->AsyncStop(); |
|
80 |
||
81 |
if(iWaitSchedular) |
|
82 |
delete iWaitSchedular; |
|
83 |
} |
|
84 |
||
85 |
void CTestAsync1::ConstructL() |
|
86 |
{ |
|
87 |
CActiveScheduler::Add(this); |
|
88 |
iWaitSchedular = new(ELeave) CActiveSchedulerWait(); |
|
89 |
} |
|
90 |
||
91 |
CTestAsync1::CTestAsync1() : |
|
92 |
CActive(EPriorityStandard),iResult(-1) |
|
93 |
{ |
|
94 |
} |
|
95 |
||
96 |
void CTestAsync1::DoCancel() |
|
97 |
{ |
|
98 |
||
99 |
} |
|
100 |
||
101 |
void CTestAsync1::RunL() |
|
102 |
{ |
|
103 |
TestFunc(); |
|
104 |
} |
|
105 |
||
106 |
void CTestAsync1::Start() |
|
107 |
{ |
|
108 |
||
109 |
SetActive(); |
|
110 |
TRequestStatus* temp = &iStatus; |
|
111 |
User::RequestComplete(temp, KErrNone); |
|
112 |
iWaitSchedular->Start(); |
|
113 |
} |
|
114 |
||
115 |
TInt CTestAsync1::Result() |
|
116 |
{ |
|
117 |
return iResult; |
|
118 |
} |
|
119 |
||
120 |
void CTestAsync1::TestFunc() |
|
121 |
{ |
|
122 |
||
123 |
iServiceHandler = CLiwServiceHandler::NewL(); |
|
124 |
CLiwGenericParamList* inparam = &(iServiceHandler->InParamListL()); |
|
125 |
CLiwGenericParamList* outparam = &(iServiceHandler->OutParamListL()); |
|
126 |
||
127 |
TInt err = KErrNone; |
|
128 |
||
129 |
CLiwCriteriaItem* crit = CLiwCriteriaItem::NewL(1, KIDataSource,KService); |
|
130 |
crit->SetServiceClass(TUid::Uid(KLiwClassBase)); |
|
131 |
||
132 |
RCriteriaArray a; |
|
133 |
a.AppendL(crit); |
|
134 |
||
135 |
iServiceHandler->AttachL(a); |
|
136 |
||
137 |
iServiceHandler->ExecuteServiceCmdL(*crit, *inparam, *outparam); |
|
138 |
||
139 |
delete crit; |
|
140 |
a.Reset(); |
|
141 |
||
142 |
TInt pos = 0; |
|
143 |
||
144 |
outparam->FindFirst( pos, KIDataSource ); |
|
145 |
if(pos != KErrNotFound) |
|
146 |
{ |
|
147 |
//getting the interface handle |
|
148 |
interface = (*outparam)[pos].Value().AsInterface(); |
|
149 |
} |
|
150 |
||
151 |
outparam->Reset(); |
|
152 |
inparam->Reset(); |
|
153 |
||
154 |
if(interface) |
|
155 |
{ |
|
156 |
TLiwGenericParam entity; |
|
157 |
TLiwVariant entityname; |
|
158 |
TLiwGenericParam key; |
|
159 |
TLiwVariant keyname; |
|
160 |
||
161 |
entityname.Set(KGeneral); |
|
162 |
entity.SetNameAndValueL(KEntity,entityname); |
|
163 |
||
164 |
keyname.Set(KVibraActive); |
|
165 |
key.SetNameAndValueL(KKey,keyname); |
|
166 |
||
167 |
inparam->AppendL(entity); |
|
168 |
||
169 |
inparam->AppendL(key); |
|
170 |
||
171 |
entity.Reset(); |
|
172 |
entityname.Reset(); |
|
173 |
key.Reset(); |
|
174 |
keyname.Reset(); |
|
175 |
||
176 |
//get notification vibra Active |
|
177 |
TRAPD(err1, interface->ExecuteCmdL(KGetNotification,*inparam,*outparam,KLiwOptASyncronous,this)); |
|
178 |
iResult = err1; |
|
179 |
if(err1 == KErrNone) |
|
180 |
{ |
|
181 |
CLiwGenericParamList* outparam1 = CLiwGenericParamList::NewL(); |
|
182 |
inparam->Reset(); |
|
183 |
||
184 |
entityname.Set(KGeneral); |
|
185 |
entity.SetNameAndValueL(KEntity,entityname); |
|
186 |
||
187 |
keyname.Set(KVibraActive); |
|
188 |
key.SetNameAndValueL(KKey,keyname); |
|
189 |
||
190 |
inparam->AppendL(entity); |
|
191 |
||
192 |
inparam->AppendL(key); |
|
193 |
||
194 |
entity.Reset(); |
|
195 |
entityname.Reset(); |
|
196 |
key.Reset(); |
|
197 |
keyname.Reset(); |
|
198 |
||
199 |
//get current display language |
|
200 |
TRAPD(err2, interface->ExecuteCmdL(KGetInfo,*inparam,*outparam1)); |
|
201 |
||
202 |
iResult = err2; |
|
203 |
if(err2 == KErrNone) |
|
204 |
{ |
|
205 |
pos = 0 ; |
|
206 |
const TLiwGenericParam* output1 = outparam1->FindFirst( pos,KReturnValue ); |
|
207 |
if(output1) |
|
208 |
{ |
|
209 |
const CLiwMap* Map = output1->Value().AsMap(); |
|
210 |
if ( Map ) |
|
211 |
{ |
|
212 |
TLiwVariant data; |
|
213 |
if(EFalse!=Map->FindL(KStatus,data)) |
|
214 |
{ |
|
215 |
vibrastatus=data.AsTInt32(); |
|
216 |
} |
|
217 |
}//map |
|
218 |
}//output |
|
219 |
||
220 |
inparam->Reset(); |
|
221 |
outparam1->Reset(); |
|
222 |
outparam->Reset(); |
|
223 |
||
224 |
entityname.Set(KGeneral); |
|
225 |
entity.SetNameAndValueL(KEntity,entityname); |
|
226 |
||
227 |
keyname.Set(KVibraActive); |
|
228 |
key.SetNameAndValueL(KKey,keyname); |
|
229 |
||
230 |
||
231 |
//sysdata as map |
|
232 |
CLiwDefaultMap* map = CLiwDefaultMap::NewL(); |
|
233 |
CleanupStack::PushL(map); |
|
234 |
||
235 |
TLiwVariant sysdata((TInt32)!vibrastatus); |
|
236 |
map->InsertL(KStatus,sysdata); |
|
237 |
sysdata.Reset(); |
|
238 |
||
239 |
||
240 |
TLiwVariant sysparam(map); |
|
241 |
TLiwGenericParam element ; |
|
242 |
element.SetNameAndValueL(KSysData,sysparam); |
|
243 |
||
244 |
||
245 |
inparam->AppendL(entity); |
|
246 |
inparam->AppendL(key); |
|
247 |
||
248 |
inparam->AppendL(element); |
|
249 |
element.Reset(); |
|
250 |
sysparam.Reset(); |
|
251 |
||
252 |
map->DecRef(); |
|
253 |
CleanupStack::Pop(map); |
|
254 |
inparam->AppendL(entity); |
|
255 |
inparam->AppendL(key); |
|
256 |
||
257 |
entity.Reset(); |
|
258 |
entityname.Reset(); |
|
259 |
key.Reset(); |
|
260 |
keyname.Reset(); |
|
261 |
sysdata.Reset(); |
|
262 |
||
263 |
//set new display language |
|
264 |
TRAPD(err3, interface->ExecuteCmdL(KSetInfo,*inparam,*outparam1)); |
|
265 |
||
266 |
inparam->Reset(); |
|
267 |
outparam1->Reset(); |
|
268 |
}//err2 |
|
269 |
||
270 |
}//err1 |
|
271 |
||
272 |
}//interface |
|
273 |
return ; |
|
274 |
} |
|
275 |
||
276 |
||
277 |
TInt CTestAsync1::HandleNotifyL(TInt /*aCmdId*/, |
|
278 |
TInt /*aEventId*/, |
|
279 |
CLiwGenericParamList& aEventParamList, |
|
280 |
const CLiwGenericParamList& /*aInParamList*/) |
|
281 |
{ |
|
282 |
TInt pos = 0; |
|
283 |
aEventParamList.FindFirst( pos, KErrorCode ); |
|
284 |
if(pos != KErrNotFound) |
|
285 |
{ |
|
286 |
iResult = (TInt)((aEventParamList)[pos].Value().AsTInt32()); |
|
287 |
} |
|
288 |
||
289 |
pos = 0 ; |
|
290 |
const TLiwGenericParam* output2 = aEventParamList.FindFirst( pos,KReturnValue ); |
|
291 |
if(output2) |
|
292 |
{ |
|
293 |
const CLiwMap* Map = output2->Value().AsMap(); |
|
294 |
if ( Map ) |
|
295 |
{ |
|
296 |
||
297 |
TLiwVariant data; |
|
298 |
if(EFalse!=Map->FindL(KStatus,data)) |
|
299 |
{ |
|
300 |
TInt32 changedvibrastatus=data.AsTInt32(); |
|
301 |
||
302 |
if(changedvibrastatus == (!vibrastatus)) |
|
303 |
{ |
|
304 |
iResult = KErrNone; |
|
305 |
} |
|
306 |
else |
|
307 |
{ |
|
308 |
iResult = KErrGeneral; |
|
309 |
} |
|
310 |
} |
|
311 |
||
312 |
}//map |
|
313 |
}//output |
|
314 |
iWaitSchedular->AsyncStop(); |
|
315 |
return 0; |
|
316 |
} |
|
317 |
||
318 |
||
319 |
int VibraNotification(int, char**) |
|
320 |
{ |
|
321 |
__UHEAP_MARK; |
|
322 |
||
323 |
CTestAsync1* test = CTestAsync1::NewL(); |
|
324 |
||
325 |
test->Start(); |
|
326 |
TInt retval = test->Result(); |
|
327 |
delete test; |
|
45 | 328 |
__UHEAP_MARKEND; |
44
0b68a1b0c15e
Revision: 201033
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
38
diff
changeset
|
329 |
return retval; |
45 | 330 |
|
5 | 331 |
|
332 |
||
333 |
} |
|
334 |