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 , NewThreadEvent ,
91 SuspendEvent , ToResumeEvent , ResumeEvent ,
92 KillEvent , StopEvent ,
93 ExecuteEvent , SuccessEvent , ErrorEvent ,
94 ToReStartEvent , ReStartEvent , ReStartAndSuspendEvent ,
96 NoDataReadyEvent , SomeDataReadyEvent ,
97 NotAllDataReadyEvent , AllDataReadyEvent ,
98 ReadyEvent , SuspendedReadyEvent ,ResumedReadyEvent ,
99 KilledReadyEvent , StoppedReadyEvent ,
100 ExecutingEvent , SuspendedExecutingEvent ,
101 ResumedExecutingEvent , KilledExecutingEvent ,
102 StoppedExecutingEvent ,
103 SuccessedExecutingEvent , ErroredExecutingEvent ,
104 SuspendedSuccessedEvent , SuspendedErroredEvent ,
105 ResumedSuccessedEvent , ResumedErroredEvent ,
106 KilledEvent , StoppedEvent ,
107 ReStartedEvent , ReStartedAndSuspendEvent ,
110 enum StateEventAction { ErrorAction ,
112 executeAction , // +- pthread_create
113 ExecuteAction , // +- pthread_create
114 DataWaiting_SomeDataReadyAction ,
115 DataUndef_NotAllDataReadyAction ,
116 DataUndef_AllDataReadyAction ,
117 DataReady_SuspendAction ,
118 SuspendedReady_ResumeAction ,
119 DataReady_KillAction ,
120 DataReady_StopAction ,
121 DataReady_ExecuteAction ,
122 Executing_SuspendAction ,
123 SuspendedExecuting_ResumeAction ,
124 Executing_KillAction ,
125 Executing_StopAction ,
126 Executing_SuccessAction ,
127 Executing_ErrorAction ,
128 Successed_SuccessAction ,
129 Errored_ErrorAction ,
130 Successed_SuspendAction ,
131 Errored_SuspendAction ,
132 SuspendedSuccessed_ResumeAction ,
133 SuspendedErrored_ResumeAction ,
134 Successed_KillAction ,
136 Successed_StopAction ,
138 SuspendedSuccessed_ReStartAction ,
139 SuspendedErrored_ReStartAction ,
140 SuspendedSuccessed_ReStartAndSuspendAction ,
141 SuspendedErrored_ReStartAndSuspendAction ,
144 class FiniteStateMachine {
148 char * _ControlStateName[ SUPERV::NumberOfControlStates ] ;
149 char * _StateName[ GraphExecutor::NumberOfAutomatonStates ] ;
150 char * _GraphStateName[ SUPERV::NumberOfGraphStates ] ;
151 char * _EventName[ GraphExecutor::NumberOfEvents ] ;
152 char * _ActionName[ NumberOfActions ] ;
153 GraphExecutor::AutomatonState _TransitionTable[ GraphExecutor::NumberOfAutomatonStates ]
154 [ GraphExecutor::NumberOfEvents ] ;
155 GraphExecutor::StateEventAction _ActionTable[ GraphExecutor::NumberOfAutomatonStates ]
156 [ GraphExecutor::NumberOfEvents ] ;
158 pthread_mutex_t _MutexPythonWait ;
159 map< string , PyObject * > _MapOfPyFunctions ;
162 int _GraphExecutingNumber ;
165 map< string , GraphBase::Graph * > _MapOfGraphs ;
166 map< string , int > _MapOfGraphNames ;
169 pthread_t _JoinThreadNo ;
170 pthread_mutex_t _MutexJoinWait ;
171 pthread_cond_t _JoinWait ;
172 list< pthread_t > _ThreadList ;
176 FiniteStateMachine() ;
177 virtual ~FiniteStateMachine() {} ;
181 bool PyInitModule() ;
184 bool PyFunction( const char * aPyFuncName , PyObject * aPyFunction ) ;
185 PyObject * PyFunction( const char * aPyFuncName ) ;
187 string DbgFileNumber() {
188 _DbgFileNumber += 1 ;
190 astr << _DbgFileNumber ;
191 return astr.str() ; } ;
192 GraphBase::Graph * MapGraph( const char * aGraphName ) ;
193 bool MapGraph( GraphBase::Graph * aGraph , const char * aGraphName ) ;
194 void EraseGraph( const char * aGraphName ) ;
195 bool GraphName( const char * aGraphName ) ;
196 string GraphInstanceName( const char * aGraphName ) ;
199 void JoinThread( pthread_t aThread ) ;
201 const char * ControlStateName( const SUPERV::ControlState & aState ) const {
202 return _ControlStateName[ aState ] ; } ;
203 const char * StateName( const GraphExecutor::AutomatonState & aState ) const {
204 return _StateName[ aState ] ; } ;
205 const char * StateName( const SUPERV::GraphState & aState ) const {
206 return _GraphStateName[ aState ] ; } ;
207 const char * EventName( const GraphExecutor::NodeEvent & anEvent ) const {
208 return _EventName[ anEvent ] ; } ;
209 const char * ActionName( const GraphExecutor::StateEventAction & anAction ) const {
210 return _ActionName[ anAction ] ; } ;
212 const GraphExecutor::AutomatonState NextState( const GraphExecutor::AutomatonState & aState ,
213 const GraphExecutor::NodeEvent & anEvent ) const {
214 return _TransitionTable[ aState ][ anEvent ] ; } ;
216 const GraphExecutor::StateEventAction NextAction( const GraphExecutor::AutomatonState & aState ,
217 const GraphExecutor::NodeEvent & anEvent ) const {
218 return _ActionTable[ aState ][ anEvent ] ; } ;
223 ostream & operator<< (ostream &f ,const GraphExecutor::AutomatonState & aState ) ;