accessoryservices/pluggeddisplay/pluggeddisplayengine/src/compositecablestatusfsm.cpp
changeset 0 4e1aa6a622a0
equal deleted inserted replaced
-1:000000000000 0:4e1aa6a622a0
       
     1 /*
       
     2 * Copyright (c) 2009 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:  Finite State Machine class for Composite Cable Status.
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 #include "pdeconstants.h"
       
    20 #include "accessoryconnectionif.h"
       
    21 #include "compositecablestateidle.h"
       
    22 #include "compositecablestateconnected.h"
       
    23 #include "compositecablestatusfsm.h"
       
    24 #include "trace.h"
       
    25 #include <centralrepository.h>
       
    26 #include <accessoriescrkeys.h>
       
    27 #include <tvoutconfig.h>
       
    28 
       
    29 
       
    30 // ======== LOCAL FUNCTIONS ========
       
    31 
       
    32 
       
    33 // ======== MEMBER FUNCTIONS ========
       
    34 
       
    35 
       
    36 // ---------------------------------------------------------------------------
       
    37 // Symbian two-phased constructor
       
    38 // ---------------------------------------------------------------------------
       
    39 //
       
    40 CCompositeCableStatusFSM* CCompositeCableStatusFSM::NewL(
       
    41         RAccessoryServer& aAccessoryServer, CPDEngine *aPdEngine )
       
    42     {
       
    43     FUNC_LOG;
       
    44     CCompositeCableStatusFSM* self = new ( ELeave ) CCompositeCableStatusFSM();
       
    45     CleanupStack::PushL( self );
       
    46     self->ConstructL( aAccessoryServer, aPdEngine );
       
    47     CleanupStack::Pop( self );    
       
    48     return self;
       
    49     }
       
    50 
       
    51 // ---------------------------------------------------------------------------
       
    52 // Destructor
       
    53 // ---------------------------------------------------------------------------
       
    54 //
       
    55 CCompositeCableStatusFSM::~CCompositeCableStatusFSM()
       
    56     {
       
    57     FUNC_LOG;
       
    58     iCurrentStateId = ECompositeCableStateUndefined;
       
    59     if ( iAccessoryConnectionIf )
       
    60         {
       
    61         iAccessoryConnectionIf->Cancel();
       
    62         delete iAccessoryConnectionIf;
       
    63         }
       
    64     if ( iTVOutConfigForComposite )
       
    65         {
       
    66         iTVOutConfigForComposite->Cancel();
       
    67         delete iTVOutConfigForComposite;
       
    68         }
       
    69     // Delete state objects
       
    70     for (TInt i = 0; i < ECompositeCableStateMaxValue; i++ )
       
    71         {
       
    72         delete iStateArray[i];
       
    73         }   
       
    74     }
       
    75 
       
    76 
       
    77 // ---------------------------------------------------------------------------
       
    78 // From MFSMForBody.
       
    79 // ---------------------------------------------------------------------------
       
    80 //
       
    81 void CCompositeCableStatusFSM::Start()
       
    82     {
       
    83     FUNC_LOG;
       
    84     // Step to the initial state.
       
    85     iCurrentStateId = ECompositeCableStateIdle;
       
    86     iStateArray[iCurrentStateId]->Enter();
       
    87     }
       
    88 
       
    89 
       
    90 // ---------------------------------------------------------------------------
       
    91 // From MFSMForBody.
       
    92 // ---------------------------------------------------------------------------
       
    93 //
       
    94 TFSMId CCompositeCableStatusFSM::FSMID()
       
    95     {
       
    96     FUNC_LOG;
       
    97     TFSMId aFSMID( EPDEFSMIdCompositeCableStatus );
       
    98     return aFSMID;    
       
    99     }
       
   100 
       
   101 // ---------------------------------------------------------------------------
       
   102 // From MFSMForBody.
       
   103 // ---------------------------------------------------------------------------
       
   104 //
       
   105 TFSMState CCompositeCableStatusFSM::CurrentStateID()
       
   106     {
       
   107     FUNC_LOG;
       
   108     TFSMState currentState( ECompositeCableStateUndefined );
       
   109     if ( ( 0 <= iCurrentStateId ) && 
       
   110             ( ECompositeCableStateMaxValue > iCurrentStateId ))
       
   111         {
       
   112         currentState = iCurrentStateId;
       
   113         }
       
   114     INFO_1( "iCurrentStateId: %i", iCurrentStateId );
       
   115     return currentState;
       
   116     }
       
   117 
       
   118 
       
   119 //------------------------------------------------------------------------------
       
   120 // From MPdeFSM.
       
   121 //------------------------------------------------------------------------------
       
   122 //
       
   123 TBool CCompositeCableStatusFSM::ProcessCommandL( const TProcessCmdId /*aCommand*/,
       
   124     const TASYCmdParams& /* aCmdParams*/,
       
   125     MPDAsyCmdHandler& /*aAsyCmdHandler*/ )
       
   126     {
       
   127     FUNC_LOG;
       
   128     TBool commandHandled( EFalse );
       
   129     // Current implementation does not receive/accept any ASY commands.
       
   130     return commandHandled;
       
   131     }
       
   132 
       
   133 //------------------------------------------------------------------------------
       
   134 //  From MPdeFSM.
       
   135 //------------------------------------------------------------------------------
       
   136 //
       
   137 TInt CCompositeCableStatusFSM::GetAccPolGenericID( TAccPolGenericID& aAccPolGenericID )
       
   138     {
       
   139     FUNC_LOG;
       
   140     return iAccessoryConnectionIf->GetAccPolGenericID( aAccPolGenericID );
       
   141     }
       
   142 
       
   143 
       
   144 // ---------------------------------------------------------------------------
       
   145 // From MFSMForBody.
       
   146 // ---------------------------------------------------------------------------
       
   147 //
       
   148 void CCompositeCableStatusFSM::Input(
       
   149         TFSMInterfaceId aInterfaceId ,
       
   150         TFSMEventId aEvent )
       
   151     {
       
   152     FUNC_LOG;
       
   153     if ( ECompositeCableStateUndefined != iCurrentStateId )
       
   154         {
       
   155         if ( NULL != iStateArray[iCurrentStateId] )
       
   156             {
       
   157             iStateArray[iCurrentStateId]->Input( aInterfaceId, aEvent );
       
   158             }
       
   159         }  
       
   160     }
       
   161 
       
   162 // ---------------------------------------------------------------------------
       
   163 // From MFSMForBody.
       
   164 // ---------------------------------------------------------------------------
       
   165 //
       
   166 MFSMState* CCompositeCableStatusFSM::CurrentState()
       
   167     {
       
   168     FUNC_LOG;
       
   169     MFSMState* currentState( NULL );
       
   170     if (    ( 0 <= iCurrentStateId ) && 
       
   171             ( ECompositeCableStateMaxValue > iCurrentStateId ))
       
   172         {
       
   173         currentState = iStateArray[iCurrentStateId];
       
   174         }
       
   175     return currentState;
       
   176     }
       
   177 
       
   178 // ---------------------------------------------------------------------------
       
   179 // From MFSMForBody.
       
   180 // ---------------------------------------------------------------------------
       
   181 //
       
   182 TPtrC CCompositeCableStatusFSM::CurrentStateName()
       
   183     {
       
   184     FUNC_LOG;
       
   185     TPtrC currentStateName;
       
   186     currentStateName.Set( KNullDesC );
       
   187     if ( ( 0 <= iCurrentStateId ) && 
       
   188          ( ECompositeCableStateMaxValue > iCurrentStateId ))
       
   189         {
       
   190         if ( NULL != iStateArray[iCurrentStateId] )
       
   191              {
       
   192              currentStateName.Set( iStateArray[iCurrentStateId]->Name() );
       
   193              }
       
   194         }
       
   195     return currentStateName;
       
   196     }
       
   197 
       
   198 // ---------------------------------------------------------------------------
       
   199 // From MFSMForBody.
       
   200 // ---------------------------------------------------------------------------
       
   201 //
       
   202 TFSMMainAndSubState CCompositeCableStatusFSM::CurrentMainAndSubstateIDs()
       
   203     {
       
   204     FUNC_LOG;
       
   205     TFSMMainAndSubState state;
       
   206     state.iMainState = ECompositeCableStateUndefined;
       
   207     state.iSubstate = 0;
       
   208     if ( ( 0 <= iCurrentStateId ) && 
       
   209             ( ECompositeCableStateMaxValue > iCurrentStateId ))
       
   210         {
       
   211         state.iMainState = iCurrentStateId;
       
   212         state.iSubstate = iStateArray[iCurrentStateId]->SubId();
       
   213         }
       
   214     INFO_2( "Main state id: %i, substate id: %i", state.iMainState, state.iSubstate );
       
   215     return state;
       
   216     }
       
   217 
       
   218 // ---------------------------------------------------------------------------
       
   219 // From MFSMForState.
       
   220 // ---------------------------------------------------------------------------
       
   221 //
       
   222 TBool CCompositeCableStatusFSM::Transit( TFSMState aNextState )
       
   223     {
       
   224     FUNC_LOG;
       
   225     TBool retVal(EFalse);
       
   226     if ( (  0 <= aNextState ) && 
       
   227          (  ECompositeCableStateMaxValue > aNextState ) )
       
   228         {
       
   229         iCurrentStateId = aNextState;
       
   230         if ( NULL != iStateArray[iCurrentStateId])
       
   231             {
       
   232             retVal = ETrue;
       
   233             iStateArray[iCurrentStateId]->Enter();
       
   234             }
       
   235         }
       
   236     if ( EFalse == retVal )
       
   237         {
       
   238         //Something is wrong
       
   239         INFO("Incorrect nextstate");
       
   240         }   
       
   241     INFO_1("TBool retVal %i", retVal);
       
   242     return retVal;
       
   243     }
       
   244 
       
   245 // ---------------------------------------------------------
       
   246 // C++ constructor
       
   247 // ---------------------------------------------------------
       
   248 //
       
   249 CCompositeCableStatusFSM::CCompositeCableStatusFSM()
       
   250     {
       
   251     FUNC_LOG;
       
   252     }
       
   253 
       
   254 
       
   255 // ---------------------------------------------------------
       
   256 // ConstructL
       
   257 // ---------------------------------------------------------
       
   258 //
       
   259 void CCompositeCableStatusFSM::ConstructL(
       
   260         RAccessoryServer& aAccessoryServer, CPDEngine *aPdEngine )
       
   261     {
       
   262     FUNC_LOG;
       
   263     
       
   264     iPdEngine = aPdEngine;    
       
   265     
       
   266     // Create interface objecs
       
   267     iAccessoryConnectionIf = CAccessoryConnectionIf::NewL( *this, aAccessoryServer );
       
   268     iTVOutConfigForComposite = CTVOutConfigForComposite::NewL( *this );
       
   269 
       
   270     // Create state objects here.
       
   271     iStateArray[ ECompositeCableStateIdle ] = CCompositeCableStateIdle::NewL( *this );
       
   272     iStateArray[ ECompositeCableStateConnected ] = CCompositeCableStateConnected::NewL( *this, *iTVOutConfigForComposite, *this );
       
   273     }
       
   274 
       
   275 // ======== GLOBAL FUNCTIONS ========
       
   276