]> SALOME platform Git repositories - modules/superv.git/blob - src/GraphExecutor/DataFlowExecutor_FiniteStateMachine.hxx
Salome HOME
*** empty log message ***
[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 GraphExecutor {
49
50   enum NodeEvent { UndefinedEvent , NewThreadEvent ,
51                      SuspendEvent , ToResumeEvent  , ResumeEvent ,
52                      KillEvent , StopEvent ,
53                      ExecuteEvent , SuccessEvent , ErrorEvent ,
54                      ToReStartEvent , ReStartEvent , ReStartAndSuspendEvent ,
55                      EndExecuteEvent ,
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 ,
68                      NumberOfEvents } ;
69
70   enum StateEventAction { ErrorAction ,
71                           VoidAction ,
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 ,
89                           Errored_ErrorAction ,
90                           Successed_SuspendAction ,
91                           Errored_SuspendAction ,
92                           SuspendedSuccessed_ResumeAction ,
93                           SuspendedErrored_ResumeAction ,
94                           Successed_KillAction ,
95                           Errored_KillAction ,
96                           Successed_StopAction ,
97                           Errored_StopAction ,
98                             SuspendedSuccessed_ReStartAction ,
99                             SuspendedErrored_ReStartAction ,
100                             SuspendedSuccessed_ReStartAndSuspendAction ,
101                             SuspendedErrored_ReStartAndSuspendAction ,
102                           NumberOfActions } ;
103
104   class FiniteStateMachine {
105
106     private :
107
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 ] ;
117
118       pthread_mutex_t            _MutexPythonWait ;
119       map< string , PyObject * > _MapOfPyFunctions ;
120       bool                       _PyInitModule ;
121       int                        _ExecNumber ;
122       int                        _GraphExecutingNumber ;
123
124       bool              _JoinThread ;
125       pthread_t         _JoinThreadNo ;
126       pthread_mutex_t   _MutexJoinWait ;
127       pthread_cond_t    _JoinWait ;
128       list< pthread_t > _ThreadList ;
129
130     public :
131
132       FiniteStateMachine() ;
133       virtual ~FiniteStateMachine() {} ;
134
135       int ExecNumber() ;
136       void Executed() ;
137       bool PyInitModule() ;
138       void PyLock() ;
139       void PyUnLock() ;
140       bool PyFunction( const char * aPyFuncName , PyObject * aPyFunction ) ;
141       PyObject * PyFunction( const char * aPyFuncName ) ;
142
143       void JoinThread() ;
144       void JoinThread( pthread_t aThread ) ;
145
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 ] ; } ;
156
157       const SUPERV::AutomatonState NextState( const SUPERV::AutomatonState & aState ,
158                                                const GraphExecutor::NodeEvent & anEvent ) const {
159             return _TransitionTable[ aState ][ anEvent ] ; } ;
160
161       const GraphExecutor::StateEventAction NextAction( const SUPERV::AutomatonState & aState ,
162                                                         const GraphExecutor::NodeEvent & anEvent ) const {
163             return _ActionTable[ aState ][ anEvent ] ; } ;
164   };
165
166 };
167
168 #endif