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