utilities/aristatemachine/inc/aristatemachine.h
changeset 0 bb31fbe78861
equal deleted inserted replaced
-1:000000000000 0:bb31fbe78861
       
     1 /*
       
     2 * Copyright (c) 2009 Aricent and/or its subsidiary(-ies).
       
     3 * All rights reserved.
       
     4 * This component and the accompanying materials are made available
       
     5 * under the terms of the License "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 * Aricent - initial contribution.
       
    11 *
       
    12 * Contributors:
       
    13 *
       
    14 * Description:
       
    15 * State machine for all video hwdevice plugins.
       
    16 *
       
    17 */
       
    18 
       
    19 #ifndef ARISTATEMACHINE_H
       
    20 #define ARISTATEMACHINE_H
       
    21 
       
    22 #include <e32base.h>
       
    23 
       
    24 #include "ariprint.h"
       
    25 
       
    26 
       
    27 // Constants
       
    28 const TUint KNumOfStates    = 13;
       
    29 const TUint	KNumOfCommands	= 8;
       
    30 
       
    31 class CStateMachine : public CBase
       
    32 {
       
    33 public:
       
    34 	/**
       
    35      * All the states of the state machine.
       
    36 	 */
       
    37 	enum TState
       
    38 		{
       
    39 		EUnInitialized = 0,
       
    40 		EInitializing,
       
    41 		EInitialized,
       
    42 		EStart,
       
    43 		EPause,
       
    44 		EStop,
       
    45 		EInitializedInStopping,
       
    46 		EStopping,
       
    47 		EPauseInStopping,
       
    48 		EStopInInputEnd,
       
    49 		EInitializedDeadState,
       
    50 		ENonInitializedDeadState,
       
    51 		EInvalidState
       
    52 		};
       
    53 	/**
       
    54      * Commands that are given to state machine
       
    55 	 */
       
    56 	enum TCommand
       
    57 		{
       
    58 		EInitializeCommand = 0 ,
       
    59 		EInitializingCommand,
       
    60 		EStartCommand,
       
    61 		EPauseCommand,
       
    62 		EResumeCommand,
       
    63 		EInputEndCommand,
       
    64 		EStopCommand,
       
    65 		EDeadStateCommand
       
    66 		};
       
    67 
       
    68 public:
       
    69 
       
    70 	/**
       
    71 	 *Constructor. State will be in EUnInitialized
       
    72 	 *
       
    73 	 *@param	"None"
       
    74 	 *@leave	"None"
       
    75 	 *@return	"None"
       
    76 	 */
       
    77 	IMPORT_C static CStateMachine* NewL();
       
    78 
       
    79 	/**
       
    80 	 *Checks whether transition to new state is possible or not
       
    81 	 *
       
    82 	 *@param	"aCommand"	"Command for the transition"
       
    83 	 *@leave	"None"
       
    84 	 *@return	"Return ETrue if transition is valid, else EFalse
       
    85 	 */
       
    86 	IMPORT_C TBool	IsTransitionValid (TCommand aCommand);
       
    87 
       
    88 	/**
       
    89 	 *Transits to new state. If transition cann't be done, object will
       
    90 	 *remain in the previous state.
       
    91 	 *
       
    92 	 *@param	"aCommand"	"Command for the transition"
       
    93 	 *@return	"Return KErrNone if transition happens else error.
       
    94 	 */
       
    95 	IMPORT_C TInt	Transit (TCommand aCommand);
       
    96 
       
    97 	/**
       
    98 	 *Tells whether the state is initialized or not. Here initilized means
       
    99 	 *if the state is in any state other than EUnInitialized
       
   100 	 *
       
   101 	 *@param	"None"
       
   102 	 *@return	"Return ETrue, if state is initialized else EFalse.
       
   103 	 */
       
   104 	IMPORT_C TBool	IsInitialized ();
       
   105 
       
   106 	/**
       
   107 	 *Tells whether the state is exactly in EInitialized state or not.
       
   108 	 *
       
   109 	 *@param	"None"
       
   110 	 *@return	Return ETrue, if in EInitialized state else EFalse.
       
   111 	 */
       
   112     IMPORT_C TBool IsInInitializedState ();
       
   113 
       
   114 	/**
       
   115 	 *Tells whether the state is in initializing state or not.
       
   116 	 *
       
   117 	 *@param	"None"
       
   118 	 *@return	"Return ETrue, if state is initializing else EFalse.
       
   119 	 */
       
   120 	IMPORT_C TBool	IsInitializing ();
       
   121 
       
   122 	/**
       
   123 	 *Tells whether the state is in any one of the input ending states i.e
       
   124 	 *	EInitializedInStopping,
       
   125 	 *	EStopping,
       
   126 	 *	EPauseInStopping,
       
   127 	 *	EStopInInputEnd
       
   128 	 *
       
   129 	 *
       
   130 	 *@param	None
       
   131 	 *@return	Return ETrue, if state is in any of inputend state else EFalse
       
   132 	 */
       
   133 	IMPORT_C TBool	IsInputEndPending ();
       
   134 
       
   135 	/**
       
   136 	 *Tells whether state is in EStart state
       
   137 	 *
       
   138 	 *@param	"None"
       
   139 	 *@return	"Return ETrue if state is EStart, elase EFalse
       
   140 	 */
       
   141 	IMPORT_C TBool	IsStarted ();
       
   142 
       
   143 	/**
       
   144 	 *Tells whether state is in EPause state
       
   145 	 *
       
   146 	 *@param	"None"
       
   147 	 *@return	"Return ETrue if state is EPause, elase EFalse
       
   148 	 */
       
   149 	IMPORT_C TBool	IsPaused ();
       
   150 
       
   151 	/**
       
   152 	 *Tells whether state is in EStop state
       
   153 	 *
       
   154 	 *@param	"None"
       
   155 	 *@return	"Return ETrue if state is EStop, elase EFalse
       
   156 	 */
       
   157 	IMPORT_C TBool	IsStopped ();
       
   158 
       
   159 	/**
       
   160 	 *Tells whether state is in EPlaying state
       
   161 	 *
       
   162 	 *@param	"None"
       
   163 	 *@return	"Return ETrue if state is EPlaying, elase EFalse
       
   164 	 */
       
   165 	IMPORT_C TBool	IsPlaying ();
       
   166 
       
   167 	/**
       
   168 	 *Tells whether state is in EInitializedDeadState/ENonInitializedDeadState
       
   169 	 *state
       
   170 	 *
       
   171 	 *@param	"None"
       
   172 	 *@return	"Return ETrue if state is
       
   173 	 *           Return EInitializedDeadState/ENonInitializedDeadState,
       
   174 	 *           elase EFalse"
       
   175 	 */
       
   176 	IMPORT_C TBool	IsInDeadState ();
       
   177 
       
   178 	/**
       
   179 	 *Resets the state machine to EUnInitialized state
       
   180 	 *
       
   181 	 *@param	"None"
       
   182 	 *@return	"None"
       
   183 	 */
       
   184 	IMPORT_C void	Reset();
       
   185 
       
   186 	/**
       
   187 	 * Returns whether the current state is in initailize or not
       
   188 	 *
       
   189 	 *@return	"ETrue if current state is in Initailize"
       
   190 	 */
       
   191 	IMPORT_C TBool IfIsStateInInitailize();
       
   192 
       
   193 
       
   194 	/**
       
   195 	 * Destructor of the statemachine
       
   196 	 *
       
   197 	 *@return	"None"
       
   198 	 */
       
   199 	~CStateMachine();
       
   200 
       
   201 private:
       
   202 
       
   203 	/**
       
   204 	 *Symbian 2nd phase constructor
       
   205 	 *@return	"None"
       
   206 	 */
       
   207 	void ConstructL();
       
   208 
       
   209     /**
       
   210 	 *Default Constructor
       
   211 	 */
       
   212 	CStateMachine();
       
   213 
       
   214 private:
       
   215 	//Stores the state of the state machine
       
   216 	TState			iState;
       
   217 
       
   218 	TState			iStateChanges[KNumOfStates][KNumOfCommands];
       
   219 };
       
   220 
       
   221 #endif // ARISTATEMACHINE_H
       
   222