]> SALOME platform Git repositories - modules/superv.git/blob - src/GraphExecutor/DataFlowExecutor_FiniteStateMachine.hxx
Salome HOME
The following methods and constants were removed as never being used:
[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                         ReStartedState ,
87                         LoadingState,
88                         NumberOfAutomatonStates } ;
89
90   enum NodeEvent { UndefinedEvent , 
91                    NewThreadEvent ,        
92                    SuspendEvent , 
93                    ToResumeEvent  , 
94                    ResumeEvent ,
95                    KillEvent , 
96                    StopEvent ,
97                    ExecuteEvent , 
98                    SuccessEvent , 
99                    ErrorEvent ,
100                    ToReStartEvent , 
101                    ReStartEvent , 
102                    ReStartAndSuspendEvent ,
103                    EndExecuteEvent ,
104                    NoDataReadyEvent , 
105                    SomeDataReadyEvent ,
106                    NotAllDataReadyEvent , 
107                    AllDataReadyEvent ,
108                    ReadyEvent , 
109                    SuspendedReadyEvent ,
110                    ResumedReadyEvent ,
111                    KilledReadyEvent , 
112                    StoppedReadyEvent ,
113                    ExecutingEvent , 
114                    SuspendedExecutingEvent ,
115                    ResumedExecutingEvent , 
116                    KilledExecutingEvent ,
117                    StoppedExecutingEvent ,
118                    SuccessedExecutingEvent , 
119                    ErroredExecutingEvent ,
120                    SuspendedSuccessedEvent , 
121                    SuspendedErroredEvent ,
122                    ResumedSuccessedEvent , 
123                    ResumedErroredEvent ,
124                    KilledEvent , 
125                    StoppedEvent ,
126                    ReStartedEvent , 
127                    ReStartedAndSuspendEvent ,
128                    NumberOfEvents } ;
129
130   enum StateEventAction { ErrorAction ,
131                           VoidAction ,
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 ,
155                           Errored_KillAction ,
156                           Successed_StopAction ,
157                           Errored_StopAction ,
158                           SuspendedSuccessed_ReStartAction ,
159                           SuspendedErrored_ReStartAction ,
160                           SuspendedSuccessed_ReStartAndSuspendAction ,
161                           SuspendedErrored_ReStartAndSuspendAction ,
162                           NumberOfActions } ;
163
164   class FiniteStateMachine {
165
166     private :
167
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 ] ;
177
178       pthread_mutex_t            _MutexPythonWait ;
179       bool                       _MutexPythonLocked ;
180       map< string , PyObject * > _MapOfPyFunctions ;
181       bool                       _PyInitModule ;
182       int                        _ExecNumber ;
183       int                        _GraphExecutingNumber ;
184
185       int                                _DbgFileNumber ;
186
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 ;
190
191       bool              _JoinThread ;
192       pthread_t         _JoinThreadNo ;
193       pthread_mutex_t   _MutexJoinWait ;
194       pthread_cond_t    _JoinWait ;
195       list< pthread_t > _ThreadList ;
196
197     public :
198
199       FiniteStateMachine() ;
200       virtual ~FiniteStateMachine() {} ;
201
202       int ExecNumber() ;
203       void Executed() ;
204       void PyInitModule(bool) ;
205       bool PyInitModule() ;
206       void PyLock() ;
207       void PyUnLock() ;
208       void PyLockReset() ;
209       bool PyFunction( const char * aPyFuncName , PyObject * aPyFunction ) ;
210       PyObject * PyFunction( const char * aPyFuncName ) ;
211
212
213       string DbgFileNumber() {
214              _DbgFileNumber += 1 ;
215              ostringstream astr ;
216              astr << _DbgFileNumber ;
217              return astr.str() ; } ;
218 /*
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 ) ;
224 */
225
226       void JoinThread() ;
227       void JoinThread( pthread_t aThread ) ;
228
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 ] ; } ;
239
240       const GraphExecutor::AutomatonState NextState( const GraphExecutor::AutomatonState & aState ,
241                                                      const GraphExecutor::NodeEvent & anEvent ) const {
242             return _TransitionTable[ aState ][ anEvent ] ; } ;
243
244       const GraphExecutor::StateEventAction NextAction( const GraphExecutor::AutomatonState & aState ,
245                                                         const GraphExecutor::NodeEvent & anEvent ) const {
246             return _ActionTable[ aState ][ anEvent ] ; } ;
247   };
248
249 };
250
251 ostream & operator<< (ostream &f ,const GraphExecutor::AutomatonState & aState ) ;
252
253 #endif