|
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 <lbs/epos_mpositionerstatus.h> |
|
20 #include <lbssatellite.h> |
|
21 #include "EPos_CPosSimulationPositioner.h" |
|
22 #include "epossimulationpsy.hrh" |
|
23 #include "EPos_CPosControllerManager.h" |
|
24 #include "EPos_CPosControllerBase.h" |
|
25 #include <e32debug.h> |
|
26 |
|
27 // ================= MEMBER FUNCTIONS ======================= |
|
28 |
|
29 // C++ default constructor can NOT contain any code, that |
|
30 // might leave. |
|
31 // |
|
32 CPosSimulationPositioner::CPosSimulationPositioner() |
|
33 { |
|
34 |
|
35 } |
|
36 |
|
37 // EPOC default constructor can leave. |
|
38 void CPosSimulationPositioner::ConstructL( |
|
39 TAny* aConstructionParameters) |
|
40 { |
|
41 BaseConstructL(aConstructionParameters); |
|
42 |
|
43 iControllerManager = CPosControllerManager::InstanceL(); |
|
44 |
|
45 TRAPD( err, iController = &iControllerManager->ControllerL(*this) ); |
|
46 |
|
47 // Check if configuration file was not found, then report error |
|
48 if (err == KErrPathNotFound || err == KErrNotFound || |
|
49 err == KErrCorrupt || err == KErrNotSupported) |
|
50 { |
|
51 ReportStatus(TPositionModuleStatus::EDeviceError); |
|
52 } |
|
53 User::LeaveIfError(err); |
|
54 |
|
55 // Device ready to retrieve position. |
|
56 ReportStatus(TPositionModuleStatus::EDeviceReady, |
|
57 TPositionModuleStatus::EDataQualityNormal); |
|
58 } |
|
59 |
|
60 // Two-phased constructor. |
|
61 CPosSimulationPositioner* CPosSimulationPositioner::NewL( |
|
62 TAny* aConstructionParameters) |
|
63 { |
|
64 CPosSimulationPositioner* self = |
|
65 new (ELeave) CPosSimulationPositioner(); |
|
66 CleanupStack::PushL(self); |
|
67 self->ConstructL(aConstructionParameters); |
|
68 CleanupStack::Pop(self); |
|
69 return self; |
|
70 } |
|
71 |
|
72 // Destructor |
|
73 CPosSimulationPositioner::~CPosSimulationPositioner() |
|
74 { |
|
75 ReportStatus(TPositionModuleStatus::EDeviceInactive, |
|
76 TPositionModuleStatus::EDataQualityUnknown); |
|
77 iControllerManager->ReleaseInstance(*this); |
|
78 } |
|
79 |
|
80 // ---------------------------------------------------------------------------- |
|
81 // CPosSimulationPositioner::CompleteRequest |
|
82 // |
|
83 // (other items were commented in a header). |
|
84 // ---------------------------------------------------------------------------- |
|
85 // |
|
86 void CPosSimulationPositioner::CompleteRequest( |
|
87 TRequestStatus& aStatus, |
|
88 TInt aErrorCode) |
|
89 { |
|
90 // If a fix was obtained, save it |
|
91 if (aErrorCode >= 0 && iPosInfo) |
|
92 { |
|
93 //ASSERT(iPosInfo); |
|
94 ASSERT(iPosInfo->PositionClassType() & EPositionInfoClass); |
|
95 iControllerManager->SetLastFix( *static_cast<TPositionInfo*>(iPosInfo) ); |
|
96 iControllerManager->SetLastFixIsPartial( aErrorCode == KPositionPartialUpdate ); |
|
97 } |
|
98 |
|
99 TRequestStatus* status = &aStatus; |
|
100 User::RequestComplete(status, aErrorCode); |
|
101 } |
|
102 |
|
103 // ---------------------------------------------------------------------------- |
|
104 // CPosSimulationPositioner::ReportStatus |
|
105 // |
|
106 // (other items were commented in a header). |
|
107 // ---------------------------------------------------------------------------- |
|
108 // |
|
109 void CPosSimulationPositioner::ReportStatus( |
|
110 TInt aDeviceStatus, |
|
111 TInt aDataQualityStatus) |
|
112 { |
|
113 if (aDeviceStatus != KErrNotFound) |
|
114 { |
|
115 SetDeviceStatus(aDeviceStatus); |
|
116 } |
|
117 if (aDataQualityStatus != KErrNotFound) |
|
118 { |
|
119 SetDataQualityStatus(aDataQualityStatus); |
|
120 } |
|
121 |
|
122 MPositionerStatus* reportTo = PositionerStatus(); |
|
123 if (reportTo) |
|
124 { |
|
125 reportTo->ReportStatus(iModuleStatus); |
|
126 } |
|
127 } |
|
128 |
|
129 // ---------------------------------------------------------------------------- |
|
130 // CPosSimulationPositioner::PartialUpdateAllowed |
|
131 // |
|
132 // (other items were commented in a header). |
|
133 // ---------------------------------------------------------------------------- |
|
134 // |
|
135 TBool CPosSimulationPositioner::PartialUpdateAllowed() const |
|
136 { |
|
137 return IsPartialUpdateAllowed(); |
|
138 } |
|
139 |
|
140 // ---------------------------------------------------------------------------- |
|
141 // CPosSimulationPositioner::ClearAndSetDefaultPositionData |
|
142 // |
|
143 // (other items were commented in a header). |
|
144 // ---------------------------------------------------------------------------- |
|
145 // |
|
146 void CPosSimulationPositioner::ClearAndSetDefaultPositionData( |
|
147 TPositionInfoBase& aPosInfo) |
|
148 { |
|
149 if (aPosInfo.PositionClassType() & EPositionGenericInfoClass) |
|
150 { |
|
151 (void) new(&aPosInfo) TPositionInfo; |
|
152 HPositionGenericInfo& genInfo = |
|
153 static_cast<HPositionGenericInfo&> (aPosInfo); |
|
154 genInfo.ClearPositionData(); |
|
155 } |
|
156 else if (aPosInfo.PositionClassType() & EPositionSatelliteInfoClass) |
|
157 { |
|
158 (void) new(&aPosInfo) TPositionSatelliteInfo; |
|
159 } |
|
160 else if (aPosInfo.PositionClassType() & EPositionCourseInfoClass) |
|
161 { |
|
162 (void) new(&aPosInfo) TPositionCourseInfo; |
|
163 } |
|
164 else // TPositionInfo |
|
165 { |
|
166 (void) new(&aPosInfo) TPositionInfo; |
|
167 } |
|
168 |
|
169 TUid implUid = { KPosSimulationPsyImplUid }; |
|
170 aPosInfo.SetModuleId(implUid); |
|
171 aPosInfo.SetUpdateType(EPositionUpdateGeneral); |
|
172 } |
|
173 |
|
174 // ---------------------------------------------------------------------------- |
|
175 // CPosSimulationPositioner::CanUseLastFix |
|
176 // ---------------------------------------------------------------------------- |
|
177 // |
|
178 TBool CPosSimulationPositioner::CanUseLastFix() const |
|
179 { |
|
180 TBool ret(EFalse); |
|
181 TTime maxAge(0); |
|
182 GetMaxAge(maxAge); |
|
183 |
|
184 // If client has set a maximum update age |
|
185 if (maxAge.Int64() > 0) |
|
186 { |
|
187 TPosition pos; |
|
188 iControllerManager->GetLastFix().GetPosition(pos); |
|
189 |
|
190 // The fix is new enough |
|
191 // and the fix is either complete or the client accepts partial fixes |
|
192 ret = (pos.Time() >= maxAge |
|
193 && (!iControllerManager->GetLastFixIsPartial() || IsPartialUpdateAllowed())); |
|
194 } |
|
195 if(ret) |
|
196 { |
|
197 RDebug::Print(_L("CanUseLastFix TRUE")); |
|
198 } |
|
199 return ret; |
|
200 } |
|
201 |
|
202 // ---------------------------------------------------------------------------- |
|
203 // CPosSimulationPositioner::NotifyPositionUpdate |
|
204 // |
|
205 // (other items were commented in a header). |
|
206 // ---------------------------------------------------------------------------- |
|
207 // |
|
208 void CPosSimulationPositioner::NotifyPositionUpdate( |
|
209 TPositionInfoBase& aPosInfo, |
|
210 TRequestStatus& aStatus) |
|
211 { |
|
212 ClearAndSetDefaultPositionData(aPosInfo); |
|
213 |
|
214 // Use the last fix obtained if possible, otherwise get a new fix |
|
215 if (CanUseLastFix()) |
|
216 { |
|
217 ASSERT(aPosInfo.PositionClassType() & EPositionInfoClass); |
|
218 TPositionInfo& pos = *static_cast<TPositionInfo*>(&aPosInfo); |
|
219 pos = iControllerManager->GetLastFix(); |
|
220 iPosInfo = NULL; |
|
221 // Complete the request with the correct status |
|
222 TInt status(KErrNone); |
|
223 if (iControllerManager->GetLastFixIsPartial()) |
|
224 { |
|
225 status = KPositionPartialUpdate; |
|
226 } |
|
227 CompleteRequest(aStatus, status); |
|
228 } |
|
229 else |
|
230 { |
|
231 iPosInfo = &aPosInfo; |
|
232 iController->NotifyPositionUpdate(aPosInfo, aStatus, *this); |
|
233 } |
|
234 } |
|
235 |
|
236 // ---------------------------------------------------------------------------- |
|
237 // CPosSimulationPositioner::CancelNotifyPositionUpdate |
|
238 // |
|
239 // (other items were commented in a header). |
|
240 // ---------------------------------------------------------------------------- |
|
241 // |
|
242 void CPosSimulationPositioner::CancelNotifyPositionUpdate() |
|
243 { |
|
244 iController->CancelNotifyPositionUpdate(*this); |
|
245 } |
|
246 |
|
247 // ---------------------------------------------------------------------------- |
|
248 // CPosSimulationPositioner::SetDeviceStatus |
|
249 // |
|
250 // (other items were commented in a header). |
|
251 // ---------------------------------------------------------------------------- |
|
252 // |
|
253 void CPosSimulationPositioner::SetDeviceStatus( |
|
254 TPositionModuleStatus::TDeviceStatus aStatus) |
|
255 { |
|
256 iModuleStatus.SetDeviceStatus(aStatus); |
|
257 } |
|
258 |
|
259 // ---------------------------------------------------------------------------- |
|
260 // CPosSimulationPositioner::SetDataQualityStatus |
|
261 // |
|
262 // (other items were commented in a header). |
|
263 // ---------------------------------------------------------------------------- |
|
264 // |
|
265 void CPosSimulationPositioner::SetDataQualityStatus( |
|
266 TPositionModuleStatus::TDataQualityStatus aStatus) |
|
267 { |
|
268 iModuleStatus.SetDataQualityStatus(aStatus); |
|
269 } |
|
270 |
|
271 // End of File |