Salome HOME
sources v1.2
[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 "DataFlowBase_Base.hxx"
38
39 #include <SALOMEconfig.h>
40 //#include CORBA_SERVER_HEADER(SUPERV)
41 #include <SALOME_LifeCycleCORBA.hxx>
42
43 namespace GraphExecutor {
44
45   enum NodeEvent { UndefinedEvent , NewThreadEvent ,
46                      SuspendEvent , ToResumeEvent  , ResumeEvent ,
47                      KillEvent , StopEvent ,
48                      ExecuteEvent , SuccessEvent , ErrorEvent ,
49                      ToReStartEvent , ReStartEvent , ReStartAndSuspendEvent ,
50                      EndExecuteEvent ,
51                    NoDataReadyEvent , SomeDataReadyEvent ,
52                    NotAllDataReadyEvent , AllDataReadyEvent ,
53                      ReadyEvent , SuspendedReadyEvent ,ResumedReadyEvent ,
54                      KilledReadyEvent , StoppedReadyEvent ,
55                    ExecutingEvent , SuspendedExecutingEvent ,
56                    ResumedExecutingEvent , KilledExecutingEvent ,
57                    StoppedExecutingEvent ,
58                      SuccessedExecutingEvent , ErroredExecutingEvent ,
59                      SuspendedSuccessedEvent , SuspendedErroredEvent ,
60                      ResumedSuccessedEvent , ResumedErroredEvent ,
61                      KilledEvent , StoppedEvent ,
62                    ReStartedEvent , ReStartedAndSuspendEvent ,
63                      NumberOfEvents } ;
64
65   enum StateEventAction { ErrorAction ,
66                           VoidAction ,
67                           executeAction , // +- pthread_create
68                           ExecuteAction , // +- pthread_create
69                             DataWaiting_SomeDataReadyAction ,
70                             DataUndef_NotAllDataReadyAction ,
71                             DataUndef_AllDataReadyAction ,
72                           DataReady_SuspendAction ,
73                           SuspendedReady_ResumeAction ,
74                           DataReady_KillAction ,
75                           DataReady_StopAction ,
76                             DataReady_ExecuteAction ,
77                           Executing_SuspendAction ,
78                           SuspendedExecuting_ResumeAction ,
79                           Executing_KillAction ,
80                           Executing_StopAction ,
81                             Executing_SuccessAction ,
82                             Executing_ErrorAction ,
83                           Successed_SuccessAction ,
84                           Errored_ErrorAction ,
85                           Successed_SuspendAction ,
86                           Errored_SuspendAction ,
87                           SuspendedSuccessed_ResumeAction ,
88                           SuspendedErrored_ResumeAction ,
89                           Successed_KillAction ,
90                           Errored_KillAction ,
91                           Successed_StopAction ,
92                           Errored_StopAction ,
93                             SuspendedSuccessed_ReStartAction ,
94                             SuspendedErrored_ReStartAction ,
95                             SuspendedSuccessed_ReStartAndSuspendAction ,
96                             SuspendedErrored_ReStartAndSuspendAction ,
97                           NumberOfActions } ;
98
99   class FiniteStateMachine {
100
101     private :
102
103       char *              _ControlStateName[ SUPERV::NumberOfControlStates ] ;
104       char *              _StateName[ SUPERV::NumberOfAutomatonStates ] ;
105       char *              _GraphStateName[ SUPERV::NumberOfGraphStates ] ;
106       char *              _EventName[ GraphExecutor::NumberOfEvents ] ;
107       char *              _ActionName[ NumberOfActions ] ;
108       SUPERV::AutomatonState _TransitionTable[ SUPERV::NumberOfAutomatonStates ]
109                                           [ GraphExecutor::NumberOfEvents ] ;
110       GraphExecutor::StateEventAction _ActionTable[ SUPERV::NumberOfAutomatonStates ]
111                                                   [ GraphExecutor::NumberOfEvents ] ;
112
113       bool              _JoinThread ;
114       pthread_t         _JoinThreadNo ;
115       pthread_mutex_t   _MutexJoinWait ;
116       pthread_cond_t    _JoinWait ;
117       list< pthread_t > _ThreadList ;
118
119     public :
120
121       FiniteStateMachine() ;
122       virtual ~FiniteStateMachine() {} ;
123
124       void JoinThread() ;
125       void JoinThread( pthread_t aThread ) ;
126
127       const char * ControlStateName(
128             const SUPERV::ControlState & aState ) const {
129             return _ControlStateName[ aState ] ; } ;
130       const char * StateName(
131             const SUPERV::AutomatonState & aState ) const {
132             return _StateName[ aState ] ; } ;
133       const char * StateName(
134             const SUPERV::GraphState & aState ) const {
135             return _GraphStateName[ aState ] ; } ;
136       const char * EventName(
137             const GraphExecutor::NodeEvent & anEvent ) const {
138             return _EventName[ anEvent ] ; } ;
139       const char * ActionName(
140             const GraphExecutor::StateEventAction & anAction ) const {
141             return _ActionName[ anAction ] ; } ;
142
143       const SUPERV::AutomatonState NextState(
144             const SUPERV::AutomatonState & aState ,
145             const GraphExecutor::NodeEvent & anEvent ) const {
146             return _TransitionTable[ aState ][ anEvent ] ; } ;
147
148       const GraphExecutor::StateEventAction NextAction(
149             const SUPERV::AutomatonState & aState ,
150             const GraphExecutor::NodeEvent & anEvent ) const {
151             return _ActionTable[ aState ][ anEvent ] ; } ;
152   };
153
154 };
155
156 #endif