|
1 // Copyright (c) 2006-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 // Definition of assistance data channel component. |
|
15 // |
|
16 // |
|
17 |
|
18 /** |
|
19 @file |
|
20 @internalTechnology |
|
21 @released |
|
22 */ |
|
23 |
|
24 #include <e32base.h> |
|
25 #include <e32property.h> |
|
26 #include <lbs/lbsassistancedatabase.h> |
|
27 #include <lbs/lbsassistancedatabuilderset.h> |
|
28 |
|
29 #include <lbs/lbslocerrors.h> |
|
30 #include <lbserrors.h> |
|
31 #include "lbsassistancedatacacheapi.h" |
|
32 #include "agpschannel.h" |
|
33 #include "lbsdevloggermacros.h" |
|
34 #include "lbsnrhngmsgs.h" |
|
35 const TLbsNetSessionIdInt KDummySessionId(TUid::Uid(0xDEADBEEF), 0xDEADBEEF); |
|
36 |
|
37 // |
|
38 // CAgpsChannel |
|
39 // |
|
40 |
|
41 CAgpsChannel::CAgpsChannel(MAgpsObserver& aObserver) : |
|
42 CActive(EPriorityStandard), |
|
43 iSessionCompleteMsgBuffer(KDummySessionId, KErrNotFound), |
|
44 iSessionCompleteMsgValid(EFalse), |
|
45 iObserver(aObserver) |
|
46 { |
|
47 } |
|
48 |
|
49 CAgpsChannel::~CAgpsChannel() |
|
50 { |
|
51 Cancel(); |
|
52 iAssistanceDataMsgBuffer.Close(); |
|
53 iAssistanceDataCache.Close(); |
|
54 iAGPSChannel.Close(); |
|
55 } |
|
56 |
|
57 CAgpsChannel* CAgpsChannel::NewL(MAgpsObserver& aObserver) |
|
58 { |
|
59 CAgpsChannel* self = new (ELeave) CAgpsChannel(aObserver); |
|
60 CleanupStack::PushL(self); |
|
61 self->ConstructL(); |
|
62 CleanupStack::Pop(self); |
|
63 return self; |
|
64 } |
|
65 |
|
66 void CAgpsChannel::ConstructL() |
|
67 { |
|
68 CActiveScheduler::Add(this); |
|
69 iAssistanceDataMsgBuffer.OpenL(); |
|
70 iAssistanceDataCache.OpenL(); |
|
71 iAGPSChannel.OpenL(RLbsNetChannel::EChannelNG2AGPS, *this); |
|
72 } |
|
73 |
|
74 void CAgpsChannel::RunL() |
|
75 { |
|
76 LBSLOG(ELogP1, "CAgpsChannel::RunL():"); |
|
77 __ASSERT_DEBUG(iStatus.Int() == KErrNone, User::Panic(KLbsNRHFault, iStatus.Int())); |
|
78 |
|
79 // Session Complete has higher priority |
|
80 if (iSessionCompleteMsgValid) |
|
81 { |
|
82 iAGPSChannel.SendMessage(iSessionCompleteMsgBuffer, iStatus); |
|
83 iSessionCompleteMsgValid = EFalse; |
|
84 SetActive(); |
|
85 } |
|
86 else if (!iAssistanceDataMsgBuffer.IsEmpty()) |
|
87 { |
|
88 TLbsNetAssistanceDataResponseMsg msg(0,0); //Empty msg |
|
89 iAssistanceDataMsgBuffer.Read(msg); |
|
90 iAGPSChannel.SendMessage(msg, iStatus); |
|
91 SetActive(); |
|
92 } |
|
93 } |
|
94 |
|
95 void CAgpsChannel::DoCancel() |
|
96 { |
|
97 iAGPSChannel.CancelSendMessageNotification(); |
|
98 } |
|
99 |
|
100 TInt CAgpsChannel::RunError(TInt aError) |
|
101 { |
|
102 return aError; |
|
103 } |
|
104 |
|
105 void CAgpsChannel::SendAssistanceDataResponse(TInt aError, |
|
106 TLbsAsistanceDataGroupInt aMask, |
|
107 const RLbsAssistanceDataBuilderSet& aData) |
|
108 { |
|
109 LBSLOG(ELogP1, "CAgpsChannel::SendAssistanceDataResponse() CAgpsChannel::SendAssistanceDataResponse:"); |
|
110 TInt err = KErrNone; |
|
111 if (aError == KErrNone) |
|
112 { |
|
113 TRAP(err, SetAssistanceDataCacheL(aData)); |
|
114 __ASSERT_DEBUG(err == KErrNone, User::Panic(KLbsNRHFault, err)); |
|
115 } |
|
116 else if(aError == KPositionAssistanceDataReset) |
|
117 { |
|
118 err = iAssistanceDataCache.ResetAssistanceData(aMask); |
|
119 __ASSERT_DEBUG(err == KErrNone, User::Panic(KLbsNRHFault, err)); |
|
120 } |
|
121 |
|
122 // Do not send if writing the cache failed |
|
123 if (err == KErrNone) |
|
124 { |
|
125 TLbsNetAssistanceDataResponseMsg msg(aMask, aError); |
|
126 if (!IsActive()) |
|
127 { |
|
128 LBSLOG(ELogP2, "CAgpsChannel::SendAssistanceDataResponse() iAGPSChannel.SendMessage()"); |
|
129 iAGPSChannel.SendMessage(msg, iStatus); |
|
130 SetActive(); |
|
131 } |
|
132 else |
|
133 { |
|
134 LBSLOG(ELogP2, "CAgpsChannel::SendAssistanceDataResponse() iAssistanceDataMsgBuffer.Write()"); |
|
135 iAssistanceDataMsgBuffer.Write(msg); |
|
136 } |
|
137 } |
|
138 } |
|
139 |
|
140 void CAgpsChannel::SendSessionComplete(TInt aReason, const TLbsNetSessionIdInt& aSessionId) |
|
141 { |
|
142 TLbsNetSessionCompleteAgpsMsg msg(aSessionId, aReason); |
|
143 if (!IsActive()) |
|
144 { |
|
145 iAGPSChannel.SendMessage(msg, iStatus); |
|
146 SetActive(); |
|
147 } |
|
148 else |
|
149 { |
|
150 iSessionCompleteMsgBuffer = msg; |
|
151 iSessionCompleteMsgValid = ETrue; |
|
152 } |
|
153 } |
|
154 |
|
155 |
|
156 void CAgpsChannel::SetAssistanceDataCacheL(const RLbsAssistanceDataBuilderSet& aData) |
|
157 { |
|
158 RUEPositioningGpsAlmanacBuilder* almanacPtr; |
|
159 RUEPositioningGpsIonosphericModelBuilder* ionosphericPtr; |
|
160 RUEPositioningGpsNavigationModelBuilder* navigationPtr; |
|
161 RUEPositioningGpsReferenceTimeBuilder* referenceTimePtr; |
|
162 RUEPositioningGpsUtcModelBuilder* utcPtr; |
|
163 RUEPositioningGpsAcquisitionAssistanceBuilder* acquisitionPtr; |
|
164 RBadSatListBuilder* badSatPtr; |
|
165 RReferenceLocationBuilder* referenceLocationPtr; |
|
166 |
|
167 RLbsAssistanceDataBuilderSet& data = const_cast<RLbsAssistanceDataBuilderSet&>(aData); |
|
168 |
|
169 // Check each item in turn and publish if it is valid |
|
170 // Publish the latest assistance data into the relevant properties |
|
171 if (KErrNone == data.GetDataBuilder(almanacPtr)) |
|
172 { |
|
173 if (almanacPtr->IsDataAvailable()) |
|
174 { |
|
175 User::LeaveIfError(iAssistanceDataCache.SetAssistDataItem(EAssistanceDataAlmanac, |
|
176 *almanacPtr)); |
|
177 } |
|
178 } |
|
179 |
|
180 if (KErrNone == data.GetDataBuilder(acquisitionPtr)) |
|
181 { |
|
182 if (acquisitionPtr->IsDataAvailable()) |
|
183 { |
|
184 User::LeaveIfError(iAssistanceDataCache.SetAssistDataItem(EAssistanceDataAquisitionAssistance, |
|
185 *acquisitionPtr)); |
|
186 } |
|
187 } |
|
188 |
|
189 if (KErrNone == data.GetDataBuilder(badSatPtr)) |
|
190 { |
|
191 if (badSatPtr->IsDataAvailable()) |
|
192 { |
|
193 User::LeaveIfError(iAssistanceDataCache.SetAssistDataItem(EAssistanceDataBadSatList, |
|
194 *badSatPtr)); |
|
195 } |
|
196 } |
|
197 |
|
198 if (KErrNone == data.GetDataBuilder(navigationPtr)) |
|
199 { |
|
200 if (navigationPtr->IsDataAvailable()) |
|
201 { |
|
202 User::LeaveIfError(iAssistanceDataCache.SetAssistDataItem(EAssistanceDataNavigationModel, |
|
203 *navigationPtr)); |
|
204 } |
|
205 } |
|
206 |
|
207 if (KErrNone == data.GetDataBuilder(referenceTimePtr)) |
|
208 { |
|
209 if (referenceTimePtr->IsDataAvailable()) |
|
210 { |
|
211 User::LeaveIfError(iAssistanceDataCache.SetAssistDataItem(EAssistanceDataReferenceTime, |
|
212 *referenceTimePtr)); |
|
213 } |
|
214 } |
|
215 |
|
216 if (KErrNone == data.GetDataBuilder(ionosphericPtr)) |
|
217 { |
|
218 if (ionosphericPtr->IsDataAvailable()) |
|
219 { |
|
220 User::LeaveIfError(iAssistanceDataCache.SetAssistDataItem(EAssistanceDataIonosphericModel, |
|
221 *ionosphericPtr)); |
|
222 } |
|
223 } |
|
224 |
|
225 if (KErrNone == data.GetDataBuilder(referenceLocationPtr)) |
|
226 { |
|
227 if (referenceLocationPtr->IsDataAvailable()) |
|
228 { |
|
229 User::LeaveIfError(iAssistanceDataCache.SetAssistDataItem(EAssistanceDataReferenceLocation, |
|
230 *referenceLocationPtr)); |
|
231 } |
|
232 } |
|
233 |
|
234 if (KErrNone == data.GetDataBuilder(utcPtr)) |
|
235 { |
|
236 if (utcPtr->IsDataAvailable()) |
|
237 { |
|
238 User::LeaveIfError(iAssistanceDataCache.SetAssistDataItem(EAssistanceDataPositioningGpsUtcModel, |
|
239 *utcPtr)); |
|
240 } |
|
241 } |
|
242 } |
|
243 |
|
244 void CAgpsChannel::ProcessNetChannelMessage(RLbsNetChannel::TLbsNetChannelId aChannelId, const TLbsNetInternalMsgBase& aMessage) |
|
245 { |
|
246 __ASSERT_DEBUG(aChannelId == RLbsNetChannel::EChannelNG2AGPS, User::Panic(KLbsNGFault, ENGUnexpectedNetChannelId)); |
|
247 (void) aChannelId; |
|
248 |
|
249 const TLbsNetAssistanceDataRequestMsg& msgAssReq = static_cast<const TLbsNetAssistanceDataRequestMsg&>(aMessage); |
|
250 const TLbsNetSelfLocationRequestMsg& msgLocReq = static_cast<const TLbsNetSelfLocationRequestMsg&>(aMessage); |
|
251 const TLbsNetSelfLocationCancelMsg& msgLocCancel = static_cast<const TLbsNetSelfLocationCancelMsg&>(aMessage); |
|
252 const TLbsNetSystemStatusAdviceMsg& msgSysStat = static_cast<const TLbsNetSystemStatusAdviceMsg&>(aMessage); |
|
253 |
|
254 switch (aMessage.Type()) |
|
255 { |
|
256 case TLbsNetInternalMsgBase::EAssistanceDataRequest: |
|
257 iObserver.OnAssistanceDataRequest(msgAssReq.DataRequestMask()); |
|
258 break; |
|
259 |
|
260 case TLbsNetInternalMsgBase::ESelfLocationRequest: |
|
261 iObserver.OnSelfLocationRequest(msgLocReq.SessionId(), msgLocReq.Options()); |
|
262 break; |
|
263 |
|
264 case TLbsNetInternalMsgBase::ESelfLocationCancel: |
|
265 iObserver.OnSelfLocationCancel(msgLocCancel.SessionId(), msgLocCancel.Reason()); |
|
266 break; |
|
267 |
|
268 case TLbsNetInternalMsgBase::ESystemStatusAdvice: |
|
269 iObserver.OnSystemStatusAdvice(msgSysStat.Tracking()); |
|
270 break; |
|
271 |
|
272 default: |
|
273 __ASSERT_DEBUG(EFalse, User::Panic(KLbsNGFault, ENGUnexpectedMsgType)); |
|
274 break; |
|
275 } |
|
276 } |
|
277 |
|
278 // |
|
279 // RAssistanceDataMsgBuffer |
|
280 // |
|
281 RAssistanceDataMsgBuffer::TBufferItem::TBufferItem(): |
|
282 iValid(EFalse), |
|
283 iReason(KErrNone) |
|
284 { |
|
285 } |
|
286 |
|
287 /** |
|
288 */ |
|
289 RAssistanceDataMsgBuffer::RAssistanceDataMsgBuffer(): |
|
290 iBuffer(KAssistanceDataListCount), |
|
291 iEmpty(ETrue), |
|
292 iErrGeneric() |
|
293 { |
|
294 } |
|
295 |
|
296 /** |
|
297 */ |
|
298 void RAssistanceDataMsgBuffer::OpenL() |
|
299 { |
|
300 TBufferItem emptyItem; |
|
301 |
|
302 for (TInt i = 0; i < KAssistanceDataListCount; i++) |
|
303 { |
|
304 iBuffer.AppendL(emptyItem); |
|
305 } |
|
306 } |
|
307 /** |
|
308 */ |
|
309 void RAssistanceDataMsgBuffer::Close() |
|
310 { |
|
311 iBuffer.Close(); |
|
312 } |
|
313 /** |
|
314 */ |
|
315 void RAssistanceDataMsgBuffer::Write(const TLbsNetAssistanceDataResponseMsg& aMsg) |
|
316 { |
|
317 LBSLOG(ELogP1, "RAssistanceDataMsgBuffer::Write():"); |
|
318 TInt reason = aMsg.Reason(); |
|
319 TLbsAsistanceDataGroup mask = aMsg.DataResponseMask(); |
|
320 __ASSERT_DEBUG((mask != 0) || (mask==0 && reason<0), User::Panic(KLbsNGFault, KErrArgument)); |
|
321 if (EAssistanceDataNone == mask) |
|
322 { |
|
323 // assume something error code comes in |
|
324 iErrGeneric.iValid = ETrue; |
|
325 iErrGeneric.iReason = reason; |
|
326 } |
|
327 else |
|
328 { |
|
329 for (TInt i = 0; i < KAssistanceDataListCount; i++) |
|
330 { |
|
331 if (mask & 0x01 == 0x01) |
|
332 { |
|
333 iBuffer[i].iValid = ETrue; |
|
334 iBuffer[i].iReason = reason; |
|
335 } |
|
336 |
|
337 mask = mask >> 1; |
|
338 } |
|
339 } |
|
340 iEmpty = EFalse; |
|
341 } |
|
342 |
|
343 /** |
|
344 */ |
|
345 void RAssistanceDataMsgBuffer::Read(TLbsNetAssistanceDataResponseMsg& aMsg) |
|
346 { |
|
347 LBSLOG(ELogP1, "RAssistanceDataMsgBuffer::Read()"); |
|
348 __ASSERT_DEBUG((iBuffer.Count() != 0), User::Panic(KLbsNGFault, KErrUnderflow)); |
|
349 |
|
350 TInt reason = KErrNone; |
|
351 TInt valid = EFalse; |
|
352 TInt mask = 0; |
|
353 TInt i; //first loop |
|
354 TInt j; //second loop |
|
355 // Check error item |
|
356 if (iErrGeneric.iValid) |
|
357 { |
|
358 mask = 0; |
|
359 reason = iErrGeneric.iReason; |
|
360 iErrGeneric.iValid = EFalse; |
|
361 |
|
362 iEmpty = ETrue; |
|
363 for (i = 0; i < KAssistanceDataListCount; i++) |
|
364 { |
|
365 if (iBuffer[i].iValid) |
|
366 { |
|
367 iEmpty = EFalse; |
|
368 break; |
|
369 } |
|
370 } |
|
371 } |
|
372 else |
|
373 { |
|
374 // Find first valid item. Save the reason code |
|
375 for (i = 0; i < KAssistanceDataListCount; i++) |
|
376 { |
|
377 if (iBuffer[i].iValid) |
|
378 { |
|
379 reason = iBuffer[i].iReason; |
|
380 break; |
|
381 } |
|
382 } |
|
383 |
|
384 // Find other valid items with the same reason code |
|
385 for (j = i; j < KAssistanceDataListCount; j++) |
|
386 { |
|
387 if (iBuffer[j].iValid && (iBuffer[j].iReason == reason)) |
|
388 { |
|
389 mask = mask | (0x00000001 << j); |
|
390 iBuffer[j].iValid = EFalse; |
|
391 } |
|
392 valid = valid || iBuffer[j].iValid; |
|
393 } |
|
394 iEmpty = !valid; |
|
395 } |
|
396 |
|
397 LBSLOG2(ELogP2, "RAssistanceDataMsgBuffer::Read() iEmpty=%d", iEmpty); |
|
398 LBSLOG2(ELogP2, "RAssistanceDataMsgBuffer::Read() mask=%d", mask); |
|
399 LBSLOG2(ELogP2, "RAssistanceDataMsgBuffer::Read() reason=%d", reason); |
|
400 |
|
401 TLbsNetAssistanceDataResponseMsg msg(mask, reason); |
|
402 aMsg = msg; |
|
403 } |
|
404 |
|
405 /** |
|
406 */ |
|
407 TBool RAssistanceDataMsgBuffer::IsEmpty() const |
|
408 { |
|
409 return iEmpty; |
|
410 } |