]> SALOME platform Git repositories - modules/superv.git/blob - src/GraphExecutor/DataFlowExecutor_FiniteStateMachine.hxx
Salome HOME
A special "Loading" state was implemented. It is returned to GUI if the correspondin...
[modules/superv.git] / src / GraphExecutor / DataFlowExecutor_FiniteStateMachine.hxx
1 //  SUPERV GraphExecutor : contains classes that permit execution of graphs and particularly the execution automaton
2 //
3 //  Copyright (C) 2003  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 //  CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS 
5 // 
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. 
10 // 
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. 
15 // 
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 
19 // 
20 //  See http://www.opencascade.org/SALOME/ or email : webmaster.salome@opencascade.org 
21 //
22 //
23 //
24 //  File   : DataFlowBase_FiniteStateMachine.hxx
25 //  Author : Jean Rahuel, CEA
26 //  Module : SUPERV
27 //  $Header:
28
29 #ifndef _DATAFLOWEXECUTOR_FINITESTATEMACHINE
30 #define _DATAFLOWEXECUTOR_FINITESTATEMACHINE
31
32 #include <stdlib.h>
33 #include <iostream>
34 #include <unistd.h>
35 #include <stdio.h>
36
37 #include <Python.h>
38
39 #include <string>
40 #include <map>
41
42 #include "DataFlowBase_Base.hxx"
43
44 #include <SALOMEconfig.h>
45 //#include CORBA_SERVER_HEADER(SUPERV)
46 #include <SALOME_LifeCycleCORBA.hxx>
47
48 namespace GraphBase {
49   class Graph ;
50 }
51
52 namespace GraphExecutor {
53
54 //The AutomatonState is an internal state of the automaton of the Executor
55   enum AutomatonState { UnKnownState ,
56                         DataUndefState ,
57                         DataWaitingState ,
58                         DataReadyState ,
59                         SuspendedReadyState,
60                         SuspendedReadyToResumeState ,
61                         ResumedReadyState ,
62                         KilledReadyState ,
63                         StoppedReadyState ,
64                         ExecutingState ,
65                         SuspendedExecutingState ,
66                         ResumedExecutingState ,
67                         KilledExecutingState ,
68                         StoppedExecutingState ,
69                         SuccessedExecutingState ,
70                         ErroredExecutingState ,
71                         SuspendedSuccessedState ,
72                         SuspendedErroredState,
73                         ResumedSuccessedState ,
74                         ResumedErroredState ,
75                              KilledSuccessedState ,
76                         KilledErroredState ,
77                              StoppedSuccessedState ,
78                         StoppedErroredState ,
79                         SuccessedState ,
80                         ErroredState ,
81                         SuspendedState ,
82                         KilledState ,
83                         StoppedState ,
84                         SuspendedSuccessedToReStartState ,
85                         SuspendedErroredToReStartState ,
86                         ReRunnedState ,
87                         ReStartedState ,
88                         LoadingState,
89                         NumberOfAutomatonStates } ;
90
91   enum NodeEvent { UndefinedEvent , NewThreadEvent ,
92                      SuspendEvent , ToResumeEvent  , ResumeEvent ,
93                      KillEvent , StopEvent ,
94                      ExecuteEvent , SuccessEvent , ErrorEvent ,
95                      ToReStartEvent , ReStartEvent , ReStartAndSuspendEvent ,
96                      EndExecuteEvent ,
97                    NoDataReadyEvent , SomeDataReadyEvent ,
98                    NotAllDataReadyEvent , AllDataReadyEvent ,
99                      ReadyEvent , SuspendedReadyEvent ,ResumedReadyEvent ,
100                      KilledReadyEvent , StoppedReadyEvent ,
101                    ExecutingEvent , SuspendedExecutingEvent ,
102                    ResumedExecutingEvent , KilledExecutingEvent ,
103                    StoppedExecutingEvent ,
104                      SuccessedExecutingEvent , ErroredExecutingEvent ,
105                      SuspendedSuccessedEvent , SuspendedErroredEvent ,
106                      ResumedSuccessedEvent , ResumedErroredEvent ,
107                      KilledEvent , StoppedEvent ,
108                    ReStartedEvent , ReStartedAndSuspendEvent ,
109                      NumberOfEvents } ;
110
111   enum StateEventAction { ErrorAction ,
112                           VoidAction ,
113                           executeAction , // +- pthread_create
114                           ExecuteAction , // +- pthread_create
115                             DataWaiting_SomeDataReadyAction ,
116                             DataUndef_NotAllDataReadyAction ,
117                             DataUndef_AllDataReadyAction ,
118                           DataReady_SuspendAction ,
119                           SuspendedReady_ResumeAction ,
120                           DataReady_KillAction ,
121                           DataReady_StopAction ,
122                             DataReady_ExecuteAction ,
123                           Executing_SuspendAction ,
124                           SuspendedExecuting_ResumeAction ,
125                           Executing_KillAction ,
126                           Executing_StopAction ,
127                             Executing_SuccessAction ,
128                             Executing_ErrorAction ,
129                           Successed_SuccessAction ,
130                           Errored_ErrorAction ,
131                           Successed_SuspendAction ,
132                           Errored_SuspendAction ,
133                           SuspendedSuccessed_ResumeAction ,
134                           SuspendedErrored_ResumeAction ,
135                           Successed_KillAction ,
136                           Errored_KillAction ,
137                           Successed_StopAction ,
138                           Errored_StopAction ,
139                             SuspendedSuccessed_ReStartAction ,
140                             SuspendedErrored_ReStartAction ,
141                             SuspendedSuccessed_ReStartAndSuspendAction ,
142                             SuspendedErrored_ReStartAndSuspendAction ,
143                           NumberOfActions } ;
144
145   class FiniteStateMachine {
146
147     private :
148
149       char *              _ControlStateName[ SUPERV::NumberOfControlStates ] ;
150       char *              _StateName[ GraphExecutor::NumberOfAutomatonStates ] ;
151       char *              _GraphStateName[ SUPERV::NumberOfGraphStates ] ;
152       char *              _EventName[ GraphExecutor::NumberOfEvents ] ;
153       char *              _ActionName[ NumberOfActions ] ;
154       GraphExecutor::AutomatonState _TransitionTable[ GraphExecutor::NumberOfAutomatonStates ]
155                                                     [ GraphExecutor::NumberOfEvents ] ;
156       GraphExecutor::StateEventAction _ActionTable[ GraphExecutor::NumberOfAutomatonStates ]
157                                                   [ GraphExecutor::NumberOfEvents ] ;
158
159       pthread_mutex_t            _MutexPythonWait ;
160       bool                       _MutexPythonLocked ;
161       map< string , PyObject * > _MapOfPyFunctions ;
162       bool                       _PyInitModule ;
163       int                        _ExecNumber ;
164       int                        _GraphExecutingNumber ;
165
166       int                                _DbgFileNumber ;
167
168 // fields and methods that use them are moved to GraphEditor::OutNode class (asv 20.09.04)  
169 //map< string , GraphBase::Graph * > _MapOfGraphs ;
170 //map< string , int >                _MapOfGraphNames ;
171
172       bool              _JoinThread ;
173       pthread_t         _JoinThreadNo ;
174       pthread_mutex_t   _MutexJoinWait ;
175       pthread_cond_t    _JoinWait ;
176       list< pthread_t > _ThreadList ;
177
178     public :
179
180       FiniteStateMachine() ;
181       virtual ~FiniteStateMachine() {} ;
182
183       int ExecNumber() ;
184       void Executed() ;
185       void PyInitModule(bool) ;
186       bool PyInitModule() ;
187       void PyLock() ;
188       void PyUnLock() ;
189       void PyLockReset() ;
190       bool PyFunction( const char * aPyFuncName , PyObject * aPyFunction ) ;
191       PyObject * PyFunction( const char * aPyFuncName ) ;
192
193
194       string DbgFileNumber() {
195              _DbgFileNumber += 1 ;
196              ostringstream astr ;
197              astr << _DbgFileNumber ;
198              return astr.str() ; } ;
199 /*
200       GraphBase::Graph * MapGraph( const char * aGraphName ) ;
201       bool MapGraph( GraphBase::Graph * aGraph , const char * aGraphName ) ;
202       void EraseGraph( const char * aGraphName ) ;
203       bool GraphName( const char * aGraphName ) ;
204       string GraphInstanceName( const char * aGraphName ) ;
205 */
206
207       void JoinThread() ;
208       void JoinThread( pthread_t aThread ) ;
209
210       const char * ControlStateName( const SUPERV::ControlState & aState ) const {
211             return _ControlStateName[ aState ] ; } ;
212       const char * StateName( const GraphExecutor::AutomatonState & aState ) const {
213             return _StateName[ aState ] ; } ;
214       const char * StateName( const SUPERV::GraphState & aState ) const {
215             return _GraphStateName[ aState ] ; } ;
216       const char * EventName( const GraphExecutor::NodeEvent & anEvent ) const {
217             return _EventName[ anEvent ] ; } ;
218       const char * ActionName( const GraphExecutor::StateEventAction & anAction ) const {
219             return _ActionName[ anAction ] ; } ;
220
221       const GraphExecutor::AutomatonState NextState( const GraphExecutor::AutomatonState & aState ,
222                                                      const GraphExecutor::NodeEvent & anEvent ) const {
223             return _TransitionTable[ aState ][ anEvent ] ; } ;
224
225       const GraphExecutor::StateEventAction NextAction( const GraphExecutor::AutomatonState & aState ,
226                                                         const GraphExecutor::NodeEvent & anEvent ) const {
227             return _ActionTable[ aState ][ anEvent ] ; } ;
228   };
229
230 };
231
232 ostream & operator<< (ostream &f ,const GraphExecutor::AutomatonState & aState ) ;
233
234 #endif