|
1 // Copyright (c) 2004-2009 Nokia Corporation and/or its subsidiary(-ies). |
|
2 // All rights reserved. |
|
3 // This component and the accompanying materials are made available |
|
4 // under the terms of "Eclipse Public License v1.0" |
|
5 // which accompanies this distribution, and is available |
|
6 // at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
7 // |
|
8 // Initial Contributors: |
|
9 // Nokia Corporation - initial contribution. |
|
10 // |
|
11 // Contributors: |
|
12 // |
|
13 // Description: |
|
14 // |
|
15 |
|
16 |
|
17 |
|
18 |
|
19 // INCLUDE FILES |
|
20 #include <e32base.h> |
|
21 #include <lbs/epos_mpositionerstatus.h> |
|
22 #include <ecom/implementationproxy.h> |
|
23 #include <lbssatellite.h> |
|
24 |
|
25 #include "BTGPSPositioner.h" |
|
26 #include "BTGPSRequestHandler.h" |
|
27 #include "BTGPSPanic.h" |
|
28 #include "btgpspsy.hrh" |
|
29 #include "BTGPSLogging.h" |
|
30 #include "BTGPSNmeaBuffer.h" |
|
31 |
|
32 // EXTERNAL DATA STRUCTURES |
|
33 |
|
34 // EXTERNAL FUNCTION PROTOTYPES |
|
35 |
|
36 // CONSTANTS |
|
37 static const TImplementationProxy KFactoryPtr = |
|
38 IMPLEMENTATION_PROXY_ENTRY( KPosBTPSYImplUid, CBTGPSPositioner::NewL); |
|
39 |
|
40 // MACROS |
|
41 |
|
42 // LOCAL CONSTANTS AND MACROS |
|
43 |
|
44 // MODULE DATA STRUCTURES |
|
45 |
|
46 /** |
|
47 * The extension class for the CBTGPSPositioner |
|
48 * Stores the instance variables |
|
49 */ |
|
50 class TBTGPSExtension |
|
51 { |
|
52 public: |
|
53 /** |
|
54 * default constructor |
|
55 */ |
|
56 TBTGPSExtension(): |
|
57 iRequestHandler(NULL), |
|
58 iActive(EFalse), |
|
59 iPosInfo(NULL), |
|
60 iStatus(NULL) |
|
61 { |
|
62 } |
|
63 |
|
64 //Pointer to the request handler |
|
65 CBTGPSRequestHandler* iRequestHandler; |
|
66 |
|
67 //Is there request pending |
|
68 TBool iActive; |
|
69 |
|
70 //Pointer to the current position info |
|
71 TPositionInfoBase* iPosInfo; |
|
72 |
|
73 //Pointer to the current request status |
|
74 TRequestStatus* iStatus; |
|
75 }; |
|
76 |
|
77 // LOCAL FUNCTION PROTOTYPES |
|
78 |
|
79 // FORWARD DECLARATIONS |
|
80 |
|
81 // ============================= LOCAL FUNCTIONS =============================== |
|
82 |
|
83 // ============================ MEMBER FUNCTIONS =============================== |
|
84 |
|
85 |
|
86 // ----------------------------------------------------------------------------- |
|
87 // CBTGPSPositioner::NewL |
|
88 // Two-phased constructor. |
|
89 // ----------------------------------------------------------------------------- |
|
90 // |
|
91 CBTGPSPositioner* CBTGPSPositioner::NewL(TAny* aConstructionParameters) |
|
92 { |
|
93 CBTGPSPositioner* self = new( ELeave ) CBTGPSPositioner; |
|
94 |
|
95 CleanupStack::PushL( self ); |
|
96 self->ConstructL(aConstructionParameters); |
|
97 CleanupStack::Pop(self); |
|
98 |
|
99 return self; |
|
100 } |
|
101 |
|
102 |
|
103 // ----------------------------------------------------------------------------- |
|
104 // CBTGPSPositioner::~CBTGPSPositioner |
|
105 // Destructor. |
|
106 // ----------------------------------------------------------------------------- |
|
107 // |
|
108 CBTGPSPositioner::~CBTGPSPositioner() |
|
109 { |
|
110 TRACESTRING("CBTGPSPositioner::~CBTGPSPositioner") |
|
111 if ( iBTGPSExtension ) |
|
112 { |
|
113 if ( iBTGPSExtension->iRequestHandler ) |
|
114 { |
|
115 iBTGPSExtension->iRequestHandler->UnregisterPSY(this); |
|
116 } |
|
117 delete iBTGPSExtension; |
|
118 } |
|
119 } |
|
120 |
|
121 // ----------------------------------------------------------------------------- |
|
122 // NotifyPositionUpdate implements Cpositioner::NotifyPositionUpdate |
|
123 // Requests position info asynchronously. |
|
124 // Returns: aPosInfo: A reference to a position info object. This object |
|
125 // must be in scope until the request has completed. |
|
126 // The position (TPosition) of this position info object |
|
127 // must be in WGS84 geodetic datum. |
|
128 // aStatus: The request status |
|
129 // |
|
130 // ----------------------------------------------------------------------------- |
|
131 // |
|
132 void CBTGPSPositioner::NotifyPositionUpdate(TPositionInfoBase& aPosInfo, |
|
133 TRequestStatus& aStatus) |
|
134 { |
|
135 TRACESTRING("CBTGPSPositioner::NotifyPositionUpdate") |
|
136 |
|
137 //Clear position info |
|
138 ClearPositionInfo(aPosInfo); |
|
139 |
|
140 const CBTGPSFix* fix = NULL; |
|
141 TTime maxAge; |
|
142 |
|
143 aStatus = KRequestPending; |
|
144 |
|
145 iBTGPSExtension->iPosInfo = &aPosInfo; |
|
146 iBTGPSExtension->iStatus = &aStatus; |
|
147 GetMaxAge(maxAge); |
|
148 |
|
149 //Check if last location can be used |
|
150 TInt result = iBTGPSExtension->iRequestHandler->LastLocation(fix,maxAge, |
|
151 IsPartialUpdateAllowed()); |
|
152 |
|
153 if( result == KErrNone ) |
|
154 { |
|
155 TInt err(KErrNone); |
|
156 |
|
157 switch(fix->FixState()) |
|
158 { |
|
159 case CBTGPSFix::EFixValidityUnkown: |
|
160 { |
|
161 //Should never happen |
|
162 TRACESTRING("CBTGPSPositioner::NotifyPositionUpdate: \ |
|
163 INTERNAL ERROR: CBTGPSFix::ENull.") |
|
164 err = KPositionQualityLoss; |
|
165 break; |
|
166 } |
|
167 case CBTGPSFix::EFixNotValid: |
|
168 { |
|
169 TRACESTRING("CBTGPSPositioner::NotifyPositionUpdate: \ |
|
170 Last known location: CBTGPSFix::ENotValid.") |
|
171 err = fix->FillPositionInfo(*(iBTGPSExtension->iPosInfo)); |
|
172 if(err == KErrNone) |
|
173 { |
|
174 err = KPositionPartialUpdate; |
|
175 } |
|
176 break; |
|
177 } |
|
178 case CBTGPSFix::EFixValid2D: |
|
179 case CBTGPSFix::EFixValid3D: |
|
180 { |
|
181 err = fix->FillPositionInfo(*(iBTGPSExtension->iPosInfo)); |
|
182 break; |
|
183 } |
|
184 default: |
|
185 { |
|
186 //Should never happen |
|
187 TRACESTRING("CBTGPSPositioner::NotifyPositionUpdate: \ |
|
188 INTERNAL ERROR: fix unknown.") |
|
189 err = KErrGeneral; |
|
190 break; |
|
191 } |
|
192 } |
|
193 TRACESTRING2("CBTGPSPositioner::Complete request error = %d", err) |
|
194 User::RequestComplete(iBTGPSExtension->iStatus, err); |
|
195 } |
|
196 else |
|
197 { |
|
198 iBTGPSExtension->iActive = ETrue; |
|
199 iBTGPSExtension->iRequestHandler->AcquireLocation(this); |
|
200 } |
|
201 |
|
202 } |
|
203 |
|
204 |
|
205 // ----------------------------------------------------------------------------- |
|
206 // CancelNotifyPositionUpdate implements Cpositioner::CancelNotifyPositionUpdate |
|
207 // Cancels position info request. |
|
208 // ----------------------------------------------------------------------------- |
|
209 // |
|
210 void CBTGPSPositioner::CancelNotifyPositionUpdate() |
|
211 { |
|
212 TRACESTRING("CBTGPSPositioner::CancelNotifyPositionUpdate") |
|
213 |
|
214 if ( iBTGPSExtension->iActive ) |
|
215 { |
|
216 iBTGPSExtension->iActive = EFalse; |
|
217 iBTGPSExtension->iPosInfo = NULL; |
|
218 iBTGPSExtension->iRequestHandler->CancelAcquireLocation(this); |
|
219 |
|
220 TRACESTRING2("CBTGPSPositioner::Complete request error = %d", KErrCancel) |
|
221 User::RequestComplete(iBTGPSExtension->iStatus,KErrCancel); |
|
222 } |
|
223 } |
|
224 |
|
225 |
|
226 // ----------------------------------------------------------------------------- |
|
227 // TrackingOverridden implements Cpositioner::TrackingOverridden |
|
228 // Indicate if the PSY has overridden tracking. |
|
229 // ----------------------------------------------------------------------------- |
|
230 // |
|
231 TBool CBTGPSPositioner::TrackingOverridden() const |
|
232 { |
|
233 return ETrue; |
|
234 } |
|
235 |
|
236 |
|
237 // ----------------------------------------------------------------------------- |
|
238 // TrackingOverridden implements Cpositioner::TrackingOverridden |
|
239 // Initiate a tracking session. |
|
240 // ----------------------------------------------------------------------------- |
|
241 // |
|
242 void CBTGPSPositioner::StartTrackingL( |
|
243 const TTimeIntervalMicroSeconds& aInterval) |
|
244 { |
|
245 TRACESTRING("CBTGPSPositioner::StartTrackingL") |
|
246 iBTGPSExtension->iRequestHandler->TrackingSessionStartL(this,aInterval); |
|
247 } |
|
248 |
|
249 // ----------------------------------------------------------------------------- |
|
250 // StopTracking implements Cpositioner::StopTracking |
|
251 // Any outstanding requests will be cancelled. |
|
252 // ----------------------------------------------------------------------------- |
|
253 // |
|
254 void CBTGPSPositioner::StopTracking() |
|
255 { |
|
256 TRACESTRING("CBTGPSPositioner::StopTracking") |
|
257 iBTGPSExtension->iRequestHandler->TrackingSessionStop(this); |
|
258 } |
|
259 |
|
260 // ----------------------------------------------------------------------------- |
|
261 // CBTGPSPositioner::RequestCompleteNotify implements |
|
262 // MBTGPSRequestCompleteListener::RequestCompleteNotify |
|
263 // ----------------------------------------------------------------------------- |
|
264 // |
|
265 TBool CBTGPSPositioner::RequestCompleteNotify( |
|
266 const CBTGPSFix* aFix, |
|
267 TInt aErr) |
|
268 { |
|
269 TRACESTRING("CBTGPSPositioner::RequestCompleteNotify start...") |
|
270 TRACESTRING2("error = %d", aErr) |
|
271 TBool completed = EFalse; |
|
272 |
|
273 //Validate the NMEA Buffer index and bottom |
|
274 if(aFix!=NULL) |
|
275 { |
|
276 aFix->ValidateNmeaBufferIndex( |
|
277 iNmeaIndex, |
|
278 iNmeaBottom); |
|
279 } |
|
280 |
|
281 //If there was error, pass it |
|
282 if ( (aErr < 0) || (KPositionQualityLoss == aErr) || (aFix==NULL)) |
|
283 { |
|
284 ClearPositionInfo(*iBTGPSExtension->iPosInfo); |
|
285 iBTGPSExtension->iActive = EFalse; |
|
286 |
|
287 TRACESTRING2("CBTGPSPositioner::Complete request error = %d", aErr) |
|
288 User::RequestComplete(iBTGPSExtension->iStatus,aErr); |
|
289 completed = ETrue; |
|
290 } |
|
291 //No error, complete with fix |
|
292 else |
|
293 { |
|
294 TRACESTRING2("fix type = %d", aFix->FixState()); |
|
295 |
|
296 TInt err = KErrNone; |
|
297 |
|
298 switch(aFix->FixState()) |
|
299 { |
|
300 case CBTGPSFix::EFixValidityUnkown: |
|
301 case CBTGPSFix::EFixNotValid: |
|
302 { |
|
303 if ( IsPartialUpdateAllowed() ) |
|
304 { |
|
305 //Complete the fix when client accept partial update. |
|
306 //Otherwise, continue |
|
307 completed = ETrue; |
|
308 err = KPositionPartialUpdate; |
|
309 } |
|
310 } |
|
311 break; |
|
312 case CBTGPSFix::EFixValid2D: |
|
313 case CBTGPSFix::EFixValid3D: |
|
314 completed = ETrue; |
|
315 err = KErrNone; |
|
316 break; |
|
317 default: |
|
318 { |
|
319 TRACESTRING("CBTGPSPositioner::RequestCompleteNotify: \ |
|
320 INTERNAL ERROR: fix unknown.") |
|
321 completed = ETrue; |
|
322 err = KErrGeneral; |
|
323 break; |
|
324 } |
|
325 } |
|
326 |
|
327 if(completed) |
|
328 { |
|
329 TInt nmeaIndex = iNmeaIndex; |
|
330 TInt fillErr = aFix->FillPositionInfo( |
|
331 *iBTGPSExtension->iPosInfo, |
|
332 &nmeaIndex); |
|
333 |
|
334 if(fillErr != KErrNone) |
|
335 { |
|
336 err = fillErr; |
|
337 } |
|
338 else |
|
339 { |
|
340 iNmeaIndex = nmeaIndex; |
|
341 } |
|
342 |
|
343 iBTGPSExtension->iActive = EFalse; |
|
344 |
|
345 TRACESTRING2("CBTGPSPositioner::Complete request error = %d", err) |
|
346 User::RequestComplete(iBTGPSExtension->iStatus,err); |
|
347 } |
|
348 |
|
349 } |
|
350 return completed; |
|
351 } |
|
352 |
|
353 // ----------------------------------------------------------------------------- |
|
354 // CBTGPSPositioner::ReportStatus |
|
355 // Reports the PSY status to the MLFW |
|
356 // ----------------------------------------------------------------------------- |
|
357 void CBTGPSPositioner::ReportStatus(const TPositionModuleStatus& aStatus) |
|
358 { |
|
359 MPositionerStatus* statusInf = this->PositionerStatus(); |
|
360 statusInf->ReportStatus(aStatus); |
|
361 } |
|
362 |
|
363 // ----------------------------------------------------------------------------- |
|
364 // CBTGPSPositioner::SetInitialNmeaBufferBottom |
|
365 // ----------------------------------------------------------------------------- |
|
366 void CBTGPSPositioner::SetInitialNmeaBufferBottom(TInt aIndex) |
|
367 { |
|
368 iNmeaIndex = aIndex; |
|
369 } |
|
370 |
|
371 // ----------------------------------------------------------------------------- |
|
372 // CBTGPSPositioner::ClearPositionInfo |
|
373 // Clears the position info |
|
374 // ----------------------------------------------------------------------------- |
|
375 void CBTGPSPositioner::ClearPositionInfo(TPositionInfoBase& aPosInfo) |
|
376 { |
|
377 if (aPosInfo.PositionClassType() & EPositionSatelliteInfoClass) |
|
378 { |
|
379 // TPositionSatelliteInfo |
|
380 (void) new (&aPosInfo) (TPositionSatelliteInfo); |
|
381 } |
|
382 else if (aPosInfo.PositionClassType() & EPositionCourseInfoClass) |
|
383 { |
|
384 // TPositionCourseInfo |
|
385 (void) new (&aPosInfo) (TPositionCourseInfo); |
|
386 } |
|
387 else if (aPosInfo.PositionClassType() & EPositionGenericInfoClass) |
|
388 { |
|
389 // HPositionGenericInfo |
|
390 HPositionGenericInfo* genInfo = |
|
391 static_cast<HPositionGenericInfo*> ( &aPosInfo ); |
|
392 |
|
393 genInfo->ClearPositionData(); |
|
394 } |
|
395 else if (aPosInfo.PositionClassType() & EPositionInfoClass) |
|
396 { |
|
397 // TPositionInfo |
|
398 (void) new (&aPosInfo) (TPositionInfo); |
|
399 } |
|
400 else |
|
401 { |
|
402 // Unknown type, this should never happen |
|
403 // --> Panic if we get here |
|
404 Panic(EPanicUnknownPositioningClass); |
|
405 } |
|
406 |
|
407 aPosInfo.SetModuleId(ImplementationUid()); |
|
408 } |
|
409 |
|
410 // ----------------------------------------------------------------------------- |
|
411 // Constructor |
|
412 // ----------------------------------------------------------------------------- |
|
413 // |
|
414 CBTGPSPositioner::CBTGPSPositioner() |
|
415 { |
|
416 iNmeaIndex = KBTGPSNmeaIndexNotSet; |
|
417 iNmeaBottom = KBTGPSNmeaIndexNotSet; |
|
418 } |
|
419 |
|
420 // ----------------------------------------------------------------------------- |
|
421 // CBTGPSPositioner::ConstructL |
|
422 // Symbian 2nd phase constructor can leave. |
|
423 // ----------------------------------------------------------------------------- |
|
424 // |
|
425 void CBTGPSPositioner::ConstructL(TAny* aConstructionParameters) |
|
426 { |
|
427 // Must call BaseConstructL first thing during |
|
428 // construction. |
|
429 CLEARTRACELOG; |
|
430 |
|
431 TRACESTRING("CBTGPSPositioner::ConstructL") |
|
432 BaseConstructL(aConstructionParameters); |
|
433 |
|
434 iBTGPSExtension = new (ELeave) TBTGPSExtension; |
|
435 |
|
436 iBTGPSExtension->iRequestHandler = CBTGPSRequestHandler::GetInstanceL(); |
|
437 iBTGPSExtension->iRequestHandler->RegisterPSYL(this); |
|
438 } |
|
439 |
|
440 |
|
441 // ========================== OTHER EXPORTED FUNCTIONS ========================= |
|
442 |
|
443 // ----------------------------------------------------------------------------- |
|
444 // |
|
445 // ----------------------------------------------------------------------------- |
|
446 // |
|
447 EXPORT_C const TImplementationProxy* ImplementationGroupProxy( |
|
448 TInt& aTableCount) |
|
449 { |
|
450 aTableCount =1; |
|
451 return &KFactoryPtr; |
|
452 } |
|
453 |
|
454 // End of File |
|
455 |