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>
54 namespace GraphExecutor {
56 //The AutomatonState is an internal state of the automaton of the Executor
57 enum AutomatonState { UnKnownState ,
62 SuspendedReadyToResumeState ,
67 SuspendedExecutingState ,
68 ResumedExecutingState ,
69 KilledExecutingState ,
70 StoppedExecutingState ,
71 SuccessedExecutingState ,
72 ErroredExecutingState ,
73 SuspendedSuccessedState ,
74 SuspendedErroredState,
75 ResumedSuccessedState ,
77 KilledSuccessedState ,
79 StoppedSuccessedState ,
86 SuspendedSuccessedToReStartState ,
87 SuspendedErroredToReStartState ,
90 NumberOfAutomatonStates } ;
92 enum NodeEvent { UndefinedEvent ,
104 ReStartAndSuspendEvent ,
108 NotAllDataReadyEvent ,
111 SuspendedReadyEvent ,
116 SuspendedExecutingEvent ,
117 ResumedExecutingEvent ,
118 KilledExecutingEvent ,
119 StoppedExecutingEvent ,
120 SuccessedExecutingEvent ,
121 ErroredExecutingEvent ,
122 SuspendedSuccessedEvent ,
123 SuspendedErroredEvent ,
124 ResumedSuccessedEvent ,
125 ResumedErroredEvent ,
129 ReStartedAndSuspendEvent ,
132 enum StateEventAction { ErrorAction ,
134 executeAction , // +- pthread_create
135 ExecuteAction , // +- pthread_create
136 DataWaiting_SomeDataReadyAction ,
137 DataUndef_NotAllDataReadyAction ,
138 DataUndef_AllDataReadyAction ,
139 DataReady_SuspendAction ,
140 SuspendedReady_ResumeAction ,
141 DataReady_KillAction ,
142 DataReady_StopAction ,
143 DataReady_ExecuteAction ,
144 Executing_SuspendAction ,
145 SuspendedExecuting_ResumeAction ,
146 Executing_KillAction ,
147 Executing_StopAction ,
148 Executing_SuccessAction ,
149 // Executing_ErrorAction ,
150 Errored_ExecutingAction ,
151 Successed_SuccessAction ,
152 Errored_ErrorAction ,
153 Successed_SuspendAction ,
154 Errored_SuspendAction ,
155 SuspendedSuccessed_ResumeAction ,
156 SuspendedErrored_ResumeAction ,
157 Successed_KillAction ,
159 Successed_StopAction ,
161 SuspendedSuccessed_ReStartAction ,
162 SuspendedErrored_ReStartAction ,
163 SuspendedSuccessed_ReStartAndSuspendAction ,
164 SuspendedErrored_ReStartAndSuspendAction ,
167 class FiniteStateMachine {
171 char * _ControlStateName[ SUPERV::NumberOfControlStates ] ;
172 char * _StateName[ GraphExecutor::NumberOfAutomatonStates ] ;
173 char * _GraphStateName[ SUPERV::NumberOfGraphStates ] ;
174 char * _EventName[ GraphExecutor::NumberOfEvents ] ;
175 char * _ActionName[ NumberOfActions ] ;
176 GraphExecutor::AutomatonState _TransitionTable[ GraphExecutor::NumberOfAutomatonStates ]
177 [ GraphExecutor::NumberOfEvents ] ;
178 GraphExecutor::StateEventAction _ActionTable[ GraphExecutor::NumberOfAutomatonStates ]
179 [ GraphExecutor::NumberOfEvents ] ;
181 pthread_mutex_t _MutexPythonWait ;
182 bool _MutexPythonLocked ;
183 // Map between FuncName and corresponding Python Object Function
184 map< string , PyObject * > _MapOfPyFunctions ;
187 int _GraphExecutingNumber ;
191 // fields and methods that use them are moved to GraphEditor::OutNode class (asv 20.09.04)
192 //map< string , GraphBase::Graph * > _MapOfGraphs ;
193 //map< string , int > _MapOfGraphNames ;
196 pthread_t _JoinThreadNo ;
197 pthread_mutex_t _MutexJoinWait ;
198 pthread_cond_t _JoinWait ;
199 list< pthread_t > _ThreadList ;
201 Graph_Impl * _GraphImpl ;
205 FiniteStateMachine() ;
206 virtual ~FiniteStateMachine() {} ;
210 void PyInitModule(bool) ;
211 bool PyInitModule() ;
215 bool PyFunction( const char * aPyFuncName , PyObject * aPyFunction ) ;
216 PyObject * PyFunction( const char * aPyFuncName ) ;
217 bool ErasePyFunction( const char * aPyFuncName ) ;
220 string DbgFileNumber() {
221 _DbgFileNumber += 1 ;
223 astr << _DbgFileNumber ;
224 return astr.str() ; } ;
226 GraphBase::Graph * MapGraph( const char * aGraphName ) ;
227 bool MapGraph( GraphBase::Graph * aGraph , const char * aGraphName ) ;
228 void EraseGraph( const char * aGraphName ) ;
229 bool GraphName( const char * aGraphName ) ;
230 string GraphInstanceName( const char * aGraphName ) ;
234 void JoinThread( pthread_t aThread ) ;
236 const char * ControlStateName( const SUPERV::ControlState & aState ) const {
237 return _ControlStateName[ aState ] ; } ;
238 const char * StateName( const GraphExecutor::AutomatonState & aState ) const {
239 return _StateName[ aState ] ; } ;
240 const char * StateName( const SUPERV::GraphState & aState ) const {
241 return _GraphStateName[ aState ] ; } ;
242 const char * EventName( const GraphExecutor::NodeEvent & anEvent ) const {
243 return _EventName[ anEvent ] ; } ;
244 const char * ActionName( const GraphExecutor::StateEventAction & anAction ) const {
245 return _ActionName[ anAction ] ; } ;
247 const GraphExecutor::AutomatonState NextState( const GraphExecutor::AutomatonState & aState ,
248 const GraphExecutor::NodeEvent & anEvent ) const {
249 return _TransitionTable[ aState ][ anEvent ] ; } ;
251 const GraphExecutor::StateEventAction NextAction( const GraphExecutor::AutomatonState & aState ,
252 const GraphExecutor::NodeEvent & anEvent ) const {
253 return _ActionTable[ aState ][ anEvent ] ; } ;
255 void GraphImpl( Graph_Impl * aGraphImpl ) {// For GraphMNode ...
256 _GraphImpl = aGraphImpl ; } ;
257 Graph_Impl * GraphImpl() {
258 return _GraphImpl ; } ;
263 ostream & operator<< (ostream &f ,const GraphExecutor::AutomatonState & aState ) ;