|
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 #ifndef AGPSINTERFACEHANDLER_H_ |
|
23 #define AGPSINTERFACEHANDLER_H_ |
|
24 |
|
25 #include "lbscommoninternaldatatypes.h" |
|
26 #include <lbs/lbsnetprotocolbase.h> |
|
27 #include <lbs/lbslocdatasourcegpsbase.h> |
|
28 #include "locationupdatemonitor.h" |
|
29 #include "measurementinfomonitor.h" |
|
30 #include "lbsnetinternalapi.h" |
|
31 |
|
32 class RLbsNetworkRegistrationStatus; |
|
33 |
|
34 /** Represents TLbsNetPosRequestMethod in a single enum value. |
|
35 |
|
36 This enum is used to summarise the positioning methods contained |
|
37 in a TLbsNetPosRequestMethod into a single enum value, to make it |
|
38 easier to compare, etc. |
|
39 */ |
|
40 typedef TUint TGpsRequestMode; |
|
41 |
|
42 enum _TGpsRequestMode |
|
43 { |
|
44 // Unkown/undefined request mode |
|
45 EGpsRequestModeUnknown = 0, |
|
46 // Autonomous (basic GPS) mode. |
|
47 EGpsRequestModeAutonomous, |
|
48 // Terminal-based (Assisted GPS) mode. |
|
49 EGpsRequestModeTerminalBased, |
|
50 // Terminal-assisted (Assisted GPS) mode. |
|
51 EGpsRequestModeTerminalAssisted, |
|
52 // Simultaneous TA and TB (hybrid GPS) mode. |
|
53 EGpsRequestModeHybrid, |
|
54 // Special case where the capabilites are TA or TB and hybrid mode has arrived (when no request active) |
|
55 // and we look at the admin AGPS setting to decide whther to us TA or TB mode. |
|
56 // if admin says A or PTB then choose TB |
|
57 // if admin says PTA or ATA then choose TA |
|
58 EGpsSpecialTreatmentForHybrid |
|
59 }; |
|
60 |
|
61 |
|
62 /** States that a location request can be in. |
|
63 |
|
64 Note: This enum is used as an index into the power mode |
|
65 advice look-up table in |
|
66 CAgpsInterfaceHandler::CalculateCombinedPowerModeAdvice(), |
|
67 so if any values are added or removed from this, be |
|
68 careful to also update the look-up table or |
|
69 it will be out of sync with the enum values. |
|
70 */ |
|
71 typedef TUint TAgpsRequestState; |
|
72 |
|
73 enum _TAgpsRequestState |
|
74 { |
|
75 // Unknown/undefined request state. |
|
76 EAgpsRequestStateUnknown = 0, |
|
77 // Idle state - exists but not sent to the AGPS manager. |
|
78 EAgpsRequestStateIdle, |
|
79 // Location request is on hold, got a response but waiting to be stopped. |
|
80 EAgpsRequestStateHold, |
|
81 // Location request has been sent to the AGPS manager. |
|
82 EAgpsRequestStateActive |
|
83 }; |
|
84 |
|
85 |
|
86 /** Small data class that records the parameters for a location request. |
|
87 |
|
88 Most of the params are stored as pointers, to save memory. They |
|
89 should point to the actual data within the CLbsPrivLocFsm that |
|
90 made the location request. |
|
91 */ |
|
92 class TAgpsRequest |
|
93 { |
|
94 public: |
|
95 TAgpsRequest() : |
|
96 iSessionId(0), |
|
97 iState(EAgpsRequestStateIdle), |
|
98 iPosQuality(0), |
|
99 iGpsMode(EGpsRequestModeUnknown), |
|
100 iEndTime(0), |
|
101 iGpsTimingOfCellFramesRequested(EFalse) |
|
102 {} |
|
103 |
|
104 public: |
|
105 const TLbsNetSessionIdInt* iSessionId; |
|
106 TAgpsRequestState iState; |
|
107 const TLbsNetPosRequestQualityInt* iPosQuality; |
|
108 TGpsRequestMode iGpsMode; |
|
109 TTime iEndTime; |
|
110 TBool iGpsTimingOfCellFramesRequested; |
|
111 }; |
|
112 |
|
113 |
|
114 /** Observer interface for the privacy and location handler to use. |
|
115 |
|
116 The callbacks in this class pass data back from the AGPS interface |
|
117 back to the privacy and location handler, e.g. location updates, |
|
118 measurement data updates. |
|
119 */ |
|
120 class MAgpsInterfaceHandlerObserver |
|
121 { |
|
122 public: |
|
123 /** Called when a valid AGPS position update arrives. |
|
124 */ |
|
125 virtual void OnAgpsPositionUpdate( |
|
126 TInt aReason, |
|
127 const TPositionExtendedSatelliteInfo& aPosInfo, |
|
128 const TTime& aTimeStamp) = 0; |
|
129 |
|
130 /** Called when a measurement results update arrives. |
|
131 */ |
|
132 virtual void OnAgpsMeasurementUpdate( |
|
133 TInt aReason, |
|
134 const TPositionGpsMeasurementInfo& aPosInfo, |
|
135 const TTime& aTimeStamp) = 0; |
|
136 }; |
|
137 |
|
138 |
|
139 /** Describes the interface for setting the current X3P handler status. |
|
140 |
|
141 The X3P handler needs to tell the AGPS interface handler what state it |
|
142 is in, so that the correct power advice can be sent to the AGPS manager. |
|
143 It uses SetX3pStatus() to do that. |
|
144 */ |
|
145 class MX3pStatusHandler |
|
146 { |
|
147 public: |
|
148 /** The current state of the X3P handler. |
|
149 |
|
150 Note: This enum is used as an index into the power mode |
|
151 advice look-up table in |
|
152 CAgpsInterfaceHandler::CalculateCombinedPowerModeAdvice(), |
|
153 so if any values are added or removed from this, be |
|
154 careful to also update the look-up table or |
|
155 it will be out of sync with the enum values. |
|
156 */ |
|
157 typedef TUint TX3pStatus; |
|
158 |
|
159 enum _TX3pStatus |
|
160 { |
|
161 // No active X3P requests and no connected clients. |
|
162 EX3pStatusIdle = 0, |
|
163 // No active X3P requests but at least one connected client. |
|
164 EX3pStatusConnected, |
|
165 // One or more active X3P request(s). |
|
166 EX3pStatusActive |
|
167 }; |
|
168 |
|
169 public: |
|
170 /** Set the current X3P handler status. |
|
171 */ |
|
172 virtual void SetX3pStatus(MX3pStatusHandler::TX3pStatus aStatus) = 0; |
|
173 }; |
|
174 |
|
175 |
|
176 /** Handles the connection to the AGPS manager. |
|
177 |
|
178 This class is responsible for sending location requests, |
|
179 location cancels and power mode advice to the AGPS manager. |
|
180 |
|
181 In response, it handles listening for and reporting location |
|
182 updates and measurement results to the privacy and location |
|
183 handler. |
|
184 |
|
185 Part of the task of sending location requests is having to |
|
186 merge requests from multiple simultaneous sessions into a |
|
187 single request for the AGPS manager. Currently, 3 simultaneous |
|
188 requests would be the maximum - one each of MO-LR, X3P, MT-LR/NI-LR. |
|
189 |
|
190 When calculating the current power mode advice, the status |
|
191 of the X3P handler is merged with the status of any current |
|
192 location requests. |
|
193 */ |
|
194 class CAgpsInterfaceHandler : public CBase, |
|
195 public MLbsLocUpdateObserver, |
|
196 public MLbsMeasurementInfoObserver, |
|
197 public MX3pStatusHandler |
|
198 { |
|
199 public: |
|
200 static CAgpsInterfaceHandler* NewL(MAgpsInterfaceHandlerObserver& aObserver, |
|
201 CLbsAdmin& aAdmin, |
|
202 RLbsNetworkRegistrationStatus& aNetRegStatus); |
|
203 ~CAgpsInterfaceHandler(); |
|
204 |
|
205 public: |
|
206 TInt PreStartPositioning(const TLbsNetSessionIdInt& aSessionId,TBool aEmergency); |
|
207 TInt StartPositioning(const TLbsNetSessionIdInt& aSessionId, |
|
208 const TLbsNetPosRequestMethodInt& aMethod, |
|
209 const TLbsNetPosRequestQualityInt& aQuality, |
|
210 TBool aEmergency); |
|
211 void HoldPositioning(const TLbsNetSessionIdInt& aSessionId, |
|
212 TInt aReason); |
|
213 void StopPositioning(const TLbsNetSessionIdInt& aSessionId); |
|
214 |
|
215 TInt GetPosition(TInt& aReason, |
|
216 TPositionExtendedSatelliteInfo& aPosInfo, |
|
217 TTime& aTimeStamp); |
|
218 void GetMeasurement(TInt& aReason, |
|
219 TPositionGpsMeasurementInfo& aPosInfo, |
|
220 TTime& aTimeStamp); |
|
221 |
|
222 void GetDefaultPosMethod(TLbsNetPosRequestMethodInt& aPosMethod); |
|
223 void GetPosSpecialTeatmentForHybrid(TLbsNetPosRequestMethodInt& aPosMethod); |
|
224 |
|
225 TGpsRequestMode ConvertPosMethodToGpsRequestMode(const TLbsNetPosRequestMethodInt& aPosMethod); |
|
226 |
|
227 public: // from MX3pStatusHandler |
|
228 void SetX3pStatus(MX3pStatusHandler::TX3pStatus aStatus); |
|
229 |
|
230 protected: |
|
231 // from MLbsLocUpdateObserver |
|
232 void OnPositionUpdate( |
|
233 TBool aConflictControl, |
|
234 TInt aReason, |
|
235 const TPositionExtendedSatelliteInfo& aPosInfo, |
|
236 const TTime& aActualTime); |
|
237 |
|
238 // from MLbsMeasurementInfoObserver |
|
239 void OnMeasurementInfoUpdate( |
|
240 TInt aReason, |
|
241 const TPositionGpsMeasurementInfo& aMeasurementResults, |
|
242 const TTime& aActualTime); |
|
243 |
|
244 protected: |
|
245 CAgpsInterfaceHandler(MAgpsInterfaceHandlerObserver& aObserver, |
|
246 CLbsAdmin& aAdmin, |
|
247 RLbsNetworkRegistrationStatus& aNetRegStatus); |
|
248 |
|
249 private: |
|
250 CAgpsInterfaceHandler(); |
|
251 void ConstructL(); |
|
252 |
|
253 protected: |
|
254 void CalculateCombinedRequestQuality(); |
|
255 |
|
256 |
|
257 void ConvertGpsRequestModeToPosMethod(TGpsRequestMode aMode, TLbsNetPosRequestMethodInt& aPosMethod); |
|
258 TInt CalculateNewCombinedRequestMethod(TGpsRequestMode aCurrentGpsMode, |
|
259 TGpsRequestMode aNewRequestGpsMode, |
|
260 TGpsRequestMode& aCombinedGpsMode, |
|
261 TBool aEmergency); |
|
262 |
|
263 void CalculateCombinedPowerModeAdvice( |
|
264 TLbsPositionUpdateRequestBase::TPowerAdvice& aCombinedPowerAdvice); |
|
265 TBool CalculateCombinedTimingOfCellFramesRequested(); |
|
266 |
|
267 void SendCombinedLocationRequest(); |
|
268 |
|
269 TBool CheckPositionUpdateIsValid( |
|
270 TBool aConflictControl, |
|
271 TInt aReason, |
|
272 const TPositionExtendedSatelliteInfo& aPosInfo, |
|
273 const TTime& aActualTime); |
|
274 |
|
275 protected: |
|
276 static TBool IsSessionIdEqual( |
|
277 const TLbsNetSessionIdInt* aSessionId, |
|
278 const TAgpsRequest& aRequest); |
|
279 |
|
280 static TBool IsRequestStateEqual( |
|
281 const TAgpsRequestState* aState, |
|
282 const TAgpsRequest& aRequest); |
|
283 |
|
284 TInt AddOrUpdateRequest(const TAgpsRequest& aRequest, TBool aEmergency); |
|
285 void RemoveRequest(const TLbsNetSessionIdInt& aSessionId); |
|
286 TBool IsAnyRequestState(TAgpsRequestState aState); |
|
287 |
|
288 private: |
|
289 MAgpsInterfaceHandlerObserver& iObserver; |
|
290 CLbsAdmin& iAdmin; |
|
291 RLbsNetworkRegistrationStatus& iNetRegStatus; |
|
292 CLbsLocUpdateMonitor* iLocationUpdateMonitor; |
|
293 CLbsMeasurementInfoMonitor* iMeasurementUpdateMonitor; |
|
294 |
|
295 MX3pStatusHandler::TX3pStatus iX3pStatus; |
|
296 |
|
297 /** This is the A-GPS mode(s) supported by the plug-in A-GPS module. */ |
|
298 TPositionModuleInfoExtended::TDeviceGpsModeCapabilities iDeviceGpsModeCaps; |
|
299 |
|
300 /** Records whether we have sent a location request and are currently waiting for a response. */ |
|
301 TBool iLocationRequestActive; |
|
302 |
|
303 TLbsPositionUpdateRequestBase::TPowerAdvice iCombinedPowerModeAdvice; |
|
304 TGpsRequestMode iCombinedRequestGpsMode; |
|
305 TLbsLocRequestQualityInt iCombinedRequestQuality; |
|
306 TUint iMaxNumLocationRequests; |
|
307 RArray<TAgpsRequest> iRequests; |
|
308 }; |
|
309 |
|
310 #endif /*AGPSINTERFACEHANDLER_H_*/ |