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 // asv : 20.01.05 : changes involved with switching to old (HEAD) KERNEL
36 //extern Engines_Container_i * _TheContainer ;
38 extern GraphExecutor::FiniteStateMachine * theAutomaton ;
40 // static const char *ComponentName = "SalomeSuperVisionComponent" ;
43 extern char ** _ArgV ;
45 GraphExecutor::OutNode::OutNode() {
47 // asv : 20.01.05 : changes involved with switching to old (HEAD) KERNEL
48 //_SuperVisionContainer = _TheContainer ;
49 //_MainThreadId = SuperVisionContainer()->MainThreadId() ;
54 _ControlState = SUPERV::VoidState ;
55 _State = GraphExecutor::UnKnownState ;
56 _PyInitialized = false ;
57 pthread_mutex_init( &_MutexWait , NULL ) ;
58 pthread_mutex_init( &_PyMutexWait , NULL ) ;
59 if ( pthread_cond_init( &_EventWait , NULL ) ) {
60 perror("pthread_cond_init( &_EventWait , NULL )") ;
63 if ( pthread_cond_init( &_JoinWait , NULL ) ) {
64 perror("pthread_cond_init( &_JoinWait , NULL )") ;
69 GraphExecutor::OutNode::OutNode( CORBA::ORB_ptr ORB,
70 SALOME_NamingService* ptrNamingService ,
71 const char *DataFlowName ,
72 const char * DebugFileName ,
73 const SUPERV::KindOfNode aKindOfNode ) {
74 // Graph( ORB , ptrNamingService , DataFlowName , DebugFileName ) {
75 Set_prof_debug( ORB , DebugFileName ) ;
76 cdebug_in << "GraphExecutor::OutNode::OutNode(" << DataFlowName << " , " << aKindOfNode << ")" << endl;
77 if ( aKindOfNode == SUPERV::DataFlowGraph ) {
79 // _Graph = new GraphBase::Graph( ORB , ptrNamingService , DataFlowName , DebugFileName ) ;
80 _Graph = new GraphBase::Graph( ORB , ptrNamingService , DataFlowName , aKindOfNode ,
81 _prof_debug , _fdebug ) ;
83 else if ( aKindOfNode == SUPERV::DataStreamGraph ) {
84 // _StreamGraph = new GraphBase::StreamGraph( ORB , ptrNamingService , DataFlowName , DebugFileName ) ;;
85 _StreamGraph = new GraphBase::StreamGraph( ORB , ptrNamingService , DataFlowName , aKindOfNode ,
86 _prof_debug , _fdebug ) ;
87 _Graph = _StreamGraph ;
89 // asv : 20.01.05 : changes involved with switching to old (HEAD) KERNEL
90 //_SuperVisionContainer = _TheContainer ;
91 //_MainThreadId = SuperVisionContainer()->MainThreadId() ;
96 _ControlState = SUPERV::VoidState ;
97 _State = GraphExecutor::UnKnownState ;
98 _PyInitialized = false ;
99 _Orb = CORBA::ORB::_duplicate( ORB ) ;
100 pthread_mutex_init( &_MutexWait , NULL ) ;
101 pthread_mutex_init( &_PyMutexWait , NULL ) ;
102 if ( pthread_cond_init( &_EventWait , NULL ) ) {
103 perror("pthread_cond_init( &_EventWait , NULL )") ;
106 if ( pthread_cond_init( &_JoinWait , NULL ) ) {
107 perror("pthread_cond_init( &_JoinWait , NULL )") ;
110 cdebug_out << "GraphExecutor::OutNode::OutNode" << endl;
113 GraphExecutor::OutNode::OutNode( CORBA::ORB_ptr ORB,
114 SALOME_NamingService* ptrNamingService ,
115 const SALOME_ModuleCatalog::Service& DataFlowService ,
116 const char *DataFlowComponentName ,
117 const char *DataFlowInterfaceName ,
118 const char *DataFlowName ,
119 const SUPERV::KindOfNode DataFlowkind ,
120 const SUPERV::SDate DataFlowFirstCreation ,
121 const SUPERV::SDate DataFlowLastModification ,
122 const char * DataFlowEditorRelease ,
123 const char * DataFlowAuthor ,
124 const char * DataFlowComputer ,
125 const char * DataFlowComment ,
126 const char * DebugFileName ) {
127 // Graph( ORB , ptrNamingService , DataFlowService , DataFlowComponentName ,
128 // DataFlowInterfaceName , DataFlowName , DataFlowkind ,
129 // DataFlowFirstCreation , DataFlowLastModification ,
130 // DataFlowEditorRelease , DataFlowAuthor ,
131 // DataFlowComputer , DataFlowComment , DebugFileName ) {
132 Set_prof_debug( ORB , DebugFileName ) ;
134 cdebug_in << "GraphExecutor::OutNode::OutNode(" << DataFlowName << " , " << DataFlowkind << ")" << endl;
135 if ( DataFlowkind == SUPERV::DataFlowGraph ) {
136 _StreamGraph = NULL ;
137 _Graph = new GraphBase::Graph( ORB , ptrNamingService , DataFlowService , DataFlowComponentName ,
138 DataFlowInterfaceName , DataFlowName , DataFlowkind ,
139 DataFlowFirstCreation , DataFlowLastModification ,
140 DataFlowEditorRelease , DataFlowAuthor ,
141 DataFlowComputer , DataFlowComment ,
142 _prof_debug , _fdebug ) ;
143 // DataFlowComputer , DataFlowComment , DebugFileName ) ;
145 else if ( DataFlowkind == SUPERV::DataStreamGraph ) {
146 _StreamGraph = new GraphBase::StreamGraph( ORB , ptrNamingService , DataFlowService , DataFlowComponentName ,
147 DataFlowInterfaceName , DataFlowName , DataFlowkind ,
148 DataFlowFirstCreation , DataFlowLastModification ,
149 DataFlowEditorRelease , DataFlowAuthor ,
150 DataFlowComputer , DataFlowComment ,
151 _prof_debug , _fdebug ) ;
152 _Graph = _StreamGraph ;
154 // asv : 20.01.05 : changes involved with switching to old (HEAD) KERNEL
155 //_SuperVisionContainer = _TheContainer ;
156 //_MainThreadId = SuperVisionContainer()->MainThreadId() ;
158 _Executable = false ;
161 _ControlState = SUPERV::VoidState ;
162 _State = GraphExecutor::UnKnownState ;
163 _PyInitialized = false ;
164 _Orb = CORBA::ORB::_duplicate( ORB ) ;
165 pthread_mutex_init( &_MutexWait , NULL ) ;
166 pthread_mutex_init( &_PyMutexWait , NULL ) ;
167 if ( pthread_cond_init( &_EventWait , NULL ) ) {
168 perror("pthread_cond_init( &_EventWait , NULL )") ;
171 if ( pthread_cond_init( &_JoinWait , NULL ) ) {
172 perror("pthread_cond_init( &_JoinWait , NULL )") ;
177 GraphExecutor::OutNode::~OutNode() {
180 void GraphExecutor::OutNode::Set_prof_debug( CORBA::ORB_ptr ORB ,
181 const char * DebugFileName ) {
182 _Graph_prof_debug = 0 ;
183 if ( DebugFileName ) {
184 _fdebug = new ofstream( DebugFileName );
185 SetDebug( ORB , &_Graph_prof_debug , _fdebug ) ;
186 MESSAGE( endl << "Trace redirected to file " << DebugFileName << endl)
190 bool GraphExecutor::OutNode::LoadDataFlow(const GraphBase::SGraph * aDataFlow ) {
191 bool RetVal = false ;
192 cdebug_in << "GraphExecutor::OutNode::LoadDataFlow " << (*aDataFlow).Info.theName << endl ;
193 RetVal = LoadInfo( (*aDataFlow).Info ) ;
194 if ( Graph()->ServiceName() != NULL ) {
195 // MESSAGE( "GraphExecutor::OutNode::LoadDataFlow" );
197 RetVal = LoadNodes( (*aDataFlow).Nodes ) ;
199 RetVal = LoadLinks( (*aDataFlow).Links ) ;
202 RetVal = LoadDatas( (*aDataFlow).Datas ) ;
205 cdebug << "GraphExecutor::OutNode::LoadDataFlow LoadDatas Error."
210 cdebug << "GraphExecutor::OutNode::LoadDataFlow LoadLinks Error."
215 cdebug << "GraphExecutor::OutNode::LoadDataFlow LoadNodes Error."
220 cdebug << "GraphExecutor::OutNode::LoadDataFlow LoadInfo Error."
225 cdebug << "GraphExecutor::OutNode::LoadDataFlow ServiceName Error." << endl ;
227 cdebug_out << "GraphExecutor::OutNode::LoadDataFlow " << Graph()->Name() << " RetVal "
233 bool GraphExecutor::OutNode::LoadXml( const char* myFileName ) {
234 bool RetVal = false ;
235 GraphBase::ListOfSGraphs aListOfDataFlows ;
236 if ( Graph()->LoadXml( _Orb , myFileName , aListOfDataFlows ) ) {
237 RetVal = LoadDataFlow( aListOfDataFlows ) ;
238 // if ( aConstructor && RetVal )
239 // RetVal = Name( aDataFlow.Info.theName.c_str() ) ;
245 bool GraphExecutor::OutNode::LoadInfo(const GraphBase::SNode &aDataFlowInfo ) {
246 cdebug << "GraphExecutor::OutNode::LoadInfo _StreamGraph " << _StreamGraph << endl ;
247 // ComponentName( aDataFlowInfo.theComponentName.c_str() ) ;
248 Graph()->Name( aDataFlowInfo.theName.c_str() ) ;
249 Graph()->Kind( aDataFlowInfo.theKind ) ;
250 if ( Graph()->IsDataStreamNode() && aDataFlowInfo.theKind == SUPERV::DataStreamGraph ) {
251 StreamGraph()->SetStreamParams( aDataFlowInfo.theTimeout , aDataFlowInfo.theDataStreamTrace , aDataFlowInfo.theDeltaTime ) ;
253 Graph()->DataService( _Orb , aDataFlowInfo.theService , _prof_debug , _fdebug ) ;
254 Graph()->FirstCreation( aDataFlowInfo.theFirstCreation ) ;
255 Graph()->LastModification( aDataFlowInfo.theLastModification ) ;
256 Graph()->EditorRelease( aDataFlowInfo.theEditorRelease.c_str() ) ;
257 Graph()->Author( aDataFlowInfo.theAuthor.c_str() ) ;
258 // Graph()->Computer( aDataFlowInfo.theContainer.c_str() ) ;
259 Graph()->Comment( aDataFlowInfo.theComment.c_str() ) ;
260 // Not in OutNode/DataFlow but in InNode/DataFlow_in_an_other_DataFlow
261 // Graph()->Coordinates( aDataFlowInfo.theX , aDataFlowInfo.theY ) ;
265 bool GraphExecutor::OutNode::LoadNodes(const GraphBase::ListOfSNodes &aListOfNodes ) {
267 GraphExecutor::InNode * anInNode ;
268 cdebug << "GraphExecutor::OutNode::LoadNodes" << endl ;
270 for ( i = 0 ; i < (int ) aListOfNodes.size() ; i++ ) {
271 GraphBase::SNode aNode = aListOfNodes[ i ] ;
272 anInNode = AddNode( aNode.theService ,
273 aNode.theListOfFuncName ,
274 aNode.theListOfPythonFunctions ,
275 aNode.theComponentName.c_str() ,
276 aNode.theInterfaceName.c_str() , aNode.theName.c_str() ,
278 aNode.theFirstCreation , aNode.theLastModification ,
279 aNode.theEditorRelease.c_str() ,
280 aNode.theAuthor.c_str() , aNode.theContainer.c_str() ,
281 aNode.theComment.c_str() ,
282 aNode.theCoords.theX , aNode.theCoords.theY ) ;
287 if ( anInNode->IsOneOfInLineNodes() || anInNode->IsMacroNode() ) {
288 anInNode->GraphExecutor::InNode::InLineNode()->DefPortsOfNode(
289 _Orb , aNode.theService , anInNode->NamePtr() ,
291 _prof_debug , _fdebug ) ;
293 // GraphBase::ComputingNode * theNode = Graph()->GetChangeGraphNode( aNode.theName.c_str() ) ;
296 for ( j = 0 ; j < aNode.theListOfInDataStreams.size() ; j++ ) {
297 GraphBase::InPort * anInPort ;
298 anInPort = anInNode->ComputingNode()->AddInDataStreamPort( aNode.theListOfInDataStreams[ j ].theDataStreamParameter.Parametername ,
299 aNode.theListOfInDataStreams[ j ].theDataStreamParameter.Parametertype ,
300 aNode.theListOfInDataStreams[ j ].theDataStreamParameter.Parameterdependency ,
301 SUPERV::DataStreamParameter ) ;
302 ((GraphBase::InDataStreamPort * ) anInPort)->SetParams( aNode.theListOfInDataStreams[ j ].theKindOfSchema ,
303 aNode.theListOfInDataStreams[ j ].theKindOfInterpolation ,
304 aNode.theListOfInDataStreams[ j ].theKindOfExtrapolation ) ;
306 for ( j = 0 ; j < aNode.theListOfOutDataStreams.size() ; j++ ) {
307 GraphBase::OutPort * anOutPort ;
308 anOutPort = anInNode->ComputingNode()->AddOutDataStreamPort( aNode.theListOfOutDataStreams[ j ].theDataStreamParameter.Parametername ,
309 aNode.theListOfOutDataStreams[ j ].theDataStreamParameter.Parametertype ,
310 aNode.theListOfOutDataStreams[ j ].theDataStreamParameter.Parameterdependency ,
311 SUPERV::DataStreamParameter ) ;
312 ((GraphBase::OutDataStreamPort * ) anOutPort)->NumberOfValues( aNode.theListOfOutDataStreams[ j ].theNumberOfValues ) ;
316 // theNode->DataStreamInPortsNumber( aNode.theDataStreamInArgsNumber ) ;
317 // theNode->DataStreamOutPortsNumber( aNode.theDataStreamOutArgsNumber ) ;
318 // cdebug << "GraphExecutor::OutNode::LoadNodes " << anInNode->Name()
319 // << " InPortsSize " << theNode->GetNodeInPortsSize()
320 // << " OutPortsSize " << theNode->GetNodeOutPortsSize()
321 // << " DataStreamInPortsNumber " << aNode.theDataStreamInArgsNumber
322 // << " DataStreamOutPortsNumber " << aNode.theDataStreamOutArgsNumber
325 // if ( aNode.theDataStreamInArgsNumber ) { // -1 because of Gates
326 // for ( j = theNode->GetNodeInPortsSize() - aNode.theDataStreamInArgsNumber - 1 ; j < theNode->GetNodeInPortsSize() - 1 ; j++ ) {
327 // cdebug << "GraphExecutor::OutNode::LoadNodes " << anInNode->Name()
328 // << " InPort " << theNode->GetChangeNodeInPort( j )->PortName()
329 // << " Kind( DataStreamParameter)" << endl ;
330 // theNode->GetChangeNodeInPort( j )->Kind( SUPERV::DataStreamParameter ) ;
333 // if ( aNode.theDataStreamOutArgsNumber ) {
334 // int withgate = 1 ;
335 // if ( theNode->IsLoopNode() || theNode->IsEndLoopNode() ) {
338 // for ( j = theNode->GetNodeOutPortsSize() - aNode.theDataStreamOutArgsNumber - withgate ; j < theNode->GetNodeOutPortsSize() - withgate ; j++ ) {
339 // cdebug << "GraphExecutor::OutNode::LoadNodes " << anInNode->Name()
340 // << " OutPort " << theNode->GetChangeNodeOutPort( j )->PortName()
341 // << " Kind( DataStreamParameter)" << endl ;
342 // theNode->GetChangeNodeOutPort( j )->Kind( SUPERV::DataStreamParameter ) ;
346 for ( i = 0 ; i < (int ) aListOfNodes.size() ; i++ ) {
347 GraphBase::SNode aNode = aListOfNodes[ i ] ;
348 anInNode = (GraphExecutor::InNode * ) Graph()->GetChangeGraphNode( aNode.theName.c_str() )->GetInNode() ;
349 cdebug << "GraphExecutor::OutNode::LoadNodes " << anInNode->Name() << " IsOneOfGOTONodes "
350 << anInNode->IsOneOfGOTONodes() << " " << aNode.theCoupledNode.c_str() << endl ;
351 if ( anInNode->IsOneOfGOTONodes() && strlen( aNode.theCoupledNode.c_str() ) ) {
352 GraphBase::GOTONode * aCoupledNode ;
353 aCoupledNode = (GraphBase::GOTONode * ) Graph()->GetGraphNode( aNode.theName.c_str() ) ;
354 GraphBase::GOTONode * aCoupledCoupledNode ;
355 aCoupledCoupledNode = (GraphBase::GOTONode * ) Graph()->GetChangeGraphNode( aNode.theCoupledNode.c_str() ) ;
356 if ( aCoupledCoupledNode != NULL ) {
357 aCoupledNode->CoupledNode( aCoupledCoupledNode ) ;
360 aCoupledNode->CoupledNodeName( aNode.theCoupledNode.c_str() ) ;
367 bool GraphExecutor::OutNode::LoadLinks(const GraphBase::ListOfSLinks &aListOfLinks ) {
369 cdebug << "GraphExecutor::OutNode::LoadLinks " << aListOfLinks.size()
372 for ( i = 0 ; i < (int ) aListOfLinks.size() ; i++ ) {
373 GraphBase::SLink aLink = aListOfLinks[ i ] ;
374 RetVal = Graph()->AddLink( aLink.FromNodeName.c_str() ,
375 aLink.FromServiceParameterName.c_str() ,
376 aLink.ToNodeName.c_str() ,
377 aLink.ToServiceParameterName.c_str() ) ;
378 // , aLink.aLinkValue ) ;
385 bool GraphExecutor::OutNode::LoadDatas(const GraphBase::ListOfSLinks &aListOfDatas ) {
387 cdebug << "GraphExecutor::OutNode::LoadDatas " << aListOfDatas.size()
390 for ( i = 0 ; i < (int ) aListOfDatas.size() ; i++ ) {
391 GraphBase::SLink aLink = aListOfDatas[ i ] ;
392 if ( !strcmp( aLink.FromNodeName.c_str() , Graph()->Name() ) )
393 RetVal = Graph()->AddInputData( aLink.ToNodeName.c_str() ,
394 aLink.ToServiceParameterName.c_str() ,
396 // else if ( !strcmp( aLink.ToNodeName.c_str() , Graph()->Name() ) ) {
397 // RetVal = Graph()->AddOutputData( aLink.FromNodeName.c_str() ,
398 // aLink.FromServiceParameterName.c_str() ) ;
399 // Graph()->AddLink( aLink.FromNodeName.c_str() , (GraphBase::ComputingNode *) this ) ;
402 cdebug << "GraphExecutor::OutNode::LoadDatas Error " << aLink.FromNodeName
403 << " and " << aLink.ToNodeName << " differents from " << Graph()->Name()
413 GraphExecutor::InNode *GraphExecutor::OutNode::AddNode(
414 const SALOME_ModuleCatalog::Service& NodeService ,
415 GraphBase::ListOfFuncName aFuncName ,
416 GraphBase::ListOfPythonFunctions aPythonFunction ,
417 const char * NodeComponentName ,
418 const char * NodeInterfaceName ,
419 const char * NodeName ,
420 const SUPERV::KindOfNode NodeKindOfNode ,
421 const SUPERV::SDate NodeFirstCreation ,
422 const SUPERV::SDate NodeLastModification ,
423 const char * NodeEditorRelease ,
424 const char * NodeAuthor ,
425 const char * NodeComputer ,
426 const char * NodeComment ,
429 cdebug_in << "GraphExecutor::OutNode::AddNode(" << NodeComponentName << " , "
430 << NodeName << ")" << endl;
431 GraphExecutor::InNode *Nd = NULL ;
432 Nd = new GraphExecutor::InNode( _Orb, Graph()->NamingService() , NodeService ,
433 NodeComponentName , NodeInterfaceName ,
434 NodeName , NodeKindOfNode ,
435 aFuncName , aPythonFunction ,
436 NodeFirstCreation , NodeLastModification ,
437 NodeEditorRelease , NodeAuthor ,
438 NodeComputer , NodeComment , false , NodeX , NodeY ,
439 _prof_debug , _fdebug ) ;
440 Graph()->AddNode( Nd->ComputingNode() ) ;
441 cdebug_out << "GraphExecutor::OutNode::AddNode" << endl;
446 bool GraphExecutor::OutNode::Valid() {
447 cdebug_in << "GraphExecutor::OutNode::Valid" << endl;
452 _Executable = false ;
454 if ( !Graph()->CreateService() ) {
455 cdebug_out << "This DataFlow has invalid type(s)." << endl ;
458 int SubStreamGraphsNumber = 0 ;
459 if ( !Graph()->Sort( SubStreamGraphsNumber ) ) {
460 cdebug_out << "This DataFlow is not valid." << endl ;
463 if ( Graph()->IsDataStreamNode() ) {
464 StreamGraph()->SubStreamGraphsNumber( SubStreamGraphsNumber ) ;
466 Graph()->InLineServices() ;
468 if ( !Graph()->ValidLoops() ) {
469 cdebug_out << "This DataFlow have not valid Loops." << endl ;
472 if ( !Graph()->ValidSwitchs() ) {
473 cdebug_out << "This DataFlow have not valid Switchs." << endl ;
479 Graph()->ComputingNodes() ;
483 cdebug_out << "GraphExecutor::OutNode::Valid " << _Valid << endl;
488 bool GraphExecutor::OutNode::Executable() {
490 cdebug_in << "GraphExecutor::OutNode::Executable" << endl;
494 if ( Graph()->DataServerNodes() )
497 cdebug << "This DataFlow is not executable." << endl ;
498 _Executable = false ;
501 cdebug_out << "GraphExecutor::OutNode::Executable " << _Executable << endl;
505 bool GraphExecutor::OutNode::Run( const bool AndSuspend ) {
506 bool RetVal = false ;
507 cdebug_in << pthread_self() << "GraphExecutor::OutNode::Run( AndSuspend " << AndSuspend
508 << " ) State " << theAutomaton->StateName( State() ) << endl;
510 if ( Executable() ) {
511 _ControlState = SUPERV::VoidState ;
512 _SuspendedThreads = 0 ;
513 Graph()->ThreadNo( pthread_self() ) ;
515 _JustStarted = true ;
518 for ( i = 0 ; i < Graph()->GraphNodesSize() ; i++ ) {
519 GraphExecutor::InNode * anInNode = (GraphExecutor::InNode *) Graph()->GraphNodes( i )->GetInNode() ;
520 anInNode->OutNode( this ) ;
521 // Initialize in python interpretor the python functions
522 if ( !PyInitialized() && anInNode->IsOneOfInLineNodes() ) {
523 if ( !Py_IsInitialized() ) {
524 // PyEval_InitThreads() ;
526 // asv : 20.01.05 : changes involved with switching to old (HEAD) KERNEL
527 // 1 line below uncommented
528 PySys_SetArgv( _ArgC , _ArgV ) ;
530 anInNode->InitPython() ;
531 PyInitialized( true ) ;
533 anInNode->InitialState() ;
534 if ( anInNode->IsOneOfInLineNodes() ) {
535 anInNode->InitPythonFunctions( false ) ;
538 // One more time because inline nodes may share one definition of the same function
539 for ( i = 0 ; i < Graph()->GraphNodesSize() ; i++ ) {
540 GraphExecutor::InNode * anInNode = (GraphExecutor::InNode *) Graph()->GraphNodes( i )->GetInNode() ;
541 if ( anInNode->IsOneOfInLineNodes() ) {
542 if ( !anInNode->InitPythonFunctions( true ) ) {
543 anInNode->State( GraphExecutor::ErroredState ) ;
545 //JR 24.03.2005 debug : State and done flags were missing
546 State( GraphExecutor::ErroredState ) ;
548 cdebug_out << "GraphExecutor::OutNode::Run InitPythonFunctions ERROR "
549 << anInNode->Name() << endl ;
554 /* asv : 29.09.04 : commented out because it does not do anything useful
555 for ( i = 0 ; i < Graph()->GraphNodesSize() ; i++ ) {
556 GraphExecutor::InNode * anInNode = (GraphExecutor::InNode *) Graph()->GraphNodes( i )->GetInNode() ;
557 if ( RetVal && anInNode->IsMacroNode() ) {
558 GraphBase::Graph * aMacroGraph = anInNode->GraphMacroNode() ;
559 cdebug << "GraphExecutor::OutNode::Run " << anInNode << " MacroNode " << aMacroGraph
560 << aMacroGraph->Name() << endl ;
561 SUPERV::Graph_var iobject = anInNode->GraphMacroNode()->MacroObject() ;
562 if ( CORBA::is_nil( iobject ) ) {
563 cdebug << "GraphExecutor::OutNode::Run MacroObject() is a nil object. Error" << endl ;
567 cdebug << "GraphExecutor::OutNode::Run MacroObject() is NOT a nil object." << endl ;
572 if ( Graph()->GraphMacroLevel() != 0 ) {
573 cdebug << "GraphExecutor::OutNode::Run Execution starting GraphExecutor::Action_DataOk_RunService Node "
574 << Graph()->Name() << " GraphMacroLevel " << Graph()->GraphMacroLevel() << endl ;
575 PushEvent( NULL , GraphExecutor::NoDataReadyEvent ,
576 GraphExecutor::DataUndefState ) ;
579 cdebug << "Execution starting GraphExecutor::Action_DataOk_RunService Node "
580 << Graph()->Name() << " GraphMacroLevel " << Graph()->GraphMacroLevel() << endl ;
581 PushEvent( NULL , GraphExecutor::ReadyEvent ,
582 GraphExecutor::DataReadyState ) ;
583 State( GraphExecutor::DataReadyState ) ;
585 cdebug << pthread_self() << " GraphExecutor::OutNode::Run Start of the " << Graph()->HeadNodesSize()
586 << " HeadNodes" << endl ;
587 for ( i = 0 ; i < Graph()->HeadNodesSize() ; i++ ) {
588 GraphExecutor::InNode * anInNode = (GraphExecutor::InNode *) Graph()->HeadNodes( i )->GetInNode() ;
589 cdebug << pthread_self() << "GraphExecutor::OutNode::Run Start of HeadNode " << i << " "
590 << anInNode->Name() << endl ;
591 if ( anInNode->State() != GraphExecutor::DataReadyState ) {
593 //JR 24.03.2005 debug : State and done flags were missing
594 State( GraphExecutor::ErroredState ) ;
596 cdebug << "GraphExecutor::OutNode::Run inconsistency State of Node "
597 << anInNode->Name() << " : " << anInNode->State() << endl ;
598 cdebug_out << "GraphExecutor::OutNode::Run State ERROR" << endl ;
601 // PushEvent( anInNode , GraphExecutor::ReadyEvent ,
602 // GraphExecutor::DataReadyState ) ;
603 // We say that we have to create a thread for that HeadNode 'anInNode'
604 anInNode->CreateNewThread( true ) ;
605 IncrCreatedThreads() ;
606 anInNode->DataFromNode( Graph()->Name() ) ;
607 // AndSuspend == true <==> Start()
609 anInNode->State( GraphExecutor::DataWaitingState ) ;
610 anInNode->ControlState( SUPERV::ToSuspendStartState ) ;
611 // We send SomeDataReadyEvent
612 // It is a HeadNode ==> AllDataReadyEvent ==> InNode::executeAction() ==> pthread_create
613 if ( !anInNode->SendEvent( GraphExecutor::SomeDataReadyEvent ) ) {
615 //JR 24.03.2005 debug : State and done flags were missing
616 State( GraphExecutor::ErroredState ) ;
618 cdebug << "InNode::SendEvent( SomeDataReadyEvent ) ERROR Node "
619 << anInNode->Name() << endl ;
620 cdebug_out << "GraphExecutor::OutNode::Run SendEvent ERROR" << endl ;
623 // ==> We wait for SuspendedState
624 anInNode->SuspendedWait() ;
626 // AndSuspend == false <==> Run()
627 else if ( anInNode->IsMacroNode() ) {
628 if ( !anInNode->SendEvent( GraphExecutor::SomeDataReadyEvent ) ) {
630 //JR 24.03.2005 debug : State and done flags were missing
631 State( GraphExecutor::ErroredState ) ;
633 cdebug << "InNode::SendEvent( SomeDataReadyEvent ) ERROR Node "
634 << anInNode->Name() << endl ;
635 cdebug_out << "GraphExecutor::OutNode::Run SendEvent ERROR" << endl ;
638 cdebug << pthread_self() << " GraphExecutor::OutNode::Run " << anInNode->Name() << "->RunningWait"
640 // ==> We wait for RunningState
641 anInNode->RunningWait() ;
642 cdebug << pthread_self() << " GraphExecutor::OutNode::Run " << anInNode->Name() << "->RunningWaited"
645 else if ( !anInNode->IsMacroNode() ) {
646 // It is a HeadNode ==> AllDataReadyEvent ==> InNode::executeAction() ==> pthread_create
647 if ( !anInNode->SendEvent( GraphExecutor::ExecuteEvent ) ) {
649 //JR 24.03.2005 debug : State and done flags were missing
650 State( GraphExecutor::ErroredState ) ;
652 cdebug << "InNode::SendEvent( ExecuteEvent ) ERROR Node "
653 << anInNode->Name() << endl ;
654 cdebug_out << "GraphExecutor::OutNode::Run SendEvent ERROR" << endl ;
657 // ==> We wait for RunningState
658 anInNode->RunningWait() ;
663 PushEvent( NULL , GraphExecutor::SuspendedReadyEvent ,
664 GraphExecutor::SuspendedReadyState ) ;
667 PushEvent( NULL , GraphExecutor::ExecutingEvent ,
668 GraphExecutor::ExecutingState ) ;
669 if (AutomatonState() == GraphExecutor::DataReadyState) {
670 State( GraphExecutor::ExecutingState ) ;
673 // ostringstream astr ;
674 // astr << "Graph " << Graph()->Name() << " is running" ;
675 // Graph()->ObjImpl()->sendMessage( NOTIF_STEP, astr.str().c_str() ) ;
681 //JR 24.03.2005 debug : State and done flags were missing
682 State( GraphExecutor::ErroredState ) ;
684 cdebug_out << "GraphExecutor::OutNode::Run Not Executable ERROR " << endl ;
688 cdebug_out << pthread_self() << "GraphExecutor::OutNode::Run " << Graph()->Name()
689 << " State " << theAutomaton->StateName( State() ) << " GraphMacroLevel "
690 << Graph()->GraphMacroLevel() << " RetVal " << RetVal << endl ;
694 void GraphExecutor::OutNode::CheckAllDone() {
696 cdebug_in << "GraphExecutor::OutNode::CheckAllDone " << endl;
697 GraphExecutor::AutomatonState OutNodeState = GraphExecutor::SuccessedState ;
698 GraphExecutor::AutomatonState InNodeState ;
699 bool AllDone = true ;
701 for ( j = 0 ; j < Graph()->QueueNodesSize() ; j++ ) {
702 InNodeState = ( (GraphExecutor::InNode * ) Graph()->QueueNodes( j )->GetInNode() )->State() ;
704 << ( (GraphExecutor::InNode * ) Graph()->QueueNodes( j )->GetInNode() )->Name()
705 << " " << theAutomaton->StateName( InNodeState ) << endl ;
706 if ( InNodeState != GraphExecutor::SuccessedState &&
707 InNodeState != GraphExecutor::ErroredState &&
708 InNodeState != GraphExecutor::DataWaitingState ) {
711 if ( InNodeState != GraphExecutor::SuccessedState &&
712 InNodeState != GraphExecutor::DataWaitingState &&
713 InNodeState != GraphExecutor::DataReadyState ) {
714 OutNodeState = InNodeState ;
718 if( _Threads == 0 && _SuspendedThreads == 0 ) {
719 if ( OutNodeState != GraphExecutor::ErroredState ) {
720 OutNodeState = GraphExecutor::SuccessedState ;
729 for ( j = 0 ; j < Graph()->GraphNodesSize() ; j++ ) {
730 GraphExecutor::InNode * aNode ;
731 aNode = (GraphExecutor::InNode * ) Graph()->GraphNodes( j )->GetInNode() ;
732 SUPERV::GraphState aState = AutomatonGraphState( aNode->State() ) ;
733 cdebug << "GraphExecutor::OutNode::CheckAllDone " << aNode->Name() << " "
734 << theAutomaton->StateName( aNode->State() ) << " CreateNewThread " << aNode->CreateNewThread()
736 if ( aState == SUPERV::ErrorState ||
737 aState == SUPERV::SuspendErroredState ||
738 aState == SUPERV::KillState ||
739 aState == SUPERV::StopState ) {
740 OutNodeState = aNode->State() ;
741 State( OutNodeState ) ;
743 else if ( aState == SUPERV::ReadyState ||
744 aState == SUPERV::SuspendReadyState ||
745 aState == SUPERV::RunningState ||
746 aState == SUPERV::SuspendDoneState ||
747 aState == SUPERV::SuspendErroredState ||
748 aState == SUPERV::SuspendState ) {
751 aNode->SuspendedAction() ;
752 aNode->DoneAction() ;
754 // PushEvent AFTER State and _Done ! ...
755 if ( alivenodes == 0 ) {
756 State( OutNodeState ) ;
758 _JustStarted = false ;
760 cdebug << Graph()->Name() << " alivenodes " << alivenodes << " OutNodeState " << OutNodeState
762 PushEvent( NULL , GraphExecutor::EndExecuteEvent ,
765 // PyInitialized( false ) ;
769 MESSAGE("================================================================================") ;
770 MESSAGE( Graph()->Name() << " IS DONE : " << theAutomaton->StateName( AutomatonState() ) << " EventQSize "
772 MESSAGE("================================================================================") ;
773 cdebug << "================================================================================" << endl ;
774 cdebug << Graph()->Name() << " IS DONE : " << theAutomaton->StateName( AutomatonState() ) << " EventQSize "
775 << EventQSize() << endl ;
776 cdebug << "================================================================================" << endl ;
779 //JR 23.02.2005, Debug : siftEvents() must be inside the pthread_mutex_lock
780 if ( pthread_mutex_lock( &_MutexWait ) ) {
781 perror("EventLoop pthread_mutex_lock ") ;
784 // asv : fix for 6798 and other bugs: "sift" the event queue after execution
786 if ( pthread_mutex_unlock( &_MutexWait ) ) {
787 perror("PushEvent pthread_mutex_unlock ") ;
791 // asv : 25.10.04 : calling Editing() to indicate stop of execution
792 Graph()->GraphEditor()->Editing();
794 cdebug_out << "GraphExecutor::OutNode::CheckAllDone " << IsDone() << " this " << this << " "
795 << Graph()->Name() << " GraphAutomatonState "
796 << theAutomaton->StateName( AutomatonState() )
797 << " State " << State() << " Threads " << _Threads << " SuspendedThreads "
798 << _SuspendedThreads << " EventQSize " << EventQSize() << endl ;
801 // asv : 20.01.05 : changes involved with switching to old (HEAD) KERNEL
802 //Engines_Container_i * GraphExecutor::OutNode::SuperVisionContainer() {
803 // return _SuperVisionContainer ;
806 //const pthread_t GraphExecutor::OutNode::MainThreadId() const {
807 // return _MainThreadId ;
810 void GraphExecutor::OutNode::PThreadLock( pthread_mutex_t * aMutex , char * errmsg ) {
811 // if ( strcmp( errmsg , "EventLoop" ) && strcmp( errmsg , "EventW" ) ) {
812 // cdebug << "GraphExecutor::OutNode::PThreadLock " << pthread_self() << " " << aMutex << " "
813 // << errmsg << endl ;
815 if ( pthread_mutex_lock( aMutex ) ) {
819 // if ( strcmp( errmsg , "EventLoop" ) && strcmp( errmsg , "EventW" ) ) {
820 // cdebug << "GraphExecutor::OutNode::PThreadLocked " << pthread_self() << " " << aMutex << " "
821 // << errmsg << endl ;
825 void GraphExecutor::OutNode::PThreadUnLock( pthread_mutex_t * aMutex , char * errmsg ) {
826 // if ( strcmp( errmsg , "EventLoop" ) && strcmp( errmsg , "EventW" ) ) {
827 // cdebug << " GraphExecutor::OutNode::PThreadUnLock " << pthread_self() << " " << aMutex << " "
828 // << errmsg << endl ;
830 if ( pthread_mutex_unlock( aMutex ) ) {
836 void GraphExecutor::OutNode::PyThreadLock() {
837 // cout << " GraphExecutor::OutNode::PyThreadLock " << pthread_self() << endl ;
838 if ( pthread_mutex_lock( &_PyMutexWait ) ) {
839 perror( "GraphExecutor::OutNode::PyThreadLock" ) ;
842 theAutomaton->PyLock() ;
843 // cout << " GraphExecutor::OutNode::PyThreadLocked " << pthread_self() << endl ;
846 void GraphExecutor::OutNode::PyThreadUnLock() {
847 // cout << " GraphExecutor::OutNode::PyThreadUnLock " << pthread_self() << endl ;
848 if ( pthread_mutex_unlock( &_PyMutexWait ) ) {
849 perror( "GraphExecutor::OutNode::PyThreadUnLock" ) ;
852 theAutomaton->PyUnLock() ;
853 // cout << " GraphExecutor::OutNode::PyThreadUnLocked " << pthread_self() << endl ;
856 void GraphExecutor::OutNode::NewThread() {
857 if ( pthread_mutex_lock( &_MutexWait ) ) {
858 perror("pthread_mutex_lock _NewThread") ;
862 // cdebug << "NewThread : " << _Threads << " running threads "
863 // << _SuspendedThreads << " suspended threads"
865 if ( pthread_mutex_unlock( &_MutexWait ) ) {
866 perror("pthread_mutex_unlock _NewThread") ;
871 void GraphExecutor::OutNode::ExitThread( pthread_t ThreadNumber ) {
872 if ( pthread_mutex_lock( &_MutexWait ) ) {
873 perror("pthread_mutex_lock _ExitThread") ;
876 if ( ThreadNumber == 0 ) {
877 ThreadNumber = pthread_self() ;
880 // cdebug << pthread_self() << " ExitThread( " << ThreadNumber << " ) " << _Threads << " running threads "
881 // << _SuspendedThreads << " suspended threads"
883 theAutomaton->JoinThread( ThreadNumber ) ;
884 if ( pthread_cond_signal( &_JoinWait ) ) {
885 perror("ExitThread pthread_cond_signal ") ;
887 if ( pthread_mutex_unlock( &_MutexWait ) ) {
888 perror("pthread_mutex_unlock _ExitThread") ;
891 if ( _Threads == 0 && _SuspendedThreads == 0 ) {
894 theAutomaton->Executed() ;
898 void GraphExecutor::OutNode::JoinedWait() {
899 if ( pthread_mutex_lock( &_MutexWait ) ) {
900 perror("pthread_mutex_lock JoinedWait") ;
904 if ( pthread_cond_wait( &_JoinWait , &_MutexWait ) ) {
905 perror("JoinedWait pthread_cond_wait ") ;
908 if ( pthread_mutex_unlock( &_MutexWait ) ) {
909 perror("pthread_mutex_unlock JoinedWait") ;
914 void GraphExecutor::OutNode::SuspendThread() {
915 if ( pthread_mutex_lock( &_MutexWait ) ) {
916 perror("pthread_mutex_lock _SuspendThread") ;
919 _SuspendedThreads += 1 ;
920 cdebug << "SuspendThread : " << _Threads << " running threads "
921 << _SuspendedThreads << " suspended threads"
923 if ( pthread_mutex_unlock( &_MutexWait ) ) {
924 perror("pthread_mutex_unlock _SuspendThread") ;
927 if ( IsSuspended() ) {
928 PushEvent( NULL , GraphExecutor::SuspendEvent , GraphExecutor::SuspendedState ) ;
931 void GraphExecutor::OutNode::ResumeThread() {
932 if ( pthread_mutex_lock( &_MutexWait ) ) {
933 perror("pthread_mutex_lock _ResumeThread") ;
936 _SuspendedThreads -= 1 ;
937 cdebug << "ResumeThread : " << _Threads << " running threads "
938 << _SuspendedThreads << " suspended threads"
940 if ( pthread_mutex_unlock( &_MutexWait ) ) {
941 perror("pthread_mutex_unlock _ResumeThread") ;
946 long GraphExecutor::OutNode::Thread( const char * aNodeName ) {
948 GraphExecutor::InNode *anInNode = (GraphExecutor::InNode *) Graph()->GetGraphNode( aNodeName )->GetInNode() ;
950 RetVal = anInNode->ThreadNo() ;
955 SUPERV::GraphEvent GraphExecutor::OutNode::AutomatonGraphEvent(GraphExecutor::NodeEvent anEvent ) {
956 SUPERV::GraphEvent aGraphEvent ;
958 case GraphExecutor::UndefinedEvent : {
959 aGraphEvent = SUPERV::UndefinedEvent ;
962 case GraphExecutor::NewThreadEvent : {
963 aGraphEvent = SUPERV::NewThreadEvent ;
966 case GraphExecutor::SuspendEvent : {
967 aGraphEvent = SUPERV::SuspendEvent ;
970 case GraphExecutor::ResumeEvent : {
971 aGraphEvent = SUPERV::ResumeEvent ;
974 case GraphExecutor::KillEvent : {
975 aGraphEvent = SUPERV::KillEvent ;
978 case GraphExecutor::StopEvent : {
979 aGraphEvent = SUPERV::StopEvent ;
982 case GraphExecutor::ExecuteEvent : {
983 aGraphEvent = SUPERV::RunningEvent ;
986 case GraphExecutor::SuccessEvent : {
987 aGraphEvent = SUPERV::DoneEvent ;
990 case GraphExecutor::ErrorEvent : {
991 aGraphEvent = SUPERV::ErroredEvent ;
994 case GraphExecutor::NoDataReadyEvent : {
995 aGraphEvent = SUPERV::WaitingEvent ;
998 case GraphExecutor::SomeDataReadyEvent : {
999 aGraphEvent = SUPERV::WaitingEvent ;
1002 case GraphExecutor::NotAllDataReadyEvent : {
1003 aGraphEvent = SUPERV::WaitingEvent ;
1006 case GraphExecutor::AllDataReadyEvent : {
1007 aGraphEvent = SUPERV::ReadyEvent ;
1010 case GraphExecutor::ReadyEvent : {
1011 aGraphEvent = SUPERV::ReadyEvent ;
1014 case GraphExecutor::SuspendedReadyEvent : {
1015 aGraphEvent = SUPERV::SuspendEvent ;
1018 case GraphExecutor::ResumedReadyEvent : {
1019 aGraphEvent = SUPERV::ResumeEvent ;
1022 case GraphExecutor::KilledReadyEvent : {
1023 aGraphEvent = SUPERV::KillEvent ;
1026 case GraphExecutor::StoppedReadyEvent : {
1027 aGraphEvent = SUPERV::StopEvent ;
1030 case GraphExecutor::ExecutingEvent : {
1031 aGraphEvent = SUPERV::RunningEvent ;
1034 case GraphExecutor::SuspendedExecutingEvent : {
1035 aGraphEvent = SUPERV::SuspendEvent ;
1038 case GraphExecutor::ResumedExecutingEvent : {
1039 aGraphEvent = SUPERV::ResumeEvent ;
1042 case GraphExecutor::KilledExecutingEvent : {
1043 aGraphEvent = SUPERV::KillEvent ;
1046 case GraphExecutor::StoppedExecutingEvent : {
1047 aGraphEvent = SUPERV::StopEvent ;
1050 case GraphExecutor::SuccessedExecutingEvent : {
1051 aGraphEvent = SUPERV::DoneEvent ;
1054 case GraphExecutor::ErroredExecutingEvent : {
1055 aGraphEvent = SUPERV:: ErroredEvent;
1058 case GraphExecutor::SuspendedSuccessedEvent : {
1059 aGraphEvent = SUPERV::SuspendEvent ;
1062 case GraphExecutor::SuspendedErroredEvent : {
1063 aGraphEvent = SUPERV::SuspendEvent ;
1066 case GraphExecutor::ResumedSuccessedEvent : {
1067 aGraphEvent = SUPERV::ResumeEvent ;
1070 case GraphExecutor::ResumedErroredEvent : {
1071 aGraphEvent = SUPERV::ResumeEvent ;
1074 case GraphExecutor::KilledEvent : {
1075 aGraphEvent = SUPERV::KillEvent ;
1078 case GraphExecutor::StoppedEvent : {
1079 aGraphEvent = SUPERV::StopEvent ;
1082 case GraphExecutor::EndExecuteEvent : {
1083 aGraphEvent = SUPERV::DoneEvent ;
1087 cdebug << " GraphExecutor::OutNode::AutomatonGraphEvent Error Undefined Event : "
1088 << anEvent << endl ;
1089 aGraphEvent = SUPERV::UndefinedEvent ;
1092 return aGraphEvent ;
1095 SUPERV::GraphState GraphExecutor::OutNode::AutomatonGraphState(GraphExecutor::AutomatonState aState ) {
1096 SUPERV::GraphState aGraphState ;
1098 case GraphExecutor::UnKnownState : {
1099 aGraphState = SUPERV::UndefinedState ;
1102 case GraphExecutor::DataUndefState : {
1103 aGraphState = SUPERV::UndefinedState ;
1106 case GraphExecutor::DataWaitingState : {
1107 aGraphState = SUPERV::WaitingState ;
1110 case GraphExecutor::DataReadyState : {
1111 aGraphState = SUPERV::ReadyState ;
1114 case GraphExecutor::SuspendedReadyState : {
1115 aGraphState = SUPERV::SuspendReadyState ;
1118 case GraphExecutor::ResumedReadyState : {
1119 aGraphState = SUPERV::ReadyState ;
1122 case GraphExecutor::KilledReadyState : {
1123 aGraphState = SUPERV::KillState ;
1126 case GraphExecutor::StoppedReadyState : {
1127 aGraphState = SUPERV::StopState ;
1130 case GraphExecutor::ExecutingState : {
1131 aGraphState = SUPERV::RunningState ;
1134 case GraphExecutor::SuspendedExecutingState : {
1135 aGraphState = SUPERV::SuspendState ;
1138 case GraphExecutor::ResumedExecutingState : {
1139 aGraphState = SUPERV::RunningState ;
1142 case GraphExecutor::KilledExecutingState : {
1143 aGraphState = SUPERV::KillState ;
1146 case GraphExecutor::StoppedExecutingState : {
1147 aGraphState = SUPERV::StopState ;
1150 case GraphExecutor::SuccessedExecutingState : {
1151 aGraphState = SUPERV::DoneState ;
1154 case GraphExecutor::ErroredExecutingState : {
1155 aGraphState = SUPERV::ErrorState ;
1158 case GraphExecutor::SuspendedSuccessedState : {
1159 aGraphState = SUPERV::SuspendDoneState ;
1162 case GraphExecutor::SuspendedErroredState : {
1163 aGraphState = SUPERV::SuspendErroredState ;
1166 case GraphExecutor::ResumedSuccessedState : {
1167 aGraphState = SUPERV::DoneState ;
1170 case GraphExecutor::ResumedErroredState : {
1171 aGraphState = SUPERV::ErrorState ;
1174 case GraphExecutor::KilledSuccessedState : {
1175 aGraphState = SUPERV::KillState ;
1178 case GraphExecutor::KilledErroredState : {
1179 aGraphState = SUPERV::KillState ;
1182 case GraphExecutor::StoppedSuccessedState : {
1183 aGraphState = SUPERV::StopState ;
1186 case GraphExecutor::StoppedErroredState : {
1187 aGraphState = SUPERV::StopState ;
1190 case GraphExecutor::SuccessedState : {
1191 aGraphState = SUPERV::DoneState ;
1194 case GraphExecutor::ErroredState : {
1195 aGraphState = SUPERV::ErrorState ;
1198 case GraphExecutor::SuspendedState : {
1199 aGraphState = SUPERV::SuspendState ;
1202 case GraphExecutor::KilledState : {
1203 aGraphState = SUPERV::KillState ;
1206 case GraphExecutor::StoppedState : {
1207 aGraphState = SUPERV::StopState ;
1210 case GraphExecutor::LoadingState : {
1211 aGraphState = SUPERV::LoadingState ;
1215 cdebug << " GraphExecutor::OutNode::AutomatonGraphState Error Undefined State : "
1216 << aGraphState << endl ;
1217 aGraphState = SUPERV::UndefinedState ;
1220 return aGraphState ;
1223 //JR 07.04.2005, Debug : access to _EventNodes must be inside the pthread_mutex_lock
1224 int GraphExecutor::OutNode::GetListSize() {
1225 if ( pthread_mutex_lock( &_MutexWait ) ) {
1226 perror("PushEvent pthread_mutex_lock ") ;
1229 int eventnbr = _EventNodes.size();
1230 if ( pthread_mutex_unlock( &_MutexWait ) ) {
1231 perror("PushEvent pthread_mutex_unlock ") ;
1237 bool GraphExecutor::OutNode::PushEvent( GraphExecutor::InNode * aNode ,
1238 GraphExecutor::NodeEvent anEvent ,
1239 GraphExecutor::AutomatonState aState ) {
1240 // cdebug_in << "PushEvent Threads " << Threads() << " SuspendedThreads "
1241 // << SuspendedThreads() << endl ;
1242 if ( pthread_mutex_lock( &_MutexWait ) ) {
1243 perror("PushEvent pthread_mutex_lock ") ;
1246 char* aNodeName = aNode ? aNode->Name() : Graph()->Name() ;
1247 _EventNodes.push_back( aNodeName ) ;
1248 _Events.push_back( anEvent ) ;
1249 _States.push_back( aState ) ;
1251 pthread_cond_broadcast( &_EventWait );
1252 // cdebug << pthread_self() << " PushEvent Threads " << Threads() << " SuspendedThreads "
1253 // << SuspendedThreads() << " pthread_cond_broadcast _EventWait " << &_EventWait << endl ;
1255 // cdebug << aNode->ThreadNo() << " PushEvent " << aNode->Name() ;
1256 // cdebug << " " << aNode->Automaton()->EventName( anEvent )
1257 // << " " << aNode->Automaton()->StateName( aState )
1258 // << " ControleState "
1259 // << aNode->Automaton()->ControlStateName( aNode->ControlState() ) ;
1262 // cdebug << "PushEvent " << Graph()->Name() ;
1263 // cdebug << " " << theAutomaton->EventName( anEvent ) << " "
1264 // << theAutomaton->StateName( aState ) ;
1266 // cdebug_out << "PushEvent Threads " << Threads() << " SuspendedThreads "
1267 // << SuspendedThreads() << endl ;
1270 //JR 21.02.2005 Debug : old events should be removed at creation time for python-clients
1271 int EventNodesSize = _EventNodes.size() ;
1272 if ( EventNodesSize > Graph()->GraphNodesSize()*70 ) {
1274 // cdebug << "OutNode::PushEvent " << _EventNodes.size() << " in queue instead of "
1275 // << EventNodesSize << endl ;
1278 if ( pthread_mutex_unlock( &_MutexWait ) ) {
1279 perror("PushEvent pthread_mutex_unlock ") ;
1285 bool GraphExecutor::OutNode::StateWait( SUPERV::GraphState aState ) {
1289 bool GraphExecutor::OutNode::Event( char ** aNodeName ,
1290 SUPERV::GraphEvent & anEvent ,
1291 SUPERV::GraphState & aState ,
1294 //JR 23.02.2005, Debug : siftEvents() must be inside the pthread_mutex_lock
1295 if ( pthread_mutex_lock( &_MutexWait ) ) {
1296 perror("EventLoop pthread_mutex_lock ") ;
1299 // asv : fixing problem of loops with large number of iterations (>5000)
1300 // experimentally was found that number of non-handled by GUI events = (number_of_nodes x 7)
1301 // or 7 events for each node - so what we want to do here is remove "old" events for nodes
1302 // "on the fly". Once again it is done in Stop(), Kill(), Done() functions.
1303 int EventNodessize = _EventNodes.size() ;
1304 if ( EventNodessize > Graph()->GraphNodesSize()*7 )
1308 int SuspendedThreadsNumber ;
1309 bool cdebuginout = false ;
1310 if ( _EventNodes.size() > 0 ) {
1311 // cdebug_in << "GraphExecutor::OutNode::Event " << _EventNodes.size() << " in queue instead of "
1312 // << EventNodessize << endl ;
1313 cdebuginout = true ;
1315 _JustStarted = false ;
1316 ThreadsNumber = Threads() ;
1317 SuspendedThreadsNumber = SuspendedThreads() ;
1318 bool RetVal = ( ThreadsNumber - SuspendedThreadsNumber) != 0 ||
1319 _EventNodes.size() > 0 ;
1320 char * NodeName = "" ;
1321 GraphExecutor::NodeEvent theEvent = GraphExecutor::UndefinedEvent ;
1322 GraphExecutor::AutomatonState theState = GraphExecutor::UnKnownState ;
1323 anEvent = SUPERV::UndefinedEvent ;
1324 aState = SUPERV::UndefinedState ;
1325 if ( ( Done() || IsKilled() || IsStopped() ) && _EventNodes.size() == 0 ) {
1326 // cdebug << "EventLoop Done()/IsKilled()/IsStopped() && _EventNodes.size() == 0" << endl ;
1329 else if ( !WithWait && _EventNodes.size() == 0 ) {
1330 anEvent = SUPERV::NoEvent ;
1331 aState = SUPERV::NoState ;
1334 else if ( RetVal ) {
1335 while ( !IsSuspended() && _EventNodes.size() == 0 ) {
1336 // cdebug << "EventLoop pthread_cond_wait _EventWait" << endl ;
1337 pthread_cond_wait( &_EventWait , &_MutexWait );
1338 // cdebug << "EventLoop pthread_cond_waited _EventWait"
1339 // << " _EventNodes.size() " << _EventNodes.size() << endl ;
1341 if ( _EventNodes.size() ) {
1342 ThreadsNumber = Threads() ;
1343 NodeName = _EventNodes.front() ;
1344 _EventNodes.pop_front() ;
1345 theEvent = _Events.front() ;
1346 anEvent = AutomatonGraphEvent( theEvent ) ;
1347 _Events.pop_front() ;
1348 theState = _States.front() ;
1349 aState = AutomatonGraphState( theState ) ;
1350 _States.pop_front() ;
1353 *aNodeName = NodeName ;
1354 if ( IsSuspended() && _EventNodes.size() == 0 ) {
1357 if ( anEvent != SUPERV::NoEvent ) {
1358 // cdebug << pthread_self() << "EventLoop "
1359 // << NodeName << " " << theAutomaton->StateName( theState )
1360 // << " _EventNodes.size() " << _EventNodes.size()
1361 // << " Threads " << Threads() << " SuspendedThreads "
1362 // << SuspendedThreads() << " RetVal " << RetVal << endl ;
1364 if ( pthread_mutex_unlock( &_MutexWait ) ) {
1365 perror("EventLoop pthread_mutex_lock ") ;
1368 if ( cdebuginout ) {
1369 // cdebug_out << "GraphExecutor::OutNode::Event " << _EventNodes.size() << " in queue"
1370 // << *aNodeName << " " << anEvent << " " << aState << endl ;
1375 bool GraphExecutor::OutNode::EventW( char ** aNodeName ,
1376 SUPERV::GraphEvent & anEvent ,
1377 SUPERV::GraphState & aState ) {
1380 aState = SUPERV::UndefinedState ;
1382 aState != SUPERV::SuspendReadyState &&
1383 aState != SUPERV::RunningState &&
1384 aState != SUPERV::SuspendDoneState &&
1385 aState != SUPERV::SuspendErroredState ) {
1386 NodeName = Graph()->Name() ;
1387 while ( sts && !strcmp( NodeName , Graph()->Name() ) ) {
1388 sts = EventWait( aNodeName , anEvent , aState ) ;
1389 NodeName = *aNodeName ;
1395 bool GraphExecutor::OutNode::EventWait( char ** aNodeName ,
1396 SUPERV::GraphEvent & anEvent ,
1397 SUPERV::GraphState & aState ) {
1398 if ( pthread_mutex_lock( &_MutexWait ) ) {
1399 perror("EventW pthread_mutex_lock ") ;
1403 int SuspendedThreadsNumber ;
1404 ThreadsNumber = Threads() ;
1405 SuspendedThreadsNumber = SuspendedThreads() ;
1406 bool RetVal = ( ThreadsNumber - SuspendedThreadsNumber) != 0 ||
1407 _EventNodes.size() > 0 ;
1408 cdebug << "--> EventW RetVal " << RetVal << endl ;
1409 char * NodeName = "" ;
1410 GraphExecutor::NodeEvent theEvent = GraphExecutor::UndefinedEvent ;
1411 GraphExecutor::AutomatonState theState = GraphExecutor::UnKnownState ;
1412 anEvent = SUPERV::UndefinedEvent ;
1413 aState = SUPERV::UndefinedState ;
1414 if ( IsDone() && _EventNodes.size() == 0 ) {
1415 cdebug << "EventW IsDone() && _EventNodes.size() == 0" << endl ;
1418 else if ( RetVal ) {
1419 GraphExecutor::InNode * aNode = NULL ;
1420 while ( aNode == NULL && RetVal ) {
1421 NodeName = _EventNodes.front() ;
1422 theEvent = _Events.front() ;
1423 anEvent = AutomatonGraphEvent( theEvent ) ;
1424 theState = _States.front() ;
1425 aState = AutomatonGraphState( theState ) ;
1427 if ( _JustStarted ) {
1428 _JustStarted = false ;
1431 _EventNodes.pop_front() ;
1432 _Events.pop_front() ;
1433 _States.pop_front() ;
1436 aNode = ((GraphExecutor::InNode *) Graph()->GetGraphNode( NodeName )->GetInNode()) ;
1437 cdebug << "EventW Previous Node " << NodeName << " ThreadsNumber "
1439 << " _EventNodes.size() " << _EventNodes.size() << " "
1440 << theAutomaton->StateName( theState )
1441 << " Threads " << Threads() << " SuspendedThreads "
1442 << SuspendedThreads() << endl ;
1445 else if ( IsDone() && _EventNodes.size() == 0 ) {
1446 cdebug << "EventW IsDone() && _EventNodes.size() == 0" << endl ;
1450 cdebug << "EventW Not InNode " << NodeName
1451 << " _EventNodes.size() " << _EventNodes.size() << endl ;
1452 while ( _EventNodes.size() == 0 ) {
1453 pthread_cond_wait( &_EventWait , &_MutexWait );
1455 cdebug << "EventW pthread_cond_waited Not InNode " << NodeName
1456 << " _EventNodes.size() " << _EventNodes.size() << endl ;
1461 if ( aState == SUPERV::SuspendState ||
1462 aState == SUPERV::SuspendReadyState ||
1463 aState == SUPERV::SuspendDoneState ||
1464 aState == SUPERV::SuspendErroredState ) {
1465 aNode->ControlState( SUPERV::ToSuspendState ) ;
1466 if ( aNode->IsSuspended() ) {
1467 if ( pthread_mutex_unlock( &_MutexWait ) ) {
1468 perror("EventW pthread_mutex_lock ") ;
1471 cdebug << "EventW " << aNode->Name() << " ResumeAction" << endl ;
1472 aNode->ResumeAction( GraphExecutor::ToResumeEvent ) ;
1473 cdebug << "EventW " << aNode->Name() << " ResumedAction" << endl ;
1474 if ( pthread_mutex_lock( &_MutexWait ) ) {
1475 perror("EventW pthread_mutex_lock ") ;
1480 cdebug << "EventW inconsistent SuspendState" << endl ;
1485 if ( aNode->IsDone() ) {
1489 cdebug << "EventW NOT SuspendedState _EventNodes.size() "
1490 << _EventNodes.size() << endl ;
1495 cdebug << "EventW " << aNode->Name() << " pthread_cond_wait" << endl ;
1496 while ( _EventNodes.size() == 0 ) {
1497 pthread_cond_wait( &_EventWait , &_MutexWait );
1499 ThreadsNumber = Threads() ;
1500 NodeName = _EventNodes.front() ;
1501 theEvent = _Events.front() ;
1502 anEvent = AutomatonGraphEvent( theEvent ) ;
1503 theState = _States.front() ;
1504 aState = AutomatonGraphState( theState ) ;
1508 *aNodeName = NodeName ;
1509 cdebug << "<-- EventW RetVal " << RetVal << " " << NodeName
1510 << " Threads " << Threads() << " SuspendedThreads "
1511 << SuspendedThreads()
1512 << " _EventNodes.size() " << _EventNodes.size()
1513 << " " << theAutomaton->EventName( theEvent ) << " "
1514 << theAutomaton->StateName( theState ) << endl ;
1515 if ( pthread_mutex_unlock( &_MutexWait ) ) {
1516 perror("EventW pthread_mutex_lock ") ;
1521 long GraphExecutor::OutNode::EventQSize() {
1522 return _EventNodes.size() ;
1525 void GraphExecutor::OutNode::EventList() {
1526 if ( pthread_mutex_lock( &_MutexWait ) ) {
1527 perror("EventList pthread_mutex_lock ") ;
1530 list< char * >::iterator itEventNodes = _EventNodes.begin() ;
1531 list< GraphExecutor::NodeEvent >::iterator itEvents = _Events.begin() ;
1532 list< GraphExecutor::AutomatonState >::iterator itStates = _States.begin() ;
1533 while ( itEventNodes != _EventNodes.end() ) {
1534 cdebug << pthread_self() << "EVENTSTACK "
1535 << *itEventNodes << " " << *itEvents << " "
1536 << theAutomaton->StateName( *itStates )
1537 << " Threads " << Threads() << " SuspendedThreads " << SuspendedThreads() << endl ;
1542 if ( pthread_mutex_unlock( &_MutexWait ) ) {
1543 perror("EventList pthread_mutex_lock ") ;
1548 void GraphExecutor::OutNode::SendSomeDataReady( const char * aNodeName ) {
1549 cdebug_in << "GraphExecutor::OutNode::SendSomeDataReady " << aNodeName << "->SendSomeDataReady( "
1550 << Graph()->Name() << " )" << endl;
1552 sts = ((GraphExecutor::InNode * ) Graph()->GetChangeGraphNode( aNodeName )->GetInNode())->SendSomeDataReady( Graph()->Name() ) ;
1553 cdebug_out << "GraphExecutor::OutNode::SendSomeDataReady sts " << sts << endl ;
1556 void GraphExecutor::OutNode::State(GraphExecutor::AutomatonState aState ) {
1557 // cdebug << "GraphExecutor::OutNode::State " << Graph()->Name() << " "
1558 // << theAutomaton->StateName( AutomatonGraphState( _State ) ) << " ---> "
1559 // << theAutomaton->StateName( AutomatonGraphState( aState ) ) << endl ;
1563 SUPERV::GraphState GraphExecutor::OutNode::State() {
1564 // cdebug_in << "GraphExecutor::OutNode::State" << endl;
1565 // cdebug_out << "GraphExecutor::OutNode::State" << endl ;
1566 // cdebug << "GraphExecutor::OutNode::State GraphState "
1567 // << theAutomaton->StateName( AutomatonGraphState( _State ) ) << endl ;
1568 return AutomatonGraphState( _State ) ;
1571 SUPERV::GraphState GraphExecutor::OutNode::State( const char * NodeName ) {
1572 // cdebug_in << "GraphExecutor::OutNode::State " << NodeName << endl;
1573 GraphExecutor::AutomatonState aret = GraphExecutor::UnKnownState ;
1574 const GraphBase::ComputingNode * aCNode = Graph()->GetGraphNode( NodeName ) ;
1576 GraphExecutor::InNode *anInNode = (GraphExecutor::InNode *)aCNode->GetInNode() ;
1578 aret = anInNode->State() ;
1579 // asv 27.01.05 - fix for PAL7849, return "Loading" state only if internal state is SUPERV::RunningState
1580 if ( ( aret == GraphExecutor::ExecutingState ||
1581 aret == GraphExecutor::ResumedExecutingState ) &&
1582 anInNode->IsLoading() )
1583 aret = GraphExecutor::LoadingState;
1584 // cdebug << "GraphExecutor::OutNode::State( " << NodeName << " ) "
1585 // << theAutomaton->StateName( AutomatonGraphState( aret ) ) << endl ;
1588 // cdebug_out << "GraphExecutor::OutNode::State" << endl ;
1589 return AutomatonGraphState( aret ) ;
1592 SUPERV::GraphState GraphExecutor::OutNode::State( const char * NodeName ,
1593 const char * ServiceParameterName ) {
1594 // cdebug_in << "GraphExecutor::OutNode::State " << NodeName << " "
1595 // << ServiceParameterName<< endl;
1596 SUPERV::GraphState aret = Graph()->PortState( NodeName , ServiceParameterName ) ;
1597 // cdebug_out << "GraphExecutor::OutNode::State" << endl ;
1601 GraphExecutor::AutomatonState GraphExecutor::OutNode::AutomatonState() {
1602 // cdebug_in << "GraphExecutor::OutNode::AutomatonState" << endl;
1603 // cdebug_out << "GraphExecutor::OutNode::AutomatonState" << endl ;
1607 GraphExecutor::AutomatonState GraphExecutor::OutNode::AutomatonState( const char * NodeName ) {
1608 // cdebug_in << "GraphExecutor::OutNode::AutomatonState " << NodeName << endl;
1609 GraphExecutor::AutomatonState aret = GraphExecutor::UnKnownState ;
1610 const GraphBase::ComputingNode * aNode = Graph()->GetGraphNode( NodeName ) ;
1612 GraphExecutor::InNode *anInNode = (GraphExecutor::InNode *) aNode->GetInNode() ;
1614 aret = anInNode->State() ;
1617 // cdebug_out << "GraphExecutor::OutNode::AutomatonState" << endl ;
1621 SUPERV::ControlState GraphExecutor::OutNode::ControlState() {
1622 // cdebug_in << "GraphExecutor::OutNode::ControlState" << endl;
1623 // cdebug_out << "GraphExecutor::OutNode::ControlState" << endl ;
1624 return _ControlState ;
1627 SUPERV::ControlState GraphExecutor::OutNode::ControlState( const char * NodeName ) {
1628 // cdebug_in << "GraphExecutor::OutNode::ControlState " << NodeName << endl;
1629 SUPERV::ControlState aret = SUPERV::VoidState ;
1630 const GraphBase::ComputingNode * aNode = Graph()->GetGraphNode( NodeName ) ;
1632 GraphExecutor::InNode *anInNode = (GraphExecutor::InNode *) aNode->GetInNode() ;
1634 aret = anInNode->ControlState() ;
1637 // cdebug_out << "GraphExecutor::OutNode::ControlState" << endl ;
1641 void GraphExecutor::OutNode::ControlClear() {
1642 // cdebug_in << "GraphExecutor::OutNode::ControlClear" << endl;
1643 // cdebug_out << "GraphExecutor::OutNode::ControlClear" << endl ;
1644 _ControlState = SUPERV::VoidState;
1647 void GraphExecutor::OutNode::ControlClear( const char * NodeName ) {
1648 // cdebug_in << "GraphExecutor::OutNode::ControlClear " << NodeName << endl;
1649 const GraphBase::ComputingNode * aNode = Graph()->GetGraphNode( NodeName ) ;
1651 GraphExecutor::InNode *anInNode = (GraphExecutor::InNode *) aNode->GetInNode() ;
1653 anInNode->ControlClear() ;
1656 // cdebug_out << "GraphExecutor::OutNode::ControlClear" << endl ;
1659 bool GraphExecutor::OutNode::IsWaiting() {
1660 // cdebug_in << "GraphExecutor::OutNode::IsWaiting" << endl;
1661 // cdebug_out << "GraphExecutor::OutNode::IsWaiting" << endl ;
1665 bool GraphExecutor::OutNode::IsReady() {
1666 // cdebug_in << "GraphExecutor::OutNode::IsReady" << endl;
1667 // cdebug_out << "GraphExecutor::OutNode::IsReady" << endl ;
1671 bool GraphExecutor::OutNode::IsRunning() {
1672 // cdebug_in << "GraphExecutor::OutNode::IsRunning" << endl;
1673 // cdebug_out << "GraphExecutor::OutNode::IsRunning" << endl ;
1677 bool GraphExecutor::OutNode::IsDone() {
1678 // cdebug_in << "GraphExecutor::OutNode::IsDone" << endl;
1679 // cdebug_out << "GraphExecutor::OutNode::IsDone" << endl ;
1680 return ( Done() || IsKilled() || IsStopped() ) ;
1683 bool GraphExecutor::OutNode::IsSuspended() {
1684 // cdebug_in << "GraphExecutor::OutNode::IsSuspended" << endl;
1686 // if ( _SuspendedThreads == _Threads && _Threads != 0 ) {
1687 if ( AutomatonGraphState( _State ) == SUPERV::SuspendState ) {
1690 // cdebug_out << "GraphExecutor::OutNode::IsSuspended" << endl ;
1694 bool GraphExecutor::OutNode::IsKilled() {
1695 // cdebug_in << "GraphExecutor::OutNode::IsKilled" << endl;
1697 if ( AutomatonGraphState( _State ) == SUPERV::KillState ) {
1700 // cdebug_out << "GraphExecutor::OutNode::IsKilled" << endl ;
1704 bool GraphExecutor::OutNode::IsStopped() {
1705 // cdebug_in << "GraphExecutor::OutNode::IsStopped" << endl;
1707 if ( AutomatonGraphState( _State ) == SUPERV::StopState ) {
1710 // cdebug_out << "GraphExecutor::OutNode::IsStopped" << endl ;
1714 bool GraphExecutor::OutNode::IsWaiting( const char * NodeName ) {
1716 // cdebug_in << "GraphExecutor::OutNode::IsWaiting " << NodeName << endl;
1717 GraphExecutor::InNode *anInNode = (GraphExecutor::InNode *) Graph()->GetGraphNode( NodeName )->GetInNode() ;
1719 aret = anInNode->IsWaiting() ;
1721 // cdebug_out << "GraphExecutor::OutNode::IsWaiting" << endl ;
1725 bool GraphExecutor::OutNode::IsReady( const char * NodeName ) {
1727 // cdebug_in << "GraphExecutor::OutNode::IsReady " << NodeName << endl;
1728 GraphExecutor::InNode *anInNode = (GraphExecutor::InNode *) Graph()->GetGraphNode( NodeName )->GetInNode() ;
1730 aret = anInNode->IsReady() ;
1732 // cdebug_out << "GraphExecutor::OutNode::IsReady" << endl ;
1736 bool GraphExecutor::OutNode::IsRunning( const char * NodeName ) {
1738 // cdebug_in << "GraphExecutor::OutNode::IsRunning " << NodeName << endl;
1739 GraphExecutor::InNode *anInNode = (GraphExecutor::InNode *) Graph()->GetGraphNode( NodeName )->GetInNode() ;
1741 aret = anInNode->IsRunning() ;
1743 // cdebug_out << "GraphExecutor::OutNode::IsRunning" << endl ;
1747 bool GraphExecutor::OutNode::IsDone( const char * NodeName ) {
1749 // cdebug_in << "GraphExecutor::OutNode::IsDone " << NodeName << endl;
1750 GraphExecutor::InNode *anInNode = (GraphExecutor::InNode *) Graph()->GetGraphNode( NodeName )->GetInNode() ;
1752 aret = anInNode->IsDone() ;
1754 // cdebug_out << "GraphExecutor::OutNode::IsDone" << endl ;
1758 bool GraphExecutor::OutNode::IsSuspended( const char * NodeName ) {
1760 // cdebug_in << "GraphExecutor::OutNode::IsSuspended " << NodeName << endl;
1761 GraphExecutor::InNode *anInNode = (GraphExecutor::InNode *) Graph()->GetGraphNode( NodeName )->GetInNode() ;
1763 aret = anInNode->IsSuspended() ;
1765 // cdebug_out << "GraphExecutor::OutNode::IsSuspended" << endl ;
1769 bool GraphExecutor::OutNode::PortDone( const char * NodeName ,
1770 const char * ServiceParameterName ) {
1771 // cdebug_in << "GraphExecutor::OutNode::IsDone " << NodeName << " "
1772 // << ServiceParameterName<< endl;
1773 bool aret = Graph()->PortDone( NodeName , ServiceParameterName ) ;
1774 // cdebug_out << "GraphExecutor::OutNode::IsDone" << endl ;
1778 bool GraphExecutor::OutNode::ContainerKill() {
1779 bool RetVal = true ;
1780 cdebug_in << "GraphExecutor::OutNode::ContainerKill" << endl;
1781 _ControlState = SUPERV::ToSuspendState ;
1783 for ( i = 0 ; i < Graph()->GraphNodesSize() ; i++ ) {
1784 GraphExecutor::InNode * aNode = (GraphExecutor::InNode * ) Graph()->GraphNodes( i )->GetInNode() ;
1785 bool sts = aNode->ContainerKill() ;
1786 if ( sts && aNode->IsKilled() ) {
1787 cdebug << aNode->Name() << " killed" << endl ;
1789 else if ( aNode->IsWaiting() || aNode->IsDone() ) {
1790 cdebug << aNode->Name() << " not killed : "
1791 << theAutomaton->StateName( aNode->State() ) << endl ;
1794 cdebug << aNode->Name() << " cannot be killed : "
1795 << theAutomaton->StateName( aNode->State() ) << endl ;
1799 if ( !RetVal || Threads() != 0 ) {
1800 for ( i = 0 ; i < Graph()->GraphNodesSize() ; i++ ) {
1801 GraphExecutor::InNode * aNode = (GraphExecutor::InNode * ) Graph()->GraphNodes( i )->GetInNode() ;
1802 if ( !aNode->IsKilled() && !aNode->IsWaiting() && !aNode->IsDone() ) {
1803 aNode->KilledAction() ;
1808 State( GraphExecutor::KilledState ) ;
1809 cdebug_out << "GraphExecutor::OutNode::ContainerKill" << endl ;
1813 bool GraphExecutor::OutNode::Suspend() {
1815 cdebug_in << "GraphExecutor::OutNode::Suspend" << endl;
1816 // _ControlState = SUPERV::ToSuspendState ;
1818 for ( i = 0 ; i < Graph()->GraphNodesSize() ; i++ ) {
1819 GraphExecutor::InNode * aNode = (GraphExecutor::InNode * ) Graph()->GraphNodes( i )->GetInNode() ;
1820 bool sts = aNode->Suspend() ;
1821 if ( sts && aNode->IsSuspended() ) {
1823 cdebug << aNode->Name() << " Suspended" << endl ;
1825 else if ( aNode->IsWaiting() || aNode->IsReady() ) {
1827 cdebug << aNode->Name() << " will be Suspended" << endl ;
1829 else if ( aNode->IsDone() ) {
1830 cdebug << aNode->Name() << " not Suspended : "
1831 << theAutomaton->StateName( aNode->State() ) << endl ;
1835 cdebug << aNode->Name() << " cannot be Suspended : "
1836 << theAutomaton->StateName( aNode->State() ) << endl ;
1840 State( GraphExecutor::SuspendedState ) ;
1841 MESSAGE("================================================================================") ;
1842 MESSAGE( Graph()->Name() << " IS SUSPENDED" ) ;
1843 MESSAGE("================================================================================") ;
1846 MESSAGE("================================================================================") ;
1847 MESSAGE( Graph()->Name() << " IS NOT SUSPENDED" ) ;
1848 MESSAGE("================================================================================") ;
1850 for ( i = 0 ; i < Graph()->GraphNodesSize() ; i++ ) {
1851 GraphExecutor::InNode * aNode = (GraphExecutor::InNode * ) Graph()->GraphNodes( i )->GetInNode() ;
1852 MESSAGE(aNode->Name() << " " << theAutomaton->StateName( aNode->State() ) ) ;
1853 cdebug << aNode->Name() << " " << theAutomaton->StateName( aNode->State() ) << endl ;
1855 cdebug_out << "GraphExecutor::OutNode::Suspend " << theAutomaton->StateName( State() )
1856 << " EventQSize " << EventQSize() << endl ;
1860 bool GraphExecutor::OutNode::Resume() {
1862 cdebug_in << "GraphExecutor::OutNode::Resume "
1863 << theAutomaton->StateName( State() ) << endl;
1864 if ( IsSuspended() ) {
1865 State( GraphExecutor::ExecutingState ) ;
1867 for ( i = 0 ; i < Graph()->GraphNodesSize() ; i++ ) {
1868 GraphExecutor::InNode * aNode = (GraphExecutor::InNode * ) Graph()->GraphNodes( i )->GetInNode() ;
1869 aNode->ControlState( SUPERV::VoidState ) ;
1870 if ( aNode->IsSuspended() ) {
1871 cdebug << aNode->Name() << "->Resume " << theAutomaton->StateName( aNode->State() )
1873 if ( aNode->Resume() ) {
1874 cdebug << aNode->Name() << " Resumed " << theAutomaton->StateName( aNode->State() )
1879 cdebug << aNode->Name() << " Resume failed"
1880 << theAutomaton->StateName( aNode->State() ) << endl ;
1884 cdebug << aNode->Name() << " " << theAutomaton->StateName( aNode->State() )
1890 cdebug << Graph()->Name() << " not suspended " << theAutomaton->StateName( State() ) << endl ;
1893 MESSAGE("================================================================================") ;
1894 MESSAGE( Graph()->Name() << " IS RESUMED" ) ;
1895 MESSAGE("================================================================================") ;
1898 MESSAGE("================================================================================") ;
1899 MESSAGE( Graph()->Name() << " IS NOT RESUMED" ) ;
1900 MESSAGE("================================================================================") ;
1903 for ( i = 0 ; i < Graph()->GraphNodesSize() ; i++ ) {
1904 GraphExecutor::InNode * aNode = (GraphExecutor::InNode * ) Graph()->GraphNodes( i )->GetInNode() ;
1905 MESSAGE(aNode->Name() << " " << theAutomaton->StateName( aNode->State() ) ) ;
1906 cdebug << aNode->Name() << " " << theAutomaton->StateName( aNode->State() ) << endl ;
1908 cdebug_out << "GraphExecutor::OutNode::Resume" << theAutomaton->StateName( State() ) << " " << RetVal
1909 << " EventQSize " << EventQSize() << endl ;
1913 bool GraphExecutor::OutNode::Kill() {
1914 bool RetVal = false ;
1915 cdebug_in << "GraphExecutor::OutNode::Kill"
1916 << " EventQSize " << EventQSize() << " State "
1917 << theAutomaton->StateName( State() ) << endl;
1919 cdebug_out << "GraphExecutor::OutNode::Kill " << RetVal
1920 << " Threads " << _Threads << " SuspendedThreads " << _SuspendedThreads
1921 << " EventQSize " << EventQSize() << " State "
1922 << theAutomaton->StateName( State() ) << endl ;
1925 _ControlState = SUPERV::ToSuspendState ;
1927 for ( i = 0 ; i < Graph()->GraphNodesSize() ; i++ ) {
1928 GraphExecutor::InNode * aNode = (GraphExecutor::InNode * ) Graph()->GraphNodes( i )->GetInNode() ;
1929 bool sts = aNode->Kill() ;
1930 if ( sts && Threads() != 0 ) {
1931 if ( !aNode->IsKilled() ) {
1932 cdebug << aNode->Name() << " not killed : "
1933 << theAutomaton->StateName( aNode->State() ) << " " << aNode->Name() << "->"
1934 << "KilledAction()" << endl ;
1935 MESSAGE( aNode->Name() << " not killed : KilledAction()" ) ;
1936 aNode->KilledAction() ;
1938 if ( aNode->IsKilled() ) {
1939 cdebug << aNode->Name() << " killed" << endl ;
1944 // JR 24.03.2005 Debug : the node may have been killed
1945 else if ( aNode->IsKilled() ) {
1946 cdebug << aNode->Name() << " killed" << endl ;
1949 else if ( aNode->IsWaiting() || aNode->IsDone() ) {
1950 cdebug << aNode->Name() << " not killed : "
1951 << theAutomaton->StateName( aNode->State() ) << endl ;
1954 cdebug << aNode->Name() << " cannot be killed : "
1955 << theAutomaton->StateName( aNode->State() ) << endl ;
1959 State( GraphExecutor::KilledState ) ;
1960 MESSAGE("================================================================================") ;
1961 MESSAGE( Graph()->Name() << " IS KILLED" << theAutomaton->StateName( AutomatonState() ) << " EventQSize "
1963 MESSAGE("================================================================================") ;
1966 MESSAGE("================================================================================") ;
1967 MESSAGE( Graph()->Name() << " IS NOT KILLED" ) ;
1968 MESSAGE("================================================================================") ;
1970 for ( i = 0 ; i < Graph()->GraphNodesSize() ; i++ ) {
1971 GraphExecutor::InNode * aNode = (GraphExecutor::InNode * ) Graph()->GraphNodes( i )->GetInNode() ;
1972 MESSAGE(aNode->Name() << " " << theAutomaton->StateName( aNode->State() ) ) ;
1973 cdebug << aNode->Name() << " " << theAutomaton->StateName( aNode->State() ) << endl ;
1976 if ( pthread_mutex_lock( &_MutexWait ) ) {
1977 perror("EventLoop pthread_mutex_lock ") ;
1981 //JR 23.02.2005, Debug : siftEvents() must be inside the pthread_mutex_lock
1982 // remove "extra" events from the event queue
1984 if ( pthread_mutex_unlock( &_MutexWait ) ) {
1985 perror("PushEvent pthread_mutex_unlock ") ;
1989 // asv : 25.10.04 : calling Editing() to indicate stop of execution
1990 Graph()->GraphEditor()->Editing();
1992 cdebug_out << "GraphExecutor::OutNode::Kill " << RetVal
1993 << " Threads " << _Threads << " SuspendedThreads " << _SuspendedThreads
1994 << " EventQSize " << EventQSize() << endl ;
1999 bool GraphExecutor::OutNode::Stop() {
2000 bool RetVal = false ;
2001 cdebug_in << "GraphExecutor::OutNode::Stop" << endl;
2003 cdebug_out << "GraphExecutor::OutNode::Stop" << endl ;
2005 MESSAGE("================================================================================") ;
2006 MESSAGE( Graph()->Name() << " IS STOPPED" ) ;
2007 MESSAGE("================================================================================") ;
2012 bool GraphExecutor::OutNode::ReadyWait() {
2013 cdebug_in << "GraphExecutor::OutNode::ReadyWait" << endl;
2015 if ( pthread_mutex_lock( &_MutexWait ) ) {
2016 perror("pthread_mutex_lock _ReadyWait") ;
2022 pthread_cond_wait( &_EventWait , &_MutexWait );
2025 if ( pthread_mutex_unlock( &_MutexWait ) ) {
2026 perror("pthread_mutex_lock _ReadyWait") ;
2029 cdebug_out << "GraphExecutor::OutNode::ReadyWait" << endl ;
2033 bool GraphExecutor::OutNode::RunningWait() {
2034 cdebug_in << "GraphExecutor::OutNode::RunningWait" << endl;
2036 if ( pthread_mutex_lock( &_MutexWait ) ) {
2037 perror("pthread_mutex_lock _RunningWait") ;
2040 aret = IsRunning() ;
2042 cdebug << "RunningWait pthread_cond_wait _EventWait" << endl;
2043 pthread_cond_wait( &_EventWait , &_MutexWait );
2044 aret = IsRunning() ;
2045 cdebug << "RunningWait pthread_cond_waited _EventWait " << aret << endl;
2047 if ( pthread_mutex_unlock( &_MutexWait ) ) {
2048 perror("pthread_mutex_lock _RunningWait") ;
2051 cdebug_out << "GraphExecutor::OutNode::RunningWait " << aret << endl ;
2055 bool GraphExecutor::OutNode::DoneWait() {
2056 cdebug_in << pthread_self() << " GraphExecutor::DoneWait " << this << " " << Graph()->Name() << endl;
2058 if ( pthread_mutex_lock( &_MutexWait ) ) {
2059 perror("pthread_mutex_lock _DoneWait") ;
2063 while ( !aret && !IsSuspended() && IsRunning() ) {
2064 cdebug << pthread_self() << " GraphExecutor::DoneWait " << this << " " << Graph()->Name()
2065 << " DoneWait pthread_cond_wait _EventWait " << &_EventWait << endl;
2066 pthread_cond_wait( &_EventWait , &_MutexWait );
2068 cdebug << pthread_self() << " GraphExecutor::DoneWait " << this << " " << Graph()->Name()
2069 << " DoneWait pthread_cond_waited _EventWaited " << &_EventWait << " : "<< aret << endl;
2071 if ( pthread_mutex_unlock( &_MutexWait ) ) {
2072 perror("pthread_mutex_lock _DoneWait") ;
2075 cdebug_out << pthread_self() << " GraphExecutor::DoneWait " << this << " " << Graph()->Name()
2076 << " " << State() << " : " << aret << endl ;
2080 bool GraphExecutor::OutNode::SuspendedWait() {
2081 cdebug_in << "GraphExecutor::OutNode::SuspendedWait" << endl;
2083 if ( pthread_mutex_lock( &_MutexWait ) ) {
2084 perror("pthread_mutex_lock _SuspendedWait") ;
2087 aret = IsSuspended() ;
2088 while ( !aret && !IsDone() ) {
2089 pthread_cond_wait( &_EventWait , &_MutexWait );
2090 aret = IsSuspended() ;
2092 if ( pthread_mutex_unlock( &_MutexWait ) ) {
2093 perror("pthread_mutex_lock _SuspendedWait") ;
2096 cdebug_out << "GraphExecutor::OutNode::SuspendedWait" << endl ;
2100 bool GraphExecutor::OutNode::ReadyWait( const char * NodeName ) {
2102 cdebug_in << "GraphExecutor::OutNode::ReadyWait " << NodeName << endl;
2103 GraphExecutor::InNode *anInNode = (GraphExecutor::InNode *) Graph()->GetGraphNode( NodeName )->GetInNode() ;
2105 aret = anInNode->ReadyWait() ;
2107 cdebug_out << "GraphExecutor::OutNode::ReadyWait" << endl ;
2111 bool GraphExecutor::OutNode::RunningWait( const char * NodeName ) {
2113 cdebug_in << "GraphExecutor::OutNode::RunningWait " << NodeName << endl;
2114 GraphExecutor::InNode *anInNode = (GraphExecutor::InNode *) Graph()->GetGraphNode( NodeName )->GetInNode() ;
2116 aret = anInNode->RunningWait() ;
2118 cdebug_out << "GraphExecutor::OutNode::RunningWait" << endl ;
2122 bool GraphExecutor::OutNode::DoneWait( const char * NodeName ) {
2124 cdebug_in << "GraphExecutor::OutNode::DoneWait " << NodeName << endl;
2125 GraphExecutor::InNode *anInNode = (GraphExecutor::InNode *) Graph()->GetGraphNode( NodeName )->GetInNode() ;
2127 aret = anInNode->DoneWait() ;
2129 cdebug_out << "GraphExecutor::OutNode::DoneWait" << endl ;
2133 bool GraphExecutor::OutNode::SuspendedWait( const char * NodeName ) {
2135 cdebug_in << "GraphExecutor::OutNode::SuspendedWait " << NodeName << endl;
2136 GraphExecutor::InNode *anInNode = (GraphExecutor::InNode *) Graph()->GetGraphNode( NodeName )->GetInNode() ;
2138 aret = anInNode->SuspendedWait() ;
2140 cdebug_out << "GraphExecutor::OutNode::SuspendedWait" << endl ;
2144 long GraphExecutor::OutNode::LastLevelDone() {
2147 for ( i = 0 ; i <= Graph()->LevelMax() ; i++ ) {
2148 for ( j = 0 ; j <= Graph()->NodesNumber( i ) ; j++ ) {
2149 GraphBase::ComputingNode * aNode = Graph()->SortedNodes( i , j ) ;
2150 if ( !IsDone( aNode->Name() ) ) {
2154 if ( j != Graph()->NodesNumber( i ) + 1 )
2162 //JR 30.03.2005const CORBA::Any *GraphExecutor::OutNode::GetInData( const char * NodeName ,
2163 const CORBA::Any GraphExecutor::OutNode::GetInData( const char * NodeName ,
2164 const char * ServiceParameterName ) {
2165 // cdebug_in << "GraphExecutor::OutNode::GetInData " << NodeName << " "
2166 // << ServiceParameterName << endl ;
2167 //JR 30.03.2005 const CORBA::Any * retdata = Graph()->PortInData( NodeName , ServiceParameterName ) ;
2168 const CORBA::Any retdata = Graph()->PortInData( NodeName , ServiceParameterName ) ;
2169 // cdebug_out << "GraphExecutor::OutNode::GetInData" << endl ;
2173 //JR 30.03.2005const CORBA::Any *GraphExecutor::OutNode::GetOutData( const char * NodeName ,
2174 const CORBA::Any GraphExecutor::OutNode::GetOutData( const char * NodeName ,
2175 const char * ServiceParameterName ) {
2176 // cdebug_in << "GraphExecutor::OutNode::GetOutData " << NodeName << " "
2177 // << ServiceParameterName << endl ;
2178 //JR 30.03.2005 const CORBA::Any * retdata = Graph()->PortOutData( NodeName , ServiceParameterName ) ;
2179 const CORBA::Any retdata = Graph()->PortOutData( NodeName , ServiceParameterName ) ;
2180 // cdebug_out << "GraphExecutor::OutNode::GetOutData" << endl ;
2184 const long GraphExecutor::OutNode::CpuUsed() {
2185 return Graph()->CpuUsed() ;
2188 const long GraphExecutor::OutNode::CpuUsed( const char * aNodeName ) {
2189 GraphBase::ComputingNode * aNode = Graph()->GetChangeGraphNode( aNodeName ) ;
2191 GraphExecutor::InNode * anInNode = (GraphExecutor::InNode * ) aNode->GetInNode() ;
2193 return anInNode->CpuUsed() ;
2199 // remove equal sets "Node-Event-State" from _EventNodes/_Events/_States queues
2200 void GraphExecutor::OutNode::siftEvents() {
2201 list<char*>::reverse_iterator itNodes = _EventNodes.rbegin();
2202 list<GraphExecutor::NodeEvent>::reverse_iterator itEvents = _Events.rbegin();
2203 list<GraphExecutor::AutomatonState>::reverse_iterator itStates = _States.rbegin();
2204 list<char*> _NewEventNodes;
2205 list<GraphExecutor::NodeEvent> _NewEvents;
2206 list<GraphExecutor::AutomatonState> _NewStates;
2207 for ( ; itNodes != _EventNodes.rend() ; ++itNodes, ++itEvents, ++itStates) {
2208 //cout << "----- aNodeName ==> " << *itNodes;
2209 list<char*>::reverse_iterator itNewNodes = _NewEventNodes.rbegin();
2211 for ( ; itNewNodes != _NewEventNodes.rend() ; ++itNewNodes ) {
2212 if ( !strcmp( *itNewNodes, *itNodes ) ) {
2222 _NewEventNodes.push_back( *itNodes );
2223 _NewEvents.push_back( *itEvents );
2224 _NewStates.push_back( *itStates );
2228 _EventNodes = _NewEventNodes;
2229 _Events = _NewEvents;
2230 _States = _NewStates;