Salome HOME
e44168b3a68bb7e84a6d75b88f0d711763fd14bc
[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 "DataFlowExecutor_InNode.hxx"
35
36 #include "DataFlowBase_StreamGraph.hxx"
37
38 namespace GraphExecutor {
39
40 //  class OutNode : public GraphBase::Graph {
41   class OutNode : public GraphBase::Base {
42
43     private :
44
45       GraphBase::StreamGraph * _StreamGraph ;
46       GraphBase::Graph       * _Graph ;
47
48       int  _Graph_prof_debug ;
49
50       bool                    _PyInitialized ;
51       bool                    _Valid ;
52       bool                    _Executable ;
53       GraphExecutor::AutomatonState  _State ;
54       SUPERV::ControlState    _ControlState ;
55       bool                    _Done ;
56
57       Engines_Container_i            * _SuperVisionContainer ;
58       pthread_t                        _MainThreadId ;
59       pthread_mutex_t                  _PyMutexWait ;
60       pthread_mutex_t                  _MutexWait ;
61       pthread_cond_t                   _EventWait ;
62       pthread_cond_t                   _JoinWait ;
63       bool                             _JustStarted ;
64       int                              _Threads ; // Number of threads
65       int                              _SuspendedThreads ;
66       list< char * >                   _EventNodes ;
67       list< GraphExecutor::NodeEvent > _Events ;
68       list< GraphExecutor::AutomatonState >   _States ;
69
70       bool Valid() ;
71       void UnValid() ;
72       bool Executable() ;
73
74       bool LoadNodes( const GraphBase::ListOfSNodes &aNodes ) ;
75       bool LoadLinks( const GraphBase::ListOfSLinks &aLinks ) ;
76       bool LoadDatas( const GraphBase::ListOfSLinks &aDatas ) ;
77
78       CORBA::ORB_ptr _Orb ;
79
80       // scan (reverse) the _EventNodes queue and leave only 1 (the last one that came) 
81       // event for every node
82       void siftEvents();
83
84     public :
85   
86       OutNode() ;
87       OutNode( CORBA::ORB_ptr ORB, SALOME_NamingService* ptrNamingService ,
88                const char *DataFlowName ,
89                const char * DebugFileName ,
90                const SUPERV::KindOfNode aKindOfNode );
91       OutNode( CORBA::ORB_ptr ORB, SALOME_NamingService* ptrNamingService ,
92                const SALOME_ModuleCatalog::Service& DataFlowService ,
93                const char *DataFlowComponentName ,
94                const char *DataFlowInterfaceName ,
95                const char *DataFlowName ,
96                const SUPERV::KindOfNode DataFlowkind ,
97                const SUPERV::SDate DataFlowFirstCreation ,
98                const SUPERV::SDate DataFlowLastModification ,
99                const char * DataFlowEditorRelease ,
100                const char * DataFlowAuthor ,
101                const char * DataFlowComputer ,
102                const char * DataFlowComment ,
103                const char * DebugFileName ) ;
104       virtual ~OutNode() ;
105
106       void Set_prof_debug( CORBA::ORB_ptr ORB , const char * DebugFileName ) ;
107       GraphBase::StreamGraph * StreamGraph() {
108                                return _StreamGraph ; } ;
109       GraphBase::StreamGraph * StreamGraph() const {
110                                return _StreamGraph ; } ;
111       GraphBase::Graph * Graph() {
112                          return _Graph ; } ;
113       GraphBase::Graph * Graph() const {
114                          return _Graph ; } ;
115
116       bool LoadDataFlow( const GraphBase::SGraph * aDataFlow ) ;
117 //      bool LoadXml( const char* myFileName ) ;
118       bool LoadInfo( const GraphBase::SNode &aDataFlowInfo ) ;
119
120       GraphExecutor::InNode * AddNode(
121                         const SALOME_ModuleCatalog::Service& NodeService ,
122                         GraphBase::ListOfFuncName aFuncName ,
123                         GraphBase::ListOfPythonFunctions aPythonFunction ,
124                         const char * NodeComponentName ,
125                         const char * NodeInterfaceName ,
126                         const char * NodeName ,
127                         const SUPERV::KindOfNode NodeKindOfNode = SUPERV::ComputingNode ,
128                         const SUPERV::SDate NodeFirstCreation = SUPERV::SDate() ,
129                         const SUPERV::SDate NodeLastModification = SUPERV::SDate() ,
130                         const char * NodeEditorRelease = NULLSTRING ,
131                         const char * NodeAuthor = NULLSTRING ,
132                         const char * NodeComputer = NULLSTRING ,
133                         const char * NodeComment = NULLSTRING ,
134                         const int NodeX = 0 ,
135                         const int NodeY = 0 ) ;
136
137       bool IsValid() { if ( !_Valid )
138                          return Valid() ;
139                        return _Valid ; } ;
140       bool IsExecutable() { if ( !_Executable )
141                                 return Executable() ;
142                             return _Executable ; } ;
143
144       bool Run( const bool AndSuspend ) ;
145
146       void PyInitialized( bool init ) {
147            _PyInitialized = init ; } ;
148       bool PyInitialized() {
149            return _PyInitialized ; } ;
150
151       void CheckAllDone() ;
152
153       Engines_Container_i * SuperVisionContainer() ;
154       const pthread_t MainThreadId() const ;
155       void PThreadLock( pthread_mutex_t * aMutex , char * errmsg ) ;
156       void PThreadUnLock( pthread_mutex_t * aMutex , char * errmsg ) ;
157       void PyThreadLock() ;
158       void PyThreadUnLock() ;
159
160       void NewThread() ;
161       void ExitThread( pthread_t ThreadNumber = 0 ) ;
162       void SuspendThread() ;
163       void ResumeThread() ;
164       long Threads() { return _Threads ; } ;
165       long SuspendedThreads() { return _SuspendedThreads ; } ;
166       void JoinedWait() ;
167
168       pthread_t ThreadNo() {
169                 return _Graph->ThreadNo() ; } ;
170       long Thread( const char * NodeName ) ;
171
172       bool PushEvent( GraphExecutor::InNode * aNode ,
173                       GraphExecutor::NodeEvent anEvent ,
174                       GraphExecutor::AutomatonState aState ) ;
175       int GetListSize();
176       bool StateWait( SUPERV::GraphState aState ) ;
177       bool Event( char ** aNodeName ,
178                   SUPERV::GraphEvent & anEvent ,
179                   SUPERV::GraphState & aState ,
180                   bool WithWait ) ;
181       bool EventW( char ** aNodeName ,
182                    SUPERV::GraphEvent & anEvent ,
183                    SUPERV::GraphState & aState ) ;
184       bool EventWait( char ** aNodeName ,
185                       SUPERV::GraphEvent & anEvent ,
186                       SUPERV::GraphState & aState ) ;
187       long EventQSize() ;
188       void EventList() ;
189
190       void SendSomeDataReady( const char * aNodeName ) ;
191
192       void State(GraphExecutor::AutomatonState aState ) ;
193       const char * StateName(GraphExecutor::AutomatonState aState ) {
194              return theAutomaton->StateName( aState ) ; }
195
196       SUPERV::GraphState State() ;
197       SUPERV::GraphState State( const char * NodeName ) ;
198       SUPERV::GraphState State( const char * NodeName ,
199                                 const char * ServiceParameterName ) ;
200
201       SUPERV::GraphEvent AutomatonGraphEvent(GraphExecutor::NodeEvent anEvent) ;
202       SUPERV::GraphState AutomatonGraphState(GraphExecutor::AutomatonState anAutomatonState) ;
203
204       GraphExecutor::AutomatonState AutomatonState() ;
205       GraphExecutor::AutomatonState AutomatonState( const char * NodeName ) ;
206
207       SUPERV::ControlState ControlState() ;
208       SUPERV::ControlState ControlState( const char * aNodeName ) ;
209       void ControlClear() ;
210       void ControlClear( const char * aNodeName ) ;
211
212       bool ContainerKill() ;
213
214       bool Suspend() ;
215       bool Resume() ;
216       bool Kill() ;
217       bool Stop() ;
218
219       bool IsWaiting() ;
220       bool IsReady() ;
221       bool IsRunning() ;
222       void Done( bool aDone ) { _Done = aDone ; } ;
223       bool Done() { return _Done ; } ;
224       bool IsDone() ;
225       bool IsSuspended() ;
226       bool IsKilled() ;
227       bool IsStopped() ;
228       bool IsWaiting( const char * NodeName ) ;
229       bool IsReady( const char * NodeName ) ;
230       bool IsRunning( const char * NodeName ) ;
231       bool IsDone( const char * NodeName ) ;
232       bool IsSuspended( const char * NodeName ) ;
233       bool IsDone( const char * NodeName ,
234                    const char * ServiceParameterName ) ;
235       long LastLevelDone() ;
236
237       bool ReadyWait() ;
238       bool RunningWait() ;
239       bool DoneWait() ;
240       bool SuspendedWait() ;
241       bool ReadyWait( const char * NodeName ) ;
242       bool RunningWait( const char * NodeName ) ;
243       bool DoneWait( const char * NodeName ) ;
244       bool SuspendedWait( const char * NodeName ) ;
245
246       const CORBA::Any *GetInData( const char *ToNodeName ,
247                                    const char *ToParameterName ) ;
248       const CORBA::Any *GetOutData( const char *FromNodeName ,
249                                     const char *FromParameterName ) ;
250       const long CpuUsed() ;
251       const long CpuUsed( const char *aNodeName ) ;
252   };
253 };
254
255 #endif