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