1 // SUPERV GraphExecutor : contains classes that permit execution of graphs and particularly the execution automaton
3 // Copyright (C) 2003 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
6 // This library is free software; you can redistribute it and/or
7 // modify it under the terms of the GNU Lesser General Public
8 // License as published by the Free Software Foundation; either
9 // version 2.1 of the License.
11 // This library is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 // Lesser General Public License for more details.
16 // You should have received a copy of the GNU Lesser General Public
17 // License along with this library; if not, write to the Free Software
18 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20 // See http://www.opencascade.org/SALOME/ or email : webmaster.salome@opencascade.org
24 // File : DataFlowBase_OutNode.cxx
25 // Author : Jean Rahuel, CEA
31 #include "DataFlowExecutor_OutNode.hxx"
33 // Implementation de la classe GraphEditor::GraphControl
35 extern GraphExecutor::FiniteStateMachine * theAutomaton ;
37 // static const char *ComponentName = "SalomeSuperVisionComponent" ;
40 extern char ** _ArgV ;
42 GraphExecutor::OutNode::OutNode() :
48 _ControlState = SUPERV::VoidState ;
49 _State = SUPERV::UnKnownState ;
50 _PyInitialized = false ;
51 pthread_mutex_init( &_MutexWait , NULL ) ;
52 pthread_mutex_init( &_PyMutexWait , 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 )") ;
63 GraphExecutor::OutNode::OutNode( CORBA::ORB_ptr ORB,
64 SALOME_NamingService* ptrNamingService ,
65 const char *DataFlowName ,
66 const char * DebugFileName ) :
67 Graph( ORB , ptrNamingService , DataFlowName , DebugFileName ) {
68 cdebug_in << "GraphEditor::OutNode::OutNode(" << DataFlowName << ")" << endl;
73 _ControlState = SUPERV::VoidState ;
74 _State = SUPERV::UnKnownState ;
75 _PyInitialized = false ;
76 _Orb = CORBA::ORB::_duplicate( ORB ) ;
77 pthread_mutex_init( &_MutexWait , NULL ) ;
78 pthread_mutex_init( &_PyMutexWait , NULL ) ;
79 if ( pthread_cond_init( &_EventWait , NULL ) ) {
80 perror("pthread_cond_init( &_EventWait , NULL )") ;
83 if ( pthread_cond_init( &_JoinWait , NULL ) ) {
84 perror("pthread_cond_init( &_JoinWait , NULL )") ;
87 cdebug_out << "GraphEditor::OutNode::OutNode" << endl;
90 GraphExecutor::OutNode::OutNode(
92 SALOME_NamingService* ptrNamingService ,
93 const SALOME_ModuleCatalog::Service& DataFlowService ,
94 const char *DataFlowComponentName ,
95 const char *DataFlowInterfaceName ,
96 const char *DataFlowName ,
97 const SUPERV::KindOfNode DataFlowkind ,
98 const SUPERV::SDate DataFlowFirstCreation ,
99 const SUPERV::SDate DataFlowLastModification ,
100 const char * DataFlowEditorRelease ,
101 const char * DataFlowAuthor ,
102 const char * DataFlowComputer ,
103 const char * DataFlowComment ,
104 const char * DebugFileName ) :
105 Graph( ORB , ptrNamingService , DataFlowService , DataFlowComponentName ,
106 DataFlowInterfaceName , DataFlowName , DataFlowkind ,
107 DataFlowFirstCreation , DataFlowLastModification ,
108 DataFlowEditorRelease , DataFlowAuthor ,
109 DataFlowComputer , DataFlowComment , DebugFileName ) {
111 _Executable = false ;
114 _ControlState = SUPERV::VoidState ;
115 _State = SUPERV::UnKnownState ;
116 _PyInitialized = false ;
117 _Orb = CORBA::ORB::_duplicate( ORB ) ;
118 pthread_mutex_init( &_MutexWait , NULL ) ;
119 pthread_mutex_init( &_PyMutexWait , NULL ) ;
120 if ( pthread_cond_init( &_EventWait , NULL ) ) {
121 perror("pthread_cond_init( &_EventWait , NULL )") ;
124 if ( pthread_cond_init( &_JoinWait , NULL ) ) {
125 perror("pthread_cond_init( &_JoinWait , NULL )") ;
130 GraphExecutor::OutNode::~OutNode() {
133 bool GraphExecutor::OutNode::LoadDataFlow(const GraphBase::SGraph &aDataFlow ) {
134 bool RetVal = false ;
135 RetVal = LoadInfo( aDataFlow.Info ) ;
136 if ( GraphBase::Service::ServiceName() != NULL ) {
137 // MESSAGE( "GraphExecutor::OutNode::LoadDataFlow" );
139 RetVal = LoadNodes( aDataFlow.Nodes ) ;
141 RetVal = LoadLinks( aDataFlow.Links ) ;
144 RetVal = LoadDatas( aDataFlow.Datas ) ;
147 cdebug << "GraphExecutor::OutNode::LoadDataFlow LoadDatas Error."
152 cdebug << "GraphExecutor::OutNode::LoadDataFlow LoadLinks Error."
157 cdebug << "GraphExecutor::OutNode::LoadDataFlow LoadNodes Error."
162 cdebug << "GraphExecutor::OutNode::LoadDataFlow LoadInfo Error."
167 cdebug << "GraphExecutor::OutNode::LoadDataFlow ServiceName Error." << endl ;
172 bool GraphExecutor::OutNode::LoadXml( const char* myFileName ) {
173 bool RetVal = false ;
174 GraphBase::SGraph aDataFlow ;
175 if ( GraphBase::Graph::LoadXml( _Orb , myFileName , aDataFlow ) ) {
176 RetVal = LoadDataFlow( aDataFlow ) ;
177 // if ( aConstructor && RetVal )
178 // RetVal = Name( aDataFlow.Info.theName.c_str() ) ;
183 bool GraphExecutor::OutNode::LoadInfo(const GraphBase::SNode &aDataFlowInfo ) {
184 cdebug << "GraphExecutor::OutNode::LoadInfo" << endl ;
185 // ComponentName( aDataFlowInfo.theComponentName.c_str() ) ;
186 Name( aDataFlowInfo.theName.c_str() ) ;
187 Kind( aDataFlowInfo.theKind ) ;
188 DataService( _Orb , aDataFlowInfo.theService , Graph_prof_debug() , Graph_fdebug() ) ;
189 FirstCreation( aDataFlowInfo.theFirstCreation ) ;
190 LastModification( aDataFlowInfo.theLastModification ) ;
191 EditorRelease( aDataFlowInfo.theEditorRelease.c_str() ) ;
192 Author( aDataFlowInfo.theAuthor.c_str() ) ;
193 // Computer( aDataFlowInfo.theContainer.c_str() ) ;
194 Comment( aDataFlowInfo.theComment.c_str() ) ;
195 // Not in OutNode/DataFlow but in InNode/DataFlow_in_an_other_DataFlow
196 // Coordinates( aDataFlowInfo.theX , aDataFlowInfo.theY ) ;
200 bool GraphExecutor::OutNode::LoadNodes(const GraphBase::ListOfNodes &aListOfNodes ) {
202 GraphExecutor::InNode * anInNode ;
203 cdebug << "GraphExecutor::OutNode::LoadNodes" << endl ;
205 for ( i = 0 ; i < (int ) aListOfNodes.size() ; i++ ) {
206 GraphBase::SNode aNode = aListOfNodes[ i ] ;
207 anInNode = AddNode( aNode.theService ,
208 aNode.theListOfFuncName ,
209 aNode.theListOfPythonFunctions ,
210 aNode.theComponentName.c_str() ,
211 aNode.theInterfaceName.c_str() , aNode.theName.c_str() ,
213 aNode.theFirstCreation , aNode.theLastModification ,
214 aNode.theEditorRelease.c_str() ,
215 aNode.theAuthor.c_str() , aNode.theContainer.c_str() ,
216 aNode.theComment.c_str() ,
217 aNode.theCoords.theX , aNode.theCoords.theY ) ;
222 if ( anInNode->IsOneOfInLineNodes() ) {
223 anInNode->GraphExecutor::InNode::InLineNode()->DefPortsOfNode(
224 _Orb , aNode.theService , anInNode->NamePtr() ,
226 Graph_prof_debug() , Graph_fdebug() ) ;
228 GraphBase::InLineNode * aINode = anInNode->InLineNode() ;
229 GraphBase::LoopNode * aLNode = NULL ;
230 if ( aINode->IsLoopNode() ) {
231 aLNode = anInNode->LoopNode() ;
232 aLNode->SetPythonFunction( aNode.theListOfFuncName[ 0 ].c_str() ,
233 *aNode.theListOfPythonFunctions[ 0 ] ) ;
234 aLNode->SetMorePythonFunction( aNode.theListOfFuncName[ 1 ].c_str() ,
235 *aNode.theListOfPythonFunctions[ 1 ] ) ;
236 aLNode->SetNextPythonFunction( aNode.theListOfFuncName[ 2 ].c_str() ,
237 *aNode.theListOfPythonFunctions[ 2 ] ) ;
239 else if ( aINode->IsInLineNode() || aINode->IsGOTONode() ||
240 aINode->IsSwitchNode() || aINode->IsEndSwitchNode() ) {
241 aINode->SetPythonFunction( aNode.theListOfFuncName[ 0 ].c_str() ,
242 *aNode.theListOfPythonFunctions[ 0 ] ) ;
247 if ( aNode.theListOfParameters.size() ) { // BusPorts ...
249 for ( j = 0 ; j < aNode.theListOfParameters.size() ; j++ ) {
250 GraphBase::InPort * InputPort = anInNode->AddInPort(
251 aNode.theListOfParameters[ j ].theInParameter.Parametername ,
252 aNode.theListOfParameters[ j ].theInParameter.Parametertype ) ;
253 GraphBase::OutPort * OutputPort = anInNode->AddOutPort(
254 aNode.theListOfParameters[ j ].theOutParameter.Parametername ,
255 aNode.theListOfParameters[ j ].theOutParameter.Parametertype ) ;
256 anInNode->InOutPort( InputPort , OutputPort ) ;
261 for ( i = 0 ; i < (int ) aListOfNodes.size() ; i++ ) {
262 GraphBase::SNode aNode = aListOfNodes[ i ] ;
263 anInNode = (GraphExecutor::InNode * ) GetChangeGraphNode( aNode.theName.c_str() )->GetInNode() ;
264 cdebug << "GraphExecutor::OutNode::LoadNodes " << anInNode->Name() << "IsOneOfGOTONodes "
265 << anInNode->IsOneOfGOTONodes() << " " << aNode.theCoupledNode.c_str() << endl ;
266 if ( anInNode->IsOneOfGOTONodes() && strlen( aNode.theCoupledNode.c_str() ) ) {
267 GraphBase::GOTONode * aCoupledNode ;
268 aCoupledNode = (GraphBase::GOTONode * ) GetGraphNode( aNode.theName.c_str() ) ;
269 aCoupledNode->CoupledNode( (GraphBase::GOTONode * ) GetChangeGraphNode( aNode.theCoupledNode.c_str() ) ) ;
275 bool GraphExecutor::OutNode::LoadLinks(const GraphBase::ListOfLinks &aListOfLinks ) {
277 cdebug << "GraphExecutor::OutNode::LoadLinks " << aListOfLinks.size()
280 for ( i = 0 ; i < (int ) aListOfLinks.size() ; i++ ) {
281 GraphBase::SLink aLink = aListOfLinks[ i ] ;
282 RetVal = AddLink( aLink.FromNodeName.c_str() ,
283 aLink.FromServiceParameterName.c_str() ,
284 aLink.ToNodeName.c_str() ,
285 aLink.ToServiceParameterName.c_str() ,
287 // aLink.aLinkValue.Value , aLink.aLinkValue.Kind ) ;
294 bool GraphExecutor::OutNode::LoadDatas(const GraphBase::ListOfLinks &aListOfDatas ) {
296 cdebug << "GraphExecutor::OutNode::LoadDatas " << aListOfDatas.size()
299 for ( i = 0 ; i < (int ) aListOfDatas.size() ; i++ ) {
300 GraphBase::SLink aLink = aListOfDatas[ i ] ;
301 if ( !strcmp( aLink.FromNodeName.c_str() , Name() ) )
302 RetVal = GraphBase::Graph::AddInputData( aLink.ToNodeName.c_str() ,
303 aLink.ToServiceParameterName.c_str() ,
305 // aLink.aLinkValue.Value , aLink.aLinkValue.Kind ) ;
306 else if ( !strcmp( aLink.ToNodeName.c_str() , Name() ) ) {
307 RetVal = AddOutputData( aLink.FromNodeName.c_str() ,
308 aLink.FromServiceParameterName.c_str() ,
310 // aLink.aLinkValue.Value ,
311 // aLink.aLinkValue.Kind ) ;
312 AddLink( aLink.FromNodeName.c_str() , (GraphBase::ComputingNode *) this ) ;
315 cdebug << "GraphExecutor::OutNode::LoadDatas Error " << aLink.FromNodeName
316 << " and " << aLink.ToNodeName << " differents from " << Name()
326 GraphExecutor::InNode *GraphExecutor::OutNode::AddNode(
327 const SALOME_ModuleCatalog::Service& NodeService ,
328 GraphBase::ListOfFuncName aFuncName ,
329 GraphBase::ListOfPythonFunctions aPythonFunction ,
330 const char * NodeComponentName ,
331 const char * NodeInterfaceName ,
332 const char * NodeName ,
333 const SUPERV::KindOfNode NodeKindOfNode ,
334 const SUPERV::SDate NodeFirstCreation ,
335 const SUPERV::SDate NodeLastModification ,
336 const char * NodeEditorRelease ,
337 const char * NodeAuthor ,
338 const char * NodeComputer ,
339 const char * NodeComment ,
342 cdebug_in << "GraphExecutor::OutNode::AddNode(" << NodeComponentName << " , "
343 << NodeName << ")" << endl;
344 GraphExecutor::InNode *Nd = NULL ;
345 Nd = new GraphExecutor::InNode( _Orb, NamingService() , NodeService ,
346 NodeComponentName , NodeInterfaceName ,
347 NodeName , NodeKindOfNode ,
348 aFuncName , aPythonFunction ,
349 NodeFirstCreation , NodeLastModification ,
350 NodeEditorRelease , NodeAuthor ,
351 NodeComputer , NodeComment , false , NodeX , NodeY ,
352 Graph_prof_debug() , Graph_fdebug() ) ;
353 GraphBase::Graph::AddNode( Nd->ComputingNode() ) ;
354 cdebug_out << "GraphExecutor::OutNode::AddNode" << endl;
359 bool GraphExecutor::OutNode::AddInputData( const char* ToNodeName1 ,
360 const char* ToParameterName1 ,
361 const char* ToNodeName2 ,
362 const char* ToParameterName2 ) {
363 cdebug_in << "GraphExecutor::OutNode::AddInputData" << endl;
364 bool RetVal = GraphBase::Graph::AddInputData( ToNodeName1 ,
368 cdebug_out << "GraphExecutor::OutNode::AddInputData" << endl;
373 bool GraphExecutor::OutNode::Valid() {
374 cdebug_in << "GraphExecutor::OutNode::Valid" << endl;
379 _Executable = false ;
381 if ( !CreateService() ) {
382 cdebug << "This DataFlow has invalid type(s)." << endl ;
387 cdebug << "This DataFlow is not valid." << endl ;
399 cdebug_out << "GraphExecutor::OutNode::Valid" << endl;
404 bool GraphExecutor::OutNode::Executable() {
406 cdebug_in << "GraphExecutor::OutNode::Executable" << endl;
410 if ( DataServerNodes() )
413 cdebug << "This DataFlow is not executable." << endl ;
414 _Executable = false ;
417 cdebug_out << "GraphExecutor::OutNode::Executable" << endl;
421 bool GraphExecutor::OutNode::Run( const bool AndSuspend ) {
422 bool RetVal = false ;
423 cdebug_in << "GraphExecutor::OutNode::Run" << endl;
425 if ( Executable() ) {
426 _ControlState = SUPERV::VoidState ;
427 _SuspendedThreads = 0 ;
428 ThreadNo( pthread_self() ) ;
430 _JustStarted = true ;
432 for ( i = 0 ; i < GraphNodesSize() ; i++ ) {
433 GraphExecutor::InNode * anInNode = (GraphExecutor::InNode *) GraphNodes( i )->GetInNode() ;
434 if ( !PyInitialized() && anInNode->IsOneOfInLineNodes() ) {
435 if ( !Py_IsInitialized() ) {
437 PySys_SetArgv( _ArgC , _ArgV ) ;
439 anInNode->InitPython() ;
440 PyInitialized( true ) ;
442 anInNode->InitialState( this ) ;
445 cdebug << "Execution starting GraphExecutor::Action_DataOk_RunService Node "
448 PushEvent( NULL , GraphExecutor::ReadyEvent ,
449 SUPERV::DataReadyState ) ;
450 State( SUPERV::DataReadyState ) ;
452 for ( i = 0 ; i < HeadNodesSize() ; i++ ) {
453 GraphExecutor::InNode * anInNode = (GraphExecutor::InNode *) HeadNodes( i )->GetInNode() ;
454 if ( anInNode->State() != SUPERV::DataReadyState ) {
455 cdebug << "GraphExecutor::OutNode::Run inconsistency State of Node "
456 << anInNode->Name() << " : " << anInNode->State() << endl ;
459 // PushEvent( anInNode , GraphExecutor::ReadyEvent ,
460 // SUPERV::DataReadyState ) ;
461 anInNode->CreateNewThread( true ) ;
462 anInNode->DataFromNode( Name() ) ;
464 anInNode->State( SUPERV::DataWaitingState ) ;
465 anInNode->ControlState( SUPERV::ToSuspendStartState ) ;
466 if ( !anInNode->SendEvent( GraphExecutor::SomeDataReadyEvent ) ) {
467 cdebug << "InNode::SendEvent( SomeDataReadyEvent ) ERROR Node "
468 << anInNode->Name() << endl ;
471 anInNode->SuspendedWait() ;
473 else if ( !anInNode->SendEvent( GraphExecutor::ExecuteEvent ) ) {
474 cdebug << "InNode::SendEvent( ExecuteEvent ) ERROR Node "
475 << anInNode->Name() << endl ;
479 anInNode->RunningWait() ;
484 PushEvent( NULL , GraphExecutor::SuspendedReadyEvent ,
485 SUPERV::SuspendedReadyState ) ;
488 PushEvent( NULL , GraphExecutor::ExecutingEvent ,
489 SUPERV::ExecutingState ) ;
490 if (AutomatonState() == SUPERV::DataReadyState) {
491 State( SUPERV::ExecutingState ) ;
498 PushEvent( NULL , GraphExecutor::NoDataReadyEvent ,
499 SUPERV::DataUndefState ) ;
502 cdebug_out << "GraphExecutor::OutNode::Run" << endl ;
506 bool GraphExecutor::OutNode::Run( const char * aNodeName ,
507 const char * AtNodeName ,
508 const bool AndSuspend ) {
509 bool RetVal = false ;
510 cdebug_in << "GraphExecutor::OutNode::Run( " << aNodeName << " , "
511 << AtNodeName << " , " << AndSuspend << ")" << endl;
512 GraphExecutor::InNode *anInNode = (GraphExecutor::InNode *) GetGraphNode( aNodeName )->GetInNode() ;
514 RetVal = anInNode->ReStart( AtNodeName , AndSuspend ) ;
516 cdebug_out << "GraphExecutor::OutNode::Run" << endl ;
520 void GraphExecutor::OutNode::CheckAllDone() {
522 cdebug_in << "GraphExecutor::OutNode::CheckAllDone " << endl;
523 SUPERV::AutomatonState OutNodeState = SUPERV::SuccessedState ;
524 SUPERV::AutomatonState InNodeState ;
525 bool AllDone = true ;
527 for ( j = 0 ; j < QueueNodesSize() ; j++ ) {
528 InNodeState = ( (GraphExecutor::InNode * ) QueueNodes( j )->GetInNode() )->State() ;
530 << ( (GraphExecutor::InNode * ) QueueNodes( j )->GetInNode() )->Name()
531 << " " << theAutomaton->StateName( InNodeState ) << endl ;
532 if ( InNodeState != SUPERV::SuccessedState &&
533 InNodeState != SUPERV::ErroredState &&
534 InNodeState != SUPERV::DataWaitingState ) {
537 if ( InNodeState != SUPERV::SuccessedState ) {
538 OutNodeState = InNodeState ;
542 if( _Threads == 0 && _SuspendedThreads == 0 ) {
543 if ( OutNodeState != SUPERV::ErroredState ) {
544 OutNodeState = SUPERV::SuccessedState ;
552 State( OutNodeState ) ;
554 _JustStarted = false ;
555 for ( j = 0 ; j < GraphNodesSize() ; j++ ) {
556 GraphExecutor::InNode * aNode ;
557 aNode = (GraphExecutor::InNode * ) GraphNodes( j )->GetInNode() ;
558 SUPERV::GraphState aState = AutomatonGraphState( aNode->State() ) ;
559 cdebug << "GraphExecutor::OutNode::CheckAllDone " << aNode->Name() << " "
560 << theAutomaton->StateName( aNode->State() ) << " :" << endl ;
561 if ( aState == SUPERV::ErrorState ||
562 aState == SUPERV::SuspendErroredState ||
563 aState == SUPERV::KillState ||
564 aState == SUPERV::StopState ) {
565 OutNodeState = aNode->State() ;
567 aNode->SuspendedAction() ;
568 aNode->DoneAction() ;
570 // PushEvent AFTER State and _Done ! ...
571 PushEvent( NULL , GraphExecutor::EndExecuteEvent ,
574 // PyInitialized( false ) ;
577 cdebug_out << "GraphExecutor::OutNode::CheckAllDone " << _Done
578 << " GraphAutomatonState " << theAutomaton->StateName( AutomatonState() )
579 << " State " << State() << " Threads " << _Threads << " SuspendedThreads "
580 << _SuspendedThreads << endl ;
582 MESSAGE("================================================================================") ;
583 MESSAGE( Name() << " IS DONE" ) ;
584 MESSAGE("================================================================================") ;
588 void GraphExecutor::OutNode::PThreadLock( pthread_mutex_t * aMutex , char * errmsg ) {
589 // if ( strcmp( errmsg , "EventLoop" ) && strcmp( errmsg , "EventW" ) ) {
590 // cdebug << "GraphExecutor::OutNode::PThreadLock " << pthread_self() << " " << aMutex << " "
591 // << errmsg << endl ;
593 if ( pthread_mutex_lock( aMutex ) ) {
597 // if ( strcmp( errmsg , "EventLoop" ) && strcmp( errmsg , "EventW" ) ) {
598 // cdebug << "GraphExecutor::OutNode::PThreadLocked " << pthread_self() << " " << aMutex << " "
599 // << errmsg << endl ;
603 void GraphExecutor::OutNode::PThreadUnLock( pthread_mutex_t * aMutex , char * errmsg ) {
604 // if ( strcmp( errmsg , "EventLoop" ) && strcmp( errmsg , "EventW" ) ) {
605 // cdebug << " GraphExecutor::OutNode::PThreadUnLock " << pthread_self() << " " << aMutex << " "
606 // << errmsg << endl ;
608 if ( pthread_mutex_unlock( aMutex ) ) {
614 void GraphExecutor::OutNode::PyThreadLock() {
615 // cout << " GraphExecutor::OutNode::PyThreadLock " << pthread_self() << endl ;
616 if ( pthread_mutex_lock( &_PyMutexWait ) ) {
617 perror( "GraphExecutor::OutNode::PyThreadLock" ) ;
620 // cout << " GraphExecutor::OutNode::PyThreadLocked " << pthread_self() << endl ;
623 void GraphExecutor::OutNode::PyThreadUnLock() {
624 // cout << " GraphExecutor::OutNode::PyThreadUnLock " << pthread_self() << endl ;
625 if ( pthread_mutex_unlock( &_PyMutexWait ) ) {
626 perror( "GraphExecutor::OutNode::PyThreadUnLock" ) ;
629 // cout << " GraphExecutor::OutNode::PyThreadUnLocked " << pthread_self() << endl ;
632 void GraphExecutor::OutNode::NewThread() {
633 if ( pthread_mutex_lock( &_MutexWait ) ) {
634 perror("pthread_mutex_lock _NewThread") ;
638 cdebug << "NewThread : " << _Threads << " running threads "
639 << _SuspendedThreads << " suspended threads"
641 if ( pthread_mutex_unlock( &_MutexWait ) ) {
642 perror("pthread_mutex_unlock _NewThread") ;
646 void GraphExecutor::OutNode::ExitThread() {
647 if ( pthread_mutex_lock( &_MutexWait ) ) {
648 perror("pthread_mutex_lock _ExitThread") ;
652 theAutomaton->JoinThread( pthread_self() ) ;
653 if ( pthread_cond_signal( &_JoinWait ) ) {
654 perror("ExitThread pthread_cond_signal ") ;
656 cdebug << "ExitThread : " << _Threads << " running threads "
657 << _SuspendedThreads << " suspended threads"
659 if ( pthread_mutex_unlock( &_MutexWait ) ) {
660 perror("pthread_mutex_unlock _ExitThread") ;
663 if ( _Threads == 0 && _SuspendedThreads == 0 ) {
667 void GraphExecutor::OutNode::JoinedWait() {
668 if ( pthread_mutex_lock( &_MutexWait ) ) {
669 perror("pthread_mutex_lock JoinedWait") ;
673 if ( pthread_cond_wait( &_JoinWait , &_MutexWait ) ) {
674 perror("JoinedWait pthread_cond_wait ") ;
677 if ( pthread_mutex_unlock( &_MutexWait ) ) {
678 perror("pthread_mutex_unlock JoinedWait") ;
682 void GraphExecutor::OutNode::SuspendThread() {
683 if ( pthread_mutex_lock( &_MutexWait ) ) {
684 perror("pthread_mutex_lock _SuspendThread") ;
687 _SuspendedThreads += 1 ;
688 cdebug << "SuspendThread : " << _Threads << " running threads "
689 << _SuspendedThreads << " suspended threads"
691 if ( pthread_mutex_unlock( &_MutexWait ) ) {
692 perror("pthread_mutex_unlock _SuspendThread") ;
695 if ( IsSuspended() ) {
696 PushEvent( NULL , GraphExecutor::SuspendEvent , SUPERV::SuspendedState ) ;
699 void GraphExecutor::OutNode::ResumeThread() {
700 if ( pthread_mutex_lock( &_MutexWait ) ) {
701 perror("pthread_mutex_lock _ResumeThread") ;
704 _SuspendedThreads -= 1 ;
705 cdebug << "ResumeThread : " << _Threads << " running threads "
706 << _SuspendedThreads << " suspended threads"
708 if ( pthread_mutex_unlock( &_MutexWait ) ) {
709 perror("pthread_mutex_unlock _ResumeThread") ;
714 long GraphExecutor::OutNode::Thread( const char * aNodeName ) {
716 GraphExecutor::InNode *anInNode = (GraphExecutor::InNode *) GetGraphNode( aNodeName )->GetInNode() ;
718 RetVal = anInNode->ThreadNo() ;
723 SUPERV::GraphEvent GraphExecutor::OutNode::AutomatonGraphEvent(GraphExecutor::NodeEvent anEvent ) {
724 SUPERV::GraphEvent aGraphEvent ;
726 case GraphExecutor::UndefinedEvent : {
727 aGraphEvent = SUPERV::UndefinedEvent ;
730 case GraphExecutor::NewThreadEvent : {
731 aGraphEvent = SUPERV::NewThreadEvent ;
734 case GraphExecutor::SuspendEvent : {
735 aGraphEvent = SUPERV::SuspendEvent ;
738 case GraphExecutor::ResumeEvent : {
739 aGraphEvent = SUPERV::ResumeEvent ;
742 case GraphExecutor::KillEvent : {
743 aGraphEvent = SUPERV::KillEvent ;
746 case GraphExecutor::StopEvent : {
747 aGraphEvent = SUPERV::StopEvent ;
750 case GraphExecutor::ExecuteEvent : {
751 aGraphEvent = SUPERV::RunningEvent ;
754 case GraphExecutor::SuccessEvent : {
755 aGraphEvent = SUPERV::DoneEvent ;
758 case GraphExecutor::ErrorEvent : {
759 aGraphEvent = SUPERV::ErroredEvent ;
762 case GraphExecutor::ReStartEvent : {
763 aGraphEvent = SUPERV::ReRunEvent ;
766 case GraphExecutor::ReStartAndSuspendEvent : {
767 aGraphEvent = SUPERV::ReStartEvent ;
770 case GraphExecutor::NoDataReadyEvent : {
771 aGraphEvent = SUPERV::WaitingEvent ;
774 case GraphExecutor::SomeDataReadyEvent : {
775 aGraphEvent = SUPERV::WaitingEvent ;
778 case GraphExecutor::NotAllDataReadyEvent : {
779 aGraphEvent = SUPERV::WaitingEvent ;
782 case GraphExecutor::AllDataReadyEvent : {
783 aGraphEvent = SUPERV::ReadyEvent ;
786 case GraphExecutor::ReadyEvent : {
787 aGraphEvent = SUPERV::ReadyEvent ;
790 case GraphExecutor::SuspendedReadyEvent : {
791 aGraphEvent = SUPERV::SuspendEvent ;
794 case GraphExecutor::ResumedReadyEvent : {
795 aGraphEvent = SUPERV::ResumeEvent ;
798 case GraphExecutor::KilledReadyEvent : {
799 aGraphEvent = SUPERV::KillEvent ;
802 case GraphExecutor::StoppedReadyEvent : {
803 aGraphEvent = SUPERV::StopEvent ;
806 case GraphExecutor::ExecutingEvent : {
807 aGraphEvent = SUPERV::RunningEvent ;
810 case GraphExecutor::SuspendedExecutingEvent : {
811 aGraphEvent = SUPERV::SuspendEvent ;
814 case GraphExecutor::ResumedExecutingEvent : {
815 aGraphEvent = SUPERV::ResumeEvent ;
818 case GraphExecutor::KilledExecutingEvent : {
819 aGraphEvent = SUPERV::KillEvent ;
822 case GraphExecutor::StoppedExecutingEvent : {
823 aGraphEvent = SUPERV::StopEvent ;
826 case GraphExecutor::SuccessedExecutingEvent : {
827 aGraphEvent = SUPERV::DoneEvent ;
830 case GraphExecutor::ErroredExecutingEvent : {
831 aGraphEvent = SUPERV:: ErroredEvent;
834 case GraphExecutor::SuspendedSuccessedEvent : {
835 aGraphEvent = SUPERV::SuspendEvent ;
838 case GraphExecutor::SuspendedErroredEvent : {
839 aGraphEvent = SUPERV::SuspendEvent ;
842 case GraphExecutor::ResumedSuccessedEvent : {
843 aGraphEvent = SUPERV::ResumeEvent ;
846 case GraphExecutor::ResumedErroredEvent : {
847 aGraphEvent = SUPERV::ResumeEvent ;
850 case GraphExecutor::KilledEvent : {
851 aGraphEvent = SUPERV::KillEvent ;
854 case GraphExecutor::StoppedEvent : {
855 aGraphEvent = SUPERV::StopEvent ;
858 case GraphExecutor::ReStartedEvent : {
859 aGraphEvent = SUPERV::ReRunEvent ;
862 case GraphExecutor::ReStartedAndSuspendEvent : {
863 aGraphEvent = SUPERV::ReStartEvent ;
866 case GraphExecutor::EndExecuteEvent : {
867 aGraphEvent = SUPERV::DoneEvent ;
871 cdebug << " GraphExecutor::OutNode::AutomatonGraphEvent Error Undefined Event : "
873 aGraphEvent = SUPERV::UndefinedEvent ;
879 SUPERV::GraphState GraphExecutor::OutNode::AutomatonGraphState(SUPERV::AutomatonState aState ) {
880 SUPERV::GraphState aGraphState ;
882 case SUPERV::UnKnownState : {
883 aGraphState = SUPERV::UndefinedState ;
886 case SUPERV::DataUndefState : {
887 aGraphState = SUPERV::UndefinedState ;
890 case SUPERV::DataWaitingState : {
891 aGraphState = SUPERV::WaitingState ;
894 case SUPERV::DataReadyState : {
895 aGraphState = SUPERV::ReadyState ;
898 case SUPERV::SuspendedReadyState : {
899 aGraphState = SUPERV::SuspendReadyState ;
902 case SUPERV::ResumedReadyState : {
903 aGraphState = SUPERV::ReadyState ;
906 case SUPERV::KilledReadyState : {
907 aGraphState = SUPERV::KillState ;
910 case SUPERV::StoppedReadyState : {
911 aGraphState = SUPERV::StopState ;
914 case SUPERV::ExecutingState : {
915 aGraphState = SUPERV::RunningState ;
918 case SUPERV::SuspendedExecutingState : {
919 aGraphState = SUPERV::SuspendState ;
922 case SUPERV::ResumedExecutingState : {
923 aGraphState = SUPERV::RunningState ;
926 case SUPERV::KilledExecutingState : {
927 aGraphState = SUPERV::KillState ;
930 case SUPERV::StoppedExecutingState : {
931 aGraphState = SUPERV::StopState ;
934 case SUPERV::SuccessedExecutingState : {
935 aGraphState = SUPERV::DoneState ;
938 case SUPERV::ErroredExecutingState : {
939 aGraphState = SUPERV::ErrorState ;
942 case SUPERV::SuspendedSuccessedState : {
943 aGraphState = SUPERV::SuspendDoneState ;
946 case SUPERV::SuspendedErroredState : {
947 aGraphState = SUPERV::SuspendErroredState ;
950 case SUPERV::ResumedSuccessedState : {
951 aGraphState = SUPERV::DoneState ;
954 case SUPERV::ResumedErroredState : {
955 aGraphState = SUPERV::ErrorState ;
958 case SUPERV::KilledSuccessedState : {
959 aGraphState = SUPERV::KillState ;
962 case SUPERV::KilledErroredState : {
963 aGraphState = SUPERV::KillState ;
966 case SUPERV::StoppedSuccessedState : {
967 aGraphState = SUPERV::StopState ;
970 case SUPERV::StoppedErroredState : {
971 aGraphState = SUPERV::StopState ;
974 case SUPERV::SuccessedState : {
975 aGraphState = SUPERV::DoneState ;
978 case SUPERV::ErroredState : {
979 aGraphState = SUPERV::ErrorState ;
982 case SUPERV::SuspendedState : {
983 aGraphState = SUPERV::SuspendState ;
986 case SUPERV::KilledState : {
987 aGraphState = SUPERV::KillState ;
990 case SUPERV::StoppedState : {
991 aGraphState = SUPERV::StopState ;
994 case SUPERV::ReRunnedState : {
995 aGraphState = SUPERV::ReRunState ;
998 case SUPERV::ReStartedState : {
999 aGraphState = SUPERV::ReStartState ;
1003 cdebug << " GraphExecutor::OutNode::AutomatonGraphState Error Undefined State : "
1004 << aGraphState << endl ;
1005 aGraphState = SUPERV::UndefinedState ;
1008 return aGraphState ;
1011 bool GraphExecutor::OutNode::PushEvent( GraphExecutor::InNode * aNode ,
1012 GraphExecutor::NodeEvent anEvent ,
1013 SUPERV::AutomatonState aState ) {
1014 // cdebug_in << "PushEvent Threads " << Threads() << " SuspendedThreads "
1015 // << SuspendedThreads() << endl ;
1016 if ( pthread_mutex_lock( &_MutexWait ) ) {
1017 perror("PushEvent pthread_mutex_lock ") ;
1021 _EventNodes.push_back( aNode->Name() ) ;
1024 _EventNodes.push_back( Name() ) ;
1026 _Events.push_back( anEvent ) ;
1027 _States.push_back( aState ) ;
1028 pthread_cond_broadcast( &_EventWait );
1030 // cdebug << aNode->ThreadNo() << " PushEvent " << aNode->Name() ;
1031 // cdebug << " " << aNode->Automaton()->EventName( anEvent )
1032 // << " " << aNode->Automaton()->StateName( aState )
1033 // << " ControleState "
1034 // << aNode->Automaton()->ControlStateName( aNode->ControlState() ) ;
1037 // cdebug << "PushEvent " << Name() ;
1038 // cdebug << " " << theAutomaton->EventName( anEvent ) << " "
1039 // << theAutomaton->StateName( aState ) ;
1041 // cdebug_out << "PushEvent Threads " << Threads() << " SuspendedThreads "
1042 // << SuspendedThreads() << endl ;
1043 if ( _EventNodes.size() > 101 ) {
1044 while ( _EventNodes.size() > 31 ) {
1045 _EventNodes.pop_front() ;
1046 _Events.pop_front() ;
1047 _States.pop_front() ;
1050 if ( pthread_mutex_unlock( &_MutexWait ) ) {
1051 perror("PushEvent pthread_mutex_unlock ") ;
1057 bool GraphExecutor::OutNode::StateWait( SUPERV::GraphState aState ) {
1061 bool GraphExecutor::OutNode::Event( char ** aNodeName ,
1062 SUPERV::GraphEvent & anEvent ,
1063 SUPERV::GraphState & aState ,
1066 int SuspendedThreadsNumber ;
1067 if ( pthread_mutex_lock( &_MutexWait ) ) {
1068 perror("EventLoop pthread_mutex_lock ") ;
1071 _JustStarted = false ;
1072 ThreadsNumber = Threads() ;
1073 SuspendedThreadsNumber = SuspendedThreads() ;
1074 bool RetVal = ( ThreadsNumber - SuspendedThreadsNumber) != 0 ||
1075 _EventNodes.size() > 0 ;
1076 char * NodeName = "" ;
1077 GraphExecutor::NodeEvent theEvent = GraphExecutor::UndefinedEvent ;
1078 SUPERV::AutomatonState theState = SUPERV::UnKnownState ;
1079 anEvent = SUPERV::UndefinedEvent ;
1080 aState = SUPERV::UndefinedState ;
1081 if ( ( IsDone() || IsKilled() || IsStopped() ) && _EventNodes.size() == 0 ) {
1082 // cdebug << "EventLoop IsDone()/IsKilled()/IsStopped() && _EventNodes.size() == 0" << endl ;
1085 else if ( !WithWait && _EventNodes.size() == 0 ) {
1086 anEvent = SUPERV::NoEvent ;
1087 aState = SUPERV::NoState ;
1090 else if ( RetVal ) {
1091 while ( !IsSuspended() && _EventNodes.size() == 0 ) {
1092 // cdebug << "EventLoop pthread_cond_wait _EventWait" << endl ;
1093 pthread_cond_wait( &_EventWait , &_MutexWait );
1094 // cdebug << "EventLoop pthread_cond_waited _EventWait"
1095 // << " _EventNodes.size() " << _EventNodes.size() << endl ;
1097 if ( _EventNodes.size() ) {
1098 ThreadsNumber = Threads() ;
1099 NodeName = _EventNodes.front() ;
1100 _EventNodes.pop_front() ;
1101 theEvent = _Events.front() ;
1102 anEvent = AutomatonGraphEvent( theEvent ) ;
1103 _Events.pop_front() ;
1104 theState = _States.front() ;
1105 aState = AutomatonGraphState( theState ) ;
1106 _States.pop_front() ;
1109 *aNodeName = NodeName ;
1110 if ( IsSuspended() && _EventNodes.size() == 0 ) {
1113 if ( anEvent != SUPERV::NoEvent ) {
1114 // cdebug << pthread_self() << "EventLoop "
1115 // << NodeName << " " << theAutomaton->StateName( theState )
1116 // << " _EventNodes.size() " << _EventNodes.size()
1117 // << " Threads " << Threads() << " SuspendedThreads "
1118 // << SuspendedThreads() << " RetVal " << RetVal << endl ;
1120 if ( pthread_mutex_unlock( &_MutexWait ) ) {
1121 perror("EventLoop pthread_mutex_lock ") ;
1127 bool GraphExecutor::OutNode::EventW( char ** aNodeName ,
1128 SUPERV::GraphEvent & anEvent ,
1129 SUPERV::GraphState & aState ) {
1132 aState = SUPERV::UndefinedState ;
1134 aState != SUPERV::SuspendReadyState &&
1135 aState != SUPERV::RunningState &&
1136 aState != SUPERV::SuspendDoneState &&
1137 aState != SUPERV::SuspendErroredState ) {
1139 while ( sts && !strcmp( NodeName , Name() ) ) {
1140 sts = EventWait( aNodeName , anEvent , aState ) ;
1141 NodeName = *aNodeName ;
1147 bool GraphExecutor::OutNode::EventWait( char ** aNodeName ,
1148 SUPERV::GraphEvent & anEvent ,
1149 SUPERV::GraphState & aState ) {
1150 if ( pthread_mutex_lock( &_MutexWait ) ) {
1151 perror("EventW pthread_mutex_lock ") ;
1155 int SuspendedThreadsNumber ;
1156 ThreadsNumber = Threads() ;
1157 SuspendedThreadsNumber = SuspendedThreads() ;
1158 bool RetVal = ( ThreadsNumber - SuspendedThreadsNumber) != 0 ||
1159 _EventNodes.size() > 0 ;
1160 cdebug << "--> EventW RetVal " << RetVal << endl ;
1161 char * NodeName = "" ;
1162 GraphExecutor::NodeEvent theEvent = GraphExecutor::UndefinedEvent ;
1163 SUPERV::AutomatonState theState = SUPERV::UnKnownState ;
1164 anEvent = SUPERV::UndefinedEvent ;
1165 aState = SUPERV::UndefinedState ;
1166 if ( IsDone() && _EventNodes.size() == 0 ) {
1167 cdebug << "EventW IsDone() && _EventNodes.size() == 0" << endl ;
1170 else if ( RetVal ) {
1171 GraphExecutor::InNode * aNode = NULL ;
1172 while ( aNode == NULL && RetVal ) {
1173 NodeName = _EventNodes.front() ;
1174 theEvent = _Events.front() ;
1175 anEvent = AutomatonGraphEvent( theEvent ) ;
1176 theState = _States.front() ;
1177 aState = AutomatonGraphState( theState ) ;
1179 if ( _JustStarted ) {
1180 _JustStarted = false ;
1183 _EventNodes.pop_front() ;
1184 _Events.pop_front() ;
1185 _States.pop_front() ;
1188 aNode = ((GraphExecutor::InNode *) GetGraphNode( NodeName )->GetInNode()) ;
1189 cdebug << "EventW Previous Node " << NodeName << " ThreadsNumber "
1191 << " _EventNodes.size() " << _EventNodes.size() << " "
1192 << theAutomaton->StateName( theState )
1193 << " Threads " << Threads() << " SuspendedThreads "
1194 << SuspendedThreads() << endl ;
1197 else if ( IsDone() && _EventNodes.size() == 0 ) {
1198 cdebug << "EventW IsDone() && _EventNodes.size() == 0" << endl ;
1202 cdebug << "EventW Not InNode " << NodeName
1203 << " _EventNodes.size() " << _EventNodes.size() << endl ;
1204 while ( _EventNodes.size() == 0 ) {
1205 pthread_cond_wait( &_EventWait , &_MutexWait );
1207 cdebug << "EventW pthread_cond_waited Not InNode " << NodeName
1208 << " _EventNodes.size() " << _EventNodes.size() << endl ;
1213 if ( aState == SUPERV::SuspendState ||
1214 aState == SUPERV::SuspendReadyState ||
1215 aState == SUPERV::SuspendDoneState ||
1216 aState == SUPERV::SuspendErroredState ) {
1217 aNode->ControlState( SUPERV::ToSuspendState ) ;
1218 if ( aNode->IsSuspended() ) {
1219 if ( pthread_mutex_unlock( &_MutexWait ) ) {
1220 perror("EventW pthread_mutex_lock ") ;
1223 cdebug << "EventW " << aNode->Name() << " ResumeAction" << endl ;
1224 aNode->ResumeAction( GraphExecutor::ToResumeEvent ) ;
1225 cdebug << "EventW " << aNode->Name() << " ResumedAction" << endl ;
1226 if ( pthread_mutex_lock( &_MutexWait ) ) {
1227 perror("EventW pthread_mutex_lock ") ;
1232 cdebug << "EventW inconsistent SuspendState" << endl ;
1237 if ( aNode->IsDone() ) {
1241 cdebug << "EventW NOT SuspendedState _EventNodes.size() "
1242 << _EventNodes.size() << endl ;
1247 cdebug << "EventW " << aNode->Name() << " pthread_cond_wait" << endl ;
1248 while ( _EventNodes.size() == 0 ) {
1249 pthread_cond_wait( &_EventWait , &_MutexWait );
1251 ThreadsNumber = Threads() ;
1252 NodeName = _EventNodes.front() ;
1253 theEvent = _Events.front() ;
1254 anEvent = AutomatonGraphEvent( theEvent ) ;
1255 theState = _States.front() ;
1256 aState = AutomatonGraphState( theState ) ;
1260 *aNodeName = NodeName ;
1261 cdebug << "<-- EventW RetVal " << RetVal << " " << NodeName
1262 << " Threads " << Threads() << " SuspendedThreads "
1263 << SuspendedThreads()
1264 << " _EventNodes.size() " << _EventNodes.size()
1265 << " " << theAutomaton->EventName( theEvent ) << " "
1266 << theAutomaton->StateName( theState ) << endl ;
1267 if ( pthread_mutex_unlock( &_MutexWait ) ) {
1268 perror("EventW pthread_mutex_lock ") ;
1274 void GraphExecutor::OutNode::State(SUPERV::AutomatonState aState ) {
1278 SUPERV::GraphState GraphExecutor::OutNode::State() {
1279 // cdebug_in << "GraphExecutor::OutNode::State" << endl;
1280 // cdebug_out << "GraphExecutor::OutNode::State" << endl ;
1281 // cdebug << "GraphExecutor::OutNode::State GraphState "
1282 // << theAutomaton->StateName( AutomatonGraphState( _State ) ) << endl ;
1283 return AutomatonGraphState( _State ) ;
1286 SUPERV::GraphState GraphExecutor::OutNode::State( const char * NodeName ) {
1287 // cdebug_in << "GraphExecutor::OutNode::State " << NodeName << endl;
1288 SUPERV::AutomatonState aret = SUPERV::UnKnownState ;
1289 const GraphBase::ComputingNode * aCNode = GetGraphNode( NodeName ) ;
1291 GraphExecutor::InNode *anInNode = (GraphExecutor::InNode *)aCNode->GetInNode() ;
1293 aret = anInNode->State() ;
1294 // cdebug << "GraphExecutor::OutNode::State( " << NodeName << " ) "
1295 // << theAutomaton->StateName( AutomatonGraphState( aret ) ) << endl ;
1298 // cdebug_out << "GraphExecutor::OutNode::State" << endl ;
1299 return AutomatonGraphState( aret ) ;
1302 SUPERV::GraphState GraphExecutor::OutNode::State(
1303 const char * NodeName ,
1304 const char * ServiceParameterName ) {
1305 // cdebug_in << "GraphExecutor::OutNode::State " << NodeName << " "
1306 // << ServiceParameterName<< endl;
1307 SUPERV::GraphState aret =
1308 PortState( NodeName , ServiceParameterName ) ;
1309 // cdebug_out << "GraphExecutor::OutNode::State" << endl ;
1313 SUPERV::AutomatonState GraphExecutor::OutNode::AutomatonState() {
1314 // cdebug_in << "GraphExecutor::OutNode::AutomatonState" << endl;
1315 // cdebug_out << "GraphExecutor::OutNode::AutomatonState" << endl ;
1319 SUPERV::AutomatonState GraphExecutor::OutNode::AutomatonState( const char * NodeName ) {
1320 // cdebug_in << "GraphExecutor::OutNode::AutomatonState " << NodeName << endl;
1321 SUPERV::AutomatonState aret = SUPERV::UnKnownState ;
1322 GraphExecutor::InNode *anInNode = (GraphExecutor::InNode *) GetGraphNode( NodeName )->GetInNode() ;
1324 aret = anInNode->State() ;
1325 // cdebug_out << "GraphExecutor::OutNode::AutomatonState" << endl ;
1329 SUPERV::ControlState GraphExecutor::OutNode::ControlState() {
1330 // cdebug_in << "GraphExecutor::OutNode::ControlState" << endl;
1331 // cdebug_out << "GraphExecutor::OutNode::ControlState" << endl ;
1332 return _ControlState ;
1335 SUPERV::ControlState GraphExecutor::OutNode::ControlState( const char * NodeName ) {
1336 // cdebug_in << "GraphExecutor::OutNode::ControlState " << NodeName << endl;
1337 SUPERV::ControlState aret = SUPERV::VoidState ;
1338 GraphExecutor::InNode *anInNode = (GraphExecutor::InNode *) GetGraphNode( NodeName )->GetInNode() ;
1340 aret = anInNode->ControlState() ;
1341 // cdebug_out << "GraphExecutor::OutNode::ControlState" << endl ;
1345 void GraphExecutor::OutNode::ControlClear() {
1346 // cdebug_in << "GraphExecutor::OutNode::ControlClear" << endl;
1347 // cdebug_out << "GraphExecutor::OutNode::ControlClear" << endl ;
1348 _ControlState = SUPERV::VoidState;
1351 void GraphExecutor::OutNode::ControlClear( const char * NodeName ) {
1352 // cdebug_in << "GraphExecutor::OutNode::ControlClear " << NodeName << endl;
1353 GraphExecutor::InNode *anInNode = (GraphExecutor::InNode *) GetGraphNode( NodeName )->GetInNode() ;
1355 anInNode->ControlClear() ;
1356 // cdebug_out << "GraphExecutor::OutNode::ControlClear" << endl ;
1359 bool GraphExecutor::OutNode::IsWaiting() {
1360 // cdebug_in << "GraphExecutor::OutNode::IsWaiting" << endl;
1361 // cdebug_out << "GraphExecutor::OutNode::IsWaiting" << endl ;
1365 bool GraphExecutor::OutNode::IsReady() {
1366 // cdebug_in << "GraphExecutor::OutNode::IsReady" << endl;
1367 // cdebug_out << "GraphExecutor::OutNode::IsReady" << endl ;
1371 bool GraphExecutor::OutNode::IsRunning() {
1372 // cdebug_in << "GraphExecutor::OutNode::IsRunning" << endl;
1373 // cdebug_out << "GraphExecutor::OutNode::IsRunning" << endl ;
1377 bool GraphExecutor::OutNode::IsDone() {
1378 // cdebug_in << "GraphExecutor::OutNode::IsDone" << endl;
1379 // cdebug_out << "GraphExecutor::OutNode::IsDone" << endl ;
1380 return ( _Done || IsKilled() || IsStopped() ) ;
1383 bool GraphExecutor::OutNode::IsSuspended() {
1384 // cdebug_in << "GraphExecutor::OutNode::IsSuspended" << endl;
1386 if ( _SuspendedThreads == _Threads ) {
1389 // cdebug_out << "GraphExecutor::OutNode::IsSuspended" << endl ;
1393 bool GraphExecutor::OutNode::IsKilled() {
1394 // cdebug_in << "GraphExecutor::OutNode::IsKilled" << endl;
1396 if ( AutomatonGraphState( _State ) == SUPERV::KillState ) {
1399 // cdebug_out << "GraphExecutor::OutNode::IsKilled" << endl ;
1403 bool GraphExecutor::OutNode::IsStopped() {
1404 // cdebug_in << "GraphExecutor::OutNode::IsStopped" << endl;
1406 if ( AutomatonGraphState( _State ) == SUPERV::StopState ) {
1409 // cdebug_out << "GraphExecutor::OutNode::IsStopped" << endl ;
1413 bool GraphExecutor::OutNode::IsWaiting( const char * NodeName ) {
1415 // cdebug_in << "GraphExecutor::OutNode::IsWaiting " << NodeName << endl;
1416 GraphExecutor::InNode *anInNode = (GraphExecutor::InNode *) GetGraphNode( NodeName )->GetInNode() ;
1418 aret = anInNode->IsWaiting() ;
1420 // cdebug_out << "GraphExecutor::OutNode::IsWaiting" << endl ;
1424 bool GraphExecutor::OutNode::IsReady( const char * NodeName ) {
1426 // cdebug_in << "GraphExecutor::OutNode::IsReady " << NodeName << endl;
1427 GraphExecutor::InNode *anInNode = (GraphExecutor::InNode *) GetGraphNode( NodeName )->GetInNode() ;
1429 aret = anInNode->IsReady() ;
1431 // cdebug_out << "GraphExecutor::OutNode::IsReady" << endl ;
1435 bool GraphExecutor::OutNode::IsRunning( const char * NodeName ) {
1437 // cdebug_in << "GraphExecutor::OutNode::IsRunning " << NodeName << endl;
1438 GraphExecutor::InNode *anInNode = (GraphExecutor::InNode *) GetGraphNode( NodeName )->GetInNode() ;
1440 aret = anInNode->IsRunning() ;
1442 // cdebug_out << "GraphExecutor::OutNode::IsRunning" << endl ;
1446 bool GraphExecutor::OutNode::IsDone( const char * NodeName ) {
1448 // cdebug_in << "GraphExecutor::OutNode::IsDone " << NodeName << endl;
1449 GraphExecutor::InNode *anInNode = (GraphExecutor::InNode *) GetGraphNode( NodeName )->GetInNode() ;
1451 aret = anInNode->IsDone() ;
1453 // cdebug_out << "GraphExecutor::OutNode::IsDone" << endl ;
1457 bool GraphExecutor::OutNode::IsSuspended( const char * NodeName ) {
1459 // cdebug_in << "GraphExecutor::OutNode::IsSuspended " << NodeName << endl;
1460 GraphExecutor::InNode *anInNode = (GraphExecutor::InNode *) GetGraphNode( NodeName )->GetInNode() ;
1462 aret = anInNode->IsSuspended() ;
1464 // cdebug_out << "GraphExecutor::OutNode::IsSuspended" << endl ;
1468 bool GraphExecutor::OutNode::IsDone( const char * NodeName ,
1469 const char * ServiceParameterName ) {
1470 // cdebug_in << "GraphExecutor::OutNode::IsDone " << NodeName << " "
1471 // << ServiceParameterName<< endl;
1472 bool aret = PortDone( NodeName , ServiceParameterName ) ;
1473 // cdebug_out << "GraphExecutor::OutNode::IsDone" << endl ;
1477 bool GraphExecutor::OutNode::ContainerKill() {
1478 bool RetVal = true ;
1479 cdebug_in << "GraphExecutor::OutNode::ContainerKill" << endl;
1480 _ControlState = SUPERV::ToSuspendState ;
1482 for ( i = 0 ; i < GraphNodesSize() ; i++ ) {
1483 GraphExecutor::InNode * aNode = (GraphExecutor::InNode * ) GraphNodes( i )->GetInNode() ;
1484 bool sts = aNode->ContainerKill() ;
1485 if ( sts && aNode->IsKilled() ) {
1486 cdebug << aNode->Name() << " killed" << endl ;
1488 else if ( aNode->IsWaiting() || aNode->IsDone() ) {
1489 cdebug << aNode->Name() << " not killed : "
1490 << theAutomaton->StateName( aNode->State() ) << endl ;
1493 cdebug << aNode->Name() << " cannot be killed : "
1494 << theAutomaton->StateName( aNode->State() ) << endl ;
1498 if ( !RetVal || Threads() != 0 ) {
1499 for ( i = 0 ; i < GraphNodesSize() ; i++ ) {
1500 GraphExecutor::InNode * aNode = (GraphExecutor::InNode * ) GraphNodes( i )->GetInNode() ;
1501 if ( !aNode->IsKilled() && !aNode->IsWaiting() && !aNode->IsDone() ) {
1502 aNode->KilledAction() ;
1507 State( SUPERV::KilledState ) ;
1508 cdebug_out << "GraphExecutor::OutNode::ContainerKill" << endl ;
1512 bool GraphExecutor::OutNode::Suspend() {
1513 bool RetVal = false ;
1514 cdebug_in << "GraphExecutor::OutNode::Suspend" << endl;
1515 _ControlState = SUPERV::ToSuspendState ;
1517 for ( i = 0 ; i < GraphNodesSize() ; i++ ) {
1518 GraphExecutor::InNode * aNode = (GraphExecutor::InNode * ) GraphNodes( i )->GetInNode() ;
1519 bool sts = aNode->Suspend() ;
1520 if ( sts && aNode->IsSuspended() ) {
1521 cdebug << aNode->Name() << " Suspend" << endl ;
1523 else if ( aNode->IsWaiting() || aNode->IsDone() ) {
1524 cdebug << aNode->Name() << " not Suspended : "
1525 << theAutomaton->StateName( aNode->State() ) << endl ;
1528 cdebug << aNode->Name() << " cannot be Suspended : "
1529 << theAutomaton->StateName( aNode->State() ) << endl ;
1533 State( SUPERV::SuspendedState ) ;
1534 cdebug_out << "GraphExecutor::OutNode::Suspend" << endl ;
1536 MESSAGE("================================================================================") ;
1537 MESSAGE( Name() << " IS SUSPENDED" ) ;
1538 MESSAGE("================================================================================") ;
1542 bool GraphExecutor::OutNode::Resume() {
1543 bool RetVal = false ;
1544 cdebug_in << "GraphExecutor::OutNode::Resume" << endl;
1545 cdebug_out << "GraphExecutor::OutNode::Resume" << endl ;
1547 MESSAGE("================================================================================") ;
1548 MESSAGE( Name() << " IS RESUMED" ) ;
1549 MESSAGE("================================================================================") ;
1554 bool GraphExecutor::OutNode::Kill() {
1555 bool RetVal = true ;
1556 cdebug_in << "GraphExecutor::OutNode::Kill" << endl;
1557 _ControlState = SUPERV::ToSuspendState ;
1559 for ( i = 0 ; i < GraphNodesSize() ; i++ ) {
1560 GraphExecutor::InNode * aNode = (GraphExecutor::InNode * ) GraphNodes( i )->GetInNode() ;
1561 bool sts = aNode->Kill() ;
1562 if ( sts && aNode->IsKilled() ) {
1563 cdebug << aNode->Name() << " killed" << endl ;
1565 else if ( aNode->IsWaiting() || aNode->IsDone() ) {
1566 cdebug << aNode->Name() << " not killed : "
1567 << theAutomaton->StateName( aNode->State() ) << endl ;
1570 cdebug << aNode->Name() << " cannot be killed : "
1571 << theAutomaton->StateName( aNode->State() ) << endl ;
1575 if ( !RetVal || Threads() != 0 ) {
1576 for ( i = 0 ; i < GraphNodesSize() ; i++ ) {
1577 GraphExecutor::InNode * aNode = (GraphExecutor::InNode * ) GraphNodes( i )->GetInNode() ;
1578 if ( !aNode->IsKilled() && !aNode->IsWaiting() && !aNode->IsDone() ) {
1579 aNode->KilledAction() ;
1584 State( SUPERV::KilledState ) ;
1585 cdebug_out << "GraphExecutor::OutNode::Kill" << endl ;
1587 MESSAGE("================================================================================") ;
1588 MESSAGE( Name() << " IS KILLED" ) ;
1589 MESSAGE("================================================================================") ;
1594 bool GraphExecutor::OutNode::Stop() {
1595 bool RetVal = false ;
1596 cdebug_in << "GraphExecutor::OutNode::Stop" << endl;
1598 cdebug_out << "GraphExecutor::OutNode::Stop" << endl ;
1600 MESSAGE("================================================================================") ;
1601 MESSAGE( Name() << " IS STOPPED" ) ;
1602 MESSAGE("================================================================================") ;
1606 bool GraphExecutor::OutNode::ReRun() {
1607 bool RetVal = false ;
1608 cdebug_in << "GraphExecutor::OutNode::ReRun" << endl;
1609 if ( IsSuspended() ) {
1611 cdebug_out << "GraphExecutor::OutNode::ReRun" << endl ;
1614 bool GraphExecutor::OutNode::ReStart() {
1615 bool RetVal = false ;
1616 cdebug_in << "GraphExecutor::OutNode::ReStart" << endl;
1617 if ( IsSuspended() ) {
1619 cdebug_out << "GraphExecutor::OutNode::ReStart" << endl ;
1623 bool GraphExecutor::OutNode::ReadyWait() {
1624 cdebug_in << "GraphExecutor::OutNode::ReadyWait" << endl;
1626 if ( pthread_mutex_lock( &_MutexWait ) ) {
1627 perror("pthread_mutex_lock _ReadyWait") ;
1633 pthread_cond_wait( &_EventWait , &_MutexWait );
1636 if ( pthread_mutex_unlock( &_MutexWait ) ) {
1637 perror("pthread_mutex_lock _ReadyWait") ;
1640 cdebug_out << "GraphExecutor::OutNode::ReadyWait" << endl ;
1644 bool GraphExecutor::OutNode::RunningWait() {
1645 cdebug_in << "GraphExecutor::OutNode::RunningWait" << endl;
1647 if ( pthread_mutex_lock( &_MutexWait ) ) {
1648 perror("pthread_mutex_lock _RunningWait") ;
1651 aret = IsRunning() ;
1653 cdebug << "RunningWait pthread_cond_wait _EventWait" << endl;
1654 pthread_cond_wait( &_EventWait , &_MutexWait );
1655 aret = IsRunning() ;
1656 cdebug << "RunningWait pthread_cond_waited _EventWait " << aret << endl;
1658 if ( pthread_mutex_unlock( &_MutexWait ) ) {
1659 perror("pthread_mutex_lock _RunningWait") ;
1662 cdebug_out << "GraphExecutor::OutNode::RunningWait " << aret << endl ;
1666 bool GraphExecutor::OutNode::DoneWait() {
1667 cdebug_in << "GraphExecutor::OutNode::DoneWait" << endl;
1669 if ( pthread_mutex_lock( &_MutexWait ) ) {
1670 perror("pthread_mutex_lock _DoneWait") ;
1674 while ( !aret && !IsSuspended() && IsRunning() ) {
1675 cdebug << "DoneWait pthread_cond_wait _EventWait" << endl;
1676 pthread_cond_wait( &_EventWait , &_MutexWait );
1678 cdebug << "DoneWait pthread_cond_waited _EventWait " << aret << endl;
1680 if ( pthread_mutex_unlock( &_MutexWait ) ) {
1681 perror("pthread_mutex_lock _DoneWait") ;
1684 cdebug_out << "GraphExecutor::OutNode::DoneWait " << aret << endl ;
1688 bool GraphExecutor::OutNode::SuspendedWait() {
1689 cdebug_in << "GraphExecutor::OutNode::SuspendedWait" << endl;
1691 if ( pthread_mutex_lock( &_MutexWait ) ) {
1692 perror("pthread_mutex_lock _SuspendedWait") ;
1695 aret = IsSuspended() ;
1696 while ( !aret && !_Done ) {
1697 pthread_cond_wait( &_EventWait , &_MutexWait );
1698 aret = IsSuspended() ;
1700 if ( pthread_mutex_unlock( &_MutexWait ) ) {
1701 perror("pthread_mutex_lock _SuspendedWait") ;
1704 cdebug_out << "GraphExecutor::OutNode::SuspendedWait" << endl ;
1708 bool GraphExecutor::OutNode::ReadyWait( const char * NodeName ) {
1710 cdebug_in << "GraphExecutor::OutNode::ReadyWait " << NodeName << endl;
1711 GraphExecutor::InNode *anInNode = (GraphExecutor::InNode *) GetGraphNode( NodeName )->GetInNode() ;
1713 aret = anInNode->ReadyWait() ;
1715 cdebug_out << "GraphExecutor::OutNode::ReadyWait" << endl ;
1719 bool GraphExecutor::OutNode::RunningWait( const char * NodeName ) {
1721 cdebug_in << "GraphExecutor::OutNode::RunningWait " << NodeName << endl;
1722 GraphExecutor::InNode *anInNode = (GraphExecutor::InNode *) GetGraphNode( NodeName )->GetInNode() ;
1724 aret = anInNode->RunningWait() ;
1726 cdebug_out << "GraphExecutor::OutNode::RunningWait" << endl ;
1730 bool GraphExecutor::OutNode::DoneWait( const char * NodeName ) {
1732 cdebug_in << "GraphExecutor::OutNode::DoneWait " << NodeName << endl;
1733 GraphExecutor::InNode *anInNode = (GraphExecutor::InNode *) GetGraphNode( NodeName )->GetInNode() ;
1735 aret = anInNode->DoneWait() ;
1737 cdebug_out << "GraphExecutor::OutNode::DoneWait" << endl ;
1741 bool GraphExecutor::OutNode::SuspendedWait( const char * NodeName ) {
1743 cdebug_in << "GraphExecutor::OutNode::SuspendedWait " << NodeName << endl;
1744 GraphExecutor::InNode *anInNode = (GraphExecutor::InNode *) GetGraphNode( NodeName )->GetInNode() ;
1746 aret = anInNode->SuspendedWait() ;
1748 cdebug_out << "GraphExecutor::OutNode::SuspendedWait" << endl ;
1752 long GraphExecutor::OutNode::LastLevelDone() {
1755 for ( i = 0 ; i <= LevelMax() ; i++ ) {
1756 for ( j = 0 ; j <= NodesNumber( i ) ; j++ ) {
1757 GraphBase::ComputingNode * aNode = SortedNodes( i , j ) ;
1758 if ( !IsDone( aNode->Name() ) ) {
1762 if ( j != NodesNumber( i ) + 1 )
1770 const CORBA::Any *GraphExecutor::OutNode::GetInData( const char * NodeName ,
1771 const char * ServiceParameterName ) {
1772 // cdebug_in << "GraphExecutor::OutNode::GetInData " << NodeName << " "
1773 // << ServiceParameterName << endl ;
1774 const CORBA::Any * retdata = PortInData( NodeName , ServiceParameterName ) ;
1775 // cdebug_out << "GraphExecutor::OutNode::GetInData" << endl ;
1779 const CORBA::Any *GraphExecutor::OutNode::GetOutData( const char * NodeName ,
1780 const char * ServiceParameterName ) {
1781 // cdebug_in << "GraphExecutor::OutNode::GetOutData " << NodeName << " "
1782 // << ServiceParameterName << endl ;
1783 const CORBA::Any * retdata = PortOutData( NodeName , ServiceParameterName ) ;
1784 // cdebug_out << "GraphExecutor::OutNode::GetOutData" << endl ;
1788 const long GraphExecutor::OutNode::CpuUsed() {
1789 return GraphBase::Graph::CpuUsed() ;
1792 const long GraphExecutor::OutNode::CpuUsed( const char * aNodeName ) {
1793 GraphBase::ComputingNode * aNode = GetChangeGraphNode( aNodeName ) ;
1795 GraphExecutor::InNode * anInNode = (GraphExecutor::InNode * ) aNode->GetInNode() ;
1797 return anInNode->CpuUsed() ;