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::ReStart( const char * AtNodeName ,
1052 const bool AndSuspend ) {
1053 bool RetVal = false ;
1054 GraphExecutor::InNode * aRestartNode = (GraphExecutor::InNode *) _OutNode->Graph()->GetGraphNode( AtNodeName )->GetInNode() ;
1055 cdebug_in << pthread_self() << "/" << ThreadNo()
1056 << " --> GraphExecutor::InNode::ReStartAt( "
1057 << AtNodeName << " , " << AndSuspend << ") " << endl
1058 << "thread " << aRestartNode->ThreadNo() << " "
1059 << Automaton()->StateName( aRestartNode->State() )
1060 << " from " << Name() << " " << Automaton()->StateName( State() )
1062 if ( IsWaiting() && aRestartNode->IsSuspended() ) {
1063 RetVal = aRestartNode->Resume() ;
1065 else if ( IsSuspended() ) {
1066 if ( strcmp( AtNodeName , Name() ) ) {
1067 aRestartNode->State( GraphExecutor::SuspendedSuccessedState ) ;
1070 ReStartAction( aRestartNode , GraphExecutor::ReStartAndSuspendEvent ) ;
1073 ReStartAction( aRestartNode , GraphExecutor::ReStartEvent ) ;
1077 cdebug_out << "<-- GraphExecutor::InNode::ReStartAt" << endl ;
1081 bool GraphExecutor::InNode::IsWaiting() {
1083 // cdebug_in << "GraphExecutor::InNode::IsWaiting " << Name() << endl;
1084 GraphExecutor::AutomatonState aState = State() ;
1085 if ( aState == GraphExecutor::DataUndefState ||
1086 aState == GraphExecutor::DataWaitingState ||
1087 aState == GraphExecutor::SuspendedReadyState )
1088 // aState == GraphExecutor::SuspendedExecutingState ||
1089 // aState == GraphExecutor::SuspendedSuccessedState ||
1090 // aState == GraphExecutor::SuspendedErroredState ||
1091 // aState == GraphExecutor::SuspendedState
1093 // cdebug_out << "GraphExecutor::InNode::IsWaiting" << endl ;
1097 bool GraphExecutor::InNode::IsReady() {
1099 // cdebug_in << "GraphExecutor::InNode::IsReady " << Name() << endl;
1100 GraphExecutor::AutomatonState aState = State() ;
1101 // if ( aState == GraphExecutor::DataUndefState ||
1102 // aState == GraphExecutor::DataWaitingState ||
1103 if ( aState == GraphExecutor::DataReadyState ||
1104 aState == GraphExecutor::ResumedReadyState )
1106 // cdebug_out << "GraphExecutor::InNode::IsReady" << endl ;
1110 bool GraphExecutor::InNode::IsRunning() {
1112 // cdebug_in << "GraphExecutor::InNode::IsRunning " << Name() << endl;
1113 GraphExecutor::AutomatonState aState = State() ;
1114 if ( aState == GraphExecutor::ExecutingState ||
1115 aState == GraphExecutor::ResumedExecutingState )
1117 // cdebug_out << "GraphExecutor::InNode::IsRunning" << endl ;
1121 bool GraphExecutor::InNode::IsDone() {
1123 // cdebug_in << "GraphExecutor::InNode::IsDone " << Name() << endl;
1124 GraphExecutor::AutomatonState aState = State() ;
1125 if ( aState == GraphExecutor::KilledReadyState ||
1126 aState == GraphExecutor::StoppedReadyState ||
1127 aState == GraphExecutor::KilledExecutingState ||
1128 aState == GraphExecutor::StoppedExecutingState ||
1129 aState == GraphExecutor::SuspendedSuccessedState ||
1130 aState == GraphExecutor::SuspendedErroredState ||
1131 // aState == GraphExecutor::SuccessedExecutingState ||
1132 // aState == GraphExecutor::ErroredExecutingState ||
1133 aState == GraphExecutor::SuccessedState ||
1134 aState == GraphExecutor::ErroredState ||
1135 aState == GraphExecutor::ResumedSuccessedState ||
1136 aState == GraphExecutor::ResumedErroredState ||
1137 aState == GraphExecutor::KilledSuccessedState ||
1138 aState == GraphExecutor::StoppedSuccessedState )
1140 // cdebug_out << "GraphExecutor::InNode::IsDone" << endl ;
1144 bool GraphExecutor::InNode::IsSuspended() {
1146 // cdebug_in << "GraphExecutor::InNode::IsSuspended " << Name() << endl;
1147 GraphExecutor::AutomatonState aState = State() ;
1148 if ( aState == GraphExecutor::SuspendedReadyState ||
1149 aState == GraphExecutor::SuspendedExecutingState ||
1150 aState == GraphExecutor::SuspendedSuccessedState ||
1151 aState == GraphExecutor::SuspendedErroredState ||
1152 aState == GraphExecutor::SuspendedState )
1154 // cdebug_out << "GraphExecutor::InNode::IsSuspended" << endl ;
1157 bool GraphExecutor::InNode::IsKilled() {
1159 // cdebug_in << "GraphExecutor::InNode::IsKilled " << Name() << endl;
1160 GraphExecutor::AutomatonState aState = State() ;
1161 if ( aState == GraphExecutor::KilledReadyState ||
1162 aState == GraphExecutor::KilledExecutingState ||
1163 aState == GraphExecutor::KilledSuccessedState ||
1164 aState == GraphExecutor::KilledErroredState ||
1165 aState == GraphExecutor::KilledState )
1167 // cdebug_out << "GraphExecutor::InNode::IsKilled" << endl ;
1170 bool GraphExecutor::InNode::IsStopped() {
1172 // cdebug_in << "GraphExecutor::InNode::IsStopped " << Name() << endl;
1173 GraphExecutor::AutomatonState aState = State() ;
1174 if ( aState == GraphExecutor::StoppedReadyState ||
1175 aState == GraphExecutor::StoppedExecutingState ||
1176 aState == GraphExecutor::StoppedSuccessedState ||
1177 aState == GraphExecutor::StoppedErroredState ||
1178 aState == GraphExecutor::StoppedState )
1180 // cdebug_out << "GraphExecutor::InNode::IsStopped" << endl ;
1184 bool GraphExecutor::InNode::StateWait( SUPERV::GraphState aState ) {
1185 bool RetVal = false ;
1186 if ( pthread_mutex_lock( &_MutexWait ) ) {
1187 perror("pthread_mutex_lock _Wait") ;
1191 case SUPERV::ReadyState : {
1192 RetVal = IsReady() ;
1193 cdebug_in << pthread_self() << " StateWait( Ready ) " << RetVal
1194 << " " << Automaton()->StateName( _currentState )
1195 << " pthread_cond_wait _ReadyWait " << Name() << endl ;
1196 while ( !RetVal && !IsDone() ) {
1197 cdebug << pthread_self() << " pthread_cond_wait ReadyWait" << endl ;
1198 pthread_cond_wait( &_ReadyWait , &_MutexWait );
1199 RetVal = IsReady() ;
1200 cdebug << pthread_self() << " pthread_cond_waited ReadyWait "
1201 << Automaton()->StateName( _currentState ) << " " << RetVal
1204 cdebug_out << pthread_self() << " StateWait( Ready ) " << RetVal
1205 << " " << Automaton()->StateName( _currentState )
1206 << " pthread_cond_wait _ReadyWait " << Name() << endl ;
1209 case SUPERV::RunningState : {
1210 RetVal = IsRunning() ;
1211 cdebug_in << pthread_self() << " StateWait( Running ) " << RetVal
1212 << " " << Automaton()->StateName( _currentState )
1213 << " pthread_cond_wait _RunningWait " << Name() << endl ;
1214 while ( !RetVal && !IsDone() ) {
1215 cdebug << pthread_self() << " pthread_cond_wait RunningWait " << Name() << endl ;
1216 pthread_cond_wait( &_RunningWait , &_MutexWait );
1217 //We may have pthread_cond_waited but !IsRunning and !IsDone :
1218 RetVal = IsRunning() || State() == GraphExecutor::SuccessedExecutingState ||
1219 State() == GraphExecutor::ErroredExecutingState ;
1220 cdebug << pthread_self() << " pthread_cond_waited RunningWait "
1221 << Automaton()->StateName( _currentState ) << " " << RetVal
1222 << " " << Name() << endl ;
1224 cdebug_out << pthread_self() << " StateWait( Running ) " << RetVal
1225 << " " << Automaton()->StateName( _currentState )
1226 << " pthread_cond_wait _RunningWait " << Name() << endl ;
1229 case SUPERV::DoneState : {
1231 cdebug_in << pthread_self() << " StateWait( Done ) " << RetVal
1232 << " " << Automaton()->StateName( _currentState )
1233 << " pthread_cond_wait _DoneWait " << Name() << endl ;
1235 cdebug << pthread_self() << " pthread_cond_wait DoneWait" << endl ;
1236 pthread_cond_wait( &_DoneWait , &_MutexWait );
1238 cdebug << pthread_self() << " pthread_cond_waited DoneWait "
1239 << Automaton()->StateName( _currentState ) << " " << RetVal
1242 cdebug_out << pthread_self() << " StateWait( Done ) " << RetVal
1243 << " " << Automaton()->StateName( _currentState )
1244 << " pthread_cond_wait _DoneWait " << Name() << endl ;
1247 case SUPERV::SuspendState : {
1248 RetVal = IsSuspended() ;
1249 cdebug_in << pthread_self() << " StateWait( Suspend ) " << RetVal
1250 << " " << Automaton()->StateName( _currentState )
1251 << " pthread_cond_wait _SuspendedWait " << Name() << endl ;
1252 while ( !RetVal && !IsDone() ) {
1253 cdebug << pthread_self() << " pthread_cond_wait SuspendedWait" << endl ;
1254 pthread_cond_wait( &_SuspendedWait , &_MutexWait );
1255 RetVal = IsSuspended() ;
1256 cdebug << pthread_self() << " pthread_cond_waited SuspendedWait "
1257 << Automaton()->StateName( _currentState ) << " " << RetVal
1260 cdebug_out << pthread_self() << " StateWait( Suspend ) " << RetVal
1261 << " " << Automaton()->StateName( _currentState )
1262 << " pthread_cond_wait _SuspendedWait " << Name() << endl ;
1266 cdebug << " SUPERV::OutNode::StateWait Error Undefined State : "
1270 if ( pthread_mutex_unlock( &_MutexWait ) ) {
1271 perror("pthread_mutex_lock _Wait") ;
1277 bool GraphExecutor::InNode::ReadyWait() {
1278 // cdebug_in << "GraphExecutor::InNode::ReadyWait " << Name() << endl;
1280 aret = StateWait( SUPERV::ReadyState ) ;
1281 // cdebug_out << "GraphExecutor::InNode::ReadyWait" << endl ;
1285 bool GraphExecutor::InNode::RunningWait() {
1286 cdebug_in << pthread_self() << "GraphExecutor::InNode::RunningWait " << Name()
1287 << " " << Automaton()->StateName( State() ) << endl;
1289 aret = StateWait( SUPERV::RunningState ) ;
1290 cdebug_out << pthread_self() << "GraphExecutor::InNode::RunningWait " << Name()
1291 << " " << Automaton()->StateName( State() ) << endl;
1295 bool GraphExecutor::InNode::DoneWait() {
1296 // cdebug_in << "GraphExecutor::InNode::DoneWait " << Name() << endl;
1298 aret = StateWait( SUPERV::DoneState ) ;
1302 bool GraphExecutor::InNode::SuspendedWait() {
1303 // cdebug_in << "GraphExecutor::InNode::SuspendedWait " << Name() << endl;
1305 aret = StateWait( SUPERV::SuspendState ) ;
1309 void GraphExecutor::InNode::InitialState()
1311 cdebug_in << "GraphExecutor::InNode::InitialState Node " << Name() << endl;
1314 _ControlState = SUPERV::VoidState ;
1315 CreateNewThread( false ) ;
1316 CreateNewThreadIf( false ) ;
1317 _SuspendSync = false ;
1318 _ResumeSync = false ;
1320 // asv : 13.12.04 : "Loading" state is ON (and OFF eventially) only for Computing, Factory, Inline nodes
1321 if ( !IsMacroNode() )
1324 // ThreadNo( pthread_self() ) ;
1327 for ( i = 0 ; i < GetNodeOutPortsSize() ; i++ ) {
1328 if ( GetNodeOutPort(i)->IsDataStream() ) {
1329 GetChangeNodeOutPort(i)->State( SUPERV::ReadyState ) ;
1330 GetChangeNodeOutPort(i)->Done( true ) ;
1332 else if ( i != 0 || !IsGOTONode() ) {
1333 GetChangeNodeOutPort(i)->State( SUPERV::WaitingState ) ;
1334 GetChangeNodeOutPort(i)->Done( false ) ;
1338 int Pc = GetNodeInPortsSize() ;
1339 for ( i = 0 ; i < GetNodeInPortsSize() ; i++ ) {
1340 const GraphBase::InPort * anInPort = GetNodeInPort(i) ;
1341 GraphBase::OutPort * anOutPort = anInPort->GetOutPort() ;
1342 if ( IsHeadNode() && IsLoopNode() && anInPort->IsLoop() ) {
1343 anOutPort->PortStatus( DataConnected );
1344 anOutPort->State( SUPERV::ReadyState ) ;
1345 anOutPort->Done( true ) ;
1346 CORBA::Any * anAny = new CORBA::Any() ;
1347 *anAny <<= (long ) 1 ;
1348 anOutPort->Value( anAny ) ;
1350 // JR 15_09_2004 if backward link from GOTONode or EndLoopNode ==> DataConnected
1351 else if ( anInPort->IsGate() && anOutPort ) {
1352 anOutPort->State( SUPERV::WaitingState ) ;
1353 anOutPort->Done( false ) ;
1354 const GraphBase::ComputingNode * aFromNode = _OutNode->Graph()->GetGraphNode( anOutPort->NodeName() ) ;
1355 if ( aFromNode->IsGOTONode() || aFromNode->IsEndLoopNode() ) { // ASV: bug with synchronization of Inline nodes (via Gate ports) fixed.
1356 // before was "else if ( IsOneOfInlineNodes() )"
1357 // IsOneOfInline() == ( Inline || IsOneOfGOTO() ), so Inline are removed..
1358 anOutPort->PortStatus( DataConnected );
1359 anOutPort->State( SUPERV::ReadyState ) ;
1360 anOutPort->Done( true ) ;
1363 if ( anInPort->IsGate() && anOutPort == NULL ) {
1365 cdebug << "InPort" << i << " " << anInPort->PortName() << " Not connected Pc " << Pc << endl ;
1367 else if ( anOutPort ) {
1368 if ( anOutPort->IsDataConnected() || anOutPort->IsDataStream() ) {
1370 anOutPort->State( SUPERV::ReadyState ) ;
1371 anOutPort->Done( true ) ;
1372 cdebug << "InPort" << i << " " << anInPort->PortName() << " " << anInPort->PortStatus()
1373 << " " << theAutomaton->StateName( anOutPort->State() ) << " Pc " << Pc << endl ;
1375 else if ( anOutPort->IsPortConnected() ) {
1376 anOutPort->State( SUPERV::WaitingState ) ;
1377 anOutPort->Done( false ) ;
1378 cdebug << "InPort" << i << " " << anInPort->PortName() << " " << " " << anInPort->PortStatus()
1379 << " " << theAutomaton->StateName( anOutPort->State() ) << " Pc " << Pc << endl ;
1382 cdebug << "InPort" << i << " " << anInPort->PortName() << " " << anInPort->PortStatus()
1383 << " OutPort " << anOutPort->NodeName() << " " << anOutPort->PortName() << " "
1384 << theAutomaton->StateName( anOutPort->State() ) << " Pc " << Pc << endl ;
1388 cdebug << "InPort" << i << " " << anInPort->PortName() << " " << " " << anInPort->PortStatus()
1389 << " no corresponding OutPort Pc " << Pc << endl ;
1392 if ( !anOutPort->IsDataStream() || anInPort->IsDataStream() ) {
1393 cdebug << "InPort" << i << " state change : " << anInPort->PortName() << " from OutPort "
1394 << anOutPort->PortName() << " from Node " << anOutPort->NodeName()
1395 << " with state " << theAutomaton->StateName( anOutPort->State() ) << endl ;
1396 GetChangeNodeInPort(i)->State( anOutPort->State() ) ;
1398 else if ( anOutPort->IsDataConnected() ) {
1399 cdebug << "InPort" << i << " state change : " << anInPort->PortName() << " from OutPort "
1400 << anOutPort->PortName() << " from Node " << anOutPort->NodeName()
1401 << " with state ReadyState" << endl ;
1402 GetChangeNodeInPort(i)->State( SUPERV::ReadyState ) ;
1405 cdebug << "InPort" << i << " state NOT changed : " << anInPort->PortName() << " from OutPort "
1406 << anOutPort->PortName() << " " << anOutPort->PortStatus() << " from Node " << anOutPort->NodeName()
1407 << " with state " << anOutPort->State() << endl ;
1411 cdebug << "InPort" << i << " : " << anInPort->PortName() << " from OutPort "
1412 << anOutPort->PortName() << " from Node " << anOutPort->NodeName()
1414 if ( anOutPort->State() == SUPERV::WaitingState ) {
1415 cdebug << "WaitingState" ;
1417 else if ( anOutPort->State() == SUPERV::ReadyState ) {
1418 cdebug << "ReadyState" ;
1423 cdebug << " PortConnected("
1424 << anOutPort->IsPortConnected() << ") DataConnected("
1425 << anOutPort->IsDataConnected() << ")" << endl ;
1429 _currentState = Pc > 0 ? GraphExecutor::DataWaitingState
1430 : GraphExecutor::DataReadyState ;
1431 if ( Pc == GetNodeInPortsSize() ) {
1432 _OutNode->PushEvent( this , GraphExecutor::NoDataReadyEvent ,
1435 else if ( Pc != 0 ) {
1436 _OutNode->PushEvent( this , GraphExecutor::SomeDataReadyEvent ,
1440 _OutNode->PushEvent( this , GraphExecutor::AllDataReadyEvent ,
1444 for ( i = 0 ; i < GetNodeOutPortsSize() ; i++ ) {
1445 cdebug << "OutPort" << i << " : " << GetNodeOutPort(i)->PortName() << " "
1446 << theAutomaton->StateName( GetChangeNodeOutPort(i)->State() )
1447 << " " << GetNodeOutPort(i)->Kind() << endl ;
1450 cdebug << "CurrentState = " << theAutomaton->StateName( _currentState )
1453 cdebug_out << "GraphExecutor::InNode::InitialState" << endl;
1456 bool GraphExecutor::InNode::InitPythonFunctions(bool WithErr ) {
1457 cdebug_in << "GraphExecutor::InNode::InitPythonFunctions " << Name() << 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 );