1 // SUPERV GraphExecutor : contains classes that permit execution of graphs and particularly the execution automaton
3 // Copyright (C) 2003 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.opencascade.org/SALOME/ or email : webmaster.salome@opencascade.org
24 // File : DataFlowBase_InNode.hxx
25 // Author : Jean Rahuel, CEA
29 #ifndef _DATAFLOWEXECUTOR_INNODE_HXX
30 #define _DATAFLOWEXECUTOR_INNODE_HXX
36 #include "DataFlowBase_Graph.hxx"
37 #include "DataFlowBase_FactoryNode.hxx"
38 #include "DataFlowBase_GOTONode.hxx"
39 #include "DataFlowBase_LoopNode.hxx"
40 #include "DataFlowBase_EndOfLoopNode.hxx"
41 #include "DataFlowBase_SwitchNode.hxx"
42 #include "DataFlowBase_EndOfSwitchNode.hxx"
44 #include "DataFlowExecutor_FiniteStateMachine.hxx"
46 #define MAXSTACKTHREADSIZE 127
48 void * run_function(void *p);
50 extern GraphExecutor::FiniteStateMachine * theAutomaton ;
52 extern "C" PyObject * PyRunMethod( PyObject * dummy , PyObject * args ) ;
54 namespace GraphExecutor {
56 struct ServicesAnyData {
63 // class InNode : public GraphBase::Node {
64 class InNode : public GraphBase::Base {
68 GraphBase::ComputingNode * _ComputingNode ;
69 GraphBase::FactoryNode * _FactoryNode ;
70 GraphBase::InLineNode * _InLineNode ;
71 GraphBase::GOTONode * _GOTONode ;
72 GraphBase::LoopNode * _LoopNode ;
73 GraphBase::EndOfLoopNode * _EndOfLoopNode ;
74 GraphBase::SwitchNode * _SwitchNode ;
75 GraphBase::EndOfSwitchNode * _EndOfSwitchNode ;
76 GraphBase::Graph * _GraphMacroNode ;
78 PyObject * _MyPyRunMethod ;
80 bool _createNewThread ;
81 bool _createNewThreadIf ;
83 GraphExecutor::AutomatonState _OldState ;
84 GraphExecutor::AutomatonState _currentState ;
85 GraphExecutor::NodeEvent _CurrentEvent ;
86 SUPERV::ControlState _ControlState ;
87 GraphExecutor::AutomatonState _NextState ;
88 GraphExecutor::StateEventAction _NextAction ;
91 pthread_mutex_t _MutexDataWait ;
94 pthread_mutex_t _MutexWait ;
96 pthread_cond_t _ReadyWait ;
97 pthread_cond_t _RunningWait ;
98 pthread_cond_t _DoneWait ;
99 pthread_cond_t _SuspendedWait ;
101 pthread_cond_t _SuspendWait ;
103 pthread_cond_t _ResumeWait ;
105 GraphExecutor::NodeEvent _aResumeEvent ;
106 GraphExecutor::InNode * _aReStartNode ;
107 GraphExecutor::NodeEvent _aReStartEvent ;
109 pthread_cond_t _KillWait ;
111 pthread_cond_t _StopWait ;
113 pthread_cond_t _ThreadStartedWait ;
114 bool _ThreadStartedSync ;
116 pthread_t _Pythread ;
120 GraphExecutor::FiniteStateMachine * _Automaton ;
124 GraphExecutor::OutNode * _OutNode ;
126 char * _DataFromNode ;
131 InNode( CORBA::ORB_ptr ORB, SALOME_NamingService* ptrNamingService,
132 const SALOME_ModuleCatalog::Service& NodeService ,
133 const char *NodeComponentName ,
134 const char* NodeInterfaceName ,
135 const char *NodeName ,
136 const SUPERV::KindOfNode akind = SUPERV::ComputingNode ,
137 GraphBase::ListOfFuncName aFuncName = GraphBase::ListOfFuncName() ,
138 GraphBase::ListOfPythonFunctions aPythonFunction = GraphBase::ListOfPythonFunctions() ,
139 const SUPERV::SDate NodeFirstCreation = SUPERV::SDate() ,
140 const SUPERV::SDate NodeLastModification = SUPERV::SDate() ,
141 const char * NodeEditorRelease = NULLSTRING ,
142 const char * NodeAuthor = NULLSTRING ,
143 const char * NodeComputer = NULLSTRING ,
144 const char * NodeComment = NULLSTRING ,
145 const bool GeneratedName = false ,
146 const int NodeX = 0 ,
147 const int NodeY = 0 ,
148 int * Graph_prof_debug = NULL ,
149 ofstream * Graph_fdebug = NULL ) ;
152 pthread_t ThreadNo() {
153 return _ComputingNode->ThreadNo() ; } ;
154 void ThreadNo( pthread_t aThread ) {
155 _ComputingNode->ThreadNo ( aThread ) ; } ;
157 char * Name() const {
158 return _ComputingNode->Name() ; } ;
159 const char *const * NamePtr() const {
160 return _ComputingNode->NamePtr() ; } ;
161 SUPERV::KindOfNode Kind() const {
162 return _ComputingNode->Kind() ; } ;
163 const bool IsComputingNode() const {
164 return _ComputingNode->IsComputingNode() ; } ;
165 const bool IsFactoryNode() const {
166 return _ComputingNode->IsFactoryNode() ; } ;
167 const bool IsInLineNode() const {
168 return _ComputingNode->IsInLineNode() ; } ;
169 const bool IsOneOfInLineNodes() const {
170 return _ComputingNode->IsOneOfInLineNodes() ; } ;
171 const bool IsOneOfGOTONodes() const {
172 return _ComputingNode->IsOneOfGOTONodes() ; } ;
173 const bool IsMacroNode() const {
174 return _ComputingNode->IsMacroNode() ; } ;
175 const bool IsDataFlowNode() const {
176 return _ComputingNode->IsDataFlowNode() ; } ;
177 const bool IsDataStreamNode() const {
178 return _ComputingNode->IsDataStreamNode() ; } ;
179 const bool IsLoopNode() const {
180 return _ComputingNode->IsLoopNode() ; } ;
181 const bool IsEndLoopNode() const {
182 return _ComputingNode->IsEndLoopNode() ; } ;
183 const bool IsSwitchNode() const {
184 return _ComputingNode->IsSwitchNode() ; } ;
185 const bool IsEndSwitchNode() const {
186 return _ComputingNode->IsEndSwitchNode() ; } ;
187 const bool IsGOTONode() const {
188 return _ComputingNode->IsGOTONode() ; } ;
189 const bool IsHeadNode() const {
190 return _ComputingNode->IsHeadNode() ; } ;
191 GraphBase::ComputingNode * ComputingNode() {
192 return _ComputingNode ; } ;
193 GraphBase::FactoryNode * FactoryNode() {
194 return _FactoryNode ; } ;
195 GraphBase::GOTONode * GOTONode() {
200 if ( _EndOfLoopNode )
201 return _EndOfLoopNode ;
204 if ( _EndOfSwitchNode )
205 return _EndOfSwitchNode ;
208 GraphBase::InLineNode * InLineNode() {
209 GraphBase::InLineNode * aNode = GOTONode() ;
214 GraphBase::LoopNode * LoopNode() {
215 return _LoopNode ; } ;
216 GraphBase::Graph * GraphMacroNode() {
217 return _GraphMacroNode ; } ;
219 SUPERV::CNode_var ObjRef() const { return _ComputingNode->ObjRef() ; } ;
220 void SetObjRef( SUPERV::CNode_var aNode ) {
221 _ComputingNode->SetObjRef( aNode ) ; } ;
223 CNode_Impl * ObjImpl() const { return _ComputingNode->ObjImpl() ; } ;
224 void SetObjImpl( CNode_Impl * aGraph ) {
225 _ComputingNode->SetObjImpl( aGraph ) ; } ;
227 Engines::Component_var Component() const ;
228 Engines::Container_var Container() const ;
229 void SetContainer(Engines::Container_var aContainer) {
230 _FactoryNode->SetContainer( aContainer ) ; } ;
231 void SetComponent(Engines::Component_var anObjComponent) {
232 _FactoryNode->SetComponent( anObjComponent ) ; } ;
233 void ObjInterface( bool k_interface ) {
234 _ComputingNode->ObjInterface( k_interface ) ; } ;
235 bool ObjInterface() {
236 return _FactoryNode->ObjInterface() ; } ;
237 char * ComponentName() const { return _FactoryNode->ComponentName() ; } ;
238 char * InterfaceName() const { return _FactoryNode->InterfaceName() ; } ;
239 char * Computer() const { return _FactoryNode->Computer() ; } ;
240 const char * ServiceName() const {
241 return _ComputingNode->ServiceName() ; } ;
242 const SALOME_ModuleCatalog::ListOfServicesParameter ServiceInParameter() const {
243 return _ComputingNode->ServiceInParameter() ; } ;
244 const SALOME_ModuleCatalog::ListOfServicesParameter ServiceOutParameter() const {
245 return _ComputingNode->ServiceOutParameter() ; } ;
247 void CoupledNode( GraphBase::InLineNode * aCoupledNode ) {
248 GOTONode()->CoupledNode( aCoupledNode ) ; } ;
249 GraphBase::InLineNode * CoupledNode() {
250 return GOTONode()->CoupledNode() ; } ;
252 GraphBase::InPort * AddInPort( const char * InputParameterName ,
253 const char * InputParameterType ,
254 const SUPERV::KindOfPort aKindOfPort ) {
255 return _ComputingNode->AddInPort( InputParameterName ,
258 GraphBase::OutPort * AddOutPort( const char * OutputParameterName ,
259 const char * OutputParameterType ,
260 const SUPERV::KindOfPort aKindOfPort ) {
261 return _ComputingNode->AddOutPort( OutputParameterName ,
262 OutputParameterType ,
264 // void InOutPort( GraphBase::InPort * InputPort ,
265 // GraphBase::OutPort * OutputPort ) {
266 // return _ComputingNode->InOutPort( InputPort , OutputPort ) ; } ;
267 int LinkedNodesSize() const {
268 return _ComputingNode->LinkedNodesSize() ; } ;
269 // GraphBase::ComputingNode * LinkedNodes( int i ) const {
270 GraphBase::StreamNode * LinkedNodes( int i ) const {
271 return _ComputingNode->LinkedNodes( i ) ; } ;
272 const int LinkedInPortsNumber( int i ) const {
273 return _ComputingNode->LinkedInPortsNumber( i ) ; } ;
275 const int GetNodeInPortsSize() const {
276 return _ComputingNode->GetNodeInPortsSize() ; } ;
277 const GraphBase::InPort *GetNodeInLoop() const {
278 return _ComputingNode->GetNodeInLoop() ; } ;
279 const GraphBase::InPort *GetNodeInGate() const {
280 return _ComputingNode->GetNodeInGate() ; } ;
281 const GraphBase::InPort *GetNodeInPort(int i) const {
282 return _ComputingNode->GetNodeInPort( i ) ; } ;
283 GraphBase::InPort *GetChangeNodeInLoop() const {
284 return _ComputingNode->GetChangeNodeInLoop() ; } ;
285 GraphBase::InPort *GetChangeNodeInGate() const {
286 return _ComputingNode->GetChangeNodeInGate() ; } ;
287 GraphBase::InPort *GetChangeNodeInPort(int i) const {
288 return _ComputingNode->GetChangeNodeInPort( i ) ; } ;
289 const int GetNodeOutPortsSize() const {
290 return _ComputingNode->GetNodeOutPortsSize() ; } ;
291 const GraphBase::OutPort *GetNodeOutLoop() const {
292 return _ComputingNode->GetNodeOutLoop() ; } ;
293 const GraphBase::OutPort *GetNodeOutGate() const {
294 return _ComputingNode->GetNodeOutGate() ; } ;
295 const GraphBase::OutPort *GetNodeOutPort(int i) const {
296 return _ComputingNode->GetNodeOutPort( i ) ; } ;
297 GraphBase::OutPort *GetChangeNodeOutLoop() const {
298 return _ComputingNode->GetChangeNodeOutLoop() ; } ;
299 GraphBase::OutPort *GetChangeNodeOutGate() const {
300 return _ComputingNode->GetChangeNodeOutGate() ; } ;
301 GraphBase::OutPort *GetChangeNodeOutPort(int i) const {
302 return _ComputingNode->GetChangeNodeOutPort( i ) ; } ;
304 const GraphBase::InPort *GetInPort( const char *name ) {
305 return _ComputingNode->GetInPort( name ) ; } ;
306 const GraphBase::OutPort *GetOutPort( const char *name ) {
307 return _ComputingNode->GetOutPort( name ) ; } ;
308 GraphBase::InPort *GetChangeInPort( const char *name ) {
309 return _ComputingNode->GetChangeInPort( name ) ; } ;
310 GraphBase::OutPort *GetChangeOutPort( const char *name ) {
311 return _ComputingNode->GetChangeOutPort( name ) ; } ;
313 void PyFuncRunned( bool arunned ) {
314 _PyFuncRunned = arunned ; } ;
315 bool PyFuncRunned() {
316 return _PyFuncRunned ; } ;
319 PyObject * InitPyDynInvoke( char * PyFuncName ,
320 const SUPERV::ListOfStrings * aPythonFunction ,
323 void LockDataWait() ;
324 void UnLockDataWait() ;
325 bool IsLockedDataWait() { return _DataWait ; } ;
328 bool ContainerKill() ;
335 bool ReStart( const char * AtNodeName , const bool AndSuspend ) ;
338 void CreateNewThread( bool k_create ) { _createNewThread = k_create ; } ;
339 void CreateNewThreadIf( bool k_create ) { _createNewThreadIf = k_create ; } ;
340 bool CreateNewThread() { return _createNewThread ; } ;
341 bool CreateNewThreadIf() { return _createNewThreadIf ; } ;
342 void NewThread( pthread_t aThread ) ;
344 void RewindStack( int aRewindStack ) { _RewindStack = aRewindStack ; } ;
345 int RewindStack() const { return _RewindStack ; } ;
347 GraphExecutor::AutomatonState State() const {
348 return _currentState; };
349 void State(GraphExecutor::AutomatonState aState ) {
350 // cdebug << "GraphExecutor::InNode::State( "
351 // << Automaton()->StateName( _currentState ) << " --> "
352 // << Automaton()->StateName( aState ) << " )" << endl ;
353 _currentState = aState ; } ;
354 SUPERV::ControlState ControlState() const {
355 return _ControlState; };
356 void ControlState(SUPERV::ControlState aControlState ) {
357 _ControlState = aControlState ; } ;
358 void ControlClear() {
359 _ControlState = SUPERV::VoidState ; } ;
361 void SetAutomaton() {
362 _Automaton = theAutomaton ; } ;
363 GraphExecutor::FiniteStateMachine * Automaton() const {
364 return _Automaton ; } ;
374 bool StateWait( SUPERV::GraphState aState ) ;
378 bool SuspendedWait() ;
380 void InitialState( GraphExecutor::OutNode * theOutNode ) ;
381 bool InitPythonFunctions(bool WithErr ) ;
382 void SetWaitingStates(GraphExecutor::InNode * EndNode ) ;
384 int SendEvent(const GraphExecutor::NodeEvent anEvent ) ;
385 void DataFromNode( char * FromNodeName ) {
386 _DataFromNode = FromNodeName ; } ;
387 const char * DataFromNode() const { return _DataFromNode ; } ;
392 void RunningAction() ;
394 void SuspendedAction() ;
395 GraphExecutor::InNode * SuspendAction() ;
396 bool ResumeAction(GraphExecutor::NodeEvent aResumeEvent ) ;
397 bool ReStartAction( GraphExecutor::InNode * aRestartNode ,
398 GraphExecutor::NodeEvent anEvent ) ;
400 void KilledAction() ;
401 void ThreadStartAction() ;
402 void ThreadStartedAction() ;
404 void StoppedAction() ;
405 int executeAction() ; // New Thread or Same Thread
406 int ExecuteAction() ;
408 int DataWaiting_SomeDataReadyAction() ;
409 int DataUndef_NotAllDataReadyAction() ;
410 int DataUndef_AllDataReadyAction() ;
411 int DataReady_SuspendAction() ;
412 int SuspendedReady_ResumeAction() ;
413 int DataReady_KillAction() ;
414 int DataReady_StopAction() ;
415 int DataReady_ExecuteAction() ;
416 void DynInvoke( Engines::Component_ptr obj,
418 ServicesAnyData * inParams, int nInParams,
419 ServicesAnyData * outParams, int nOutParams) ;
420 void DynInvoke( Engines::Component_ptr obj,
422 const char * aGraphName ,
423 const char * aNodeName );
424 bool PyDynInvoke( PyObject * MyPyRunMethod ,
426 ServicesAnyData * inParams , int nInParams ,
427 ServicesAnyData * inParams , int nOutParams ) ;
429 int Executing_SuspendAction() ;
430 int SuspendedExecuting_ResumeAction() ;
431 int Executing_KillAction() ;
432 int Executing_StopAction() ;
433 int Executing_SuccessAction() ;
434 int Executing_ErrorAction() ;
435 int Successed_SuccessAction() ;
436 bool SendSomeDataReady( char * FromNodeName ) ;
437 int Errored_ErrorAction() ;
438 int Successed_SuspendAction() ;
439 int Errored_SuspendAction() ;
440 int SuspendedSuccessed_ResumeAction() ;
441 int SuspendedErrored_ResumeAction() ;
442 int Successed_KillAction() ;
443 int Errored_KillAction() ;
444 int Successed_StopAction() ;
445 int Errored_StopAction() ;
446 int SuspendedSuccessed_ReStartAction() ;
447 int SuspendedErrored_ReStartAction() ;
448 int SuspendedSuccessed_ReStartAndSuspendAction() ;
449 int SuspendedErrored_ReStartAndSuspendAction() ;
451 void InParametersSet( bool & Err ,
453 ServicesAnyData * InParametersList ) ;
454 void InOutParametersSet( int nOutParams ,
455 ServicesAnyData * OutParametersList ) ;
456 bool OutParametersSet( bool Err , SUPERV::GraphState NewState ,
458 ServicesAnyData * OutParametersList ) ;
462 const long CpuUsed( bool tot = false ) ;
464 long PyCpuUsed( bool tot = false ) ;
465 void SetPyCpuUsed() ;
468 bool PyRunSimpleString( char* thePyString );