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>
48 namespace GraphExecutor {
50 enum NodeEvent { UndefinedEvent , NewThreadEvent ,
51 SuspendEvent , ToResumeEvent , ResumeEvent ,
52 KillEvent , StopEvent ,
53 ExecuteEvent , SuccessEvent , ErrorEvent ,
54 ToReStartEvent , ReStartEvent , ReStartAndSuspendEvent ,
56 NoDataReadyEvent , SomeDataReadyEvent ,
57 NotAllDataReadyEvent , AllDataReadyEvent ,
58 ReadyEvent , SuspendedReadyEvent ,ResumedReadyEvent ,
59 KilledReadyEvent , StoppedReadyEvent ,
60 ExecutingEvent , SuspendedExecutingEvent ,
61 ResumedExecutingEvent , KilledExecutingEvent ,
62 StoppedExecutingEvent ,
63 SuccessedExecutingEvent , ErroredExecutingEvent ,
64 SuspendedSuccessedEvent , SuspendedErroredEvent ,
65 ResumedSuccessedEvent , ResumedErroredEvent ,
66 KilledEvent , StoppedEvent ,
67 ReStartedEvent , ReStartedAndSuspendEvent ,
70 enum StateEventAction { ErrorAction ,
72 executeAction , // +- pthread_create
73 ExecuteAction , // +- pthread_create
74 DataWaiting_SomeDataReadyAction ,
75 DataUndef_NotAllDataReadyAction ,
76 DataUndef_AllDataReadyAction ,
77 DataReady_SuspendAction ,
78 SuspendedReady_ResumeAction ,
79 DataReady_KillAction ,
80 DataReady_StopAction ,
81 DataReady_ExecuteAction ,
82 Executing_SuspendAction ,
83 SuspendedExecuting_ResumeAction ,
84 Executing_KillAction ,
85 Executing_StopAction ,
86 Executing_SuccessAction ,
87 Executing_ErrorAction ,
88 Successed_SuccessAction ,
90 Successed_SuspendAction ,
91 Errored_SuspendAction ,
92 SuspendedSuccessed_ResumeAction ,
93 SuspendedErrored_ResumeAction ,
94 Successed_KillAction ,
96 Successed_StopAction ,
98 SuspendedSuccessed_ReStartAction ,
99 SuspendedErrored_ReStartAction ,
100 SuspendedSuccessed_ReStartAndSuspendAction ,
101 SuspendedErrored_ReStartAndSuspendAction ,
104 class FiniteStateMachine {
108 char * _ControlStateName[ SUPERV::NumberOfControlStates ] ;
109 char * _StateName[ SUPERV::NumberOfAutomatonStates ] ;
110 char * _GraphStateName[ SUPERV::NumberOfGraphStates ] ;
111 char * _EventName[ GraphExecutor::NumberOfEvents ] ;
112 char * _ActionName[ NumberOfActions ] ;
113 SUPERV::AutomatonState _TransitionTable[ SUPERV::NumberOfAutomatonStates ]
114 [ GraphExecutor::NumberOfEvents ] ;
115 GraphExecutor::StateEventAction _ActionTable[ SUPERV::NumberOfAutomatonStates ]
116 [ GraphExecutor::NumberOfEvents ] ;
118 pthread_mutex_t _MutexPythonWait ;
119 map< string , PyObject * > _MapOfPyFunctions ;
122 int _GraphExecutingNumber ;
125 pthread_t _JoinThreadNo ;
126 pthread_mutex_t _MutexJoinWait ;
127 pthread_cond_t _JoinWait ;
128 list< pthread_t > _ThreadList ;
132 FiniteStateMachine() ;
133 virtual ~FiniteStateMachine() {} ;
137 bool PyInitModule() ;
140 bool PyFunction( const char * aPyFuncName , PyObject * aPyFunction ) ;
141 PyObject * PyFunction( const char * aPyFuncName ) ;
144 void JoinThread( pthread_t aThread ) ;
146 const char * ControlStateName( const SUPERV::ControlState & aState ) const {
147 return _ControlStateName[ aState ] ; } ;
148 const char * StateName( const SUPERV::AutomatonState & aState ) const {
149 return _StateName[ aState ] ; } ;
150 const char * StateName( const SUPERV::GraphState & aState ) const {
151 return _GraphStateName[ aState ] ; } ;
152 const char * EventName( const GraphExecutor::NodeEvent & anEvent ) const {
153 return _EventName[ anEvent ] ; } ;
154 const char * ActionName( const GraphExecutor::StateEventAction & anAction ) const {
155 return _ActionName[ anAction ] ; } ;
157 const SUPERV::AutomatonState NextState( const SUPERV::AutomatonState & aState ,
158 const GraphExecutor::NodeEvent & anEvent ) const {
159 return _TransitionTable[ aState ][ anEvent ] ; } ;
161 const GraphExecutor::StateEventAction NextAction( const SUPERV::AutomatonState & aState ,
162 const GraphExecutor::NodeEvent & anEvent ) const {
163 return _ActionTable[ aState ][ anEvent ] ; } ;