realtimenetprots/sipfw/ProfileAgent/Server/Src/SipProfileServerCore.cpp
branchRCL_3
changeset 20 a7d1e54a7332
parent 19 8517a9ac4a23
child 26 822e1f077722
equal deleted inserted replaced
19:8517a9ac4a23 20:a7d1e54a7332
    55 using namespace CommsDat;
    55 using namespace CommsDat;
    56 
    56 
    57 
    57 
    58 const TInt KMicroSecInSec = 1000000;
    58 const TInt KMicroSecInSec = 1000000;
    59 const TInt KIdleTimer = 2;
    59 const TInt KIdleTimer = 2;
       
    60 const TInt KOfflineTimer = 5;
    60 
    61 
    61 // ============================ MEMBER FUNCTIONS ===============================
    62 // ============================ MEMBER FUNCTIONS ===============================
    62 
    63 
    63 // -----------------------------------------------------------------------------
    64 // -----------------------------------------------------------------------------
    64 // CSIPProfileServerCore::NewL
    65 // CSIPProfileServerCore::NewL
   169     LoadProfilesL(EFalse);
   170     LoadProfilesL(EFalse);
   170 
   171 
   171     iNotify = CSIPProfileStorageSecureBackup::NewL(this);
   172     iNotify = CSIPProfileStorageSecureBackup::NewL(this);
   172     
   173     
   173     iServer = CSIPProfileCSServer::NewL(*this);
   174     iServer = CSIPProfileCSServer::NewL(*this);
   174 	
       
   175 	iOfflineEventReceived = EFalse;
       
   176     
   175     
   177     PROFILE_DEBUG1("ProfileServer started")
   176     PROFILE_DEBUG1("ProfileServer started")
   178     }
   177     }
   179 
   178 
   180 // -----------------------------------------------------------------------------
   179 // -----------------------------------------------------------------------------
   289             	"ProfileServerCore::SIPProfileStatusEventL(removed) id",
   288             	"ProfileServerCore::SIPProfileStatusEventL(removed) id",
   290                 	aProfileId)
   289                 	aProfileId)
   291             	}
   290             	}
   292         		
   291         		
   293         	}
   292         	}
       
   293         
       
   294         //For Profiles which were in RegInProgress and has moved to Registered State,
       
   295         //needs to be deregistered if Offline or RFs or Vpn if in Use has been triggered.
   294         TBool eventCompleted = EFalse;
   296         TBool eventCompleted = EFalse;
   295         if(item && (item->IsRfsInprogress() || iOfflineEventReceived ||
   297         if(item && (item->IsRfsInprogress() || item->IsOfflineInitiated()  ||
   296                 (FeatureManager::FeatureSupported( KFeatureIdFfImsDeregistrationInVpn )&& 
   298                 (FeatureManager::FeatureSupported( KFeatureIdFfImsDeregistrationInVpn )&& 
   297                         item->IsVpnInUse())))
   299                         item->IsVpnInUse())))
   298             {
   300             {
   299             CSIPConcreteProfile::TStatus status;
   301             CSIPConcreteProfile::TStatus status;
   300             TInt count = iProfileCache.Count();
   302             TInt count = iProfileCache.Count();
   303                 iPluginDirector->State( status, iProfileCache[i]->UsedProfile() );
   305                 iPluginDirector->State( status, iProfileCache[i]->UsedProfile() );
   304                 if ( status == CSIPConcreteProfile::EUnregistered )
   306                 if ( status == CSIPConcreteProfile::EUnregistered )
   305                     {
   307                     {
   306                     count--;
   308                     count--;
   307                     }
   309                     }
   308                 else if (status == CSIPConcreteProfile::ERegistered )
   310                 else if (status == CSIPConcreteProfile::ERegistered)
   309                     {
   311                     {
   310                     iProfileCache[i]->ShutdownInitiated();
   312                     if(item->IsOfflineInitiated())
   311                     }
   313                         {                        
   312                 }
   314                         //Don't do anything. If the ProfileStatusEvent = Registered in Offline, it
       
   315                         //will only be for WLAN so don't deregister it. If ProfileStatusEvent = Deregistered
       
   316                         //means application triggered deregistration so ProfileAgent should not attempt registering it.
       
   317                         }
       
   318                     else
       
   319                         {
       
   320                         iProfileCache[i]->ShutdownInitiated();
       
   321                         }
       
   322                     } //end if unregistered
   313             if ( !count )
   323             if ( !count )
   314                 eventCompleted = ETrue;
   324                 eventCompleted = ETrue;
   315             }
   325                 } //end for
       
   326             } //end outer if
       
   327         
       
   328         
   316         if(eventCompleted)
   329         if(eventCompleted)
   317             {
   330             {
   318             if (item->IsRfsInprogress())
   331             if (item->IsRfsInprogress())
   319                 StartConnectionCloseTimer();
   332                 StartConnectionCloseTimer(KIdleTimer);
   320             else if(iOfflineEventReceived)
   333             else if(item->IsOfflineInitiated() )
   321                 ConfirmSystemstateMonitor(CSipSystemStateMonitor::ESystemState);
   334                 ConfirmSystemstateMonitor(CSipSystemStateMonitor::ESystemState);
   322             else if((FeatureManager::FeatureSupported( KFeatureIdFfImsDeregistrationInVpn )&& 
   335             else if((FeatureManager::FeatureSupported( KFeatureIdFfImsDeregistrationInVpn )&& 
   323                         item->IsVpnInUse()))
   336                         item->IsVpnInUse()))
   324                 ConfirmSystemstateMonitor(CSipSystemStateMonitor::EVpnState);                
   337                 ConfirmSystemstateMonitor(CSipSystemStateMonitor::EVpnState);                
   325             }       
   338             }       
   442     TInt /*aObjectId*/,
   455     TInt /*aObjectId*/,
   443     TInt aValue )
   456     TInt aValue )
   444     {
   457     {
   445     PROFILE_DEBUG3("CSIPProfileServerCore::SystemVariableUpdated System State changed to value", aValue)
   458     PROFILE_DEBUG3("CSIPProfileServerCore::SystemVariableUpdated System State changed to value", aValue)
   446     
   459     
   447     //If the SystemState is Offline, turn the boolean variable to true so that Profile-Server
   460 	if ( aVariable == CSipSystemStateMonitor::ESystemState )
   448     //can indicate System State monitor that event processing is completed, provided all the 
       
   449     //profiles have got deregistered
       
   450     if (CSipSystemStateMonitor::ESystemOffline == aValue)
       
   451         iOfflineEventReceived = ETrue;
       
   452     
       
   453 	if ( aVariable == CSipSystemStateMonitor::ESystemState &&
       
   454 	     (aValue == CSipSystemStateMonitor::ESystemShuttingDown || 
       
   455 	     aValue == CSipSystemStateMonitor::ESystemOffline
       
   456 			 ))
       
   457 	    {   
   461 	    {   
   458 	    TBool waitForDeregistration = EFalse;
   462             // If the System is Shutting down
   459         for (TInt i = 0; i < iProfileCache.Count(); i++)
   463             if(aValue == CSipSystemStateMonitor::ESystemShuttingDown)
   460             {
   464                 {                
   461             iProfileCache[i]->ShutdownInitiated();
   465                 for (TInt i = 0; i < iProfileCache.Count(); i++)
   462             CSIPConcreteProfile::TStatus status;
   466                     {
   463             iPluginDirector->State(status, iProfileCache[i]->UsedProfile());
   467                     iProfileCache[i]->ShutdownInitiated();                                
   464             if(status != CSIPConcreteProfile::EUnregistered)
   468                     }                
   465                 waitForDeregistration = ETrue;            
   469                 } //end if Shutdown
   466             }
   470             
   467         if(!waitForDeregistration)
   471             //If the System receives Offline event
   468             {
   472             if(aValue == CSipSystemStateMonitor::ESystemOffline)
   469             ConfirmSystemstateMonitor(CSipSystemStateMonitor::ESystemState);
   473                 {                
   470             }
   474                 StartConnectionCloseTimer(KOfflineTimer);
   471 	    }
   475                 TBool waitForDeregistration = EFalse;
   472 	//If the System State is Online, register all the profiles in always on mode
   476                 for (TInt i = 0; i < iProfileCache.Count(); i++)
   473 	else if(aVariable == CSipSystemStateMonitor::ESystemState && 
   477                     {
   474 		aValue == CSipSystemStateMonitor::ESystemOnline)
   478                     iProfileCache[i]->OfflineInitiated(ETrue);
   475 		{
   479                     CSIPConcreteProfile::TStatus status;
   476 		iOfflineEventReceived = EFalse;
   480                     iPluginDirector->State(status, iProfileCache[i]->UsedProfile());
   477 		for (TInt i = 0; i < iProfileCache.Count(); i++)
   481                     if(status != CSIPConcreteProfile::EUnregistered)
   478 		    {
   482                         waitForDeregistration = ETrue;            
   479 		    iProfileCache[i]->ResetShutdownvariable();
   483                     }
   480 		    CSIPProfileCacheItem* item = iProfileCache[i];
   484                 if(!waitForDeregistration)
   481 		    if (iProfileCache[i]->IsReferred())
   485                     {
   482 		        {
   486                     ConfirmSystemstateMonitor(CSipSystemStateMonitor::ESystemState);
   483                 TRAPD(err, item->StartRegisterL(*iWaitForIAP, *iRegInProg, ETrue));
   487                     }
   484 		        if (err != KErrNone)
   488                 } //end if Offline
   485 		            {
   489             
   486 		            HandleAsyncError(*item,CSIPConcreteProfile::ERegistrationInProgress,err);
   490             //If the System receives Online event
   487 		            }
   491             if(aValue == CSipSystemStateMonitor::ESystemOnline)
   488 				}
   492                 {                
   489 			}
   493                 for (TInt i = 0; i < iProfileCache.Count(); i++)
   490 		}
   494                     {
       
   495                     CSIPProfileCacheItem* item = iProfileCache[i];
       
   496                     item->OfflineInitiated(EFalse);                    
       
   497                     CSIPConcreteProfile::TStatus status;
       
   498                     iPluginDirector->State(status, item->UsedProfile());
       
   499                     if (item->IsReferred() && status == CSIPConcreteProfile::EUnregistered)
       
   500                         {
       
   501                         TRAPD(err, item->StartRegisterL(*iWaitForIAP, *iRegInProg, ETrue));
       
   502                         if (err != KErrNone)
       
   503                             {
       
   504                             HandleAsyncError(*item,CSIPConcreteProfile::ERegistrationInProgress,err);
       
   505                             }
       
   506                         }
       
   507                     }
       
   508                 } //end if Online           
       
   509 	    } //end if SystemState    
   491 	else if(aVariable == CSipSystemStateMonitor::ERfsState)
   510 	else if(aVariable == CSipSystemStateMonitor::ERfsState)
   492 	    {
   511 	    {
   493 	    if(aValue == CSipSystemStateMonitor::ERfsStarted)
   512 	    if(aValue == CSipSystemStateMonitor::ERfsStarted)
   494 	        {
   513 	        {
   495 	        PROFILE_DEBUG1("RFS Started, de-registering the profiles")
   514 	        PROFILE_DEBUG1("RFS Started, de-registering the profiles")
  2134 
  2153 
  2135 // -----------------------------------------------------------------------------
  2154 // -----------------------------------------------------------------------------
  2136 // CSIPProfileServerCore::StartConnectionCloseTimer
  2155 // CSIPProfileServerCore::StartConnectionCloseTimer
  2137 // -----------------------------------------------------------------------------
  2156 // -----------------------------------------------------------------------------
  2138 //
  2157 //
  2139 void CSIPProfileServerCore::StartConnectionCloseTimer()
  2158 void CSIPProfileServerCore::StartConnectionCloseTimer(TInt aValue)
  2140 	{
  2159 	{
  2141 	PROFILE_DEBUG1("CSIPProfileServerCore::StartConnectionCloseTimer")
  2160 	PROFILE_DEBUG1("CSIPProfileServerCore::StartConnectionCloseTimer")
  2142 	iDeltaTimer->Remove(iDeltaTimerEntry);
  2161 	iDeltaTimer->Remove(iDeltaTimerEntry);
  2143 	TTimeIntervalMicroSeconds32 interval(KMicroSecInSec * KIdleTimer);
  2162 	TTimeIntervalMicroSeconds32 interval(KMicroSecInSec * aValue);
  2144 	iDeltaTimer->Queue(interval, iDeltaTimerEntry);
  2163 	iDeltaTimer->Queue(interval, iDeltaTimerEntry);
  2145 	}
  2164 	}
  2146 
  2165 
  2147 // -----------------------------------------------------------------------------
  2166 // -----------------------------------------------------------------------------
  2148 // CSIPProfileServerCore::ConnectionCloseTimerExpired
  2167 // CSIPProfileServerCore::ConnectionCloseTimerExpired
  2150 //
  2169 //
  2151 TInt CSIPProfileServerCore::ConnectionCloseTimerExpired(TAny* aPtr)
  2170 TInt CSIPProfileServerCore::ConnectionCloseTimerExpired(TAny* aPtr)
  2152 	{
  2171 	{
  2153 	PROFILE_DEBUG1("CSIPProfileServerCore::ConnectionCloseTimerExpired")
  2172 	PROFILE_DEBUG1("CSIPProfileServerCore::ConnectionCloseTimerExpired")
  2154 	CSIPProfileServerCore* self = reinterpret_cast<CSIPProfileServerCore*>(aPtr);
  2173 	CSIPProfileServerCore* self = reinterpret_cast<CSIPProfileServerCore*>(aPtr);
  2155   	self->ConfirmSystemstateMonitor(CSipSystemStateMonitor::ERfsState);
  2174 	
       
  2175 	TBool IsOffline = self->iProfileCache[0]->IsOfflineInitiated();
       
  2176 	if(IsOffline)
       
  2177 	    {
       
  2178 	    self->ConfirmSystemstateMonitor(CSipSystemStateMonitor::ESystemState);	    	        
       
  2179         for (TInt i = 0; i < self->iProfileCache.Count(); i++)
       
  2180             {            
       
  2181             CSIPProfileCacheItem* item = self->iProfileCache[i];
       
  2182             CSIPConcreteProfile::TStatus status;
       
  2183             self->iPluginDirector->State( status, self->iProfileCache[i]->UsedProfile() );
       
  2184             item->OfflineInitiated(EFalse);
       
  2185             if (item->IsReferred() && (!self->iApnManager->IsIapGPRSL(item->Profile().IapId())) 
       
  2186                     && status == CSIPConcreteProfile::EUnregistered) 
       
  2187                 {                
       
  2188                 TRAPD(err, item->StartRegisterL(*(self->iWaitForIAP), *(self->iRegInProg), ETrue));
       
  2189                 if (err != KErrNone)
       
  2190                     {
       
  2191                     self->HandleAsyncError(*item,CSIPConcreteProfile::ERegistrationInProgress,err);
       
  2192                     }                  
       
  2193                 }
       
  2194             else
       
  2195                 {}           
       
  2196             } //end for	    	    
       
  2197 	    }//end Outer If
       
  2198 	else
       
  2199 	    self->ConfirmSystemstateMonitor(CSipSystemStateMonitor::ERfsState);
       
  2200 	
  2156   	return ETrue;
  2201   	return ETrue;
  2157 	}
  2202 	}
  2158 
  2203 
  2159 // -----------------------------------------------------------------------------
  2204 // -----------------------------------------------------------------------------
  2160 // CSIPProfileServerCore::ConfirmSystemstateMonitor
  2205 // CSIPProfileServerCore::ConfirmSystemstateMonitor
  2161 // -----------------------------------------------------------------------------
  2206 // -----------------------------------------------------------------------------
  2162 //
  2207 //
  2163 void CSIPProfileServerCore::ConfirmSystemstateMonitor(
  2208 void CSIPProfileServerCore::ConfirmSystemstateMonitor(
  2164 	CSipSystemStateMonitor::TSystemVariable aVariable)
  2209 	CSipSystemStateMonitor::TSystemVariable aVariable)
  2165 	{
  2210 	{    
  2166 		iSystemStateMonitor->EventProcessingCompleted(
  2211         iSystemStateMonitor->EventProcessingCompleted(aVariable, 0, *this);
  2167 		        aVariable, 0, *this);
       
  2168 	}
  2212 	}
  2169 	
  2213 	
  2170 // ----------------------------------------------------------------------------
  2214 // ----------------------------------------------------------------------------
  2171 //CSIPProfileServerCore::ApnChanged
  2215 //CSIPProfileServerCore::ApnChanged
  2172 // ----------------------------------------------------------------------------
  2216 // ----------------------------------------------------------------------------