36
|
1 |
// Copyright (c) 2005-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 |
// INCLUDE FILES
|
|
19 |
#include <e32base.h>
|
|
20 |
#include <lbspositioninfo.h>
|
|
21 |
#include <lbs/epos_cpositioner.h>
|
|
22 |
#include <lbs/epos_cposmodules.h>
|
|
23 |
#include <lbs/epos_mposmodulesobserver.h>
|
|
24 |
#include "lbsdevloggermacros.h"
|
|
25 |
#include "EPos_ServerPanic.h"
|
|
26 |
#include "EPos_Global.h"
|
|
27 |
#include "EPos_CPosCallbackTimer.h"
|
|
28 |
#include "EPos_CPositionRequest.h"
|
|
29 |
#include "epos_cposmodulessettings.h"
|
|
30 |
|
|
31 |
//TODO Verify
|
|
32 |
#include "EPos_CPosLocMonitorReqHandlerHub.h"
|
|
33 |
#include "OstTraceDefinitions.h"
|
|
34 |
#ifdef OST_TRACE_COMPILER_IN_USE
|
|
35 |
#include "EPos_CPositionRequestTraces.h"
|
|
36 |
#endif
|
|
37 |
|
|
38 |
|
|
39 |
|
|
40 |
// CONSTANTS
|
|
41 |
#ifdef _DEBUG
|
|
42 |
_LIT(KTraceFileName, "EPos_CPositionRequest.cpp");
|
|
43 |
#endif
|
|
44 |
|
|
45 |
const TInt KParamPositionInfo = 0;
|
|
46 |
|
|
47 |
// ================= LOCAL FUNCTIONS ========================
|
|
48 |
|
|
49 |
void CancelTimerCleanup(TAny* aTimer)
|
|
50 |
{
|
|
51 |
(static_cast<CPosCallbackTimer*>(aTimer))->Cancel();
|
|
52 |
}
|
|
53 |
|
|
54 |
inline TPositionInfoBase& PositionInfoBase(HBufC8* aBuffer)
|
|
55 |
{
|
|
56 |
return reinterpret_cast<TPositionInfoBase&>
|
|
57 |
(const_cast<TUint8&>(*aBuffer->Ptr()));
|
|
58 |
}
|
|
59 |
inline TPositionInfo& PositionInfo(HBufC8* aBuffer)
|
|
60 |
{
|
|
61 |
return reinterpret_cast<TPositionInfo&>
|
|
62 |
(const_cast<TUint8&>(*aBuffer->Ptr()));
|
|
63 |
}
|
|
64 |
|
|
65 |
// ================= MEMBER FUNCTIONS =======================
|
|
66 |
|
|
67 |
// C++ default constructor can NOT contain any code, that
|
|
68 |
// might leave.
|
|
69 |
//
|
|
70 |
CPositionRequest::CPositionRequest(
|
|
71 |
CPosModuleSettings& aModuleSettings,
|
|
72 |
CPosLocMonitorReqHandlerHub& aLocMonitorReqHandlerHub,
|
|
73 |
TProxyPositionerConstructParams& aPositionerParams,
|
|
74 |
TBool aIsProxy)
|
|
75 |
:
|
|
76 |
CActive(EPriorityStandard),
|
|
77 |
iRequestPhase(EPosReqInactive),
|
|
78 |
iPositionerParams(aPositionerParams),
|
|
79 |
iHasProxyPositioner(aIsProxy),
|
|
80 |
iLocMonitorReqHandler(aLocMonitorReqHandlerHub),
|
|
81 |
iModuleSettings(aModuleSettings)
|
|
82 |
{
|
|
83 |
CActiveScheduler::Add(this);
|
|
84 |
}
|
|
85 |
|
|
86 |
// EPOC default constructor can leave.
|
|
87 |
void CPositionRequest::ConstructL()
|
|
88 |
{
|
|
89 |
TCallBack timeoutCallBack(HandleTimeOut, this);
|
|
90 |
iTimeoutTimer = CPosCallbackTimer::NewL(timeoutCallBack);
|
|
91 |
|
|
92 |
TCallBack trackingCallBack(TrackingCallback, this);
|
|
93 |
iTrackingTimer = CPosCallbackTimer::NewL(trackingCallBack);
|
|
94 |
|
|
95 |
iModuleSettings.PosModules().GetModuleInfoL(
|
|
96 |
iPositionerParams.iImplementationUid,
|
|
97 |
iModuleInfo);
|
|
98 |
|
|
99 |
if (!iModuleInfo.IsAvailable())
|
|
100 |
{
|
|
101 |
User::Leave(KErrNotFound);
|
|
102 |
}
|
|
103 |
|
|
104 |
LoadPositionerL();
|
|
105 |
}
|
|
106 |
|
|
107 |
/**
|
|
108 |
* Two-phased constructor.
|
|
109 |
*
|
|
110 |
* @param aModules Location Settings reference
|
|
111 |
* @param aLocMonitorReqHandlerHub The hub for requests to the location monitor.
|
|
112 |
* @param aPositionerParams contruction parameters needed when creating
|
|
113 |
* positioner.
|
|
114 |
* @param aIsProxy ETrue if aImplementationUid represents a proxy PSY,
|
|
115 |
* EFalse otherwise.
|
|
116 |
*/
|
|
117 |
CPositionRequest* CPositionRequest::NewL(
|
|
118 |
CPosModuleSettings& aModuleSettings,
|
|
119 |
CPosLocMonitorReqHandlerHub& aLocMonitorReqHandlerHub,
|
|
120 |
TProxyPositionerConstructParams& aPositionerParams,
|
|
121 |
TBool aIsProxy)
|
|
122 |
{
|
|
123 |
CPositionRequest* self = new (ELeave) CPositionRequest(
|
|
124 |
aModuleSettings,
|
|
125 |
aLocMonitorReqHandlerHub,
|
|
126 |
aPositionerParams,
|
|
127 |
aIsProxy);
|
|
128 |
CleanupStack::PushL(self);
|
|
129 |
self->ConstructL();
|
|
130 |
CleanupStack::Pop(self);
|
|
131 |
return self;
|
|
132 |
}
|
|
133 |
|
|
134 |
/**
|
|
135 |
* Destructor.
|
|
136 |
*/
|
|
137 |
CPositionRequest::~CPositionRequest()
|
|
138 |
{
|
|
139 |
// Panic client if request is outstanding
|
|
140 |
if (IsActive())
|
|
141 |
{
|
|
142 |
iMessage.Panic(KPosClientFault, EPositionRequestsNotCancelled);
|
|
143 |
}
|
|
144 |
Cancel();
|
|
145 |
if (iTrackingState == EPosTracking)
|
|
146 |
{
|
|
147 |
StopTracking();
|
|
148 |
}
|
|
149 |
delete iTrackingTimer;
|
|
150 |
delete iPositionBuffer;
|
|
151 |
delete iTimeoutTimer;
|
|
152 |
delete iPositioner;
|
|
153 |
}
|
|
154 |
|
|
155 |
/**
|
|
156 |
* Starts a position request cycle. Should only be called when PSY is
|
|
157 |
* enabled.
|
|
158 |
* @param aMessage the request message from the client
|
|
159 |
*/
|
|
160 |
void CPositionRequest::MakeRequestL(const RMessage2& aMessage)
|
|
161 |
{
|
|
162 |
if (!iModuleInfo.IsAvailable())
|
|
163 |
{
|
|
164 |
User::Leave(KErrNotFound);
|
|
165 |
}
|
|
166 |
|
|
167 |
__ASSERT_DEBUG(iPositioner, DebugPanic(EPosServerPanicPositionerNotInitialized));
|
|
168 |
|
|
169 |
iMessage = aMessage; // Store parameter here in case of leave.
|
|
170 |
|
|
171 |
// Clear previous position data
|
|
172 |
delete iPositionBuffer;
|
|
173 |
iPositionBuffer = NULL;
|
|
174 |
|
|
175 |
HBufC8* clientBuf = Global::CopyClientBuffer8LC(aMessage, KParamPositionInfo);
|
|
176 |
CleanupStack::Pop(clientBuf);
|
|
177 |
iPositionBuffer = clientBuf;
|
|
178 |
|
|
179 |
TPositionInfoBase& infoBase = PositionInfoBase(iPositionBuffer);
|
|
180 |
TUint32 classType = infoBase.PositionClassType();
|
|
181 |
|
|
182 |
TUint32 classesSupported = iModuleInfo.ClassesSupported(EPositionInfoFamily);
|
|
183 |
|
|
184 |
// Check that classtype is supported and is of type TPositionInfo
|
|
185 |
if ((classType != (classType & classesSupported)) ||
|
|
186 |
!(classType & EPositionInfoClass))
|
|
187 |
{
|
|
188 |
User::Leave(KErrArgument);
|
|
189 |
}
|
|
190 |
|
|
191 |
// Set ModuleId to KNullId to be able to verify that Id is set by PSY.
|
|
192 |
infoBase.SetModuleId(KNullUid);
|
|
193 |
|
|
194 |
CleanupStack::PushL(TCleanupItem(CancelTimerCleanup, iTimeoutTimer));
|
|
195 |
|
|
196 |
// Start timer if necessary
|
|
197 |
if (iTimeOut.Int64() > 0)
|
|
198 |
{
|
|
199 |
LBS_RDEBUG_INFO("CPositionRequest::MakeRequestL() Start Timeout Timer");
|
|
200 |
iTimeoutTimer->StartTimer(iTimeOut);
|
|
201 |
}
|
|
202 |
|
|
203 |
LBS_RDEBUG_VAR_INT("CPositionRequest::MakeRequestL() iTrackingState", iTrackingState);
|
|
204 |
switch (iTrackingState)
|
|
205 |
{
|
|
206 |
case EPosNoTracking:
|
|
207 |
case EPosFirstTrackingRequest:
|
|
208 |
StartPositionDataRequestPhase();
|
|
209 |
break;
|
|
210 |
|
|
211 |
case EPosTracking:
|
|
212 |
StartTrackingTimerWaitPhase();
|
|
213 |
break;
|
|
214 |
|
|
215 |
case EPosStopTracking:
|
|
216 |
// This must have been handled by Cancel or RunL
|
|
217 |
default:
|
|
218 |
DebugPanic(EPosServerPanicTrackingInconsistency);
|
|
219 |
}
|
|
220 |
|
|
221 |
CleanupStack::Pop(iTimeoutTimer);
|
|
222 |
}
|
|
223 |
|
|
224 |
/**
|
|
225 |
* Set the TPositionUpdateOptions object.
|
|
226 |
*
|
|
227 |
* When this class is constructed, the TPositionUpdateOptions object
|
|
228 |
* is constructed using default constructor with no parameters.
|
|
229 |
*
|
|
230 |
* @param aOptions The update options from the client.
|
|
231 |
*/
|
|
232 |
void CPositionRequest::SetUpdateOptions(
|
|
233 |
const TPositionUpdateOptionsBase& aOptions)
|
|
234 |
{
|
|
235 |
iTimeOut = aOptions.UpdateTimeOut();
|
|
236 |
TTimeIntervalMicroSeconds newInterval = aOptions.UpdateInterval();
|
|
237 |
TTimeIntervalMicroSeconds oldInterval = iTrackingUpdateInterval;
|
|
238 |
|
|
239 |
if (newInterval != iTrackingUpdateInterval)
|
|
240 |
{
|
|
241 |
iTrackingUpdateInterval = newInterval;
|
|
242 |
|
|
243 |
if (newInterval == 0) // "stop periodic updates"
|
|
244 |
{
|
|
245 |
switch (iTrackingState)
|
|
246 |
{
|
|
247 |
case EPosFirstTrackingRequest:
|
|
248 |
iTrackingState = EPosNoTracking;
|
|
249 |
break;
|
|
250 |
|
|
251 |
case EPosTracking:
|
|
252 |
if (!IsActive())
|
|
253 |
{
|
|
254 |
// can stop it right now
|
|
255 |
StopTracking();
|
|
256 |
}
|
|
257 |
else
|
|
258 |
{
|
|
259 |
// mark to stop later
|
|
260 |
iTrackingState = EPosStopTracking;
|
|
261 |
}
|
|
262 |
break;
|
|
263 |
|
|
264 |
case EPosNoTracking:
|
|
265 |
case EPosStopTracking:
|
|
266 |
break;
|
|
267 |
default:
|
|
268 |
DebugPanic(EPosServerPanicTrackingInconsistency);
|
|
269 |
break;
|
|
270 |
}
|
|
271 |
}
|
|
272 |
else if (oldInterval != 0) // "use another update interval"
|
|
273 |
{
|
|
274 |
if (iRequestPhase == EPosReqInactive)
|
|
275 |
{
|
|
276 |
TInt err;
|
|
277 |
TRAP(err, RestartTrackingL());
|
|
278 |
}
|
|
279 |
else
|
|
280 |
{
|
|
281 |
// can't affect outstanding request
|
|
282 |
// postpone until request is completed
|
|
283 |
// it will be handled by RunL or DoCancel
|
|
284 |
// via HandleTrackingStateL
|
|
285 |
iNewTrackingInterval = ETrue;
|
|
286 |
}
|
|
287 |
}
|
|
288 |
else
|
|
289 |
{
|
|
290 |
// oldInterval == 0
|
|
291 |
// newInterval != 0
|
|
292 |
// it means - "start periodic updates"
|
|
293 |
iTrackingState = EPosFirstTrackingRequest;
|
|
294 |
}
|
|
295 |
}
|
|
296 |
}
|
|
297 |
|
|
298 |
/**
|
|
299 |
* Get the TPositionUpdateOptions object.
|
|
300 |
* @param aOptions The TPositionUpdateOptions object.
|
|
301 |
*/
|
|
302 |
void CPositionRequest::GetUpdateOptions(
|
|
303 |
TPositionUpdateOptionsBase& aOptions) const
|
|
304 |
{
|
|
305 |
aOptions.SetUpdateTimeOut(iTimeOut);
|
|
306 |
aOptions.SetUpdateInterval(iTrackingUpdateInterval);
|
|
307 |
}
|
|
308 |
|
|
309 |
/**
|
|
310 |
* Stops current tracking session
|
|
311 |
*/
|
|
312 |
void CPositionRequest::NewTrackingSessionIfTracking()
|
|
313 |
{
|
|
314 |
/* Requestor has been changed. Call Privacy Server. */
|
|
315 |
}
|
|
316 |
|
|
317 |
/**
|
|
318 |
* Called when changes in locations settings occur.
|
|
319 |
* @param aEvent Event information
|
|
320 |
*/
|
|
321 |
void CPositionRequest::HandleSettingsChangeL(TPosModulesEvent aEvent)
|
|
322 |
{
|
|
323 |
if (aEvent.iModuleId != iModuleInfo.ModuleId())
|
|
324 |
{
|
|
325 |
return;
|
|
326 |
}
|
|
327 |
|
|
328 |
switch (aEvent.iType)
|
|
329 |
{
|
|
330 |
case EPosModulesEventAvailabilityChanged:
|
|
331 |
case EPosModulesEventModuleInstalled:
|
|
332 |
iModuleSettings.PosModules().GetModuleInfoL(
|
|
333 |
iModuleInfo.ModuleId(),
|
|
334 |
iModuleInfo);
|
|
335 |
break;
|
|
336 |
case EPosModulesEventModuleRemoved:
|
|
337 |
iModuleInfo.SetIsAvailable(EFalse);
|
|
338 |
break;
|
|
339 |
default:
|
|
340 |
return;
|
|
341 |
}
|
|
342 |
|
|
343 |
if (!iModuleInfo.IsAvailable())
|
|
344 |
{
|
|
345 |
if (IsActive())
|
|
346 |
{
|
|
347 |
CompleteClient(KErrNotFound);
|
|
348 |
Cancel();
|
|
349 |
}
|
|
350 |
|
|
351 |
// Unuse positioner and unload it
|
|
352 |
if (iTrackingState == EPosTracking)
|
|
353 |
{
|
|
354 |
StopPsyTracking();
|
|
355 |
}
|
|
356 |
delete iPositioner;
|
|
357 |
iPositioner = NULL;
|
|
358 |
}
|
|
359 |
else if (!iPositioner)
|
|
360 |
{
|
|
361 |
// psy is re-enabled after being disabled
|
|
362 |
LoadPositionerL();
|
|
363 |
if (iTrackingState == EPosTracking)
|
|
364 |
{
|
|
365 |
StartPsyTrackingL();
|
|
366 |
}
|
|
367 |
}
|
|
368 |
else
|
|
369 |
{
|
|
370 |
// shouldn't happen, but if it does, ignore it
|
|
371 |
}
|
|
372 |
}
|
|
373 |
|
|
374 |
/**
|
|
375 |
* Called when the server class is shutting down.
|
|
376 |
*/
|
|
377 |
void CPositionRequest::NotifyServerShutdown()
|
|
378 |
{
|
|
379 |
if (IsActive())
|
|
380 |
{
|
|
381 |
DEBUG_TRACE("CPositionRequest::NotifyServerShutdown() with active request", __LINE__)
|
|
382 |
CompleteClient(KErrServerTerminated);
|
|
383 |
Cancel();
|
|
384 |
}
|
|
385 |
|
|
386 |
if (iTrackingState == EPosTracking)
|
|
387 |
{
|
|
388 |
StopTracking();
|
|
389 |
}
|
|
390 |
delete iPositioner;
|
|
391 |
iPositioner = NULL;
|
|
392 |
}
|
|
393 |
|
|
394 |
/**
|
|
395 |
* From CActive
|
|
396 |
*/
|
|
397 |
void CPositionRequest::RunL()
|
|
398 |
{
|
|
399 |
LBS_RDEBUG_VAR_INT("CPositionRequest::RunL() iRequestPhase", iRequestPhase);
|
|
400 |
TInt err = iStatus.Int();
|
|
401 |
switch (iRequestPhase)
|
|
402 |
{
|
|
403 |
case EPosReqPositionRequest:
|
|
404 |
{
|
|
405 |
LBS_RDEBUG_INFO("CPositionRequest::RunL() EPosReqPositionRequest");
|
|
406 |
// Position request finished. Cancel timer.
|
|
407 |
iTimeoutTimer->Cancel();
|
|
408 |
iRequestPhase = EPosReqInactive;
|
|
409 |
|
|
410 |
CompleteRequest(err);
|
|
411 |
|
|
412 |
HandleTrackingStateL(); // don't care if it leaves
|
|
413 |
break;
|
|
414 |
}
|
|
415 |
|
|
416 |
case EPosWaitForTracking:
|
|
417 |
StartPositionDataRequestPhase();
|
|
418 |
break;
|
|
419 |
|
|
420 |
default :
|
|
421 |
DEBUG_TRACE("CPositionRequest::RunL() panicing", __LINE__)
|
|
422 |
DebugPanic(EPosServerPanicRequestInconsistency);
|
|
423 |
}
|
|
424 |
}
|
|
425 |
|
|
426 |
/**
|
|
427 |
* From CActive
|
|
428 |
*/
|
|
429 |
TInt CPositionRequest::RunError(TInt /*aError*/)
|
|
430 |
{
|
|
431 |
// Happens only if HandleTrackingStateL leaves
|
|
432 |
// which in turn means that StartTrackingL leaved somewhere
|
|
433 |
// As request is already completed, just ignore the error
|
|
434 |
return KErrNone;
|
|
435 |
}
|
|
436 |
|
|
437 |
/**
|
|
438 |
* From CActive
|
|
439 |
*/
|
|
440 |
void CPositionRequest::DoCancel()
|
|
441 |
{
|
|
442 |
OstTraceFunctionEntry1( CPOSITIONREQUEST_DOCANCEL_ENTRY, this );
|
|
443 |
LBS_RDEBUG_VAR_INT("CPositionRequest::DoCancel() iRequestPhase", iRequestPhase);
|
|
444 |
iTimeoutTimer->Cancel();
|
|
445 |
|
|
446 |
switch (iRequestPhase)
|
|
447 |
{
|
|
448 |
case EPosReqPositionRequest:
|
|
449 |
{
|
|
450 |
__ASSERT_DEBUG(iPositioner, DebugPanic(EPosServerPanicPositionerNotInitialized));
|
|
451 |
DEBUG_TRACE("calling CPositioner::CancelNotifyPositionUpdate()", __LINE__)
|
|
452 |
if(iRequestTimedOut)
|
|
453 |
{
|
|
454 |
iPositioner->CancelNotifyPositionUpdate(KErrTimedOut);
|
|
455 |
}
|
|
456 |
else
|
|
457 |
{
|
|
458 |
iPositioner->CancelNotifyPositionUpdate();
|
|
459 |
}
|
|
460 |
break;
|
|
461 |
}
|
|
462 |
case EPosWaitForTracking:
|
|
463 |
CompleteSelf(KErrCancel);
|
|
464 |
break;
|
|
465 |
|
|
466 |
default:
|
|
467 |
DEBUG_TRACE("CPositionRequest::DoCancel() panicing", __LINE__)
|
|
468 |
DebugPanic(EPosServerPanicRequestInconsistency);
|
|
469 |
}
|
|
470 |
|
|
471 |
TInt err;
|
|
472 |
if (iRequestTimedOut)
|
|
473 |
{
|
|
474 |
iRequestTimedOut = EFalse;
|
|
475 |
CompleteClient(KErrTimedOut);
|
|
476 |
TRAP(err, HandleTrackingStateL());
|
|
477 |
}
|
|
478 |
else
|
|
479 |
{
|
|
480 |
CompleteClient(KErrCancel);
|
|
481 |
|
|
482 |
// Handle Tracking State
|
|
483 |
if (iTrackingState == EPosStopTracking)
|
|
484 |
{
|
|
485 |
StopTracking();
|
|
486 |
}
|
|
487 |
}
|
|
488 |
|
|
489 |
iRequestPhase = EPosReqInactive;
|
|
490 |
OstTraceFunctionExit1( CPOSITIONREQUEST_DOCANCEL_EXIT, this );
|
|
491 |
}
|
|
492 |
|
|
493 |
|
|
494 |
void CPositionRequest::CompleteSelf(TInt aReason)
|
|
495 |
{
|
|
496 |
TRequestStatus* status = &iStatus;
|
|
497 |
User::RequestComplete(status, aReason);
|
|
498 |
}
|
|
499 |
|
|
500 |
void CPositionRequest::CompleteClient(TInt aReason)
|
|
501 |
{
|
|
502 |
if (!iMessage.IsNull())
|
|
503 |
{
|
|
504 |
LBS_RDEBUG_ARGINT("LBS","Client", "RunL", aReason);
|
|
505 |
iMessage.Complete(aReason);
|
|
506 |
}
|
|
507 |
}
|
|
508 |
|
|
509 |
void CPositionRequest::CompleteRequest(TInt aReason)
|
|
510 |
{
|
|
511 |
// Return fix to the client
|
|
512 |
if (aReason == KErrNone || aReason == KPositionPartialUpdate)
|
|
513 |
{
|
|
514 |
TInt err = PackPositionData();
|
|
515 |
// err - client cannot receive result data
|
|
516 |
CompleteClient((err != KErrNone) ? err : aReason);
|
|
517 |
|
|
518 |
// Save current fix to LastKnownPosition handler
|
|
519 |
// partial updates are not stored
|
|
520 |
if ( aReason == KErrNone )
|
|
521 |
{
|
|
522 |
SaveAsLastKnownPosition();
|
|
523 |
}
|
|
524 |
}
|
|
525 |
else
|
|
526 |
{
|
|
527 |
CompleteClient(aReason);
|
|
528 |
}
|
|
529 |
}
|
|
530 |
|
|
531 |
void CPositionRequest::StartPositionDataRequestPhase()
|
|
532 |
{
|
|
533 |
LBS_RDEBUG_VAR_INT("CPositionRequest::StartPositionDataRequestPhase() iRequestPhase", iRequestPhase);
|
|
534 |
|
|
535 |
__ASSERT_DEBUG(iPositioner,
|
|
536 |
DebugPanic(EPosServerPanicPositionerNotInitialized));
|
|
537 |
|
|
538 |
iReqStartTime.UniversalTime();
|
|
539 |
|
|
540 |
TPositionInfo& info = PositionInfo(iPositionBuffer);
|
|
541 |
|
|
542 |
// Set datum type to WGS84
|
|
543 |
TPosition position;
|
|
544 |
info.GetPosition(position);
|
|
545 |
position.SetDatum(KPositionDatumWgs84);
|
|
546 |
info.SetPosition(position);
|
|
547 |
|
|
548 |
TPositionInfoBase& infoBase = reinterpret_cast<TPositionInfoBase&>(info);
|
|
549 |
|
|
550 |
// issue request to psy
|
|
551 |
DEBUG_TRACE("calling CPositioner::NotifyPositionUpdate()", __LINE__)
|
|
552 |
|
|
553 |
iStatus = KRequestPending;
|
|
554 |
iPositioner->NotifyPositionUpdate(infoBase, iStatus);
|
|
555 |
|
|
556 |
iRequestPhase = EPosReqPositionRequest;
|
|
557 |
SetActive();
|
|
558 |
}
|
|
559 |
|
|
560 |
void CPositionRequest::StartTrackingTimerWaitPhase()
|
|
561 |
{
|
|
562 |
LBS_RDEBUG_VAR_INT("CPositionRequest::StartTrackingTimerWaitPhase() iRequestPhase", iRequestPhase);
|
|
563 |
iRequestPhase = EPosWaitForTracking;
|
|
564 |
iStatus = KRequestPending;
|
|
565 |
SetActive();
|
|
566 |
}
|
|
567 |
|
|
568 |
TInt CPositionRequest::PackPositionData()
|
|
569 |
{
|
|
570 |
TPositionInfo& info = PositionInfo(iPositionBuffer);
|
|
571 |
|
|
572 |
// Verify that ModuleId, set by PSY, is correct if using specific PSY.
|
|
573 |
// If a proxy PSY is used, the proxy is responsible for verifying UID.
|
|
574 |
if (!iHasProxyPositioner &&
|
|
575 |
info.ModuleId() != iPositionerParams.iImplementationUid)
|
|
576 |
{
|
|
577 |
return KErrGeneral;
|
|
578 |
}
|
|
579 |
|
|
580 |
// Check that datum type still is WGS84
|
|
581 |
TPosition position;
|
|
582 |
info.GetPosition(position);
|
|
583 |
if (position.Datum() != KPositionDatumWgs84)
|
|
584 |
{
|
|
585 |
return KErrNotSupported;
|
|
586 |
}
|
|
587 |
|
|
588 |
TPtr8 ptrToBuffer = iPositionBuffer->Des();
|
|
589 |
return Global::Write(iMessage, KParamPositionInfo, ptrToBuffer);
|
|
590 |
}
|
|
591 |
|
|
592 |
void CPositionRequest::SaveAsLastKnownPosition()
|
|
593 |
{
|
|
594 |
TPosition pos;
|
|
595 |
TPositionInfo& positionInfo = PositionInfo(iPositionBuffer);
|
|
596 |
positionInfo.GetPosition(pos);
|
|
597 |
|
|
598 |
// Don't set last known position if the position request is in the past. //TODO check if this is required
|
|
599 |
if (iReqStartTime <= pos.Time())
|
|
600 |
{
|
|
601 |
iLocMonitorReqHandler.SetPositionInfo(positionInfo);
|
|
602 |
}
|
|
603 |
}
|
|
604 |
|
|
605 |
TInt CPositionRequest::HandleTimeOut(TAny* aPositionRequest)
|
|
606 |
{
|
|
607 |
CPositionRequest* self =
|
|
608 |
reinterpret_cast<CPositionRequest*>(aPositionRequest);
|
|
609 |
|
|
610 |
LBS_RDEBUG_VAR_INT("CPositionRequest::HandleTimeOut() iRequestPhase", self->iRequestPhase);
|
|
611 |
DEBUG_TRACE("CPositionRequest::HandleTimeOut()", __LINE__)
|
|
612 |
__ASSERT_DEBUG(self->iRequestPhase == EPosReqPositionRequest || self->iRequestPhase == EPosWaitForTracking,
|
|
613 |
DebugPanic(EPosServerPanicRequestInconsistency));
|
|
614 |
|
|
615 |
self->iRequestTimedOut = ETrue;
|
|
616 |
self->Cancel();
|
|
617 |
|
|
618 |
return KErrNone;
|
|
619 |
}
|
|
620 |
|
|
621 |
TInt CPositionRequest::TrackingCallback(TAny* aPositionRequest)
|
|
622 |
{
|
|
623 |
CPositionRequest* self =
|
|
624 |
reinterpret_cast<CPositionRequest*>(aPositionRequest);
|
|
625 |
|
|
626 |
// continue tracking timer
|
|
627 |
if (self->iTrackingState == EPosTracking)
|
|
628 |
{
|
|
629 |
self->ContinueTrackingTimer();
|
|
630 |
}
|
|
631 |
|
|
632 |
if (self->iRequestPhase == EPosWaitForTracking)
|
|
633 |
{
|
|
634 |
// This is the normal case. The client's request was delayed
|
|
635 |
// by the update interval.
|
|
636 |
// Complete tracking timer waiting and go next stage
|
|
637 |
self->CompleteSelf(KErrNone);
|
|
638 |
}
|
|
639 |
|
|
640 |
return KErrNone;
|
|
641 |
}
|
|
642 |
|
|
643 |
void CPositionRequest::HandleTrackingStateL()
|
|
644 |
{
|
|
645 |
switch (iTrackingState)
|
|
646 |
{
|
|
647 |
case EPosNoTracking:
|
|
648 |
break;
|
|
649 |
|
|
650 |
case EPosFirstTrackingRequest:
|
|
651 |
// start internal tracking
|
|
652 |
iTrackingState = EPosTracking;
|
|
653 |
ContinueTrackingTimer();
|
|
654 |
|
|
655 |
StartPsyTrackingL();
|
|
656 |
break;
|
|
657 |
|
|
658 |
case EPosTracking:
|
|
659 |
// if tracking interval was changed
|
|
660 |
if (iNewTrackingInterval)
|
|
661 |
{
|
|
662 |
RestartTrackingL();
|
|
663 |
}
|
|
664 |
break;
|
|
665 |
|
|
666 |
case EPosStopTracking:
|
|
667 |
StopTracking();
|
|
668 |
break;
|
|
669 |
|
|
670 |
default:
|
|
671 |
DebugPanic(EPosServerPanicTrackingInconsistency);
|
|
672 |
}
|
|
673 |
}
|
|
674 |
|
|
675 |
void CPositionRequest::StartPsyTrackingL()
|
|
676 |
{
|
|
677 |
__ASSERT_DEBUG(iPositioner, DebugPanic(EPosServerPanicPositionerNotInitialized));
|
|
678 |
|
|
679 |
iNewTrackingInterval = EFalse;
|
|
680 |
|
|
681 |
DEBUG_TRACE("calling CPositioner::TrackingOverridden()", __LINE__)
|
|
682 |
if (iPositioner->TrackingOverridden())
|
|
683 |
{
|
|
684 |
DEBUG_TRACE("calling CPositioner::StartTrackingL()", __LINE__)
|
|
685 |
iPositioner->StartTrackingL(iTrackingUpdateInterval);
|
|
686 |
iPositionerTrackingStarted = ETrue;
|
|
687 |
}
|
|
688 |
}
|
|
689 |
|
|
690 |
void CPositionRequest::RestartTrackingL()
|
|
691 |
{
|
|
692 |
LBS_RDEBUG_INFO("CPositionRequest::RestartTrackingL()");
|
|
693 |
iTrackingTimer->Cancel();
|
|
694 |
StopPsyTracking();
|
|
695 |
ContinueTrackingTimer();
|
|
696 |
StartPsyTrackingL();
|
|
697 |
}
|
|
698 |
|
|
699 |
void CPositionRequest::StopTracking()
|
|
700 |
{
|
|
701 |
LBS_RDEBUG_INFO("CPositionRequest::StopTracking()");
|
|
702 |
iTrackingTimer->Cancel();
|
|
703 |
iTrackingState = EPosNoTracking;
|
|
704 |
|
|
705 |
StopPsyTracking();
|
|
706 |
}
|
|
707 |
|
|
708 |
void CPositionRequest::StopPsyTracking()
|
|
709 |
{
|
|
710 |
if (iPositioner && iPositionerTrackingStarted)
|
|
711 |
{
|
|
712 |
DEBUG_TRACE("calling CPositioner::StopTracking()", __LINE__)
|
|
713 |
iPositioner->StopTracking();
|
|
714 |
iPositionerTrackingStarted = EFalse;
|
|
715 |
}
|
|
716 |
}
|
|
717 |
|
|
718 |
void CPositionRequest::ContinueTrackingTimer()
|
|
719 |
{
|
|
720 |
LBS_RDEBUG_INFO("CPositionRequest::ContinueTrackingTimer()");
|
|
721 |
iTrackingTimer->StartTimer(iTrackingUpdateInterval);
|
|
722 |
}
|
|
723 |
|
|
724 |
void CPositionRequest::LoadPositionerL()
|
|
725 |
{
|
|
726 |
iPositioner = CPositioner::NewL(&iPositionerParams);
|
|
727 |
iPositionerTrackingStarted = EFalse;
|
|
728 |
}
|
|
729 |
|
|
730 |
void CPositionRequest::ExtendUpdateTimeOut(const TTimeIntervalMicroSeconds& aAdditionalTime)
|
|
731 |
{
|
|
732 |
LBS_RDEBUG_INFO("CPositionRequest::ExtendUpdateTimeOut()");
|
|
733 |
iTimeoutTimer->ExtendTimeout(aAdditionalTime);
|
|
734 |
}
|
|
735 |
|
|
736 |
// End of File
|