|
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 // |
|
15 |
|
16 #include "lbsdevloggermacros.h" |
|
17 #include "lbsnetsimgatewayhandler.h" |
|
18 #include "lbsnetsimtesthandler.h" |
|
19 #include "lbsnetsimassistancedataprovider.h" |
|
20 #include <lbspositioninfo.h> |
|
21 #include <lbs/lbslocdatasourcegpsbase.h> |
|
22 #include <lbs/test/lbsnetsimstatus.h> |
|
23 #include <lbs/test/lbsnetsimtest.h> |
|
24 #include <e32property.h> |
|
25 |
|
26 #include <s32mem.h> |
|
27 |
|
28 TLbsAssistanceDataGroup CLbsNetSimGatewayHandler::iDefaultAssistanceDataMask = EAssistanceDataReferenceTime | EAssistanceDataReferenceLocation | EAssistanceDataNavigationModel; |
|
29 |
|
30 /** |
|
31 */ |
|
32 CLbsNetSimGatewayHandler* CLbsNetSimGatewayHandler::NewL(CLbsNetSimAssistanceDataProvider& aAssistanceDataProvider) |
|
33 { |
|
34 CLbsNetSimGatewayHandler* self = new(ELeave) CLbsNetSimGatewayHandler(aAssistanceDataProvider); |
|
35 |
|
36 CleanupStack::PushL(self); |
|
37 self->ConstructL(); |
|
38 CleanupStack::Pop(self); |
|
39 |
|
40 |
|
41 return self; |
|
42 } |
|
43 |
|
44 /** |
|
45 */ |
|
46 CLbsNetSimGatewayHandler::~CLbsNetSimGatewayHandler() |
|
47 { |
|
48 iMessages.Reset(); |
|
49 iMeasurementControlLocationAssistanceData.Close(); |
|
50 } |
|
51 |
|
52 /** |
|
53 */ |
|
54 void CLbsNetSimGatewayHandler::SetTestHandler(CLbsNetSimTestHandler* aTestHandler) |
|
55 { |
|
56 iTestHandler = aTestHandler; |
|
57 } |
|
58 |
|
59 /** |
|
60 */ |
|
61 void CLbsNetSimGatewayHandler::ServiceL(const RMessage2& aMessage) |
|
62 { |
|
63 TInt function = aMessage.Function(); |
|
64 |
|
65 if ((iError == KErrNone) || |
|
66 (function == EGWNotificationMeasurementControlLocation) || |
|
67 (function == EGWNotificationMeasurementControlLocationCancel) || |
|
68 (function == EGWNotificationRegisterLcsLocation) || |
|
69 (function == EGWNotificationRegisterLcsLocationCancel) || |
|
70 (function == EGWNotificationCancelPrivacy) || |
|
71 (function == EGWNotificationCancelPrivacyCancel) || |
|
72 (function == EGWNotificationNetworkGone) || |
|
73 (function == EGWNotificationNetworkGoneCancel) || |
|
74 (function == EGWNotificationResetAssistanceData) || |
|
75 (function == EGWNotificationResetAssistanceDataCancel)) |
|
76 { |
|
77 switch (aMessage.Function()) |
|
78 { |
|
79 case EGWRegisterLcsMoLr: |
|
80 { |
|
81 HandleRegisterLcsMoLrL(aMessage); |
|
82 break; |
|
83 } |
|
84 case EGWMeasurementReportLocation: |
|
85 { |
|
86 HandleMeasurementReportLocationL(aMessage); |
|
87 break; |
|
88 } |
|
89 case EGWMeasurementReportLocationCancel: |
|
90 { |
|
91 if (!iMessageMeasurementReportLocation.IsNull()) |
|
92 { |
|
93 iMessageMeasurementReportLocation.Complete(KErrCancel); |
|
94 } |
|
95 |
|
96 aMessage.Complete(KErrNone); |
|
97 break; |
|
98 } |
|
99 case EGWReleaseLcsMoLr: |
|
100 { |
|
101 HandleReleaseLcsMoLrL(aMessage); |
|
102 break; |
|
103 } |
|
104 case EGWMeasurementControlFailure: |
|
105 { |
|
106 HandleMeasurementControlFailureL(aMessage); |
|
107 break; |
|
108 } |
|
109 case EGWRequestMoreAssistanceData: |
|
110 { |
|
111 HandleRequestMoreAssistanceDataL(aMessage); |
|
112 break; |
|
113 } |
|
114 case EGWNotificationMeasurementControlLocation: |
|
115 { |
|
116 iNotificationMeasurementControlLocation = aMessage; |
|
117 break; |
|
118 } |
|
119 case EGWNotificationMeasurementControlLocationCancel: |
|
120 { |
|
121 if (!iNotificationMeasurementControlLocation.IsNull()) |
|
122 { |
|
123 iNotificationMeasurementControlLocation.Complete(KErrCancel); |
|
124 } |
|
125 break; |
|
126 } |
|
127 case EGWNotificationRegisterLcsLocation: |
|
128 { |
|
129 iNotificationRegisterLcsLocation = aMessage; |
|
130 break; |
|
131 } |
|
132 case EGWNotificationRegisterLcsLocationCancel: |
|
133 { |
|
134 if (!iNotificationRegisterLcsLocation.IsNull()) |
|
135 { |
|
136 iNotificationRegisterLcsLocation.Complete(KErrCancel); |
|
137 } |
|
138 break; |
|
139 } |
|
140 case EGWReleaseLcsLocationNotification: |
|
141 { |
|
142 HandleReleaseLcsLocationNotifcationL(aMessage); |
|
143 break; |
|
144 } |
|
145 case EGWNotificationCancelPrivacy: |
|
146 { |
|
147 iNotificationCancelPrivacyRequest = aMessage; |
|
148 break; |
|
149 } |
|
150 case EGWNotificationCancelPrivacyCancel: |
|
151 { |
|
152 if (!iNotificationCancelPrivacyRequest.IsNull()) |
|
153 { |
|
154 iNotificationCancelPrivacyRequest.Complete(KErrCancel); |
|
155 } |
|
156 break; |
|
157 } |
|
158 case EGWNotificationNetworkGone: |
|
159 { |
|
160 iNotificationNetworkGone = aMessage; |
|
161 break; |
|
162 } |
|
163 case EGWNotificationNetworkGoneCancel: |
|
164 { |
|
165 if (!iNotificationNetworkGone.IsNull()) |
|
166 { |
|
167 iNotificationNetworkGone.Complete(KErrCancel); |
|
168 } |
|
169 break; |
|
170 } |
|
171 case EGWNotificationResetAssistanceData: |
|
172 { |
|
173 iNotificationResetAssistanceData = aMessage; |
|
174 break; |
|
175 } |
|
176 case EGWNotificationResetAssistanceDataCancel: |
|
177 { |
|
178 if (!iNotificationResetAssistanceData.IsNull()) |
|
179 { |
|
180 iNotificationResetAssistanceData.Complete(KErrCancel); |
|
181 } |
|
182 break; |
|
183 } |
|
184 default: |
|
185 { |
|
186 ASSERT(EFalse); |
|
187 User::Leave(KErrNotSupported); |
|
188 } |
|
189 } // switch |
|
190 } // if |
|
191 else |
|
192 { |
|
193 if (!iNotificationMeasurementControlLocation.IsNull() && |
|
194 ((function == EGWRegisterLcsMoLr) || |
|
195 (function == EGWRequestMoreAssistanceData))) |
|
196 { |
|
197 iNotificationMeasurementControlLocation.Complete(iError); |
|
198 FinishL(); |
|
199 } |
|
200 else |
|
201 { |
|
202 aMessage.Complete(iError); |
|
203 FinishL(); |
|
204 } |
|
205 |
|
206 if (!iErrorSticky) |
|
207 { |
|
208 iError = KErrNone; |
|
209 } // if |
|
210 } |
|
211 } |
|
212 |
|
213 |
|
214 /** |
|
215 */ |
|
216 void CLbsNetSimGatewayHandler::Connected() |
|
217 { |
|
218 LBSLOG(ELogP1, "CLbsNetSimGatewayHandler::Connected()"); |
|
219 iTestHandler->GatewayConnected(); |
|
220 } |
|
221 |
|
222 |
|
223 /** |
|
224 */ |
|
225 void CLbsNetSimGatewayHandler::Disconnected() |
|
226 { |
|
227 LBSLOG(ELogP1, "CLbsNetSimGatewayHandler::Disconnected()"); |
|
228 |
|
229 // As the server and handlers could possibly be used for a |
|
230 // second session reset some internals here |
|
231 ResetInternals(); |
|
232 |
|
233 // Empty Messages |
|
234 CTimer::Cancel(); |
|
235 while (iMessages.Count() > 0) |
|
236 { |
|
237 TRAP_IGNORE(RunL()); |
|
238 } |
|
239 |
|
240 iTestHandler->GatewayDisconnected(); |
|
241 |
|
242 // Complete any outstanding messages |
|
243 if (!iAssistanceDataToFill.IsNull()) |
|
244 { |
|
245 iAssistanceDataToFill.Complete(KErrDisconnected); |
|
246 } |
|
247 |
|
248 if (!iMessageReleaseLcsMoLr.IsNull()) |
|
249 { |
|
250 iMessageReleaseLcsMoLr.Complete(KErrDisconnected); |
|
251 } |
|
252 |
|
253 if (!iMessageMeasurementReportLocation.IsNull()) |
|
254 { |
|
255 iMessageMeasurementReportLocation.Complete(KErrDisconnected); |
|
256 } |
|
257 |
|
258 if (!iMessageMeasurementControlFailure.IsNull()) |
|
259 { |
|
260 iMessageMeasurementControlFailure.Complete(KErrDisconnected); |
|
261 } |
|
262 |
|
263 if (!iNotificationMeasurementControlLocation.IsNull()) |
|
264 { |
|
265 iNotificationMeasurementControlLocation.Complete(KErrDisconnected); |
|
266 } |
|
267 |
|
268 if (!iNotificationRegisterLcsLocation.IsNull()) |
|
269 { |
|
270 iNotificationRegisterLcsLocation.Complete(KErrDisconnected); |
|
271 } |
|
272 |
|
273 if (!iNotificationCancelPrivacyRequest.IsNull()) |
|
274 { |
|
275 iNotificationCancelPrivacyRequest.Complete(KErrDisconnected); |
|
276 } |
|
277 |
|
278 if (!iNotificationNetworkGone.IsNull()) |
|
279 { |
|
280 iNotificationNetworkGone.Complete(KErrDisconnected); |
|
281 } |
|
282 |
|
283 if (!iNotificationResetAssistanceData.IsNull()) |
|
284 { |
|
285 iNotificationResetAssistanceData.Complete(KErrDisconnected); |
|
286 } |
|
287 } |
|
288 |
|
289 /** |
|
290 */ |
|
291 void CLbsNetSimGatewayHandler::ProcessAssistanceDataL(TInt aError, |
|
292 RLbsAssistanceDataBuilderSet& aAssistanceData, |
|
293 TPositionInfo& aPosition, |
|
294 TLbsNetPosRequestQuality& aQuality) |
|
295 { |
|
296 LBSLOG(ELogP1, "CLbsNetSimGatewayHandler::ProcessAssistanceDataL()"); |
|
297 LBSLOG2(ELogP2, "AssistanceDataError = %d", aError); |
|
298 |
|
299 iAssistanceDataError = aError; |
|
300 |
|
301 // Write position to message |
|
302 TPckg<TPositionInfo> positionPkg(aPosition); |
|
303 iNotificationMeasurementControlLocation.WriteL(0, positionPkg, 0); |
|
304 |
|
305 // Write quality to message |
|
306 TPckg<TLbsNetPosRequestQuality> qualityPkg(aQuality); |
|
307 iNotificationMeasurementControlLocation.WriteL(1, qualityPkg, 0); |
|
308 |
|
309 // Write assistance data to the message |
|
310 HBufC8* buffer = HBufC8::NewLC(RLbsAssistanceDataBuilderSet::MaxExternalizedBufferSize()); |
|
311 TPtr8 des(buffer->Des()); |
|
312 RDesWriteStream stream(des); |
|
313 CleanupClosePushL(stream); |
|
314 aAssistanceData.ExternalizeL(stream); |
|
315 stream.CommitL(); |
|
316 iNotificationMeasurementControlLocation.WriteL(2, des, 0); |
|
317 CleanupStack::PopAndDestroy(2, buffer); |
|
318 |
|
319 // Fire test notification |
|
320 iMeasurementControlLocationAssistanceData.MergeL(aAssistanceData); |
|
321 iMeasurementControlLocationPosition = aPosition; |
|
322 iMeasurementControlLocationQuality = aQuality; |
|
323 |
|
324 // Complete the message |
|
325 iGotAssistanceData = ETrue; |
|
326 if (!IsActive() && |
|
327 (iMessages.Count() > 0) && |
|
328 ((iMessages.At(0) == EContinueRegisterLcsMoLr2) || |
|
329 (iMessages.At(0) == EContinueRequestMoreAssistanceData) || |
|
330 (iMessages.At(0) == EContinueMtLr))) |
|
331 { |
|
332 After(0); |
|
333 } |
|
334 } |
|
335 |
|
336 |
|
337 /** |
|
338 */ |
|
339 void CLbsNetSimGatewayHandler::SetAssistanceDataMask(TLbsAssistanceDataGroup& aMask) |
|
340 { |
|
341 iAssistanceDataMask = aMask; |
|
342 } |
|
343 |
|
344 |
|
345 /** |
|
346 */ |
|
347 void CLbsNetSimGatewayHandler::SetMoreAssistanceDataMask(TLbsAssistanceDataGroup& aMask) |
|
348 { |
|
349 iMoreAssistanceDataMask = aMask; |
|
350 } |
|
351 |
|
352 |
|
353 |
|
354 /** |
|
355 */ |
|
356 void CLbsNetSimGatewayHandler::ClearAssistanceDataMasks() |
|
357 { |
|
358 iAssistanceDataMask = iDefaultAssistanceDataMask; |
|
359 } |
|
360 |
|
361 |
|
362 /** |
|
363 */ |
|
364 void CLbsNetSimGatewayHandler::StartNetworkPrivacyRequestL(TLbsNetPosRequestPrivacy& aType, TLbsExternalRequestInfo& aRequestInfo) |
|
365 { |
|
366 // Get emergency state |
|
367 TBool emergency = EFalse; |
|
368 RProperty::Get(TUid::Uid(KLbsNetSimStatus), KLbsEmergencyStatus, emergency); |
|
369 |
|
370 if (iState == ENothing) |
|
371 { |
|
372 // Write args |
|
373 TPckg<TLbsExternalRequestInfo> requestInfoPkg(aRequestInfo); |
|
374 iNotificationRegisterLcsLocation.WriteL(0, requestInfoPkg); |
|
375 TPckg<TLbsNetPosRequestPrivacy> requestPrivacyPkg(aType); |
|
376 iNotificationRegisterLcsLocation.WriteL(1, requestPrivacyPkg); |
|
377 |
|
378 iNotificationRegisterLcsLocation.Complete(KErrNone); |
|
379 |
|
380 iState = (emergency) ? EPrivacy_E : EPrivacy; |
|
381 } |
|
382 else |
|
383 { |
|
384 if ((iMtLrOverrides) || |
|
385 (emergency && ((iState != EPrivacy_E) && (iState != EMtLr_E)))) |
|
386 { |
|
387 // Cancel what we are doing and start the MtLr |
|
388 iPrivacyType = aType; |
|
389 iPrivacyRequest = aRequestInfo; |
|
390 Cancel((emergency) ? EPrivacy_E : EPrivacy); |
|
391 } |
|
392 else |
|
393 { |
|
394 User::Leave(KErrInUse); |
|
395 } |
|
396 } |
|
397 } |
|
398 |
|
399 |
|
400 /** |
|
401 */ |
|
402 void CLbsNetSimGatewayHandler::CancelNetworkPrivacyRequestL() |
|
403 { |
|
404 if (iState != ENothing) |
|
405 { |
|
406 if (!iNotificationRegisterLcsLocation.IsNull()) |
|
407 { |
|
408 iNotificationRegisterLcsLocation.Complete(KErrCancel); |
|
409 } |
|
410 |
|
411 FinishL(); |
|
412 } |
|
413 } |
|
414 |
|
415 |
|
416 /** |
|
417 */ |
|
418 void CLbsNetSimGatewayHandler::StartNetworkLocationRequestL() |
|
419 { |
|
420 // Get emergency state |
|
421 TBool emergency = EFalse; |
|
422 RProperty::Get(TUid::Uid(KLbsNetSimStatus), KLbsEmergencyStatus, emergency); |
|
423 |
|
424 if (iState == ENothing) |
|
425 { |
|
426 iGotAssistanceData = EFalse; |
|
427 iAssistanceDataProvider.RequestAssistanceDataL(iDefaultAssistanceDataMask); |
|
428 AddMessageL(EContinueMtLr); |
|
429 |
|
430 iState = (emergency) ? EMtLr_E : EMtLr; |
|
431 } |
|
432 else |
|
433 { |
|
434 if ((iMtLrOverrides) || |
|
435 (emergency && ((iState != EPrivacy_E) && (iState != EMtLr_E)))) |
|
436 { |
|
437 // Cancel what we are doing and start the MtLr |
|
438 Cancel((emergency) ? EMtLr_E : EMtLr); |
|
439 } |
|
440 else |
|
441 { |
|
442 User::Leave(KErrInUse); |
|
443 } |
|
444 } |
|
445 } |
|
446 |
|
447 |
|
448 /** |
|
449 */ |
|
450 void CLbsNetSimGatewayHandler::CancelNetworkLocationRequestL() |
|
451 { |
|
452 if (iState != ENothing) |
|
453 { |
|
454 if (!iNotificationMeasurementControlLocation.IsNull()) |
|
455 { |
|
456 iNotificationMeasurementControlLocation.Complete(KErrCancel); |
|
457 } |
|
458 |
|
459 FinishL(); |
|
460 } |
|
461 } |
|
462 |
|
463 void CLbsNetSimGatewayHandler::SendResetAssistanceData(TLbsAssistanceDataGroup aMask) |
|
464 { |
|
465 TPckg<TLbsAssistanceDataGroup> maskPkg(aMask); |
|
466 TInt err = iNotificationResetAssistanceData.Write(0, maskPkg); |
|
467 iNotificationResetAssistanceData.Complete(err); |
|
468 } |
|
469 |
|
470 /** |
|
471 */ |
|
472 void CLbsNetSimGatewayHandler::RunL() |
|
473 { |
|
474 if (!iWaitTimeSticky) |
|
475 { |
|
476 iWaitTime = 0; |
|
477 } |
|
478 |
|
479 switch (iMessages.At(0)) |
|
480 { |
|
481 case EContinueRegisterLcsMoLr1: |
|
482 { |
|
483 // Check to see we have a valid destination |
|
484 if (CheckDestinationValidity(iRegisterLcsMoLrData->Des())) |
|
485 { |
|
486 // Notify test handler |
|
487 TInt err = iTestHandler->GatewayRegisterLcsMoLr(iRegisterLcsMoLrData->Des()); |
|
488 if (err == KErrNone) |
|
489 { |
|
490 // So MoLr or X3P |
|
491 if (iRegisterLcsMoLrData->Length() == 0) |
|
492 { |
|
493 iState = EMoLr; |
|
494 } |
|
495 else |
|
496 { |
|
497 iState = EX3P; |
|
498 } |
|
499 iSubState = EPreMrl; |
|
500 iRequestCancelled = EFalse; |
|
501 |
|
502 // Regardless of type we do same thing here => kick of request for assitance data |
|
503 iGotAssistanceData = EFalse; |
|
504 iAssistanceDataProvider.RequestAssistanceDataL(iAssistanceDataMask); |
|
505 AddMessageL(EContinueRegisterLcsMoLr2); |
|
506 } |
|
507 else |
|
508 { |
|
509 iNotificationMeasurementControlLocation.Complete(err); |
|
510 FinishL(); |
|
511 } |
|
512 } |
|
513 else |
|
514 { |
|
515 iNotificationMeasurementControlLocation.Complete(KErrArgument); |
|
516 FinishL(); |
|
517 } |
|
518 |
|
519 delete iRegisterLcsMoLrData; |
|
520 iRegisterLcsMoLrData = NULL; |
|
521 |
|
522 iMessages.Delete(0); |
|
523 break; |
|
524 } |
|
525 case EContinueRegisterLcsMoLr2: |
|
526 case EContinueRequestMoreAssistanceData: |
|
527 case EContinueMtLr: |
|
528 { |
|
529 // Has the assitance data arrived? |
|
530 if (iGotAssistanceData) |
|
531 { |
|
532 if (!iNotificationMeasurementControlLocation.IsNull() && !iRequestCancelled && (iState != ENothing)) // Could have been cancelled in the delay |
|
533 { |
|
534 TInt err = iTestHandler->GatewayProcessAssistanceDataL(iMeasurementControlLocationAssistanceData, |
|
535 iMeasurementControlLocationPosition, |
|
536 iMeasurementControlLocationQuality); |
|
537 if (err == KErrNone) |
|
538 { |
|
539 iNotificationMeasurementControlLocation.Complete(iAssistanceDataError); |
|
540 } |
|
541 else |
|
542 { |
|
543 iNotificationMeasurementControlLocation.Complete(err); |
|
544 FinishL(); |
|
545 } |
|
546 } |
|
547 |
|
548 iRequestCancelled = EFalse; |
|
549 |
|
550 iMessages.Delete(0); |
|
551 } |
|
552 break; |
|
553 } |
|
554 case EContinueMeasurementReportLocation: |
|
555 { |
|
556 // Complete the message |
|
557 if (!iMessageMeasurementReportLocation.IsNull()) |
|
558 { |
|
559 TInt err = KErrNone; |
|
560 if ((iState == EMoLr) || (iState == EX3P))// Only inform observers if MoLr or X3P |
|
561 { |
|
562 err = iTestHandler->GatewayFacilityLcsMoLrResultL(iMeasurementReportLocationStatus, iMeasurementReportLocationPosition); |
|
563 } |
|
564 iMessageMeasurementReportLocation.Complete(err); // We will complete but fireNotification should be false |
|
565 } |
|
566 |
|
567 // Reset state? |
|
568 if ((iState == EMtLr) || (iState == EMtLr_E)) |
|
569 { |
|
570 FinishL(); |
|
571 // Dont delete top message FinishL clears up for us. |
|
572 } |
|
573 else |
|
574 { |
|
575 iMessages.Delete(0); |
|
576 } |
|
577 |
|
578 iRequestCancelled = EFalse; |
|
579 break; |
|
580 } |
|
581 case EContinueReleaseLcsMoLr: |
|
582 { |
|
583 iTestHandler->GatewayReleaseLcsMoLrL(iReleaseLcsMoLrReason); |
|
584 FinishL(); |
|
585 |
|
586 // Do not delete the top messages as FinishL will have cleared up the messages. |
|
587 break; |
|
588 } |
|
589 case EContinueMeasurementControlFailure: |
|
590 { |
|
591 iTestHandler->GatewayMeasurementControlFailureL(iMeasurementControlFailureReason); |
|
592 |
|
593 if ((iState == EMtLr) || |
|
594 (iState == EMtLr_E)) |
|
595 { |
|
596 FinishL(); |
|
597 } |
|
598 else |
|
599 { |
|
600 iMessages.Delete(0); |
|
601 } |
|
602 break; |
|
603 } |
|
604 default: |
|
605 { |
|
606 ASSERT(EFalse); |
|
607 _LIT(KInternalError, "Internal Error"); |
|
608 User::Panic(KInternalError, KErrAbort); |
|
609 } |
|
610 } |
|
611 |
|
612 if (iMessages.Count() > 0) |
|
613 { |
|
614 if (!IsActive()) |
|
615 { |
|
616 if ((iMessages[0] == EContinueRegisterLcsMoLr2) || |
|
617 (iMessages[0] == EContinueRequestMoreAssistanceData) || |
|
618 (iMessages[0] == EContinueMtLr)) |
|
619 { |
|
620 if (iGotAssistanceData) |
|
621 { |
|
622 After(0); |
|
623 } |
|
624 } |
|
625 else |
|
626 { |
|
627 After(iWaitTime); |
|
628 } |
|
629 } |
|
630 } |
|
631 } |
|
632 |
|
633 |
|
634 |
|
635 |
|
636 // |
|
637 // Private |
|
638 |
|
639 |
|
640 /** |
|
641 */ |
|
642 CLbsNetSimGatewayHandler::CLbsNetSimGatewayHandler(CLbsNetSimAssistanceDataProvider& aAssistanceDataProvider) : |
|
643 CTimer(EPriorityMuchLess), iMessages(2), iState(ENothing), iAssistanceDataProvider(aAssistanceDataProvider), |
|
644 iWaitTime(0), iWaitTimeSticky(EFalse), iError(KErrNone), iErrorSticky(EFalse), |
|
645 iMtLrOverrides(EFalse), iRequestCancelled(EFalse), iStartOnComplete(ENothing) |
|
646 { |
|
647 CActiveScheduler::Add(this); |
|
648 |
|
649 iAssistanceDataMask = iDefaultAssistanceDataMask; |
|
650 iAssistanceDataProvider.SetObserver(this); |
|
651 } |
|
652 |
|
653 |
|
654 /** |
|
655 */ |
|
656 void CLbsNetSimGatewayHandler::ConstructL() |
|
657 { |
|
658 CTimer::ConstructL(); |
|
659 iMeasurementControlLocationAssistanceData.OpenL(); |
|
660 } |
|
661 |
|
662 |
|
663 /** |
|
664 */ |
|
665 void CLbsNetSimGatewayHandler::HandleRegisterLcsMoLrL(const RMessage2& aMessage) |
|
666 { |
|
667 ASSERT(iRegisterLcsMoLrData == NULL); |
|
668 |
|
669 // Read args |
|
670 TInt size = aMessage.GetDesLengthL(0); |
|
671 iRegisterLcsMoLrData = HBufC::NewL(size); |
|
672 TPtr ptr(iRegisterLcsMoLrData->Des()); |
|
673 aMessage.ReadL(0, ptr, 0); |
|
674 |
|
675 AddMessageL(EContinueRegisterLcsMoLr1); |
|
676 } |
|
677 |
|
678 |
|
679 /** |
|
680 */ |
|
681 void CLbsNetSimGatewayHandler::HandleMeasurementReportLocationL(const RMessage2& aMessage) |
|
682 { |
|
683 if (iState != ENothing) |
|
684 { |
|
685 TInt status = KErrNone; |
|
686 iMessageMeasurementReportLocation = aMessage; |
|
687 |
|
688 // Read args |
|
689 TPositionInfo position; |
|
690 TPckg<TPositionInfo> positionPkg(position); |
|
691 aMessage.ReadL(1, positionPkg, 0); |
|
692 |
|
693 // Notifications |
|
694 TInt err = iTestHandler->GatewayMeasurementReportLocationL(position); |
|
695 if (err == KErrNone) |
|
696 { |
|
697 TBool fireNotification = EFalse; |
|
698 // Write args |
|
699 if ((iState == EMoLr)||(iState == EX3P)) |
|
700 { |
|
701 fireNotification = ETrue; |
|
702 } |
|
703 |
|
704 TPckg<TInt> statusPkg(status); |
|
705 TPckg<TBool> fireNotificationPkg(fireNotification); |
|
706 aMessage.WriteL(0, statusPkg, 0); |
|
707 aMessage.WriteL(2, fireNotificationPkg, 0); |
|
708 |
|
709 // Fire the notification |
|
710 iMeasurementReportLocationStatus = status; |
|
711 iMeasurementReportLocationPosition = position; |
|
712 //iTestHandler->GatewayFacilityLcsMoLrResultL(status, position); |
|
713 |
|
714 iSubState = EPostMrl; |
|
715 AddMessageL(EContinueMeasurementReportLocation); |
|
716 } |
|
717 else |
|
718 { |
|
719 iMessageMeasurementReportLocation.Complete(err); |
|
720 FinishL(); |
|
721 } |
|
722 } |
|
723 else |
|
724 { |
|
725 aMessage.Complete(KErrNotReady); |
|
726 FinishL(); |
|
727 } |
|
728 } |
|
729 |
|
730 |
|
731 /** |
|
732 */ |
|
733 void CLbsNetSimGatewayHandler::HandleReleaseLcsMoLrL(const RMessage2& aMessage) |
|
734 { |
|
735 // A release may come in even though we have not managed to transit into a |
|
736 // state. So dont check state here. |
|
737 iMessageReleaseLcsMoLr = aMessage; |
|
738 |
|
739 // Read args |
|
740 TPckg<TInt> reasonPkg(iReleaseLcsMoLrReason); |
|
741 aMessage.ReadL(0, reasonPkg, 0); |
|
742 |
|
743 iRequestCancelled = ETrue; |
|
744 AddMessageL(EContinueReleaseLcsMoLr); |
|
745 } |
|
746 |
|
747 |
|
748 /** |
|
749 */ |
|
750 void CLbsNetSimGatewayHandler::HandleMeasurementControlFailureL(const RMessage2& aMessage) |
|
751 { |
|
752 if (iState != ENothing) |
|
753 { |
|
754 iMeasurementControlFailureReason = aMessage.Int0(); |
|
755 AddMessageL(EContinueMeasurementControlFailure); |
|
756 } |
|
757 } |
|
758 |
|
759 |
|
760 /** |
|
761 */ |
|
762 void CLbsNetSimGatewayHandler::HandleRequestMoreAssistanceDataL(const RMessage2& aMessage) |
|
763 { |
|
764 LBSLOG(ELogP1, "CLbsNetSimGatewayHandler::HandleRequestMoreAssistanceDataL()"); |
|
765 |
|
766 if (iState != ENothing) |
|
767 { |
|
768 // Read filter |
|
769 TLbsAssistanceDataGroup filter; |
|
770 TPckg<TLbsAssistanceDataGroup> filterPkg(filter); |
|
771 aMessage.ReadL(0, filterPkg, 0); |
|
772 |
|
773 // Fire notification |
|
774 TInt err = iTestHandler->GatewayRequestMoreAssistanceDataL(filter); |
|
775 if (err == KErrNone) |
|
776 { |
|
777 // Request assistance data |
|
778 iGotAssistanceData = EFalse; |
|
779 iAssistanceDataProvider.RequestAssistanceDataL(filter); |
|
780 AddMessageL(EContinueRequestMoreAssistanceData); |
|
781 } |
|
782 else |
|
783 { |
|
784 iNotificationMeasurementControlLocation.Complete(err); |
|
785 FinishL(); |
|
786 } |
|
787 } |
|
788 } |
|
789 |
|
790 |
|
791 /** |
|
792 */ |
|
793 void CLbsNetSimGatewayHandler::HandleReleaseLcsLocationNotifcationL(const RMessage2& aMessage) |
|
794 { |
|
795 // Read the response |
|
796 CLbsNetworkProtocolBase::TLbsPrivacyResponse response; |
|
797 TPckg<CLbsNetworkProtocolBase::TLbsPrivacyResponse> responsePkg(response); |
|
798 aMessage.ReadL(0, responsePkg, 0); |
|
799 |
|
800 iTestHandler->GatewayReleaseLcsLocationNotificationL(response); |
|
801 |
|
802 FinishL(); |
|
803 } |
|
804 |
|
805 |
|
806 /** |
|
807 */ |
|
808 void CLbsNetSimGatewayHandler::SetResponseTime(TInt32 aTime, TBool aSticky) |
|
809 { |
|
810 iWaitTime = aTime * 1000; // We need millisecond |
|
811 iWaitTimeSticky = aSticky; |
|
812 } |
|
813 |
|
814 |
|
815 /** |
|
816 */ |
|
817 void CLbsNetSimGatewayHandler::SetResponseError(TInt32 aError, TBool aSticky) |
|
818 { |
|
819 iError = aError; |
|
820 iErrorSticky = aSticky; |
|
821 |
|
822 LBSLOG3(ELogP2, "SetResponseError %d (sticky = %d)", aError, aSticky); |
|
823 |
|
824 if (iError == RLbsNetSimTest::KNetSimNetworkNotAvailable) |
|
825 { |
|
826 if (!iNotificationNetworkGone.IsNull()) |
|
827 { |
|
828 iNotificationNetworkGone.Complete(iError); |
|
829 if (iState != ENothing) |
|
830 { |
|
831 FinishL(); |
|
832 } |
|
833 } |
|
834 } |
|
835 } |
|
836 |
|
837 |
|
838 /** |
|
839 */ |
|
840 void CLbsNetSimGatewayHandler::AddMessageL(NextMessage aMessage) |
|
841 { |
|
842 LBSLOG2(ELogP2, "Appending message to NetSim queue: %d", aMessage); |
|
843 iMessages.AppendL(aMessage); |
|
844 |
|
845 // Is the timer already running? |
|
846 if (!IsActive()) |
|
847 { |
|
848 if ((iMessages[0] == EContinueRegisterLcsMoLr2) || |
|
849 (iMessages[0] == EContinueRequestMoreAssistanceData) || |
|
850 (iMessages[0] == EContinueMtLr)) |
|
851 { |
|
852 if (iGotAssistanceData) |
|
853 { |
|
854 After(0); |
|
855 } |
|
856 } |
|
857 else |
|
858 { |
|
859 After(iWaitTime); |
|
860 } |
|
861 } |
|
862 } |
|
863 |
|
864 |
|
865 /** |
|
866 */ |
|
867 void CLbsNetSimGatewayHandler::Cancel(MessageState aToStart) |
|
868 { |
|
869 // Store what we need to start |
|
870 iStartOnComplete = aToStart; |
|
871 |
|
872 // Cancel what we are doing |
|
873 switch (iState) |
|
874 { |
|
875 case EMoLr: |
|
876 case EX3P: |
|
877 { |
|
878 if (iSubState == EPreMrl) |
|
879 { |
|
880 iNotificationMeasurementControlLocation.Complete(KErrCancel); |
|
881 iRequestCancelled = ETrue; |
|
882 } |
|
883 else |
|
884 { |
|
885 if (iState == EMoLr) // Cant cancel an X3P here |
|
886 { |
|
887 iMessageMeasurementReportLocation.Complete(KErrCancel); |
|
888 iRequestCancelled = ETrue; |
|
889 } |
|
890 } |
|
891 break; |
|
892 } |
|
893 case EPrivacy: |
|
894 { |
|
895 TPckg<TInt> reasonPkg(KErrCancel); |
|
896 iNotificationCancelPrivacyRequest.Write(0, reasonPkg, 0); |
|
897 iNotificationCancelPrivacyRequest.Complete(KErrNone); |
|
898 break; |
|
899 } |
|
900 case EMtLr: |
|
901 { |
|
902 iNotificationMeasurementControlLocation.Complete(KErrCancel); |
|
903 break; |
|
904 } |
|
905 default: |
|
906 { |
|
907 ASSERT(EFalse); |
|
908 } |
|
909 } |
|
910 } |
|
911 |
|
912 void CLbsNetSimGatewayHandler::FinishL() |
|
913 { |
|
914 iState = ENothing; |
|
915 |
|
916 switch (iStartOnComplete) |
|
917 { |
|
918 case ENothing: |
|
919 { |
|
920 break; |
|
921 } |
|
922 case EPrivacy: |
|
923 case EPrivacy_E: |
|
924 { |
|
925 StartNetworkPrivacyRequestL(iPrivacyType, iPrivacyRequest); |
|
926 break; |
|
927 } |
|
928 case EMtLr: |
|
929 case EMtLr_E: |
|
930 { |
|
931 StartNetworkLocationRequestL(); |
|
932 break; |
|
933 } |
|
934 default: |
|
935 { |
|
936 ASSERT(EFalse); |
|
937 } |
|
938 } |
|
939 |
|
940 iStartOnComplete = ENothing; |
|
941 ResetInternals(); |
|
942 } |
|
943 |
|
944 TBool CLbsNetSimGatewayHandler::CheckDestinationValidity(TPtrC aDestination) |
|
945 { |
|
946 TInt size = aDestination.Length(); |
|
947 TBool valid = ETrue; |
|
948 for (TInt x = 0; valid && (x < size); x++) |
|
949 { |
|
950 TChar chr(aDestination[x]); |
|
951 valid = chr.IsDigit(); |
|
952 } |
|
953 |
|
954 return valid; |
|
955 } |
|
956 |
|
957 void CLbsNetSimGatewayHandler::ResetInternals() |
|
958 { |
|
959 iWaitTime = 0; |
|
960 iWaitTimeSticky = EFalse; |
|
961 iError = KErrNone; |
|
962 iErrorSticky = EFalse; |
|
963 iRequestCancelled = EFalse; |
|
964 // Cancel the timer |
|
965 CTimer::Cancel(); |
|
966 // Reset the messages. Only delete messages up to a LBSRegisterLcsMoLr. |
|
967 while (iMessages.Count() > 0) |
|
968 { |
|
969 if (iMessages[0] != EContinueRegisterLcsMoLr1) |
|
970 { |
|
971 iMessages.Delete(0); |
|
972 } |
|
973 else |
|
974 { |
|
975 break; |
|
976 } |
|
977 } |
|
978 } |