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 Set_prof_debug( ORB , DebugFileName ) ;
75 cdebug_in << "GraphExecutor::OutNode::OutNode(" << DataFlowName << " , " << DebugFileName
76 << " , " << aKindOfNode << ")" << endl;
77 if ( aKindOfNode == SUPERV::DataFlowGraph ) {
79 _Graph = new GraphBase::Graph( ORB , ptrNamingService , DataFlowName , aKindOfNode ,
80 _prof_debug , _fdebug ) ;
82 else if ( aKindOfNode == SUPERV::DataStreamGraph ) {
83 _StreamGraph = new GraphBase::StreamGraph( ORB , ptrNamingService , DataFlowName , aKindOfNode ,
84 _prof_debug , _fdebug ) ;
85 _Graph = _StreamGraph ;
87 // asv : 20.01.05 : changes involved with switching to old (HEAD) KERNEL
88 //_SuperVisionContainer = _TheContainer ;
89 //_MainThreadId = SuperVisionContainer()->MainThreadId() ;
94 _ControlState = SUPERV::VoidState ;
95 _State = GraphExecutor::UnKnownState ;
96 _PyInitialized = false ;
97 _Orb = CORBA::ORB::_duplicate( ORB ) ;
98 pthread_mutex_init( &_MutexWait , NULL ) ;
99 pthread_mutex_init( &_PyMutexWait , NULL ) ;
100 if ( pthread_cond_init( &_EventWait , NULL ) ) {
101 perror("pthread_cond_init( &_EventWait , NULL )") ;
104 if ( pthread_cond_init( &_JoinWait , NULL ) ) {
105 perror("pthread_cond_init( &_JoinWait , NULL )") ;
108 cdebug_out << "GraphExecutor::OutNode::OutNode" << endl;
111 GraphExecutor::OutNode::OutNode( CORBA::ORB_ptr ORB,
112 SALOME_NamingService* ptrNamingService ,
113 const SALOME_ModuleCatalog::Service& DataFlowService ,
114 const char *DataFlowComponentName ,
115 const char *DataFlowInterfaceName ,
116 const char *DataFlowName ,
117 const SUPERV::KindOfNode DataFlowkind ,
118 const SUPERV::SDate DataFlowFirstCreation ,
119 const SUPERV::SDate DataFlowLastModification ,
120 const char * DataFlowEditorRelease ,
121 const char * DataFlowAuthor ,
122 const char * DataFlowComputer ,
123 const char * DataFlowComment ,
124 const char * DebugFileName ) {
125 Set_prof_debug( ORB , DebugFileName ) ;
127 cdebug_in << "GraphExecutor::OutNode::OutNode(" << DataFlowComponentName << " , "
128 << DataFlowInterfaceName << " , " << DataFlowName << " , " << DataFlowkind << ")"
129 << " , ... , " << DebugFileName << ")" << endl;
130 if ( DataFlowkind == SUPERV::DataFlowGraph ) {
131 _StreamGraph = NULL ;
132 _Graph = new GraphBase::Graph( ORB , ptrNamingService , DataFlowService , DataFlowComponentName ,
133 DataFlowInterfaceName , DataFlowName , DataFlowkind ,
134 DataFlowFirstCreation , DataFlowLastModification ,
135 DataFlowEditorRelease , DataFlowAuthor ,
136 DataFlowComputer , DataFlowComment ,
137 _prof_debug , _fdebug ) ;
138 // DataFlowComputer , DataFlowComment , DebugFileName ) ;
140 else if ( DataFlowkind == SUPERV::DataStreamGraph ) {
141 _StreamGraph = new GraphBase::StreamGraph( ORB , ptrNamingService , DataFlowService , DataFlowComponentName ,
142 DataFlowInterfaceName , DataFlowName , DataFlowkind ,
143 DataFlowFirstCreation , DataFlowLastModification ,
144 DataFlowEditorRelease , DataFlowAuthor ,
145 DataFlowComputer , DataFlowComment ,
146 _prof_debug , _fdebug ) ;
147 _Graph = _StreamGraph ;
149 // asv : 20.01.05 : changes involved with switching to old (HEAD) KERNEL
150 //_SuperVisionContainer = _TheContainer ;
151 //_MainThreadId = SuperVisionContainer()->MainThreadId() ;
153 _Executable = false ;
156 _ControlState = SUPERV::VoidState ;
157 _State = GraphExecutor::UnKnownState ;
158 _PyInitialized = false ;
159 _Orb = CORBA::ORB::_duplicate( ORB ) ;
160 pthread_mutex_init( &_MutexWait , NULL ) ;
161 pthread_mutex_init( &_PyMutexWait , NULL ) ;
162 if ( pthread_cond_init( &_EventWait , NULL ) ) {
163 perror("pthread_cond_init( &_EventWait , NULL )") ;
166 if ( pthread_cond_init( &_JoinWait , NULL ) ) {
167 perror("pthread_cond_init( &_JoinWait , NULL )") ;
172 GraphExecutor::OutNode::~OutNode() {
175 void GraphExecutor::OutNode::Set_prof_debug( CORBA::ORB_ptr ORB ,
176 const char * DebugFileName ) {
177 _Graph_prof_debug = 0 ;
178 if ( DebugFileName ) {
179 _fdebug = new ofstream( DebugFileName );
180 SetDebug( ORB , &_Graph_prof_debug , _fdebug ) ;
181 MESSAGE( endl << "Trace redirected to file " << DebugFileName << endl)
185 bool GraphExecutor::OutNode::LoadDataFlow(const GraphBase::SGraph * aDataFlow ) {
186 bool RetVal = false ;
187 cdebug_in << "GraphExecutor::OutNode::LoadDataFlow " << (*aDataFlow).Info.theName << endl ;
188 RetVal = LoadInfo( (*aDataFlow).Info ) ;
189 if ( Graph()->ServiceName() != NULL ) {
190 // MESSAGE( "GraphExecutor::OutNode::LoadDataFlow" );
192 RetVal = LoadNodes( (*aDataFlow).Nodes ) ;
194 RetVal = LoadLinks( (*aDataFlow).Links ) ;
197 RetVal = LoadDatas( (*aDataFlow).Datas ) ;
200 cdebug << "GraphExecutor::OutNode::LoadDataFlow LoadDatas Error."
205 cdebug << "GraphExecutor::OutNode::LoadDataFlow LoadLinks Error."
210 cdebug << "GraphExecutor::OutNode::LoadDataFlow LoadNodes Error."
215 cdebug << "GraphExecutor::OutNode::LoadDataFlow LoadInfo Error."
220 cdebug << "GraphExecutor::OutNode::LoadDataFlow ServiceName Error." << endl ;
222 cdebug_out << "GraphExecutor::OutNode::LoadDataFlow " << Name() << " RetVal "
228 bool GraphExecutor::OutNode::LoadXml( const char* myFileName ) {
229 bool RetVal = false ;
230 GraphBase::ListOfSGraphs aListOfDataFlows ;
231 if ( Graph()->LoadXml( _Orb , myFileName , aListOfDataFlows ) ) {
232 RetVal = LoadDataFlow( aListOfDataFlows ) ;
233 // if ( aConstructor && RetVal )
234 // RetVal = Name( aDataFlow.Info.theName.c_str() ) ;
240 bool GraphExecutor::OutNode::LoadInfo(const GraphBase::SNode &aDataFlowInfo ) {
241 cdebug << "GraphExecutor::OutNode::LoadInfo _StreamGraph " << _StreamGraph << endl ;
242 // ComponentName( aDataFlowInfo.theComponentName.c_str() ) ;
243 Graph()->Name( aDataFlowInfo.theName.c_str() ) ;
244 Graph()->Kind( aDataFlowInfo.theKind ) ;
245 if ( Graph()->IsDataStreamNode() && aDataFlowInfo.theKind == SUPERV::DataStreamGraph ) {
246 StreamGraph()->SetStreamParams( aDataFlowInfo.theTimeout , aDataFlowInfo.theDataStreamTrace , aDataFlowInfo.theDeltaTime ) ;
248 Graph()->DataService( _Orb , aDataFlowInfo.theService , _prof_debug , _fdebug ) ;
249 Graph()->FirstCreation( aDataFlowInfo.theFirstCreation ) ;
250 Graph()->LastModification( aDataFlowInfo.theLastModification ) ;
251 Graph()->EditorRelease( aDataFlowInfo.theEditorRelease.c_str() ) ;
252 Graph()->Author( aDataFlowInfo.theAuthor.c_str() ) ;
253 // Graph()->Computer( aDataFlowInfo.theContainer.c_str() ) ;
254 Graph()->Comment( aDataFlowInfo.theComment.c_str() ) ;
255 // Not in OutNode/DataFlow but in InNode/DataFlow_in_an_other_DataFlow
256 // Graph()->Coordinates( aDataFlowInfo.theX , aDataFlowInfo.theY ) ;
260 bool GraphExecutor::OutNode::LoadNodes(const GraphBase::ListOfSNodes &aListOfNodes ) {
262 GraphExecutor::InNode * anInNode ;
263 cdebug << "GraphExecutor::OutNode::LoadNodes" << endl ;
265 for ( i = 0 ; i < (int ) aListOfNodes.size() ; i++ ) {
266 GraphBase::SNode aNode = aListOfNodes[ i ] ;
267 anInNode = AddNode( aNode.theService ,
268 aNode.theListOfFuncName ,
269 aNode.theListOfPythonFunctions ,
270 aNode.theComponentName.c_str() ,
271 aNode.theInterfaceName.c_str() , aNode.theName.c_str() ,
273 aNode.theFirstCreation , aNode.theLastModification ,
274 aNode.theEditorRelease.c_str() ,
275 aNode.theAuthor.c_str() , aNode.theContainer.c_str() ,
276 aNode.theComment.c_str() ,
277 aNode.theCoords.theX , aNode.theCoords.theY ) ;
282 if ( anInNode->IsOneOfInLineNodes() || anInNode->IsMacroNode() ) {
283 anInNode->GraphExecutor::InNode::InLineNode()->DefPortsOfNode(
284 _Orb , aNode.theService , anInNode->NamePtr() ,
286 _prof_debug , _fdebug ) ;
288 // GraphBase::ComputingNode * theNode = Graph()->GetChangeGraphNode( aNode.theName.c_str() ) ;
291 for ( j = 0 ; j < aNode.theListOfInDataStreams.size() ; j++ ) {
292 GraphBase::InPort * anInPort ;
293 anInPort = anInNode->ComputingNode()->AddInDataStreamPort( aNode.theListOfInDataStreams[ j ].theDataStreamParameter.Parametername ,
294 aNode.theListOfInDataStreams[ j ].theDataStreamParameter.Parametertype ,
295 aNode.theListOfInDataStreams[ j ].theDataStreamParameter.Parameterdependency ,
296 SUPERV::DataStreamParameter ) ;
297 ((GraphBase::InDataStreamPort * ) anInPort)->SetParams( aNode.theListOfInDataStreams[ j ].theKindOfSchema ,
298 aNode.theListOfInDataStreams[ j ].theKindOfInterpolation ,
299 aNode.theListOfInDataStreams[ j ].theKindOfExtrapolation ) ;
301 for ( j = 0 ; j < aNode.theListOfOutDataStreams.size() ; j++ ) {
302 GraphBase::OutPort * anOutPort ;
303 anOutPort = anInNode->ComputingNode()->AddOutDataStreamPort( aNode.theListOfOutDataStreams[ j ].theDataStreamParameter.Parametername ,
304 aNode.theListOfOutDataStreams[ j ].theDataStreamParameter.Parametertype ,
305 aNode.theListOfOutDataStreams[ j ].theDataStreamParameter.Parameterdependency ,
306 SUPERV::DataStreamParameter ) ;
307 ((GraphBase::OutDataStreamPort * ) anOutPort)->NumberOfValues( aNode.theListOfOutDataStreams[ j ].theNumberOfValues ) ;
311 // theNode->DataStreamInPortsNumber( aNode.theDataStreamInArgsNumber ) ;
312 // theNode->DataStreamOutPortsNumber( aNode.theDataStreamOutArgsNumber ) ;
313 // cdebug << "GraphExecutor::OutNode::LoadNodes " << anInNode->Name()
314 // << " InPortsSize " << theNode->GetNodeInPortsSize()
315 // << " OutPortsSize " << theNode->GetNodeOutPortsSize()
316 // << " DataStreamInPortsNumber " << aNode.theDataStreamInArgsNumber
317 // << " DataStreamOutPortsNumber " << aNode.theDataStreamOutArgsNumber
320 // if ( aNode.theDataStreamInArgsNumber ) { // -1 because of Gates
321 // for ( j = theNode->GetNodeInPortsSize() - aNode.theDataStreamInArgsNumber - 1 ; j < theNode->GetNodeInPortsSize() - 1 ; j++ ) {
322 // cdebug << "GraphExecutor::OutNode::LoadNodes " << anInNode->Name()
323 // << " InPort " << theNode->GetChangeNodeInPort( j )->PortName()
324 // << " Kind( DataStreamParameter)" << endl ;
325 // theNode->GetChangeNodeInPort( j )->Kind( SUPERV::DataStreamParameter ) ;
328 // if ( aNode.theDataStreamOutArgsNumber ) {
329 // int withgate = 1 ;
330 // if ( theNode->IsLoopNode() || theNode->IsEndLoopNode() ) {
333 // for ( j = theNode->GetNodeOutPortsSize() - aNode.theDataStreamOutArgsNumber - withgate ; j < theNode->GetNodeOutPortsSize() - withgate ; j++ ) {
334 // cdebug << "GraphExecutor::OutNode::LoadNodes " << anInNode->Name()
335 // << " OutPort " << theNode->GetChangeNodeOutPort( j )->PortName()
336 // << " Kind( DataStreamParameter)" << endl ;
337 // theNode->GetChangeNodeOutPort( j )->Kind( SUPERV::DataStreamParameter ) ;
341 for ( i = 0 ; i < (int ) aListOfNodes.size() ; i++ ) {
342 GraphBase::SNode aNode = aListOfNodes[ i ] ;
343 anInNode = (GraphExecutor::InNode * ) Graph()->GetChangeGraphNode( aNode.theName.c_str() )->GetInNode() ;
344 cdebug << "GraphExecutor::OutNode::LoadNodes " << anInNode->Name() << " IsOneOfGOTONodes "
345 << anInNode->IsOneOfGOTONodes() << " " << aNode.theCoupledNode.c_str() << endl ;
346 if ( anInNode->IsOneOfGOTONodes() && strlen( aNode.theCoupledNode.c_str() ) ) {
347 GraphBase::GOTONode * aCoupledNode ;
348 aCoupledNode = (GraphBase::GOTONode * ) Graph()->GetGraphNode( aNode.theName.c_str() ) ;
349 GraphBase::GOTONode * aCoupledCoupledNode ;
350 aCoupledCoupledNode = (GraphBase::GOTONode * ) Graph()->GetChangeGraphNode( aNode.theCoupledNode.c_str() ) ;
351 if ( aCoupledCoupledNode != NULL ) {
352 aCoupledNode->CoupledNode( aCoupledCoupledNode ) ;
355 aCoupledNode->CoupledNodeName( aNode.theCoupledNode.c_str() ) ;
362 bool GraphExecutor::OutNode::LoadLinks(const GraphBase::ListOfSLinks &aListOfLinks ) {
364 cdebug << "GraphExecutor::OutNode::LoadLinks " << aListOfLinks.size()
367 for ( i = 0 ; i < (int ) aListOfLinks.size() ; i++ ) {
368 GraphBase::SLink aLink = aListOfLinks[ i ] ;
369 RetVal = Graph()->AddLink( aLink.FromNodeName.c_str() ,
370 aLink.FromServiceParameterName.c_str() ,
371 aLink.ToNodeName.c_str() ,
372 aLink.ToServiceParameterName.c_str() ) ;
373 // , aLink.aLinkValue ) ;
380 bool GraphExecutor::OutNode::LoadDatas(const GraphBase::ListOfSLinks &aListOfDatas ) {
382 cdebug << "GraphExecutor::OutNode::LoadDatas " << aListOfDatas.size()
385 for ( i = 0 ; i < (int ) aListOfDatas.size() ; i++ ) {
386 GraphBase::SLink aLink = aListOfDatas[ i ] ;
387 if ( !strcmp( aLink.FromNodeName.c_str() , Name() ) )
388 RetVal = Graph()->AddInputData( aLink.ToNodeName.c_str() ,
389 aLink.ToServiceParameterName.c_str() ,
391 // else if ( !strcmp( aLink.ToNodeName.c_str() , Name() ) ) {
392 // RetVal = Graph()->AddOutputData( aLink.FromNodeName.c_str() ,
393 // aLink.FromServiceParameterName.c_str() ) ;
394 // Graph()->AddLink( aLink.FromNodeName.c_str() , (GraphBase::ComputingNode *) this ) ;
397 cdebug << "GraphExecutor::OutNode::LoadDatas Error " << aLink.FromNodeName
398 << " and " << aLink.ToNodeName << " differents from " << Name()
408 GraphExecutor::InNode *GraphExecutor::OutNode::AddNode(
409 const SALOME_ModuleCatalog::Service& NodeService ,
410 GraphBase::ListOfFuncName aFuncName ,
411 GraphBase::ListOfPythonFunctions aPythonFunction ,
412 const char * NodeComponentName ,
413 const char * NodeInterfaceName ,
414 const char * NodeName ,
415 const SUPERV::KindOfNode NodeKindOfNode ,
416 const SUPERV::SDate NodeFirstCreation ,
417 const SUPERV::SDate NodeLastModification ,
418 const char * NodeEditorRelease ,
419 const char * NodeAuthor ,
420 const char * NodeComputer ,
421 const char * NodeComment ,
424 cdebug_in << "GraphExecutor::OutNode::AddNode(" << NodeComponentName << " , "
425 << NodeName << ")" << endl;
426 GraphExecutor::InNode *Nd = NULL ;
427 Nd = new GraphExecutor::InNode( _Orb, Graph()->NamingService() , NodeService ,
428 NodeComponentName , NodeInterfaceName ,
429 NodeName , NodeKindOfNode ,
430 aFuncName , aPythonFunction ,
431 NodeFirstCreation , NodeLastModification ,
432 NodeEditorRelease , NodeAuthor ,
433 NodeComputer , NodeComment , false , NodeX , NodeY ,
434 _prof_debug , _fdebug ) ;
435 Graph()->AddNode( Nd->ComputingNode() ) ;
436 cdebug_out << "GraphExecutor::OutNode::AddNode" << endl;
441 bool GraphExecutor::OutNode::Valid() {
442 cdebug_in << "GraphExecutor::OutNode::Valid" << endl;
447 _Executable = false ;
449 if ( !Graph()->CreateService() ) {
450 cdebug_out << "This DataFlow has invalid type(s)." << endl ;
453 int SubStreamGraphsNumber = 0 ;
454 if ( !Graph()->Sort( SubStreamGraphsNumber ) ) {
455 cdebug_out << "This DataFlow is not valid." << endl ;
458 if ( Graph()->IsDataStreamNode() ) {
459 StreamGraph()->SubStreamGraphsNumber( SubStreamGraphsNumber ) ;
461 Graph()->InLineServices() ;
463 if ( !Graph()->ValidLoops() ) {
464 cdebug_out << "This DataFlow have not valid Loops." << endl ;
467 if ( !Graph()->ValidSwitchs() ) {
468 cdebug_out << "This DataFlow have not valid Switchs." << endl ;
474 Graph()->ComputingNodes() ;
478 cdebug_out << "GraphExecutor::OutNode::Valid " << _Valid << endl;
483 bool GraphExecutor::OutNode::Executable() {
485 cdebug_in << "GraphExecutor::OutNode::Executable" << endl;
489 if ( Graph()->DataServerNodes() )
492 cdebug << "This DataFlow is not executable." << endl ;
493 _Executable = false ;
496 cdebug_out << "GraphExecutor::OutNode::Executable " << _Executable << endl;
500 bool GraphExecutor::OutNode::Run( const bool AndSuspend ) {
501 bool RetVal = false ;
502 cdebug_in << pthread_self() << "GraphExecutor::OutNode::Run( AndSuspend " << AndSuspend
503 << " ) State " << theAutomaton->StateName( State() ) << endl;
505 if ( Executable() ) {
506 _ControlState = SUPERV::VoidState ;
507 _SuspendedThreads = 0 ;
508 Graph()->ThreadNo( pthread_self() ) ;
510 _JustStarted = true ;
513 for ( i = 0 ; i < Graph()->GraphNodesSize() ; i++ ) {
514 GraphExecutor::InNode * anInNode = (GraphExecutor::InNode *) Graph()->GraphNodes( i )->GetInNode() ;
515 anInNode->OutNode( this ) ;
516 // Initialize in python interpretor the python functions
517 if ( !PyInitialized() && anInNode->IsOneOfInLineNodes() ) {
518 if ( !Py_IsInitialized() ) {
519 // PyEval_InitThreads() ;
521 // asv : 20.01.05 : changes involved with switching to old (HEAD) KERNEL
522 // 1 line below uncommented
523 PySys_SetArgv( _ArgC , _ArgV ) ;
525 anInNode->InitPython() ;
526 PyInitialized( true ) ;
528 anInNode->InitialState() ;
529 if ( anInNode->IsOneOfInLineNodes() ) {
530 anInNode->InitPythonFunctions( false ) ;
533 // One more time because inline nodes may share one definition of the same function
534 for ( i = 0 ; i < Graph()->GraphNodesSize() ; i++ ) {
535 GraphExecutor::InNode * anInNode = (GraphExecutor::InNode *) Graph()->GraphNodes( i )->GetInNode() ;
536 if ( anInNode->IsOneOfInLineNodes() ) {
537 if ( !anInNode->InitPythonFunctions( true ) ) {
538 anInNode->State( GraphExecutor::ErroredState ) ;
540 //JR 24.03.2005 debug : State and done flags were missing
541 State( GraphExecutor::ErroredState ) ;
543 cdebug_out << "GraphExecutor::OutNode::Run InitPythonFunctions ERROR "
544 << anInNode->Name() << endl ;
549 /* asv : 29.09.04 : commented out because it does not do anything useful
550 for ( i = 0 ; i < Graph()->GraphNodesSize() ; i++ ) {
551 GraphExecutor::InNode * anInNode = (GraphExecutor::InNode *) Graph()->GraphNodes( i )->GetInNode() ;
552 if ( RetVal && anInNode->IsMacroNode() ) {
553 GraphBase::Graph * aMacroGraph = anInNode->GraphMacroNode() ;
554 cdebug << "GraphExecutor::OutNode::Run " << anInNode << " MacroNode " << aMacroGraph
555 << aMacroGraph->Name() << endl ;
556 SUPERV::Graph_var iobject = anInNode->GraphMacroNode()->MacroObject() ;
557 if ( CORBA::is_nil( iobject ) ) {
558 cdebug << "GraphExecutor::OutNode::Run MacroObject() is a nil object. Error" << endl ;
562 cdebug << "GraphExecutor::OutNode::Run MacroObject() is NOT a nil object." << endl ;
567 if ( Graph()->GraphMacroLevel() != 0 ) {
568 cdebug << "GraphExecutor::OutNode::Run Execution starting GraphExecutor::Action_DataOk_RunService Node "
569 << Name() << " GraphMacroLevel " << Graph()->GraphMacroLevel() << endl ;
570 PushEvent( NULL , GraphExecutor::NoDataReadyEvent ,
571 GraphExecutor::DataUndefState ) ;
574 cdebug << "Execution starting GraphExecutor::Action_DataOk_RunService Node "
575 << Name() << " GraphMacroLevel " << Graph()->GraphMacroLevel() << endl ;
576 PushEvent( NULL , GraphExecutor::ReadyEvent ,
577 GraphExecutor::DataReadyState ) ;
578 State( GraphExecutor::DataReadyState ) ;
580 cdebug << pthread_self() << " GraphExecutor::OutNode::Run Start of the " << Graph()->HeadNodesSize()
581 << " HeadNodes" << endl ;
582 for ( i = 0 ; i < Graph()->HeadNodesSize() ; i++ ) {
583 GraphExecutor::InNode * anInNode = (GraphExecutor::InNode *) Graph()->HeadNodes( i )->GetInNode() ;
584 cdebug << pthread_self() << "GraphExecutor::OutNode::Run Start of HeadNode " << i << " "
585 << anInNode->Name() << endl ;
586 if ( anInNode->State() != GraphExecutor::DataReadyState ) {
588 //JR 24.03.2005 debug : State and done flags were missing
589 State( GraphExecutor::ErroredState ) ;
591 cdebug << "GraphExecutor::OutNode::Run inconsistency State of Node "
592 << anInNode->Name() << " : " << anInNode->State() << endl ;
593 cdebug_out << "GraphExecutor::OutNode::Run State ERROR" << endl ;
596 // PushEvent( anInNode , GraphExecutor::ReadyEvent ,
597 // GraphExecutor::DataReadyState ) ;
598 // We say that we have to create a thread for that HeadNode 'anInNode'
599 if ( !anInNode->IsMacroNode() ) {
600 anInNode->CreateNewThread( true ) ;
601 IncrCreatedThreads() ;
603 anInNode->DataFromNode( Name() ) ;
604 // AndSuspend == true <==> Start()
606 anInNode->State( GraphExecutor::DataWaitingState ) ;
607 anInNode->ControlState( SUPERV::ToSuspendStartState ) ;
608 // We send SomeDataReadyEvent
609 // It is a HeadNode ==> AllDataReadyEvent ==> InNode::executeAction() ==> pthread_create
610 if ( !anInNode->SendEvent( GraphExecutor::SomeDataReadyEvent ) ) {
612 //JR 24.03.2005 debug : State and done flags were missing
613 State( GraphExecutor::ErroredState ) ;
615 cdebug << "InNode::SendEvent( SomeDataReadyEvent ) ERROR Node "
616 << anInNode->Name() << endl ;
617 cdebug_out << "GraphExecutor::OutNode::Run SendEvent ERROR" << endl ;
620 // ==> We wait for SuspendedState
621 anInNode->SuspendedWait() ;
623 // AndSuspend == false <==> Run()
624 else if ( anInNode->IsMacroNode() ) {
625 if ( !anInNode->SendEvent( GraphExecutor::SomeDataReadyEvent ) ) {
627 //JR 24.03.2005 debug : State and done flags were missing
628 State( GraphExecutor::ErroredState ) ;
630 cdebug << "InNode::SendEvent( SomeDataReadyEvent ) ERROR Node "
631 << anInNode->Name() << endl ;
632 cdebug_out << "GraphExecutor::OutNode::Run SendEvent ERROR" << endl ;
635 //JR 15.04.2005 Debug PAL8624 RetroConception :
636 anInNode->CreateNewThread( true ) ;
637 IncrCreatedThreads() ;
638 if ( anInNode->HasAllDataReady() ) {
639 if ( !anInNode->SendEvent( GraphExecutor::AllDataReadyEvent ) ) { // ==> Ready to execute
640 cdebug << "GraphExecutor::OutNode::Run SendEvent(AllDataReadyEvent) ERROR "
641 << " Node " << anInNode->Name() << endl ;
642 cdebug_out << "GraphExecutor::OutNode::Run SendEvent ERROR" << endl ;
647 State( GraphExecutor::ErroredState ) ;
649 cdebug << "GraphExecutor::OutNode::Run HasAllDataReady " << anInNode->HasAllDataReady()
650 << " Node " << anInNode->Name() << endl ;
651 cdebug_out << "GraphExecutor::OutNode::Run HasAllDataReady ERROR" << endl ;
654 cdebug << pthread_self() << " GraphExecutor::OutNode::Run " << anInNode->Name() << "->RunningWait"
656 // ==> We wait for RunningState
657 anInNode->RunningWait() ;
658 cdebug << pthread_self() << " GraphExecutor::OutNode::Run " << anInNode->Name() << "->RunningWaited"
661 else if ( !anInNode->IsMacroNode() ) {
662 // It is a HeadNode ==> AllDataReadyEvent ==> InNode::executeAction() ==> pthread_create
663 if ( !anInNode->SendEvent( GraphExecutor::ExecuteEvent ) ) {
665 //JR 24.03.2005 debug : State and done flags were missing
666 State( GraphExecutor::ErroredState ) ;
668 cdebug << "InNode::SendEvent( ExecuteEvent ) ERROR Node "
669 << anInNode->Name() << endl ;
670 cdebug_out << "GraphExecutor::OutNode::Run SendEvent ERROR" << endl ;
673 // ==> We wait for RunningState
674 anInNode->RunningWait() ;
679 PushEvent( NULL , GraphExecutor::SuspendedReadyEvent ,
680 GraphExecutor::SuspendedReadyState ) ;
683 PushEvent( NULL , GraphExecutor::ExecutingEvent ,
684 GraphExecutor::ExecutingState ) ;
685 if (AutomatonState() == GraphExecutor::DataReadyState) {
686 State( GraphExecutor::ExecutingState ) ;
689 // ostringstream astr ;
690 // astr << "Graph " << Name() << " is running" ;
691 // Graph()->ObjImpl()->sendMessage( NOTIF_STEP, astr.str().c_str() ) ;
697 //JR 24.03.2005 debug : State and done flags were missing
698 State( GraphExecutor::ErroredState ) ;
700 cdebug_out << "GraphExecutor::OutNode::Run Not Executable ERROR " << endl ;
704 cdebug_out << pthread_self() << "GraphExecutor::OutNode::Run " << Name()
705 << " State " << theAutomaton->StateName( State() ) << " GraphMacroLevel "
706 << Graph()->GraphMacroLevel() << " RetVal " << RetVal << endl ;
710 void GraphExecutor::OutNode::CheckAllDone() {
712 cdebug_in << "GraphExecutor::OutNode::CheckAllDone " << endl;
713 GraphExecutor::AutomatonState OutNodeState = GraphExecutor::SuccessedState ;
714 GraphExecutor::AutomatonState InNodeState ;
715 bool AllDone = true ;
717 for ( j = 0 ; j < Graph()->QueueNodesSize() ; j++ ) {
718 InNodeState = ( (GraphExecutor::InNode * ) Graph()->QueueNodes( j )->GetInNode() )->State() ;
720 << ( (GraphExecutor::InNode * ) Graph()->QueueNodes( j )->GetInNode() )->Name()
721 << " " << theAutomaton->StateName( InNodeState ) << endl ;
722 if ( InNodeState != GraphExecutor::SuccessedState &&
723 InNodeState != GraphExecutor::ErroredState &&
724 InNodeState != GraphExecutor::DataWaitingState ) {
727 if ( InNodeState != GraphExecutor::SuccessedState &&
728 InNodeState != GraphExecutor::DataWaitingState &&
729 InNodeState != GraphExecutor::DataReadyState ) {
730 OutNodeState = InNodeState ;
734 if( _Threads == 0 && _SuspendedThreads == 0 ) {
735 if ( OutNodeState != GraphExecutor::ErroredState ) {
736 OutNodeState = GraphExecutor::SuccessedState ;
745 for ( j = 0 ; j < Graph()->GraphNodesSize() ; j++ ) {
746 GraphExecutor::InNode * aNode ;
747 aNode = (GraphExecutor::InNode * ) Graph()->GraphNodes( j )->GetInNode() ;
748 SUPERV::GraphState aState = AutomatonGraphState( aNode->State() ) ;
749 cdebug << "GraphExecutor::OutNode::CheckAllDone " << aNode->Name() << " "
750 << theAutomaton->StateName( aNode->State() ) << " CreateNewThread " << aNode->CreateNewThread()
752 if ( aState == SUPERV::ErrorState ||
753 aState == SUPERV::SuspendErroredState ||
754 aState == SUPERV::KillState ||
755 aState == SUPERV::StopState ) {
756 OutNodeState = aNode->State() ;
757 State( OutNodeState ) ;
759 else if ( aState == SUPERV::ReadyState ||
760 aState == SUPERV::SuspendReadyState ||
761 aState == SUPERV::RunningState ||
762 aState == SUPERV::SuspendDoneState ||
763 aState == SUPERV::SuspendErroredState ||
764 aState == SUPERV::SuspendState ) {
767 aNode->SuspendedAction() ;
768 aNode->DoneAction() ;
770 // PushEvent AFTER State and _Done ! ...
771 if ( alivenodes == 0 ) {
772 State( OutNodeState ) ;
774 _JustStarted = false ;
776 cdebug << Name() << " alivenodes " << alivenodes << " OutNodeState " << OutNodeState
778 PushEvent( NULL , GraphExecutor::EndExecuteEvent ,
781 // PyInitialized( false ) ;
785 MESSAGE("================================================================================") ;
786 MESSAGE( Name() << " IS DONE : " << theAutomaton->StateName( AutomatonState() ) << " EventQSize "
788 MESSAGE("================================================================================") ;
789 cdebug << "================================================================================" << endl ;
790 cdebug << Name() << " IS DONE : " << theAutomaton->StateName( AutomatonState() ) << " EventQSize "
791 << EventQSize() << endl ;
792 cdebug << "================================================================================" << endl ;
795 //JR 23.02.2005, Debug : siftEvents() must be inside the pthread_mutex_lock
796 if ( pthread_mutex_lock( &_MutexWait ) ) {
797 perror("EventLoop pthread_mutex_lock ") ;
800 // asv : fix for 6798 and other bugs: "sift" the event queue after execution
802 if ( pthread_mutex_unlock( &_MutexWait ) ) {
803 perror("PushEvent pthread_mutex_unlock ") ;
807 // asv : 25.10.04 : calling Editing() to indicate stop of execution
808 Graph()->GraphEditor()->Editing();
810 cdebug_out << "GraphExecutor::OutNode::CheckAllDone " << IsDone() << " this " << this << " "
811 << Name() << " GraphAutomatonState "
812 << theAutomaton->StateName( AutomatonState() )
813 << " State " << State() << " Threads " << _Threads << " SuspendedThreads "
814 << _SuspendedThreads << " EventQSize " << EventQSize() << endl ;
817 // asv : 20.01.05 : changes involved with switching to old (HEAD) KERNEL
818 //Engines_Container_i * GraphExecutor::OutNode::SuperVisionContainer() {
819 // return _SuperVisionContainer ;
822 //const pthread_t GraphExecutor::OutNode::MainThreadId() const {
823 // return _MainThreadId ;
826 void GraphExecutor::OutNode::PThreadLock( pthread_mutex_t * aMutex , char * errmsg ) {
827 // if ( strcmp( errmsg , "EventLoop" ) && strcmp( errmsg , "EventW" ) ) {
828 // cdebug << "GraphExecutor::OutNode::PThreadLock " << pthread_self() << " " << aMutex << " "
829 // << errmsg << endl ;
831 if ( pthread_mutex_lock( aMutex ) ) {
835 // if ( strcmp( errmsg , "EventLoop" ) && strcmp( errmsg , "EventW" ) ) {
836 // cdebug << "GraphExecutor::OutNode::PThreadLocked " << pthread_self() << " " << aMutex << " "
837 // << errmsg << endl ;
841 void GraphExecutor::OutNode::PThreadUnLock( pthread_mutex_t * aMutex , char * errmsg ) {
842 // if ( strcmp( errmsg , "EventLoop" ) && strcmp( errmsg , "EventW" ) ) {
843 // cdebug << " GraphExecutor::OutNode::PThreadUnLock " << pthread_self() << " " << aMutex << " "
844 // << errmsg << endl ;
846 if ( pthread_mutex_unlock( aMutex ) ) {
852 void GraphExecutor::OutNode::PyThreadLock() {
853 // cout << " GraphExecutor::OutNode::PyThreadLock " << pthread_self() << endl ;
854 if ( pthread_mutex_lock( &_PyMutexWait ) ) {
855 perror( "GraphExecutor::OutNode::PyThreadLock" ) ;
858 theAutomaton->PyLock() ;
859 // cout << " GraphExecutor::OutNode::PyThreadLocked " << pthread_self() << endl ;
862 void GraphExecutor::OutNode::PyThreadUnLock() {
863 // cout << " GraphExecutor::OutNode::PyThreadUnLock " << pthread_self() << endl ;
864 if ( pthread_mutex_unlock( &_PyMutexWait ) ) {
865 perror( "GraphExecutor::OutNode::PyThreadUnLock" ) ;
868 theAutomaton->PyUnLock() ;
869 // cout << " GraphExecutor::OutNode::PyThreadUnLocked " << pthread_self() << endl ;
872 void GraphExecutor::OutNode::NewThread() {
873 if ( pthread_mutex_lock( &_MutexWait ) ) {
874 perror("pthread_mutex_lock _NewThread") ;
878 // cdebug << "NewThread : " << _Threads << " running threads "
879 // << _SuspendedThreads << " suspended threads"
881 if ( pthread_mutex_unlock( &_MutexWait ) ) {
882 perror("pthread_mutex_unlock _NewThread") ;
887 void GraphExecutor::OutNode::ExitThread( pthread_t ThreadNumber ) {
888 if ( pthread_mutex_lock( &_MutexWait ) ) {
889 perror("pthread_mutex_lock _ExitThread") ;
892 if ( ThreadNumber == 0 ) {
893 ThreadNumber = pthread_self() ;
896 // cdebug << pthread_self() << " ExitThread( " << ThreadNumber << " ) " << _Threads << " running threads "
897 // << _SuspendedThreads << " suspended threads"
899 theAutomaton->JoinThread( ThreadNumber ) ;
900 if ( pthread_cond_signal( &_JoinWait ) ) {
901 perror("ExitThread pthread_cond_signal ") ;
903 if ( pthread_mutex_unlock( &_MutexWait ) ) {
904 perror("pthread_mutex_unlock _ExitThread") ;
907 if ( _Threads == 0 && _SuspendedThreads == 0 ) {
910 theAutomaton->Executed() ;
914 void GraphExecutor::OutNode::JoinedWait() {
915 if ( pthread_mutex_lock( &_MutexWait ) ) {
916 perror("pthread_mutex_lock JoinedWait") ;
920 if ( pthread_cond_wait( &_JoinWait , &_MutexWait ) ) {
921 perror("JoinedWait pthread_cond_wait ") ;
924 if ( pthread_mutex_unlock( &_MutexWait ) ) {
925 perror("pthread_mutex_unlock JoinedWait") ;
930 void GraphExecutor::OutNode::SuspendThread() {
931 if ( pthread_mutex_lock( &_MutexWait ) ) {
932 perror("pthread_mutex_lock _SuspendThread") ;
935 _SuspendedThreads += 1 ;
936 cdebug << "SuspendThread : " << _Threads << " running threads "
937 << _SuspendedThreads << " suspended threads"
939 if ( pthread_mutex_unlock( &_MutexWait ) ) {
940 perror("pthread_mutex_unlock _SuspendThread") ;
943 if ( IsSuspended() ) {
944 PushEvent( NULL , GraphExecutor::SuspendEvent , GraphExecutor::SuspendedState ) ;
947 void GraphExecutor::OutNode::ResumeThread() {
948 if ( pthread_mutex_lock( &_MutexWait ) ) {
949 perror("pthread_mutex_lock _ResumeThread") ;
952 _SuspendedThreads -= 1 ;
953 cdebug << "ResumeThread : " << _Threads << " running threads "
954 << _SuspendedThreads << " suspended threads"
956 if ( pthread_mutex_unlock( &_MutexWait ) ) {
957 perror("pthread_mutex_unlock _ResumeThread") ;
962 long GraphExecutor::OutNode::Thread( const char * aNodeName ) {
964 GraphExecutor::InNode *anInNode = (GraphExecutor::InNode *) Graph()->GetGraphNode( aNodeName )->GetInNode() ;
966 RetVal = anInNode->ThreadNo() ;
971 SUPERV::GraphEvent GraphExecutor::OutNode::AutomatonGraphEvent(GraphExecutor::NodeEvent anEvent ) {
972 SUPERV::GraphEvent aGraphEvent ;
974 case GraphExecutor::UndefinedEvent : {
975 aGraphEvent = SUPERV::UndefinedEvent ;
978 case GraphExecutor::NewThreadEvent : {
979 aGraphEvent = SUPERV::NewThreadEvent ;
982 case GraphExecutor::SuspendEvent : {
983 aGraphEvent = SUPERV::SuspendEvent ;
986 case GraphExecutor::ResumeEvent : {
987 aGraphEvent = SUPERV::ResumeEvent ;
990 case GraphExecutor::KillEvent : {
991 aGraphEvent = SUPERV::KillEvent ;
994 case GraphExecutor::StopEvent : {
995 aGraphEvent = SUPERV::StopEvent ;
998 case GraphExecutor::ExecuteEvent : {
999 aGraphEvent = SUPERV::RunningEvent ;
1002 case GraphExecutor::SuccessEvent : {
1003 aGraphEvent = SUPERV::DoneEvent ;
1006 case GraphExecutor::ErrorEvent : {
1007 aGraphEvent = SUPERV::ErroredEvent ;
1010 case GraphExecutor::NoDataReadyEvent : {
1011 aGraphEvent = SUPERV::WaitingEvent ;
1014 case GraphExecutor::SomeDataReadyEvent : {
1015 aGraphEvent = SUPERV::WaitingEvent ;
1018 case GraphExecutor::NotAllDataReadyEvent : {
1019 aGraphEvent = SUPERV::WaitingEvent ;
1022 case GraphExecutor::AllDataReadyEvent : {
1023 aGraphEvent = SUPERV::ReadyEvent ;
1026 case GraphExecutor::ReadyEvent : {
1027 aGraphEvent = SUPERV::ReadyEvent ;
1030 case GraphExecutor::SuspendedReadyEvent : {
1031 aGraphEvent = SUPERV::SuspendEvent ;
1034 case GraphExecutor::ResumedReadyEvent : {
1035 aGraphEvent = SUPERV::ResumeEvent ;
1038 case GraphExecutor::KilledReadyEvent : {
1039 aGraphEvent = SUPERV::KillEvent ;
1042 case GraphExecutor::StoppedReadyEvent : {
1043 aGraphEvent = SUPERV::StopEvent ;
1046 case GraphExecutor::ExecutingEvent : {
1047 aGraphEvent = SUPERV::RunningEvent ;
1050 case GraphExecutor::SuspendedExecutingEvent : {
1051 aGraphEvent = SUPERV::SuspendEvent ;
1054 case GraphExecutor::ResumedExecutingEvent : {
1055 aGraphEvent = SUPERV::ResumeEvent ;
1058 case GraphExecutor::KilledExecutingEvent : {
1059 aGraphEvent = SUPERV::KillEvent ;
1062 case GraphExecutor::StoppedExecutingEvent : {
1063 aGraphEvent = SUPERV::StopEvent ;
1066 case GraphExecutor::SuccessedExecutingEvent : {
1067 aGraphEvent = SUPERV::DoneEvent ;
1070 case GraphExecutor::ErroredExecutingEvent : {
1071 aGraphEvent = SUPERV:: ErroredEvent;
1074 case GraphExecutor::SuspendedSuccessedEvent : {
1075 aGraphEvent = SUPERV::SuspendEvent ;
1078 case GraphExecutor::SuspendedErroredEvent : {
1079 aGraphEvent = SUPERV::SuspendEvent ;
1082 case GraphExecutor::ResumedSuccessedEvent : {
1083 aGraphEvent = SUPERV::ResumeEvent ;
1086 case GraphExecutor::ResumedErroredEvent : {
1087 aGraphEvent = SUPERV::ResumeEvent ;
1090 case GraphExecutor::KilledEvent : {
1091 aGraphEvent = SUPERV::KillEvent ;
1094 case GraphExecutor::StoppedEvent : {
1095 aGraphEvent = SUPERV::StopEvent ;
1098 case GraphExecutor::EndExecuteEvent : {
1099 aGraphEvent = SUPERV::DoneEvent ;
1103 cdebug << " GraphExecutor::OutNode::AutomatonGraphEvent Error Undefined Event : "
1104 << anEvent << endl ;
1105 aGraphEvent = SUPERV::UndefinedEvent ;
1108 return aGraphEvent ;
1111 SUPERV::GraphState GraphExecutor::OutNode::AutomatonGraphState(GraphExecutor::AutomatonState aState ) {
1112 SUPERV::GraphState aGraphState ;
1114 case GraphExecutor::UnKnownState : {
1115 aGraphState = SUPERV::UndefinedState ;
1118 case GraphExecutor::DataUndefState : {
1119 aGraphState = SUPERV::UndefinedState ;
1122 case GraphExecutor::DataWaitingState : {
1123 aGraphState = SUPERV::WaitingState ;
1126 case GraphExecutor::DataReadyState : {
1127 aGraphState = SUPERV::ReadyState ;
1130 case GraphExecutor::SuspendedReadyState : {
1131 aGraphState = SUPERV::SuspendReadyState ;
1134 case GraphExecutor::ResumedReadyState : {
1135 aGraphState = SUPERV::ReadyState ;
1138 case GraphExecutor::KilledReadyState : {
1139 aGraphState = SUPERV::KillState ;
1142 case GraphExecutor::StoppedReadyState : {
1143 aGraphState = SUPERV::StopState ;
1146 case GraphExecutor::ExecutingState : {
1147 aGraphState = SUPERV::RunningState ;
1150 case GraphExecutor::SuspendedExecutingState : {
1151 aGraphState = SUPERV::SuspendState ;
1154 case GraphExecutor::ResumedExecutingState : {
1155 aGraphState = SUPERV::RunningState ;
1158 case GraphExecutor::KilledExecutingState : {
1159 aGraphState = SUPERV::KillState ;
1162 case GraphExecutor::StoppedExecutingState : {
1163 aGraphState = SUPERV::StopState ;
1166 case GraphExecutor::SuccessedExecutingState : {
1167 aGraphState = SUPERV::DoneState ;
1170 case GraphExecutor::ErroredExecutingState : {
1171 aGraphState = SUPERV::ErrorState ;
1174 case GraphExecutor::SuspendedSuccessedState : {
1175 aGraphState = SUPERV::SuspendDoneState ;
1178 case GraphExecutor::SuspendedErroredState : {
1179 aGraphState = SUPERV::SuspendErroredState ;
1182 case GraphExecutor::ResumedSuccessedState : {
1183 aGraphState = SUPERV::DoneState ;
1186 case GraphExecutor::ResumedErroredState : {
1187 aGraphState = SUPERV::ErrorState ;
1190 case GraphExecutor::KilledSuccessedState : {
1191 aGraphState = SUPERV::KillState ;
1194 case GraphExecutor::KilledErroredState : {
1195 aGraphState = SUPERV::KillState ;
1198 case GraphExecutor::StoppedSuccessedState : {
1199 aGraphState = SUPERV::StopState ;
1202 case GraphExecutor::StoppedErroredState : {
1203 aGraphState = SUPERV::StopState ;
1206 case GraphExecutor::SuccessedState : {
1207 aGraphState = SUPERV::DoneState ;
1210 case GraphExecutor::ErroredState : {
1211 aGraphState = SUPERV::ErrorState ;
1214 case GraphExecutor::SuspendedState : {
1215 aGraphState = SUPERV::SuspendState ;
1218 case GraphExecutor::KilledState : {
1219 aGraphState = SUPERV::KillState ;
1222 case GraphExecutor::StoppedState : {
1223 aGraphState = SUPERV::StopState ;
1226 case GraphExecutor::LoadingState : {
1227 aGraphState = SUPERV::LoadingState ;
1231 cdebug << " GraphExecutor::OutNode::AutomatonGraphState Error Undefined State : "
1232 << aGraphState << endl ;
1233 aGraphState = SUPERV::UndefinedState ;
1236 return aGraphState ;
1239 //JR 07.04.2005, Debug : access to _EventNodes must be inside the pthread_mutex_lock
1240 int GraphExecutor::OutNode::GetListSize() {
1241 if ( pthread_mutex_lock( &_MutexWait ) ) {
1242 perror("PushEvent pthread_mutex_lock ") ;
1245 int eventnbr = _EventNodes.size();
1246 if ( pthread_mutex_unlock( &_MutexWait ) ) {
1247 perror("PushEvent pthread_mutex_unlock ") ;
1253 bool GraphExecutor::OutNode::PushEvent( GraphExecutor::InNode * aNode ,
1254 GraphExecutor::NodeEvent anEvent ,
1255 GraphExecutor::AutomatonState aState ) {
1256 // cdebug_in << "PushEvent Threads " << Threads() << " SuspendedThreads "
1257 // << SuspendedThreads() << endl ;
1258 if ( pthread_mutex_lock( &_MutexWait ) ) {
1259 perror("PushEvent pthread_mutex_lock ") ;
1262 char* aNodeName = aNode ? aNode->Name() : Name() ;
1263 _EventNodes.push_back( aNodeName ) ;
1264 _Events.push_back( anEvent ) ;
1265 _States.push_back( aState ) ;
1267 pthread_cond_broadcast( &_EventWait );
1268 // cdebug << pthread_self() << " PushEvent Threads " << Threads() << " SuspendedThreads "
1269 // << SuspendedThreads() << " pthread_cond_broadcast _EventWait " << &_EventWait << endl ;
1271 // cdebug << aNode->ThreadNo() << " PushEvent " << aNode->Name() ;
1272 // cdebug << " " << aNode->Automaton()->EventName( anEvent )
1273 // << " " << aNode->Automaton()->StateName( aState )
1274 // << " ControleState "
1275 // << aNode->Automaton()->ControlStateName( aNode->ControlState() ) ;
1278 // cdebug << "PushEvent " << Name() ;
1279 // cdebug << " " << theAutomaton->EventName( anEvent ) << " "
1280 // << theAutomaton->StateName( aState ) ;
1282 // cdebug_out << "PushEvent Threads " << Threads() << " SuspendedThreads "
1283 // << SuspendedThreads() << endl ;
1286 //JR 21.02.2005 Debug : old events should be removed at creation time for python-clients
1287 int EventNodesSize = _EventNodes.size() ;
1288 if ( EventNodesSize > Graph()->GraphNodesSize()*70 ) {
1290 // cdebug << "OutNode::PushEvent " << _EventNodes.size() << " in queue instead of "
1291 // << EventNodesSize << endl ;
1294 if ( pthread_mutex_unlock( &_MutexWait ) ) {
1295 perror("PushEvent pthread_mutex_unlock ") ;
1301 bool GraphExecutor::OutNode::StateWait( SUPERV::GraphState aState ) {
1305 bool GraphExecutor::OutNode::Event( char ** aNodeName ,
1306 SUPERV::GraphEvent & anEvent ,
1307 SUPERV::GraphState & aState ,
1310 //JR 23.02.2005, Debug : siftEvents() must be inside the pthread_mutex_lock
1311 if ( pthread_mutex_lock( &_MutexWait ) ) {
1312 perror("EventLoop pthread_mutex_lock ") ;
1315 // asv : fixing problem of loops with large number of iterations (>5000)
1316 // experimentally was found that number of non-handled by GUI events = (number_of_nodes x 7)
1317 // or 7 events for each node - so what we want to do here is remove "old" events for nodes
1318 // "on the fly". Once again it is done in Stop(), Kill(), Done() functions.
1319 int EventNodessize = _EventNodes.size() ;
1320 if ( EventNodessize > Graph()->GraphNodesSize()*7 )
1324 int SuspendedThreadsNumber ;
1325 bool cdebuginout = false ;
1326 if ( _EventNodes.size() > 0 ) {
1327 // cdebug_in << "GraphExecutor::OutNode::Event " << _EventNodes.size() << " in queue instead of "
1328 // << EventNodessize << endl ;
1329 cdebuginout = true ;
1331 _JustStarted = false ;
1332 ThreadsNumber = Threads() ;
1333 SuspendedThreadsNumber = SuspendedThreads() ;
1334 bool RetVal = ( ThreadsNumber - SuspendedThreadsNumber) != 0 ||
1335 _EventNodes.size() > 0 ;
1336 char * NodeName = "" ;
1337 GraphExecutor::NodeEvent theEvent = GraphExecutor::UndefinedEvent ;
1338 GraphExecutor::AutomatonState theState = GraphExecutor::UnKnownState ;
1339 anEvent = SUPERV::UndefinedEvent ;
1340 aState = SUPERV::UndefinedState ;
1341 if ( ( Done() || IsKilled() || IsStopped() ) && _EventNodes.size() == 0 ) {
1342 // cdebug << "EventLoop Done()/IsKilled()/IsStopped() && _EventNodes.size() == 0" << endl ;
1345 else if ( !WithWait && _EventNodes.size() == 0 ) {
1346 anEvent = SUPERV::NoEvent ;
1347 aState = SUPERV::NoState ;
1350 else if ( RetVal ) {
1351 while ( !IsSuspended() && _EventNodes.size() == 0 ) {
1352 // cdebug << "EventLoop pthread_cond_wait _EventWait" << endl ;
1353 pthread_cond_wait( &_EventWait , &_MutexWait );
1354 // cdebug << "EventLoop pthread_cond_waited _EventWait"
1355 // << " _EventNodes.size() " << _EventNodes.size() << endl ;
1357 if ( _EventNodes.size() ) {
1358 ThreadsNumber = Threads() ;
1359 NodeName = _EventNodes.front() ;
1360 _EventNodes.pop_front() ;
1361 theEvent = _Events.front() ;
1362 anEvent = AutomatonGraphEvent( theEvent ) ;
1363 _Events.pop_front() ;
1364 theState = _States.front() ;
1365 aState = AutomatonGraphState( theState ) ;
1366 _States.pop_front() ;
1369 *aNodeName = NodeName ;
1370 if ( IsSuspended() && _EventNodes.size() == 0 ) {
1373 if ( anEvent != SUPERV::NoEvent ) {
1374 // cdebug << pthread_self() << "EventLoop "
1375 // << NodeName << " " << theAutomaton->StateName( theState )
1376 // << " _EventNodes.size() " << _EventNodes.size()
1377 // << " Threads " << Threads() << " SuspendedThreads "
1378 // << SuspendedThreads() << " RetVal " << RetVal << endl ;
1380 if ( pthread_mutex_unlock( &_MutexWait ) ) {
1381 perror("EventLoop pthread_mutex_lock ") ;
1384 if ( cdebuginout ) {
1385 // cdebug_out << "GraphExecutor::OutNode::Event " << _EventNodes.size() << " in queue"
1386 // << *aNodeName << " " << anEvent << " " << aState << endl ;
1391 bool GraphExecutor::OutNode::EventW( char ** aNodeName ,
1392 SUPERV::GraphEvent & anEvent ,
1393 SUPERV::GraphState & aState ) {
1396 aState = SUPERV::UndefinedState ;
1398 aState != SUPERV::SuspendReadyState &&
1399 aState != SUPERV::RunningState &&
1400 aState != SUPERV::SuspendDoneState &&
1401 aState != SUPERV::SuspendErroredState ) {
1403 while ( sts && !strcmp( NodeName , Name() ) ) {
1404 sts = EventWait( aNodeName , anEvent , aState ) ;
1405 NodeName = *aNodeName ;
1411 bool GraphExecutor::OutNode::EventWait( char ** aNodeName ,
1412 SUPERV::GraphEvent & anEvent ,
1413 SUPERV::GraphState & aState ) {
1414 if ( pthread_mutex_lock( &_MutexWait ) ) {
1415 perror("EventW pthread_mutex_lock ") ;
1419 int SuspendedThreadsNumber ;
1420 ThreadsNumber = Threads() ;
1421 SuspendedThreadsNumber = SuspendedThreads() ;
1422 bool RetVal = ( ThreadsNumber - SuspendedThreadsNumber) != 0 ||
1423 _EventNodes.size() > 0 ;
1424 cdebug << "--> EventW RetVal " << RetVal << endl ;
1425 char * NodeName = "" ;
1426 GraphExecutor::NodeEvent theEvent = GraphExecutor::UndefinedEvent ;
1427 GraphExecutor::AutomatonState theState = GraphExecutor::UnKnownState ;
1428 anEvent = SUPERV::UndefinedEvent ;
1429 aState = SUPERV::UndefinedState ;
1430 if ( IsDone() && _EventNodes.size() == 0 ) {
1431 cdebug << "EventW IsDone() && _EventNodes.size() == 0" << endl ;
1434 else if ( RetVal ) {
1435 GraphExecutor::InNode * aNode = NULL ;
1436 while ( aNode == NULL && RetVal ) {
1437 NodeName = _EventNodes.front() ;
1438 theEvent = _Events.front() ;
1439 anEvent = AutomatonGraphEvent( theEvent ) ;
1440 theState = _States.front() ;
1441 aState = AutomatonGraphState( theState ) ;
1443 if ( _JustStarted ) {
1444 _JustStarted = false ;
1447 _EventNodes.pop_front() ;
1448 _Events.pop_front() ;
1449 _States.pop_front() ;
1452 aNode = ((GraphExecutor::InNode *) Graph()->GetGraphNode( NodeName )->GetInNode()) ;
1453 cdebug << "EventW Previous Node " << NodeName << " ThreadsNumber "
1455 << " _EventNodes.size() " << _EventNodes.size() << " "
1456 << theAutomaton->StateName( theState )
1457 << " Threads " << Threads() << " SuspendedThreads "
1458 << SuspendedThreads() << endl ;
1461 else if ( IsDone() && _EventNodes.size() == 0 ) {
1462 cdebug << "EventW IsDone() && _EventNodes.size() == 0" << endl ;
1466 cdebug << "EventW Not InNode " << NodeName
1467 << " _EventNodes.size() " << _EventNodes.size() << endl ;
1468 while ( _EventNodes.size() == 0 ) {
1469 pthread_cond_wait( &_EventWait , &_MutexWait );
1471 cdebug << "EventW pthread_cond_waited Not InNode " << NodeName
1472 << " _EventNodes.size() " << _EventNodes.size() << endl ;
1477 if ( aState == SUPERV::SuspendState ||
1478 aState == SUPERV::SuspendReadyState ||
1479 aState == SUPERV::SuspendDoneState ||
1480 aState == SUPERV::SuspendErroredState ) {
1481 aNode->ControlState( SUPERV::ToSuspendState ) ;
1482 if ( aNode->IsSuspended() ) {
1483 if ( pthread_mutex_unlock( &_MutexWait ) ) {
1484 perror("EventW pthread_mutex_lock ") ;
1487 cdebug << "EventW " << aNode->Name() << " ResumeAction" << endl ;
1488 aNode->ResumeAction( GraphExecutor::ToResumeEvent ) ;
1489 cdebug << "EventW " << aNode->Name() << " ResumedAction" << endl ;
1490 if ( pthread_mutex_lock( &_MutexWait ) ) {
1491 perror("EventW pthread_mutex_lock ") ;
1496 cdebug << "EventW inconsistent SuspendState" << endl ;
1501 if ( aNode->IsDone() ) {
1505 cdebug << "EventW NOT SuspendedState _EventNodes.size() "
1506 << _EventNodes.size() << endl ;
1511 cdebug << "EventW " << aNode->Name() << " pthread_cond_wait" << endl ;
1512 while ( _EventNodes.size() == 0 ) {
1513 pthread_cond_wait( &_EventWait , &_MutexWait );
1515 ThreadsNumber = Threads() ;
1516 NodeName = _EventNodes.front() ;
1517 theEvent = _Events.front() ;
1518 anEvent = AutomatonGraphEvent( theEvent ) ;
1519 theState = _States.front() ;
1520 aState = AutomatonGraphState( theState ) ;
1524 *aNodeName = NodeName ;
1525 cdebug << "<-- EventW RetVal " << RetVal << " " << NodeName
1526 << " Threads " << Threads() << " SuspendedThreads "
1527 << SuspendedThreads()
1528 << " _EventNodes.size() " << _EventNodes.size()
1529 << " " << theAutomaton->EventName( theEvent ) << " "
1530 << theAutomaton->StateName( theState ) << endl ;
1531 if ( pthread_mutex_unlock( &_MutexWait ) ) {
1532 perror("EventW pthread_mutex_lock ") ;
1537 long GraphExecutor::OutNode::EventQSize() {
1538 return _EventNodes.size() ;
1541 void GraphExecutor::OutNode::EventList() {
1542 if ( pthread_mutex_lock( &_MutexWait ) ) {
1543 perror("EventList pthread_mutex_lock ") ;
1546 list< char * >::iterator itEventNodes = _EventNodes.begin() ;
1547 list< GraphExecutor::NodeEvent >::iterator itEvents = _Events.begin() ;
1548 list< GraphExecutor::AutomatonState >::iterator itStates = _States.begin() ;
1549 while ( itEventNodes != _EventNodes.end() ) {
1550 cdebug << pthread_self() << "EVENTSTACK "
1551 << *itEventNodes << " " << *itEvents << " "
1552 << theAutomaton->StateName( *itStates )
1553 << " Threads " << Threads() << " SuspendedThreads " << SuspendedThreads() << endl ;
1558 if ( pthread_mutex_unlock( &_MutexWait ) ) {
1559 perror("EventList pthread_mutex_lock ") ;
1564 void GraphExecutor::OutNode::SendSomeDataReady( const char * aNodeName ) {
1565 cdebug_in << "GraphExecutor::OutNode::SendSomeDataReady " << aNodeName << "->SendSomeDataReady( "
1566 << Name() << " )" << endl;
1568 sts = ((GraphExecutor::InNode * ) Graph()->GetChangeGraphNode( aNodeName )->GetInNode())->SendSomeDataReady( Name() ) ;
1569 cdebug_out << "GraphExecutor::OutNode::SendSomeDataReady sts " << sts << endl ;
1572 void GraphExecutor::OutNode::State(GraphExecutor::AutomatonState aState ) {
1573 // cdebug << "GraphExecutor::OutNode::State " << Name() << " "
1574 // << theAutomaton->StateName( AutomatonGraphState( _State ) ) << " ---> "
1575 // << theAutomaton->StateName( AutomatonGraphState( aState ) ) << endl ;
1579 SUPERV::GraphState GraphExecutor::OutNode::State() {
1580 // cdebug_in << "GraphExecutor::OutNode::State" << endl;
1581 // cdebug_out << "GraphExecutor::OutNode::State" << endl ;
1582 // cdebug << "GraphExecutor::OutNode::State GraphState "
1583 // << theAutomaton->StateName( AutomatonGraphState( _State ) ) << endl ;
1584 return AutomatonGraphState( _State ) ;
1587 SUPERV::GraphState GraphExecutor::OutNode::State( const char * NodeName ) {
1588 // cdebug_in << "GraphExecutor::OutNode::State " << NodeName << endl;
1589 GraphExecutor::AutomatonState aret = GraphExecutor::UnKnownState ;
1590 const GraphBase::ComputingNode * aCNode = Graph()->GetGraphNode( NodeName ) ;
1592 GraphExecutor::InNode *anInNode = (GraphExecutor::InNode *)aCNode->GetInNode() ;
1594 aret = anInNode->State() ;
1595 // asv 27.01.05 - fix for PAL7849, return "Loading" state only if internal state is SUPERV::RunningState
1596 if ( ( aret == GraphExecutor::ExecutingState ||
1597 aret == GraphExecutor::ResumedExecutingState ) &&
1598 anInNode->IsLoading() )
1599 aret = GraphExecutor::LoadingState;
1600 // cdebug << "GraphExecutor::OutNode::State( " << NodeName << " ) "
1601 // << theAutomaton->StateName( AutomatonGraphState( aret ) ) << endl ;
1604 // cdebug_out << "GraphExecutor::OutNode::State" << endl ;
1605 return AutomatonGraphState( aret ) ;
1608 SUPERV::GraphState GraphExecutor::OutNode::State( const char * NodeName ,
1609 const char * ServiceParameterName ) {
1610 // cdebug_in << "GraphExecutor::OutNode::State " << NodeName << " "
1611 // << ServiceParameterName<< endl;
1612 SUPERV::GraphState aret = Graph()->PortState( NodeName , ServiceParameterName ) ;
1613 // cdebug_out << "GraphExecutor::OutNode::State" << endl ;
1617 GraphExecutor::AutomatonState GraphExecutor::OutNode::AutomatonState() {
1618 // cdebug_in << "GraphExecutor::OutNode::AutomatonState" << endl;
1619 // cdebug_out << "GraphExecutor::OutNode::AutomatonState" << endl ;
1623 GraphExecutor::AutomatonState GraphExecutor::OutNode::AutomatonState( const char * NodeName ) {
1624 // cdebug_in << "GraphExecutor::OutNode::AutomatonState " << NodeName << endl;
1625 GraphExecutor::AutomatonState aret = GraphExecutor::UnKnownState ;
1626 const GraphBase::ComputingNode * aNode = Graph()->GetGraphNode( NodeName ) ;
1628 GraphExecutor::InNode *anInNode = (GraphExecutor::InNode *) aNode->GetInNode() ;
1630 aret = anInNode->State() ;
1633 // cdebug_out << "GraphExecutor::OutNode::AutomatonState" << endl ;
1637 SUPERV::ControlState GraphExecutor::OutNode::ControlState() {
1638 // cdebug_in << "GraphExecutor::OutNode::ControlState" << endl;
1639 // cdebug_out << "GraphExecutor::OutNode::ControlState" << endl ;
1640 return _ControlState ;
1643 SUPERV::ControlState GraphExecutor::OutNode::ControlState( const char * NodeName ) {
1644 // cdebug_in << "GraphExecutor::OutNode::ControlState " << NodeName << endl;
1645 SUPERV::ControlState aret = SUPERV::VoidState ;
1646 const GraphBase::ComputingNode * aNode = Graph()->GetGraphNode( NodeName ) ;
1648 GraphExecutor::InNode *anInNode = (GraphExecutor::InNode *) aNode->GetInNode() ;
1650 aret = anInNode->ControlState() ;
1653 // cdebug_out << "GraphExecutor::OutNode::ControlState" << endl ;
1657 void GraphExecutor::OutNode::ControlClear() {
1658 // cdebug_in << "GraphExecutor::OutNode::ControlClear" << endl;
1659 // cdebug_out << "GraphExecutor::OutNode::ControlClear" << endl ;
1660 _ControlState = SUPERV::VoidState;
1663 void GraphExecutor::OutNode::ControlClear( const char * NodeName ) {
1664 // cdebug_in << "GraphExecutor::OutNode::ControlClear " << NodeName << endl;
1665 const GraphBase::ComputingNode * aNode = Graph()->GetGraphNode( NodeName ) ;
1667 GraphExecutor::InNode *anInNode = (GraphExecutor::InNode *) aNode->GetInNode() ;
1669 anInNode->ControlClear() ;
1672 // cdebug_out << "GraphExecutor::OutNode::ControlClear" << endl ;
1675 bool GraphExecutor::OutNode::IsWaiting() {
1676 // cdebug_in << "GraphExecutor::OutNode::IsWaiting" << endl;
1677 // cdebug_out << "GraphExecutor::OutNode::IsWaiting" << endl ;
1681 bool GraphExecutor::OutNode::IsReady() {
1682 // cdebug_in << "GraphExecutor::OutNode::IsReady" << endl;
1683 // cdebug_out << "GraphExecutor::OutNode::IsReady" << endl ;
1687 bool GraphExecutor::OutNode::IsRunning() {
1688 // cdebug_in << "GraphExecutor::OutNode::IsRunning" << endl;
1689 // cdebug_out << "GraphExecutor::OutNode::IsRunning" << endl ;
1693 bool GraphExecutor::OutNode::IsDone() {
1694 // cdebug_in << "GraphExecutor::OutNode::IsDone" << endl;
1695 // cdebug_out << "GraphExecutor::OutNode::IsDone" << endl ;
1696 return ( Done() || IsKilled() || IsStopped() ) ;
1699 bool GraphExecutor::OutNode::IsSuspended() {
1700 // cdebug_in << "GraphExecutor::OutNode::IsSuspended" << endl;
1702 // if ( _SuspendedThreads == _Threads && _Threads != 0 ) {
1703 if ( AutomatonGraphState( _State ) == SUPERV::SuspendState ) {
1706 // cdebug_out << "GraphExecutor::OutNode::IsSuspended" << endl ;
1710 bool GraphExecutor::OutNode::IsKilled() {
1711 // cdebug_in << "GraphExecutor::OutNode::IsKilled" << endl;
1713 if ( AutomatonGraphState( _State ) == SUPERV::KillState ) {
1716 // cdebug_out << "GraphExecutor::OutNode::IsKilled" << endl ;
1720 bool GraphExecutor::OutNode::IsStopped() {
1721 // cdebug_in << "GraphExecutor::OutNode::IsStopped" << endl;
1723 if ( AutomatonGraphState( _State ) == SUPERV::StopState ) {
1726 // cdebug_out << "GraphExecutor::OutNode::IsStopped" << endl ;
1730 bool GraphExecutor::OutNode::IsWaiting( const char * NodeName ) {
1732 // cdebug_in << "GraphExecutor::OutNode::IsWaiting " << NodeName << endl;
1733 GraphExecutor::InNode *anInNode = (GraphExecutor::InNode *) Graph()->GetGraphNode( NodeName )->GetInNode() ;
1735 aret = anInNode->IsWaiting() ;
1737 // cdebug_out << "GraphExecutor::OutNode::IsWaiting" << endl ;
1741 bool GraphExecutor::OutNode::IsReady( const char * NodeName ) {
1743 // cdebug_in << "GraphExecutor::OutNode::IsReady " << NodeName << endl;
1744 GraphExecutor::InNode *anInNode = (GraphExecutor::InNode *) Graph()->GetGraphNode( NodeName )->GetInNode() ;
1746 aret = anInNode->IsReady() ;
1748 // cdebug_out << "GraphExecutor::OutNode::IsReady" << endl ;
1752 bool GraphExecutor::OutNode::IsRunning( const char * NodeName ) {
1754 // cdebug_in << "GraphExecutor::OutNode::IsRunning " << NodeName << endl;
1755 GraphExecutor::InNode *anInNode = (GraphExecutor::InNode *) Graph()->GetGraphNode( NodeName )->GetInNode() ;
1757 aret = anInNode->IsRunning() ;
1759 // cdebug_out << "GraphExecutor::OutNode::IsRunning" << endl ;
1763 bool GraphExecutor::OutNode::IsDone( const char * NodeName ) {
1765 // cdebug_in << "GraphExecutor::OutNode::IsDone " << NodeName << endl;
1766 GraphExecutor::InNode *anInNode = (GraphExecutor::InNode *) Graph()->GetGraphNode( NodeName )->GetInNode() ;
1768 aret = anInNode->IsDone() ;
1770 // cdebug_out << "GraphExecutor::OutNode::IsDone" << endl ;
1774 bool GraphExecutor::OutNode::IsSuspended( const char * NodeName ) {
1776 // cdebug_in << "GraphExecutor::OutNode::IsSuspended " << NodeName << endl;
1777 GraphExecutor::InNode *anInNode = (GraphExecutor::InNode *) Graph()->GetGraphNode( NodeName )->GetInNode() ;
1779 aret = anInNode->IsSuspended() ;
1781 // cdebug_out << "GraphExecutor::OutNode::IsSuspended" << endl ;
1785 bool GraphExecutor::OutNode::PortDone( const char * NodeName ,
1786 const char * ServiceParameterName ) {
1787 // cdebug_in << "GraphExecutor::OutNode::IsDone " << NodeName << " "
1788 // << ServiceParameterName<< endl;
1789 bool aret = Graph()->PortDone( NodeName , ServiceParameterName ) ;
1790 // cdebug_out << "GraphExecutor::OutNode::IsDone" << endl ;
1794 bool GraphExecutor::OutNode::ContainerKill() {
1795 bool RetVal = true ;
1796 cdebug_in << "GraphExecutor::OutNode::ContainerKill" << endl;
1797 _ControlState = SUPERV::ToSuspendState ;
1799 for ( i = 0 ; i < Graph()->GraphNodesSize() ; i++ ) {
1800 GraphExecutor::InNode * aNode = (GraphExecutor::InNode * ) Graph()->GraphNodes( i )->GetInNode() ;
1801 bool sts = aNode->ContainerKill() ;
1802 if ( sts && aNode->IsKilled() ) {
1803 cdebug << aNode->Name() << " killed" << endl ;
1805 else if ( aNode->IsWaiting() || aNode->IsDone() ) {
1806 cdebug << aNode->Name() << " not killed : "
1807 << theAutomaton->StateName( aNode->State() ) << endl ;
1810 cdebug << aNode->Name() << " cannot be killed : "
1811 << theAutomaton->StateName( aNode->State() ) << endl ;
1815 if ( !RetVal || Threads() != 0 ) {
1816 for ( i = 0 ; i < Graph()->GraphNodesSize() ; i++ ) {
1817 GraphExecutor::InNode * aNode = (GraphExecutor::InNode * ) Graph()->GraphNodes( i )->GetInNode() ;
1818 if ( !aNode->IsKilled() && !aNode->IsWaiting() && !aNode->IsDone() ) {
1819 aNode->KilledAction() ;
1824 State( GraphExecutor::KilledState ) ;
1825 cdebug_out << "GraphExecutor::OutNode::ContainerKill" << endl ;
1829 bool GraphExecutor::OutNode::Suspend() {
1831 cdebug_in << "GraphExecutor::OutNode::Suspend" << endl;
1832 // _ControlState = SUPERV::ToSuspendState ;
1834 for ( i = 0 ; i < Graph()->GraphNodesSize() ; i++ ) {
1835 GraphExecutor::InNode * aNode = (GraphExecutor::InNode * ) Graph()->GraphNodes( i )->GetInNode() ;
1836 bool sts = aNode->Suspend() ;
1837 if ( sts && aNode->IsSuspended() ) {
1839 cdebug << aNode->Name() << " Suspended" << endl ;
1841 else if ( aNode->IsWaiting() || aNode->IsReady() ) {
1843 cdebug << aNode->Name() << " will be Suspended" << endl ;
1845 else if ( aNode->IsDone() ) {
1846 cdebug << aNode->Name() << " not Suspended : "
1847 << theAutomaton->StateName( aNode->State() ) << endl ;
1851 cdebug << aNode->Name() << " cannot be Suspended : "
1852 << theAutomaton->StateName( aNode->State() ) << endl ;
1856 State( GraphExecutor::SuspendedState ) ;
1857 MESSAGE("================================================================================") ;
1858 MESSAGE( Name() << " IS SUSPENDED" ) ;
1859 MESSAGE("================================================================================") ;
1862 MESSAGE("================================================================================") ;
1863 MESSAGE( Name() << " IS NOT SUSPENDED" ) ;
1864 MESSAGE("================================================================================") ;
1866 for ( i = 0 ; i < Graph()->GraphNodesSize() ; i++ ) {
1867 GraphExecutor::InNode * aNode = (GraphExecutor::InNode * ) Graph()->GraphNodes( i )->GetInNode() ;
1868 MESSAGE(aNode->Name() << " " << theAutomaton->StateName( aNode->State() ) ) ;
1869 cdebug << aNode->Name() << " " << theAutomaton->StateName( aNode->State() ) << endl ;
1871 cdebug_out << "GraphExecutor::OutNode::Suspend " << theAutomaton->StateName( State() )
1872 << " EventQSize " << EventQSize() << endl ;
1876 bool GraphExecutor::OutNode::Resume() {
1878 cdebug_in << "GraphExecutor::OutNode::Resume "
1879 << theAutomaton->StateName( State() ) << endl;
1880 if ( IsSuspended() ) {
1881 State( GraphExecutor::ExecutingState ) ;
1883 for ( i = 0 ; i < Graph()->GraphNodesSize() ; i++ ) {
1884 GraphExecutor::InNode * aNode = (GraphExecutor::InNode * ) Graph()->GraphNodes( i )->GetInNode() ;
1885 aNode->ControlState( SUPERV::VoidState ) ;
1886 if ( aNode->IsSuspended() ) {
1887 cdebug << aNode->Name() << "->Resume " << theAutomaton->StateName( aNode->State() )
1889 if ( aNode->Resume() ) {
1890 cdebug << aNode->Name() << " Resumed " << theAutomaton->StateName( aNode->State() )
1895 cdebug << aNode->Name() << " Resume failed"
1896 << theAutomaton->StateName( aNode->State() ) << endl ;
1900 cdebug << aNode->Name() << " " << theAutomaton->StateName( aNode->State() )
1906 cdebug << Name() << " not suspended " << theAutomaton->StateName( State() ) << endl ;
1909 MESSAGE("================================================================================") ;
1910 MESSAGE( Name() << " IS RESUMED" ) ;
1911 MESSAGE("================================================================================") ;
1914 MESSAGE("================================================================================") ;
1915 MESSAGE( Name() << " IS NOT RESUMED" ) ;
1916 MESSAGE("================================================================================") ;
1919 for ( i = 0 ; i < Graph()->GraphNodesSize() ; i++ ) {
1920 GraphExecutor::InNode * aNode = (GraphExecutor::InNode * ) Graph()->GraphNodes( i )->GetInNode() ;
1921 MESSAGE(aNode->Name() << " " << theAutomaton->StateName( aNode->State() ) ) ;
1922 cdebug << aNode->Name() << " " << theAutomaton->StateName( aNode->State() ) << endl ;
1924 cdebug_out << "GraphExecutor::OutNode::Resume" << theAutomaton->StateName( State() ) << " " << RetVal
1925 << " EventQSize " << EventQSize() << endl ;
1929 bool GraphExecutor::OutNode::Kill() {
1930 bool RetVal = false ;
1931 cdebug_in << "GraphExecutor::OutNode::Kill"
1932 << " EventQSize " << EventQSize() << " State "
1933 << theAutomaton->StateName( State() ) << endl;
1935 cdebug_out << "GraphExecutor::OutNode::Kill " << RetVal
1936 << " Threads " << _Threads << " SuspendedThreads " << _SuspendedThreads
1937 << " EventQSize " << EventQSize() << " State "
1938 << theAutomaton->StateName( State() ) << endl ;
1941 _ControlState = SUPERV::ToSuspendState ;
1943 for ( i = 0 ; i < Graph()->GraphNodesSize() ; i++ ) {
1944 GraphExecutor::InNode * aNode = (GraphExecutor::InNode * ) Graph()->GraphNodes( i )->GetInNode() ;
1945 bool sts = aNode->Kill() ;
1946 if ( sts && Threads() != 0 ) {
1947 if ( !aNode->IsKilled() ) {
1948 cdebug << aNode->Name() << " not killed : "
1949 << theAutomaton->StateName( aNode->State() ) << " " << aNode->Name() << "->"
1950 << "KilledAction()" << endl ;
1951 MESSAGE( aNode->Name() << " not killed : KilledAction()" ) ;
1952 aNode->KilledAction() ;
1954 if ( aNode->IsKilled() ) {
1955 cdebug << aNode->Name() << " killed" << endl ;
1960 // JR 24.03.2005 Debug : the node may have been killed
1961 else if ( aNode->IsKilled() ) {
1962 cdebug << aNode->Name() << " killed" << endl ;
1965 else if ( aNode->IsWaiting() || aNode->IsDone() ) {
1966 cdebug << aNode->Name() << " not killed : "
1967 << theAutomaton->StateName( aNode->State() ) << endl ;
1970 cdebug << aNode->Name() << " cannot be killed : "
1971 << theAutomaton->StateName( aNode->State() ) << endl ;
1975 State( GraphExecutor::KilledState ) ;
1976 MESSAGE("================================================================================") ;
1977 MESSAGE( Name() << " IS KILLED" << theAutomaton->StateName( AutomatonState() ) << " EventQSize "
1979 MESSAGE("================================================================================") ;
1982 MESSAGE("================================================================================") ;
1983 MESSAGE( Name() << " IS NOT KILLED" ) ;
1984 MESSAGE("================================================================================") ;
1986 for ( i = 0 ; i < Graph()->GraphNodesSize() ; i++ ) {
1987 GraphExecutor::InNode * aNode = (GraphExecutor::InNode * ) Graph()->GraphNodes( i )->GetInNode() ;
1988 MESSAGE(aNode->Name() << " " << theAutomaton->StateName( aNode->State() ) ) ;
1989 cdebug << aNode->Name() << " " << theAutomaton->StateName( aNode->State() ) << endl ;
1992 if ( pthread_mutex_lock( &_MutexWait ) ) {
1993 perror("EventLoop pthread_mutex_lock ") ;
1997 //JR 23.02.2005, Debug : siftEvents() must be inside the pthread_mutex_lock
1998 // remove "extra" events from the event queue
2000 if ( pthread_mutex_unlock( &_MutexWait ) ) {
2001 perror("PushEvent pthread_mutex_unlock ") ;
2005 // asv : 25.10.04 : calling Editing() to indicate stop of execution
2006 Graph()->GraphEditor()->Editing();
2008 cdebug_out << "GraphExecutor::OutNode::Kill " << RetVal
2009 << " Threads " << _Threads << " SuspendedThreads " << _SuspendedThreads
2010 << " EventQSize " << EventQSize() << endl ;
2015 bool GraphExecutor::OutNode::Stop() {
2016 bool RetVal = false ;
2017 cdebug_in << "GraphExecutor::OutNode::Stop" << endl;
2019 cdebug_out << "GraphExecutor::OutNode::Stop" << endl ;
2021 MESSAGE("================================================================================") ;
2022 MESSAGE( Name() << " IS STOPPED" ) ;
2023 MESSAGE("================================================================================") ;
2028 bool GraphExecutor::OutNode::ReadyWait() {
2029 cdebug_in << "GraphExecutor::OutNode::ReadyWait" << endl;
2031 if ( pthread_mutex_lock( &_MutexWait ) ) {
2032 perror("pthread_mutex_lock _ReadyWait") ;
2038 pthread_cond_wait( &_EventWait , &_MutexWait );
2041 if ( pthread_mutex_unlock( &_MutexWait ) ) {
2042 perror("pthread_mutex_lock _ReadyWait") ;
2045 cdebug_out << "GraphExecutor::OutNode::ReadyWait" << endl ;
2049 bool GraphExecutor::OutNode::RunningWait() {
2050 cdebug_in << "GraphExecutor::OutNode::RunningWait" << endl;
2052 if ( pthread_mutex_lock( &_MutexWait ) ) {
2053 perror("pthread_mutex_lock _RunningWait") ;
2056 aret = IsRunning() ;
2058 cdebug << "RunningWait pthread_cond_wait _EventWait" << endl;
2059 pthread_cond_wait( &_EventWait , &_MutexWait );
2060 aret = IsRunning() ;
2061 cdebug << "RunningWait pthread_cond_waited _EventWait " << aret << endl;
2063 if ( pthread_mutex_unlock( &_MutexWait ) ) {
2064 perror("pthread_mutex_lock _RunningWait") ;
2067 cdebug_out << "GraphExecutor::OutNode::RunningWait " << aret << endl ;
2071 bool GraphExecutor::OutNode::DoneWait() {
2072 cdebug_in << pthread_self() << " GraphExecutor::DoneWait " << this << " " << Name() << endl;
2074 if ( pthread_mutex_lock( &_MutexWait ) ) {
2075 perror("pthread_mutex_lock _DoneWait") ;
2079 while ( !aret && !IsSuspended() && IsRunning() ) {
2080 cdebug << pthread_self() << " GraphExecutor::DoneWait " << this << " " << Name()
2081 << " DoneWait pthread_cond_wait _EventWait " << &_EventWait << endl;
2082 pthread_cond_wait( &_EventWait , &_MutexWait );
2084 cdebug << pthread_self() << " GraphExecutor::DoneWait " << this << " " << Name()
2085 << " DoneWait pthread_cond_waited _EventWaited " << &_EventWait << " : "<< aret << endl;
2087 if ( pthread_mutex_unlock( &_MutexWait ) ) {
2088 perror("pthread_mutex_lock _DoneWait") ;
2091 cdebug_out << pthread_self() << " GraphExecutor::DoneWait " << this << " " << Name()
2092 << " " << State() << " : " << aret << endl ;
2096 bool GraphExecutor::OutNode::SuspendedWait() {
2097 cdebug_in << "GraphExecutor::OutNode::SuspendedWait" << endl;
2099 if ( pthread_mutex_lock( &_MutexWait ) ) {
2100 perror("pthread_mutex_lock _SuspendedWait") ;
2103 aret = IsSuspended() ;
2104 while ( !aret && !IsDone() ) {
2105 pthread_cond_wait( &_EventWait , &_MutexWait );
2106 aret = IsSuspended() ;
2108 if ( pthread_mutex_unlock( &_MutexWait ) ) {
2109 perror("pthread_mutex_lock _SuspendedWait") ;
2112 cdebug_out << "GraphExecutor::OutNode::SuspendedWait" << endl ;
2116 bool GraphExecutor::OutNode::ReadyWait( const char * NodeName ) {
2118 cdebug_in << "GraphExecutor::OutNode::ReadyWait " << NodeName << endl;
2119 GraphExecutor::InNode *anInNode = (GraphExecutor::InNode *) Graph()->GetGraphNode( NodeName )->GetInNode() ;
2121 aret = anInNode->ReadyWait() ;
2123 cdebug_out << "GraphExecutor::OutNode::ReadyWait" << endl ;
2127 bool GraphExecutor::OutNode::RunningWait( const char * NodeName ) {
2129 cdebug_in << "GraphExecutor::OutNode::RunningWait " << NodeName << endl;
2130 GraphExecutor::InNode *anInNode = (GraphExecutor::InNode *) Graph()->GetGraphNode( NodeName )->GetInNode() ;
2132 aret = anInNode->RunningWait() ;
2134 cdebug_out << "GraphExecutor::OutNode::RunningWait" << endl ;
2138 bool GraphExecutor::OutNode::DoneWait( const char * NodeName ) {
2140 cdebug_in << "GraphExecutor::OutNode::DoneWait " << NodeName << endl;
2141 GraphExecutor::InNode *anInNode = (GraphExecutor::InNode *) Graph()->GetGraphNode( NodeName )->GetInNode() ;
2143 aret = anInNode->DoneWait() ;
2145 cdebug_out << "GraphExecutor::OutNode::DoneWait" << endl ;
2149 bool GraphExecutor::OutNode::SuspendedWait( const char * NodeName ) {
2151 cdebug_in << "GraphExecutor::OutNode::SuspendedWait " << NodeName << endl;
2152 GraphExecutor::InNode *anInNode = (GraphExecutor::InNode *) Graph()->GetGraphNode( NodeName )->GetInNode() ;
2154 aret = anInNode->SuspendedWait() ;
2156 cdebug_out << "GraphExecutor::OutNode::SuspendedWait" << endl ;
2160 long GraphExecutor::OutNode::LastLevelDone() {
2163 for ( i = 0 ; i <= Graph()->LevelMax() ; i++ ) {
2164 for ( j = 0 ; j <= Graph()->NodesNumber( i ) ; j++ ) {
2165 GraphBase::ComputingNode * aNode = Graph()->SortedNodes( i , j ) ;
2166 if ( !IsDone( aNode->Name() ) ) {
2170 if ( j != Graph()->NodesNumber( i ) + 1 )
2178 //JR 30.03.2005const CORBA::Any *GraphExecutor::OutNode::GetInData( const char * NodeName ,
2179 const CORBA::Any GraphExecutor::OutNode::GetInData( const char * NodeName ,
2180 const char * ServiceParameterName ) {
2181 // cdebug_in << "GraphExecutor::OutNode::GetInData " << NodeName << " "
2182 // << ServiceParameterName << endl ;
2183 //JR 30.03.2005 const CORBA::Any * retdata = Graph()->PortInData( NodeName , ServiceParameterName ) ;
2184 const CORBA::Any retdata = Graph()->PortInData( NodeName , ServiceParameterName ) ;
2185 // cdebug_out << "GraphExecutor::OutNode::GetInData" << endl ;
2189 //JR 30.03.2005const CORBA::Any *GraphExecutor::OutNode::GetOutData( const char * NodeName ,
2190 const CORBA::Any GraphExecutor::OutNode::GetOutData( const char * NodeName ,
2191 const char * ServiceParameterName ) {
2192 // cdebug_in << "GraphExecutor::OutNode::GetOutData " << NodeName << " "
2193 // << ServiceParameterName << endl ;
2194 //JR 30.03.2005 const CORBA::Any * retdata = Graph()->PortOutData( NodeName , ServiceParameterName ) ;
2195 const CORBA::Any retdata = Graph()->PortOutData( NodeName , ServiceParameterName ) ;
2196 // cdebug_out << "GraphExecutor::OutNode::GetOutData" << endl ;
2200 const long GraphExecutor::OutNode::CpuUsed() {
2201 return Graph()->CpuUsed() ;
2204 const long GraphExecutor::OutNode::CpuUsed( const char * aNodeName ) {
2205 GraphBase::ComputingNode * aNode = Graph()->GetChangeGraphNode( aNodeName ) ;
2207 GraphExecutor::InNode * anInNode = (GraphExecutor::InNode * ) aNode->GetInNode() ;
2209 return anInNode->CpuUsed() ;
2215 // remove equal sets "Node-Event-State" from _EventNodes/_Events/_States queues
2216 void GraphExecutor::OutNode::siftEvents() {
2217 list<char*>::reverse_iterator itNodes = _EventNodes.rbegin();
2218 list<GraphExecutor::NodeEvent>::reverse_iterator itEvents = _Events.rbegin();
2219 list<GraphExecutor::AutomatonState>::reverse_iterator itStates = _States.rbegin();
2220 list<char*> _NewEventNodes;
2221 list<GraphExecutor::NodeEvent> _NewEvents;
2222 list<GraphExecutor::AutomatonState> _NewStates;
2223 for ( ; itNodes != _EventNodes.rend() ; ++itNodes, ++itEvents, ++itStates) {
2224 //cout << "----- aNodeName ==> " << *itNodes;
2225 list<char*>::reverse_iterator itNewNodes = _NewEventNodes.rbegin();
2227 for ( ; itNewNodes != _NewEventNodes.rend() ; ++itNewNodes ) {
2228 if ( !strcmp( *itNewNodes, *itNodes ) ) {
2238 _NewEventNodes.push_back( *itNodes );
2239 _NewEvents.push_back( *itEvents );
2240 _NewStates.push_back( *itStates );
2244 _EventNodes = _NewEventNodes;
2245 _Events = _NewEvents;
2246 _States = _NewStates;