|
1 /* |
|
2 * Copyright (c) 2008-2009 Nokia Corporation and/or its subsidiary(-ies). |
|
3 * All rights reserved. |
|
4 * This component and the accompanying materials are made available |
|
5 * under the terms of "Eclipse Public License v1.0" |
|
6 * which accompanies this distribution, and is available |
|
7 * at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
8 * |
|
9 * Initial Contributors: |
|
10 * Nokia Corporation - initial contribution. |
|
11 * |
|
12 * Contributors: |
|
13 * |
|
14 * Description: Handling of the MPM interface. |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 /** |
|
20 @file s60mpmrequests.cpp |
|
21 Handling of the MPM interface. |
|
22 */ |
|
23 |
|
24 // Project includes |
|
25 #include "s60mpmrequests.h" |
|
26 #include "s60mcpr.h" |
|
27 #include "s60mpmnotifications.h" |
|
28 |
|
29 // Namespace |
|
30 using namespace S60MCPRMPMOperations; |
|
31 |
|
32 // ============================ MEMBER FUNCTIONS =============================== |
|
33 // ----------------------------------------------------------------------------- |
|
34 // CMPMPolicyRequests::NewL |
|
35 // ----------------------------------------------------------------------------- |
|
36 // |
|
37 CMPMPolicyRequests* CMPMPolicyRequests::NewL( MMPMPolicyNotificationUser& aUser ) |
|
38 { |
|
39 CMPMPolicyRequests* self = new ( ELeave ) CMPMPolicyRequests(); |
|
40 CleanupStack::PushL( self ); |
|
41 self->ConstructL( aUser ); |
|
42 CleanupStack::Pop( self ); |
|
43 return self; |
|
44 } |
|
45 |
|
46 // ----------------------------------------------------------------------------- |
|
47 // CMPMPolicyRequests::PolicyNotification |
|
48 // ----------------------------------------------------------------------------- |
|
49 // |
|
50 void CMPMPolicyRequests::PolicyNotification( TMpmNotification& aNotification ) |
|
51 { |
|
52 if ( !iCommitedToDeleteItself ) |
|
53 { |
|
54 S60MCPRLOGSTRING1( "S60MCPR::CMPMPolicyRequests<%x>::PolicyNotification() forwarding call tocalling MCPR", this ) |
|
55 iPolicyNotificationsUser->PolicyNotification( aNotification ); |
|
56 } |
|
57 } |
|
58 |
|
59 // ----------------------------------------------------------------------------- |
|
60 // CMPMPolicyRequests::RequestDelete |
|
61 // ----------------------------------------------------------------------------- |
|
62 // |
|
63 void CMPMPolicyRequests::RequestDelete() |
|
64 { |
|
65 iCommitedToDeleteItself = ETrue; |
|
66 // Either we have pending requests |
|
67 // (we always have at least notifications if we're connected.) |
|
68 // |
|
69 if ( iPolicyRequests.Count() > 0 ) |
|
70 { |
|
71 S60MCPRLOGSTRING2( "S60MCPR::CMPMPolicyRequests<%x>::RequestDelete() %d pending requests, IssueRequest", this, iPolicyRequests.Count() ) |
|
72 IssueRequest(); |
|
73 } |
|
74 // Or we are free to delete this. |
|
75 // |
|
76 else |
|
77 { |
|
78 S60MCPRLOGSTRING1( "S60MCPR::CMPMPolicyRequests<%x>::RequestDelete() IssueDeleteRequest", this ) |
|
79 IssueDeleteRequest(); |
|
80 } |
|
81 } |
|
82 |
|
83 // ----------------------------------------------------------------------------- |
|
84 // CMPMPolicyRequests::CMPMPolicyRequests |
|
85 // ----------------------------------------------------------------------------- |
|
86 // |
|
87 CMPMPolicyRequests::CMPMPolicyRequests() : |
|
88 CActive( EPriorityStandard ), |
|
89 iCommitedToDeleteItself( EFalse ) |
|
90 { |
|
91 S60MCPRLOGSTRING1( "S60MCPR::CMPMPolicyRequests<%x>::CMPMPolicyRequests()", this ) |
|
92 CActiveScheduler::Add( this ); |
|
93 iConnId = (TConnectionId)this; |
|
94 } |
|
95 |
|
96 // ----------------------------------------------------------------------------- |
|
97 // CMPMPolicyRequests::~CMPMPolicyRequests |
|
98 // ----------------------------------------------------------------------------- |
|
99 // |
|
100 CMPMPolicyRequests::~CMPMPolicyRequests() |
|
101 { |
|
102 //LOG( ESockLog::Printf(KESockMetaConnectionTag, _L8("CMPMPolicyRequests<%x>::~CMPMPolicyRequests"), this ); ) |
|
103 S60MCPRLOGSTRING1( "S60MCPR::CMPMPolicyRequests<%x>::~CMPMPolicyRequests()", this ) |
|
104 |
|
105 __ASSERT_ALWAYS(!IsActive(), User::Panic(KS60MCprPanic, KPanicInvalidCActiveUsage)); |
|
106 __ASSERT_DEBUG(iPolicyRequests.Count() == 0, User::Panic(KS60MCprPanic, KPanicInvalidCActiveUsage)); |
|
107 |
|
108 // Clean up all objects in the list |
|
109 // Normally there shouldn't be any. |
|
110 TInt count = iPolicyRequests.Count(); |
|
111 for (TInt i = 0; i < count; i++) |
|
112 { |
|
113 S60MCPRLOGSTRING2( "S60MCPR::CMPMPolicyRequests<%x>::~CMPMPolicyRequests() deleting request %d", |
|
114 this, (TInt)iPolicyRequests[i].iRequestType ) |
|
115 // Delete prefs |
|
116 delete iPolicyRequests[i].iConnPref; |
|
117 delete iPolicyRequests[i].iPolicyPref; |
|
118 // PolicyRequest owns this class and can delete it. |
|
119 // MCPR must have cancelled its activity when this happens. |
|
120 delete iPolicyRequests[i].iUser; |
|
121 } |
|
122 |
|
123 // Reset the array. |
|
124 iPolicyRequests.Close(); |
|
125 |
|
126 // Close the MPM handle |
|
127 if ( iMpm.Connected() ) |
|
128 { |
|
129 S60MCPRLOGSTRING1( "S60MCPR::CMPMPolicyRequests<%x>::~CMPMPolicyRequests() closing MPM session", this ) |
|
130 iMpm.Close(); |
|
131 } |
|
132 } |
|
133 |
|
134 // ----------------------------------------------------------------------------- |
|
135 // CMPMPolicyRequests::ConstructL |
|
136 // ----------------------------------------------------------------------------- |
|
137 // |
|
138 void CMPMPolicyRequests::ConstructL( MMPMPolicyNotificationUser& aUser ) |
|
139 { |
|
140 // Force MPMNotifications to go through CMPMPolicyRequests |
|
141 iPolicyNotificationsUser = &aUser; |
|
142 iPolicyNotifications = CMPMPolicyNotifications::NewL( *(MMPMPolicyNotificationUser*)this, |
|
143 iMpm ); |
|
144 S60MCPRLOGSTRING2( "S60MCPR::CMPMPolicyRequests<%x>::ConstructL() using iPolicyNotifications<%x>", |
|
145 this, iPolicyNotifications ) |
|
146 } |
|
147 |
|
148 // ----------------------------------------------------------------------------- |
|
149 // CMPMPolicyRequests::IAPConnectionStartedL |
|
150 // ----------------------------------------------------------------------------- |
|
151 // |
|
152 void CMPMPolicyRequests::IAPConnectionStartedL( const TUint32 aIapId ) |
|
153 { |
|
154 S60MCPRLOGSTRING2( "S60MCPR::CMPMPolicyRequests<%x>::IAPConnectionStartedL() IAP %d", this, aIapId ) |
|
155 CreatePolicyRequestL( EPolicyRequestIAPConnectionStarted, aIapId ); |
|
156 } |
|
157 |
|
158 // ----------------------------------------------------------------------------- |
|
159 // CMPMPolicyRequests::IAPConnectionStoppedL |
|
160 // ----------------------------------------------------------------------------- |
|
161 // |
|
162 void CMPMPolicyRequests::IAPConnectionStoppedL( const TUint32 aIapId ) |
|
163 { |
|
164 S60MCPRLOGSTRING2( "S60MCPR::CMPMPolicyRequests<%x>::IAPConnectionStoppedL() IAP %d", this, aIapId ) |
|
165 CreatePolicyRequestL( EPolicyRequestIAPConnectionStopped, aIapId ); |
|
166 } |
|
167 |
|
168 // ----------------------------------------------------------------------------- |
|
169 // CMPMPolicyRequests::ApplicationJoinsConnectionL |
|
170 // ----------------------------------------------------------------------------- |
|
171 // |
|
172 void CMPMPolicyRequests::ApplicationJoinsConnectionL( const TUint32 aIapId ) |
|
173 { |
|
174 // Can't use CreatePolicyRequest() here because this could |
|
175 // be the first call to MPM. |
|
176 |
|
177 PolicyRequest policydata = PolicyRequest(); |
|
178 policydata.iRequestType = EPolicyRequestApplicationJoinsConnection; |
|
179 policydata.iConnId = iConnId; |
|
180 policydata.iIapId = aIapId; |
|
181 |
|
182 // Add request to array of uncompleted requests |
|
183 iPolicyRequests.AppendL( policydata ); |
|
184 |
|
185 S60MCPRLOGSTRING2( "S60MCPR::CMPMPolicyRequests<%x>::ApplicationJoinsConnectionL() IAP %d", this, aIapId ) |
|
186 |
|
187 // Submit it. |
|
188 IssueRequest(); |
|
189 } |
|
190 |
|
191 // ----------------------------------------------------------------------------- |
|
192 // CMPMPolicyRequests::ApplicationLeavesConnectionL |
|
193 // ----------------------------------------------------------------------------- |
|
194 // |
|
195 void CMPMPolicyRequests::ApplicationLeavesConnectionL( const TUint32 aIapId ) |
|
196 { |
|
197 S60MCPRLOGSTRING2( "S60MCPR::CMPMPolicyRequests<%x>::ApplicationLeavesConnectionL() IAP %d", this, aIapId ) |
|
198 CreatePolicyRequestL( EPolicyRequestApplicationLeavesConnection, aIapId ); |
|
199 } |
|
200 |
|
201 // ----------------------------------------------------------------------------- |
|
202 // CMPMPolicyRequests::ApplicationLeavesConnectionL |
|
203 // ----------------------------------------------------------------------------- |
|
204 // |
|
205 void CMPMPolicyRequests::ApplicationConnectionEndsL() |
|
206 { |
|
207 // This is only a notification. Thus, if the session doesn't exist, don't create one |
|
208 if ( !iMpm.Connected() ) |
|
209 { |
|
210 return; |
|
211 } |
|
212 |
|
213 S60MCPRLOGSTRING1( "S60MCPR::CMPMPolicyRequests<%x>::ApplicationConnectionEndsL() IAP %d", this ) |
|
214 |
|
215 PolicyRequest policydata = PolicyRequest(); |
|
216 policydata.iRequestType = EPolicyRequestApplicationConnectionEnds; |
|
217 policydata.iConnId = iConnId; |
|
218 // policydata.iIapId = aIapId; |
|
219 // Nothing to cleanup so it's ok to Leave in AppendL |
|
220 |
|
221 // Add request to array of uncompleted requests |
|
222 iPolicyRequests.AppendL( policydata ); |
|
223 |
|
224 // Submit it. |
|
225 IssueRequest(); |
|
226 } |
|
227 |
|
228 |
|
229 // ----------------------------------------------------------------------------- |
|
230 // CMPMPolicyRequests::RegisterPreferredIAPNotificationL |
|
231 // ----------------------------------------------------------------------------- |
|
232 // |
|
233 void CMPMPolicyRequests::RegisterPreferredIAPNotificationL() |
|
234 { |
|
235 S60MCPRLOGSTRING1( "S60MCPR::CMPMPolicyRequests<%x>::RegisterPreferredIAPNotificationL()", this ) |
|
236 |
|
237 PolicyRequest policydata = PolicyRequest(); |
|
238 |
|
239 policydata.iRequestType = EPolicyRequestRegisterPrefIAPNotif; |
|
240 policydata.iConnId = iConnId; |
|
241 |
|
242 // Add request to array of uncompleted requests |
|
243 iPolicyRequests.AppendL( policydata ); |
|
244 |
|
245 // Submit it. |
|
246 IssueRequest(); |
|
247 } |
|
248 |
|
249 // ----------------------------------------------------------------------------- |
|
250 // CMPMPolicyRequests::UnregisterPreferredIAPNotificationL |
|
251 // ----------------------------------------------------------------------------- |
|
252 // |
|
253 void CMPMPolicyRequests::UnregisterPreferredIAPNotificationL() |
|
254 { |
|
255 // Sanity check that we're still in business. |
|
256 if ( !iMpm.Connected() ) |
|
257 { |
|
258 return; |
|
259 } |
|
260 |
|
261 S60MCPRLOGSTRING1( "S60MCPR::CMPMPolicyRequests<%x>::UnregisterPreferredIAPNotificationL()", this ) |
|
262 |
|
263 PolicyRequest policydata = PolicyRequest(); |
|
264 |
|
265 policydata.iRequestType = EPolicyRequestUnregisterPrefIAPNotif; |
|
266 policydata.iConnId = iConnId; |
|
267 |
|
268 // Add request to array of uncompleted requests |
|
269 iPolicyRequests.AppendL( policydata ); |
|
270 |
|
271 // Submit it. |
|
272 IssueRequest(); |
|
273 } |
|
274 |
|
275 |
|
276 // ----------------------------------------------------------------------------- |
|
277 // CMPMPolicyRequests::ApplicationIgnoredTheCarrierL |
|
278 // ----------------------------------------------------------------------------- |
|
279 // |
|
280 void CMPMPolicyRequests::ApplicationIgnoredTheCarrierL( const TUint32 aIapId ) |
|
281 { |
|
282 S60MCPRLOGSTRING1( "S60MCPR::CMPMPolicyRequests<%x>::ApplicationIgnoredTheCarrierL()", this ) |
|
283 CreatePolicyRequestL( EPolicyRequestApplicationIgnoredTheCarrier, aIapId ); |
|
284 } |
|
285 |
|
286 |
|
287 // ----------------------------------------------------------------------------- |
|
288 // CMPMPolicyRequests::ApplicationMigratesToCarrierL |
|
289 // ----------------------------------------------------------------------------- |
|
290 // |
|
291 void CMPMPolicyRequests::ApplicationMigratesToCarrierL( const TUint32 aIapId ) |
|
292 { |
|
293 S60MCPRLOGSTRING1( "S60MCPR::CMPMPolicyRequests<%x>::ApplicationMigratesToCarrierL()", this ) |
|
294 CreatePolicyRequestL( EPolicyRequestApplicationMigratesToCarrier, aIapId ); |
|
295 } |
|
296 |
|
297 // ----------------------------------------------------------------------------- |
|
298 // CMPMPolicyRequests::ApplicationRejectedTheCarrierL |
|
299 // ----------------------------------------------------------------------------- |
|
300 // |
|
301 void CMPMPolicyRequests::ApplicationRejectedTheCarrierL( const TUint32 aIapId ) |
|
302 { |
|
303 S60MCPRLOGSTRING1( "S60MCPR::CMPMPolicyRequests<%x>::ApplicationRejectedTheCarrierL()", this ) |
|
304 CreatePolicyRequestL( EPolicyRequestApplicationRejectedTheCarrier, aIapId ); |
|
305 } |
|
306 |
|
307 // ----------------------------------------------------------------------------- |
|
308 // CMPMPolicyRequests::ApplicationAcceptedTheCarrierL |
|
309 // ----------------------------------------------------------------------------- |
|
310 // |
|
311 void CMPMPolicyRequests::ApplicationAcceptedTheCarrierL( const TUint32 aIapId) |
|
312 { |
|
313 S60MCPRLOGSTRING1( "S60MCPR::CMPMPolicyRequests<%x>::ApplicationAcceptedTheCarrierL()", this ) |
|
314 CreatePolicyRequestL( EPolicyRequestApplicationAcceptedTheCarrier, aIapId ); |
|
315 } |
|
316 |
|
317 // ----------------------------------------------------------------------------- |
|
318 // CMPMPolicyRequests::ChooseBestIAP |
|
319 // ----------------------------------------------------------------------------- |
|
320 // |
|
321 void CMPMPolicyRequests::ChooseBestIAPL( TConnPref* aConnPref, |
|
322 const TUid& aAppUid, |
|
323 TConnPref* aPolicyPref, |
|
324 MMPMPolicyRequestsUser* aUser ) |
|
325 { |
|
326 S60MCPRLOGSTRING1( "S60MCPR::CMPMPolicyRequests<%x>::ChooseBestIAPL()", this ) |
|
327 |
|
328 // Define policydata |
|
329 PolicyRequest policydata = PolicyRequest(); |
|
330 policydata.iRequestType = EPolicyRequestChooseBestIAP; |
|
331 policydata.iConnId = iConnId; |
|
332 policydata.iAppUid = aAppUid; |
|
333 |
|
334 // Heap allocated objects |
|
335 policydata.iConnPref = aConnPref; |
|
336 policydata.iPolicyPref = aPolicyPref; |
|
337 policydata.iUser = aUser; |
|
338 |
|
339 // Nothing to cleanup so it's ok to Leave in AppendL |
|
340 // Heap allocated objects are on callers responsibility if we Leave. |
|
341 |
|
342 // Add it to the array of uncompleted requests |
|
343 iPolicyRequests.AppendL( policydata ); |
|
344 |
|
345 IssueRequest(); |
|
346 } |
|
347 |
|
348 // ----------------------------------------------------------------------------- |
|
349 // CMPMPolicyRequests::CancelReselectBestIAP() |
|
350 // ----------------------------------------------------------------------------- |
|
351 // |
|
352 void CMPMPolicyRequests::CancelReselectBestIAP() |
|
353 { |
|
354 S60MCPRLOGSTRING1( "S60MCPR::CMPMPolicyRequests<%x>::CancelReselectBestIAPL()", this ) |
|
355 ASSERT( iPolicyRequests.Count() > 0 ); |
|
356 CancelRequest( EMPMReselectBestIAP ); |
|
357 } |
|
358 |
|
359 // ----------------------------------------------------------------------------- |
|
360 // CMPMPolicyRequests::CancelChooseBestIAPL() |
|
361 // ----------------------------------------------------------------------------- |
|
362 // |
|
363 void CMPMPolicyRequests::CancelChooseBestIAPL() |
|
364 { |
|
365 S60MCPRLOGSTRING1( "S60MCPR::CMPMPolicyRequests<%x>::CancelChooseBestIAPL()", this ) |
|
366 ASSERT( iPolicyRequests.Count() > 0 ); |
|
367 CancelRequest( EMPMChooseBestIAP ); |
|
368 } |
|
369 |
|
370 // ----------------------------------------------------------------------------- |
|
371 // CMPMPolicyRequests::CancelProcessError() |
|
372 // ----------------------------------------------------------------------------- |
|
373 // |
|
374 void CMPMPolicyRequests::CancelProcessError() |
|
375 { |
|
376 S60MCPRLOGSTRING1( "S60MCPR::CMPMPolicyRequests<%x>::CancelProcessErrorL()", this ) |
|
377 ASSERT( iPolicyRequests.Count() > 0 ); |
|
378 CancelRequest( EMPMProcessError ); |
|
379 } |
|
380 |
|
381 // ----------------------------------------------------------------------------- |
|
382 // CMPMPolicyRequests::ReselectIAPL() |
|
383 // ----------------------------------------------------------------------------- |
|
384 // |
|
385 void CMPMPolicyRequests::ReselectIAPL( TConnPref* aPolicyPref, |
|
386 MMPMPolicyRequestsUser* aUser ) |
|
387 { |
|
388 S60MCPRLOGSTRING1( "S60MCPR::CMPMPolicyRequests<%x>::ReselectIAPL()", this ) |
|
389 //Call MPM to get the list of potential IAPs for the connection |
|
390 // |
|
391 PolicyRequest policydata = PolicyRequest(); |
|
392 |
|
393 policydata.iRequestType = EPolicyRequestReselectBestIAP; |
|
394 policydata.iConnId = iConnId; |
|
395 policydata.iPolicyPref = aPolicyPref; |
|
396 policydata.iUser = aUser; |
|
397 |
|
398 // Add it to the array of uncompleted requests |
|
399 iPolicyRequests.AppendL( policydata ); |
|
400 |
|
401 IssueRequest(); |
|
402 } |
|
403 |
|
404 // ----------------------------------------------------------------------------- |
|
405 // CMPMPolicyRequests::ProcessErrorL |
|
406 // ----------------------------------------------------------------------------- |
|
407 // |
|
408 void CMPMPolicyRequests::ProcessErrorL( TInt& anError, |
|
409 MMPMPolicyRequestsUser* aUser ) |
|
410 { |
|
411 S60MCPRLOGSTRING2( "S60MCPR::CMPMPolicyRequests<%x>::ProcessErrorL() %d", this, anError ) |
|
412 |
|
413 // insert into array of pending policy request |
|
414 PolicyRequest policydata = PolicyRequest(); |
|
415 |
|
416 policydata.iRequestType = EPolicyRequestProcessError; |
|
417 policydata.iError = anError; |
|
418 policydata.iConnId = iConnId; |
|
419 policydata.iUser = aUser; |
|
420 |
|
421 // Add it to the array of uncompleted requests |
|
422 iPolicyRequests.AppendL( policydata ); |
|
423 |
|
424 IssueRequest(); |
|
425 } |
|
426 |
|
427 // ----------------------------------------------------------------------------- |
|
428 // CMPMPolicyRequests::IssueDeleteRequest |
|
429 // ----------------------------------------------------------------------------- |
|
430 // |
|
431 void CMPMPolicyRequests::IssueDeleteRequest() |
|
432 { |
|
433 ASSERT( !IsActive() ); |
|
434 // Always cancel & delete policynotifications. |
|
435 if ( iMpm.Connected() && iPolicyNotifications->IsActive() ) |
|
436 { |
|
437 S60MCPRLOGSTRING1( "S60MCPR::CMPMPolicyRequests<%x>::IssueDeleteRequest() Asynch", this ) |
|
438 iPolicyNotifications->CancelRequestAndDestroyD( &iStatus ); |
|
439 iPolicyNotifications = NULL; |
|
440 SetActive(); |
|
441 } |
|
442 else if ( iPolicyNotifications ) |
|
443 { |
|
444 S60MCPRLOGSTRING1( "S60MCPR::CMPMPolicyRequests<%x>::IssueDeleteRequest() Immediate", this ) |
|
445 iPolicyNotifications->CancelRequestAndDestroyD(); |
|
446 iPolicyNotifications = NULL; |
|
447 delete this; |
|
448 } |
|
449 else |
|
450 { |
|
451 S60MCPRLOGSTRING1( "S60MCPR::CMPMPolicyRequests<%x>::IssueDeleteRequest() Invalid state", this ) |
|
452 } |
|
453 } |
|
454 |
|
455 // ----------------------------------------------------------------------------- |
|
456 // CMPMPolicyRequests::IssueRequest |
|
457 // ----------------------------------------------------------------------------- |
|
458 // |
|
459 void CMPMPolicyRequests::IssueRequest() |
|
460 { |
|
461 //__ASSERT_ALWAYS(IsActive() || iPolicyRequests.Count() > 0,User::Panic(KNetMCprPanic, KPanicInvalidCActiveUsage)); |
|
462 |
|
463 // If we have a pending request, back off. |
|
464 // |
|
465 if ( IsActive() || iPolicyRequests.Count() == 0 ) |
|
466 { |
|
467 S60MCPRLOGSTRING1( "S60MCPR::CMPMPolicyRequests<%x>::IssueRequest() Unnecessary call, back off", this ) |
|
468 return; |
|
469 } |
|
470 |
|
471 if ( !iMpm.Connected() ) |
|
472 { |
|
473 PolicyRequest policydata = PolicyRequest(); |
|
474 policydata.iRequestType = EPolicyRequestConnect; |
|
475 // OK because default granularity is 8 and this is done when first request arrives. |
|
476 iPolicyRequests.Insert(policydata, 0); |
|
477 } |
|
478 |
|
479 S60MCPRLOGSTRING2( "S60MCPR::CMPMPolicyRequests<%x>::IssueRequest() iRequestType %d", this, (TInt)iPolicyRequests[0].iRequestType ) |
|
480 // |
|
481 // else we submit a new one. |
|
482 switch ( iPolicyRequests[0].iRequestType ) |
|
483 { |
|
484 case EPolicyRequestConnect: |
|
485 { |
|
486 iMpm.Connect( iStatus ); |
|
487 SetActive(); |
|
488 break; |
|
489 } |
|
490 case EPolicyRequestChooseBestIAP: |
|
491 { |
|
492 //LOG(ESockLog::Printf(KESockMetaConnectionTag, _L8("\tcall MPM ChooseBestIAP"))); |
|
493 iMpm.ChooseBestIAP( ( *iPolicyRequests[0].iConnPref ), |
|
494 iPolicyRequests[0].iConnId, |
|
495 iPolicyRequests[0].iAppUid, |
|
496 ( *iPolicyRequests[0].iPolicyPref ), |
|
497 iStatus ); |
|
498 SetActive(); |
|
499 break; |
|
500 } |
|
501 case EPolicyRequestReselectBestIAP: |
|
502 { |
|
503 iMpm.ReselectBestIAP( iPolicyRequests[0].iConnId, |
|
504 ( *iPolicyRequests[0].iPolicyPref ), |
|
505 iStatus ); |
|
506 SetActive(); |
|
507 break; |
|
508 } |
|
509 case EPolicyRequestIAPConnectionStarted: |
|
510 { |
|
511 iMpm.IAPConnectionStarted( iPolicyRequests[0].iIapId, |
|
512 iPolicyRequests[0].iConnId, |
|
513 iStatus ); |
|
514 SetActive(); |
|
515 break; |
|
516 } |
|
517 case EPolicyRequestIAPConnectionStopped: |
|
518 { |
|
519 iMpm.IAPConnectionStopped( iPolicyRequests[0].iIapId, |
|
520 iPolicyRequests[0].iConnId, |
|
521 iStatus ); |
|
522 SetActive(); |
|
523 break; |
|
524 } |
|
525 case EPolicyRequestApplicationJoinsConnection: |
|
526 { |
|
527 iMpm.ApplicationJoinsConnection( iPolicyRequests[0].iIapId, |
|
528 iPolicyRequests[0].iConnId, |
|
529 iStatus ); |
|
530 SetActive(); |
|
531 break; |
|
532 } |
|
533 case EPolicyRequestApplicationLeavesConnection: |
|
534 { |
|
535 iMpm.ApplicationLeavesConnection( iPolicyRequests[0].iIapId, |
|
536 iPolicyRequests[0].iConnId, |
|
537 iStatus ); |
|
538 SetActive(); |
|
539 break; |
|
540 } |
|
541 case EPolicyRequestApplicationConnectionEnds: |
|
542 { |
|
543 iMpm.ApplicationConnectionEnds( iPolicyRequests[0].iConnId, |
|
544 iStatus ); |
|
545 SetActive(); |
|
546 break; |
|
547 } |
|
548 case EPolicyRequestRegisterPrefIAPNotif: |
|
549 { |
|
550 iMpm.RegisterPrefIAPNotif( iPolicyRequests[0].iConnId, |
|
551 iStatus ); |
|
552 SetActive(); |
|
553 break; |
|
554 } |
|
555 case EPolicyRequestUnregisterPrefIAPNotif: |
|
556 { |
|
557 iMpm.UnregisterPrefIAPNotif( iPolicyRequests[0].iConnId, |
|
558 iStatus ); |
|
559 SetActive(); |
|
560 break; |
|
561 } |
|
562 case EPolicyRequestApplicationIgnoredTheCarrier: |
|
563 { |
|
564 iMpm.ApplicationIgnoredTheCarrier( iPolicyRequests[0].iIapId, |
|
565 iPolicyRequests[0].iConnId, |
|
566 iStatus ); |
|
567 SetActive(); |
|
568 break; |
|
569 } |
|
570 case EPolicyRequestApplicationMigratesToCarrier: |
|
571 { |
|
572 iMpm.ApplicationMigratesToCarrier( iPolicyRequests[0].iIapId, |
|
573 iPolicyRequests[0].iConnId, |
|
574 iStatus ); |
|
575 SetActive(); |
|
576 break; |
|
577 } |
|
578 case EPolicyRequestApplicationRejectedTheCarrier: |
|
579 { |
|
580 iMpm.ApplicationRejectedTheCarrier( iPolicyRequests[0].iIapId, |
|
581 iPolicyRequests[0].iConnId, |
|
582 iStatus ); |
|
583 SetActive(); |
|
584 break; |
|
585 } |
|
586 case EPolicyRequestApplicationAcceptedTheCarrier: |
|
587 { |
|
588 iMpm.ApplicationAcceptedTheCarrier( iPolicyRequests[0].iIapId, |
|
589 iPolicyRequests[0].iConnId, |
|
590 iStatus ); |
|
591 SetActive(); |
|
592 break; |
|
593 } |
|
594 case EPolicyRequestProcessError: |
|
595 { |
|
596 //LOG(ESockLog::Printf(KESockMetaConnectionTag, _L8("\tcall MPM ProcessError"))); |
|
597 iMpm.ProcessError( iPolicyRequests[0].iError, |
|
598 iPolicyRequests[0].iConnId, |
|
599 iPolicyRequests[0].iNeededAction, |
|
600 iStatus ); |
|
601 SetActive(); |
|
602 break; |
|
603 } |
|
604 default: |
|
605 { |
|
606 #ifdef _DEBUG |
|
607 // In debug builds, panic |
|
608 _LIT( KPanicMsg, "CMPMPolicyRequests::IssueRequestL: Invalid case" ); |
|
609 User::Panic( KPanicMsg, KErrNotSupported ); |
|
610 #endif |
|
611 break; |
|
612 } |
|
613 } |
|
614 } |
|
615 |
|
616 // ----------------------------------------------------------------------------- |
|
617 // CMPMPolicyRequests::RunL |
|
618 // ----------------------------------------------------------------------------- |
|
619 // |
|
620 void CMPMPolicyRequests::RunL() |
|
621 { |
|
622 S60MCPRLOGSTRING2( "S60MCPR::CMPMPolicyRequests<%x>::RunL() iStatus %d", this, iStatus.Int() ) |
|
623 |
|
624 // If there's a request waiting and is now completed |
|
625 // |
|
626 if ( iPolicyRequests.Count() > 0 && !iCommitedToDeleteItself) |
|
627 { |
|
628 S60MCPRLOGSTRING1( "S60MCPR::CMPMPolicyRequests<%x>::RunL() Standard processing", this ) |
|
629 PolicyRequest& policydata = iPolicyRequests[0]; |
|
630 // Process the response |
|
631 // |
|
632 switch ( policydata.iRequestType ) |
|
633 { |
|
634 case EPolicyRequestConnect: |
|
635 { |
|
636 if ( iStatus.Int() != KErrNone ) |
|
637 { |
|
638 //-jl- MPM connection failed, set MPM connection required again. |
|
639 iMpm.Close(); |
|
640 //-jl- Go to RunError |
|
641 User::Leave( iStatus.Int() ); |
|
642 } |
|
643 else |
|
644 { |
|
645 // Otherwise MPM ok and start listening for notifications |
|
646 iPolicyNotifications->Activate(); |
|
647 } |
|
648 break; |
|
649 } |
|
650 case EPolicyRequestProcessError: |
|
651 case EPolicyRequestChooseBestIAP: |
|
652 case EPolicyRequestReselectBestIAP: |
|
653 { |
|
654 if ( policydata.iUser ) |
|
655 { |
|
656 // ChooseBest IAP is completed by iUser. |
|
657 // |
|
658 policydata.iStatus = iStatus.Int(); |
|
659 policydata.iUser->PolicyResponse( policydata ); |
|
660 } |
|
661 break; |
|
662 } |
|
663 // With these messages we ignore the result. |
|
664 case EPolicyRequestRegisterPrefIAPNotif: |
|
665 case EPolicyRequestUnregisterPrefIAPNotif: |
|
666 case EPolicyRequestApplicationIgnoredTheCarrier: |
|
667 case EPolicyRequestApplicationMigratesToCarrier: |
|
668 case EPolicyRequestApplicationRejectedTheCarrier: |
|
669 case EPolicyRequestApplicationAcceptedTheCarrier: |
|
670 case EPolicyRequestIAPConnectionStarted: |
|
671 case EPolicyRequestIAPConnectionStopped: |
|
672 case EPolicyRequestApplicationJoinsConnection: |
|
673 case EPolicyRequestApplicationLeavesConnection: |
|
674 case EPolicyRequestApplicationConnectionEnds: |
|
675 { |
|
676 #ifdef _DEBUG |
|
677 if ( iStatus.Int() != KErrNone ) |
|
678 { |
|
679 S60MCPRLOGSTRING3( "S60MCPR::CMPMPolicyRequests<%x>::RunL() Request %d failed %d", |
|
680 this, (TInt) policydata.iRequestType, iStatus.Int() ) |
|
681 } |
|
682 #endif // _DEBUG |
|
683 break; |
|
684 } |
|
685 default: |
|
686 { |
|
687 #ifdef _DEBUG |
|
688 // In debug builds, panic |
|
689 _LIT( KPanicMsg, "CMPMPolicyRequests::RunL: Invalid case" ); |
|
690 User::Panic( KPanicMsg, KErrNotSupported ); |
|
691 #endif |
|
692 break; |
|
693 } |
|
694 } |
|
695 // Then cleanup |
|
696 // |
|
697 policydata.Cleanup(); |
|
698 iPolicyRequests.Remove( 0 ); // remove request from the array |
|
699 // And if there are still pending request, cotinue with the next one |
|
700 // |
|
701 if ( iPolicyRequests.Count() > 0 ) |
|
702 { |
|
703 IssueRequest(); |
|
704 } |
|
705 } |
|
706 // We have pending requests but we have commited to delete itself |
|
707 // |
|
708 else if ( iPolicyRequests.Count() > 0 && iCommitedToDeleteItself ) |
|
709 { |
|
710 S60MCPRLOGSTRING1( "S60MCPR::CMPMPolicyRequests<%x>::RunL() Processing pending requests before delete", this ) |
|
711 // Submit pending requests to keep MPM in consistent state. |
|
712 // First cleanup the old one |
|
713 // |
|
714 iPolicyRequests[0].Cleanup(); |
|
715 iPolicyRequests.Remove( 0 ); // remove request from the array |
|
716 // And if there are still pending request, cotinue with the next one |
|
717 // |
|
718 if ( iPolicyRequests.Count() > 0 ) |
|
719 { |
|
720 IssueRequest(); |
|
721 } |
|
722 // In this case we've processed everything and can close. |
|
723 // |
|
724 else |
|
725 { |
|
726 IssueDeleteRequest(); |
|
727 } |
|
728 } |
|
729 else if ( iPolicyRequests.Count() == 0 && iCommitedToDeleteItself ) |
|
730 { |
|
731 S60MCPRLOGSTRING1( "S60MCPR::CMPMPolicyRequests<%x>::RunL() About to delete itself", this ) |
|
732 ASSERT( !iPolicyNotifications ); |
|
733 delete this; |
|
734 } |
|
735 else |
|
736 { |
|
737 // INVALID STATE |
|
738 #ifdef _DEBUG |
|
739 // In debug builds, panic |
|
740 _LIT( KPanicMsg, "CMPMPolicyRequests::RunL: Invalid state" ); |
|
741 User::Panic( KPanicMsg, KErrNotSupported ); |
|
742 #endif |
|
743 // Even still, make sure we don't leak memory |
|
744 // |
|
745 iPolicyNotifications->CancelRequestAndDestroyD(); |
|
746 iPolicyNotifications = NULL; |
|
747 delete this; |
|
748 } |
|
749 } |
|
750 |
|
751 |
|
752 // ----------------------------------------------------------------------------- |
|
753 // CMPMPolicyRequests::DoCancel |
|
754 // ----------------------------------------------------------------------------- |
|
755 // |
|
756 void CMPMPolicyRequests::DoCancel() |
|
757 { |
|
758 // Not allowed! Cancel() may cause deadlock! |
|
759 _LIT( KPanicMsg, "CMPMPolicyRequests::DoCancel" ); |
|
760 User::Panic( KPanicMsg, KErrNotSupported ); |
|
761 } |
|
762 |
|
763 |
|
764 // ----------------------------------------------------------------------------- |
|
765 // CMPMPolicyRequests::RunError |
|
766 // ----------------------------------------------------------------------------- |
|
767 // |
|
768 TInt CMPMPolicyRequests::RunError( TInt aError ) |
|
769 { |
|
770 S60MCPRLOGSTRING1( "S60MCPR::CMPMPolicyRequests<%x>::RunError()", this ) |
|
771 // Connect has failed, cleanup and deliver errors |
|
772 TInt count = iPolicyRequests.Count(); |
|
773 for ( TInt i = 0; i < count; i++ ) |
|
774 { |
|
775 if ( iPolicyRequests[i].iUser ) |
|
776 { |
|
777 S60MCPRLOGSTRING2( "S60MCPR::CMPMPolicyRequests<%x>::RunError() Sending error %d in PolicyResponse", this, aError ) |
|
778 iPolicyRequests[i].iStatus = aError; |
|
779 iPolicyRequests[i].iUser->PolicyResponse( iPolicyRequests[i] ); |
|
780 } |
|
781 |
|
782 // Delete prefs |
|
783 iPolicyRequests[i].Cleanup(); |
|
784 } |
|
785 iPolicyRequests.Reset(); |
|
786 |
|
787 return KErrNone; |
|
788 } |
|
789 |
|
790 |
|
791 // ----------------------------------------------------------------------------- |
|
792 // CMPMPolicyRequests::CancelRequest |
|
793 // ----------------------------------------------------------------------------- |
|
794 // |
|
795 void CMPMPolicyRequests::CancelRequest( TMpmAsynchCodes aRequestCode ) |
|
796 { |
|
797 // Semantics of asynchronous cancellations: |
|
798 // |
|
799 // The biggest difference is that asynchronous cancellation will |
|
800 // cause RunL() -call for original request. Because of this the |
|
801 // PolicyResponse() calls must be prevented. |
|
802 // |
|
803 // Asynch Cancellation cannot be queued along with the other requests. |
|
804 // Precondition for cancellation call to MPM is that there's an active request |
|
805 // and that request code matches to the given parameter. |
|
806 // |
|
807 // Cancellation of the unsent requests is simple. Just remove it from the queue. |
|
808 // |
|
809 // Asynchronous cancellation adds message to MPMServer's IPC queue but since we |
|
810 // queue all requests we can safely always call the SendCancelRequest() |
|
811 |
|
812 // If the cancelled request is the active one. |
|
813 // |
|
814 S60MCPRLOGSTRING2( "S60MCPR::CMPMPolicyRequests<%x>::CancelRequest() %d", this, (TInt)aRequestCode ) |
|
815 if ( iPolicyRequests[0].iRequestType == aRequestCode ) |
|
816 { |
|
817 // Cancel the query if active |
|
818 // |
|
819 if ( IsActive() ) |
|
820 { |
|
821 S60MCPRLOGSTRING1( "S60MCPR::CMPMPolicyRequests<%x>::CancelRequest() Cancelling active request", this ) |
|
822 #ifdef _DEBUG |
|
823 TInt ret = iMpm.SendCancelRequest( aRequestCode ); |
|
824 #else |
|
825 iMpm.SendCancelRequest( aRequestCode ); |
|
826 #endif |
|
827 __ASSERT_DEBUG( ret == KErrNone, User::Panic( KS60MCprPanic, ret ) ); |
|
828 // Prevent the callback. |
|
829 iPolicyRequests[0].Cancel(); |
|
830 } |
|
831 // Completed or not started. Just remove the request. |
|
832 // |
|
833 else |
|
834 { |
|
835 S60MCPRLOGSTRING1( "S60MCPR::CMPMPolicyRequests<%x>::CancelRequest() Cancelling non-active request", this ) |
|
836 iPolicyRequests[0].Cleanup(); |
|
837 // remove it. |
|
838 iPolicyRequests.Remove(0); |
|
839 } |
|
840 } |
|
841 // Else we need to find it from the queue |
|
842 // |
|
843 else |
|
844 { |
|
845 S60MCPRLOGSTRING1( "S60MCPR::CMPMPolicyRequests<%x>::CancelRequest() Cancelling pending request", this ) |
|
846 TInt count = iPolicyRequests.Count(); |
|
847 for (TInt i = 1; i < count; i++) |
|
848 { |
|
849 if ( iPolicyRequests[i].iRequestType == aRequestCode ) |
|
850 { |
|
851 // Cancellable request found, clean it up |
|
852 iPolicyRequests[i].Cleanup(); |
|
853 // remove it. |
|
854 iPolicyRequests.Remove(i); |
|
855 break; // first occurence is enough. |
|
856 } |
|
857 } |
|
858 } |
|
859 } |
|
860 |
|
861 |
|
862 // ----------------------------------------------------------------------------- |
|
863 // CMPMPolicyRequests::CreatePolicyRequestL |
|
864 // ----------------------------------------------------------------------------- |
|
865 // |
|
866 void CMPMPolicyRequests::CreatePolicyRequestL( TPolicyServerOperations aRequestCode, |
|
867 const TUint32& aIapId ) |
|
868 { |
|
869 // Sanity check that we're still in business. |
|
870 if ( !iMpm.Connected() ) |
|
871 { |
|
872 return; |
|
873 } |
|
874 |
|
875 PolicyRequest policydata = PolicyRequest(); |
|
876 |
|
877 policydata.iRequestType = aRequestCode; |
|
878 policydata.iConnId = iConnId; |
|
879 policydata.iIapId = aIapId; |
|
880 |
|
881 // Add request to array of uncompleted requests |
|
882 iPolicyRequests.AppendL( policydata ); |
|
883 |
|
884 // Submit it. |
|
885 IssueRequest(); |
|
886 } |
|
887 |
|
888 |
|
889 // End of file |