vtengines/videoteleng/Src/State/CVtEngStateManager.cpp
changeset 0 ed9695c8bcbe
equal deleted inserted replaced
-1:000000000000 0:ed9695c8bcbe
       
     1 /*
       
     2 * Copyright (c) 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:  Implementation of state manager for session and audio routing states.
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 
       
    20 // INCLUDE FILES
       
    21 #include    "CVtEngStateManager.h"
       
    22 #include    "CVtEngHandlerContainer.h"
       
    23 #include    "CVtEngStateBase.h"
       
    24 #include    "CVtEngStateIdle.h"
       
    25 #include    "CVtEngStateOpen.h"
       
    26 #include    "CVtEngEventManager.h"
       
    27 #include    "CVtEngStateConnected.h"
       
    28 #include    "CVtEngOperation.h"
       
    29 #include    "cvtlogger.h"
       
    30 
       
    31 // ============================ MEMBER FUNCTIONS ===============================
       
    32 
       
    33 // -----------------------------------------------------------------------------
       
    34 // CVtEngStateManager::CVtEngStateManager
       
    35 // C++ constructor can NOT contain any code, that
       
    36 // might leave.
       
    37 // -----------------------------------------------------------------------------
       
    38 //
       
    39 CVtEngStateManager::CVtEngStateManager( 
       
    40     CVtEngHandlerContainer& aHandlers,
       
    41     CVtEngEventManager& aEventManager ) : 
       
    42     iPreviousSessionState( MVtEngSessionInfo::EUnknown ),
       
    43     iHandlers( aHandlers ), 
       
    44     iEventManager( aEventManager )
       
    45     {
       
    46     }
       
    47 
       
    48 // -----------------------------------------------------------------------------
       
    49 // CVtEngStateManager::ConstructL
       
    50 // Symbian 2nd phase constructor can leave.
       
    51 // -----------------------------------------------------------------------------
       
    52 //
       
    53 void CVtEngStateManager::ConstructL()
       
    54     {
       
    55     iSessionState = new ( ELeave ) 
       
    56         CVtEngStateIdle( *this, iEventManager );
       
    57     }
       
    58 
       
    59 // -----------------------------------------------------------------------------
       
    60 // CVtEngStateManager::NewL
       
    61 // Two-phased constructor.
       
    62 // -----------------------------------------------------------------------------
       
    63 //
       
    64 CVtEngStateManager* CVtEngStateManager::NewL(
       
    65     CVtEngHandlerContainer& aHandlers,
       
    66     CVtEngEventManager& aEventManager )
       
    67     {
       
    68     __VTPRINT( DEBUG_GEN , "CVtEngStateManager::NewL" )
       
    69     CVtEngStateManager* self = new ( ELeave ) 
       
    70         CVtEngStateManager( aHandlers, aEventManager );
       
    71     
       
    72     CleanupStack::PushL( self );
       
    73     self->ConstructL();
       
    74     CleanupStack::Pop();
       
    75 
       
    76     return self;
       
    77     }
       
    78 
       
    79     
       
    80 // Destructor
       
    81 CVtEngStateManager::~CVtEngStateManager()
       
    82     {
       
    83     __VTPRINT( DEBUG_GEN , "CVtEngStateManager::~" )
       
    84     delete iSessionState;
       
    85     }
       
    86 
       
    87 // -----------------------------------------------------------------------------
       
    88 // CVtEngStateManager::UpdateL
       
    89 // Updates current state.
       
    90 // 
       
    91 // -----------------------------------------------------------------------------
       
    92 //
       
    93 void CVtEngStateManager::Update( )
       
    94     {
       
    95     if ( iSessionState )
       
    96         {
       
    97         TRAPD(err,iSessionState->UpdateL());
       
    98         if ( err != KErrNone )
       
    99             {
       
   100             __VTPRINT2( DEBUG_GEN, "SM.update fail=%d", err )
       
   101             iEventManager.NotifyEvent( err );
       
   102             }
       
   103         }
       
   104     }
       
   105 
       
   106 // -----------------------------------------------------------------------------
       
   107 // CVtEngStateManager::IsCommandPossible
       
   108 // Checks if a command is possible in current state.
       
   109 // 
       
   110 // -----------------------------------------------------------------------------
       
   111 //
       
   112 TBool CVtEngStateManager::IsCommandPossible( 
       
   113             const TVtEngCommandId aCommandId ) const
       
   114     {
       
   115     if ( iSessionState )
       
   116         {
       
   117         return iSessionState->ValidateCommand( aCommandId );
       
   118         }
       
   119     return EFalse;
       
   120     }
       
   121 
       
   122 // -----------------------------------------------------------------------------
       
   123 // CVtEngStateManager::SetState
       
   124 // Sets new session state.
       
   125 // 
       
   126 // -----------------------------------------------------------------------------
       
   127 //
       
   128 void CVtEngStateManager::SetState( CVtEngStateBase& aNewState )
       
   129     {
       
   130     if( iSessionState )
       
   131         {
       
   132         iPreviousSessionState = iSessionState->State();
       
   133         }
       
   134     iSessionState = &aNewState;
       
   135     }
       
   136 
       
   137 // -----------------------------------------------------------------------------
       
   138 // CVtEngStateManager::HandleOperationL
       
   139 // 
       
   140 // 
       
   141 // -----------------------------------------------------------------------------
       
   142 //
       
   143 TBool CVtEngStateManager::HandleOperationL( CVtEngOperation& aOp )
       
   144     {
       
   145     __VTPRINT2( DEBUG_GEN, "StateMgr.HandleOp=%d", aOp.Command() )
       
   146     TInt handled( EFalse );
       
   147     if ( iSessionState )
       
   148         {
       
   149         handled = iSessionState->HandleL( aOp );
       
   150         }
       
   151     __VTPRINT2( DEBUG_GEN | DEBUG_RETURN, "StateMgr.HandleOp handled=%d", 
       
   152         handled )
       
   153     return handled;
       
   154     }
       
   155 
       
   156 // -----------------------------------------------------------------------------
       
   157 // CVtEngStateManager::SessionState
       
   158 // Returns session state.
       
   159 // 
       
   160 // -----------------------------------------------------------------------------
       
   161 //
       
   162 MVtEngSessionInfo::TSessionState CVtEngStateManager::SessionState() const
       
   163     {
       
   164     if ( iSessionState )
       
   165         {
       
   166         return iSessionState->State();
       
   167         }
       
   168     return MVtEngSessionInfo::EUnknown;
       
   169     }
       
   170 
       
   171 // -----------------------------------------------------------------------------
       
   172 // CVtEngStateManager::PreviousSessionState
       
   173 // Returns session state.
       
   174 // 
       
   175 // -----------------------------------------------------------------------------
       
   176 //
       
   177 MVtEngSessionInfo::TSessionState CVtEngStateManager::PreviousSessionState() const
       
   178     {
       
   179     return iPreviousSessionState;
       
   180     }
       
   181 
       
   182 //  End of File