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 = GraphExecutor::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 const SUPERV::KindOfNode aKindOfNode ) {
68 // Graph( ORB , ptrNamingService , DataFlowName , DebugFileName ) {
69 Set_prof_debug( ORB , DebugFileName ) ;
70 cdebug_in << "GraphEditor::OutNode::OutNode(" << DataFlowName << " , " << aKindOfNode << ")" << endl;
71 if ( aKindOfNode == SUPERV::DataFlowGraph ) {
73 // _Graph = new GraphBase::Graph( ORB , ptrNamingService , DataFlowName , DebugFileName ) ;
74 _Graph = new GraphBase::Graph( ORB , ptrNamingService , DataFlowName , aKindOfNode ,
75 _prof_debug , _fdebug ) ;
77 else if ( aKindOfNode == SUPERV::DataStreamGraph ) {
78 // _StreamGraph = new GraphBase::StreamGraph( ORB , ptrNamingService , DataFlowName , DebugFileName ) ;;
79 _StreamGraph = new GraphBase::StreamGraph( ORB , ptrNamingService , DataFlowName , aKindOfNode ,
80 _prof_debug , _fdebug ) ;
81 _Graph = _StreamGraph ;
87 _ControlState = SUPERV::VoidState ;
88 _State = GraphExecutor::UnKnownState ;
89 _PyInitialized = false ;
90 _Orb = CORBA::ORB::_duplicate( ORB ) ;
91 pthread_mutex_init( &_MutexWait , NULL ) ;
92 pthread_mutex_init( &_PyMutexWait , NULL ) ;
93 if ( pthread_cond_init( &_EventWait , NULL ) ) {
94 perror("pthread_cond_init( &_EventWait , NULL )") ;
97 if ( pthread_cond_init( &_JoinWait , NULL ) ) {
98 perror("pthread_cond_init( &_JoinWait , NULL )") ;
101 cdebug_out << "GraphEditor::OutNode::OutNode" << endl;
104 GraphExecutor::OutNode::OutNode( CORBA::ORB_ptr ORB,
105 SALOME_NamingService* ptrNamingService ,
106 const SALOME_ModuleCatalog::Service& DataFlowService ,
107 const char *DataFlowComponentName ,
108 const char *DataFlowInterfaceName ,
109 const char *DataFlowName ,
110 const SUPERV::KindOfNode DataFlowkind ,
111 const SUPERV::SDate DataFlowFirstCreation ,
112 const SUPERV::SDate DataFlowLastModification ,
113 const char * DataFlowEditorRelease ,
114 const char * DataFlowAuthor ,
115 const char * DataFlowComputer ,
116 const char * DataFlowComment ,
117 const char * DebugFileName ) {
118 // Graph( ORB , ptrNamingService , DataFlowService , DataFlowComponentName ,
119 // DataFlowInterfaceName , DataFlowName , DataFlowkind ,
120 // DataFlowFirstCreation , DataFlowLastModification ,
121 // DataFlowEditorRelease , DataFlowAuthor ,
122 // DataFlowComputer , DataFlowComment , DebugFileName ) {
123 Set_prof_debug( ORB , DebugFileName ) ;
125 cdebug_in << "GraphEditor::OutNode::OutNode(" << DataFlowName << " , " << DataFlowkind << ")" << endl;
126 if ( DataFlowkind == SUPERV::DataFlowGraph ) {
127 _StreamGraph = NULL ;
128 _Graph = new GraphBase::Graph( ORB , ptrNamingService , DataFlowService , DataFlowComponentName ,
129 DataFlowInterfaceName , DataFlowName , DataFlowkind ,
130 DataFlowFirstCreation , DataFlowLastModification ,
131 DataFlowEditorRelease , DataFlowAuthor ,
132 DataFlowComputer , DataFlowComment ,
133 _prof_debug , _fdebug ) ;
134 // DataFlowComputer , DataFlowComment , DebugFileName ) ;
136 else if ( DataFlowkind == SUPERV::DataStreamGraph ) {
137 _StreamGraph = new GraphBase::StreamGraph( ORB , ptrNamingService , DataFlowService , DataFlowComponentName ,
138 DataFlowInterfaceName , DataFlowName , DataFlowkind ,
139 DataFlowFirstCreation , DataFlowLastModification ,
140 DataFlowEditorRelease , DataFlowAuthor ,
141 DataFlowComputer , DataFlowComment ,
142 _prof_debug , _fdebug ) ;
143 _Graph = _StreamGraph ;
146 _Executable = false ;
149 _ControlState = SUPERV::VoidState ;
150 _State = GraphExecutor::UnKnownState ;
151 _PyInitialized = false ;
152 _Orb = CORBA::ORB::_duplicate( ORB ) ;
153 pthread_mutex_init( &_MutexWait , NULL ) ;
154 pthread_mutex_init( &_PyMutexWait , NULL ) ;
155 if ( pthread_cond_init( &_EventWait , NULL ) ) {
156 perror("pthread_cond_init( &_EventWait , NULL )") ;
159 if ( pthread_cond_init( &_JoinWait , NULL ) ) {
160 perror("pthread_cond_init( &_JoinWait , NULL )") ;
165 GraphExecutor::OutNode::~OutNode() {
168 void GraphExecutor::OutNode::Set_prof_debug( CORBA::ORB_ptr ORB ,
169 const char * DebugFileName ) {
170 _Graph_prof_debug = 0 ;
171 if ( DebugFileName ) {
172 _fdebug = new ofstream( DebugFileName );
173 SetDebug( ORB , &_Graph_prof_debug , _fdebug ) ;
174 MESSAGE( endl << "Trace redirected to file " << DebugFileName << endl)
178 bool GraphExecutor::OutNode::LoadDataFlow(const GraphBase::SGraph * aDataFlow ) {
179 bool RetVal = false ;
180 cdebug_in << "GraphExecutor::OutNode::LoadDataFlow " << (*aDataFlow).Info.theName << endl ;
181 RetVal = LoadInfo( (*aDataFlow).Info ) ;
182 if ( Graph()->ServiceName() != NULL ) {
183 // MESSAGE( "GraphExecutor::OutNode::LoadDataFlow" );
185 RetVal = LoadNodes( (*aDataFlow).Nodes ) ;
187 RetVal = LoadLinks( (*aDataFlow).Links ) ;
190 RetVal = LoadDatas( (*aDataFlow).Datas ) ;
193 cdebug << "GraphExecutor::OutNode::LoadDataFlow LoadDatas Error."
198 cdebug << "GraphExecutor::OutNode::LoadDataFlow LoadLinks Error."
203 cdebug << "GraphExecutor::OutNode::LoadDataFlow LoadNodes Error."
208 cdebug << "GraphExecutor::OutNode::LoadDataFlow LoadInfo Error."
213 cdebug << "GraphExecutor::OutNode::LoadDataFlow ServiceName Error." << endl ;
215 cdebug_in << "GraphExecutor::OutNode::LoadDataFlow " << RetVal << endl ;
220 bool GraphExecutor::OutNode::LoadXml( const char* myFileName ) {
221 bool RetVal = false ;
222 GraphBase::ListOfSGraphs aListOfDataFlows ;
223 if ( Graph()->LoadXml( _Orb , myFileName , aListOfDataFlows ) ) {
224 RetVal = LoadDataFlow( aListOfDataFlows ) ;
225 // if ( aConstructor && RetVal )
226 // RetVal = Name( aDataFlow.Info.theName.c_str() ) ;
232 bool GraphExecutor::OutNode::LoadInfo(const GraphBase::SNode &aDataFlowInfo ) {
233 cdebug << "GraphExecutor::OutNode::LoadInfo _StreamGraph " << _StreamGraph << endl ;
234 // ComponentName( aDataFlowInfo.theComponentName.c_str() ) ;
235 Graph()->Name( aDataFlowInfo.theName.c_str() ) ;
236 Graph()->Kind( aDataFlowInfo.theKind ) ;
237 if ( Graph()->IsDataStreamNode() && aDataFlowInfo.theKind == SUPERV::DataStreamGraph ) {
238 StreamGraph()->SetStreamParams( aDataFlowInfo.theTimeout , aDataFlowInfo.theDataStreamTrace , aDataFlowInfo.theDeltaTime ) ;
240 Graph()->DataService( _Orb , aDataFlowInfo.theService , _prof_debug , _fdebug ) ;
241 Graph()->FirstCreation( aDataFlowInfo.theFirstCreation ) ;
242 Graph()->LastModification( aDataFlowInfo.theLastModification ) ;
243 Graph()->EditorRelease( aDataFlowInfo.theEditorRelease.c_str() ) ;
244 Graph()->Author( aDataFlowInfo.theAuthor.c_str() ) ;
245 // Graph()->Computer( aDataFlowInfo.theContainer.c_str() ) ;
246 Graph()->Comment( aDataFlowInfo.theComment.c_str() ) ;
247 // Not in OutNode/DataFlow but in InNode/DataFlow_in_an_other_DataFlow
248 // Graph()->Coordinates( aDataFlowInfo.theX , aDataFlowInfo.theY ) ;
252 bool GraphExecutor::OutNode::LoadNodes(const GraphBase::ListOfSNodes &aListOfNodes ) {
254 GraphExecutor::InNode * anInNode ;
255 cdebug << "GraphExecutor::OutNode::LoadNodes" << endl ;
257 for ( i = 0 ; i < (int ) aListOfNodes.size() ; i++ ) {
258 GraphBase::SNode aNode = aListOfNodes[ i ] ;
259 anInNode = AddNode( aNode.theService ,
260 aNode.theListOfFuncName ,
261 aNode.theListOfPythonFunctions ,
262 aNode.theComponentName.c_str() ,
263 aNode.theInterfaceName.c_str() , aNode.theName.c_str() ,
265 aNode.theFirstCreation , aNode.theLastModification ,
266 aNode.theEditorRelease.c_str() ,
267 aNode.theAuthor.c_str() , aNode.theContainer.c_str() ,
268 aNode.theComment.c_str() ,
269 aNode.theCoords.theX , aNode.theCoords.theY ) ;
274 if ( anInNode->IsOneOfInLineNodes() || anInNode->IsMacroNode() ) {
275 anInNode->GraphExecutor::InNode::InLineNode()->DefPortsOfNode(
276 _Orb , aNode.theService , anInNode->NamePtr() ,
278 _prof_debug , _fdebug ) ;
280 // GraphBase::ComputingNode * theNode = Graph()->GetChangeGraphNode( aNode.theName.c_str() ) ;
283 for ( j = 0 ; j < aNode.theListOfInDataStreams.size() ; j++ ) {
284 GraphBase::InPort * anInPort ;
285 anInPort = anInNode->ComputingNode()->AddInDataStreamPort( aNode.theListOfInDataStreams[ j ].theDataStreamParameter.Parametername ,
286 aNode.theListOfInDataStreams[ j ].theDataStreamParameter.Parametertype ,
287 aNode.theListOfInDataStreams[ j ].theDataStreamParameter.Parameterdependency ,
288 SUPERV::DataStreamParameter ) ;
289 ((GraphBase::InDataStreamPort * ) anInPort)->SetParams( aNode.theListOfInDataStreams[ j ].theKindOfSchema ,
290 aNode.theListOfInDataStreams[ j ].theKindOfInterpolation ,
291 aNode.theListOfInDataStreams[ j ].theKindOfExtrapolation ) ;
293 for ( j = 0 ; j < aNode.theListOfOutDataStreams.size() ; j++ ) {
294 GraphBase::OutPort * anOutPort ;
295 anOutPort = anInNode->ComputingNode()->AddOutDataStreamPort( aNode.theListOfOutDataStreams[ j ].theDataStreamParameter.Parametername ,
296 aNode.theListOfOutDataStreams[ j ].theDataStreamParameter.Parametertype ,
297 aNode.theListOfOutDataStreams[ j ].theDataStreamParameter.Parameterdependency ,
298 SUPERV::DataStreamParameter ) ;
299 ((GraphBase::OutDataStreamPort * ) anOutPort)->NumberOfValues( aNode.theListOfOutDataStreams[ j ].theNumberOfValues ) ;
303 // theNode->DataStreamInPortsNumber( aNode.theDataStreamInArgsNumber ) ;
304 // theNode->DataStreamOutPortsNumber( aNode.theDataStreamOutArgsNumber ) ;
305 // cdebug << "GraphExecutor::OutNode::LoadNodes " << anInNode->Name()
306 // << " InPortsSize " << theNode->GetNodeInPortsSize()
307 // << " OutPortsSize " << theNode->GetNodeOutPortsSize()
308 // << " DataStreamInPortsNumber " << aNode.theDataStreamInArgsNumber
309 // << " DataStreamOutPortsNumber " << aNode.theDataStreamOutArgsNumber
312 // if ( aNode.theDataStreamInArgsNumber ) { // -1 because of Gates
313 // for ( j = theNode->GetNodeInPortsSize() - aNode.theDataStreamInArgsNumber - 1 ; j < theNode->GetNodeInPortsSize() - 1 ; j++ ) {
314 // cdebug << "GraphExecutor::OutNode::LoadNodes " << anInNode->Name()
315 // << " InPort " << theNode->GetChangeNodeInPort( j )->PortName()
316 // << " Kind( DataStreamParameter)" << endl ;
317 // theNode->GetChangeNodeInPort( j )->Kind( SUPERV::DataStreamParameter ) ;
320 // if ( aNode.theDataStreamOutArgsNumber ) {
321 // int withgate = 1 ;
322 // if ( theNode->IsLoopNode() || theNode->IsEndLoopNode() ) {
325 // for ( j = theNode->GetNodeOutPortsSize() - aNode.theDataStreamOutArgsNumber - withgate ; j < theNode->GetNodeOutPortsSize() - withgate ; j++ ) {
326 // cdebug << "GraphExecutor::OutNode::LoadNodes " << anInNode->Name()
327 // << " OutPort " << theNode->GetChangeNodeOutPort( j )->PortName()
328 // << " Kind( DataStreamParameter)" << endl ;
329 // theNode->GetChangeNodeOutPort( j )->Kind( SUPERV::DataStreamParameter ) ;
333 for ( i = 0 ; i < (int ) aListOfNodes.size() ; i++ ) {
334 GraphBase::SNode aNode = aListOfNodes[ i ] ;
335 anInNode = (GraphExecutor::InNode * ) Graph()->GetChangeGraphNode( aNode.theName.c_str() )->GetInNode() ;
336 cdebug << "GraphExecutor::OutNode::LoadNodes " << anInNode->Name() << " IsOneOfGOTONodes "
337 << anInNode->IsOneOfGOTONodes() << " " << aNode.theCoupledNode.c_str() << endl ;
338 if ( anInNode->IsOneOfGOTONodes() && strlen( aNode.theCoupledNode.c_str() ) ) {
339 GraphBase::GOTONode * aCoupledNode ;
340 aCoupledNode = (GraphBase::GOTONode * ) Graph()->GetGraphNode( aNode.theName.c_str() ) ;
341 GraphBase::GOTONode * aCoupledCoupledNode ;
342 aCoupledCoupledNode = (GraphBase::GOTONode * ) Graph()->GetChangeGraphNode( aNode.theCoupledNode.c_str() ) ;
343 if ( aCoupledCoupledNode != NULL ) {
344 aCoupledNode->CoupledNode( aCoupledCoupledNode ) ;
347 aCoupledNode->CoupledNodeName( aNode.theCoupledNode.c_str() ) ;
349 aCoupledNode->SetGraphExecutor( (GraphExecutor::DataFlow * ) this ) ;
355 bool GraphExecutor::OutNode::LoadLinks(const GraphBase::ListOfSLinks &aListOfLinks ) {
357 cdebug << "GraphExecutor::OutNode::LoadLinks " << aListOfLinks.size()
360 for ( i = 0 ; i < (int ) aListOfLinks.size() ; i++ ) {
361 GraphBase::SLink aLink = aListOfLinks[ i ] ;
362 RetVal = Graph()->AddLink( aLink.FromNodeName.c_str() ,
363 aLink.FromServiceParameterName.c_str() ,
364 aLink.ToNodeName.c_str() ,
365 aLink.ToServiceParameterName.c_str() ) ;
366 // , aLink.aLinkValue ) ;
373 bool GraphExecutor::OutNode::LoadDatas(const GraphBase::ListOfSLinks &aListOfDatas ) {
375 cdebug << "GraphExecutor::OutNode::LoadDatas " << aListOfDatas.size()
378 for ( i = 0 ; i < (int ) aListOfDatas.size() ; i++ ) {
379 GraphBase::SLink aLink = aListOfDatas[ i ] ;
380 if ( !strcmp( aLink.FromNodeName.c_str() , Graph()->Name() ) )
381 RetVal = Graph()->AddInputData( aLink.ToNodeName.c_str() ,
382 aLink.ToServiceParameterName.c_str() ,
384 // else if ( !strcmp( aLink.ToNodeName.c_str() , Graph()->Name() ) ) {
385 // RetVal = Graph()->AddOutputData( aLink.FromNodeName.c_str() ,
386 // aLink.FromServiceParameterName.c_str() ) ;
387 // Graph()->AddLink( aLink.FromNodeName.c_str() , (GraphBase::ComputingNode *) this ) ;
390 cdebug << "GraphExecutor::OutNode::LoadDatas Error " << aLink.FromNodeName
391 << " and " << aLink.ToNodeName << " differents from " << Graph()->Name()
401 GraphExecutor::InNode *GraphExecutor::OutNode::AddNode(
402 const SALOME_ModuleCatalog::Service& NodeService ,
403 GraphBase::ListOfFuncName aFuncName ,
404 GraphBase::ListOfPythonFunctions aPythonFunction ,
405 const char * NodeComponentName ,
406 const char * NodeInterfaceName ,
407 const char * NodeName ,
408 const SUPERV::KindOfNode NodeKindOfNode ,
409 const SUPERV::SDate NodeFirstCreation ,
410 const SUPERV::SDate NodeLastModification ,
411 const char * NodeEditorRelease ,
412 const char * NodeAuthor ,
413 const char * NodeComputer ,
414 const char * NodeComment ,
417 cdebug_in << "GraphExecutor::OutNode::AddNode(" << NodeComponentName << " , "
418 << NodeName << ")" << endl;
419 GraphExecutor::InNode *Nd = NULL ;
420 Nd = new GraphExecutor::InNode( _Orb, Graph()->NamingService() , NodeService ,
421 NodeComponentName , NodeInterfaceName ,
422 NodeName , NodeKindOfNode ,
423 aFuncName , aPythonFunction ,
424 NodeFirstCreation , NodeLastModification ,
425 NodeEditorRelease , NodeAuthor ,
426 NodeComputer , NodeComment , false , NodeX , NodeY ,
427 _prof_debug , _fdebug ) ;
428 Graph()->AddNode( Nd->ComputingNode() ) ;
429 cdebug_out << "GraphExecutor::OutNode::AddNode" << endl;
434 bool GraphExecutor::OutNode::Valid() {
435 cdebug_in << "GraphExecutor::OutNode::Valid" << endl;
440 _Executable = false ;
442 if ( !Graph()->CreateService() ) {
443 cdebug << "This DataFlow has invalid type(s)." << endl ;
446 int SubStreamGraphsNumber = 0 ;
447 if ( !Graph()->Sort( SubStreamGraphsNumber ) ) {
448 cdebug << "This DataFlow is not valid." << endl ;
451 if ( Graph()->IsDataStreamNode() ) {
452 StreamGraph()->SubStreamGraphsNumber( SubStreamGraphsNumber ) ;
457 Graph()->InLineServices() ;
459 Graph()->ComputingNodes() ;
463 cdebug_out << "GraphExecutor::OutNode::Valid" << endl;
468 bool GraphExecutor::OutNode::Executable() {
470 cdebug_in << "GraphExecutor::OutNode::Executable" << endl;
474 if ( Graph()->DataServerNodes() )
477 cdebug << "This DataFlow is not executable." << endl ;
478 _Executable = false ;
481 cdebug_out << "GraphExecutor::OutNode::Executable " << _Executable << endl;
485 bool GraphExecutor::OutNode::Run( const bool AndSuspend ) {
486 bool RetVal = false ;
487 cdebug_in << "GraphExecutor::OutNode::Run" << endl;
489 if ( Executable() ) {
490 _ControlState = SUPERV::VoidState ;
491 _SuspendedThreads = 0 ;
492 Graph()->ThreadNo( pthread_self() ) ;
494 _JustStarted = true ;
496 for ( i = 0 ; i < Graph()->GraphNodesSize() ; i++ ) {
497 GraphExecutor::InNode * anInNode = (GraphExecutor::InNode *) Graph()->GraphNodes( i )->GetInNode() ;
498 if ( !PyInitialized() && anInNode->IsOneOfInLineNodes() ) {
499 if ( !Py_IsInitialized() ) {
501 PySys_SetArgv( _ArgC , _ArgV ) ;
503 anInNode->InitPython() ;
504 PyInitialized( true ) ;
506 anInNode->InitialState( this ) ;
507 if ( anInNode->IsOneOfInLineNodes() ) {
508 anInNode->InitPythonFunctions( false ) ;
511 // One more time because inline nodes may share one definition of the same function
512 for ( i = 0 ; i < Graph()->GraphNodesSize() ; i++ ) {
513 GraphExecutor::InNode * anInNode = (GraphExecutor::InNode *) Graph()->GraphNodes( i )->GetInNode() ;
514 if ( anInNode->IsOneOfInLineNodes() ) {
515 if ( !anInNode->InitPythonFunctions( true ) ) {
516 anInNode->State( GraphExecutor::ErroredState ) ;
517 State( GraphExecutor::ErroredState ) ;
518 cdebug_out << "GraphExecutor::OutNode::Run InitPythonFunctions ERROR "
519 << anInNode->Name() << endl ;
525 for ( i = 0 ; i < Graph()->GraphNodesSize() ; i++ ) {
526 GraphExecutor::InNode * anInNode = (GraphExecutor::InNode *) Graph()->GraphNodes( i )->GetInNode() ;
527 if ( anInNode->IsMacroNode() ) {
528 GraphBase::Graph * aMacroGraph = anInNode->GraphMacroNode() ;
529 cdebug << "GraphExecutor::OutNode::Run " << anInNode << " MacroNode " << aMacroGraph
530 << aMacroGraph->Name() << endl ;
531 SUPERV::Graph_var iobject = anInNode->GraphMacroNode()->MacroObject() ;
532 if ( CORBA::is_nil( iobject ) ) {
533 cdebug << "MacroObject() is a nil object. Error" << endl ;
536 cdebug << "MacroObject() is NOT a nil object." << endl ;
541 if ( Graph()->GraphMacroLevel() != 0 ) {
542 cdebug << "Execution starting GraphExecutor::Action_DataOk_RunService Node "
543 << Graph()->Name() << " GraphMacroLevel " << Graph()->GraphMacroLevel() << endl ;
544 PushEvent( NULL , GraphExecutor::NoDataReadyEvent ,
545 GraphExecutor::DataUndefState ) ;
548 cdebug << "Execution starting GraphExecutor::Action_DataOk_RunService Node "
549 << Graph()->Name() << " GraphMacroLevel " << Graph()->GraphMacroLevel() << endl ;
550 PushEvent( NULL , GraphExecutor::ReadyEvent ,
551 GraphExecutor::DataReadyState ) ;
552 State( GraphExecutor::DataReadyState ) ;
554 cdebug << pthread_self() << " GraphExecutor::OutNode::Run Start of the " << Graph()->HeadNodesSize()
555 << " HeadNodes" << endl ;
556 for ( i = 0 ; i < Graph()->HeadNodesSize() ; i++ ) {
557 GraphExecutor::InNode * anInNode = (GraphExecutor::InNode *) Graph()->HeadNodes( i )->GetInNode() ;
558 cdebug << pthread_self() << "GraphExecutor::OutNode::Run Start of HeadNode " << i << " "
559 << anInNode->Name() << endl ;
560 if ( anInNode->State() != GraphExecutor::DataReadyState ) {
561 cdebug << "GraphExecutor::OutNode::Run inconsistency State of Node "
562 << anInNode->Name() << " : " << anInNode->State() << endl ;
563 cdebug_out << "GraphExecutor::OutNode::Run State ERROR" << endl ;
566 // PushEvent( anInNode , GraphExecutor::ReadyEvent ,
567 // GraphExecutor::DataReadyState ) ;
568 anInNode->CreateNewThread( true ) ;
569 anInNode->DataFromNode( Graph()->Name() ) ;
571 anInNode->State( GraphExecutor::DataWaitingState ) ;
572 anInNode->ControlState( SUPERV::ToSuspendStartState ) ;
573 if ( !anInNode->SendEvent( GraphExecutor::SomeDataReadyEvent ) ) {
574 cdebug << "InNode::SendEvent( SomeDataReadyEvent ) ERROR Node "
575 << anInNode->Name() << endl ;
576 cdebug_out << "GraphExecutor::OutNode::Run SendEvent ERROR" << endl ;
579 anInNode->SuspendedWait() ;
581 else if ( anInNode->IsMacroNode() ) {
582 if ( !anInNode->SendEvent( GraphExecutor::SomeDataReadyEvent ) ) {
583 cdebug << "InNode::SendEvent( SomeDataReadyEvent ) ERROR Node "
584 << anInNode->Name() << endl ;
585 cdebug_out << "GraphExecutor::OutNode::Run SendEvent ERROR" << endl ;
588 cdebug << pthread_self() << " GraphExecutor::OutNode::Run " << anInNode->Name() << "->RunningWait"
590 anInNode->RunningWait() ;
591 cdebug << pthread_self() << " GraphExecutor::OutNode::Run " << anInNode->Name() << "->RunningWaited"
594 else if ( !anInNode->IsMacroNode() ) {
595 if ( !anInNode->SendEvent( GraphExecutor::ExecuteEvent ) ) {
596 cdebug << "InNode::SendEvent( ExecuteEvent ) ERROR Node "
597 << anInNode->Name() << endl ;
598 cdebug_out << "GraphExecutor::OutNode::Run SendEvent ERROR" << endl ;
601 anInNode->RunningWait() ;
606 PushEvent( NULL , GraphExecutor::SuspendedReadyEvent ,
607 GraphExecutor::SuspendedReadyState ) ;
610 PushEvent( NULL , GraphExecutor::ExecutingEvent ,
611 GraphExecutor::ExecutingState ) ;
612 if (AutomatonState() == GraphExecutor::DataReadyState) {
613 State( GraphExecutor::ExecutingState ) ;
616 // ostringstream astr ;
617 // astr << "Graph " << Graph()->Name() << " is running" ;
618 // Graph()->ObjImpl()->sendMessage( NOTIF_STEP, astr.str().c_str() ) ;
623 cdebug_out << "GraphExecutor::OutNode::Run GraphMacroLevel " << Graph()->GraphMacroLevel() << endl ;
627 bool GraphExecutor::OutNode::Run( const char * aNodeName ,
628 const char * AtNodeName ,
629 const bool AndSuspend ) {
630 bool RetVal = false ;
631 cdebug_in << "GraphExecutor::OutNode::Run( " << aNodeName << " , "
632 << AtNodeName << " , " << AndSuspend << ")" << endl;
633 GraphExecutor::InNode *anInNode = (GraphExecutor::InNode *) Graph()->GetGraphNode( aNodeName )->GetInNode() ;
635 RetVal = anInNode->ReStart( AtNodeName , AndSuspend ) ;
637 cdebug_out << "GraphExecutor::OutNode::Run" << endl ;
641 void GraphExecutor::OutNode::CheckAllDone() {
643 cdebug_in << "GraphExecutor::OutNode::CheckAllDone " << endl;
644 GraphExecutor::AutomatonState OutNodeState = GraphExecutor::SuccessedState ;
645 GraphExecutor::AutomatonState InNodeState ;
646 bool AllDone = true ;
648 for ( j = 0 ; j < Graph()->QueueNodesSize() ; j++ ) {
649 InNodeState = ( (GraphExecutor::InNode * ) Graph()->QueueNodes( j )->GetInNode() )->State() ;
651 << ( (GraphExecutor::InNode * ) Graph()->QueueNodes( j )->GetInNode() )->Name()
652 << " " << theAutomaton->StateName( InNodeState ) << endl ;
653 if ( InNodeState != GraphExecutor::SuccessedState &&
654 InNodeState != GraphExecutor::ErroredState &&
655 InNodeState != GraphExecutor::DataWaitingState ) {
658 if ( InNodeState != GraphExecutor::SuccessedState &&
659 InNodeState != GraphExecutor::DataWaitingState &&
660 InNodeState != GraphExecutor::DataReadyState ) {
661 OutNodeState = InNodeState ;
665 if( _Threads == 0 && _SuspendedThreads == 0 ) {
666 if ( OutNodeState != GraphExecutor::ErroredState ) {
667 OutNodeState = GraphExecutor::SuccessedState ;
676 for ( j = 0 ; j < Graph()->GraphNodesSize() ; j++ ) {
677 GraphExecutor::InNode * aNode ;
678 aNode = (GraphExecutor::InNode * ) Graph()->GraphNodes( j )->GetInNode() ;
679 SUPERV::GraphState aState = AutomatonGraphState( aNode->State() ) ;
680 cdebug << "GraphExecutor::OutNode::CheckAllDone " << aNode->Name() << " "
681 << theAutomaton->StateName( aNode->State() ) << " CreateNewThread " << aNode->CreateNewThread()
683 if ( aState == SUPERV::ErrorState ||
684 aState == SUPERV::SuspendErroredState ||
685 aState == SUPERV::KillState ||
686 aState == SUPERV::StopState ) {
687 OutNodeState = aNode->State() ;
688 State( OutNodeState ) ;
690 else if ( aState == SUPERV::ReadyState ||
691 aState == SUPERV::SuspendReadyState ||
692 aState == SUPERV::RunningState ||
693 aState == SUPERV::SuspendDoneState ||
694 aState == SUPERV::SuspendErroredState ||
695 aState == SUPERV::ReRunState ||
696 aState == SUPERV::ReStartState ||
697 aState == SUPERV::SuspendState ) {
700 aNode->SuspendedAction() ;
701 aNode->DoneAction() ;
703 // PushEvent AFTER State and _Done ! ...
704 if ( alivenodes == 0 ) {
705 State( OutNodeState ) ;
707 _JustStarted = false ;
709 PushEvent( NULL , GraphExecutor::EndExecuteEvent ,
712 // PyInitialized( false ) ;
716 MESSAGE("================================================================================") ;
717 MESSAGE( Graph()->Name() << " IS DONE : " << theAutomaton->StateName( AutomatonState() ) << " EventQSize "
719 MESSAGE("================================================================================") ;
720 cdebug << "================================================================================" << endl ;
721 cdebug << Graph()->Name() << " IS DONE : " << theAutomaton->StateName( AutomatonState() ) << " EventQSize "
722 << EventQSize() << endl ;
723 cdebug << "================================================================================" << endl ;
724 // ostringstream astr ;
725 // astr << "Graph " << Graph()->Name() << " is done : "
726 // << theAutomaton->StateName( AutomatonState() ) ;
727 // Graph()->ObjImpl()->sendMessage( NOTIF_STEP, astr.str().c_str() ) ;
728 //cout << Graph()->Name() << " IS DONE : " << theAutomaton->StateName( AutomatonState() ) << " EventQSize "
729 // << EventQSize() << endl ;
731 cdebug_out << "GraphExecutor::OutNode::CheckAllDone " << IsDone()
732 << " GraphAutomatonState " << theAutomaton->StateName( AutomatonState() )
733 << " State " << State() << " Threads " << _Threads << " SuspendedThreads "
734 << _SuspendedThreads << " EventQSize " << EventQSize() << endl ;
737 void GraphExecutor::OutNode::PThreadLock( pthread_mutex_t * aMutex , char * errmsg ) {
738 // if ( strcmp( errmsg , "EventLoop" ) && strcmp( errmsg , "EventW" ) ) {
739 // cdebug << "GraphExecutor::OutNode::PThreadLock " << pthread_self() << " " << aMutex << " "
740 // << errmsg << endl ;
742 if ( pthread_mutex_lock( aMutex ) ) {
746 // if ( strcmp( errmsg , "EventLoop" ) && strcmp( errmsg , "EventW" ) ) {
747 // cdebug << "GraphExecutor::OutNode::PThreadLocked " << pthread_self() << " " << aMutex << " "
748 // << errmsg << endl ;
752 void GraphExecutor::OutNode::PThreadUnLock( pthread_mutex_t * aMutex , char * errmsg ) {
753 // if ( strcmp( errmsg , "EventLoop" ) && strcmp( errmsg , "EventW" ) ) {
754 // cdebug << " GraphExecutor::OutNode::PThreadUnLock " << pthread_self() << " " << aMutex << " "
755 // << errmsg << endl ;
757 if ( pthread_mutex_unlock( aMutex ) ) {
763 void GraphExecutor::OutNode::PyThreadLock() {
764 // cout << " GraphExecutor::OutNode::PyThreadLock " << pthread_self() << endl ;
765 if ( pthread_mutex_lock( &_PyMutexWait ) ) {
766 perror( "GraphExecutor::OutNode::PyThreadLock" ) ;
769 theAutomaton->PyLock() ;
770 // cout << " GraphExecutor::OutNode::PyThreadLocked " << pthread_self() << endl ;
773 void GraphExecutor::OutNode::PyThreadUnLock() {
774 // cout << " GraphExecutor::OutNode::PyThreadUnLock " << pthread_self() << endl ;
775 if ( pthread_mutex_unlock( &_PyMutexWait ) ) {
776 perror( "GraphExecutor::OutNode::PyThreadUnLock" ) ;
779 theAutomaton->PyUnLock() ;
780 // cout << " GraphExecutor::OutNode::PyThreadUnLocked " << pthread_self() << endl ;
783 void GraphExecutor::OutNode::NewThread() {
784 if ( pthread_mutex_lock( &_MutexWait ) ) {
785 perror("pthread_mutex_lock _NewThread") ;
789 cdebug << "NewThread : " << _Threads << " running threads "
790 << _SuspendedThreads << " suspended threads"
792 if ( pthread_mutex_unlock( &_MutexWait ) ) {
793 perror("pthread_mutex_unlock _NewThread") ;
798 void GraphExecutor::OutNode::ExitThread() {
799 if ( pthread_mutex_lock( &_MutexWait ) ) {
800 perror("pthread_mutex_lock _ExitThread") ;
804 theAutomaton->JoinThread( pthread_self() ) ;
805 if ( pthread_cond_signal( &_JoinWait ) ) {
806 perror("ExitThread pthread_cond_signal ") ;
808 cdebug << "ExitThread : " << _Threads << " running threads "
809 << _SuspendedThreads << " suspended threads"
811 if ( pthread_mutex_unlock( &_MutexWait ) ) {
812 perror("pthread_mutex_unlock _ExitThread") ;
815 if ( _Threads == 0 && _SuspendedThreads == 0 ) {
818 theAutomaton->Executed() ;
822 void GraphExecutor::OutNode::JoinedWait() {
823 if ( pthread_mutex_lock( &_MutexWait ) ) {
824 perror("pthread_mutex_lock JoinedWait") ;
828 if ( pthread_cond_wait( &_JoinWait , &_MutexWait ) ) {
829 perror("JoinedWait pthread_cond_wait ") ;
832 if ( pthread_mutex_unlock( &_MutexWait ) ) {
833 perror("pthread_mutex_unlock JoinedWait") ;
838 void GraphExecutor::OutNode::SuspendThread() {
839 if ( pthread_mutex_lock( &_MutexWait ) ) {
840 perror("pthread_mutex_lock _SuspendThread") ;
843 _SuspendedThreads += 1 ;
844 cdebug << "SuspendThread : " << _Threads << " running threads "
845 << _SuspendedThreads << " suspended threads"
847 if ( pthread_mutex_unlock( &_MutexWait ) ) {
848 perror("pthread_mutex_unlock _SuspendThread") ;
851 if ( IsSuspended() ) {
852 PushEvent( NULL , GraphExecutor::SuspendEvent , GraphExecutor::SuspendedState ) ;
855 void GraphExecutor::OutNode::ResumeThread() {
856 if ( pthread_mutex_lock( &_MutexWait ) ) {
857 perror("pthread_mutex_lock _ResumeThread") ;
860 _SuspendedThreads -= 1 ;
861 cdebug << "ResumeThread : " << _Threads << " running threads "
862 << _SuspendedThreads << " suspended threads"
864 if ( pthread_mutex_unlock( &_MutexWait ) ) {
865 perror("pthread_mutex_unlock _ResumeThread") ;
870 long GraphExecutor::OutNode::Thread( const char * aNodeName ) {
872 GraphExecutor::InNode *anInNode = (GraphExecutor::InNode *) Graph()->GetGraphNode( aNodeName )->GetInNode() ;
874 RetVal = anInNode->ThreadNo() ;
879 SUPERV::GraphEvent GraphExecutor::OutNode::AutomatonGraphEvent(GraphExecutor::NodeEvent anEvent ) {
880 SUPERV::GraphEvent aGraphEvent ;
882 case GraphExecutor::UndefinedEvent : {
883 aGraphEvent = SUPERV::UndefinedEvent ;
886 case GraphExecutor::NewThreadEvent : {
887 aGraphEvent = SUPERV::NewThreadEvent ;
890 case GraphExecutor::SuspendEvent : {
891 aGraphEvent = SUPERV::SuspendEvent ;
894 case GraphExecutor::ResumeEvent : {
895 aGraphEvent = SUPERV::ResumeEvent ;
898 case GraphExecutor::KillEvent : {
899 aGraphEvent = SUPERV::KillEvent ;
902 case GraphExecutor::StopEvent : {
903 aGraphEvent = SUPERV::StopEvent ;
906 case GraphExecutor::ExecuteEvent : {
907 aGraphEvent = SUPERV::RunningEvent ;
910 case GraphExecutor::SuccessEvent : {
911 aGraphEvent = SUPERV::DoneEvent ;
914 case GraphExecutor::ErrorEvent : {
915 aGraphEvent = SUPERV::ErroredEvent ;
918 case GraphExecutor::ReStartEvent : {
919 aGraphEvent = SUPERV::ReRunEvent ;
922 case GraphExecutor::ReStartAndSuspendEvent : {
923 aGraphEvent = SUPERV::ReStartEvent ;
926 case GraphExecutor::NoDataReadyEvent : {
927 aGraphEvent = SUPERV::WaitingEvent ;
930 case GraphExecutor::SomeDataReadyEvent : {
931 aGraphEvent = SUPERV::WaitingEvent ;
934 case GraphExecutor::NotAllDataReadyEvent : {
935 aGraphEvent = SUPERV::WaitingEvent ;
938 case GraphExecutor::AllDataReadyEvent : {
939 aGraphEvent = SUPERV::ReadyEvent ;
942 case GraphExecutor::ReadyEvent : {
943 aGraphEvent = SUPERV::ReadyEvent ;
946 case GraphExecutor::SuspendedReadyEvent : {
947 aGraphEvent = SUPERV::SuspendEvent ;
950 case GraphExecutor::ResumedReadyEvent : {
951 aGraphEvent = SUPERV::ResumeEvent ;
954 case GraphExecutor::KilledReadyEvent : {
955 aGraphEvent = SUPERV::KillEvent ;
958 case GraphExecutor::StoppedReadyEvent : {
959 aGraphEvent = SUPERV::StopEvent ;
962 case GraphExecutor::ExecutingEvent : {
963 aGraphEvent = SUPERV::RunningEvent ;
966 case GraphExecutor::SuspendedExecutingEvent : {
967 aGraphEvent = SUPERV::SuspendEvent ;
970 case GraphExecutor::ResumedExecutingEvent : {
971 aGraphEvent = SUPERV::ResumeEvent ;
974 case GraphExecutor::KilledExecutingEvent : {
975 aGraphEvent = SUPERV::KillEvent ;
978 case GraphExecutor::StoppedExecutingEvent : {
979 aGraphEvent = SUPERV::StopEvent ;
982 case GraphExecutor::SuccessedExecutingEvent : {
983 aGraphEvent = SUPERV::DoneEvent ;
986 case GraphExecutor::ErroredExecutingEvent : {
987 aGraphEvent = SUPERV:: ErroredEvent;
990 case GraphExecutor::SuspendedSuccessedEvent : {
991 aGraphEvent = SUPERV::SuspendEvent ;
994 case GraphExecutor::SuspendedErroredEvent : {
995 aGraphEvent = SUPERV::SuspendEvent ;
998 case GraphExecutor::ResumedSuccessedEvent : {
999 aGraphEvent = SUPERV::ResumeEvent ;
1002 case GraphExecutor::ResumedErroredEvent : {
1003 aGraphEvent = SUPERV::ResumeEvent ;
1006 case GraphExecutor::KilledEvent : {
1007 aGraphEvent = SUPERV::KillEvent ;
1010 case GraphExecutor::StoppedEvent : {
1011 aGraphEvent = SUPERV::StopEvent ;
1014 case GraphExecutor::ReStartedEvent : {
1015 aGraphEvent = SUPERV::ReRunEvent ;
1018 case GraphExecutor::ReStartedAndSuspendEvent : {
1019 aGraphEvent = SUPERV::ReStartEvent ;
1022 case GraphExecutor::EndExecuteEvent : {
1023 aGraphEvent = SUPERV::DoneEvent ;
1027 cdebug << " GraphExecutor::OutNode::AutomatonGraphEvent Error Undefined Event : "
1028 << anEvent << endl ;
1029 aGraphEvent = SUPERV::UndefinedEvent ;
1032 return aGraphEvent ;
1035 SUPERV::GraphState GraphExecutor::OutNode::AutomatonGraphState(GraphExecutor::AutomatonState aState ) {
1036 SUPERV::GraphState aGraphState ;
1038 case GraphExecutor::UnKnownState : {
1039 aGraphState = SUPERV::UndefinedState ;
1042 case GraphExecutor::DataUndefState : {
1043 aGraphState = SUPERV::UndefinedState ;
1046 case GraphExecutor::DataWaitingState : {
1047 aGraphState = SUPERV::WaitingState ;
1050 case GraphExecutor::DataReadyState : {
1051 aGraphState = SUPERV::ReadyState ;
1054 case GraphExecutor::SuspendedReadyState : {
1055 aGraphState = SUPERV::SuspendReadyState ;
1058 case GraphExecutor::ResumedReadyState : {
1059 aGraphState = SUPERV::ReadyState ;
1062 case GraphExecutor::KilledReadyState : {
1063 aGraphState = SUPERV::KillState ;
1066 case GraphExecutor::StoppedReadyState : {
1067 aGraphState = SUPERV::StopState ;
1070 case GraphExecutor::ExecutingState : {
1071 aGraphState = SUPERV::RunningState ;
1074 case GraphExecutor::SuspendedExecutingState : {
1075 aGraphState = SUPERV::SuspendState ;
1078 case GraphExecutor::ResumedExecutingState : {
1079 aGraphState = SUPERV::RunningState ;
1082 case GraphExecutor::KilledExecutingState : {
1083 aGraphState = SUPERV::KillState ;
1086 case GraphExecutor::StoppedExecutingState : {
1087 aGraphState = SUPERV::StopState ;
1090 case GraphExecutor::SuccessedExecutingState : {
1091 aGraphState = SUPERV::DoneState ;
1094 case GraphExecutor::ErroredExecutingState : {
1095 aGraphState = SUPERV::ErrorState ;
1098 case GraphExecutor::SuspendedSuccessedState : {
1099 aGraphState = SUPERV::SuspendDoneState ;
1102 case GraphExecutor::SuspendedErroredState : {
1103 aGraphState = SUPERV::SuspendErroredState ;
1106 case GraphExecutor::ResumedSuccessedState : {
1107 aGraphState = SUPERV::DoneState ;
1110 case GraphExecutor::ResumedErroredState : {
1111 aGraphState = SUPERV::ErrorState ;
1114 case GraphExecutor::KilledSuccessedState : {
1115 aGraphState = SUPERV::KillState ;
1118 case GraphExecutor::KilledErroredState : {
1119 aGraphState = SUPERV::KillState ;
1122 case GraphExecutor::StoppedSuccessedState : {
1123 aGraphState = SUPERV::StopState ;
1126 case GraphExecutor::StoppedErroredState : {
1127 aGraphState = SUPERV::StopState ;
1130 case GraphExecutor::SuccessedState : {
1131 aGraphState = SUPERV::DoneState ;
1134 case GraphExecutor::ErroredState : {
1135 aGraphState = SUPERV::ErrorState ;
1138 case GraphExecutor::SuspendedState : {
1139 aGraphState = SUPERV::SuspendState ;
1142 case GraphExecutor::KilledState : {
1143 aGraphState = SUPERV::KillState ;
1146 case GraphExecutor::StoppedState : {
1147 aGraphState = SUPERV::StopState ;
1150 case GraphExecutor::ReRunnedState : {
1151 aGraphState = SUPERV::ReRunState ;
1154 case GraphExecutor::ReStartedState : {
1155 aGraphState = SUPERV::ReStartState ;
1159 cdebug << " GraphExecutor::OutNode::AutomatonGraphState Error Undefined State : "
1160 << aGraphState << endl ;
1161 aGraphState = SUPERV::UndefinedState ;
1164 return aGraphState ;
1167 int GraphExecutor::OutNode::GetListSize() {
1168 return _EventNodes.size();
1171 bool GraphExecutor::OutNode::PushEvent( GraphExecutor::InNode * aNode ,
1172 GraphExecutor::NodeEvent anEvent ,
1173 GraphExecutor::AutomatonState aState ) {
1174 // cdebug_in << "PushEvent Threads " << Threads() << " SuspendedThreads "
1175 // << SuspendedThreads() << endl ;
1176 if ( pthread_mutex_lock( &_MutexWait ) ) {
1177 perror("PushEvent pthread_mutex_lock ") ;
1181 _EventNodes.push_back( aNode->Name() ) ;
1184 _EventNodes.push_back( Graph()->Name() ) ;
1186 _Events.push_back( anEvent ) ;
1187 _States.push_back( aState ) ;
1188 pthread_cond_broadcast( &_EventWait );
1190 // cdebug << aNode->ThreadNo() << " PushEvent " << aNode->Name() ;
1191 // cdebug << " " << aNode->Automaton()->EventName( anEvent )
1192 // << " " << aNode->Automaton()->StateName( aState )
1193 // << " ControleState "
1194 // << aNode->Automaton()->ControlStateName( aNode->ControlState() ) ;
1197 // cdebug << "PushEvent " << Graph()->Name() ;
1198 // cdebug << " " << theAutomaton->EventName( anEvent ) << " "
1199 // << theAutomaton->StateName( aState ) ;
1201 // cdebug_out << "PushEvent Threads " << Threads() << " SuspendedThreads "
1202 // << SuspendedThreads() << endl ;
1204 if ( _EventNodes.size() > 101 ) {
1205 while ( _EventNodes.size() > 31 ) {
1206 _EventNodes.pop_front() ;
1207 _Events.pop_front() ;
1208 _States.pop_front() ;
1212 if ( pthread_mutex_unlock( &_MutexWait ) ) {
1213 perror("PushEvent pthread_mutex_unlock ") ;
1219 bool GraphExecutor::OutNode::StateWait( SUPERV::GraphState aState ) {
1223 bool GraphExecutor::OutNode::Event( char ** aNodeName ,
1224 SUPERV::GraphEvent & anEvent ,
1225 SUPERV::GraphState & aState ,
1228 int SuspendedThreadsNumber ;
1229 if ( _EventNodes.size() > 0 ) {
1230 cdebug_in << "GraphExecutor::OutNode::Event " << _EventNodes.size() << " in queue" << endl ;
1232 if ( pthread_mutex_lock( &_MutexWait ) ) {
1233 perror("EventLoop pthread_mutex_lock ") ;
1236 _JustStarted = false ;
1237 ThreadsNumber = Threads() ;
1238 SuspendedThreadsNumber = SuspendedThreads() ;
1239 bool RetVal = ( ThreadsNumber - SuspendedThreadsNumber) != 0 ||
1240 _EventNodes.size() > 0 ;
1241 char * NodeName = "" ;
1242 GraphExecutor::NodeEvent theEvent = GraphExecutor::UndefinedEvent ;
1243 GraphExecutor::AutomatonState theState = GraphExecutor::UnKnownState ;
1244 anEvent = SUPERV::UndefinedEvent ;
1245 aState = SUPERV::UndefinedState ;
1246 if ( ( Done() || IsKilled() || IsStopped() ) && _EventNodes.size() == 0 ) {
1247 // cdebug << "EventLoop Done()/IsKilled()/IsStopped() && _EventNodes.size() == 0" << endl ;
1250 else if ( !WithWait && _EventNodes.size() == 0 ) {
1251 anEvent = SUPERV::NoEvent ;
1252 aState = SUPERV::NoState ;
1255 else if ( RetVal ) {
1256 while ( !IsSuspended() && _EventNodes.size() == 0 ) {
1257 // cdebug << "EventLoop pthread_cond_wait _EventWait" << endl ;
1258 pthread_cond_wait( &_EventWait , &_MutexWait );
1259 // cdebug << "EventLoop pthread_cond_waited _EventWait"
1260 // << " _EventNodes.size() " << _EventNodes.size() << endl ;
1262 if ( _EventNodes.size() ) {
1263 ThreadsNumber = Threads() ;
1264 NodeName = _EventNodes.front() ;
1265 _EventNodes.pop_front() ;
1266 theEvent = _Events.front() ;
1267 anEvent = AutomatonGraphEvent( theEvent ) ;
1268 _Events.pop_front() ;
1269 theState = _States.front() ;
1270 aState = AutomatonGraphState( theState ) ;
1271 _States.pop_front() ;
1274 *aNodeName = NodeName ;
1275 if ( IsSuspended() && _EventNodes.size() == 0 ) {
1278 if ( anEvent != SUPERV::NoEvent ) {
1279 // cdebug << pthread_self() << "EventLoop "
1280 // << NodeName << " " << theAutomaton->StateName( theState )
1281 // << " _EventNodes.size() " << _EventNodes.size()
1282 // << " Threads " << Threads() << " SuspendedThreads "
1283 // << SuspendedThreads() << " RetVal " << RetVal << endl ;
1285 if ( pthread_mutex_unlock( &_MutexWait ) ) {
1286 perror("EventLoop pthread_mutex_lock ") ;
1289 if ( _EventNodes.size() > 0 ) {
1290 cdebug_out << "GraphExecutor::OutNode::Event " << _EventNodes.size() << " in queue" << endl ;
1295 bool GraphExecutor::OutNode::EventW( char ** aNodeName ,
1296 SUPERV::GraphEvent & anEvent ,
1297 SUPERV::GraphState & aState ) {
1300 aState = SUPERV::UndefinedState ;
1302 aState != SUPERV::SuspendReadyState &&
1303 aState != SUPERV::RunningState &&
1304 aState != SUPERV::SuspendDoneState &&
1305 aState != SUPERV::SuspendErroredState ) {
1306 NodeName = Graph()->Name() ;
1307 while ( sts && !strcmp( NodeName , Graph()->Name() ) ) {
1308 sts = EventWait( aNodeName , anEvent , aState ) ;
1309 NodeName = *aNodeName ;
1315 bool GraphExecutor::OutNode::EventWait( char ** aNodeName ,
1316 SUPERV::GraphEvent & anEvent ,
1317 SUPERV::GraphState & aState ) {
1318 if ( pthread_mutex_lock( &_MutexWait ) ) {
1319 perror("EventW pthread_mutex_lock ") ;
1323 int SuspendedThreadsNumber ;
1324 ThreadsNumber = Threads() ;
1325 SuspendedThreadsNumber = SuspendedThreads() ;
1326 bool RetVal = ( ThreadsNumber - SuspendedThreadsNumber) != 0 ||
1327 _EventNodes.size() > 0 ;
1328 cdebug << "--> EventW RetVal " << RetVal << endl ;
1329 char * NodeName = "" ;
1330 GraphExecutor::NodeEvent theEvent = GraphExecutor::UndefinedEvent ;
1331 GraphExecutor::AutomatonState theState = GraphExecutor::UnKnownState ;
1332 anEvent = SUPERV::UndefinedEvent ;
1333 aState = SUPERV::UndefinedState ;
1334 if ( IsDone() && _EventNodes.size() == 0 ) {
1335 cdebug << "EventW IsDone() && _EventNodes.size() == 0" << endl ;
1338 else if ( RetVal ) {
1339 GraphExecutor::InNode * aNode = NULL ;
1340 while ( aNode == NULL && RetVal ) {
1341 NodeName = _EventNodes.front() ;
1342 theEvent = _Events.front() ;
1343 anEvent = AutomatonGraphEvent( theEvent ) ;
1344 theState = _States.front() ;
1345 aState = AutomatonGraphState( theState ) ;
1347 if ( _JustStarted ) {
1348 _JustStarted = false ;
1351 _EventNodes.pop_front() ;
1352 _Events.pop_front() ;
1353 _States.pop_front() ;
1356 aNode = ((GraphExecutor::InNode *) Graph()->GetGraphNode( NodeName )->GetInNode()) ;
1357 cdebug << "EventW Previous Node " << NodeName << " ThreadsNumber "
1359 << " _EventNodes.size() " << _EventNodes.size() << " "
1360 << theAutomaton->StateName( theState )
1361 << " Threads " << Threads() << " SuspendedThreads "
1362 << SuspendedThreads() << endl ;
1365 else if ( IsDone() && _EventNodes.size() == 0 ) {
1366 cdebug << "EventW IsDone() && _EventNodes.size() == 0" << endl ;
1370 cdebug << "EventW Not InNode " << NodeName
1371 << " _EventNodes.size() " << _EventNodes.size() << endl ;
1372 while ( _EventNodes.size() == 0 ) {
1373 pthread_cond_wait( &_EventWait , &_MutexWait );
1375 cdebug << "EventW pthread_cond_waited Not InNode " << NodeName
1376 << " _EventNodes.size() " << _EventNodes.size() << endl ;
1381 if ( aState == SUPERV::SuspendState ||
1382 aState == SUPERV::SuspendReadyState ||
1383 aState == SUPERV::SuspendDoneState ||
1384 aState == SUPERV::SuspendErroredState ) {
1385 aNode->ControlState( SUPERV::ToSuspendState ) ;
1386 if ( aNode->IsSuspended() ) {
1387 if ( pthread_mutex_unlock( &_MutexWait ) ) {
1388 perror("EventW pthread_mutex_lock ") ;
1391 cdebug << "EventW " << aNode->Name() << " ResumeAction" << endl ;
1392 aNode->ResumeAction( GraphExecutor::ToResumeEvent ) ;
1393 cdebug << "EventW " << aNode->Name() << " ResumedAction" << endl ;
1394 if ( pthread_mutex_lock( &_MutexWait ) ) {
1395 perror("EventW pthread_mutex_lock ") ;
1400 cdebug << "EventW inconsistent SuspendState" << endl ;
1405 if ( aNode->IsDone() ) {
1409 cdebug << "EventW NOT SuspendedState _EventNodes.size() "
1410 << _EventNodes.size() << endl ;
1415 cdebug << "EventW " << aNode->Name() << " pthread_cond_wait" << endl ;
1416 while ( _EventNodes.size() == 0 ) {
1417 pthread_cond_wait( &_EventWait , &_MutexWait );
1419 ThreadsNumber = Threads() ;
1420 NodeName = _EventNodes.front() ;
1421 theEvent = _Events.front() ;
1422 anEvent = AutomatonGraphEvent( theEvent ) ;
1423 theState = _States.front() ;
1424 aState = AutomatonGraphState( theState ) ;
1428 *aNodeName = NodeName ;
1429 cdebug << "<-- EventW RetVal " << RetVal << " " << NodeName
1430 << " Threads " << Threads() << " SuspendedThreads "
1431 << SuspendedThreads()
1432 << " _EventNodes.size() " << _EventNodes.size()
1433 << " " << theAutomaton->EventName( theEvent ) << " "
1434 << theAutomaton->StateName( theState ) << endl ;
1435 if ( pthread_mutex_unlock( &_MutexWait ) ) {
1436 perror("EventW pthread_mutex_lock ") ;
1441 long GraphExecutor::OutNode::EventQSize() {
1442 return _EventNodes.size() ;
1445 void GraphExecutor::OutNode::EventList() {
1446 if ( pthread_mutex_lock( &_MutexWait ) ) {
1447 perror("EventList pthread_mutex_lock ") ;
1450 list< char * >::iterator itEventNodes = _EventNodes.begin() ;
1451 list< GraphExecutor::NodeEvent >::iterator itEvents = _Events.begin() ;
1452 list< GraphExecutor::AutomatonState >::iterator itStates = _States.begin() ;
1453 while ( itEventNodes != _EventNodes.end() ) {
1454 cdebug << pthread_self() << "EVENTSTACK "
1455 << *itEventNodes << " " << *itEvents << " "
1456 << theAutomaton->StateName( *itStates )
1457 << " Threads " << Threads() << " SuspendedThreads " << SuspendedThreads() << endl ;
1462 if ( pthread_mutex_unlock( &_MutexWait ) ) {
1463 perror("EventList pthread_mutex_lock ") ;
1468 void GraphExecutor::OutNode::SendSomeDataReady( const char * aNodeName ) {
1469 cdebug_in << "GraphExecutor::OutNode::SendSomeDataReady " << aNodeName << "->SendSomeDataReady( "
1470 << Graph()->Name() << " )" << endl;
1472 sts = ((GraphExecutor::InNode * ) Graph()->GetChangeGraphNode( aNodeName )->GetInNode())->SendSomeDataReady( Graph()->Name() ) ;
1473 cdebug_out << "GraphExecutor::OutNode::SendSomeDataReady sts " << sts << endl ;
1476 void GraphExecutor::OutNode::State(GraphExecutor::AutomatonState aState ) {
1477 // cdebug << "GraphExecutor::OutNode::State " << Graph()->Name() << " "
1478 // << theAutomaton->StateName( AutomatonGraphState( _State ) ) << " ---> "
1479 // << theAutomaton->StateName( AutomatonGraphState( aState ) ) << endl ;
1483 SUPERV::GraphState GraphExecutor::OutNode::State() {
1484 // cdebug_in << "GraphExecutor::OutNode::State" << endl;
1485 // cdebug_out << "GraphExecutor::OutNode::State" << endl ;
1486 // cdebug << "GraphExecutor::OutNode::State GraphState "
1487 // << theAutomaton->StateName( AutomatonGraphState( _State ) ) << endl ;
1488 return AutomatonGraphState( _State ) ;
1491 SUPERV::GraphState GraphExecutor::OutNode::State( const char * NodeName ) {
1492 // cdebug_in << "GraphExecutor::OutNode::State " << NodeName << endl;
1493 GraphExecutor::AutomatonState aret = GraphExecutor::UnKnownState ;
1494 const GraphBase::ComputingNode * aCNode = Graph()->GetGraphNode( NodeName ) ;
1496 GraphExecutor::InNode *anInNode = (GraphExecutor::InNode *)aCNode->GetInNode() ;
1498 aret = anInNode->State() ;
1499 // cdebug << "GraphExecutor::OutNode::State( " << NodeName << " ) "
1500 // << theAutomaton->StateName( AutomatonGraphState( aret ) ) << endl ;
1503 // cdebug_out << "GraphExecutor::OutNode::State" << endl ;
1504 return AutomatonGraphState( aret ) ;
1507 SUPERV::GraphState GraphExecutor::OutNode::State( const char * NodeName ,
1508 const char * ServiceParameterName ) {
1509 // cdebug_in << "GraphExecutor::OutNode::State " << NodeName << " "
1510 // << ServiceParameterName<< endl;
1511 SUPERV::GraphState aret = Graph()->PortState( NodeName , ServiceParameterName ) ;
1512 // cdebug_out << "GraphExecutor::OutNode::State" << endl ;
1516 GraphExecutor::AutomatonState GraphExecutor::OutNode::AutomatonState() {
1517 // cdebug_in << "GraphExecutor::OutNode::AutomatonState" << endl;
1518 // cdebug_out << "GraphExecutor::OutNode::AutomatonState" << endl ;
1522 GraphExecutor::AutomatonState GraphExecutor::OutNode::AutomatonState( const char * NodeName ) {
1523 // cdebug_in << "GraphExecutor::OutNode::AutomatonState " << NodeName << endl;
1524 GraphExecutor::AutomatonState aret = GraphExecutor::UnKnownState ;
1525 GraphExecutor::InNode *anInNode = (GraphExecutor::InNode *) Graph()->GetGraphNode( NodeName )->GetInNode() ;
1527 aret = anInNode->State() ;
1528 // cdebug_out << "GraphExecutor::OutNode::AutomatonState" << endl ;
1532 SUPERV::ControlState GraphExecutor::OutNode::ControlState() {
1533 // cdebug_in << "GraphExecutor::OutNode::ControlState" << endl;
1534 // cdebug_out << "GraphExecutor::OutNode::ControlState" << endl ;
1535 return _ControlState ;
1538 SUPERV::ControlState GraphExecutor::OutNode::ControlState( const char * NodeName ) {
1539 // cdebug_in << "GraphExecutor::OutNode::ControlState " << NodeName << endl;
1540 SUPERV::ControlState aret = SUPERV::VoidState ;
1541 GraphExecutor::InNode *anInNode = (GraphExecutor::InNode *) Graph()->GetGraphNode( NodeName )->GetInNode() ;
1543 aret = anInNode->ControlState() ;
1544 // cdebug_out << "GraphExecutor::OutNode::ControlState" << endl ;
1548 void GraphExecutor::OutNode::ControlClear() {
1549 // cdebug_in << "GraphExecutor::OutNode::ControlClear" << endl;
1550 // cdebug_out << "GraphExecutor::OutNode::ControlClear" << endl ;
1551 _ControlState = SUPERV::VoidState;
1554 void GraphExecutor::OutNode::ControlClear( const char * NodeName ) {
1555 // cdebug_in << "GraphExecutor::OutNode::ControlClear " << NodeName << endl;
1556 GraphExecutor::InNode *anInNode = (GraphExecutor::InNode *) Graph()->GetGraphNode( NodeName )->GetInNode() ;
1558 anInNode->ControlClear() ;
1559 // cdebug_out << "GraphExecutor::OutNode::ControlClear" << endl ;
1562 bool GraphExecutor::OutNode::IsWaiting() {
1563 // cdebug_in << "GraphExecutor::OutNode::IsWaiting" << endl;
1564 // cdebug_out << "GraphExecutor::OutNode::IsWaiting" << endl ;
1568 bool GraphExecutor::OutNode::IsReady() {
1569 // cdebug_in << "GraphExecutor::OutNode::IsReady" << endl;
1570 // cdebug_out << "GraphExecutor::OutNode::IsReady" << endl ;
1574 bool GraphExecutor::OutNode::IsRunning() {
1575 // cdebug_in << "GraphExecutor::OutNode::IsRunning" << endl;
1576 // cdebug_out << "GraphExecutor::OutNode::IsRunning" << endl ;
1580 bool GraphExecutor::OutNode::IsDone() {
1581 // cdebug_in << "GraphExecutor::OutNode::IsDone" << endl;
1582 // cdebug_out << "GraphExecutor::OutNode::IsDone" << endl ;
1583 return ( Done() || IsKilled() || IsStopped() ) ;
1586 bool GraphExecutor::OutNode::IsSuspended() {
1587 // cdebug_in << "GraphExecutor::OutNode::IsSuspended" << endl;
1589 if ( _SuspendedThreads == _Threads ) {
1592 // cdebug_out << "GraphExecutor::OutNode::IsSuspended" << endl ;
1596 bool GraphExecutor::OutNode::IsKilled() {
1597 // cdebug_in << "GraphExecutor::OutNode::IsKilled" << endl;
1599 if ( AutomatonGraphState( _State ) == SUPERV::KillState ) {
1602 // cdebug_out << "GraphExecutor::OutNode::IsKilled" << endl ;
1606 bool GraphExecutor::OutNode::IsStopped() {
1607 // cdebug_in << "GraphExecutor::OutNode::IsStopped" << endl;
1609 if ( AutomatonGraphState( _State ) == SUPERV::StopState ) {
1612 // cdebug_out << "GraphExecutor::OutNode::IsStopped" << endl ;
1616 bool GraphExecutor::OutNode::IsWaiting( const char * NodeName ) {
1618 // cdebug_in << "GraphExecutor::OutNode::IsWaiting " << NodeName << endl;
1619 GraphExecutor::InNode *anInNode = (GraphExecutor::InNode *) Graph()->GetGraphNode( NodeName )->GetInNode() ;
1621 aret = anInNode->IsWaiting() ;
1623 // cdebug_out << "GraphExecutor::OutNode::IsWaiting" << endl ;
1627 bool GraphExecutor::OutNode::IsReady( const char * NodeName ) {
1629 // cdebug_in << "GraphExecutor::OutNode::IsReady " << NodeName << endl;
1630 GraphExecutor::InNode *anInNode = (GraphExecutor::InNode *) Graph()->GetGraphNode( NodeName )->GetInNode() ;
1632 aret = anInNode->IsReady() ;
1634 // cdebug_out << "GraphExecutor::OutNode::IsReady" << endl ;
1638 bool GraphExecutor::OutNode::IsRunning( const char * NodeName ) {
1640 // cdebug_in << "GraphExecutor::OutNode::IsRunning " << NodeName << endl;
1641 GraphExecutor::InNode *anInNode = (GraphExecutor::InNode *) Graph()->GetGraphNode( NodeName )->GetInNode() ;
1643 aret = anInNode->IsRunning() ;
1645 // cdebug_out << "GraphExecutor::OutNode::IsRunning" << endl ;
1649 bool GraphExecutor::OutNode::IsDone( const char * NodeName ) {
1651 // cdebug_in << "GraphExecutor::OutNode::IsDone " << NodeName << endl;
1652 GraphExecutor::InNode *anInNode = (GraphExecutor::InNode *) Graph()->GetGraphNode( NodeName )->GetInNode() ;
1654 aret = anInNode->IsDone() ;
1656 // cdebug_out << "GraphExecutor::OutNode::IsDone" << endl ;
1660 bool GraphExecutor::OutNode::IsSuspended( const char * NodeName ) {
1662 // cdebug_in << "GraphExecutor::OutNode::IsSuspended " << NodeName << endl;
1663 GraphExecutor::InNode *anInNode = (GraphExecutor::InNode *) Graph()->GetGraphNode( NodeName )->GetInNode() ;
1665 aret = anInNode->IsSuspended() ;
1667 // cdebug_out << "GraphExecutor::OutNode::IsSuspended" << endl ;
1671 bool GraphExecutor::OutNode::IsDone( const char * NodeName ,
1672 const char * ServiceParameterName ) {
1673 // cdebug_in << "GraphExecutor::OutNode::IsDone " << NodeName << " "
1674 // << ServiceParameterName<< endl;
1675 bool aret = Graph()->PortDone( NodeName , ServiceParameterName ) ;
1676 // cdebug_out << "GraphExecutor::OutNode::IsDone" << endl ;
1680 bool GraphExecutor::OutNode::ContainerKill() {
1681 bool RetVal = true ;
1682 cdebug_in << "GraphExecutor::OutNode::ContainerKill" << endl;
1683 _ControlState = SUPERV::ToSuspendState ;
1685 for ( i = 0 ; i < Graph()->GraphNodesSize() ; i++ ) {
1686 GraphExecutor::InNode * aNode = (GraphExecutor::InNode * ) Graph()->GraphNodes( i )->GetInNode() ;
1687 bool sts = aNode->ContainerKill() ;
1688 if ( sts && aNode->IsKilled() ) {
1689 cdebug << aNode->Name() << " killed" << endl ;
1691 else if ( aNode->IsWaiting() || aNode->IsDone() ) {
1692 cdebug << aNode->Name() << " not killed : "
1693 << theAutomaton->StateName( aNode->State() ) << endl ;
1696 cdebug << aNode->Name() << " cannot be killed : "
1697 << theAutomaton->StateName( aNode->State() ) << endl ;
1701 if ( !RetVal || Threads() != 0 ) {
1702 for ( i = 0 ; i < Graph()->GraphNodesSize() ; i++ ) {
1703 GraphExecutor::InNode * aNode = (GraphExecutor::InNode * ) Graph()->GraphNodes( i )->GetInNode() ;
1704 if ( !aNode->IsKilled() && !aNode->IsWaiting() && !aNode->IsDone() ) {
1705 aNode->KilledAction() ;
1710 State( GraphExecutor::KilledState ) ;
1711 cdebug_out << "GraphExecutor::OutNode::ContainerKill" << endl ;
1715 bool GraphExecutor::OutNode::Suspend() {
1717 cdebug_in << "GraphExecutor::OutNode::Suspend" << endl;
1718 // _ControlState = SUPERV::ToSuspendState ;
1720 for ( i = 0 ; i < Graph()->GraphNodesSize() ; i++ ) {
1721 GraphExecutor::InNode * aNode = (GraphExecutor::InNode * ) Graph()->GraphNodes( i )->GetInNode() ;
1722 bool sts = aNode->Suspend() ;
1723 if ( sts && aNode->IsSuspended() ) {
1725 cdebug << aNode->Name() << " Suspended" << endl ;
1727 else if ( aNode->IsWaiting() || aNode->IsDone() ) {
1728 cdebug << aNode->Name() << " not Suspended : "
1729 << theAutomaton->StateName( aNode->State() ) << endl ;
1733 cdebug << aNode->Name() << " cannot be Suspended : "
1734 << theAutomaton->StateName( aNode->State() ) << endl ;
1738 State( GraphExecutor::SuspendedState ) ;
1739 MESSAGE("================================================================================") ;
1740 MESSAGE( Graph()->Name() << " IS SUSPENDED" ) ;
1741 MESSAGE("================================================================================") ;
1744 MESSAGE("================================================================================") ;
1745 MESSAGE( Graph()->Name() << " IS NOT SUSPENDED" ) ;
1746 MESSAGE("================================================================================") ;
1748 cdebug_out << "GraphExecutor::OutNode::Suspend" << theAutomaton->StateName( State() ) << endl ;
1752 bool GraphExecutor::OutNode::Resume() {
1754 cdebug_in << "GraphExecutor::OutNode::Resume" << endl;
1755 if ( IsSuspended() ) {
1756 State( GraphExecutor::ExecutingState ) ;
1758 for ( i = 0 ; i < Graph()->GraphNodesSize() ; i++ ) {
1759 GraphExecutor::InNode * aNode = (GraphExecutor::InNode * ) Graph()->GraphNodes( i )->GetInNode() ;
1760 aNode->ControlState( SUPERV::VoidState ) ;
1761 if ( aNode->IsSuspended() ) {
1762 cdebug << aNode->Name() << "->Resume " << theAutomaton->StateName( aNode->State() )
1764 if ( aNode->Resume() ) {
1765 cdebug << aNode->Name() << " Resumed " << theAutomaton->StateName( aNode->State() )
1770 cdebug << aNode->Name() << " Resume failed"
1771 << theAutomaton->StateName( aNode->State() ) << endl ;
1775 cdebug << aNode->Name() << " " << theAutomaton->StateName( aNode->State() )
1781 cdebug << Graph()->Name() << " not suspended " << theAutomaton->StateName( State() ) << endl ;
1784 MESSAGE("================================================================================") ;
1785 MESSAGE( Graph()->Name() << " IS RESUMED" ) ;
1786 MESSAGE("================================================================================") ;
1789 MESSAGE("================================================================================") ;
1790 MESSAGE( Graph()->Name() << " IS NOT RESUMED" ) ;
1791 MESSAGE("================================================================================") ;
1793 cdebug_out << "GraphExecutor::OutNode::Resume" << theAutomaton->StateName( State() ) << " " << RetVal << endl ;
1797 bool GraphExecutor::OutNode::Kill() {
1798 bool RetVal = true ;
1799 cdebug_in << "GraphExecutor::OutNode::Kill" << endl;
1800 _ControlState = SUPERV::ToSuspendState ;
1802 for ( i = 0 ; i < Graph()->GraphNodesSize() ; i++ ) {
1803 GraphExecutor::InNode * aNode = (GraphExecutor::InNode * ) Graph()->GraphNodes( i )->GetInNode() ;
1804 bool sts = aNode->Kill() ;
1805 if ( sts && aNode->IsKilled() ) {
1806 cdebug << aNode->Name() << " killed" << endl ;
1808 else if ( aNode->IsWaiting() || aNode->IsDone() ) {
1809 cdebug << aNode->Name() << " not killed : "
1810 << theAutomaton->StateName( aNode->State() ) << endl ;
1813 cdebug << aNode->Name() << " cannot be killed : "
1814 << theAutomaton->StateName( aNode->State() ) << endl ;
1818 if ( !RetVal || Threads() != 0 ) {
1819 for ( i = 0 ; i < Graph()->GraphNodesSize() ; i++ ) {
1820 GraphExecutor::InNode * aNode = (GraphExecutor::InNode * ) Graph()->GraphNodes( i )->GetInNode() ;
1821 if ( !aNode->IsKilled() && !aNode->IsWaiting() && !aNode->IsDone() ) {
1822 cdebug << aNode->Name() << " not killed : "
1823 << theAutomaton->StateName( aNode->State() ) << " " << aNode->Name() << "->"
1824 << "KilledAction()" << endl ;
1825 aNode->KilledAction() ;
1830 State( GraphExecutor::KilledState ) ;
1832 MESSAGE("================================================================================") ;
1833 MESSAGE( Graph()->Name() << " IS KILLED" << theAutomaton->StateName( AutomatonState() ) << " EventQSize "
1835 MESSAGE("================================================================================") ;
1838 MESSAGE("================================================================================") ;
1839 MESSAGE( Graph()->Name() << " IS NOT KILLED" ) ;
1840 MESSAGE("================================================================================") ;
1842 cdebug_out << "GraphExecutor::OutNode::Kill " << RetVal << endl ;
1846 bool GraphExecutor::OutNode::Stop() {
1847 bool RetVal = false ;
1848 cdebug_in << "GraphExecutor::OutNode::Stop" << endl;
1850 cdebug_out << "GraphExecutor::OutNode::Stop" << endl ;
1852 MESSAGE("================================================================================") ;
1853 MESSAGE( Graph()->Name() << " IS STOPPED" ) ;
1854 MESSAGE("================================================================================") ;
1858 bool GraphExecutor::OutNode::ReRun() {
1859 bool RetVal = false ;
1860 cdebug_in << "GraphExecutor::OutNode::ReRun" << endl;
1861 if ( IsSuspended() ) {
1863 cdebug_out << "GraphExecutor::OutNode::ReRun" << endl ;
1866 bool GraphExecutor::OutNode::ReStart() {
1867 bool RetVal = false ;
1868 cdebug_in << "GraphExecutor::OutNode::ReStart" << endl;
1869 if ( IsSuspended() ) {
1871 cdebug_out << "GraphExecutor::OutNode::ReStart" << endl ;
1875 bool GraphExecutor::OutNode::ReadyWait() {
1876 cdebug_in << "GraphExecutor::OutNode::ReadyWait" << endl;
1878 if ( pthread_mutex_lock( &_MutexWait ) ) {
1879 perror("pthread_mutex_lock _ReadyWait") ;
1885 pthread_cond_wait( &_EventWait , &_MutexWait );
1888 if ( pthread_mutex_unlock( &_MutexWait ) ) {
1889 perror("pthread_mutex_lock _ReadyWait") ;
1892 cdebug_out << "GraphExecutor::OutNode::ReadyWait" << endl ;
1896 bool GraphExecutor::OutNode::RunningWait() {
1897 cdebug_in << "GraphExecutor::OutNode::RunningWait" << endl;
1899 if ( pthread_mutex_lock( &_MutexWait ) ) {
1900 perror("pthread_mutex_lock _RunningWait") ;
1903 aret = IsRunning() ;
1905 cdebug << "RunningWait pthread_cond_wait _EventWait" << endl;
1906 pthread_cond_wait( &_EventWait , &_MutexWait );
1907 aret = IsRunning() ;
1908 cdebug << "RunningWait pthread_cond_waited _EventWait " << aret << endl;
1910 if ( pthread_mutex_unlock( &_MutexWait ) ) {
1911 perror("pthread_mutex_lock _RunningWait") ;
1914 cdebug_out << "GraphExecutor::OutNode::RunningWait " << aret << endl ;
1918 bool GraphExecutor::OutNode::DoneWait() {
1919 cdebug_in << "GraphExecutor::OutNode::DoneWait" << endl;
1921 if ( pthread_mutex_lock( &_MutexWait ) ) {
1922 perror("pthread_mutex_lock _DoneWait") ;
1926 while ( !aret && !IsSuspended() && IsRunning() ) {
1927 cdebug << "DoneWait pthread_cond_wait _EventWait" << endl;
1928 pthread_cond_wait( &_EventWait , &_MutexWait );
1930 cdebug << "DoneWait pthread_cond_waited _EventWait " << aret << endl;
1932 if ( pthread_mutex_unlock( &_MutexWait ) ) {
1933 perror("pthread_mutex_lock _DoneWait") ;
1936 cdebug_out << "GraphExecutor::OutNode::DoneWait " << aret << endl ;
1940 bool GraphExecutor::OutNode::SuspendedWait() {
1941 cdebug_in << "GraphExecutor::OutNode::SuspendedWait" << endl;
1943 if ( pthread_mutex_lock( &_MutexWait ) ) {
1944 perror("pthread_mutex_lock _SuspendedWait") ;
1947 aret = IsSuspended() ;
1948 while ( !aret && !IsDone() ) {
1949 pthread_cond_wait( &_EventWait , &_MutexWait );
1950 aret = IsSuspended() ;
1952 if ( pthread_mutex_unlock( &_MutexWait ) ) {
1953 perror("pthread_mutex_lock _SuspendedWait") ;
1956 cdebug_out << "GraphExecutor::OutNode::SuspendedWait" << endl ;
1960 bool GraphExecutor::OutNode::ReadyWait( const char * NodeName ) {
1962 cdebug_in << "GraphExecutor::OutNode::ReadyWait " << NodeName << endl;
1963 GraphExecutor::InNode *anInNode = (GraphExecutor::InNode *) Graph()->GetGraphNode( NodeName )->GetInNode() ;
1965 aret = anInNode->ReadyWait() ;
1967 cdebug_out << "GraphExecutor::OutNode::ReadyWait" << endl ;
1971 bool GraphExecutor::OutNode::RunningWait( const char * NodeName ) {
1973 cdebug_in << "GraphExecutor::OutNode::RunningWait " << NodeName << endl;
1974 GraphExecutor::InNode *anInNode = (GraphExecutor::InNode *) Graph()->GetGraphNode( NodeName )->GetInNode() ;
1976 aret = anInNode->RunningWait() ;
1978 cdebug_out << "GraphExecutor::OutNode::RunningWait" << endl ;
1982 bool GraphExecutor::OutNode::DoneWait( const char * NodeName ) {
1984 cdebug_in << "GraphExecutor::OutNode::DoneWait " << NodeName << endl;
1985 GraphExecutor::InNode *anInNode = (GraphExecutor::InNode *) Graph()->GetGraphNode( NodeName )->GetInNode() ;
1987 aret = anInNode->DoneWait() ;
1989 cdebug_out << "GraphExecutor::OutNode::DoneWait" << endl ;
1993 bool GraphExecutor::OutNode::SuspendedWait( const char * NodeName ) {
1995 cdebug_in << "GraphExecutor::OutNode::SuspendedWait " << NodeName << endl;
1996 GraphExecutor::InNode *anInNode = (GraphExecutor::InNode *) Graph()->GetGraphNode( NodeName )->GetInNode() ;
1998 aret = anInNode->SuspendedWait() ;
2000 cdebug_out << "GraphExecutor::OutNode::SuspendedWait" << endl ;
2004 long GraphExecutor::OutNode::LastLevelDone() {
2007 for ( i = 0 ; i <= Graph()->LevelMax() ; i++ ) {
2008 for ( j = 0 ; j <= Graph()->NodesNumber( i ) ; j++ ) {
2009 GraphBase::ComputingNode * aNode = Graph()->SortedNodes( i , j ) ;
2010 if ( !IsDone( aNode->Name() ) ) {
2014 if ( j != Graph()->NodesNumber( i ) + 1 )
2022 const CORBA::Any *GraphExecutor::OutNode::GetInData( const char * NodeName ,
2023 const char * ServiceParameterName ) {
2024 // cdebug_in << "GraphExecutor::OutNode::GetInData " << NodeName << " "
2025 // << ServiceParameterName << endl ;
2026 const CORBA::Any * retdata = Graph()->PortInData( NodeName , ServiceParameterName ) ;
2027 // cdebug_out << "GraphExecutor::OutNode::GetInData" << endl ;
2031 const CORBA::Any *GraphExecutor::OutNode::GetOutData( const char * NodeName ,
2032 const char * ServiceParameterName ) {
2033 // cdebug_in << "GraphExecutor::OutNode::GetOutData " << NodeName << " "
2034 // << ServiceParameterName << endl ;
2035 const CORBA::Any * retdata = Graph()->PortOutData( NodeName , ServiceParameterName ) ;
2036 // cdebug_out << "GraphExecutor::OutNode::GetOutData" << endl ;
2040 const long GraphExecutor::OutNode::CpuUsed() {
2041 return Graph()->CpuUsed() ;
2044 const long GraphExecutor::OutNode::CpuUsed( const char * aNodeName ) {
2045 GraphBase::ComputingNode * aNode = Graph()->GetChangeGraphNode( aNodeName ) ;
2047 GraphExecutor::InNode * anInNode = (GraphExecutor::InNode * ) aNode->GetInNode() ;
2049 return anInNode->CpuUsed() ;