Salome HOME
e16f0ef66dbc746449db85edaa77d1861ad2086f
[modules/superv.git] / src / GraphExecutor / DataFlowExecutor_OutNode.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_OutNode.hxx
25 //  Author : Jean Rahuel, CEA
26 //  Module : SUPERV
27 //  $Header:
28
29 #ifndef _DATAFLOWEXECUTOR_OUTNODE_HXX
30 #define _DATAFLOWEXECUTOR_OUTNODE_HXX
31
32 #include "SALOME_Component_i.hxx"
33
34 #include "DataFlowBase_Graph.hxx"
35
36 #include "DataFlowExecutor_InNode.hxx"
37
38 namespace GraphExecutor {
39
40   class OutNode : public GraphBase::Graph {
41
42     private :
43
44       bool                    _PyInitialized ;
45       bool                    _Valid ;
46       bool                    _Executable ;
47       SUPERV::AutomatonState  _State ;
48       SUPERV::ControlState    _ControlState ;
49       bool                    _Done ;
50
51       pthread_mutex_t                  _PyMutexWait ;
52       pthread_mutex_t                  _MutexWait ;
53       pthread_cond_t                   _EventWait ;
54       pthread_cond_t                   _JoinWait ;
55       bool                             _JustStarted ;
56       int                              _Threads ; // Number of threads
57       int                              _SuspendedThreads ;
58       list< char * >                   _EventNodes ;
59       list< GraphExecutor::NodeEvent > _Events ;
60       list< SUPERV::AutomatonState >   _States ;
61
62       bool Valid() ;
63       void UnValid() ;
64       bool Executable() ;
65
66       bool LoadNodes( const GraphBase::ListOfNodes &aNodes ) ;
67       bool LoadLinks( const GraphBase::ListOfLinks &aLinks ) ;
68       bool LoadDatas( const GraphBase::ListOfLinks &aDatas ) ;
69
70       CORBA::ORB_ptr _Orb ;
71
72     public :
73   
74       OutNode() ;
75       OutNode( CORBA::ORB_ptr ORB, SALOME_NamingService* ptrNamingService ,
76                const char *DataFlowName ,
77                const char * DebugFileName );
78       OutNode( CORBA::ORB_ptr ORB, SALOME_NamingService* ptrNamingService ,
79                const SALOME_ModuleCatalog::Service& DataFlowService ,
80                const char *DataFlowComponentName ,
81                const char *DataFlowInterfaceName ,
82                const char *DataFlowName ,
83                const SUPERV::KindOfNode DataFlowkind ,
84                const SUPERV::SDate DataFlowFirstCreation ,
85                const SUPERV::SDate DataFlowLastModification ,
86                const char * DataFlowEditorRelease ,
87                const char * DataFlowAuthor ,
88                const char * DataFlowComputer ,
89                const char * DataFlowComment ,
90                const char * DebugFileName ) ;
91       virtual ~OutNode() ;
92
93       bool LoadDataFlow( const GraphBase::SGraph &aDataFlow ) ;
94       bool LoadXml( const char* myFileName ) ;
95       bool LoadInfo( const GraphBase::SNode &aDataFlowInfo ) ;
96
97       GraphExecutor::InNode * AddNode(
98                         const SALOME_ModuleCatalog::Service& NodeService ,
99                         GraphBase::ListOfFuncName aFuncName ,
100                         GraphBase::ListOfPythonFunctions aPythonFunction ,
101                         const char * NodeComponentName ,
102                         const char * NodeInterfaceName ,
103                         const char * NodeName ,
104                         const SUPERV::KindOfNode NodeKindOfNode = SUPERV::ComputingNode ,
105                         const SUPERV::SDate NodeFirstCreation = SUPERV::SDate() ,
106                         const SUPERV::SDate NodeLastModification = SUPERV::SDate() ,
107                         const char * NodeEditorRelease = NULLSTRING ,
108                         const char * NodeAuthor = NULLSTRING ,
109                         const char * NodeComputer = NULLSTRING ,
110                         const char * NodeComment = NULLSTRING ,
111                         const int NodeX = 0 ,
112                         const int NodeY = 0 ) ;
113
114       bool AddInputData( const char* ToNodeName1 ,
115                          const char* ToParameterName1 ,
116                          const char* ToNodeName2 ,
117                          const char* ToParameterName2 ) ;
118
119       bool IsValid() { if ( !_Valid )
120                          return Valid() ;
121                        return _Valid ; } ;
122       bool IsExecutable() { if ( !_Executable )
123                                 return Executable() ;
124                             return _Executable ; } ;
125
126       bool Run( const bool AndSuspend ) ;
127       bool Run( const char * aNodeName , const char * AtNodeName ,
128                 const bool AndSuspend ) ;
129
130       void PyInitialized( bool init ) {
131            _PyInitialized = init ; } ;
132       bool PyInitialized() {
133            return _PyInitialized ; } ;
134
135       void CheckAllDone() ;
136
137       void PThreadLock( pthread_mutex_t * aMutex , char * errmsg ) ;
138       void PThreadUnLock( pthread_mutex_t * aMutex , char * errmsg ) ;
139       void PyThreadLock() ;
140       void PyThreadUnLock() ;
141
142       void NewThread() ;
143       void ExitThread() ;
144       void SuspendThread() ;
145       void ResumeThread() ;
146       long Threads() { return _Threads ; } ;
147       long SuspendedThreads() { return _SuspendedThreads ; } ;
148       void JoinedWait() ;
149
150       long Thread( const char * NodeName ) ;
151
152       bool PushEvent( GraphExecutor::InNode * aNode ,
153                       GraphExecutor::NodeEvent anEvent ,
154                       SUPERV::AutomatonState aState ) ;
155       bool StateWait( SUPERV::GraphState aState ) ;
156       bool Event( char ** aNodeName ,
157                   SUPERV::GraphEvent & anEvent ,
158                   SUPERV::GraphState & aState ,
159                   bool WithWait ) ;
160       bool EventW( char ** aNodeName ,
161                    SUPERV::GraphEvent & anEvent ,
162                    SUPERV::GraphState & aState ) ;
163       bool EventWait( char ** aNodeName ,
164                       SUPERV::GraphEvent & anEvent ,
165                       SUPERV::GraphState & aState ) ;
166
167       void State(SUPERV::AutomatonState aState ) ;
168       const char * StateName(SUPERV::AutomatonState aState ) {
169              return theAutomaton->StateName( aState ) ; }
170
171       SUPERV::GraphState State() ;
172       SUPERV::GraphState State( const char * NodeName ) ;
173       SUPERV::GraphState State( const char * NodeName ,
174                                 const char * ServiceParameterName ) ;
175
176       SUPERV::GraphEvent AutomatonGraphEvent(GraphExecutor::NodeEvent anEvent) ;
177       SUPERV::GraphState AutomatonGraphState(SUPERV::AutomatonState anAutomatonState) ;
178
179       SUPERV::AutomatonState AutomatonState() ;
180       SUPERV::AutomatonState AutomatonState( const char * NodeName ) ;
181
182       SUPERV::ControlState ControlState() ;
183       SUPERV::ControlState ControlState( const char * aNodeName ) ;
184       void ControlClear() ;
185       void ControlClear( const char * aNodeName ) ;
186
187       bool ContainerKill() ;
188
189       bool Suspend() ;
190       bool Resume() ;
191       bool Kill() ;
192       bool Stop() ;
193       bool ReRun() ;
194       bool ReStart() ;
195
196       void Done( bool aDone ) { _Done = aDone ; } ;
197
198       bool IsWaiting() ;
199       bool IsReady() ;
200       bool IsRunning() ;
201       bool IsDone() ;
202       bool IsSuspended() ;
203       bool IsKilled() ;
204       bool IsStopped() ;
205       bool IsWaiting( const char * NodeName ) ;
206       bool IsReady( const char * NodeName ) ;
207       bool IsRunning( const char * NodeName ) ;
208       bool IsDone( const char * NodeName ) ;
209       bool IsSuspended( const char * NodeName ) ;
210       bool IsDone( const char * NodeName ,
211                    const char * ServiceParameterName ) ;
212       long LastLevelDone() ;
213
214       bool ReadyWait() ;
215       bool RunningWait() ;
216       bool DoneWait() ;
217       bool SuspendedWait() ;
218       bool ReadyWait( const char * NodeName ) ;
219       bool RunningWait( const char * NodeName ) ;
220       bool DoneWait( const char * NodeName ) ;
221       bool SuspendedWait( const char * NodeName ) ;
222
223       const CORBA::Any *GetInData( const char *ToNodeName ,
224                                    const char *ToParameterName ) ;
225       const CORBA::Any *GetOutData( const char *FromNodeName ,
226                                     const char *FromParameterName ) ;
227       const long CpuUsed() ;
228       const long CpuUsed( const char *aNodeName ) ;
229   };
230 };
231
232 #endif