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 // asv : 20.01.05 : changes involved with switching to old (HEAD) KERNEL
569 State( GraphExecutor::ErroredState ) ;
570 _OutNode->State( GraphExecutor::ErroredState ) ; RetVal = false;
571 cdebug << "Suspend of InLine nodes is NOT implemented." << endl;
572 MESSAGE( "Suspend of InLine nodes is NOT implemented." );
574 if ( pthread_kill( _OutNode->MainThreadId() , SIGUSR2 ) == -1 ) {
575 perror("Suspend pthread_kill error") ;
576 State( GraphExecutor::ErroredState ) ;
577 _OutNode->State( GraphExecutor::ErroredState ) ;
585 cdebug << pthread_self() << "GraphExecutor::InNode::Suspend " << Name()
586 << " --> thread" << ThreadNo() << " SuspendEvent " << endl;
587 SendEvent( GraphExecutor::SuspendEvent ) ;
588 cdebug << pthread_self() << "GraphExecutor::InNode::Suspended in SuperVision Container"
589 << Name() << " --> thread" << ThreadNo() << endl;
591 else if ( IsDone() ) {
592 ControlState( SUPERV::VoidState ) ;
593 RetVal = false ; // Too late ...
596 cdebug << "component Suspended and !IsDone and !IsRunning !"
604 cdebug << "Suspend and IsDone " << IsDone() << " and IsRunning " << IsRunning()
605 << " and IsWaiting " << IsWaiting() << " and IsReady " << IsReady()
609 cdebug_out << "GraphExecutor::InNode::Suspend " << RetVal << " "
610 << Automaton()->StateName( State() ) << endl ;
614 bool GraphExecutor::InNode::ContainerKill() {
615 cdebug_in << "GraphExecutor::InNode::ContainerKill " << Name() << " "
616 << ThreadNo() << endl;
618 if ( IsFactoryNode() ) {
620 RetVal = Container()->Kill_impl() ;
622 cdebug_out << "GraphExecutor::InNode::ContainerKill" << endl ;
626 bool GraphExecutor::InNode::Kill() {
627 cdebug_in << "GraphExecutor::InNode::Kill " << Name() << " " << ThreadNo() << " "
628 << Automaton()->StateName( State() ) << " Threads " << _OutNode->Threads()
629 << " SuspendedThreads " << _OutNode->SuspendedThreads()
630 << " EventQSize " << _OutNode->EventQSize() << endl;
633 ControlState( SUPERV::ToKillState ) ; // if loop
634 if ( _OutNode->IsDone() ) {
635 ControlState( SUPERV::VoidState ) ;
640 ControlState( SUPERV::ToKillState ) ;
642 if ( _OutNode->IsDone() ) {
643 ControlState( SUPERV::VoidState ) ;
649 if ( IsFactoryNode() || IsComputingNode() ) {
650 // We have to suspend in the container of that node
653 if ( !CORBA::is_nil( Component() ) ) {
654 // We can call that component
656 RetVal = Component()->Kill_impl() ;
659 cdebug << "InNode::Kill_impl ERROR catched" << endl ;
660 State( GraphExecutor::ErroredState ) ;
661 _OutNode->State( GraphExecutor::ErroredState ) ;
665 cdebug << "Component()->Kill_impl() returns status " << RetVal << endl ;
668 cdebug << pthread_self() << "GraphExecutor::InNode::Kill_impl " << Name()
669 << " --> thread" << ThreadNo() << " KillEvent " << endl;
670 SendEvent( GraphExecutor::KillEvent ) ;
671 cdebug << pthread_self() << "GraphExecutor::InNode::Killed_impl in Container"
672 << Name() << " --> thread" << ThreadNo() << endl;
675 else if ( IsDone() ) {
676 ControlState( SUPERV::VoidState ) ;
677 RetVal = false ; // Too late ...
681 cdebug << "Kill component Killed and !IsDone and !IsRunning !"
687 // Kill in the Container failed : it is always false if it is a Python Container
688 cdebug << "InNode::Suspend cannot Kill component ! Python Component ?"
690 if ( TryKill == 1 ) {
701 cdebug << "InNode::Kill with nilComponent while RunningState !. Loading Component ?"
703 // Wait for the end of loading of the component
704 while ( IsLoading() ) {
707 if ( TryKill == 1 ) {
722 else if ( IsMacroNode() ) {
723 // It should be like that but it is not completely implemented
724 GraphBase::Graph * aGraph = (GraphBase::Graph * ) GraphMacroNode()->CoupledNode() ;
725 RetVal = aGraph->GraphEditor()->Executor()->Kill() ;
727 State( GraphExecutor::KilledState ) ;
732 // Now we can kill an InLineNode with the handler of the SuperVision Container
733 // asv : 20.01.05 : changes involved with switching to old (HEAD) KERNEL
734 State( GraphExecutor::ErroredState ) ;
735 _OutNode->State( GraphExecutor::ErroredState ) ;
737 cdebug << "Kill of InLine nodes is NOT implemented." << endl;
738 MESSAGE( "Kill of InLine nodes is NOT implemented." );
740 cdebug << pthread_self() << "Kill of InLineNode " << Name() << " MainThreadId "
741 << _OutNode->MainThreadId() << " :" << endl ;
742 MESSAGE( pthread_self() << "Kill of InLineNode " << Name() << " MainThreadId "
743 << _OutNode->MainThreadId() << " :" ) ;
744 if ( pthread_kill( _OutNode->MainThreadId() , SIGINT ) == -1 ) {
745 // python signals run only in main thread ...
746 perror("Kill pthread_kill error") ;
747 State( GraphExecutor::ErroredState ) ;
748 _OutNode->State( GraphExecutor::ErroredState ) ;
752 cdebug << pthread_self() << "pthread_kill of InLineNode " << Name()
753 << " done. MainThreadId " << _OutNode->MainThreadId() << endl ;
754 MESSAGE( pthread_self() << "pthread_kill of InLineNode " << Name()
755 << " done. MainThreadId " << _OutNode->MainThreadId() ) ;
761 else if ( IsSuspended() ) {
762 cdebug << pthread_self() << "GraphExecutor::InNode::Kill " << Name()
763 << " --> thread" << ThreadNo() << " Resume()" << endl;
771 else if ( IsWaiting() ) {
774 else if ( IsReady() ) {
778 cdebug << "Kill and IsDone " << IsDone() << " and IsRunning " << IsRunning()
779 << " and IsWaiting " << IsWaiting() << " and IsReady " << IsReady()
785 cdebug_out << "GraphExecutor::InNode::Kill " << Name() << " " << ThreadNo() << " "
786 << Automaton()->StateName( State() ) << " Threads " << _OutNode->Threads()
787 << " SuspendedThreads " << _OutNode->SuspendedThreads()
788 << " EventQSize " << _OutNode->EventQSize() << endl ;
792 bool GraphExecutor::InNode::KillDone() {
793 cdebug_in << "GraphExecutor::InNode::KillDone " << Name() << " " << ThreadNo()
796 if ( ControlState() == SUPERV::ToKillDoneState || IsDone() ) {
800 ControlState( SUPERV::ToKillDoneState ) ;
802 if ( _OutNode->IsDone() ) {
803 ControlState( SUPERV::VoidState ) ;
811 else if ( IsWaiting() ) {
815 cdebug << "KillDone and !IsDone and !IsRunning and !IsWaiting ?"
821 cdebug_out << "GraphExecutor::InNode::KillDone" << endl ;
825 bool GraphExecutor::InNode::Stop() {
826 cdebug_in << "GraphExecutor::InNode::Stop " << Name() << " " << ThreadNo()
829 if ( ControlState() == SUPERV::ToStopState || IsDone() ) {
833 ControlState( SUPERV::ToStopState ) ;
835 if ( _OutNode->IsDone() ) {
836 ControlState( SUPERV::VoidState ) ;
842 if ( IsFactoryNode() || IsComputingNode() ) {
843 if ( !CORBA::is_nil( Component() ) ) {
845 RetVal = Component()->Stop_impl() ;
848 cdebug << "InNode::Stop() ERROR catched" << endl ;
849 State( GraphExecutor::ErroredState ) ;
850 _OutNode->State( GraphExecutor::ErroredState ) ;
855 SendEvent( GraphExecutor::StopEvent ) ;
857 else if ( IsDone() ) {
858 ControlState( SUPERV::VoidState ) ;
859 RetVal = false ; // Too late ...
862 cdebug << "component Suspended and !IsDone and !IsRunning !"
868 cdebug << "Suspend cannot Stop component ! Python Component ?" << endl ;
873 cdebug << "Suspend with nilComponent while RunningState !" << endl ;
877 else if ( IsWaiting() ) {
881 cdebug << "Suspend and !IsDone and !IsRunning and !IsWaiting ?"
887 cdebug_out << "GraphExecutor::InNode::Stop" << endl ;
891 bool GraphExecutor::InNode::SuspendDone() {
892 cdebug_in << "GraphExecutor::InNode::SuspendDone " << Name() << " "
893 << ThreadNo() << endl;
895 if ( ControlState() == SUPERV::ToSuspendDoneState || IsDone() ) {
899 ControlState( SUPERV::ToSuspendDoneState ) ;
901 if ( _OutNode->IsDone() ) {
902 ControlState( SUPERV::VoidState ) ;
910 cdebug_out << "GraphExecutor::InNode::SuspendDone" << endl ;
914 bool GraphExecutor::InNode::Resume() {
915 cdebug_in << pthread_self() << "/" << ThreadNo()
916 << " GraphExecutor::InNode::Resume " << Name() << " "
917 << Automaton()->StateName( State() ) << endl;
918 bool RetVal = false ;
919 if ( IsSuspended() ) {
920 if ( State() == GraphExecutor::SuspendedReadyState ) {
921 ResumeAction( GraphExecutor::ToResumeEvent ) ;
924 else if ( State() == GraphExecutor::SuspendedExecutingState ) {
925 if ( IsFactoryNode() || IsComputingNode() ) {
926 if ( pthread_mutex_lock( &_MutexWait ) ) {
927 perror("ResumeAction pthread_mutex_lock ") ;
931 RetVal = Component()->Resume_impl() ;
933 State( GraphExecutor::ExecutingState ) ;
937 cdebug << "InNode::Resume() ERROR catched" << endl ;
938 State( GraphExecutor::ErroredState ) ;
939 _OutNode->State( GraphExecutor::ErroredState ) ;
942 if ( pthread_mutex_unlock( &_MutexWait ) ) {
943 perror("ResumeAction pthread_mutex_unlock ") ;
947 else if ( IsMacroNode() ) {
948 cdebug << "Suspend of MacroNode not yet implemented ? Trying" << endl ;
949 GraphBase::Graph * aGraph = (GraphBase::Graph * ) GraphMacroNode()->CoupledNode() ;
950 RetVal = aGraph->GraphEditor()->Executor()->Resume() ;
952 State( GraphExecutor::ExecutingState ) ;
956 // Resume of InLinePythonNode in the Node of the SuperVisionContainer ...
957 // asv : 20.01.05 : changes involved with switching to old (HEAD) KERNEL
958 State( GraphExecutor::ErroredState ) ;
959 _OutNode->State( GraphExecutor::ErroredState ) ;
961 cdebug << "Resume of InLine nodes is NOT implemented." << endl;
962 MESSAGE( "Resume of InLine nodes is NOT implemented." );
964 cdebug << ThreadNo() << "/" << pthread_self()
965 << "Resume of InLineNode pthread_kill" << Name() << endl ;
966 if ( pthread_kill( _OutNode->MainThreadId() , SIGCONT ) == -1 ) {
967 perror("Resume pthread_kill error") ;
968 State( GraphExecutor::ErroredState ) ;
969 _OutNode->State( GraphExecutor::ErroredState ) ;
973 State( GraphExecutor::ExecutingState ) ;
979 else if ( State() == GraphExecutor::SuspendedSuccessedState ) {
980 ResumeAction( GraphExecutor::ResumeEvent ) ;
983 else if ( State() == GraphExecutor::SuspendedErroredState ) {
984 ResumeAction( GraphExecutor::ResumeEvent ) ;
988 cdebug << "GraphExecutor::InNode::Resume Not SuspendedReady/Executing/Successed/ErroredState "
989 << Automaton()->StateName( State() ) << endl ;
994 cdebug << "GraphExecutor::InNode::Resume Not Suspended State "
995 << Automaton()->StateName( State() ) << endl ;
998 if ( ControlState() == SUPERV::ToSuspendStartState ) {
999 ControlState( SUPERV::VoidState ) ;
1003 if ( ControlState() == SUPERV::ToSuspendRunState ||
1004 ( ControlState() == SUPERV::ToSuspendState &&
1005 State() == GraphExecutor::SuspendedReadyState) ) {
1006 if ( IsSuspended() ) {
1007 if ( State() == GraphExecutor::SuspendedReadyState ) {
1011 else if ( State() == GraphExecutor::SuspendedExecutingState ) {
1013 RetVal = Component()->Resume_impl() ;
1016 cdebug << "GraphExecutor::InNode::Resume State "
1017 << Automaton()->StateName( State() ) << endl ;
1020 if ( ControlState() != SUPERV::ToSuspendState ) {
1021 ControlState( SUPERV::VoidState ) ;
1024 else if ( IsRunning() ) {
1027 else if ( IsWaiting() ) {
1028 ControlState( SUPERV::VoidState ) ;
1031 else if ( IsDone() ) {
1035 else if ( ControlState() == SUPERV::ToSuspendDoneState ||
1036 ( ControlState() == SUPERV::ToSuspendState &&
1037 State() == GraphExecutor::SuspendedSuccessedState) ) {
1038 if ( IsSuspended() ) {
1039 if ( State() == GraphExecutor::SuspendedSuccessedState ) {
1043 else if ( State() == GraphExecutor::SuspendedErroredState ) {
1048 cdebug << "GraphExecutor::InNode::Resume State " << State() << endl ;
1051 if ( ControlState() != SUPERV::ToSuspendState ) {
1052 ControlState( SUPERV::VoidState ) ;
1055 else if ( IsRunning() ) {
1056 ControlState( SUPERV::VoidState ) ;
1059 else if ( IsWaiting() ) {
1060 ControlState( SUPERV::VoidState ) ;
1063 else if ( IsDone() ) {
1064 ControlState( SUPERV::VoidState ) ;
1069 cdebug_out << "GraphExecutor::InNode::Resume " << Name() << " " << RetVal << " "
1070 << Automaton()->StateName( State() ) << endl ;
1074 bool GraphExecutor::InNode::IsWaiting() {
1076 // cdebug_in << "GraphExecutor::InNode::IsWaiting " << Name() << endl;
1077 GraphExecutor::AutomatonState aState = State() ;
1078 if ( aState == GraphExecutor::DataUndefState ||
1079 aState == GraphExecutor::DataWaitingState ||
1080 aState == GraphExecutor::SuspendedReadyState )
1081 // aState == GraphExecutor::SuspendedExecutingState ||
1082 // aState == GraphExecutor::SuspendedSuccessedState ||
1083 // aState == GraphExecutor::SuspendedErroredState ||
1084 // aState == GraphExecutor::SuspendedState
1086 // cdebug_out << "GraphExecutor::InNode::IsWaiting" << endl ;
1090 bool GraphExecutor::InNode::IsReady() {
1092 // cdebug_in << "GraphExecutor::InNode::IsReady " << Name() << endl;
1093 GraphExecutor::AutomatonState aState = State() ;
1094 // if ( aState == GraphExecutor::DataUndefState ||
1095 // aState == GraphExecutor::DataWaitingState ||
1096 if ( aState == GraphExecutor::DataReadyState ||
1097 aState == GraphExecutor::ResumedReadyState )
1099 // cdebug_out << "GraphExecutor::InNode::IsReady" << endl ;
1103 bool GraphExecutor::InNode::IsRunning() {
1105 // cdebug_in << "GraphExecutor::InNode::IsRunning " << Name() << endl;
1106 GraphExecutor::AutomatonState aState = State() ;
1107 if ( aState == GraphExecutor::ExecutingState ||
1108 aState == GraphExecutor::ResumedExecutingState )
1110 // cdebug_out << "GraphExecutor::InNode::IsRunning" << endl ;
1114 bool GraphExecutor::InNode::IsDone() {
1116 // cdebug_in << "GraphExecutor::InNode::IsDone " << Name() << endl;
1117 GraphExecutor::AutomatonState aState = State() ;
1118 if ( aState == GraphExecutor::KilledReadyState ||
1119 aState == GraphExecutor::StoppedReadyState ||
1120 aState == GraphExecutor::KilledExecutingState ||
1121 aState == GraphExecutor::StoppedExecutingState ||
1122 aState == GraphExecutor::SuspendedSuccessedState ||
1123 aState == GraphExecutor::SuspendedErroredState ||
1124 // aState == GraphExecutor::SuccessedExecutingState ||
1125 // aState == GraphExecutor::ErroredExecutingState ||
1126 aState == GraphExecutor::SuccessedState ||
1127 aState == GraphExecutor::ErroredState ||
1128 aState == GraphExecutor::ResumedSuccessedState ||
1129 aState == GraphExecutor::ResumedErroredState ||
1130 aState == GraphExecutor::KilledSuccessedState ||
1131 aState == GraphExecutor::StoppedSuccessedState )
1133 // cdebug_out << "GraphExecutor::InNode::IsDone" << endl ;
1137 bool GraphExecutor::InNode::IsSuspended() {
1139 // cdebug_in << "GraphExecutor::InNode::IsSuspended " << Name() << endl;
1140 GraphExecutor::AutomatonState aState = State() ;
1141 if ( aState == GraphExecutor::SuspendedReadyState ||
1142 aState == GraphExecutor::SuspendedExecutingState ||
1143 aState == GraphExecutor::SuspendedSuccessedState ||
1144 aState == GraphExecutor::SuspendedErroredState ||
1145 aState == GraphExecutor::SuspendedState )
1147 // cdebug_out << "GraphExecutor::InNode::IsSuspended" << endl ;
1150 bool GraphExecutor::InNode::IsKilled() {
1152 // cdebug_in << "GraphExecutor::InNode::IsKilled " << Name() << endl;
1153 GraphExecutor::AutomatonState aState = State() ;
1154 if ( aState == GraphExecutor::KilledReadyState ||
1155 aState == GraphExecutor::KilledExecutingState ||
1156 aState == GraphExecutor::KilledSuccessedState ||
1157 aState == GraphExecutor::KilledErroredState ||
1158 aState == GraphExecutor::KilledState )
1160 // cdebug_out << "GraphExecutor::InNode::IsKilled" << endl ;
1163 bool GraphExecutor::InNode::IsStopped() {
1165 // cdebug_in << "GraphExecutor::InNode::IsStopped " << Name() << endl;
1166 GraphExecutor::AutomatonState aState = State() ;
1167 if ( aState == GraphExecutor::StoppedReadyState ||
1168 aState == GraphExecutor::StoppedExecutingState ||
1169 aState == GraphExecutor::StoppedSuccessedState ||
1170 aState == GraphExecutor::StoppedErroredState ||
1171 aState == GraphExecutor::StoppedState )
1173 // cdebug_out << "GraphExecutor::InNode::IsStopped" << endl ;
1177 bool GraphExecutor::InNode::StateWait( SUPERV::GraphState aState ) {
1178 bool RetVal = false ;
1179 if ( pthread_mutex_lock( &_MutexWait ) ) {
1180 perror("pthread_mutex_lock _Wait") ;
1184 case SUPERV::ReadyState : {
1185 RetVal = IsReady() ;
1186 cdebug_in << pthread_self() << " StateWait( Ready ) " << RetVal
1187 << " " << Automaton()->StateName( _currentState )
1188 << " pthread_cond_wait _ReadyWait " << Name() << endl ;
1189 while ( !RetVal && !IsDone() ) {
1190 cdebug << pthread_self() << " pthread_cond_wait ReadyWait" << endl ;
1191 pthread_cond_wait( &_ReadyWait , &_MutexWait );
1192 RetVal = IsReady() ;
1193 cdebug << pthread_self() << " pthread_cond_waited ReadyWait "
1194 << Automaton()->StateName( _currentState ) << " " << RetVal
1197 cdebug_out << pthread_self() << " StateWait( Ready ) " << RetVal
1198 << " " << Automaton()->StateName( _currentState )
1199 << " pthread_cond_wait _ReadyWait " << Name() << endl ;
1202 case SUPERV::RunningState : {
1203 RetVal = IsRunning() ;
1204 cdebug_in << pthread_self() << " StateWait( Running ) " << RetVal
1205 << " " << Automaton()->StateName( _currentState )
1206 << " pthread_cond_wait _RunningWait " << Name() << endl ;
1207 while ( !RetVal && !IsDone() ) {
1208 cdebug << pthread_self() << " pthread_cond_wait RunningWait " << Name() << endl ;
1209 pthread_cond_wait( &_RunningWait , &_MutexWait );
1210 //We may have pthread_cond_waited but !IsRunning and !IsDone :
1211 RetVal = IsRunning() || State() == GraphExecutor::SuccessedExecutingState ||
1212 State() == GraphExecutor::ErroredExecutingState ;
1213 cdebug << pthread_self() << " pthread_cond_waited RunningWait "
1214 << Automaton()->StateName( _currentState ) << " " << RetVal
1215 << " " << Name() << endl ;
1217 cdebug_out << pthread_self() << " StateWait( Running ) " << RetVal
1218 << " " << Automaton()->StateName( _currentState )
1219 << " pthread_cond_wait _RunningWait " << Name() << endl ;
1222 case SUPERV::DoneState : {
1224 cdebug_in << pthread_self() << " StateWait( Done ) " << RetVal
1225 << " " << Automaton()->StateName( _currentState )
1226 << " pthread_cond_wait _DoneWait " << Name() << endl ;
1228 cdebug << pthread_self() << " pthread_cond_wait DoneWait" << endl ;
1229 pthread_cond_wait( &_DoneWait , &_MutexWait );
1231 cdebug << pthread_self() << " pthread_cond_waited DoneWait "
1232 << Automaton()->StateName( _currentState ) << " " << RetVal
1235 cdebug_out << pthread_self() << " StateWait( Done ) " << RetVal
1236 << " " << Automaton()->StateName( _currentState )
1237 << " pthread_cond_wait _DoneWait " << Name() << endl ;
1240 case SUPERV::SuspendState : {
1241 RetVal = IsSuspended() ;
1242 cdebug_in << pthread_self() << " StateWait( Suspend ) " << RetVal
1243 << " " << Automaton()->StateName( _currentState )
1244 << " pthread_cond_wait _SuspendedWait " << Name() << endl ;
1245 while ( !RetVal && !IsDone() ) {
1246 cdebug << pthread_self() << " pthread_cond_wait SuspendedWait" << endl ;
1247 pthread_cond_wait( &_SuspendedWait , &_MutexWait );
1248 RetVal = IsSuspended() ;
1249 cdebug << pthread_self() << " pthread_cond_waited SuspendedWait "
1250 << Automaton()->StateName( _currentState ) << " " << RetVal
1253 cdebug_out << pthread_self() << " StateWait( Suspend ) " << RetVal
1254 << " " << Automaton()->StateName( _currentState )
1255 << " pthread_cond_wait _SuspendedWait " << Name() << endl ;
1259 cdebug << " SUPERV::OutNode::StateWait Error Undefined State : "
1263 if ( pthread_mutex_unlock( &_MutexWait ) ) {
1264 perror("pthread_mutex_lock _Wait") ;
1270 bool GraphExecutor::InNode::ReadyWait() {
1271 // cdebug_in << "GraphExecutor::InNode::ReadyWait " << Name() << endl;
1273 aret = StateWait( SUPERV::ReadyState ) ;
1274 // cdebug_out << "GraphExecutor::InNode::ReadyWait" << endl ;
1278 bool GraphExecutor::InNode::RunningWait() {
1279 cdebug_in << pthread_self() << "GraphExecutor::InNode::RunningWait " << Name()
1280 << " " << Automaton()->StateName( State() ) << endl;
1282 aret = StateWait( SUPERV::RunningState ) ;
1283 cdebug_out << pthread_self() << "GraphExecutor::InNode::RunningWait " << Name()
1284 << " " << Automaton()->StateName( State() ) << endl;
1288 bool GraphExecutor::InNode::DoneWait() {
1289 // cdebug_in << "GraphExecutor::InNode::DoneWait " << Name() << endl;
1291 aret = StateWait( SUPERV::DoneState ) ;
1295 bool GraphExecutor::InNode::SuspendedWait() {
1296 // cdebug_in << "GraphExecutor::InNode::SuspendedWait " << Name() << endl;
1298 aret = StateWait( SUPERV::SuspendState ) ;
1302 void GraphExecutor::InNode::InitialState()
1304 cdebug_in << "GraphExecutor::InNode::InitialState Node " << Name() << endl;
1307 _ControlState = SUPERV::VoidState ;
1308 CreateNewThread( false ) ;
1309 CreateNewThreadIf( false ) ;
1310 _SuspendSync = false ;
1311 _ResumeSync = false ;
1314 // asv : 13.12.04 : Decided to set "Loading" state for factory and computing nodes ONLY.
1315 // See extended comment in p.2.19 of "Bugs and Improvements" about IsLoading for InLine.
1316 if ( IsComputingNode() || IsFactoryNode() ) {
1320 // ThreadNo( pthread_self() ) ;
1323 for ( i = 0 ; i < GetNodeOutPortsSize() ; i++ ) {
1324 if ( GetNodeOutPort(i)->IsDataStream() ) {
1325 GetChangeNodeOutPort(i)->State( SUPERV::ReadyState ) ;
1326 GetChangeNodeOutPort(i)->Done( true ) ;
1328 else if ( i != 0 || !IsGOTONode() ) {
1329 GetChangeNodeOutPort(i)->State( SUPERV::WaitingState ) ;
1330 GetChangeNodeOutPort(i)->Done( false ) ;
1334 int Pc = GetNodeInPortsSize() ;
1335 for ( i = 0 ; i < GetNodeInPortsSize() ; i++ ) {
1336 const GraphBase::InPort * anInPort = GetNodeInPort(i) ;
1337 GraphBase::OutPort * anOutPort = anInPort->GetOutPort() ;
1338 if ( IsHeadNode() && IsLoopNode() && anInPort->IsLoop() ) {
1339 anOutPort->PortStatus( DataConnected );
1340 anOutPort->State( SUPERV::ReadyState ) ;
1341 anOutPort->Done( true ) ;
1342 CORBA::Any * anAny = new CORBA::Any() ;
1343 *anAny <<= (long ) 1 ;
1344 anOutPort->Value( anAny ) ;
1347 // JR 15_09_2004 if backward link from GOTONode or EndLoopNode ==> DataConnected
1348 else if ( anInPort->IsGate() && anOutPort ) {
1349 anOutPort->State( SUPERV::WaitingState ) ;
1350 anOutPort->Done( false ) ;
1351 const GraphBase::ComputingNode * aFromNode = _OutNode->Graph()->GetGraphNode( anOutPort->NodeName() ) ;
1352 //JR if ( aFromNode->IsGOTONode() || aFromNode->IsEndLoopNode() ) {
1353 if ( aFromNode->IsGOTONode() || ( IsLoopNode() && CoupledNode() == aFromNode ) ) {
1354 // ASV: bug with synchronization of Inline nodes (via Gate ports) fixed.
1355 // before was "else if ( IsOneOfInlineNodes() )"
1356 // IsOneOfInline() == ( Inline || IsOneOfGOTO() ), so Inline are removed..
1357 anOutPort->PortStatus( DataConnected );
1358 anOutPort->State( SUPERV::ReadyState ) ;
1359 anOutPort->Done( true ) ;
1362 if ( anInPort->IsGate() && anOutPort == NULL ) {
1364 cdebug << "InPort" << i << " " << anInPort->PortName() << " Not connected Pc " << Pc << endl ;
1366 else if ( anOutPort ) {
1367 if ( anOutPort->IsDataConnected() || anOutPort->IsDataStream() ) {
1369 anOutPort->State( SUPERV::ReadyState ) ;
1370 anOutPort->Done( true ) ;
1371 cdebug << "InPort" << i << " " << anInPort->PortName() << " " << anInPort->PortStatus()
1372 << " " << theAutomaton->StateName( anOutPort->State() ) << " Pc " << Pc << endl ;
1374 else if ( anOutPort->IsPortConnected() ) {
1375 anOutPort->State( SUPERV::WaitingState ) ;
1376 anOutPort->Done( false ) ;
1377 cdebug << "InPort" << i << " " << anInPort->PortName() << " " << " " << anInPort->PortStatus()
1378 << " " << theAutomaton->StateName( anOutPort->State() ) << " Pc " << Pc << endl ;
1381 cdebug << "InPort" << i << " " << anInPort->PortName() << " " << anInPort->PortStatus()
1382 << " OutPort " << anOutPort->NodeName() << " " << anOutPort->PortName() << " "
1383 << theAutomaton->StateName( anOutPort->State() ) << " Pc " << Pc << endl ;
1387 cdebug << "InPort" << i << " " << anInPort->PortName() << " " << " " << anInPort->PortStatus()
1388 << " no corresponding OutPort Pc " << Pc << endl ;
1391 if ( !anOutPort->IsDataStream() || anInPort->IsDataStream() ) {
1392 cdebug << "InPort" << i << " state change : " << anInPort->PortName() << " from OutPort "
1393 << anOutPort->PortName() << " from Node " << anOutPort->NodeName()
1394 << " with state " << theAutomaton->StateName( anOutPort->State() ) << endl ;
1395 GetChangeNodeInPort(i)->State( anOutPort->State() ) ;
1397 else if ( anOutPort->IsDataConnected() ) {
1398 cdebug << "InPort" << i << " state change : " << anInPort->PortName() << " from OutPort "
1399 << anOutPort->PortName() << " from Node " << anOutPort->NodeName()
1400 << " with state ReadyState" << endl ;
1401 GetChangeNodeInPort(i)->State( SUPERV::ReadyState ) ;
1404 cdebug << "InPort" << i << " state NOT changed : " << anInPort->PortName() << " from OutPort "
1405 << anOutPort->PortName() << " " << anOutPort->PortStatus() << " from Node " << anOutPort->NodeName()
1406 << " with state " << anOutPort->State() << endl ;
1410 cdebug << "InPort" << i << " : " << anInPort->PortName() << " from OutPort "
1411 << anOutPort->PortName() << " from Node " << anOutPort->NodeName()
1413 if ( anOutPort->State() == SUPERV::WaitingState ) {
1414 cdebug << "WaitingState" ;
1416 else if ( anOutPort->State() == SUPERV::ReadyState ) {
1417 cdebug << "ReadyState" ;
1422 cdebug << " PortConnected("
1423 << anOutPort->IsPortConnected() << ") DataConnected("
1424 << anOutPort->IsDataConnected() << ")" << endl ;
1428 _currentState = Pc > 0 ? GraphExecutor::DataWaitingState
1429 : GraphExecutor::DataReadyState ;
1430 if ( Pc == GetNodeInPortsSize() ) {
1431 _OutNode->PushEvent( this , GraphExecutor::NoDataReadyEvent ,
1434 else if ( Pc != 0 ) {
1435 _OutNode->PushEvent( this , GraphExecutor::SomeDataReadyEvent ,
1439 _OutNode->PushEvent( this , GraphExecutor::AllDataReadyEvent ,
1443 for ( i = 0 ; i < GetNodeOutPortsSize() ; i++ ) {
1444 cdebug << "OutPort" << i << " : " << GetNodeOutPort(i)->PortName() << " "
1445 << theAutomaton->StateName( GetChangeNodeOutPort(i)->State() )
1446 << " " << GetNodeOutPort(i)->Kind() << endl ;
1449 cdebug << "CurrentState = " << theAutomaton->StateName( _currentState )
1452 cdebug_out << "GraphExecutor::InNode::InitialState" << endl;
1455 bool GraphExecutor::InNode::InitPythonFunctions(bool WithErr ) {
1456 cdebug_in << "GraphExecutor::InNode::InitPythonFunctions " << Name() << " WithErr " << WithErr
1457 << " PyFuncRunned() " << PyFuncRunned() << endl;
1459 if ( !PyFuncRunned() && IsOneOfInLineNodes() ) {
1460 if ( IsLoopNode() ) {
1461 PyObject * PyRunMethod = InLineNode()->PyRunMethod() ;
1462 PyObject * PyMoreMethod = NULL ;
1463 PyObject * PyNextMethod = NULL ;
1464 if ( PyRunMethod ) {
1467 PyRunMethod = InitPyDynInvoke( InLineNode()->PyFuncName() ,
1468 InLineNode()->PythonFunction() ,
1470 InLineNode()->PyRunMethod( PyRunMethod ) ;
1473 PyMoreMethod = LoopNode()->PyMoreMethod() ;
1474 if ( PyMoreMethod ) {
1477 PyMoreMethod = InitPyDynInvoke( LoopNode()->PyMoreName() ,
1478 LoopNode()->MorePythonFunction() ,
1480 LoopNode()->PyMoreMethod( PyMoreMethod ) ;
1484 PyNextMethod = LoopNode()->PyNextMethod() ;
1485 if ( PyNextMethod ) {
1488 PyNextMethod = InitPyDynInvoke( LoopNode()->PyNextName() ,
1489 LoopNode()->NextPythonFunction() ,
1491 LoopNode()->PyNextMethod( PyNextMethod ) ;
1494 cdebug << "GraphExecutor::InNode::InitPythonFunctions " << Name() << " PyRunMethod(Init) " << PyRunMethod
1495 << " PyMoreMethod " << PyMoreMethod << " PyNextMethod " << PyNextMethod << endl;
1497 else if ( IsInLineNode() || IsSwitchNode() ) {
1498 PyObject * PyRunMethod = InLineNode()->PyRunMethod() ;
1499 if ( PyRunMethod ) {
1502 PyRunMethod = InitPyDynInvoke( InLineNode()->PyFuncName() ,
1503 InLineNode()->PythonFunction() ,
1505 InLineNode()->PyRunMethod( PyRunMethod ) ;
1507 cdebug << "GraphExecutor::InNode::InitPythonFunctions " << Name() << " PyRunMethod " << PyRunMethod << endl;
1509 else if ( ( IsEndLoopNode() || IsEndSwitchNode() || IsGOTONode() ) &&
1510 (*InLineNode()->PythonFunction()).length() ) {
1511 PyObject * PyRunMethod = InLineNode()->PyRunMethod() ;
1512 if ( PyRunMethod ) {
1515 PyRunMethod = InitPyDynInvoke( InLineNode()->PyFuncName() ,
1516 InLineNode()->PythonFunction() ,
1518 InLineNode()->PyRunMethod( PyRunMethod ) ;
1520 cdebug << "GraphExecutor::InNode::InitPythonFunctions " << Name() << " PyRunMethod " << PyRunMethod << endl;
1523 Err = WithErr && Err ;
1524 cdebug_out << "GraphExecutor::InNode::InitPythonFunctions " << Name() ;
1526 cdebug << " Error " << Err ;
1532 const long GraphExecutor::InNode::CpuUsed( bool tot ) {
1533 CORBA::Long cpu = 0 ;
1534 // cout << "Begin CpuUsed " << Name() << " CpuUsed : " << cpu << " State "
1535 // << theAutomaton->StateName( _currentState ) << endl ;
1536 cdebug_in << "GraphExecutor::InNode::CpuUsed( " << tot << " )" << Name() << endl ;
1537 if ( IsOneOfInLineNodes() ) {
1538 // cdebug << "CpuUsed " << Name() << " --> PyCpuUsed()" << endl ;
1539 // cout << "CpuUsed " << Name() << " --> PyCpuUsed()" << endl ;
1540 cpu = PyCpuUsed( tot ) ;
1543 if ( !CORBA::is_nil( Component() ) ) {
1544 // cdebug << "CpuUsed " << Name() << " --> Component()->CpuUsed_impl()" << endl ;
1545 // cout << "CpuUsed " << Name() << " --> Component()->CpuUsed_impl()" << endl ;
1547 cpu = Component()->CpuUsed_impl() ;
1550 cdebug << "CpuUsed " << Name() << " --> Component()->CpuUsed_impl() ERROR catched " << endl ;
1551 State( GraphExecutor::ErroredState ) ;
1552 _OutNode->State( GraphExecutor::ErroredState ) ;
1557 cdebug_out << "GraphExecutor::InNode::CpuUsed " << Name() << " CpuUsed : " << cpu << endl ;
1558 // cout << "End CpuUsed " << Name() << " CpuUsed : " << cpu << " State "
1559 // << theAutomaton->StateName( _currentState ) << endl ;
1563 #include <sys/time.h>
1564 #include <sys/resource.h>
1567 long GraphExecutor::InNode::PyCpu() {
1568 struct rusage usage ;
1570 if ( getrusage( RUSAGE_SELF , &usage ) == -1 ) {
1571 perror("GraphExecutor::InNode::PyCpu") ;
1574 // return usage.ru_utime.__time_t tv_sec ;
1575 // cdebug << pthread_self() << "PyCpu " << Name() << " " << usage.ru_utime.tv_sec << " "
1576 // << usage.ru_utime.tv_usec << " " << usage.ru_stime.tv_sec << " " << usage.ru_stime.tv_usec
1578 cpu = usage.ru_utime.tv_sec ;
1582 long GraphExecutor::InNode::PyCpuUsed( bool tot ) {
1584 if ( _PyTotCpuUsed == -1 ) {
1585 if ( _Pythread == pthread_self() ) {
1586 // cdebug << pthread_self() << "GraphExecutor::InNode::PyCpuUsed(" << tot << ") " << Name()
1587 // << " _PyTotCpuUsed " << _PyTotCpuUsed << " PyCpu() " << PyCpu() << " - " << " _PyCpuUsed "
1588 // << _PyCpuUsed << endl ;
1589 cpu = PyCpu() - _PyCpuUsed ;
1591 _PyTotCpuUsed = cpu ;
1599 cpu = _PyTotCpuUsed ;
1601 // cdebug << pthread_self() << "GraphExecutor::InNode::PyCpuUsed(" << tot << ") " << Name() << "_PyTotCpuUsed"
1602 // << _PyTotCpuUsed << " CpuUsed : " << cpu << endl ;
1606 void GraphExecutor::InNode::SetPyCpuUsed() {
1607 _PyTotCpuUsed = -1 ;
1609 _Pythread = pthread_self() ;
1610 _PyCpuUsed = PyCpu() ;
1611 // cdebug << pthread_self() << "GraphExecutor::InNode::SetPyCpuUsed " << Name() << " _PyCpuUsed : "
1612 // << _PyCpuUsed << endl ;
1615 void GraphExecutor::InNode::IsLoading( bool Loading ) {
1616 _Loading = Loading ;
1618 // asv : 09.12.04 : "Bugs and Improvents" 2.19 : how it works:
1619 // LoadingState is returned by OutNode::State( NodeName ) if InNode->IsLoading()
1620 // after Loading is finished (here below), ExecutingState must be pushed for GUI.
1622 _OutNode->PushEvent( this, GraphExecutor::ExecuteEvent, GraphExecutor::ExecutingState );