|
1 // Copyright (c) 2008-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 @file |
|
18 @internalTechnology |
|
19 @released |
|
20 */ |
|
21 |
|
22 #include "lbsprocessuiddefs.h" |
|
23 #include "locationupdatemonitor.h" |
|
24 |
|
25 |
|
26 CLbsLocUpdateMonitor::CLbsLocUpdateMonitor( |
|
27 MLbsLocUpdateObserver& aObserver) : |
|
28 CActive(EPriorityStandard), |
|
29 iObserver(aObserver) |
|
30 { |
|
31 CActiveScheduler::Add(this); |
|
32 } |
|
33 |
|
34 CLbsLocUpdateMonitor::~CLbsLocUpdateMonitor() |
|
35 { |
|
36 Cancel(); |
|
37 iLbsPositionUpdateRequestor.Close(); |
|
38 iLbsPositionUpdateMonitor.Close(); |
|
39 } |
|
40 |
|
41 CLbsLocUpdateMonitor* CLbsLocUpdateMonitor::NewL( |
|
42 MLbsLocUpdateObserver& aObserver) |
|
43 { |
|
44 CLbsLocUpdateMonitor* self = new (ELeave) CLbsLocUpdateMonitor(aObserver); |
|
45 CleanupStack::PushL(self); |
|
46 self->ConstructL(); |
|
47 CleanupStack::Pop(self); |
|
48 return self; |
|
49 } |
|
50 |
|
51 void CLbsLocUpdateMonitor::ConstructL() |
|
52 { |
|
53 iLbsPositionUpdateMonitor.OpenL(KLbsGpsLocManagerUid); |
|
54 |
|
55 RLbsPositionUpdateRequests::TChannelIdentifer channelId; |
|
56 channelId.iModuleId = KLbsGpsLocManagerUid; |
|
57 channelId.iClientId = KLbsNetRequestHandlerUid; |
|
58 iLbsPositionUpdateRequestor.OpenL(channelId); |
|
59 } |
|
60 |
|
61 void CLbsLocUpdateMonitor::StartMonitor() |
|
62 { |
|
63 if (!IsActive()) |
|
64 { |
|
65 iLbsPositionUpdateMonitor.NotifyPositionUpdate(iStatus); |
|
66 SetActive(); |
|
67 } |
|
68 } |
|
69 |
|
70 void CLbsLocUpdateMonitor::StopMonitor() |
|
71 { |
|
72 Cancel(); |
|
73 } |
|
74 |
|
75 void CLbsLocUpdateMonitor::SendLocationRequest( |
|
76 TLbsPositionUpdateRequestBase::TPowerAdvice aPowerAdvice, |
|
77 const TLbsNetPosRequestMethodInt& aMethod, |
|
78 const TLbsLocRequestQualityInt& aQuality) |
|
79 { |
|
80 TLbsPositionUpdateRequest updateRequest; |
|
81 updateRequest.SetPowerAdvice(aPowerAdvice); |
|
82 updateRequest.TargetTime() = TTime(0); |
|
83 updateRequest.RequestQuality() = aQuality; |
|
84 updateRequest.RequestMethod() = aMethod; |
|
85 iLbsPositionUpdateRequestor.SetPositionUpdateRequest(updateRequest); |
|
86 } |
|
87 |
|
88 void CLbsLocUpdateMonitor::SendCancelRequest( |
|
89 TLbsPositionUpdateRequestBase::TPowerAdvice aPowerAdvice) |
|
90 { |
|
91 TLbsPositionUpdateRequestCancel cancel; |
|
92 cancel.SetPowerAdvice(aPowerAdvice); |
|
93 iLbsPositionUpdateRequestor.SetPositionUpdateRequest(cancel); |
|
94 } |
|
95 |
|
96 |
|
97 void CLbsLocUpdateMonitor::SendPowerAdviceRequest( |
|
98 TLbsPositionUpdateRequestBase::TPowerAdvice aPowerAdvice) |
|
99 { |
|
100 TLbsPositionUpdateRequest request; |
|
101 iLbsPositionUpdateRequestor.GetPositionUpdateRequest(request); |
|
102 |
|
103 if ( request.Type()==TLbsPositionUpdateRequestBase::ECancel ) |
|
104 { |
|
105 // if the last thing we sent to the manager was a cancel then re-issue it |
|
106 // (with the correct PowerAdvice) to prevent the cancel being overwritten and therefore lost |
|
107 TLbsPositionUpdateRequestCancel cancel; |
|
108 cancel.Tracking() = EFalse; // cancel always disables tracking |
|
109 cancel.SetPowerAdvice(aPowerAdvice); |
|
110 iLbsPositionUpdateRequestor.SetPositionUpdateRequest(cancel); |
|
111 } |
|
112 else |
|
113 { |
|
114 TLbsPositionUpdateRequestStatus powerAdvice; |
|
115 powerAdvice.SetPowerAdvice(aPowerAdvice); |
|
116 iLbsPositionUpdateRequestor.SetPositionUpdateRequest(powerAdvice); |
|
117 } |
|
118 } |
|
119 |
|
120 void CLbsLocUpdateMonitor::GetPosition( |
|
121 TBool& aConflictControl, |
|
122 TInt& aReason, |
|
123 TPositionExtendedSatelliteInfo& aPosInfo, |
|
124 TTime& aActualTime) |
|
125 { |
|
126 TTime targetTime; |
|
127 aReason = iLbsPositionUpdateMonitor.GetPositionInfo( |
|
128 aConflictControl, |
|
129 &aPosInfo, |
|
130 sizeof(aPosInfo), |
|
131 targetTime, |
|
132 aActualTime); |
|
133 } |
|
134 |
|
135 void CLbsLocUpdateMonitor::RunL() |
|
136 { |
|
137 // Re-subscribe |
|
138 StartMonitor(); |
|
139 |
|
140 // Get the latest update |
|
141 TBool conflictControl; |
|
142 TInt posReason; |
|
143 TPositionExtendedSatelliteInfo posInfo; |
|
144 TTime actualTime; |
|
145 GetPosition(conflictControl, posReason, posInfo, actualTime); |
|
146 |
|
147 // Notify the observer |
|
148 iObserver.OnPositionUpdate(conflictControl, |
|
149 posReason, |
|
150 posInfo, |
|
151 actualTime); |
|
152 } |
|
153 |
|
154 TInt CLbsLocUpdateMonitor::RunError(TInt /*aError*/) |
|
155 { |
|
156 return KErrNone; |
|
157 } |
|
158 |
|
159 void CLbsLocUpdateMonitor::DoCancel() |
|
160 { |
|
161 iLbsPositionUpdateMonitor.CancelNotifyPositionUpdate(); |
|
162 } |
|
163 |