|
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 <bt_sock.h> |
|
20 #include <lbserrors.h> |
|
21 |
|
22 #include "BTGPSPanic.h" |
|
23 #include "BTGPSRequestHandler.h" |
|
24 #include "BTGPSConstantsManager.h" |
|
25 #include "BTGPSSettingManager.h" |
|
26 #include "BTGPSDeviceManager.h" |
|
27 #include "BTGPSConnectManager.h" |
|
28 #include "BTGPSMessageSender.h" |
|
29 #include "BTGPSInitManager.h" |
|
30 #include "BTGPSRequestManager.h" |
|
31 #include "BTGPSPsyConnectionManager.h" |
|
32 #include "BTGPSNokDeviceHandler.h" |
|
33 #include "BTGPSEnvChangeHandler.h" |
|
34 #include "BTGPSModuleStatusHandler.h" |
|
35 #include "BTGPSPowerManager.h" |
|
36 #include "BTGPSPositionerExt.h" |
|
37 #include "BTGPSLogging.h" |
|
38 #include "btgpsdevicelistmanager.h" |
|
39 |
|
40 // CONSTANTS |
|
41 |
|
42 // ============================ MEMBER FUNCTIONS =============================== |
|
43 |
|
44 // ----------------------------------------------------------------------------- |
|
45 // CBTGPSRequestHandler::NewL |
|
46 // Two-phased constructor. |
|
47 // ----------------------------------------------------------------------------- |
|
48 // |
|
49 CBTGPSRequestHandler* CBTGPSRequestHandler::NewL() |
|
50 { |
|
51 CBTGPSRequestHandler* self = new( ELeave ) CBTGPSRequestHandler; |
|
52 |
|
53 CleanupStack::PushL( self ); |
|
54 self->ConstructL(); |
|
55 CleanupStack::Pop(); |
|
56 |
|
57 return self; |
|
58 } |
|
59 |
|
60 // ----------------------------------------------------------------------------- |
|
61 // CBTGPSRequestHandler::CBTGPSRequestHandler |
|
62 // C++ default constructor can NOT contain any code, that |
|
63 // might leave. |
|
64 // ----------------------------------------------------------------------------- |
|
65 // |
|
66 CBTGPSRequestHandler::CBTGPSRequestHandler() |
|
67 { |
|
68 } |
|
69 |
|
70 |
|
71 // ----------------------------------------------------------------------------- |
|
72 // CBTGPSRequestHandler::ConstructL |
|
73 // Symbian 2nd phase constructor can leave. |
|
74 // ----------------------------------------------------------------------------- |
|
75 // |
|
76 void CBTGPSRequestHandler::ConstructL() |
|
77 { |
|
78 TRACESTRING("CBTGPSRequestHandler::ConstructL start...") |
|
79 //Construct Constants Mangaer |
|
80 iConstantsManager = CBTGPSConstantsManager::NewL(); |
|
81 |
|
82 //Construct the Device List Manager |
|
83 iDeviceListManager = CBTGPSDeviceListManager::NewL(); |
|
84 |
|
85 //Construct Setting Manager |
|
86 iSettingManager = CBTGPSSettingManager::NewL(); |
|
87 |
|
88 //Construct BT Device Manager |
|
89 iDeviceManager = CBTGPSDeviceManager::NewL(); |
|
90 iDeviceManager->AddListenerL(*this); |
|
91 |
|
92 //Construct connection manager |
|
93 iConnectManager = CBTGPSConnectManager::NewL( |
|
94 *iSettingManager, |
|
95 *iDeviceManager, |
|
96 *iConstantsManager, |
|
97 *iDeviceListManager); |
|
98 |
|
99 //Construct init manager |
|
100 iInitManager = CBTGPSInitManager::NewL( |
|
101 *iConnectManager, |
|
102 *iDeviceManager, |
|
103 *iSettingManager); |
|
104 |
|
105 //Construct request manager |
|
106 iRequestManager = CBTGPSRequestManager::NewL( |
|
107 *iConnectManager, |
|
108 *iConstantsManager); |
|
109 iRequestManager->AddListenerL(*this); |
|
110 |
|
111 //Construct PSY connection manager |
|
112 iPsyConnectionManager = CBTGPSPsyConnectionManager::NewL(); |
|
113 |
|
114 //Construct Nok device handler |
|
115 iNokDeviceHandler = CBTGPSNokDeviceHandler::NewL( |
|
116 *iConnectManager, |
|
117 *iSettingManager, |
|
118 *iConstantsManager, |
|
119 *iDeviceManager, |
|
120 *iDeviceListManager); |
|
121 |
|
122 //Module status handler |
|
123 iModuleStatusHandler = CBTGPSModuleStatusHandler::NewL( |
|
124 *iPsyConnectionManager, |
|
125 *iDeviceManager, |
|
126 *iRequestManager); |
|
127 |
|
128 //Power manager |
|
129 iPowerManager = CBTGPSPowerManager::NewL( |
|
130 *iConnectManager, |
|
131 *iPsyConnectionManager, |
|
132 *iDeviceManager, |
|
133 *iConstantsManager); |
|
134 |
|
135 //Construct Environment change handler |
|
136 iEnvChangeHandler = CBTGPSEnvChangeHandler::NewL(*iRequestManager); |
|
137 TRACESTRING("CBTGPSRequestHandler::ConstructL end") |
|
138 } |
|
139 |
|
140 // ----------------------------------------------------------------------------- |
|
141 // CBTGPSRequestHandler::~CBTGPSRequestHandler |
|
142 // Destructor. |
|
143 // ----------------------------------------------------------------------------- |
|
144 CBTGPSRequestHandler::~CBTGPSRequestHandler() |
|
145 { |
|
146 if(iDeviceManager != NULL) |
|
147 { |
|
148 iDeviceManager->RemoveListener(*this); |
|
149 } |
|
150 |
|
151 if(iRequestManager!=NULL) |
|
152 { |
|
153 iRequestManager->RemoveListener(*this); |
|
154 } |
|
155 |
|
156 delete iDeviceListManager; |
|
157 delete iEnvChangeHandler; |
|
158 delete iPowerManager; |
|
159 delete iModuleStatusHandler; |
|
160 delete iNokDeviceHandler; |
|
161 delete iPsyConnectionManager; |
|
162 delete iRequestManager; |
|
163 delete iInitManager; |
|
164 delete iConnectManager; |
|
165 delete iDeviceManager; |
|
166 delete iSettingManager; |
|
167 delete iConstantsManager; |
|
168 Dll::SetTls(NULL); |
|
169 } |
|
170 |
|
171 // ----------------------------------------------------------------------------- |
|
172 // CBTGPSRequestHandler::GetInstanceL |
|
173 // ----------------------------------------------------------------------------- |
|
174 // |
|
175 CBTGPSRequestHandler * CBTGPSRequestHandler::GetInstanceL() |
|
176 { |
|
177 //Have we loaded the request handler already |
|
178 if ( !Dll::Tls() ) |
|
179 { |
|
180 CBTGPSRequestHandler * theHandler = CBTGPSRequestHandler::NewL(); |
|
181 Dll::SetTls(theHandler); |
|
182 } |
|
183 |
|
184 return reinterpret_cast<CBTGPSRequestHandler*>(Dll::Tls()); |
|
185 } |
|
186 |
|
187 // ----------------------------------------------------------------------------- |
|
188 // CBTGPSRequestHandler::Instance |
|
189 // ----------------------------------------------------------------------------- |
|
190 CBTGPSRequestHandler& CBTGPSRequestHandler::Instance() |
|
191 { |
|
192 if(!Dll::Tls()) |
|
193 { |
|
194 Panic(EPanicSingletonNotConstructed); |
|
195 } |
|
196 return *(reinterpret_cast<CBTGPSRequestHandler*>(Dll::Tls())); |
|
197 } |
|
198 |
|
199 // ----------------------------------------------------------------------------- |
|
200 // CBTGPSRequestHandler::ConstantsManager |
|
201 // ----------------------------------------------------------------------------- |
|
202 CBTGPSConstantsManager& CBTGPSRequestHandler::ConstantsManager() |
|
203 { |
|
204 return *(Instance().iConstantsManager); |
|
205 } |
|
206 |
|
207 // ----------------------------------------------------------------------------- |
|
208 // CBTGPSRequestHandler::AcquireLocation |
|
209 // ----------------------------------------------------------------------------- |
|
210 void CBTGPSRequestHandler::AcquireLocation(MBTGPSPositionerExt* aPSY) |
|
211 { |
|
212 TRACESTRING("CBTGPSRequestHandler::AcquireLocation start...") |
|
213 //tries to acquire locaiton |
|
214 TRAPD(err, AcquireLocationL(aPSY)); |
|
215 if(err!=KErrNone) |
|
216 { |
|
217 //Convert error code |
|
218 if(err == KErrCouldNotConnect) |
|
219 { |
|
220 err = KPositionQualityLoss; |
|
221 } |
|
222 |
|
223 //if function leaves, then complete request with error code |
|
224 CompleteRequest(*aPSY, err); |
|
225 } |
|
226 TRACESTRING("CBTGPSRequestHandler::AcquireLocation end") |
|
227 } |
|
228 |
|
229 // ----------------------------------------------------------------------------- |
|
230 // CBTGPSRequestHandler::AcquireLocation |
|
231 // ----------------------------------------------------------------------------- |
|
232 void CBTGPSRequestHandler::AcquireLocationL(MBTGPSPositionerExt* aPSY) |
|
233 { |
|
234 //Make location request to connection manager |
|
235 iPsyConnectionManager->AcquireLocation(aPSY); |
|
236 |
|
237 //Connect to GPS |
|
238 User::LeaveIfError(iConnectManager->Connecting()); |
|
239 |
|
240 //Retrieve Fix |
|
241 iRequestManager->RetrieveFixL(); |
|
242 |
|
243 } |
|
244 |
|
245 // ----------------------------------------------------------------------------- |
|
246 // CBTGPSRequestHandler::CancelAcquireLocation |
|
247 // ----------------------------------------------------------------------------- |
|
248 void CBTGPSRequestHandler::CancelAcquireLocation( |
|
249 MBTGPSPositionerExt* aPSY) |
|
250 { |
|
251 TRACESTRING("CBTGPSRequestHandler::CancelAcquireLocation start...") |
|
252 //Cancel location request from connection manager |
|
253 iPsyConnectionManager->CancelAcquireLocation(aPSY); |
|
254 |
|
255 if(iPsyConnectionManager->LocationRequestCount() == 0) |
|
256 { |
|
257 //When no location request, stop retrieving fix |
|
258 iRequestManager->StopRetrievingFix(); |
|
259 } |
|
260 TRACESTRING("CBTGPSRequestHandler::CancelAcquireLocation end") |
|
261 } |
|
262 |
|
263 // ----------------------------------------------------------------------------- |
|
264 // CBTGPSRequestHandler::RegisterPSYL |
|
265 // ----------------------------------------------------------------------------- |
|
266 void CBTGPSRequestHandler::RegisterPSYL(MBTGPSPositionerExt* aPSY) |
|
267 { |
|
268 TRACESTRING("CBTGPSRequestHandler::RegisterPSYL start...") |
|
269 //Register the psy |
|
270 iPsyConnectionManager->RegisterPSYL(aPSY); |
|
271 |
|
272 //Reconnecting to GPS and try to recover from error states |
|
273 iConnectManager->Reconnecting(); |
|
274 |
|
275 //Set NMEA index |
|
276 aPSY->SetInitialNmeaBufferBottom( |
|
277 iRequestManager->GetPreviousNmeaBufferBottom()); |
|
278 |
|
279 TRACESTRING2("Initial NMEA Buffer Bottom: %d", |
|
280 iRequestManager->GetPreviousNmeaBufferBottom()); |
|
281 TRACESTRING("CBTGPSRequestHandler::RegisterPSYL end") |
|
282 } |
|
283 |
|
284 // ----------------------------------------------------------------------------- |
|
285 // CBTGPSRequestHandler::UnregisterPSY |
|
286 // ----------------------------------------------------------------------------- |
|
287 void CBTGPSRequestHandler::UnregisterPSY(MBTGPSPositionerExt* aPSY) |
|
288 { |
|
289 TRACESTRING("CBTGPSRequestHandler::UnregisterPSY start...") |
|
290 //Unregister PSY |
|
291 iPsyConnectionManager->UnregisterPSY(aPSY); |
|
292 |
|
293 //If no PSY is connected, then delete this instance |
|
294 if ( iPsyConnectionManager->Count() == 0 ) |
|
295 { |
|
296 //Report device status before destruction |
|
297 TPositionModuleStatus moduleStatus; |
|
298 moduleStatus.SetDataQualityStatus(TPositionModuleStatus::EDataQualityUnknown); |
|
299 moduleStatus.SetDeviceStatus(TPositionModuleStatus::EDeviceInactive); |
|
300 aPSY->ReportStatus(moduleStatus); |
|
301 |
|
302 delete this; |
|
303 } |
|
304 TRACESTRING("CBTGPSRequestHandler::UnregisterPSY end") |
|
305 } |
|
306 |
|
307 // ----------------------------------------------------------------------------- |
|
308 // CBTGPSRequestHandler::TrackingSessionStart |
|
309 // ----------------------------------------------------------------------------- |
|
310 void CBTGPSRequestHandler::TrackingSessionStartL( |
|
311 MBTGPSPositionerExt* aPSY, |
|
312 const TTimeIntervalMicroSeconds& aInterval) |
|
313 { |
|
314 TRACESTRING("CBTGPSRequestHandler::TrackingSessionStartL start...") |
|
315 iPsyConnectionManager->TrackingSessionStartL(aPSY, aInterval); |
|
316 TRACESTRING("CBTGPSRequestHandler::TrackingSessionStartL end") |
|
317 } |
|
318 |
|
319 // ----------------------------------------------------------------------------- |
|
320 // CBTGPSRequestHandler::TrackingSessionStop |
|
321 // ----------------------------------------------------------------------------- |
|
322 void CBTGPSRequestHandler::TrackingSessionStop( |
|
323 MBTGPSPositionerExt* aPSY) |
|
324 { |
|
325 TRACESTRING("CBTGPSRequestHandler::TrackingSessionStop start...") |
|
326 iPsyConnectionManager->TrackingSessionStop(aPSY); |
|
327 TRACESTRING("CBTGPSRequestHandler::TrackingSessionStop end") |
|
328 } |
|
329 |
|
330 // ----------------------------------------------------------------------------- |
|
331 // CBTGPSRequestHandler::LastLocation |
|
332 // ----------------------------------------------------------------------------- |
|
333 TInt CBTGPSRequestHandler::LastLocation( |
|
334 const CBTGPSFix*& aFix, |
|
335 const TTime& aMaxAge, |
|
336 const TBool aAcceptPartial) |
|
337 { |
|
338 return iRequestManager->LastLocation(aFix, aMaxAge, aAcceptPartial); |
|
339 } |
|
340 |
|
341 // ----------------------------------------------------------------------------- |
|
342 // CBTGPSRequestHandler::CompleteRequest |
|
343 // ----------------------------------------------------------------------------- |
|
344 void CBTGPSRequestHandler::CompleteRequest( |
|
345 MBTGPSPositionerExt& aPSY, |
|
346 TInt aErr) |
|
347 { |
|
348 iPsyConnectionManager->CompleteRequest(aPSY, aErr); |
|
349 } |
|
350 |
|
351 // ----------------------------------------------------------------------------- |
|
352 // CBTGPSRequestHandler::CompleteAllRequests |
|
353 // ----------------------------------------------------------------------------- |
|
354 void CBTGPSRequestHandler::CompleteAllRequests(TInt aErr) |
|
355 { |
|
356 iPsyConnectionManager->CompleteAllRequests(aErr); |
|
357 } |
|
358 |
|
359 // ----------------------------------------------------------------------------- |
|
360 // CBTGPSRequestHandler::HandleLocationFixAvailable |
|
361 // ----------------------------------------------------------------------------- |
|
362 // |
|
363 void CBTGPSRequestHandler::HandleLocationFixUpdate(const CBTGPSFix& aFix) |
|
364 { |
|
365 iPsyConnectionManager->LocationFixUpdate(aFix); |
|
366 |
|
367 if(iPsyConnectionManager->LocationRequestCount() == 0) |
|
368 { |
|
369 //If no location request, then stop retrieving fix |
|
370 iRequestManager->StopRetrievingFix(); |
|
371 } |
|
372 } |
|
373 |
|
374 // ----------------------------------------------------------------------------- |
|
375 // CBTGPSRequestHandler::BTDeviceStatusChanged |
|
376 // ----------------------------------------------------------------------------- |
|
377 void CBTGPSRequestHandler::BTDeviceStatusChanged( |
|
378 TInt aConnectStatus, |
|
379 TInt /*aDeviceType*/, |
|
380 TInt aErr) |
|
381 { |
|
382 if(aConnectStatus==EBTDeviceConnectError || |
|
383 aConnectStatus == EBTDeviceDisconnected ) |
|
384 { |
|
385 //When connect error or disconnected, then we complete all |
|
386 //request with error KErrQualityLoss |
|
387 if(aErr!=KErrNoMemory) |
|
388 { |
|
389 aErr = KPositionQualityLoss; |
|
390 } |
|
391 CompleteAllRequests(aErr); |
|
392 } |
|
393 } |
|
394 |
|
395 |
|
396 // End of File |
|
397 |