|
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 <lbs/epos_privacy.h> |
|
20 #include "EPos_PrivacyInternal.h" |
|
21 |
|
22 #include "EPos_CPosPrivManager.h" |
|
23 #include "EPos_CPosDialogCtrl.h" |
|
24 #include "EPos_PosCommonPrivacyResources.h" |
|
25 #include "EPos_PrivacyServerDebugPanic.h" |
|
26 |
|
27 // ================= MEMBER FUNCTIONS ======================= |
|
28 |
|
29 // Two-phased constructor. |
|
30 CPosPrivManager* CPosPrivManager::NewL() |
|
31 { |
|
32 CPosPrivManager* self = new (ELeave) CPosPrivManager(); |
|
33 CleanupStack::PushL(self); |
|
34 self->ConstructL(); |
|
35 CleanupStack::Pop(self); |
|
36 return self; |
|
37 } |
|
38 |
|
39 // Destructor |
|
40 CPosPrivManager::~CPosPrivManager() |
|
41 { |
|
42 Cancel(); |
|
43 if (iRequestInfo) |
|
44 { |
|
45 delete iRequestInfo; |
|
46 } |
|
47 } |
|
48 |
|
49 // C++ default constructor can NOT contain any code, that |
|
50 // might leave. |
|
51 // |
|
52 CPosPrivManager::CPosPrivManager() |
|
53 : CActive(CActive::EPriorityStandard), |
|
54 iDlgCtrl(PosCommonPrivacyResources::DialogCtrl()) |
|
55 { |
|
56 CActiveScheduler::Add(this); |
|
57 iActivity = EPosInactive; |
|
58 } |
|
59 |
|
60 // EPOC default constructor can leave. |
|
61 void CPosPrivManager::ConstructL() |
|
62 { |
|
63 iRequestInfo = new (ELeave) TLbsExternalRequestInfo2; |
|
64 } |
|
65 |
|
66 // --------------------------------------------------------- |
|
67 // CPosPrivManager::VerifyL |
|
68 // |
|
69 // (other items were commented in a header). |
|
70 // --------------------------------------------------------- |
|
71 // |
|
72 void CPosPrivManager::VerifyL( |
|
73 TRequestStatus& aRequestStatus, |
|
74 const TLbsExternalRequestInfo& aRequestInfo, |
|
75 const TPosRequestData& aRequestData, |
|
76 TInt aRequestId) |
|
77 { |
|
78 if (iActivity != EPosInactive) |
|
79 { |
|
80 TRequestStatus* status = &aRequestStatus; |
|
81 User::RequestComplete(status, KErrOverflow); |
|
82 return; |
|
83 } |
|
84 |
|
85 Mem::Copy(iRequestInfo, |
|
86 &aRequestInfo, |
|
87 aRequestInfo.ClassSize()); |
|
88 iRequestStatus = &aRequestStatus; |
|
89 *iRequestStatus = KRequestPending; |
|
90 iRequestData = aRequestData; |
|
91 iRequestId = aRequestId; |
|
92 iActivity = EPosResolvingForVerification; |
|
93 |
|
94 ResolveL(); |
|
95 } |
|
96 |
|
97 // --------------------------------------------------------- |
|
98 // CPosPrivManager::CancelVerify |
|
99 // |
|
100 // (other items were commented in a header). |
|
101 // --------------------------------------------------------- |
|
102 // |
|
103 void CPosPrivManager::CancelVerify() |
|
104 { |
|
105 if (IsVerifying()) |
|
106 { |
|
107 User::RequestComplete(iRequestStatus, KErrCancel); |
|
108 Cancel(); |
|
109 iActivity = EPosInactive; |
|
110 } |
|
111 } |
|
112 |
|
113 // --------------------------------------------------------- |
|
114 // CPosPrivManager::CancelVerifyL |
|
115 // |
|
116 // (other items were commented in a header). |
|
117 // --------------------------------------------------------- |
|
118 // |
|
119 void CPosPrivManager::CancelVerifyL( |
|
120 TPosVerifyCancelReason aCancelReason) |
|
121 { |
|
122 if (!IsVerifying() && iActivity != EPosInactive) |
|
123 { // Notification is running. Cancel is then not allowed. |
|
124 User::Leave(KErrOverflow); |
|
125 } |
|
126 |
|
127 switch (iActivity) |
|
128 { |
|
129 case EPosVerifying: |
|
130 { |
|
131 //Cancel could occur on four places during the state EPosVerifying. |
|
132 //1. The request is queued in CPosDlgCtrl |
|
133 //2. The request is cancelled when the dialog is shown. |
|
134 //3. The user has dismissed the dialog but CPosDlgCtrl::RunL has not |
|
135 // yet been run by the AS. |
|
136 //4. The user has dismissed the dialog, CPosDlgCtrl::RunL has been |
|
137 // run, however, CPosPrivManager::RunL has not. In this case, it |
|
138 // is not necessary to cancel CPosDialogCtrl since it has already |
|
139 // completed the request. |
|
140 // |
|
141 //Case 3 and 4 are treated the same way, i.e. the |
|
142 //user will be notified. |
|
143 // |
|
144 if (iRequestData.iTimeoutStrategy != EPosDecisionNotAvailable) |
|
145 { |
|
146 if (iStatus == KRequestPending) |
|
147 { |
|
148 TInt err; |
|
149 TBool requestQueued; |
|
150 iDlgCtrl->CancelLaunch(iStatus, err, iUserResponse, |
|
151 requestQueued, aCancelReason); |
|
152 |
|
153 if (requestQueued) |
|
154 { |
|
155 iActivity = EPosCancelBeforeDialog; //Case 1 |
|
156 } |
|
157 else if (err == KErrArgument || |
|
158 err == KErrNotReady && |
|
159 iUserResponse != KRequestPending || //S60 |
|
160 err == KErrNone && |
|
161 iUserResponse != KRequestPending) //S90 |
|
162 { |
|
163 iActivity = EPosCancelAfterDialog2; //Case 3 |
|
164 } |
|
165 else |
|
166 { |
|
167 iActivity = EPosCancelDuringDialog; //Case 2 |
|
168 } |
|
169 } |
|
170 else |
|
171 { |
|
172 iActivity = EPosCancelAfterDialog1; //Case 4. |
|
173 } |
|
174 } |
|
175 else |
|
176 { |
|
177 CancelVerify(); |
|
178 } |
|
179 break; |
|
180 } |
|
181 case EPosInactive: |
|
182 { |
|
183 //A cancel request is received after user response, |
|
184 //but client has not yet received the request. |
|
185 if (iRequestData.iTimeoutStrategy != EPosDecisionNotAvailable) |
|
186 { |
|
187 TInt result = iLastVerificationResult == KErrNone ? |
|
188 KErrNone : KErrAccessDenied; |
|
189 TInt reqDecision = iRequestData.iTimeoutStrategy == |
|
190 EPosDecisionRejected ? KErrAccessDenied : KErrNone; |
|
191 if (result != reqDecision) |
|
192 { |
|
193 NotifyPluginL(); |
|
194 } |
|
195 } |
|
196 break; |
|
197 } |
|
198 default: break; |
|
199 } |
|
200 } |
|
201 |
|
202 // --------------------------------------------------------- |
|
203 // CPosPrivManager::NotifyL |
|
204 // |
|
205 // (other items were commented in a header). |
|
206 // --------------------------------------------------------- |
|
207 // |
|
208 void CPosPrivManager::NotifyL( |
|
209 TRequestStatus& aRequestStatus, |
|
210 const TLbsExternalRequestInfo& aRequestInfo, |
|
211 const TPosRequestData& aRequestData, |
|
212 TInt aRequestId) |
|
213 { |
|
214 if (iActivity != EPosInactive) |
|
215 { |
|
216 TRequestStatus* status = &aRequestStatus; |
|
217 User::RequestComplete(status, KErrOverflow); |
|
218 return; |
|
219 } |
|
220 |
|
221 iRequestStatus = &aRequestStatus; |
|
222 *iRequestStatus = KRequestPending; |
|
223 |
|
224 iRequestData = aRequestData; |
|
225 iRequestId = aRequestId; |
|
226 |
|
227 TLbsExternalRequestInfo2* reqInfo = new (ELeave) TLbsExternalRequestInfo2; |
|
228 Mem::Copy(reqInfo, |
|
229 &aRequestInfo, |
|
230 aRequestInfo.ClassSize()); |
|
231 delete iRequestInfo; |
|
232 iRequestInfo = reqInfo; |
|
233 |
|
234 iActivity = EPosResolvingForNotification; |
|
235 ResolveL(); |
|
236 } |
|
237 |
|
238 // --------------------------------------------------------- |
|
239 // CPosPrivManager::RunL |
|
240 // |
|
241 // (other items were commented in a header). |
|
242 // --------------------------------------------------------- |
|
243 // |
|
244 void CPosPrivManager::RunL() |
|
245 { |
|
246 if (iStatus.Int() == KErrNoMemory) |
|
247 { |
|
248 User::Leave(KErrNoMemory); |
|
249 } |
|
250 |
|
251 if (iActivity == EPosResolvingForVerification) |
|
252 { |
|
253 // Resolving is done. Start verification |
|
254 iActivity = EPosVerifying; |
|
255 |
|
256 // Launch the verification dialog |
|
257 iDlgCtrl->VerifyL(iStatus, *iRequestInfo, iRequestData); |
|
258 SetActive(); |
|
259 } |
|
260 else if (iActivity == EPosResolvingForNotification) |
|
261 { |
|
262 if (iRequestData.iNotificationReason == EPosVerificationTimeout) |
|
263 // Notify verification timeout |
|
264 { |
|
265 NotifyPluginL(); |
|
266 } |
|
267 else // Notify (without previous verification) |
|
268 { |
|
269 iDlgCtrl->NotifyL(*iRequestInfo, iRequestData); |
|
270 iRequestInfo = NULL; |
|
271 iRequestInfo = new (ELeave) TLbsExternalRequestInfo2; |
|
272 } |
|
273 |
|
274 // Notify message not completed until now, in order to prevent |
|
275 // parallell notifications |
|
276 User::RequestComplete(iRequestStatus, KErrNone); |
|
277 iActivity = EPosInactive; |
|
278 } |
|
279 else if (iActivity == EPosVerifying) |
|
280 { |
|
281 CompleteRequestL(iStatus.Int()); |
|
282 } |
|
283 else |
|
284 { |
|
285 if (iActivity == EPosCancelBeforeDialog && |
|
286 iRequestData.iTimeoutStrategy == EPosDecisionAccepted) |
|
287 { |
|
288 iRequestData.iNotificationReason = EPosDecisionByRequestSource; |
|
289 iDlgCtrl->NotifyL(*iRequestInfo, iRequestData); |
|
290 delete iRequestInfo; |
|
291 iRequestInfo = NULL; |
|
292 iRequestInfo = new (ELeave) TLbsExternalRequestInfo2; |
|
293 } |
|
294 else if (iActivity == EPosCancelAfterDialog1 |
|
295 || iActivity == EPosCancelAfterDialog2) |
|
296 { |
|
297 TInt userResponse; |
|
298 if (iActivity == EPosCancelAfterDialog1) |
|
299 { |
|
300 userResponse = iStatus.Int() == KErrNone ? |
|
301 KErrNone : KErrAccessDenied; |
|
302 } |
|
303 else |
|
304 { |
|
305 userResponse = iUserResponse == KErrNone ? |
|
306 KErrNone : KErrAccessDenied; |
|
307 } |
|
308 |
|
309 TInt timeoutStrategy = iRequestData.iTimeoutStrategy == |
|
310 EPosDecisionRejected ? KErrAccessDenied : KErrNone; |
|
311 |
|
312 if (userResponse != timeoutStrategy) |
|
313 { |
|
314 NotifyPluginL(); |
|
315 } |
|
316 } |
|
317 User::RequestComplete(iRequestStatus, KErrCancel); |
|
318 iActivity = EPosInactive; |
|
319 } |
|
320 } |
|
321 |
|
322 // --------------------------------------------------------- |
|
323 // CPosPrivManager::DoCancel |
|
324 // |
|
325 // (other items were commented in a header). |
|
326 // --------------------------------------------------------- |
|
327 // |
|
328 void CPosPrivManager::DoCancel() |
|
329 { |
|
330 if (PosCommonPrivacyResources::Installed()) |
|
331 { |
|
332 if (iActivity == EPosVerifying) |
|
333 { |
|
334 iDlgCtrl->CancelLaunch(iStatus); |
|
335 } |
|
336 } |
|
337 } |
|
338 |
|
339 // --------------------------------------------------------- |
|
340 // CPosPrivManager::RunError |
|
341 // |
|
342 // (other items were commented in a header). |
|
343 // --------------------------------------------------------- |
|
344 // |
|
345 TInt CPosPrivManager::RunError(TInt aError) |
|
346 { |
|
347 User::RequestComplete(iRequestStatus, aError); |
|
348 iActivity = EPosInactive; |
|
349 return KErrNone; |
|
350 } |
|
351 |
|
352 // --------------------------------------------------------- |
|
353 // CPosPrivManager::ResolveL |
|
354 // |
|
355 // (other items were commented in a header). |
|
356 // --------------------------------------------------------- |
|
357 // |
|
358 void CPosPrivManager::ResolveL() |
|
359 { |
|
360 // No resolving of requestors is implemented |
|
361 iStatus = KErrNone; |
|
362 RunL(); |
|
363 } |
|
364 |
|
365 // --------------------------------------------------------- |
|
366 // CPosPrivManager::CompleteRequestL |
|
367 // |
|
368 // (other items were commented in a header). |
|
369 // --------------------------------------------------------- |
|
370 // |
|
371 void CPosPrivManager::CompleteRequestL(TInt aCompleteCode) |
|
372 { |
|
373 iLastVerificationResult = aCompleteCode; |
|
374 |
|
375 TInt result = aCompleteCode == |
|
376 KErrNone ? KErrNone : KErrAccessDenied; |
|
377 User::RequestComplete(iRequestStatus, result); |
|
378 iActivity = EPosInactive; |
|
379 } |
|
380 |
|
381 // --------------------------------------------------------- |
|
382 // CPosPrivManager::NotifyPluginL |
|
383 // |
|
384 // (other items were commented in a header). |
|
385 // --------------------------------------------------------- |
|
386 // |
|
387 void CPosPrivManager::NotifyPluginL() |
|
388 { |
|
389 if (iRequestData.iRequestDecision == EPosDecisionNotAvailable) |
|
390 { |
|
391 iRequestData.iRequestDecision = iRequestData.iTimeoutStrategy; |
|
392 } |
|
393 |
|
394 iRequestData.iTimeoutStrategy = EPosDecisionNotAvailable; |
|
395 iRequestData.iNotificationReason = EPosVerificationTimeout; |
|
396 iRequestData.iCancelReason = EPosCancelReasonNotAvailable; |
|
397 |
|
398 iDlgCtrl->NotifyL(*iRequestInfo, iRequestData); |
|
399 delete iRequestInfo; |
|
400 iRequestInfo = NULL; |
|
401 iRequestInfo = new (ELeave) TLbsExternalRequestInfo2; |
|
402 } |
|
403 |
|
404 // --------------------------------------------------------- |
|
405 // CPosPrivManager::IsVerifying |
|
406 // |
|
407 // (other items were commented in a header). |
|
408 // --------------------------------------------------------- |
|
409 // |
|
410 TBool CPosPrivManager::IsVerifying() const |
|
411 { |
|
412 switch (iActivity) |
|
413 { |
|
414 case EPosInactive: |
|
415 case EPosResolvingForNotification: |
|
416 return EFalse; |
|
417 case EPosResolvingForVerification: |
|
418 case EPosVerifying: |
|
419 case EPosCancelBeforeDialog: |
|
420 case EPosCancelDuringDialog: |
|
421 case EPosCancelAfterDialog1: |
|
422 case EPosCancelAfterDialog2: |
|
423 return ETrue; |
|
424 default: |
|
425 //DebugPanic(EPosPrivSrvPanicUnknownActivity); |
|
426 break; |
|
427 } |
|
428 return EFalse; |
|
429 } |
|
430 |
|
431 // End of File |