|
1 // Copyright (c) 2003-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 CNetworkController.cpp |
|
18 */ |
|
19 |
|
20 #include "CNetworkController.h" |
|
21 #include <comms-infras/nifagt.h> |
|
22 #include <comms-infras/nifif.h> |
|
23 #include <cdblen.h> |
|
24 #include "NetConPanic.h" |
|
25 #include "NetConLog.h" |
|
26 #include "CTelBearer.h" |
|
27 #include "CNetConDlgProcessor.h" |
|
28 |
|
29 CNetworkController::~CNetworkController() |
|
30 /** |
|
31 Destuctor |
|
32 |
|
33 Implementation of CNetworkController |
|
34 */ |
|
35 { |
|
36 LOG_DETAILED( NetConLog::Printf(_L("~CNetworkController()")); ) |
|
37 |
|
38 if (iImplicitNotificationCb) |
|
39 { |
|
40 delete iImplicitNotificationCb; |
|
41 } |
|
42 |
|
43 iImplicitNotifyList.Close(); |
|
44 |
|
45 if(iImplicitConnectionAgentName) |
|
46 { |
|
47 delete iImplicitConnectionAgentName; |
|
48 iImplicitConnectionAgentName = NULL; |
|
49 } |
|
50 |
|
51 // delete all CNetConRequestBase objects |
|
52 while(!iRequestQueue.IsEmpty()) |
|
53 { |
|
54 CNetConRequestBase* request = iRequestQueue.First(); |
|
55 iRequestQueue.Remove(*request); |
|
56 delete request; |
|
57 } |
|
58 iRequestQueue.Reset(); |
|
59 |
|
60 if (iCurrentRequest) |
|
61 { |
|
62 iCurrentRequest->CancelRequest(); |
|
63 delete iCurrentRequest; |
|
64 iCurrentRequest = NULL; |
|
65 } |
|
66 |
|
67 if (iProcessRequestCb) |
|
68 { |
|
69 delete iProcessRequestCb; |
|
70 } |
|
71 |
|
72 |
|
73 LOG ( NetConLog::Printf(_L("--------------- Network Controller Finished ---------------")); ) |
|
74 } |
|
75 |
|
76 CNetworkController* CNetworkController::NewL() |
|
77 /** |
|
78 Factory function |
|
79 |
|
80 @return the new CNetworkController object |
|
81 @exception leaves if memory allocation fails |
|
82 */ |
|
83 { |
|
84 LOG_DETAILED( NetConLog::Printf(_L("CNetworkController::NewL()")); ) |
|
85 CNetworkController* self = new(ELeave) CNetworkController(); |
|
86 CleanupStack::PushL(self); |
|
87 self->ConstructL(); |
|
88 CleanupStack::Pop(); // self |
|
89 return self; |
|
90 } |
|
91 |
|
92 CNetworkController::CNetworkController() |
|
93 /** |
|
94 Constructor |
|
95 */ |
|
96 { |
|
97 LOG_DETAILED( NetConLog::Printf(_L("CNetworkController()")); ) |
|
98 |
|
99 iRequestQueue.SetOffset(_FOFF(CNetConRequestBase, iLink)); |
|
100 } |
|
101 |
|
102 void CNetworkController::ConstructL() |
|
103 /** |
|
104 2nd phase of construction |
|
105 |
|
106 @exception leaves if callback, database, dialog processor or bearer construction fails |
|
107 */ |
|
108 { |
|
109 LOG ( NetConLog::Printf(_L("--------------- Network Controller Starting ---------------")); ) |
|
110 LOG_DETAILED( NetConLog::Printf(_L("Detailed logging enabled")); ) |
|
111 LOG_DETAILED( NetConLog::Printf(_L("CNetworkController::ConstructL()")); ) |
|
112 |
|
113 // create a callback for processing requests |
|
114 TCallBack callback(ProcessRequestCb, this); |
|
115 iProcessRequestCb = new(ELeave) CAsyncCallBack(callback, CActive::EPriorityStandard); |
|
116 |
|
117 // there is no existing implicitly started connection |
|
118 iImplicitConnectionAgentName = NULL; |
|
119 |
|
120 // set up callback for implicit connection event notification |
|
121 TCallBack implicitCallBack(ImplicitNotificationCb, this); |
|
122 iImplicitNotificationCb = new(ELeave) CAsyncCallBack(implicitCallBack, CActive::EPriorityStandard); |
|
123 |
|
124 // set up telephony bearer with this object as observer and dbaccess |
|
125 // note that all bearers are deleted in the CNetworkControllerBase d'tor |
|
126 CTelBearer* telBearer = CTelBearer::NewLC(this); |
|
127 AddBearerL(telBearer); |
|
128 CleanupStack::Pop(); // telBearer |
|
129 |
|
130 // ensure that the telephony bearer was added where we expect |
|
131 __ASSERT_DEBUG(iBearers[KTelBearerPosition] == telBearer, NetConPanic(NetworkController::ENetConTelBearerMissing)); |
|
132 } |
|
133 |
|
134 TInt CNetworkController::FindExistingAgentForSelection(CNifAgentBase*& aAgent, CCommsDbAccess* aDatabase) const |
|
135 /** |
|
136 Searches for an Agent associated with the selected IAP |
|
137 |
|
138 @note that there is a one-to-one relationship between agents and IAPs |
|
139 @param aAgent if found a pointer to the CNifAgentBase |
|
140 @return KErrNotFound if the agent with selected IAP is not found else KErrNone |
|
141 @pre the selected IAP setting is stored in the DbAccess object. |
|
142 */ |
|
143 { |
|
144 LOG_DETAILED( NetConLog::Printf(_L("CNetworkController::FindExistingAgentForSelection()")); ) |
|
145 |
|
146 // read the CommDb ID of the current IAP |
|
147 TUint32 iapId(0); |
|
148 TInt err(KErrNone); |
|
149 |
|
150 TRAP(err, aDatabase->GetIntL(TPtrC(IAP), TPtrC(COMMDB_ID), iapId)); |
|
151 if (err != KErrNone) |
|
152 { |
|
153 return KErrNotFound; |
|
154 } |
|
155 |
|
156 // read network ID of the current IAP |
|
157 TUint32 networkId(0); |
|
158 TRAP(err, aDatabase->GetIntL(TPtrC(IAP), TPtrC(IAP_NETWORK), networkId)); |
|
159 if (err != KErrNone) |
|
160 { |
|
161 return KErrNotFound; |
|
162 } |
|
163 |
|
164 // find the network |
|
165 CNetwork* network = NULL; |
|
166 err = FindNetworkById(networkId, network); |
|
167 if (err!=KErrNone) |
|
168 { |
|
169 return err; |
|
170 } |
|
171 |
|
172 // ask network to find the agent |
|
173 return network->FindAgentByIap(iapId, aAgent); |
|
174 } |
|
175 |
|
176 void CNetworkController::SelectAgent(MNetworkControllerObserver* aObserver, MServiceChangeObserver* apServiceChangeObserver, TConnStartType aStartType, TInt aConnectionAttempt, TInt aLastConnectionError, const TConnPref& aPrefs) |
|
177 |
|
178 /** |
|
179 Adds a selection request to the queue and calls the Process Request Callback |
|
180 This allows the current callstack to unwind. Processing is resumed at ProcessRequestCb |
|
181 |
|
182 @param aObserver the pointer to the MNetworkControllerObserver that requested the selection |
|
183 @param apServiceChangeObserver that requests service change notification |
|
184 @param aStartType how this connection request was started - either Implicit or Explicit |
|
185 @param aConnectionAttempt the connection attempt |
|
186 @param aLastConnectionError if this is not the first connection attempt the error from the last connection |
|
187 @param aPrefs the connection preferences to use in preference(?!) to the ones stored in commdb |
|
188 */ |
|
189 { |
|
190 LOG_DETAILED( NetConLog::Printf(_L("CNetworkController::SelectAgent()")); ) |
|
191 |
|
192 // create a new request and add it to the queue |
|
193 CNetConRequestBase* newRequest = NULL; |
|
194 TRAPD(err, newRequest = CSelectionRequest::NewL(this, aObserver, aStartType, aPrefs, aConnectionAttempt, aLastConnectionError)); |
|
195 if(err!=KErrNone) |
|
196 { |
|
197 aObserver->SelectComplete(err); |
|
198 return; |
|
199 } |
|
200 |
|
201 newRequest->ipServiceChangeObserver = apServiceChangeObserver; |
|
202 iRequestQueue.AddLast(*newRequest); |
|
203 |
|
204 LOG( NetConLog::Printf(_L("\tAdded request [0x%08x] to queue"), newRequest); ) |
|
205 |
|
206 // start to process request if not already processing |
|
207 if(!iCurrentRequest) |
|
208 { |
|
209 iProcessRequestCb->CallBack(); |
|
210 } |
|
211 } |
|
212 |
|
213 void CNetworkController::SelectAgent(MNetworkControllerObserver* aObserver, MServiceChangeObserver* apServiceChangeObserver, TConnStartType aStartType, TInt aConnectionAttempt, TInt aLastConnectionError) |
|
214 |
|
215 /** |
|
216 SelectAgent |
|
217 |
|
218 @param aObserver the pointer to the MNetworkControllerObserver that requested the selection |
|
219 @param apServiceChangeObserver that requests service change notification |
|
220 @param aStartType how this connection request was started - either Implicit or Explicit |
|
221 @param aConnectionAttempt the connection attempt |
|
222 @param aLastConnectionError if this is not the first connection attempt the error from the last connection |
|
223 */ |
|
224 { |
|
225 LOG_DETAILED( NetConLog::Printf(_L("CNetworkController::SelectAgent2()")); ) |
|
226 |
|
227 // construct some default connection preference - this will cause the default commdb settings to be used |
|
228 TConnPref prefs; |
|
229 |
|
230 SelectAgent(aObserver, apServiceChangeObserver, aStartType, aConnectionAttempt, aLastConnectionError, prefs); |
|
231 } |
|
232 |
|
233 void CNetworkController::Reconnect(MNetworkControllerObserver* aObserver, CNifAgentBase* aAgent) |
|
234 /** |
|
235 Reconnect |
|
236 |
|
237 @param aObserver the pointer to the MNetworkControllerObserver that requested the selection |
|
238 @param aAgent,the agent who's connection failed |
|
239 */ |
|
240 { |
|
241 LOG_DETAILED( NetConLog::Printf(_L("CNetworkController::Reconnect()")); ) |
|
242 |
|
243 Reconnect(aObserver, aAgent, NULL); |
|
244 } |
|
245 |
|
246 void CNetworkController::Reconnect(MNetworkControllerObserver* aObserver, CNifAgentBase* aAgent, CStoreableOverrideSettings* aOverrides) |
|
247 /** |
|
248 Adds a reconnect request to the queue and calls the Process Request Callback |
|
249 This allows the current callstack to unwind. Processing is resumed at ProcessRequestCb |
|
250 |
|
251 @param aObserver the pointer to the MNetworkControllerObserver that requested the selection |
|
252 @param aAgent,the agent who's connection failed |
|
253 @param aOverrides,pointer to the override settings to store. |
|
254 @note that ownership of these overrides is retained by the caller. |
|
255 */ |
|
256 { |
|
257 LOG_DETAILED( NetConLog::Printf(_L("CNetworkController::Reconnect2()")); ) |
|
258 |
|
259 CNetConRequestBase* newRequest = NULL; |
|
260 TRAPD(err, newRequest = CReconnectRequest::NewL(this, aObserver, aAgent, aOverrides);) |
|
261 if(err!=KErrNone) |
|
262 { |
|
263 aObserver->ReconnectComplete(err); |
|
264 return; |
|
265 } |
|
266 |
|
267 iRequestQueue.AddLast(*newRequest); |
|
268 |
|
269 LOG( NetConLog::Printf(_L("\tAdded request [0x%08x] to queue"), newRequest); ) |
|
270 |
|
271 // start to process request if not already processing |
|
272 if(!iCurrentRequest) |
|
273 { |
|
274 iProcessRequestCb->CallBack(); |
|
275 } |
|
276 } |
|
277 |
|
278 TInt CNetworkController::CancelRequest(MNetworkControllerObserver* aObserver) |
|
279 /** |
|
280 Cancel the request made by aObserver. |
|
281 If this request is currently being processed then stop processing immediately. |
|
282 |
|
283 @param aObserver pointer to the object that initiated the request |
|
284 @return KErrNone if the request was found and cancelled ok otherwise KErrNotFound |
|
285 */ |
|
286 { |
|
287 LOG_DETAILED( NetConLog::Printf(_L("CNetworkController::CancelRequest()")); ) |
|
288 |
|
289 TInt retval(KErrNotFound); |
|
290 CNetConRequestBase* request = NULL; |
|
291 |
|
292 // find the request to cancel |
|
293 if (iCurrentRequest && iCurrentRequest->Observer() == aObserver) |
|
294 { |
|
295 LOG( NetConLog::Printf(_L("\tCancelled request [0x%08x]"), iCurrentRequest); ) |
|
296 |
|
297 // cancel the active request - this will cancel all bearer checking and any dialog box activity |
|
298 iCurrentRequest->CancelRequest(); |
|
299 |
|
300 // delete the request |
|
301 delete iCurrentRequest; |
|
302 iCurrentRequest = NULL; |
|
303 |
|
304 // trigger callback to process next request in the queue |
|
305 iProcessRequestCb->CallBack(); |
|
306 |
|
307 retval = KErrNone; |
|
308 } |
|
309 else |
|
310 { |
|
311 TSglQueIter<CNetConRequestBase> iter(iRequestQueue); |
|
312 |
|
313 while ((request = iter++) != NULL) |
|
314 { |
|
315 if (request->Observer() == aObserver) |
|
316 { |
|
317 // remove request from queue |
|
318 iRequestQueue.Remove(*request); |
|
319 |
|
320 LOG( NetConLog::Printf(_L("\tCancelled request [0x%08x]"), request); ) |
|
321 |
|
322 // note: don't call Cancel() on this request as it is not active |
|
323 |
|
324 // delete the request |
|
325 delete request; |
|
326 request = NULL; |
|
327 |
|
328 retval = KErrNone; |
|
329 break; |
|
330 } |
|
331 } |
|
332 } |
|
333 |
|
334 return retval; |
|
335 } |
|
336 |
|
337 void CNetworkController::AgentConnectionFailure(CNifAgentBase* aAgent, TInt aError) |
|
338 /** |
|
339 A connection has failed. |
|
340 |
|
341 @param aAgent the agent who's connection failed |
|
342 @param aError the reason for the failure |
|
343 */ |
|
344 { |
|
345 LOG_DETAILED( NetConLog::Printf(_L("CNetworkController::AgentConnectionFailure()")); ) |
|
346 |
|
347 if(!aAgent) |
|
348 { |
|
349 return; |
|
350 } |
|
351 |
|
352 // retrieve agent name |
|
353 TNifAgentInfo info; |
|
354 aAgent->Info(info); |
|
355 |
|
356 LOG( NetConLog::Printf(_L("\tAgent '%S' has disconnected with error %d"), &info.iName, aError); ) |
|
357 |
|
358 // remove warning - the error code is not used in all builds |
|
359 (void)aError; |
|
360 |
|
361 // if the agent was the one for implicit connections |
|
362 // then remove the stored name |
|
363 if(iImplicitConnectionAgentName && info.iName == *iImplicitConnectionAgentName) |
|
364 { |
|
365 delete iImplicitConnectionAgentName; |
|
366 iImplicitConnectionAgentName = NULL; |
|
367 |
|
368 (void)GetConnectionInfo(aAgent, iImplicitNotifyInfo); |
|
369 iImplicitNotifyEvent = MImplicitConnectionNotify::EImplicitConnectionDown; |
|
370 iImplicitNotificationCb->CallBack(); |
|
371 } |
|
372 |
|
373 TInt i(0); |
|
374 // remove this agent from any bearers |
|
375 for (i=0; i<iBearers.Count(); ++i) |
|
376 { |
|
377 CBearerBase* bearer = iBearers[i]; |
|
378 // try and remove the agent from this bearer - ignore Not Found error |
|
379 TRAPD(err, bearer->RemoveAgentL(aAgent)); |
|
380 if (KErrNone != err) |
|
381 { |
|
382 LOG( NetConLog::Printf(_L("\tERROR: Agent has disconnected from bearer with error %d"), err); ) |
|
383 } |
|
384 } |
|
385 |
|
386 // remove this agent from its network |
|
387 for (i=0; i<iNetworks.Count(); ++i) |
|
388 { |
|
389 CNetwork* network = iNetworks[i]; |
|
390 // try and remove the agent from this network - ignore Not Found error |
|
391 TRAPD(err, network->RemoveAgentL(aAgent)); |
|
392 if (KErrNone != err) |
|
393 { |
|
394 LOG( NetConLog::Printf(_L("\tERROR: Agent has disconnected from network with error %d"), err); ) |
|
395 } |
|
396 } |
|
397 } |
|
398 |
|
399 TInt CNetworkController::GetConnectionInfo(CNifAgentBase* aAgent, TDes8& aConnectionInfo) |
|
400 { |
|
401 LOG_DETAILED( NetConLog::Printf(_L("CNetworkController::GetConnectionInfo()")); ) |
|
402 |
|
403 _LIT(KIapId, "IAP\\Id"); |
|
404 _LIT(KNetId, "IAP\\IAPNetwork"); |
|
405 |
|
406 TSoIfConnectionInfo info; |
|
407 TInt err = aAgent->ReadInt(KIapId(), info.iIAPId); |
|
408 if(err!=KErrNone) |
|
409 { |
|
410 return err; |
|
411 } |
|
412 |
|
413 err = aAgent->ReadInt(KNetId(), info.iNetworkId); |
|
414 if(err!=KErrNone) |
|
415 { |
|
416 return err; |
|
417 } |
|
418 |
|
419 |
|
420 aConnectionInfo = TPckg<TSoIfConnectionInfo>(info); |
|
421 return KErrNone; |
|
422 } |
|
423 |
|
424 TInt CNetworkController::ProcessRequestCb(TAny* aThisPtr) |
|
425 /** |
|
426 ProcessRequestCb |
|
427 |
|
428 @param aThisPtr the pointer to the object that initiated the callback |
|
429 @return KErrNone always |
|
430 */ |
|
431 { |
|
432 CNetworkController* self = static_cast<CNetworkController*>(aThisPtr); |
|
433 self->ProcessRequest(); |
|
434 return KErrNone; |
|
435 } |
|
436 |
|
437 void CNetworkController::ProcessRequest() |
|
438 /** |
|
439 ProcessRequest |
|
440 Deque a request and start to process it. |
|
441 */ |
|
442 { |
|
443 LOG_DETAILED( NetConLog::Printf(_L("CNetworkController::ProcessRequest()")); ) |
|
444 LOG ( |
|
445 if (iCurrentRequest) |
|
446 NetConLog::Printf(_L("\tCurrently processing request [0x%08x]"), iCurrentRequest); |
|
447 else |
|
448 NetConLog::Printf(_L("\tNot currently processing any request")); |
|
449 |
|
450 if (!iRequestQueue.IsEmpty()) |
|
451 NetConLog::Printf(_L("\tSome requests are queued")); |
|
452 else |
|
453 NetConLog::Printf(_L("\tRequest queue is empty")); |
|
454 ) |
|
455 |
|
456 if (iCurrentRequest) |
|
457 { |
|
458 return; // we are already processing a request |
|
459 } |
|
460 |
|
461 if (!iRequestQueue.IsEmpty()) |
|
462 { |
|
463 iCurrentRequest = iRequestQueue.First(); |
|
464 iRequestQueue.Remove(*iCurrentRequest); |
|
465 LOG( NetConLog::Printf(_L("--------------- Starting to process request [0x%08x] ---------------"), iCurrentRequest); ) |
|
466 iCurrentRequest->StartRequest(); |
|
467 } |
|
468 } |
|
469 |
|
470 void CNetworkController::RequestComplete(const CSelectionRequest* aRequest, TInt aError) |
|
471 /** |
|
472 A selection request has been processed - queue another one. |
|
473 |
|
474 @param aRequest pointer to the actual selection request |
|
475 @param aError contains the reason for failure of processing the request or KErrNone |
|
476 */ |
|
477 { |
|
478 LOG_DETAILED( NetConLog::Printf(_L("CNetworkController::RequestComplete()")); ) |
|
479 __ASSERT_ALWAYS((CNetConRequestBase*)aRequest == iCurrentRequest, NetConPanic(NetworkController::ENetConBadRequestCallback)); |
|
480 |
|
481 LOG( NetConLog::Printf(_L("--------------- Finished processing request [0x%08x] ---------------"), iCurrentRequest); ) |
|
482 |
|
483 // Trigger callback to process next request in the queue |
|
484 iProcessRequestCb->CallBack(); |
|
485 |
|
486 // if this was an implicit request then store the name of the agent for other implicit requests |
|
487 if (aError == KErrNone && aRequest->ConnectionStartType() == EConnStartImplicit) |
|
488 { |
|
489 if(!iImplicitConnectionAgentName) |
|
490 { |
|
491 TRAPD(err, iImplicitConnectionAgentName = (aRequest->AgentName()).AllocL()); |
|
492 if (err != KErrNone) |
|
493 { |
|
494 aError = err; |
|
495 } |
|
496 else |
|
497 { |
|
498 iImplicitConnectionPrefs = aRequest->ConnPrefs(); |
|
499 iImplicitNotifyInfo = aRequest->AgentConnectionInfo(); |
|
500 iImplicitNotifyEvent = MImplicitConnectionNotify::EImplicitConnectionUp; |
|
501 iImplicitNotificationCb->CallBack(); |
|
502 } |
|
503 } |
|
504 else |
|
505 { |
|
506 ASSERT(*iImplicitConnectionAgentName == aRequest->AgentName()); |
|
507 } |
|
508 } |
|
509 |
|
510 ASSERT(aRequest->Observer()); |
|
511 |
|
512 // signal the observer that the selection is complete |
|
513 if(aError==KErrNone) |
|
514 { |
|
515 aRequest->Observer()->SelectComplete(aRequest->AgentName()); |
|
516 } |
|
517 else |
|
518 { |
|
519 aRequest->Observer()->SelectComplete(aError); |
|
520 } |
|
521 |
|
522 delete iCurrentRequest; |
|
523 iCurrentRequest = NULL; |
|
524 |
|
525 CancelBearerAvailabilityCheck(); |
|
526 } |
|
527 |
|
528 void CNetworkController::RequestComplete(const CReconnectRequest* aRequest, TInt aError) |
|
529 /** |
|
530 RequestComplete |
|
531 |
|
532 A reconnect request has been processed - queue another one. |
|
533 |
|
534 @param aRequest pointer to the actual reconnect request |
|
535 @param aError contains the reason for failure of processing the request or KErrNone |
|
536 */ |
|
537 { |
|
538 __ASSERT_ALWAYS( (CReconnectRequest*)aRequest == iCurrentRequest, NetConPanic(NetworkController::ENetConBadRequestCallback)); |
|
539 |
|
540 LOG_DETAILED ( NetConLog::Printf(_L("CNetworkController::RequestComplete(CReconnectRequest aRequest = 0x%08x, aError = %d)"), aRequest, aError); ) |
|
541 LOG( NetConLog::Printf(_L("--------------- Finished processing request [0x%08x] ---------------"), iCurrentRequest); ) |
|
542 |
|
543 // Trigger callback to process next request in the queue |
|
544 iProcessRequestCb->CallBack(); |
|
545 |
|
546 // signal the observer that the selection is complete |
|
547 aRequest->Observer()->ReconnectComplete(aError); |
|
548 |
|
549 delete iCurrentRequest; |
|
550 iCurrentRequest = NULL; |
|
551 } |
|
552 |
|
553 TInt CNetworkController::RequestImplicitConnectionNotification(MImplicitConnectionNotify* aObserver) |
|
554 /** |
|
555 Register for implicit connection event notification |
|
556 Implicit Connection Notification |
|
557 |
|
558 @param aObserver to notify of event changes |
|
559 */ |
|
560 { |
|
561 LOG_DETAILED( NetConLog::Printf(_L("CNetworkController::RequestImplicitConnectionNotification()")); ) |
|
562 |
|
563 if(iImplicitConnectionAgentName) |
|
564 { |
|
565 aObserver->ImplicitConnectionEvent(iImplicitNotifyInfo, MImplicitConnectionNotify::EImplicitConnectionUp); |
|
566 } |
|
567 |
|
568 return iImplicitNotifyList.Append(aObserver); |
|
569 } |
|
570 |
|
571 void CNetworkController::CancelImplicitConnectionNotification(MImplicitConnectionNotify* aObserver) |
|
572 /** |
|
573 Deregister for implicit connection event notification |
|
574 |
|
575 @param aObserver to notify of event changes |
|
576 */ |
|
577 { |
|
578 LOG_DETAILED( NetConLog::Printf(_L("CNetworkController::CancelImplicitConnectionNotification()")); ) |
|
579 |
|
580 TInt index = iImplicitNotifyList.Find(aObserver); |
|
581 if(index>=0) |
|
582 { |
|
583 iImplicitNotifyList.Remove(index); |
|
584 } |
|
585 } |
|
586 |
|
587 TInt CNetworkController::ImplicitNotificationCb(TAny* aThisPtr) |
|
588 /** |
|
589 Static callback function |
|
590 |
|
591 @param aThisPtr the pointer to the instance of this class that triggered the callback |
|
592 */ |
|
593 { |
|
594 CNetworkController* self = STATIC_CAST(CNetworkController*, aThisPtr); |
|
595 self->SendImplicitConnectionNotification(self->iImplicitNotifyInfo, self->iImplicitNotifyEvent); |
|
596 return KErrNone; |
|
597 } |
|
598 |
|
599 void CNetworkController::SendImplicitConnectionNotification(const TDesC8& aConnectionInfo, MImplicitConnectionNotify::TEvent aEvent) |
|
600 /** |
|
601 Notify all registered observers about the implicit connection event |
|
602 |
|
603 @param aConnectionInfo a TSoIfConnectionInfo describing the implicit connection IapId and NetId |
|
604 @param aEvent either Up or Down |
|
605 */ |
|
606 { |
|
607 LOG_DETAILED( NetConLog::Printf(_L("CNetworkController::SendImplicitConnectionNotification()")); ) |
|
608 |
|
609 for(TInt i=0; i<iImplicitNotifyList.Count(); ++i) |
|
610 { |
|
611 iImplicitNotifyList[i]->ImplicitConnectionEvent(aConnectionInfo, aEvent); |
|
612 } |
|
613 } |
|
614 |
|
615 // |
|
616 // // |
|
617 // Bearer Availability Checking // |
|
618 // // |
|
619 // |
|
620 |
|
621 void CNetworkController::CheckBearerAvailability(TBool aIsReconnect) |
|
622 /** |
|
623 Check Bearer Availability |
|
624 |
|
625 @param aIsReconnect if this is a reconnection then any asynchronous requests are skipped in order to speed things up |
|
626 */ |
|
627 { |
|
628 LOG_DETAILED( NetConLog::Printf(_L("CNetworkController::CheckBearerAvailability()")); ) |
|
629 |
|
630 // ensure that the telephony bearer is in the array |
|
631 __ASSERT_DEBUG(iBearers[KTelBearerPosition], NetConPanic(NetworkController::ENetConTelBearerMissing)); |
|
632 |
|
633 // ask the telephony bearer to start checking for availability |
|
634 TBool ret = iBearers[KTelBearerPosition]->StartChecking(aIsReconnect); |
|
635 __ASSERT_DEBUG(ret, NetConPanic(NetworkController::ENetConTelBearerAlreadyChecking)); |
|
636 (void)ret; // remove warning in release builds |
|
637 } |
|
638 |
|
639 void CNetworkController::CancelBearerAvailabilityCheck() |
|
640 /** |
|
641 CancelBearerAvailabilityCheck |
|
642 */ |
|
643 { |
|
644 LOG_DETAILED( NetConLog::Printf(_L("CNetworkController::CancelBearerAvailabilityCheck()")); ) |
|
645 |
|
646 // ensure that the telephony bearer is in the array |
|
647 __ASSERT_DEBUG(iBearers[KTelBearerPosition], NetConPanic(NetworkController::ENetConTelBearerMissing)); |
|
648 |
|
649 iBearers[KTelBearerPosition]->StopChecking(); |
|
650 } |
|
651 |
|
652 /** |
|
653 Construct a new database accessor |
|
654 @returns the new database accessor |
|
655 */ |
|
656 CCommsDbAccess* CNetworkController::NewDatabaseL() |
|
657 { |
|
658 LOG_DETAILED( NetConLog::Printf(_L("CNetworkController::NewDatabaseL()")); ) |
|
659 |
|
660 CCommsDbAccess *database = CCommsDbAccess::NewL(ETrue); |
|
661 ASSERT( database ); |
|
662 return database; |
|
663 } |
|
664 |
|
665 |
|
666 /** |
|
667 Construct a new dialog processor |
|
668 @returns the new dialog processor |
|
669 */ |
|
670 CNetConDlgProcessor* CNetworkController::NewDialogProcessorL() |
|
671 { |
|
672 LOG_DETAILED( NetConLog::Printf(_L("CNetworkController::NewDialogProcessorL()")); ) |
|
673 |
|
674 return CNetConDlgProcessor::NewL(); |
|
675 } |
|
676 |
|
677 |
|
678 TInt CNetworkController::RequestSecondPhaseAvailability() |
|
679 /** |
|
680 Check Second Phase Bearer Availability - e.g. signal strength |
|
681 |
|
682 @returns KErrNone if the bearer availability is above the threshold stored in CommDB, otherwise KErrNetConInadequateSignalStrengh |
|
683 */ |
|
684 { |
|
685 LOG_DETAILED( NetConLog::Printf(_L("CNetworkController::RequestSecondPhaseAvailability()")); ) |
|
686 |
|
687 CBearerBase* const telBearer = iBearers[KTelBearerPosition]; |
|
688 |
|
689 // ensure that the telephony bearer is in the array |
|
690 __ASSERT_DEBUG(telBearer, NetConPanic(NetworkController::ENetConTelBearerMissing)); |
|
691 |
|
692 // ask the telephony bearer to start checking for availability |
|
693 TInt availability = telBearer->SecondPhaseAvailability(); |
|
694 |
|
695 // we have to tell the bearer to stop checking for availability here, otherwise |
|
696 // subsequent availability requests will fail |
|
697 // the logic is that every selection request triggers a *new* bearer availabilty |
|
698 // check - in a one box device this could be optimised to a single check. |
|
699 telBearer->StopChecking(); |
|
700 return availability; |
|
701 } |
|
702 |
|
703 void CNetworkController::BearerStateChange(CBearerBase* aBearer) |
|
704 /** |
|
705 The bearer set available has changed - update the current |
|
706 request |
|
707 |
|
708 |
|
709 Implementation of MBearerObserver Interface |
|
710 |
|
711 @param aBearer the bearer who's availability has changed |
|
712 @note that this is quite a simple implementation |
|
713 of bearer availability checking because we only |
|
714 have a single bearer. If further bearers are |
|
715 implemented then a 'bearer manager' class may |
|
716 be used to take the responsibility of retrieveing |
|
717 the availability of all bearers and then returing |
|
718 to the network controller |
|
719 */ |
|
720 { |
|
721 LOG_DETAILED( NetConLog::Printf(_L("CNetworkController::BearerStateChange()")); ) |
|
722 |
|
723 __ASSERT_DEBUG(iCurrentRequest, NetConPanic(NetworkController::ENetConNoCurrentRequest)); |
|
724 |
|
725 // fetch the available bearer set from the telephony bearer |
|
726 TUint32 availableBearerSet(aBearer->AvailableBearerSet()); |
|
727 |
|
728 // the LAN bearer is assumed to be always available so mask it in |
|
729 availableBearerSet |= (KCommDbBearerLAN|KCommDbBearerVirtual); |
|
730 |
|
731 // update the current request |
|
732 iCurrentRequest->SetAvailableBearers(availableBearerSet); |
|
733 } |
|
734 |
|
735 CCommsDbAccess* CNetworkController::DbAccess() |
|
736 /** Provide a pointer to the CCommsDbAccess class to facilitate access to commdb |
|
737 @return CCommsDbAccess |
|
738 */ |
|
739 { |
|
740 LOG_DETAILED( NetConLog::Printf(_L("CNetworkController::DbAccess()")); ) |
|
741 |
|
742 ASSERT(iCurrentRequest); |
|
743 ASSERT(iCurrentRequest->DbAccess()); |
|
744 return iCurrentRequest->DbAccess(); |
|
745 } |
|
746 |
|
747 // |
|
748 // // |
|
749 // MNetConEnv Interface // |
|
750 // // |
|
751 // |
|
752 |
|
753 const HBufC* CNetworkController::ImplicitConnectionAgentName() const |
|
754 /** |
|
755 Retrieve the name of the Agent that is used for implicit connection |
|
756 requests - i.e. connection startup from RSocket SendTo()/Connect() or |
|
757 RHostResolver GetByName() |
|
758 |
|
759 @returns an Agent name |
|
760 */ |
|
761 { |
|
762 LOG_DETAILED( |
|
763 if (iImplicitConnectionAgentName) |
|
764 NetConLog::Printf(_L("CNetworkController::ImplicitConnectionAgentName() %S"), iImplicitConnectionAgentName); |
|
765 else |
|
766 NetConLog::Printf(_L("CNetworkController::ImplicitConnectionAgentName() returns NULL")); |
|
767 ) |
|
768 |
|
769 return iImplicitConnectionAgentName; |
|
770 } |
|
771 |
|
772 const TConnPref& CNetworkController::ImplicitConnectionPrefs() const |
|
773 /** |
|
774 Retrieve the connection preferences associated with the current |
|
775 implicit connection |
|
776 |
|
777 @returns a TConnPref reference |
|
778 */ |
|
779 { |
|
780 |
|
781 return iImplicitConnectionPrefs; |
|
782 } |
|
783 |
|
784 void CNetworkController::AddAgentToNetworkL(CNifAgentBase* aAgent, TUint32 aNetworkId) |
|
785 /** |
|
786 Create an association between an Agent and a Network ID. |
|
787 |
|
788 @param aAgent pointer to the Agent |
|
789 @param aNetworkId the CommDb ID of the Network |
|
790 */ |
|
791 { |
|
792 LOG_DETAILED( NetConLog::Printf(_L("CNetworkController::AddAgentToNetworkL()")); ) |
|
793 |
|
794 // Is the network already available? |
|
795 CNetwork* network = NULL; |
|
796 TInt findErr = FindNetworkById(aNetworkId, network); |
|
797 |
|
798 // ...if not create a new network |
|
799 if(findErr!=KErrNone) |
|
800 { |
|
801 network=CNetwork::NewLC(aNetworkId, this); |
|
802 AddNetworkL(network); |
|
803 CleanupStack::Pop(); // network |
|
804 } |
|
805 |
|
806 // add this agent to the network. |
|
807 network->AddAgentL(aAgent); |
|
808 |
|
809 LOG( NetConLog::Printf(_L("\tAdded agent [0x%08x] to Network %d [0x%08x]"), aAgent, aNetworkId, network); ) |
|
810 } |
|
811 |