vtuis/videotelui/src/tvtuistatestarting.cpp
branchRCL_3
changeset 35 779871d1e4f4
parent 0 ed9695c8bcbe
equal deleted inserted replaced
34:f15ac8e65a02 35:779871d1e4f4
       
     1 /*
       
     2 * Copyright (c) 2007 - 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:  waiting details application state
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 #include "tvtuistates.h"
       
    20 #include "tvtuiappstates.h"
       
    21 #include "mvtuistatecontext.h"
       
    22 #include "videotelui.hrh"
       
    23 #include "cvtuiappshutter.h"
       
    24 #include <cvtlogger.h>
       
    25 #include <vtengevents.h>
       
    26 #include <vtengcommands.h>
       
    27 #include <cvtengmodel.h>
       
    28 #include <mvtengsessioninfo.h>
       
    29 
       
    30 
       
    31 TVtUiStateStarting* TVtUiStateStarting::iInstance = NULL;
       
    32 
       
    33 // c++ constructor
       
    34 TVtUiStateStarting::TVtUiStateStarting(
       
    35     MVtUiStateContext& aCtx, TVtUiStates& aUiStates ) 
       
    36     : TVtUiAppStateBase( aCtx, aUiStates )
       
    37     {
       
    38     iPreconditions.Set( EWaitingCLI );
       
    39     iPreconditions.Set( EWaitingPhase1ToComplete );
       
    40     }
       
    41 
       
    42 // Destructor
       
    43 TVtUiStateStarting::~TVtUiStateStarting()
       
    44     {
       
    45     delete iStartCallback;
       
    46     }
       
    47 
       
    48 // -----------------------------------------------------------------------------
       
    49 // TVtUiStateStarting::InstanceL
       
    50 //
       
    51 // -----------------------------------------------------------------------------
       
    52 //
       
    53 TVtUiStateStarting * TVtUiStateStarting::InstanceL(
       
    54     MVtUiStateContext& aCtx, TVtUiStates& aUiStates )
       
    55     {
       
    56     __VTPRINTENTER( "TVtUiStateStarting.InstanceL" )
       
    57     if ( iInstance == NULL )
       
    58         {
       
    59         iInstance = new ( ELeave ) TVtUiStateStarting( aCtx, aUiStates );
       
    60         }
       
    61     __VTPRINTEXIT( "TVtUiStateStarting.InstanceL" )
       
    62     return iInstance;
       
    63     }
       
    64 
       
    65 // -----------------------------------------------------------------------------
       
    66 // TVtUiStateStarting::AppUiStartupPhase1DoneL
       
    67 //
       
    68 // Phase 1 of application startup is completed, check if we can proceed to
       
    69 // phase 2.
       
    70 // -----------------------------------------------------------------------------
       
    71 //
       
    72 void TVtUiStateStarting::AppUiStartupPhase1DoneL()
       
    73     {
       
    74     __VTPRINTENTER( "TVtUiStateStarting.AppUiStartupPhase1DoneL" )
       
    75     // From startup phase point of view we're ready to proceed
       
    76     // to phase 2. Clear that precondition and proceed if otherwise ready.
       
    77     CheckPhase2StartupL( EWaitingPhase1ToComplete );
       
    78     __VTPRINTEXIT( "TVtUiStateStarting.AppUiStartupPhase1DoneL" )
       
    79     }
       
    80 
       
    81 // -----------------------------------------------------------------------------
       
    82 // TVtUiStateStarting::AppUiStartupPhase2DoneL
       
    83 //
       
    84 // -----------------------------------------------------------------------------
       
    85 //
       
    86 void TVtUiStateStarting::AppUiStartupPhase2DoneL()
       
    87     {
       
    88     __VTPRINTENTER( "TVtUiStateStarting.AppUiStartupPhase2DoneL" )
       
    89     // Phase 2 completed, proceed to next state
       
    90     ChangeStateL( *TVtUiStateRunning::InstanceL( iCtx, iUiStates ) );
       
    91     __VTPRINTEXIT( "TVtUiStateStarting.AppUiStartupPhase2DoneL" )
       
    92     }
       
    93 
       
    94 // -----------------------------------------------------------------------------
       
    95 // TVtUiStateStarting::HandleVtEventL
       
    96 //
       
    97 // -----------------------------------------------------------------------------
       
    98 //
       
    99 TVtUiAppStateBase::TEventResponse TVtUiStateStarting::HandleVtEventL(
       
   100     const TInt aEvent )
       
   101     {
       
   102     __VTPRINTENTER( "TVtUiStateStarting.HandleVtEventL" )
       
   103     TEventResponse handled = EEventHandled;
       
   104     switch ( aEvent )
       
   105         {
       
   106     case KVtEngRemoteDisconnect:
       
   107         // base class handles this.
       
   108         handled = TVtUiAppStateBase::HandleVtEventL( aEvent );
       
   109         break;
       
   110     case KVtEngSessionStateChanged:
       
   111         {
       
   112         // check if session state is proper for proceeding to next phase
       
   113         // in startup.
       
   114         CheckSessionStateL();
       
   115         }
       
   116         break;
       
   117     case KVtEngRemoteVideoStarted:
       
   118         // allow to start remote video rendering
       
   119     case KVtEngSourceChanged:
       
   120         // allow handling of source changed event
       
   121         handled = EEventNotHandled; 
       
   122         break;
       
   123     case KVtEngCLIAvailable:
       
   124         HandleCLIReceivedL();
       
   125         break;
       
   126         
       
   127     case KVtEngRemoteUIIIA5StringSupport:
       
   128         break;
       
   129     case KVtEngDeviceLockOn:
       
   130     case KVtEngDeviceLockOff:
       
   131     default:
       
   132         handled = TVtUiAppStateBase::HandleVtEventL( aEvent );
       
   133         break;
       
   134         }
       
   135     __VTPRINTEXIT( "TVtUiStateStarting.HandleVtEventL" )
       
   136     return handled;
       
   137     }
       
   138 
       
   139 // -----------------------------------------------------------------------------
       
   140 // TVtUiStateStarting::HandleCommandL
       
   141 //
       
   142 // -----------------------------------------------------------------------------
       
   143 //
       
   144 TVtUiAppStateBase::TEventResponse TVtUiStateStarting::HandleCommandL(
       
   145     const TInt /*aCommand*/ )
       
   146     {
       
   147     __VTPRINTENTER( "TVtUiStateStarting.HandleCommandL" )
       
   148     __VTPRINTEXIT( "TVtUiStateStarting.HandleCommandL" )
       
   149     return EEventNotHandled;
       
   150     }
       
   151 
       
   152 // -----------------------------------------------------------------------------
       
   153 // TVtUiStateStarting::HandleForegroundChangedL
       
   154 //
       
   155 // -----------------------------------------------------------------------------
       
   156 //
       
   157 TBool TVtUiStateStarting::HandleForegroundChangedL( const TBool aIsForeground )
       
   158     {
       
   159     __VTPRINTENTER( "TVtUiStateStarting.HandleForegroundChangedL" )
       
   160         
       
   161     SetLightsState( aIsForeground );
       
   162     iCtx.RefreshL( MVtUiStateContext::ENaviPane );
       
   163     
       
   164     // behave as in background if CLI (=details) has not yet received
       
   165     TBool handleAsForeground( aIsForeground && iUiStates.IsDetailsReceived() ); 
       
   166     TVtUiAppStateBase::ExecuteEngineCommand( KVtEngSetUIForeground, 
       
   167         handleAsForeground );
       
   168     
       
   169     __VTPRINTEXIT( "TVtUiStateStarting.HandleForegroundChangedL" )
       
   170     return handleAsForeground;
       
   171     }
       
   172 
       
   173 // -----------------------------------------------------------------------------
       
   174 // TVtUiStateStarting::OpenL
       
   175 // -----------------------------------------------------------------------------
       
   176 //
       
   177 void TVtUiStateStarting::OpenL()
       
   178     {
       
   179     __VTPRINTENTER( "TVtUiStateStarting.OpenL" )
       
   180     iStartCallback = new ( ELeave ) CAsyncCallBack (
       
   181             TCallBack( &AsynchOpen, this ),
       
   182             CActive::EPriorityStandard );
       
   183     iStartCallback->CallBack();  
       
   184     __VTPRINTEXIT( "TVtUiStateStarting.OpenL" )
       
   185     }
       
   186 
       
   187 // -----------------------------------------------------------------------------
       
   188 // TVtUiStateStarting::AsynchOpen
       
   189 // asynchronous entry to the state.
       
   190 // -----------------------------------------------------------------------------
       
   191 //
       
   192 TInt TVtUiStateStarting::AsynchOpen( TAny* aAny )
       
   193     {
       
   194     __VTPRINTENTER( "TVtUiStateStarting.AsynchOpen" )
       
   195     TVtUiStateStarting* state = reinterpret_cast<TVtUiStateStarting*>( aAny );
       
   196     delete state->iStartCallback;
       
   197     state->iStartCallback = NULL;
       
   198     TRAPD( res, state->DoOpenL() );
       
   199     __VTPRINTEXITR( "TVtUiStateStarting.AsynchOpen err=%d>", res )
       
   200     return res;
       
   201     }
       
   202 
       
   203 // -----------------------------------------------------------------------------
       
   204 // TVtUiStateStarting::DoOpenL
       
   205 // -----------------------------------------------------------------------------
       
   206 //
       
   207 void TVtUiStateStarting::DoOpenL()
       
   208     {
       
   209     __VTPRINTENTER( "TVtUiStateStarting.DoOpenL" )
       
   210     if ( !CheckEndActiveCallL() )
       
   211         {
       
   212         // not shutting down, proceed to phase 1
       
   213         iCtx.StartupPhase1L();
       
   214         }
       
   215     __VTPRINTEXIT( "TVtUiStateStarting.DoOpenL" )
       
   216     }
       
   217 
       
   218 // -----------------------------------------------------------------------------
       
   219 // TVtUiStateStarting::CheckSessionStateL
       
   220 // Resolve action based on session state change in the engine.
       
   221 // -----------------------------------------------------------------------------
       
   222 //
       
   223 void TVtUiStateStarting::CheckSessionStateL()
       
   224     {
       
   225     __VTPRINTENTER( "TVtUiStateStarting.CheckSessionStateL" )
       
   226     const MVtEngSessionInfo::TSessionState state = SessionState( EFalse );
       
   227     switch ( state )
       
   228         {
       
   229     case MVtEngSessionInfo::EConnected:
       
   230     case MVtEngSessionInfo::ENegotiating:
       
   231     case MVtEngSessionInfo::EOpen:
       
   232         // From session state point of view we're ready to proceed.
       
   233         // Clear precondition and proceed if otherwise ready.
       
   234         CheckPhase2StartupL( EWaitingSessionState );
       
   235         break;
       
   236     default:
       
   237         // Is session state such that we need to shutdown?
       
   238         CheckEndActiveCallL();
       
   239         break;
       
   240         }
       
   241     __VTPRINTEXIT( "TVtUiStateStarting.CheckSessionStateL" )
       
   242     }
       
   243 
       
   244 // -----------------------------------------------------------------------------
       
   245 // TVtUiStateStarting::CheckPhase2StartupL
       
   246 //
       
   247 // mark precondition passed and if no more preconditions exist proceed
       
   248 // in startup.
       
   249 // -----------------------------------------------------------------------------
       
   250 //
       
   251 void TVtUiStateStarting::CheckPhase2StartupL(
       
   252     const TPreconditions aCond )
       
   253     {
       
   254     __VTPRINTENTER( "TVtUiStateStarting.CheckPhase2StartupL" )
       
   255     // First check that at least one precondition holds
       
   256     if ( iPreconditions.Value() )
       
   257         {
       
   258         iPreconditions.Clear( aCond );
       
   259         if ( !iPreconditions.Value() )
       
   260             {
       
   261             CleanupResetPushL();  // start shutdown if StartupPhase2L leaves
       
   262             iCtx.StartupPhase2L();
       
   263             CleanupStack::Pop(); // CleanupResetPushL
       
   264             }
       
   265         }
       
   266 #ifdef VTDEBUG
       
   267     else {
       
   268         __VTPRINT( DEBUG_GEN, "TVtUiStateStarting.CheckPhase2StartupL NoOp!" )
       
   269         }
       
   270 #endif // VTDEBUG
       
   271     __VTPRINTEXITR( "TVtUiStateStarting.CheckPhase2StartupL cond=%d",
       
   272         (TInt) iPreconditions.Value() )
       
   273     }
       
   274 
       
   275 // -----------------------------------------------------------------------------
       
   276 // TVtUiStateStarting::HandleCLIReceivedL
       
   277 // CLI reception from engine is one of the two preconditions for proceeding
       
   278 // to phase2 startup.
       
   279 // -----------------------------------------------------------------------------
       
   280 //
       
   281 void TVtUiStateStarting::HandleCLIReceivedL()
       
   282     {
       
   283     __VTPRINTENTER( "TVtUiStateStarting.HandleCLIReceivedL" )
       
   284     const MVtEngSessionInfo& session = iCtx.Model().Session();
       
   285     MVtEngSessionInfo::TCLI cli;
       
   286     if ( session.GetCLI( cli ) == KErrNone )
       
   287         {
       
   288         iUiStates.SetDetailsReceived( ETrue );
       
   289         iUiStates.SetCLIReceived( cli.iVoiceCallPossible );
       
   290         iCtx.SetCallIdL( cli.iCallId );
       
   291         iCtx.SetCallNameL( cli.iName );
       
   292         }
       
   293     CheckPhase2StartupL( EWaitingCLI );
       
   294     __VTPRINTEXIT( "TVtUiStateStarting.HandleCLIReceivedL" )
       
   295     }
       
   296 
       
   297 // -----------------------------------------------------------------------------
       
   298 // TVtUiStateStarting::Close
       
   299 // -----------------------------------------------------------------------------
       
   300 //
       
   301 void TVtUiStateStarting::Close()
       
   302     {
       
   303     __VTPRINTENTER( "TVtUiStateStarting.Close" )
       
   304     if ( TVtUiStateStarting::iInstance )
       
   305         {
       
   306         delete TVtUiStateStarting::iInstance;
       
   307         TVtUiStateStarting::iInstance = NULL;
       
   308         }
       
   309     __VTPRINTEXIT( "TVtUiStateStarting.Close" )
       
   310     }