2 //=============================================================================
3 // File : DataFlowBase_InNode.cxx
5 // Author : Jean Rahuel, CEA
8 //=============================================================================
17 #include <SALOMEconfig.h>
18 #include CORBA_CLIENT_HEADER(SALOME_Component)
19 #include "SALOME_NamingService.hxx"
20 #include "SALOME_LifeCycleCORBA.hxx"
22 #include "DataFlowBase_FactoryNode.hxx"
23 #include "DataFlowBase_GOTONode.hxx"
24 #include "DataFlowBase_LoopNode.hxx"
25 #include "DataFlowBase_EndOfLoopNode.hxx"
26 #include "DataFlowBase_SwitchNode.hxx"
27 #include "DataFlowBase_EndOfSwitchNode.hxx"
29 #include "DataFlowExecutor_OutNode.hxx"
31 static void InitInNode( SUPERV::ControlState &_ControlState ,
32 SUPERV::AutomatonState &_currentState ,
33 GraphExecutor::InNode ** _aReStartNode ,
34 bool & _PyFuncRunned ,
35 PyObject ** _MyPyRunMethod ,
36 pthread_mutex_t &_MutexDataWait ,
38 pthread_mutex_t &_MutexWait ,
39 pthread_cond_t &_ReadyWait ,
40 pthread_cond_t &_RunningWait ,
41 pthread_cond_t &_DoneWait ,
42 pthread_cond_t &_SuspendedWait ,
43 pthread_cond_t &_SuspendWait ,
45 pthread_cond_t &_ResumeWait ,
47 pthread_cond_t &_KillWait ,
49 pthread_cond_t &_StopWait ,
50 GraphExecutor::FiniteStateMachine ** _Automaton ,
51 GraphExecutor::FiniteStateMachine * theAutomaton ,
52 CORBA::ORB_ptr * _Orb ,
53 CORBA::ORB_ptr ORB ) {
54 _ControlState = SUPERV::VoidState ;
55 _currentState = SUPERV::UnKnownState ;
56 *_aReStartNode = NULL ;
57 _PyFuncRunned = false ;
58 *_MyPyRunMethod = NULL ;
59 pthread_mutex_init( &_MutexDataWait , NULL ) ;
61 pthread_mutex_init( &_MutexWait , NULL ) ;
62 if ( pthread_cond_init( &_ReadyWait , NULL ) ) {
63 perror("pthread_cond_init( &_ReadyWait , NULL )") ;
66 if ( pthread_cond_init( &_RunningWait , NULL ) ) {
67 perror("pthread_cond_init( &_RunningWait , NULL )") ;
70 if ( pthread_cond_init( &_DoneWait , NULL ) ) {
71 perror("pthread_cond_init( &_DoneWait , NULL )") ;
74 if ( pthread_cond_init( &_SuspendedWait , NULL ) ) {
75 perror("pthread_cond_init( &_SuspendedWait , NULL )") ;
78 if ( pthread_cond_init( &_SuspendWait , NULL ) ) {
79 perror("pthread_cond_init( &_SuspendWait , NULL )") ;
82 _SuspendSync = false ;
83 if ( pthread_cond_init( &_ResumeWait , NULL ) ) {
84 perror("pthread_cond_init( &_ResumeWait , NULL )") ;
88 if ( pthread_cond_init( &_KillWait , NULL ) ) {
89 perror("pthread_cond_init( &_KillWait , NULL )") ;
93 if ( pthread_cond_init( &_StopWait , NULL ) ) {
94 perror("pthread_cond_init( &_StopWait , NULL )") ;
97 *_Automaton = theAutomaton ;
98 *_Orb = CORBA::ORB::_nil();
101 GraphExecutor::FiniteStateMachine * theAutomaton = new
102 GraphExecutor::FiniteStateMachine() ;
104 //GraphExecutor::InNode::InNode() :
105 // GraphBase::FactoryNode() {
106 GraphExecutor::InNode::InNode() {
107 InitInNode( _ControlState ,
129 CORBA::ORB::_nil() ) ;
132 GraphExecutor::InNode::InNode(CORBA::ORB_ptr ORB,
133 SALOME_NamingService* ptrNamingService ,
134 const SALOME_ModuleCatalog::Service& aService ,
135 const char * ComponentName ,
136 const char * NodeInterfaceName ,
137 const char * NodeName ,
138 const SUPERV::KindOfNode akind ,
139 GraphBase::ListOfFuncName aFuncName ,
140 GraphBase::ListOfPythonFunctions aPythonFunction ,
141 const SUPERV::SDate NodeFirstCreation ,
142 const SUPERV::SDate NodeLastModification ,
143 const char * NodeEditorRelease ,
144 const char * NodeAuthor ,
145 const char * NodeComputer ,
146 const char * NodeComment ,
147 const bool GeneratedName ,
150 int * Graph_prof_debug,
151 ostream * Graph_fdebug) {
152 // ostream * Graph_fdebug = NULL ) :
153 // GraphBase::FactoryNode( ORB , ptrNamingService , aService ,
154 // ComponentName , NodeInterfaceName ,
155 // NodeName , akind ,
156 // NodeFirstCreation , NodeLastModification ,
157 // NodeEditorRelease , NodeAuthor ,
158 // NodeComputer , NodeComment , GeneratedName ,
160 // Graph_prof_debug , Graph_fdebug ) {
161 InitInNode( _ControlState ,
184 SetDebug( ORB , Graph_prof_debug , Graph_fdebug ) ;
186 _ComputingNode = NULL ;
187 _FactoryNode = NULL ;
191 _EndOfLoopNode = NULL ;
193 _EndOfSwitchNode = NULL ;
195 case SUPERV::ComputingNode : {
196 cdebug << "GraphExecutor::InNode::InNode SUPERV::ComputingNode : " << NodeName ;
197 _ComputingNode = new GraphBase::ComputingNode( ORB , ptrNamingService ,
201 NodeLastModification ,
202 NodeEditorRelease , NodeAuthor ,
203 NodeComment , GeneratedName ,
205 Graph_prof_debug , Graph_fdebug ) ;
208 case SUPERV::FactoryNode : {
209 cdebug << "GraphExecutor::InNode::InNode SUPERV::FactoryNode : " << NodeName ;
210 _FactoryNode = new GraphBase::FactoryNode( ORB , ptrNamingService , aService ,
211 ComponentName , NodeInterfaceName ,
214 NodeLastModification ,
215 NodeEditorRelease , NodeAuthor ,
216 NodeComputer , NodeComment ,
217 GeneratedName , NodeX , NodeY ,
218 Graph_prof_debug , Graph_fdebug ) ;
219 _ComputingNode = (GraphBase::ComputingNode *) _FactoryNode ;
222 case SUPERV::InLineNode : {
223 cdebug << "GraphExecutor::InNode::InNode SUPERV::InLineNode : " << NodeName ;
224 _InLineNode = new GraphBase::InLineNode( ORB , ptrNamingService ,
225 aFuncName[0].c_str() , *aPythonFunction[0] ,
227 NodeFirstCreation , NodeLastModification ,
228 NodeEditorRelease , NodeAuthor ,
229 NodeComment , GeneratedName ,
231 Graph_prof_debug , Graph_fdebug ) ;
232 _ComputingNode = (GraphBase::ComputingNode *) _InLineNode ;
235 case SUPERV::GOTONode : {
236 cdebug << "GraphEditor::InNode::InNode SUPERV::GOTONode : " << NodeName ;
237 _GOTONode = new GraphBase::GOTONode( ORB , ptrNamingService ,
238 aFuncName[0].c_str() , *aPythonFunction[0] ,
240 NodeFirstCreation , NodeLastModification ,
241 NodeEditorRelease , NodeAuthor ,
242 NodeComment , GeneratedName ,
244 Graph_prof_debug , Graph_fdebug ) ;
245 _ComputingNode = (GraphBase::ComputingNode *) _GOTONode ;
248 case SUPERV::LoopNode : {
249 cdebug << "GraphExecutor::InNode::InNode SUPERV::LoopNode : " << NodeName ;
250 _LoopNode = new GraphBase::LoopNode( ORB , ptrNamingService ,
251 aFuncName[0].c_str() , *aPythonFunction[0] ,
252 aFuncName[1].c_str() , *aPythonFunction[1] ,
253 aFuncName[2].c_str() , *aPythonFunction[2] ,
255 NodeFirstCreation , NodeLastModification ,
256 NodeEditorRelease , NodeAuthor ,
257 NodeComment , GeneratedName ,
259 Graph_prof_debug , Graph_fdebug ) ;
260 _ComputingNode = (GraphBase::ComputingNode *) _LoopNode ;
261 _GOTONode = (GraphBase::GOTONode *) _ComputingNode ;
264 case SUPERV::EndLoopNode : {
265 cdebug << "GraphEditor::InNode::InNode SUPERV::EndOfLoopNode : " << NodeName ;
266 _EndOfLoopNode = new GraphBase::EndOfLoopNode(
267 ORB , ptrNamingService ,
268 aFuncName[0].c_str() , *aPythonFunction[0] ,
270 NodeFirstCreation , NodeLastModification ,
271 NodeEditorRelease , NodeAuthor ,
272 NodeComment , GeneratedName ,
274 Graph_prof_debug , Graph_fdebug ) ;
275 _ComputingNode = (GraphBase::ComputingNode *) _EndOfLoopNode ;
276 _GOTONode = (GraphBase::GOTONode *) _ComputingNode ;
279 case SUPERV::SwitchNode : {
280 cdebug << "GraphExecutor::InNode::InNode SUPERV::SwitchNode : " << NodeName ;
281 _SwitchNode = new GraphBase::SwitchNode( ORB , ptrNamingService ,
282 aFuncName[0].c_str() , *aPythonFunction[0] ,
284 NodeFirstCreation , NodeLastModification ,
285 NodeEditorRelease , NodeAuthor ,
286 NodeComment , GeneratedName ,
288 Graph_prof_debug , Graph_fdebug ) ;
289 _ComputingNode = (GraphBase::ComputingNode *) _SwitchNode ;
290 _GOTONode = (GraphBase::GOTONode *) _ComputingNode ;
293 case SUPERV::EndSwitchNode : {
294 cdebug << "GraphEditor::InNode::InNode SUPERV::EndOfSwitchNode : " << NodeName ;
295 _EndOfSwitchNode = new GraphBase::EndOfSwitchNode(
296 ORB , ptrNamingService ,
297 aFuncName[0].c_str() , *aPythonFunction[0] ,
299 NodeFirstCreation , NodeLastModification ,
300 NodeEditorRelease , NodeAuthor ,
301 NodeComment , GeneratedName ,
303 Graph_prof_debug , Graph_fdebug ) ;
304 _ComputingNode = (GraphBase::ComputingNode *) _EndOfSwitchNode ;
305 _GOTONode = (GraphBase::GOTONode *) _ComputingNode ;
309 cdebug << "GraphExecutor::InNode::InNode " << (void *) this
310 << " _ComputingNode " << (void *) _ComputingNode ;
311 _ComputingNode->InNode( this ) ;
314 GraphExecutor::InNode::~InNode() {
317 void GraphExecutor::InNode::LockDataWait() {
318 if ( pthread_mutex_lock( &_MutexDataWait ) ) {
319 perror("Ready pthread_mutex_lock ") ;
324 void GraphExecutor::InNode::UnLockDataWait() {
326 if ( pthread_mutex_unlock( &_MutexDataWait ) ) {
327 perror("Ready pthread_mutex_unlock ") ;
332 bool GraphExecutor::InNode::Ping() {
333 // cdebug_in << "GraphExecutor::InNode::Ping" << endl;
335 if ( IsFactoryNode() ) {
336 RetVal = !CORBA::is_nil( _FactoryNode->Component() ) ;
338 if ( State() != SUPERV::SuspendedExecutingState ) {
339 _FactoryNode->Component()->ping() ;
346 // cdebug_out << "GraphExecutor::InNode::Ping" << endl ;
350 void GraphExecutor::InNode::NewThread( pthread_t aThread ) {
351 ThreadNo ( aThread ) ;
353 _OutNode->NewThread() ;
355 void GraphExecutor::InNode::ExitThread() {
357 _OutNode->ExitThread() ;
360 bool GraphExecutor::InNode::Suspend() {
361 cdebug_in << "GraphExecutor::InNode::Suspend " << Name() << " " << ThreadNo()
365 ControlState( SUPERV::VoidState ) ;
368 else if ( IsWaiting() || IsReady() ) {
369 ControlState( SUPERV::ToSuspendState ) ;
372 else if ( IsRunning() ) {
373 ControlState( SUPERV::ToSuspendState ) ;
374 if ( IsFactoryNode() ) {
375 if ( !CORBA::is_nil( Component() ) ) {
376 RetVal = Component()->Suspend_impl() ;
379 SendEvent( GraphExecutor::SuspendEvent ) ;
381 else if ( IsDone() ) {
382 ControlState( SUPERV::VoidState ) ;
383 RetVal = false ; // Too late ...
386 cdebug << "component Suspended and !IsDone and !IsRunning !"
392 cdebug << "Suspend cannot Suspend component !" << endl ;
397 cdebug << "Suspend with nilComponent while RunningState !" << endl ;
402 cdebug << "Suspend and !IsDone and !IsRunning and !IsWaiting ?"
406 cdebug_out << "GraphExecutor::InNode::Suspend " << RetVal << endl ;
410 bool GraphExecutor::InNode::ContainerKill() {
411 cdebug_in << "GraphExecutor::InNode::ContainerKill " << Name() << " "
412 << ThreadNo() << endl;
414 if ( IsFactoryNode() ) {
416 Container()->Kill_impl() ;
418 cdebug_out << "GraphExecutor::InNode::ContainerKill" << endl ;
422 bool GraphExecutor::InNode::Kill() {
423 cdebug_in << "GraphExecutor::InNode::Kill " << Name() << " " << ThreadNo() << " "
424 << Automaton()->StateName( State() ) << endl;
426 if ( ControlState() == SUPERV::ToKillState || IsDone() ) {
430 ControlState( SUPERV::ToKillState ) ;
432 ControlState( SUPERV::VoidState ) ;
437 if ( IsFactoryNode() ) {
438 if ( !CORBA::is_nil( Component() ) ) {
439 RetVal = Component()->Kill_impl() ;
442 SendEvent( GraphExecutor::KillEvent ) ;
444 else if ( IsDone() ) {
445 ControlState( SUPERV::VoidState ) ;
446 RetVal = false ; // Too late ...
449 cdebug << "component Killed and !IsDone and !IsRunning !"
455 cdebug << "Kill cannot Kill component !" << endl ;
460 cdebug << "Kill with nilComponent while RunningState !" << endl ;
461 SendEvent( GraphExecutor::KillEvent ) ;
462 RetVal = IsKilled() ;
465 else if ( IsSuspended() ) {
466 SendEvent( GraphExecutor::KillEvent ) ;
469 else if ( IsWaiting() ) {
473 cdebug << "Kill and !IsDone and !IsRunning and !IsWaiting ?"
479 cdebug_out << "GraphExecutor::InNode::Kill" << endl ;
483 bool GraphExecutor::InNode::KillDone() {
484 cdebug_in << "GraphExecutor::InNode::KillDone " << Name() << " " << ThreadNo()
487 if ( ControlState() == SUPERV::ToKillDoneState || IsDone() ) {
491 ControlState( SUPERV::ToKillDoneState ) ;
493 ControlState( SUPERV::VoidState ) ;
498 if ( IsFactoryNode() ) {
499 if ( !CORBA::is_nil( Component() ) ) {
500 RetVal = Component()->Kill_impl() ;
503 SendEvent( GraphExecutor::SuspendEvent ) ;
505 else if ( IsDone() ) {
506 ControlState( SUPERV::VoidState ) ;
507 RetVal = false ; // Too late ...
510 cdebug << "component Suspended and !IsDone and !IsRunning !"
516 cdebug << "Suspend cannot Suspend component !" << endl ;
521 cdebug << "Suspend with nilComponent while RunningState !" << endl ;
525 else if ( IsWaiting() ) {
529 cdebug << "Suspend and !IsDone and !IsRunning and !IsWaiting ?"
535 cdebug_out << "GraphExecutor::InNode::KillDone" << endl ;
539 bool GraphExecutor::InNode::Stop() {
540 cdebug_in << "GraphExecutor::InNode::Stop " << Name() << " " << ThreadNo()
543 if ( ControlState() == SUPERV::ToStopState || IsDone() ) {
547 ControlState( SUPERV::ToStopState ) ;
549 ControlState( SUPERV::VoidState ) ;
554 if ( IsFactoryNode() ) {
555 if ( !CORBA::is_nil( Component() ) ) {
556 RetVal = Component()->Stop_impl() ;
559 SendEvent( GraphExecutor::SuspendEvent ) ;
561 else if ( IsDone() ) {
562 ControlState( SUPERV::VoidState ) ;
563 RetVal = false ; // Too late ...
566 cdebug << "component Suspended and !IsDone and !IsRunning !"
572 cdebug << "Suspend cannot Suspend component !" << endl ;
577 cdebug << "Suspend with nilComponent while RunningState !" << endl ;
581 else if ( IsWaiting() ) {
585 cdebug << "Suspend and !IsDone and !IsRunning and !IsWaiting ?"
591 cdebug_out << "GraphExecutor::InNode::Stop" << endl ;
595 bool GraphExecutor::InNode::SuspendDone() {
596 cdebug_in << "GraphExecutor::InNode::SuspendDone " << Name() << " "
597 << ThreadNo() << endl;
599 if ( ControlState() == SUPERV::ToSuspendDoneState || IsDone() ) {
603 ControlState( SUPERV::ToSuspendDoneState ) ;
605 ControlState( SUPERV::VoidState ) ;
612 cdebug_out << "GraphExecutor::InNode::SuspendDone" << endl ;
616 bool GraphExecutor::InNode::Resume() {
617 cdebug_in << pthread_self() << "/" << ThreadNo()
618 << " GraphExecutor::InNode::Resume " << Name() << " "
619 << Automaton()->StateName( State() ) << endl;
620 bool RetVal = false ;
621 if ( IsSuspended() ) {
622 if ( State() == SUPERV::SuspendedReadyState ) {
623 ResumeAction( GraphExecutor::ToResumeEvent ) ;
626 else if ( State() == SUPERV::SuspendedExecutingState ) {
627 if ( IsFactoryNode() ) {
628 RetVal = Component()->Resume_impl() ;
631 else if ( State() == SUPERV::SuspendedSuccessedState ) {
632 ResumeAction( GraphExecutor::ToResumeEvent ) ;
635 else if ( State() == SUPERV::SuspendedErroredState ) {
636 ResumeAction( GraphExecutor::ToResumeEvent ) ;
640 cdebug << "GraphExecutor::InNode::Resume Not SuspendedReady/Executing/Successed/ErroredState "
641 << Automaton()->StateName( State() ) << endl ;
646 cdebug << "GraphExecutor::InNode::Resume Not Suspended State "
647 << Automaton()->StateName( State() ) << endl ;
650 if ( ControlState() == SUPERV::ToSuspendStartState ) {
651 ControlState( SUPERV::VoidState ) ;
655 if ( ControlState() == SUPERV::ToSuspendRunState ||
656 ( ControlState() == SUPERV::ToSuspendState &&
657 State() == SUPERV::SuspendedReadyState) ) {
658 if ( IsSuspended() ) {
659 if ( State() == SUPERV::SuspendedReadyState ) {
663 else if ( State() == SUPERV::SuspendedExecutingState ) {
665 RetVal = Component()->Resume_impl() ;
668 cdebug << "GraphExecutor::InNode::Resume State "
669 << Automaton()->StateName( State() ) << endl ;
672 if ( ControlState() != SUPERV::ToSuspendState ) {
673 ControlState( SUPERV::VoidState ) ;
676 else if ( IsRunning() ) {
679 else if ( IsWaiting() ) {
680 ControlState( SUPERV::VoidState ) ;
683 else if ( IsDone() ) {
687 else if ( ControlState() == SUPERV::ToSuspendDoneState ||
688 ( ControlState() == SUPERV::ToSuspendState &&
689 State() == SUPERV::SuspendedSuccessedState) ) {
690 if ( IsSuspended() ) {
691 if ( State() == SUPERV::SuspendedSuccessedState ) {
695 else if ( State() == SUPERV::SuspendedErroredState ) {
700 cdebug << "GraphExecutor::InNode::Resume State " << State() << endl ;
703 if ( ControlState() != SUPERV::ToSuspendState ) {
704 ControlState( SUPERV::VoidState ) ;
707 else if ( IsRunning() ) {
708 ControlState( SUPERV::VoidState ) ;
711 else if ( IsWaiting() ) {
712 ControlState( SUPERV::VoidState ) ;
715 else if ( IsDone() ) {
716 ControlState( SUPERV::VoidState ) ;
721 cdebug_out << "GraphExecutor::InNode::Resume " << RetVal << endl ;
725 bool GraphExecutor::InNode::ReStart( const char * AtNodeName ,
726 const bool AndSuspend ) {
727 bool RetVal = false ;
728 GraphExecutor::InNode * aRestartNode = (GraphExecutor::InNode *) _OutNode->GetGraphNode( AtNodeName )->GetInNode() ;
729 cdebug_in << pthread_self() << "/" << ThreadNo()
730 << " --> GraphExecutor::InNode::ReStartAt( "
731 << AtNodeName << " , " << AndSuspend << ") " << endl
732 << "thread " << aRestartNode->ThreadNo() << " "
733 << Automaton()->StateName( aRestartNode->State() )
734 << " from " << Name() << " " << Automaton()->StateName( State() )
736 if ( IsWaiting() && aRestartNode->IsSuspended() ) {
737 RetVal = aRestartNode->Resume() ;
739 else if ( IsSuspended() ) {
740 if ( strcmp( AtNodeName , Name() ) ) {
741 aRestartNode->State( SUPERV::SuspendedSuccessedState ) ;
744 ReStartAction( aRestartNode , GraphExecutor::ReStartAndSuspendEvent ) ;
747 ReStartAction( aRestartNode , GraphExecutor::ReStartEvent ) ;
751 cdebug_out << "<-- GraphExecutor::InNode::ReStartAt" << endl ;
755 bool GraphExecutor::InNode::IsWaiting() {
757 // cdebug_in << "GraphExecutor::InNode::IsWaiting " << Name() << endl;
758 SUPERV::AutomatonState aState = State() ;
759 if ( aState == SUPERV::DataUndefState ||
760 aState == SUPERV::DataWaitingState ||
761 aState == SUPERV::SuspendedReadyState )
762 // aState == SUPERV::SuspendedExecutingState ||
763 // aState == SUPERV::SuspendedSuccessedState ||
764 // aState == SUPERV::SuspendedErroredState ||
765 // aState == SUPERV::SuspendedState
767 // cdebug_out << "GraphExecutor::InNode::IsWaiting" << endl ;
771 bool GraphExecutor::InNode::IsReady() {
773 // cdebug_in << "GraphExecutor::InNode::IsReady " << Name() << endl;
774 SUPERV::AutomatonState aState = State() ;
775 if ( aState == SUPERV::DataUndefState ||
776 aState == SUPERV::DataWaitingState ||
777 aState == SUPERV::DataReadyState ||
778 aState == SUPERV::ResumedReadyState )
780 // cdebug_out << "GraphExecutor::InNode::IsReady" << endl ;
784 bool GraphExecutor::InNode::IsRunning() {
786 // cdebug_in << "GraphExecutor::InNode::IsRunning " << Name() << endl;
787 SUPERV::AutomatonState aState = State() ;
788 if ( aState == SUPERV::ExecutingState ||
789 aState == SUPERV::ResumedExecutingState )
791 // cdebug_out << "GraphExecutor::InNode::IsRunning" << endl ;
795 bool GraphExecutor::InNode::IsDone() {
797 // cdebug_in << "GraphExecutor::InNode::IsDone " << Name() << endl;
798 SUPERV::AutomatonState aState = State() ;
799 if ( aState == SUPERV::KilledReadyState ||
800 aState == SUPERV::StoppedReadyState ||
801 aState == SUPERV::KilledExecutingState ||
802 aState == SUPERV::StoppedExecutingState ||
803 aState == SUPERV::SuspendedSuccessedState ||
804 aState == SUPERV::SuspendedErroredState ||
805 // aState == SUPERV::SuccessedExecutingState ||
806 // aState == SUPERV::ErroredExecutingState ||
807 aState == SUPERV::SuccessedState ||
808 aState == SUPERV::ErroredState ||
809 aState == SUPERV::ResumedSuccessedState ||
810 aState == SUPERV::ResumedErroredState ||
811 aState == SUPERV::KilledSuccessedState ||
812 aState == SUPERV::StoppedSuccessedState )
814 // cdebug_out << "GraphExecutor::InNode::IsDone" << endl ;
818 bool GraphExecutor::InNode::IsSuspended() {
820 // cdebug_in << "GraphExecutor::InNode::IsSuspended " << Name() << endl;
821 SUPERV::AutomatonState aState = State() ;
822 if ( aState == SUPERV::SuspendedReadyState ||
823 aState == SUPERV::SuspendedExecutingState ||
824 aState == SUPERV::SuspendedSuccessedState ||
825 aState == SUPERV::SuspendedErroredState )
827 // cdebug_out << "GraphExecutor::InNode::IsSuspended" << endl ;
830 bool GraphExecutor::InNode::IsKilled() {
832 // cdebug_in << "GraphExecutor::InNode::IsKilled " << Name() << endl;
833 SUPERV::AutomatonState aState = State() ;
834 if ( aState == SUPERV::KilledReadyState ||
835 aState == SUPERV::KilledExecutingState ||
836 aState == SUPERV::KilledSuccessedState ||
837 aState == SUPERV::KilledErroredState ||
838 aState == SUPERV::KilledState )
840 // cdebug_out << "GraphExecutor::InNode::IsKilled" << endl ;
843 bool GraphExecutor::InNode::IsStopped() {
845 // cdebug_in << "GraphExecutor::InNode::IsStopped " << Name() << endl;
846 SUPERV::AutomatonState aState = State() ;
847 if ( aState == SUPERV::StoppedReadyState ||
848 aState == SUPERV::StoppedExecutingState ||
849 aState == SUPERV::StoppedSuccessedState ||
850 aState == SUPERV::StoppedErroredState ||
851 aState == SUPERV::StoppedState )
853 // cdebug_out << "GraphExecutor::InNode::IsStopped" << endl ;
857 bool GraphExecutor::InNode::StateWait( SUPERV::GraphState aState ) {
858 bool RetVal = false ;
859 if ( pthread_mutex_lock( &_MutexWait ) ) {
860 perror("pthread_mutex_lock _Wait") ;
864 case SUPERV::ReadyState : {
866 cdebug_in << pthread_self() << " StateWait( Ready ) " << RetVal
867 << " " << Automaton()->StateName( _currentState )
868 << " pthread_cond_wait _ReadyWait " << Name() << endl ;
869 while ( !RetVal && !IsDone() ) {
870 cdebug << pthread_self() << " pthread_cond_wait ReadyWait" << endl ;
871 pthread_cond_wait( &_ReadyWait , &_MutexWait );
873 cdebug << pthread_self() << " pthread_cond_waited ReadyWait "
874 << Automaton()->StateName( _currentState ) << " " << RetVal
877 cdebug_out << pthread_self() << " StateWait( Ready ) " << RetVal
878 << " " << Automaton()->StateName( _currentState )
879 << " pthread_cond_wait _ReadyWait " << Name() << endl ;
882 case SUPERV::RunningState : {
883 RetVal = IsRunning() ;
884 cdebug_in << pthread_self() << " StateWait( Running ) " << RetVal
885 << " " << Automaton()->StateName( _currentState )
886 << " pthread_cond_wait _RunningWait " << Name() << endl ;
887 while ( !RetVal && !IsDone() ) {
888 cdebug << pthread_self() << " pthread_cond_wait RunningWait" << endl ;
889 pthread_cond_wait( &_RunningWait , &_MutexWait );
890 RetVal = IsRunning() ;
891 cdebug << pthread_self() << " pthread_cond_waited RunningWait "
892 << Automaton()->StateName( _currentState ) << " " << RetVal
895 cdebug_out << pthread_self() << " StateWait( Running ) " << RetVal
896 << " " << Automaton()->StateName( _currentState )
897 << " pthread_cond_wait _RunningWait " << Name() << endl ;
900 case SUPERV::DoneState : {
902 cdebug_in << pthread_self() << " StateWait( Done ) " << RetVal
903 << " " << Automaton()->StateName( _currentState )
904 << " pthread_cond_wait _DoneWait " << Name() << endl ;
906 cdebug << pthread_self() << " pthread_cond_wait DoneWait" << endl ;
907 pthread_cond_wait( &_DoneWait , &_MutexWait );
909 cdebug << pthread_self() << " pthread_cond_waited DoneWait "
910 << Automaton()->StateName( _currentState ) << " " << RetVal
913 cdebug_out << pthread_self() << " StateWait( Done ) " << RetVal
914 << " " << Automaton()->StateName( _currentState )
915 << " pthread_cond_wait _DoneWait " << Name() << endl ;
918 case SUPERV::SuspendState : {
919 RetVal = IsSuspended() ;
920 cdebug_in << pthread_self() << " StateWait( Suspend ) " << RetVal
921 << " " << Automaton()->StateName( _currentState )
922 << " pthread_cond_wait _SuspendedWait " << Name() << endl ;
923 while ( !RetVal && !IsDone() ) {
924 cdebug << pthread_self() << " pthread_cond_wait SuspendedWait" << endl ;
925 pthread_cond_wait( &_SuspendedWait , &_MutexWait );
926 RetVal = IsSuspended() ;
927 cdebug << pthread_self() << " pthread_cond_waited SuspendedWait "
928 << Automaton()->StateName( _currentState ) << " " << RetVal
931 cdebug_out << pthread_self() << " StateWait( Suspend ) " << RetVal
932 << " " << Automaton()->StateName( _currentState )
933 << " pthread_cond_wait _SuspendedWait " << Name() << endl ;
937 cdebug << " GraphExecutor::OutNode::StateWait Error Undefined State : "
941 if ( pthread_mutex_unlock( &_MutexWait ) ) {
942 perror("pthread_mutex_lock _Wait") ;
948 bool GraphExecutor::InNode::ReadyWait() {
949 // cdebug_in << "GraphExecutor::InNode::ReadyWait " << Name() << endl;
951 aret = StateWait( SUPERV::ReadyState ) ;
952 // cdebug_out << "GraphExecutor::InNode::ReadyWait" << endl ;
956 bool GraphExecutor::InNode::RunningWait() {
957 // cdebug_in << "GraphExecutor::InNode::RunningWait " << Name() << endl;
959 aret = StateWait( SUPERV::RunningState ) ;
963 bool GraphExecutor::InNode::DoneWait() {
964 // cdebug_in << "GraphExecutor::InNode::DoneWait " << Name() << endl;
966 aret = StateWait( SUPERV::DoneState ) ;
970 bool GraphExecutor::InNode::SuspendedWait() {
971 // cdebug_in << "GraphExecutor::InNode::SuspendedWait " << Name() << endl;
973 aret = StateWait( SUPERV::SuspendState ) ;
977 void GraphExecutor::InNode::InitialState( GraphExecutor::OutNode * theOutNode )
979 cdebug_in << "GraphExecutor::InNode::InitialState Node " << Name() << endl;
981 _OutNode = theOutNode ;
984 _ControlState = SUPERV::VoidState ;
985 CreateNewThread( false ) ;
986 CreateNewThreadIf( false ) ;
987 _SuspendSync = false ;
988 _ResumeSync = false ;
989 // ThreadNo( pthread_self() ) ;
992 for ( i = 0 ; i < GetNodeOutPortsSize() ; i++ ) {
993 if ( i != 0 || !IsGOTONode() ) {
994 GetChangeNodeOutPort(i)->State( SUPERV::WaitingState ) ;
995 GetChangeNodeOutPort(i)->Done( false ) ;
999 int Pc = GetNodeInPortsSize() ;
1000 for ( i = 0 ; i < GetNodeInPortsSize() ; i++ ) {
1001 const GraphBase::InPort * anInPort = GetNodeInPort(i) ;
1002 GraphBase::OutPort * anOutPort = anInPort->GetOutPort() ;
1003 if ( IsHeadNode() && IsLoopNode() && anInPort->IsLoop() ) {
1004 anOutPort->PortStatus( DataConnected );
1005 anOutPort->State( SUPERV::ReadyState ) ;
1006 anOutPort->Done( true ) ;
1007 CORBA::Any * anAny = new CORBA::Any() ;
1008 *anAny <<= (long ) 1 ;
1009 anOutPort->Value( anAny ) ;
1011 else if ( anInPort->IsGate() && anOutPort ) {
1012 if ( IsComputingNode() || IsFactoryNode() ) {
1013 anOutPort->State( SUPERV::WaitingState ) ;
1014 anOutPort->Done( false ) ;
1016 else if ( IsOneOfInLineNodes() ) {
1017 anOutPort->PortStatus( DataConnected );
1018 anOutPort->State( SUPERV::ReadyState ) ;
1019 anOutPort->Done( true ) ;
1022 // if ( ( anInPort->IsGate() || anInPort->IsBus() ) && anOutPort == NULL ) {
1023 if ( ( anInPort->IsGate() ) && anOutPort == NULL ) {
1027 if ( anOutPort->IsDataConnected() ) {
1030 if ( anOutPort->IsPortConnected() ) {
1031 anOutPort->State( SUPERV::WaitingState ) ;
1032 anOutPort->Done( false ) ;
1034 else if ( anOutPort->IsDataConnected() ) {
1035 anOutPort->State( SUPERV::ReadyState ) ;
1036 anOutPort->Done( true ) ;
1040 GetChangeNodeInPort(i)->State( anOutPort->State() ) ;
1043 cdebug << "InPort" << i << " : " << anInPort->PortName() << " from OutPort "
1044 << anOutPort->PortName() << " from Node " << anOutPort->NodeName()
1046 if ( anOutPort->State() == SUPERV::WaitingState ) {
1047 cdebug << "WaitingState" ;
1049 else if ( anOutPort->State() == SUPERV::ReadyState ) {
1050 cdebug << "ReadyState" ;
1055 cdebug << " PortConnected("
1056 << anOutPort->IsPortConnected() << ") DataConnected("
1057 << anOutPort->IsDataConnected() << ")" << endl ;
1060 if ( !PyFuncRunned() ) {
1062 if ( IsLoopNode() ) {
1063 PyObject * PyRunMethod = InitPyDynInvoke( InLineNode()->PyFuncName() ,
1064 InLineNode()->PythonFunction() ) ;
1065 InLineNode()->PyRunMethod( PyRunMethod ) ;
1066 PyObject * PyMoreMethod = NULL ;
1067 if ( PyRunMethod ) {
1068 PyMoreMethod = InitPyDynInvoke( LoopNode()->PyMoreName() ,
1069 LoopNode()->MorePythonFunction() ) ;
1070 LoopNode()->PyMoreMethod( PyMoreMethod ) ;
1072 PyObject * PyNextMethod = NULL ;
1073 if ( PyMoreMethod ) {
1074 PyNextMethod = InitPyDynInvoke( LoopNode()->PyNextName() ,
1075 LoopNode()->NextPythonFunction() ) ;
1076 LoopNode()->PyNextMethod( PyNextMethod ) ;
1078 Err = !PyRunMethod || !PyMoreMethod || !PyNextMethod ;
1080 else if ( IsInLineNode() || IsSwitchNode() ) {
1081 PyObject * PyRunMethod = InitPyDynInvoke( InLineNode()->PyFuncName() ,
1082 InLineNode()->PythonFunction() ) ;
1083 InLineNode()->PyRunMethod( PyRunMethod ) ;
1084 Err = !PyRunMethod ;
1086 else if ( ( IsEndSwitchNode() || IsGOTONode() ) &&
1087 (*InLineNode()->PythonFunction()).length() ) {
1088 PyObject * PyRunMethod = InitPyDynInvoke( InLineNode()->PyFuncName() ,
1089 InLineNode()->PythonFunction() ) ;
1090 InLineNode()->PyRunMethod( PyRunMethod ) ;
1091 Err = !PyRunMethod ;
1096 _currentState = Pc > 0 ? SUPERV::DataWaitingState
1097 : SUPERV::DataReadyState ;
1098 if ( Pc == GetNodeInPortsSize() ) {
1099 _OutNode->PushEvent( this , GraphExecutor::NoDataReadyEvent ,
1102 else if ( Pc != 0 ) {
1103 _OutNode->PushEvent( this , GraphExecutor::SomeDataReadyEvent ,
1107 _OutNode->PushEvent( this , GraphExecutor::AllDataReadyEvent ,
1110 cdebug << "CurrentState = " << theAutomaton->StateName( _currentState )
1114 GraphExecutor::InNode * anInNode = (GraphExecutor::InNode *) _OutNode->GetGraphNode( "label_begin" ) ;
1115 const GraphBase::InPort * anInPort = anInNode->GetNodeInPort(0) ;
1116 GraphBase::OutPort * anOutPort = anInPort->GetLink() ;
1118 cdebug << "InPort" << i << " : " << anInPort->PortName() << " from OutPort "
1119 << anOutPort->PortName() << " from Node " << anOutPort->NodeName()
1121 if ( anOutPort->State() == SUPERV::WaitingState ) {
1122 cdebug << "WaitingState" ;
1124 else if ( anOutPort->State() == SUPERV::ReadyState ) {
1125 cdebug << "ReadyState" ;
1130 cdebug << " PortConnected("
1131 << anOutPort->IsPortConnected() << ") DataConnected("
1132 << anOutPort->IsDataConnected() << ")" << endl ;
1136 cdebug_out << "GraphExecutor::InNode::InitialState" << endl;