1 // SUPERV GraphExecutor : contains classes that permit execution of graphs and particularly the execution automaton
3 // Copyright (C) 2003 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
6 // This library is free software; you can redistribute it and/or
7 // modify it under the terms of the GNU Lesser General Public
8 // License as published by the Free Software Foundation; either
9 // version 2.1 of the License.
11 // This library is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 // Lesser General Public License for more details.
16 // You should have received a copy of the GNU Lesser General Public
17 // License along with this library; if not, write to the Free Software
18 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20 // See http://www.opencascade.org/SALOME/ or email : webmaster.salome@opencascade.org
24 // File : DataFlowBase_FiniteStateMachine.hxx
25 // Author : Jean Rahuel, CEA
29 #ifndef _DATAFLOWEXECUTOR_FINITESTATEMACHINE
30 #define _DATAFLOWEXECUTOR_FINITESTATEMACHINE
42 #include "DataFlowBase_Base.hxx"
44 #include <SALOMEconfig.h>
45 //#include CORBA_SERVER_HEADER(SUPERV)
46 #include <SALOME_LifeCycleCORBA.hxx>
52 namespace GraphExecutor {
54 //The AutomatonState is an internal state of the automaton of the Executor
55 enum AutomatonState { UnKnownState ,
60 SuspendedReadyToResumeState ,
65 SuspendedExecutingState ,
66 ResumedExecutingState ,
67 KilledExecutingState ,
68 StoppedExecutingState ,
69 SuccessedExecutingState ,
70 ErroredExecutingState ,
71 SuspendedSuccessedState ,
72 SuspendedErroredState,
73 ResumedSuccessedState ,
75 KilledSuccessedState ,
77 StoppedSuccessedState ,
84 SuspendedSuccessedToReStartState ,
85 SuspendedErroredToReStartState ,
89 NumberOfAutomatonStates } ;
91 enum NodeEvent { UndefinedEvent , NewThreadEvent ,
92 SuspendEvent , ToResumeEvent , ResumeEvent ,
93 KillEvent , StopEvent ,
94 ExecuteEvent , SuccessEvent , ErrorEvent ,
95 ToReStartEvent , ReStartEvent , ReStartAndSuspendEvent ,
97 NoDataReadyEvent , SomeDataReadyEvent ,
98 NotAllDataReadyEvent , AllDataReadyEvent ,
99 ReadyEvent , SuspendedReadyEvent ,ResumedReadyEvent ,
100 KilledReadyEvent , StoppedReadyEvent ,
101 ExecutingEvent , SuspendedExecutingEvent ,
102 ResumedExecutingEvent , KilledExecutingEvent ,
103 StoppedExecutingEvent ,
104 SuccessedExecutingEvent , ErroredExecutingEvent ,
105 SuspendedSuccessedEvent , SuspendedErroredEvent ,
106 ResumedSuccessedEvent , ResumedErroredEvent ,
107 KilledEvent , StoppedEvent ,
108 ReStartedEvent , ReStartedAndSuspendEvent ,
111 enum StateEventAction { ErrorAction ,
113 executeAction , // +- pthread_create
114 ExecuteAction , // +- pthread_create
115 DataWaiting_SomeDataReadyAction ,
116 DataUndef_NotAllDataReadyAction ,
117 DataUndef_AllDataReadyAction ,
118 DataReady_SuspendAction ,
119 SuspendedReady_ResumeAction ,
120 DataReady_KillAction ,
121 DataReady_StopAction ,
122 DataReady_ExecuteAction ,
123 Executing_SuspendAction ,
124 SuspendedExecuting_ResumeAction ,
125 Executing_KillAction ,
126 Executing_StopAction ,
127 Executing_SuccessAction ,
128 Executing_ErrorAction ,
129 Successed_SuccessAction ,
130 Errored_ErrorAction ,
131 Successed_SuspendAction ,
132 Errored_SuspendAction ,
133 SuspendedSuccessed_ResumeAction ,
134 SuspendedErrored_ResumeAction ,
135 Successed_KillAction ,
137 Successed_StopAction ,
139 SuspendedSuccessed_ReStartAction ,
140 SuspendedErrored_ReStartAction ,
141 SuspendedSuccessed_ReStartAndSuspendAction ,
142 SuspendedErrored_ReStartAndSuspendAction ,
145 class FiniteStateMachine {
149 char * _ControlStateName[ SUPERV::NumberOfControlStates ] ;
150 char * _StateName[ GraphExecutor::NumberOfAutomatonStates ] ;
151 char * _GraphStateName[ SUPERV::NumberOfGraphStates ] ;
152 char * _EventName[ GraphExecutor::NumberOfEvents ] ;
153 char * _ActionName[ NumberOfActions ] ;
154 GraphExecutor::AutomatonState _TransitionTable[ GraphExecutor::NumberOfAutomatonStates ]
155 [ GraphExecutor::NumberOfEvents ] ;
156 GraphExecutor::StateEventAction _ActionTable[ GraphExecutor::NumberOfAutomatonStates ]
157 [ GraphExecutor::NumberOfEvents ] ;
159 pthread_mutex_t _MutexPythonWait ;
160 bool _MutexPythonLocked ;
161 map< string , PyObject * > _MapOfPyFunctions ;
164 int _GraphExecutingNumber ;
168 // fields and methods that use them are moved to GraphEditor::OutNode class (asv 20.09.04)
169 //map< string , GraphBase::Graph * > _MapOfGraphs ;
170 //map< string , int > _MapOfGraphNames ;
173 pthread_t _JoinThreadNo ;
174 pthread_mutex_t _MutexJoinWait ;
175 pthread_cond_t _JoinWait ;
176 list< pthread_t > _ThreadList ;
180 FiniteStateMachine() ;
181 virtual ~FiniteStateMachine() {} ;
185 void PyInitModule(bool) ;
186 bool PyInitModule() ;
190 bool PyFunction( const char * aPyFuncName , PyObject * aPyFunction ) ;
191 PyObject * PyFunction( const char * aPyFuncName ) ;
194 string DbgFileNumber() {
195 _DbgFileNumber += 1 ;
197 astr << _DbgFileNumber ;
198 return astr.str() ; } ;
200 GraphBase::Graph * MapGraph( const char * aGraphName ) ;
201 bool MapGraph( GraphBase::Graph * aGraph , const char * aGraphName ) ;
202 void EraseGraph( const char * aGraphName ) ;
203 bool GraphName( const char * aGraphName ) ;
204 string GraphInstanceName( const char * aGraphName ) ;
208 void JoinThread( pthread_t aThread ) ;
210 const char * ControlStateName( const SUPERV::ControlState & aState ) const {
211 return _ControlStateName[ aState ] ; } ;
212 const char * StateName( const GraphExecutor::AutomatonState & aState ) const {
213 return _StateName[ aState ] ; } ;
214 const char * StateName( const SUPERV::GraphState & aState ) const {
215 return _GraphStateName[ aState ] ; } ;
216 const char * EventName( const GraphExecutor::NodeEvent & anEvent ) const {
217 return _EventName[ anEvent ] ; } ;
218 const char * ActionName( const GraphExecutor::StateEventAction & anAction ) const {
219 return _ActionName[ anAction ] ; } ;
221 const GraphExecutor::AutomatonState NextState( const GraphExecutor::AutomatonState & aState ,
222 const GraphExecutor::NodeEvent & anEvent ) const {
223 return _TransitionTable[ aState ][ anEvent ] ; } ;
225 const GraphExecutor::StateEventAction NextAction( const GraphExecutor::AutomatonState & aState ,
226 const GraphExecutor::NodeEvent & anEvent ) const {
227 return _ActionTable[ aState ][ anEvent ] ; } ;
232 ostream & operator<< (ostream &f ,const GraphExecutor::AutomatonState & aState ) ;