wlan_bearer/wlanengine/wlan_symbian/wlanengine_symbian_3.1/src/wlmplatform.cpp
changeset 0 c40eb8fe8501
child 3 6524e815f76f
equal deleted inserted replaced
-1:000000000000 0:c40eb8fe8501
       
     1 /*
       
     2 * Copyright (c) 2002-2006 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 the License "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:  Offers API to platform for the rest of the engine
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 #include <e32std.h>
       
    20 #include "wlmplatform.h"
       
    21 #include "wlmplatformdata.h"
       
    22 #include "am_debug.h"
       
    23 
       
    24 // ================= MEMBER FUNCTIONS =======================
       
    25 
       
    26 // C++ default constructor can NOT contain any code, that
       
    27 // might leave.
       
    28 //
       
    29 CWlmPlatform::CWlmPlatform( MWlmPlatformCallback& aCallback ) :
       
    30     iCallback( aCallback ), 
       
    31     iCurrentSystemMode( EWlanSystemStartupInProgress ),
       
    32     iPlatformData( NULL ),
       
    33     iWlanConnectedBeforeEmergencyCall( EFalse ),
       
    34     iSystemTimeHandler( NULL ),
       
    35     iPeriodicCacheClearingHandler( NULL )
       
    36     {
       
    37     DEBUG( "CWlmPlatform::CWlmPlatform()" );
       
    38     }
       
    39 
       
    40 // Symbian 2nd phase constructor can leave.
       
    41 void CWlmPlatform::ConstructL()
       
    42     {
       
    43     DEBUG( "CWlmPlatform::ConstructL()" );
       
    44 
       
    45     iPlatformData = CWlmPlatformData::NewL( *this );
       
    46     iSystemTimeHandler = CWlanSystemTimeHandler::NewL( *this );
       
    47     iPeriodicCacheClearingHandler = CWlanPeriodicCacheClearingHandler::NewL ( *this );
       
    48     }
       
    49 
       
    50 // Static constructor.
       
    51 EXPORT_C  CWlmPlatform* CWlmPlatform::NewL( MWlmPlatformCallback& aCallback )
       
    52     {
       
    53     DEBUG( "CWlmPlatform::NewL()" );
       
    54 
       
    55     CWlmPlatform* self = new(ELeave) CWlmPlatform( aCallback );
       
    56     CleanupStack::PushL( self );
       
    57     self->ConstructL();
       
    58     CleanupStack::Pop( self );
       
    59     return self;
       
    60     }
       
    61     
       
    62 // Destructor
       
    63 EXPORT_C CWlmPlatform::~CWlmPlatform()
       
    64     {
       
    65     DEBUG( "CWlmPlatform::~CWlmPlatform()" );
       
    66 
       
    67     delete iPlatformData;
       
    68     delete iSystemTimeHandler;
       
    69     delete iPeriodicCacheClearingHandler;
       
    70     }
       
    71 
       
    72 // ---------------------------------------------------------
       
    73 // CWlmPlatform::Initialize
       
    74 // ---------------------------------------------------------
       
    75 //
       
    76 EXPORT_C void CWlmPlatform::Initialize()
       
    77     {
       
    78     DEBUG( "CWlmPlatform::Initialize()" );
       
    79 
       
    80     iPlatformData->UpdateSystemStatuses();
       
    81     }
       
    82 
       
    83 // ---------------------------------------------------------
       
    84 // CWlmPlatform::GetScanType
       
    85 // ---------------------------------------------------------
       
    86 //
       
    87 EXPORT_C TWLMScanType CWlmPlatform::GetScanType()
       
    88     {
       
    89     DEBUG( "CWlmPlatform::GetScanType()" );
       
    90 
       
    91     //
       
    92     // No scans if WLAN has been disabled or system is just
       
    93     // starting up.
       
    94     //
       
    95     if( iCurrentSystemMode == EWlanSystemDisabled ||
       
    96         iCurrentSystemMode == EWlanSystemStartupInProgress )
       
    97         {
       
    98         return EWLMScanNotAllowed;
       
    99         }
       
   100 
       
   101     //
       
   102     // Scans are passive in PDA/Flight profile until a connection
       
   103     // has been made.
       
   104     //
       
   105     if( iCallback.GetCurrentState() == EWlanStateNotConnected &&
       
   106         iCurrentSystemMode == EWlanSystemFlight )
       
   107         {
       
   108         return EWLMScanForcedPassive;
       
   109         }
       
   110 
       
   111     return EWLMScanAsRequested;
       
   112     }
       
   113 
       
   114 // ---------------------------------------------------------
       
   115 // CWlmPlatform::IsWlanDisabled
       
   116 // ---------------------------------------------------------
       
   117 //   
       
   118 EXPORT_C TBool CWlmPlatform::IsWlanDisabled()
       
   119     {
       
   120     if( iCurrentSystemMode == EWlanSystemDisabled )
       
   121         {
       
   122         return ETrue;   
       
   123         }
       
   124     return EFalse;
       
   125     }
       
   126 
       
   127 // ---------------------------------------------------------
       
   128 // CWlmPlatform::GetCurrentSystemMode
       
   129 // ---------------------------------------------------------
       
   130 //
       
   131 EXPORT_C TWlanSystemMode CWlmPlatform::GetCurrentSystemMode()
       
   132     {
       
   133     DEBUG( "CWlmPlatform::GetCurrentSystemMode()" );
       
   134 
       
   135     return iCurrentSystemMode;
       
   136     }
       
   137 
       
   138 // ---------------------------------------------------------
       
   139 // CWlmPlatform::SetIconState
       
   140 // ---------------------------------------------------------
       
   141 //
       
   142 EXPORT_C TInt CWlmPlatform::SetIconState( TWlmIconStatus aStatus )
       
   143     {
       
   144     if ( aStatus != EWlmIconStatusConnected &&
       
   145          aStatus != EWlmIconStatusConnectedSecure )
       
   146         {
       
   147         iWlanConnectedBeforeEmergencyCall = EFalse;
       
   148         }
       
   149     
       
   150     return iPlatformData->SetIconState( aStatus );    
       
   151     }
       
   152 
       
   153 // ---------------------------------------------------------
       
   154 // CWlmPlatform::GetCurrentOperatorMccL
       
   155 // ---------------------------------------------------------
       
   156 //
       
   157 EXPORT_C void CWlmPlatform::GetCurrentOperatorMccL( TUint& aCountryCode )
       
   158     {
       
   159     iPlatformData->GetCurrentOperatorMccL( aCountryCode );
       
   160     }
       
   161 
       
   162 // ---------------------------------------------------------
       
   163 // CWlmPlatform::PublishMacAddress
       
   164 // ---------------------------------------------------------
       
   165 //
       
   166 EXPORT_C TInt CWlmPlatform::PublishMacAddress( TMacAddress& aMacAddr )
       
   167     {
       
   168     return iPlatformData->PublishMacAddress( aMacAddr );
       
   169     }
       
   170 
       
   171 // ---------------------------------------------------------
       
   172 // CWlmPlatform::InitializeSystemTimeHandler
       
   173 // ---------------------------------------------------------
       
   174 //
       
   175 EXPORT_C void CWlmPlatform::InitializeSystemTimeHandler()
       
   176     {
       
   177     DEBUG( "CWlmPlatform::InitializeSystemTimeHandler()" );
       
   178 
       
   179     iSystemTimeHandler->StopTimer();
       
   180     iPeriodicCacheClearingHandler->StopTimer();
       
   181     
       
   182     iSystemTimeHandler->StartTimer();
       
   183     iPeriodicCacheClearingHandler->StartTimer();
       
   184     }
       
   185 
       
   186 // ---------------------------------------------------------
       
   187 // CWlmPlatform::SystemModeChanged
       
   188 // ---------------------------------------------------------
       
   189 //
       
   190 void CWlmPlatform::SystemModeChanged(
       
   191     TWlanSystemMode aOldMode,
       
   192     TWlanSystemMode aNewMode )
       
   193     {
       
   194     DEBUG( "CWlmPlatform::SystemModeChanged()" );
       
   195 
       
   196     if ( aOldMode != aNewMode )
       
   197         {
       
   198         DEBUG2( "System Mode changed from %u to %u", aOldMode, aNewMode );
       
   199         iCurrentSystemMode = aNewMode;
       
   200 
       
   201         /**
       
   202         * The "order" of System Modes is
       
   203         * 1) GSM
       
   204         * 2) Flight
       
   205         * 3) Disabled
       
   206         * 4) Starting
       
   207         */
       
   208         if ( aOldMode < aNewMode )
       
   209             {
       
   210             iCallback.ReleaseRequest();
       
   211             }
       
   212         else if ( aOldMode == EWlanSystemDisabled )
       
   213             {
       
   214             iCallback.EnableWlan();
       
   215             }
       
   216         else if ( aOldMode == EWlanSystemStartupInProgress )
       
   217             {
       
   218             iCallback.StartupComplete();
       
   219             }
       
   220         }
       
   221     }
       
   222 
       
   223 // ---------------------------------------------------------
       
   224 // CWlmPlatform::EmergencyCallEstablished
       
   225 // ---------------------------------------------------------
       
   226 //
       
   227 void CWlmPlatform::EmergencyCallEstablished()
       
   228     {
       
   229     DEBUG( "CWlmPlatform::EmergencyCallEstablished()" );
       
   230 
       
   231     iCurrentSystemMode = EWlanSystemNormal;
       
   232     iCallback.EnableWlan();
       
   233         
       
   234     if ( iCallback.GetCurrentState() == EWlanStateInfrastructure ||
       
   235          iCallback.GetCurrentState() == EWlanStateIBSS || 
       
   236          iCallback.GetCurrentState() == EWlanStateSecureInfra )
       
   237         {
       
   238         iWlanConnectedBeforeEmergencyCall = ETrue;
       
   239         }
       
   240     }
       
   241 
       
   242 // ---------------------------------------------------------
       
   243 // CWlmPlatform::EmergencyCallCompleted
       
   244 // ---------------------------------------------------------
       
   245 //
       
   246 void CWlmPlatform::EmergencyCallCompleted( TWlanSystemMode aNewMode )
       
   247     {
       
   248     DEBUG( "CWlmPlatform::EmergencyCallCompleted()" );
       
   249 
       
   250         TBool startupComplete;
       
   251         iCurrentSystemMode = aNewMode;
       
   252         if ( aNewMode == EWlanSystemNormal )
       
   253             {
       
   254             startupComplete = ETrue;
       
   255             iCallback.EmergencyCallComplete( startupComplete );
       
   256             } 
       
   257         else if ( aNewMode == EWlanSystemStartupInProgress)
       
   258             {
       
   259             /**
       
   260             * Return back to the Startup in Progress mode
       
   261             */
       
   262             startupComplete = EFalse;
       
   263             iCallback.ReleaseRequest();
       
   264             iCallback.EmergencyCallComplete( startupComplete );
       
   265             }
       
   266         else if ( aNewMode == EWlanSystemFlight )
       
   267       	    {
       
   268        	    /* WLAN connection must be released if WLAN connection 
       
   269        	     * was established only for the emergency call 
       
   270        	     * (connection did not exist before the emergency call) 
       
   271        	     */
       
   272        	    if ( !iWlanConnectedBeforeEmergencyCall )
       
   273        	        {
       
   274        	        iCallback.ReleaseRequest();
       
   275        	        }
       
   276             startupComplete = ETrue;
       
   277             iCallback.EmergencyCallComplete( startupComplete );
       
   278        	    }
       
   279         else
       
   280             {
       
   281             iCallback.ReleaseRequest();
       
   282             }
       
   283     iWlanConnectedBeforeEmergencyCall = EFalse;
       
   284     }
       
   285 
       
   286 
       
   287 // ---------------------------------------------------------
       
   288 // CWlmPlatform::BtConnectionEstablished
       
   289 // ---------------------------------------------------------
       
   290 //
       
   291 void CWlmPlatform::BtConnectionEstablished()
       
   292     {
       
   293     iCallback.BtConnectionEstablished();  
       
   294     }
       
   295 
       
   296 // ---------------------------------------------------------
       
   297 // CWlmPlatform::BtConnectionDisabled
       
   298 // ---------------------------------------------------------
       
   299 //
       
   300 void CWlmPlatform::BtConnectionDisabled()
       
   301     {
       
   302     iCallback.BtConnectionDisabled();
       
   303     }
       
   304 
       
   305 // ---------------------------------------------------------
       
   306 // CWlmPlatform::OnSystemTimeChange
       
   307 // ---------------------------------------------------------
       
   308 //
       
   309 void CWlmPlatform::OnSystemTimeChange()
       
   310     {
       
   311     DEBUG( "CWlmPlatform::OnSystemTimeChange()" );
       
   312     
       
   313     iCallback.SystemTimeChanged();
       
   314     }
       
   315 
       
   316 // ---------------------------------------------------------
       
   317 // CWlmPlatform::OnCacheClearTimerExpiration
       
   318 // ---------------------------------------------------------
       
   319 //
       
   320 void CWlmPlatform::OnCacheClearTimerExpiration()
       
   321     {
       
   322     DEBUG( "CWlmPlatform::OnCacheClearTimerExpiration()" );
       
   323     
       
   324     iCallback.ClearRegionCache();
       
   325     }