internetradio2.0/networkcontrollersrc/irnetworkobserver.cpp
changeset 0 09774dfdd46b
child 11 f683e24efca3
equal deleted inserted replaced
-1:000000000000 0:09774dfdd46b
       
     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 					iMonitorObserver->IRNetworkEventL(ENetworkConnectionDisconnected);
       
   185 					}
       
   186 				}			
       
   187 			}
       
   188 		break;
       
   189 
       
   190 		case EConnMonCreateSubConnection:       
       
   191 			{
       
   192 			//Triggered when a new subconnection has been been created
       
   193 			// for future implementation
       
   194 			}
       
   195 		break;
       
   196 
       
   197 		case EConnMonDeleteSubConnection:       
       
   198 			{
       
   199 			//Triggered when a subconnection has been been deleted
       
   200 			// for future implementation
       
   201 			}
       
   202 		break;
       
   203 
       
   204 		case EConnMonDownlinkDataThreshold:     
       
   205 			{
       
   206 			// for future implementation
       
   207 			}
       
   208 		break;
       
   209 
       
   210 		case EConnMonUplinkDataThreshold:       
       
   211 			{
       
   212 			// for future implementation
       
   213 			}
       
   214 		break;
       
   215 
       
   216 		case EConnMonNetworkStatusChange:       
       
   217 			{
       
   218 			// for future implementation
       
   219 			}
       
   220 		break;
       
   221 
       
   222 		case EConnMonConnectionStatusChange:    
       
   223 			{
       
   224 			//Triggered when the status of some connection changes.
       
   225 			// for future implementation
       
   226 			}
       
   227 		break;
       
   228 
       
   229 		case EConnMonConnectionActivityChange:  
       
   230 			{
       
   231 			//Triggered when some connection changes from active to idle or vice versa
       
   232 			// for future implementation
       
   233 			}
       
   234 		break;
       
   235 
       
   236 		case EConnMonNetworkRegistrationChange: 
       
   237 			{
       
   238 			// for future implementation
       
   239 			}
       
   240 		break;
       
   241 
       
   242 		case EConnMonBearerChange:              
       
   243 			{
       
   244 			//Triggered when bearer type (GPRS / Edge GPRS / WCDMA) changes
       
   245 			// for future implementation
       
   246 			}
       
   247 		break;
       
   248 
       
   249 		case EConnMonSignalStrengthChange:      
       
   250 			{
       
   251 			// for future implementation
       
   252 			}
       
   253 		break;
       
   254 
       
   255 		case EConnMonBearerAvailabilityChange:  
       
   256 			{
       
   257 			//Triggered when the availability of some bearer changes
       
   258 			// for future implementation
       
   259 			}
       
   260 		break;
       
   261 
       
   262 		case EConnMonIapAvailabilityChange:     
       
   263 			{
       
   264 			// for future implementation
       
   265 			}
       
   266 		break;
       
   267 
       
   268 		case EConnMonTransmitPowerChange:    
       
   269 			{
       
   270 			// for future implementation
       
   271 			}
       
   272 		break;
       
   273 		default:
       
   274 			{
       
   275 			// no implementation
       
   276 			}
       
   277 		break;    
       
   278 		}
       
   279 	IRLOG_DEBUG( "CIRNetworkObserver::EventL - Exiting." );
       
   280 	}
       
   281 
       
   282 // ---------------------------------------------------------------------------
       
   283 // CIRNetworkObserver::IdentifyConnection()
       
   284 // Identifies the type of connection we have used to get connected to network
       
   285 // ---------------------------------------------------------------------------
       
   286 //
       
   287 void CIRNetworkObserver::IdentifyConnection()
       
   288 	{
       
   289 	IRLOG_DEBUG( "CIRNetworkObserver::IdentifyConnection - Entering" );
       
   290 	if(!IsActive())
       
   291 		{
       
   292 		iObserverState = EGettingConnectionInfo;
       
   293 		iIRConnectionMonitor.GetConnectionInfo(
       
   294 		    iConnectionCount,iConnectionId,iSubConnectionCount);
       
   295 		// O Indicates method applies to connection
       
   296 		iIRConnectionMonitor.GetIntAttribute(
       
   297 		    iConnectionId,0,KBearer,iConnectionType,iStatus);
       
   298 		SetActive();
       
   299 		}
       
   300 	IRLOG_DEBUG( "CIRNetworkObserver::IdentifyConnection - Exiting." );
       
   301 }
       
   302 
       
   303 // ---------------------------------------------------------------------------
       
   304 // CIRNetworkObserver::GetIAPId()
       
   305 // Retrieves the IAP Id of the connection
       
   306 // ---------------------------------------------------------------------------
       
   307 //
       
   308 void CIRNetworkObserver::GetAPId()
       
   309 	{
       
   310 	IRLOG_DEBUG( "CIRNetworkObserver::GetIAPId - Entering" );
       
   311 	if(!IsActive())
       
   312 		{
       
   313 		iObserverState = EGettingIAPId;
       
   314 		iIRConnectionMonitor.GetConnectionInfo(
       
   315 		    iConnectionCount,iConnectionId,iSubConnectionCount);
       
   316 		// O in RConnectionMonitor::GetIntAttribute indicates method applies to connection
       
   317 		iIRConnectionMonitor.GetUintAttribute(
       
   318 		    iConnectionId,0,KIAPId,iIAPId,iStatus);
       
   319 		SetActive();
       
   320 		}
       
   321 	IRLOG_DEBUG( "CIRNetworkObserver::GetIAPId - Exiting." );
       
   322 	}
       
   323 
       
   324 // ---------------------------------------------------------------------------
       
   325 // CIRNetworkObserver::IRNetworkObserverRunL()
       
   326 // Utility function used just to keep RunL() small
       
   327 // ---------------------------------------------------------------------------
       
   328 // 
       
   329 void CIRNetworkObserver::IRNetworkObserverRunL()
       
   330 	{
       
   331 	IRLOG_DEBUG( "CIRNetworkObserver::IRNetworkObserverRunL - Entering" );
       
   332 	switch(iObserverState)
       
   333 		{
       
   334 		case EInitializing:
       
   335 			{
       
   336 			if( iStatus.Int() == KErrNone )
       
   337 				{
       
   338 				// Initializing the Connection Monitor sucessful    
       
   339 				IdentifyConnection();
       
   340 				}
       
   341 			else
       
   342 				{
       
   343 				// Error initializing the connection monitor
       
   344 				iNetworkController->ResetHandingOverConnection();
       
   345 				}    
       
   346 			}
       
   347 		break;
       
   348 
       
   349 		case EGettingConnectionInfo:
       
   350 			{
       
   351 			if( iStatus.Int() == KErrNone )
       
   352 				{
       
   353                 iIsIAPIdAvailable = EFalse;
       
   354 				GetAPId();	
       
   355 				}
       
   356 			else
       
   357 				{
       
   358 				// Error initializing the connection monitor
       
   359 				iNetworkController->ResetHandingOverConnection();
       
   360 				}    
       
   361 			}
       
   362 		break;   
       
   363 		
       
   364 		case EGettingIAPId:
       
   365 			{
       
   366 			    iIsIAPIdAvailable = ETrue;   
       
   367 			    switch(iConnectionType)
       
   368 			    {
       
   369 			        case EBearerGPRS:
       
   370 			            {
       
   371 			            iIRConnectionType = EGprs;
       
   372 			            if(iMonitoringRequired)
       
   373 			             {
       
   374 			             // Intimate the connection established event
       
   375 			                 iMonitorObserver->IRNetworkEventL(
       
   376 			                     ENetworkConnectionEstablished);
       
   377 			             }
       
   378 			            }
       
   379 			        break;
       
   380                     
       
   381 			        case EBearerEdgeGPRS:
       
   382 			            {
       
   383 			            iIRConnectionType = EEdge;
       
   384 			            if(iMonitoringRequired)
       
   385 			             {
       
   386 			             // Intimate the connection established event
       
   387 			                 iMonitorObserver->IRNetworkEventL(
       
   388 			                     ENetworkConnectionEstablished);
       
   389 			             }
       
   390 			            }
       
   391 			        break;
       
   392                     
       
   393 			        case EBearerWLAN:
       
   394 			            {
       
   395 			            iIRConnectionType = EWiFi;    
       
   396 			            if(iMonitoringRequired)
       
   397 			                {
       
   398 			                // Intimate the connection established event
       
   399 			                iMonitorObserver->IRNetworkEventL(
       
   400 			                    ENetworkConnectionEstablished);
       
   401 			                }
       
   402 			            }
       
   403 			        break;
       
   404                     
       
   405 			        case EBearerWCDMA:
       
   406 			            {
       
   407 			            iIRConnectionType = EWcdma;
       
   408 			            if(iMonitoringRequired)
       
   409 			            {
       
   410 			            // Intimate the connection established event
       
   411 			                iMonitorObserver->IRNetworkEventL(
       
   412 			                    ENetworkConnectionEstablished);
       
   413 			            }
       
   414 			            }
       
   415                     break;
       
   416 			            
       
   417 			        case EBearerCDMA2000:
       
   418 			            {
       
   419 			            iIRConnectionType = ECdma2000;
       
   420 			            if(iMonitoringRequired)
       
   421 			            {
       
   422 			            // Intimate the connection established event
       
   423 			                iMonitorObserver->IRNetworkEventL(
       
   424 			                    ENetworkConnectionEstablished);
       
   425 			            }
       
   426 			            }
       
   427 			        break;
       
   428 			        
       
   429 			        default:
       
   430 			            {
       
   431 			            #ifdef __WINS__
       
   432 			            iIRConnectionType = EGprs;
       
   433 			            if(iMonitoringRequired)
       
   434 			             {
       
   435 			             // Intimate the connection established event
       
   436 			                 iMonitorObserver->IRNetworkEventL(
       
   437 			                     ENetworkConnectionEstablished);
       
   438 			             }
       
   439 			            #endif
       
   440 			            }
       
   441 			        break;
       
   442 			    }
       
   443 			    
       
   444 			    iNetworkController->ResetHandingOverConnection();
       
   445 			}
       
   446 			break;
       
   447 			
       
   448 		default:
       
   449 			{
       
   450 			// no implementation
       
   451 			}
       
   452 		break;
       
   453 		}
       
   454 	IRLOG_DEBUG( "CIRNetworkObserver::IRNetworkObserverRunL	- Exiting." );
       
   455 	}
       
   456 
       
   457 // ---------------------------------------------------------------------------
       
   458 // CIRNetworkObserver::SetNetworkMonitoring()
       
   459 // Sets network monitoring observer to decide whether network monitoring is required.
       
   460 // ---------------------------------------------------------------------------
       
   461 // 
       
   462 void CIRNetworkObserver::SetNetworkMonitoring(TBool aValue)
       
   463 	{
       
   464 	IRLOG_DEBUG( "CIRNetworkObserver::SetNetworkMonitoring - Entering" );
       
   465 
       
   466 	iMonitoringRequired = aValue;	
       
   467 	
       
   468 	IRLOG_DEBUG( "CIRNetworkObserver::SetNetworkMonitoring - Exiting" );
       
   469 
       
   470 	}