vtuis/lcvtplugin/src/states/tlcvtstatebase.cpp
branchRCL_3
changeset 24 f15ac8e65a02
equal deleted inserted replaced
23:890b5dd735f8 24:f15ac8e65a02
       
     1 /*
       
     2 * Copyright (c) 2008 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:  base class for lc vt plugin states
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 #include "tlcvtstatebase.h"
       
    20 #include "tlcvtstates.h"
       
    21 #include "tlcvtpluginstates.h"
       
    22 #include "clcvtappshutter.h"
       
    23 #include "mlcvtstatecontext.h"
       
    24 #include <StringLoader.h>
       
    25 #include <cvtlogger.h>
       
    26 #include <cvtengmodel.h>
       
    27 #include <vtengevents.h>
       
    28 #include <mvtengcommandhandler.h>
       
    29 
       
    30 // By default call ending command is allowed to send to call handling.
       
    31 
       
    32 // Initially no shutdown request
       
    33 TBool TLcVtStateBase::iShutdownRequested = EFalse;
       
    34 
       
    35 // -----------------------------------------------------------------------------
       
    36 // c++ constructor
       
    37 // -----------------------------------------------------------------------------
       
    38 //
       
    39 TLcVtStateBase::TLcVtStateBase(
       
    40     MLcVtStateContext& aCtx,
       
    41     TLcVtStates& aUiStates ) : iCtx(aCtx), iUiStates( aUiStates )
       
    42     {
       
    43     }
       
    44 
       
    45 // -----------------------------------------------------------------------------
       
    46 // Destructor
       
    47 // -----------------------------------------------------------------------------
       
    48 //
       
    49 TLcVtStateBase::~TLcVtStateBase()
       
    50     {
       
    51     }
       
    52 
       
    53 // -----------------------------------------------------------------------------
       
    54 // TLcVtStateBase::LcVtStartupPhase1DoneL
       
    55 // -----------------------------------------------------------------------------
       
    56 //
       
    57 void TLcVtStateBase::LcVtStartupPhase1DoneL()
       
    58     {
       
    59     // no default behavior
       
    60     }
       
    61 
       
    62 // -----------------------------------------------------------------------------
       
    63 // TLcVtStateBase::LcVtStartupPhase2DoneL
       
    64 // -----------------------------------------------------------------------------
       
    65 //
       
    66 void TLcVtStateBase::LcVtStartupPhase2DoneL()
       
    67     {
       
    68     // no default behavior
       
    69     }
       
    70 
       
    71 // -----------------------------------------------------------------------------
       
    72 // TLcVtStateBase::ShutdownDoneL
       
    73 // -----------------------------------------------------------------------------
       
    74 //
       
    75 void TLcVtStateBase::ShutdownDoneL()
       
    76     {
       
    77     // no default behavior
       
    78     }
       
    79 #if 0
       
    80 // -----------------------------------------------------------------------------
       
    81 // TLcVtStateBase::HandleForegroundChangedL
       
    82 // -----------------------------------------------------------------------------
       
    83 //
       
    84 TBool TLcVtStateBase::HandleForegroundChangedL(
       
    85     const TBool /*aIsForegroung*/ )
       
    86     {
       
    87     // no default behavior
       
    88     return EFalse;
       
    89     }
       
    90 
       
    91 // -----------------------------------------------------------------------------
       
    92 // TLcVtStateBase::PreHandleForegroundChangedL
       
    93 // -----------------------------------------------------------------------------
       
    94 //
       
    95 TBool TLcVtStateBase::PreHandleForegroundChangedL(
       
    96     const TBool /*aIsForegroung*/ )
       
    97     {
       
    98     // no default behavior
       
    99     return EFalse;
       
   100     }
       
   101 
       
   102 // -----------------------------------------------------------------------------
       
   103 // TLcVtStateBase::StartDtmfTone
       
   104 // -----------------------------------------------------------------------------
       
   105 //
       
   106 void TLcVtStateBase::StartDtmfTone( const TChar& /*aTone*/ )
       
   107     {
       
   108     // no default behavior
       
   109     }
       
   110 
       
   111 // -----------------------------------------------------------------------------
       
   112 // TLcVtStateBase::StopDtmfTone
       
   113 // -----------------------------------------------------------------------------
       
   114 //
       
   115 void TLcVtStateBase::StopDtmfTone()
       
   116     {
       
   117     // no default behavior
       
   118     }
       
   119 #endif
       
   120 
       
   121 // -----------------------------------------------------------------------------
       
   122 // TLcVtStateBase::SetInitialStateL
       
   123 // -----------------------------------------------------------------------------
       
   124 //
       
   125 void TLcVtStateBase::SetInitialStateL(
       
   126     MLcVtStateContext& aCtx,
       
   127     TLcVtStates& aUiStates )
       
   128     {
       
   129     __VTPRINTENTER( "TLcVtStateBase.SetInitialState" )
       
   130     TLcVtStateBase* initialState =
       
   131         TLcVtStateStarting::InstanceL( aCtx, aUiStates );
       
   132     aCtx.ChangeState( initialState );
       
   133     initialState->OpenL();
       
   134     __VTPRINTEXIT( "TLcVtStateBase.SetInitialState" )
       
   135     }
       
   136 
       
   137 // -----------------------------------------------------------------------------
       
   138 // TLcVtStateBase::LcVtStartupFailedL
       
   139 // -----------------------------------------------------------------------------
       
   140 //
       
   141 void TLcVtStateBase::LcVtStartupFailedL()
       
   142     {
       
   143     __VTPRINTENTER( "TLcVtStateBase.AppUiStartupFailedL" )
       
   144     // Shutdown
       
   145     ChangeStateL( *TLcVtStateResetting::InstanceL( iCtx, iUiStates ) );
       
   146     __VTPRINTEXIT( "TLcVtStateBase.AppUiStartupFailedL" )
       
   147     }
       
   148 #if 0
       
   149 // -----------------------------------------------------------------------------
       
   150 // TLcVtStateBase::OpenL
       
   151 // -----------------------------------------------------------------------------
       
   152 //
       
   153 void TLcVtStateBase::OpenL()
       
   154     {
       
   155     }
       
   156 
       
   157 // -----------------------------------------------------------------------------
       
   158 // TLcVtStateBase::Close
       
   159 // -----------------------------------------------------------------------------
       
   160 //
       
   161 void TLcVtStateBase::Close()
       
   162     {
       
   163     }
       
   164 #endif
       
   165 
       
   166 // -----------------------------------------------------------------------------
       
   167 // TLcVtStateBase::ChangeStateL
       
   168 // -----------------------------------------------------------------------------
       
   169 //
       
   170 void TLcVtStateBase::ChangeStateL( TLcVtStateBase& aNewState )
       
   171     {
       
   172     __VTPRINTENTER( "TLcVtStateBase.ChangeStateL" )
       
   173 
       
   174     // Check for transition to already active state.
       
   175     TLcVtStateBase* state = &aNewState;
       
   176     if ( state == this )
       
   177         {
       
   178         __VTPRINTEXITR( "TLcVtStateBase.ChangeStateL %d", 0 )
       
   179         return;
       
   180         }
       
   181     const TVtEngCommandId pending =
       
   182         iCtx.Model().CommandHandler().PendingCommand();
       
   183     if ( pending !=  KVtEngCommandNone &&
       
   184          state == TLcVtStateResetting::InstanceL( iCtx, iUiStates ) )
       
   185         {
       
   186         // delay shutdown until engine command completes
       
   187         __VTPRINT2( DEBUG_GEN, "TLcVtStateBase.ChangeStateL, pengind command is: %d", pending );
       
   188         TLcVtStateBase::iShutdownRequested = ETrue;
       
   189 
       
   190         if ( pending == KVtEngInitializeShareImage )
       
   191             {
       
   192             iCtx.Model().CommandHandler().CancelCommand( pending );
       
   193             }
       
   194 
       
   195         __VTPRINTEXITR( "TLcVtStateBase.ChangeStateL %d", KErrNotReady )
       
   196         return;
       
   197         }
       
   198     __VTPRINT( DEBUG_GEN,
       
   199         " TLcVtStateBase.ChangeStateL !! STATE TRANSITION !!" )
       
   200     iCtx.ChangeState( &aNewState );
       
   201     Close();
       
   202     // perform entry action for new state
       
   203     aNewState.OpenL();
       
   204     __VTPRINTEXITR( "TLcVtStateBase.ChangeStateL %d", 1 )
       
   205     }
       
   206 
       
   207 // -----------------------------------------------------------------------------
       
   208 // TLcVtStateBase::CleanupResetPushL
       
   209 // -----------------------------------------------------------------------------
       
   210 //
       
   211 void TLcVtStateBase::CleanupResetPushL()
       
   212     {
       
   213     // Shutdown if leave occurs in critical ops.
       
   214     CleanupStack::PushL(
       
   215         TCleanupItem( TransitionToReset, this ) );
       
   216     }
       
   217 
       
   218 // -----------------------------------------------------------------------------
       
   219 // TLcVtStateBase::TransitionToReset
       
   220 // -----------------------------------------------------------------------------
       
   221 //
       
   222 void TLcVtStateBase::TransitionToReset( TAny* aAny )
       
   223     {
       
   224     TLcVtStateBase* state = reinterpret_cast< TLcVtStateBase* >( aAny );
       
   225     TRAP_IGNORE( state->ChangeStateL( *TLcVtStateResetting::InstanceL(
       
   226         state->iCtx, state->iUiStates ) ) );
       
   227     }
       
   228 
       
   229 // -----------------------------------------------------------------------------
       
   230 // TLcVtStateBase::HandleVTCommandPerformedL
       
   231 // -----------------------------------------------------------------------------
       
   232 //
       
   233 TLcVtStateBase::TEventResponse TLcVtStateBase::HandleVTCommandPerformedL(
       
   234             TVtEngCommandId /*aCommand*/,
       
   235             const TInt /*aError*/ )
       
   236     {
       
   237     __VTPRINTENTER( "TLcVtStateBase.HandleVTCommandPerformedL" )
       
   238     // By default all UI is allowed to handle all command completions.
       
   239     TEventResponse handled = EEventNotHandled;
       
   240 
       
   241     // check if shutdown requested while command was pending
       
   242     const TVtEngCommandId pending = iCtx.Model().CommandHandler().PendingCommand();
       
   243     if ( pending == KVtEngCommandNone &&
       
   244             TLcVtStateBase::iShutdownRequested )
       
   245         {
       
   246         __VTPRINT( DEBUG_GEN, "Handling delayed shutdown" );
       
   247         ChangeStateL( *TLcVtStateResetting::InstanceL(
       
   248             iCtx, iUiStates ) );
       
   249         }
       
   250     __VTPRINTEXIT( "TLcVtStateBase.HandleVTCommandPerformedL" )
       
   251     return handled;
       
   252     }
       
   253 
       
   254 // -----------------------------------------------------------------------------
       
   255 // TLcVtStateBase::HandleVtEventL
       
   256 // -----------------------------------------------------------------------------
       
   257 //
       
   258 TLcVtStateBase::TEventResponse TLcVtStateBase::HandleVtEventL(
       
   259     const TInt aEvent )
       
   260     {
       
   261     __VTPRINTENTER( "TLcVtStateBase.HandleVtEventL" )
       
   262     TEventResponse handled = EEventHandled;
       
   263     switch ( aEvent )
       
   264         {
       
   265     case KVtEngDeviceLockOn:
       
   266     case KVtEngDeviceLockOff:
       
   267         HandleDeviceLockEventL( aEvent == KVtEngDeviceLockOn );
       
   268         break;
       
   269     case KVtEngRemoteDisconnect:
       
   270         /** Don't allow sending of end active call command to call handling
       
   271          *  because requesting disconnect from the network after NW originated
       
   272          *  termination violates standards.
       
   273          */
       
   274         break;
       
   275     default:
       
   276         handled = EEventNotHandled;
       
   277         break;
       
   278         }
       
   279     __VTPRINTEXIT( "TLcVtStateBase.HandleVtEventL" )
       
   280     return handled;
       
   281     }
       
   282 
       
   283 // -----------------------------------------------------------------------------
       
   284 // TLcVtStateBase::HandleCommandL
       
   285 // -----------------------------------------------------------------------------
       
   286 //
       
   287 TLcVtStateBase::TEventResponse TLcVtStateBase::HandleCommandL(
       
   288     const TInt /*aCommand*/ )
       
   289     {
       
   290     __VTPRINTENTER( "TLcVtStateBase.HandleCommandL" )
       
   291     TEventResponse handled = EEventNotHandled;
       
   292     __VTPRINTEXITR( "TLcVtStateBase.HandleCommandL %d", handled )
       
   293     return handled;
       
   294     }
       
   295 #if 0
       
   296 // -----------------------------------------------------------------------------
       
   297 // TLcVtStateBase::HandleLayoutChangedL
       
   298 // -----------------------------------------------------------------------------
       
   299 //
       
   300 void TLcVtStateBase::HandleLayoutChangedL( )
       
   301     {
       
   302     __VTPRINTENTER( "TLcVtStateBase.HandleLayoutChangedL" )
       
   303     // By default only indicate that layout change needs to be handled.
       
   304     iUiStates.SetLayoutChangeNeeded( ETrue );
       
   305     __VTPRINTEXIT( "TLcVtStateBase.HandleLayoutChangedL" )
       
   306     }
       
   307 #endif
       
   308 // -----------------------------------------------------------------------------
       
   309 // TLcVtStateBase::HandleShutdownReady
       
   310 // -----------------------------------------------------------------------------
       
   311 //
       
   312 void TLcVtStateBase::HandleShutdownReady()
       
   313     {
       
   314      __VTPRINTENTER( "TLcVtStateBase.HandleShutdownReady" )
       
   315     // forwarded to AppUi which handles UI framework exit
       
   316     iCtx.HandleShutdownReady();
       
   317     iCtx.ChangeState( NULL );
       
   318     // deletes current state
       
   319     Close();
       
   320      __VTPRINTEXIT( "TLcVtStateBase.HandleShutdownReady" )
       
   321     }
       
   322 
       
   323 // -----------------------------------------------------------------------------
       
   324 // TLcVtStateBase::HandleDeviceLockEventL
       
   325 //
       
   326 // -----------------------------------------------------------------------------
       
   327 //
       
   328 void TLcVtStateBase::HandleDeviceLockEventL( const TBool aDeviceIsLocked )
       
   329     {
       
   330     __VTPRINTENTER( "TLcVtStateBase.HandleDeviceLockEventL" )
       
   331     iUiStates.SetDeviceLockOn( aDeviceIsLocked );
       
   332     if ( aDeviceIsLocked )
       
   333         {
       
   334         iCtx.ChangeApplicationFocus( EFalse );
       
   335         }
       
   336     __VTPRINTEXITR( "TLcVtStateBase.HandleDeviceLockEventL lock state=%d",
       
   337         aDeviceIsLocked )
       
   338     }
       
   339 
       
   340 // -----------------------------------------------------------------------------
       
   341 // TLcVtStateBase::CheckEndActiveCallL
       
   342 // -----------------------------------------------------------------------------
       
   343 //
       
   344 TBool TLcVtStateBase::CheckEndActiveCallL()
       
   345     {
       
   346     __VTPRINTENTER( "TLcVtStateBase.CheckEndActiveCallL" )
       
   347     const MVtEngSessionInfo::TSessionState state = SessionState( EFalse );
       
   348     TBool shutdownStarted( EFalse );
       
   349     if ( state == MVtEngSessionInfo::EIdle )
       
   350         {
       
   351         __VTPRINT( DEBUG_GEN, "VtUi.Release bearer" )
       
   352         // h.245 session is ended
       
   353         ChangeStateL( *TLcVtStateResetting::InstanceL( iCtx, iUiStates ) );        
       
   354         shutdownStarted = ETrue;
       
   355         }
       
   356     __VTPRINTEXITR( "TLcVtStateBase.CheckEndActiveCallL %d",
       
   357         shutdownStarted )
       
   358     return shutdownStarted;
       
   359     }
       
   360 
       
   361 // -----------------------------------------------------------------------------
       
   362 // TLcVtStateBase::SessionState
       
   363 // -----------------------------------------------------------------------------
       
   364 //
       
   365 MVtEngSessionInfo::TSessionState TLcVtStateBase::SessionState(
       
   366     const TBool aUpdate ) const
       
   367     {
       
   368     const CVtEngModel& model = iCtx.Model();
       
   369     const MVtEngSessionInfo& session = model.Session();
       
   370     return session.State( aUpdate );
       
   371     }
       
   372 
       
   373 // -----------------------------------------------------------------------------
       
   374 // TLcVtStateBase::SetExecState
       
   375 // -----------------------------------------------------------------------------
       
   376 //
       
   377 void TLcVtStateBase::SetExecState( const TLcVtStates::TLcVtExecState aState )
       
   378     {
       
   379     __VTPRINTENTER( "TLcVtStateBase.SetExecState" )
       
   380     iUiStates.SetExecState( aState );
       
   381     __VTPRINTEXITR( "TLcVtStateBase.SetExecState %d", aState )
       
   382     }