connectionmonitoring/connmon/connectionmonitor/src/ConnMonServ.cpp
changeset 52 bbe4544dfd31
parent 18 fcbbe021d614
child 71 9f263f780e41
equal deleted inserted replaced
50:6a30cdd10231 52:bbe4544dfd31
     1 /*
     1 /*
     2 * Copyright (c) 2002-2009 Nokia Corporation and/or its subsidiary(-ies).
     2 * Copyright (c) 2002-2010 Nokia Corporation and/or its subsidiary(-ies).
     3 * All rights reserved.
     3 * All rights reserved.
     4 * This component and the accompanying materials are made available
     4 * This component and the accompanying materials are made available
     5 * under the terms of "Eclipse Public License v1.0"
     5 * under the terms of "Eclipse Public License v1.0"
     6 * which accompanies this distribution, and is available
     6 * which accompanies this distribution, and is available
     7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
     7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
    32 #include "ConnMonBearerLAN.h"
    32 #include "ConnMonBearerLAN.h"
    33 #include "ConnMonBearerWLAN.h"
    33 #include "ConnMonBearerWLAN.h"
    34 #include "ConnMonBearerGroupManager.h"
    34 #include "ConnMonBearerGroupManager.h"
    35 #include "connmoncommsdatnotifier.h"
    35 #include "connmoncommsdatnotifier.h"
    36 #include "cellulardatausagekeyupdater.h"
    36 #include "cellulardatausagekeyupdater.h"
       
    37 #include "connmondialupoverridenotifier.h"
    37 
    38 
    38 // ============================ LOCAL FUNCTIONS ===============================
    39 // ============================ LOCAL FUNCTIONS ===============================
    39 
    40 
    40 // -----------------------------------------------------------------------------
    41 // -----------------------------------------------------------------------------
    41 // PanicServer
    42 // PanicServer
   234 // -----------------------------------------------------------------------------
   235 // -----------------------------------------------------------------------------
   235 //
   236 //
   236 CConnMonServer::CConnMonServer()
   237 CConnMonServer::CConnMonServer()
   237         :
   238         :
   238         CPolicyServer( CActive::EPriorityStandard, KConnMonPolicy ),
   239         CPolicyServer( CActive::EPriorityStandard, KConnMonPolicy ),
   239         iAvailabilityManager( NULL )
   240         iIap( NULL ),
       
   241         iEventQueue( NULL ),
       
   242         iSessionCount( 0 ),
       
   243         iShutdown( NULL ),
       
   244         iContainerIndex( NULL ),
       
   245         iCommsDatCache( NULL ),
       
   246         iAvailabilityManager( NULL ),
       
   247         iIapTableNotifier( NULL ),
       
   248         iSnapTableNotifier( NULL ),
       
   249         iVirtualTableNotifier( NULL ),
       
   250         iBearerGroupManager( NULL ),
       
   251         iCellularDataUsageKeyUpdater( NULL ),
       
   252         iDialUpOverrideNotifier( NULL ),
       
   253         iDialUpOverrideTimer( NULL ),
       
   254         iDialUpOverrideStatus( EConnMonDialUpOverrideDisabled )
   240     {
   255     {
   241     }
   256     }
   242 
   257 
   243 // -----------------------------------------------------------------------------
   258 // -----------------------------------------------------------------------------
   244 // CConnMonServer::ConstructL
   259 // CConnMonServer::ConstructL
   320     iBearerGroupManager = CConnMonBearerGroupManager::NewL();
   335     iBearerGroupManager = CConnMonBearerGroupManager::NewL();
   321     LOGIT("ConstructL: Bearer group manager constructed")
   336     LOGIT("ConstructL: Bearer group manager constructed")
   322     
   337     
   323     iCellularDataUsageKeyUpdater = CCellularDataUsageKeyUpdater::NewL( this );
   338     iCellularDataUsageKeyUpdater = CCellularDataUsageKeyUpdater::NewL( this );
   324     LOGIT("ConstructL: CCellularDataUsageKeyUpdater constructed")
   339     LOGIT("ConstructL: CCellularDataUsageKeyUpdater constructed")
   325     
   340 
       
   341     // Add P&S listener for dial-up PDP context override, if feature enabled.
       
   342     if ( iCellularDataUsageKeyUpdater->DialUpOverrideEnabled() )
       
   343         {
       
   344         iDialUpOverrideNotifier = CConnMonDialUpOverrideNotifier::NewL( this );
       
   345         iDialUpOverrideStatus = EConnMonDialUpOverrideInactive;
       
   346         LOGIT("ConstructL: Dial-up override notifier constructed")
       
   347 
       
   348         // Construct dial-up PDP context override timer.
       
   349         iDialUpOverrideTimer = CConnMonDialUpOverrideTimer::NewL( this );
       
   350         }
       
   351 
   326     // Identify ourselves and open for service
   352     // Identify ourselves and open for service
   327     StartL( KConnectionMonitorServerName );
   353     StartL( KConnectionMonitorServerName );
   328 
   354 
   329     //Start Indicator observer process
   355     //Start Indicator observer process
   330     _LIT(KIndicatorObserverExeFile,"indicatorobserver.exe");
   356     _LIT(KIndicatorObserverExeFile,"indicatorobserver.exe");
   378     // CommsDat cache
   404     // CommsDat cache
   379     delete iCommsDatCache;
   405     delete iCommsDatCache;
   380 
   406 
   381     // Bearer Group Manager
   407     // Bearer Group Manager
   382     delete iBearerGroupManager;
   408     delete iBearerGroupManager;
   383     
   409 
   384     delete iCellularDataUsageKeyUpdater;
   410     delete iCellularDataUsageKeyUpdater;
       
   411 
       
   412     // Dial-up PDP context override timer.
       
   413     delete iDialUpOverrideTimer;
       
   414 
       
   415     // P&S listener for dial-up PDP context override.
       
   416     delete iDialUpOverrideNotifier;
   385 
   417 
   386     FeatureManager::UnInitializeLib();
   418     FeatureManager::UnInitializeLib();
   387     }
   419     }
   388 
   420 
   389 // -----------------------------------------------------------------------------
   421 // -----------------------------------------------------------------------------
   787 TInt CConnMonServer::GetAvailableSnaps( RArray<TConnMonId>& aSnapIds )
   819 TInt CConnMonServer::GetAvailableSnaps( RArray<TConnMonId>& aSnapIds )
   788     {
   820     {
   789     // See comment in CConnMonServer::GetAvailableIaps() (above)
   821     // See comment in CConnMonServer::GetAvailableIaps() (above)
   790     /*TRAPD( err, iCommsDatCache->RefreshCommsDatCacheL( 0 ) );*/
   822     /*TRAPD( err, iCommsDatCache->RefreshCommsDatCacheL( 0 ) );*/
   791     return iCommsDatCache->GetAvailableSnaps( aSnapIds );
   823     return iCommsDatCache->GetAvailableSnaps( aSnapIds );
       
   824     }
       
   825 
       
   826 // -----------------------------------------------------------------------------
       
   827 // Set the dial-up PDP context override feature status. Either activates or
       
   828 // deactivates it. Does nothing if the feature itself has not been enabled.
       
   829 // -----------------------------------------------------------------------------
       
   830 //
       
   831 void CConnMonServer::SetDialUpOverrideStatus( TInt aStatus )
       
   832     {
       
   833     LOGENTRFN("CConnMonServer::SetDialUpOverrideStatus()")
       
   834 
       
   835     // Do nothing if whole feature is disabled.
       
   836     LOGIT2("iDialUpOverrideStatus = %d, aStatus = %d", iDialUpOverrideStatus, aStatus)
       
   837     if ( iDialUpOverrideStatus == EConnMonDialUpOverrideInactive &&
       
   838             aStatus == EConnMonDialUpOverrideActive )
       
   839         {
       
   840         LOGIT("Setting dial-up override status from inactive to active")
       
   841         // Start the dial-up override timer to ensure packetdata connectivity
       
   842         // is restored to original state eventually. Normally it is restored
       
   843         // after the dial-up connection has been successfully established.
       
   844         iDialUpOverrideTimer->Start();
       
   845         // Status must be set before updating cellular data usage key.
       
   846         iDialUpOverrideStatus = aStatus;
       
   847 
       
   848         // Disable cellular data usage until the expected dial-up
       
   849         // connection has been established (or timeout).
       
   850         TRAP_IGNORE( iCellularDataUsageKeyUpdater->UpdateKeyL( 0 ) );
       
   851 
       
   852         LOGIT("SetDialUpOverrideStatus() triggered HandleAvailabilityChange()")
       
   853         AvailabilityManager()->HandleAvailabilityChange();
       
   854         }
       
   855     else if ( iDialUpOverrideStatus == EConnMonDialUpOverrideActive &&
       
   856             aStatus == EConnMonDialUpOverrideInactive )
       
   857         {
       
   858         LOGIT("Setting dial-up override status from active to inactive")
       
   859         // Stop the dial-up override timer.
       
   860         iDialUpOverrideTimer->Cancel();
       
   861         // Status must be set before updating cellular data usage key.
       
   862         iDialUpOverrideStatus = aStatus;
       
   863 
       
   864         TInt registration( ENetworkRegistrationExtUnknown );
       
   865         TInt err = iIap->GetNetworkRegistration_v2( registration );
       
   866         if ( err == KErrNone )
       
   867             {
       
   868             TRAP_IGNORE( iCellularDataUsageKeyUpdater->UpdateKeyL( registration ) );
       
   869             }
       
   870         else
       
   871             {
       
   872             LOGIT1("GetNetworkRegistration_v2 failed <%d>", err)
       
   873             }
       
   874         iDialUpOverrideNotifier->ResetStatus();
       
   875 
       
   876         LOGIT("SetDialUpOverrideStatus() triggered HandleAvailabilityChange()")
       
   877         AvailabilityManager()->HandleAvailabilityChange();
       
   878         }
       
   879 
       
   880     LOGEXITFN("CConnMonServer::SetDialUpOverrideStatus()")
       
   881     }
       
   882 
       
   883 // -----------------------------------------------------------------------------
       
   884 // Signals that all internal PDP connections have closed through the
       
   885 // KDialUpConnection P&S-property.
       
   886 // -----------------------------------------------------------------------------
       
   887 //
       
   888 void CConnMonServer::ConnectionsClosedForDialUpOverride()
       
   889     {
       
   890     LOGENTRFN("CConnMonServer::ConnectionsClosedForDialUpOverride()")
       
   891     if ( iDialUpOverrideStatus == EConnMonDialUpOverrideActive )
       
   892         {
       
   893         iDialUpOverrideNotifier->ResetStatus();
       
   894         }
       
   895     LOGEXITFN("CConnMonServer::ConnectionsClosedForDialUpOverride()")
   792     }
   896     }
   793 
   897 
   794 // -----------------------------------------------------------------------------
   898 // -----------------------------------------------------------------------------
   795 // CConnMonServer::CustomSecurityCheckL
   899 // CConnMonServer::CustomSecurityCheckL
   796 // Implements custom security checking for IPCs marked with
   900 // Implements custom security checking for IPCs marked with
   887     {
   991     {
   888     LOGIT("Server: Shutting down by timer")
   992     LOGIT("Server: Shutting down by timer")
   889     CActiveScheduler::Stop();
   993     CActiveScheduler::Stop();
   890     }
   994     }
   891 
   995 
   892 // End-of-file
   996 // -----------------------------------------------------------------------------
       
   997 // CConnMonDialUpOverrideTimer::NewL
       
   998 // -----------------------------------------------------------------------------
       
   999 //
       
  1000 CConnMonDialUpOverrideTimer* CConnMonDialUpOverrideTimer::NewL(
       
  1001         CConnMonServer* aServer )
       
  1002     {
       
  1003     CConnMonDialUpOverrideTimer* self = CConnMonDialUpOverrideTimer::NewLC( aServer );
       
  1004     CleanupStack::Pop( self );
       
  1005     return self;
       
  1006     }
       
  1007 
       
  1008 // -----------------------------------------------------------------------------
       
  1009 // CConnMonDialUpOverrideTimer::NewLC
       
  1010 // -----------------------------------------------------------------------------
       
  1011 //
       
  1012 CConnMonDialUpOverrideTimer* CConnMonDialUpOverrideTimer::NewLC(
       
  1013         CConnMonServer* aServer )
       
  1014     {
       
  1015     CConnMonDialUpOverrideTimer* self = new( ELeave ) CConnMonDialUpOverrideTimer( aServer );
       
  1016     CleanupStack::PushL( self );
       
  1017     self->ConstructL();
       
  1018     return self;
       
  1019     }
       
  1020 
       
  1021 // -----------------------------------------------------------------------------
       
  1022 // CConnMonDialUpOverrideTimer::~CConnMonDialUpOverrideTimer
       
  1023 // -----------------------------------------------------------------------------
       
  1024 //
       
  1025 CConnMonDialUpOverrideTimer::~CConnMonDialUpOverrideTimer()
       
  1026     {
       
  1027     Cancel();
       
  1028     iTimer.Close();
       
  1029     iServer = NULL;
       
  1030     }
       
  1031 
       
  1032 // -----------------------------------------------------------------------------
       
  1033 // CConnMonDialUpOverrideTimer::CConnMonDialUpOverrideTimer
       
  1034 // -----------------------------------------------------------------------------
       
  1035 //
       
  1036 CConnMonDialUpOverrideTimer::CConnMonDialUpOverrideTimer(
       
  1037         CConnMonServer* aServer )
       
  1038         :
       
  1039         CActive( EConnMonPriorityNormal ),
       
  1040         iServer( aServer )
       
  1041     {
       
  1042     }
       
  1043 
       
  1044 // -----------------------------------------------------------------------------
       
  1045 // CConnMonDialUpOverrideTimer::ConstructL
       
  1046 // -----------------------------------------------------------------------------
       
  1047 //
       
  1048 void CConnMonDialUpOverrideTimer::ConstructL()
       
  1049     {
       
  1050     CActiveScheduler::Add( this );
       
  1051     User::LeaveIfError( iTimer.CreateLocal() );
       
  1052     }
       
  1053 
       
  1054 // -----------------------------------------------------------------------------
       
  1055 // CConnMonDialUpOverrideTimer::Start
       
  1056 // -----------------------------------------------------------------------------
       
  1057 //
       
  1058 void CConnMonDialUpOverrideTimer::Start()
       
  1059     {
       
  1060     if ( !IsActive() )
       
  1061         {
       
  1062         iTimer.After( iStatus, KConnMonDialUpOverrideInterval );
       
  1063         SetActive();
       
  1064         }
       
  1065     }
       
  1066 
       
  1067 // -----------------------------------------------------------------------------
       
  1068 // CConnMonDialUpOverrideTimer::DoCancel
       
  1069 // -----------------------------------------------------------------------------
       
  1070 //
       
  1071 void CConnMonDialUpOverrideTimer::DoCancel()
       
  1072     {
       
  1073     iTimer.Cancel();
       
  1074     }
       
  1075 
       
  1076 // -----------------------------------------------------------------------------
       
  1077 // CConnMonDialUpOverrideTimer::RunL
       
  1078 // -----------------------------------------------------------------------------
       
  1079 //
       
  1080 void CConnMonDialUpOverrideTimer::RunL()
       
  1081     {
       
  1082     LOGIT(".")
       
  1083     LOGIT1("RunL: CConnMonDialUpOverrideTimer <%d>", iStatus.Int())
       
  1084     iServer->SetDialUpOverrideStatus( EConnMonDialUpOverrideInactive );
       
  1085     }
       
  1086 
       
  1087 // End of file