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