idlefw/src/framework/aistatealive.cpp
branchRCL_3
changeset 9 d0529222e3f0
parent 4 1a2a00e78665
child 10 5ef93ea513cb
child 18 bd874ee5e5e2
equal deleted inserted replaced
4:1a2a00e78665 9:d0529222e3f0
     1 /*
       
     2 * Copyright (c) 2005-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:  State class for alive states
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 #include "aistatealive.h"
       
    20 #include "aipluginstatemachine.h"
       
    21 #include "debug.h"
       
    22 
       
    23 
       
    24 // ======== MEMBER FUNCTIONS ========
       
    25 
       
    26 // ----------------------------------------------------------------------------
       
    27 // TAiStateAliveActive::TAiStateAliveActive()
       
    28 // ----------------------------------------------------------------------------
       
    29 //
       
    30 TAiStateAliveActive::TAiStateAliveActive()
       
    31     {
       
    32     }
       
    33 
       
    34 // ----------------------------------------------------------------------------
       
    35 // TAiStateAliveActive::Enter()
       
    36 // ----------------------------------------------------------------------------
       
    37 //
       
    38 void TAiStateAliveActive::Enter( MAiPluginStateMachine& aStateMachine,
       
    39     TAiStateChanges aStateChange )
       
    40     {
       
    41     __PRINTS( "XAI: Enter Alive active" );
       
    42     
       
    43     const TAiTransitionReason reason( 
       
    44             aStateMachine.TranslateReason( aStateChange ) );
       
    45     
       
    46     aStateMachine.ChangePluginState( reason, CAiContentPublisher::Resume );                                    
       
    47     }
       
    48     
       
    49 // ----------------------------------------------------------------------------
       
    50 // TAiStateAliveActive::HandleEvent()
       
    51 // ----------------------------------------------------------------------------
       
    52 //
       
    53 TBool TAiStateAliveActive::HandleEvent( MAiPluginStateMachine& aStateMachine,
       
    54     TAiStateChanges aStateChange )
       
    55     {
       
    56     __PRINTS( "XAI: Alive active handles event" );
       
    57     switch( aStateChange )
       
    58         {
       
    59         case ESMAIBacklightOff:
       
    60             {
       
    61             aStateMachine.SwitchToState( EAiAliveInactive, aStateChange );
       
    62             return ETrue;
       
    63             }
       
    64         default:
       
    65             {
       
    66             return EFalse;
       
    67             }
       
    68         }
       
    69     }
       
    70     
       
    71 // ----------------------------------------------------------------------------
       
    72 // TAiStateAliveActive::Exit()
       
    73 // ----------------------------------------------------------------------------
       
    74 //
       
    75 void TAiStateAliveActive::Exit( MAiPluginStateMachine& /*aStateMachine*/,
       
    76     TAiStateChanges /*aStateChange*/ )
       
    77     {
       
    78     __PRINTS( "XAI: Exit alive active" );
       
    79     }
       
    80 
       
    81 // ======== MEMBER FUNCTIONS ========
       
    82 
       
    83 // ----------------------------------------------------------------------------
       
    84 // TAiStateAliveInactive::TAiStateAliveInactive()
       
    85 // ----------------------------------------------------------------------------
       
    86 //
       
    87 TAiStateAliveInactive::TAiStateAliveInactive()
       
    88     {
       
    89     }
       
    90 
       
    91 // ----------------------------------------------------------------------------
       
    92 // TAiStateAliveInactive::Enter()
       
    93 // ----------------------------------------------------------------------------
       
    94 //
       
    95 void TAiStateAliveInactive::Enter( MAiPluginStateMachine& aStateMachine,
       
    96     TAiStateChanges aStateChange )
       
    97     {
       
    98     __PRINTS( "XAI: Enter alive inactive" );
       
    99     const TAiTransitionReason reason( 
       
   100             aStateMachine.TranslateReason( aStateChange ) );
       
   101     
       
   102     aStateMachine.ChangePluginState( reason, CAiContentPublisher::Resume );
       
   103                                          
       
   104     aStateMachine.RestartSuspendTimer();
       
   105     }
       
   106 
       
   107 // ----------------------------------------------------------------------------
       
   108 // TAiStateAliveInactive::HandleEvent()
       
   109 // ----------------------------------------------------------------------------
       
   110 //
       
   111 TBool TAiStateAliveInactive::HandleEvent( MAiPluginStateMachine& aStateMachine,
       
   112     TAiStateChanges aStateChange )
       
   113     {
       
   114     __PRINTS( "XAI: alive inactive handles event" );
       
   115     switch( aStateChange )
       
   116         {
       
   117         case ESMAIIdleForeground:
       
   118         case ESMAIBacklightOn:
       
   119             {
       
   120             aStateMachine.SwitchToState( EAiAliveActive, aStateChange );
       
   121             return ETrue;
       
   122             }
       
   123         case ESMAIT1Timeout:
       
   124             {
       
   125             aStateMachine.SwitchToState( EAiSuspended, aStateChange );
       
   126             return ETrue;
       
   127             }
       
   128         default:
       
   129             {
       
   130             return EFalse;
       
   131             }
       
   132         }
       
   133     }
       
   134 
       
   135 // ----------------------------------------------------------------------------
       
   136 // TAiStateAliveInactive::Exit()
       
   137 // ----------------------------------------------------------------------------
       
   138 //
       
   139 void TAiStateAliveInactive::Exit( MAiPluginStateMachine& /*aStateMachine*/,
       
   140     TAiStateChanges /*aStateChange*/ )
       
   141     {
       
   142     __PRINTS( "XAI: Exit alive inactive" );
       
   143     }
       
   144 
       
   145 
       
   146 // ======== MEMBER FUNCTIONS ========
       
   147 
       
   148 // ----------------------------------------------------------------------------
       
   149 // TAiStateAliveIncall::TAiStateAliveIncall()
       
   150 // ----------------------------------------------------------------------------
       
   151 //
       
   152 TAiStateAliveIncall::TAiStateAliveIncall()
       
   153     {
       
   154     }
       
   155 
       
   156 // ----------------------------------------------------------------------------
       
   157 // TAiStateAliveIncall::Enter()
       
   158 // ----------------------------------------------------------------------------
       
   159 //
       
   160 void TAiStateAliveIncall::Enter( MAiPluginStateMachine& aStateMachine,
       
   161     TAiStateChanges aStateChange )
       
   162     {
       
   163     __PRINTS( "XAI: Enter alive incall" );
       
   164     
       
   165     const TAiTransitionReason reason( 
       
   166             aStateMachine.TranslateReason( aStateChange ) );
       
   167     
       
   168     aStateMachine.ChangePluginState( reason, CAiContentPublisher::Resume );                                    
       
   169     }
       
   170 
       
   171 // ----------------------------------------------------------------------------
       
   172 // TAiStateAliveIncall::HandleEvent()
       
   173 // ----------------------------------------------------------------------------
       
   174 //
       
   175 TBool TAiStateAliveIncall::HandleEvent( MAiPluginStateMachine& aStateMachine,
       
   176     TAiStateChanges aStateChange )
       
   177     {
       
   178     __PRINTS( "XAI: alive incall handles event" );
       
   179     switch( aStateChange )
       
   180         {
       
   181         case ESMAINoCall:
       
   182             {
       
   183             // To alive switch
       
   184             aStateMachine.SwitchToState( EAiAlive, aStateChange );
       
   185             return ETrue;
       
   186             }
       
   187         case ESMAIInCall:
       
   188             {
       
   189             // prevent master state from handling this
       
   190             return ETrue;
       
   191             }
       
   192         default:
       
   193             {
       
   194             return EFalse;
       
   195             }
       
   196         }
       
   197     }
       
   198 
       
   199 // ----------------------------------------------------------------------------
       
   200 // TAiStateAliveIncall::Exit()
       
   201 // ----------------------------------------------------------------------------
       
   202 //
       
   203 void TAiStateAliveIncall::Exit( MAiPluginStateMachine& /*aStateMachine*/,
       
   204     TAiStateChanges /*aStateChange*/ )
       
   205     {
       
   206     __PRINTS( "XAI: Exit alive incall" );
       
   207     }
       
   208    
       
   209 // ======== MEMBER FUNCTIONS ========
       
   210 
       
   211 // ----------------------------------------------------------------------------
       
   212 // TAiStateAlive::TAiStateAlive()
       
   213 // ----------------------------------------------------------------------------
       
   214 //
       
   215 TAiStateAlive::TAiStateAlive( MAiPluginStateMachine& aParentStateMachine )
       
   216   : iCurrentState( &iStateAliveInactive ),
       
   217     iParentStateMachine( &aParentStateMachine )
       
   218     {
       
   219     }
       
   220 
       
   221 // ----------------------------------------------------------------------------
       
   222 // TAiStateAlive::SwitchToState()
       
   223 // ----------------------------------------------------------------------------
       
   224 //
       
   225 void TAiStateAlive::SwitchToState( TAiState aState,
       
   226     TAiStateChanges aStateChange )
       
   227     {
       
   228     switch( aState )
       
   229         {
       
   230         case EAiAliveInactive:
       
   231             {
       
   232             iCurrentState = &iStateAliveInactive;
       
   233             break;
       
   234             }
       
   235         case EAiAliveActive:
       
   236             {
       
   237             iCurrentState = &iStateAliveActive;
       
   238             break;
       
   239             }
       
   240         case EAiAliveIncall:
       
   241             {
       
   242             iCurrentState = &iStateAliveIncall;
       
   243             break;
       
   244             }
       
   245         default:
       
   246             {
       
   247             iParentStateMachine->SwitchToState( aState, aStateChange );
       
   248             return;
       
   249             }
       
   250         }   
       
   251     iCurrentState->Enter( *this, aStateChange );
       
   252     }
       
   253 
       
   254 // ----------------------------------------------------------------------------
       
   255 // TAiStateAlive::StateVariable()
       
   256 // ----------------------------------------------------------------------------
       
   257 //
       
   258 TBool TAiStateAlive::StateVariable( TAiStateVariable aStateVariable )
       
   259     {
       
   260     return iParentStateMachine->StateVariable( aStateVariable );
       
   261     }
       
   262 
       
   263 // ----------------------------------------------------------------------------
       
   264 // TAiStateAlive::Plugin()
       
   265 // ----------------------------------------------------------------------------
       
   266 //
       
   267 CAiContentPublisher& TAiStateAlive::Plugin() const
       
   268     {
       
   269     return iParentStateMachine->Plugin();
       
   270     }
       
   271 
       
   272 // ----------------------------------------------------------------------------
       
   273 // TAiStateAlive::TranslateReason()
       
   274 // ----------------------------------------------------------------------------
       
   275 //
       
   276 TAiTransitionReason TAiStateAlive::TranslateReason( 
       
   277     TAiStateChanges aStateChange )
       
   278     {
       
   279     return iParentStateMachine->TranslateReason( aStateChange );
       
   280     }
       
   281 
       
   282 // ----------------------------------------------------------------------------
       
   283 // TAiStateAlive::RestartSuspendTimer()
       
   284 // ----------------------------------------------------------------------------
       
   285 //
       
   286 void TAiStateAlive::RestartSuspendTimer()
       
   287     {
       
   288     iParentStateMachine->RestartSuspendTimer();
       
   289     }
       
   290 
       
   291 // ----------------------------------------------------------------------------
       
   292 // TAiStateAlive::Enter()
       
   293 // ----------------------------------------------------------------------------
       
   294 //
       
   295 void TAiStateAlive::Enter( MAiPluginStateMachine& aStateMachine,
       
   296     TAiStateChanges aStateChange )
       
   297     {
       
   298     __PRINTS( "XAI: Alive switch - enter" );
       
   299     if( aStateMachine.StateVariable( ESMAICallStatus ) )
       
   300         {
       
   301         // If call is ongoing enter alive in call
       
   302         iCurrentState = &iStateAliveIncall;
       
   303         }
       
   304     else if( !aStateMachine.StateVariable( ESMAILightStatus ) )
       
   305         {
       
   306         // If light is off enter alive inactive
       
   307         iCurrentState = &iStateAliveInactive;
       
   308         }
       
   309     else
       
   310         {
       
   311         // Otherwise alive active
       
   312         iCurrentState = &iStateAliveActive;
       
   313         }
       
   314     // finally call the Enter() method
       
   315     iCurrentState->Enter( *this, aStateChange );
       
   316     }
       
   317  
       
   318 // ----------------------------------------------------------------------------
       
   319 // TAiStateAlive::HandleEvent()
       
   320 // ----------------------------------------------------------------------------
       
   321 //
       
   322 TBool TAiStateAlive::HandleEvent( MAiPluginStateMachine& /*aStateMachine*/,
       
   323     TAiStateChanges aStateChange )
       
   324     {
       
   325     __PRINTS( "XAI: Alive switch handle event" );
       
   326 
       
   327     if( !iCurrentState->HandleEvent( *this, aStateChange ) )
       
   328         {
       
   329         // Only master state machine handles the "backup/restore on" and
       
   330         // screen layout changed cases.
       
   331         // Other event are forwarded to the currently active sub state.
       
   332         // Other common events may be added here in the future also.
       
   333         switch( aStateChange )
       
   334             {
       
   335             case ESMAIOffLine:
       
   336             case ESMAIOnLine:
       
   337             case ESMAIKeylockEnabled:
       
   338             case ESMAIKeylockDisabled:
       
   339             case ESMAIRelayoutScreen:
       
   340             case ESMAIIdleForeground:
       
   341             case ESMAIIdleBackground:
       
   342             case ESMAIPageSwitch:
       
   343             case ESMAIGeneralThemeChanged: // fallthrough
       
   344                 {
       
   345                 iCurrentState->Enter( *this, aStateChange );
       
   346                 // Handled the event ok
       
   347                 break;
       
   348                 }
       
   349             case ESMAIInCall:
       
   350                 {
       
   351                 SwitchToState( EAiAliveIncall, aStateChange );
       
   352                 // Handled the event ok
       
   353                 break;
       
   354                 }
       
   355             default:
       
   356                 {
       
   357                 // Neither current state or master handled this event
       
   358                 return EFalse;
       
   359                 }
       
   360             }
       
   361         }
       
   362     // Current state handled the event
       
   363     return ETrue;
       
   364     }
       
   365 
       
   366 // ----------------------------------------------------------------------------
       
   367 // TAiStateAlive::Exit()
       
   368 // ----------------------------------------------------------------------------
       
   369 //
       
   370 void TAiStateAlive::Exit( MAiPluginStateMachine& /*aStateMachine*/,
       
   371     TAiStateChanges aStateChange )
       
   372     {
       
   373     __PRINTS( "XAI: Alive switch exit" );
       
   374     iCurrentState->Exit( *this, aStateChange );
       
   375     }
       
   376 
       
   377 // ----------------------------------------------------------------------------
       
   378 // TAiStateAlive::ChangePluginState()
       
   379 // ----------------------------------------------------------------------------
       
   380 //
       
   381 void TAiStateAlive::ChangePluginState( TAiTransitionReason aReason,       
       
   382     void (CAiContentPublisher::*aStateChangeMethod)(TAiTransitionReason) )
       
   383     {
       
   384     iParentStateMachine->ChangePluginState( aReason, aStateChangeMethod );
       
   385     }
       
   386    
       
   387 // End of file