1 //=============================================================================
2 // File : DataFlowBase_FiniteStateMachine.hxx
4 // Author : Jean Rahuel, CEA
7 //=============================================================================
9 #ifndef _DATAFLOWEXECUTOR_FINITESTATEMACHINE
10 #define _DATAFLOWEXECUTOR_FINITESTATEMACHINE
17 #include "DataFlowBase_Base.hxx"
19 #include <SALOMEconfig.h>
20 //#include CORBA_SERVER_HEADER(SUPERV)
21 #include <SALOME_LifeCycleCORBA.hxx>
23 namespace GraphExecutor {
25 enum NodeEvent { UndefinedEvent , NewThreadEvent ,
26 SuspendEvent , ToResumeEvent , ResumeEvent ,
27 KillEvent , StopEvent ,
28 ExecuteEvent , SuccessEvent , ErrorEvent ,
29 ToReStartEvent , ReStartEvent , ReStartAndSuspendEvent ,
31 NoDataReadyEvent , SomeDataReadyEvent ,
32 NotAllDataReadyEvent , AllDataReadyEvent ,
33 ReadyEvent , SuspendedReadyEvent ,ResumedReadyEvent ,
34 KilledReadyEvent , StoppedReadyEvent ,
35 ExecutingEvent , SuspendedExecutingEvent ,
36 ResumedExecutingEvent , KilledExecutingEvent ,
37 StoppedExecutingEvent ,
38 SuccessedExecutingEvent , ErroredExecutingEvent ,
39 SuspendedSuccessedEvent , SuspendedErroredEvent ,
40 ResumedSuccessedEvent , ResumedErroredEvent ,
41 KilledEvent , StoppedEvent ,
42 ReStartedEvent , ReStartedAndSuspendEvent ,
45 enum StateEventAction { ErrorAction ,
47 executeAction , // +- pthread_create
48 ExecuteAction , // +- pthread_create
49 DataWaiting_SomeDataReadyAction ,
50 DataUndef_NotAllDataReadyAction ,
51 DataUndef_AllDataReadyAction ,
52 DataReady_SuspendAction ,
53 SuspendedReady_ResumeAction ,
54 DataReady_KillAction ,
55 DataReady_StopAction ,
56 DataReady_ExecuteAction ,
57 Executing_SuspendAction ,
58 SuspendedExecuting_ResumeAction ,
59 Executing_KillAction ,
60 Executing_StopAction ,
61 Executing_SuccessAction ,
62 Executing_ErrorAction ,
63 Successed_SuccessAction ,
65 Successed_SuspendAction ,
66 Errored_SuspendAction ,
67 SuspendedSuccessed_ResumeAction ,
68 SuspendedErrored_ResumeAction ,
69 Successed_KillAction ,
71 Successed_StopAction ,
73 SuspendedSuccessed_ReStartAction ,
74 SuspendedErrored_ReStartAction ,
75 SuspendedSuccessed_ReStartAndSuspendAction ,
76 SuspendedErrored_ReStartAndSuspendAction ,
79 class FiniteStateMachine {
83 char * _ControlStateName[ SUPERV::NumberOfControlStates ] ;
84 char * _StateName[ SUPERV::NumberOfAutomatonStates ] ;
85 char * _GraphStateName[ SUPERV::NumberOfGraphStates ] ;
86 char * _EventName[ GraphExecutor::NumberOfEvents ] ;
87 char * _ActionName[ NumberOfActions ] ;
88 SUPERV::AutomatonState _TransitionTable[ SUPERV::NumberOfAutomatonStates ]
89 [ GraphExecutor::NumberOfEvents ] ;
90 GraphExecutor::StateEventAction _ActionTable[ SUPERV::NumberOfAutomatonStates ]
91 [ GraphExecutor::NumberOfEvents ] ;
94 pthread_t _JoinThreadNo ;
95 pthread_mutex_t _MutexJoinWait ;
96 pthread_cond_t _JoinWait ;
97 list< pthread_t > _ThreadList ;
101 FiniteStateMachine() ;
102 virtual ~FiniteStateMachine() {} ;
105 void JoinThread( pthread_t aThread ) ;
107 const char * ControlStateName(
108 const SUPERV::ControlState & aState ) const {
109 return _ControlStateName[ aState ] ; } ;
110 const char * StateName(
111 const SUPERV::AutomatonState & aState ) const {
112 return _StateName[ aState ] ; } ;
113 const char * StateName(
114 const SUPERV::GraphState & aState ) const {
115 return _GraphStateName[ aState ] ; } ;
116 const char * EventName(
117 const GraphExecutor::NodeEvent & anEvent ) const {
118 return _EventName[ anEvent ] ; } ;
119 const char * ActionName(
120 const GraphExecutor::StateEventAction & anAction ) const {
121 return _ActionName[ anAction ] ; } ;
123 const SUPERV::AutomatonState NextState(
124 const SUPERV::AutomatonState & aState ,
125 const GraphExecutor::NodeEvent & anEvent ) const {
126 return _TransitionTable[ aState ][ anEvent ] ; } ;
128 const GraphExecutor::StateEventAction NextAction(
129 const SUPERV::AutomatonState & aState ,
130 const GraphExecutor::NodeEvent & anEvent ) const {
131 return _ActionTable[ aState ][ anEvent ] ; } ;