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 #include "DataFlowEditor_DataFlow.hxx"
35 extern Engines_Container_i * _TheContainer ;
37 extern GraphExecutor::FiniteStateMachine * theAutomaton ;
39 // static const char *ComponentName = "SalomeSuperVisionComponent" ;
42 extern char ** _ArgV ;
44 GraphExecutor::OutNode::OutNode() {
46 _SuperVisionContainer = _TheContainer ;
47 _MainThreadId = SuperVisionContainer()->MainThreadId() ;
52 _ControlState = SUPERV::VoidState ;
53 _State = GraphExecutor::UnKnownState ;
54 _PyInitialized = false ;
55 pthread_mutex_init( &_MutexWait , NULL ) ;
56 pthread_mutex_init( &_PyMutexWait , NULL ) ;
57 if ( pthread_cond_init( &_EventWait , NULL ) ) {
58 perror("pthread_cond_init( &_EventWait , NULL )") ;
61 if ( pthread_cond_init( &_JoinWait , NULL ) ) {
62 perror("pthread_cond_init( &_JoinWait , NULL )") ;
67 GraphExecutor::OutNode::OutNode( CORBA::ORB_ptr ORB,
68 SALOME_NamingService* ptrNamingService ,
69 const char *DataFlowName ,
70 const char * DebugFileName ,
71 const SUPERV::KindOfNode aKindOfNode ) {
72 // Graph( ORB , ptrNamingService , DataFlowName , DebugFileName ) {
73 Set_prof_debug( ORB , DebugFileName ) ;
74 cdebug_in << "GraphExecutor::OutNode::OutNode(" << DataFlowName << " , " << aKindOfNode << ")" << endl;
75 if ( aKindOfNode == SUPERV::DataFlowGraph ) {
77 // _Graph = new GraphBase::Graph( ORB , ptrNamingService , DataFlowName , DebugFileName ) ;
78 _Graph = new GraphBase::Graph( ORB , ptrNamingService , DataFlowName , aKindOfNode ,
79 _prof_debug , _fdebug ) ;
81 else if ( aKindOfNode == SUPERV::DataStreamGraph ) {
82 // _StreamGraph = new GraphBase::StreamGraph( ORB , ptrNamingService , DataFlowName , DebugFileName ) ;;
83 _StreamGraph = new GraphBase::StreamGraph( ORB , ptrNamingService , DataFlowName , aKindOfNode ,
84 _prof_debug , _fdebug ) ;
85 _Graph = _StreamGraph ;
87 _SuperVisionContainer = _TheContainer ;
88 _MainThreadId = SuperVisionContainer()->MainThreadId() ;
93 _ControlState = SUPERV::VoidState ;
94 _State = GraphExecutor::UnKnownState ;
95 _PyInitialized = false ;
96 _Orb = CORBA::ORB::_duplicate( ORB ) ;
97 pthread_mutex_init( &_MutexWait , NULL ) ;
98 pthread_mutex_init( &_PyMutexWait , NULL ) ;
99 if ( pthread_cond_init( &_EventWait , NULL ) ) {
100 perror("pthread_cond_init( &_EventWait , NULL )") ;
103 if ( pthread_cond_init( &_JoinWait , NULL ) ) {
104 perror("pthread_cond_init( &_JoinWait , NULL )") ;
107 cdebug_out << "GraphExecutor::OutNode::OutNode" << endl;
110 GraphExecutor::OutNode::OutNode( CORBA::ORB_ptr ORB,
111 SALOME_NamingService* ptrNamingService ,
112 const SALOME_ModuleCatalog::Service& DataFlowService ,
113 const char *DataFlowComponentName ,
114 const char *DataFlowInterfaceName ,
115 const char *DataFlowName ,
116 const SUPERV::KindOfNode DataFlowkind ,
117 const SUPERV::SDate DataFlowFirstCreation ,
118 const SUPERV::SDate DataFlowLastModification ,
119 const char * DataFlowEditorRelease ,
120 const char * DataFlowAuthor ,
121 const char * DataFlowComputer ,
122 const char * DataFlowComment ,
123 const char * DebugFileName ) {
124 // Graph( ORB , ptrNamingService , DataFlowService , DataFlowComponentName ,
125 // DataFlowInterfaceName , DataFlowName , DataFlowkind ,
126 // DataFlowFirstCreation , DataFlowLastModification ,
127 // DataFlowEditorRelease , DataFlowAuthor ,
128 // DataFlowComputer , DataFlowComment , DebugFileName ) {
129 Set_prof_debug( ORB , DebugFileName ) ;
131 cdebug_in << "GraphExecutor::OutNode::OutNode(" << DataFlowName << " , " << DataFlowkind << ")" << endl;
132 if ( DataFlowkind == SUPERV::DataFlowGraph ) {
133 _StreamGraph = NULL ;
134 _Graph = new GraphBase::Graph( ORB , ptrNamingService , DataFlowService , DataFlowComponentName ,
135 DataFlowInterfaceName , DataFlowName , DataFlowkind ,
136 DataFlowFirstCreation , DataFlowLastModification ,
137 DataFlowEditorRelease , DataFlowAuthor ,
138 DataFlowComputer , DataFlowComment ,
139 _prof_debug , _fdebug ) ;
140 // DataFlowComputer , DataFlowComment , DebugFileName ) ;
142 else if ( DataFlowkind == SUPERV::DataStreamGraph ) {
143 _StreamGraph = new GraphBase::StreamGraph( ORB , ptrNamingService , DataFlowService , DataFlowComponentName ,
144 DataFlowInterfaceName , DataFlowName , DataFlowkind ,
145 DataFlowFirstCreation , DataFlowLastModification ,
146 DataFlowEditorRelease , DataFlowAuthor ,
147 DataFlowComputer , DataFlowComment ,
148 _prof_debug , _fdebug ) ;
149 _Graph = _StreamGraph ;
151 _SuperVisionContainer = _TheContainer ;
152 _MainThreadId = SuperVisionContainer()->MainThreadId() ;
154 _Executable = false ;
157 _ControlState = SUPERV::VoidState ;
158 _State = GraphExecutor::UnKnownState ;
159 _PyInitialized = false ;
160 _Orb = CORBA::ORB::_duplicate( ORB ) ;
161 pthread_mutex_init( &_MutexWait , NULL ) ;
162 pthread_mutex_init( &_PyMutexWait , NULL ) ;
163 if ( pthread_cond_init( &_EventWait , NULL ) ) {
164 perror("pthread_cond_init( &_EventWait , NULL )") ;
167 if ( pthread_cond_init( &_JoinWait , NULL ) ) {
168 perror("pthread_cond_init( &_JoinWait , NULL )") ;
173 GraphExecutor::OutNode::~OutNode() {
176 void GraphExecutor::OutNode::Set_prof_debug( CORBA::ORB_ptr ORB ,
177 const char * DebugFileName ) {
178 _Graph_prof_debug = 0 ;
179 if ( DebugFileName ) {
180 _fdebug = new ofstream( DebugFileName );
181 SetDebug( ORB , &_Graph_prof_debug , _fdebug ) ;
182 MESSAGE( endl << "Trace redirected to file " << DebugFileName << endl)
186 bool GraphExecutor::OutNode::LoadDataFlow(const GraphBase::SGraph * aDataFlow ) {
187 bool RetVal = false ;
188 cdebug_in << "GraphExecutor::OutNode::LoadDataFlow " << (*aDataFlow).Info.theName << endl ;
189 RetVal = LoadInfo( (*aDataFlow).Info ) ;
190 if ( Graph()->ServiceName() != NULL ) {
191 // MESSAGE( "GraphExecutor::OutNode::LoadDataFlow" );
193 RetVal = LoadNodes( (*aDataFlow).Nodes ) ;
195 RetVal = LoadLinks( (*aDataFlow).Links ) ;
198 RetVal = LoadDatas( (*aDataFlow).Datas ) ;
201 cdebug << "GraphExecutor::OutNode::LoadDataFlow LoadDatas Error."
206 cdebug << "GraphExecutor::OutNode::LoadDataFlow LoadLinks Error."
211 cdebug << "GraphExecutor::OutNode::LoadDataFlow LoadNodes Error."
216 cdebug << "GraphExecutor::OutNode::LoadDataFlow LoadInfo Error."
221 cdebug << "GraphExecutor::OutNode::LoadDataFlow ServiceName Error." << endl ;
223 cdebug_out << "GraphExecutor::OutNode::LoadDataFlow " << Graph()->Name() << " RetVal "
229 bool GraphExecutor::OutNode::LoadXml( const char* myFileName ) {
230 bool RetVal = false ;
231 GraphBase::ListOfSGraphs aListOfDataFlows ;
232 if ( Graph()->LoadXml( _Orb , myFileName , aListOfDataFlows ) ) {
233 RetVal = LoadDataFlow( aListOfDataFlows ) ;
234 // if ( aConstructor && RetVal )
235 // RetVal = Name( aDataFlow.Info.theName.c_str() ) ;
241 bool GraphExecutor::OutNode::LoadInfo(const GraphBase::SNode &aDataFlowInfo ) {
242 cdebug << "GraphExecutor::OutNode::LoadInfo _StreamGraph " << _StreamGraph << endl ;
243 // ComponentName( aDataFlowInfo.theComponentName.c_str() ) ;
244 Graph()->Name( aDataFlowInfo.theName.c_str() ) ;
245 Graph()->Kind( aDataFlowInfo.theKind ) ;
246 if ( Graph()->IsDataStreamNode() && aDataFlowInfo.theKind == SUPERV::DataStreamGraph ) {
247 StreamGraph()->SetStreamParams( aDataFlowInfo.theTimeout , aDataFlowInfo.theDataStreamTrace , aDataFlowInfo.theDeltaTime ) ;
249 Graph()->DataService( _Orb , aDataFlowInfo.theService , _prof_debug , _fdebug ) ;
250 Graph()->FirstCreation( aDataFlowInfo.theFirstCreation ) ;
251 Graph()->LastModification( aDataFlowInfo.theLastModification ) ;
252 Graph()->EditorRelease( aDataFlowInfo.theEditorRelease.c_str() ) ;
253 Graph()->Author( aDataFlowInfo.theAuthor.c_str() ) ;
254 // Graph()->Computer( aDataFlowInfo.theContainer.c_str() ) ;
255 Graph()->Comment( aDataFlowInfo.theComment.c_str() ) ;
256 // Not in OutNode/DataFlow but in InNode/DataFlow_in_an_other_DataFlow
257 // Graph()->Coordinates( aDataFlowInfo.theX , aDataFlowInfo.theY ) ;
261 bool GraphExecutor::OutNode::LoadNodes(const GraphBase::ListOfSNodes &aListOfNodes ) {
263 GraphExecutor::InNode * anInNode ;
264 cdebug << "GraphExecutor::OutNode::LoadNodes" << endl ;
266 for ( i = 0 ; i < (int ) aListOfNodes.size() ; i++ ) {
267 GraphBase::SNode aNode = aListOfNodes[ i ] ;
268 anInNode = AddNode( aNode.theService ,
269 aNode.theListOfFuncName ,
270 aNode.theListOfPythonFunctions ,
271 aNode.theComponentName.c_str() ,
272 aNode.theInterfaceName.c_str() , aNode.theName.c_str() ,
274 aNode.theFirstCreation , aNode.theLastModification ,
275 aNode.theEditorRelease.c_str() ,
276 aNode.theAuthor.c_str() , aNode.theContainer.c_str() ,
277 aNode.theComment.c_str() ,
278 aNode.theCoords.theX , aNode.theCoords.theY ) ;
283 if ( anInNode->IsOneOfInLineNodes() || anInNode->IsMacroNode() ) {
284 anInNode->GraphExecutor::InNode::InLineNode()->DefPortsOfNode(
285 _Orb , aNode.theService , anInNode->NamePtr() ,
287 _prof_debug , _fdebug ) ;
289 // GraphBase::ComputingNode * theNode = Graph()->GetChangeGraphNode( aNode.theName.c_str() ) ;
292 for ( j = 0 ; j < aNode.theListOfInDataStreams.size() ; j++ ) {
293 GraphBase::InPort * anInPort ;
294 anInPort = anInNode->ComputingNode()->AddInDataStreamPort( aNode.theListOfInDataStreams[ j ].theDataStreamParameter.Parametername ,
295 aNode.theListOfInDataStreams[ j ].theDataStreamParameter.Parametertype ,
296 aNode.theListOfInDataStreams[ j ].theDataStreamParameter.Parameterdependency ,
297 SUPERV::DataStreamParameter ) ;
298 ((GraphBase::InDataStreamPort * ) anInPort)->SetParams( aNode.theListOfInDataStreams[ j ].theKindOfSchema ,
299 aNode.theListOfInDataStreams[ j ].theKindOfInterpolation ,
300 aNode.theListOfInDataStreams[ j ].theKindOfExtrapolation ) ;
302 for ( j = 0 ; j < aNode.theListOfOutDataStreams.size() ; j++ ) {
303 GraphBase::OutPort * anOutPort ;
304 anOutPort = anInNode->ComputingNode()->AddOutDataStreamPort( aNode.theListOfOutDataStreams[ j ].theDataStreamParameter.Parametername ,
305 aNode.theListOfOutDataStreams[ j ].theDataStreamParameter.Parametertype ,
306 aNode.theListOfOutDataStreams[ j ].theDataStreamParameter.Parameterdependency ,
307 SUPERV::DataStreamParameter ) ;
308 ((GraphBase::OutDataStreamPort * ) anOutPort)->NumberOfValues( aNode.theListOfOutDataStreams[ j ].theNumberOfValues ) ;
312 // theNode->DataStreamInPortsNumber( aNode.theDataStreamInArgsNumber ) ;
313 // theNode->DataStreamOutPortsNumber( aNode.theDataStreamOutArgsNumber ) ;
314 // cdebug << "GraphExecutor::OutNode::LoadNodes " << anInNode->Name()
315 // << " InPortsSize " << theNode->GetNodeInPortsSize()
316 // << " OutPortsSize " << theNode->GetNodeOutPortsSize()
317 // << " DataStreamInPortsNumber " << aNode.theDataStreamInArgsNumber
318 // << " DataStreamOutPortsNumber " << aNode.theDataStreamOutArgsNumber
321 // if ( aNode.theDataStreamInArgsNumber ) { // -1 because of Gates
322 // for ( j = theNode->GetNodeInPortsSize() - aNode.theDataStreamInArgsNumber - 1 ; j < theNode->GetNodeInPortsSize() - 1 ; j++ ) {
323 // cdebug << "GraphExecutor::OutNode::LoadNodes " << anInNode->Name()
324 // << " InPort " << theNode->GetChangeNodeInPort( j )->PortName()
325 // << " Kind( DataStreamParameter)" << endl ;
326 // theNode->GetChangeNodeInPort( j )->Kind( SUPERV::DataStreamParameter ) ;
329 // if ( aNode.theDataStreamOutArgsNumber ) {
330 // int withgate = 1 ;
331 // if ( theNode->IsLoopNode() || theNode->IsEndLoopNode() ) {
334 // for ( j = theNode->GetNodeOutPortsSize() - aNode.theDataStreamOutArgsNumber - withgate ; j < theNode->GetNodeOutPortsSize() - withgate ; j++ ) {
335 // cdebug << "GraphExecutor::OutNode::LoadNodes " << anInNode->Name()
336 // << " OutPort " << theNode->GetChangeNodeOutPort( j )->PortName()
337 // << " Kind( DataStreamParameter)" << endl ;
338 // theNode->GetChangeNodeOutPort( j )->Kind( SUPERV::DataStreamParameter ) ;
342 for ( i = 0 ; i < (int ) aListOfNodes.size() ; i++ ) {
343 GraphBase::SNode aNode = aListOfNodes[ i ] ;
344 anInNode = (GraphExecutor::InNode * ) Graph()->GetChangeGraphNode( aNode.theName.c_str() )->GetInNode() ;
345 cdebug << "GraphExecutor::OutNode::LoadNodes " << anInNode->Name() << " IsOneOfGOTONodes "
346 << anInNode->IsOneOfGOTONodes() << " " << aNode.theCoupledNode.c_str() << endl ;
347 if ( anInNode->IsOneOfGOTONodes() && strlen( aNode.theCoupledNode.c_str() ) ) {
348 GraphBase::GOTONode * aCoupledNode ;
349 aCoupledNode = (GraphBase::GOTONode * ) Graph()->GetGraphNode( aNode.theName.c_str() ) ;
350 GraphBase::GOTONode * aCoupledCoupledNode ;
351 aCoupledCoupledNode = (GraphBase::GOTONode * ) Graph()->GetChangeGraphNode( aNode.theCoupledNode.c_str() ) ;
352 if ( aCoupledCoupledNode != NULL ) {
353 aCoupledNode->CoupledNode( aCoupledCoupledNode ) ;
356 aCoupledNode->CoupledNodeName( aNode.theCoupledNode.c_str() ) ;
363 bool GraphExecutor::OutNode::LoadLinks(const GraphBase::ListOfSLinks &aListOfLinks ) {
365 cdebug << "GraphExecutor::OutNode::LoadLinks " << aListOfLinks.size()
368 for ( i = 0 ; i < (int ) aListOfLinks.size() ; i++ ) {
369 GraphBase::SLink aLink = aListOfLinks[ i ] ;
370 RetVal = Graph()->AddLink( aLink.FromNodeName.c_str() ,
371 aLink.FromServiceParameterName.c_str() ,
372 aLink.ToNodeName.c_str() ,
373 aLink.ToServiceParameterName.c_str() ) ;
374 // , aLink.aLinkValue ) ;
381 bool GraphExecutor::OutNode::LoadDatas(const GraphBase::ListOfSLinks &aListOfDatas ) {
383 cdebug << "GraphExecutor::OutNode::LoadDatas " << aListOfDatas.size()
386 for ( i = 0 ; i < (int ) aListOfDatas.size() ; i++ ) {
387 GraphBase::SLink aLink = aListOfDatas[ i ] ;
388 if ( !strcmp( aLink.FromNodeName.c_str() , Graph()->Name() ) )
389 RetVal = Graph()->AddInputData( aLink.ToNodeName.c_str() ,
390 aLink.ToServiceParameterName.c_str() ,
392 // else if ( !strcmp( aLink.ToNodeName.c_str() , Graph()->Name() ) ) {
393 // RetVal = Graph()->AddOutputData( aLink.FromNodeName.c_str() ,
394 // aLink.FromServiceParameterName.c_str() ) ;
395 // Graph()->AddLink( aLink.FromNodeName.c_str() , (GraphBase::ComputingNode *) this ) ;
398 cdebug << "GraphExecutor::OutNode::LoadDatas Error " << aLink.FromNodeName
399 << " and " << aLink.ToNodeName << " differents from " << Graph()->Name()
409 GraphExecutor::InNode *GraphExecutor::OutNode::AddNode(
410 const SALOME_ModuleCatalog::Service& NodeService ,
411 GraphBase::ListOfFuncName aFuncName ,
412 GraphBase::ListOfPythonFunctions aPythonFunction ,
413 const char * NodeComponentName ,
414 const char * NodeInterfaceName ,
415 const char * NodeName ,
416 const SUPERV::KindOfNode NodeKindOfNode ,
417 const SUPERV::SDate NodeFirstCreation ,
418 const SUPERV::SDate NodeLastModification ,
419 const char * NodeEditorRelease ,
420 const char * NodeAuthor ,
421 const char * NodeComputer ,
422 const char * NodeComment ,
425 cdebug_in << "GraphExecutor::OutNode::AddNode(" << NodeComponentName << " , "
426 << NodeName << ")" << endl;
427 GraphExecutor::InNode *Nd = NULL ;
428 Nd = new GraphExecutor::InNode( _Orb, Graph()->NamingService() , NodeService ,
429 NodeComponentName , NodeInterfaceName ,
430 NodeName , NodeKindOfNode ,
431 aFuncName , aPythonFunction ,
432 NodeFirstCreation , NodeLastModification ,
433 NodeEditorRelease , NodeAuthor ,
434 NodeComputer , NodeComment , false , NodeX , NodeY ,
435 _prof_debug , _fdebug ) ;
436 Graph()->AddNode( Nd->ComputingNode() ) ;
437 cdebug_out << "GraphExecutor::OutNode::AddNode" << endl;
442 bool GraphExecutor::OutNode::Valid() {
443 cdebug_in << "GraphExecutor::OutNode::Valid" << endl;
448 _Executable = false ;
450 if ( !Graph()->CreateService() ) {
451 cdebug_out << "This DataFlow has invalid type(s)." << endl ;
454 int SubStreamGraphsNumber = 0 ;
455 if ( !Graph()->Sort( SubStreamGraphsNumber ) ) {
456 cdebug_out << "This DataFlow is not valid." << endl ;
459 if ( Graph()->IsDataStreamNode() ) {
460 StreamGraph()->SubStreamGraphsNumber( SubStreamGraphsNumber ) ;
462 if ( !Graph()->ValidLoops() ) {
463 cdebug_out << "This DataFlow have not valid Loops." << endl ;
469 Graph()->InLineServices() ;
471 Graph()->ComputingNodes() ;
475 cdebug_out << "GraphExecutor::OutNode::Valid" << endl;
480 bool GraphExecutor::OutNode::Executable() {
482 cdebug_in << "GraphExecutor::OutNode::Executable" << endl;
486 if ( Graph()->DataServerNodes() )
489 cdebug << "This DataFlow is not executable." << endl ;
490 _Executable = false ;
493 cdebug_out << "GraphExecutor::OutNode::Executable " << _Executable << endl;
497 bool GraphExecutor::OutNode::Run( const bool AndSuspend ) {
498 bool RetVal = false ;
499 cdebug_in << pthread_self() << "GraphExecutor::OutNode::Run( AndSuspend " << AndSuspend << " )"
502 if ( Executable() ) {
503 _ControlState = SUPERV::VoidState ;
504 _SuspendedThreads = 0 ;
505 Graph()->ThreadNo( pthread_self() ) ;
507 _JustStarted = true ;
510 for ( i = 0 ; i < Graph()->GraphNodesSize() ; i++ ) {
511 GraphExecutor::InNode * anInNode = (GraphExecutor::InNode *) Graph()->GraphNodes( i )->GetInNode() ;
512 anInNode->OutNode( this ) ;
513 // Initialize in python interpretor the python functions
514 if ( !PyInitialized() && anInNode->IsOneOfInLineNodes() ) {
515 if ( !Py_IsInitialized() ) {
516 // PyEval_InitThreads() ;
518 // PySys_SetArgv( _ArgC , _ArgV ) ;
520 anInNode->InitPython() ;
521 PyInitialized( true ) ;
523 anInNode->InitialState() ;
524 if ( anInNode->IsOneOfInLineNodes() ) {
525 anInNode->InitPythonFunctions( false ) ;
528 // One more time because inline nodes may share one definition of the same function
529 for ( i = 0 ; i < Graph()->GraphNodesSize() ; i++ ) {
530 GraphExecutor::InNode * anInNode = (GraphExecutor::InNode *) Graph()->GraphNodes( i )->GetInNode() ;
531 if ( anInNode->IsOneOfInLineNodes() ) {
532 if ( !anInNode->InitPythonFunctions( true ) ) {
533 anInNode->State( GraphExecutor::ErroredState ) ;
534 State( GraphExecutor::ErroredState ) ;
535 cdebug_out << "GraphExecutor::OutNode::Run InitPythonFunctions ERROR "
536 << anInNode->Name() << endl ;
541 /* asv : 29.09.04 : commented out because it does not do anything useful
542 for ( i = 0 ; i < Graph()->GraphNodesSize() ; i++ ) {
543 GraphExecutor::InNode * anInNode = (GraphExecutor::InNode *) Graph()->GraphNodes( i )->GetInNode() ;
544 if ( RetVal && anInNode->IsMacroNode() ) {
545 GraphBase::Graph * aMacroGraph = anInNode->GraphMacroNode() ;
546 cdebug << "GraphExecutor::OutNode::Run " << anInNode << " MacroNode " << aMacroGraph
547 << aMacroGraph->Name() << endl ;
548 SUPERV::Graph_var iobject = anInNode->GraphMacroNode()->MacroObject() ;
549 if ( CORBA::is_nil( iobject ) ) {
550 cdebug << "GraphExecutor::OutNode::Run MacroObject() is a nil object. Error" << endl ;
554 cdebug << "GraphExecutor::OutNode::Run MacroObject() is NOT a nil object." << endl ;
559 if ( Graph()->GraphMacroLevel() != 0 ) {
560 cdebug << "GraphExecutor::OutNode::Run Execution starting GraphExecutor::Action_DataOk_RunService Node "
561 << Graph()->Name() << " GraphMacroLevel " << Graph()->GraphMacroLevel() << endl ;
562 PushEvent( NULL , GraphExecutor::NoDataReadyEvent ,
563 GraphExecutor::DataUndefState ) ;
566 cdebug << "Execution starting GraphExecutor::Action_DataOk_RunService Node "
567 << Graph()->Name() << " GraphMacroLevel " << Graph()->GraphMacroLevel() << endl ;
568 PushEvent( NULL , GraphExecutor::ReadyEvent ,
569 GraphExecutor::DataReadyState ) ;
570 State( GraphExecutor::DataReadyState ) ;
572 cdebug << pthread_self() << " GraphExecutor::OutNode::Run Start of the " << Graph()->HeadNodesSize()
573 << " HeadNodes" << endl ;
574 for ( i = 0 ; i < Graph()->HeadNodesSize() ; i++ ) {
575 GraphExecutor::InNode * anInNode = (GraphExecutor::InNode *) Graph()->HeadNodes( i )->GetInNode() ;
576 cdebug << pthread_self() << "GraphExecutor::OutNode::Run Start of HeadNode " << i << " "
577 << anInNode->Name() << endl ;
578 if ( anInNode->State() != GraphExecutor::DataReadyState ) {
579 cdebug << "GraphExecutor::OutNode::Run inconsistency State of Node "
580 << anInNode->Name() << " : " << anInNode->State() << endl ;
581 cdebug_out << "GraphExecutor::OutNode::Run State ERROR" << endl ;
584 // PushEvent( anInNode , GraphExecutor::ReadyEvent ,
585 // GraphExecutor::DataReadyState ) ;
586 // We say that we have to create a thread for that HeadNode 'anInNode'
587 anInNode->CreateNewThread( true ) ;
588 anInNode->DataFromNode( Graph()->Name() ) ;
589 // AndSuspend == true <==> Start()
591 anInNode->State( GraphExecutor::DataWaitingState ) ;
592 anInNode->ControlState( SUPERV::ToSuspendStartState ) ;
593 // We send SomeDataReadyEvent
594 // It is a HeadNode ==> AllDataReadyEvent ==> InNode::executeAction() ==> pthread_create
595 if ( !anInNode->SendEvent( GraphExecutor::SomeDataReadyEvent ) ) {
596 cdebug << "InNode::SendEvent( SomeDataReadyEvent ) ERROR Node "
597 << anInNode->Name() << endl ;
598 cdebug_out << "GraphExecutor::OutNode::Run SendEvent ERROR" << endl ;
601 // ==> We wait for SuspendedState
602 anInNode->SuspendedWait() ;
604 // AndSuspend == false <==> Run()
605 else if ( anInNode->IsMacroNode() ) {
606 if ( !anInNode->SendEvent( GraphExecutor::SomeDataReadyEvent ) ) {
607 cdebug << "InNode::SendEvent( SomeDataReadyEvent ) ERROR Node "
608 << anInNode->Name() << endl ;
609 cdebug_out << "GraphExecutor::OutNode::Run SendEvent ERROR" << endl ;
612 cdebug << pthread_self() << " GraphExecutor::OutNode::Run " << anInNode->Name() << "->RunningWait"
614 // ==> We wait for RunningState
615 anInNode->RunningWait() ;
616 cdebug << pthread_self() << " GraphExecutor::OutNode::Run " << anInNode->Name() << "->RunningWaited"
619 else if ( !anInNode->IsMacroNode() ) {
620 // It is a HeadNode ==> AllDataReadyEvent ==> InNode::executeAction() ==> pthread_create
621 if ( !anInNode->SendEvent( GraphExecutor::ExecuteEvent ) ) {
622 cdebug << "InNode::SendEvent( ExecuteEvent ) ERROR Node "
623 << anInNode->Name() << endl ;
624 cdebug_out << "GraphExecutor::OutNode::Run SendEvent ERROR" << endl ;
627 // ==> We wait for RunningState
628 anInNode->RunningWait() ;
633 PushEvent( NULL , GraphExecutor::SuspendedReadyEvent ,
634 GraphExecutor::SuspendedReadyState ) ;
637 PushEvent( NULL , GraphExecutor::ExecutingEvent ,
638 GraphExecutor::ExecutingState ) ;
639 if (AutomatonState() == GraphExecutor::DataReadyState) {
640 State( GraphExecutor::ExecutingState ) ;
643 // ostringstream astr ;
644 // astr << "Graph " << Graph()->Name() << " is running" ;
645 // Graph()->ObjImpl()->sendMessage( NOTIF_STEP, astr.str().c_str() ) ;
650 cdebug_out << pthread_self() << "GraphExecutor::OutNode::Run " << Graph()->Name()
651 << " GraphMacroLevel "
652 << Graph()->GraphMacroLevel() << " RetVal " << RetVal << endl ;
656 void GraphExecutor::OutNode::CheckAllDone() {
658 cdebug_in << "GraphExecutor::OutNode::CheckAllDone " << endl;
659 GraphExecutor::AutomatonState OutNodeState = GraphExecutor::SuccessedState ;
660 GraphExecutor::AutomatonState InNodeState ;
661 bool AllDone = true ;
663 for ( j = 0 ; j < Graph()->QueueNodesSize() ; j++ ) {
664 InNodeState = ( (GraphExecutor::InNode * ) Graph()->QueueNodes( j )->GetInNode() )->State() ;
666 << ( (GraphExecutor::InNode * ) Graph()->QueueNodes( j )->GetInNode() )->Name()
667 << " " << theAutomaton->StateName( InNodeState ) << endl ;
668 if ( InNodeState != GraphExecutor::SuccessedState &&
669 InNodeState != GraphExecutor::ErroredState &&
670 InNodeState != GraphExecutor::DataWaitingState ) {
673 if ( InNodeState != GraphExecutor::SuccessedState &&
674 InNodeState != GraphExecutor::DataWaitingState &&
675 InNodeState != GraphExecutor::DataReadyState ) {
676 OutNodeState = InNodeState ;
680 if( _Threads == 0 && _SuspendedThreads == 0 ) {
681 if ( OutNodeState != GraphExecutor::ErroredState ) {
682 OutNodeState = GraphExecutor::SuccessedState ;
691 for ( j = 0 ; j < Graph()->GraphNodesSize() ; j++ ) {
692 GraphExecutor::InNode * aNode ;
693 aNode = (GraphExecutor::InNode * ) Graph()->GraphNodes( j )->GetInNode() ;
694 SUPERV::GraphState aState = AutomatonGraphState( aNode->State() ) ;
695 cdebug << "GraphExecutor::OutNode::CheckAllDone " << aNode->Name() << " "
696 << theAutomaton->StateName( aNode->State() ) << " CreateNewThread " << aNode->CreateNewThread()
698 if ( aState == SUPERV::ErrorState ||
699 aState == SUPERV::SuspendErroredState ||
700 aState == SUPERV::KillState ||
701 aState == SUPERV::StopState ) {
702 OutNodeState = aNode->State() ;
703 State( OutNodeState ) ;
705 else if ( aState == SUPERV::ReadyState ||
706 aState == SUPERV::SuspendReadyState ||
707 aState == SUPERV::RunningState ||
708 aState == SUPERV::SuspendDoneState ||
709 aState == SUPERV::SuspendErroredState ||
710 aState == SUPERV::SuspendState ) {
713 aNode->SuspendedAction() ;
714 aNode->DoneAction() ;
716 // PushEvent AFTER State and _Done ! ...
717 if ( alivenodes == 0 ) {
718 State( OutNodeState ) ;
720 _JustStarted = false ;
722 cdebug << Graph()->Name() << " alivenodes " << alivenodes << " OutNodeState " << OutNodeState
724 PushEvent( NULL , GraphExecutor::EndExecuteEvent ,
727 // PyInitialized( false ) ;
731 MESSAGE("================================================================================") ;
732 MESSAGE( Graph()->Name() << " IS DONE : " << theAutomaton->StateName( AutomatonState() ) << " EventQSize "
734 MESSAGE("================================================================================") ;
735 cdebug << "================================================================================" << endl ;
736 cdebug << Graph()->Name() << " IS DONE : " << theAutomaton->StateName( AutomatonState() ) << " EventQSize "
737 << EventQSize() << endl ;
738 cdebug << "================================================================================" << endl ;
740 // asv : fix for 6798 and other bugs: "sift" the event queue after execution
743 // asv : 25.10.04 : calling Editing() to indicate stop of execution
744 Graph()->GraphEditor()->Editing();
746 cdebug_out << "GraphExecutor::OutNode::CheckAllDone " << IsDone() << " this " << this << " "
747 << Graph()->Name() << " GraphAutomatonState "
748 << theAutomaton->StateName( AutomatonState() )
749 << " State " << State() << " Threads " << _Threads << " SuspendedThreads "
750 << _SuspendedThreads << " EventQSize " << EventQSize() << endl ;
753 Engines_Container_i * GraphExecutor::OutNode::SuperVisionContainer() {
754 return _SuperVisionContainer ;
757 const pthread_t GraphExecutor::OutNode::MainThreadId() const {
758 return _MainThreadId ;
761 void GraphExecutor::OutNode::PThreadLock( pthread_mutex_t * aMutex , char * errmsg ) {
762 // if ( strcmp( errmsg , "EventLoop" ) && strcmp( errmsg , "EventW" ) ) {
763 // cdebug << "GraphExecutor::OutNode::PThreadLock " << pthread_self() << " " << aMutex << " "
764 // << errmsg << endl ;
766 if ( pthread_mutex_lock( aMutex ) ) {
770 // if ( strcmp( errmsg , "EventLoop" ) && strcmp( errmsg , "EventW" ) ) {
771 // cdebug << "GraphExecutor::OutNode::PThreadLocked " << pthread_self() << " " << aMutex << " "
772 // << errmsg << endl ;
776 void GraphExecutor::OutNode::PThreadUnLock( pthread_mutex_t * aMutex , char * errmsg ) {
777 // if ( strcmp( errmsg , "EventLoop" ) && strcmp( errmsg , "EventW" ) ) {
778 // cdebug << " GraphExecutor::OutNode::PThreadUnLock " << pthread_self() << " " << aMutex << " "
779 // << errmsg << endl ;
781 if ( pthread_mutex_unlock( aMutex ) ) {
787 void GraphExecutor::OutNode::PyThreadLock() {
788 // cout << " GraphExecutor::OutNode::PyThreadLock " << pthread_self() << endl ;
789 if ( pthread_mutex_lock( &_PyMutexWait ) ) {
790 perror( "GraphExecutor::OutNode::PyThreadLock" ) ;
793 theAutomaton->PyLock() ;
794 // cout << " GraphExecutor::OutNode::PyThreadLocked " << pthread_self() << endl ;
797 void GraphExecutor::OutNode::PyThreadUnLock() {
798 // cout << " GraphExecutor::OutNode::PyThreadUnLock " << pthread_self() << endl ;
799 if ( pthread_mutex_unlock( &_PyMutexWait ) ) {
800 perror( "GraphExecutor::OutNode::PyThreadUnLock" ) ;
803 theAutomaton->PyUnLock() ;
804 // cout << " GraphExecutor::OutNode::PyThreadUnLocked " << pthread_self() << endl ;
807 void GraphExecutor::OutNode::NewThread() {
808 if ( pthread_mutex_lock( &_MutexWait ) ) {
809 perror("pthread_mutex_lock _NewThread") ;
813 cdebug << "NewThread : " << _Threads << " running threads "
814 << _SuspendedThreads << " suspended threads"
816 if ( pthread_mutex_unlock( &_MutexWait ) ) {
817 perror("pthread_mutex_unlock _NewThread") ;
822 void GraphExecutor::OutNode::ExitThread( pthread_t ThreadNumber ) {
823 if ( pthread_mutex_lock( &_MutexWait ) ) {
824 perror("pthread_mutex_lock _ExitThread") ;
827 if ( ThreadNumber == 0 ) {
828 ThreadNumber = pthread_self() ;
831 cdebug << pthread_self() << " ExitThread( " << ThreadNumber << " ) " << _Threads << " running threads "
832 << _SuspendedThreads << " suspended threads"
834 theAutomaton->JoinThread( ThreadNumber ) ;
835 if ( pthread_cond_signal( &_JoinWait ) ) {
836 perror("ExitThread pthread_cond_signal ") ;
838 if ( pthread_mutex_unlock( &_MutexWait ) ) {
839 perror("pthread_mutex_unlock _ExitThread") ;
842 if ( _Threads == 0 && _SuspendedThreads == 0 ) {
845 theAutomaton->Executed() ;
849 void GraphExecutor::OutNode::JoinedWait() {
850 if ( pthread_mutex_lock( &_MutexWait ) ) {
851 perror("pthread_mutex_lock JoinedWait") ;
855 if ( pthread_cond_wait( &_JoinWait , &_MutexWait ) ) {
856 perror("JoinedWait pthread_cond_wait ") ;
859 if ( pthread_mutex_unlock( &_MutexWait ) ) {
860 perror("pthread_mutex_unlock JoinedWait") ;
865 void GraphExecutor::OutNode::SuspendThread() {
866 if ( pthread_mutex_lock( &_MutexWait ) ) {
867 perror("pthread_mutex_lock _SuspendThread") ;
870 _SuspendedThreads += 1 ;
871 cdebug << "SuspendThread : " << _Threads << " running threads "
872 << _SuspendedThreads << " suspended threads"
874 if ( pthread_mutex_unlock( &_MutexWait ) ) {
875 perror("pthread_mutex_unlock _SuspendThread") ;
878 if ( IsSuspended() ) {
879 PushEvent( NULL , GraphExecutor::SuspendEvent , GraphExecutor::SuspendedState ) ;
882 void GraphExecutor::OutNode::ResumeThread() {
883 if ( pthread_mutex_lock( &_MutexWait ) ) {
884 perror("pthread_mutex_lock _ResumeThread") ;
887 _SuspendedThreads -= 1 ;
888 cdebug << "ResumeThread : " << _Threads << " running threads "
889 << _SuspendedThreads << " suspended threads"
891 if ( pthread_mutex_unlock( &_MutexWait ) ) {
892 perror("pthread_mutex_unlock _ResumeThread") ;
897 long GraphExecutor::OutNode::Thread( const char * aNodeName ) {
899 GraphExecutor::InNode *anInNode = (GraphExecutor::InNode *) Graph()->GetGraphNode( aNodeName )->GetInNode() ;
901 RetVal = anInNode->ThreadNo() ;
906 SUPERV::GraphEvent GraphExecutor::OutNode::AutomatonGraphEvent(GraphExecutor::NodeEvent anEvent ) {
907 SUPERV::GraphEvent aGraphEvent ;
909 case GraphExecutor::UndefinedEvent : {
910 aGraphEvent = SUPERV::UndefinedEvent ;
913 case GraphExecutor::NewThreadEvent : {
914 aGraphEvent = SUPERV::NewThreadEvent ;
917 case GraphExecutor::SuspendEvent : {
918 aGraphEvent = SUPERV::SuspendEvent ;
921 case GraphExecutor::ResumeEvent : {
922 aGraphEvent = SUPERV::ResumeEvent ;
925 case GraphExecutor::KillEvent : {
926 aGraphEvent = SUPERV::KillEvent ;
929 case GraphExecutor::StopEvent : {
930 aGraphEvent = SUPERV::StopEvent ;
933 case GraphExecutor::ExecuteEvent : {
934 aGraphEvent = SUPERV::RunningEvent ;
937 case GraphExecutor::SuccessEvent : {
938 aGraphEvent = SUPERV::DoneEvent ;
941 case GraphExecutor::ErrorEvent : {
942 aGraphEvent = SUPERV::ErroredEvent ;
945 case GraphExecutor::NoDataReadyEvent : {
946 aGraphEvent = SUPERV::WaitingEvent ;
949 case GraphExecutor::SomeDataReadyEvent : {
950 aGraphEvent = SUPERV::WaitingEvent ;
953 case GraphExecutor::NotAllDataReadyEvent : {
954 aGraphEvent = SUPERV::WaitingEvent ;
957 case GraphExecutor::AllDataReadyEvent : {
958 aGraphEvent = SUPERV::ReadyEvent ;
961 case GraphExecutor::ReadyEvent : {
962 aGraphEvent = SUPERV::ReadyEvent ;
965 case GraphExecutor::SuspendedReadyEvent : {
966 aGraphEvent = SUPERV::SuspendEvent ;
969 case GraphExecutor::ResumedReadyEvent : {
970 aGraphEvent = SUPERV::ResumeEvent ;
973 case GraphExecutor::KilledReadyEvent : {
974 aGraphEvent = SUPERV::KillEvent ;
977 case GraphExecutor::StoppedReadyEvent : {
978 aGraphEvent = SUPERV::StopEvent ;
981 case GraphExecutor::ExecutingEvent : {
982 aGraphEvent = SUPERV::RunningEvent ;
985 case GraphExecutor::SuspendedExecutingEvent : {
986 aGraphEvent = SUPERV::SuspendEvent ;
989 case GraphExecutor::ResumedExecutingEvent : {
990 aGraphEvent = SUPERV::ResumeEvent ;
993 case GraphExecutor::KilledExecutingEvent : {
994 aGraphEvent = SUPERV::KillEvent ;
997 case GraphExecutor::StoppedExecutingEvent : {
998 aGraphEvent = SUPERV::StopEvent ;
1001 case GraphExecutor::SuccessedExecutingEvent : {
1002 aGraphEvent = SUPERV::DoneEvent ;
1005 case GraphExecutor::ErroredExecutingEvent : {
1006 aGraphEvent = SUPERV:: ErroredEvent;
1009 case GraphExecutor::SuspendedSuccessedEvent : {
1010 aGraphEvent = SUPERV::SuspendEvent ;
1013 case GraphExecutor::SuspendedErroredEvent : {
1014 aGraphEvent = SUPERV::SuspendEvent ;
1017 case GraphExecutor::ResumedSuccessedEvent : {
1018 aGraphEvent = SUPERV::ResumeEvent ;
1021 case GraphExecutor::ResumedErroredEvent : {
1022 aGraphEvent = SUPERV::ResumeEvent ;
1025 case GraphExecutor::KilledEvent : {
1026 aGraphEvent = SUPERV::KillEvent ;
1029 case GraphExecutor::StoppedEvent : {
1030 aGraphEvent = SUPERV::StopEvent ;
1033 case GraphExecutor::EndExecuteEvent : {
1034 aGraphEvent = SUPERV::DoneEvent ;
1038 cdebug << " GraphExecutor::OutNode::AutomatonGraphEvent Error Undefined Event : "
1039 << anEvent << endl ;
1040 aGraphEvent = SUPERV::UndefinedEvent ;
1043 return aGraphEvent ;
1046 SUPERV::GraphState GraphExecutor::OutNode::AutomatonGraphState(GraphExecutor::AutomatonState aState ) {
1047 SUPERV::GraphState aGraphState ;
1049 case GraphExecutor::UnKnownState : {
1050 aGraphState = SUPERV::UndefinedState ;
1053 case GraphExecutor::DataUndefState : {
1054 aGraphState = SUPERV::UndefinedState ;
1057 case GraphExecutor::DataWaitingState : {
1058 aGraphState = SUPERV::WaitingState ;
1061 case GraphExecutor::DataReadyState : {
1062 aGraphState = SUPERV::ReadyState ;
1065 case GraphExecutor::SuspendedReadyState : {
1066 aGraphState = SUPERV::SuspendReadyState ;
1069 case GraphExecutor::ResumedReadyState : {
1070 aGraphState = SUPERV::ReadyState ;
1073 case GraphExecutor::KilledReadyState : {
1074 aGraphState = SUPERV::KillState ;
1077 case GraphExecutor::StoppedReadyState : {
1078 aGraphState = SUPERV::StopState ;
1081 case GraphExecutor::ExecutingState : {
1082 aGraphState = SUPERV::RunningState ;
1085 case GraphExecutor::SuspendedExecutingState : {
1086 aGraphState = SUPERV::SuspendState ;
1089 case GraphExecutor::ResumedExecutingState : {
1090 aGraphState = SUPERV::RunningState ;
1093 case GraphExecutor::KilledExecutingState : {
1094 aGraphState = SUPERV::KillState ;
1097 case GraphExecutor::StoppedExecutingState : {
1098 aGraphState = SUPERV::StopState ;
1101 case GraphExecutor::SuccessedExecutingState : {
1102 aGraphState = SUPERV::DoneState ;
1105 case GraphExecutor::ErroredExecutingState : {
1106 aGraphState = SUPERV::ErrorState ;
1109 case GraphExecutor::SuspendedSuccessedState : {
1110 aGraphState = SUPERV::SuspendDoneState ;
1113 case GraphExecutor::SuspendedErroredState : {
1114 aGraphState = SUPERV::SuspendErroredState ;
1117 case GraphExecutor::ResumedSuccessedState : {
1118 aGraphState = SUPERV::DoneState ;
1121 case GraphExecutor::ResumedErroredState : {
1122 aGraphState = SUPERV::ErrorState ;
1125 case GraphExecutor::KilledSuccessedState : {
1126 aGraphState = SUPERV::KillState ;
1129 case GraphExecutor::KilledErroredState : {
1130 aGraphState = SUPERV::KillState ;
1133 case GraphExecutor::StoppedSuccessedState : {
1134 aGraphState = SUPERV::StopState ;
1137 case GraphExecutor::StoppedErroredState : {
1138 aGraphState = SUPERV::StopState ;
1141 case GraphExecutor::SuccessedState : {
1142 aGraphState = SUPERV::DoneState ;
1145 case GraphExecutor::ErroredState : {
1146 aGraphState = SUPERV::ErrorState ;
1149 case GraphExecutor::SuspendedState : {
1150 aGraphState = SUPERV::SuspendState ;
1153 case GraphExecutor::KilledState : {
1154 aGraphState = SUPERV::KillState ;
1157 case GraphExecutor::StoppedState : {
1158 aGraphState = SUPERV::StopState ;
1161 case GraphExecutor::LoadingState : {
1162 aGraphState = SUPERV::LoadingState ;
1166 cdebug << " GraphExecutor::OutNode::AutomatonGraphState Error Undefined State : "
1167 << aGraphState << endl ;
1168 aGraphState = SUPERV::UndefinedState ;
1171 return aGraphState ;
1174 int GraphExecutor::OutNode::GetListSize() {
1175 return _EventNodes.size();
1178 bool GraphExecutor::OutNode::PushEvent( GraphExecutor::InNode * aNode ,
1179 GraphExecutor::NodeEvent anEvent ,
1180 GraphExecutor::AutomatonState aState ) {
1181 // cdebug_in << "PushEvent Threads " << Threads() << " SuspendedThreads "
1182 // << SuspendedThreads() << endl ;
1183 if ( pthread_mutex_lock( &_MutexWait ) ) {
1184 perror("PushEvent pthread_mutex_lock ") ;
1187 char* aNodeName = aNode ? aNode->Name() : Graph()->Name() ;
1188 _EventNodes.push_back( aNodeName ) ;
1189 _Events.push_back( anEvent ) ;
1190 _States.push_back( aState ) ;
1192 pthread_cond_broadcast( &_EventWait );
1193 cdebug << pthread_self() << " PushEvent Threads " << Threads() << " SuspendedThreads "
1194 << SuspendedThreads() << " pthread_cond_broadcast _EventWait " << &_EventWait << endl ;
1196 // cdebug << aNode->ThreadNo() << " PushEvent " << aNode->Name() ;
1197 // cdebug << " " << aNode->Automaton()->EventName( anEvent )
1198 // << " " << aNode->Automaton()->StateName( aState )
1199 // << " ControleState "
1200 // << aNode->Automaton()->ControlStateName( aNode->ControlState() ) ;
1203 // cdebug << "PushEvent " << Graph()->Name() ;
1204 // cdebug << " " << theAutomaton->EventName( anEvent ) << " "
1205 // << theAutomaton->StateName( aState ) ;
1207 // cdebug_out << "PushEvent Threads " << Threads() << " SuspendedThreads "
1208 // << SuspendedThreads() << endl ;
1210 if ( _EventNodes.size() > 101 ) {
1211 while ( _EventNodes.size() > 31 ) {
1212 _EventNodes.pop_front() ;
1213 _Events.pop_front() ;
1214 _States.pop_front() ;
1218 if ( pthread_mutex_unlock( &_MutexWait ) ) {
1219 perror("PushEvent pthread_mutex_unlock ") ;
1225 bool GraphExecutor::OutNode::StateWait( SUPERV::GraphState aState ) {
1229 bool GraphExecutor::OutNode::Event( char ** aNodeName ,
1230 SUPERV::GraphEvent & anEvent ,
1231 SUPERV::GraphState & aState ,
1233 // asv : fixing problem of loops with large number of iterations (>5000)
1234 // experimentally was found that number of non-handled by GUI events = (number_of_nodes x 7)
1235 // or 7 events for each node - so what we want to do here is remove "old" events for nodes
1236 // "on the fly". Once again it is done in Stop(), Kill(), Done() functions.
1237 if ( _EventNodes.size() > (unsigned int)Graph()->GraphNodesSize()*7 )
1241 int SuspendedThreadsNumber ;
1242 bool cdebuginout = false ;
1243 if ( _EventNodes.size() > 0 ) {
1244 // cdebug_in << "GraphExecutor::OutNode::Event " << _EventNodes.size() << " in queue" << endl ;
1245 cdebuginout = true ;
1247 if ( pthread_mutex_lock( &_MutexWait ) ) {
1248 perror("EventLoop pthread_mutex_lock ") ;
1251 _JustStarted = false ;
1252 ThreadsNumber = Threads() ;
1253 SuspendedThreadsNumber = SuspendedThreads() ;
1254 bool RetVal = ( ThreadsNumber - SuspendedThreadsNumber) != 0 ||
1255 _EventNodes.size() > 0 ;
1256 char * NodeName = "" ;
1257 GraphExecutor::NodeEvent theEvent = GraphExecutor::UndefinedEvent ;
1258 GraphExecutor::AutomatonState theState = GraphExecutor::UnKnownState ;
1259 anEvent = SUPERV::UndefinedEvent ;
1260 aState = SUPERV::UndefinedState ;
1261 if ( ( Done() || IsKilled() || IsStopped() ) && _EventNodes.size() == 0 ) {
1262 // cdebug << "EventLoop Done()/IsKilled()/IsStopped() && _EventNodes.size() == 0" << endl ;
1265 else if ( !WithWait && _EventNodes.size() == 0 ) {
1266 anEvent = SUPERV::NoEvent ;
1267 aState = SUPERV::NoState ;
1270 else if ( RetVal ) {
1271 while ( !IsSuspended() && _EventNodes.size() == 0 ) {
1272 // cdebug << "EventLoop pthread_cond_wait _EventWait" << endl ;
1273 pthread_cond_wait( &_EventWait , &_MutexWait );
1274 // cdebug << "EventLoop pthread_cond_waited _EventWait"
1275 // << " _EventNodes.size() " << _EventNodes.size() << endl ;
1277 if ( _EventNodes.size() ) {
1278 ThreadsNumber = Threads() ;
1279 NodeName = _EventNodes.front() ;
1280 _EventNodes.pop_front() ;
1281 theEvent = _Events.front() ;
1282 anEvent = AutomatonGraphEvent( theEvent ) ;
1283 _Events.pop_front() ;
1284 theState = _States.front() ;
1285 aState = AutomatonGraphState( theState ) ;
1286 _States.pop_front() ;
1289 *aNodeName = NodeName ;
1290 if ( IsSuspended() && _EventNodes.size() == 0 ) {
1293 if ( anEvent != SUPERV::NoEvent ) {
1294 // cdebug << pthread_self() << "EventLoop "
1295 // << NodeName << " " << theAutomaton->StateName( theState )
1296 // << " _EventNodes.size() " << _EventNodes.size()
1297 // << " Threads " << Threads() << " SuspendedThreads "
1298 // << SuspendedThreads() << " RetVal " << RetVal << endl ;
1300 if ( pthread_mutex_unlock( &_MutexWait ) ) {
1301 perror("EventLoop pthread_mutex_lock ") ;
1304 if ( cdebuginout ) {
1305 // cdebug_out << "GraphExecutor::OutNode::Event " << _EventNodes.size() << " in queue"
1306 // << *aNodeName << " " << anEvent << " " << aState << endl ;
1311 bool GraphExecutor::OutNode::EventW( char ** aNodeName ,
1312 SUPERV::GraphEvent & anEvent ,
1313 SUPERV::GraphState & aState ) {
1316 aState = SUPERV::UndefinedState ;
1318 aState != SUPERV::SuspendReadyState &&
1319 aState != SUPERV::RunningState &&
1320 aState != SUPERV::SuspendDoneState &&
1321 aState != SUPERV::SuspendErroredState ) {
1322 NodeName = Graph()->Name() ;
1323 while ( sts && !strcmp( NodeName , Graph()->Name() ) ) {
1324 sts = EventWait( aNodeName , anEvent , aState ) ;
1325 NodeName = *aNodeName ;
1331 bool GraphExecutor::OutNode::EventWait( char ** aNodeName ,
1332 SUPERV::GraphEvent & anEvent ,
1333 SUPERV::GraphState & aState ) {
1334 if ( pthread_mutex_lock( &_MutexWait ) ) {
1335 perror("EventW pthread_mutex_lock ") ;
1339 int SuspendedThreadsNumber ;
1340 ThreadsNumber = Threads() ;
1341 SuspendedThreadsNumber = SuspendedThreads() ;
1342 bool RetVal = ( ThreadsNumber - SuspendedThreadsNumber) != 0 ||
1343 _EventNodes.size() > 0 ;
1344 cdebug << "--> EventW RetVal " << RetVal << endl ;
1345 char * NodeName = "" ;
1346 GraphExecutor::NodeEvent theEvent = GraphExecutor::UndefinedEvent ;
1347 GraphExecutor::AutomatonState theState = GraphExecutor::UnKnownState ;
1348 anEvent = SUPERV::UndefinedEvent ;
1349 aState = SUPERV::UndefinedState ;
1350 if ( IsDone() && _EventNodes.size() == 0 ) {
1351 cdebug << "EventW IsDone() && _EventNodes.size() == 0" << endl ;
1354 else if ( RetVal ) {
1355 GraphExecutor::InNode * aNode = NULL ;
1356 while ( aNode == NULL && RetVal ) {
1357 NodeName = _EventNodes.front() ;
1358 theEvent = _Events.front() ;
1359 anEvent = AutomatonGraphEvent( theEvent ) ;
1360 theState = _States.front() ;
1361 aState = AutomatonGraphState( theState ) ;
1363 if ( _JustStarted ) {
1364 _JustStarted = false ;
1367 _EventNodes.pop_front() ;
1368 _Events.pop_front() ;
1369 _States.pop_front() ;
1372 aNode = ((GraphExecutor::InNode *) Graph()->GetGraphNode( NodeName )->GetInNode()) ;
1373 cdebug << "EventW Previous Node " << NodeName << " ThreadsNumber "
1375 << " _EventNodes.size() " << _EventNodes.size() << " "
1376 << theAutomaton->StateName( theState )
1377 << " Threads " << Threads() << " SuspendedThreads "
1378 << SuspendedThreads() << endl ;
1381 else if ( IsDone() && _EventNodes.size() == 0 ) {
1382 cdebug << "EventW IsDone() && _EventNodes.size() == 0" << endl ;
1386 cdebug << "EventW Not InNode " << NodeName
1387 << " _EventNodes.size() " << _EventNodes.size() << endl ;
1388 while ( _EventNodes.size() == 0 ) {
1389 pthread_cond_wait( &_EventWait , &_MutexWait );
1391 cdebug << "EventW pthread_cond_waited Not InNode " << NodeName
1392 << " _EventNodes.size() " << _EventNodes.size() << endl ;
1397 if ( aState == SUPERV::SuspendState ||
1398 aState == SUPERV::SuspendReadyState ||
1399 aState == SUPERV::SuspendDoneState ||
1400 aState == SUPERV::SuspendErroredState ) {
1401 aNode->ControlState( SUPERV::ToSuspendState ) ;
1402 if ( aNode->IsSuspended() ) {
1403 if ( pthread_mutex_unlock( &_MutexWait ) ) {
1404 perror("EventW pthread_mutex_lock ") ;
1407 cdebug << "EventW " << aNode->Name() << " ResumeAction" << endl ;
1408 aNode->ResumeAction( GraphExecutor::ToResumeEvent ) ;
1409 cdebug << "EventW " << aNode->Name() << " ResumedAction" << endl ;
1410 if ( pthread_mutex_lock( &_MutexWait ) ) {
1411 perror("EventW pthread_mutex_lock ") ;
1416 cdebug << "EventW inconsistent SuspendState" << endl ;
1421 if ( aNode->IsDone() ) {
1425 cdebug << "EventW NOT SuspendedState _EventNodes.size() "
1426 << _EventNodes.size() << endl ;
1431 cdebug << "EventW " << aNode->Name() << " pthread_cond_wait" << endl ;
1432 while ( _EventNodes.size() == 0 ) {
1433 pthread_cond_wait( &_EventWait , &_MutexWait );
1435 ThreadsNumber = Threads() ;
1436 NodeName = _EventNodes.front() ;
1437 theEvent = _Events.front() ;
1438 anEvent = AutomatonGraphEvent( theEvent ) ;
1439 theState = _States.front() ;
1440 aState = AutomatonGraphState( theState ) ;
1444 *aNodeName = NodeName ;
1445 cdebug << "<-- EventW RetVal " << RetVal << " " << NodeName
1446 << " Threads " << Threads() << " SuspendedThreads "
1447 << SuspendedThreads()
1448 << " _EventNodes.size() " << _EventNodes.size()
1449 << " " << theAutomaton->EventName( theEvent ) << " "
1450 << theAutomaton->StateName( theState ) << endl ;
1451 if ( pthread_mutex_unlock( &_MutexWait ) ) {
1452 perror("EventW pthread_mutex_lock ") ;
1457 long GraphExecutor::OutNode::EventQSize() {
1458 return _EventNodes.size() ;
1461 void GraphExecutor::OutNode::EventList() {
1462 if ( pthread_mutex_lock( &_MutexWait ) ) {
1463 perror("EventList pthread_mutex_lock ") ;
1466 list< char * >::iterator itEventNodes = _EventNodes.begin() ;
1467 list< GraphExecutor::NodeEvent >::iterator itEvents = _Events.begin() ;
1468 list< GraphExecutor::AutomatonState >::iterator itStates = _States.begin() ;
1469 while ( itEventNodes != _EventNodes.end() ) {
1470 cdebug << pthread_self() << "EVENTSTACK "
1471 << *itEventNodes << " " << *itEvents << " "
1472 << theAutomaton->StateName( *itStates )
1473 << " Threads " << Threads() << " SuspendedThreads " << SuspendedThreads() << endl ;
1478 if ( pthread_mutex_unlock( &_MutexWait ) ) {
1479 perror("EventList pthread_mutex_lock ") ;
1484 void GraphExecutor::OutNode::SendSomeDataReady( const char * aNodeName ) {
1485 cdebug_in << "GraphExecutor::OutNode::SendSomeDataReady " << aNodeName << "->SendSomeDataReady( "
1486 << Graph()->Name() << " )" << endl;
1488 sts = ((GraphExecutor::InNode * ) Graph()->GetChangeGraphNode( aNodeName )->GetInNode())->SendSomeDataReady( Graph()->Name() ) ;
1489 cdebug_out << "GraphExecutor::OutNode::SendSomeDataReady sts " << sts << endl ;
1492 void GraphExecutor::OutNode::State(GraphExecutor::AutomatonState aState ) {
1493 // cdebug << "GraphExecutor::OutNode::State " << Graph()->Name() << " "
1494 // << theAutomaton->StateName( AutomatonGraphState( _State ) ) << " ---> "
1495 // << theAutomaton->StateName( AutomatonGraphState( aState ) ) << endl ;
1499 SUPERV::GraphState GraphExecutor::OutNode::State() {
1500 // cdebug_in << "GraphExecutor::OutNode::State" << endl;
1501 // cdebug_out << "GraphExecutor::OutNode::State" << endl ;
1502 // cdebug << "GraphExecutor::OutNode::State GraphState "
1503 // << theAutomaton->StateName( AutomatonGraphState( _State ) ) << endl ;
1504 return AutomatonGraphState( _State ) ;
1507 SUPERV::GraphState GraphExecutor::OutNode::State( const char * NodeName ) {
1508 // cdebug_in << "GraphExecutor::OutNode::State " << NodeName << endl;
1509 GraphExecutor::AutomatonState aret = GraphExecutor::UnKnownState ;
1510 const GraphBase::ComputingNode * aCNode = Graph()->GetGraphNode( NodeName ) ;
1512 GraphExecutor::InNode *anInNode = (GraphExecutor::InNode *)aCNode->GetInNode() ;
1514 if ( anInNode->IsLoading() )
1515 aret = GraphExecutor::LoadingState;
1517 aret = anInNode->State() ;
1518 // cdebug << "GraphExecutor::OutNode::State( " << NodeName << " ) "
1519 // << theAutomaton->StateName( AutomatonGraphState( aret ) ) << endl ;
1522 // cdebug_out << "GraphExecutor::OutNode::State" << endl ;
1523 return AutomatonGraphState( aret ) ;
1526 SUPERV::GraphState GraphExecutor::OutNode::State( const char * NodeName ,
1527 const char * ServiceParameterName ) {
1528 // cdebug_in << "GraphExecutor::OutNode::State " << NodeName << " "
1529 // << ServiceParameterName<< endl;
1530 SUPERV::GraphState aret = Graph()->PortState( NodeName , ServiceParameterName ) ;
1531 // cdebug_out << "GraphExecutor::OutNode::State" << endl ;
1535 GraphExecutor::AutomatonState GraphExecutor::OutNode::AutomatonState() {
1536 // cdebug_in << "GraphExecutor::OutNode::AutomatonState" << endl;
1537 // cdebug_out << "GraphExecutor::OutNode::AutomatonState" << endl ;
1541 GraphExecutor::AutomatonState GraphExecutor::OutNode::AutomatonState( const char * NodeName ) {
1542 // cdebug_in << "GraphExecutor::OutNode::AutomatonState " << NodeName << endl;
1543 GraphExecutor::AutomatonState aret = GraphExecutor::UnKnownState ;
1544 const GraphBase::ComputingNode * aNode = Graph()->GetGraphNode( NodeName ) ;
1546 GraphExecutor::InNode *anInNode = (GraphExecutor::InNode *) aNode->GetInNode() ;
1548 aret = anInNode->State() ;
1551 // cdebug_out << "GraphExecutor::OutNode::AutomatonState" << endl ;
1555 SUPERV::ControlState GraphExecutor::OutNode::ControlState() {
1556 // cdebug_in << "GraphExecutor::OutNode::ControlState" << endl;
1557 // cdebug_out << "GraphExecutor::OutNode::ControlState" << endl ;
1558 return _ControlState ;
1561 SUPERV::ControlState GraphExecutor::OutNode::ControlState( const char * NodeName ) {
1562 // cdebug_in << "GraphExecutor::OutNode::ControlState " << NodeName << endl;
1563 SUPERV::ControlState aret = SUPERV::VoidState ;
1564 const GraphBase::ComputingNode * aNode = Graph()->GetGraphNode( NodeName ) ;
1566 GraphExecutor::InNode *anInNode = (GraphExecutor::InNode *) aNode->GetInNode() ;
1568 aret = anInNode->ControlState() ;
1571 // cdebug_out << "GraphExecutor::OutNode::ControlState" << endl ;
1575 void GraphExecutor::OutNode::ControlClear() {
1576 // cdebug_in << "GraphExecutor::OutNode::ControlClear" << endl;
1577 // cdebug_out << "GraphExecutor::OutNode::ControlClear" << endl ;
1578 _ControlState = SUPERV::VoidState;
1581 void GraphExecutor::OutNode::ControlClear( const char * NodeName ) {
1582 // cdebug_in << "GraphExecutor::OutNode::ControlClear " << NodeName << endl;
1583 const GraphBase::ComputingNode * aNode = Graph()->GetGraphNode( NodeName ) ;
1585 GraphExecutor::InNode *anInNode = (GraphExecutor::InNode *) aNode->GetInNode() ;
1587 anInNode->ControlClear() ;
1590 // cdebug_out << "GraphExecutor::OutNode::ControlClear" << endl ;
1593 bool GraphExecutor::OutNode::IsWaiting() {
1594 // cdebug_in << "GraphExecutor::OutNode::IsWaiting" << endl;
1595 // cdebug_out << "GraphExecutor::OutNode::IsWaiting" << endl ;
1599 bool GraphExecutor::OutNode::IsReady() {
1600 // cdebug_in << "GraphExecutor::OutNode::IsReady" << endl;
1601 // cdebug_out << "GraphExecutor::OutNode::IsReady" << endl ;
1605 bool GraphExecutor::OutNode::IsRunning() {
1606 // cdebug_in << "GraphExecutor::OutNode::IsRunning" << endl;
1607 // cdebug_out << "GraphExecutor::OutNode::IsRunning" << endl ;
1611 bool GraphExecutor::OutNode::IsDone() {
1612 // cdebug_in << "GraphExecutor::OutNode::IsDone" << endl;
1613 // cdebug_out << "GraphExecutor::OutNode::IsDone" << endl ;
1614 return ( Done() || IsKilled() || IsStopped() ) ;
1617 bool GraphExecutor::OutNode::IsSuspended() {
1618 // cdebug_in << "GraphExecutor::OutNode::IsSuspended" << endl;
1620 // if ( _SuspendedThreads == _Threads && _Threads != 0 ) {
1621 if ( AutomatonGraphState( _State ) == SUPERV::SuspendState ) {
1624 // cdebug_out << "GraphExecutor::OutNode::IsSuspended" << endl ;
1628 bool GraphExecutor::OutNode::IsKilled() {
1629 // cdebug_in << "GraphExecutor::OutNode::IsKilled" << endl;
1631 if ( AutomatonGraphState( _State ) == SUPERV::KillState ) {
1634 // cdebug_out << "GraphExecutor::OutNode::IsKilled" << endl ;
1638 bool GraphExecutor::OutNode::IsStopped() {
1639 // cdebug_in << "GraphExecutor::OutNode::IsStopped" << endl;
1641 if ( AutomatonGraphState( _State ) == SUPERV::StopState ) {
1644 // cdebug_out << "GraphExecutor::OutNode::IsStopped" << endl ;
1648 bool GraphExecutor::OutNode::IsWaiting( const char * NodeName ) {
1650 // cdebug_in << "GraphExecutor::OutNode::IsWaiting " << NodeName << endl;
1651 GraphExecutor::InNode *anInNode = (GraphExecutor::InNode *) Graph()->GetGraphNode( NodeName )->GetInNode() ;
1653 aret = anInNode->IsWaiting() ;
1655 // cdebug_out << "GraphExecutor::OutNode::IsWaiting" << endl ;
1659 bool GraphExecutor::OutNode::IsReady( const char * NodeName ) {
1661 // cdebug_in << "GraphExecutor::OutNode::IsReady " << NodeName << endl;
1662 GraphExecutor::InNode *anInNode = (GraphExecutor::InNode *) Graph()->GetGraphNode( NodeName )->GetInNode() ;
1664 aret = anInNode->IsReady() ;
1666 // cdebug_out << "GraphExecutor::OutNode::IsReady" << endl ;
1670 bool GraphExecutor::OutNode::IsRunning( const char * NodeName ) {
1672 // cdebug_in << "GraphExecutor::OutNode::IsRunning " << NodeName << endl;
1673 GraphExecutor::InNode *anInNode = (GraphExecutor::InNode *) Graph()->GetGraphNode( NodeName )->GetInNode() ;
1675 aret = anInNode->IsRunning() ;
1677 // cdebug_out << "GraphExecutor::OutNode::IsRunning" << endl ;
1681 bool GraphExecutor::OutNode::IsDone( const char * NodeName ) {
1683 // cdebug_in << "GraphExecutor::OutNode::IsDone " << NodeName << endl;
1684 GraphExecutor::InNode *anInNode = (GraphExecutor::InNode *) Graph()->GetGraphNode( NodeName )->GetInNode() ;
1686 aret = anInNode->IsDone() ;
1688 // cdebug_out << "GraphExecutor::OutNode::IsDone" << endl ;
1692 bool GraphExecutor::OutNode::IsSuspended( const char * NodeName ) {
1694 // cdebug_in << "GraphExecutor::OutNode::IsSuspended " << NodeName << endl;
1695 GraphExecutor::InNode *anInNode = (GraphExecutor::InNode *) Graph()->GetGraphNode( NodeName )->GetInNode() ;
1697 aret = anInNode->IsSuspended() ;
1699 // cdebug_out << "GraphExecutor::OutNode::IsSuspended" << endl ;
1703 bool GraphExecutor::OutNode::IsDone( const char * NodeName ,
1704 const char * ServiceParameterName ) {
1705 // cdebug_in << "GraphExecutor::OutNode::IsDone " << NodeName << " "
1706 // << ServiceParameterName<< endl;
1707 bool aret = Graph()->PortDone( NodeName , ServiceParameterName ) ;
1708 // cdebug_out << "GraphExecutor::OutNode::IsDone" << endl ;
1712 bool GraphExecutor::OutNode::ContainerKill() {
1713 bool RetVal = true ;
1714 cdebug_in << "GraphExecutor::OutNode::ContainerKill" << endl;
1715 _ControlState = SUPERV::ToSuspendState ;
1717 for ( i = 0 ; i < Graph()->GraphNodesSize() ; i++ ) {
1718 GraphExecutor::InNode * aNode = (GraphExecutor::InNode * ) Graph()->GraphNodes( i )->GetInNode() ;
1719 bool sts = aNode->ContainerKill() ;
1720 if ( sts && aNode->IsKilled() ) {
1721 cdebug << aNode->Name() << " killed" << endl ;
1723 else if ( aNode->IsWaiting() || aNode->IsDone() ) {
1724 cdebug << aNode->Name() << " not killed : "
1725 << theAutomaton->StateName( aNode->State() ) << endl ;
1728 cdebug << aNode->Name() << " cannot be killed : "
1729 << theAutomaton->StateName( aNode->State() ) << endl ;
1733 if ( !RetVal || Threads() != 0 ) {
1734 for ( i = 0 ; i < Graph()->GraphNodesSize() ; i++ ) {
1735 GraphExecutor::InNode * aNode = (GraphExecutor::InNode * ) Graph()->GraphNodes( i )->GetInNode() ;
1736 if ( !aNode->IsKilled() && !aNode->IsWaiting() && !aNode->IsDone() ) {
1737 aNode->KilledAction() ;
1742 State( GraphExecutor::KilledState ) ;
1743 cdebug_out << "GraphExecutor::OutNode::ContainerKill" << endl ;
1747 bool GraphExecutor::OutNode::Suspend() {
1749 cdebug_in << "GraphExecutor::OutNode::Suspend" << endl;
1750 // _ControlState = SUPERV::ToSuspendState ;
1752 for ( i = 0 ; i < Graph()->GraphNodesSize() ; i++ ) {
1753 GraphExecutor::InNode * aNode = (GraphExecutor::InNode * ) Graph()->GraphNodes( i )->GetInNode() ;
1754 bool sts = aNode->Suspend() ;
1755 if ( sts && aNode->IsSuspended() ) {
1757 cdebug << aNode->Name() << " Suspended" << endl ;
1759 else if ( aNode->IsWaiting() || aNode->IsReady() ) {
1761 cdebug << aNode->Name() << " will be Suspended" << endl ;
1763 else if ( aNode->IsDone() ) {
1764 cdebug << aNode->Name() << " not Suspended : "
1765 << theAutomaton->StateName( aNode->State() ) << endl ;
1769 cdebug << aNode->Name() << " cannot be Suspended : "
1770 << theAutomaton->StateName( aNode->State() ) << endl ;
1774 State( GraphExecutor::SuspendedState ) ;
1775 MESSAGE("================================================================================") ;
1776 MESSAGE( Graph()->Name() << " IS SUSPENDED" ) ;
1777 MESSAGE("================================================================================") ;
1780 MESSAGE("================================================================================") ;
1781 MESSAGE( Graph()->Name() << " IS NOT SUSPENDED" ) ;
1782 MESSAGE("================================================================================") ;
1784 for ( i = 0 ; i < Graph()->GraphNodesSize() ; i++ ) {
1785 GraphExecutor::InNode * aNode = (GraphExecutor::InNode * ) Graph()->GraphNodes( i )->GetInNode() ;
1786 MESSAGE(aNode->Name() << " " << theAutomaton->StateName( aNode->State() ) ) ;
1787 cdebug << aNode->Name() << " " << theAutomaton->StateName( aNode->State() ) << endl ;
1789 cdebug_out << "GraphExecutor::OutNode::Suspend " << theAutomaton->StateName( State() )
1790 << " EventQSize " << EventQSize() << endl ;
1794 bool GraphExecutor::OutNode::Resume() {
1796 cdebug_in << "GraphExecutor::OutNode::Resume "
1797 << theAutomaton->StateName( State() ) << endl;
1798 if ( IsSuspended() ) {
1799 State( GraphExecutor::ExecutingState ) ;
1801 for ( i = 0 ; i < Graph()->GraphNodesSize() ; i++ ) {
1802 GraphExecutor::InNode * aNode = (GraphExecutor::InNode * ) Graph()->GraphNodes( i )->GetInNode() ;
1803 aNode->ControlState( SUPERV::VoidState ) ;
1804 if ( aNode->IsSuspended() ) {
1805 cdebug << aNode->Name() << "->Resume " << theAutomaton->StateName( aNode->State() )
1807 if ( aNode->Resume() ) {
1808 cdebug << aNode->Name() << " Resumed " << theAutomaton->StateName( aNode->State() )
1813 cdebug << aNode->Name() << " Resume failed"
1814 << theAutomaton->StateName( aNode->State() ) << endl ;
1818 cdebug << aNode->Name() << " " << theAutomaton->StateName( aNode->State() )
1824 cdebug << Graph()->Name() << " not suspended " << theAutomaton->StateName( State() ) << endl ;
1827 MESSAGE("================================================================================") ;
1828 MESSAGE( Graph()->Name() << " IS RESUMED" ) ;
1829 MESSAGE("================================================================================") ;
1832 MESSAGE("================================================================================") ;
1833 MESSAGE( Graph()->Name() << " IS NOT RESUMED" ) ;
1834 MESSAGE("================================================================================") ;
1837 for ( i = 0 ; i < Graph()->GraphNodesSize() ; i++ ) {
1838 GraphExecutor::InNode * aNode = (GraphExecutor::InNode * ) Graph()->GraphNodes( i )->GetInNode() ;
1839 MESSAGE(aNode->Name() << " " << theAutomaton->StateName( aNode->State() ) ) ;
1840 cdebug << aNode->Name() << " " << theAutomaton->StateName( aNode->State() ) << endl ;
1842 cdebug_out << "GraphExecutor::OutNode::Resume" << theAutomaton->StateName( State() ) << " " << RetVal
1843 << " EventQSize " << EventQSize() << endl ;
1847 bool GraphExecutor::OutNode::Kill() {
1848 bool RetVal = false ;
1849 cdebug_in << "GraphExecutor::OutNode::Kill"
1850 << " EventQSize " << EventQSize() << endl;
1851 _ControlState = SUPERV::ToSuspendState ;
1853 for ( i = 0 ; i < Graph()->GraphNodesSize() ; i++ ) {
1854 GraphExecutor::InNode * aNode = (GraphExecutor::InNode * ) Graph()->GraphNodes( i )->GetInNode() ;
1855 bool sts = aNode->Kill() ;
1856 if ( sts && Threads() != 0 ) {
1857 if ( !aNode->IsKilled() ) {
1858 cdebug << aNode->Name() << " not killed : "
1859 << theAutomaton->StateName( aNode->State() ) << " " << aNode->Name() << "->"
1860 << "KilledAction()" << endl ;
1861 MESSAGE( aNode->Name() << " not killed : KilledAction()" ) ;
1862 aNode->KilledAction() ;
1864 if ( aNode->IsKilled() ) {
1865 cdebug << aNode->Name() << " killed" << endl ;
1869 else if ( aNode->IsWaiting() || aNode->IsDone() ) {
1870 cdebug << aNode->Name() << " not killed : "
1871 << theAutomaton->StateName( aNode->State() ) << endl ;
1874 cdebug << aNode->Name() << " cannot be killed : "
1875 << theAutomaton->StateName( aNode->State() ) << endl ;
1879 State( GraphExecutor::KilledState ) ;
1880 MESSAGE("================================================================================") ;
1881 MESSAGE( Graph()->Name() << " IS KILLED" << theAutomaton->StateName( AutomatonState() ) << " EventQSize "
1883 MESSAGE("================================================================================") ;
1886 MESSAGE("================================================================================") ;
1887 MESSAGE( Graph()->Name() << " IS NOT KILLED" ) ;
1888 MESSAGE("================================================================================") ;
1890 for ( i = 0 ; i < Graph()->GraphNodesSize() ; i++ ) {
1891 GraphExecutor::InNode * aNode = (GraphExecutor::InNode * ) Graph()->GraphNodes( i )->GetInNode() ;
1892 MESSAGE(aNode->Name() << " " << theAutomaton->StateName( aNode->State() ) ) ;
1893 cdebug << aNode->Name() << " " << theAutomaton->StateName( aNode->State() ) << endl ;
1895 cdebug_out << "GraphExecutor::OutNode::Kill " << RetVal
1896 << " Threads " << _Threads << " SuspendedThreads " << _SuspendedThreads
1897 << " EventQSize " << EventQSize() << endl ;
1899 // remove "extra" events from the event queue
1902 // asv : 25.10.04 : calling Editing() to indicate stop of execution
1903 Graph()->GraphEditor()->Editing();
1908 bool GraphExecutor::OutNode::Stop() {
1909 bool RetVal = false ;
1910 cdebug_in << "GraphExecutor::OutNode::Stop" << endl;
1912 cdebug_out << "GraphExecutor::OutNode::Stop" << endl ;
1914 MESSAGE("================================================================================") ;
1915 MESSAGE( Graph()->Name() << " IS STOPPED" ) ;
1916 MESSAGE("================================================================================") ;
1921 bool GraphExecutor::OutNode::ReadyWait() {
1922 cdebug_in << "GraphExecutor::OutNode::ReadyWait" << endl;
1924 if ( pthread_mutex_lock( &_MutexWait ) ) {
1925 perror("pthread_mutex_lock _ReadyWait") ;
1931 pthread_cond_wait( &_EventWait , &_MutexWait );
1934 if ( pthread_mutex_unlock( &_MutexWait ) ) {
1935 perror("pthread_mutex_lock _ReadyWait") ;
1938 cdebug_out << "GraphExecutor::OutNode::ReadyWait" << endl ;
1942 bool GraphExecutor::OutNode::RunningWait() {
1943 cdebug_in << "GraphExecutor::OutNode::RunningWait" << endl;
1945 if ( pthread_mutex_lock( &_MutexWait ) ) {
1946 perror("pthread_mutex_lock _RunningWait") ;
1949 aret = IsRunning() ;
1951 cdebug << "RunningWait pthread_cond_wait _EventWait" << endl;
1952 pthread_cond_wait( &_EventWait , &_MutexWait );
1953 aret = IsRunning() ;
1954 cdebug << "RunningWait pthread_cond_waited _EventWait " << aret << endl;
1956 if ( pthread_mutex_unlock( &_MutexWait ) ) {
1957 perror("pthread_mutex_lock _RunningWait") ;
1960 cdebug_out << "GraphExecutor::OutNode::RunningWait " << aret << endl ;
1964 bool GraphExecutor::OutNode::DoneWait() {
1965 cdebug_in << pthread_self() << " GraphExecutor::DoneWait " << this << " " << Graph()->Name() << endl;
1967 if ( pthread_mutex_lock( &_MutexWait ) ) {
1968 perror("pthread_mutex_lock _DoneWait") ;
1972 while ( !aret && !IsSuspended() && IsRunning() ) {
1973 cdebug << pthread_self() << " GraphExecutor::DoneWait " << this << " " << Graph()->Name()
1974 << " DoneWait pthread_cond_wait _EventWait " << &_EventWait << endl;
1975 pthread_cond_wait( &_EventWait , &_MutexWait );
1977 cdebug << pthread_self() << " GraphExecutor::DoneWait " << this << " " << Graph()->Name()
1978 << " DoneWait pthread_cond_waited _EventWaited " << &_EventWait << " : "<< aret << endl;
1980 if ( pthread_mutex_unlock( &_MutexWait ) ) {
1981 perror("pthread_mutex_lock _DoneWait") ;
1984 cdebug_out << pthread_self() << " GraphExecutor::DoneWait " << this << " " << Graph()->Name()
1985 << " " << State() << " : " << aret << endl ;
1989 bool GraphExecutor::OutNode::SuspendedWait() {
1990 cdebug_in << "GraphExecutor::OutNode::SuspendedWait" << endl;
1992 if ( pthread_mutex_lock( &_MutexWait ) ) {
1993 perror("pthread_mutex_lock _SuspendedWait") ;
1996 aret = IsSuspended() ;
1997 while ( !aret && !IsDone() ) {
1998 pthread_cond_wait( &_EventWait , &_MutexWait );
1999 aret = IsSuspended() ;
2001 if ( pthread_mutex_unlock( &_MutexWait ) ) {
2002 perror("pthread_mutex_lock _SuspendedWait") ;
2005 cdebug_out << "GraphExecutor::OutNode::SuspendedWait" << endl ;
2009 bool GraphExecutor::OutNode::ReadyWait( const char * NodeName ) {
2011 cdebug_in << "GraphExecutor::OutNode::ReadyWait " << NodeName << endl;
2012 GraphExecutor::InNode *anInNode = (GraphExecutor::InNode *) Graph()->GetGraphNode( NodeName )->GetInNode() ;
2014 aret = anInNode->ReadyWait() ;
2016 cdebug_out << "GraphExecutor::OutNode::ReadyWait" << endl ;
2020 bool GraphExecutor::OutNode::RunningWait( const char * NodeName ) {
2022 cdebug_in << "GraphExecutor::OutNode::RunningWait " << NodeName << endl;
2023 GraphExecutor::InNode *anInNode = (GraphExecutor::InNode *) Graph()->GetGraphNode( NodeName )->GetInNode() ;
2025 aret = anInNode->RunningWait() ;
2027 cdebug_out << "GraphExecutor::OutNode::RunningWait" << endl ;
2031 bool GraphExecutor::OutNode::DoneWait( const char * NodeName ) {
2033 cdebug_in << "GraphExecutor::OutNode::DoneWait " << NodeName << endl;
2034 GraphExecutor::InNode *anInNode = (GraphExecutor::InNode *) Graph()->GetGraphNode( NodeName )->GetInNode() ;
2036 aret = anInNode->DoneWait() ;
2038 cdebug_out << "GraphExecutor::OutNode::DoneWait" << endl ;
2042 bool GraphExecutor::OutNode::SuspendedWait( const char * NodeName ) {
2044 cdebug_in << "GraphExecutor::OutNode::SuspendedWait " << NodeName << endl;
2045 GraphExecutor::InNode *anInNode = (GraphExecutor::InNode *) Graph()->GetGraphNode( NodeName )->GetInNode() ;
2047 aret = anInNode->SuspendedWait() ;
2049 cdebug_out << "GraphExecutor::OutNode::SuspendedWait" << endl ;
2053 long GraphExecutor::OutNode::LastLevelDone() {
2056 for ( i = 0 ; i <= Graph()->LevelMax() ; i++ ) {
2057 for ( j = 0 ; j <= Graph()->NodesNumber( i ) ; j++ ) {
2058 GraphBase::ComputingNode * aNode = Graph()->SortedNodes( i , j ) ;
2059 if ( !IsDone( aNode->Name() ) ) {
2063 if ( j != Graph()->NodesNumber( i ) + 1 )
2071 const CORBA::Any *GraphExecutor::OutNode::GetInData( const char * NodeName ,
2072 const char * ServiceParameterName ) {
2073 // cdebug_in << "GraphExecutor::OutNode::GetInData " << NodeName << " "
2074 // << ServiceParameterName << endl ;
2075 const CORBA::Any * retdata = Graph()->PortInData( NodeName , ServiceParameterName ) ;
2076 // cdebug_out << "GraphExecutor::OutNode::GetInData" << endl ;
2080 const CORBA::Any *GraphExecutor::OutNode::GetOutData( const char * NodeName ,
2081 const char * ServiceParameterName ) {
2082 // cdebug_in << "GraphExecutor::OutNode::GetOutData " << NodeName << " "
2083 // << ServiceParameterName << endl ;
2084 const CORBA::Any * retdata = Graph()->PortOutData( NodeName , ServiceParameterName ) ;
2085 // cdebug_out << "GraphExecutor::OutNode::GetOutData" << endl ;
2089 const long GraphExecutor::OutNode::CpuUsed() {
2090 return Graph()->CpuUsed() ;
2093 const long GraphExecutor::OutNode::CpuUsed( const char * aNodeName ) {
2094 GraphBase::ComputingNode * aNode = Graph()->GetChangeGraphNode( aNodeName ) ;
2096 GraphExecutor::InNode * anInNode = (GraphExecutor::InNode * ) aNode->GetInNode() ;
2098 return anInNode->CpuUsed() ;
2104 // remove equal sets "Node-Event-State" from _EventNodes/_Events/_States queues
2105 void GraphExecutor::OutNode::siftEvents() {
2106 list<char*>::reverse_iterator itNodes = _EventNodes.rbegin();
2107 list<GraphExecutor::NodeEvent>::reverse_iterator itEvents = _Events.rbegin();
2108 list<GraphExecutor::AutomatonState>::reverse_iterator itStates = _States.rbegin();
2109 list<char*> _NewEventNodes;
2110 list<GraphExecutor::NodeEvent> _NewEvents;
2111 list<GraphExecutor::AutomatonState> _NewStates;
2112 for ( ; itNodes != _EventNodes.rend() ; ++itNodes, ++itEvents, ++itStates) {
2113 //cout << "----- aNodeName ==> " << *itNodes;
2114 list<char*>::reverse_iterator itNewNodes = _NewEventNodes.rbegin();
2116 for ( ; itNewNodes != _NewEventNodes.rend() ; ++itNewNodes ) {
2117 if ( !strcmp( *itNewNodes, *itNodes ) ) {
2127 _NewEventNodes.push_back( *itNodes );
2128 _NewEvents.push_back( *itEvents );
2129 _NewStates.push_back( *itStates );
2133 _EventNodes = _NewEventNodes;
2134 _Events = _NewEvents;
2135 _States = _NewStates;