|
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 * Enable High Accuracy params |
|
19 */ |
|
20 |
|
21 #include <e32svr.h> |
|
22 #include <StifParser.h> |
|
23 #include <Stiftestinterface.h> |
|
24 #include <LbsRequestor.h> |
|
25 #include <LiwServiceHandler.h> |
|
26 #include <LiwCommon.h> |
|
27 |
|
28 |
|
29 #include "tcomplugin.h" |
|
30 TInt cbErr; |
|
31 TInt EnableHighAccL(TInt aCallType,TBool aEnableAcc); |
|
32 |
|
33 class EnableHighAccClass : public MLiwNotifyCallback |
|
34 { |
|
35 |
|
36 MLiwInterface *iLocationInterface ; |
|
37 CLiwGenericParamList *iInputList ; |
|
38 TInt cnt; |
|
39 public : |
|
40 TInt iRetStatus ; |
|
41 |
|
42 TInt HandleNotifyL( |
|
43 TInt aCmdId, |
|
44 TInt aEventId, |
|
45 CLiwGenericParamList& aEventParamList, |
|
46 const CLiwGenericParamList& aInParamList) ; |
|
47 |
|
48 EnableHighAccClass() : iRetStatus(KErrGeneral),cnt(0) //Default constructor |
|
49 { |
|
50 ; |
|
51 } |
|
52 EnableHighAccClass(TInt aCmd , MLiwInterface *aInterface , CLiwGenericParamList *aInputList) ; |
|
53 }; |
|
54 |
|
55 |
|
56 EnableHighAccClass :: EnableHighAccClass(TInt aCmd ,MLiwInterface *aInterface , CLiwGenericParamList *aInputList) |
|
57 { |
|
58 cnt = 0; |
|
59 iLocationInterface = aInterface ; |
|
60 iInputList = aInputList ; |
|
61 |
|
62 } |
|
63 |
|
64 TInt EnableHighAccClass :: HandleNotifyL( |
|
65 TInt aCmdId, |
|
66 TInt aEventId, |
|
67 CLiwGenericParamList& aEventParamList, |
|
68 const CLiwGenericParamList& aInParamList) |
|
69 { |
|
70 |
|
71 //DeRefrence Allocated Map first |
|
72 cnt++; |
|
73 TInt index = 0; |
|
74 const TLiwGenericParam *GenericParam = aEventParamList.FindFirst(index , KErrorCode) ; |
|
75 |
|
76 if(!GenericParam) |
|
77 { |
|
78 cbErr = KErrGeneral ; |
|
79 } |
|
80 |
|
81 if((GenericParam->Value()).AsTInt32() != KErrNone) |
|
82 { |
|
83 cbErr = (GenericParam->Value()).AsTInt32() ; |
|
84 } |
|
85 |
|
86 CActiveScheduler::Stop(); |
|
87 |
|
88 return 0 ; |
|
89 } |
|
90 |
|
91 |
|
92 TInt EnableHighAccL(TInt aCallType,TBool aEnableAcc) |
|
93 { |
|
94 __UHEAP_MARK ; |
|
95 cbErr = KErrNone; |
|
96 RFile LogFile ; |
|
97 RFs LogSession ; |
|
98 TBuf8<50> data ; |
|
99 TRealFormat format ; |
|
100 CActiveScheduler *Scheduler = CActiveScheduler :: Current() ; |
|
101 |
|
102 if(!Scheduler) |
|
103 { |
|
104 Scheduler = new CActiveScheduler ; |
|
105 } |
|
106 |
|
107 |
|
108 CActiveScheduler :: Install(Scheduler) ; |
|
109 |
|
110 |
|
111 |
|
112 |
|
113 |
|
114 _LIT(LogFileNameCancel , "C:\\cancelinvalid.txt") ; |
|
115 /* |
|
116 if(LogFile.Open(LogSession ,LogFileNameCancel , EFileWrite | EFileShareAny ) == KErrNotFound) |
|
117 { |
|
118 if(LogFile.Create(LogSession ,LogFileNameCancel , EFileWrite | EFileShareAny ) != KErrNone) |
|
119 { |
|
120 _LIT(KLog , "Failed to create log file\n") ; |
|
121 |
|
122 return KErrGeneral ; |
|
123 } |
|
124 |
|
125 } |
|
126 */ |
|
127 _LIT(KLog , "In CancelWithInvalidTransactionID\n") ; |
|
128 data.Copy(KLog); |
|
129 // LogFile.Write(data) ; |
|
130 |
|
131 |
|
132 |
|
133 CLiwServiceHandler* ServiceHandler = CLiwServiceHandler::NewL(); |
|
134 |
|
135 // Input and output parameter list |
|
136 CLiwGenericParamList* inputlist = &(ServiceHandler->InParamListL()); |
|
137 CLiwGenericParamList* outputlist = &(ServiceHandler->OutParamListL()); |
|
138 |
|
139 |
|
140 |
|
141 |
|
142 CLiwCriteriaItem* crit = CLiwCriteriaItem::NewL(1, KDataSource , KService); |
|
143 |
|
144 |
|
145 crit->SetServiceClass(TUid::Uid(KLiwClassBase)); |
|
146 |
|
147 RCriteriaArray a; |
|
148 a.AppendL(crit); |
|
149 |
|
150 ServiceHandler->AttachL(a) ; |
|
151 ServiceHandler->ExecuteServiceCmdL(*crit, *inputlist, *outputlist); |
|
152 |
|
153 |
|
154 |
|
155 |
|
156 TInt pos = 0; |
|
157 |
|
158 const TLiwGenericParam *errorprm = outputlist->FindFirst(pos , KErrorCode) ; |
|
159 |
|
160 if(!errorprm) |
|
161 { |
|
162 |
|
163 return KErrGeneral ; |
|
164 } |
|
165 |
|
166 |
|
167 _LIT8(KDataSource, "ILocation"); |
|
168 |
|
169 pos = 0 ; |
|
170 |
|
171 const TLiwGenericParam *genericparm = outputlist->FindFirst(pos,KLocationInterface); |
|
172 |
|
173 if(!genericparm) |
|
174 { |
|
175 |
|
176 return KErrGeneral ; |
|
177 } |
|
178 |
|
179 MLiwInterface* locinterface = (genericparm->Value()).AsInterface(); |
|
180 |
|
181 outputlist->Reset() ; |
|
182 inputlist->Reset() ; |
|
183 EnableHighAccClass* callBack = new(ELeave) EnableHighAccClass; |
|
184 |
|
185 TBuf8<20>CmdBuf(KTraceLocation) ; |
|
186 |
|
187 if(aCallType == 1) |
|
188 { |
|
189 TBuf8<20>CmdBuf1(KCmdGetLocation); |
|
190 CmdBuf = CmdBuf1; |
|
191 } |
|
192 |
|
193 |
|
194 |
|
195 |
|
196 //Appending update options |
|
197 /* CLiwMap* updateoptionMap = CLiwDefaultMap::NewL(); |
|
198 |
|
199 TInt32 updateInterval = 2; |
|
200 |
|
201 updateoptionMap->InsertL(KUpdateOptionInterval,TLiwVariant(updateInterval)); |
|
202 |
|
203 TInt32 updateTimeOut = 3; |
|
204 updateoptionMap->InsertL(KUpdateOptionTimeOut,TLiwVariant(updateTimeOut)); |
|
205 |
|
206 TInt32 updateMaxAge = 1; |
|
207 updateoptionMap->InsertL(KUpdateOptionMaxAge,TLiwVariant(updateMaxAge)); |
|
208 |
|
209 TLiwGenericParam updateOption(KUpdateOptionMap,TLiwVariant(updateoptionMap)); |
|
210 inputlist->AppendL(updateOption) ; |
|
211 */ |
|
212 _LIT8(KEnableHighAccuracy,"EnableHighAccuracy"); |
|
213 |
|
214 TLiwGenericParam EnableHighAcc(KEnableHighAccuracy,TLiwVariant(aEnableAcc)); |
|
215 |
|
216 inputlist->AppendL(EnableHighAcc); |
|
217 |
|
218 |
|
219 locinterface->ExecuteCmdL(CmdBuf , *inputlist , *outputlist,KLiwOptASyncronous, callBack); |
|
220 |
|
221 pos = 0 ; |
|
222 |
|
223 const TLiwGenericParam *ErrorParm = outputlist->FindFirst(pos ,KErrorCode ) ; |
|
224 |
|
225 if(!ErrorParm) |
|
226 { |
|
227 return KErrGeneral ; |
|
228 } |
|
229 |
|
230 TInt reqerror = (ErrorParm->Value()).AsTInt32(); |
|
231 |
|
232 if(reqerror == KErrNone ) |
|
233 CActiveScheduler::Start(); |
|
234 |
|
235 |
|
236 |
|
237 //const TLiwGenericParam *ErrorParm = outputlist->FindFirst(pos ,KErrorCode ) ; |
|
238 //delete updateoptionMap; |
|
239 delete callBack; |
|
240 locinterface->Close() ; |
|
241 delete ServiceHandler ; |
|
242 a.ResetAndDestroy() ; |
|
243 a.Close() ; |
|
244 delete Scheduler; |
|
245 |
|
246 |
|
247 __UHEAP_MARKEND ; |
|
248 return reqerror | cbErr ; |
|
249 |
|
250 |
|
251 |
|
252 } |
|
253 |
|
254 |
|
255 TInt EnableHighAcc(TAny *aFlag) |
|
256 { |
|
257 |
|
258 CTrapCleanup* cleanup = CTrapCleanup::New(); |
|
259 TInt Val = KErrGeneral; |
|
260 TInt *flag = static_cast<TInt *>(aFlag); |
|
261 TInt err = 0; |
|
262 //Install a new active scheduler to this thread |
|
263 |
|
264 if(*flag == 1) |
|
265 { |
|
266 //GetLocation, EnablehighAcc is true |
|
267 TRAP(err ,( Val = EnableHighAccL(1,true)) ); |
|
268 } |
|
269 |
|
270 else if(*flag == 2) |
|
271 { |
|
272 //GetLocation, EnablehighAcc is false |
|
273 TRAP(err ,( Val = EnableHighAccL(1,false)) ); |
|
274 } |
|
275 |
|
276 else if(*flag == 3) |
|
277 { |
|
278 //Trace, EnablehighAcc is true |
|
279 TRAP(err ,( Val = EnableHighAccL(2,true)) ); |
|
280 } |
|
281 |
|
282 else if(*flag == 4) |
|
283 { |
|
284 //Trace, EnablehighAcc is false |
|
285 TRAP(err ,( Val = EnableHighAccL(2,false)) ); |
|
286 } |
|
287 |
|
288 delete cleanup ; |
|
289 |
|
290 |
|
291 return Val | err; |
|
292 } |
|
293 |
|
294 |
|
295 |
|
296 TInt EnableHighAcc_PosBased(TAny *aFlag) |
|
297 { |
|
298 |
|
299 CTrapCleanup* cleanup = CTrapCleanup::New(); |
|
300 TInt Val ; |
|
301 TInt *flag = static_cast<TInt *>(aFlag); |
|
302 TInt err; |
|
303 //Install a new active scheduler to this thread |
|
304 |
|
305 if(*flag == 1) |
|
306 { |
|
307 //GetLocation, Correct value for EnableAcc PosBased |
|
308 TRAP(err ,( Val = EnableHighAcc_PosBasedL(1,true)) ); |
|
309 } |
|
310 |
|
311 else if(*flag == 2) |
|
312 { |
|
313 //GetLocation, Wrong Type for enableAcc |
|
314 TRAP(err ,( Val = EnableHighAcc_PosBasedL(1,false)) ); |
|
315 } |
|
316 |
|
317 else if(*flag == 3) |
|
318 { |
|
319 //Trace , Correct type |
|
320 TRAP(err ,( Val = EnableHighAcc_PosBasedL(2,true)) ); |
|
321 } |
|
322 |
|
323 else if(*flag == 4) |
|
324 { |
|
325 //Trace, Wrong type |
|
326 TRAP(err ,( Val = EnableHighAcc_PosBasedL(2,false)) ); |
|
327 } |
|
328 |
|
329 delete cleanup ; |
|
330 |
|
331 return Val | err; |
|
332 } |
|
333 |
|
334 |
|
335 TInt EnableHighAcc_PosBasedL(TInt aCallType,TBool aEnableAcc) |
|
336 { |
|
337 __UHEAP_MARK ; |
|
338 RFile LogFile ; |
|
339 RFs LogSession ; |
|
340 TBuf8<50> data ; |
|
341 TRealFormat format ; |
|
342 cbErr = KErrNone; |
|
343 CActiveScheduler *Scheduler = CActiveScheduler :: Current() ; |
|
344 |
|
345 if(!Scheduler) |
|
346 { |
|
347 Scheduler = new CActiveScheduler ; |
|
348 } |
|
349 |
|
350 |
|
351 CActiveScheduler :: Install(Scheduler) ; |
|
352 |
|
353 |
|
354 |
|
355 |
|
356 |
|
357 _LIT(LogFileNameCancel , "C:\\cancelinvalid.txt") ; |
|
358 |
|
359 _LIT(KLog , "In CancelWithInvalidTransactionID\n") ; |
|
360 data.Copy(KLog); |
|
361 // LogFile.Write(data) ; |
|
362 |
|
363 |
|
364 |
|
365 CLiwServiceHandler* ServiceHandler = CLiwServiceHandler::NewL(); |
|
366 |
|
367 // Input and output parameter list |
|
368 CLiwGenericParamList* inputlist = CLiwGenericParamList::NewL(); |
|
369 CLiwGenericParamList* outputlist = CLiwGenericParamList::NewL(); |
|
370 |
|
371 |
|
372 |
|
373 |
|
374 CLiwCriteriaItem* crit = CLiwCriteriaItem::NewL(1, KDataSource , KService); |
|
375 |
|
376 |
|
377 crit->SetServiceClass(TUid::Uid(KLiwClassBase)); |
|
378 |
|
379 RCriteriaArray a; |
|
380 a.AppendL(crit); |
|
381 |
|
382 ServiceHandler->AttachL(a) ; |
|
383 ServiceHandler->ExecuteServiceCmdL(*crit, *inputlist, *outputlist); |
|
384 |
|
385 |
|
386 |
|
387 |
|
388 TInt pos = 0; |
|
389 |
|
390 const TLiwGenericParam *errorprm = outputlist->FindFirst(pos , KErrorCode) ; |
|
391 |
|
392 if(!errorprm) |
|
393 { |
|
394 |
|
395 return KErrGeneral ; |
|
396 } |
|
397 |
|
398 |
|
399 _LIT8(KDataSource, "ILocation"); |
|
400 |
|
401 pos = 0 ; |
|
402 |
|
403 const TLiwGenericParam *genericparm = outputlist->FindFirst(pos,KLocationInterface); |
|
404 |
|
405 if(!genericparm) |
|
406 { |
|
407 |
|
408 return KErrGeneral ; |
|
409 } |
|
410 |
|
411 MLiwInterface* locinterface = (genericparm->Value()).AsInterface(); |
|
412 |
|
413 outputlist->Reset() ; |
|
414 inputlist->Reset() ; |
|
415 EnableHighAccClass* callBack = new(ELeave) EnableHighAccClass; |
|
416 |
|
417 TBuf8<20>CmdBuf(KTraceLocation) ; |
|
418 |
|
419 if(aCallType == 1) |
|
420 { |
|
421 TBuf8<20>CmdBuf1(KCmdGetLocation); |
|
422 CmdBuf = CmdBuf1; |
|
423 } |
|
424 |
|
425 |
|
426 |
|
427 |
|
428 _LIT(KClass,"GenericLocationInfo"); |
|
429 inputlist->AppendL( TLiwGenericParam( KNullDesC8,TLiwVariant( KClass ) ) ); |
|
430 CLiwMap* updatemap = CLiwDefaultMap::NewL(); |
|
431 updatemap->PushL(); |
|
432 _LIT8(KInterval,"UpdateInterval"); |
|
433 _LIT8(KTimeout,"UpdateTimeOut"); |
|
434 _LIT8(KAge,"UpdateMaxAge"); |
|
435 _LIT8(KPartial,"PartialUpdates"); |
|
436 const TInt KTime = 1000000; |
|
437 |
|
438 updatemap->InsertL(KInterval , TLiwVariant(TInt32(2*KTime))); |
|
439 updatemap->InsertL(KTimeout , TLiwVariant(TInt32(30*KTime))); |
|
440 updatemap->InsertL(KAge , TLiwVariant(TInt32(0))); |
|
441 updatemap->InsertL(KPartial , TLiwVariant(TBool(FALSE))); |
|
442 |
|
443 inputlist->AppendL(TLiwGenericParam(KNullDesC8,TLiwVariant(updatemap))); |
|
444 updatemap->DecRef(); |
|
445 |
|
446 if(aEnableAcc){ |
|
447 TLiwGenericParam EnableHighAcc(KNullDesC8,TLiwVariant(aEnableAcc)); |
|
448 inputlist->AppendL(EnableHighAcc); |
|
449 } |
|
450 else |
|
451 { |
|
452 TPtrC aEnableAcc1(_L("hi")); |
|
453 TLiwGenericParam EnableHighAcc(KNullDesC8,TLiwVariant(aEnableAcc1)); |
|
454 inputlist->AppendL(EnableHighAcc); |
|
455 } |
|
456 |
|
457 |
|
458 |
|
459 |
|
460 locinterface->ExecuteCmdL(CmdBuf , *inputlist , *outputlist,KLiwOptASyncronous, callBack); |
|
461 |
|
462 pos = 0 ; |
|
463 |
|
464 const TLiwGenericParam *ErrorParm = outputlist->FindFirst(pos ,KErrorCode ) ; |
|
465 |
|
466 if(!ErrorParm) |
|
467 { |
|
468 return KErrGeneral ; |
|
469 } |
|
470 |
|
471 TInt reqerror = (ErrorParm->Value()).AsTInt32(); |
|
472 |
|
473 if(reqerror == KErrNone) |
|
474 CActiveScheduler::Start(); |
|
475 |
|
476 if(reqerror == SErrBadArgumentType && !aEnableAcc) |
|
477 reqerror = KErrNone; |
|
478 |
|
479 pos = 0 ; |
|
480 CleanupStack::PopAndDestroy(updatemap); |
|
481 inputlist->Reset(); |
|
482 outputlist->Reset(); |
|
483 delete outputlist; |
|
484 |
|
485 delete inputlist; |
|
486 |
|
487 delete callBack; |
|
488 locinterface->Close() ; |
|
489 |
|
490 a.ResetAndDestroy() ; |
|
491 a.Close() ; |
|
492 delete Scheduler; |
|
493 delete ServiceHandler ; |
|
494 __UHEAP_MARKEND ; |
|
495 |
|
496 return reqerror | cbErr; |
|
497 |
|
498 |
|
499 |
|
500 } |
|
501 |
|
502 |