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