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