|
1 // Copyright (c) 2007-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 // Privacy handler for Location Update requests |
|
15 // |
|
16 // |
|
17 |
|
18 #include <e32base.h> |
|
19 |
|
20 #include <lbs/lbslocclasstypes.h> |
|
21 #include "lbsdevloggermacros.h" |
|
22 |
|
23 #include "privacyadvancednotifierhandler.h" |
|
24 #include "EPos_CPosPrivManager.h" |
|
25 #include "EPos_CPosDialogCtrl.h" |
|
26 #include "EPos_PosCommonPrivacyResources.h" |
|
27 |
|
28 |
|
29 // Special 'invalid session' SessionId. |
|
30 const TLbsNetSessionIdInt KInvalidSessionId(TUid::Uid(0), 0); |
|
31 |
|
32 // |
|
33 // CPrivacyAdvancedRequest |
|
34 // |
|
35 |
|
36 CPrivacyAdvancedRequest* CPrivacyAdvancedRequest::NewL() |
|
37 { |
|
38 CPrivacyAdvancedRequest* self = new (ELeave) CPrivacyAdvancedRequest; |
|
39 return self; |
|
40 } |
|
41 |
|
42 // |
|
43 // CPrivacyAdvancedNotifierHandler |
|
44 // |
|
45 CPrivacyAdvancedNotifierHandler::CPrivacyAdvancedNotifierHandler(CLbsAdmin& aLbsAdmin, |
|
46 RLbsNetworkRegistrationStatus& aNetRegStatus) : |
|
47 CPrivacyHandler(aLbsAdmin, aNetRegStatus) |
|
48 { |
|
49 CActiveScheduler::Add(this); |
|
50 iHighestSessionId = KInvalidSessionId; |
|
51 } |
|
52 |
|
53 CPrivacyAdvancedNotifierHandler* CPrivacyAdvancedNotifierHandler::NewL(CLbsAdmin& aLbsAdmin, |
|
54 RLbsNetworkRegistrationStatus& aNetRegStatus) |
|
55 { |
|
56 CPrivacyAdvancedNotifierHandler* self = new (ELeave) CPrivacyAdvancedNotifierHandler(aLbsAdmin, |
|
57 aNetRegStatus); |
|
58 CleanupStack::PushL(self); |
|
59 self->ConstructL(); |
|
60 CleanupStack::Pop(self); |
|
61 return(self); |
|
62 } |
|
63 |
|
64 /** |
|
65 */ |
|
66 void CPrivacyAdvancedNotifierHandler::ConstructL() |
|
67 { |
|
68 User::LeaveIfError(PosCommonPrivacyResources::Install()); |
|
69 iPrivacyDialogController = CPosDialogCtrl::InstanceL(); |
|
70 PosCommonPrivacyResources::SetDialogCtrl(iPrivacyDialogController); |
|
71 iPrivacyManager = CPosPrivManager::NewL(); |
|
72 } |
|
73 |
|
74 /** |
|
75 */ |
|
76 CPrivacyAdvancedNotifierHandler::~CPrivacyAdvancedNotifierHandler() |
|
77 { |
|
78 Cancel(); |
|
79 iRequestBuffer.ResetAndDestroy(); |
|
80 delete iPrivacyManager; |
|
81 delete iPrivacyDialogController; |
|
82 PosCommonPrivacyResources::Uninstall(); |
|
83 } |
|
84 |
|
85 /** |
|
86 */ |
|
87 void CPrivacyAdvancedNotifierHandler::RunL() |
|
88 { |
|
89 // Send response to current privacy request. |
|
90 SendPrivacyResponse(); |
|
91 |
|
92 // If there is another request in the buffer, send it. |
|
93 SendNextPrivacyRequest(); |
|
94 } |
|
95 |
|
96 /** |
|
97 */ |
|
98 void CPrivacyAdvancedNotifierHandler::DoCancel() |
|
99 { |
|
100 // Cancel the verification dialog if it is |
|
101 // currently being displayed. |
|
102 if (iRequestBuffer.Count() > 0) |
|
103 { |
|
104 CPrivacyAdvancedRequest* requestData = iRequestBuffer[0]; |
|
105 if (requestData->RequestPrivacy().RequestAdvice() |
|
106 == TLbsNetPosRequestPrivacyInt::ERequestAdviceVerify) |
|
107 { |
|
108 iPrivacyManager->CancelVerify(); |
|
109 } |
|
110 |
|
111 // Remove the cancelled session. |
|
112 iRequestBuffer.Remove(0); |
|
113 delete requestData; |
|
114 } |
|
115 } |
|
116 |
|
117 /** |
|
118 */ |
|
119 void CPrivacyAdvancedNotifierHandler::RegisterObserver(MPrivacyHandlerObserver* aObserver) |
|
120 { |
|
121 iObserver = aObserver; |
|
122 } |
|
123 |
|
124 /** Receive a privacy request from the network and pass on to the Q&N notifier. |
|
125 |
|
126 This function receives the privacy request from the network and converts |
|
127 it into a verify or notify request for the Privacy Q&N API. |
|
128 |
|
129 Currently only one active request is supported. If a new request arrives |
|
130 when the previous one is still running, then the previous request |
|
131 will be cancelled before the new request is sent to the Q&N API. |
|
132 |
|
133 */ |
|
134 void CPrivacyAdvancedNotifierHandler::ProcessNetworkLocationRequest(TLbsNetSessionIdInt aSessionId, |
|
135 const TLbsNetworkEnumInt::TLbsNetProtocolServiceInt /*aSessionType*/, |
|
136 const TLbsExternalRequestInfo& aRequestInfo, |
|
137 const TLbsNetPosRequestPrivacyInt& aNetPosRequestPrivacy, |
|
138 TBool aIsEmergency) |
|
139 |
|
140 { |
|
141 // TODO: |
|
142 // 1) Convert the data types into the data types used by the CPosPrivManager |
|
143 // 2) Store the data in a single class, tied to the session Id? |
|
144 // 3) Issue a VerifyL or NotifyL as required |
|
145 // 3) Set this AO as 'active' and wait for RunL to be triggered. |
|
146 |
|
147 |
|
148 // Record the highest session Id so far. |
|
149 // We need this in case we need to check if a new request |
|
150 // is actually a repeat of an old request. |
|
151 if (aSessionId.SessionNum() > iHighestSessionId.SessionNum()) |
|
152 { |
|
153 iHighestSessionId = aSessionId; |
|
154 } |
|
155 |
|
156 // Add this new request to the buffer |
|
157 BufferPrivacyRequest(aSessionId, aRequestInfo, aNetPosRequestPrivacy, aIsEmergency); |
|
158 |
|
159 // If there is no current request outstanding, send it now |
|
160 if (!IsPrivacyRequestActive()) |
|
161 { |
|
162 SendNextPrivacyRequest(); |
|
163 } |
|
164 } |
|
165 |
|
166 /** |
|
167 */ |
|
168 void CPrivacyAdvancedNotifierHandler::ProcessNetworkPositionUpdate(TLbsNetSessionIdInt /*aSessionId*/, |
|
169 const TPositionInfo& /*aPosInfo*/) |
|
170 { |
|
171 // Position updates are not supported by the Privacy Q&N API so ignore |
|
172 // this position update. |
|
173 } |
|
174 |
|
175 |
|
176 /** |
|
177 */ |
|
178 void CPrivacyAdvancedNotifierHandler::ProcessRequestComplete(TLbsNetSessionIdInt aSessionId, |
|
179 TInt aReason) |
|
180 { |
|
181 // How we interpret this session complete depends on what |
|
182 // state the request for aSessionId is in, and the value |
|
183 // of aReason. |
|
184 // |
|
185 // Generally: |
|
186 // KErrNone - Should only happen after we've sent a reply. |
|
187 // KErrCancel - Generic cancel for a session, usually happens before |
|
188 // we have sent a reply (but not always). |
|
189 // KErrTimedOut - Cancel because of a network-side timeout. Usually |
|
190 // happens before we have sent a reply (but not always). |
|
191 // Other error code - Completely unexpected - at the moment these are |
|
192 // ignored and the session is ended without any other |
|
193 // action. |
|
194 TInt index = iRequestBuffer.Find(aSessionId, CPrivacyAdvancedRequest::IsSessionIdEqual); |
|
195 if (index >= 0) |
|
196 { |
|
197 CPrivacyAdvancedRequest* request(iRequestBuffer[index]); |
|
198 request->SetState(CPrivacyRequest::EPrivReqStateCompleted); |
|
199 |
|
200 if (index == 0) |
|
201 { |
|
202 // If the request is the currently active one then |
|
203 // we have to cancel the dialog. |
|
204 switch (aReason) |
|
205 { |
|
206 case KErrNone: |
|
207 { |
|
208 // Normal end of a session. Don't need to send anything more |
|
209 // to the Q&N API. |
|
210 break; |
|
211 } |
|
212 case KErrTimedOut: |
|
213 { |
|
214 if (request->RequestPrivacy().RequestAdvice() == TLbsNetPosRequestPrivacyInt::ERequestAdviceVerify) |
|
215 { |
|
216 // Network-side timeout, tell the Q&N API about this. |
|
217 TRAP_IGNORE(iPrivacyManager->CancelVerifyL(EPosCancelReasonTimeout)); |
|
218 } |
|
219 break; |
|
220 } |
|
221 case KErrCancel: |
|
222 { |
|
223 if (request->RequestPrivacy().RequestAdvice() == TLbsNetPosRequestPrivacyInt::ERequestAdviceVerify) |
|
224 { |
|
225 // Generic network-side cancel, tell the Q&N API about this. |
|
226 iPrivacyManager->CancelVerify(); |
|
227 } |
|
228 break; |
|
229 } |
|
230 default: |
|
231 { |
|
232 // Ignore any other error code. Don't send |
|
233 // anything else to the Q&N API. |
|
234 break; |
|
235 } |
|
236 } |
|
237 |
|
238 // Delete the cancelled request |
|
239 iRequestBuffer.Remove(index); |
|
240 delete request; |
|
241 } |
|
242 else |
|
243 { |
|
244 // If the request has not yet been sent to the dialog, |
|
245 // then what to do will depend on what type of privacy |
|
246 // request it is. |
|
247 // |
|
248 // Notification: Just remove it from the list. |
|
249 // Verification: If the timeout action is 'accept', turn it into |
|
250 // a notification for the user. Else just remove. |
|
251 switch (request->RequestPrivacy().RequestAdvice()) |
|
252 { |
|
253 case TLbsNetPosRequestPrivacyInt::ERequestAdviceNotify: |
|
254 { |
|
255 // Delete the cancelled request |
|
256 iRequestBuffer.Remove(index); |
|
257 delete request; |
|
258 break; |
|
259 } |
|
260 case TLbsNetPosRequestPrivacyInt::ERequestAdviceVerify: |
|
261 { |
|
262 if (request->RequestPrivacy().RequestAction() == TLbsNetPosRequestPrivacyInt::ERequestActionAllow) |
|
263 { |
|
264 // Change the request into a notification and move to after any pending verifications |
|
265 TLbsNetPosRequestPrivacyInt privacy(request->RequestPrivacy()); |
|
266 privacy.SetRequestAdvice(TLbsNetPosRequestPrivacyInt::ERequestAdviceNotify); |
|
267 request->SetRequestPrivacy(privacy); |
|
268 |
|
269 TPosRequestData data(request->RequestData()); |
|
270 data.iRequestDecision = EPosDecisionAccepted; |
|
271 data.iNotificationReason = EPosDecisionByRequestSource; |
|
272 request->SetRequestData(data); |
|
273 |
|
274 DeferNotification(index); |
|
275 } |
|
276 else |
|
277 { |
|
278 // Delete the cancelled request |
|
279 iRequestBuffer.Remove(index); |
|
280 delete request; |
|
281 } |
|
282 break; |
|
283 } |
|
284 default: |
|
285 { |
|
286 // Should never get here |
|
287 break; |
|
288 } |
|
289 } |
|
290 } |
|
291 } |
|
292 |
|
293 // If there is no current request outstanding, start the next one. |
|
294 if (!IsPrivacyRequestActive()) |
|
295 { |
|
296 SendNextPrivacyRequest(); |
|
297 } |
|
298 |
|
299 CPrivacyAdvancedRequest* activeRequest = NULL; |
|
300 if (iRequestBuffer.Count() > 0) |
|
301 { |
|
302 activeRequest = iRequestBuffer[0]; |
|
303 } |
|
304 |
|
305 if (activeRequest |
|
306 && aSessionId == activeRequest->SessionId()) |
|
307 { |
|
308 |
|
309 |
|
310 // Delete the cancelled request |
|
311 iRequestBuffer.Remove(0); |
|
312 delete activeRequest; |
|
313 |
|
314 // Start the next request in the buffer |
|
315 SendNextPrivacyRequest(); |
|
316 } |
|
317 } |
|
318 |
|
319 /** |
|
320 */ |
|
321 void CPrivacyAdvancedNotifierHandler::OnRespondNetworkLocationRequest(const TLbsNetSessionIdInt& /* aRequestId */, |
|
322 TLbsNetworkEnumInt::TLbsPrivacyResponseInt /* aRequestResult */, |
|
323 TInt /*aResponseReason*/) |
|
324 { |
|
325 // Unused for advanced notifier |
|
326 } |
|
327 |
|
328 /** |
|
329 */ |
|
330 void CPrivacyAdvancedNotifierHandler::OnCancelNetworkLocationRequest(const TLbsNetSessionIdInt& /*aRequestId*/) |
|
331 { |
|
332 // Unused for advanced notifier |
|
333 } |
|
334 |
|
335 /** |
|
336 */ |
|
337 void CPrivacyAdvancedNotifierHandler::SetServerObserver(MLbsSessionObserver* /*aNrhServer*/) |
|
338 { |
|
339 // Unused for advanced notifier |
|
340 } |
|
341 |
|
342 TBool CPrivacyAdvancedNotifierHandler::IsPrivacyRequestActive() |
|
343 { |
|
344 return (IsActive()); |
|
345 } |
|
346 |
|
347 void CPrivacyAdvancedNotifierHandler::SendNextPrivacyRequest() |
|
348 { |
|
349 if (iRequestBuffer.Count() == 0) |
|
350 { |
|
351 // No request to actually send! |
|
352 return; |
|
353 } |
|
354 |
|
355 // Send a verify or notify request to the Q&N API depending on the |
|
356 // RequestAdvice(). |
|
357 CPrivacyAdvancedRequest* activeRequest = iRequestBuffer[0]; |
|
358 switch (activeRequest->RequestPrivacy().RequestAdvice()) |
|
359 { |
|
360 case TLbsNetPosRequestPrivacyInt::ERequestAdviceNotify: |
|
361 { |
|
362 SendNotificationRequest(*activeRequest); |
|
363 break; |
|
364 } |
|
365 case TLbsNetPosRequestPrivacyInt::ERequestAdviceVerify: |
|
366 { |
|
367 SendVerificationRequest(*activeRequest); |
|
368 break; |
|
369 } |
|
370 case TLbsNetPosRequestPrivacyInt::ERequestAdviceSilent: |
|
371 { |
|
372 // The request was for no notification/no verification. |
|
373 // These are handled as per the admin setting. |
|
374 CLbsAdmin::TExternalLocateService externalLocate(CLbsAdmin::EExternalLocateOff); |
|
375 GetExternalLocateAdminSetting(activeRequest->SessionType(), externalLocate); |
|
376 |
|
377 switch (externalLocate) |
|
378 { |
|
379 case CLbsAdmin::EExternalLocateOn: |
|
380 { |
|
381 // Accept the request with no notification/verification. |
|
382 iObserver->OnRespondNetworkLocationRequest( |
|
383 activeRequest->SessionId(), |
|
384 TLbsNetworkEnumInt::EPrivacyResponseAccepted, |
|
385 KErrArgument); |
|
386 break; |
|
387 } |
|
388 case CLbsAdmin::EExternalLocateOnButAlwaysVerify: |
|
389 { |
|
390 SendVerificationRequest(*activeRequest); |
|
391 break; |
|
392 } |
|
393 |
|
394 case CLbsAdmin::EExternalLocateOffButNotify: |
|
395 { |
|
396 // Notify the user about the request. |
|
397 SendNotificationRequest(*activeRequest); |
|
398 // Reject the request. |
|
399 iObserver->OnRespondNetworkLocationRequest( |
|
400 activeRequest->SessionId(), |
|
401 TLbsNetworkEnumInt::EPrivacyResponseRejected, |
|
402 KErrNotSupported); |
|
403 break; |
|
404 } |
|
405 |
|
406 case CLbsAdmin::EExternalLocateOff: |
|
407 case CLbsAdmin::EExternalLocateUnknown: |
|
408 default: |
|
409 { |
|
410 // This advice type is not supported. |
|
411 // Our response is to reject such requests. |
|
412 iObserver->OnRespondNetworkLocationRequest( |
|
413 activeRequest->SessionId(), |
|
414 TLbsNetworkEnumInt::EPrivacyResponseRejected, |
|
415 KErrNotSupported); |
|
416 break; |
|
417 } |
|
418 } |
|
419 |
|
420 break; |
|
421 } |
|
422 case TLbsNetPosRequestPrivacyInt::ERequestAdviceStealth: |
|
423 { |
|
424 // This advice type is not supported. Our response |
|
425 // is to reject such requests. |
|
426 iObserver->OnRespondNetworkLocationRequest( |
|
427 activeRequest->SessionId(), |
|
428 TLbsNetworkEnumInt::EPrivacyResponseRejected, |
|
429 KErrNotSupported); |
|
430 break; |
|
431 } |
|
432 case TLbsNetPosRequestPrivacyInt::ERequestAdviceNotUsed: |
|
433 default: |
|
434 { |
|
435 // These Advice types are not expected arguments. |
|
436 // Our response is to reject them. |
|
437 iObserver->OnRespondNetworkLocationRequest( |
|
438 activeRequest->SessionId(), |
|
439 TLbsNetworkEnumInt::EPrivacyResponseRejected, |
|
440 KErrArgument); |
|
441 break; |
|
442 } |
|
443 } |
|
444 } |
|
445 |
|
446 /** |
|
447 * Issues the notification request. |
|
448 */ |
|
449 void CPrivacyAdvancedNotifierHandler::SendNotificationRequest(CPrivacyAdvancedRequest& aActiveRequest) |
|
450 { |
|
451 TRAPD(err, iPrivacyManager->NotifyL( |
|
452 iStatus, |
|
453 aActiveRequest.RequestInfo(), |
|
454 aActiveRequest.RequestData(), |
|
455 aActiveRequest.SessionId().SessionNum())); |
|
456 if (KErrNone == err) |
|
457 { |
|
458 // Set AO active and wait for result. |
|
459 SetActive(); |
|
460 } |
|
461 else |
|
462 { |
|
463 // Error starting the notifier; reject the privacy request. |
|
464 iObserver->OnRespondNetworkLocationRequest( |
|
465 aActiveRequest.SessionId(), |
|
466 TLbsNetworkEnumInt::EPrivacyResponseRejected, |
|
467 KErrGeneral); |
|
468 } |
|
469 } |
|
470 |
|
471 /** |
|
472 * Issues the verification request. |
|
473 */ |
|
474 void CPrivacyAdvancedNotifierHandler::SendVerificationRequest(CPrivacyAdvancedRequest& aActiveRequest) |
|
475 { |
|
476 TRAPD(err, iPrivacyManager->VerifyL( |
|
477 iStatus, |
|
478 aActiveRequest.RequestInfo(), |
|
479 aActiveRequest.RequestData(), |
|
480 aActiveRequest.SessionId().SessionNum())); |
|
481 if (KErrNone == err) |
|
482 { |
|
483 // Set AO active and wait for result. |
|
484 SetActive(); |
|
485 } |
|
486 else |
|
487 { |
|
488 // Error starting the notifier; reject the privacy request. |
|
489 iObserver->OnRespondNetworkLocationRequest( |
|
490 aActiveRequest.SessionId(), |
|
491 TLbsNetworkEnumInt::EPrivacyResponseRejected, |
|
492 KErrGeneral); |
|
493 } |
|
494 } |
|
495 |
|
496 void CPrivacyAdvancedNotifierHandler::SendPrivacyResponse() |
|
497 { |
|
498 if (iRequestBuffer.Count() == 0) |
|
499 { |
|
500 return; |
|
501 } |
|
502 |
|
503 // Process the result from a notification or verification request. |
|
504 CPrivacyAdvancedRequest* activeRequest = iRequestBuffer[0]; |
|
505 if (activeRequest->State() != CPrivacyRequest::EPrivReqStateCompleted) |
|
506 { |
|
507 switch (activeRequest->RequestPrivacy().RequestAdvice()) |
|
508 { |
|
509 case TLbsNetPosRequestPrivacyInt::ERequestAdviceVerify: |
|
510 { |
|
511 // Convert the response into the internal LBS enum |
|
512 TLbsNetworkEnumInt::TLbsPrivacyResponseInt response; |
|
513 if (iStatus.Int() == KErrNone) |
|
514 { |
|
515 response = TLbsNetworkEnumInt::EPrivacyResponseAccepted; |
|
516 } |
|
517 else |
|
518 { |
|
519 response = TLbsNetworkEnumInt::EPrivacyResponseRejected; |
|
520 } |
|
521 |
|
522 // Pass the verification response to the network. |
|
523 iObserver->OnRespondNetworkLocationRequest( |
|
524 activeRequest->SessionId(), response, KErrNone); |
|
525 break; |
|
526 } |
|
527 case TLbsNetPosRequestPrivacyInt::ERequestAdviceNotify: |
|
528 { |
|
529 // Return the default response for notify requests |
|
530 TLbsNetworkEnumInt::TLbsPrivacyResponseInt response; |
|
531 if (activeRequest->RequestPrivacy().RequestAction() == TLbsNetPosRequestPrivacyInt::ERequestActionAllow) |
|
532 { |
|
533 response = TLbsNetworkEnumInt::EPrivacyResponseAccepted; |
|
534 } |
|
535 else |
|
536 { |
|
537 response = TLbsNetworkEnumInt::EPrivacyResponseRejected; |
|
538 } |
|
539 |
|
540 // For notification, simply return the default action. |
|
541 iObserver->OnRespondNetworkLocationRequest( |
|
542 activeRequest->SessionId(), response, KErrNone); |
|
543 break; |
|
544 } |
|
545 default: |
|
546 { |
|
547 // Other types of response are not expected, so |
|
548 // just ignore them??? |
|
549 break; |
|
550 } |
|
551 } |
|
552 } |
|
553 |
|
554 // Delete the finished request |
|
555 iRequestBuffer.Remove(0); |
|
556 delete activeRequest; |
|
557 } |
|
558 |
|
559 /* |
|
560 * Buffers requests. Verifications always take priority over notifications (ie are inserted in front of them) |
|
561 * If a notification is at the front of the queue (ie has already been sent) then we leave it there (it will complete almost instantly) |
|
562 * |
|
563 */ |
|
564 TInt CPrivacyAdvancedNotifierHandler::BufferPrivacyRequest( |
|
565 const TLbsNetSessionIdInt& aSessionId, |
|
566 const TLbsExternalRequestInfo& aRequestInfo, |
|
567 const TLbsNetPosRequestPrivacyInt& aRequestPrivacy, |
|
568 TBool aIsEmergency) |
|
569 { |
|
570 TBool isVerification = EFalse; |
|
571 // create the new request |
|
572 CPrivacyAdvancedRequest* request = NULL; |
|
573 TRAPD(err, request = CPrivacyAdvancedRequest::NewL()); |
|
574 if (err == KErrNone) |
|
575 { |
|
576 request->SetSessionId(aSessionId); |
|
577 request->SetRequestInfo(aRequestInfo); |
|
578 request->SetRequestPrivacy(aRequestPrivacy); |
|
579 request->SetIsEmergency(aIsEmergency); |
|
580 request->SetStartTime(); |
|
581 |
|
582 TPosRequestData data; |
|
583 ResetRequestData(data); |
|
584 switch (request->RequestPrivacy().RequestAdvice()) |
|
585 { |
|
586 case TLbsNetPosRequestPrivacyInt::ERequestAdviceNotify: |
|
587 { |
|
588 data.iRequestDecision = EPosDecisionAccepted; |
|
589 |
|
590 // If the session Id is less than the previous highest session Id |
|
591 // then assume that it is for a request that has already been processed. |
|
592 // (This should only happen if a client has called |
|
593 // NotifyVerificationTimeout() on the Network Privacy API.) |
|
594 // We should use a different notification reason for these |
|
595 // types of request. |
|
596 if (request->SessionId().SessionNum() < iHighestSessionId.SessionNum()) |
|
597 { |
|
598 data.iNotificationReason = EPosVerificationTimeout; |
|
599 } |
|
600 else |
|
601 { |
|
602 data.iNotificationReason = EPosDecisionByRequestSource; |
|
603 } |
|
604 break; |
|
605 } |
|
606 case TLbsNetPosRequestPrivacyInt::ERequestAdviceVerify: |
|
607 { |
|
608 ConvertActionToTPosRequestDecision( |
|
609 request->RequestPrivacy().RequestAction(), |
|
610 data.iTimeoutStrategy); |
|
611 isVerification = ETrue; |
|
612 break; |
|
613 } |
|
614 default: |
|
615 { |
|
616 // Should never get here; ignore for now. |
|
617 break; |
|
618 } |
|
619 } |
|
620 request->SetRequestData(data); |
|
621 |
|
622 // add it to the buffer |
|
623 if(isVerification) // verification gets inserted before pending notifications |
|
624 { |
|
625 err = InsertVerification(request); |
|
626 } |
|
627 else // notifications just get appended on the end |
|
628 { |
|
629 err = iRequestBuffer.Append(request); |
|
630 } |
|
631 } |
|
632 |
|
633 return err; |
|
634 } |
|
635 |
|
636 /* |
|
637 * If the notification at the given index is in front of any verifications |
|
638 * then it is moved to immediately after the last verification. |
|
639 */ |
|
640 TInt CPrivacyAdvancedNotifierHandler::DeferNotification(TInt aIndex) |
|
641 { |
|
642 TInt err = KErrNone; |
|
643 TInt lastVerification = aIndex; |
|
644 |
|
645 for( TInt i = aIndex + 1; i < iRequestBuffer.Count(); i++ ) |
|
646 { |
|
647 if(iRequestBuffer[i]->RequestPrivacy().RequestAdvice() == TLbsNetPosRequestPrivacyInt::ERequestAdviceVerify) |
|
648 { |
|
649 lastVerification = i; |
|
650 } |
|
651 } |
|
652 |
|
653 // there are pending verifications after the notification, so move it back |
|
654 if(lastVerification > aIndex) |
|
655 { |
|
656 CPrivacyAdvancedRequest* request = iRequestBuffer[aIndex]; |
|
657 if(lastVerification + 1 < iRequestBuffer.Count()) |
|
658 { |
|
659 err = iRequestBuffer.Insert(request, lastVerification + 1); |
|
660 } |
|
661 else |
|
662 { |
|
663 err = iRequestBuffer.Append(request); |
|
664 } |
|
665 iRequestBuffer.Remove(aIndex); |
|
666 } |
|
667 |
|
668 return err; |
|
669 |
|
670 } |
|
671 |
|
672 /* |
|
673 * Inserts a verification request into the request queue ahead of pending notifications |
|
674 * nb: the first request, which has already been issued, is left in place |
|
675 */ |
|
676 TInt CPrivacyAdvancedNotifierHandler::InsertVerification(CPrivacyAdvancedRequest* aRequest) |
|
677 { |
|
678 TInt err; |
|
679 |
|
680 for( TInt i = 1; i < iRequestBuffer.Count(); i++ ) |
|
681 { |
|
682 if ( iRequestBuffer[i]->RequestPrivacy().RequestAdvice() == TLbsNetPosRequestPrivacyInt::ERequestAdviceNotify) |
|
683 { |
|
684 return iRequestBuffer.Insert(aRequest,i); |
|
685 } |
|
686 } |
|
687 |
|
688 // there were no notifications, just append on the end |
|
689 err = iRequestBuffer.Append(aRequest); |
|
690 |
|
691 return err; |
|
692 } |
|
693 |
|
694 void CPrivacyAdvancedNotifierHandler::RemovePrivacyRequestFromBuffer( |
|
695 const TLbsNetSessionIdInt& aSessionId) |
|
696 { |
|
697 TInt index = iRequestBuffer.Find(aSessionId, CPrivacyAdvancedRequest::IsSessionIdEqual); |
|
698 while (KErrNotFound != index) |
|
699 { |
|
700 CPrivacyRequest* reqData = iRequestBuffer[index]; |
|
701 iRequestBuffer.Remove(index); |
|
702 delete reqData; |
|
703 |
|
704 index = iRequestBuffer.Find(aSessionId, CPrivacyAdvancedRequest::IsSessionIdEqual); |
|
705 } |
|
706 } |
|
707 |
|
708 /** Reset the members of aRequestData to their default values. |
|
709 */ |
|
710 void CPrivacyAdvancedNotifierHandler::ResetRequestData(TPosRequestData& aRequestData) |
|
711 { |
|
712 aRequestData.iRequestSource = EPosRequestSourceNetwork; |
|
713 aRequestData.iTimeoutStrategy = EPosDecisionNotAvailable; |
|
714 aRequestData.iRequestDecision = EPosDecisionNotAvailable; |
|
715 aRequestData.iNotificationReason = EPosNotificationReasonNotAvailable; |
|
716 aRequestData.iCancelReason = EPosCancelReasonNotAvailable; |
|
717 } |
|
718 |
|
719 /** |
|
720 */ |
|
721 void CPrivacyAdvancedNotifierHandler::ConvertActionToTPosRequestDecision( |
|
722 TLbsNetPosRequestPrivacyInt::TLbsRequestActionInt aAction, |
|
723 TPosRequestDecision& aDecision) |
|
724 { |
|
725 switch (aAction) |
|
726 { |
|
727 case TLbsNetPosRequestPrivacyInt::ERequestActionAllow: |
|
728 { |
|
729 aDecision = EPosDecisionAccepted; |
|
730 break; |
|
731 } |
|
732 case TLbsNetPosRequestPrivacyInt::ERequestActionReject: |
|
733 { |
|
734 aDecision = EPosDecisionRejected; |
|
735 break; |
|
736 } |
|
737 case TLbsNetPosRequestPrivacyInt::ERequestActionNotUsed: |
|
738 default: |
|
739 { |
|
740 aDecision = EPosDecisionNotAvailable; |
|
741 break; |
|
742 } |
|
743 } |
|
744 } |