1 // Copyright (C) 2007-2008 CEA/DEN, EDF R&D, OPEN CASCADE
3 // Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
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.
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.
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
20 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
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
28 #ifndef _DATAFLOWEXECUTOR_OUTNODE_HXX
29 #define _DATAFLOWEXECUTOR_OUTNODE_HXX
31 #include "SALOME_Component_i.hxx"
33 #include "DataFlowExecutor_InNode.hxx"
35 #include "DataFlowBase_StreamGraph.hxx"
37 namespace GraphExecutor {
39 // class OutNode : public GraphBase::Graph {
40 class OutNode : public GraphBase::Base {
44 GraphBase::StreamGraph * _StreamGraph ;
45 GraphBase::Graph * _Graph ;
47 int _Graph_prof_debug ;
52 GraphExecutor::AutomatonState _State ;
53 SUPERV::ControlState _ControlState ;
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 ;
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 ;
72 pthread_t _run_func_thread ;
78 bool LoadNodes( const GraphBase::ListOfSNodes &aNodes ) ;
79 bool LoadLinks( const GraphBase::ListOfSLinks &aLinks ) ;
80 bool LoadDatas( const GraphBase::ListOfSLinks &aDatas ) ;
84 // scan (reverse) the _EventNodes queue and leave only 1 (the last one that came)
85 // event for every node
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 ) ;
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() {
117 GraphBase::Graph * Graph() const {
120 char * Name() { return Graph()->Name() ; } ;
122 bool LoadDataFlow( const GraphBase::SGraph * aDataFlow ) ;
123 // bool LoadXml( const char* myFileName ) ;
124 bool LoadInfo( const GraphBase::SNode &aDataFlowInfo ) ;
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 ) ;
143 bool IsValid() { if ( !_Valid )
146 bool IsExecutable() { if ( !_Executable )
147 return Executable() ;
148 return _Executable ; } ;
150 bool Run( const bool AndSuspend ) ;
152 void PyInitialized( bool init ) {
153 _PyInitialized = init ; } ;
154 bool PyInitialized() {
155 return _PyInitialized ; } ;
157 void CheckAllDone() ;
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() ;
168 void ExitThread( pthread_t ThreadNumber = 0 ) ;
169 void SuspendThread() ;
170 void ResumeThread() ;
171 long Threads() { return _Threads ; } ;
172 long SuspendedThreads() { return _SuspendedThreads ; } ;
175 pthread_t ThreadNo() {
176 return _Graph->ThreadNo() ; } ;
177 long Thread( const char * NodeName ) ;
179 void IncrCreatedThreads() {
180 _CreatedThreads += 1 ; } ;
181 long CreatedThreads() {
182 return _CreatedThreads ; } ;
184 bool PushEvent( GraphExecutor::InNode * aNode ,
185 GraphExecutor::NodeEvent anEvent ,
186 GraphExecutor::AutomatonState aState ) ;
188 bool StateWait( SUPERV::GraphState aState ) ;
189 bool Event( char ** aNodeName ,
190 SUPERV::GraphEvent & anEvent ,
191 SUPERV::GraphState & aState ,
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 ) ;
202 void SendSomeDataReady( const char * aNodeName ) ;
204 void State(GraphExecutor::AutomatonState aState ) ;
205 const char * StateName(GraphExecutor::AutomatonState aState ) {
206 return theAutomaton->StateName( aState ) ; }
208 SUPERV::GraphState State() ;
209 SUPERV::GraphState State( const char * NodeName ) ;
210 SUPERV::GraphState State( const char * NodeName ,
211 const char * ServiceParameterName ) ;
213 SUPERV::GraphEvent AutomatonGraphEvent(GraphExecutor::NodeEvent anEvent) ;
214 SUPERV::GraphState AutomatonGraphState(GraphExecutor::AutomatonState anAutomatonState) ;
216 GraphExecutor::AutomatonState AutomatonState() ;
217 GraphExecutor::AutomatonState AutomatonState( const char * NodeName ) ;
219 SUPERV::ControlState ControlState() ;
220 SUPERV::ControlState ControlState( const char * aNodeName ) ;
221 void ControlClear() ;
222 void ControlClear( const char * aNodeName ) ;
224 bool ContainerKill() ;
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 ; } ;
241 void Done( bool aDone ) { _Done = aDone ; } ;
242 bool Done() { return _Done ; } ;
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() ;
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 ) ;
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 ) ;
274 void setRunFuncThread( pthread_t theThread ) { _run_func_thread = theThread; } ; // mkr : IPAL14711