|
1 // Copyright (c) 2008-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 @file |
|
18 @internalComponent |
|
19 */ |
|
20 |
|
21 #include "pdptiermanager.h" |
|
22 #include "mbmsengine.h" |
|
23 #include "pdptiermanagerselector.h" |
|
24 #include <comms-infras/ss_log.h> |
|
25 #include <comms-infras/coretiermanagerstates.h> |
|
26 #include <comms-infras/coretiermanageractivities.h> |
|
27 #include <pcktcs.h> |
|
28 |
|
29 #include "pdpmcpr.h" |
|
30 |
|
31 #ifdef SYMBIAN_TRACE_ENABLE |
|
32 #define KPDPTierMgrTag KESockMetaConnectionTag |
|
33 _LIT8(KPDPTierMgrSubTag, "pdptiermgr"); |
|
34 #endif |
|
35 |
|
36 using namespace Messages; |
|
37 using namespace MeshMachine; |
|
38 using namespace ESock; |
|
39 using namespace ConnectionServ; |
|
40 using namespace NetStateMachine; |
|
41 using namespace CommsDat; |
|
42 |
|
43 namespace PDPTierManagerActivities |
|
44 { |
|
45 DECLARE_DEFINE_ACTIVITY_MAP(stateMap) |
|
46 ACTIVITY_MAP_END_BASE(TMActivities, coreTMActivities) |
|
47 } |
|
48 |
|
49 |
|
50 CContextTypeChecker::CContextTypeChecker(RPacketService& aPacketService, MContextEventsObserver& aCallback):CActive(EPriorityStandard), |
|
51 iPacketService(aPacketService), iCallback(aCallback) |
|
52 { |
|
53 CActiveScheduler::Add(this); |
|
54 } |
|
55 |
|
56 CContextTypeChecker::~CContextTypeChecker() |
|
57 { |
|
58 iContextName = NULL; |
|
59 } |
|
60 |
|
61 void CContextTypeChecker::Start(const TName* aContextName) |
|
62 { |
|
63 iContextName = aContextName; |
|
64 iPacketService.EnumerateContextsInNif(iStatus, *iContextName, iCountInNif); |
|
65 SetActive(); |
|
66 } |
|
67 |
|
68 void CContextTypeChecker::RunL() |
|
69 { |
|
70 User::LeaveIfError(iStatus.Int()); |
|
71 if (iCountInNif == 1) // This is a primary context |
|
72 { |
|
73 iCallback.PrimaryContextAddedL(iContextName); |
|
74 } |
|
75 else |
|
76 { |
|
77 iCallback.SecondaryContextAdded(iContextName); |
|
78 } |
|
79 } |
|
80 |
|
81 void CContextTypeChecker::DoCancel() |
|
82 { |
|
83 iPacketService.CancelAsyncRequest(EPacketEnumerateContextsInNif); |
|
84 } |
|
85 |
|
86 TInt CContextTypeChecker::RunError(TInt aError) |
|
87 { |
|
88 // Report an error |
|
89 iCallback.ContextTypeCheckingError(iContextName, aError); |
|
90 return KErrNone; // Make ActiveScheduler happy |
|
91 } |
|
92 |
|
93 CPrimaryContextsMonitor::CPrimaryContextsMonitor(RPacketService& aPacketService, MContentionObserver& aCallback) : CActive(EPriorityStandard), |
|
94 iPacketService(aPacketService), iCallback(aCallback) |
|
95 { |
|
96 CActiveScheduler::Add(this); |
|
97 } |
|
98 |
|
99 CPrimaryContextsMonitor::~CPrimaryContextsMonitor() |
|
100 { |
|
101 Cancel(); |
|
102 iContextMonitors.ResetAndDestroy(); |
|
103 delete iContextTypeChecker; |
|
104 iAddedContextsNames.ResetAndDestroy(); |
|
105 } |
|
106 |
|
107 void CPrimaryContextsMonitor::StartL() |
|
108 { |
|
109 iContextTypeChecker = new(ELeave) CContextTypeChecker(iPacketService, *this); |
|
110 iState = EEnumeratingContexts; |
|
111 iPacketService.EnumerateNifs(iStatus, iInitialNifsCount); |
|
112 SetActive(); |
|
113 } |
|
114 |
|
115 void CPrimaryContextsMonitor::PrimaryContextAddedL(const TName* aContextName) |
|
116 { |
|
117 // Create new status monitor for this context |
|
118 StartContextStatusMonitoringL(*aContextName); |
|
119 RemoveContextNameAndCheckNext(aContextName); |
|
120 } |
|
121 |
|
122 void CPrimaryContextsMonitor::SecondaryContextAdded(const TName* aContextName) |
|
123 { |
|
124 // This is not a primary context, just delete its name. |
|
125 RemoveContextNameAndCheckNext(aContextName); |
|
126 } |
|
127 |
|
128 void CPrimaryContextsMonitor::RemoveContextNameAndCheckNext(const TName* aContextName) |
|
129 { |
|
130 TInt nameIndex = iAddedContextsNames.Find(aContextName); |
|
131 __ASSERT_DEBUG(nameIndex != KErrNotFound, User::Invariant()); |
|
132 delete iAddedContextsNames[nameIndex]; |
|
133 iAddedContextsNames.Remove(nameIndex); |
|
134 |
|
135 if (iAddedContextsNames.Count() > 1) |
|
136 // Should be more than one here, coz we are waiting for new context added all the time, |
|
137 // so the last one item is always empty. |
|
138 { |
|
139 iContextTypeChecker->Start(iAddedContextsNames[0]); |
|
140 } |
|
141 } |
|
142 |
|
143 void CPrimaryContextsMonitor::PrimaryContextDeleted(const CContextStatusMonitor* aContextStatusMonitor) |
|
144 { |
|
145 if (aContextStatusMonitor->IsPassedThroughActiveState()) |
|
146 { |
|
147 iCallback.ContentionResolved(); |
|
148 } |
|
149 DeleteContextStatusMonitor(aContextStatusMonitor); |
|
150 } |
|
151 |
|
152 void CPrimaryContextsMonitor::ContextTypeCheckingError(const TName* aContextName, TInt aError) |
|
153 { |
|
154 RemoveContextNameAndCheckNext(aContextName); |
|
155 ProcessError(aError); |
|
156 } |
|
157 |
|
158 |
|
159 void CPrimaryContextsMonitor::ContextMonitoringError(const CContextStatusMonitor* aContextStatusMonitor, TInt aError) |
|
160 { |
|
161 DeleteContextStatusMonitor(aContextStatusMonitor); |
|
162 ProcessError(aError); |
|
163 } |
|
164 |
|
165 void CPrimaryContextsMonitor::DeleteContextStatusMonitor(const CContextStatusMonitor* aContextStatusMonitor) |
|
166 { |
|
167 TInt monitorIndex = iContextMonitors.Find(aContextStatusMonitor); |
|
168 __ASSERT_DEBUG(monitorIndex != KErrNotFound, User::Invariant()); |
|
169 delete iContextMonitors[monitorIndex]; |
|
170 iContextMonitors.Remove(monitorIndex); |
|
171 } |
|
172 |
|
173 void CPrimaryContextsMonitor::ProcessError( |
|
174 #ifdef _DEBUG |
|
175 TInt aError |
|
176 #else //remove compilation warning in release builds |
|
177 TInt /*aError*/ |
|
178 #endif |
|
179 ) |
|
180 { |
|
181 __ASSERT_DEBUG(aError != KErrNone, User::Invariant()); |
|
182 __FLOG_STATIC1(KPDPTierMgrTag, KPDPTierMgrSubTag, _L("PDP context monitoring error: %d"), aError); |
|
183 } |
|
184 |
|
185 void CPrimaryContextsMonitor::RunL() |
|
186 { |
|
187 User::LeaveIfError(iStatus.Int()); |
|
188 SwitchStateL(); |
|
189 RPacketService::TNifInfoV2Pckg nifInfoV2Pckg(iCurrentNifInfo); |
|
190 switch(iState) |
|
191 { |
|
192 case EGettingInfo: |
|
193 StartContextStatusMonitoringL(iCurrentNifInfo.iContextName); |
|
194 iPacketService.GetNifInfo(iStatus, iCurrentNifIndex, nifInfoV2Pckg); |
|
195 ++iCurrentNifIndex; |
|
196 SetActive(); |
|
197 break; |
|
198 case EListening: |
|
199 // All functions in RPacketService and RPacketContext, |
|
200 // that can be used to check if context is primary, are asynchronous. |
|
201 // We could not call them here, coz can miss some events from NotifyContextAdded |
|
202 // So subscribe to NotifyContextAdded as soon as possible and check context |
|
203 // type using CContextTypeChecker active object |
|
204 TName *contextName = new (ELeave) TName; |
|
205 CleanupStack::PushL(contextName); |
|
206 iAddedContextsNames.AppendL(contextName); |
|
207 CleanupStack::Pop(contextName); |
|
208 // subscribe to NotifyContextAdded |
|
209 iPacketService.NotifyContextAdded(iStatus, *contextName); |
|
210 SetActive(); |
|
211 // if there are any items in iAddedContextsNames except that one that has been added above, i.e count > 1 |
|
212 // starting asynchronous context type checking |
|
213 if (!iContextTypeChecker->IsActive() && iAddedContextsNames.Count()>1) |
|
214 { |
|
215 iContextTypeChecker->Start(iAddedContextsNames[0]); |
|
216 } |
|
217 break; |
|
218 } |
|
219 } |
|
220 void CPrimaryContextsMonitor::DoCancel() |
|
221 { |
|
222 switch(iState) |
|
223 { |
|
224 case EEnumeratingContexts: |
|
225 iPacketService.CancelAsyncRequest(EPacketEnumerateNifs); |
|
226 break; |
|
227 case EGettingInfo: |
|
228 iPacketService.CancelAsyncRequest(EPacketGetNifInfo); |
|
229 break; |
|
230 case EListening: |
|
231 iPacketService.CancelAsyncRequest(EPacketNotifyContextAdded); |
|
232 break; |
|
233 } |
|
234 |
|
235 } |
|
236 |
|
237 TInt CPrimaryContextsMonitor::RunError(TInt aError) |
|
238 { |
|
239 // Process an error |
|
240 ProcessError(aError); |
|
241 return KErrNone; // Make ActiveScheduler happy |
|
242 } |
|
243 |
|
244 |
|
245 void CPrimaryContextsMonitor::SwitchStateL() |
|
246 { |
|
247 if (iState == EEnumeratingContexts) |
|
248 { |
|
249 if (iInitialNifsCount > 0) |
|
250 { |
|
251 iState = EGettingInfo; |
|
252 } |
|
253 else |
|
254 { |
|
255 iState = EListening; |
|
256 } |
|
257 } |
|
258 else if (iState == EGettingInfo && iCurrentNifIndex == iInitialNifsCount) |
|
259 { |
|
260 StartContextStatusMonitoringL(iCurrentNifInfo.iContextName); |
|
261 iState = EListening; |
|
262 } |
|
263 } |
|
264 |
|
265 void CPrimaryContextsMonitor::StartContextStatusMonitoringL(const TName& aContextName) |
|
266 { |
|
267 CContextStatusMonitor* newStatusMonitor = new (ELeave) CContextStatusMonitor(iPacketService, *this); |
|
268 CleanupStack::PushL(newStatusMonitor); |
|
269 iContextMonitors.AppendL(newStatusMonitor); |
|
270 CleanupStack::Pop(newStatusMonitor); |
|
271 newStatusMonitor->StartL(aContextName); |
|
272 } |
|
273 |
|
274 CContextStatusMonitor::CContextStatusMonitor(RPacketService& aPacketService, MContextEventsObserver& aCallback):CActive(EPriorityStandard), |
|
275 iPacketService(aPacketService), iCallback(aCallback) |
|
276 { |
|
277 CActiveScheduler::Add(this); |
|
278 } |
|
279 |
|
280 CContextStatusMonitor::~CContextStatusMonitor() |
|
281 { |
|
282 Cancel(); |
|
283 iPacketContext.Close(); |
|
284 } |
|
285 |
|
286 TBool CContextStatusMonitor::StartL(const TName& aContextName) |
|
287 { |
|
288 iContextName.Copy(aContextName); |
|
289 User::LeaveIfError(iPacketContext.OpenExistingContext(iPacketService, iContextName)); |
|
290 iPacketContext.GetStatus(iContextStatus); |
|
291 |
|
292 if (iContextStatus == RPacketContext::EStatusDeleted) |
|
293 { |
|
294 return EFalse; |
|
295 } |
|
296 |
|
297 if (iContextStatus == RPacketContext::EStatusActive || |
|
298 iContextStatus == RPacketContext::EStatusSuspended || |
|
299 iContextStatus == RPacketContext::EStatusDeactivating) |
|
300 { |
|
301 iWasActive = ETrue; |
|
302 } |
|
303 |
|
304 iPacketContext.NotifyStatusChange(iStatus, iContextStatus); |
|
305 SetActive(); |
|
306 return ETrue; |
|
307 } |
|
308 |
|
309 void CContextStatusMonitor::RunL() |
|
310 { |
|
311 User::LeaveIfError(iStatus.Int()); |
|
312 if (iContextStatus == RPacketContext::EStatusActive) |
|
313 { |
|
314 iWasActive = ETrue; |
|
315 } |
|
316 |
|
317 if (iContextStatus == RPacketContext::EStatusDeleted) |
|
318 { |
|
319 iPacketContext.CancelAsyncRequest(EPacketContextNotifyStatusChange); |
|
320 iCallback.PrimaryContextDeleted(this); |
|
321 } |
|
322 else |
|
323 { |
|
324 iPacketContext.NotifyStatusChange(iStatus, iContextStatus); |
|
325 SetActive(); |
|
326 } |
|
327 } |
|
328 |
|
329 void CContextStatusMonitor::DoCancel() |
|
330 { |
|
331 iPacketContext.CancelAsyncRequest(EPacketContextNotifyStatusChange); |
|
332 } |
|
333 |
|
334 TInt CContextStatusMonitor::RunError(TInt aError) |
|
335 { |
|
336 iCallback.ContextMonitoringError(this, aError); |
|
337 return KErrNone; |
|
338 } |
|
339 |
|
340 CPdpContentionManager* CPdpContentionManager::NewL(const ESock::CTierManagerBase& aTierManager, RPacketService& aPacketService) |
|
341 { |
|
342 CPdpContentionManager* self = new (ELeave) CPdpContentionManager(aTierManager); |
|
343 CleanupStack::PushL(self); |
|
344 self->ConstructL(aPacketService); |
|
345 CleanupStack::Pop(self); |
|
346 return self; |
|
347 } |
|
348 |
|
349 CPdpContentionManager::CPdpContentionManager(const ESock::CTierManagerBase& aTierManager): |
|
350 CContentionManager(aTierManager) |
|
351 { |
|
352 } |
|
353 |
|
354 CPdpContentionManager::~CPdpContentionManager() |
|
355 { |
|
356 delete iPrimaryContextsMonitor; |
|
357 } |
|
358 |
|
359 void CPdpContentionManager::ConstructL(RPacketService& aPacketService) |
|
360 { |
|
361 iPrimaryContextsMonitor = new (ELeave) CPrimaryContextsMonitor(aPacketService, *this); |
|
362 } |
|
363 |
|
364 void CPdpContentionManager::StartMonitoringL() |
|
365 { |
|
366 if (iPrimaryContextsMonitor) |
|
367 { |
|
368 iPrimaryContextsMonitor->StartL(); |
|
369 } |
|
370 } |
|
371 |
|
372 void CPdpContentionManager::ContentionResolved(const TContentionRequestItem& aContentionRequest, TBool aResult) |
|
373 { |
|
374 CPdpMetaConnectionProvider* pdpMcpr = static_cast<CPdpMetaConnectionProvider*>(aContentionRequest.iMcpr); |
|
375 |
|
376 pdpMcpr->ContentionResolved(aContentionRequest.iPendingCprId, aResult); |
|
377 } |
|
378 |
|
379 void CPdpContentionManager::ContentionOccured(ESock::CMetaConnectionProviderBase& aMcpr) |
|
380 { |
|
381 CPdpMetaConnectionProvider& pdpMcpr = static_cast<CPdpMetaConnectionProvider&>(aMcpr); |
|
382 |
|
383 pdpMcpr.ContentionOccured(); |
|
384 } |
|
385 |
|
386 void CPdpContentionManager::ReportContentionAvailabilityStatus(ESock::CMetaConnectionProviderBase& aMcpr, const ESock::TAvailabilityStatus& aStatus) const |
|
387 { |
|
388 CPdpMetaConnectionProvider& pdpMcpr = static_cast<CPdpMetaConnectionProvider&>(aMcpr); |
|
389 |
|
390 pdpMcpr.ReportContentionAvailabilityStatus(aStatus); |
|
391 } |
|
392 |
|
393 /** |
|
394 The NewL factory function for PDPTierManager. |
|
395 This function also acts as the single ECom entry point into this object. |
|
396 @param aFactory The reference to CTierManagerFactoryBase |
|
397 @return CPDPTierManager* |
|
398 */ |
|
399 CPDPTierManager* CPDPTierManager::NewL(ESock::CTierManagerFactoryBase& aFactory) |
|
400 { |
|
401 CPDPTierManager* self = new(ELeave)CPDPTierManager(aFactory, PDPTierManagerActivities::stateMap::Self()); |
|
402 CleanupStack::PushL(self); |
|
403 self->ConstructL(); |
|
404 CleanupStack::Pop(self); |
|
405 return self; |
|
406 } |
|
407 |
|
408 /** |
|
409 Constructor for CPDPTierManager |
|
410 */ |
|
411 CPDPTierManager::CPDPTierManager(ESock::CTierManagerFactoryBase& aFactory, |
|
412 const MeshMachine::TNodeActivityMap& aActivityMap) |
|
413 :CCoreTierManager(aFactory,aActivityMap) |
|
414 { |
|
415 LOG_NODE_CREATE(KPDPTierMgrTag, CPDPTierManager); |
|
416 } |
|
417 |
|
418 /** |
|
419 Descructor for CPDPTierManager |
|
420 */ |
|
421 CPDPTierManager::~CPDPTierManager() |
|
422 { |
|
423 LOG_NODE_DESTROY(KPDPTierMgrTag, CPDPTierManager); |
|
424 delete iPdpContentionManager; |
|
425 iPdpContentionManager = NULL; |
|
426 if (iMBMSEngine) |
|
427 { |
|
428 iMBMSEngine->Cancel(); |
|
429 delete iMBMSEngine; |
|
430 iMBMSEngine = NULL; |
|
431 } |
|
432 } |
|
433 |
|
434 /** |
|
435 Create selector for this Tier. |
|
436 @return MProviderSelector* |
|
437 */ |
|
438 MProviderSelector* CPDPTierManager::DoCreateProviderSelectorL(const Meta::SMetaData& aSelectionPreferences) |
|
439 { |
|
440 __CFLOG_VAR((KPDPTierMgrTag, KPDPTierMgrSubTag, _L8("CPdpTierManager[%08x]::DoSelectProvider()"), this)); |
|
441 return TPdpSelectorFactory::NewSelectorL(aSelectionPreferences); |
|
442 } |
|
443 |
|
444 /** |
|
445 ConstructL function of CPDPTierManager. |
|
446 This function is used to retrieve tsy name. |
|
447 @return void |
|
448 */ |
|
449 void CPDPTierManager::ConstructL() |
|
450 { |
|
451 __CFLOG_VAR((KPDPTierMgrTag, KPDPTierMgrSubTag, _L8("ConstructL::In CPDPTierManager"))); |
|
452 iMBMSEngine = CMBMSEngine::NewL(NodeId(), *this); |
|
453 } |
|
454 |
|
455 /** |
|
456 The PacketServiceAttachedCallbackL is a callback function. |
|
457 It's called by MBMSEngine when RPacketService has been attached. |
|
458 */ |
|
459 void CPDPTierManager::PacketServiceAttachedCallbackL() |
|
460 { |
|
461 if (!iPdpContentionManager) |
|
462 { |
|
463 iPdpContentionManager = CPdpContentionManager::NewL(*this, iMBMSEngine->GetRPacketService()); |
|
464 } |
|
465 static_cast<CPdpContentionManager*>(iPdpContentionManager)->StartMonitoringL(); |
|
466 } |
|
467 |
|
468 /** |
|
469 The ReceivedL function for PDPTierManager. |
|
470 The messages from RConnectionServ are received in ReceivedL function. |
|
471 @param aCFMessage The reference to Messages::TSignatureBase |
|
472 @return TInt* |
|
473 */ |
|
474 void CPDPTierManager::ReceivedL(const TRuntimeCtxId& aSender, const TNodeId& aRecipient, TSignatureBase& aMessage) |
|
475 { |
|
476 //TODO I think that the generic TCancel handling will do this - so perhaps remove this and CancelAndRemoveFromRequestList! |
|
477 if (aMessage.IsMessage<TEBase::TCancel>()) |
|
478 { |
|
479 TRAPD(err, iMBMSEngine->CancelAndRemoveFromRequestListL(aSender)); |
|
480 if (err == KErrNone) |
|
481 { |
|
482 aMessage.ClearMessageId(); |
|
483 } |
|
484 else if (err != KErrNotFound) |
|
485 { |
|
486 User::Leave(err); |
|
487 } |
|
488 // err == KErrNotFound |
|
489 // Probably this is not cancel for MBMS request but cancel for PDP availability notification request |
|
490 // It will be processed by core TM then. |
|
491 } |
|
492 |
|
493 if (aMessage.IsMessage<TCFTierStatusProvider::TTierNotificationRegistration>()) |
|
494 { |
|
495 TCFTierStatusProvider::TTierNotificationRegistration* msgTNR = message_cast<TCFTierStatusProvider::TTierNotificationRegistration>(&aMessage); |
|
496 |
|
497 const Messages::TNodeSignal::TMessageId requestType = TCFTierStatusProvider::TTierNotificationRegistration::Id(); |
|
498 CRefCountOwnedParameterBundle* requestBundleOwner = msgTNR->iBundle; |
|
499 |
|
500 TRAPD(err, iMBMSEngine->AddToRequestListL(FindClient(aSender), aSender, requestType, requestBundleOwner)); |
|
501 if (err == KErrNone) |
|
502 { |
|
503 aMessage.ClearMessageId(); |
|
504 } |
|
505 else if (err != KErrArgument) |
|
506 { |
|
507 User::Leave(err); |
|
508 } |
|
509 // err == KErrArgument |
|
510 // Probably this is not MBMS notification request but PDP availability notification request |
|
511 // It will be processed by core TM then. |
|
512 } |
|
513 |
|
514 TNodeContext<CPDPTierManager> ctx(*this, aMessage, aSender, aRecipient); |
|
515 CCoreTierManager::Received(ctx); |
|
516 User::LeaveIfError(ctx.iReturn); |
|
517 } |
|
518 |
|
519 TBool CPDPTierManager::HandleContentionL(ESock::CMetaConnectionProviderBase* aMcpr, Messages::TNodeId& aPendingCprId, TUint aPriority) |
|
520 { |
|
521 User::LeaveIfNull(iMBMSEngine); |
|
522 if (!iPdpContentionManager) |
|
523 { |
|
524 iPdpContentionManager = CPdpContentionManager::NewL(*this, iMBMSEngine->GetRPacketService()); |
|
525 } |
|
526 return iPdpContentionManager->HandleContentionL(aMcpr, aPendingCprId, aPriority); |
|
527 } |
|
528 |
|
529 TBool CPDPTierManager::IsUnavailableDueToContention(const ESock::CMetaConnectionProviderBase* aMetaConnectionProvider) const |
|
530 { |
|
531 if (!iPdpContentionManager) |
|
532 return EFalse; |
|
533 return iPdpContentionManager->IsUnavailableDueToContention(aMetaConnectionProvider); |
|
534 } |
|
535 |
|
536 |