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