alwayson_net_plugin/pdpcontextmanager2/src/caoserver.cpp
changeset 0 5a93021fdf25
child 3 f7816ffc66ed
equal deleted inserted replaced
-1:000000000000 0:5a93021fdf25
       
     1 /*
       
     2 * Copyright (c) 2004,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 "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:  Implements the CAOServer class
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 // INCLUDE FILES
       
    20 #include <mmtsy_names.h>
       
    21 
       
    22 #include "caoserver.h"
       
    23 #include "caoconnectionmanager.h"
       
    24 #include "caotimer.h"
       
    25 #include "caoraumanager.h"
       
    26 #include "caosettings.h"
       
    27 #include "caogpds.h"
       
    28 #include "taostateinit.h"
       
    29 #include "taostatestarting.h"
       
    30 #include "taostatedisabled.h"
       
    31 #include "taostateconnecting.h"
       
    32 #include "taostateconnected.h"
       
    33 #include "taostatedisconnected.h"
       
    34 #include "taostatewaiting.h"
       
    35 #include "taostateunconnected.h"
       
    36 #include "taostateresetfactorysettings.h"
       
    37 #include "taostateexternalconnection.h"
       
    38 #include "logger.h"
       
    39 #include "pdpcontextmanagerpskeys.h"
       
    40 
       
    41 #ifdef LOGGING_ENABLED
       
    42 #ifdef LOGGING_MODE_FILE
       
    43 #include <f32file.h>
       
    44 #endif // LOGGING_MODE_FILE
       
    45 #endif // LOGGING_ENABLED
       
    46 
       
    47 // UNNAMED NAMESPACE FOR LOCAL DEFINITIONS
       
    48 namespace
       
    49     {
       
    50     // CONSTANTS
       
    51 #ifdef LOGGING_ENABLED
       
    52 
       
    53     _LIT( KStateNone,           "None" );
       
    54     _LIT( KStateInit,           "Init" );
       
    55     _LIT( KStateStarting,       "Starting" );
       
    56     _LIT( KStateDisabled,       "Disabled" );
       
    57     _LIT( KStateConnecting,     "Connecting" );
       
    58     _LIT( KStateConnected,      "Connected" );
       
    59     _LIT( KStateDisconnected,   "Disconnected" );
       
    60     _LIT( KStateWaiting,        "Waiting" );
       
    61     _LIT( KStateUnconnected,    "Unconnected" );
       
    62     _LIT( KStateRfs,            "ResetFactorySettings" );
       
    63     _LIT( KStateExtConn,        "ExternalConnection" );
       
    64     _LIT( KStateUnexpected,     "Unexpected" );
       
    65 
       
    66 #endif // LOGGING_ENABLED
       
    67 
       
    68     const TInt KReactivationDelay = 25000000; // 25 seconds
       
    69     const TInt KSetupDelay = 2000000; // 2 seconds
       
    70     _LIT_SECURITY_POLICY_PASS( KPDPAlwaysPass );
       
    71 
       
    72 #ifdef _DEBUG
       
    73     _LIT( KPanicCat, "AOServ" );
       
    74     
       
    75     // DATA TYPES
       
    76     enum TPanicReason
       
    77         {
       
    78         ENoReason,
       
    79         EPDPAlreadySubscribed,
       
    80         ESetupAlreadyInitiated
       
    81         };
       
    82 
       
    83     // LOCAL FUNCTIONS
       
    84     LOCAL_C void Panic( TPanicReason aReason )
       
    85         {
       
    86         User::Panic( KPanicCat, aReason );
       
    87         }
       
    88 #endif // _DEBUG
       
    89     
       
    90     
       
    91 #ifdef LOGGING_ENABLED
       
    92     LOCAL_C const TDesC& StateToDesC( TAOState::TAOStateName aState )
       
    93         {
       
    94         switch ( aState )
       
    95             {
       
    96             case TAOState::EStateInit:
       
    97                 {
       
    98                 return KStateInit;
       
    99                 }
       
   100             case TAOState::EStateStarting:
       
   101                 {
       
   102                 return KStateStarting;
       
   103                 }
       
   104             case TAOState::EStateDisabled:
       
   105                 {
       
   106                 return KStateDisabled;
       
   107                 }
       
   108             case TAOState::EStateConnecting:
       
   109                 {
       
   110                 return KStateConnecting;
       
   111                 }
       
   112             case TAOState::EStateConnected:
       
   113                 {
       
   114                 return KStateConnected;
       
   115                 }
       
   116             case TAOState::EStateDisconnected:
       
   117                 {
       
   118                 return KStateDisconnected;
       
   119                 }
       
   120             case TAOState::EStateWaiting:
       
   121                 {
       
   122                 return KStateWaiting;
       
   123                 }
       
   124             case TAOState::EStateUnconnected:
       
   125                 {
       
   126                 return KStateUnconnected;
       
   127                 }
       
   128             case TAOState::EStateResetFactorySettings:
       
   129                 {
       
   130                 return KStateRfs;
       
   131                 }
       
   132             case TAOState::EStateExternalConnection:
       
   133                 {
       
   134                 return KStateExtConn;
       
   135                 }
       
   136             default:
       
   137                 {
       
   138                 return KStateUnexpected;
       
   139                 }
       
   140             }
       
   141         }
       
   142 #endif // LOGGING_ENABLED
       
   143     }
       
   144 
       
   145 // METHODS
       
   146 
       
   147 // ---------------------------------------------------------------------------
       
   148 // CAOServer::NewL
       
   149 // ---------------------------------------------------------------------------
       
   150 //
       
   151 CAOServer* CAOServer::NewL()
       
   152     {
       
   153     LOG_1( _L("CAOServer::NewL") );
       
   154     
       
   155     CAOServer* self = new( ELeave ) CAOServer;
       
   156     
       
   157     CleanupStack::PushL( self );
       
   158     self->ConstructL();
       
   159     CleanupStack::Pop( self );
       
   160     
       
   161     return self;
       
   162     }
       
   163 
       
   164 // ---------------------------------------------------------------------------
       
   165 // CAOServer::~CAOServer
       
   166 // ---------------------------------------------------------------------------
       
   167 //
       
   168 CAOServer::~CAOServer()
       
   169     {
       
   170     LOG_1( _L("CAOServer::~CAOServer") );
       
   171 
       
   172     delete iAsyncSetup;
       
   173     ReleasePDPProperty();    
       
   174     delete iAsyncReactivation;
       
   175     
       
   176     if ( iPointerStatePool )
       
   177         {
       
   178         iPointerStatePool->ResetAndDestroy();
       
   179         delete iPointerStatePool;    
       
   180         }
       
   181     
       
   182     delete iGpds;
       
   183     delete iRAUManager;
       
   184     delete iTimer;
       
   185     delete iConnectionManager;
       
   186     delete iSettings;
       
   187     
       
   188     iCustomAPI.Close();
       
   189     iMobilePhone.Close();
       
   190     iTelServer.UnloadPhoneModule( KMmTsyModuleName() );
       
   191     iTelServer.Close();
       
   192     }
       
   193 
       
   194 // ---------------------------------------------------------------------------
       
   195 // CAOServer::CAOServer
       
   196 // ---------------------------------------------------------------------------
       
   197 //
       
   198 CAOServer::CAOServer()
       
   199     {
       
   200     LOG_1( _L("CAOServer::CAOServer") );
       
   201     }
       
   202 
       
   203 // ---------------------------------------------------------------------------
       
   204 // CAOServer::ConstructL
       
   205 // ---------------------------------------------------------------------------
       
   206 //
       
   207 void CAOServer::ConstructL()
       
   208     {
       
   209     LOG_1( _L("CAOServer::ConstructL") );
       
   210     
       
   211     // Configure Custom API
       
   212     ConfigureCustomAPIL();
       
   213     
       
   214     // Create services
       
   215     iSettings = CAOSettings::NewL( *this );
       
   216     iConnectionManager = CAOConnectionManager::NewL( *this, *iSettings );
       
   217     iTimer = CAOTimer::NewL( *this, *iSettings );
       
   218 
       
   219 #ifdef __ALWAYS_ON_CUSTOM_API
       
   220 
       
   221     iRAUManager = CAORAUManager::NewL( *this, iCustomAPI );
       
   222     
       
   223 #else
       
   224 
       
   225     iRAUManager = CAORAUManager::NewL( *this );
       
   226 
       
   227 #endif // __ALWAYS_ON_CUSTOM_API
       
   228     
       
   229     iGpds = CAOGpds::NewL( iCustomAPI );
       
   230     
       
   231     InitStatePoolL();
       
   232         
       
   233     // Set current state to 'init'
       
   234     iCurrentState = ChangeState( TAOState::EStateInit );
       
   235     
       
   236     // Init timers
       
   237     iAsyncReactivation = CPeriodic::NewL( CActive::EPriorityStandard );
       
   238     iAsyncSetup = CPeriodic::NewL( CActive::EPriorityStandard );
       
   239     
       
   240     // Create PDP property observer
       
   241     CreatePDPPropertyAndSubscribeL();
       
   242     
       
   243     // Setup Always-On server
       
   244     Setup();
       
   245     }
       
   246 
       
   247 // ---------------------------------------------------------------------------
       
   248 // CAOServer::Setup
       
   249 // ---------------------------------------------------------------------------
       
   250 //
       
   251 void CAOServer::Setup()
       
   252     {
       
   253     LOG_1( _L("CAOServer::SetupL") );
       
   254     
       
   255     __ASSERT_DEBUG( !iAsyncSetup->IsActive(), 
       
   256                     Panic( ESetupAlreadyInitiated ) );
       
   257     
       
   258     TCallBack cb( SetupCallBack, this );
       
   259     iAsyncSetup->Start( KSetupDelay, KSetupDelay, cb );
       
   260     }
       
   261 
       
   262 // ---------------------------------------------------------------------------
       
   263 // CAOServer::ReactivationCallBack
       
   264 // ---------------------------------------------------------------------------
       
   265 //
       
   266 TInt CAOServer::ReactivationCallBack( TAny* aSelf )
       
   267     {
       
   268     LOG_1( _L("CAOServer::ReactivationCallBack") );
       
   269     
       
   270     TRAP_IGNORE( static_cast<CAOServer*>( aSelf )->HandleReactivationL() );
       
   271     return KErrNone;
       
   272     }
       
   273 
       
   274 // ---------------------------------------------------------------------------
       
   275 // CAOServer::HandleReactivationL
       
   276 // ---------------------------------------------------------------------------
       
   277 //
       
   278 void CAOServer::HandleReactivationL()
       
   279     {
       
   280     LOG_1( _L("CAOServer::HandleReactivationL") );
       
   281     
       
   282     iAsyncReactivation->Cancel();
       
   283     
       
   284     TAOState* newState =
       
   285         iCurrentState->HandleSwitchFromDisconnectedL( iFailure );
       
   286     if ( newState )
       
   287         {
       
   288         iCurrentState = newState;
       
   289         }
       
   290     }
       
   291 
       
   292 // ---------------------------------------------------------------------------
       
   293 // CAOServer::DoReactivation
       
   294 // ---------------------------------------------------------------------------
       
   295 //
       
   296 void CAOServer::DoReactivation( MAOConnectionManager::TFailureReason aReason )
       
   297     {
       
   298     LOG_1( _L("CAOServer::DoReactivation") );
       
   299     
       
   300     // If we are not already re-activating
       
   301     if ( !iAsyncReactivation->IsActive() )
       
   302         {
       
   303         iFailure = aReason;
       
   304         TCallBack cb( ReactivationCallBack, this );
       
   305         iAsyncReactivation->Start(
       
   306             KReactivationDelay, KReactivationDelay, cb );
       
   307         }
       
   308     }
       
   309 
       
   310 // ---------------------------------------------------------------------------
       
   311 // CAOServer::IssuePDPPropertySubscription
       
   312 // ---------------------------------------------------------------------------
       
   313 //
       
   314 void CAOServer::IssuePDPPropertySubscription()
       
   315     {
       
   316     LOG_1( _L("CAOServer::IssuePDPPropertySubscription") );
       
   317     
       
   318     __ASSERT_DEBUG( !iPDPPropertySubscriber->IsActive(),
       
   319         Panic( EPDPAlreadySubscribed ) );
       
   320     
       
   321     iPDPPropertySubscriber->IssueRequest();
       
   322     }
       
   323 // ---------------------------------------------------------------------------
       
   324 // CAOServer::PDPPropertySubscriptionIssueRequest
       
   325 // ---------------------------------------------------------------------------
       
   326 //
       
   327 void CAOServer::PDPPropertySubscriptionIssueRequest( TRequestStatus& aStatus )
       
   328     {
       
   329     LOG_1( _L("CAOServer::PDPPropertySubscriptionIssueRequest") );
       
   330     
       
   331     iPDPProperty.Subscribe( aStatus );
       
   332     }
       
   333 
       
   334 // ---------------------------------------------------------------------------
       
   335 // CAOServer::PDPPropertySubscriptionRunL
       
   336 // ---------------------------------------------------------------------------
       
   337 //
       
   338 void CAOServer::PDPPropertySubscriptionRunL( TInt aStatus )
       
   339     {
       
   340     LOG_2( _L("CAOServer::PDPPropertySubscriptionRunL: aStatus: %d"),
       
   341         aStatus );
       
   342     
       
   343     if ( aStatus == KErrNone )
       
   344         {
       
   345         TInt val = 0;
       
   346         TInt err = iPDPProperty.Get(
       
   347             KPDPContextManager2,
       
   348             KPDPContextManagerFactorySettingsReset,
       
   349             val );
       
   350             
       
   351         TAOState* newState = NULL;
       
   352         if ( err == KErrNone )
       
   353             {
       
   354             if ( val == EPDPContextManagerFactorySettingsResetStart )
       
   355                 {
       
   356                 newState =
       
   357                     iCurrentState->HandleResetFactorySettingsL( ETrue );
       
   358                 }
       
   359             else if ( val == EPDPContextManagerFactorySettingsResetStop )
       
   360                 {
       
   361                 newState =
       
   362                     iCurrentState->HandleResetFactorySettingsL( EFalse );
       
   363                 }
       
   364             }
       
   365         if ( newState )
       
   366             {
       
   367             iCurrentState = newState;
       
   368             }
       
   369         }
       
   370     IssuePDPPropertySubscription();
       
   371     }
       
   372 
       
   373 // ---------------------------------------------------------------------------
       
   374 // CAOServer::PDPPropertySubscriptionDoCancel
       
   375 // ---------------------------------------------------------------------------
       
   376 //
       
   377 void CAOServer::PDPPropertySubscriptionDoCancel()
       
   378     {
       
   379     LOG_1( _L("CAOServer::PDPPropertySubscriptionDoCancel") );
       
   380     
       
   381     iPDPProperty.Cancel();
       
   382     }
       
   383 
       
   384 // ---------------------------------------------------------------------------
       
   385 // CAOServer::ReleasePDPProperty
       
   386 // ---------------------------------------------------------------------------
       
   387 //
       
   388 void CAOServer::ReleasePDPProperty()
       
   389     {
       
   390     LOG_1( _L("CAOServer::ReleasePDPProperty") );
       
   391     
       
   392     delete iPDPPropertySubscriber;
       
   393     iPDPProperty.Delete(
       
   394         KPDPContextManager2,
       
   395         KPDPContextManagerFactorySettingsReset );
       
   396     iPDPProperty.Close();
       
   397     }
       
   398 
       
   399 // ---------------------------------------------------------------------------
       
   400 // CAOServer::CreatePDPPropertyAndSubscribeL
       
   401 // ---------------------------------------------------------------------------
       
   402 //
       
   403 void CAOServer::CreatePDPPropertyAndSubscribeL()
       
   404     {
       
   405     LOG_1( _L("CAOServer::CreatePDPPropertyAndSubscribeL") );
       
   406 
       
   407     // Define PDP property
       
   408     TInt err = iPDPProperty.Define(
       
   409         KPDPContextManager2,
       
   410         KPDPContextManagerFactorySettingsReset,
       
   411         RProperty::EInt,
       
   412         KPDPAlwaysPass,
       
   413         KPDPAlwaysPass,
       
   414         0 );
       
   415     LOG_2( _L("> Property define: %d"), err );
       
   416     if ( err != KErrAlreadyExists )
       
   417         {
       
   418         User::LeaveIfError( err );
       
   419         }
       
   420     
       
   421     // Attach to property
       
   422     err = iPDPProperty.Attach(
       
   423         KPDPContextManager2,
       
   424         KPDPContextManagerFactorySettingsReset );
       
   425     LOG_2( _L("> Property attach: %d"), err );
       
   426     User::LeaveIfError( err );
       
   427         
       
   428     // Create property subscriber
       
   429     iPDPPropertySubscriber = CAOAsyncWrapper<CAOServer>::NewL(
       
   430         this,
       
   431         &PDPPropertySubscriptionIssueRequest,
       
   432         &PDPPropertySubscriptionRunL,
       
   433         &PDPPropertySubscriptionDoCancel,
       
   434         NULL );
       
   435         
       
   436     // Subscribe
       
   437     IssuePDPPropertySubscription();
       
   438     }
       
   439 
       
   440 // ---------------------------------------------------------------------------
       
   441 // CAOServer::SetupCallBack
       
   442 // ---------------------------------------------------------------------------
       
   443 //
       
   444 TInt CAOServer::SetupCallBack( TAny* aSelf )
       
   445     {
       
   446     LOG_1( _L("CAOServer::SetupCallBack") );
       
   447     
       
   448     CAOServer* server = static_cast<CAOServer*>( aSelf );
       
   449     TRAPD( err, server->HandleSetup() );
       
   450     return err;
       
   451     }
       
   452 
       
   453 // ---------------------------------------------------------------------------
       
   454 // CAOServer::HandleSetupL
       
   455 // ---------------------------------------------------------------------------
       
   456 //
       
   457 void CAOServer::HandleSetup()
       
   458     {
       
   459     LOG_1( _L("CAOServer::HandleSetup") );
       
   460     
       
   461     iAsyncSetup->Cancel();
       
   462     
       
   463     // Fetch settings and network registration status
       
   464     iSettings->FetchSettings();
       
   465     iConnectionManager->FetchNetworkRegistrationStatus();
       
   466     }
       
   467 
       
   468 // ---------------------------------------------------------------------------
       
   469 // CAOServer::ConfigureCustomAPIL
       
   470 // ---------------------------------------------------------------------------
       
   471 //
       
   472 void CAOServer::ConfigureCustomAPIL()
       
   473     {
       
   474     LOG_1( _L("CAOServer::ConfigureCustomAPIL") );
       
   475     
       
   476     // Connect tel server
       
   477     // If not possible to load module and if it not already loaded
       
   478     // no way to recover.
       
   479     User::LeaveIfError( iTelServer.Connect() );
       
   480     TInt err = iTelServer.LoadPhoneModule( KMmTsyModuleName() );
       
   481     if ( err != KErrNone && err != KErrAlreadyExists )
       
   482         {
       
   483         User::Leave( KErrGeneral );
       
   484         }
       
   485 
       
   486     // Open mobile phone and custom API
       
   487     User::LeaveIfError( iMobilePhone.Open( iTelServer, KMmTsyPhoneName() ) );
       
   488     User::LeaveIfError( iCustomAPI.Open( iMobilePhone ) );
       
   489     }
       
   490 
       
   491 // ---------------------------------------------------------------------------
       
   492 // CAOServer::ConnectionManager
       
   493 // ---------------------------------------------------------------------------
       
   494 //
       
   495 MAOConnectionManager& CAOServer::ConnectionManager() const
       
   496     {
       
   497     LOG_1( _L("CAOServer::ConnectionManager") );
       
   498     
       
   499     return *iConnectionManager;
       
   500     }
       
   501 
       
   502 // ---------------------------------------------------------------------------
       
   503 // CAOServer::Timer
       
   504 // ---------------------------------------------------------------------------
       
   505 //
       
   506 MAOTimer& CAOServer::Timer() const
       
   507     {
       
   508     LOG_1( _L("CAOServer::Timer") );
       
   509     
       
   510     return *iTimer;
       
   511     }
       
   512 
       
   513 // ---------------------------------------------------------------------------
       
   514 // CAOServer::RAUManager
       
   515 // ---------------------------------------------------------------------------
       
   516 //
       
   517 MAORAUManager& CAOServer::RAUManager() const
       
   518     {
       
   519     LOG_1( _L("CAOServer::RAUManager") );
       
   520     
       
   521     return *iRAUManager;
       
   522     }
       
   523 
       
   524 // ---------------------------------------------------------------------------
       
   525 // CAOServer::Settings
       
   526 // ---------------------------------------------------------------------------
       
   527 //
       
   528 MAOSettings& CAOServer::Settings() const
       
   529     {
       
   530     LOG_1( _L("CAOServer::Settings") );
       
   531     
       
   532     return *iSettings;
       
   533     }
       
   534 
       
   535 // ---------------------------------------------------------------------------
       
   536 // CAOServer::Gpds
       
   537 // ---------------------------------------------------------------------------
       
   538 //
       
   539 MAOGpds& CAOServer::Gpds() const
       
   540     {
       
   541     LOG_1( _L("CAOServer::Gpds") );
       
   542     
       
   543     return *iGpds;
       
   544     }
       
   545 
       
   546 // ---------------------------------------------------------------------------
       
   547 // CAOServer::ChangeState
       
   548 // ---------------------------------------------------------------------------
       
   549 //
       
   550 TAOState* CAOServer::ChangeState( TAOState::TAOStateName aState )
       
   551     {
       
   552     if ( !iCurrentState )
       
   553         {
       
   554         LOG_3( _L(
       
   555             ">>>> CAOServer::ChangeState: Old state %S > New state %S <<<<" ),
       
   556             &KStateNone, &StateToDesC( aState ) );
       
   557         }
       
   558     else
       
   559         {
       
   560         LOG_3( _L(
       
   561             ">>>> CAOServer::ChangeState: Old state %S > New state %S <<<<" ),
       
   562             &StateToDesC( CurrentState()->StateName() ),
       
   563             &StateToDesC( aState ) );
       
   564         }
       
   565     
       
   566     return (*iPointerStatePool)[aState];
       
   567     }
       
   568 
       
   569 // ---------------------------------------------------------------------------
       
   570 // CAOServer::CurrentState
       
   571 // ---------------------------------------------------------------------------
       
   572 //
       
   573 TAOState* CAOServer::CurrentState() const
       
   574     {
       
   575     LOG_1( _L("CAOServer::CurrentState") );
       
   576     
       
   577     if( !iCurrentState )
       
   578         {
       
   579         LOG_1( _L("CAOServer::CurrentState is NULL !") );
       
   580         }
       
   581     
       
   582     return iCurrentState;
       
   583     }
       
   584 
       
   585 // ---------------------------------------------------------------------------
       
   586 // CAOServer::HandlePDPContextActivatedL
       
   587 // ---------------------------------------------------------------------------
       
   588 //
       
   589 void CAOServer::HandlePDPContextActivatedL()
       
   590     {
       
   591     LOG_1( _L("CAOServer::HandlePDPContextActivatedL") );
       
   592     LOG_2( _L("> Current state: %S"),
       
   593         &StateToDesC( CurrentState()->StateName() ) );
       
   594     
       
   595     TAOState* newState = iCurrentState->HandlePDPContextActivatedL();
       
   596     if ( newState )
       
   597         {
       
   598         iCurrentState = newState;
       
   599         }
       
   600     }
       
   601 
       
   602 // ---------------------------------------------------------------------------
       
   603 // CAOServer::HandlePDPContextActivationFailedL
       
   604 // ---------------------------------------------------------------------------
       
   605 //
       
   606 void CAOServer::HandlePDPContextActivationFailedL(
       
   607     MAOConnectionManager::TFailureReason aReason )
       
   608     {
       
   609     LOG_1( _L("CAOServer::HandlePDPContextActivationFailedL") );
       
   610     LOG_2( _L("> Current state: %S"),
       
   611         &StateToDesC( CurrentState()->StateName() ) );
       
   612         
       
   613     iActivationFailure = ETrue;
       
   614     
       
   615     TAOState* newState = iCurrentState->HandlePDPContextActivationFailedL();
       
   616     if ( newState )
       
   617         {
       
   618         iCurrentState = newState;
       
   619         
       
   620         // If new state is disconnected we need synchronously change to new
       
   621         // state depending from the failure reason
       
   622         if ( CurrentState()->StateName() == TAOState::EStateDisconnected )
       
   623             {
       
   624             newState = iCurrentState->HandleSwitchFromDisconnectedL( 
       
   625                                                                 aReason );
       
   626             }
       
   627             
       
   628         // Change state if new state received
       
   629         if ( newState )
       
   630             {
       
   631             iCurrentState = newState;
       
   632             }
       
   633         }
       
   634     }
       
   635 
       
   636 // ---------------------------------------------------------------------------
       
   637 // CAOServer::HandlePDPContextDisconnectedL
       
   638 // ---------------------------------------------------------------------------
       
   639 //
       
   640 void CAOServer::HandlePDPContextDisconnectedL(
       
   641     MAOConnectionManager::TFailureReason aReason )
       
   642     {
       
   643     LOG_1( _L("CAOServer::HandlePDPContextDisconnectedL") );
       
   644     LOG_2( _L("> Current state: %S"),
       
   645         &StateToDesC( CurrentState()->StateName() ) );
       
   646     
       
   647     TAOState* newState =
       
   648         iCurrentState->HandlePDPContextDisconnectedL( aReason );
       
   649     if ( newState )
       
   650         {
       
   651         iCurrentState = newState;
       
   652         
       
   653         // If new state is disconnected we need synchronously change to new
       
   654         // state depending from the failure reason
       
   655         if ( CurrentState()->StateName() == TAOState::EStateDisconnected )
       
   656             {
       
   657             // Do asnyc re-activation to ensure old connection
       
   658             // has really been closed
       
   659             DoReactivation( aReason );
       
   660             }
       
   661         }
       
   662     }
       
   663 
       
   664 // ---------------------------------------------------------------------------
       
   665 // CAOServer::HandlePDPContextTemporarilyBlockedL
       
   666 // ---------------------------------------------------------------------------
       
   667 //
       
   668 void CAOServer::HandlePDPContextTemporarilyBlockedL()
       
   669     {
       
   670     LOG_1( _L("CAOServer::HandlePDPContextTemporarilyBlockedL") );
       
   671     LOG_2( _L("> Current state: %S"),
       
   672         &StateToDesC( CurrentState()->StateName() ) );
       
   673     
       
   674     TAOState* newState = iCurrentState->HandlePDPContextTemporarilyBlockedL();
       
   675     if ( newState )
       
   676         {
       
   677         iCurrentState = newState;
       
   678         }
       
   679     }
       
   680 
       
   681 // ---------------------------------------------------------------------------
       
   682 // CAOServer::HandleNWRegistrationStatusChangedL
       
   683 // ---------------------------------------------------------------------------
       
   684 //
       
   685 void CAOServer::HandleNWRegistrationStatusChangedL(
       
   686     CTelephony::TRegistrationStatus /*aNetworkRegistration*/ )
       
   687     {
       
   688     LOG_1( _L("CAOServer::HandleNWRegistrationStatusChangedL") );
       
   689     LOG_2( _L("> Current state: %S"),
       
   690         &StateToDesC( CurrentState()->StateName() ) );
       
   691     
       
   692     // Get current network type from connection manager
       
   693     MAOConnectionManager::TNetworkType nwType =
       
   694         iConnectionManager->NetworkType();
       
   695         
       
   696     TAOState* newState = iCurrentState->HandleNetworkChangedL( nwType );
       
   697     if ( newState )
       
   698         {
       
   699         iCurrentState = newState;
       
   700         
       
   701         // New state is 'starting'
       
   702         if ( CurrentState()->StateName() == TAOState::EStateStarting )
       
   703             {
       
   704             newState = iCurrentState->HandleEnableAlwaysOnL();
       
   705             }
       
   706         // New state is 'disconnected'
       
   707         else if ( CurrentState()->StateName() == TAOState::EStateDisconnected )
       
   708             {
       
   709             newState = iCurrentState->HandleSwitchFromDisconnectedL(
       
   710                 MAOConnectionManager::ETemporary );
       
   711             }
       
   712             
       
   713         // Change state if new state received
       
   714         if ( newState )
       
   715             {
       
   716             iCurrentState = newState;
       
   717             }
       
   718         }
       
   719     }
       
   720 
       
   721 // ---------------------------------------------------------------------------
       
   722 // CAOServer::HandleConnectionDeletedL
       
   723 // ---------------------------------------------------------------------------
       
   724 //
       
   725 void CAOServer::HandleConnectionDeletedL( const TUint /*aConnectionId*/,
       
   726                                           const TBool /*aForward*/ )
       
   727     {
       
   728     LOG_1( _L("CAOServer::HandleConnectionDeletedL") );
       
   729     LOG_2( _L("> Current state: %S"),
       
   730         &StateToDesC( CurrentState()->StateName() ) );
       
   731         
       
   732     // If we currently tried to activate PDP context and it has failed
       
   733     // due temporary or permanent reason do not do anything with
       
   734     // connection deleted notification since notification concerns
       
   735     // the same connection that just failed to activate
       
   736     if ( iActivationFailure )
       
   737         {
       
   738         LOG_1( _L("> Activation failure -> ignore") );
       
   739         iActivationFailure = EFalse;
       
   740         }
       
   741     // If we have not already received disconnect message
       
   742     else if ( !iAsyncReactivation->IsActive() )
       
   743         {
       
   744         LOG_1( _L("> Not an activation failure -> process") );
       
   745         TAOState* newState = iCurrentState->HandleConnectionDeletedL();
       
   746         if ( newState )
       
   747             {
       
   748             iCurrentState = newState;
       
   749             
       
   750             // If new state is disconnected
       
   751             if ( CurrentState()->StateName() == TAOState::EStateDisconnected )
       
   752                 {
       
   753                 // Do async re-activation
       
   754                 DoReactivation( MAOConnectionManager::EDisconnected );
       
   755                 }
       
   756             }
       
   757         }
       
   758     // Just to log
       
   759     else
       
   760         {
       
   761         LOG_1( _L("> Already re-activating -> ignore") );
       
   762         }
       
   763     }
       
   764 
       
   765 // ---------------------------------------------------------------------------
       
   766 // CAOServer::HandleExternalConnectionCreatedL
       
   767 // ---------------------------------------------------------------------------
       
   768 //
       
   769 void CAOServer::HandleExternalConnectionCreatedL()
       
   770     {
       
   771     LOG_1( _L("CAOServer::HandleExternalConnectionCreatedL") );
       
   772     LOG_2( _L("> Current state: %S"),
       
   773         &StateToDesC( CurrentState()->StateName() ) );
       
   774         
       
   775     // End possible re-activation
       
   776     iAsyncReactivation->Cancel();
       
   777     TAOState* newState = iCurrentState->HandleExternalConnectionCreatedL();
       
   778     if( newState )
       
   779         {
       
   780         iCurrentState = newState;
       
   781         }
       
   782     }
       
   783     
       
   784 // ---------------------------------------------------------------------------
       
   785 // CAOServer::HandleInternalConnectionCreatedL
       
   786 // ---------------------------------------------------------------------------
       
   787 //    
       
   788 void CAOServer::HandleInternalConnectionCreatedL( const TUint /*aConnectionId*/,
       
   789                                                   const TUint /*aIapId*/, 
       
   790                                                   const TUint /*aNetId*/ )
       
   791     {
       
   792     }    
       
   793 
       
   794 // ---------------------------------------------------------------------------
       
   795 // CAOServer::HandleError
       
   796 // ---------------------------------------------------------------------------
       
   797 //
       
   798 void CAOServer::HandleError( TInt /*aError*/ )
       
   799     {
       
   800     LOG_1( _L("CAOServer::HandleError") );
       
   801     LOG_2( _L("> Current state: %S"),
       
   802         &StateToDesC( CurrentState()->StateName() ) );
       
   803     
       
   804     TAOState* newState = iCurrentState->HandleGeneralError();
       
   805     if ( newState )
       
   806         {
       
   807         iCurrentState = newState;
       
   808         }
       
   809     }
       
   810 
       
   811 // ---------------------------------------------------------------------------
       
   812 // CAOServer::HandleRetryTimerExpiredL
       
   813 // ---------------------------------------------------------------------------
       
   814 //
       
   815 void CAOServer::HandleRetryTimerExpiredL()
       
   816     {
       
   817     LOG_1( _L("CAOServer::HandleRetryTimerExpiredL") );
       
   818     LOG_2( _L("> Current state: %S"),
       
   819         &StateToDesC( CurrentState()->StateName() ) );
       
   820     
       
   821     TAOState* newState = iCurrentState->HandleRetryTimerTriggeredL();
       
   822     if ( newState )
       
   823         {
       
   824         iCurrentState = newState;
       
   825         }
       
   826     }
       
   827 
       
   828 // ---------------------------------------------------------------------------
       
   829 // CAOServer::HandleConnectionTimerExpiredL
       
   830 // ---------------------------------------------------------------------------
       
   831 //
       
   832 void CAOServer::HandleConnectionTimerExpiredL()
       
   833     {
       
   834     LOG_1( _L("CAOServer::HandleConnectionTimerExpiredL") );
       
   835     LOG_2( _L("> Current state: %S"),
       
   836         &StateToDesC( CurrentState()->StateName() ) );
       
   837     
       
   838     TAOState* newState = iCurrentState->HandleConnectionTimerTriggeredL();
       
   839     if ( newState )
       
   840         {
       
   841         iCurrentState = newState;
       
   842         
       
   843         // Connection timer has trigered maximum amount -> start retry timer
       
   844         if ( iCurrentState->StateName() == TAOState::EStateDisconnected )
       
   845             {
       
   846             newState = iCurrentState->HandleSwitchFromDisconnectedL(
       
   847                 MAOConnectionManager::ETemporary );
       
   848             }
       
   849             
       
   850         // Change state if new state received
       
   851         if ( newState )
       
   852             {
       
   853             iCurrentState = newState;
       
   854             }
       
   855         }
       
   856     }
       
   857 
       
   858 // ---------------------------------------------------------------------------
       
   859 // CAOServer::HandleUnconnectTimerExpiredL
       
   860 // ---------------------------------------------------------------------------
       
   861 //
       
   862 void CAOServer::HandleUnconnectTimerExpiredL()
       
   863     {
       
   864     LOG_1( _L("CAOServer::HandleUnconnectTimerExpiredL") );
       
   865     
       
   866     TAOState* newState = iCurrentState->HandleUnconnectTimerExpiredL();
       
   867     if( newState )
       
   868         {
       
   869         iCurrentState = newState;
       
   870         }
       
   871     }
       
   872 
       
   873 // ---------------------------------------------------------------------------
       
   874 // CAOServer::HandleSettingsChangedL
       
   875 // ---------------------------------------------------------------------------
       
   876 //
       
   877 void CAOServer::HandleSettingsChangedL()
       
   878     {
       
   879     LOG_1( _L("CAOServer::HandleSettingsChangedL") );
       
   880 
       
   881     // Update retry timer value
       
   882     iTimer->HandleSettingsChangedL();
       
   883     
       
   884     // Handle notification
       
   885     TAOState* newState = iCurrentState->HandleSettingsReceivedL();
       
   886 
       
   887     if ( newState )
       
   888         {
       
   889 
       
   890         LOG_2( _L("> newState1: %d"), newState->StateName() );
       
   891     
       
   892         iCurrentState = newState;
       
   893         
       
   894         if ( iCurrentState->StateName() == TAOState::EStateStarting )
       
   895             {
       
   896             // If new state is starting check if Always On should be enabled
       
   897             // in current network
       
   898             newState = iCurrentState->HandleEnableAlwaysOnL();
       
   899             }
       
   900             
       
   901         // Change state if new state received
       
   902         if ( newState )
       
   903             {
       
   904             LOG_2( _L("> newState2: %d"), newState->StateName() );
       
   905             iCurrentState = newState;
       
   906             }
       
   907         else
       
   908             {
       
   909             LOG_1( _L("> New state is null2.") );
       
   910             }
       
   911         }
       
   912      else
       
   913         {
       
   914         LOG_1( _L("> New state is null1.") );
       
   915         }
       
   916        
       
   917     // Update linger objects    
       
   918     iConnectionManager->HandleSettingsChangedL();    
       
   919     }
       
   920 
       
   921 // ---------------------------------------------------------------------------
       
   922 // CAOServer::HandleSuccesfulRAUL
       
   923 // ---------------------------------------------------------------------------
       
   924 //
       
   925 void CAOServer::HandleSuccesfulRAUL( TRAUType /*aType*/ )
       
   926     {
       
   927     LOG_1( _L("CAOServer::HandleSuccesfulRAUL") );
       
   928     LOG_2( _L("> Current state: %S"),
       
   929         &StateToDesC( CurrentState()->StateName() ) );
       
   930     
       
   931     TAOState* newState = iCurrentState->HandleSuccesfulRAUEventL();
       
   932     if ( newState )
       
   933         {
       
   934         iCurrentState = newState;
       
   935         }
       
   936     }
       
   937 
       
   938 
       
   939 // ---------------------------------------------------------------------------
       
   940 // CAOServer::InitStatePoolL
       
   941 // ---------------------------------------------------------------------------
       
   942 //
       
   943 void CAOServer::InitStatePoolL()
       
   944     {
       
   945     LOG_1( _L("CAOServer::InitStatePoolL") );
       
   946 
       
   947     iPointerStatePool = new (ELeave) CArrayPtrFlat<TAOState>( TAOState::EStateLastItem );
       
   948     
       
   949     
       
   950     TAOStateInit *stateInit = new (ELeave) TAOStateInit( *this, *this );
       
   951     CleanupStack::PushL( stateInit );
       
   952     iPointerStatePool->InsertL( TAOState::EStateInit, stateInit );
       
   953     CleanupStack::Pop( stateInit );
       
   954 
       
   955     TAOStateStarting *stateStarting = new (ELeave) TAOStateStarting( *this, *this );
       
   956     CleanupStack::PushL( stateStarting );
       
   957     iPointerStatePool->InsertL( TAOState::EStateStarting, stateStarting );
       
   958     CleanupStack::Pop( stateStarting );
       
   959 
       
   960     TAOStateDisabled *stateDisabled = new (ELeave) TAOStateDisabled( *this, *this );
       
   961     CleanupStack::PushL( stateDisabled );
       
   962     iPointerStatePool->InsertL( TAOState::EStateDisabled, stateDisabled );
       
   963     CleanupStack::Pop( stateDisabled );
       
   964     
       
   965     TAOStateConnecting *stateConnecting = new (ELeave) TAOStateConnecting( *this, *this );
       
   966     CleanupStack::PushL( stateConnecting );
       
   967     iPointerStatePool->InsertL( TAOState::EStateConnecting, stateConnecting );
       
   968     CleanupStack::Pop( stateConnecting );
       
   969     
       
   970     TAOState *stateConnected = new (ELeave) TAOStateConnected( *this, *this );
       
   971     CleanupStack::PushL( stateConnected );
       
   972     iPointerStatePool->InsertL( TAOState::EStateConnected, stateConnected );
       
   973     CleanupStack::Pop( stateConnected );
       
   974     
       
   975     TAOState *stateDisconnected = new (ELeave) TAOStateDisconnected( *this, *this );
       
   976     CleanupStack::PushL( stateDisconnected );
       
   977     iPointerStatePool->InsertL( TAOState::EStateDisconnected, stateDisconnected );
       
   978     CleanupStack::Pop( stateDisconnected );
       
   979     
       
   980     TAOState *stateWaiting = new (ELeave) TAOStateWaiting( *this, *this );
       
   981     CleanupStack::PushL( stateWaiting );
       
   982     iPointerStatePool->InsertL( TAOState::EStateWaiting, stateWaiting );
       
   983     CleanupStack::Pop( stateWaiting );
       
   984     
       
   985     TAOState *stateUnconnected = new (ELeave) TAOStateUnconnected( *this, *this );
       
   986     CleanupStack::PushL( stateUnconnected );
       
   987     iPointerStatePool->InsertL( TAOState::EStateUnconnected, stateUnconnected );
       
   988     CleanupStack::Pop( stateUnconnected );
       
   989     
       
   990     TAOState *stateResetFactorySettings = new (ELeave) TAOStateResetFactorySettings( *this, *this );
       
   991     CleanupStack::PushL( stateResetFactorySettings );
       
   992     iPointerStatePool->InsertL( TAOState::EStateResetFactorySettings, stateResetFactorySettings );
       
   993     CleanupStack::Pop( stateResetFactorySettings );
       
   994     
       
   995     TAOState *stateExternalConnection = new (ELeave) TAOStateExternalConnection( *this, *this );
       
   996     CleanupStack::PushL( stateExternalConnection );
       
   997     iPointerStatePool->InsertL( TAOState::EStateExternalConnection, stateExternalConnection );
       
   998     CleanupStack::Pop( stateExternalConnection );
       
   999     
       
  1000     }
       
  1001 
       
  1002 
       
  1003 // End of file