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 : DataFlowExecutor_InNode.cxx
25 // Author : Jean Rahuel, CEA
39 #include <SALOMEconfig.h>
40 #include CORBA_CLIENT_HEADER(SALOME_Component)
41 //#include "SALOME_NamingService.hxx"
42 #include "SALOME_LifeCycleCORBA.hxx"
44 #include "DataFlowBase_FactoryNode.hxx"
45 #include "DataFlowBase_GOTONode.hxx"
46 #include "DataFlowBase_LoopNode.hxx"
47 #include "DataFlowBase_EndOfLoopNode.hxx"
48 #include "DataFlowBase_SwitchNode.hxx"
49 #include "DataFlowBase_EndOfSwitchNode.hxx"
51 #include "DataFlowExecutor_DataFlow.hxx"
52 #include "DataFlowEditor_DataFlow.hxx" // GraphEditor package must be built BEFORE
54 static void InitInNode( int &_RewindStack ,
55 SUPERV::ControlState &_ControlState ,
56 GraphExecutor::AutomatonState &_currentState ,
57 GraphExecutor::InNode ** _aReStartNode ,
58 bool & _PyFuncRunned ,
59 PyObject ** _MyPyRunMethod ,
60 pthread_mutex_t &_MutexDataWait ,
62 pthread_mutex_t &_MutexWait ,
63 pthread_cond_t &_ReadyWait ,
64 pthread_cond_t &_RunningWait ,
65 pthread_cond_t &_DoneWait ,
66 pthread_cond_t &_SuspendedWait ,
67 pthread_cond_t &_SuspendWait ,
69 pthread_cond_t &_ResumeWait ,
71 pthread_cond_t &_KillWait ,
73 pthread_cond_t &_ThreadStartedWait ,
74 bool &_ThreadStartedSync ,
75 pthread_cond_t &_StopWait ,
76 GraphExecutor::FiniteStateMachine ** _Automaton ,
77 GraphExecutor::FiniteStateMachine * theAutomaton ,
78 CORBA::ORB_ptr * _Orb ,
82 _ControlState = SUPERV::VoidState ;
83 _currentState = GraphExecutor::UnKnownState ;
84 *_aReStartNode = NULL ;
85 _PyFuncRunned = false ;
86 *_MyPyRunMethod = NULL ;
87 pthread_mutex_init( &_MutexDataWait , NULL ) ;
89 pthread_mutex_init( &_MutexWait , NULL ) ;
90 if ( pthread_cond_init( &_ReadyWait , NULL ) ) {
91 perror("pthread_cond_init( &_ReadyWait , NULL )") ;
94 if ( pthread_cond_init( &_RunningWait , NULL ) ) {
95 perror("pthread_cond_init( &_RunningWait , NULL )") ;
98 if ( pthread_cond_init( &_DoneWait , NULL ) ) {
99 perror("pthread_cond_init( &_DoneWait , NULL )") ;
102 if ( pthread_cond_init( &_SuspendedWait , NULL ) ) {
103 perror("pthread_cond_init( &_SuspendedWait , NULL )") ;
106 if ( pthread_cond_init( &_SuspendWait , NULL ) ) {
107 perror("pthread_cond_init( &_SuspendWait , NULL )") ;
110 _SuspendSync = false ;
111 if ( pthread_cond_init( &_ResumeWait , NULL ) ) {
112 perror("pthread_cond_init( &_ResumeWait , NULL )") ;
115 _ResumeSync = false ;
116 if ( pthread_cond_init( &_KillWait , NULL ) ) {
117 perror("pthread_cond_init( &_KillWait , NULL )") ;
121 if ( pthread_cond_init( &_ThreadStartedWait , NULL ) ) {
122 perror("pthread_cond_init( &_ThreadStartedWait , NULL )") ;
125 _ThreadStartedSync = false ;
126 if ( pthread_cond_init( &_StopWait , NULL ) ) {
127 perror("pthread_cond_init( &_StopWait , NULL )") ;
130 *_Automaton = theAutomaton ;
131 *_Orb = CORBA::ORB::_nil();
135 GraphExecutor::FiniteStateMachine * theAutomaton = new GraphExecutor::FiniteStateMachine() ;
137 //GraphExecutor::InNode::InNode() :
138 // GraphBase::FactoryNode() {
139 GraphExecutor::InNode::InNode() {
140 InitInNode( _RewindStack ,
169 GraphExecutor::InNode::InNode( CORBA::ORB_ptr ORB,
170 SALOME_NamingService* ptrNamingService ,
171 const SALOME_ModuleCatalog::Service& aService ,
172 const char * ComponentName ,
173 const char * NodeInterfaceName ,
174 const char * NodeName ,
175 const SUPERV::KindOfNode akind ,
176 GraphBase::ListOfFuncName aFuncName ,
177 GraphBase::ListOfPythonFunctions aPythonFunction ,
178 const SUPERV::SDate NodeFirstCreation ,
179 const SUPERV::SDate NodeLastModification ,
180 const char * NodeEditorRelease ,
181 const char * NodeAuthor ,
182 const char * NodeComputer ,
183 const char * NodeComment ,
184 const bool GeneratedName ,
187 int * Graph_prof_debug,
188 ofstream * Graph_fdebug) {
189 // ostream * Graph_fdebug = NULL ) :
190 // GraphBase::FactoryNode( ORB , ptrNamingService , aService ,
191 // ComponentName , NodeInterfaceName ,
192 // NodeName , akind ,
193 // NodeFirstCreation , NodeLastModification ,
194 // NodeEditorRelease , NodeAuthor ,
195 // NodeComputer , NodeComment , GeneratedName ,
197 // Graph_prof_debug , Graph_fdebug ) {
198 InitInNode( _RewindStack ,
225 SetDebug( ORB , Graph_prof_debug , Graph_fdebug ) ;
227 _ComputingNode = NULL ;
228 _FactoryNode = NULL ;
232 _EndOfLoopNode = NULL ;
234 _EndOfSwitchNode = NULL ;
236 case SUPERV::ComputingNode : {
237 cdebug << "GraphExecutor::InNode::InNode SUPERV::ComputingNode : " << NodeName ;
238 _ComputingNode = new GraphBase::ComputingNode( ORB , ptrNamingService ,
242 NodeLastModification ,
243 NodeEditorRelease , NodeAuthor ,
244 NodeComment , GeneratedName ,
246 Graph_prof_debug , Graph_fdebug ) ;
249 case SUPERV::FactoryNode : {
250 cdebug << "GraphExecutor::InNode::InNode SUPERV::FactoryNode : " << NodeName ;
251 _FactoryNode = new GraphBase::FactoryNode( ORB , ptrNamingService , aService ,
252 ComponentName , NodeInterfaceName ,
255 NodeLastModification ,
256 NodeEditorRelease , NodeAuthor ,
257 NodeComputer , NodeComment ,
258 GeneratedName , NodeX , NodeY ,
259 Graph_prof_debug , Graph_fdebug ) ;
260 _ComputingNode = (GraphBase::ComputingNode *) _FactoryNode ;
263 case SUPERV::InLineNode : {
264 cdebug << "GraphExecutor::InNode::InNode SUPERV::InLineNode : " << NodeName ;
265 _InLineNode = new GraphBase::InLineNode( ORB , ptrNamingService ,
266 aFuncName[0].c_str() , *aPythonFunction[0] ,
268 NodeFirstCreation , NodeLastModification ,
269 NodeEditorRelease , NodeAuthor ,
270 NodeComment , GeneratedName ,
272 Graph_prof_debug , Graph_fdebug ) ;
273 _ComputingNode = (GraphBase::ComputingNode *) _InLineNode ;
276 case SUPERV::MacroNode : {
277 cdebug << "GraphExecutor::InNode::InNode SUPERV::MacroNode : " << NodeName << endl ;
278 _GraphMacroNode = new GraphBase::Graph( ORB , ptrNamingService ,
279 // aFuncName[0].c_str() , *aPythonFunction[0] ,
281 // NodeFirstCreation , NodeLastModification ,
282 // NodeEditorRelease , NodeAuthor ,
283 // NodeComment , GeneratedName ,
285 Graph_prof_debug , Graph_fdebug ) ;
286 _ComputingNode = (GraphBase::ComputingNode *) _GraphMacroNode ;
287 _InLineNode = (GraphBase::InLineNode *) _ComputingNode ;
288 _GOTONode = (GraphBase::GOTONode *) _InLineNode ;
289 _GraphMacroNode->Coordinates( NodeX , NodeY ) ;
292 case SUPERV::GOTONode : {
293 cdebug << "GraphEditor::InNode::InNode SUPERV::GOTONode : " << NodeName ;
294 _GOTONode = new GraphBase::GOTONode( ORB , ptrNamingService ,
295 aFuncName[0].c_str() , *aPythonFunction[0] ,
297 NodeFirstCreation , NodeLastModification ,
298 NodeEditorRelease , NodeAuthor ,
299 NodeComment , GeneratedName ,
301 Graph_prof_debug , Graph_fdebug ) ;
302 _ComputingNode = (GraphBase::ComputingNode *) _GOTONode ;
303 _InLineNode = (GraphBase::InLineNode *) _ComputingNode ;
306 case SUPERV::LoopNode : {
307 cdebug << "GraphExecutor::InNode::InNode SUPERV::LoopNode : " << NodeName ;
308 _LoopNode = new GraphBase::LoopNode( ORB , ptrNamingService ,
309 aFuncName[0].c_str() , *aPythonFunction[0] ,
310 aFuncName[1].c_str() , *aPythonFunction[1] ,
311 aFuncName[2].c_str() , *aPythonFunction[2] ,
313 NodeFirstCreation , NodeLastModification ,
314 NodeEditorRelease , NodeAuthor ,
315 NodeComment , GeneratedName ,
317 Graph_prof_debug , Graph_fdebug ) ;
318 _ComputingNode = (GraphBase::ComputingNode *) _LoopNode ;
319 _GOTONode = (GraphBase::GOTONode *) _ComputingNode ;
320 _InLineNode = (GraphBase::InLineNode *) _ComputingNode ;
323 case SUPERV::EndLoopNode : {
324 cdebug << "GraphEditor::InNode::InNode SUPERV::EndOfLoopNode : " << NodeName ;
325 _EndOfLoopNode = new GraphBase::EndOfLoopNode(
326 ORB , ptrNamingService ,
327 aFuncName[0].c_str() , *aPythonFunction[0] ,
329 NodeFirstCreation , NodeLastModification ,
330 NodeEditorRelease , NodeAuthor ,
331 NodeComment , GeneratedName ,
333 Graph_prof_debug , Graph_fdebug ) ;
334 _ComputingNode = (GraphBase::ComputingNode *) _EndOfLoopNode ;
335 _GOTONode = (GraphBase::GOTONode *) _ComputingNode ;
336 _InLineNode = (GraphBase::InLineNode *) _ComputingNode ;
339 case SUPERV::SwitchNode : {
340 cdebug << "GraphExecutor::InNode::InNode SUPERV::SwitchNode : " << NodeName ;
341 _SwitchNode = new GraphBase::SwitchNode( ORB , ptrNamingService ,
342 aFuncName[0].c_str() , *aPythonFunction[0] ,
344 NodeFirstCreation , NodeLastModification ,
345 NodeEditorRelease , NodeAuthor ,
346 NodeComment , GeneratedName ,
348 Graph_prof_debug , Graph_fdebug ) ;
349 _ComputingNode = (GraphBase::ComputingNode *) _SwitchNode ;
350 _GOTONode = (GraphBase::GOTONode *) _ComputingNode ;
351 _InLineNode = (GraphBase::InLineNode *) _ComputingNode ;
354 case SUPERV::EndSwitchNode : {
355 cdebug << "GraphEditor::InNode::InNode SUPERV::EndOfSwitchNode : " << NodeName ;
356 _EndOfSwitchNode = new GraphBase::EndOfSwitchNode(
357 ORB , ptrNamingService ,
358 aFuncName[0].c_str() , *aPythonFunction[0] ,
360 NodeFirstCreation , NodeLastModification ,
361 NodeEditorRelease , NodeAuthor ,
362 NodeComment , GeneratedName ,
364 Graph_prof_debug , Graph_fdebug ) ;
365 _ComputingNode = (GraphBase::ComputingNode *) _EndOfSwitchNode ;
366 _GOTONode = (GraphBase::GOTONode *) _ComputingNode ;
367 _InLineNode = (GraphBase::InLineNode *) _ComputingNode ;
370 case SUPERV::DataFlowGraph : {
371 cdebug << "GraphEditor::InNode::InNode SUPERV::DataFlowGraph ERROR : " << NodeName ;
373 case SUPERV::DataStreamGraph : {
374 cdebug << "GraphEditor::InNode::InNode SUPERV::DataStreamGraph ERROR : " << NodeName ;
376 case SUPERV::UnknownNode : {
377 cdebug << "GraphEditor::InNode::InNode SUPERV::UnknownNode ERROR : " << NodeName ;
380 cdebug << "GraphExecutor::InNode::InNode " << (void *) this
381 << " _ComputingNode " << (void *) _ComputingNode ;
382 _ComputingNode->InNode( this ) ;
385 GraphExecutor::InNode::~InNode() {
388 void GraphExecutor::InNode::LockDataWait() {
389 if ( pthread_mutex_lock( &_MutexDataWait ) ) {
390 perror("Ready pthread_mutex_lock ") ;
395 void GraphExecutor::InNode::UnLockDataWait() {
397 if ( pthread_mutex_unlock( &_MutexDataWait ) ) {
398 perror("Ready pthread_mutex_unlock ") ;
403 Engines::Component_var GraphExecutor::InNode::Component() const {
404 if ( IsFactoryNode() ) {
405 return _FactoryNode->Component() ;
408 CORBA::Any const * anAnyComponent = GetChangeNodeInPort( 0 )->GetOutPort()->Value() ; // this
409 CORBA::Object_ptr obj ;
411 *anAnyComponent >>= obj ;
412 return Engines::Component::_narrow( obj ) ;
415 cdebug << "GraphExecutor::InNode::Component Component catch" << endl ;
418 return Engines::Component::_nil() ;
421 Engines::Container_var GraphExecutor::InNode::Container() const {
422 if ( IsFactoryNode() ) {
423 return _FactoryNode->Container() ;
425 return Engines::Container::_nil() ;
429 bool GraphExecutor::InNode::Ping() {
430 // cdebug_in << "GraphExecutor::InNode::Ping" << endl;
432 if ( IsFactoryNode() ) {
433 RetVal = !CORBA::is_nil( _FactoryNode->Component() ) ;
435 if ( State() != GraphExecutor::SuspendedExecutingState ) {
437 _FactoryNode->Component()->ping() ;
440 cdebug << "InNode::Ping() ERROR catched" << endl ;
441 State( GraphExecutor::ErroredState ) ;
442 _OutNode->State( GraphExecutor::ErroredState ) ;
451 // cdebug_out << "GraphExecutor::InNode::Ping" << endl ;
455 void GraphExecutor::InNode::NewThread( pthread_t aThread ) {
456 ThreadNo ( aThread ) ;
458 _OutNode->NewThread() ;
460 void GraphExecutor::InNode::ExitThread() {
462 _OutNode->ExitThread() ;
465 bool GraphExecutor::InNode::Suspend() {
466 cdebug_in << "GraphExecutor::InNode::Suspend " << Name() << " " << ThreadNo()
467 << " " << Automaton()->StateName( State() ) << endl;
468 bool RetVal = false ;
470 //If loop we need to suspend also ControlState( SUPERV::VoidState ) ;
471 ControlState( SUPERV::ToSuspendState ) ;
473 if ( _OutNode->IsDone() ) {
474 ControlState( SUPERV::VoidState ) ;
478 else if ( IsWaiting() || IsReady() ) {
479 ControlState( SUPERV::ToSuspendState ) ;
482 else if ( IsRunning() ) {
483 ControlState( SUPERV::ToSuspendState ) ;
484 if ( IsFactoryNode() || IsComputingNode() ) {
485 // We have to suspend in the container of that node
486 int TrySuspend = 10 ;
487 while ( TrySuspend ) {
488 if ( !CORBA::is_nil( Component() ) ) {
489 // We can call that component
491 RetVal = Component()->Suspend_impl() ;
494 cdebug << "InNode::Suspend() ERROR catched" << endl ;
495 State( GraphExecutor::ErroredState ) ;
496 _OutNode->State( GraphExecutor::ErroredState ) ;
500 cdebug << "Component()->Suspend_impl() returns status " << RetVal << endl ;
503 cdebug << pthread_self() << "GraphExecutor::InNode::Suspend_impl " << Name()
504 << " --> thread" << ThreadNo() << " SuspendEvent " << endl;
505 SendEvent( GraphExecutor::SuspendEvent ) ;
506 cdebug << pthread_self() << "GraphExecutor::InNode::Suspended_impl in Container"
507 << Name() << " --> thread" << ThreadNo() << endl;
510 else if ( IsDone() ) {
511 ControlState( SUPERV::VoidState ) ;
512 RetVal = false ; // Too late ...
516 cdebug << "InNode::Suspend component Suspended and !IsDone and !IsRunning !"
518 MESSAGE("InNode::Suspend component Suspended and !IsDone and !IsRunning !") ;
523 // Suspend in the Container failed : it is always false if it is a Python Container
524 cdebug << "InNode::Suspend cannot Suspend component ! Python Component ?"
526 if ( TrySuspend == 1 ) {
527 if ( IsSuspended() ) {
537 cdebug << "InNode::Suspend with nilComponent while RunningState !. Loading Component ?"
539 // Wait for the end of loading of the component
540 while ( IsLoading() ) {
543 if ( TrySuspend == 1 ) {
544 if ( IsSuspended() ) {
558 else if ( IsMacroNode() ) {
559 // It should be like that but it is not completely implemented
560 GraphBase::Graph * aGraph = (GraphBase::Graph * ) GraphMacroNode()->CoupledNode() ;
561 RetVal = aGraph->GraphEditor()->Executor()->Suspend() ;
563 State( GraphExecutor::SuspendedState ) ;
567 // Now we can suspend an InLineNode with the handler of the SuperVision Container
568 if ( pthread_kill( _OutNode->MainThreadId() , SIGUSR2 ) == -1 ) {
569 perror("Suspend pthread_kill error") ;
570 State( GraphExecutor::ErroredState ) ;
571 _OutNode->State( GraphExecutor::ErroredState ) ;
579 cdebug << pthread_self() << "GraphExecutor::InNode::Suspend " << Name()
580 << " --> thread" << ThreadNo() << " SuspendEvent " << endl;
581 SendEvent( GraphExecutor::SuspendEvent ) ;
582 cdebug << pthread_self() << "GraphExecutor::InNode::Suspended in SuperVision Container"
583 << Name() << " --> thread" << ThreadNo() << endl;
585 else if ( IsDone() ) {
586 ControlState( SUPERV::VoidState ) ;
587 RetVal = false ; // Too late ...
590 cdebug << "component Suspended and !IsDone and !IsRunning !"
597 cdebug << "Suspend and IsDone " << IsDone() << " and IsRunning " << IsRunning()
598 << " and IsWaiting " << IsWaiting() << " and IsReady " << IsReady()
602 cdebug_out << "GraphExecutor::InNode::Suspend " << RetVal << " "
603 << Automaton()->StateName( State() ) << endl ;
607 bool GraphExecutor::InNode::ContainerKill() {
608 cdebug_in << "GraphExecutor::InNode::ContainerKill " << Name() << " "
609 << ThreadNo() << endl;
611 if ( IsFactoryNode() ) {
613 RetVal = Container()->Kill_impl() ;
615 cdebug_out << "GraphExecutor::InNode::ContainerKill" << endl ;
619 bool GraphExecutor::InNode::Kill() {
620 cdebug_in << "GraphExecutor::InNode::Kill " << Name() << " " << ThreadNo() << " "
621 << Automaton()->StateName( State() ) << " Threads " << _OutNode->Threads()
622 << " SuspendedThreads " << _OutNode->SuspendedThreads()
623 << " EventQSize " << _OutNode->EventQSize() << endl;
626 ControlState( SUPERV::ToKillState ) ; // if loop
627 if ( _OutNode->IsDone() ) {
628 ControlState( SUPERV::VoidState ) ;
633 ControlState( SUPERV::ToKillState ) ;
635 if ( _OutNode->IsDone() ) {
636 ControlState( SUPERV::VoidState ) ;
642 if ( IsFactoryNode() || IsComputingNode() ) {
643 // We have to suspend in the container of that node
646 if ( !CORBA::is_nil( Component() ) ) {
647 // We can call that component
649 RetVal = Component()->Kill_impl() ;
652 cdebug << "InNode::Kill_impl ERROR catched" << endl ;
653 State( GraphExecutor::ErroredState ) ;
654 _OutNode->State( GraphExecutor::ErroredState ) ;
658 cdebug << "Component()->Kill_impl() returns status " << RetVal << endl ;
661 cdebug << pthread_self() << "GraphExecutor::InNode::Kill_impl " << Name()
662 << " --> thread" << ThreadNo() << " KillEvent " << endl;
663 SendEvent( GraphExecutor::KillEvent ) ;
664 cdebug << pthread_self() << "GraphExecutor::InNode::Killed_impl in Container"
665 << Name() << " --> thread" << ThreadNo() << endl;
668 else if ( IsDone() ) {
669 ControlState( SUPERV::VoidState ) ;
670 RetVal = false ; // Too late ...
674 cdebug << "Kill component Killed and !IsDone and !IsRunning !"
680 // Kill in the Container failed : it is always false if it is a Python Container
681 cdebug << "InNode::Suspend cannot Kill component ! Python Component ?"
683 if ( TryKill == 1 ) {
694 cdebug << "InNode::Kill with nilComponent while RunningState !. Loading Component ?"
696 // Wait for the end of loading of the component
697 while ( IsLoading() ) {
700 if ( TryKill == 1 ) {
715 else if ( IsMacroNode() ) {
716 // It should be like that but it is not completely implemented
717 GraphBase::Graph * aGraph = (GraphBase::Graph * ) GraphMacroNode()->CoupledNode() ;
718 RetVal = aGraph->GraphEditor()->Executor()->Kill() ;
720 State( GraphExecutor::KilledState ) ;
725 // Now we can kill an InLineNode with the handler of the SuperVision Container
726 cdebug << pthread_self() << "Kill of InLineNode " << Name() << " MainThreadId "
727 << _OutNode->MainThreadId() << " :" << endl ;
728 MESSAGE( pthread_self() << "Kill of InLineNode " << Name() << " MainThreadId "
729 << _OutNode->MainThreadId() << " :" ) ;
730 if ( pthread_kill( _OutNode->MainThreadId() , SIGINT ) == -1 ) {
731 // python signals run only in main thread ...
732 perror("Kill pthread_kill error") ;
733 State( GraphExecutor::ErroredState ) ;
734 _OutNode->State( GraphExecutor::ErroredState ) ;
738 cdebug << pthread_self() << "pthread_kill of InLineNode " << Name()
739 << " done. MainThreadId " << _OutNode->MainThreadId() << endl ;
740 MESSAGE( pthread_self() << "pthread_kill of InLineNode " << Name()
741 << " done. MainThreadId " << _OutNode->MainThreadId() ) ;
746 else if ( IsSuspended() ) {
747 cdebug << pthread_self() << "GraphExecutor::InNode::Kill " << Name()
748 << " --> thread" << ThreadNo() << " Resume()" << endl;
756 else if ( IsWaiting() ) {
759 else if ( IsReady() ) {
763 cdebug << "Kill and IsDone " << IsDone() << " and IsRunning " << IsRunning()
764 << " and IsWaiting " << IsWaiting() << " and IsReady " << IsReady()
770 cdebug_out << "GraphExecutor::InNode::Kill " << Name() << " " << ThreadNo() << " "
771 << Automaton()->StateName( State() ) << " Threads " << _OutNode->Threads()
772 << " SuspendedThreads " << _OutNode->SuspendedThreads()
773 << " EventQSize " << _OutNode->EventQSize() << endl ;
777 bool GraphExecutor::InNode::KillDone() {
778 cdebug_in << "GraphExecutor::InNode::KillDone " << Name() << " " << ThreadNo()
781 if ( ControlState() == SUPERV::ToKillDoneState || IsDone() ) {
785 ControlState( SUPERV::ToKillDoneState ) ;
787 if ( _OutNode->IsDone() ) {
788 ControlState( SUPERV::VoidState ) ;
796 else if ( IsWaiting() ) {
800 cdebug << "KillDone and !IsDone and !IsRunning and !IsWaiting ?"
806 cdebug_out << "GraphExecutor::InNode::KillDone" << endl ;
810 bool GraphExecutor::InNode::Stop() {
811 cdebug_in << "GraphExecutor::InNode::Stop " << Name() << " " << ThreadNo()
814 if ( ControlState() == SUPERV::ToStopState || IsDone() ) {
818 ControlState( SUPERV::ToStopState ) ;
820 if ( _OutNode->IsDone() ) {
821 ControlState( SUPERV::VoidState ) ;
827 if ( IsFactoryNode() || IsComputingNode() ) {
828 if ( !CORBA::is_nil( Component() ) ) {
830 RetVal = Component()->Stop_impl() ;
833 cdebug << "InNode::Stop() ERROR catched" << endl ;
834 State( GraphExecutor::ErroredState ) ;
835 _OutNode->State( GraphExecutor::ErroredState ) ;
840 SendEvent( GraphExecutor::StopEvent ) ;
842 else if ( IsDone() ) {
843 ControlState( SUPERV::VoidState ) ;
844 RetVal = false ; // Too late ...
847 cdebug << "component Suspended and !IsDone and !IsRunning !"
853 cdebug << "Suspend cannot Stop component ! Python Component ?" << endl ;
858 cdebug << "Suspend with nilComponent while RunningState !" << endl ;
862 else if ( IsWaiting() ) {
866 cdebug << "Suspend and !IsDone and !IsRunning and !IsWaiting ?"
872 cdebug_out << "GraphExecutor::InNode::Stop" << endl ;
876 bool GraphExecutor::InNode::SuspendDone() {
877 cdebug_in << "GraphExecutor::InNode::SuspendDone " << Name() << " "
878 << ThreadNo() << endl;
880 if ( ControlState() == SUPERV::ToSuspendDoneState || IsDone() ) {
884 ControlState( SUPERV::ToSuspendDoneState ) ;
886 if ( _OutNode->IsDone() ) {
887 ControlState( SUPERV::VoidState ) ;
895 cdebug_out << "GraphExecutor::InNode::SuspendDone" << endl ;
899 bool GraphExecutor::InNode::Resume() {
900 cdebug_in << pthread_self() << "/" << ThreadNo()
901 << " GraphExecutor::InNode::Resume " << Name() << " "
902 << Automaton()->StateName( State() ) << endl;
903 bool RetVal = false ;
904 if ( IsSuspended() ) {
905 if ( State() == GraphExecutor::SuspendedReadyState ) {
906 ResumeAction( GraphExecutor::ToResumeEvent ) ;
909 else if ( State() == GraphExecutor::SuspendedExecutingState ) {
910 if ( IsFactoryNode() || IsComputingNode() ) {
911 if ( pthread_mutex_lock( &_MutexWait ) ) {
912 perror("ResumeAction pthread_mutex_lock ") ;
916 RetVal = Component()->Resume_impl() ;
918 State( GraphExecutor::ExecutingState ) ;
922 cdebug << "InNode::Resume() ERROR catched" << endl ;
923 State( GraphExecutor::ErroredState ) ;
924 _OutNode->State( GraphExecutor::ErroredState ) ;
927 if ( pthread_mutex_unlock( &_MutexWait ) ) {
928 perror("ResumeAction pthread_mutex_unlock ") ;
932 else if ( IsMacroNode() ) {
933 cdebug << "Suspend of MacroNode not yet implemented ? Trying" << endl ;
934 GraphBase::Graph * aGraph = (GraphBase::Graph * ) GraphMacroNode()->CoupledNode() ;
935 RetVal = aGraph->GraphEditor()->Executor()->Resume() ;
937 State( GraphExecutor::ExecutingState ) ;
941 // Resume of InLinePythonNode in the Node of the SuperVisionContainer ...
942 cdebug << ThreadNo() << "/" << pthread_self()
943 << "Resume of InLineNode pthread_kill" << Name() << endl ;
944 if ( pthread_kill( _OutNode->MainThreadId() , SIGCONT ) == -1 ) {
945 perror("Resume pthread_kill error") ;
946 State( GraphExecutor::ErroredState ) ;
947 _OutNode->State( GraphExecutor::ErroredState ) ;
951 State( GraphExecutor::ExecutingState ) ;
956 else if ( State() == GraphExecutor::SuspendedSuccessedState ) {
957 ResumeAction( GraphExecutor::ResumeEvent ) ;
960 else if ( State() == GraphExecutor::SuspendedErroredState ) {
961 ResumeAction( GraphExecutor::ResumeEvent ) ;
965 cdebug << "GraphExecutor::InNode::Resume Not SuspendedReady/Executing/Successed/ErroredState "
966 << Automaton()->StateName( State() ) << endl ;
971 cdebug << "GraphExecutor::InNode::Resume Not Suspended State "
972 << Automaton()->StateName( State() ) << endl ;
975 if ( ControlState() == SUPERV::ToSuspendStartState ) {
976 ControlState( SUPERV::VoidState ) ;
980 if ( ControlState() == SUPERV::ToSuspendRunState ||
981 ( ControlState() == SUPERV::ToSuspendState &&
982 State() == GraphExecutor::SuspendedReadyState) ) {
983 if ( IsSuspended() ) {
984 if ( State() == GraphExecutor::SuspendedReadyState ) {
988 else if ( State() == GraphExecutor::SuspendedExecutingState ) {
990 RetVal = Component()->Resume_impl() ;
993 cdebug << "GraphExecutor::InNode::Resume State "
994 << Automaton()->StateName( State() ) << endl ;
997 if ( ControlState() != SUPERV::ToSuspendState ) {
998 ControlState( SUPERV::VoidState ) ;
1001 else if ( IsRunning() ) {
1004 else if ( IsWaiting() ) {
1005 ControlState( SUPERV::VoidState ) ;
1008 else if ( IsDone() ) {
1012 else if ( ControlState() == SUPERV::ToSuspendDoneState ||
1013 ( ControlState() == SUPERV::ToSuspendState &&
1014 State() == GraphExecutor::SuspendedSuccessedState) ) {
1015 if ( IsSuspended() ) {
1016 if ( State() == GraphExecutor::SuspendedSuccessedState ) {
1020 else if ( State() == GraphExecutor::SuspendedErroredState ) {
1025 cdebug << "GraphExecutor::InNode::Resume State " << State() << endl ;
1028 if ( ControlState() != SUPERV::ToSuspendState ) {
1029 ControlState( SUPERV::VoidState ) ;
1032 else if ( IsRunning() ) {
1033 ControlState( SUPERV::VoidState ) ;
1036 else if ( IsWaiting() ) {
1037 ControlState( SUPERV::VoidState ) ;
1040 else if ( IsDone() ) {
1041 ControlState( SUPERV::VoidState ) ;
1046 cdebug_out << "GraphExecutor::InNode::Resume " << Name() << " " << RetVal << " "
1047 << Automaton()->StateName( State() ) << endl ;
1051 bool GraphExecutor::InNode::IsWaiting() {
1053 // cdebug_in << "GraphExecutor::InNode::IsWaiting " << Name() << endl;
1054 GraphExecutor::AutomatonState aState = State() ;
1055 if ( aState == GraphExecutor::DataUndefState ||
1056 aState == GraphExecutor::DataWaitingState ||
1057 aState == GraphExecutor::SuspendedReadyState )
1058 // aState == GraphExecutor::SuspendedExecutingState ||
1059 // aState == GraphExecutor::SuspendedSuccessedState ||
1060 // aState == GraphExecutor::SuspendedErroredState ||
1061 // aState == GraphExecutor::SuspendedState
1063 // cdebug_out << "GraphExecutor::InNode::IsWaiting" << endl ;
1067 bool GraphExecutor::InNode::IsReady() {
1069 // cdebug_in << "GraphExecutor::InNode::IsReady " << Name() << endl;
1070 GraphExecutor::AutomatonState aState = State() ;
1071 // if ( aState == GraphExecutor::DataUndefState ||
1072 // aState == GraphExecutor::DataWaitingState ||
1073 if ( aState == GraphExecutor::DataReadyState ||
1074 aState == GraphExecutor::ResumedReadyState )
1076 // cdebug_out << "GraphExecutor::InNode::IsReady" << endl ;
1080 bool GraphExecutor::InNode::IsRunning() {
1082 // cdebug_in << "GraphExecutor::InNode::IsRunning " << Name() << endl;
1083 GraphExecutor::AutomatonState aState = State() ;
1084 if ( aState == GraphExecutor::ExecutingState ||
1085 aState == GraphExecutor::ResumedExecutingState )
1087 // cdebug_out << "GraphExecutor::InNode::IsRunning" << endl ;
1091 bool GraphExecutor::InNode::IsDone() {
1093 // cdebug_in << "GraphExecutor::InNode::IsDone " << Name() << endl;
1094 GraphExecutor::AutomatonState aState = State() ;
1095 if ( aState == GraphExecutor::KilledReadyState ||
1096 aState == GraphExecutor::StoppedReadyState ||
1097 aState == GraphExecutor::KilledExecutingState ||
1098 aState == GraphExecutor::StoppedExecutingState ||
1099 aState == GraphExecutor::SuspendedSuccessedState ||
1100 aState == GraphExecutor::SuspendedErroredState ||
1101 // aState == GraphExecutor::SuccessedExecutingState ||
1102 // aState == GraphExecutor::ErroredExecutingState ||
1103 aState == GraphExecutor::SuccessedState ||
1104 aState == GraphExecutor::ErroredState ||
1105 aState == GraphExecutor::ResumedSuccessedState ||
1106 aState == GraphExecutor::ResumedErroredState ||
1107 aState == GraphExecutor::KilledSuccessedState ||
1108 aState == GraphExecutor::StoppedSuccessedState )
1110 // cdebug_out << "GraphExecutor::InNode::IsDone" << endl ;
1114 bool GraphExecutor::InNode::IsSuspended() {
1116 // cdebug_in << "GraphExecutor::InNode::IsSuspended " << Name() << endl;
1117 GraphExecutor::AutomatonState aState = State() ;
1118 if ( aState == GraphExecutor::SuspendedReadyState ||
1119 aState == GraphExecutor::SuspendedExecutingState ||
1120 aState == GraphExecutor::SuspendedSuccessedState ||
1121 aState == GraphExecutor::SuspendedErroredState ||
1122 aState == GraphExecutor::SuspendedState )
1124 // cdebug_out << "GraphExecutor::InNode::IsSuspended" << endl ;
1127 bool GraphExecutor::InNode::IsKilled() {
1129 // cdebug_in << "GraphExecutor::InNode::IsKilled " << Name() << endl;
1130 GraphExecutor::AutomatonState aState = State() ;
1131 if ( aState == GraphExecutor::KilledReadyState ||
1132 aState == GraphExecutor::KilledExecutingState ||
1133 aState == GraphExecutor::KilledSuccessedState ||
1134 aState == GraphExecutor::KilledErroredState ||
1135 aState == GraphExecutor::KilledState )
1137 // cdebug_out << "GraphExecutor::InNode::IsKilled" << endl ;
1140 bool GraphExecutor::InNode::IsStopped() {
1142 // cdebug_in << "GraphExecutor::InNode::IsStopped " << Name() << endl;
1143 GraphExecutor::AutomatonState aState = State() ;
1144 if ( aState == GraphExecutor::StoppedReadyState ||
1145 aState == GraphExecutor::StoppedExecutingState ||
1146 aState == GraphExecutor::StoppedSuccessedState ||
1147 aState == GraphExecutor::StoppedErroredState ||
1148 aState == GraphExecutor::StoppedState )
1150 // cdebug_out << "GraphExecutor::InNode::IsStopped" << endl ;
1154 bool GraphExecutor::InNode::StateWait( SUPERV::GraphState aState ) {
1155 bool RetVal = false ;
1156 if ( pthread_mutex_lock( &_MutexWait ) ) {
1157 perror("pthread_mutex_lock _Wait") ;
1161 case SUPERV::ReadyState : {
1162 RetVal = IsReady() ;
1163 cdebug_in << pthread_self() << " StateWait( Ready ) " << RetVal
1164 << " " << Automaton()->StateName( _currentState )
1165 << " pthread_cond_wait _ReadyWait " << Name() << endl ;
1166 while ( !RetVal && !IsDone() ) {
1167 cdebug << pthread_self() << " pthread_cond_wait ReadyWait" << endl ;
1168 pthread_cond_wait( &_ReadyWait , &_MutexWait );
1169 RetVal = IsReady() ;
1170 cdebug << pthread_self() << " pthread_cond_waited ReadyWait "
1171 << Automaton()->StateName( _currentState ) << " " << RetVal
1174 cdebug_out << pthread_self() << " StateWait( Ready ) " << RetVal
1175 << " " << Automaton()->StateName( _currentState )
1176 << " pthread_cond_wait _ReadyWait " << Name() << endl ;
1179 case SUPERV::RunningState : {
1180 RetVal = IsRunning() ;
1181 cdebug_in << pthread_self() << " StateWait( Running ) " << RetVal
1182 << " " << Automaton()->StateName( _currentState )
1183 << " pthread_cond_wait _RunningWait " << Name() << endl ;
1184 while ( !RetVal && !IsDone() ) {
1185 cdebug << pthread_self() << " pthread_cond_wait RunningWait " << Name() << endl ;
1186 pthread_cond_wait( &_RunningWait , &_MutexWait );
1187 //We may have pthread_cond_waited but !IsRunning and !IsDone :
1188 RetVal = IsRunning() || State() == GraphExecutor::SuccessedExecutingState ||
1189 State() == GraphExecutor::ErroredExecutingState ;
1190 cdebug << pthread_self() << " pthread_cond_waited RunningWait "
1191 << Automaton()->StateName( _currentState ) << " " << RetVal
1192 << " " << Name() << endl ;
1194 cdebug_out << pthread_self() << " StateWait( Running ) " << RetVal
1195 << " " << Automaton()->StateName( _currentState )
1196 << " pthread_cond_wait _RunningWait " << Name() << endl ;
1199 case SUPERV::DoneState : {
1201 cdebug_in << pthread_self() << " StateWait( Done ) " << RetVal
1202 << " " << Automaton()->StateName( _currentState )
1203 << " pthread_cond_wait _DoneWait " << Name() << endl ;
1205 cdebug << pthread_self() << " pthread_cond_wait DoneWait" << endl ;
1206 pthread_cond_wait( &_DoneWait , &_MutexWait );
1208 cdebug << pthread_self() << " pthread_cond_waited DoneWait "
1209 << Automaton()->StateName( _currentState ) << " " << RetVal
1212 cdebug_out << pthread_self() << " StateWait( Done ) " << RetVal
1213 << " " << Automaton()->StateName( _currentState )
1214 << " pthread_cond_wait _DoneWait " << Name() << endl ;
1217 case SUPERV::SuspendState : {
1218 RetVal = IsSuspended() ;
1219 cdebug_in << pthread_self() << " StateWait( Suspend ) " << RetVal
1220 << " " << Automaton()->StateName( _currentState )
1221 << " pthread_cond_wait _SuspendedWait " << Name() << endl ;
1222 while ( !RetVal && !IsDone() ) {
1223 cdebug << pthread_self() << " pthread_cond_wait SuspendedWait" << endl ;
1224 pthread_cond_wait( &_SuspendedWait , &_MutexWait );
1225 RetVal = IsSuspended() ;
1226 cdebug << pthread_self() << " pthread_cond_waited SuspendedWait "
1227 << Automaton()->StateName( _currentState ) << " " << RetVal
1230 cdebug_out << pthread_self() << " StateWait( Suspend ) " << RetVal
1231 << " " << Automaton()->StateName( _currentState )
1232 << " pthread_cond_wait _SuspendedWait " << Name() << endl ;
1236 cdebug << " SUPERV::OutNode::StateWait Error Undefined State : "
1240 if ( pthread_mutex_unlock( &_MutexWait ) ) {
1241 perror("pthread_mutex_lock _Wait") ;
1247 bool GraphExecutor::InNode::ReadyWait() {
1248 // cdebug_in << "GraphExecutor::InNode::ReadyWait " << Name() << endl;
1250 aret = StateWait( SUPERV::ReadyState ) ;
1251 // cdebug_out << "GraphExecutor::InNode::ReadyWait" << endl ;
1255 bool GraphExecutor::InNode::RunningWait() {
1256 cdebug_in << pthread_self() << "GraphExecutor::InNode::RunningWait " << Name()
1257 << " " << Automaton()->StateName( State() ) << endl;
1259 aret = StateWait( SUPERV::RunningState ) ;
1260 cdebug_out << pthread_self() << "GraphExecutor::InNode::RunningWait " << Name()
1261 << " " << Automaton()->StateName( State() ) << endl;
1265 bool GraphExecutor::InNode::DoneWait() {
1266 // cdebug_in << "GraphExecutor::InNode::DoneWait " << Name() << endl;
1268 aret = StateWait( SUPERV::DoneState ) ;
1272 bool GraphExecutor::InNode::SuspendedWait() {
1273 // cdebug_in << "GraphExecutor::InNode::SuspendedWait " << Name() << endl;
1275 aret = StateWait( SUPERV::SuspendState ) ;
1279 void GraphExecutor::InNode::InitialState()
1281 cdebug_in << "GraphExecutor::InNode::InitialState Node " << Name() << endl;
1284 _ControlState = SUPERV::VoidState ;
1285 CreateNewThread( false ) ;
1286 CreateNewThreadIf( false ) ;
1287 _SuspendSync = false ;
1288 _ResumeSync = false ;
1291 // asv : 13.12.04 : Decided to set "Loading" state for factory and computing nodes ONLY.
1292 // See extended comment in p.2.19 of "Bugs and Improvements" about IsLoading for InLine.
1293 if ( IsComputingNode() || IsFactoryNode() ) {
1297 // ThreadNo( pthread_self() ) ;
1300 for ( i = 0 ; i < GetNodeOutPortsSize() ; i++ ) {
1301 if ( GetNodeOutPort(i)->IsDataStream() ) {
1302 GetChangeNodeOutPort(i)->State( SUPERV::ReadyState ) ;
1303 GetChangeNodeOutPort(i)->Done( true ) ;
1305 else if ( i != 0 || !IsGOTONode() ) {
1306 GetChangeNodeOutPort(i)->State( SUPERV::WaitingState ) ;
1307 GetChangeNodeOutPort(i)->Done( false ) ;
1311 int Pc = GetNodeInPortsSize() ;
1312 for ( i = 0 ; i < GetNodeInPortsSize() ; i++ ) {
1313 const GraphBase::InPort * anInPort = GetNodeInPort(i) ;
1314 GraphBase::OutPort * anOutPort = anInPort->GetOutPort() ;
1315 if ( IsHeadNode() && IsLoopNode() && anInPort->IsLoop() ) {
1316 anOutPort->PortStatus( DataConnected );
1317 anOutPort->State( SUPERV::ReadyState ) ;
1318 anOutPort->Done( true ) ;
1319 CORBA::Any * anAny = new CORBA::Any() ;
1320 *anAny <<= (long ) 1 ;
1321 anOutPort->Value( anAny ) ;
1324 // JR 15_09_2004 if backward link from GOTONode or EndLoopNode ==> DataConnected
1325 else if ( anInPort->IsGate() && anOutPort ) {
1326 anOutPort->State( SUPERV::WaitingState ) ;
1327 anOutPort->Done( false ) ;
1328 const GraphBase::ComputingNode * aFromNode = _OutNode->Graph()->GetGraphNode( anOutPort->NodeName() ) ;
1329 //JR if ( aFromNode->IsGOTONode() || aFromNode->IsEndLoopNode() ) {
1330 if ( aFromNode->IsGOTONode() || ( IsLoopNode() && CoupledNode() == aFromNode ) ) {
1331 // ASV: bug with synchronization of Inline nodes (via Gate ports) fixed.
1332 // before was "else if ( IsOneOfInlineNodes() )"
1333 // IsOneOfInline() == ( Inline || IsOneOfGOTO() ), so Inline are removed..
1334 anOutPort->PortStatus( DataConnected );
1335 anOutPort->State( SUPERV::ReadyState ) ;
1336 anOutPort->Done( true ) ;
1339 if ( anInPort->IsGate() && anOutPort == NULL ) {
1341 cdebug << "InPort" << i << " " << anInPort->PortName() << " Not connected Pc " << Pc << endl ;
1343 else if ( anOutPort ) {
1344 if ( anOutPort->IsDataConnected() || anOutPort->IsDataStream() ) {
1346 anOutPort->State( SUPERV::ReadyState ) ;
1347 anOutPort->Done( true ) ;
1348 cdebug << "InPort" << i << " " << anInPort->PortName() << " " << anInPort->PortStatus()
1349 << " " << theAutomaton->StateName( anOutPort->State() ) << " Pc " << Pc << endl ;
1351 else if ( anOutPort->IsPortConnected() ) {
1352 anOutPort->State( SUPERV::WaitingState ) ;
1353 anOutPort->Done( false ) ;
1354 cdebug << "InPort" << i << " " << anInPort->PortName() << " " << " " << anInPort->PortStatus()
1355 << " " << theAutomaton->StateName( anOutPort->State() ) << " Pc " << Pc << endl ;
1358 cdebug << "InPort" << i << " " << anInPort->PortName() << " " << anInPort->PortStatus()
1359 << " OutPort " << anOutPort->NodeName() << " " << anOutPort->PortName() << " "
1360 << theAutomaton->StateName( anOutPort->State() ) << " Pc " << Pc << endl ;
1364 cdebug << "InPort" << i << " " << anInPort->PortName() << " " << " " << anInPort->PortStatus()
1365 << " no corresponding OutPort Pc " << Pc << endl ;
1368 if ( !anOutPort->IsDataStream() || anInPort->IsDataStream() ) {
1369 cdebug << "InPort" << i << " state change : " << anInPort->PortName() << " from OutPort "
1370 << anOutPort->PortName() << " from Node " << anOutPort->NodeName()
1371 << " with state " << theAutomaton->StateName( anOutPort->State() ) << endl ;
1372 GetChangeNodeInPort(i)->State( anOutPort->State() ) ;
1374 else if ( anOutPort->IsDataConnected() ) {
1375 cdebug << "InPort" << i << " state change : " << anInPort->PortName() << " from OutPort "
1376 << anOutPort->PortName() << " from Node " << anOutPort->NodeName()
1377 << " with state ReadyState" << endl ;
1378 GetChangeNodeInPort(i)->State( SUPERV::ReadyState ) ;
1381 cdebug << "InPort" << i << " state NOT changed : " << anInPort->PortName() << " from OutPort "
1382 << anOutPort->PortName() << " " << anOutPort->PortStatus() << " from Node " << anOutPort->NodeName()
1383 << " with state " << anOutPort->State() << endl ;
1387 cdebug << "InPort" << i << " : " << anInPort->PortName() << " from OutPort "
1388 << anOutPort->PortName() << " from Node " << anOutPort->NodeName()
1390 if ( anOutPort->State() == SUPERV::WaitingState ) {
1391 cdebug << "WaitingState" ;
1393 else if ( anOutPort->State() == SUPERV::ReadyState ) {
1394 cdebug << "ReadyState" ;
1399 cdebug << " PortConnected("
1400 << anOutPort->IsPortConnected() << ") DataConnected("
1401 << anOutPort->IsDataConnected() << ")" << endl ;
1405 _currentState = Pc > 0 ? GraphExecutor::DataWaitingState
1406 : GraphExecutor::DataReadyState ;
1407 if ( Pc == GetNodeInPortsSize() ) {
1408 _OutNode->PushEvent( this , GraphExecutor::NoDataReadyEvent ,
1411 else if ( Pc != 0 ) {
1412 _OutNode->PushEvent( this , GraphExecutor::SomeDataReadyEvent ,
1416 _OutNode->PushEvent( this , GraphExecutor::AllDataReadyEvent ,
1420 for ( i = 0 ; i < GetNodeOutPortsSize() ; i++ ) {
1421 cdebug << "OutPort" << i << " : " << GetNodeOutPort(i)->PortName() << " "
1422 << theAutomaton->StateName( GetChangeNodeOutPort(i)->State() )
1423 << " " << GetNodeOutPort(i)->Kind() << endl ;
1426 cdebug << "CurrentState = " << theAutomaton->StateName( _currentState )
1429 cdebug_out << "GraphExecutor::InNode::InitialState" << endl;
1432 bool GraphExecutor::InNode::InitPythonFunctions(bool WithErr ) {
1433 cdebug_in << "GraphExecutor::InNode::InitPythonFunctions " << Name() << " WithErr " << WithErr
1434 << " PyFuncRunned() " << PyFuncRunned() << endl;
1436 if ( !PyFuncRunned() && IsOneOfInLineNodes() ) {
1437 if ( IsLoopNode() ) {
1438 PyObject * PyRunMethod = InLineNode()->PyRunMethod() ;
1439 PyObject * PyMoreMethod = NULL ;
1440 PyObject * PyNextMethod = NULL ;
1441 if ( PyRunMethod ) {
1444 PyRunMethod = InitPyDynInvoke( InLineNode()->PyFuncName() ,
1445 InLineNode()->PythonFunction() ,
1447 InLineNode()->PyRunMethod( PyRunMethod ) ;
1450 PyMoreMethod = LoopNode()->PyMoreMethod() ;
1451 if ( PyMoreMethod ) {
1454 PyMoreMethod = InitPyDynInvoke( LoopNode()->PyMoreName() ,
1455 LoopNode()->MorePythonFunction() ,
1457 LoopNode()->PyMoreMethod( PyMoreMethod ) ;
1461 PyNextMethod = LoopNode()->PyNextMethod() ;
1462 if ( PyNextMethod ) {
1465 PyNextMethod = InitPyDynInvoke( LoopNode()->PyNextName() ,
1466 LoopNode()->NextPythonFunction() ,
1468 LoopNode()->PyNextMethod( PyNextMethod ) ;
1471 cdebug << "GraphExecutor::InNode::InitPythonFunctions " << Name() << " PyRunMethod(Init) " << PyRunMethod
1472 << " PyMoreMethod " << PyMoreMethod << " PyNextMethod " << PyNextMethod << endl;
1474 else if ( IsInLineNode() || IsSwitchNode() ) {
1475 PyObject * PyRunMethod = InLineNode()->PyRunMethod() ;
1476 if ( PyRunMethod ) {
1479 PyRunMethod = InitPyDynInvoke( InLineNode()->PyFuncName() ,
1480 InLineNode()->PythonFunction() ,
1482 InLineNode()->PyRunMethod( PyRunMethod ) ;
1484 cdebug << "GraphExecutor::InNode::InitPythonFunctions " << Name() << " PyRunMethod " << PyRunMethod << endl;
1486 else if ( ( IsEndLoopNode() || IsEndSwitchNode() || IsGOTONode() ) &&
1487 (*InLineNode()->PythonFunction()).length() ) {
1488 PyObject * PyRunMethod = InLineNode()->PyRunMethod() ;
1489 if ( PyRunMethod ) {
1492 PyRunMethod = InitPyDynInvoke( InLineNode()->PyFuncName() ,
1493 InLineNode()->PythonFunction() ,
1495 InLineNode()->PyRunMethod( PyRunMethod ) ;
1497 cdebug << "GraphExecutor::InNode::InitPythonFunctions " << Name() << " PyRunMethod " << PyRunMethod << endl;
1500 Err = WithErr && Err ;
1501 cdebug_out << "GraphExecutor::InNode::InitPythonFunctions " << Name() ;
1503 cdebug << " Error " << Err ;
1509 const long GraphExecutor::InNode::CpuUsed( bool tot ) {
1510 CORBA::Long cpu = 0 ;
1511 // cout << "Begin CpuUsed " << Name() << " CpuUsed : " << cpu << " State "
1512 // << theAutomaton->StateName( _currentState ) << endl ;
1513 cdebug_in << "GraphExecutor::InNode::CpuUsed( " << tot << " )" << Name() << endl ;
1514 if ( IsOneOfInLineNodes() ) {
1515 // cdebug << "CpuUsed " << Name() << " --> PyCpuUsed()" << endl ;
1516 // cout << "CpuUsed " << Name() << " --> PyCpuUsed()" << endl ;
1517 cpu = PyCpuUsed( tot ) ;
1520 if ( !CORBA::is_nil( Component() ) ) {
1521 // cdebug << "CpuUsed " << Name() << " --> Component()->CpuUsed_impl()" << endl ;
1522 // cout << "CpuUsed " << Name() << " --> Component()->CpuUsed_impl()" << endl ;
1524 cpu = Component()->CpuUsed_impl() ;
1527 cdebug << "CpuUsed " << Name() << " --> Component()->CpuUsed_impl() ERROR catched " << endl ;
1528 State( GraphExecutor::ErroredState ) ;
1529 _OutNode->State( GraphExecutor::ErroredState ) ;
1534 cdebug_out << "GraphExecutor::InNode::CpuUsed " << Name() << " CpuUsed : " << cpu << endl ;
1535 // cout << "End CpuUsed " << Name() << " CpuUsed : " << cpu << " State "
1536 // << theAutomaton->StateName( _currentState ) << endl ;
1540 #include <sys/time.h>
1541 #include <sys/resource.h>
1544 long GraphExecutor::InNode::PyCpu() {
1545 struct rusage usage ;
1547 if ( getrusage( RUSAGE_SELF , &usage ) == -1 ) {
1548 perror("GraphExecutor::InNode::PyCpu") ;
1551 // return usage.ru_utime.__time_t tv_sec ;
1552 // cdebug << pthread_self() << "PyCpu " << Name() << " " << usage.ru_utime.tv_sec << " "
1553 // << usage.ru_utime.tv_usec << " " << usage.ru_stime.tv_sec << " " << usage.ru_stime.tv_usec
1555 cpu = usage.ru_utime.tv_sec ;
1559 long GraphExecutor::InNode::PyCpuUsed( bool tot ) {
1561 if ( _PyTotCpuUsed == -1 ) {
1562 if ( _Pythread == pthread_self() ) {
1563 // cdebug << pthread_self() << "GraphExecutor::InNode::PyCpuUsed(" << tot << ") " << Name()
1564 // << " _PyTotCpuUsed " << _PyTotCpuUsed << " PyCpu() " << PyCpu() << " - " << " _PyCpuUsed "
1565 // << _PyCpuUsed << endl ;
1566 cpu = PyCpu() - _PyCpuUsed ;
1568 _PyTotCpuUsed = cpu ;
1576 cpu = _PyTotCpuUsed ;
1578 // cdebug << pthread_self() << "GraphExecutor::InNode::PyCpuUsed(" << tot << ") " << Name() << "_PyTotCpuUsed"
1579 // << _PyTotCpuUsed << " CpuUsed : " << cpu << endl ;
1583 void GraphExecutor::InNode::SetPyCpuUsed() {
1584 _PyTotCpuUsed = -1 ;
1586 _Pythread = pthread_self() ;
1587 _PyCpuUsed = PyCpu() ;
1588 // cdebug << pthread_self() << "GraphExecutor::InNode::SetPyCpuUsed " << Name() << " _PyCpuUsed : "
1589 // << _PyCpuUsed << endl ;
1592 void GraphExecutor::InNode::IsLoading( bool Loading ) {
1593 _Loading = Loading ;
1595 // asv : 09.12.04 : "Bugs and Improvents" 2.19 : how it works:
1596 // LoadingState is returned by OutNode::State( NodeName ) if InNode->IsLoading()
1597 // after Loading is finished (here below), ExecutingState must be pushed for GUI.
1599 _OutNode->PushEvent( this, GraphExecutor::ExecuteEvent, GraphExecutor::ExecutingState );