|
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 <e32std.h> |
|
20 #include "BTGPSPsyConnectionManager.h" |
|
21 #include "BTGPSPositionerExt.h" |
|
22 #include "BTGPSPsyConnectionListener.h" |
|
23 #include "BTGPSPanic.h" |
|
24 #include "BTGPSLogging.h" |
|
25 |
|
26 // EXTERNAL DATA STRUCTURES |
|
27 |
|
28 // EXTERNAL FUNCTION PROTOTYPES |
|
29 |
|
30 // CONSTANTS |
|
31 |
|
32 // Undefined tracking interval |
|
33 const TInt KTrackingIntervalUndefined = -1; |
|
34 |
|
35 // MACROS |
|
36 |
|
37 // LOCAL CONSTANTS AND MACROS |
|
38 |
|
39 // MODULE DATA STRUCTURES |
|
40 |
|
41 // LOCAL FUNCTION PROTOTYPES |
|
42 |
|
43 // FORWARD DECLARATIONS |
|
44 |
|
45 // ============================= LOCAL FUNCTIONS =============================== |
|
46 |
|
47 // ============================ MEMBER FUNCTIONS =============================== |
|
48 |
|
49 |
|
50 // ----------------------------------------------------------------------------- |
|
51 // CBTGPSPsyConnectionManager::NewL |
|
52 // ----------------------------------------------------------------------------- |
|
53 CBTGPSPsyConnectionManager* CBTGPSPsyConnectionManager::NewL() |
|
54 { |
|
55 CBTGPSPsyConnectionManager* self = new (ELeave) CBTGPSPsyConnectionManager(); |
|
56 CleanupStack::PushL(self); |
|
57 self->ConstructL(); |
|
58 CleanupStack::Pop(); |
|
59 return self; |
|
60 } |
|
61 |
|
62 // ----------------------------------------------------------------------------- |
|
63 // CBTGPSPsyConnectionManager::~CBTGPSPsyConnectionManager |
|
64 // ----------------------------------------------------------------------------- |
|
65 CBTGPSPsyConnectionManager::~CBTGPSPsyConnectionManager() |
|
66 { |
|
67 iPsyArray.Close(); |
|
68 iListenerArray.Close(); |
|
69 } |
|
70 |
|
71 |
|
72 // ----------------------------------------------------------------------------- |
|
73 // CBTGPSPsyConnectionManager::ConstructL |
|
74 // ----------------------------------------------------------------------------- |
|
75 void CBTGPSPsyConnectionManager::ConstructL() |
|
76 { |
|
77 } |
|
78 |
|
79 // ----------------------------------------------------------------------------- |
|
80 // CBTGPSPsyConnectionManager::CBTGPSPsyConnectionManager |
|
81 // C++ default constructor can NOT contain any code, that |
|
82 // might leave. |
|
83 // ----------------------------------------------------------------------------- |
|
84 CBTGPSPsyConnectionManager::CBTGPSPsyConnectionManager() |
|
85 { |
|
86 } |
|
87 |
|
88 // ----------------------------------------------------------------------------- |
|
89 // CBTGPSPsyConnectionManager::RegisterPSYL |
|
90 // ----------------------------------------------------------------------------- |
|
91 void CBTGPSPsyConnectionManager::RegisterPSYL(MBTGPSPositionerExt* aPSY) |
|
92 { |
|
93 TRACESTRING("CBTGPSPsyConnectionManager::RegisterPSYL start...") |
|
94 //Construct PSY status |
|
95 TPSYStatusStruct psyStatus; |
|
96 psyStatus.iPsy = aPSY; |
|
97 psyStatus.iLocationRequest = EFalse; |
|
98 psyStatus.iTrackingInterval = KTrackingIntervalUndefined; |
|
99 |
|
100 //Location FW garentee that PSY can't be registered more than once |
|
101 |
|
102 //Add psy status to array |
|
103 User::LeaveIfError(iPsyArray.Append(psyStatus)); |
|
104 InformListenersChange(); |
|
105 TRACESTRING("CBTGPSPsyConnectionManager::RegisterPSYL end") |
|
106 } |
|
107 |
|
108 // ----------------------------------------------------------------------------- |
|
109 // CBTGPSPsyConnectionManager::UnregisterPSY |
|
110 // ----------------------------------------------------------------------------- |
|
111 void CBTGPSPsyConnectionManager::UnregisterPSY(MBTGPSPositionerExt* aPSY) |
|
112 { |
|
113 TRACESTRING("CBTGPSPsyConnectionManager::UnregisterPSY start...") |
|
114 TInt index = FindPsy(aPSY); |
|
115 __ASSERT_DEBUG(index!=KErrNotFound, Panic(EPanicIndexOutOfRange)); |
|
116 if(index!=KErrNotFound) |
|
117 { |
|
118 iPsyArray.Remove(index); |
|
119 InformListenersChange(); |
|
120 } |
|
121 TRACESTRING("CBTGPSPsyConnectionManager::UnregisterPSY end") |
|
122 } |
|
123 |
|
124 // ----------------------------------------------------------------------------- |
|
125 // CBTGPSPsyConnectionManager::AcquireLocation |
|
126 // ----------------------------------------------------------------------------- |
|
127 void CBTGPSPsyConnectionManager::AcquireLocation(MBTGPSPositionerExt* aPSY) |
|
128 { |
|
129 TInt index = FindPsy(aPSY); |
|
130 __ASSERT_DEBUG(index!=KErrNotFound, Panic(EPanicIndexOutOfRange)); |
|
131 if(index!=KErrNotFound) |
|
132 { |
|
133 iPsyArray[index].iLocationRequest = ETrue; |
|
134 InformListenersChange(); |
|
135 } |
|
136 } |
|
137 |
|
138 // ----------------------------------------------------------------------------- |
|
139 // CBTGPSPsyConnectionManager::CancelAcquireLocation |
|
140 // ----------------------------------------------------------------------------- |
|
141 void CBTGPSPsyConnectionManager::CancelAcquireLocation(MBTGPSPositionerExt* aPSY) |
|
142 { |
|
143 TInt index = FindPsy(aPSY); |
|
144 __ASSERT_DEBUG(index!=KErrNotFound, Panic(EPanicIndexOutOfRange)); |
|
145 if(index!=KErrNotFound) |
|
146 { |
|
147 iPsyArray[index].iLocationRequest = EFalse; |
|
148 InformListenersChange(); |
|
149 } |
|
150 } |
|
151 |
|
152 // ----------------------------------------------------------------------------- |
|
153 // CBTGPSPsyConnectionManager::CompleteRequest |
|
154 // ----------------------------------------------------------------------------- |
|
155 |
|
156 void CBTGPSPsyConnectionManager::CompleteRequest( |
|
157 MBTGPSPositionerExt& aPSY, |
|
158 TInt aErr) |
|
159 { |
|
160 TRACESTRING("CBTGPSPsyConnectionManager::CompleteRequest start...") |
|
161 TInt index = FindPsy(&aPSY); |
|
162 __ASSERT_DEBUG(index!=KErrNotFound, Panic(EPanicIndexOutOfRange)); |
|
163 if(index!=KErrNotFound) |
|
164 { |
|
165 CompleteLocationRequest(index, NULL, aErr); |
|
166 } |
|
167 TRACESTRING("CBTGPSPsyConnectionManager::CompleteRequest end") |
|
168 } |
|
169 // ----------------------------------------------------------------------------- |
|
170 // CBTGPSPsyConnectionManager::CompleteAllRequests |
|
171 // ----------------------------------------------------------------------------- |
|
172 void CBTGPSPsyConnectionManager::CompleteAllRequests(TInt aErr) |
|
173 { |
|
174 TInt count = iPsyArray.Count(); |
|
175 for(TInt i=0; i<count; i++) |
|
176 { |
|
177 CompleteLocationRequest(i, NULL, aErr); |
|
178 } |
|
179 } |
|
180 |
|
181 // ----------------------------------------------------------------------------- |
|
182 // CBTGPSPsyConnectionManager::LocationFixUpdate |
|
183 // ----------------------------------------------------------------------------- |
|
184 void CBTGPSPsyConnectionManager::LocationFixUpdate(const CBTGPSFix& aFix) |
|
185 { |
|
186 TInt count = iPsyArray.Count(); |
|
187 for(TInt i=0; i<count; i++) |
|
188 { |
|
189 CompleteLocationRequest(i,&aFix, KErrNone); |
|
190 } |
|
191 } |
|
192 |
|
193 // ----------------------------------------------------------------------------- |
|
194 // CBTGPSPsyConnectionManager::Count |
|
195 // ----------------------------------------------------------------------------- |
|
196 TInt CBTGPSPsyConnectionManager::Count() const |
|
197 { |
|
198 return iPsyArray.Count(); |
|
199 } |
|
200 |
|
201 // ----------------------------------------------------------------------------- |
|
202 // CBTGPSPsyConnectionManager::LocationRequestCount |
|
203 // ----------------------------------------------------------------------------- |
|
204 TInt CBTGPSPsyConnectionManager::LocationRequestCount() const |
|
205 { |
|
206 TInt count = iPsyArray.Count(); |
|
207 TInt locationReqCount = 0; |
|
208 for(TInt i=0; i<count; i++) |
|
209 { |
|
210 if(iPsyArray[i].iLocationRequest) |
|
211 { |
|
212 locationReqCount++; |
|
213 } |
|
214 } |
|
215 return locationReqCount; |
|
216 } |
|
217 |
|
218 // ----------------------------------------------------------------------------- |
|
219 // CBTGPSPsyConnectionManager::TrackingSessionCount |
|
220 // ----------------------------------------------------------------------------- |
|
221 TInt CBTGPSPsyConnectionManager::TrackingSessionCount() const |
|
222 { |
|
223 TInt count = iPsyArray.Count(); |
|
224 TInt trackingCount = 0; |
|
225 for(TInt i=0; i<count; i++) |
|
226 { |
|
227 if(iPsyArray[i].iTrackingInterval>0) |
|
228 { |
|
229 trackingCount++; |
|
230 } |
|
231 } |
|
232 return trackingCount; |
|
233 } |
|
234 |
|
235 // ----------------------------------------------------------------------------- |
|
236 // CBTGPSPsyConnectionManager::TrackingSessionStartL |
|
237 // ----------------------------------------------------------------------------- |
|
238 void CBTGPSPsyConnectionManager::TrackingSessionStartL( |
|
239 MBTGPSPositionerExt* aPSY, |
|
240 TTimeIntervalMicroSeconds aInterval) |
|
241 { |
|
242 TInt index = FindPsy(aPSY); |
|
243 __ASSERT_DEBUG(index!=KErrNotFound, Panic(EPanicIndexOutOfRange)); |
|
244 if(index!=KErrNotFound && aInterval > 0) |
|
245 { |
|
246 iPsyArray[index].iTrackingInterval = aInterval; |
|
247 InformListenersChange(); |
|
248 } |
|
249 } |
|
250 |
|
251 // ----------------------------------------------------------------------------- |
|
252 // CBTGPSPsyConnectionManager::TrackingSessionStop |
|
253 // ----------------------------------------------------------------------------- |
|
254 void CBTGPSPsyConnectionManager::TrackingSessionStop(MBTGPSPositionerExt* aPSY) |
|
255 { |
|
256 TInt index = FindPsy(aPSY); |
|
257 if(index!=KErrNotFound) |
|
258 { |
|
259 iPsyArray[index].iTrackingInterval = KTrackingIntervalUndefined; |
|
260 InformListenersChange(); |
|
261 } |
|
262 } |
|
263 |
|
264 // ----------------------------------------------------------------------------- |
|
265 // CBTGPSPsyConnectionManager::FindPsy |
|
266 // ----------------------------------------------------------------------------- |
|
267 TInt CBTGPSPsyConnectionManager::FindPsy(MBTGPSPositionerExt* aPSY) |
|
268 { |
|
269 TInt count = iPsyArray.Count(); |
|
270 for(TInt i=0; i<count; i++) |
|
271 { |
|
272 if(iPsyArray[i].iPsy == aPSY) |
|
273 { |
|
274 return i; |
|
275 } |
|
276 } |
|
277 return KErrNotFound; |
|
278 } |
|
279 |
|
280 // ----------------------------------------------------------------------------- |
|
281 // CBTGPSPsyConnectionManager::CompleteLocationRequest |
|
282 // ----------------------------------------------------------------------------- |
|
283 void CBTGPSPsyConnectionManager::CompleteLocationRequest( |
|
284 TInt aIndex, |
|
285 const CBTGPSFix* aFix, |
|
286 TInt aErr) |
|
287 { |
|
288 if(iPsyArray[aIndex].iLocationRequest) |
|
289 { |
|
290 TBool completed = iPsyArray[aIndex].iPsy->RequestCompleteNotify(aFix, aErr); |
|
291 if(completed) |
|
292 { |
|
293 iPsyArray[aIndex].iLocationRequest = EFalse; |
|
294 InformListenersChange(); |
|
295 } |
|
296 } |
|
297 } |
|
298 |
|
299 // ----------------------------------------------------------------------------- |
|
300 // CBTGPSPsyConnectionManager::ReportStatus |
|
301 // ----------------------------------------------------------------------------- |
|
302 void CBTGPSPsyConnectionManager::ReportStatus(const TPositionModuleStatus& aStatus) |
|
303 { |
|
304 TRACESTRING("CBTGPSPsyConnectionManager::ReportStatus start...") |
|
305 TRACESTRING2("DeviceStatus=%d", aStatus.DeviceStatus()) |
|
306 TRACESTRING2("DataQuality =%d", aStatus.DataQualityStatus()) |
|
307 |
|
308 //Report status from one PSY connection only |
|
309 if(iPsyArray.Count()>0) |
|
310 { |
|
311 iPsyArray[0].iPsy->ReportStatus(aStatus); |
|
312 } |
|
313 |
|
314 TRACESTRING("CBTGPSPsyConnectionManager::ReportStatus end") |
|
315 |
|
316 } |
|
317 |
|
318 // ----------------------------------------------------------------------------- |
|
319 // CBTGPSPsyConnectionManager::AddListenerL |
|
320 // ----------------------------------------------------------------------------- |
|
321 void CBTGPSPsyConnectionManager::AddListenerL(MBTGPSPsyConnectionListener& aListener) |
|
322 { |
|
323 User::LeaveIfError(iListenerArray.Append(&aListener)); |
|
324 } |
|
325 |
|
326 // ----------------------------------------------------------------------------- |
|
327 // CBTGPSPsyConnectionManager::RemoveListener |
|
328 // ----------------------------------------------------------------------------- |
|
329 void CBTGPSPsyConnectionManager::RemoveListener(MBTGPSPsyConnectionListener& aListener) |
|
330 { |
|
331 TInt index = iListenerArray.Find(&aListener); |
|
332 if(index!=KErrNotFound) |
|
333 { |
|
334 iListenerArray.Remove(index); |
|
335 } |
|
336 } |
|
337 |
|
338 // ----------------------------------------------------------------------------- |
|
339 // CBTGPSPsyConnectionManager::InformListenersChange |
|
340 // ----------------------------------------------------------------------------- |
|
341 void CBTGPSPsyConnectionManager::InformListenersChange() |
|
342 { |
|
343 TInt count = iListenerArray.Count(); |
|
344 for(TInt i=count-1; i>=0; i--) |
|
345 { |
|
346 iListenerArray[i]->HandlePsyConnectionChange(); |
|
347 } |
|
348 } |
|
349 |
|
350 // End of File |
|
351 |
|
352 |
|
353 |