internetradio2.0/networkcontrollersrc/irnetworkobserver.cpp
changeset 14 896e9dbc5f19
parent 12 608f67c22514
child 15 065198191975
equal deleted inserted replaced
12:608f67c22514 14:896e9dbc5f19
     1 /*
       
     2 * Copyright (c) 2006-2007 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:  ?Description
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 #include "irdebug.h"
       
    20 #include "irnetworkobserver.h"
       
    21 #include "irnetworkcontroller.h"
       
    22 
       
    23 // ---------------------------------------------------------------------------
       
    24 // CIRNetworkObserver::NewL
       
    25 // Creates an Instance of CIRNetworkObserver
       
    26 // ---------------------------------------------------------------------------
       
    27 //
       
    28 EXPORT_C CIRNetworkObserver *CIRNetworkObserver::NewL(CIRNetworkController *aNetworkController)
       
    29 	{
       
    30 	IRLOG_DEBUG( "CIRNetworkObserver::NewL - Entering" );
       
    31 	CIRNetworkObserver *self = NewLC(aNetworkController);
       
    32 	CleanupStack::Pop(self);
       
    33 	IRLOG_DEBUG( "CIRNetworkObserver::NewL - Exiting." );
       
    34 	return self;
       
    35 	}
       
    36 
       
    37 // ---------------------------------------------------------------------------
       
    38 // CIRNetworkObserver::~CIRNetworkObserver()
       
    39 // Default Destructor
       
    40 // ---------------------------------------------------------------------------
       
    41 //
       
    42 CIRNetworkObserver::~CIRNetworkObserver()
       
    43 	{
       
    44 	IRLOG_DEBUG( "CIRNetworkObserver::~CIRNetworkObserver - Entering" );
       
    45         Cancel();
       
    46 	iIRConnectionMonitor.CancelNotifications();
       
    47 	iIRConnectionMonitor.Close();
       
    48 	IRLOG_DEBUG( "CIRNetworkObserver::~CIRNetworkObserver - Exiting." );
       
    49 	}
       
    50 
       
    51 // ---------------------------------------------------------------------------
       
    52 // CIRNetworkObserver::InitializeNetworkObserver()
       
    53 //  Initializes the Connection monitor
       
    54 // ---------------------------------------------------------------------------
       
    55 //
       
    56 void CIRNetworkObserver::InitializeNetworkObserver()
       
    57 	{
       
    58 	IRLOG_DEBUG( "CIRNetworkObserver::InitializeNetworkObserver - Entering" );
       
    59 	iConnectionId = 0;
       
    60 	if(!IsActive())
       
    61 		{
       
    62 		iObserverState = EInitializing;
       
    63 		iIRConnectionMonitor.GetConnectionCount(iConnectionCount,iStatus);
       
    64 		SetActive();
       
    65 		}
       
    66 	IRLOG_DEBUG( "CIRNetworkObserver::InitializeNetworkObserver - Exiting." );
       
    67 	}
       
    68 
       
    69 // ---------------------------------------------------------------------------
       
    70 // CIRNetworkObserver::SetObserver(MIRNetworkController* aObserver)
       
    71 // Set the observer used to communicate with the IRNetworkController
       
    72 // ---------------------------------------------------------------------------
       
    73 //
       
    74 void CIRNetworkObserver::SetObserver(MIRNetworkController* aObserver)
       
    75 	{
       
    76 	IRLOG_DEBUG( "CIRNetworkObserver::SetObserver - Entering" );
       
    77 	iMonitorObserver = aObserver;
       
    78 	iMonitoringRequired = ETrue;  
       
    79 	IRLOG_DEBUG( "CIRNetworkObserver::SetObserver - Exiting." );
       
    80 	}
       
    81 
       
    82 // ---------------------------------------------------------------------------
       
    83 // CIRNetworkObserver::CIRNetworkObserver()
       
    84 // Default Constructor
       
    85 // ---------------------------------------------------------------------------
       
    86 //
       
    87 CIRNetworkObserver::CIRNetworkObserver(CIRNetworkController *aNetworkController):
       
    88     CActive( CActive::EPriorityStandard ), iNetworkController(aNetworkController)
       
    89 	{
       
    90 	IRLOG_DEBUG( "CIRNetworkObserver::CIRNetworkObserver - Entering" );
       
    91 	// Add the AO to the ActiveScheduler
       
    92 	CActiveScheduler::Add( this );
       
    93 	IRLOG_DEBUG( "CIRNetworkObserver::CIRNetworkObserver - Exiting." );
       
    94 	}
       
    95 
       
    96 // ---------------------------------------------------------------------------
       
    97 // Creates an Instance of CIRNetworkObserver
       
    98 // ---------------------------------------------------------------------------
       
    99 //
       
   100 CIRNetworkObserver *CIRNetworkObserver::NewLC(CIRNetworkController *aNetworkController )
       
   101 	{
       
   102 	IRLOG_DEBUG( "CIRNetworkObserver::NewLC - Entering " );
       
   103 	CIRNetworkObserver *self = new( ELeave )CIRNetworkObserver(aNetworkController);
       
   104 	CleanupStack::PushL( self );
       
   105 	self->ConstructL();
       
   106 	IRLOG_DEBUG( "CIRNetworkObserver::NewLC - Exiting." );
       
   107 	return self;
       
   108 	}
       
   109 
       
   110 // ---------------------------------------------------------------------------
       
   111 // CIRNetworkObserver::ConstructL() 
       
   112 // Second Phase construction.
       
   113 // ---------------------------------------------------------------------------
       
   114 //
       
   115 void CIRNetworkObserver::ConstructL()
       
   116 	{
       
   117 	IRLOG_DEBUG( "CIRNetworkObserver::ConstructL - Entering" );
       
   118 	iIRConnectionMonitor.ConnectL();
       
   119 	iIRConnectionMonitor.NotifyEventL(*this);
       
   120 	iMonitoringRequired = EFalse;  
       
   121 	IRLOG_DEBUG( "CIRNetworkObserver::ConstructL - Exiting." );	
       
   122 	}
       
   123 
       
   124 // ---------------------------------------------------------------------------
       
   125 // CIRNetworkObserver::RunL()
       
   126 // The function is called by the active scheduler when a request completion event occurs,
       
   127 // ---------------------------------------------------------------------------
       
   128 //
       
   129 void CIRNetworkObserver::RunL()
       
   130 	{
       
   131 	IRLOG_DEBUG( "CIRNetworkObserver::RunL - Entering" );
       
   132 	IRNetworkObserverRunL();
       
   133 	IRLOG_DEBUG( "CIRNetworkObserver::RunL - Exiting" );
       
   134 	}
       
   135 
       
   136 // ---------------------------------------------------------------------------
       
   137 // CIRNetworkObserver::DoCancel()
       
   138 // Cancels the pending requests on the CIRNetworkObserver Active object
       
   139 // ---------------------------------------------------------------------------
       
   140 //
       
   141 void CIRNetworkObserver::DoCancel()
       
   142 	{
       
   143 	IRLOG_DEBUG( "CIRNetworkObserver::DoCancel" );
       
   144 	}
       
   145 
       
   146 // ---------------------------------------------------------------------------    
       
   147 // CIRNetworkObserver::RunError()
       
   148 // Handles a leave occurring in the request completion event handler RunL()
       
   149 // ---------------------------------------------------------------------------
       
   150 //    
       
   151 TInt CIRNetworkObserver::RunError(TInt /*aError*/)
       
   152 	{
       
   153 	IRLOG_DEBUG( "CIRNetworkObserver::RunError" );
       
   154 	iNetworkController->ResetHandingOverConnection();
       
   155 	return KErrNone;
       
   156 	}
       
   157 
       
   158 // ---------------------------------------------------------------------------
       
   159 // CIRNetworkObserver::EventL(const CConnMonEventBase &aConnMonEvent)
       
   160 // Derived from MConnectionMonitorObserver
       
   161 // Implements the EventL method which is called when there is a network event
       
   162 // ---------------------------------------------------------------------------
       
   163 //
       
   164 void CIRNetworkObserver::EventL(const CConnMonEventBase &aConnMonEvent)
       
   165 	{
       
   166 	IRLOG_INFO4( "CIRNetworkObserver::EventL - Event type %d for connection %d, iConnectionId=%d", 
       
   167 	             aConnMonEvent.EventType(), aConnMonEvent.ConnectionId(), iConnectionId );
       
   168 	switch(aConnMonEvent.EventType())
       
   169 		{
       
   170 		case EConnMonCreateConnection:
       
   171 			{
       
   172 			//Triggered when a new connection has been been created
       
   173 			// for future implementation
       
   174 			}
       
   175 		break;
       
   176 
       
   177 		case EConnMonDeleteConnection:
       
   178 			{
       
   179 			//Triggered when a connection has been been deleted.
       
   180 			if( aConnMonEvent.ConnectionId() == iConnectionId )
       
   181 				{
       
   182 				if(iMonitoringRequired)
       
   183 					{
       
   184 				    if (iMonitorObserver)
       
   185 					{
       
   186 				        iMonitorObserver->IRNetworkEventL(ENetworkConnectionDisconnected);
       
   187 					}
       
   188 				    else
       
   189 				    {
       
   190 				        iNetworkController->NotifyActiveNetworkObserversL(ENetworkConnectionDisconnected);
       
   191 				    }
       
   192 					}
       
   193 				}			
       
   194 			}
       
   195 		break;
       
   196 
       
   197 		case EConnMonCreateSubConnection:       
       
   198 			{
       
   199 			//Triggered when a new subconnection has been been created
       
   200 			// for future implementation
       
   201 			}
       
   202 		break;
       
   203 
       
   204 		case EConnMonDeleteSubConnection:       
       
   205 			{
       
   206 			//Triggered when a subconnection has been been deleted
       
   207 			// for future implementation
       
   208 			}
       
   209 		break;
       
   210 
       
   211 		case EConnMonDownlinkDataThreshold:     
       
   212 			{
       
   213 			// for future implementation
       
   214 			}
       
   215 		break;
       
   216 
       
   217 		case EConnMonUplinkDataThreshold:       
       
   218 			{
       
   219 			// for future implementation
       
   220 			}
       
   221 		break;
       
   222 
       
   223 		case EConnMonNetworkStatusChange:       
       
   224 			{
       
   225 			// for future implementation
       
   226 			}
       
   227 		break;
       
   228 
       
   229 		case EConnMonConnectionStatusChange:    
       
   230 			{
       
   231 			//Triggered when the status of some connection changes.
       
   232 			// for future implementation
       
   233 			}
       
   234 		break;
       
   235 
       
   236 		case EConnMonConnectionActivityChange:  
       
   237 			{
       
   238 			//Triggered when some connection changes from active to idle or vice versa
       
   239 			// for future implementation
       
   240 			}
       
   241 		break;
       
   242 
       
   243 		case EConnMonNetworkRegistrationChange: 
       
   244 			{
       
   245 			// for future implementation
       
   246 			}
       
   247 		break;
       
   248 
       
   249 		case EConnMonBearerChange:              
       
   250 			{
       
   251 			//Triggered when bearer type (GPRS / Edge GPRS / WCDMA) changes
       
   252 			// for future implementation
       
   253 			}
       
   254 		break;
       
   255 
       
   256 		case EConnMonSignalStrengthChange:      
       
   257 			{
       
   258 			// for future implementation
       
   259 			}
       
   260 		break;
       
   261 
       
   262 		case EConnMonBearerAvailabilityChange:  
       
   263 			{
       
   264 			//Triggered when the availability of some bearer changes
       
   265 			// for future implementation
       
   266 			}
       
   267 		break;
       
   268 
       
   269 		case EConnMonIapAvailabilityChange:     
       
   270 			{
       
   271 			// for future implementation
       
   272 			}
       
   273 		break;
       
   274 
       
   275 		case EConnMonTransmitPowerChange:    
       
   276 			{
       
   277 			// for future implementation
       
   278 			}
       
   279 		break;
       
   280 		default:
       
   281 			{
       
   282 			// no implementation
       
   283 			}
       
   284 		break;    
       
   285 		}
       
   286 	IRLOG_DEBUG( "CIRNetworkObserver::EventL - Exiting." );
       
   287 	}
       
   288 
       
   289 // ---------------------------------------------------------------------------
       
   290 // CIRNetworkObserver::IdentifyConnection()
       
   291 // Identifies the type of connection we have used to get connected to network
       
   292 // ---------------------------------------------------------------------------
       
   293 //
       
   294 void CIRNetworkObserver::IdentifyConnection()
       
   295 	{
       
   296 	IRLOG_DEBUG( "CIRNetworkObserver::IdentifyConnection - Entering" );
       
   297 	if(!IsActive())
       
   298 		{
       
   299 		iObserverState = EGettingConnectionInfo;
       
   300 		iIRConnectionMonitor.GetConnectionInfo(
       
   301 		    iConnectionCount,iConnectionId,iSubConnectionCount);
       
   302 		// O Indicates method applies to connection
       
   303 		iIRConnectionMonitor.GetIntAttribute(
       
   304 		    iConnectionId,0,KBearer,iConnectionType,iStatus);
       
   305 		SetActive();
       
   306 		}
       
   307 	IRLOG_DEBUG( "CIRNetworkObserver::IdentifyConnection - Exiting." );
       
   308 }
       
   309 
       
   310 // ---------------------------------------------------------------------------
       
   311 // CIRNetworkObserver::GetIAPId()
       
   312 // Retrieves the IAP Id of the connection
       
   313 // ---------------------------------------------------------------------------
       
   314 //
       
   315 void CIRNetworkObserver::GetAPId()
       
   316 	{
       
   317 	IRLOG_DEBUG( "CIRNetworkObserver::GetIAPId - Entering" );
       
   318 	if(!IsActive())
       
   319 		{
       
   320 		iObserverState = EGettingIAPId;
       
   321 		iIRConnectionMonitor.GetConnectionInfo(
       
   322 		    iConnectionCount,iConnectionId,iSubConnectionCount);
       
   323 		// O in RConnectionMonitor::GetIntAttribute indicates method applies to connection
       
   324 		iIRConnectionMonitor.GetUintAttribute(
       
   325 		    iConnectionId,0,KIAPId,iIAPId,iStatus);
       
   326 		SetActive();
       
   327 		}
       
   328 	IRLOG_DEBUG( "CIRNetworkObserver::GetIAPId - Exiting." );
       
   329 	}
       
   330 
       
   331 // ---------------------------------------------------------------------------
       
   332 // CIRNetworkObserver::IRNetworkObserverRunL()
       
   333 // Utility function used just to keep RunL() small
       
   334 // ---------------------------------------------------------------------------
       
   335 // 
       
   336 void CIRNetworkObserver::IRNetworkObserverRunL()
       
   337 	{
       
   338 	IRLOG_DEBUG( "CIRNetworkObserver::IRNetworkObserverRunL - Entering" );
       
   339 	switch(iObserverState)
       
   340 		{
       
   341 		case EInitializing:
       
   342 			{
       
   343 			if( iStatus.Int() == KErrNone )
       
   344 				{
       
   345 				// Initializing the Connection Monitor sucessful    
       
   346 				IdentifyConnection();
       
   347 				}
       
   348 			else
       
   349 				{
       
   350 				// Error initializing the connection monitor
       
   351 				iNetworkController->ResetHandingOverConnection();
       
   352 				}    
       
   353 			}
       
   354 		break;
       
   355 
       
   356 		case EGettingConnectionInfo:
       
   357 			{
       
   358 			if( iStatus.Int() == KErrNone )
       
   359 				{
       
   360                 iIsIAPIdAvailable = EFalse;
       
   361 				GetAPId();	
       
   362 				}
       
   363 			else
       
   364 				{
       
   365 				// Error initializing the connection monitor
       
   366 				iNetworkController->ResetHandingOverConnection();
       
   367 				}    
       
   368 			}
       
   369 		break;   
       
   370 		
       
   371 		case EGettingIAPId:
       
   372 			{
       
   373 			    iIsIAPIdAvailable = ETrue;   
       
   374 			    switch(iConnectionType)
       
   375 			    {
       
   376 			        case EBearerGPRS:
       
   377 			            {
       
   378 			            iIRConnectionType = EGprs;
       
   379 			            }
       
   380 			        break;
       
   381                     
       
   382 			        case EBearerEdgeGPRS:
       
   383 			            {
       
   384 			            iIRConnectionType = EEdge;
       
   385 			            }
       
   386 			        break;
       
   387                     
       
   388 			        case EBearerWLAN:
       
   389 			            {
       
   390 			            iIRConnectionType = EWiFi;    
       
   391 			            }
       
   392 			        break;
       
   393                     
       
   394 			        case EBearerWCDMA:
       
   395 			            {
       
   396 			            iIRConnectionType = EWcdma;
       
   397 			            }
       
   398                     break;
       
   399 			            
       
   400 			        case EBearerCDMA2000:
       
   401 			            {
       
   402 			            iIRConnectionType = ECdma2000;
       
   403 			            }
       
   404 			        break;
       
   405 			        
       
   406 			        default:
       
   407 			            {
       
   408 			            #ifdef __WINS__
       
   409 			            iIRConnectionType = EGprs;
       
   410 			            #endif
       
   411 			            }
       
   412 			        break;
       
   413 			    }
       
   414 			    
       
   415                 
       
   416                 if (iMonitoringRequired)
       
   417                 {
       
   418                     if (iMonitorObserver)    
       
   419                     {
       
   420                         // Intimate the connection established event
       
   421                         iMonitorObserver->IRNetworkEventL(ENetworkConnectionEstablished);
       
   422                     }
       
   423                     else
       
   424                     {
       
   425                         iNetworkController->NotifyActiveNetworkObserversL(ENetworkConnectionEstablished);
       
   426                     }
       
   427                 }
       
   428                 
       
   429 			    iNetworkController->ResetHandingOverConnection();
       
   430 			}
       
   431 			break;
       
   432 			
       
   433 		default:
       
   434 			{
       
   435 			// no implementation
       
   436 			}
       
   437 		break;
       
   438 		}
       
   439 	IRLOG_DEBUG( "CIRNetworkObserver::IRNetworkObserverRunL	- Exiting." );
       
   440 	}
       
   441 
       
   442 // ---------------------------------------------------------------------------
       
   443 // CIRNetworkObserver::SetNetworkMonitoring()
       
   444 // Sets network monitoring observer to decide whether network monitoring is required.
       
   445 // ---------------------------------------------------------------------------
       
   446 // 
       
   447 void CIRNetworkObserver::SetNetworkMonitoring(TBool aValue)
       
   448 	{
       
   449 	IRLOG_DEBUG( "CIRNetworkObserver::SetNetworkMonitoring - Entering" );
       
   450 
       
   451 	iMonitoringRequired = aValue;	
       
   452 	
       
   453 	IRLOG_DEBUG( "CIRNetworkObserver::SetNetworkMonitoring - Exiting" );
       
   454 
       
   455 	}