Salome HOME
NRI : First integration.
[modules/superv.git] / src / GraphExecutor / DataFlowExecutor_FiniteStateMachine.hxx
1 //=============================================================================
2 // File      : DataFlowBase_FiniteStateMachine.hxx
3 // Created   : 2002
4 // Author    : Jean Rahuel, CEA
5 // Project   : SALOME
6 // $Header:
7 //=============================================================================
8
9 #ifndef _DATAFLOWEXECUTOR_FINITESTATEMACHINE
10 #define _DATAFLOWEXECUTOR_FINITESTATEMACHINE
11
12 #include <stdlib.h>
13 #include <iostream>
14 #include <unistd.h>
15 #include <stdio.h>
16
17 #include "DataFlowBase_Base.hxx"
18
19 #include <SALOMEconfig.h>
20 //#include CORBA_SERVER_HEADER(SUPERV)
21 #include <SALOME_LifeCycleCORBA.hxx>
22
23 namespace GraphExecutor {
24
25   enum NodeEvent { UndefinedEvent , NewThreadEvent ,
26                      SuspendEvent , ToResumeEvent  , ResumeEvent ,
27                      KillEvent , StopEvent ,
28                      ExecuteEvent , SuccessEvent , ErrorEvent ,
29                      ToReStartEvent , ReStartEvent , ReStartAndSuspendEvent ,
30                      EndExecuteEvent ,
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 ,
43                      NumberOfEvents } ;
44
45   enum StateEventAction { ErrorAction ,
46                           VoidAction ,
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 ,
64                           Errored_ErrorAction ,
65                           Successed_SuspendAction ,
66                           Errored_SuspendAction ,
67                           SuspendedSuccessed_ResumeAction ,
68                           SuspendedErrored_ResumeAction ,
69                           Successed_KillAction ,
70                           Errored_KillAction ,
71                           Successed_StopAction ,
72                           Errored_StopAction ,
73                             SuspendedSuccessed_ReStartAction ,
74                             SuspendedErrored_ReStartAction ,
75                             SuspendedSuccessed_ReStartAndSuspendAction ,
76                             SuspendedErrored_ReStartAndSuspendAction ,
77                           NumberOfActions } ;
78
79   class FiniteStateMachine {
80
81     private :
82
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 ] ;
92
93       bool              _JoinThread ;
94       pthread_t         _JoinThreadNo ;
95       pthread_mutex_t   _MutexJoinWait ;
96       pthread_cond_t    _JoinWait ;
97       list< pthread_t > _ThreadList ;
98
99     public :
100
101       FiniteStateMachine() ;
102       virtual ~FiniteStateMachine() {} ;
103
104       void JoinThread() ;
105       void JoinThread( pthread_t aThread ) ;
106
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 ] ; } ;
122
123       const SUPERV::AutomatonState NextState(
124             const SUPERV::AutomatonState & aState ,
125             const GraphExecutor::NodeEvent & anEvent ) const {
126             return _TransitionTable[ aState ][ anEvent ] ; } ;
127
128       const GraphExecutor::StateEventAction NextAction(
129             const SUPERV::AutomatonState & aState ,
130             const GraphExecutor::NodeEvent & anEvent ) const {
131             return _ActionTable[ aState ][ anEvent ] ; } ;
132   };
133
134 };
135
136 #endif