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" ;
19 extern char ** _ArgV ;
21 GraphExecutor::OutNode::OutNode() :
27 _ControlState = SUPERV::VoidState ;
28 _State = SUPERV::UnKnownState ;
29 _PyInitialized = false ;
30 pthread_mutex_init( &_MutexWait , NULL ) ;
31 if ( pthread_cond_init( &_EventWait , NULL ) ) {
32 perror("pthread_cond_init( &_EventWait , NULL )") ;
35 if ( pthread_cond_init( &_JoinWait , NULL ) ) {
36 perror("pthread_cond_init( &_JoinWait , NULL )") ;
41 GraphExecutor::OutNode::OutNode( CORBA::ORB_ptr ORB,
42 SALOME_NamingService* ptrNamingService ,
43 const char *DataFlowName ,
44 const char * DebugFileName ) :
45 Graph( ORB , ptrNamingService , DataFlowName , DebugFileName ) {
46 cdebug_in << "GraphEditor::OutNode::OutNode(" << DataFlowName << ")" << endl;
51 _ControlState = SUPERV::VoidState ;
52 _State = SUPERV::UnKnownState ;
53 _PyInitialized = false ;
54 _Orb = CORBA::ORB::_duplicate( ORB ) ;
55 pthread_mutex_init( &_MutexWait , NULL ) ;
56 if ( pthread_cond_init( &_EventWait , NULL ) ) {
57 perror("pthread_cond_init( &_EventWait , NULL )") ;
60 if ( pthread_cond_init( &_JoinWait , NULL ) ) {
61 perror("pthread_cond_init( &_JoinWait , NULL )") ;
64 cdebug_out << "GraphEditor::OutNode::OutNode" << endl;
67 GraphExecutor::OutNode::OutNode(
69 SALOME_NamingService* ptrNamingService ,
70 const SALOME_ModuleCatalog::Service& DataFlowService ,
71 const char *DataFlowComponentName ,
72 const char *DataFlowInterfaceName ,
73 const char *DataFlowName ,
74 const SUPERV::KindOfNode DataFlowkind ,
75 const SUPERV::SDate DataFlowFirstCreation ,
76 const SUPERV::SDate DataFlowLastModification ,
77 const char * DataFlowEditorRelease ,
78 const char * DataFlowAuthor ,
79 const char * DataFlowComputer ,
80 const char * DataFlowComment ,
81 const char * DebugFileName ) :
82 Graph( ORB , ptrNamingService , DataFlowService , DataFlowComponentName ,
83 DataFlowInterfaceName , DataFlowName , DataFlowkind ,
84 DataFlowFirstCreation , DataFlowLastModification ,
85 DataFlowEditorRelease , DataFlowAuthor ,
86 DataFlowComputer , DataFlowComment , DebugFileName ) {
91 _ControlState = SUPERV::VoidState ;
92 _State = SUPERV::UnKnownState ;
93 _PyInitialized = false ;
94 _Orb = CORBA::ORB::_duplicate( ORB ) ;
95 pthread_mutex_init( &_MutexWait , NULL ) ;
96 if ( pthread_cond_init( &_EventWait , NULL ) ) {
97 perror("pthread_cond_init( &_EventWait , NULL )") ;
100 if ( pthread_cond_init( &_JoinWait , NULL ) ) {
101 perror("pthread_cond_init( &_JoinWait , NULL )") ;
106 GraphExecutor::OutNode::~OutNode() {
109 bool GraphExecutor::OutNode::LoadDataFlow(const GraphBase::SGraph &aDataFlow ) {
110 bool RetVal = false ;
111 RetVal = LoadInfo( aDataFlow.Info ) ;
112 if ( GraphBase::Service::ServiceName() != NULL ) {
113 // MESSAGE( "GraphExecutor::OutNode::LoadDataFlow" );
115 RetVal = LoadNodes( aDataFlow.Nodes ) ;
117 RetVal = LoadLinks( aDataFlow.Links ) ;
120 RetVal = LoadDatas( aDataFlow.Datas ) ;
123 cdebug << "GraphExecutor::OutNode::LoadDataFlow LoadDatas Error."
128 cdebug << "GraphExecutor::OutNode::LoadDataFlow LoadLinks Error."
133 cdebug << "GraphExecutor::OutNode::LoadDataFlow LoadNodes Error."
138 cdebug << "GraphExecutor::OutNode::LoadDataFlow LoadInfo Error."
143 cdebug << "GraphExecutor::OutNode::LoadDataFlow ServiceName Error." << endl ;
148 bool GraphExecutor::OutNode::LoadXml( const char* myFileName ) {
149 bool RetVal = false ;
150 GraphBase::SGraph aDataFlow ;
151 if ( GraphBase::Graph::LoadXml( _Orb , myFileName , aDataFlow ) ) {
152 RetVal = LoadDataFlow( aDataFlow ) ;
153 // if ( aConstructor && RetVal )
154 // RetVal = Name( aDataFlow.Info.theName.c_str() ) ;
159 bool GraphExecutor::OutNode::LoadInfo(const GraphBase::SNode &aDataFlowInfo ) {
160 cdebug << "GraphExecutor::OutNode::LoadInfo" << endl ;
161 // ComponentName( aDataFlowInfo.theComponentName.c_str() ) ;
162 Name( aDataFlowInfo.theName.c_str() ) ;
163 Kind( aDataFlowInfo.theKind ) ;
164 DataService( _Orb , aDataFlowInfo.theService , Graph_prof_debug() , Graph_fdebug() ) ;
165 FirstCreation( aDataFlowInfo.theFirstCreation ) ;
166 LastModification( aDataFlowInfo.theLastModification ) ;
167 EditorRelease( aDataFlowInfo.theEditorRelease.c_str() ) ;
168 Author( aDataFlowInfo.theAuthor.c_str() ) ;
169 // Computer( aDataFlowInfo.theContainer.c_str() ) ;
170 Comment( aDataFlowInfo.theComment.c_str() ) ;
171 // Not in OutNode/DataFlow but in InNode/DataFlow_in_an_other_DataFlow
172 // Coordinates( aDataFlowInfo.theX , aDataFlowInfo.theY ) ;
176 bool GraphExecutor::OutNode::LoadNodes(const GraphBase::ListOfNodes &aListOfNodes ) {
178 GraphExecutor::InNode * anInNode ;
179 cdebug << "GraphExecutor::OutNode::LoadNodes" << endl ;
181 for ( i = 0 ; i < aListOfNodes.size() ; i++ ) {
182 GraphBase::SNode aNode = aListOfNodes[ i ] ;
183 anInNode = AddNode( aNode.theService ,
184 aNode.theListOfFuncName ,
185 aNode.theListOfPythonFunctions ,
186 aNode.theComponentName.c_str() ,
187 aNode.theInterfaceName.c_str() , aNode.theName.c_str() ,
189 aNode.theFirstCreation , aNode.theLastModification ,
190 aNode.theEditorRelease.c_str() ,
191 aNode.theAuthor.c_str() , aNode.theContainer.c_str() ,
192 aNode.theComment.c_str() ,
193 aNode.theCoords.theX , aNode.theCoords.theY ) ;
198 if ( anInNode->IsOneOfInLineNodes() ) {
199 anInNode->GraphExecutor::InNode::InLineNode()->DefPortsOfNode(
200 _Orb , aNode.theService , anInNode->NamePtr() ,
202 Graph_prof_debug() , Graph_fdebug() ) ;
204 GraphBase::InLineNode * aINode = anInNode->InLineNode() ;
205 GraphBase::LoopNode * aLNode = NULL ;
206 if ( aINode->IsLoopNode() ) {
207 aLNode = anInNode->LoopNode() ;
208 aLNode->SetPythonFunction( aNode.theListOfFuncName[ 0 ].c_str() ,
209 *aNode.theListOfPythonFunctions[ 0 ] ) ;
210 aLNode->SetMorePythonFunction( aNode.theListOfFuncName[ 1 ].c_str() ,
211 *aNode.theListOfPythonFunctions[ 1 ] ) ;
212 aLNode->SetNextPythonFunction( aNode.theListOfFuncName[ 2 ].c_str() ,
213 *aNode.theListOfPythonFunctions[ 2 ] ) ;
215 else if ( aINode->IsInLineNode() || aINode->IsGOTONode() ||
216 aINode->IsSwitchNode() || aINode->IsEndSwitchNode() ) {
217 aINode->SetPythonFunction( aNode.theListOfFuncName[ 0 ].c_str() ,
218 *aNode.theListOfPythonFunctions[ 0 ] ) ;
223 if ( aNode.theListOfParameters.size() ) { // BusPorts ...
225 for ( j = 0 ; j < aNode.theListOfParameters.size() ; j++ ) {
226 GraphBase::InPort * InputPort = anInNode->AddInPort(
227 aNode.theListOfParameters[ j ].theInParameter.Parametername ,
228 aNode.theListOfParameters[ j ].theInParameter.Parametertype ) ;
229 GraphBase::OutPort * OutputPort = anInNode->AddOutPort(
230 aNode.theListOfParameters[ j ].theOutParameter.Parametername ,
231 aNode.theListOfParameters[ j ].theOutParameter.Parametertype ) ;
232 anInNode->InOutPort( InputPort , OutputPort ) ;
237 for ( i = 0 ; i < aListOfNodes.size() ; i++ ) {
238 GraphBase::SNode aNode = aListOfNodes[ i ] ;
239 anInNode = (GraphExecutor::InNode * ) GetChangeGraphNode( aNode.theName.c_str() )->GetInNode() ;
240 cdebug << "GraphExecutor::OutNode::LoadNodes " << anInNode->Name() << "IsOneOfGOTONodes "
241 << anInNode->IsOneOfGOTONodes() << " " << aNode.theCoupledNode.c_str() << endl ;
242 if ( anInNode->IsOneOfGOTONodes() && strlen( aNode.theCoupledNode.c_str() ) ) {
243 GraphBase::GOTONode * aCoupledNode ;
244 aCoupledNode = (GraphBase::GOTONode * ) GetGraphNode( aNode.theName.c_str() ) ;
245 aCoupledNode->CoupledNode( (GraphBase::GOTONode * ) GetChangeGraphNode( aNode.theCoupledNode.c_str() ) ) ;
251 bool GraphExecutor::OutNode::LoadLinks(const GraphBase::ListOfLinks &aListOfLinks ) {
253 cdebug << "GraphExecutor::OutNode::LoadLinks " << aListOfLinks.size()
256 for ( i = 0 ; i < aListOfLinks.size() ; i++ ) {
257 GraphBase::SLink aLink = aListOfLinks[ i ] ;
258 RetVal = AddLink( aLink.FromNodeName.c_str() ,
259 aLink.FromServiceParameterName.c_str() ,
260 aLink.ToNodeName.c_str() ,
261 aLink.ToServiceParameterName.c_str() ,
263 // aLink.aLinkValue.Value , aLink.aLinkValue.Kind ) ;
270 bool GraphExecutor::OutNode::LoadDatas(const GraphBase::ListOfLinks &aListOfDatas ) {
272 cdebug << "GraphExecutor::OutNode::LoadDatas " << aListOfDatas.size()
275 for ( i = 0 ; i < aListOfDatas.size() ; i++ ) {
276 GraphBase::SLink aLink = aListOfDatas[ i ] ;
277 if ( !strcmp( aLink.FromNodeName.c_str() , Name() ) )
278 RetVal = GraphBase::Graph::AddInputData( aLink.ToNodeName.c_str() ,
279 aLink.ToServiceParameterName.c_str() ,
281 // aLink.aLinkValue.Value , aLink.aLinkValue.Kind ) ;
282 else if ( !strcmp( aLink.ToNodeName.c_str() , Name() ) ) {
283 RetVal = AddOutputData( aLink.FromNodeName.c_str() ,
284 aLink.FromServiceParameterName.c_str() ,
286 // aLink.aLinkValue.Value ,
287 // aLink.aLinkValue.Kind ) ;
288 AddLink( aLink.FromNodeName.c_str() , (GraphBase::ComputingNode *) this ) ;
291 cdebug << "GraphExecutor::OutNode::LoadDatas Error " << aLink.FromNodeName
292 << " and " << aLink.ToNodeName << " differents from " << Name()
302 GraphExecutor::InNode *GraphExecutor::OutNode::AddNode(
303 const SALOME_ModuleCatalog::Service& NodeService ,
304 GraphBase::ListOfFuncName aFuncName ,
305 GraphBase::ListOfPythonFunctions aPythonFunction ,
306 const char * NodeComponentName ,
307 const char * NodeInterfaceName ,
308 const char * NodeName ,
309 const SUPERV::KindOfNode NodeKindOfNode ,
310 const SUPERV::SDate NodeFirstCreation ,
311 const SUPERV::SDate NodeLastModification ,
312 const char * NodeEditorRelease ,
313 const char * NodeAuthor ,
314 const char * NodeComputer ,
315 const char * NodeComment ,
318 cdebug_in << "GraphExecutor::OutNode::AddNode(" << NodeComponentName << " , "
319 << NodeName << ")" << endl;
320 GraphExecutor::InNode *Nd = NULL ;
321 Nd = new GraphExecutor::InNode( _Orb, NamingService() , NodeService ,
322 NodeComponentName , NodeInterfaceName ,
323 NodeName , NodeKindOfNode ,
324 aFuncName , aPythonFunction ,
325 NodeFirstCreation , NodeLastModification ,
326 NodeEditorRelease , NodeAuthor ,
327 NodeComputer , NodeComment , false , NodeX , NodeY ,
328 Graph_prof_debug() , Graph_fdebug() ) ;
329 GraphBase::Graph::AddNode( Nd->ComputingNode() ) ;
330 cdebug_out << "GraphExecutor::OutNode::AddNode" << endl;
335 bool GraphExecutor::OutNode::AddInputData( const char* ToNodeName1 ,
336 const char* ToParameterName1 ,
337 const char* ToNodeName2 ,
338 const char* ToParameterName2 ) {
339 cdebug_in << "GraphExecutor::OutNode::AddInputData" << endl;
340 bool RetVal = GraphBase::Graph::AddInputData( ToNodeName1 ,
344 cdebug_out << "GraphExecutor::OutNode::AddInputData" << endl;
349 bool GraphExecutor::OutNode::Valid() {
350 cdebug_in << "GraphExecutor::OutNode::Valid" << endl;
355 _Executable = false ;
360 cdebug << "This DataFlow is not valid." << endl ;
372 cdebug_out << "GraphExecutor::OutNode::Valid" << endl;
377 bool GraphExecutor::OutNode::Executable() {
379 cdebug_in << "GraphExecutor::OutNode::Executable" << endl;
383 if ( DataServerNodes() )
386 cdebug << "This DataFlow is not executable." << endl ;
387 _Executable = false ;
390 cdebug_out << "GraphExecutor::OutNode::Executable" << endl;
394 bool GraphExecutor::OutNode::Run( const bool AndSuspend ) {
395 bool RetVal = false ;
396 cdebug_in << "GraphExecutor::OutNode::Run" << endl;
398 if ( Executable() ) {
399 _ControlState = SUPERV::VoidState ;
400 _SuspendedThreads = 0 ;
401 ThreadNo( pthread_self() ) ;
403 _JustStarted = true ;
405 for ( i = 0 ; i < GraphNodesSize() ; i++ ) {
406 GraphExecutor::InNode * anInNode = (GraphExecutor::InNode *) GraphNodes( i )->GetInNode() ;
407 if ( !PyInitialized() && anInNode->IsOneOfInLineNodes() ) {
408 if ( !Py_IsInitialized() ) {
410 PySys_SetArgv( _ArgC , _ArgV ) ;
412 anInNode->InitPython() ;
413 PyInitialized( true ) ;
415 anInNode->InitialState( this ) ;
418 cdebug << "Execution starting GraphExecutor::Action_DataOk_RunService Node "
421 PushEvent( NULL , GraphExecutor::ReadyEvent ,
422 SUPERV::DataReadyState ) ;
423 State( SUPERV::DataReadyState ) ;
425 for ( i = 0 ; i < HeadNodesSize() ; i++ ) {
426 GraphExecutor::InNode * anInNode = (GraphExecutor::InNode *) HeadNodes( i )->GetInNode() ;
427 if ( anInNode->State() != SUPERV::DataReadyState ) {
428 cdebug << "GraphExecutor::OutNode::Run inconsistency State of Node "
429 << anInNode->Name() << " : " << anInNode->State() << endl ;
432 // PushEvent( anInNode , GraphExecutor::ReadyEvent ,
433 // SUPERV::DataReadyState ) ;
434 anInNode->CreateNewThread( true ) ;
435 anInNode->DataFromNode( Name() ) ;
437 anInNode->State( SUPERV::DataWaitingState ) ;
438 anInNode->ControlState( SUPERV::ToSuspendStartState ) ;
439 if ( !anInNode->SendEvent( GraphExecutor::SomeDataReadyEvent ) ) {
440 cdebug << "InNode::SendEvent( SomeDataReadyEvent ) Node "
441 << anInNode->Name() << endl ;
444 anInNode->SuspendedWait() ;
446 else if ( !anInNode->SendEvent( GraphExecutor::ExecuteEvent ) ) {
447 cdebug << "InNode::SendEvent( RunningEvent ) Node "
448 << anInNode->Name() << endl ;
452 anInNode->RunningWait() ;
457 PushEvent( NULL , GraphExecutor::SuspendedReadyEvent ,
458 SUPERV::SuspendedReadyState ) ;
461 PushEvent( NULL , GraphExecutor::ExecutingEvent ,
462 SUPERV::ExecutingState ) ;
463 if (AutomatonState() == SUPERV::DataReadyState) {
464 State( SUPERV::ExecutingState ) ;
471 PushEvent( NULL , GraphExecutor::NoDataReadyEvent ,
472 SUPERV::DataUndefState ) ;
475 cdebug_out << "GraphExecutor::OutNode::Run" << endl ;
479 bool GraphExecutor::OutNode::Run( const char * aNodeName ,
480 const char * AtNodeName ,
481 const bool AndSuspend ) {
482 bool RetVal = false ;
483 cdebug_in << "GraphExecutor::OutNode::Run( " << aNodeName << " , "
484 << AtNodeName << " , " << AndSuspend << ")" << endl;
485 GraphExecutor::InNode *anInNode = (GraphExecutor::InNode *) GetGraphNode( aNodeName )->GetInNode() ;
487 RetVal = anInNode->ReStart( AtNodeName , AndSuspend ) ;
489 cdebug_out << "GraphExecutor::OutNode::Run" << endl ;
493 void GraphExecutor::OutNode::CheckAllDone() {
495 cdebug_in << "GraphExecutor::OutNode::CheckAllDone " << endl;
496 SUPERV::AutomatonState OutNodeState = SUPERV::SuccessedState ;
497 SUPERV::AutomatonState InNodeState ;
498 bool AllDone = true ;
500 for ( j = 0 ; j < QueueNodesSize() ; j++ ) {
501 InNodeState = ( (GraphExecutor::InNode * ) QueueNodes( j )->GetInNode() )->State() ;
503 << ( (GraphExecutor::InNode * ) QueueNodes( j )->GetInNode() )->Name()
504 << " " << theAutomaton->StateName( InNodeState ) << endl ;
505 if ( InNodeState != SUPERV::SuccessedState &&
506 InNodeState != SUPERV::ErroredState &&
507 InNodeState != SUPERV::DataWaitingState ) {
510 if ( InNodeState != SUPERV::SuccessedState ) {
511 OutNodeState = InNodeState ;
515 if( _Threads == 0 && _SuspendedThreads == 0 ) {
516 if ( OutNodeState != SUPERV::ErroredState ) {
517 OutNodeState = SUPERV::SuccessedState ;
525 State( OutNodeState ) ;
527 _JustStarted = false ;
528 for ( j = 0 ; j < GraphNodesSize() ; j++ ) {
529 GraphExecutor::InNode * aNode ;
530 aNode = (GraphExecutor::InNode * ) GraphNodes( j )->GetInNode() ;
531 SUPERV::GraphState aState = AutomatonGraphState( aNode->State() ) ;
532 cdebug << "GraphExecutor::OutNode::CheckAllDone " << aNode->Name() << " "
533 << theAutomaton->StateName( aNode->State() ) << " :" << endl ;
534 if ( aState == SUPERV::ErrorState ||
535 aState == SUPERV::SuspendErroredState ||
536 aState == SUPERV::KillState ||
537 aState == SUPERV::StopState ) {
538 OutNodeState = aNode->State() ;
540 aNode->SuspendedAction() ;
541 aNode->DoneAction() ;
543 // PushEvent AFTER State and _Done ! ...
544 PushEvent( NULL , GraphExecutor::EndExecuteEvent ,
547 // PyInitialized( false ) ;
550 cdebug_out << "GraphExecutor::OutNode::CheckAllDone " << _Done
551 << " GraphAutomatonState " << theAutomaton->StateName( AutomatonState() )
552 << " State " << State() << " Threads " << _Threads << " SuspendedThreads "
553 << _SuspendedThreads << endl ;
556 void GraphExecutor::OutNode::PThreadLock( pthread_mutex_t * aMutex , char * errmsg ) {
557 // if ( strcmp( errmsg , "EventLoop" ) && strcmp( errmsg , "EventW" ) ) {
558 // cdebug << "GraphExecutor::OutNode::PThreadLock " << pthread_self() << " " << aMutex << " "
559 // << errmsg << endl ;
561 if ( pthread_mutex_lock( aMutex ) ) {
565 // if ( strcmp( errmsg , "EventLoop" ) && strcmp( errmsg , "EventW" ) ) {
566 // cdebug << "GraphExecutor::OutNode::PThreadLocked " << pthread_self() << " " << aMutex << " "
567 // << errmsg << endl ;
571 void GraphExecutor::OutNode::PThreadUnLock( pthread_mutex_t * aMutex , char * errmsg ) {
572 // if ( strcmp( errmsg , "EventLoop" ) && strcmp( errmsg , "EventW" ) ) {
573 // cdebug << " GraphExecutor::OutNode::PThreadUnLock " << pthread_self() << " " << aMutex << " "
574 // << errmsg << endl ;
576 if ( pthread_mutex_unlock( aMutex ) ) {
582 void GraphExecutor::OutNode::PThreadLock() {
583 cout << " GraphExecutor::OutNode::PThreadLock " << pthread_self() << endl ;
584 if ( pthread_mutex_lock( &_MutexWait ) ) {
585 perror( "GraphExecutor::OutNode::PThreadLock" ) ;
588 cout << " GraphExecutor::OutNode::PThreadLocked " << pthread_self() << endl ;
591 void GraphExecutor::OutNode::PThreadUnLock() {
592 cout << " GraphExecutor::OutNode::PThreadUnLock " << pthread_self() << endl ;
593 if ( pthread_mutex_unlock( &_MutexWait ) ) {
594 perror( "GraphExecutor::OutNode::PThreadUnLock" ) ;
597 cout << " GraphExecutor::OutNode::PThreadUnLocked " << pthread_self() << endl ;
600 void GraphExecutor::OutNode::NewThread() {
601 if ( pthread_mutex_lock( &_MutexWait ) ) {
602 perror("pthread_mutex_lock _NewThread") ;
606 cdebug << "NewThread : " << _Threads << " running threads "
607 << _SuspendedThreads << " suspended threads"
609 if ( pthread_mutex_unlock( &_MutexWait ) ) {
610 perror("pthread_mutex_unlock _NewThread") ;
614 void GraphExecutor::OutNode::ExitThread() {
615 if ( pthread_mutex_lock( &_MutexWait ) ) {
616 perror("pthread_mutex_lock _ExitThread") ;
620 theAutomaton->JoinThread( pthread_self() ) ;
621 if ( pthread_cond_signal( &_JoinWait ) ) {
622 perror("ExitThread pthread_cond_signal ") ;
624 cdebug << "ExitThread : " << _Threads << " running threads "
625 << _SuspendedThreads << " suspended threads"
627 if ( pthread_mutex_unlock( &_MutexWait ) ) {
628 perror("pthread_mutex_unlock _ExitThread") ;
631 if ( _Threads == 0 && _SuspendedThreads == 0 ) {
635 void GraphExecutor::OutNode::JoinedWait() {
636 if ( pthread_mutex_lock( &_MutexWait ) ) {
637 perror("pthread_mutex_lock JoinedWait") ;
641 if ( pthread_cond_wait( &_JoinWait , &_MutexWait ) ) {
642 perror("JoinedWait pthread_cond_wait ") ;
645 if ( pthread_mutex_unlock( &_MutexWait ) ) {
646 perror("pthread_mutex_unlock JoinedWait") ;
650 void GraphExecutor::OutNode::SuspendThread() {
651 if ( pthread_mutex_lock( &_MutexWait ) ) {
652 perror("pthread_mutex_lock _SuspendThread") ;
655 _SuspendedThreads += 1 ;
656 cdebug << "SuspendThread : " << _Threads << " running threads "
657 << _SuspendedThreads << " suspended threads"
659 if ( pthread_mutex_unlock( &_MutexWait ) ) {
660 perror("pthread_mutex_unlock _SuspendThread") ;
663 if ( IsSuspended() ) {
664 PushEvent( NULL , GraphExecutor::SuspendEvent , SUPERV::SuspendedState ) ;
667 void GraphExecutor::OutNode::ResumeThread() {
668 if ( pthread_mutex_lock( &_MutexWait ) ) {
669 perror("pthread_mutex_lock _ResumeThread") ;
672 _SuspendedThreads -= 1 ;
673 cdebug << "ResumeThread : " << _Threads << " running threads "
674 << _SuspendedThreads << " suspended threads"
676 if ( pthread_mutex_unlock( &_MutexWait ) ) {
677 perror("pthread_mutex_unlock _ResumeThread") ;
682 long GraphExecutor::OutNode::Thread( const char * aNodeName ) {
684 GraphExecutor::InNode *anInNode = (GraphExecutor::InNode *) GetGraphNode( aNodeName )->GetInNode() ;
686 RetVal = anInNode->ThreadNo() ;
691 SUPERV::GraphEvent GraphExecutor::OutNode::AutomatonGraphEvent(GraphExecutor::NodeEvent anEvent ) {
692 SUPERV::GraphEvent aGraphEvent ;
694 case GraphExecutor::UndefinedEvent : {
695 aGraphEvent = SUPERV::UndefinedEvent ;
698 case GraphExecutor::NewThreadEvent : {
699 aGraphEvent = SUPERV::NewThreadEvent ;
702 case GraphExecutor::SuspendEvent : {
703 aGraphEvent = SUPERV::SuspendEvent ;
706 case GraphExecutor::ResumeEvent : {
707 aGraphEvent = SUPERV::ResumeEvent ;
710 case GraphExecutor::KillEvent : {
711 aGraphEvent = SUPERV::KillEvent ;
714 case GraphExecutor::StopEvent : {
715 aGraphEvent = SUPERV::StopEvent ;
718 case GraphExecutor::ExecuteEvent : {
719 aGraphEvent = SUPERV::RunningEvent ;
722 case GraphExecutor::SuccessEvent : {
723 aGraphEvent = SUPERV::DoneEvent ;
726 case GraphExecutor::ErrorEvent : {
727 aGraphEvent = SUPERV::ErroredEvent ;
730 case GraphExecutor::ReStartEvent : {
731 aGraphEvent = SUPERV::ReRunEvent ;
734 case GraphExecutor::ReStartAndSuspendEvent : {
735 aGraphEvent = SUPERV::ReStartEvent ;
738 case GraphExecutor::NoDataReadyEvent : {
739 aGraphEvent = SUPERV::WaitingEvent ;
742 case GraphExecutor::SomeDataReadyEvent : {
743 aGraphEvent = SUPERV::WaitingEvent ;
746 case GraphExecutor::NotAllDataReadyEvent : {
747 aGraphEvent = SUPERV::WaitingEvent ;
750 case GraphExecutor::AllDataReadyEvent : {
751 aGraphEvent = SUPERV::ReadyEvent ;
754 case GraphExecutor::ReadyEvent : {
755 aGraphEvent = SUPERV::ReadyEvent ;
758 case GraphExecutor::SuspendedReadyEvent : {
759 aGraphEvent = SUPERV::SuspendEvent ;
762 case GraphExecutor::ResumedReadyEvent : {
763 aGraphEvent = SUPERV::ResumeEvent ;
766 case GraphExecutor::KilledReadyEvent : {
767 aGraphEvent = SUPERV::KillEvent ;
770 case GraphExecutor::StoppedReadyEvent : {
771 aGraphEvent = SUPERV::StopEvent ;
774 case GraphExecutor::ExecutingEvent : {
775 aGraphEvent = SUPERV::RunningEvent ;
778 case GraphExecutor::SuspendedExecutingEvent : {
779 aGraphEvent = SUPERV::SuspendEvent ;
782 case GraphExecutor::ResumedExecutingEvent : {
783 aGraphEvent = SUPERV::ResumeEvent ;
786 case GraphExecutor::KilledExecutingEvent : {
787 aGraphEvent = SUPERV::KillEvent ;
790 case GraphExecutor::StoppedExecutingEvent : {
791 aGraphEvent = SUPERV::StopEvent ;
794 case GraphExecutor::SuccessedExecutingEvent : {
795 aGraphEvent = SUPERV::DoneEvent ;
798 case GraphExecutor::ErroredExecutingEvent : {
799 aGraphEvent = SUPERV:: ErroredEvent;
802 case GraphExecutor::SuspendedSuccessedEvent : {
803 aGraphEvent = SUPERV::SuspendEvent ;
806 case GraphExecutor::SuspendedErroredEvent : {
807 aGraphEvent = SUPERV::SuspendEvent ;
810 case GraphExecutor::ResumedSuccessedEvent : {
811 aGraphEvent = SUPERV::ResumeEvent ;
814 case GraphExecutor::ResumedErroredEvent : {
815 aGraphEvent = SUPERV::ResumeEvent ;
818 case GraphExecutor::KilledEvent : {
819 aGraphEvent = SUPERV::KillEvent ;
822 case GraphExecutor::StoppedEvent : {
823 aGraphEvent = SUPERV::StopEvent ;
826 case GraphExecutor::ReStartedEvent : {
827 aGraphEvent = SUPERV::ReRunEvent ;
830 case GraphExecutor::ReStartedAndSuspendEvent : {
831 aGraphEvent = SUPERV::ReStartEvent ;
834 case GraphExecutor::EndExecuteEvent : {
835 aGraphEvent = SUPERV::DoneEvent ;
839 cdebug << " GraphExecutor::OutNode::AutomatonGraphEvent Error Undefined Event : "
841 aGraphEvent = SUPERV::UndefinedEvent ;
847 SUPERV::GraphState GraphExecutor::OutNode::AutomatonGraphState(SUPERV::AutomatonState aState ) {
848 SUPERV::GraphState aGraphState ;
850 case SUPERV::UnKnownState : {
851 aGraphState = SUPERV::UndefinedState ;
854 case SUPERV::DataUndefState : {
855 aGraphState = SUPERV::UndefinedState ;
858 case SUPERV::DataWaitingState : {
859 aGraphState = SUPERV::WaitingState ;
862 case SUPERV::DataReadyState : {
863 aGraphState = SUPERV::ReadyState ;
866 case SUPERV::SuspendedReadyState : {
867 aGraphState = SUPERV::SuspendReadyState ;
870 case SUPERV::ResumedReadyState : {
871 aGraphState = SUPERV::ReadyState ;
874 case SUPERV::KilledReadyState : {
875 aGraphState = SUPERV::KillState ;
878 case SUPERV::StoppedReadyState : {
879 aGraphState = SUPERV::StopState ;
882 case SUPERV::ExecutingState : {
883 aGraphState = SUPERV::RunningState ;
886 case SUPERV::SuspendedExecutingState : {
887 aGraphState = SUPERV::SuspendState ;
890 case SUPERV::ResumedExecutingState : {
891 aGraphState = SUPERV::RunningState ;
894 case SUPERV::KilledExecutingState : {
895 aGraphState = SUPERV::KillState ;
898 case SUPERV::StoppedExecutingState : {
899 aGraphState = SUPERV::StopState ;
902 case SUPERV::SuccessedExecutingState : {
903 aGraphState = SUPERV::DoneState ;
906 case SUPERV::ErroredExecutingState : {
907 aGraphState = SUPERV::ErrorState ;
910 case SUPERV::SuspendedSuccessedState : {
911 aGraphState = SUPERV::SuspendDoneState ;
914 case SUPERV::SuspendedErroredState : {
915 aGraphState = SUPERV::SuspendErroredState ;
918 case SUPERV::ResumedSuccessedState : {
919 aGraphState = SUPERV::DoneState ;
922 case SUPERV::ResumedErroredState : {
923 aGraphState = SUPERV::ErrorState ;
926 case SUPERV::KilledSuccessedState : {
927 aGraphState = SUPERV::KillState ;
930 case SUPERV::KilledErroredState : {
931 aGraphState = SUPERV::KillState ;
934 case SUPERV::StoppedSuccessedState : {
935 aGraphState = SUPERV::StopState ;
938 case SUPERV::StoppedErroredState : {
939 aGraphState = SUPERV::StopState ;
942 case SUPERV::SuccessedState : {
943 aGraphState = SUPERV::DoneState ;
946 case SUPERV::ErroredState : {
947 aGraphState = SUPERV::ErrorState ;
950 case SUPERV::SuspendedState : {
951 aGraphState = SUPERV::SuspendState ;
954 case SUPERV::KilledState : {
955 aGraphState = SUPERV::KillState ;
958 case SUPERV::StoppedState : {
959 aGraphState = SUPERV::StopState ;
962 case SUPERV::ReRunnedState : {
963 aGraphState = SUPERV::ReRunState ;
966 case SUPERV::ReStartedState : {
967 aGraphState = SUPERV::ReStartState ;
971 cdebug << " GraphExecutor::OutNode::AutomatonGraphState Error Undefined State : "
972 << aGraphState << endl ;
973 aGraphState = SUPERV::UndefinedState ;
979 bool GraphExecutor::OutNode::PushEvent( GraphExecutor::InNode * aNode ,
980 GraphExecutor::NodeEvent anEvent ,
981 SUPERV::AutomatonState aState ) {
982 // cdebug_in << "PushEvent Threads " << Threads() << " SuspendedThreads "
983 // << SuspendedThreads() << endl ;
984 if ( pthread_mutex_lock( &_MutexWait ) ) {
985 perror("PushEvent pthread_mutex_lock ") ;
989 _EventNodes.push_back( aNode->Name() ) ;
992 _EventNodes.push_back( Name() ) ;
994 _Events.push_back( anEvent ) ;
995 _States.push_back( aState ) ;
996 pthread_cond_broadcast( &_EventWait );
998 // cdebug << aNode->ThreadNo() << " PushEvent " << aNode->Name() ;
999 // cdebug << " " << aNode->Automaton()->EventName( anEvent )
1000 // << " " << aNode->Automaton()->StateName( aState )
1001 // << " ControleState "
1002 // << aNode->Automaton()->ControlStateName( aNode->ControlState() ) ;
1005 // cdebug << "PushEvent " << Name() ;
1006 // cdebug << " " << theAutomaton->EventName( anEvent ) << " "
1007 // << theAutomaton->StateName( aState ) ;
1009 // cdebug_out << "PushEvent Threads " << Threads() << " SuspendedThreads "
1010 // << SuspendedThreads() << endl ;
1011 if ( pthread_mutex_unlock( &_MutexWait ) ) {
1012 perror("PushEvent pthread_mutex_unlock ") ;
1017 bool GraphExecutor::OutNode::StateWait( SUPERV::GraphState aState ) {
1020 bool GraphExecutor::OutNode::Event( char ** aNodeName ,
1021 SUPERV::GraphEvent & anEvent ,
1022 SUPERV::GraphState & aState ,
1025 int SuspendedThreadsNumber ;
1026 if ( pthread_mutex_lock( &_MutexWait ) ) {
1027 perror("EventLoop pthread_mutex_lock ") ;
1030 _JustStarted = false ;
1031 ThreadsNumber = Threads() ;
1032 SuspendedThreadsNumber = SuspendedThreads() ;
1033 bool RetVal = ( ThreadsNumber - SuspendedThreadsNumber) != 0 ||
1034 _EventNodes.size() > 0 ;
1035 char * NodeName = "" ;
1036 GraphExecutor::NodeEvent theEvent = GraphExecutor::UndefinedEvent ;
1037 SUPERV::AutomatonState theState = SUPERV::UnKnownState ;
1038 anEvent = SUPERV::UndefinedEvent ;
1039 aState = SUPERV::UndefinedState ;
1040 if ( ( IsDone() || IsKilled() || IsStopped() ) && _EventNodes.size() == 0 ) {
1041 cdebug << "EventLoop IsDone()/IsKilled()/IsStopped() && _EventNodes.size() == 0" << endl ;
1044 else if ( !WithWait && _EventNodes.size() == 0 ) {
1045 anEvent = SUPERV::NoEvent ;
1046 aState = SUPERV::NoState ;
1049 else if ( RetVal ) {
1050 while ( !IsSuspended() && _EventNodes.size() == 0 ) {
1051 cdebug << "EventLoop pthread_cond_wait _EventWait" << endl ;
1052 pthread_cond_wait( &_EventWait , &_MutexWait );
1053 cdebug << "EventLoop pthread_cond_waited _EventWait"
1054 << " _EventNodes.size() " << _EventNodes.size() << endl ;
1056 if ( _EventNodes.size() ) {
1057 ThreadsNumber = Threads() ;
1058 NodeName = _EventNodes.front() ;
1059 _EventNodes.pop_front() ;
1060 theEvent = _Events.front() ;
1061 anEvent = AutomatonGraphEvent( theEvent ) ;
1062 _Events.pop_front() ;
1063 theState = _States.front() ;
1064 aState = AutomatonGraphState( theState ) ;
1065 _States.pop_front() ;
1068 *aNodeName = NodeName ;
1069 if ( IsSuspended() && _EventNodes.size() == 0 ) {
1072 if ( anEvent != SUPERV::NoEvent ) {
1073 cdebug << pthread_self() << "EventLoop "
1074 << NodeName << " " << theAutomaton->StateName( theState )
1075 << " _EventNodes.size() " << _EventNodes.size()
1076 << " Threads " << Threads() << " SuspendedThreads "
1077 << SuspendedThreads() << " RetVal " << RetVal << endl ;
1079 if ( pthread_mutex_unlock( &_MutexWait ) ) {
1080 perror("EventLoop pthread_mutex_lock ") ;
1086 bool GraphExecutor::OutNode::EventW( char ** aNodeName ,
1087 SUPERV::GraphEvent & anEvent ,
1088 SUPERV::GraphState & aState ) {
1091 aState = SUPERV::UndefinedState ;
1093 aState != SUPERV::SuspendReadyState &&
1094 aState != SUPERV::RunningState &&
1095 aState != SUPERV::SuspendDoneState &&
1096 aState != SUPERV::SuspendErroredState ) {
1098 while ( sts && !strcmp( NodeName , Name() ) ) {
1099 sts = EventWait( aNodeName , anEvent , aState ) ;
1100 NodeName = *aNodeName ;
1106 bool GraphExecutor::OutNode::EventWait( char ** aNodeName ,
1107 SUPERV::GraphEvent & anEvent ,
1108 SUPERV::GraphState & aState ) {
1109 if ( pthread_mutex_lock( &_MutexWait ) ) {
1110 perror("EventW pthread_mutex_lock ") ;
1114 int SuspendedThreadsNumber ;
1115 ThreadsNumber = Threads() ;
1116 SuspendedThreadsNumber = SuspendedThreads() ;
1117 bool RetVal = ( ThreadsNumber - SuspendedThreadsNumber) != 0 ||
1118 _EventNodes.size() > 0 ;
1119 cdebug << "--> EventW RetVal " << RetVal << endl ;
1120 char * NodeName = "" ;
1121 GraphExecutor::NodeEvent theEvent = GraphExecutor::UndefinedEvent ;
1122 SUPERV::AutomatonState theState = SUPERV::UnKnownState ;
1123 anEvent = SUPERV::UndefinedEvent ;
1124 aState = SUPERV::UndefinedState ;
1125 if ( IsDone() && _EventNodes.size() == 0 ) {
1126 cdebug << "EventW IsDone() && _EventNodes.size() == 0" << endl ;
1129 else if ( RetVal ) {
1130 GraphExecutor::InNode * aNode = NULL ;
1131 while ( aNode == NULL && RetVal ) {
1132 NodeName = _EventNodes.front() ;
1133 theEvent = _Events.front() ;
1134 anEvent = AutomatonGraphEvent( theEvent ) ;
1135 theState = _States.front() ;
1136 aState = AutomatonGraphState( theState ) ;
1138 if ( _JustStarted ) {
1139 _JustStarted = false ;
1142 _EventNodes.pop_front() ;
1143 _Events.pop_front() ;
1144 _States.pop_front() ;
1147 aNode = ((GraphExecutor::InNode *) GetGraphNode( NodeName )->GetInNode()) ;
1148 cdebug << "EventW Previous Node " << NodeName << " ThreadsNumber "
1150 << " _EventNodes.size() " << _EventNodes.size() << " "
1151 << theAutomaton->StateName( theState )
1152 << " Threads " << Threads() << " SuspendedThreads "
1153 << SuspendedThreads() << endl ;
1156 else if ( IsDone() && _EventNodes.size() == 0 ) {
1157 cdebug << "EventW IsDone() && _EventNodes.size() == 0" << endl ;
1161 cdebug << "EventW Not InNode " << NodeName
1162 << " _EventNodes.size() " << _EventNodes.size() << endl ;
1163 while ( _EventNodes.size() == 0 ) {
1164 pthread_cond_wait( &_EventWait , &_MutexWait );
1166 cdebug << "EventW pthread_cond_waited Not InNode " << NodeName
1167 << " _EventNodes.size() " << _EventNodes.size() << endl ;
1172 if ( aState == SUPERV::SuspendState ||
1173 aState == SUPERV::SuspendReadyState ||
1174 aState == SUPERV::SuspendDoneState ||
1175 aState == SUPERV::SuspendErroredState ) {
1176 aNode->ControlState( SUPERV::ToSuspendState ) ;
1177 if ( aNode->IsSuspended() ) {
1178 if ( pthread_mutex_unlock( &_MutexWait ) ) {
1179 perror("EventW pthread_mutex_lock ") ;
1182 cdebug << "EventW " << aNode->Name() << " ResumeAction" << endl ;
1183 aNode->ResumeAction( GraphExecutor::ToResumeEvent ) ;
1184 cdebug << "EventW " << aNode->Name() << " ResumedAction" << endl ;
1185 if ( pthread_mutex_lock( &_MutexWait ) ) {
1186 perror("EventW pthread_mutex_lock ") ;
1191 cdebug << "EventW inconsistent SuspendState" << endl ;
1196 if ( aNode->IsDone() ) {
1200 cdebug << "EventW NOT SuspendedState _EventNodes.size() "
1201 << _EventNodes.size() << endl ;
1206 cdebug << "EventW " << aNode->Name() << " pthread_cond_wait" << endl ;
1207 while ( _EventNodes.size() == 0 ) {
1208 pthread_cond_wait( &_EventWait , &_MutexWait );
1210 ThreadsNumber = Threads() ;
1211 NodeName = _EventNodes.front() ;
1212 theEvent = _Events.front() ;
1213 anEvent = AutomatonGraphEvent( theEvent ) ;
1214 theState = _States.front() ;
1215 aState = AutomatonGraphState( theState ) ;
1219 *aNodeName = NodeName ;
1220 cdebug << "<-- EventW RetVal " << RetVal << " " << NodeName
1221 << " Threads " << Threads() << " SuspendedThreads "
1222 << SuspendedThreads()
1223 << " _EventNodes.size() " << _EventNodes.size()
1224 << " " << theAutomaton->EventName( theEvent ) << " "
1225 << theAutomaton->StateName( theState ) << endl ;
1226 if ( pthread_mutex_unlock( &_MutexWait ) ) {
1227 perror("EventW pthread_mutex_lock ") ;
1233 void GraphExecutor::OutNode::State(SUPERV::AutomatonState aState ) {
1237 SUPERV::GraphState GraphExecutor::OutNode::State() {
1238 // cdebug_in << "GraphExecutor::OutNode::State" << endl;
1239 // cdebug_out << "GraphExecutor::OutNode::State" << endl ;
1240 // cdebug << "GraphExecutor::OutNode::State GraphState "
1241 // << theAutomaton->StateName( AutomatonGraphState( _State ) ) << endl ;
1242 return AutomatonGraphState( _State ) ;
1245 SUPERV::GraphState GraphExecutor::OutNode::State( const char * NodeName ) {
1246 // cdebug_in << "GraphExecutor::OutNode::State " << NodeName << endl;
1247 SUPERV::AutomatonState aret = SUPERV::UnKnownState ;
1248 const GraphBase::ComputingNode * aCNode = GetGraphNode( NodeName ) ;
1250 GraphExecutor::InNode *anInNode = (GraphExecutor::InNode *)aCNode->GetInNode() ;
1252 aret = anInNode->State() ;
1253 cdebug << "GraphExecutor::OutNode::State( " << NodeName << " ) "
1254 << theAutomaton->StateName( AutomatonGraphState( aret ) ) << endl ;
1257 // cdebug_out << "GraphExecutor::OutNode::State" << endl ;
1258 return AutomatonGraphState( aret ) ;
1261 SUPERV::GraphState GraphExecutor::OutNode::State(
1262 const char * NodeName ,
1263 const char * ServiceParameterName ) {
1264 // cdebug_in << "GraphExecutor::OutNode::State " << NodeName << " "
1265 // << ServiceParameterName<< endl;
1266 SUPERV::GraphState aret =
1267 PortState( NodeName , ServiceParameterName ) ;
1268 // cdebug_out << "GraphExecutor::OutNode::State" << endl ;
1272 SUPERV::AutomatonState GraphExecutor::OutNode::AutomatonState() {
1273 // cdebug_in << "GraphExecutor::OutNode::AutomatonState" << endl;
1274 // cdebug_out << "GraphExecutor::OutNode::AutomatonState" << endl ;
1278 SUPERV::AutomatonState GraphExecutor::OutNode::AutomatonState( const char * NodeName ) {
1279 // cdebug_in << "GraphExecutor::OutNode::AutomatonState " << NodeName << endl;
1280 SUPERV::AutomatonState aret = SUPERV::UnKnownState ;
1281 GraphExecutor::InNode *anInNode = (GraphExecutor::InNode *) GetGraphNode( NodeName )->GetInNode() ;
1283 aret = anInNode->State() ;
1284 // cdebug_out << "GraphExecutor::OutNode::AutomatonState" << endl ;
1288 SUPERV::ControlState GraphExecutor::OutNode::ControlState() {
1289 // cdebug_in << "GraphExecutor::OutNode::ControlState" << endl;
1290 // cdebug_out << "GraphExecutor::OutNode::ControlState" << endl ;
1291 return _ControlState ;
1294 SUPERV::ControlState GraphExecutor::OutNode::ControlState( const char * NodeName ) {
1295 // cdebug_in << "GraphExecutor::OutNode::ControlState " << NodeName << endl;
1296 SUPERV::ControlState aret = SUPERV::VoidState ;
1297 GraphExecutor::InNode *anInNode = (GraphExecutor::InNode *) GetGraphNode( NodeName )->GetInNode() ;
1299 aret = anInNode->ControlState() ;
1300 // cdebug_out << "GraphExecutor::OutNode::ControlState" << endl ;
1304 void GraphExecutor::OutNode::ControlClear() {
1305 // cdebug_in << "GraphExecutor::OutNode::ControlClear" << endl;
1306 // cdebug_out << "GraphExecutor::OutNode::ControlClear" << endl ;
1307 _ControlState = SUPERV::VoidState;
1310 void GraphExecutor::OutNode::ControlClear( const char * NodeName ) {
1311 // cdebug_in << "GraphExecutor::OutNode::ControlClear " << NodeName << endl;
1312 GraphExecutor::InNode *anInNode = (GraphExecutor::InNode *) GetGraphNode( NodeName )->GetInNode() ;
1314 anInNode->ControlClear() ;
1315 // cdebug_out << "GraphExecutor::OutNode::ControlClear" << endl ;
1318 bool GraphExecutor::OutNode::IsWaiting() {
1319 // cdebug_in << "GraphExecutor::OutNode::IsWaiting" << endl;
1320 // cdebug_out << "GraphExecutor::OutNode::IsWaiting" << endl ;
1324 bool GraphExecutor::OutNode::IsReady() {
1325 // cdebug_in << "GraphExecutor::OutNode::IsReady" << endl;
1326 // cdebug_out << "GraphExecutor::OutNode::IsReady" << endl ;
1330 bool GraphExecutor::OutNode::IsRunning() {
1331 // cdebug_in << "GraphExecutor::OutNode::IsRunning" << endl;
1332 // cdebug_out << "GraphExecutor::OutNode::IsRunning" << endl ;
1336 bool GraphExecutor::OutNode::IsDone() {
1337 // cdebug_in << "GraphExecutor::OutNode::IsDone" << endl;
1338 // cdebug_out << "GraphExecutor::OutNode::IsDone" << endl ;
1339 return ( _Done || IsKilled() || IsStopped() ) ;
1342 bool GraphExecutor::OutNode::IsSuspended() {
1343 // cdebug_in << "GraphExecutor::OutNode::IsSuspended" << endl;
1345 if ( _SuspendedThreads == _Threads ) {
1348 // cdebug_out << "GraphExecutor::OutNode::IsSuspended" << endl ;
1352 bool GraphExecutor::OutNode::IsKilled() {
1353 // cdebug_in << "GraphExecutor::OutNode::IsKilled" << endl;
1355 if ( AutomatonGraphState( _State ) == SUPERV::KillState ) {
1358 // cdebug_out << "GraphExecutor::OutNode::IsKilled" << endl ;
1362 bool GraphExecutor::OutNode::IsStopped() {
1363 // cdebug_in << "GraphExecutor::OutNode::IsStopped" << endl;
1365 if ( AutomatonGraphState( _State ) == SUPERV::StopState ) {
1368 // cdebug_out << "GraphExecutor::OutNode::IsStopped" << endl ;
1372 bool GraphExecutor::OutNode::IsWaiting( const char * NodeName ) {
1374 // cdebug_in << "GraphExecutor::OutNode::IsWaiting " << NodeName << endl;
1375 GraphExecutor::InNode *anInNode = (GraphExecutor::InNode *) GetGraphNode( NodeName )->GetInNode() ;
1377 aret = anInNode->IsWaiting() ;
1379 // cdebug_out << "GraphExecutor::OutNode::IsWaiting" << endl ;
1383 bool GraphExecutor::OutNode::IsReady( const char * NodeName ) {
1385 // cdebug_in << "GraphExecutor::OutNode::IsReady " << NodeName << endl;
1386 GraphExecutor::InNode *anInNode = (GraphExecutor::InNode *) GetGraphNode( NodeName )->GetInNode() ;
1388 aret = anInNode->IsReady() ;
1390 // cdebug_out << "GraphExecutor::OutNode::IsReady" << endl ;
1394 bool GraphExecutor::OutNode::IsRunning( const char * NodeName ) {
1396 // cdebug_in << "GraphExecutor::OutNode::IsRunning " << NodeName << endl;
1397 GraphExecutor::InNode *anInNode = (GraphExecutor::InNode *) GetGraphNode( NodeName )->GetInNode() ;
1399 aret = anInNode->IsRunning() ;
1401 // cdebug_out << "GraphExecutor::OutNode::IsRunning" << endl ;
1405 bool GraphExecutor::OutNode::IsDone( const char * NodeName ) {
1407 // cdebug_in << "GraphExecutor::OutNode::IsDone " << NodeName << endl;
1408 GraphExecutor::InNode *anInNode = (GraphExecutor::InNode *) GetGraphNode( NodeName )->GetInNode() ;
1410 aret = anInNode->IsDone() ;
1412 // cdebug_out << "GraphExecutor::OutNode::IsDone" << endl ;
1416 bool GraphExecutor::OutNode::IsSuspended( const char * NodeName ) {
1418 // cdebug_in << "GraphExecutor::OutNode::IsSuspended " << NodeName << endl;
1419 GraphExecutor::InNode *anInNode = (GraphExecutor::InNode *) GetGraphNode( NodeName )->GetInNode() ;
1421 aret = anInNode->IsSuspended() ;
1423 // cdebug_out << "GraphExecutor::OutNode::IsSuspended" << endl ;
1427 bool GraphExecutor::OutNode::IsDone( const char * NodeName ,
1428 const char * ServiceParameterName ) {
1429 // cdebug_in << "GraphExecutor::OutNode::IsDone " << NodeName << " "
1430 // << ServiceParameterName<< endl;
1431 bool aret = PortDone( NodeName , ServiceParameterName ) ;
1432 // cdebug_out << "GraphExecutor::OutNode::IsDone" << endl ;
1436 bool GraphExecutor::OutNode::ContainerKill() {
1437 bool RetVal = true ;
1438 cdebug_in << "GraphExecutor::OutNode::ContainerKill" << endl;
1439 _ControlState = SUPERV::ToSuspendState ;
1441 for ( i = 0 ; i < GraphNodesSize() ; i++ ) {
1442 GraphExecutor::InNode * aNode = (GraphExecutor::InNode * ) GraphNodes( i )->GetInNode() ;
1443 bool sts = aNode->ContainerKill() ;
1444 if ( sts && aNode->IsKilled() ) {
1445 cdebug << aNode->Name() << " killed" << endl ;
1447 else if ( aNode->IsWaiting() || aNode->IsDone() ) {
1448 cdebug << aNode->Name() << " not killed : "
1449 << theAutomaton->StateName( aNode->State() ) << endl ;
1452 cdebug << aNode->Name() << " cannot be killed : "
1453 << theAutomaton->StateName( aNode->State() ) << endl ;
1457 if ( !RetVal || Threads() != 0 ) {
1458 for ( i = 0 ; i < GraphNodesSize() ; i++ ) {
1459 GraphExecutor::InNode * aNode = (GraphExecutor::InNode * ) GraphNodes( i )->GetInNode() ;
1460 if ( !aNode->IsKilled() && !aNode->IsWaiting() && !aNode->IsDone() ) {
1461 aNode->KilledAction() ;
1466 State( SUPERV::KilledState ) ;
1467 cdebug_out << "GraphExecutor::OutNode::ContainerKill" << endl ;
1471 bool GraphExecutor::OutNode::Suspend() {
1472 bool RetVal = false ;
1473 cdebug_in << "GraphExecutor::OutNode::Suspend" << endl;
1474 _ControlState = SUPERV::ToSuspendState ;
1476 for ( i = 0 ; i < GraphNodesSize() ; i++ ) {
1477 GraphExecutor::InNode * aNode = (GraphExecutor::InNode * ) GraphNodes( i )->GetInNode() ;
1478 bool sts = aNode->Suspend() ;
1479 if ( sts && aNode->IsSuspended() ) {
1480 cdebug << aNode->Name() << " Suspend" << endl ;
1482 else if ( aNode->IsWaiting() || aNode->IsDone() ) {
1483 cdebug << aNode->Name() << " not Suspended : "
1484 << theAutomaton->StateName( aNode->State() ) << endl ;
1487 cdebug << aNode->Name() << " cannot be Suspended : "
1488 << theAutomaton->StateName( aNode->State() ) << endl ;
1492 State( SUPERV::SuspendedState ) ;
1493 cdebug_out << "GraphExecutor::OutNode::Suspend" << endl ;
1496 bool GraphExecutor::OutNode::Resume() {
1497 bool RetVal = false ;
1498 cdebug_in << "GraphExecutor::OutNode::Resume" << endl;
1499 cdebug_out << "GraphExecutor::OutNode::Resume" << endl ;
1503 bool GraphExecutor::OutNode::Kill() {
1504 bool RetVal = true ;
1505 cdebug_in << "GraphExecutor::OutNode::Kill" << endl;
1506 _ControlState = SUPERV::ToSuspendState ;
1508 for ( i = 0 ; i < GraphNodesSize() ; i++ ) {
1509 GraphExecutor::InNode * aNode = (GraphExecutor::InNode * ) GraphNodes( i )->GetInNode() ;
1510 bool sts = aNode->Kill() ;
1511 if ( sts && aNode->IsKilled() ) {
1512 cdebug << aNode->Name() << " killed" << endl ;
1514 else if ( aNode->IsWaiting() || aNode->IsDone() ) {
1515 cdebug << aNode->Name() << " not killed : "
1516 << theAutomaton->StateName( aNode->State() ) << endl ;
1519 cdebug << aNode->Name() << " cannot be killed : "
1520 << theAutomaton->StateName( aNode->State() ) << endl ;
1524 if ( !RetVal || Threads() != 0 ) {
1525 for ( i = 0 ; i < GraphNodesSize() ; i++ ) {
1526 GraphExecutor::InNode * aNode = (GraphExecutor::InNode * ) GraphNodes( i )->GetInNode() ;
1527 if ( !aNode->IsKilled() && !aNode->IsWaiting() && !aNode->IsDone() ) {
1528 aNode->KilledAction() ;
1533 State( SUPERV::KilledState ) ;
1534 cdebug_out << "GraphExecutor::OutNode::Kill" << endl ;
1538 bool GraphExecutor::OutNode::Stop() {
1539 bool RetVal = false ;
1540 cdebug_in << "GraphExecutor::OutNode::Stop" << endl;
1542 cdebug_out << "GraphExecutor::OutNode::Stop" << endl ;
1545 bool GraphExecutor::OutNode::ReRun() {
1546 bool RetVal = false ;
1547 cdebug_in << "GraphExecutor::OutNode::ReRun" << endl;
1548 if ( IsSuspended() ) {
1550 cdebug_out << "GraphExecutor::OutNode::ReRun" << endl ;
1553 bool GraphExecutor::OutNode::ReStart() {
1554 bool RetVal = false ;
1555 cdebug_in << "GraphExecutor::OutNode::ReStart" << endl;
1556 if ( IsSuspended() ) {
1558 cdebug_out << "GraphExecutor::OutNode::ReStart" << endl ;
1562 bool GraphExecutor::OutNode::ReadyWait() {
1563 cdebug_in << "GraphExecutor::OutNode::ReadyWait" << endl;
1565 if ( pthread_mutex_lock( &_MutexWait ) ) {
1566 perror("pthread_mutex_lock _ReadyWait") ;
1572 pthread_cond_wait( &_EventWait , &_MutexWait );
1575 if ( pthread_mutex_unlock( &_MutexWait ) ) {
1576 perror("pthread_mutex_lock _ReadyWait") ;
1579 cdebug_out << "GraphExecutor::OutNode::ReadyWait" << endl ;
1583 bool GraphExecutor::OutNode::RunningWait() {
1584 cdebug_in << "GraphExecutor::OutNode::RunningWait" << endl;
1586 if ( pthread_mutex_lock( &_MutexWait ) ) {
1587 perror("pthread_mutex_lock _RunningWait") ;
1590 aret = IsRunning() ;
1592 cdebug << "RunningWait pthread_cond_wait _EventWait" << endl;
1593 pthread_cond_wait( &_EventWait , &_MutexWait );
1594 aret = IsRunning() ;
1595 cdebug << "RunningWait pthread_cond_waited _EventWait " << aret << endl;
1597 if ( pthread_mutex_unlock( &_MutexWait ) ) {
1598 perror("pthread_mutex_lock _RunningWait") ;
1601 cdebug_out << "GraphExecutor::OutNode::RunningWait " << aret << endl ;
1605 bool GraphExecutor::OutNode::DoneWait() {
1606 cdebug_in << "GraphExecutor::OutNode::DoneWait" << endl;
1608 if ( pthread_mutex_lock( &_MutexWait ) ) {
1609 perror("pthread_mutex_lock _DoneWait") ;
1613 while ( !aret && !IsSuspended() ) {
1614 cdebug << "DoneWait pthread_cond_wait _EventWait" << endl;
1615 pthread_cond_wait( &_EventWait , &_MutexWait );
1617 cdebug << "DoneWait pthread_cond_waited _EventWait " << aret << endl;
1619 if ( pthread_mutex_unlock( &_MutexWait ) ) {
1620 perror("pthread_mutex_lock _DoneWait") ;
1623 cdebug_out << "GraphExecutor::OutNode::DoneWait " << aret << endl ;
1627 bool GraphExecutor::OutNode::SuspendedWait() {
1628 cdebug_in << "GraphExecutor::OutNode::SuspendedWait" << endl;
1630 if ( pthread_mutex_lock( &_MutexWait ) ) {
1631 perror("pthread_mutex_lock _SuspendedWait") ;
1634 aret = IsSuspended() ;
1635 while ( !aret && !_Done ) {
1636 pthread_cond_wait( &_EventWait , &_MutexWait );
1637 aret = IsSuspended() ;
1639 if ( pthread_mutex_unlock( &_MutexWait ) ) {
1640 perror("pthread_mutex_lock _SuspendedWait") ;
1643 cdebug_out << "GraphExecutor::OutNode::SuspendedWait" << endl ;
1647 bool GraphExecutor::OutNode::ReadyWait( const char * NodeName ) {
1649 cdebug_in << "GraphExecutor::OutNode::ReadyWait " << NodeName << endl;
1650 GraphExecutor::InNode *anInNode = (GraphExecutor::InNode *) GetGraphNode( NodeName )->GetInNode() ;
1652 aret = anInNode->ReadyWait() ;
1654 cdebug_out << "GraphExecutor::OutNode::ReadyWait" << endl ;
1658 bool GraphExecutor::OutNode::RunningWait( const char * NodeName ) {
1660 cdebug_in << "GraphExecutor::OutNode::RunningWait " << NodeName << endl;
1661 GraphExecutor::InNode *anInNode = (GraphExecutor::InNode *) GetGraphNode( NodeName )->GetInNode() ;
1663 aret = anInNode->RunningWait() ;
1665 cdebug_out << "GraphExecutor::OutNode::RunningWait" << endl ;
1669 bool GraphExecutor::OutNode::DoneWait( const char * NodeName ) {
1671 cdebug_in << "GraphExecutor::OutNode::DoneWait " << NodeName << endl;
1672 GraphExecutor::InNode *anInNode = (GraphExecutor::InNode *) GetGraphNode( NodeName )->GetInNode() ;
1674 aret = anInNode->DoneWait() ;
1676 cdebug_out << "GraphExecutor::OutNode::DoneWait" << endl ;
1680 bool GraphExecutor::OutNode::SuspendedWait( const char * NodeName ) {
1682 cdebug_in << "GraphExecutor::OutNode::SuspendedWait " << NodeName << endl;
1683 GraphExecutor::InNode *anInNode = (GraphExecutor::InNode *) GetGraphNode( NodeName )->GetInNode() ;
1685 aret = anInNode->SuspendedWait() ;
1687 cdebug_out << "GraphExecutor::OutNode::SuspendedWait" << endl ;
1691 long GraphExecutor::OutNode::LastLevelDone() {
1694 for ( i = 0 ; i <= LevelMax() ; i++ ) {
1695 for ( j = 0 ; j <= NodesNumber( i ) ; j++ ) {
1696 GraphBase::ComputingNode * aNode = SortedNodes( i , j ) ;
1697 if ( !IsDone( aNode->Name() ) ) {
1701 if ( j != NodesNumber( i ) + 1 )
1709 const CORBA::Any *GraphExecutor::OutNode::GetInData(
1710 const char * NodeName ,
1711 const char * ServiceParameterName ) {
1712 // cdebug_in << "GraphExecutor::OutNode::GetInData " << NodeName << " "
1713 // << ServiceParameterName << endl ;
1714 const CORBA::Any * retdata = PortInData( NodeName , ServiceParameterName ) ;
1715 // cdebug_out << "GraphExecutor::OutNode::GetInData" << endl ;
1719 const CORBA::Any *GraphExecutor::OutNode::GetOutData(
1720 const char * NodeName ,
1721 const char * ServiceParameterName ) {
1722 // cdebug_in << "GraphExecutor::OutNode::GetOutData " << NodeName << " "
1723 // << ServiceParameterName << endl ;
1724 const CORBA::Any * retdata = PortOutData( NodeName , ServiceParameterName ) ;
1725 // cdebug_out << "GraphExecutor::OutNode::GetOutData" << endl ;