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 Errored_ExecutingAction ,
149 Successed_SuccessAction ,
150 Errored_ErrorAction ,
151 Successed_SuspendAction ,
152 Errored_SuspendAction ,
153 SuspendedSuccessed_ResumeAction ,
154 SuspendedErrored_ResumeAction ,
155 Successed_KillAction ,
157 Successed_StopAction ,
159 SuspendedSuccessed_ReStartAction ,
160 SuspendedErrored_ReStartAction ,
161 SuspendedSuccessed_ReStartAndSuspendAction ,
162 SuspendedErrored_ReStartAndSuspendAction ,
165 class FiniteStateMachine {
169 char * _ControlStateName[ SUPERV::NumberOfControlStates ] ;
170 char * _StateName[ GraphExecutor::NumberOfAutomatonStates ] ;
171 char * _GraphStateName[ SUPERV::NumberOfGraphStates ] ;
172 char * _EventName[ GraphExecutor::NumberOfEvents ] ;
173 char * _ActionName[ NumberOfActions ] ;
174 GraphExecutor::AutomatonState _TransitionTable[ GraphExecutor::NumberOfAutomatonStates ]
175 [ GraphExecutor::NumberOfEvents ] ;
176 GraphExecutor::StateEventAction _ActionTable[ GraphExecutor::NumberOfAutomatonStates ]
177 [ GraphExecutor::NumberOfEvents ] ;
180 SUPERV::SuperG_var _SuperVisionComponent ;
183 pthread_mutex_t _MutexPythonWait ;
184 bool _MutexPythonLocked ;
185 // Map between FuncName and corresponding Python Object Function
186 map< string , PyObject * > _MapOfPyFunctions ;
189 int _GraphExecutingNumber ;
193 // fields and methods that use them are moved to GraphEditor::OutNode class (asv 20.09.04)
194 //map< string , GraphBase::Graph * > _MapOfGraphs ;
195 //map< string , int > _MapOfGraphNames ;
198 pthread_t _JoinThreadNo ;
199 pthread_mutex_t _MutexJoinWait ;
200 pthread_cond_t _JoinWait ;
201 list< pthread_t > _ThreadList ;
205 FiniteStateMachine() ;
206 virtual ~FiniteStateMachine() {} ;
209 void SuperVisionComponent( SUPERV::SuperG_var mySuperVision ) {
210 _SuperVisionComponent = mySuperVision ; } ;
211 SUPERV::SuperG_var SuperVisionComponent() {
212 return _SuperVisionComponent ; } ;
217 void PyInitModule(bool) ;
218 bool PyInitModule() ;
222 bool PyFunction( const char * aPyFuncName , PyObject * aPyFunction ) ;
223 PyObject * PyFunction( const char * aPyFuncName ) ;
224 bool ErasePyFunction( const char * aPyFuncName ) ;
227 string DbgFileNumber() {
228 _DbgFileNumber += 1 ;
230 astr << _DbgFileNumber ;
231 return astr.str() ; } ;
233 GraphBase::Graph * MapGraph( const char * aGraphName ) ;
234 bool MapGraph( GraphBase::Graph * aGraph , const char * aGraphName ) ;
235 void EraseGraph( const char * aGraphName ) ;
236 bool GraphName( const char * aGraphName ) ;
237 string GraphInstanceName( const char * aGraphName ) ;
241 void JoinThread( pthread_t aThread ) ;
243 const char * ControlStateName( const SUPERV::ControlState & aState ) const {
244 return _ControlStateName[ aState ] ; } ;
245 const char * StateName( const GraphExecutor::AutomatonState & aState ) const {
246 return _StateName[ aState ] ; } ;
247 const char * StateName( const SUPERV::GraphState & aState ) const {
248 return _GraphStateName[ aState ] ; } ;
249 const char * EventName( const GraphExecutor::NodeEvent & anEvent ) const {
250 return _EventName[ anEvent ] ; } ;
251 const char * ActionName( const GraphExecutor::StateEventAction & anAction ) const {
252 return _ActionName[ anAction ] ; } ;
254 const GraphExecutor::AutomatonState NextState( const GraphExecutor::AutomatonState & aState ,
255 const GraphExecutor::NodeEvent & anEvent ) const {
256 return _TransitionTable[ aState ][ anEvent ] ; } ;
258 const GraphExecutor::StateEventAction NextAction( const GraphExecutor::AutomatonState & aState ,
259 const GraphExecutor::NodeEvent & anEvent ) const {
260 return _ActionTable[ aState ][ anEvent ] ; } ;
265 ostream & operator<< (ostream &f ,const GraphExecutor::AutomatonState & aState ) ;