2 //=============================================================================
3 // File : DataFlowBase_OutNode.cxx
5 // Author : Jean Rahuel, CEA
8 //=============================================================================
10 #include "DataFlowExecutor_OutNode.hxx"
12 // Implementation de la classe GraphEditor::GraphControl
14 extern GraphExecutor::FiniteStateMachine * theAutomaton ;
16 static const char *ComponentName = "SalomeSuperVisionComponent" ;
18 GraphExecutor::OutNode::OutNode() :
24 _ControlState = SUPERV::VoidState ;
25 _State = SUPERV::UnKnownState ;
26 _PyInitialized = false ;
27 pthread_mutex_init( &_MutexWait , NULL ) ;
28 if ( pthread_cond_init( &_EventWait , NULL ) ) {
29 perror("pthread_cond_init( &_EventWait , NULL )") ;
32 if ( pthread_cond_init( &_JoinWait , NULL ) ) {
33 perror("pthread_cond_init( &_JoinWait , NULL )") ;
38 GraphExecutor::OutNode::OutNode( CORBA::ORB_ptr ORB,
39 SALOME_NamingService* ptrNamingService ,
40 const char *DataFlowName ,
41 const char * DebugFileName ) :
42 Graph( ORB , ptrNamingService , DataFlowName , DebugFileName ) {
43 cdebug_in << "GraphEditor::OutNode::OutNode(" << DataFlowName << ")" << endl;
48 _ControlState = SUPERV::VoidState ;
49 _State = SUPERV::UnKnownState ;
50 _PyInitialized = false ;
51 _Orb = CORBA::ORB::_duplicate( ORB ) ;
52 pthread_mutex_init( &_MutexWait , NULL ) ;
53 if ( pthread_cond_init( &_EventWait , NULL ) ) {
54 perror("pthread_cond_init( &_EventWait , NULL )") ;
57 if ( pthread_cond_init( &_JoinWait , NULL ) ) {
58 perror("pthread_cond_init( &_JoinWait , NULL )") ;
61 cdebug_out << "GraphEditor::OutNode::OutNode" << endl;
64 GraphExecutor::OutNode::OutNode(
66 SALOME_NamingService* ptrNamingService ,
67 const SALOME_ModuleCatalog::Service& DataFlowService ,
68 const char *DataFlowComponentName ,
69 const char *DataFlowInterfaceName ,
70 const char *DataFlowName ,
71 const SUPERV::KindOfNode DataFlowkind ,
72 const SUPERV::SDate DataFlowFirstCreation ,
73 const SUPERV::SDate DataFlowLastModification ,
74 const char * DataFlowEditorRelease ,
75 const char * DataFlowAuthor ,
76 const char * DataFlowComputer ,
77 const char * DataFlowComment ,
78 const char * DebugFileName ) :
79 Graph( ORB , ptrNamingService , DataFlowService , DataFlowComponentName ,
80 DataFlowInterfaceName , DataFlowName , DataFlowkind ,
81 DataFlowFirstCreation , DataFlowLastModification ,
82 DataFlowEditorRelease , DataFlowAuthor ,
83 DataFlowComputer , DataFlowComment , DebugFileName ) {
88 _ControlState = SUPERV::VoidState ;
89 _State = SUPERV::UnKnownState ;
90 _PyInitialized = false ;
91 _Orb = CORBA::ORB::_duplicate( ORB ) ;
92 pthread_mutex_init( &_MutexWait , NULL ) ;
93 if ( pthread_cond_init( &_EventWait , NULL ) ) {
94 perror("pthread_cond_init( &_EventWait , NULL )") ;
97 if ( pthread_cond_init( &_JoinWait , NULL ) ) {
98 perror("pthread_cond_init( &_JoinWait , NULL )") ;
103 GraphExecutor::OutNode::~OutNode() {
106 bool GraphExecutor::OutNode::LoadDataFlow(const GraphBase::SGraph &aDataFlow ) {
107 bool RetVal = false ;
108 RetVal = LoadInfo( aDataFlow.Info ) ;
109 if ( GraphBase::Service::ServiceName() != NULL ) {
110 // MESSAGE( "GraphExecutor::OutNode::LoadDataFlow" );
112 RetVal = LoadNodes( aDataFlow.Nodes ) ;
114 RetVal = LoadLinks( aDataFlow.Links ) ;
117 RetVal = LoadDatas( aDataFlow.Datas ) ;
120 cdebug << "GraphExecutor::OutNode::LoadDataFlow LoadDatas Error."
125 cdebug << "GraphExecutor::OutNode::LoadDataFlow LoadLinks Error."
130 cdebug << "GraphExecutor::OutNode::LoadDataFlow LoadNodes Error."
135 cdebug << "GraphExecutor::OutNode::LoadDataFlow LoadInfo Error."
140 cdebug << "GraphExecutor::OutNode::LoadDataFlow ServiceName Error." << endl ;
145 bool GraphExecutor::OutNode::LoadXml( const char* myFileName ) {
146 bool RetVal = false ;
147 GraphBase::SGraph aDataFlow ;
148 if ( GraphBase::Graph::LoadXml( _Orb , myFileName , aDataFlow ) ) {
149 RetVal = LoadDataFlow( aDataFlow ) ;
150 // if ( aConstructor && RetVal )
151 // RetVal = Name( aDataFlow.Info.theName.c_str() ) ;
156 bool GraphExecutor::OutNode::LoadInfo(const GraphBase::SNode &aDataFlowInfo ) {
157 cdebug << "GraphExecutor::OutNode::LoadInfo" << endl ;
158 // ComponentName( aDataFlowInfo.theComponentName.c_str() ) ;
159 Name( aDataFlowInfo.theName.c_str() ) ;
160 Kind( aDataFlowInfo.theKind ) ;
161 DataService( _Orb , aDataFlowInfo.theService , Graph_prof_debug() , Graph_fdebug() ) ;
162 FirstCreation( aDataFlowInfo.theFirstCreation ) ;
163 LastModification( aDataFlowInfo.theLastModification ) ;
164 EditorRelease( aDataFlowInfo.theEditorRelease.c_str() ) ;
165 Author( aDataFlowInfo.theAuthor.c_str() ) ;
166 // Computer( aDataFlowInfo.theContainer.c_str() ) ;
167 Comment( aDataFlowInfo.theComment.c_str() ) ;
168 // Not in OutNode/DataFlow but in InNode/DataFlow_in_an_other_DataFlow
169 // Coordinates( aDataFlowInfo.theX , aDataFlowInfo.theY ) ;
173 bool GraphExecutor::OutNode::LoadNodes(const GraphBase::ListOfNodes &aListOfNodes ) {
175 GraphExecutor::InNode * anInNode ;
176 cdebug << "GraphExecutor::OutNode::LoadNodes" << endl ;
178 for ( i = 0 ; i < aListOfNodes.size() ; i++ ) {
179 GraphBase::SNode aNode = aListOfNodes[ i ] ;
180 anInNode = AddNode( aNode.theService ,
181 aNode.theListOfFuncName ,
182 aNode.theListOfPythonFunctions ,
183 aNode.theComponentName.c_str() ,
184 aNode.theInterfaceName.c_str() , aNode.theName.c_str() ,
186 aNode.theFirstCreation , aNode.theLastModification ,
187 aNode.theEditorRelease.c_str() ,
188 aNode.theAuthor.c_str() , aNode.theContainer.c_str() ,
189 aNode.theComment.c_str() ,
190 aNode.theCoords.theX , aNode.theCoords.theY ) ;
195 if ( anInNode->IsOneOfInLineNodes() ) {
196 anInNode->GraphExecutor::InNode::InLineNode()->DefPortsOfNode(
197 _Orb , aNode.theService , anInNode->NamePtr() ,
198 anInNode->Kind() , false ,
199 anInNode->IsLoopNode() || anInNode->IsEndLoopNode() ,
200 true , true , Graph_prof_debug() , Graph_fdebug() ) ;
202 GraphBase::InLineNode * aINode = anInNode->InLineNode() ;
203 GraphBase::LoopNode * aLNode = NULL ;
204 if ( aINode->IsLoopNode() ) {
205 aLNode = anInNode->LoopNode() ;
206 aLNode->SetPythonFunction( aNode.theListOfFuncName[ 0 ].c_str() ,
207 *aNode.theListOfPythonFunctions[ 0 ] ) ;
208 aLNode->SetMorePythonFunction( aNode.theListOfFuncName[ 1 ].c_str() ,
209 *aNode.theListOfPythonFunctions[ 1 ] ) ;
210 aLNode->SetNextPythonFunction( aNode.theListOfFuncName[ 2 ].c_str() ,
211 *aNode.theListOfPythonFunctions[ 2 ] ) ;
213 else if ( aINode->IsInLineNode() || aINode->IsGOTONode() ||
214 aINode->IsSwitchNode() || aINode->IsEndSwitchNode() ) {
215 aINode->SetPythonFunction( aNode.theListOfFuncName[ 0 ].c_str() ,
216 *aNode.theListOfPythonFunctions[ 0 ] ) ;
221 if ( aNode.theListOfParameters.size() ) { // BusPorts ...
223 for ( j = 0 ; j < aNode.theListOfParameters.size() ; j++ ) {
224 GraphBase::InPort * InputPort = anInNode->AddInPort(
225 aNode.theListOfParameters[ j ].theInParameter.Parametername ,
226 aNode.theListOfParameters[ j ].theInParameter.Parametertype ) ;
227 GraphBase::OutPort * OutputPort = anInNode->AddOutPort(
228 aNode.theListOfParameters[ j ].theOutParameter.Parametername ,
229 aNode.theListOfParameters[ j ].theOutParameter.Parametertype ) ;
230 anInNode->InOutPort( InputPort , OutputPort ) ;
235 for ( i = 0 ; i < aListOfNodes.size() ; i++ ) {
236 GraphBase::SNode aNode = aListOfNodes[ i ] ;
237 anInNode = (GraphExecutor::InNode * ) GetChangeGraphNode( aNode.theName.c_str() )->GetInNode() ;
238 cdebug << "GraphExecutor::OutNode::LoadNodes " << anInNode->Name() << "IsOneOfGOTONodes "
239 << anInNode->IsOneOfGOTONodes() << " " << aNode.theCoupledNode.c_str() << endl ;
240 if ( anInNode->IsOneOfGOTONodes() && strlen( aNode.theCoupledNode.c_str() ) ) {
241 GraphBase::GOTONode * aCoupledNode ;
242 aCoupledNode = (GraphBase::GOTONode * ) GetGraphNode( aNode.theName.c_str() ) ;
243 aCoupledNode->CoupledNode( (GraphBase::GOTONode * ) GetChangeGraphNode( aNode.theCoupledNode.c_str() ) ) ;
249 bool GraphExecutor::OutNode::LoadLinks(const GraphBase::ListOfLinks &aListOfLinks ) {
251 cdebug << "GraphExecutor::OutNode::LoadLinks " << aListOfLinks.size()
254 for ( i = 0 ; i < aListOfLinks.size() ; i++ ) {
255 GraphBase::SLink aLink = aListOfLinks[ i ] ;
256 RetVal = AddLink( aLink.FromNodeName.c_str() ,
257 aLink.FromServiceParameterName.c_str() ,
258 aLink.ToNodeName.c_str() ,
259 aLink.ToServiceParameterName.c_str() ,
261 // aLink.aLinkValue.Value , aLink.aLinkValue.Kind ) ;
268 bool GraphExecutor::OutNode::LoadDatas(const GraphBase::ListOfLinks &aListOfDatas ) {
270 cdebug << "GraphExecutor::OutNode::LoadDatas " << aListOfDatas.size()
273 for ( i = 0 ; i < aListOfDatas.size() ; i++ ) {
274 GraphBase::SLink aLink = aListOfDatas[ i ] ;
275 if ( !strcmp( aLink.FromNodeName.c_str() , Name() ) )
276 RetVal = GraphBase::Graph::AddInputData( aLink.ToNodeName.c_str() ,
277 aLink.ToServiceParameterName.c_str() ,
279 // aLink.aLinkValue.Value , aLink.aLinkValue.Kind ) ;
280 else if ( !strcmp( aLink.ToNodeName.c_str() , Name() ) ) {
281 RetVal = AddOutputData( aLink.FromNodeName.c_str() ,
282 aLink.FromServiceParameterName.c_str() ,
284 // aLink.aLinkValue.Value ,
285 // aLink.aLinkValue.Kind ) ;
286 AddLink( aLink.FromNodeName.c_str() , (GraphBase::ComputingNode *) this ) ;
289 cdebug << "GraphExecutor::OutNode::LoadDatas Error " << aLink.FromNodeName
290 << " and " << aLink.ToNodeName << " differents from " << Name()
300 GraphExecutor::InNode *GraphExecutor::OutNode::AddNode(
301 const SALOME_ModuleCatalog::Service& NodeService ,
302 GraphBase::ListOfFuncName aFuncName ,
303 GraphBase::ListOfPythonFunctions aPythonFunction ,
304 const char * NodeComponentName ,
305 const char * NodeInterfaceName ,
306 const char * NodeName ,
307 const SUPERV::KindOfNode NodeKindOfNode ,
308 const SUPERV::SDate NodeFirstCreation ,
309 const SUPERV::SDate NodeLastModification ,
310 const char * NodeEditorRelease ,
311 const char * NodeAuthor ,
312 const char * NodeComputer ,
313 const char * NodeComment ,
316 cdebug_in << "GraphExecutor::OutNode::AddNode(" << NodeComponentName << " , "
317 << NodeName << ")" << endl;
318 GraphExecutor::InNode *Nd = NULL ;
319 Nd = new GraphExecutor::InNode( _Orb, NamingService() , NodeService ,
320 NodeComponentName , NodeInterfaceName ,
321 NodeName , NodeKindOfNode ,
322 aFuncName , aPythonFunction ,
323 NodeFirstCreation , NodeLastModification ,
324 NodeEditorRelease , NodeAuthor ,
325 NodeComputer , NodeComment , false , NodeX , NodeY ,
326 Graph_prof_debug() , Graph_fdebug() ) ;
327 GraphBase::Graph::AddNode( Nd->ComputingNode() ) ;
328 cdebug_out << "GraphExecutor::OutNode::AddNode" << endl;
333 bool GraphExecutor::OutNode::AddInputData( const char* ToNodeName1 ,
334 const char* ToParameterName1 ,
335 const char* ToNodeName2 ,
336 const char* ToParameterName2 ) {
337 cdebug_in << "GraphExecutor::OutNode::AddInputData" << endl;
338 bool RetVal = GraphBase::Graph::AddInputData( ToNodeName1 ,
342 cdebug_out << "GraphExecutor::OutNode::AddInputData" << endl;
347 bool GraphExecutor::OutNode::Valid() {
348 cdebug_in << "GraphExecutor::OutNode::Valid" << endl;
353 _Executable = false ;
358 cdebug << "This DataFlow is not valid." << endl ;
370 cdebug_out << "GraphExecutor::OutNode::Valid" << endl;
375 bool GraphExecutor::OutNode::Executable() {
377 cdebug_in << "GraphExecutor::OutNode::Executable" << endl;
381 if ( DataServerNodes() )
384 cdebug << "This DataFlow is not executable." << endl ;
385 _Executable = false ;
388 cdebug_out << "GraphExecutor::OutNode::Executable" << endl;
392 bool GraphExecutor::OutNode::Run( const bool AndSuspend ) {
393 bool RetVal = false ;
394 cdebug_in << "GraphExecutor::OutNode::Run" << endl;
396 if ( Executable() ) {
397 _ControlState = SUPERV::VoidState ;
398 _SuspendedThreads = 0 ;
399 ThreadNo( pthread_self() ) ;
401 _JustStarted = true ;
403 for ( i = 0 ; i < GraphNodesSize() ; i++ ) {
404 GraphExecutor::InNode * anInNode = (GraphExecutor::InNode *) GraphNodes( i )->GetInNode() ;
405 if ( !PyInitialized() && anInNode->IsOneOfInLineNodes() ) {
406 if ( !Py_IsInitialized() ) {
409 anInNode->InitPython() ;
410 PyInitialized( true ) ;
412 anInNode->InitialState( this ) ;
415 cdebug << "Execution starting GraphExecutor::Action_DataOk_RunService Node "
418 PushEvent( NULL , GraphExecutor::ReadyEvent ,
419 SUPERV::DataReadyState ) ;
420 State( SUPERV::DataReadyState ) ;
422 for ( i = 0 ; i < HeadNodesSize() ; i++ ) {
423 GraphExecutor::InNode * anInNode = (GraphExecutor::InNode *) HeadNodes( i )->GetInNode() ;
424 if ( anInNode->State() != SUPERV::DataReadyState ) {
425 cdebug << "GraphExecutor::OutNode::Run inconsistency State of Node "
426 << anInNode->Name() << " : " << anInNode->State() << endl ;
429 // PushEvent( anInNode , GraphExecutor::ReadyEvent ,
430 // SUPERV::DataReadyState ) ;
431 anInNode->CreateNewThread( true ) ;
432 anInNode->DataFromNode( Name() ) ;
434 anInNode->State( SUPERV::DataWaitingState ) ;
435 anInNode->ControlState( SUPERV::ToSuspendStartState ) ;
436 if ( !anInNode->SendEvent( GraphExecutor::SomeDataReadyEvent ) ) {
437 cdebug << "InNode::SendEvent( SomeDataReadyEvent ) Node "
438 << anInNode->Name() << endl ;
441 anInNode->SuspendedWait() ;
443 else if ( !anInNode->SendEvent( GraphExecutor::ExecuteEvent ) ) {
444 cdebug << "InNode::SendEvent( RunningEvent ) Node "
445 << anInNode->Name() << endl ;
449 anInNode->RunningWait() ;
454 PushEvent( NULL , GraphExecutor::SuspendedReadyEvent ,
455 SUPERV::SuspendedReadyState ) ;
458 PushEvent( NULL , GraphExecutor::ExecutingEvent ,
459 SUPERV::ExecutingState ) ;
460 if (AutomatonState() == SUPERV::DataReadyState) {
461 State( SUPERV::ExecutingState ) ;
468 PushEvent( NULL , GraphExecutor::NoDataReadyEvent ,
469 SUPERV::DataUndefState ) ;
472 cdebug_out << "GraphExecutor::OutNode::Run" << endl ;
476 bool GraphExecutor::OutNode::Run( const char * aNodeName ,
477 const char * AtNodeName ,
478 const bool AndSuspend ) {
479 bool RetVal = false ;
480 cdebug_in << "GraphExecutor::OutNode::Run( " << aNodeName << " , "
481 << AtNodeName << " , " << AndSuspend << ")" << endl;
482 GraphExecutor::InNode *anInNode = (GraphExecutor::InNode *) GetGraphNode( aNodeName )->GetInNode() ;
484 RetVal = anInNode->ReStart( AtNodeName , AndSuspend ) ;
486 cdebug_out << "GraphExecutor::OutNode::Run" << endl ;
490 void GraphExecutor::OutNode::CheckAllDone() {
492 cdebug_in << "GraphExecutor::OutNode::CheckAllDone " << endl;
493 SUPERV::AutomatonState OutNodeState = SUPERV::SuccessedState ;
494 SUPERV::AutomatonState InNodeState ;
495 bool AllDone = true ;
497 for ( j = 0 ; j < QueueNodesSize() ; j++ ) {
498 InNodeState = ( (GraphExecutor::InNode * ) QueueNodes( j )->GetInNode() )->State() ;
500 << ( (GraphExecutor::InNode * ) QueueNodes( j )->GetInNode() )->Name()
501 << " " << theAutomaton->StateName( InNodeState ) << endl ;
502 if ( InNodeState != SUPERV::SuccessedState &&
503 InNodeState != SUPERV::ErroredState &&
504 InNodeState != SUPERV::DataWaitingState ) {
507 if ( InNodeState != SUPERV::SuccessedState ) {
508 OutNodeState = InNodeState ;
512 if( _Threads == 0 && _SuspendedThreads == 0 ) {
513 if ( OutNodeState != SUPERV::ErroredState ) {
514 OutNodeState = SUPERV::SuccessedState ;
522 State( OutNodeState ) ;
524 _JustStarted = false ;
525 for ( j = 0 ; j < GraphNodesSize() ; j++ ) {
526 GraphExecutor::InNode * aNode ;
527 aNode = (GraphExecutor::InNode * ) GraphNodes( j )->GetInNode() ;
528 SUPERV::GraphState aState = AutomatonGraphState( aNode->State() ) ;
529 cdebug << "GraphExecutor::OutNode::CheckAllDone " << aNode->Name() << " "
530 << theAutomaton->StateName( aNode->State() ) << " :" << endl ;
531 if ( aState == SUPERV::ErrorState ||
532 aState == SUPERV::SuspendErroredState ||
533 aState == SUPERV::KillState ||
534 aState == SUPERV::StopState ) {
535 OutNodeState = aNode->State() ;
537 aNode->SuspendedAction() ;
538 aNode->DoneAction() ;
540 // PushEvent AFTER State and _Done ! ...
541 PushEvent( NULL , GraphExecutor::EndExecuteEvent ,
544 PyInitialized( false ) ;
547 cdebug_out << "GraphExecutor::OutNode::CheckAllDone " << _Done
548 << " GraphAutomatonState " << theAutomaton->StateName( AutomatonState() )
549 << " State " << State() << " Threads " << _Threads << " SuspendedThreads "
550 << _SuspendedThreads << endl ;
553 void GraphExecutor::OutNode::NewThread() {
554 if ( pthread_mutex_lock( &_MutexWait ) ) {
555 perror("pthread_mutex_lock _NewThread") ;
559 cdebug << "NewThread : " << _Threads << " running threads "
560 << _SuspendedThreads << " suspended threads"
562 if ( pthread_mutex_unlock( &_MutexWait ) ) {
563 perror("pthread_mutex_unlock _NewThread") ;
567 void GraphExecutor::OutNode::ExitThread() {
568 if ( pthread_mutex_lock( &_MutexWait ) ) {
569 perror("pthread_mutex_lock _ExitThread") ;
573 theAutomaton->JoinThread( pthread_self() ) ;
574 if ( pthread_cond_signal( &_JoinWait ) ) {
575 perror("ExitThread pthread_cond_signal ") ;
577 cdebug << "ExitThread : " << _Threads << " running threads "
578 << _SuspendedThreads << " suspended threads"
580 if ( pthread_mutex_unlock( &_MutexWait ) ) {
581 perror("pthread_mutex_unlock _ExitThread") ;
584 if ( _Threads == 0 && _SuspendedThreads == 0 ) {
588 void GraphExecutor::OutNode::JoinedWait() {
589 if ( pthread_mutex_lock( &_MutexWait ) ) {
590 perror("pthread_mutex_lock JoinedWait") ;
594 if ( pthread_cond_wait( &_JoinWait , &_MutexWait ) ) {
595 perror("JoinedWait pthread_cond_wait ") ;
598 if ( pthread_mutex_unlock( &_MutexWait ) ) {
599 perror("pthread_mutex_unlock JoinedWait") ;
603 void GraphExecutor::OutNode::SuspendThread() {
604 if ( pthread_mutex_lock( &_MutexWait ) ) {
605 perror("pthread_mutex_lock _SuspendThread") ;
608 _SuspendedThreads += 1 ;
609 cdebug << "SuspendThread : " << _Threads << " running threads "
610 << _SuspendedThreads << " suspended threads"
612 if ( pthread_mutex_unlock( &_MutexWait ) ) {
613 perror("pthread_mutex_unlock _SuspendThread") ;
616 if ( IsSuspended() ) {
617 PushEvent( NULL , GraphExecutor::SuspendEvent , SUPERV::SuspendedState ) ;
620 void GraphExecutor::OutNode::ResumeThread() {
621 if ( pthread_mutex_lock( &_MutexWait ) ) {
622 perror("pthread_mutex_lock _ResumeThread") ;
625 _SuspendedThreads -= 1 ;
626 cdebug << "ResumeThread : " << _Threads << " running threads "
627 << _SuspendedThreads << " suspended threads"
629 if ( pthread_mutex_unlock( &_MutexWait ) ) {
630 perror("pthread_mutex_unlock _ResumeThread") ;
635 long GraphExecutor::OutNode::Thread( const char * aNodeName ) {
637 GraphExecutor::InNode *anInNode = (GraphExecutor::InNode *) GetGraphNode( aNodeName )->GetInNode() ;
639 RetVal = anInNode->ThreadNo() ;
644 SUPERV::GraphEvent GraphExecutor::OutNode::AutomatonGraphEvent(GraphExecutor::NodeEvent anEvent ) {
645 SUPERV::GraphEvent aGraphEvent ;
647 case GraphExecutor::UndefinedEvent : {
648 aGraphEvent = SUPERV::UndefinedEvent ;
651 case GraphExecutor::NewThreadEvent : {
652 aGraphEvent = SUPERV::NewThreadEvent ;
655 case GraphExecutor::SuspendEvent : {
656 aGraphEvent = SUPERV::SuspendEvent ;
659 case GraphExecutor::ResumeEvent : {
660 aGraphEvent = SUPERV::ResumeEvent ;
663 case GraphExecutor::KillEvent : {
664 aGraphEvent = SUPERV::KillEvent ;
667 case GraphExecutor::StopEvent : {
668 aGraphEvent = SUPERV::StopEvent ;
671 case GraphExecutor::ExecuteEvent : {
672 aGraphEvent = SUPERV::RunningEvent ;
675 case GraphExecutor::SuccessEvent : {
676 aGraphEvent = SUPERV::DoneEvent ;
679 case GraphExecutor::ErrorEvent : {
680 aGraphEvent = SUPERV::ErroredEvent ;
683 case GraphExecutor::ReStartEvent : {
684 aGraphEvent = SUPERV::ReRunEvent ;
687 case GraphExecutor::ReStartAndSuspendEvent : {
688 aGraphEvent = SUPERV::ReStartEvent ;
691 case GraphExecutor::NoDataReadyEvent : {
692 aGraphEvent = SUPERV::WaitingEvent ;
695 case GraphExecutor::SomeDataReadyEvent : {
696 aGraphEvent = SUPERV::WaitingEvent ;
699 case GraphExecutor::NotAllDataReadyEvent : {
700 aGraphEvent = SUPERV::WaitingEvent ;
703 case GraphExecutor::AllDataReadyEvent : {
704 aGraphEvent = SUPERV::ReadyEvent ;
707 case GraphExecutor::ReadyEvent : {
708 aGraphEvent = SUPERV::ReadyEvent ;
711 case GraphExecutor::SuspendedReadyEvent : {
712 aGraphEvent = SUPERV::SuspendEvent ;
715 case GraphExecutor::ResumedReadyEvent : {
716 aGraphEvent = SUPERV::ResumeEvent ;
719 case GraphExecutor::KilledReadyEvent : {
720 aGraphEvent = SUPERV::KillEvent ;
723 case GraphExecutor::StoppedReadyEvent : {
724 aGraphEvent = SUPERV::StopEvent ;
727 case GraphExecutor::ExecutingEvent : {
728 aGraphEvent = SUPERV::RunningEvent ;
731 case GraphExecutor::SuspendedExecutingEvent : {
732 aGraphEvent = SUPERV::SuspendEvent ;
735 case GraphExecutor::ResumedExecutingEvent : {
736 aGraphEvent = SUPERV::ResumeEvent ;
739 case GraphExecutor::KilledExecutingEvent : {
740 aGraphEvent = SUPERV::KillEvent ;
743 case GraphExecutor::StoppedExecutingEvent : {
744 aGraphEvent = SUPERV::StopEvent ;
747 case GraphExecutor::SuccessedExecutingEvent : {
748 aGraphEvent = SUPERV::DoneEvent ;
751 case GraphExecutor::ErroredExecutingEvent : {
752 aGraphEvent = SUPERV:: ErroredEvent;
755 case GraphExecutor::SuspendedSuccessedEvent : {
756 aGraphEvent = SUPERV::SuspendEvent ;
759 case GraphExecutor::SuspendedErroredEvent : {
760 aGraphEvent = SUPERV::SuspendEvent ;
763 case GraphExecutor::ResumedSuccessedEvent : {
764 aGraphEvent = SUPERV::ResumeEvent ;
767 case GraphExecutor::ResumedErroredEvent : {
768 aGraphEvent = SUPERV::ResumeEvent ;
771 case GraphExecutor::KilledEvent : {
772 aGraphEvent = SUPERV::KillEvent ;
775 case GraphExecutor::StoppedEvent : {
776 aGraphEvent = SUPERV::StopEvent ;
779 case GraphExecutor::ReStartedEvent : {
780 aGraphEvent = SUPERV::ReRunEvent ;
783 case GraphExecutor::ReStartedAndSuspendEvent : {
784 aGraphEvent = SUPERV::ReStartEvent ;
787 case GraphExecutor::EndExecuteEvent : {
788 aGraphEvent = SUPERV::DoneEvent ;
792 cdebug << " GraphExecutor::OutNode::AutomatonGraphEvent Error Undefined Event : "
794 aGraphEvent = SUPERV::UndefinedEvent ;
800 SUPERV::GraphState GraphExecutor::OutNode::AutomatonGraphState(SUPERV::AutomatonState aState ) {
801 SUPERV::GraphState aGraphState ;
803 case SUPERV::UnKnownState : {
804 aGraphState = SUPERV::UndefinedState ;
807 case SUPERV::DataUndefState : {
808 aGraphState = SUPERV::UndefinedState ;
811 case SUPERV::DataWaitingState : {
812 aGraphState = SUPERV::WaitingState ;
815 case SUPERV::DataReadyState : {
816 aGraphState = SUPERV::ReadyState ;
819 case SUPERV::SuspendedReadyState : {
820 aGraphState = SUPERV::SuspendReadyState ;
823 case SUPERV::ResumedReadyState : {
824 aGraphState = SUPERV::ReadyState ;
827 case SUPERV::KilledReadyState : {
828 aGraphState = SUPERV::KillState ;
831 case SUPERV::StoppedReadyState : {
832 aGraphState = SUPERV::StopState ;
835 case SUPERV::ExecutingState : {
836 aGraphState = SUPERV::RunningState ;
839 case SUPERV::SuspendedExecutingState : {
840 aGraphState = SUPERV::SuspendState ;
843 case SUPERV::ResumedExecutingState : {
844 aGraphState = SUPERV::RunningState ;
847 case SUPERV::KilledExecutingState : {
848 aGraphState = SUPERV::KillState ;
851 case SUPERV::StoppedExecutingState : {
852 aGraphState = SUPERV::StopState ;
855 case SUPERV::SuccessedExecutingState : {
856 aGraphState = SUPERV::DoneState ;
859 case SUPERV::ErroredExecutingState : {
860 aGraphState = SUPERV::ErrorState ;
863 case SUPERV::SuspendedSuccessedState : {
864 aGraphState = SUPERV::SuspendDoneState ;
867 case SUPERV::SuspendedErroredState : {
868 aGraphState = SUPERV::SuspendErroredState ;
871 case SUPERV::ResumedSuccessedState : {
872 aGraphState = SUPERV::DoneState ;
875 case SUPERV::ResumedErroredState : {
876 aGraphState = SUPERV::ErrorState ;
879 case SUPERV::KilledSuccessedState : {
880 aGraphState = SUPERV::KillState ;
883 case SUPERV::KilledErroredState : {
884 aGraphState = SUPERV::KillState ;
887 case SUPERV::StoppedSuccessedState : {
888 aGraphState = SUPERV::StopState ;
891 case SUPERV::StoppedErroredState : {
892 aGraphState = SUPERV::StopState ;
895 case SUPERV::SuccessedState : {
896 aGraphState = SUPERV::DoneState ;
899 case SUPERV::ErroredState : {
900 aGraphState = SUPERV::ErrorState ;
903 case SUPERV::SuspendedState : {
904 aGraphState = SUPERV::SuspendState ;
907 case SUPERV::KilledState : {
908 aGraphState = SUPERV::KillState ;
911 case SUPERV::StoppedState : {
912 aGraphState = SUPERV::StopState ;
915 case SUPERV::ReRunnedState : {
916 aGraphState = SUPERV::ReRunState ;
919 case SUPERV::ReStartedState : {
920 aGraphState = SUPERV::ReStartState ;
924 cdebug << " GraphExecutor::OutNode::AutomatonGraphState Error Undefined State : "
925 << aGraphState << endl ;
926 aGraphState = SUPERV::UndefinedState ;
932 bool GraphExecutor::OutNode::PushEvent( GraphExecutor::InNode * aNode ,
933 GraphExecutor::NodeEvent anEvent ,
934 SUPERV::AutomatonState aState ) {
935 cdebug_in << "PushEvent Threads " << Threads() << " SuspendedThreads "
936 << SuspendedThreads() << endl ;
937 if ( pthread_mutex_lock( &_MutexWait ) ) {
938 perror("PushEvent pthread_mutex_lock ") ;
942 _EventNodes.push_back( aNode->Name() ) ;
945 _EventNodes.push_back( Name() ) ;
947 _Events.push_back( anEvent ) ;
948 _States.push_back( aState ) ;
949 pthread_cond_broadcast( &_EventWait );
951 cdebug << aNode->ThreadNo() << " PushEvent " << aNode->Name() ;
952 cdebug << " " << aNode->Automaton()->EventName( anEvent )
953 << " " << aNode->Automaton()->StateName( aState )
955 << aNode->Automaton()->ControlStateName( aNode->ControlState() ) ;
958 cdebug << "PushEvent " << Name() ;
959 cdebug << " " << theAutomaton->EventName( anEvent ) << " "
960 << theAutomaton->StateName( aState ) ;
962 cdebug_out << "PushEvent Threads " << Threads() << " SuspendedThreads "
963 << SuspendedThreads() << endl ;
964 if ( pthread_mutex_unlock( &_MutexWait ) ) {
965 perror("PushEvent pthread_mutex_unlock ") ;
970 bool GraphExecutor::OutNode::StateWait( SUPERV::GraphState aState ) {
973 bool GraphExecutor::OutNode::Event( char ** aNodeName ,
974 SUPERV::GraphEvent & anEvent ,
975 SUPERV::GraphState & aState ,
978 int SuspendedThreadsNumber ;
979 if ( pthread_mutex_lock( &_MutexWait ) ) {
980 perror("EventLoop pthread_mutex_lock ") ;
983 _JustStarted = false ;
984 ThreadsNumber = Threads() ;
985 SuspendedThreadsNumber = SuspendedThreads() ;
986 bool RetVal = ( ThreadsNumber - SuspendedThreadsNumber) != 0 ||
987 _EventNodes.size() > 0 ;
988 char * NodeName = "" ;
989 GraphExecutor::NodeEvent theEvent = GraphExecutor::UndefinedEvent ;
990 SUPERV::AutomatonState theState = SUPERV::UnKnownState ;
991 anEvent = SUPERV::UndefinedEvent ;
992 aState = SUPERV::UndefinedState ;
993 if ( ( IsDone() || IsKilled() || IsStopped() ) && _EventNodes.size() == 0 ) {
994 cdebug << "EventLoop IsDone()/IsKilled()/IsStopped() && _EventNodes.size() == 0" << endl ;
997 else if ( !WithWait && _EventNodes.size() == 0 ) {
998 anEvent = SUPERV::NoEvent ;
999 aState = SUPERV::NoState ;
1002 else if ( RetVal ) {
1003 while ( !IsSuspended() && _EventNodes.size() == 0 ) {
1004 cdebug << "EventLoop pthread_cond_wait _EventWait" << endl ;
1005 pthread_cond_wait( &_EventWait , &_MutexWait );
1006 cdebug << "EventLoop pthread_cond_waited _EventWait"
1007 << " _EventNodes.size() " << _EventNodes.size() << endl ;
1009 if ( _EventNodes.size() ) {
1010 ThreadsNumber = Threads() ;
1011 NodeName = _EventNodes.front() ;
1012 _EventNodes.pop_front() ;
1013 theEvent = _Events.front() ;
1014 anEvent = AutomatonGraphEvent( theEvent ) ;
1015 _Events.pop_front() ;
1016 theState = _States.front() ;
1017 aState = AutomatonGraphState( theState ) ;
1018 _States.pop_front() ;
1021 *aNodeName = NodeName ;
1022 if ( IsSuspended() && _EventNodes.size() == 0 ) {
1025 if ( anEvent != SUPERV::NoEvent ) {
1026 cdebug << pthread_self() << "EventLoop "
1027 << NodeName << " " << theAutomaton->StateName( theState )
1028 << " _EventNodes.size() " << _EventNodes.size()
1029 << " Threads " << Threads() << " SuspendedThreads "
1030 << SuspendedThreads() << " RetVal " << RetVal << endl ;
1032 if ( pthread_mutex_unlock( &_MutexWait ) ) {
1033 perror("EventLoop pthread_mutex_lock ") ;
1039 bool GraphExecutor::OutNode::EventW( char ** aNodeName ,
1040 SUPERV::GraphEvent & anEvent ,
1041 SUPERV::GraphState & aState ) {
1044 aState = SUPERV::UndefinedState ;
1046 aState != SUPERV::SuspendReadyState &&
1047 aState != SUPERV::RunningState &&
1048 aState != SUPERV::SuspendDoneState &&
1049 aState != SUPERV::SuspendErroredState ) {
1051 while ( sts && !strcmp( NodeName , Name() ) ) {
1052 sts = EventWait( aNodeName , anEvent , aState ) ;
1053 NodeName = *aNodeName ;
1059 bool GraphExecutor::OutNode::EventWait( char ** aNodeName ,
1060 SUPERV::GraphEvent & anEvent ,
1061 SUPERV::GraphState & aState ) {
1062 if ( pthread_mutex_lock( &_MutexWait ) ) {
1063 perror("EventW pthread_mutex_lock ") ;
1067 int SuspendedThreadsNumber ;
1068 ThreadsNumber = Threads() ;
1069 SuspendedThreadsNumber = SuspendedThreads() ;
1070 bool RetVal = ( ThreadsNumber - SuspendedThreadsNumber) != 0 ||
1071 _EventNodes.size() > 0 ;
1072 cdebug << "--> EventW RetVal " << RetVal << endl ;
1073 char * NodeName = "" ;
1074 GraphExecutor::NodeEvent theEvent = GraphExecutor::UndefinedEvent ;
1075 SUPERV::AutomatonState theState = SUPERV::UnKnownState ;
1076 anEvent = SUPERV::UndefinedEvent ;
1077 aState = SUPERV::UndefinedState ;
1078 if ( IsDone() && _EventNodes.size() == 0 ) {
1079 cdebug << "EventW IsDone() && _EventNodes.size() == 0" << endl ;
1082 else if ( RetVal ) {
1083 GraphExecutor::InNode * aNode = NULL ;
1084 while ( aNode == NULL && RetVal ) {
1085 NodeName = _EventNodes.front() ;
1086 theEvent = _Events.front() ;
1087 anEvent = AutomatonGraphEvent( theEvent ) ;
1088 theState = _States.front() ;
1089 aState = AutomatonGraphState( theState ) ;
1091 if ( _JustStarted ) {
1092 _JustStarted = false ;
1095 _EventNodes.pop_front() ;
1096 _Events.pop_front() ;
1097 _States.pop_front() ;
1100 aNode = ((GraphExecutor::InNode *) GetGraphNode( NodeName )->GetInNode()) ;
1101 cdebug << "EventW Previous Node " << NodeName << " ThreadsNumber "
1103 << " _EventNodes.size() " << _EventNodes.size() << " "
1104 << theAutomaton->StateName( theState )
1105 << " Threads " << Threads() << " SuspendedThreads "
1106 << SuspendedThreads() << endl ;
1109 else if ( IsDone() && _EventNodes.size() == 0 ) {
1110 cdebug << "EventW IsDone() && _EventNodes.size() == 0" << endl ;
1114 cdebug << "EventW Not InNode " << NodeName
1115 << " _EventNodes.size() " << _EventNodes.size() << endl ;
1116 while ( _EventNodes.size() == 0 ) {
1117 pthread_cond_wait( &_EventWait , &_MutexWait );
1119 cdebug << "EventW pthread_cond_waited Not InNode " << NodeName
1120 << " _EventNodes.size() " << _EventNodes.size() << endl ;
1125 if ( aState == SUPERV::SuspendState ||
1126 aState == SUPERV::SuspendReadyState ||
1127 aState == SUPERV::SuspendDoneState ||
1128 aState == SUPERV::SuspendErroredState ) {
1129 aNode->ControlState( SUPERV::ToSuspendState ) ;
1130 if ( aNode->IsSuspended() ) {
1131 if ( pthread_mutex_unlock( &_MutexWait ) ) {
1132 perror("EventW pthread_mutex_lock ") ;
1135 cdebug << "EventW " << aNode->Name() << " ResumeAction" << endl ;
1136 aNode->ResumeAction( GraphExecutor::ToResumeEvent ) ;
1137 cdebug << "EventW " << aNode->Name() << " ResumedAction" << endl ;
1138 if ( pthread_mutex_lock( &_MutexWait ) ) {
1139 perror("EventW pthread_mutex_lock ") ;
1144 cdebug << "EventW inconsistent SuspendState" << endl ;
1149 if ( aNode->IsDone() ) {
1153 cdebug << "EventW NOT SuspendedState _EventNodes.size() "
1154 << _EventNodes.size() << endl ;
1159 cdebug << "EventW " << aNode->Name() << " pthread_cond_wait" << endl ;
1160 while ( _EventNodes.size() == 0 ) {
1161 pthread_cond_wait( &_EventWait , &_MutexWait );
1163 ThreadsNumber = Threads() ;
1164 NodeName = _EventNodes.front() ;
1165 theEvent = _Events.front() ;
1166 anEvent = AutomatonGraphEvent( theEvent ) ;
1167 theState = _States.front() ;
1168 aState = AutomatonGraphState( theState ) ;
1172 *aNodeName = NodeName ;
1173 cdebug << "<-- EventW RetVal " << RetVal << " " << NodeName
1174 << " Threads " << Threads() << " SuspendedThreads "
1175 << SuspendedThreads()
1176 << " _EventNodes.size() " << _EventNodes.size()
1177 << " " << theAutomaton->EventName( theEvent ) << " "
1178 << theAutomaton->StateName( theState ) << endl ;
1179 if ( pthread_mutex_unlock( &_MutexWait ) ) {
1180 perror("EventW pthread_mutex_lock ") ;
1186 void GraphExecutor::OutNode::State(SUPERV::AutomatonState aState ) {
1190 SUPERV::GraphState GraphExecutor::OutNode::State() {
1191 // cdebug_in << "GraphExecutor::OutNode::State" << endl;
1192 // cdebug_out << "GraphExecutor::OutNode::State" << endl ;
1193 // cdebug << "GraphExecutor::OutNode::State GraphState "
1194 // << theAutomaton->StateName( AutomatonGraphState( _State ) ) << endl ;
1195 return AutomatonGraphState( _State ) ;
1198 SUPERV::GraphState GraphExecutor::OutNode::State( const char * NodeName ) {
1199 // cdebug_in << "GraphExecutor::OutNode::State " << NodeName << endl;
1200 SUPERV::AutomatonState aret = SUPERV::UnKnownState ;
1201 const GraphBase::ComputingNode * aCNode = GetGraphNode( NodeName ) ;
1203 GraphExecutor::InNode *anInNode = (GraphExecutor::InNode *)aCNode->GetInNode() ;
1205 aret = anInNode->State() ;
1206 cdebug << "GraphExecutor::OutNode::State( " << NodeName << " ) "
1207 << theAutomaton->StateName( AutomatonGraphState( aret ) ) << endl ;
1210 // cdebug_out << "GraphExecutor::OutNode::State" << endl ;
1211 return AutomatonGraphState( aret ) ;
1214 SUPERV::GraphState GraphExecutor::OutNode::State(
1215 const char * NodeName ,
1216 const char * ServiceParameterName ) {
1217 // cdebug_in << "GraphExecutor::OutNode::State " << NodeName << " "
1218 // << ServiceParameterName<< endl;
1219 SUPERV::GraphState aret =
1220 PortState( NodeName , ServiceParameterName ) ;
1221 // cdebug_out << "GraphExecutor::OutNode::State" << endl ;
1225 SUPERV::AutomatonState GraphExecutor::OutNode::AutomatonState() {
1226 // cdebug_in << "GraphExecutor::OutNode::AutomatonState" << endl;
1227 // cdebug_out << "GraphExecutor::OutNode::AutomatonState" << endl ;
1231 SUPERV::AutomatonState GraphExecutor::OutNode::AutomatonState( const char * NodeName ) {
1232 // cdebug_in << "GraphExecutor::OutNode::AutomatonState " << NodeName << endl;
1233 SUPERV::AutomatonState aret = SUPERV::UnKnownState ;
1234 GraphExecutor::InNode *anInNode = (GraphExecutor::InNode *) GetGraphNode( NodeName )->GetInNode() ;
1236 aret = anInNode->State() ;
1237 // cdebug_out << "GraphExecutor::OutNode::AutomatonState" << endl ;
1241 SUPERV::ControlState GraphExecutor::OutNode::ControlState() {
1242 // cdebug_in << "GraphExecutor::OutNode::ControlState" << endl;
1243 // cdebug_out << "GraphExecutor::OutNode::ControlState" << endl ;
1244 return _ControlState ;
1247 SUPERV::ControlState GraphExecutor::OutNode::ControlState( const char * NodeName ) {
1248 // cdebug_in << "GraphExecutor::OutNode::ControlState " << NodeName << endl;
1249 SUPERV::ControlState aret = SUPERV::VoidState ;
1250 GraphExecutor::InNode *anInNode = (GraphExecutor::InNode *) GetGraphNode( NodeName )->GetInNode() ;
1252 aret = anInNode->ControlState() ;
1253 // cdebug_out << "GraphExecutor::OutNode::ControlState" << endl ;
1257 void GraphExecutor::OutNode::ControlClear() {
1258 // cdebug_in << "GraphExecutor::OutNode::ControlClear" << endl;
1259 // cdebug_out << "GraphExecutor::OutNode::ControlClear" << endl ;
1260 _ControlState = SUPERV::VoidState;
1263 void GraphExecutor::OutNode::ControlClear( const char * NodeName ) {
1264 // cdebug_in << "GraphExecutor::OutNode::ControlClear " << NodeName << endl;
1265 GraphExecutor::InNode *anInNode = (GraphExecutor::InNode *) GetGraphNode( NodeName )->GetInNode() ;
1267 anInNode->ControlClear() ;
1268 // cdebug_out << "GraphExecutor::OutNode::ControlClear" << endl ;
1271 bool GraphExecutor::OutNode::IsWaiting() {
1272 // cdebug_in << "GraphExecutor::OutNode::IsWaiting" << endl;
1273 // cdebug_out << "GraphExecutor::OutNode::IsWaiting" << endl ;
1277 bool GraphExecutor::OutNode::IsReady() {
1278 // cdebug_in << "GraphExecutor::OutNode::IsReady" << endl;
1279 // cdebug_out << "GraphExecutor::OutNode::IsReady" << endl ;
1283 bool GraphExecutor::OutNode::IsRunning() {
1284 // cdebug_in << "GraphExecutor::OutNode::IsRunning" << endl;
1285 // cdebug_out << "GraphExecutor::OutNode::IsRunning" << endl ;
1289 bool GraphExecutor::OutNode::IsDone() {
1290 // cdebug_in << "GraphExecutor::OutNode::IsDone" << endl;
1291 // cdebug_out << "GraphExecutor::OutNode::IsDone" << endl ;
1292 return ( _Done || IsKilled() || IsStopped() ) ;
1295 bool GraphExecutor::OutNode::IsSuspended() {
1296 // cdebug_in << "GraphExecutor::OutNode::IsSuspended" << endl;
1298 if ( _SuspendedThreads == _Threads ) {
1301 // cdebug_out << "GraphExecutor::OutNode::IsSuspended" << endl ;
1305 bool GraphExecutor::OutNode::IsKilled() {
1306 // cdebug_in << "GraphExecutor::OutNode::IsKilled" << endl;
1308 if ( AutomatonGraphState( _State ) == SUPERV::KillState ) {
1311 // cdebug_out << "GraphExecutor::OutNode::IsKilled" << endl ;
1315 bool GraphExecutor::OutNode::IsStopped() {
1316 // cdebug_in << "GraphExecutor::OutNode::IsStopped" << endl;
1318 if ( AutomatonGraphState( _State ) == SUPERV::StopState ) {
1321 // cdebug_out << "GraphExecutor::OutNode::IsStopped" << endl ;
1325 bool GraphExecutor::OutNode::IsWaiting( const char * NodeName ) {
1327 // cdebug_in << "GraphExecutor::OutNode::IsWaiting " << NodeName << endl;
1328 GraphExecutor::InNode *anInNode = (GraphExecutor::InNode *) GetGraphNode( NodeName )->GetInNode() ;
1330 aret = anInNode->IsWaiting() ;
1332 // cdebug_out << "GraphExecutor::OutNode::IsWaiting" << endl ;
1336 bool GraphExecutor::OutNode::IsReady( const char * NodeName ) {
1338 // cdebug_in << "GraphExecutor::OutNode::IsReady " << NodeName << endl;
1339 GraphExecutor::InNode *anInNode = (GraphExecutor::InNode *) GetGraphNode( NodeName )->GetInNode() ;
1341 aret = anInNode->IsReady() ;
1343 // cdebug_out << "GraphExecutor::OutNode::IsReady" << endl ;
1347 bool GraphExecutor::OutNode::IsRunning( const char * NodeName ) {
1349 // cdebug_in << "GraphExecutor::OutNode::IsRunning " << NodeName << endl;
1350 GraphExecutor::InNode *anInNode = (GraphExecutor::InNode *) GetGraphNode( NodeName )->GetInNode() ;
1352 aret = anInNode->IsRunning() ;
1354 // cdebug_out << "GraphExecutor::OutNode::IsRunning" << endl ;
1358 bool GraphExecutor::OutNode::IsDone( const char * NodeName ) {
1360 // cdebug_in << "GraphExecutor::OutNode::IsDone " << NodeName << endl;
1361 GraphExecutor::InNode *anInNode = (GraphExecutor::InNode *) GetGraphNode( NodeName )->GetInNode() ;
1363 aret = anInNode->IsDone() ;
1365 // cdebug_out << "GraphExecutor::OutNode::IsDone" << endl ;
1369 bool GraphExecutor::OutNode::IsSuspended( const char * NodeName ) {
1371 // cdebug_in << "GraphExecutor::OutNode::IsSuspended " << NodeName << endl;
1372 GraphExecutor::InNode *anInNode = (GraphExecutor::InNode *) GetGraphNode( NodeName )->GetInNode() ;
1374 aret = anInNode->IsSuspended() ;
1376 // cdebug_out << "GraphExecutor::OutNode::IsSuspended" << endl ;
1380 bool GraphExecutor::OutNode::IsDone( const char * NodeName ,
1381 const char * ServiceParameterName ) {
1382 // cdebug_in << "GraphExecutor::OutNode::IsDone " << NodeName << " "
1383 // << ServiceParameterName<< endl;
1384 bool aret = PortDone( NodeName , ServiceParameterName ) ;
1385 // cdebug_out << "GraphExecutor::OutNode::IsDone" << endl ;
1389 bool GraphExecutor::OutNode::ContainerKill() {
1390 bool RetVal = true ;
1391 cdebug_in << "GraphExecutor::OutNode::ContainerKill" << endl;
1392 _ControlState = SUPERV::ToSuspendState ;
1394 for ( i = 0 ; i < GraphNodesSize() ; i++ ) {
1395 GraphExecutor::InNode * aNode = (GraphExecutor::InNode * ) GraphNodes( i )->GetInNode() ;
1396 bool sts = aNode->ContainerKill() ;
1397 if ( sts && aNode->IsKilled() ) {
1398 cdebug << aNode->Name() << " killed" << endl ;
1400 else if ( aNode->IsWaiting() || aNode->IsDone() ) {
1401 cdebug << aNode->Name() << " not killed : "
1402 << theAutomaton->StateName( aNode->State() ) << endl ;
1405 cdebug << aNode->Name() << " cannot be killed : "
1406 << theAutomaton->StateName( aNode->State() ) << endl ;
1410 if ( !RetVal || Threads() != 0 ) {
1411 for ( i = 0 ; i < GraphNodesSize() ; i++ ) {
1412 GraphExecutor::InNode * aNode = (GraphExecutor::InNode * ) GraphNodes( i )->GetInNode() ;
1413 if ( !aNode->IsKilled() && !aNode->IsWaiting() && !aNode->IsDone() ) {
1414 aNode->KilledAction() ;
1419 State( SUPERV::KilledState ) ;
1420 cdebug_out << "GraphExecutor::OutNode::ContainerKill" << endl ;
1424 bool GraphExecutor::OutNode::Suspend() {
1425 bool RetVal = false ;
1426 cdebug_in << "GraphExecutor::OutNode::Suspend" << endl;
1427 _ControlState = SUPERV::ToSuspendState ;
1429 for ( i = 0 ; i < GraphNodesSize() ; i++ ) {
1430 GraphExecutor::InNode * aNode = (GraphExecutor::InNode * ) GraphNodes( i )->GetInNode() ;
1431 bool sts = aNode->Suspend() ;
1432 if ( sts && aNode->IsSuspended() ) {
1433 cdebug << aNode->Name() << " Suspend" << endl ;
1435 else if ( aNode->IsWaiting() || aNode->IsDone() ) {
1436 cdebug << aNode->Name() << " not Suspended : "
1437 << theAutomaton->StateName( aNode->State() ) << endl ;
1440 cdebug << aNode->Name() << " cannot be Suspended : "
1441 << theAutomaton->StateName( aNode->State() ) << endl ;
1445 State( SUPERV::SuspendedState ) ;
1446 cdebug_out << "GraphExecutor::OutNode::Suspend" << endl ;
1449 bool GraphExecutor::OutNode::Resume() {
1450 bool RetVal = false ;
1451 cdebug_in << "GraphExecutor::OutNode::Resume" << endl;
1452 cdebug_out << "GraphExecutor::OutNode::Resume" << endl ;
1456 bool GraphExecutor::OutNode::Kill() {
1457 bool RetVal = true ;
1458 cdebug_in << "GraphExecutor::OutNode::Kill" << endl;
1459 _ControlState = SUPERV::ToSuspendState ;
1461 for ( i = 0 ; i < GraphNodesSize() ; i++ ) {
1462 GraphExecutor::InNode * aNode = (GraphExecutor::InNode * ) GraphNodes( i )->GetInNode() ;
1463 bool sts = aNode->Kill() ;
1464 if ( sts && aNode->IsKilled() ) {
1465 cdebug << aNode->Name() << " killed" << endl ;
1467 else if ( aNode->IsWaiting() || aNode->IsDone() ) {
1468 cdebug << aNode->Name() << " not killed : "
1469 << theAutomaton->StateName( aNode->State() ) << endl ;
1472 cdebug << aNode->Name() << " cannot be killed : "
1473 << theAutomaton->StateName( aNode->State() ) << endl ;
1477 if ( !RetVal || Threads() != 0 ) {
1478 for ( i = 0 ; i < GraphNodesSize() ; i++ ) {
1479 GraphExecutor::InNode * aNode = (GraphExecutor::InNode * ) GraphNodes( i )->GetInNode() ;
1480 if ( !aNode->IsKilled() && !aNode->IsWaiting() && !aNode->IsDone() ) {
1481 aNode->KilledAction() ;
1486 State( SUPERV::KilledState ) ;
1487 cdebug_out << "GraphExecutor::OutNode::Kill" << endl ;
1491 bool GraphExecutor::OutNode::Stop() {
1492 bool RetVal = false ;
1493 cdebug_in << "GraphExecutor::OutNode::Stop" << endl;
1495 cdebug_out << "GraphExecutor::OutNode::Stop" << endl ;
1498 bool GraphExecutor::OutNode::ReRun() {
1499 bool RetVal = false ;
1500 cdebug_in << "GraphExecutor::OutNode::ReRun" << endl;
1501 if ( IsSuspended() ) {
1503 cdebug_out << "GraphExecutor::OutNode::ReRun" << endl ;
1506 bool GraphExecutor::OutNode::ReStart() {
1507 bool RetVal = false ;
1508 cdebug_in << "GraphExecutor::OutNode::ReStart" << endl;
1509 if ( IsSuspended() ) {
1511 cdebug_out << "GraphExecutor::OutNode::ReStart" << endl ;
1515 bool GraphExecutor::OutNode::ReadyWait() {
1516 cdebug_in << "GraphExecutor::OutNode::ReadyWait" << endl;
1518 if ( pthread_mutex_lock( &_MutexWait ) ) {
1519 perror("pthread_mutex_lock _ReadyWait") ;
1525 pthread_cond_wait( &_EventWait , &_MutexWait );
1528 if ( pthread_mutex_unlock( &_MutexWait ) ) {
1529 perror("pthread_mutex_lock _ReadyWait") ;
1532 cdebug_out << "GraphExecutor::OutNode::ReadyWait" << endl ;
1536 bool GraphExecutor::OutNode::RunningWait() {
1537 cdebug_in << "GraphExecutor::OutNode::RunningWait" << endl;
1539 if ( pthread_mutex_lock( &_MutexWait ) ) {
1540 perror("pthread_mutex_lock _RunningWait") ;
1543 aret = IsRunning() ;
1545 cdebug << "RunningWait pthread_cond_wait _EventWait" << endl;
1546 pthread_cond_wait( &_EventWait , &_MutexWait );
1547 aret = IsRunning() ;
1548 cdebug << "RunningWait pthread_cond_waited _EventWait " << aret << endl;
1550 if ( pthread_mutex_unlock( &_MutexWait ) ) {
1551 perror("pthread_mutex_lock _RunningWait") ;
1554 cdebug_out << "GraphExecutor::OutNode::RunningWait " << aret << endl ;
1558 bool GraphExecutor::OutNode::DoneWait() {
1559 cdebug_in << "GraphExecutor::OutNode::DoneWait" << endl;
1561 if ( pthread_mutex_lock( &_MutexWait ) ) {
1562 perror("pthread_mutex_lock _DoneWait") ;
1566 while ( !aret && !IsSuspended() ) {
1567 cdebug << "DoneWait pthread_cond_wait _EventWait" << endl;
1568 pthread_cond_wait( &_EventWait , &_MutexWait );
1570 cdebug << "DoneWait pthread_cond_waited _EventWait " << aret << endl;
1572 if ( pthread_mutex_unlock( &_MutexWait ) ) {
1573 perror("pthread_mutex_lock _DoneWait") ;
1576 cdebug_out << "GraphExecutor::OutNode::DoneWait " << aret << endl ;
1580 bool GraphExecutor::OutNode::SuspendedWait() {
1581 cdebug_in << "GraphExecutor::OutNode::SuspendedWait" << endl;
1583 if ( pthread_mutex_lock( &_MutexWait ) ) {
1584 perror("pthread_mutex_lock _SuspendedWait") ;
1587 aret = IsSuspended() ;
1588 while ( !aret && !_Done ) {
1589 pthread_cond_wait( &_EventWait , &_MutexWait );
1590 aret = IsSuspended() ;
1592 if ( pthread_mutex_unlock( &_MutexWait ) ) {
1593 perror("pthread_mutex_lock _SuspendedWait") ;
1596 cdebug_out << "GraphExecutor::OutNode::SuspendedWait" << endl ;
1600 bool GraphExecutor::OutNode::ReadyWait( const char * NodeName ) {
1602 cdebug_in << "GraphExecutor::OutNode::ReadyWait " << NodeName << endl;
1603 GraphExecutor::InNode *anInNode = (GraphExecutor::InNode *) GetGraphNode( NodeName )->GetInNode() ;
1605 aret = anInNode->ReadyWait() ;
1607 cdebug_out << "GraphExecutor::OutNode::ReadyWait" << endl ;
1611 bool GraphExecutor::OutNode::RunningWait( const char * NodeName ) {
1613 cdebug_in << "GraphExecutor::OutNode::RunningWait " << NodeName << endl;
1614 GraphExecutor::InNode *anInNode = (GraphExecutor::InNode *) GetGraphNode( NodeName )->GetInNode() ;
1616 aret = anInNode->RunningWait() ;
1618 cdebug_out << "GraphExecutor::OutNode::RunningWait" << endl ;
1622 bool GraphExecutor::OutNode::DoneWait( const char * NodeName ) {
1624 cdebug_in << "GraphExecutor::OutNode::DoneWait " << NodeName << endl;
1625 GraphExecutor::InNode *anInNode = (GraphExecutor::InNode *) GetGraphNode( NodeName )->GetInNode() ;
1627 aret = anInNode->DoneWait() ;
1629 cdebug_out << "GraphExecutor::OutNode::DoneWait" << endl ;
1633 bool GraphExecutor::OutNode::SuspendedWait( const char * NodeName ) {
1635 cdebug_in << "GraphExecutor::OutNode::SuspendedWait " << NodeName << endl;
1636 GraphExecutor::InNode *anInNode = (GraphExecutor::InNode *) GetGraphNode( NodeName )->GetInNode() ;
1638 aret = anInNode->SuspendedWait() ;
1640 cdebug_out << "GraphExecutor::OutNode::SuspendedWait" << endl ;
1644 long GraphExecutor::OutNode::LastLevelDone() {
1647 for ( i = 0 ; i <= LevelMax() ; i++ ) {
1648 for ( j = 0 ; j <= NodesNumber( i ) ; j++ ) {
1649 GraphBase::ComputingNode * aNode = SortedNodes( i , j ) ;
1650 if ( !IsDone( aNode->Name() ) ) {
1654 if ( j != NodesNumber( i ) + 1 )
1662 const CORBA::Any *GraphExecutor::OutNode::GetInData(
1663 const char * NodeName ,
1664 const char * ServiceParameterName ) {
1665 cdebug_in << "GraphExecutor::OutNode::GetInData " << NodeName << " "
1666 << ServiceParameterName << endl ;
1667 const CORBA::Any * retdata = PortInData( NodeName , ServiceParameterName ) ;
1668 cdebug_out << "GraphExecutor::OutNode::GetInData" << endl ;
1672 const CORBA::Any *GraphExecutor::OutNode::GetOutData(
1673 const char * NodeName ,
1674 const char * ServiceParameterName ) {
1675 cdebug_in << "GraphExecutor::OutNode::GetData " << NodeName << " "
1676 << ServiceParameterName << endl ;
1677 const CORBA::Any * retdata = PortOutData( NodeName , ServiceParameterName ) ;
1678 cdebug_out << "GraphExecutor::OutNode::GetOutData" << endl ;