|
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 <e32svr.h> |
|
19 #include <StifParser.h> |
|
20 #include <Stiftestinterface.h> |
|
21 #include <LbsRequestor.h> |
|
22 #include <LiwServiceHandler.h> |
|
23 #include <LiwCommon.h> |
|
24 #include "tcomplugin.h" |
|
25 |
|
26 using namespace LIW; |
|
27 |
|
28 _LIT(LogFileName , "C:\\Notifications.txt") ; |
|
29 |
|
30 class ASyncLocCB : public MLiwNotifyCallback |
|
31 { |
|
32 |
|
33 public : |
|
34 TInt iRetStatus ; |
|
35 |
|
36 TInt HandleNotifyL( |
|
37 TInt aCmdId, |
|
38 TInt aEventId, |
|
39 CLiwGenericParamList& aEventParamList, |
|
40 const CLiwGenericParamList& aInParamList) ; |
|
41 |
|
42 ASyncLocCB() : iRetStatus(KErrGeneral) //Default constructor |
|
43 { |
|
44 ; |
|
45 } |
|
46 |
|
47 }; |
|
48 |
|
49 |
|
50 |
|
51 TInt ASyncLocCB :: HandleNotifyL( |
|
52 TInt aCmdId, |
|
53 TInt aEventId, |
|
54 CLiwGenericParamList& aEventParamList, |
|
55 const CLiwGenericParamList& aInParamList) |
|
56 |
|
57 { |
|
58 TBuf8<50> data ; |
|
59 TRealFormat format ; |
|
60 |
|
61 |
|
62 RFile LogFile ; |
|
63 RFs LogSession ; |
|
64 TBuf8<50> Buffer(_L8("Latitude = ")) ; |
|
65 |
|
66 |
|
67 |
|
68 LogSession.Connect() ; |
|
69 |
|
70 if(LogFile.Open(LogSession ,LogFileName , EFileWrite | EFileShareAny ) == KErrNotFound) |
|
71 { |
|
72 LogFile.Create(LogSession ,LogFileName , EFileWrite | EFileShareAny ) ; |
|
73 |
|
74 } |
|
75 |
|
76 |
|
77 TInt End = 0 ; |
|
78 TInt index = 0 ; |
|
79 const TLiwGenericParam *GenericParam = aEventParamList.FindFirst(index , KErrorCode) ; |
|
80 |
|
81 if(!GenericParam) |
|
82 { |
|
83 return KErrGeneral ; |
|
84 } |
|
85 |
|
86 if((GenericParam->Value()).AsTInt32() != KErrNone) |
|
87 { |
|
88 return (GenericParam->Value()).AsTInt32() ; |
|
89 } |
|
90 |
|
91 index = 0 ; |
|
92 |
|
93 LogFile.Seek(ESeekEnd , End) ; //Seek to end of the file before writing |
|
94 const TLiwGenericParam *MapParam = aEventParamList.FindFirst(index ,KLocationMap) ; |
|
95 |
|
96 if(!MapParam) |
|
97 { |
|
98 return KErrGeneral ; |
|
99 } |
|
100 |
|
101 TLiwVariant Variant ; |
|
102 |
|
103 Variant = MapParam->Value() ; |
|
104 const CLiwMap *LocMap = Variant.AsMap() ; |
|
105 |
|
106 TLiwVariant PosVariant ; |
|
107 |
|
108 LocMap->FindL(KLongitudeKey , PosVariant) ; |
|
109 |
|
110 |
|
111 TReal64 LongData = (TReal64)PosVariant.AsTReal() ; //Longitude |
|
112 data.Num(LongData , format) ; |
|
113 LogFile.Write(_L8("\n")) ; |
|
114 LogFile.Write(_L8("Logitude = ")) ; |
|
115 LogFile.Write(data) ; |
|
116 |
|
117 LocMap->FindL(KLatitudeKey ,PosVariant) ; //Latitude |
|
118 |
|
119 TReal64 LatData = (TReal64)PosVariant.AsTReal() ; |
|
120 data.Num(LatData , format) ; |
|
121 LogFile.Write(_L8(" Latitude = ")) ; |
|
122 LogFile.Write(data) ; |
|
123 |
|
124 LocMap->FindL(KAltitudeKey , PosVariant) ; //Altitude |
|
125 TReal32 AltData = PosVariant.AsTReal() ; |
|
126 data.Num(AltData , format) ; |
|
127 |
|
128 LogFile.Write(_L8(" Altitude = ")) ; |
|
129 LogFile.Write(data) ; |
|
130 // LocMap->DecRef() ; |
|
131 |
|
132 const TLiwGenericParam *Speed = aEventParamList.FindFirst(index , _L8("HorizontalSpeed")) ; |
|
133 |
|
134 if(index != -1) |
|
135 { |
|
136 Variant = Speed->Value() ; |
|
137 TReal speed = Variant.AsTReal() ; |
|
138 |
|
139 data.Num(speed , format) ; |
|
140 |
|
141 LogFile.Write(_L8("Speed = ")) ; |
|
142 LogFile.Write(data) ; |
|
143 |
|
144 } |
|
145 |
|
146 const TLiwGenericParam *SpeedError = aEventParamList.FindFirst(index , _L8("HorizontalSpeedError")) ; |
|
147 |
|
148 |
|
149 if(index != -1) |
|
150 { |
|
151 Variant = SpeedError->Value() ; |
|
152 TReal speed = Variant.AsTReal() ; |
|
153 |
|
154 data.Num(speed , format) ; |
|
155 |
|
156 LogFile.Write(_L8("Speed = ")) ; |
|
157 LogFile.Write(data) ; |
|
158 |
|
159 } |
|
160 |
|
161 index = 0 ; |
|
162 |
|
163 const TLiwGenericParam *SatInfo = aEventParamList.FindFirst(index , _L8("SatelliteNumView")) ; |
|
164 |
|
165 if(index != -1 ) |
|
166 { |
|
167 Variant = SatInfo->Value() ; |
|
168 |
|
169 TInt satnumView = Variant.AsTInt32() ; |
|
170 data.Num(satnumView , format); |
|
171 |
|
172 LogFile.Write(_L8("Satellite information")) ; |
|
173 |
|
174 LogFile.Write(_L8("Number of visible satellites ")) ; |
|
175 LogFile.Write(data) ; |
|
176 } |
|
177 |
|
178 index = 0 ; |
|
179 |
|
180 const TLiwGenericParam *SatInfoview = aEventParamList.FindFirst(index , _L8("SatelliteNumViewUsed")) ; |
|
181 |
|
182 if(index != -1 ) |
|
183 { |
|
184 Variant = SatInfoview->Value() ; |
|
185 |
|
186 TInt satnumViewUsed = Variant.AsTInt32() ; |
|
187 data.Num(satnumViewUsed , format); |
|
188 |
|
189 LogFile.Write(_L8("\nSatellite information")) ; |
|
190 |
|
191 LogFile.Write(_L8("\nSatelliteNumViewUsed")) ; |
|
192 LogFile.Write(data) ; |
|
193 } |
|
194 |
|
195 index = 0 ; |
|
196 |
|
197 const TLiwGenericParam *Heading = aEventParamList.FindFirst(index ,_L8("Heading") ) ; |
|
198 |
|
199 if(-1 != index) |
|
200 { |
|
201 Variant = Heading->Value() ; |
|
202 |
|
203 TReal heading = Variant.AsTReal() ; |
|
204 data.Num(heading , format); |
|
205 |
|
206 LogFile.Write(_L8("\ncompass information")) ; |
|
207 |
|
208 LogFile.Write(_L8("\nHeading")) ; |
|
209 LogFile.Write(data) ; |
|
210 } |
|
211 |
|
212 index = 0 ; |
|
213 |
|
214 if(Heading) |
|
215 { |
|
216 const TLiwGenericParam *HeadingError = aEventParamList.FindFirst(index , _L8("HeadingError") ) ; |
|
217 |
|
218 if(-1 != index) |
|
219 { |
|
220 Variant = HeadingError->Value() ; |
|
221 |
|
222 TReal heading = Variant.AsTReal() ; |
|
223 data.Num(heading , format); |
|
224 |
|
225 LogFile.Write(_L8("\ncompass information")) ; |
|
226 |
|
227 LogFile.Write(_L8("\nHeading Error")) ; |
|
228 LogFile.Write(data) ; |
|
229 |
|
230 } |
|
231 index = 0 ; |
|
232 const TLiwGenericParam *MagneticHeading = aEventParamList.FindFirst(index , _L8("MagneticHeading") ) ; |
|
233 |
|
234 if(-1 != index) |
|
235 { |
|
236 Variant = MagneticHeading->Value() ; |
|
237 |
|
238 TReal heading = Variant.AsTReal() ; |
|
239 data.Num(heading , format); |
|
240 |
|
241 LogFile.Write(_L8("\ncompass information")) ; |
|
242 |
|
243 LogFile.Write(_L8("\n MagneticHeading ")) ; |
|
244 LogFile.Write(data) ; |
|
245 |
|
246 } |
|
247 |
|
248 index = 0 ; |
|
249 const TLiwGenericParam *MagneticHeadingError = aEventParamList.FindFirst(index , _L8("MagneticHeadingError") ) ; |
|
250 |
|
251 if(-1 != index) |
|
252 { |
|
253 Variant = MagneticHeadingError->Value() ; |
|
254 |
|
255 TReal heading = Variant.AsTReal() ; |
|
256 data.Num(heading , format); |
|
257 |
|
258 LogFile.Write(_L8("\ncompass information")) ; |
|
259 |
|
260 LogFile.Write(_L8("\nMagneticHeading Error")) ; |
|
261 LogFile.Write(data) ; |
|
262 |
|
263 } |
|
264 |
|
265 |
|
266 } //End of Heading |
|
267 |
|
268 index = 0 ; |
|
269 |
|
270 const TLiwGenericParam *TrueCourse = aEventParamList.FindFirst(index , _L8("TrueCourse") ) ; |
|
271 |
|
272 if(-1 != index) |
|
273 { |
|
274 |
|
275 Variant = TrueCourse->Value() ; |
|
276 |
|
277 TReal heading = Variant.AsTReal() ; |
|
278 data.Num(heading , format); |
|
279 |
|
280 LogFile.Write(_L8("\nDirection ")) ; |
|
281 |
|
282 LogFile.Write(_L8("\n TrueCourse Error")) ; |
|
283 LogFile.Write(data) ; |
|
284 |
|
285 index = 0 ; |
|
286 |
|
287 const TLiwGenericParam *TrueCourseError = aEventParamList.FindFirst(index , _L8("TrueCourseError") ) ; |
|
288 |
|
289 if(-1 != index) |
|
290 { |
|
291 Variant = TrueCourseError->Value() ; |
|
292 |
|
293 TReal heading = Variant.AsTReal() ; |
|
294 data.Num(heading , format); |
|
295 |
|
296 LogFile.Write(_L8("\ncompass information")) ; |
|
297 |
|
298 LogFile.Write(_L8("\nMagneticHeading Error")) ; |
|
299 LogFile.Write(data) ; |
|
300 |
|
301 } |
|
302 |
|
303 |
|
304 } |
|
305 |
|
306 index = 0 ; |
|
307 const TLiwGenericParam *MagneticCourse = aEventParamList.FindFirst(index , _L8("MagneticCourse") ) ; |
|
308 |
|
309 |
|
310 if(-1 != index) |
|
311 { |
|
312 Variant = MagneticCourse->Value() ; |
|
313 |
|
314 TReal heading = Variant.AsTReal() ; |
|
315 data.Num(heading , format); |
|
316 |
|
317 LogFile.Write(_L8("\ncompass information")) ; |
|
318 |
|
319 LogFile.Write(_L8("\nMagneticCourse ")) ; |
|
320 LogFile.Write(data) ; |
|
321 |
|
322 index = 0 ; |
|
323 |
|
324 const TLiwGenericParam *MagneticCourseError = aEventParamList.FindFirst(index , _L8("MagneticCourseError") ) ; |
|
325 |
|
326 if(-1 != index) |
|
327 { |
|
328 Variant = MagneticCourseError->Value() ; |
|
329 |
|
330 TReal heading = Variant.AsTReal() ; |
|
331 data.Num(heading , format); |
|
332 |
|
333 LogFile.Write(_L8("\ncompass information")) ; |
|
334 |
|
335 LogFile.Write(_L8("\n MagneticCourseError Error")) ; |
|
336 LogFile.Write(data) ; |
|
337 |
|
338 } |
|
339 |
|
340 |
|
341 } |
|
342 |
|
343 |
|
344 /*index = 0 ; |
|
345 const TLiwGenericParam *NmeaNum = aEventParamList.FindFirst(index , _L8("NMEASentence") ) ; |
|
346 |
|
347 |
|
348 if(-1 != index) |
|
349 { |
|
350 Variant = NmeaNum->Value() ; |
|
351 |
|
352 TInt32 NMEASentence = Variant.AsTInt32() ; |
|
353 data.Num(NMEASentence , format); |
|
354 |
|
355 LogFile.Write(_L8("\nNMEA Information")) ; |
|
356 |
|
357 LogFile.Write(_L8("\n number of NMEA Sentences ")) ; |
|
358 LogFile.Write(data) ; |
|
359 |
|
360 index = 0 ; |
|
361 |
|
362 const TLiwGenericParam *MagneticCourseError = aEventParamList.FindFirst(index , _L8("NMEASentenceStart") ) ; |
|
363 |
|
364 if(-1 != index) |
|
365 { |
|
366 Variant = MagneticCourseError->Value() ; |
|
367 |
|
368 // TDes8 heading = Variant.AsDes() ; |
|
369 |
|
370 // LogFile.Write(_L8("\nNMEA information")) ; |
|
371 |
|
372 // LogFile.Write(_L8("\n NMEA Sentences")) ; |
|
373 // LogFile.Write(data) ; |
|
374 |
|
375 } |
|
376 }*/ |
|
377 |
|
378 |
|
379 |
|
380 LogFile.Close() ; |
|
381 LogSession.Close() ; |
|
382 iRetStatus = KErrNone ; |
|
383 CActiveScheduler *Current = CActiveScheduler :: Current() ; |
|
384 Current->Stop() ; |
|
385 |
|
386 |
|
387 return KErrNone ; |
|
388 } |
|
389 |
|
390 |
|
391 |
|
392 TInt GetLocAsynchFunctionL() |
|
393 { |
|
394 __UHEAP_MARK; |
|
395 TInt start = User::CountAllocCells(); |
|
396 ASyncLocCB MyUpdates ; |
|
397 |
|
398 _LIT8(KService, "Service.Location"); |
|
399 _LIT8(KIDataSource,"ILocation"); |
|
400 |
|
401 |
|
402 |
|
403 CActiveScheduler *Scheduler = CActiveScheduler :: Current() ; |
|
404 |
|
405 if(!Scheduler) |
|
406 { |
|
407 Scheduler = new CActiveScheduler ; |
|
408 } |
|
409 |
|
410 |
|
411 CActiveScheduler :: Install(Scheduler) ; |
|
412 |
|
413 |
|
414 |
|
415 |
|
416 CLiwServiceHandler* ServiceHandler = CLiwServiceHandler::NewL(); |
|
417 |
|
418 // Input and output parameter list |
|
419 CLiwGenericParamList* inputlist = &(ServiceHandler->InParamListL()); |
|
420 CLiwGenericParamList* outputlist = &(ServiceHandler->OutParamListL()); |
|
421 |
|
422 |
|
423 |
|
424 |
|
425 //CLiwCriteriaItem* crit = CLiwCriteriaItem::NewL(1, KContents, KService); |
|
426 CLiwCriteriaItem* crit = CLiwCriteriaItem::NewL(1, KDataSource, KService); |
|
427 |
|
428 |
|
429 crit->SetServiceClass(TUid::Uid(KLiwClassBase)); |
|
430 |
|
431 RCriteriaArray a; |
|
432 a.AppendL(crit); |
|
433 |
|
434 ServiceHandler->AttachL(a) ; |
|
435 |
|
436 |
|
437 |
|
438 |
|
439 |
|
440 |
|
441 |
|
442 ServiceHandler->ExecuteServiceCmdL(*crit, *inputlist, *outputlist); |
|
443 |
|
444 |
|
445 |
|
446 |
|
447 TInt pos = 0; |
|
448 |
|
449 const TLiwGenericParam *errorprm = outputlist->FindFirst(pos , KErrorCode) ; |
|
450 |
|
451 if(!errorprm) |
|
452 { |
|
453 //_LIT(Klog , "Success/Failure error code missing from outputlist") ; |
|
454 //iLog->Log(Klog) ; |
|
455 return KErrGeneral ; |
|
456 } |
|
457 |
|
458 |
|
459 _LIT8(KDataSource, "ILocation"); |
|
460 |
|
461 pos = 0 ; |
|
462 |
|
463 const TLiwGenericParam *genericparm = outputlist->FindFirst(pos,KIDataSource ); |
|
464 |
|
465 if(!genericparm) |
|
466 { |
|
467 //_LIT(KLog , "Interface not found"); |
|
468 //iLog->Log(KLog) ; |
|
469 return KErrGeneral ; |
|
470 } |
|
471 |
|
472 MLiwInterface* locinterface = (genericparm->Value()).AsInterface(); |
|
473 // CLiwGenericParamList *OutParmList = CLiwGenericParamList :: NewL() ; |
|
474 |
|
475 |
|
476 TBuf8<20>CmdBuf(KCmdGetLocation) ; |
|
477 |
|
478 outputlist->Reset() ; |
|
479 inputlist->Reset() ; |
|
480 locinterface->ExecuteCmdL(CmdBuf , *inputlist , *outputlist ,KLiwOptASyncronous , &MyUpdates); |
|
481 |
|
482 CActiveScheduler :: Start() ; |
|
483 delete Scheduler ; |
|
484 |
|
485 locinterface->Close(); |
|
486 delete ServiceHandler; |
|
487 a.ResetAndDestroy(); |
|
488 a.Close(); |
|
489 //delete inputlist ; |
|
490 //delete outputlist ; |
|
491 |
|
492 //delete ServiceHandler; |
|
493 TInt end = User::CountAllocCells(); |
|
494 __UHEAP_MARKEND; |
|
495 return MyUpdates.iRetStatus ; |
|
496 } |
|
497 |
|
498 |
|
499 |
|
500 |
|
501 TInt FindLocationAsynch(TAny * /*Arg*/) |
|
502 { |
|
503 // __UHEAP_MARK; |
|
504 CTrapCleanup* cleanup = CTrapCleanup::New(); |
|
505 |
|
506 TInt ret = 0 ; |
|
507 TRAPD(err , (ret = GetLocAsynchFunctionL()) ); |
|
508 delete cleanup ; |
|
509 // __UHEAP_MARKEND; |
|
510 |
|
511 if(err) |
|
512 { |
|
513 return err ; |
|
514 } |
|
515 return ret ; |
|
516 } |