50 DECLARE_DEFINE_ACTIVITY_MAP(stateMap) |
50 DECLARE_DEFINE_ACTIVITY_MAP(stateMap) |
51 ACTIVITY_MAP_END_BASE(TMActivities, coreTMActivities) |
51 ACTIVITY_MAP_END_BASE(TMActivities, coreTMActivities) |
52 } |
52 } |
53 |
53 |
54 |
54 |
55 CContextTypeChecker::CContextTypeChecker(RPacketService& aPacketService, MContextEventsObserver& aCallback):CActive(EPriorityStandard), |
|
56 iPacketService(aPacketService), iCallback(aCallback) |
|
57 { |
|
58 CActiveScheduler::Add(this); |
|
59 } |
|
60 |
|
61 CContextTypeChecker::~CContextTypeChecker() |
|
62 { |
|
63 iContextName = NULL; |
|
64 } |
|
65 |
|
66 void CContextTypeChecker::Start(const TName* aContextName) |
|
67 { |
|
68 iContextName = aContextName; |
|
69 iPacketService.EnumerateContextsInNif(iStatus, *iContextName, iCountInNif); |
|
70 SetActive(); |
|
71 } |
|
72 |
|
73 void CContextTypeChecker::RunL() |
|
74 { |
|
75 User::LeaveIfError(iStatus.Int()); |
|
76 if (iCountInNif == 1) // This is a primary context |
|
77 { |
|
78 iCallback.PrimaryContextAddedL(iContextName); |
|
79 } |
|
80 else |
|
81 { |
|
82 iCallback.SecondaryContextAdded(iContextName); |
|
83 } |
|
84 } |
|
85 |
|
86 void CContextTypeChecker::DoCancel() |
|
87 { |
|
88 iPacketService.CancelAsyncRequest(EPacketEnumerateContextsInNif); |
|
89 } |
|
90 |
|
91 TInt CContextTypeChecker::RunError(TInt aError) |
|
92 { |
|
93 // Report an error |
|
94 iCallback.ContextTypeCheckingError(iContextName, aError); |
|
95 return KErrNone; // Make ActiveScheduler happy |
|
96 } |
|
97 |
|
98 CPrimaryContextsMonitor::CPrimaryContextsMonitor(RPacketService& aPacketService, MContentionObserver& aCallback) : CActive(EPriorityStandard), |
|
99 iPacketService(aPacketService), iCallback(aCallback) |
|
100 { |
|
101 CActiveScheduler::Add(this); |
|
102 } |
|
103 |
|
104 CPrimaryContextsMonitor::~CPrimaryContextsMonitor() |
|
105 { |
|
106 Cancel(); |
|
107 iContextMonitors.ResetAndDestroy(); |
|
108 delete iContextTypeChecker; |
|
109 iAddedContextsNames.ResetAndDestroy(); |
|
110 } |
|
111 |
|
112 void CPrimaryContextsMonitor::StartL() |
|
113 { |
|
114 iContextTypeChecker = new(ELeave) CContextTypeChecker(iPacketService, *this); |
|
115 iState = EEnumeratingContexts; |
|
116 iPacketService.EnumerateNifs(iStatus, iInitialNifsCount); |
|
117 SetActive(); |
|
118 } |
|
119 |
|
120 void CPrimaryContextsMonitor::PrimaryContextAddedL(const TName* aContextName) |
|
121 { |
|
122 // Create new status monitor for this context |
|
123 StartContextStatusMonitoringL(*aContextName); |
|
124 RemoveContextNameAndCheckNext(aContextName); |
|
125 } |
|
126 |
|
127 void CPrimaryContextsMonitor::SecondaryContextAdded(const TName* aContextName) |
|
128 { |
|
129 // This is not a primary context, just delete its name. |
|
130 RemoveContextNameAndCheckNext(aContextName); |
|
131 } |
|
132 |
|
133 void CPrimaryContextsMonitor::RemoveContextNameAndCheckNext(const TName* aContextName) |
|
134 { |
|
135 TInt nameIndex = iAddedContextsNames.Find(aContextName); |
|
136 __ASSERT_DEBUG(nameIndex != KErrNotFound, User::Invariant()); |
|
137 delete iAddedContextsNames[nameIndex]; |
|
138 iAddedContextsNames.Remove(nameIndex); |
|
139 |
|
140 if (iAddedContextsNames.Count() > 1) |
|
141 // Should be more than one here, coz we are waiting for new context added all the time, |
|
142 // so the last one item is always empty. |
|
143 { |
|
144 iContextTypeChecker->Start(iAddedContextsNames[0]); |
|
145 } |
|
146 } |
|
147 |
|
148 void CPrimaryContextsMonitor::PrimaryContextDeleted(const CContextStatusMonitor* aContextStatusMonitor) |
|
149 { |
|
150 if (aContextStatusMonitor->IsPassedThroughActiveState()) |
|
151 { |
|
152 iCallback.ContentionResolved(); |
|
153 } |
|
154 DeleteContextStatusMonitor(aContextStatusMonitor); |
|
155 } |
|
156 |
|
157 void CPrimaryContextsMonitor::ContextTypeCheckingError(const TName* aContextName, TInt aError) |
|
158 { |
|
159 RemoveContextNameAndCheckNext(aContextName); |
|
160 ProcessError(aError); |
|
161 } |
|
162 |
|
163 |
|
164 void CPrimaryContextsMonitor::ContextMonitoringError(const CContextStatusMonitor* aContextStatusMonitor, TInt aError) |
|
165 { |
|
166 DeleteContextStatusMonitor(aContextStatusMonitor); |
|
167 ProcessError(aError); |
|
168 } |
|
169 |
|
170 void CPrimaryContextsMonitor::DeleteContextStatusMonitor(const CContextStatusMonitor* aContextStatusMonitor) |
|
171 { |
|
172 TInt monitorIndex = iContextMonitors.Find(aContextStatusMonitor); |
|
173 __ASSERT_DEBUG(monitorIndex != KErrNotFound, User::Invariant()); |
|
174 delete iContextMonitors[monitorIndex]; |
|
175 iContextMonitors.Remove(monitorIndex); |
|
176 } |
|
177 |
|
178 void CPrimaryContextsMonitor::ProcessError(TInt aError) |
|
179 { |
|
180 __ASSERT_DEBUG(aError != KErrNone, User::Invariant()); |
|
181 OstTraceDef1(OST_TRACE_CATEGORY_DEBUG, TRACE_INTERNALS, CPRIMARYCONTEXTSMONITOR_PROCESSERROR_1, ("PDP context monitoring error: %d"), aError); |
|
182 (void)aError; //needed for debug builds |
|
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 User::LeaveIfError(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 /** |
55 /** |
394 The NewL factory function for PDPTierManager. |
56 The NewL factory function for PDPTierManager. |
395 This function also acts as the single ECom entry point into this object. |
57 This function also acts as the single ECom entry point into this object. |
396 @param aFactory The reference to CTierManagerFactoryBase |
58 @param aFactory The reference to CTierManagerFactoryBase |
397 @return CPDPTierManager* |
59 @return CPDPTierManager* |