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 ,
88 NumberOfAutomatonStates } ;
90 enum NodeEvent { UndefinedEvent ,
102 ReStartAndSuspendEvent ,
106 NotAllDataReadyEvent ,
109 SuspendedReadyEvent ,
114 SuspendedExecutingEvent ,
115 ResumedExecutingEvent ,
116 KilledExecutingEvent ,
117 StoppedExecutingEvent ,
118 SuccessedExecutingEvent ,
119 ErroredExecutingEvent ,
120 SuspendedSuccessedEvent ,
121 SuspendedErroredEvent ,
122 ResumedSuccessedEvent ,
123 ResumedErroredEvent ,
127 ReStartedAndSuspendEvent ,
130 enum StateEventAction { ErrorAction ,
132 executeAction , // +- pthread_create
133 ExecuteAction , // +- pthread_create
134 DataWaiting_SomeDataReadyAction ,
135 DataUndef_NotAllDataReadyAction ,
136 DataUndef_AllDataReadyAction ,
137 DataReady_SuspendAction ,
138 SuspendedReady_ResumeAction ,
139 DataReady_KillAction ,
140 DataReady_StopAction ,
141 DataReady_ExecuteAction ,
142 Executing_SuspendAction ,
143 SuspendedExecuting_ResumeAction ,
144 Executing_KillAction ,
145 Executing_StopAction ,
146 Executing_SuccessAction ,
147 Executing_ErrorAction ,
148 Successed_SuccessAction ,
149 Errored_ErrorAction ,
150 Successed_SuspendAction ,
151 Errored_SuspendAction ,
152 SuspendedSuccessed_ResumeAction ,
153 SuspendedErrored_ResumeAction ,
154 Successed_KillAction ,
156 Successed_StopAction ,
158 SuspendedSuccessed_ReStartAction ,
159 SuspendedErrored_ReStartAction ,
160 SuspendedSuccessed_ReStartAndSuspendAction ,
161 SuspendedErrored_ReStartAndSuspendAction ,
164 class FiniteStateMachine {
168 char * _ControlStateName[ SUPERV::NumberOfControlStates ] ;
169 char * _StateName[ GraphExecutor::NumberOfAutomatonStates ] ;
170 char * _GraphStateName[ SUPERV::NumberOfGraphStates ] ;
171 char * _EventName[ GraphExecutor::NumberOfEvents ] ;
172 char * _ActionName[ NumberOfActions ] ;
173 GraphExecutor::AutomatonState _TransitionTable[ GraphExecutor::NumberOfAutomatonStates ]
174 [ GraphExecutor::NumberOfEvents ] ;
175 GraphExecutor::StateEventAction _ActionTable[ GraphExecutor::NumberOfAutomatonStates ]
176 [ GraphExecutor::NumberOfEvents ] ;
178 pthread_mutex_t _MutexPythonWait ;
179 bool _MutexPythonLocked ;
180 map< string , PyObject * > _MapOfPyFunctions ;
183 int _GraphExecutingNumber ;
187 // fields and methods that use them are moved to GraphEditor::OutNode class (asv 20.09.04)
188 //map< string , GraphBase::Graph * > _MapOfGraphs ;
189 //map< string , int > _MapOfGraphNames ;
192 pthread_t _JoinThreadNo ;
193 pthread_mutex_t _MutexJoinWait ;
194 pthread_cond_t _JoinWait ;
195 list< pthread_t > _ThreadList ;
199 FiniteStateMachine() ;
200 virtual ~FiniteStateMachine() {} ;
204 void PyInitModule(bool) ;
205 bool PyInitModule() ;
209 bool PyFunction( const char * aPyFuncName , PyObject * aPyFunction ) ;
210 PyObject * PyFunction( const char * aPyFuncName ) ;
213 string DbgFileNumber() {
214 _DbgFileNumber += 1 ;
216 astr << _DbgFileNumber ;
217 return astr.str() ; } ;
219 GraphBase::Graph * MapGraph( const char * aGraphName ) ;
220 bool MapGraph( GraphBase::Graph * aGraph , const char * aGraphName ) ;
221 void EraseGraph( const char * aGraphName ) ;
222 bool GraphName( const char * aGraphName ) ;
223 string GraphInstanceName( const char * aGraphName ) ;
227 void JoinThread( pthread_t aThread ) ;
229 const char * ControlStateName( const SUPERV::ControlState & aState ) const {
230 return _ControlStateName[ aState ] ; } ;
231 const char * StateName( const GraphExecutor::AutomatonState & aState ) const {
232 return _StateName[ aState ] ; } ;
233 const char * StateName( const SUPERV::GraphState & aState ) const {
234 return _GraphStateName[ aState ] ; } ;
235 const char * EventName( const GraphExecutor::NodeEvent & anEvent ) const {
236 return _EventName[ anEvent ] ; } ;
237 const char * ActionName( const GraphExecutor::StateEventAction & anAction ) const {
238 return _ActionName[ anAction ] ; } ;
240 const GraphExecutor::AutomatonState NextState( const GraphExecutor::AutomatonState & aState ,
241 const GraphExecutor::NodeEvent & anEvent ) const {
242 return _TransitionTable[ aState ][ anEvent ] ; } ;
244 const GraphExecutor::StateEventAction NextAction( const GraphExecutor::AutomatonState & aState ,
245 const GraphExecutor::NodeEvent & anEvent ) const {
246 return _ActionTable[ aState ][ anEvent ] ; } ;
251 ostream & operator<< (ostream &f ,const GraphExecutor::AutomatonState & aState ) ;