realtimenetprots/sipfw/ProfileAgent/AlrMonitor/src/sipalrsnapmonitor.cpp
changeset 37 0295359a7673
parent 15 8248b03a2669
child 42 69df6ed78a6a
equal deleted inserted replaced
33:b8a7e07b2677 37:0295359a7673
    26 // -----------------------------------------------------------------------------
    26 // -----------------------------------------------------------------------------
    27 // CSipAlrSnapMonitor::NewLC
    27 // CSipAlrSnapMonitor::NewLC
    28 // -----------------------------------------------------------------------------
    28 // -----------------------------------------------------------------------------
    29 //
    29 //
    30 CSipAlrSnapMonitor* CSipAlrSnapMonitor::NewLC(
    30 CSipAlrSnapMonitor* CSipAlrSnapMonitor::NewLC(
    31     TUint32 aSnapId,
    31     TSipSNAPConfigurationData aSnapData,
    32     MSipAlrObserver& aObserver,
    32     MSipAlrObserver& aObserver,
    33     RSocketServ& aSocketServer,
    33     RSocketServ& aSocketServer,
    34     CSipSystemStateMonitor& aSystemStateMonitor )
    34     CSipSystemStateMonitor& aSystemStateMonitor)
    35 	{
    35 	{
    36   	CSipAlrSnapMonitor* self = 
    36   	CSipAlrSnapMonitor* self = 
    37   	    new ( ELeave ) CSipAlrSnapMonitor( 
    37   	    new ( ELeave ) CSipAlrSnapMonitor( 
    38   	        aSnapId, aSocketServer, aSystemStateMonitor );
    38   	        aSnapData, aSocketServer, aSystemStateMonitor);
    39     CleanupStack::PushL( self );
    39     CleanupStack::PushL( self );
    40     self->ConstructL( aObserver );
    40     self->ConstructL( aObserver );
    41     return self;	
    41     return self;	
    42 	}
    42 	}
    43 
    43 
    44 // -----------------------------------------------------------------------------
    44 // -----------------------------------------------------------------------------
    45 // CSipAlrSnapMonitor::CSipAlrSnapMonitor
    45 // CSipAlrSnapMonitor::CSipAlrSnapMonitor
    46 // -----------------------------------------------------------------------------
    46 // -----------------------------------------------------------------------------
    47 //	
    47 //	
    48 CSipAlrSnapMonitor::CSipAlrSnapMonitor( 
    48 CSipAlrSnapMonitor::CSipAlrSnapMonitor( 
    49     TUint32 aSnapId,
    49     TSipSNAPConfigurationData aSnapData,
    50     RSocketServ& aSocketServer,
    50     RSocketServ& aSocketServer,
    51     CSipSystemStateMonitor& aSystemStateMonitor ) : 
    51     CSipSystemStateMonitor& aSystemStateMonitor) : 
    52     CActive ( CActive::EPriorityStandard ),
    52     CActive ( CActive::EPriorityStandard ),
    53     iSnapId( aSnapId ),
    53     iSnapData( aSnapData ),
    54     iSocketServer( aSocketServer ),
    54     iSocketServer( aSocketServer ),
    55 	iSystemStateMonitor( aSystemStateMonitor )									
    55 	iSystemStateMonitor( aSystemStateMonitor )
    56 	{
    56 	{
    57 	iPrefs.SetSnap( iSnapId );
    57 	iPrefs.SetSnap( aSnapData.iSnapId );
    58 	CActiveScheduler::Add( this );
    58 	CActiveScheduler::Add( this );
    59 	}
    59 	}
    60 
    60 
    61 // -----------------------------------------------------------------------------
    61 // -----------------------------------------------------------------------------
    62 // CSipAlrSnapMonitor::ConstructL
    62 // CSipAlrSnapMonitor::ConstructL
    65 void CSipAlrSnapMonitor::ConstructL( MSipAlrObserver& aObserver )
    65 void CSipAlrSnapMonitor::ConstructL( MSipAlrObserver& aObserver )
    66 	{
    66 	{
    67 	PROFILE_DEBUG1( "CSipAlrSnapMonitor::ConstructL entered" )
    67 	PROFILE_DEBUG1( "CSipAlrSnapMonitor::ConstructL entered" )
    68 	
    68 	
    69 	iSystemStateMonitor.StartMonitoringL( 
    69 	iSystemStateMonitor.StartMonitoringL( 
    70 	    CSipSystemStateMonitor::ESnapAvailability, iSnapId, *this );
    70 	    CSipSystemStateMonitor::ESnapAvailability, SnapId(), *this );
    71 
    71 
    72   	AddObserverL( aObserver );
    72   	AddObserverL( aObserver );
       
    73   	
       
    74   	if(IsSnapAvailable())
       
    75   	    {
       
    76         // SNAP is already Available to be started.
       
    77         // No Need to wait for Notification from System State Monitor.
       
    78   	    StartSnap();
       
    79   	    }
    73 	
    80 	
    74 	PROFILE_DEBUG1( "CSipAlrSnapMonitor::ConstructL returns" )
    81 	PROFILE_DEBUG1( "CSipAlrSnapMonitor::ConstructL returns" )
    75 	}
    82 	}
    76 	
    83 	
    77 // -----------------------------------------------------------------------------
    84 // -----------------------------------------------------------------------------
    89 	ResetState();
    96 	ResetState();
    90 	
    97 	
    91 	iObservers.Close();
    98 	iObservers.Close();
    92 	
    99 	
    93 	iSystemStateMonitor.StopMonitoring( 
   100 	iSystemStateMonitor.StopMonitoring( 
    94 	    CSipSystemStateMonitor::ESnapAvailability, iSnapId, *this );
   101 	    CSipSystemStateMonitor::ESnapAvailability, SnapId(), *this );
    95 	    
   102 	    
    96 	PROFILE_DEBUG1( "CSipAlrSnapMonitor::~CSipAlrSnapMonitor returns" )
   103 	PROFILE_DEBUG1( "CSipAlrSnapMonitor::~CSipAlrSnapMonitor returns" )
    97 	}
   104 	}
    98 
   105 
    99 // -----------------------------------------------------------------------------
   106 // -----------------------------------------------------------------------------
   127 	else if ( err == KErrCancel )
   134 	else if ( err == KErrCancel )
   128 		{
   135 		{
   129 		for ( TInt i = iObservers.Count() - 1; i >= 0; --i )
   136 		for ( TInt i = iObservers.Count() - 1; i >= 0; --i )
   130 			{
   137 			{
   131 			iObservers[i].iObserver->AlrEvent(
   138 			iObservers[i].iObserver->AlrEvent(
   132 				MSipAlrObserver::EOfferedIapRejected, iSnapId, KNoIap );
   139 				MSipAlrObserver::EOfferedIapRejected, SnapId(), KNoIap );
   133 			}
   140 			}
   134 		}
   141 		}
   135     else
   142     else
   136         {
   143         {
   137         ResetState();
   144         ResetState();
   186 //    	    
   193 //    	    
   187 void CSipAlrSnapMonitor::NewCarrierActive(
   194 void CSipAlrSnapMonitor::NewCarrierActive(
   188     TAccessPointInfo aNewAP, 
   195     TAccessPointInfo aNewAP, 
   189     TBool /*aIsSeamless*/ )
   196     TBool /*aIsSeamless*/ )
   190     {
   197     {
   191     PROFILE_DEBUG3( "CSipSnapAlrMonitor::NewCarrierActive", iSnapId )
   198     PROFILE_DEBUG3( "CSipSnapAlrMonitor::NewCarrierActive", SnapId() )
   192     
   199     
   193     NotifyInitializedObservers( aNewAP.AccessPoint(), 
   200     NotifyInitializedObservers( aNewAP.AccessPoint(), 
   194                                 MSipAlrObserver::EIapActive );
   201                                 MSipAlrObserver::EIapActive );
   195     }
   202     }
   196 
   203 
   204     if ( !iCommsMobilityAO )
   211     if ( !iCommsMobilityAO )
   205     	{
   212     	{
   206     	PROFILE_DEBUG1( "CSipSnapAlrMonitor::Error iCommsMobilityAO==NULL")
   213     	PROFILE_DEBUG1( "CSipSnapAlrMonitor::Error iCommsMobilityAO==NULL")
   207     	return;
   214     	return;
   208     	}
   215     	}
   209     if ( aError == KErrNotFound)
   216     if ( aError == KErrNotFound && !BearerId())
   210 	    {
   217 	    {
   211 	    NotifyInitializedObservers( KNoIap,
   218 	    NotifyInitializedObservers( KNoIap,
   212 	    							MSipAlrObserver::ENoNewIapAvailable );
   219 	    							MSipAlrObserver::ENoNewIapAvailable );
   213 	    }
   220 	    }
   214 
   221 
   215     // MMobilityProtocolResp::Error is called from ~CActiveCommsMobilityApiExt.
   222     // MMobilityProtocolResp::Error is called from ~CActiveCommsMobilityApiExt.
   216     // Flag iDying prevents starting the RConnection if not needed.
   223     // Flag iDying prevents starting the RConnection if not needed.
   217     if ( !iDying )
   224     if ( !iDying )
   218         {
   225         {
   219         ResetState();
   226         ResetState();
       
   227         if(!BearerId())
       
   228         {
       
   229         PROFILE_DEBUG3( "CSipSnapAlrMonitor::Error, Start Snap as Bearer Id is ", BearerId() )
   220         StartSnap();
   230         StartSnap();
       
   231         }
   221         }
   232         }
   222     }
   233     }
   223 
   234 
   224 // -----------------------------------------------------------------------------
   235 // -----------------------------------------------------------------------------
   225 // CSipAlrSnapMonitor::SystemVariableUpdated
   236 // CSipAlrSnapMonitor::SystemVariableUpdated
   233     PROFILE_DEBUG4( "CSipAlrSnapMonitor::SystemVariableUpdated, snap, value",
   244     PROFILE_DEBUG4( "CSipAlrSnapMonitor::SystemVariableUpdated, snap, value",
   234                     aObjectId, aValue )
   245                     aObjectId, aValue )
   235     
   246     
   236     if ( !IsActive() &&
   247     if ( !IsActive() &&
   237          aVariable == CSipSystemStateMonitor::ESnapAvailability &&
   248          aVariable == CSipSystemStateMonitor::ESnapAvailability &&
   238          aObjectId == iSnapId )
   249          aObjectId == SnapId() )
   239         {
   250         {
   240         if ( aValue == CSipSystemStateMonitor::ESnapAvailable )
   251         if ( aValue == CSipSystemStateMonitor::ESnapAvailable )
   241             {
   252             {
   242             if ( StartSnap() != KErrNone )
   253             if ( StartSnap() != KErrNone )
   243                 {
   254                 {
   255 // CSipAlrSnapMonitor::SnapId
   266 // CSipAlrSnapMonitor::SnapId
   256 // -----------------------------------------------------------------------------
   267 // -----------------------------------------------------------------------------
   257 //		
   268 //		
   258 TUint32 CSipAlrSnapMonitor::SnapId() const
   269 TUint32 CSipAlrSnapMonitor::SnapId() const
   259 	{
   270 	{
   260 	return iSnapId;
   271 	return iSnapData.iSnapId;
   261 	}
   272 	}
   262 			
   273 			
   263 // -----------------------------------------------------------------------------
   274 // -----------------------------------------------------------------------------
   264 // CSipAlrSnapMonitor::AddObserverL
   275 // CSipAlrSnapMonitor::AddObserverL
   265 // -----------------------------------------------------------------------------
   276 // -----------------------------------------------------------------------------
   322 			// So after last AlrEvent(), don't access this object's data.
   333 			// So after last AlrEvent(), don't access this object's data.
   323 			PROFILE_DEBUG3( "CSipAlrSnapMonitor::RefreshL error", err )
   334 			PROFILE_DEBUG3( "CSipAlrSnapMonitor::RefreshL error", err )
   324 			for ( TInt i = iObservers.Count() - 1; i >= 0; --i )
   335 			for ( TInt i = iObservers.Count() - 1; i >= 0; --i )
   325 				{
   336 				{
   326 				iObservers[i].iObserver->AlrEvent(
   337 				iObservers[i].iObserver->AlrEvent(
   327 					MSipAlrObserver::ERefreshError, iSnapId, KNoIap );
   338 					MSipAlrObserver::ERefreshError, SnapId(), KNoIap );
   328 				}
   339 				}
   329 			}
   340 			}
   330         }
   341         }
   331 
   342 
   332     PROFILE_DEBUG1( "CSipAlrSnapMonitor::Refresh returns" )
   343     PROFILE_DEBUG1( "CSipAlrSnapMonitor::Refresh returns" )
   400 // -----------------------------------------------------------------------------
   411 // -----------------------------------------------------------------------------
   401 //
   412 //
   402 TInt CSipAlrSnapMonitor::StartSnap()
   413 TInt CSipAlrSnapMonitor::StartSnap()
   403     {
   414     {
   404     PROFILE_DEBUG1( "CSipAlrSnapMonitor::StartSnap entered" )
   415     PROFILE_DEBUG1( "CSipAlrSnapMonitor::StartSnap entered" )
   405 
       
   406     TInt err = KErrNone;
   416     TInt err = KErrNone;
   407     if ( !IsActive() && IsSnapAvailable() )
   417     if ( !IsActive() && IsSnapAvailable() )
   408         {
   418         {
   409         PROFILE_DEBUG1( "CSipAlrSnapMonitor::StartSnap SNAP is available" )
   419         PROFILE_DEBUG1( "CSipAlrSnapMonitor::StartSnap SNAP is available" )
   410 
   420 
   411     	err = iConnection.Open( iSocketServer );
   421     	err = iConnection.Open( iSocketServer );
   412 		PROFILE_DEBUG3( "CSipAlrSnapMonitor::StartSnap Open done, err=", err )
   422 		PROFILE_DEBUG3( "CSipAlrSnapMonitor::StartSnap Open done, err=", err )
   413 
   423 
   414     	if ( err == KErrNone )
   424     	if ( err == KErrNone )
   415     	    {
   425     	    {
   416         	iConnection.Start( iPrefs, iStatus );
   426             if(BearerId())
   417         	SetActive();
   427                 {
       
   428                 if(BearerId()== 1)
       
   429                     {
       
   430                     iExtPrefs.SetBearerSet(TExtendedConnPref::EExtendedConnBearerWLAN);
       
   431                     }
       
   432                 else if(BearerId() == 2)
       
   433                     {
       
   434                     iExtPrefs.SetBearerSet(TExtendedConnPref::EExtendedConnBearerCellular);
       
   435                     }
       
   436 				PROFILE_DEBUG1( "CSipAlrSnapMonitor::Starting Bearer Filtered connection" )
       
   437                 iExtPrefs.SetSnapId( SnapId());
       
   438                 
       
   439                 TRAPD(error, iPrefList.AppendL(&iExtPrefs));
       
   440 				if(error)
       
   441 				{
       
   442 				return error;
       
   443 				}
       
   444                 // Start connecting
       
   445                 iConnection.Start( iPrefList, iStatus );
       
   446                 SetActive();
       
   447                 }
       
   448             else
       
   449                 {
       
   450 				PROFILE_DEBUG1( "CSipAlrSnapMonitor::Starting Normal Connection" )
       
   451                 iConnection.Start( iPrefs, iStatus );
       
   452                 SetActive();
       
   453                 }
   418     	    }
   454     	    }
   419         }
   455         }
   420 
   456 
   421 	PROFILE_DEBUG3( "CSipAlrSnapMonitor::StartSnap returns", err )
   457 	PROFILE_DEBUG3( "CSipAlrSnapMonitor::StartSnap returns", err )
   422     return err;
   458     return err;
   423     }
   459    }
   424 
   460 
   425 // -----------------------------------------------------------------------------
   461 // -----------------------------------------------------------------------------
   426 // CSipAlrSnapMonitor::CreateMobilityAoL
   462 // CSipAlrSnapMonitor::CreateMobilityAoL
   427 // -----------------------------------------------------------------------------
   463 // -----------------------------------------------------------------------------
   428 //	
   464 //	
   474 // -----------------------------------------------------------------------------
   510 // -----------------------------------------------------------------------------
   475 //
   511 //
   476 void CSipAlrSnapMonitor::NotifyObservers( TUint aIapId )
   512 void CSipAlrSnapMonitor::NotifyObservers( TUint aIapId )
   477 	{
   513 	{
   478 	PROFILE_DEBUG4( "CSipSnapAlrMonitor::NotifyObservers SNAP, IAP",
   514 	PROFILE_DEBUG4( "CSipSnapAlrMonitor::NotifyObservers SNAP, IAP",
   479 	                iSnapId, aIapId )
   515 	        SnapId(), aIapId )
   480 
   516 
   481 	NotifyInitializedObservers( aIapId, MSipAlrObserver::EIapAvailable );
   517 	NotifyInitializedObservers( aIapId, MSipAlrObserver::EIapAvailable );
   482 	NotifyNewObservers( aIapId );
   518 	NotifyNewObservers( aIapId );
   483 	}
   519 	}
   484 	
   520 	
   493 	for (TInt i = iObservers.Count() - 1; i >= 0; --i) 
   529 	for (TInt i = iObservers.Count() - 1; i >= 0; --i) 
   494 		{
   530 		{
   495 		if ( iObservers[i].iInitialEventDone )
   531 		if ( iObservers[i].iInitialEventDone )
   496 			{
   532 			{
   497 			PROFILE_DEBUG3( "CSipAlrSnapMonitor::NotifyIntitializedObservers",
   533 			PROFILE_DEBUG3( "CSipAlrSnapMonitor::NotifyIntitializedObservers",
   498 			                iSnapId )			
   534 			                SnapId() )			
   499 			
   535 			
   500 			iObservers[i].iObserver->AlrEvent( aEvent, iSnapId, aIapId );
   536 			iObservers[i].iObserver->AlrEvent( aEvent, SnapId(), aIapId );
   501 			}
   537 			}
   502 		}
   538 		}
   503 	}
   539 	}
   504 	
   540 	
   505 // -----------------------------------------------------------------------------
   541 // -----------------------------------------------------------------------------
   510 	{
   546 	{
   511 	for ( TInt i = iObservers.Count() - 1; i >= 0; --i )
   547 	for ( TInt i = iObservers.Count() - 1; i >= 0; --i )
   512 		{
   548 		{
   513 		if ( !iObservers[i].iInitialEventDone )
   549 		if ( !iObservers[i].iInitialEventDone )
   514 			{
   550 			{
   515 			PROFILE_DEBUG3( "CSipAlrSnapMonitor::NotifyNewObservers", iSnapId )
   551 			PROFILE_DEBUG3( "CSipAlrSnapMonitor::NotifyNewObservers", SnapId() )
   516 
   552 
   517 			iObservers[i].iObserver->AlrEvent(
   553 			iObservers[i].iObserver->AlrEvent(
   518 			    MSipAlrObserver::EIapAvailable, iSnapId, aIapId );
   554 			    MSipAlrObserver::EIapAvailable, SnapId(), aIapId );
   519 
   555 
   520 			iObservers[i].iInitialEventDone = ETrue;
   556 			iObservers[i].iInitialEventDone = ETrue;
   521 			}
   557 			}
   522 		}
   558 		}
   523 	}
   559 	}
   527 // -----------------------------------------------------------------------------
   563 // -----------------------------------------------------------------------------
   528 //
   564 //
   529 TBool CSipAlrSnapMonitor::IsSnapAvailable() const
   565 TBool CSipAlrSnapMonitor::IsSnapAvailable() const
   530     {
   566     {
   531     return ( iSystemStateMonitor.CurrentValue( 
   567     return ( iSystemStateMonitor.CurrentValue( 
   532 	             CSipSystemStateMonitor::ESnapAvailability, iSnapId ) == 
   568 	             CSipSystemStateMonitor::ESnapAvailability, SnapId() ) == 
   533 	                 CSipSystemStateMonitor::ESnapAvailable );
   569 	                 CSipSystemStateMonitor::ESnapAvailable );
   534     }
   570     }
       
   571 
       
   572 // -----------------------------------------------------------------------------
       
   573 // CSipAlrSnapMonitor::BearerId
       
   574 // -----------------------------------------------------------------------------
       
   575 //
       
   576 TBool CSipAlrSnapMonitor::BearerId()
       
   577     {
       
   578     return iSnapData.iBearerId;
       
   579     }