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