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