connectionmonitoring/connmon/connectionmonitor/src/ConnMonServ.cpp
branchRCL_3
changeset 23 fc7b30ed2058
parent 2 086aae6fc07e
child 24 05bc53fe583b
equal deleted inserted replaced
22:984e13af52c4 23:fc7b30ed2058
     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     LOGIT("ConstructL: Server started successfully")
   355     LOGIT("ConstructL: Server started successfully")
   330     LOGEXITFN("CConnMonServer::ConstructL()")
   356     LOGEXITFN("CConnMonServer::ConstructL()")
   370     // CommsDat cache
   396     // CommsDat cache
   371     delete iCommsDatCache;
   397     delete iCommsDatCache;
   372 
   398 
   373     // Bearer Group Manager
   399     // Bearer Group Manager
   374     delete iBearerGroupManager;
   400     delete iBearerGroupManager;
   375     
   401 
   376     delete iCellularDataUsageKeyUpdater;
   402     delete iCellularDataUsageKeyUpdater;
       
   403 
       
   404     // Dial-up PDP context override timer.
       
   405     delete iDialUpOverrideTimer;
       
   406 
       
   407     // P&S listener for dial-up PDP context override.
       
   408     delete iDialUpOverrideNotifier;
   377 
   409 
   378     FeatureManager::UnInitializeLib();
   410     FeatureManager::UnInitializeLib();
   379     }
   411     }
   380 
   412 
   381 // -----------------------------------------------------------------------------
   413 // -----------------------------------------------------------------------------
   779 TInt CConnMonServer::GetAvailableSnaps( RArray<TConnMonId>& aSnapIds )
   811 TInt CConnMonServer::GetAvailableSnaps( RArray<TConnMonId>& aSnapIds )
   780     {
   812     {
   781     // See comment in CConnMonServer::GetAvailableIaps() (above)
   813     // See comment in CConnMonServer::GetAvailableIaps() (above)
   782     /*TRAPD( err, iCommsDatCache->RefreshCommsDatCacheL( 0 ) );*/
   814     /*TRAPD( err, iCommsDatCache->RefreshCommsDatCacheL( 0 ) );*/
   783     return iCommsDatCache->GetAvailableSnaps( aSnapIds );
   815     return iCommsDatCache->GetAvailableSnaps( aSnapIds );
       
   816     }
       
   817 
       
   818 // -----------------------------------------------------------------------------
       
   819 // Set the dial-up PDP context override feature status. Either activates or
       
   820 // deactivates it. Does nothing if the feature itself has not been enabled.
       
   821 // -----------------------------------------------------------------------------
       
   822 //
       
   823 void CConnMonServer::SetDialUpOverrideStatus( TInt aStatus )
       
   824     {
       
   825     LOGENTRFN("CConnMonServer::SetDialUpOverrideStatus()")
       
   826 
       
   827     // Do nothing if whole feature is disabled.
       
   828     LOGIT2("iDialUpOverrideStatus = %d, aStatus = %d", iDialUpOverrideStatus, aStatus)
       
   829     if ( iDialUpOverrideStatus == EConnMonDialUpOverrideInactive &&
       
   830             aStatus == EConnMonDialUpOverrideActive )
       
   831         {
       
   832         LOGIT("Setting dial-up override status from inactive to active")
       
   833         // Start the dial-up override timer to ensure packetdata connectivity
       
   834         // is restored to original state eventually. Normally it is restored
       
   835         // after the dial-up connection has been successfully established.
       
   836         iDialUpOverrideTimer->Start();
       
   837         // Status must be set before updating cellular data usage key.
       
   838         iDialUpOverrideStatus = aStatus;
       
   839 
       
   840         // Disable cellular data usage until the expected dial-up
       
   841         // connection has been established (or timeout).
       
   842         TRAP_IGNORE( iCellularDataUsageKeyUpdater->UpdateKeyL( 0 ) );
       
   843 
       
   844         LOGIT("SetDialUpOverrideStatus() triggered HandleAvailabilityChange()")
       
   845         AvailabilityManager()->HandleAvailabilityChange();
       
   846         }
       
   847     else if ( iDialUpOverrideStatus == EConnMonDialUpOverrideActive &&
       
   848             aStatus == EConnMonDialUpOverrideInactive )
       
   849         {
       
   850         LOGIT("Setting dial-up override status from active to inactive")
       
   851         // Stop the dial-up override timer.
       
   852         iDialUpOverrideTimer->Cancel();
       
   853         // Status must be set before updating cellular data usage key.
       
   854         iDialUpOverrideStatus = aStatus;
       
   855 
       
   856         TInt registration( ENetworkRegistrationExtUnknown );
       
   857         TInt err = iIap->GetNetworkRegistration_v2( registration );
       
   858         if ( err == KErrNone )
       
   859             {
       
   860             TRAP_IGNORE( iCellularDataUsageKeyUpdater->UpdateKeyL( registration ) );
       
   861             }
       
   862         else
       
   863             {
       
   864             LOGIT1("GetNetworkRegistration_v2 failed <%d>", err)
       
   865             }
       
   866         iDialUpOverrideNotifier->ResetStatus();
       
   867 
       
   868         LOGIT("SetDialUpOverrideStatus() triggered HandleAvailabilityChange()")
       
   869         AvailabilityManager()->HandleAvailabilityChange();
       
   870         }
       
   871 
       
   872     LOGEXITFN("CConnMonServer::SetDialUpOverrideStatus()")
       
   873     }
       
   874 
       
   875 // -----------------------------------------------------------------------------
       
   876 // Signals that all internal PDP connections have closed through the
       
   877 // KDialUpConnection P&S-property.
       
   878 // -----------------------------------------------------------------------------
       
   879 //
       
   880 void CConnMonServer::ConnectionsClosedForDialUpOverride()
       
   881     {
       
   882     LOGENTRFN("CConnMonServer::ConnectionsClosedForDialUpOverride()")
       
   883     if ( iDialUpOverrideStatus == EConnMonDialUpOverrideActive )
       
   884         {
       
   885         iDialUpOverrideNotifier->ResetStatus();
       
   886         }
       
   887     LOGEXITFN("CConnMonServer::ConnectionsClosedForDialUpOverride()")
   784     }
   888     }
   785 
   889 
   786 // -----------------------------------------------------------------------------
   890 // -----------------------------------------------------------------------------
   787 // CConnMonServer::CustomSecurityCheckL
   891 // CConnMonServer::CustomSecurityCheckL
   788 // Implements custom security checking for IPCs marked with
   892 // Implements custom security checking for IPCs marked with
   879     {
   983     {
   880     LOGIT("Server: Shutting down by timer")
   984     LOGIT("Server: Shutting down by timer")
   881     CActiveScheduler::Stop();
   985     CActiveScheduler::Stop();
   882     }
   986     }
   883 
   987 
   884 // End-of-file
   988 // -----------------------------------------------------------------------------
       
   989 // CConnMonDialUpOverrideTimer::NewL
       
   990 // -----------------------------------------------------------------------------
       
   991 //
       
   992 CConnMonDialUpOverrideTimer* CConnMonDialUpOverrideTimer::NewL(
       
   993         CConnMonServer* aServer )
       
   994     {
       
   995     CConnMonDialUpOverrideTimer* self = CConnMonDialUpOverrideTimer::NewLC( aServer );
       
   996     CleanupStack::Pop( self );
       
   997     return self;
       
   998     }
       
   999 
       
  1000 // -----------------------------------------------------------------------------
       
  1001 // CConnMonDialUpOverrideTimer::NewLC
       
  1002 // -----------------------------------------------------------------------------
       
  1003 //
       
  1004 CConnMonDialUpOverrideTimer* CConnMonDialUpOverrideTimer::NewLC(
       
  1005         CConnMonServer* aServer )
       
  1006     {
       
  1007     CConnMonDialUpOverrideTimer* self = new( ELeave ) CConnMonDialUpOverrideTimer( aServer );
       
  1008     CleanupStack::PushL( self );
       
  1009     self->ConstructL();
       
  1010     return self;
       
  1011     }
       
  1012 
       
  1013 // -----------------------------------------------------------------------------
       
  1014 // CConnMonDialUpOverrideTimer::~CConnMonDialUpOverrideTimer
       
  1015 // -----------------------------------------------------------------------------
       
  1016 //
       
  1017 CConnMonDialUpOverrideTimer::~CConnMonDialUpOverrideTimer()
       
  1018     {
       
  1019     Cancel();
       
  1020     iTimer.Close();
       
  1021     iServer = NULL;
       
  1022     }
       
  1023 
       
  1024 // -----------------------------------------------------------------------------
       
  1025 // CConnMonDialUpOverrideTimer::CConnMonDialUpOverrideTimer
       
  1026 // -----------------------------------------------------------------------------
       
  1027 //
       
  1028 CConnMonDialUpOverrideTimer::CConnMonDialUpOverrideTimer(
       
  1029         CConnMonServer* aServer )
       
  1030         :
       
  1031         CActive( EConnMonPriorityNormal ),
       
  1032         iServer( aServer )
       
  1033     {
       
  1034     }
       
  1035 
       
  1036 // -----------------------------------------------------------------------------
       
  1037 // CConnMonDialUpOverrideTimer::ConstructL
       
  1038 // -----------------------------------------------------------------------------
       
  1039 //
       
  1040 void CConnMonDialUpOverrideTimer::ConstructL()
       
  1041     {
       
  1042     CActiveScheduler::Add( this );
       
  1043     User::LeaveIfError( iTimer.CreateLocal() );
       
  1044     }
       
  1045 
       
  1046 // -----------------------------------------------------------------------------
       
  1047 // CConnMonDialUpOverrideTimer::Start
       
  1048 // -----------------------------------------------------------------------------
       
  1049 //
       
  1050 void CConnMonDialUpOverrideTimer::Start()
       
  1051     {
       
  1052     if ( !IsActive() )
       
  1053         {
       
  1054         iTimer.After( iStatus, KConnMonDialUpOverrideInterval );
       
  1055         SetActive();
       
  1056         }
       
  1057     }
       
  1058 
       
  1059 // -----------------------------------------------------------------------------
       
  1060 // CConnMonDialUpOverrideTimer::DoCancel
       
  1061 // -----------------------------------------------------------------------------
       
  1062 //
       
  1063 void CConnMonDialUpOverrideTimer::DoCancel()
       
  1064     {
       
  1065     iTimer.Cancel();
       
  1066     }
       
  1067 
       
  1068 // -----------------------------------------------------------------------------
       
  1069 // CConnMonDialUpOverrideTimer::RunL
       
  1070 // -----------------------------------------------------------------------------
       
  1071 //
       
  1072 void CConnMonDialUpOverrideTimer::RunL()
       
  1073     {
       
  1074     LOGIT(".")
       
  1075     LOGIT1("RunL: CConnMonDialUpOverrideTimer <%d>", iStatus.Int())
       
  1076     iServer->SetDialUpOverrideStatus( EConnMonDialUpOverrideInactive );
       
  1077     }
       
  1078 
       
  1079 // End of file