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 << " )"
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 ) ;
544 State( GraphExecutor::ErroredState ) ;
545 cdebug_out << "GraphExecutor::OutNode::Run InitPythonFunctions ERROR "
546 << anInNode->Name() << endl ;
551 /* asv : 29.09.04 : commented out because it does not do anything useful
552 for ( i = 0 ; i < Graph()->GraphNodesSize() ; i++ ) {
553 GraphExecutor::InNode * anInNode = (GraphExecutor::InNode *) Graph()->GraphNodes( i )->GetInNode() ;
554 if ( RetVal && anInNode->IsMacroNode() ) {
555 GraphBase::Graph * aMacroGraph = anInNode->GraphMacroNode() ;
556 cdebug << "GraphExecutor::OutNode::Run " << anInNode << " MacroNode " << aMacroGraph
557 << aMacroGraph->Name() << endl ;
558 SUPERV::Graph_var iobject = anInNode->GraphMacroNode()->MacroObject() ;
559 if ( CORBA::is_nil( iobject ) ) {
560 cdebug << "GraphExecutor::OutNode::Run MacroObject() is a nil object. Error" << endl ;
564 cdebug << "GraphExecutor::OutNode::Run MacroObject() is NOT a nil object." << endl ;
569 if ( Graph()->GraphMacroLevel() != 0 ) {
570 cdebug << "GraphExecutor::OutNode::Run Execution starting GraphExecutor::Action_DataOk_RunService Node "
571 << Graph()->Name() << " GraphMacroLevel " << Graph()->GraphMacroLevel() << endl ;
572 PushEvent( NULL , GraphExecutor::NoDataReadyEvent ,
573 GraphExecutor::DataUndefState ) ;
576 cdebug << "Execution starting GraphExecutor::Action_DataOk_RunService Node "
577 << Graph()->Name() << " GraphMacroLevel " << Graph()->GraphMacroLevel() << endl ;
578 PushEvent( NULL , GraphExecutor::ReadyEvent ,
579 GraphExecutor::DataReadyState ) ;
580 State( GraphExecutor::DataReadyState ) ;
582 cdebug << pthread_self() << " GraphExecutor::OutNode::Run Start of the " << Graph()->HeadNodesSize()
583 << " HeadNodes" << endl ;
584 for ( i = 0 ; i < Graph()->HeadNodesSize() ; i++ ) {
585 GraphExecutor::InNode * anInNode = (GraphExecutor::InNode *) Graph()->HeadNodes( i )->GetInNode() ;
586 cdebug << pthread_self() << "GraphExecutor::OutNode::Run Start of HeadNode " << i << " "
587 << anInNode->Name() << endl ;
588 if ( anInNode->State() != GraphExecutor::DataReadyState ) {
589 cdebug << "GraphExecutor::OutNode::Run inconsistency State of Node "
590 << anInNode->Name() << " : " << anInNode->State() << endl ;
591 cdebug_out << "GraphExecutor::OutNode::Run State ERROR" << endl ;
594 // PushEvent( anInNode , GraphExecutor::ReadyEvent ,
595 // GraphExecutor::DataReadyState ) ;
596 // We say that we have to create a thread for that HeadNode 'anInNode'
597 anInNode->CreateNewThread( true ) ;
598 IncrCreatedThreads() ;
599 anInNode->DataFromNode( Graph()->Name() ) ;
600 // AndSuspend == true <==> Start()
602 anInNode->State( GraphExecutor::DataWaitingState ) ;
603 anInNode->ControlState( SUPERV::ToSuspendStartState ) ;
604 // We send SomeDataReadyEvent
605 // It is a HeadNode ==> AllDataReadyEvent ==> InNode::executeAction() ==> pthread_create
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 // ==> We wait for SuspendedState
613 anInNode->SuspendedWait() ;
615 // AndSuspend == false <==> Run()
616 else if ( anInNode->IsMacroNode() ) {
617 if ( !anInNode->SendEvent( GraphExecutor::SomeDataReadyEvent ) ) {
618 cdebug << "InNode::SendEvent( SomeDataReadyEvent ) ERROR Node "
619 << anInNode->Name() << endl ;
620 cdebug_out << "GraphExecutor::OutNode::Run SendEvent ERROR" << endl ;
623 cdebug << pthread_self() << " GraphExecutor::OutNode::Run " << anInNode->Name() << "->RunningWait"
625 // ==> We wait for RunningState
626 anInNode->RunningWait() ;
627 cdebug << pthread_self() << " GraphExecutor::OutNode::Run " << anInNode->Name() << "->RunningWaited"
630 else if ( !anInNode->IsMacroNode() ) {
631 // It is a HeadNode ==> AllDataReadyEvent ==> InNode::executeAction() ==> pthread_create
632 if ( !anInNode->SendEvent( GraphExecutor::ExecuteEvent ) ) {
633 cdebug << "InNode::SendEvent( ExecuteEvent ) ERROR Node "
634 << anInNode->Name() << endl ;
635 cdebug_out << "GraphExecutor::OutNode::Run SendEvent ERROR" << endl ;
638 // ==> We wait for RunningState
639 anInNode->RunningWait() ;
644 PushEvent( NULL , GraphExecutor::SuspendedReadyEvent ,
645 GraphExecutor::SuspendedReadyState ) ;
648 PushEvent( NULL , GraphExecutor::ExecutingEvent ,
649 GraphExecutor::ExecutingState ) ;
650 if (AutomatonState() == GraphExecutor::DataReadyState) {
651 State( GraphExecutor::ExecutingState ) ;
654 // ostringstream astr ;
655 // astr << "Graph " << Graph()->Name() << " is running" ;
656 // Graph()->ObjImpl()->sendMessage( NOTIF_STEP, astr.str().c_str() ) ;
661 cdebug_out << pthread_self() << "GraphExecutor::OutNode::Run " << Graph()->Name()
662 << " GraphMacroLevel "
663 << Graph()->GraphMacroLevel() << " RetVal " << RetVal << endl ;
667 void GraphExecutor::OutNode::CheckAllDone() {
669 cdebug_in << "GraphExecutor::OutNode::CheckAllDone " << endl;
670 GraphExecutor::AutomatonState OutNodeState = GraphExecutor::SuccessedState ;
671 GraphExecutor::AutomatonState InNodeState ;
672 bool AllDone = true ;
674 for ( j = 0 ; j < Graph()->QueueNodesSize() ; j++ ) {
675 InNodeState = ( (GraphExecutor::InNode * ) Graph()->QueueNodes( j )->GetInNode() )->State() ;
677 << ( (GraphExecutor::InNode * ) Graph()->QueueNodes( j )->GetInNode() )->Name()
678 << " " << theAutomaton->StateName( InNodeState ) << endl ;
679 if ( InNodeState != GraphExecutor::SuccessedState &&
680 InNodeState != GraphExecutor::ErroredState &&
681 InNodeState != GraphExecutor::DataWaitingState ) {
684 if ( InNodeState != GraphExecutor::SuccessedState &&
685 InNodeState != GraphExecutor::DataWaitingState &&
686 InNodeState != GraphExecutor::DataReadyState ) {
687 OutNodeState = InNodeState ;
691 if( _Threads == 0 && _SuspendedThreads == 0 ) {
692 if ( OutNodeState != GraphExecutor::ErroredState ) {
693 OutNodeState = GraphExecutor::SuccessedState ;
702 for ( j = 0 ; j < Graph()->GraphNodesSize() ; j++ ) {
703 GraphExecutor::InNode * aNode ;
704 aNode = (GraphExecutor::InNode * ) Graph()->GraphNodes( j )->GetInNode() ;
705 SUPERV::GraphState aState = AutomatonGraphState( aNode->State() ) ;
706 cdebug << "GraphExecutor::OutNode::CheckAllDone " << aNode->Name() << " "
707 << theAutomaton->StateName( aNode->State() ) << " CreateNewThread " << aNode->CreateNewThread()
709 if ( aState == SUPERV::ErrorState ||
710 aState == SUPERV::SuspendErroredState ||
711 aState == SUPERV::KillState ||
712 aState == SUPERV::StopState ) {
713 OutNodeState = aNode->State() ;
714 State( OutNodeState ) ;
716 else if ( aState == SUPERV::ReadyState ||
717 aState == SUPERV::SuspendReadyState ||
718 aState == SUPERV::RunningState ||
719 aState == SUPERV::SuspendDoneState ||
720 aState == SUPERV::SuspendErroredState ||
721 aState == SUPERV::SuspendState ) {
724 aNode->SuspendedAction() ;
725 aNode->DoneAction() ;
727 // PushEvent AFTER State and _Done ! ...
728 if ( alivenodes == 0 ) {
729 State( OutNodeState ) ;
731 _JustStarted = false ;
733 cdebug << Graph()->Name() << " alivenodes " << alivenodes << " OutNodeState " << OutNodeState
735 PushEvent( NULL , GraphExecutor::EndExecuteEvent ,
738 // PyInitialized( false ) ;
742 MESSAGE("================================================================================") ;
743 MESSAGE( Graph()->Name() << " IS DONE : " << theAutomaton->StateName( AutomatonState() ) << " EventQSize "
745 MESSAGE("================================================================================") ;
746 cdebug << "================================================================================" << endl ;
747 cdebug << Graph()->Name() << " IS DONE : " << theAutomaton->StateName( AutomatonState() ) << " EventQSize "
748 << EventQSize() << endl ;
749 cdebug << "================================================================================" << endl ;
751 //JR 23.02.2005, Debug : siftEvents() must be inside the pthread_mutex_lock
752 if ( pthread_mutex_lock( &_MutexWait ) ) {
753 perror("EventLoop pthread_mutex_lock ") ;
756 // asv : fix for 6798 and other bugs: "sift" the event queue after execution
758 if ( pthread_mutex_unlock( &_MutexWait ) ) {
759 perror("PushEvent pthread_mutex_unlock ") ;
763 // asv : 25.10.04 : calling Editing() to indicate stop of execution
764 Graph()->GraphEditor()->Editing();
766 cdebug_out << "GraphExecutor::OutNode::CheckAllDone " << IsDone() << " this " << this << " "
767 << Graph()->Name() << " GraphAutomatonState "
768 << theAutomaton->StateName( AutomatonState() )
769 << " State " << State() << " Threads " << _Threads << " SuspendedThreads "
770 << _SuspendedThreads << " EventQSize " << EventQSize() << endl ;
773 // asv : 20.01.05 : changes involved with switching to old (HEAD) KERNEL
774 //Engines_Container_i * GraphExecutor::OutNode::SuperVisionContainer() {
775 // return _SuperVisionContainer ;
778 //const pthread_t GraphExecutor::OutNode::MainThreadId() const {
779 // return _MainThreadId ;
782 void GraphExecutor::OutNode::PThreadLock( pthread_mutex_t * aMutex , char * errmsg ) {
783 // if ( strcmp( errmsg , "EventLoop" ) && strcmp( errmsg , "EventW" ) ) {
784 // cdebug << "GraphExecutor::OutNode::PThreadLock " << pthread_self() << " " << aMutex << " "
785 // << errmsg << endl ;
787 if ( pthread_mutex_lock( aMutex ) ) {
791 // if ( strcmp( errmsg , "EventLoop" ) && strcmp( errmsg , "EventW" ) ) {
792 // cdebug << "GraphExecutor::OutNode::PThreadLocked " << pthread_self() << " " << aMutex << " "
793 // << errmsg << endl ;
797 void GraphExecutor::OutNode::PThreadUnLock( pthread_mutex_t * aMutex , char * errmsg ) {
798 // if ( strcmp( errmsg , "EventLoop" ) && strcmp( errmsg , "EventW" ) ) {
799 // cdebug << " GraphExecutor::OutNode::PThreadUnLock " << pthread_self() << " " << aMutex << " "
800 // << errmsg << endl ;
802 if ( pthread_mutex_unlock( aMutex ) ) {
808 void GraphExecutor::OutNode::PyThreadLock() {
809 // cout << " GraphExecutor::OutNode::PyThreadLock " << pthread_self() << endl ;
810 if ( pthread_mutex_lock( &_PyMutexWait ) ) {
811 perror( "GraphExecutor::OutNode::PyThreadLock" ) ;
814 theAutomaton->PyLock() ;
815 // cout << " GraphExecutor::OutNode::PyThreadLocked " << pthread_self() << endl ;
818 void GraphExecutor::OutNode::PyThreadUnLock() {
819 // cout << " GraphExecutor::OutNode::PyThreadUnLock " << pthread_self() << endl ;
820 if ( pthread_mutex_unlock( &_PyMutexWait ) ) {
821 perror( "GraphExecutor::OutNode::PyThreadUnLock" ) ;
824 theAutomaton->PyUnLock() ;
825 // cout << " GraphExecutor::OutNode::PyThreadUnLocked " << pthread_self() << endl ;
828 void GraphExecutor::OutNode::NewThread() {
829 if ( pthread_mutex_lock( &_MutexWait ) ) {
830 perror("pthread_mutex_lock _NewThread") ;
834 cdebug << "NewThread : " << _Threads << " running threads "
835 << _SuspendedThreads << " suspended threads"
837 if ( pthread_mutex_unlock( &_MutexWait ) ) {
838 perror("pthread_mutex_unlock _NewThread") ;
843 void GraphExecutor::OutNode::ExitThread( pthread_t ThreadNumber ) {
844 if ( pthread_mutex_lock( &_MutexWait ) ) {
845 perror("pthread_mutex_lock _ExitThread") ;
848 if ( ThreadNumber == 0 ) {
849 ThreadNumber = pthread_self() ;
852 cdebug << pthread_self() << " ExitThread( " << ThreadNumber << " ) " << _Threads << " running threads "
853 << _SuspendedThreads << " suspended threads"
855 theAutomaton->JoinThread( ThreadNumber ) ;
856 if ( pthread_cond_signal( &_JoinWait ) ) {
857 perror("ExitThread pthread_cond_signal ") ;
859 if ( pthread_mutex_unlock( &_MutexWait ) ) {
860 perror("pthread_mutex_unlock _ExitThread") ;
863 if ( _Threads == 0 && _SuspendedThreads == 0 ) {
866 theAutomaton->Executed() ;
870 void GraphExecutor::OutNode::JoinedWait() {
871 if ( pthread_mutex_lock( &_MutexWait ) ) {
872 perror("pthread_mutex_lock JoinedWait") ;
876 if ( pthread_cond_wait( &_JoinWait , &_MutexWait ) ) {
877 perror("JoinedWait pthread_cond_wait ") ;
880 if ( pthread_mutex_unlock( &_MutexWait ) ) {
881 perror("pthread_mutex_unlock JoinedWait") ;
886 void GraphExecutor::OutNode::SuspendThread() {
887 if ( pthread_mutex_lock( &_MutexWait ) ) {
888 perror("pthread_mutex_lock _SuspendThread") ;
891 _SuspendedThreads += 1 ;
892 cdebug << "SuspendThread : " << _Threads << " running threads "
893 << _SuspendedThreads << " suspended threads"
895 if ( pthread_mutex_unlock( &_MutexWait ) ) {
896 perror("pthread_mutex_unlock _SuspendThread") ;
899 if ( IsSuspended() ) {
900 PushEvent( NULL , GraphExecutor::SuspendEvent , GraphExecutor::SuspendedState ) ;
903 void GraphExecutor::OutNode::ResumeThread() {
904 if ( pthread_mutex_lock( &_MutexWait ) ) {
905 perror("pthread_mutex_lock _ResumeThread") ;
908 _SuspendedThreads -= 1 ;
909 cdebug << "ResumeThread : " << _Threads << " running threads "
910 << _SuspendedThreads << " suspended threads"
912 if ( pthread_mutex_unlock( &_MutexWait ) ) {
913 perror("pthread_mutex_unlock _ResumeThread") ;
918 long GraphExecutor::OutNode::Thread( const char * aNodeName ) {
920 GraphExecutor::InNode *anInNode = (GraphExecutor::InNode *) Graph()->GetGraphNode( aNodeName )->GetInNode() ;
922 RetVal = anInNode->ThreadNo() ;
927 SUPERV::GraphEvent GraphExecutor::OutNode::AutomatonGraphEvent(GraphExecutor::NodeEvent anEvent ) {
928 SUPERV::GraphEvent aGraphEvent ;
930 case GraphExecutor::UndefinedEvent : {
931 aGraphEvent = SUPERV::UndefinedEvent ;
934 case GraphExecutor::NewThreadEvent : {
935 aGraphEvent = SUPERV::NewThreadEvent ;
938 case GraphExecutor::SuspendEvent : {
939 aGraphEvent = SUPERV::SuspendEvent ;
942 case GraphExecutor::ResumeEvent : {
943 aGraphEvent = SUPERV::ResumeEvent ;
946 case GraphExecutor::KillEvent : {
947 aGraphEvent = SUPERV::KillEvent ;
950 case GraphExecutor::StopEvent : {
951 aGraphEvent = SUPERV::StopEvent ;
954 case GraphExecutor::ExecuteEvent : {
955 aGraphEvent = SUPERV::RunningEvent ;
958 case GraphExecutor::SuccessEvent : {
959 aGraphEvent = SUPERV::DoneEvent ;
962 case GraphExecutor::ErrorEvent : {
963 aGraphEvent = SUPERV::ErroredEvent ;
966 case GraphExecutor::NoDataReadyEvent : {
967 aGraphEvent = SUPERV::WaitingEvent ;
970 case GraphExecutor::SomeDataReadyEvent : {
971 aGraphEvent = SUPERV::WaitingEvent ;
974 case GraphExecutor::NotAllDataReadyEvent : {
975 aGraphEvent = SUPERV::WaitingEvent ;
978 case GraphExecutor::AllDataReadyEvent : {
979 aGraphEvent = SUPERV::ReadyEvent ;
982 case GraphExecutor::ReadyEvent : {
983 aGraphEvent = SUPERV::ReadyEvent ;
986 case GraphExecutor::SuspendedReadyEvent : {
987 aGraphEvent = SUPERV::SuspendEvent ;
990 case GraphExecutor::ResumedReadyEvent : {
991 aGraphEvent = SUPERV::ResumeEvent ;
994 case GraphExecutor::KilledReadyEvent : {
995 aGraphEvent = SUPERV::KillEvent ;
998 case GraphExecutor::StoppedReadyEvent : {
999 aGraphEvent = SUPERV::StopEvent ;
1002 case GraphExecutor::ExecutingEvent : {
1003 aGraphEvent = SUPERV::RunningEvent ;
1006 case GraphExecutor::SuspendedExecutingEvent : {
1007 aGraphEvent = SUPERV::SuspendEvent ;
1010 case GraphExecutor::ResumedExecutingEvent : {
1011 aGraphEvent = SUPERV::ResumeEvent ;
1014 case GraphExecutor::KilledExecutingEvent : {
1015 aGraphEvent = SUPERV::KillEvent ;
1018 case GraphExecutor::StoppedExecutingEvent : {
1019 aGraphEvent = SUPERV::StopEvent ;
1022 case GraphExecutor::SuccessedExecutingEvent : {
1023 aGraphEvent = SUPERV::DoneEvent ;
1026 case GraphExecutor::ErroredExecutingEvent : {
1027 aGraphEvent = SUPERV:: ErroredEvent;
1030 case GraphExecutor::SuspendedSuccessedEvent : {
1031 aGraphEvent = SUPERV::SuspendEvent ;
1034 case GraphExecutor::SuspendedErroredEvent : {
1035 aGraphEvent = SUPERV::SuspendEvent ;
1038 case GraphExecutor::ResumedSuccessedEvent : {
1039 aGraphEvent = SUPERV::ResumeEvent ;
1042 case GraphExecutor::ResumedErroredEvent : {
1043 aGraphEvent = SUPERV::ResumeEvent ;
1046 case GraphExecutor::KilledEvent : {
1047 aGraphEvent = SUPERV::KillEvent ;
1050 case GraphExecutor::StoppedEvent : {
1051 aGraphEvent = SUPERV::StopEvent ;
1054 case GraphExecutor::EndExecuteEvent : {
1055 aGraphEvent = SUPERV::DoneEvent ;
1059 cdebug << " GraphExecutor::OutNode::AutomatonGraphEvent Error Undefined Event : "
1060 << anEvent << endl ;
1061 aGraphEvent = SUPERV::UndefinedEvent ;
1064 return aGraphEvent ;
1067 SUPERV::GraphState GraphExecutor::OutNode::AutomatonGraphState(GraphExecutor::AutomatonState aState ) {
1068 SUPERV::GraphState aGraphState ;
1070 case GraphExecutor::UnKnownState : {
1071 aGraphState = SUPERV::UndefinedState ;
1074 case GraphExecutor::DataUndefState : {
1075 aGraphState = SUPERV::UndefinedState ;
1078 case GraphExecutor::DataWaitingState : {
1079 aGraphState = SUPERV::WaitingState ;
1082 case GraphExecutor::DataReadyState : {
1083 aGraphState = SUPERV::ReadyState ;
1086 case GraphExecutor::SuspendedReadyState : {
1087 aGraphState = SUPERV::SuspendReadyState ;
1090 case GraphExecutor::ResumedReadyState : {
1091 aGraphState = SUPERV::ReadyState ;
1094 case GraphExecutor::KilledReadyState : {
1095 aGraphState = SUPERV::KillState ;
1098 case GraphExecutor::StoppedReadyState : {
1099 aGraphState = SUPERV::StopState ;
1102 case GraphExecutor::ExecutingState : {
1103 aGraphState = SUPERV::RunningState ;
1106 case GraphExecutor::SuspendedExecutingState : {
1107 aGraphState = SUPERV::SuspendState ;
1110 case GraphExecutor::ResumedExecutingState : {
1111 aGraphState = SUPERV::RunningState ;
1114 case GraphExecutor::KilledExecutingState : {
1115 aGraphState = SUPERV::KillState ;
1118 case GraphExecutor::StoppedExecutingState : {
1119 aGraphState = SUPERV::StopState ;
1122 case GraphExecutor::SuccessedExecutingState : {
1123 aGraphState = SUPERV::DoneState ;
1126 case GraphExecutor::ErroredExecutingState : {
1127 aGraphState = SUPERV::ErrorState ;
1130 case GraphExecutor::SuspendedSuccessedState : {
1131 aGraphState = SUPERV::SuspendDoneState ;
1134 case GraphExecutor::SuspendedErroredState : {
1135 aGraphState = SUPERV::SuspendErroredState ;
1138 case GraphExecutor::ResumedSuccessedState : {
1139 aGraphState = SUPERV::DoneState ;
1142 case GraphExecutor::ResumedErroredState : {
1143 aGraphState = SUPERV::ErrorState ;
1146 case GraphExecutor::KilledSuccessedState : {
1147 aGraphState = SUPERV::KillState ;
1150 case GraphExecutor::KilledErroredState : {
1151 aGraphState = SUPERV::KillState ;
1154 case GraphExecutor::StoppedSuccessedState : {
1155 aGraphState = SUPERV::StopState ;
1158 case GraphExecutor::StoppedErroredState : {
1159 aGraphState = SUPERV::StopState ;
1162 case GraphExecutor::SuccessedState : {
1163 aGraphState = SUPERV::DoneState ;
1166 case GraphExecutor::ErroredState : {
1167 aGraphState = SUPERV::ErrorState ;
1170 case GraphExecutor::SuspendedState : {
1171 aGraphState = SUPERV::SuspendState ;
1174 case GraphExecutor::KilledState : {
1175 aGraphState = SUPERV::KillState ;
1178 case GraphExecutor::StoppedState : {
1179 aGraphState = SUPERV::StopState ;
1182 case GraphExecutor::LoadingState : {
1183 aGraphState = SUPERV::LoadingState ;
1187 cdebug << " GraphExecutor::OutNode::AutomatonGraphState Error Undefined State : "
1188 << aGraphState << endl ;
1189 aGraphState = SUPERV::UndefinedState ;
1192 return aGraphState ;
1195 int GraphExecutor::OutNode::GetListSize() {
1196 return _EventNodes.size();
1199 bool GraphExecutor::OutNode::PushEvent( GraphExecutor::InNode * aNode ,
1200 GraphExecutor::NodeEvent anEvent ,
1201 GraphExecutor::AutomatonState aState ) {
1202 // cdebug_in << "PushEvent Threads " << Threads() << " SuspendedThreads "
1203 // << SuspendedThreads() << endl ;
1204 if ( pthread_mutex_lock( &_MutexWait ) ) {
1205 perror("PushEvent pthread_mutex_lock ") ;
1208 char* aNodeName = aNode ? aNode->Name() : Graph()->Name() ;
1209 _EventNodes.push_back( aNodeName ) ;
1210 _Events.push_back( anEvent ) ;
1211 _States.push_back( aState ) ;
1213 pthread_cond_broadcast( &_EventWait );
1214 cdebug << pthread_self() << " PushEvent Threads " << Threads() << " SuspendedThreads "
1215 << SuspendedThreads() << " pthread_cond_broadcast _EventWait " << &_EventWait << endl ;
1217 // cdebug << aNode->ThreadNo() << " PushEvent " << aNode->Name() ;
1218 // cdebug << " " << aNode->Automaton()->EventName( anEvent )
1219 // << " " << aNode->Automaton()->StateName( aState )
1220 // << " ControleState "
1221 // << aNode->Automaton()->ControlStateName( aNode->ControlState() ) ;
1224 // cdebug << "PushEvent " << Graph()->Name() ;
1225 // cdebug << " " << theAutomaton->EventName( anEvent ) << " "
1226 // << theAutomaton->StateName( aState ) ;
1228 // cdebug_out << "PushEvent Threads " << Threads() << " SuspendedThreads "
1229 // << SuspendedThreads() << endl ;
1231 //JR 21.02.2005 Debug : old events should be removed at creation time for python-clients
1232 int EventNodesSize = _EventNodes.size() ;
1233 if ( _EventNodes.size() > (unsigned int)Graph()->GraphNodesSize()*70 ) {
1235 cdebug << "OutNode::PushEvent " << _EventNodes.size() << " in queue instead of "
1236 << EventNodesSize << endl ;
1239 if ( pthread_mutex_unlock( &_MutexWait ) ) {
1240 perror("PushEvent pthread_mutex_unlock ") ;
1246 bool GraphExecutor::OutNode::StateWait( SUPERV::GraphState aState ) {
1250 bool GraphExecutor::OutNode::Event( char ** aNodeName ,
1251 SUPERV::GraphEvent & anEvent ,
1252 SUPERV::GraphState & aState ,
1254 //JR 23.02.2005, Debug : siftEvents() must be inside the pthread_mutex_lock
1255 if ( pthread_mutex_lock( &_MutexWait ) ) {
1256 perror("EventLoop pthread_mutex_lock ") ;
1259 // asv : fixing problem of loops with large number of iterations (>5000)
1260 // experimentally was found that number of non-handled by GUI events = (number_of_nodes x 7)
1261 // or 7 events for each node - so what we want to do here is remove "old" events for nodes
1262 // "on the fly". Once again it is done in Stop(), Kill(), Done() functions.
1263 int EventNodessize = _EventNodes.size() ;
1264 if ( _EventNodes.size() > (unsigned int)Graph()->GraphNodesSize()*7 )
1268 int SuspendedThreadsNumber ;
1269 bool cdebuginout = false ;
1270 if ( _EventNodes.size() > 0 ) {
1271 cdebug_in << "GraphExecutor::OutNode::Event " << _EventNodes.size() << " in queue instead of "
1272 << EventNodessize << endl ;
1273 cdebuginout = true ;
1275 _JustStarted = false ;
1276 ThreadsNumber = Threads() ;
1277 SuspendedThreadsNumber = SuspendedThreads() ;
1278 bool RetVal = ( ThreadsNumber - SuspendedThreadsNumber) != 0 ||
1279 _EventNodes.size() > 0 ;
1280 char * NodeName = "" ;
1281 GraphExecutor::NodeEvent theEvent = GraphExecutor::UndefinedEvent ;
1282 GraphExecutor::AutomatonState theState = GraphExecutor::UnKnownState ;
1283 anEvent = SUPERV::UndefinedEvent ;
1284 aState = SUPERV::UndefinedState ;
1285 if ( ( Done() || IsKilled() || IsStopped() ) && _EventNodes.size() == 0 ) {
1286 // cdebug << "EventLoop Done()/IsKilled()/IsStopped() && _EventNodes.size() == 0" << endl ;
1289 else if ( !WithWait && _EventNodes.size() == 0 ) {
1290 anEvent = SUPERV::NoEvent ;
1291 aState = SUPERV::NoState ;
1294 else if ( RetVal ) {
1295 while ( !IsSuspended() && _EventNodes.size() == 0 ) {
1296 // cdebug << "EventLoop pthread_cond_wait _EventWait" << endl ;
1297 pthread_cond_wait( &_EventWait , &_MutexWait );
1298 // cdebug << "EventLoop pthread_cond_waited _EventWait"
1299 // << " _EventNodes.size() " << _EventNodes.size() << endl ;
1301 if ( _EventNodes.size() ) {
1302 ThreadsNumber = Threads() ;
1303 NodeName = _EventNodes.front() ;
1304 _EventNodes.pop_front() ;
1305 theEvent = _Events.front() ;
1306 anEvent = AutomatonGraphEvent( theEvent ) ;
1307 _Events.pop_front() ;
1308 theState = _States.front() ;
1309 aState = AutomatonGraphState( theState ) ;
1310 _States.pop_front() ;
1313 *aNodeName = NodeName ;
1314 if ( IsSuspended() && _EventNodes.size() == 0 ) {
1317 if ( anEvent != SUPERV::NoEvent ) {
1318 // cdebug << pthread_self() << "EventLoop "
1319 // << NodeName << " " << theAutomaton->StateName( theState )
1320 // << " _EventNodes.size() " << _EventNodes.size()
1321 // << " Threads " << Threads() << " SuspendedThreads "
1322 // << SuspendedThreads() << " RetVal " << RetVal << endl ;
1324 if ( pthread_mutex_unlock( &_MutexWait ) ) {
1325 perror("EventLoop pthread_mutex_lock ") ;
1328 if ( cdebuginout ) {
1329 // cdebug_out << "GraphExecutor::OutNode::Event " << _EventNodes.size() << " in queue"
1330 // << *aNodeName << " " << anEvent << " " << aState << endl ;
1335 bool GraphExecutor::OutNode::EventW( char ** aNodeName ,
1336 SUPERV::GraphEvent & anEvent ,
1337 SUPERV::GraphState & aState ) {
1340 aState = SUPERV::UndefinedState ;
1342 aState != SUPERV::SuspendReadyState &&
1343 aState != SUPERV::RunningState &&
1344 aState != SUPERV::SuspendDoneState &&
1345 aState != SUPERV::SuspendErroredState ) {
1346 NodeName = Graph()->Name() ;
1347 while ( sts && !strcmp( NodeName , Graph()->Name() ) ) {
1348 sts = EventWait( aNodeName , anEvent , aState ) ;
1349 NodeName = *aNodeName ;
1355 bool GraphExecutor::OutNode::EventWait( char ** aNodeName ,
1356 SUPERV::GraphEvent & anEvent ,
1357 SUPERV::GraphState & aState ) {
1358 if ( pthread_mutex_lock( &_MutexWait ) ) {
1359 perror("EventW pthread_mutex_lock ") ;
1363 int SuspendedThreadsNumber ;
1364 ThreadsNumber = Threads() ;
1365 SuspendedThreadsNumber = SuspendedThreads() ;
1366 bool RetVal = ( ThreadsNumber - SuspendedThreadsNumber) != 0 ||
1367 _EventNodes.size() > 0 ;
1368 cdebug << "--> EventW RetVal " << RetVal << endl ;
1369 char * NodeName = "" ;
1370 GraphExecutor::NodeEvent theEvent = GraphExecutor::UndefinedEvent ;
1371 GraphExecutor::AutomatonState theState = GraphExecutor::UnKnownState ;
1372 anEvent = SUPERV::UndefinedEvent ;
1373 aState = SUPERV::UndefinedState ;
1374 if ( IsDone() && _EventNodes.size() == 0 ) {
1375 cdebug << "EventW IsDone() && _EventNodes.size() == 0" << endl ;
1378 else if ( RetVal ) {
1379 GraphExecutor::InNode * aNode = NULL ;
1380 while ( aNode == NULL && RetVal ) {
1381 NodeName = _EventNodes.front() ;
1382 theEvent = _Events.front() ;
1383 anEvent = AutomatonGraphEvent( theEvent ) ;
1384 theState = _States.front() ;
1385 aState = AutomatonGraphState( theState ) ;
1387 if ( _JustStarted ) {
1388 _JustStarted = false ;
1391 _EventNodes.pop_front() ;
1392 _Events.pop_front() ;
1393 _States.pop_front() ;
1396 aNode = ((GraphExecutor::InNode *) Graph()->GetGraphNode( NodeName )->GetInNode()) ;
1397 cdebug << "EventW Previous Node " << NodeName << " ThreadsNumber "
1399 << " _EventNodes.size() " << _EventNodes.size() << " "
1400 << theAutomaton->StateName( theState )
1401 << " Threads " << Threads() << " SuspendedThreads "
1402 << SuspendedThreads() << endl ;
1405 else if ( IsDone() && _EventNodes.size() == 0 ) {
1406 cdebug << "EventW IsDone() && _EventNodes.size() == 0" << endl ;
1410 cdebug << "EventW Not InNode " << NodeName
1411 << " _EventNodes.size() " << _EventNodes.size() << endl ;
1412 while ( _EventNodes.size() == 0 ) {
1413 pthread_cond_wait( &_EventWait , &_MutexWait );
1415 cdebug << "EventW pthread_cond_waited Not InNode " << NodeName
1416 << " _EventNodes.size() " << _EventNodes.size() << endl ;
1421 if ( aState == SUPERV::SuspendState ||
1422 aState == SUPERV::SuspendReadyState ||
1423 aState == SUPERV::SuspendDoneState ||
1424 aState == SUPERV::SuspendErroredState ) {
1425 aNode->ControlState( SUPERV::ToSuspendState ) ;
1426 if ( aNode->IsSuspended() ) {
1427 if ( pthread_mutex_unlock( &_MutexWait ) ) {
1428 perror("EventW pthread_mutex_lock ") ;
1431 cdebug << "EventW " << aNode->Name() << " ResumeAction" << endl ;
1432 aNode->ResumeAction( GraphExecutor::ToResumeEvent ) ;
1433 cdebug << "EventW " << aNode->Name() << " ResumedAction" << endl ;
1434 if ( pthread_mutex_lock( &_MutexWait ) ) {
1435 perror("EventW pthread_mutex_lock ") ;
1440 cdebug << "EventW inconsistent SuspendState" << endl ;
1445 if ( aNode->IsDone() ) {
1449 cdebug << "EventW NOT SuspendedState _EventNodes.size() "
1450 << _EventNodes.size() << endl ;
1455 cdebug << "EventW " << aNode->Name() << " pthread_cond_wait" << endl ;
1456 while ( _EventNodes.size() == 0 ) {
1457 pthread_cond_wait( &_EventWait , &_MutexWait );
1459 ThreadsNumber = Threads() ;
1460 NodeName = _EventNodes.front() ;
1461 theEvent = _Events.front() ;
1462 anEvent = AutomatonGraphEvent( theEvent ) ;
1463 theState = _States.front() ;
1464 aState = AutomatonGraphState( theState ) ;
1468 *aNodeName = NodeName ;
1469 cdebug << "<-- EventW RetVal " << RetVal << " " << NodeName
1470 << " Threads " << Threads() << " SuspendedThreads "
1471 << SuspendedThreads()
1472 << " _EventNodes.size() " << _EventNodes.size()
1473 << " " << theAutomaton->EventName( theEvent ) << " "
1474 << theAutomaton->StateName( theState ) << endl ;
1475 if ( pthread_mutex_unlock( &_MutexWait ) ) {
1476 perror("EventW pthread_mutex_lock ") ;
1481 long GraphExecutor::OutNode::EventQSize() {
1482 return _EventNodes.size() ;
1485 void GraphExecutor::OutNode::EventList() {
1486 if ( pthread_mutex_lock( &_MutexWait ) ) {
1487 perror("EventList pthread_mutex_lock ") ;
1490 list< char * >::iterator itEventNodes = _EventNodes.begin() ;
1491 list< GraphExecutor::NodeEvent >::iterator itEvents = _Events.begin() ;
1492 list< GraphExecutor::AutomatonState >::iterator itStates = _States.begin() ;
1493 while ( itEventNodes != _EventNodes.end() ) {
1494 cdebug << pthread_self() << "EVENTSTACK "
1495 << *itEventNodes << " " << *itEvents << " "
1496 << theAutomaton->StateName( *itStates )
1497 << " Threads " << Threads() << " SuspendedThreads " << SuspendedThreads() << endl ;
1502 if ( pthread_mutex_unlock( &_MutexWait ) ) {
1503 perror("EventList pthread_mutex_lock ") ;
1508 void GraphExecutor::OutNode::SendSomeDataReady( const char * aNodeName ) {
1509 cdebug_in << "GraphExecutor::OutNode::SendSomeDataReady " << aNodeName << "->SendSomeDataReady( "
1510 << Graph()->Name() << " )" << endl;
1512 sts = ((GraphExecutor::InNode * ) Graph()->GetChangeGraphNode( aNodeName )->GetInNode())->SendSomeDataReady( Graph()->Name() ) ;
1513 cdebug_out << "GraphExecutor::OutNode::SendSomeDataReady sts " << sts << endl ;
1516 void GraphExecutor::OutNode::State(GraphExecutor::AutomatonState aState ) {
1517 // cdebug << "GraphExecutor::OutNode::State " << Graph()->Name() << " "
1518 // << theAutomaton->StateName( AutomatonGraphState( _State ) ) << " ---> "
1519 // << theAutomaton->StateName( AutomatonGraphState( aState ) ) << endl ;
1523 SUPERV::GraphState GraphExecutor::OutNode::State() {
1524 // cdebug_in << "GraphExecutor::OutNode::State" << endl;
1525 // cdebug_out << "GraphExecutor::OutNode::State" << endl ;
1526 // cdebug << "GraphExecutor::OutNode::State GraphState "
1527 // << theAutomaton->StateName( AutomatonGraphState( _State ) ) << endl ;
1528 return AutomatonGraphState( _State ) ;
1531 SUPERV::GraphState GraphExecutor::OutNode::State( const char * NodeName ) {
1532 // cdebug_in << "GraphExecutor::OutNode::State " << NodeName << endl;
1533 GraphExecutor::AutomatonState aret = GraphExecutor::UnKnownState ;
1534 const GraphBase::ComputingNode * aCNode = Graph()->GetGraphNode( NodeName ) ;
1536 GraphExecutor::InNode *anInNode = (GraphExecutor::InNode *)aCNode->GetInNode() ;
1538 aret = anInNode->State() ;
1539 // asv 27.01.05 - fix for PAL7849, return "Loading" state only if internal state is SUPERV::RunningState
1540 if ( ( aret == GraphExecutor::ExecutingState ||
1541 aret == GraphExecutor::ResumedExecutingState ) &&
1542 anInNode->IsLoading() )
1543 aret = GraphExecutor::LoadingState;
1544 // cdebug << "GraphExecutor::OutNode::State( " << NodeName << " ) "
1545 // << theAutomaton->StateName( AutomatonGraphState( aret ) ) << endl ;
1548 // cdebug_out << "GraphExecutor::OutNode::State" << endl ;
1549 return AutomatonGraphState( aret ) ;
1552 SUPERV::GraphState GraphExecutor::OutNode::State( const char * NodeName ,
1553 const char * ServiceParameterName ) {
1554 // cdebug_in << "GraphExecutor::OutNode::State " << NodeName << " "
1555 // << ServiceParameterName<< endl;
1556 SUPERV::GraphState aret = Graph()->PortState( NodeName , ServiceParameterName ) ;
1557 // cdebug_out << "GraphExecutor::OutNode::State" << endl ;
1561 GraphExecutor::AutomatonState GraphExecutor::OutNode::AutomatonState() {
1562 // cdebug_in << "GraphExecutor::OutNode::AutomatonState" << endl;
1563 // cdebug_out << "GraphExecutor::OutNode::AutomatonState" << endl ;
1567 GraphExecutor::AutomatonState GraphExecutor::OutNode::AutomatonState( const char * NodeName ) {
1568 // cdebug_in << "GraphExecutor::OutNode::AutomatonState " << NodeName << endl;
1569 GraphExecutor::AutomatonState aret = GraphExecutor::UnKnownState ;
1570 const GraphBase::ComputingNode * aNode = Graph()->GetGraphNode( NodeName ) ;
1572 GraphExecutor::InNode *anInNode = (GraphExecutor::InNode *) aNode->GetInNode() ;
1574 aret = anInNode->State() ;
1577 // cdebug_out << "GraphExecutor::OutNode::AutomatonState" << endl ;
1581 SUPERV::ControlState GraphExecutor::OutNode::ControlState() {
1582 // cdebug_in << "GraphExecutor::OutNode::ControlState" << endl;
1583 // cdebug_out << "GraphExecutor::OutNode::ControlState" << endl ;
1584 return _ControlState ;
1587 SUPERV::ControlState GraphExecutor::OutNode::ControlState( const char * NodeName ) {
1588 // cdebug_in << "GraphExecutor::OutNode::ControlState " << NodeName << endl;
1589 SUPERV::ControlState aret = SUPERV::VoidState ;
1590 const GraphBase::ComputingNode * aNode = Graph()->GetGraphNode( NodeName ) ;
1592 GraphExecutor::InNode *anInNode = (GraphExecutor::InNode *) aNode->GetInNode() ;
1594 aret = anInNode->ControlState() ;
1597 // cdebug_out << "GraphExecutor::OutNode::ControlState" << endl ;
1601 void GraphExecutor::OutNode::ControlClear() {
1602 // cdebug_in << "GraphExecutor::OutNode::ControlClear" << endl;
1603 // cdebug_out << "GraphExecutor::OutNode::ControlClear" << endl ;
1604 _ControlState = SUPERV::VoidState;
1607 void GraphExecutor::OutNode::ControlClear( const char * NodeName ) {
1608 // cdebug_in << "GraphExecutor::OutNode::ControlClear " << NodeName << endl;
1609 const GraphBase::ComputingNode * aNode = Graph()->GetGraphNode( NodeName ) ;
1611 GraphExecutor::InNode *anInNode = (GraphExecutor::InNode *) aNode->GetInNode() ;
1613 anInNode->ControlClear() ;
1616 // cdebug_out << "GraphExecutor::OutNode::ControlClear" << endl ;
1619 bool GraphExecutor::OutNode::IsWaiting() {
1620 // cdebug_in << "GraphExecutor::OutNode::IsWaiting" << endl;
1621 // cdebug_out << "GraphExecutor::OutNode::IsWaiting" << endl ;
1625 bool GraphExecutor::OutNode::IsReady() {
1626 // cdebug_in << "GraphExecutor::OutNode::IsReady" << endl;
1627 // cdebug_out << "GraphExecutor::OutNode::IsReady" << endl ;
1631 bool GraphExecutor::OutNode::IsRunning() {
1632 // cdebug_in << "GraphExecutor::OutNode::IsRunning" << endl;
1633 // cdebug_out << "GraphExecutor::OutNode::IsRunning" << endl ;
1637 bool GraphExecutor::OutNode::IsDone() {
1638 // cdebug_in << "GraphExecutor::OutNode::IsDone" << endl;
1639 // cdebug_out << "GraphExecutor::OutNode::IsDone" << endl ;
1640 return ( Done() || IsKilled() || IsStopped() ) ;
1643 bool GraphExecutor::OutNode::IsSuspended() {
1644 // cdebug_in << "GraphExecutor::OutNode::IsSuspended" << endl;
1646 // if ( _SuspendedThreads == _Threads && _Threads != 0 ) {
1647 if ( AutomatonGraphState( _State ) == SUPERV::SuspendState ) {
1650 // cdebug_out << "GraphExecutor::OutNode::IsSuspended" << endl ;
1654 bool GraphExecutor::OutNode::IsKilled() {
1655 // cdebug_in << "GraphExecutor::OutNode::IsKilled" << endl;
1657 if ( AutomatonGraphState( _State ) == SUPERV::KillState ) {
1660 // cdebug_out << "GraphExecutor::OutNode::IsKilled" << endl ;
1664 bool GraphExecutor::OutNode::IsStopped() {
1665 // cdebug_in << "GraphExecutor::OutNode::IsStopped" << endl;
1667 if ( AutomatonGraphState( _State ) == SUPERV::StopState ) {
1670 // cdebug_out << "GraphExecutor::OutNode::IsStopped" << endl ;
1674 bool GraphExecutor::OutNode::IsWaiting( const char * NodeName ) {
1676 // cdebug_in << "GraphExecutor::OutNode::IsWaiting " << NodeName << endl;
1677 GraphExecutor::InNode *anInNode = (GraphExecutor::InNode *) Graph()->GetGraphNode( NodeName )->GetInNode() ;
1679 aret = anInNode->IsWaiting() ;
1681 // cdebug_out << "GraphExecutor::OutNode::IsWaiting" << endl ;
1685 bool GraphExecutor::OutNode::IsReady( const char * NodeName ) {
1687 // cdebug_in << "GraphExecutor::OutNode::IsReady " << NodeName << endl;
1688 GraphExecutor::InNode *anInNode = (GraphExecutor::InNode *) Graph()->GetGraphNode( NodeName )->GetInNode() ;
1690 aret = anInNode->IsReady() ;
1692 // cdebug_out << "GraphExecutor::OutNode::IsReady" << endl ;
1696 bool GraphExecutor::OutNode::IsRunning( const char * NodeName ) {
1698 // cdebug_in << "GraphExecutor::OutNode::IsRunning " << NodeName << endl;
1699 GraphExecutor::InNode *anInNode = (GraphExecutor::InNode *) Graph()->GetGraphNode( NodeName )->GetInNode() ;
1701 aret = anInNode->IsRunning() ;
1703 // cdebug_out << "GraphExecutor::OutNode::IsRunning" << endl ;
1707 bool GraphExecutor::OutNode::IsDone( const char * NodeName ) {
1709 // cdebug_in << "GraphExecutor::OutNode::IsDone " << NodeName << endl;
1710 GraphExecutor::InNode *anInNode = (GraphExecutor::InNode *) Graph()->GetGraphNode( NodeName )->GetInNode() ;
1712 aret = anInNode->IsDone() ;
1714 // cdebug_out << "GraphExecutor::OutNode::IsDone" << endl ;
1718 bool GraphExecutor::OutNode::IsSuspended( const char * NodeName ) {
1720 // cdebug_in << "GraphExecutor::OutNode::IsSuspended " << NodeName << endl;
1721 GraphExecutor::InNode *anInNode = (GraphExecutor::InNode *) Graph()->GetGraphNode( NodeName )->GetInNode() ;
1723 aret = anInNode->IsSuspended() ;
1725 // cdebug_out << "GraphExecutor::OutNode::IsSuspended" << endl ;
1729 bool GraphExecutor::OutNode::PortDone( const char * NodeName ,
1730 const char * ServiceParameterName ) {
1731 // cdebug_in << "GraphExecutor::OutNode::IsDone " << NodeName << " "
1732 // << ServiceParameterName<< endl;
1733 bool aret = Graph()->PortDone( NodeName , ServiceParameterName ) ;
1734 // cdebug_out << "GraphExecutor::OutNode::IsDone" << endl ;
1738 bool GraphExecutor::OutNode::ContainerKill() {
1739 bool RetVal = true ;
1740 cdebug_in << "GraphExecutor::OutNode::ContainerKill" << endl;
1741 _ControlState = SUPERV::ToSuspendState ;
1743 for ( i = 0 ; i < Graph()->GraphNodesSize() ; i++ ) {
1744 GraphExecutor::InNode * aNode = (GraphExecutor::InNode * ) Graph()->GraphNodes( i )->GetInNode() ;
1745 bool sts = aNode->ContainerKill() ;
1746 if ( sts && aNode->IsKilled() ) {
1747 cdebug << aNode->Name() << " killed" << endl ;
1749 else if ( aNode->IsWaiting() || aNode->IsDone() ) {
1750 cdebug << aNode->Name() << " not killed : "
1751 << theAutomaton->StateName( aNode->State() ) << endl ;
1754 cdebug << aNode->Name() << " cannot be killed : "
1755 << theAutomaton->StateName( aNode->State() ) << endl ;
1759 if ( !RetVal || Threads() != 0 ) {
1760 for ( i = 0 ; i < Graph()->GraphNodesSize() ; i++ ) {
1761 GraphExecutor::InNode * aNode = (GraphExecutor::InNode * ) Graph()->GraphNodes( i )->GetInNode() ;
1762 if ( !aNode->IsKilled() && !aNode->IsWaiting() && !aNode->IsDone() ) {
1763 aNode->KilledAction() ;
1768 State( GraphExecutor::KilledState ) ;
1769 cdebug_out << "GraphExecutor::OutNode::ContainerKill" << endl ;
1773 bool GraphExecutor::OutNode::Suspend() {
1775 cdebug_in << "GraphExecutor::OutNode::Suspend" << endl;
1776 // _ControlState = SUPERV::ToSuspendState ;
1778 for ( i = 0 ; i < Graph()->GraphNodesSize() ; i++ ) {
1779 GraphExecutor::InNode * aNode = (GraphExecutor::InNode * ) Graph()->GraphNodes( i )->GetInNode() ;
1780 bool sts = aNode->Suspend() ;
1781 if ( sts && aNode->IsSuspended() ) {
1783 cdebug << aNode->Name() << " Suspended" << endl ;
1785 else if ( aNode->IsWaiting() || aNode->IsReady() ) {
1787 cdebug << aNode->Name() << " will be Suspended" << endl ;
1789 else if ( aNode->IsDone() ) {
1790 cdebug << aNode->Name() << " not Suspended : "
1791 << theAutomaton->StateName( aNode->State() ) << endl ;
1795 cdebug << aNode->Name() << " cannot be Suspended : "
1796 << theAutomaton->StateName( aNode->State() ) << endl ;
1800 State( GraphExecutor::SuspendedState ) ;
1801 MESSAGE("================================================================================") ;
1802 MESSAGE( Graph()->Name() << " IS SUSPENDED" ) ;
1803 MESSAGE("================================================================================") ;
1806 MESSAGE("================================================================================") ;
1807 MESSAGE( Graph()->Name() << " IS NOT SUSPENDED" ) ;
1808 MESSAGE("================================================================================") ;
1810 for ( i = 0 ; i < Graph()->GraphNodesSize() ; i++ ) {
1811 GraphExecutor::InNode * aNode = (GraphExecutor::InNode * ) Graph()->GraphNodes( i )->GetInNode() ;
1812 MESSAGE(aNode->Name() << " " << theAutomaton->StateName( aNode->State() ) ) ;
1813 cdebug << aNode->Name() << " " << theAutomaton->StateName( aNode->State() ) << endl ;
1815 cdebug_out << "GraphExecutor::OutNode::Suspend " << theAutomaton->StateName( State() )
1816 << " EventQSize " << EventQSize() << endl ;
1820 bool GraphExecutor::OutNode::Resume() {
1822 cdebug_in << "GraphExecutor::OutNode::Resume "
1823 << theAutomaton->StateName( State() ) << endl;
1824 if ( IsSuspended() ) {
1825 State( GraphExecutor::ExecutingState ) ;
1827 for ( i = 0 ; i < Graph()->GraphNodesSize() ; i++ ) {
1828 GraphExecutor::InNode * aNode = (GraphExecutor::InNode * ) Graph()->GraphNodes( i )->GetInNode() ;
1829 aNode->ControlState( SUPERV::VoidState ) ;
1830 if ( aNode->IsSuspended() ) {
1831 cdebug << aNode->Name() << "->Resume " << theAutomaton->StateName( aNode->State() )
1833 if ( aNode->Resume() ) {
1834 cdebug << aNode->Name() << " Resumed " << theAutomaton->StateName( aNode->State() )
1839 cdebug << aNode->Name() << " Resume failed"
1840 << theAutomaton->StateName( aNode->State() ) << endl ;
1844 cdebug << aNode->Name() << " " << theAutomaton->StateName( aNode->State() )
1850 cdebug << Graph()->Name() << " not suspended " << theAutomaton->StateName( State() ) << endl ;
1853 MESSAGE("================================================================================") ;
1854 MESSAGE( Graph()->Name() << " IS RESUMED" ) ;
1855 MESSAGE("================================================================================") ;
1858 MESSAGE("================================================================================") ;
1859 MESSAGE( Graph()->Name() << " IS NOT RESUMED" ) ;
1860 MESSAGE("================================================================================") ;
1863 for ( i = 0 ; i < Graph()->GraphNodesSize() ; i++ ) {
1864 GraphExecutor::InNode * aNode = (GraphExecutor::InNode * ) Graph()->GraphNodes( i )->GetInNode() ;
1865 MESSAGE(aNode->Name() << " " << theAutomaton->StateName( aNode->State() ) ) ;
1866 cdebug << aNode->Name() << " " << theAutomaton->StateName( aNode->State() ) << endl ;
1868 cdebug_out << "GraphExecutor::OutNode::Resume" << theAutomaton->StateName( State() ) << " " << RetVal
1869 << " EventQSize " << EventQSize() << endl ;
1873 bool GraphExecutor::OutNode::Kill() {
1874 bool RetVal = false ;
1875 cdebug_in << "GraphExecutor::OutNode::Kill"
1876 << " EventQSize " << EventQSize() << endl;
1877 _ControlState = SUPERV::ToSuspendState ;
1879 for ( i = 0 ; i < Graph()->GraphNodesSize() ; i++ ) {
1880 GraphExecutor::InNode * aNode = (GraphExecutor::InNode * ) Graph()->GraphNodes( i )->GetInNode() ;
1881 bool sts = aNode->Kill() ;
1882 if ( sts && Threads() != 0 ) {
1883 if ( !aNode->IsKilled() ) {
1884 cdebug << aNode->Name() << " not killed : "
1885 << theAutomaton->StateName( aNode->State() ) << " " << aNode->Name() << "->"
1886 << "KilledAction()" << endl ;
1887 MESSAGE( aNode->Name() << " not killed : KilledAction()" ) ;
1888 aNode->KilledAction() ;
1890 if ( aNode->IsKilled() ) {
1891 cdebug << aNode->Name() << " killed" << endl ;
1895 else if ( aNode->IsWaiting() || aNode->IsDone() ) {
1896 cdebug << aNode->Name() << " not killed : "
1897 << theAutomaton->StateName( aNode->State() ) << endl ;
1900 cdebug << aNode->Name() << " cannot be killed : "
1901 << theAutomaton->StateName( aNode->State() ) << endl ;
1905 State( GraphExecutor::KilledState ) ;
1906 MESSAGE("================================================================================") ;
1907 MESSAGE( Graph()->Name() << " IS KILLED" << theAutomaton->StateName( AutomatonState() ) << " EventQSize "
1909 MESSAGE("================================================================================") ;
1912 MESSAGE("================================================================================") ;
1913 MESSAGE( Graph()->Name() << " IS NOT KILLED" ) ;
1914 MESSAGE("================================================================================") ;
1916 for ( i = 0 ; i < Graph()->GraphNodesSize() ; i++ ) {
1917 GraphExecutor::InNode * aNode = (GraphExecutor::InNode * ) Graph()->GraphNodes( i )->GetInNode() ;
1918 MESSAGE(aNode->Name() << " " << theAutomaton->StateName( aNode->State() ) ) ;
1919 cdebug << aNode->Name() << " " << theAutomaton->StateName( aNode->State() ) << endl ;
1921 cdebug_out << "GraphExecutor::OutNode::Kill " << RetVal
1922 << " Threads " << _Threads << " SuspendedThreads " << _SuspendedThreads
1923 << " EventQSize " << EventQSize() << endl ;
1925 if ( pthread_mutex_lock( &_MutexWait ) ) {
1926 perror("EventLoop pthread_mutex_lock ") ;
1929 //JR 23.02.2005, Debug : siftEvents() must be inside the pthread_mutex_lock
1930 // remove "extra" events from the event queue
1932 if ( pthread_mutex_unlock( &_MutexWait ) ) {
1933 perror("PushEvent pthread_mutex_unlock ") ;
1937 // asv : 25.10.04 : calling Editing() to indicate stop of execution
1938 Graph()->GraphEditor()->Editing();
1943 bool GraphExecutor::OutNode::Stop() {
1944 bool RetVal = false ;
1945 cdebug_in << "GraphExecutor::OutNode::Stop" << endl;
1947 cdebug_out << "GraphExecutor::OutNode::Stop" << endl ;
1949 MESSAGE("================================================================================") ;
1950 MESSAGE( Graph()->Name() << " IS STOPPED" ) ;
1951 MESSAGE("================================================================================") ;
1956 bool GraphExecutor::OutNode::ReadyWait() {
1957 cdebug_in << "GraphExecutor::OutNode::ReadyWait" << endl;
1959 if ( pthread_mutex_lock( &_MutexWait ) ) {
1960 perror("pthread_mutex_lock _ReadyWait") ;
1966 pthread_cond_wait( &_EventWait , &_MutexWait );
1969 if ( pthread_mutex_unlock( &_MutexWait ) ) {
1970 perror("pthread_mutex_lock _ReadyWait") ;
1973 cdebug_out << "GraphExecutor::OutNode::ReadyWait" << endl ;
1977 bool GraphExecutor::OutNode::RunningWait() {
1978 cdebug_in << "GraphExecutor::OutNode::RunningWait" << endl;
1980 if ( pthread_mutex_lock( &_MutexWait ) ) {
1981 perror("pthread_mutex_lock _RunningWait") ;
1984 aret = IsRunning() ;
1986 cdebug << "RunningWait pthread_cond_wait _EventWait" << endl;
1987 pthread_cond_wait( &_EventWait , &_MutexWait );
1988 aret = IsRunning() ;
1989 cdebug << "RunningWait pthread_cond_waited _EventWait " << aret << endl;
1991 if ( pthread_mutex_unlock( &_MutexWait ) ) {
1992 perror("pthread_mutex_lock _RunningWait") ;
1995 cdebug_out << "GraphExecutor::OutNode::RunningWait " << aret << endl ;
1999 bool GraphExecutor::OutNode::DoneWait() {
2000 cdebug_in << pthread_self() << " GraphExecutor::DoneWait " << this << " " << Graph()->Name() << endl;
2002 if ( pthread_mutex_lock( &_MutexWait ) ) {
2003 perror("pthread_mutex_lock _DoneWait") ;
2007 while ( !aret && !IsSuspended() && IsRunning() ) {
2008 cdebug << pthread_self() << " GraphExecutor::DoneWait " << this << " " << Graph()->Name()
2009 << " DoneWait pthread_cond_wait _EventWait " << &_EventWait << endl;
2010 pthread_cond_wait( &_EventWait , &_MutexWait );
2012 cdebug << pthread_self() << " GraphExecutor::DoneWait " << this << " " << Graph()->Name()
2013 << " DoneWait pthread_cond_waited _EventWaited " << &_EventWait << " : "<< aret << endl;
2015 if ( pthread_mutex_unlock( &_MutexWait ) ) {
2016 perror("pthread_mutex_lock _DoneWait") ;
2019 cdebug_out << pthread_self() << " GraphExecutor::DoneWait " << this << " " << Graph()->Name()
2020 << " " << State() << " : " << aret << endl ;
2024 bool GraphExecutor::OutNode::SuspendedWait() {
2025 cdebug_in << "GraphExecutor::OutNode::SuspendedWait" << endl;
2027 if ( pthread_mutex_lock( &_MutexWait ) ) {
2028 perror("pthread_mutex_lock _SuspendedWait") ;
2031 aret = IsSuspended() ;
2032 while ( !aret && !IsDone() ) {
2033 pthread_cond_wait( &_EventWait , &_MutexWait );
2034 aret = IsSuspended() ;
2036 if ( pthread_mutex_unlock( &_MutexWait ) ) {
2037 perror("pthread_mutex_lock _SuspendedWait") ;
2040 cdebug_out << "GraphExecutor::OutNode::SuspendedWait" << endl ;
2044 bool GraphExecutor::OutNode::ReadyWait( const char * NodeName ) {
2046 cdebug_in << "GraphExecutor::OutNode::ReadyWait " << NodeName << endl;
2047 GraphExecutor::InNode *anInNode = (GraphExecutor::InNode *) Graph()->GetGraphNode( NodeName )->GetInNode() ;
2049 aret = anInNode->ReadyWait() ;
2051 cdebug_out << "GraphExecutor::OutNode::ReadyWait" << endl ;
2055 bool GraphExecutor::OutNode::RunningWait( const char * NodeName ) {
2057 cdebug_in << "GraphExecutor::OutNode::RunningWait " << NodeName << endl;
2058 GraphExecutor::InNode *anInNode = (GraphExecutor::InNode *) Graph()->GetGraphNode( NodeName )->GetInNode() ;
2060 aret = anInNode->RunningWait() ;
2062 cdebug_out << "GraphExecutor::OutNode::RunningWait" << endl ;
2066 bool GraphExecutor::OutNode::DoneWait( const char * NodeName ) {
2068 cdebug_in << "GraphExecutor::OutNode::DoneWait " << NodeName << endl;
2069 GraphExecutor::InNode *anInNode = (GraphExecutor::InNode *) Graph()->GetGraphNode( NodeName )->GetInNode() ;
2071 aret = anInNode->DoneWait() ;
2073 cdebug_out << "GraphExecutor::OutNode::DoneWait" << endl ;
2077 bool GraphExecutor::OutNode::SuspendedWait( const char * NodeName ) {
2079 cdebug_in << "GraphExecutor::OutNode::SuspendedWait " << NodeName << endl;
2080 GraphExecutor::InNode *anInNode = (GraphExecutor::InNode *) Graph()->GetGraphNode( NodeName )->GetInNode() ;
2082 aret = anInNode->SuspendedWait() ;
2084 cdebug_out << "GraphExecutor::OutNode::SuspendedWait" << endl ;
2088 long GraphExecutor::OutNode::LastLevelDone() {
2091 for ( i = 0 ; i <= Graph()->LevelMax() ; i++ ) {
2092 for ( j = 0 ; j <= Graph()->NodesNumber( i ) ; j++ ) {
2093 GraphBase::ComputingNode * aNode = Graph()->SortedNodes( i , j ) ;
2094 if ( !IsDone( aNode->Name() ) ) {
2098 if ( j != Graph()->NodesNumber( i ) + 1 )
2106 const CORBA::Any *GraphExecutor::OutNode::GetInData( const char * NodeName ,
2107 const char * ServiceParameterName ) {
2108 // cdebug_in << "GraphExecutor::OutNode::GetInData " << NodeName << " "
2109 // << ServiceParameterName << endl ;
2110 const CORBA::Any * retdata = Graph()->PortInData( NodeName , ServiceParameterName ) ;
2111 // cdebug_out << "GraphExecutor::OutNode::GetInData" << endl ;
2115 const CORBA::Any *GraphExecutor::OutNode::GetOutData( const char * NodeName ,
2116 const char * ServiceParameterName ) {
2117 // cdebug_in << "GraphExecutor::OutNode::GetOutData " << NodeName << " "
2118 // << ServiceParameterName << endl ;
2119 const CORBA::Any * retdata = Graph()->PortOutData( NodeName , ServiceParameterName ) ;
2120 // cdebug_out << "GraphExecutor::OutNode::GetOutData" << endl ;
2124 const long GraphExecutor::OutNode::CpuUsed() {
2125 return Graph()->CpuUsed() ;
2128 const long GraphExecutor::OutNode::CpuUsed( const char * aNodeName ) {
2129 GraphBase::ComputingNode * aNode = Graph()->GetChangeGraphNode( aNodeName ) ;
2131 GraphExecutor::InNode * anInNode = (GraphExecutor::InNode * ) aNode->GetInNode() ;
2133 return anInNode->CpuUsed() ;
2139 // remove equal sets "Node-Event-State" from _EventNodes/_Events/_States queues
2140 void GraphExecutor::OutNode::siftEvents() {
2141 list<char*>::reverse_iterator itNodes = _EventNodes.rbegin();
2142 list<GraphExecutor::NodeEvent>::reverse_iterator itEvents = _Events.rbegin();
2143 list<GraphExecutor::AutomatonState>::reverse_iterator itStates = _States.rbegin();
2144 list<char*> _NewEventNodes;
2145 list<GraphExecutor::NodeEvent> _NewEvents;
2146 list<GraphExecutor::AutomatonState> _NewStates;
2147 for ( ; itNodes != _EventNodes.rend() ; ++itNodes, ++itEvents, ++itStates) {
2148 //cout << "----- aNodeName ==> " << *itNodes;
2149 list<char*>::reverse_iterator itNewNodes = _NewEventNodes.rbegin();
2151 for ( ; itNewNodes != _NewEventNodes.rend() ; ++itNewNodes ) {
2152 if ( !strcmp( *itNewNodes, *itNodes ) ) {
2162 _NewEventNodes.push_back( *itNodes );
2163 _NewEvents.push_back( *itEvents );
2164 _NewStates.push_back( *itStates );
2168 _EventNodes = _NewEventNodes;
2169 _Events = _NewEvents;
2170 _States = _NewStates;