1 // Copyright (C) 2007-2008 CEA/DEN, EDF R&D, OPEN CASCADE
3 // Copyright (C) 2003-2007 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.salome-platform.org/ or email : webmaster.salome@opencascade.com
22 // SUPERV GraphExecutor : contains classes that permit execution of graphs and particularly the execution automaton
23 // File : DataFlowBase_OutNode.cxx
24 // Author : Jean Rahuel, CEA
30 #include "DataFlowExecutor_OutNode.hxx"
32 #include "DataFlowEditor_DataFlow.hxx"
33 #include "DataFlowExecutor_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() ;
53 _NodeAborted = false ;
55 _ControlState = SUPERV::VoidState ;
56 _State = GraphExecutor::UnKnownState ;
57 _PyInitialized = false ;
59 pthread_mutex_init( &_MutexWait , NULL ) ;
60 pthread_mutex_init( &_PyMutexWait , NULL ) ;
61 if ( pthread_cond_init( &_EventWait , NULL ) ) {
62 perror("pthread_cond_init( &_EventWait , NULL )") ;
65 if ( pthread_cond_init( &_JoinWait , NULL ) ) {
66 perror("pthread_cond_init( &_JoinWait , NULL )") ;
71 GraphExecutor::OutNode::OutNode( CORBA::ORB_ptr ORB,
72 SALOME_NamingService* ptrNamingService ,
73 const char *DataFlowName ,
74 const char * DebugFileName ,
75 const SUPERV::KindOfNode aKindOfNode ) {
76 Set_prof_debug( ORB , DebugFileName ) ;
77 cdebug_in << "GraphExecutor::OutNode::OutNode(" << DataFlowName << " , " << DebugFileName
78 << " , " << aKindOfNode << ")" << endl;
79 if ( aKindOfNode == SUPERV::DataFlowGraph ) {
81 _Graph = new GraphBase::Graph( ORB , ptrNamingService , DataFlowName , aKindOfNode ,
82 _prof_debug , _fdebug ) ;
84 else if ( aKindOfNode == SUPERV::DataStreamGraph ) {
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() ;
95 _NodeAborted = false ;
97 _ControlState = SUPERV::VoidState ;
98 _State = GraphExecutor::UnKnownState ;
99 _PyInitialized = false ;
100 _run_func_thread = 0;
101 _Orb = CORBA::ORB::_duplicate( ORB ) ;
102 pthread_mutex_init( &_MutexWait , NULL ) ;
103 pthread_mutex_init( &_PyMutexWait , NULL ) ;
104 if ( pthread_cond_init( &_EventWait , NULL ) ) {
105 perror("pthread_cond_init( &_EventWait , NULL )") ;
108 if ( pthread_cond_init( &_JoinWait , NULL ) ) {
109 perror("pthread_cond_init( &_JoinWait , NULL )") ;
112 cdebug_out << "GraphExecutor::OutNode::OutNode" << endl;
115 GraphExecutor::OutNode::OutNode( CORBA::ORB_ptr ORB,
116 SALOME_NamingService* ptrNamingService ,
117 const SALOME_ModuleCatalog::Service& DataFlowService ,
118 const char *DataFlowComponentName ,
119 const char *DataFlowInterfaceName ,
120 const char *DataFlowName ,
121 const SUPERV::KindOfNode DataFlowkind ,
122 const SUPERV::SDate DataFlowFirstCreation ,
123 const SUPERV::SDate DataFlowLastModification ,
124 const char * DataFlowEditorRelease ,
125 const char * DataFlowAuthor ,
126 const char * DataFlowComputer ,
127 const char * DataFlowComment ,
128 const char * DebugFileName ) {
129 Set_prof_debug( ORB , DebugFileName ) ;
131 cdebug_in << "GraphExecutor::OutNode::OutNode(" << DataFlowComponentName << " , "
132 << DataFlowInterfaceName << " , " << DataFlowName << " , " << DataFlowkind << ")"
133 << " , ... , " << DebugFileName << ")" << endl;
134 if ( DataFlowkind == SUPERV::DataFlowGraph ) {
135 _StreamGraph = NULL ;
136 _Graph = new GraphBase::Graph( ORB , ptrNamingService , DataFlowService , DataFlowComponentName ,
137 DataFlowInterfaceName , DataFlowName , DataFlowkind ,
138 DataFlowFirstCreation , DataFlowLastModification ,
139 DataFlowEditorRelease , DataFlowAuthor ,
140 DataFlowComputer , DataFlowComment ,
141 _prof_debug , _fdebug ) ;
142 // DataFlowComputer , DataFlowComment , DebugFileName ) ;
144 else if ( DataFlowkind == SUPERV::DataStreamGraph ) {
145 _StreamGraph = new GraphBase::StreamGraph( ORB , ptrNamingService , DataFlowService , DataFlowComponentName ,
146 DataFlowInterfaceName , DataFlowName , DataFlowkind ,
147 DataFlowFirstCreation , DataFlowLastModification ,
148 DataFlowEditorRelease , DataFlowAuthor ,
149 DataFlowComputer , DataFlowComment ,
150 _prof_debug , _fdebug ) ;
151 _Graph = _StreamGraph ;
153 // asv : 20.01.05 : changes involved with switching to old (HEAD) KERNEL
154 //_SuperVisionContainer = _TheContainer ;
155 //_MainThreadId = SuperVisionContainer()->MainThreadId() ;
157 _Executable = false ;
159 _NodeAborted = false ;
161 _ControlState = SUPERV::VoidState ;
162 _State = GraphExecutor::UnKnownState ;
163 _PyInitialized = false ;
164 _run_func_thread = 0;
165 _Orb = CORBA::ORB::_duplicate( ORB ) ;
166 pthread_mutex_init( &_MutexWait , NULL ) ;
167 pthread_mutex_init( &_PyMutexWait , NULL ) ;
168 if ( pthread_cond_init( &_EventWait , NULL ) ) {
169 perror("pthread_cond_init( &_EventWait , NULL )") ;
172 if ( pthread_cond_init( &_JoinWait , NULL ) ) {
173 perror("pthread_cond_init( &_JoinWait , NULL )") ;
178 GraphExecutor::OutNode::~OutNode() {
181 void GraphExecutor::OutNode::Set_prof_debug( CORBA::ORB_ptr ORB ,
182 const char * DebugFileName ) {
183 _Graph_prof_debug = 0 ;
184 if ( DebugFileName ) {
185 _fdebug = new ofstream( DebugFileName );
186 SetDebug( ORB , &_Graph_prof_debug , _fdebug ) ;
187 MESSAGE( endl << "Trace redirected to file " << DebugFileName << endl)
191 bool GraphExecutor::OutNode::LoadDataFlow(const GraphBase::SGraph * aDataFlow ) {
192 bool RetVal = false ;
193 cdebug_in << "GraphExecutor::OutNode::LoadDataFlow " << (*aDataFlow).Info.theName << endl ;
194 RetVal = LoadInfo( (*aDataFlow).Info ) ;
195 if ( Graph()->ServiceName() != NULL ) {
196 // MESSAGE( "GraphExecutor::OutNode::LoadDataFlow" );
198 RetVal = LoadNodes( (*aDataFlow).Nodes ) ;
200 RetVal = LoadLinks( (*aDataFlow).Links ) ;
203 RetVal = LoadDatas( (*aDataFlow).Datas ) ;
206 cdebug << "GraphExecutor::OutNode::LoadDataFlow LoadDatas Error."
211 cdebug << "GraphExecutor::OutNode::LoadDataFlow LoadLinks Error."
216 cdebug << "GraphExecutor::OutNode::LoadDataFlow LoadNodes Error."
221 cdebug << "GraphExecutor::OutNode::LoadDataFlow LoadInfo Error."
226 cdebug << "GraphExecutor::OutNode::LoadDataFlow ServiceName Error." << endl ;
228 cdebug_out << "GraphExecutor::OutNode::LoadDataFlow " << Name() << " RetVal "
234 bool GraphExecutor::OutNode::LoadXml( const char* myFileName ) {
235 bool RetVal = false ;
236 GraphBase::ListOfSGraphs aListOfDataFlows ;
237 if ( Graph()->LoadXml( _Orb , myFileName , aListOfDataFlows ) ) {
238 RetVal = LoadDataFlow( aListOfDataFlows ) ;
239 // if ( aConstructor && RetVal )
240 // RetVal = Name( aDataFlow.Info.theName.c_str() ) ;
246 bool GraphExecutor::OutNode::LoadInfo(const GraphBase::SNode &aDataFlowInfo ) {
247 cdebug << "GraphExecutor::OutNode::LoadInfo _StreamGraph " << _StreamGraph << endl ;
248 // ComponentName( aDataFlowInfo.theComponentName.c_str() ) ;
249 Graph()->Name( aDataFlowInfo.theName.c_str() ) ;
250 Graph()->Kind( aDataFlowInfo.theKind ) ;
251 if ( Graph()->IsDataStreamNode() && aDataFlowInfo.theKind == SUPERV::DataStreamGraph ) {
252 StreamGraph()->SetStreamParams( aDataFlowInfo.theTimeout , aDataFlowInfo.theDataStreamTrace , aDataFlowInfo.theDeltaTime ) ;
254 Graph()->DataService( _Orb , aDataFlowInfo.theService , _prof_debug , _fdebug ) ;
255 Graph()->FirstCreation( aDataFlowInfo.theFirstCreation ) ;
256 Graph()->LastModification( aDataFlowInfo.theLastModification ) ;
257 Graph()->EditorRelease( aDataFlowInfo.theEditorRelease.c_str() ) ;
258 Graph()->Author( aDataFlowInfo.theAuthor.c_str() ) ;
259 // Graph()->Computer( aDataFlowInfo.theContainer.c_str() ) ;
260 Graph()->Comment( aDataFlowInfo.theComment.c_str() ) ;
261 // Not in OutNode/DataFlow but in InNode/DataFlow_in_an_other_DataFlow
262 // Graph()->Coordinates( aDataFlowInfo.theX , aDataFlowInfo.theY ) ;
266 bool GraphExecutor::OutNode::LoadNodes(const GraphBase::ListOfSNodes &aListOfNodes ) {
268 GraphExecutor::InNode * anInNode ;
269 cdebug << "GraphExecutor::OutNode::LoadNodes" << endl ;
271 for ( i = 0 ; i < (int ) aListOfNodes.size() ; i++ ) {
272 GraphBase::SNode aNode = aListOfNodes[ i ] ;
273 anInNode = AddNode( aNode.theService ,
274 aNode.theListOfFuncName ,
275 aNode.theListOfPythonFunctions ,
276 aNode.theComponentName.c_str() ,
277 aNode.theInterfaceName.c_str() , aNode.theName.c_str() ,
279 aNode.theFirstCreation , aNode.theLastModification ,
280 aNode.theEditorRelease.c_str() ,
281 aNode.theAuthor.c_str() , aNode.theContainer.c_str() ,
282 aNode.theComment.c_str() ,
283 aNode.theCoords.theX , aNode.theCoords.theY ) ;
288 if ( anInNode->IsOneOfInLineNodes() || anInNode->IsMacroNode() ) {
289 anInNode->GraphExecutor::InNode::InLineNode()->DefPortsOfNode(
290 _Orb , aNode.theService , anInNode->NamePtr() ,
292 _prof_debug , _fdebug ) ;
294 // GraphBase::ComputingNode * theNode = Graph()->GetChangeGraphNode( aNode.theName.c_str() ) ;
297 for ( j = 0 ; j < aNode.theListOfInDataStreams.size() ; j++ ) {
298 GraphBase::InPort * anInPort ;
299 anInPort = anInNode->ComputingNode()->AddInDataStreamPort( aNode.theListOfInDataStreams[ j ].theDataStreamParameter.Parametername ,
300 aNode.theListOfInDataStreams[ j ].theDataStreamParameter.Parametertype ,
301 aNode.theListOfInDataStreams[ j ].theDataStreamParameter.Parameterdependency ,
302 SUPERV::DataStreamParameter ) ;
303 ((GraphBase::InDataStreamPort * ) anInPort)->SetParams( aNode.theListOfInDataStreams[ j ].theKindOfSchema ,
304 aNode.theListOfInDataStreams[ j ].theKindOfInterpolation ,
305 aNode.theListOfInDataStreams[ j ].theKindOfExtrapolation ) ;
307 for ( j = 0 ; j < aNode.theListOfOutDataStreams.size() ; j++ ) {
308 GraphBase::OutPort * anOutPort ;
309 anOutPort = anInNode->ComputingNode()->AddOutDataStreamPort( aNode.theListOfOutDataStreams[ j ].theDataStreamParameter.Parametername ,
310 aNode.theListOfOutDataStreams[ j ].theDataStreamParameter.Parametertype ,
311 aNode.theListOfOutDataStreams[ j ].theDataStreamParameter.Parameterdependency ,
312 SUPERV::DataStreamParameter ) ;
313 ((GraphBase::OutDataStreamPort * ) anOutPort)->NumberOfValues( aNode.theListOfOutDataStreams[ j ].theNumberOfValues ) ;
317 // theNode->DataStreamInPortsNumber( aNode.theDataStreamInArgsNumber ) ;
318 // theNode->DataStreamOutPortsNumber( aNode.theDataStreamOutArgsNumber ) ;
319 // cdebug << "GraphExecutor::OutNode::LoadNodes " << anInNode->Name()
320 // << " InPortsSize " << theNode->GetNodeInPortsSize()
321 // << " OutPortsSize " << theNode->GetNodeOutPortsSize()
322 // << " DataStreamInPortsNumber " << aNode.theDataStreamInArgsNumber
323 // << " DataStreamOutPortsNumber " << aNode.theDataStreamOutArgsNumber
326 // if ( aNode.theDataStreamInArgsNumber ) { // -1 because of Gates
327 // for ( j = theNode->GetNodeInPortsSize() - aNode.theDataStreamInArgsNumber - 1 ; j < theNode->GetNodeInPortsSize() - 1 ; j++ ) {
328 // cdebug << "GraphExecutor::OutNode::LoadNodes " << anInNode->Name()
329 // << " InPort " << theNode->GetChangeNodeInPort( j )->PortName()
330 // << " Kind( DataStreamParameter)" << endl ;
331 // theNode->GetChangeNodeInPort( j )->Kind( SUPERV::DataStreamParameter ) ;
334 // if ( aNode.theDataStreamOutArgsNumber ) {
335 // int withgate = 1 ;
336 // if ( theNode->IsLoopNode() || theNode->IsEndLoopNode() ) {
339 // for ( j = theNode->GetNodeOutPortsSize() - aNode.theDataStreamOutArgsNumber - withgate ; j < theNode->GetNodeOutPortsSize() - withgate ; j++ ) {
340 // cdebug << "GraphExecutor::OutNode::LoadNodes " << anInNode->Name()
341 // << " OutPort " << theNode->GetChangeNodeOutPort( j )->PortName()
342 // << " Kind( DataStreamParameter)" << endl ;
343 // theNode->GetChangeNodeOutPort( j )->Kind( SUPERV::DataStreamParameter ) ;
347 for ( i = 0 ; i < (int ) aListOfNodes.size() ; i++ ) {
348 GraphBase::SNode aNode = aListOfNodes[ i ] ;
349 anInNode = (GraphExecutor::InNode * ) Graph()->GetChangeGraphNode( aNode.theName.c_str() )->GetInNode() ;
350 cdebug << "GraphExecutor::OutNode::LoadNodes " << anInNode->Name() << " IsOneOfGOTONodes "
351 << anInNode->IsOneOfGOTONodes() << " " << aNode.theCoupledNode.c_str() << endl ;
352 if ( anInNode->IsOneOfGOTONodes() && strlen( aNode.theCoupledNode.c_str() ) ) {
353 GraphBase::GOTONode * aCoupledNode ;
354 aCoupledNode = (GraphBase::GOTONode * ) Graph()->GetGraphNode( aNode.theName.c_str() ) ;
355 GraphBase::GOTONode * aCoupledCoupledNode ;
356 aCoupledCoupledNode = (GraphBase::GOTONode * ) Graph()->GetChangeGraphNode( aNode.theCoupledNode.c_str() ) ;
357 if ( aCoupledCoupledNode != NULL ) {
358 aCoupledNode->CoupledNode( aCoupledCoupledNode ) ;
361 aCoupledNode->CoupledNodeName( aNode.theCoupledNode.c_str() ) ;
368 bool GraphExecutor::OutNode::LoadLinks(const GraphBase::ListOfSLinks &aListOfLinks ) {
370 cdebug << "GraphExecutor::OutNode::LoadLinks " << aListOfLinks.size()
373 for ( i = 0 ; i < (int ) aListOfLinks.size() ; i++ ) {
374 GraphBase::SLink aLink = aListOfLinks[ i ] ;
375 RetVal = Graph()->AddLink( aLink.FromNodeName.c_str() ,
376 aLink.FromServiceParameterName.c_str() ,
377 aLink.ToNodeName.c_str() ,
378 aLink.ToServiceParameterName.c_str() ) ;
379 // , aLink.aLinkValue ) ;
386 bool GraphExecutor::OutNode::LoadDatas(const GraphBase::ListOfSLinks &aListOfDatas ) {
388 cdebug << "GraphExecutor::OutNode::LoadDatas " << aListOfDatas.size()
391 for ( i = 0 ; i < (int ) aListOfDatas.size() ; i++ ) {
392 GraphBase::SLink aLink = aListOfDatas[ i ] ;
393 if ( !strcmp( aLink.FromNodeName.c_str() , Name() ) )
394 RetVal = Graph()->AddInputData( aLink.ToNodeName.c_str() ,
395 aLink.ToServiceParameterName.c_str() ,
397 // else if ( !strcmp( aLink.ToNodeName.c_str() , Name() ) ) {
398 // RetVal = Graph()->AddOutputData( aLink.FromNodeName.c_str() ,
399 // aLink.FromServiceParameterName.c_str() ) ;
400 // Graph()->AddLink( aLink.FromNodeName.c_str() , (GraphBase::ComputingNode *) this ) ;
403 cdebug << "GraphExecutor::OutNode::LoadDatas Error " << aLink.FromNodeName
404 << " and " << aLink.ToNodeName << " differents from " << Name()
414 GraphExecutor::InNode *GraphExecutor::OutNode::AddNode(
415 const SALOME_ModuleCatalog::Service& NodeService ,
416 GraphBase::ListOfFuncName aFuncName ,
417 GraphBase::ListOfPythonFunctions aPythonFunction ,
418 const char * NodeComponentName ,
419 const char * NodeInterfaceName ,
420 const char * NodeName ,
421 const SUPERV::KindOfNode NodeKindOfNode ,
422 const SUPERV::SDate NodeFirstCreation ,
423 const SUPERV::SDate NodeLastModification ,
424 const char * NodeEditorRelease ,
425 const char * NodeAuthor ,
426 const char * NodeComputer ,
427 const char * NodeComment ,
430 cdebug_in << "GraphExecutor::OutNode::AddNode(" << NodeComponentName << " , "
431 << NodeName << ")" << endl;
432 GraphExecutor::InNode *Nd = NULL ;
433 Nd = new GraphExecutor::InNode( _Orb, Graph()->NamingService() , NodeService ,
434 NodeComponentName , NodeInterfaceName ,
435 NodeName , NodeKindOfNode ,
436 aFuncName , aPythonFunction ,
437 NodeFirstCreation , NodeLastModification ,
438 NodeEditorRelease , NodeAuthor ,
439 NodeComputer , NodeComment , false , NodeX , NodeY ,
440 _prof_debug , _fdebug ) ;
441 Graph()->AddNode( Nd->ComputingNode() ) ;
442 cdebug_out << "GraphExecutor::OutNode::AddNode" << endl;
447 bool GraphExecutor::OutNode::Valid() {
448 cdebug_in << "GraphExecutor::OutNode::Valid" << endl;
450 Graph()->ReSetMessages() ; // ==> Only one set of errors messages ...
454 _Executable = false ;
456 if ( !Graph()->CreateService() ) {
457 cdebug_out << "This DataFlow has invalid type(s)." << endl ;
460 int SubStreamGraphsNumber = 0 ;
461 if ( !Graph()->Sort( SubStreamGraphsNumber ) ) {
462 cdebug_out << "This DataFlow is not valid." << endl ;
465 if ( Graph()->IsDataStreamNode() ) {
466 StreamGraph()->SubStreamGraphsNumber( SubStreamGraphsNumber ) ;
468 Graph()->InLineServices() ;
470 if ( !Graph()->ValidLoops() ) {
471 cdebug_out << "This DataFlow have not valid Loops." << endl ;
474 if ( !Graph()->ValidSwitchs() ) {
475 cdebug_out << "This DataFlow have not valid Switchs." << endl ;
481 Graph()->ComputingNodes() ;
486 cdebug_out << "GraphExecutor::OutNode::Valid " << _Valid << " RetVal " << RetVal << endl;
490 bool GraphExecutor::OutNode::Executable() {
491 cdebug_in << "GraphExecutor::OutNode::Executable" << endl;
497 if ( Graph()->DataServerNodes() ) {
503 cdebug << "This DataFlow is not executable." << endl ;
504 _Executable = false ;
508 cdebug_out << "GraphExecutor::OutNode::Executable " << _Executable << endl;
512 bool GraphExecutor::OutNode::Run( const bool AndSuspend ) {
513 bool RetVal = false ;
514 cdebug_in << pthread_self() << "GraphExecutor::OutNode::Run( AndSuspend " << AndSuspend
515 << " ) State " << theAutomaton->StateName( State() ) << endl;
517 if ( Executable() ) {
518 _ControlState = SUPERV::VoidState ;
519 _SuspendedThreads = 0 ;
520 Graph()->ThreadNo( pthread_self() ) ;
522 _JustStarted = true ;
526 for ( i = 0 ; i < Graph()->GraphNodesSize() ; i++ ) {
527 GraphExecutor::InNode * anInNode = (GraphExecutor::InNode *) Graph()->GraphNodes( i )->GetInNode() ;
528 anInNode->OutNode( this ) ;
529 // Initialize in python interpretor the python functions
530 if ( !PyInitialized() && anInNode->IsOneOfInLineNodes() ) {
531 if ( !Py_IsInitialized() ) {
532 // PyEval_InitThreads() ;
534 // asv : 20.01.05 : changes involved with switching to old (HEAD) KERNEL
535 // 1 line below uncommented
536 PySys_SetArgv( _ArgC , _ArgV ) ;
538 anInNode->InitPython() ;
539 PyInitialized( true ) ;
541 anInNode->InitialState() ;
542 if ( anInNode->IsOneOfInLineNodes() ) {
543 //JR with Python2.3.4, we may get an error because of a normal previous error
544 bool sts = anInNode->InitPythonFunctions( false ) ;
545 if ( again && !sts ) {
546 sts = anInNode->InitPythonFunctions( false ) ;
551 // One more time because inline nodes may share one definition of the same function
552 for ( i = 0 ; i < Graph()->GraphNodesSize() ; i++ ) {
553 GraphExecutor::InNode * anInNode = (GraphExecutor::InNode *) Graph()->GraphNodes( i )->GetInNode() ;
554 if ( anInNode->IsOneOfInLineNodes() ) {
555 if ( !anInNode->InitPythonFunctions( true ) ) {
556 anInNode->State( GraphExecutor::ErroredState ) ;
558 //JR 24.03.2005 debug : State and done flags were missing
559 State( GraphExecutor::ErroredState ) ;
561 cdebug_out << "GraphExecutor::OutNode::Run InitPythonFunctions ERROR "
562 << anInNode->Name() << endl ;
567 /* asv : 29.09.04 : commented out because it does not do anything useful
568 for ( i = 0 ; i < Graph()->GraphNodesSize() ; i++ ) {
569 GraphExecutor::InNode * anInNode = (GraphExecutor::InNode *) Graph()->GraphNodes( i )->GetInNode() ;
570 if ( RetVal && anInNode->IsMacroNode() ) {
571 GraphBase::Graph * aMacroGraph = anInNode->GraphMacroNode() ;
572 cdebug << "GraphExecutor::OutNode::Run " << anInNode << " MacroNode " << aMacroGraph
573 << aMacroGraph->Name() << endl ;
574 SUPERV::Graph_var iobject = anInNode->GraphMacroNode()->MacroObject() ;
575 if ( CORBA::is_nil( iobject ) ) {
576 cdebug << "GraphExecutor::OutNode::Run MacroObject() is a nil object. Error" << endl ;
580 cdebug << "GraphExecutor::OutNode::Run MacroObject() is NOT a nil object." << endl ;
585 //JR Debug : if there was an error in initialisation of python functions,
586 // we must not try to execute the graph.
588 if ( Graph()->GraphMacroLevel() != 0 ) {
589 cdebug << "GraphExecutor::OutNode::Run Execution starting GraphExecutor::Action_DataOk_RunService Node "
590 << Name() << " GraphMacroLevel " << Graph()->GraphMacroLevel() << endl ;
591 PushEvent( NULL , GraphExecutor::NoDataReadyEvent ,
592 GraphExecutor::DataUndefState ) ;
595 cdebug << "Execution starting GraphExecutor::Action_DataOk_RunService Node "
596 << Name() << " GraphMacroLevel " << Graph()->GraphMacroLevel() << endl ;
597 PushEvent( NULL , GraphExecutor::ReadyEvent ,
598 GraphExecutor::DataReadyState ) ;
599 State( GraphExecutor::DataReadyState ) ;
601 cdebug << pthread_self() << " GraphExecutor::OutNode::Run Start of the " << Graph()->HeadNodesSize()
602 << " HeadNodes" << endl ;
603 for ( i = 0 ; i < Graph()->HeadNodesSize() ; i++ ) {
604 GraphExecutor::InNode * anInNode = (GraphExecutor::InNode *) Graph()->HeadNodes( i )->GetInNode() ;
605 cdebug << pthread_self() << "GraphExecutor::OutNode::Run Start of HeadNode " << i << " "
606 << anInNode->Name() << endl ;
607 if ( anInNode->State() != GraphExecutor::DataReadyState ) {
609 //JR 24.03.2005 debug : State and done flags were missing
610 State( GraphExecutor::ErroredState ) ;
612 cdebug << "GraphExecutor::OutNode::Run inconsistency State of Node "
613 << anInNode->Name() << " : " << anInNode->State() << endl ;
614 cdebug_out << "GraphExecutor::OutNode::Run State ERROR" << endl ;
617 // PushEvent( anInNode , GraphExecutor::ReadyEvent ,
618 // GraphExecutor::DataReadyState ) ;
619 // We say that we have to create a thread for that HeadNode 'anInNode'
620 if ( !anInNode->IsMacroNode() ) {
621 anInNode->CreateNewThread( true ) ;
622 IncrCreatedThreads() ;
624 anInNode->DataFromNode( Name() ) ;
625 // AndSuspend == true <==> Start()
627 anInNode->State( GraphExecutor::DataWaitingState ) ;
628 anInNode->ControlState( SUPERV::ToSuspendStartState ) ;
629 // We send SomeDataReadyEvent
630 // It is a HeadNode ==> AllDataReadyEvent ==> InNode::executeAction() ==> pthread_create
631 if ( !anInNode->SendEvent( GraphExecutor::SomeDataReadyEvent ) ) {
633 //JR 24.03.2005 debug : State and done flags were missing
634 State( GraphExecutor::ErroredState ) ;
636 cdebug << "InNode::SendEvent( SomeDataReadyEvent ) ERROR Node "
637 << anInNode->Name() << endl ;
638 cdebug_out << "GraphExecutor::OutNode::Run SendEvent ERROR" << endl ;
641 // ==> We wait for SuspendedState
642 anInNode->SuspendedWait() ;
644 // AndSuspend == false <==> Run()
645 else if ( anInNode->IsMacroNode() ) {
646 if ( !anInNode->SendEvent( GraphExecutor::SomeDataReadyEvent ) ) {
648 //JR 24.03.2005 debug : State and done flags were missing
649 State( GraphExecutor::ErroredState ) ;
651 cdebug << "InNode::SendEvent( SomeDataReadyEvent ) ERROR Node "
652 << anInNode->Name() << endl ;
653 cdebug_out << "GraphExecutor::OutNode::Run SendEvent ERROR" << endl ;
656 //JR 15.04.2005 Debug PAL8624 RetroConception :
657 anInNode->CreateNewThread( true ) ;
658 IncrCreatedThreads() ;
659 if ( anInNode->HasAllDataReady() ) {
660 if ( !anInNode->SendEvent( GraphExecutor::AllDataReadyEvent ) ) { // ==> Ready to execute
661 cdebug << "GraphExecutor::OutNode::Run SendEvent(AllDataReadyEvent) ERROR "
662 << " Node " << anInNode->Name() << endl ;
663 cdebug_out << "GraphExecutor::OutNode::Run SendEvent ERROR" << endl ;
668 State( GraphExecutor::ErroredState ) ;
670 cdebug << "GraphExecutor::OutNode::Run HasAllDataReady " << anInNode->HasAllDataReady()
671 << " Node " << anInNode->Name() << endl ;
672 cdebug_out << "GraphExecutor::OutNode::Run HasAllDataReady ERROR" << endl ;
675 cdebug << pthread_self() << " GraphExecutor::OutNode::Run " << anInNode->Name() << "->RunningWait"
677 // ==> We wait for RunningState
678 anInNode->RunningWait() ;
679 cdebug << pthread_self() << " GraphExecutor::OutNode::Run " << anInNode->Name() << "->RunningWaited"
682 else if ( !anInNode->IsMacroNode() ) {
683 // It is a HeadNode ==> AllDataReadyEvent ==> InNode::executeAction() ==> pthread_create
684 if ( !anInNode->SendEvent( GraphExecutor::ExecuteEvent ) ) {
686 //JR 24.03.2005 debug : State and done flags were missing
687 State( GraphExecutor::ErroredState ) ;
689 cdebug << "InNode::SendEvent( ExecuteEvent ) ERROR Node "
690 << anInNode->Name() << endl ;
691 cdebug_out << "GraphExecutor::OutNode::Run SendEvent ERROR" << endl ;
694 // ==> We wait for RunningState
695 anInNode->RunningWait() ;
700 PushEvent( NULL , GraphExecutor::SuspendedReadyEvent ,
701 GraphExecutor::SuspendedReadyState ) ;
704 PushEvent( NULL , GraphExecutor::ExecutingEvent ,
705 GraphExecutor::ExecutingState ) ;
706 if (AutomatonState() == GraphExecutor::DataReadyState) {
707 State( GraphExecutor::ExecutingState ) ;
710 // ostringstream astr ;
711 // astr << "Graph " << Name() << " is running" ;
712 // Graph()->ObjImpl()->sendMessage( NOTIF_STEP, astr.str().c_str() ) ;
718 State( GraphExecutor::ErroredState ) ;
720 if ( IsDone() && Graph()->GraphMacroLevel() == 0 ) {
721 cdebug << " ==> theAutomaton->Executed() " << endl ;
722 theAutomaton->Executed() ;
725 cdebug << " NO theAutomaton->Executed() " << endl ;
731 //JR 24.03.2005 debug : State and done flags were missing
732 State( GraphExecutor::ErroredState ) ;
734 //JR 17.06.2005 debug call to executed was missing ===>
735 // _GraphExecutingNumber field of FiniteStateMachine was not decremented ===>
736 // register of python functions was de-activated ==>
737 // two graphs execution with two different python functions with the same name
738 // give aborted state for the second one
739 //Example : GraphLoopSwitchOfSwitchNOTValid, GraphLoopSwitchs and GraphLoopSwitchsBranches
740 if ( IsDone() && Graph()->GraphMacroLevel() == 0 ) {
741 cdebug << " ==> theAutomaton->Executed() " << endl ;
742 theAutomaton->Executed() ;
745 cdebug << " NO theAutomaton->Executed() " << endl ;
747 cdebug_out << "GraphExecutor::OutNode::Run Not Executable ERROR " << endl ;
751 cdebug_out << pthread_self() << "GraphExecutor::OutNode::Run " << Name()
752 << " State " << theAutomaton->StateName( State() ) << " GraphMacroLevel "
753 << Graph()->GraphMacroLevel() << " RetVal " << RetVal << endl ;
757 void GraphExecutor::OutNode::CheckAllDone() {
759 cdebug_in << "GraphExecutor::OutNode::CheckAllDone " << endl;
760 GraphExecutor::AutomatonState OutNodeState = GraphExecutor::SuccessedState ;
761 GraphExecutor::AutomatonState InNodeState ;
762 bool AllDone = true ;
764 for ( j = 0 ; j < Graph()->QueueNodesSize() ; j++ ) {
765 InNodeState = ( (GraphExecutor::InNode * ) Graph()->QueueNodes( j )->GetInNode() )->State() ;
767 << ( (GraphExecutor::InNode * ) Graph()->QueueNodes( j )->GetInNode() )->Name()
768 << " " << theAutomaton->StateName( InNodeState ) << endl ;
769 if ( InNodeState != GraphExecutor::SuccessedState &&
770 InNodeState != GraphExecutor::ErroredState &&
771 InNodeState != GraphExecutor::DataWaitingState ) {
772 if ( !IsNodeAborted() ) {
776 if ( InNodeState != GraphExecutor::SuccessedState &&
777 InNodeState != GraphExecutor::DataWaitingState &&
778 InNodeState != GraphExecutor::DataReadyState ) {
779 OutNodeState = InNodeState ;
783 if( _Threads == 0 && _SuspendedThreads == 0 ) {
784 if ( OutNodeState != GraphExecutor::ErroredState ) {
785 OutNodeState = GraphExecutor::SuccessedState ;
794 for ( j = 0 ; j < Graph()->GraphNodesSize() ; j++ ) {
795 GraphExecutor::InNode * aNode ;
796 aNode = (GraphExecutor::InNode * ) Graph()->GraphNodes( j )->GetInNode() ;
797 SUPERV::GraphState aState = AutomatonGraphState( aNode->State() ) ;
798 cdebug << "GraphExecutor::OutNode::CheckAllDone " << aNode->Name() << " "
799 << theAutomaton->StateName( aNode->State() ) << " CreateNewThread " << aNode->CreateNewThread()
801 if ( aState == SUPERV::ErrorState ||
802 aState == SUPERV::SuspendErroredState ||
803 aState == SUPERV::KillState ||
804 aState == SUPERV::StopState ) {
805 OutNodeState = aNode->State() ;
806 State( OutNodeState ) ;
808 else if ( aState == SUPERV::ReadyState ||
809 aState == SUPERV::SuspendReadyState ||
810 aState == SUPERV::RunningState ||
811 aState == SUPERV::SuspendDoneState ||
812 aState == SUPERV::SuspendErroredState ||
813 aState == SUPERV::SuspendState ) {
814 if ( !IsNodeAborted() ) {
818 aNode->SuspendedAction() ;
819 aNode->DoneAction() ;
821 // PushEvent AFTER State and _Done ! ...
822 if ( alivenodes == 0 ) {
823 State( OutNodeState ) ;
825 _JustStarted = false ;
827 cdebug << Name() << " alivenodes " << alivenodes << " OutNodeState " << OutNodeState
829 PushEvent( NULL , GraphExecutor::EndExecuteEvent ,
832 // PyInitialized( false ) ;
836 MESSAGE("================================================================================") ;
837 MESSAGE( Name() << " IS DONE : " << theAutomaton->StateName( AutomatonState() ) << " EventQSize "
839 MESSAGE("================================================================================") ;
840 cdebug << "================================================================================" << endl ;
841 cdebug << Name() << " IS DONE : " << theAutomaton->StateName( AutomatonState() ) << " EventQSize "
842 << EventQSize() << endl ;
843 cdebug << "================================================================================" << endl ;
845 if ( Graph()->GraphMacroLevel() != 0 ) {
846 //JR NPAL14110 09.02.2007 : That must be done only at the end of SubGraph because we may
847 // have an output of the SubGraph in a Loop !...
848 // So that code must be done in CheckAllDone instead of OutParametersSet
849 cdebug << "CheckAllDone ToNodeName " << Name() << " CoupledNode "
850 << Graph()->CoupledNodeName() << Graph()->CoupledNode()
852 cdebug << "CheckAllDone GraphExecutor " << Graph()->CoupledNode()->GraphEditor()->Executor() << endl ;
853 const GraphBase::InPort * anInPort ;
854 GraphBase::OutPort * anOutPort ;
856 for ( i = 0 ; i < Graph()->GetNodeOutDataNodePortsSize() ; i++ ) {
857 anInPort = Graph()->GetNodeOutDataNodePort( i ) ;
858 if ( !anInPort->IsGate() ) {
859 anOutPort = anInPort->GetOutPort() ;
860 Graph()->CoupledNode()->GraphEditor()->Executor()->OutputOfAny( Graph()->CoupledNodeName() ,
861 anInPort->PortName() ,
862 anOutPort->Value() ) ;
863 cdebug << "CheckAllDone OutputOfAny( " << Graph()->CoupledNodeName() << " , "
864 << anInPort->PortName() << " , value ) done" << endl ;
870 //JR 23.02.2005, Debug : siftEvents() must be inside the pthread_mutex_lock
871 if ( pthread_mutex_lock( &_MutexWait ) ) {
872 perror("EventLoop pthread_mutex_lock ") ;
875 // asv : fix for 6798 and other bugs: "sift" the event queue after execution
877 if ( pthread_mutex_unlock( &_MutexWait ) ) {
878 perror("PushEvent pthread_mutex_unlock ") ;
882 // asv : 25.10.04 : calling Editing() to indicate stop of execution
883 Graph()->GraphEditor()->Editing();
885 cdebug_out << "GraphExecutor::OutNode::CheckAllDone " << IsDone() << " this " << this << " "
886 << Name() << " GraphAutomatonState "
887 << theAutomaton->StateName( AutomatonState() )
888 << " State " << State() << " Threads " << _Threads << " SuspendedThreads "
889 << _SuspendedThreads << " EventQSize " << EventQSize() << endl ;
892 // asv : 20.01.05 : changes involved with switching to old (HEAD) KERNEL
893 //Engines_Container_i * GraphExecutor::OutNode::SuperVisionContainer() {
894 // return _SuperVisionContainer ;
897 //const pthread_t GraphExecutor::OutNode::MainThreadId() const {
898 // return _MainThreadId ;
901 void GraphExecutor::OutNode::PThreadLock( pthread_mutex_t * aMutex , char * errmsg ) {
902 // if ( strcmp( errmsg , "EventLoop" ) && strcmp( errmsg , "EventW" ) ) {
903 // cdebug << "GraphExecutor::OutNode::PThreadLock " << pthread_self() << " " << aMutex << " "
904 // << errmsg << endl ;
906 if ( pthread_mutex_lock( aMutex ) ) {
910 // if ( strcmp( errmsg , "EventLoop" ) && strcmp( errmsg , "EventW" ) ) {
911 // cdebug << "GraphExecutor::OutNode::PThreadLocked " << pthread_self() << " " << aMutex << " "
912 // << errmsg << endl ;
916 void GraphExecutor::OutNode::PThreadUnLock( pthread_mutex_t * aMutex , char * errmsg ) {
917 // if ( strcmp( errmsg , "EventLoop" ) && strcmp( errmsg , "EventW" ) ) {
918 // cdebug << " GraphExecutor::OutNode::PThreadUnLock " << pthread_self() << " " << aMutex << " "
919 // << errmsg << endl ;
921 if ( pthread_mutex_unlock( aMutex ) ) {
927 void GraphExecutor::OutNode::PyThreadLock() {
928 // cout << " GraphExecutor::OutNode::PyThreadLock " << pthread_self() << endl ;
929 if ( pthread_mutex_lock( &_PyMutexWait ) ) {
930 perror( "GraphExecutor::OutNode::PyThreadLock" ) ;
933 theAutomaton->PyLock() ;
934 // cout << " GraphExecutor::OutNode::PyThreadLocked " << pthread_self() << endl ;
937 void GraphExecutor::OutNode::PyThreadUnLock() {
938 // cout << " GraphExecutor::OutNode::PyThreadUnLock " << pthread_self() << endl ;
939 if ( pthread_mutex_unlock( &_PyMutexWait ) ) {
940 perror( "GraphExecutor::OutNode::PyThreadUnLock" ) ;
943 theAutomaton->PyUnLock() ;
944 // cout << " GraphExecutor::OutNode::PyThreadUnLocked " << pthread_self() << endl ;
947 void GraphExecutor::OutNode::NewThread() {
948 if ( pthread_mutex_lock( &_MutexWait ) ) {
949 perror("pthread_mutex_lock _NewThread") ;
953 // cdebug << "NewThread : " << _Threads << " running threads "
954 // << _SuspendedThreads << " suspended threads"
956 if ( pthread_mutex_unlock( &_MutexWait ) ) {
957 perror("pthread_mutex_unlock _NewThread") ;
962 void GraphExecutor::OutNode::ExitThread( pthread_t ThreadNumber ) {
963 if ( pthread_mutex_lock( &_MutexWait ) ) {
964 perror("pthread_mutex_lock _ExitThread") ;
967 if ( ThreadNumber == 0 ) {
968 ThreadNumber = pthread_self() ;
971 // cdebug << pthread_self() << " ExitThread( " << ThreadNumber << " ) " << _Threads << " running threads "
972 // << _SuspendedThreads << " suspended threads"
974 theAutomaton->JoinThread( ThreadNumber ) ;
975 if ( pthread_cond_signal( &_JoinWait ) ) {
976 perror("ExitThread pthread_cond_signal ") ;
978 if ( pthread_mutex_unlock( &_MutexWait ) ) {
979 perror("pthread_mutex_unlock _ExitThread") ;
982 if ( _Threads == 0 && _SuspendedThreads == 0 ) {
984 cdebug << pthread_self() << " ExitThread( " << ThreadNumber << " ) " << _Threads
985 << " running threads " << _SuspendedThreads << " suspended threads IsDone() "
987 _run_func_thread = 0 ; // mkr : IPAL14711
988 if ( IsDone() && Graph()->GraphMacroLevel() == 0 ) {
989 cdebug << " ==> theAutomaton->Executed() " << endl ;
990 theAutomaton->Executed() ;
993 cdebug << " NO theAutomaton->Executed() " << endl ;
997 void GraphExecutor::OutNode::JoinedWait() {
998 if ( pthread_mutex_lock( &_MutexWait ) ) {
999 perror("pthread_mutex_lock JoinedWait") ;
1002 while ( _Threads ) {
1003 if ( pthread_cond_wait( &_JoinWait , &_MutexWait ) ) {
1004 perror("JoinedWait pthread_cond_wait ") ;
1007 if ( pthread_mutex_unlock( &_MutexWait ) ) {
1008 perror("pthread_mutex_unlock JoinedWait") ;
1013 void GraphExecutor::OutNode::SuspendThread() {
1014 if ( pthread_mutex_lock( &_MutexWait ) ) {
1015 perror("pthread_mutex_lock _SuspendThread") ;
1018 _SuspendedThreads += 1 ;
1019 cdebug << "SuspendThread : " << _Threads << " running threads "
1020 << _SuspendedThreads << " suspended threads"
1022 if ( pthread_mutex_unlock( &_MutexWait ) ) {
1023 perror("pthread_mutex_unlock _SuspendThread") ;
1026 if ( IsSuspended() ) {
1027 PushEvent( NULL , GraphExecutor::SuspendEvent , GraphExecutor::SuspendedState ) ;
1030 void GraphExecutor::OutNode::ResumeThread() {
1031 if ( pthread_mutex_lock( &_MutexWait ) ) {
1032 perror("pthread_mutex_lock _ResumeThread") ;
1035 _SuspendedThreads -= 1 ;
1036 cdebug << "ResumeThread : " << _Threads << " running threads "
1037 << _SuspendedThreads << " suspended threads"
1039 if ( pthread_mutex_unlock( &_MutexWait ) ) {
1040 perror("pthread_mutex_unlock _ResumeThread") ;
1045 long GraphExecutor::OutNode::Thread( const char * aNodeName ) {
1047 GraphExecutor::InNode *anInNode = (GraphExecutor::InNode *) Graph()->GetGraphNode( aNodeName )->GetInNode() ;
1049 RetVal = anInNode->ThreadNo() ;
1054 SUPERV::GraphEvent GraphExecutor::OutNode::AutomatonGraphEvent(GraphExecutor::NodeEvent anEvent ) {
1055 SUPERV::GraphEvent aGraphEvent ;
1056 switch ( anEvent ) {
1057 case GraphExecutor::UndefinedEvent : {
1058 aGraphEvent = SUPERV::UndefinedEvent ;
1061 case GraphExecutor::NewThreadEvent : {
1062 aGraphEvent = SUPERV::NewThreadEvent ;
1065 case GraphExecutor::SuspendEvent : {
1066 aGraphEvent = SUPERV::SuspendEvent ;
1069 case GraphExecutor::ResumeEvent : {
1070 aGraphEvent = SUPERV::ResumeEvent ;
1073 case GraphExecutor::KillEvent : {
1074 aGraphEvent = SUPERV::KillEvent ;
1077 case GraphExecutor::StopEvent : {
1078 aGraphEvent = SUPERV::StopEvent ;
1081 case GraphExecutor::ExecuteEvent : {
1082 aGraphEvent = SUPERV::RunningEvent ;
1085 case GraphExecutor::SuccessEvent : {
1086 aGraphEvent = SUPERV::DoneEvent ;
1089 case GraphExecutor::ErrorEvent : {
1090 aGraphEvent = SUPERV::ErroredEvent ;
1093 case GraphExecutor::NoDataReadyEvent : {
1094 aGraphEvent = SUPERV::WaitingEvent ;
1097 case GraphExecutor::SomeDataReadyEvent : {
1098 aGraphEvent = SUPERV::WaitingEvent ;
1101 case GraphExecutor::NotAllDataReadyEvent : {
1102 aGraphEvent = SUPERV::WaitingEvent ;
1105 case GraphExecutor::AllDataReadyEvent : {
1106 aGraphEvent = SUPERV::ReadyEvent ;
1109 case GraphExecutor::ReadyEvent : {
1110 aGraphEvent = SUPERV::ReadyEvent ;
1113 case GraphExecutor::SuspendedReadyEvent : {
1114 aGraphEvent = SUPERV::SuspendEvent ;
1117 case GraphExecutor::ResumedReadyEvent : {
1118 aGraphEvent = SUPERV::ResumeEvent ;
1121 case GraphExecutor::KilledReadyEvent : {
1122 aGraphEvent = SUPERV::KillEvent ;
1125 case GraphExecutor::StoppedReadyEvent : {
1126 aGraphEvent = SUPERV::StopEvent ;
1129 case GraphExecutor::ExecutingEvent : {
1130 aGraphEvent = SUPERV::RunningEvent ;
1133 case GraphExecutor::SuspendedExecutingEvent : {
1134 aGraphEvent = SUPERV::SuspendEvent ;
1137 case GraphExecutor::ResumedExecutingEvent : {
1138 aGraphEvent = SUPERV::ResumeEvent ;
1141 case GraphExecutor::KilledExecutingEvent : {
1142 aGraphEvent = SUPERV::KillEvent ;
1145 case GraphExecutor::StoppedExecutingEvent : {
1146 aGraphEvent = SUPERV::StopEvent ;
1149 case GraphExecutor::SuccessedExecutingEvent : {
1150 aGraphEvent = SUPERV::DoneEvent ;
1153 case GraphExecutor::ErroredExecutingEvent : {
1154 aGraphEvent = SUPERV:: ErroredEvent;
1157 case GraphExecutor::SuspendedSuccessedEvent : {
1158 aGraphEvent = SUPERV::SuspendEvent ;
1161 case GraphExecutor::SuspendedErroredEvent : {
1162 aGraphEvent = SUPERV::SuspendEvent ;
1165 case GraphExecutor::ResumedSuccessedEvent : {
1166 aGraphEvent = SUPERV::ResumeEvent ;
1169 case GraphExecutor::ResumedErroredEvent : {
1170 aGraphEvent = SUPERV::ResumeEvent ;
1173 case GraphExecutor::KilledEvent : {
1174 aGraphEvent = SUPERV::KillEvent ;
1177 case GraphExecutor::StoppedEvent : {
1178 aGraphEvent = SUPERV::StopEvent ;
1181 case GraphExecutor::EndExecuteEvent : {
1182 aGraphEvent = SUPERV::DoneEvent ;
1186 cdebug << " GraphExecutor::OutNode::AutomatonGraphEvent Error Undefined Event : "
1187 << anEvent << endl ;
1188 aGraphEvent = SUPERV::UndefinedEvent ;
1191 return aGraphEvent ;
1194 SUPERV::GraphState GraphExecutor::OutNode::AutomatonGraphState(GraphExecutor::AutomatonState aState ) {
1195 SUPERV::GraphState aGraphState ;
1197 case GraphExecutor::UnKnownState : {
1198 aGraphState = SUPERV::UndefinedState ;
1201 case GraphExecutor::DataUndefState : {
1202 aGraphState = SUPERV::UndefinedState ;
1205 case GraphExecutor::DataWaitingState : {
1206 aGraphState = SUPERV::WaitingState ;
1209 case GraphExecutor::DataReadyState : {
1210 aGraphState = SUPERV::ReadyState ;
1213 case GraphExecutor::SuspendedReadyState : {
1214 aGraphState = SUPERV::SuspendReadyState ;
1217 case GraphExecutor::ResumedReadyState : {
1218 aGraphState = SUPERV::ReadyState ;
1221 case GraphExecutor::KilledReadyState : {
1222 aGraphState = SUPERV::KillState ;
1225 case GraphExecutor::StoppedReadyState : {
1226 aGraphState = SUPERV::StopState ;
1229 case GraphExecutor::ExecutingState : {
1230 aGraphState = SUPERV::RunningState ;
1233 case GraphExecutor::SuspendedExecutingState : {
1234 aGraphState = SUPERV::SuspendState ;
1237 case GraphExecutor::ResumedExecutingState : {
1238 aGraphState = SUPERV::RunningState ;
1241 case GraphExecutor::KilledExecutingState : {
1242 aGraphState = SUPERV::KillState ;
1245 case GraphExecutor::StoppedExecutingState : {
1246 aGraphState = SUPERV::StopState ;
1249 case GraphExecutor::SuccessedExecutingState : {
1250 aGraphState = SUPERV::DoneState ;
1253 case GraphExecutor::ErroredExecutingState : {
1254 aGraphState = SUPERV::ErrorState ;
1257 case GraphExecutor::SuspendedSuccessedState : {
1258 aGraphState = SUPERV::SuspendDoneState ;
1261 case GraphExecutor::SuspendedErroredState : {
1262 aGraphState = SUPERV::SuspendErroredState ;
1265 case GraphExecutor::ResumedSuccessedState : {
1266 aGraphState = SUPERV::DoneState ;
1269 case GraphExecutor::ResumedErroredState : {
1270 aGraphState = SUPERV::ErrorState ;
1273 case GraphExecutor::KilledSuccessedState : {
1274 aGraphState = SUPERV::KillState ;
1277 case GraphExecutor::KilledErroredState : {
1278 aGraphState = SUPERV::KillState ;
1281 case GraphExecutor::StoppedSuccessedState : {
1282 aGraphState = SUPERV::StopState ;
1285 case GraphExecutor::StoppedErroredState : {
1286 aGraphState = SUPERV::StopState ;
1289 case GraphExecutor::SuccessedState : {
1290 aGraphState = SUPERV::DoneState ;
1293 case GraphExecutor::ErroredState : {
1294 aGraphState = SUPERV::ErrorState ;
1297 case GraphExecutor::SuspendedState : {
1298 aGraphState = SUPERV::SuspendState ;
1301 case GraphExecutor::KilledState : {
1302 aGraphState = SUPERV::KillState ;
1305 case GraphExecutor::StoppedState : {
1306 aGraphState = SUPERV::StopState ;
1309 case GraphExecutor::LoadingState : {
1310 aGraphState = SUPERV::LoadingState ;
1314 cdebug << " GraphExecutor::OutNode::AutomatonGraphState Error Undefined State : "
1315 << aGraphState << endl ;
1316 aGraphState = SUPERV::UndefinedState ;
1319 return aGraphState ;
1322 //JR 07.04.2005, Debug : access to _EventNodes must be inside the pthread_mutex_lock
1323 int GraphExecutor::OutNode::GetListSize() {
1324 if ( pthread_mutex_lock( &_MutexWait ) ) {
1325 perror("PushEvent pthread_mutex_lock ") ;
1328 int eventnbr = _EventNodes.size();
1329 if ( pthread_mutex_unlock( &_MutexWait ) ) {
1330 perror("PushEvent pthread_mutex_unlock ") ;
1336 bool GraphExecutor::OutNode::PushEvent( GraphExecutor::InNode * aNode ,
1337 GraphExecutor::NodeEvent anEvent ,
1338 GraphExecutor::AutomatonState aState ) {
1339 // cdebug_in << "PushEvent Threads " << Threads() << " SuspendedThreads "
1340 // << SuspendedThreads() << endl ;
1341 if ( pthread_mutex_lock( &_MutexWait ) ) {
1342 perror("PushEvent pthread_mutex_lock ") ;
1345 char* aNodeName = aNode ? aNode->Name() : Name() ;
1346 _EventNodes.push_back( aNodeName ) ;
1347 _Events.push_back( anEvent ) ;
1348 _States.push_back( aState ) ;
1350 pthread_cond_broadcast( &_EventWait );
1351 // cdebug << pthread_self() << " PushEvent Threads " << Threads() << " SuspendedThreads "
1352 // << SuspendedThreads() << " pthread_cond_broadcast _EventWait " << &_EventWait << endl ;
1354 // cdebug << aNode->ThreadNo() << " PushEvent " << aNode->Name() ;
1355 // cdebug << " " << aNode->Automaton()->EventName( anEvent )
1356 // << " " << aNode->Automaton()->StateName( aState )
1357 // << " ControleState "
1358 // << aNode->Automaton()->ControlStateName( aNode->ControlState() ) ;
1361 // cdebug << "PushEvent " << Name() ;
1362 // cdebug << " " << theAutomaton->EventName( anEvent ) << " "
1363 // << theAutomaton->StateName( aState ) ;
1365 // cdebug_out << "PushEvent Threads " << Threads() << " SuspendedThreads "
1366 // << SuspendedThreads() << endl ;
1369 //JR 21.02.2005 Debug : old events should be removed at creation time for python-clients
1370 int EventNodesSize = _EventNodes.size() ;
1371 if ( EventNodesSize > Graph()->GraphNodesSize()*70 ) {
1373 // cdebug << "OutNode::PushEvent " << _EventNodes.size() << " in queue instead of "
1374 // << EventNodesSize << endl ;
1377 if ( pthread_mutex_unlock( &_MutexWait ) ) {
1378 perror("PushEvent pthread_mutex_unlock ") ;
1384 bool GraphExecutor::OutNode::StateWait( SUPERV::GraphState aState ) {
1388 bool GraphExecutor::OutNode::Event( char ** aNodeName ,
1389 SUPERV::GraphEvent & anEvent ,
1390 SUPERV::GraphState & aState ,
1393 //JR 23.02.2005, Debug : siftEvents() must be inside the pthread_mutex_lock
1394 if ( pthread_mutex_lock( &_MutexWait ) ) {
1395 perror("EventLoop pthread_mutex_lock ") ;
1398 // asv : fixing problem of loops with large number of iterations (>5000)
1399 // experimentally was found that number of non-handled by GUI events = (number_of_nodes x 7)
1400 // or 7 events for each node - so what we want to do here is remove "old" events for nodes
1401 // "on the fly". Once again it is done in Stop(), Kill(), Done() functions.
1402 int EventNodessize = _EventNodes.size() ;
1403 if ( EventNodessize > Graph()->GraphNodesSize()*7 )
1407 int SuspendedThreadsNumber ;
1408 bool cdebuginout = false ;
1409 if ( _EventNodes.size() > 0 ) {
1410 // cdebug_in << "GraphExecutor::OutNode::Event " << _EventNodes.size() << " in queue instead of "
1411 // << EventNodessize << endl ;
1412 cdebuginout = true ;
1414 _JustStarted = false ;
1415 ThreadsNumber = Threads() ;
1416 SuspendedThreadsNumber = SuspendedThreads() ;
1417 bool RetVal = ( ThreadsNumber - SuspendedThreadsNumber) != 0 ||
1418 _EventNodes.size() > 0 ;
1419 char * NodeName = "" ;
1420 GraphExecutor::NodeEvent theEvent = GraphExecutor::UndefinedEvent ;
1421 GraphExecutor::AutomatonState theState = GraphExecutor::UnKnownState ;
1422 anEvent = SUPERV::UndefinedEvent ;
1423 aState = SUPERV::UndefinedState ;
1424 if ( ( Done() || IsKilled() || IsStopped() ) && _EventNodes.size() == 0 ) {
1425 // cdebug << "EventLoop Done()/IsKilled()/IsStopped() && _EventNodes.size() == 0" << endl ;
1428 else if ( !WithWait && _EventNodes.size() == 0 ) {
1429 anEvent = SUPERV::NoEvent ;
1430 aState = SUPERV::NoState ;
1433 else if ( RetVal ) {
1434 while ( !IsSuspended() && _EventNodes.size() == 0 ) {
1435 // cdebug << "EventLoop pthread_cond_wait _EventWait" << endl ;
1436 pthread_cond_wait( &_EventWait , &_MutexWait );
1437 // cdebug << "EventLoop pthread_cond_waited _EventWait"
1438 // << " _EventNodes.size() " << _EventNodes.size() << endl ;
1440 if ( _EventNodes.size() ) {
1441 ThreadsNumber = Threads() ;
1442 NodeName = _EventNodes.front() ;
1443 _EventNodes.pop_front() ;
1444 theEvent = _Events.front() ;
1445 anEvent = AutomatonGraphEvent( theEvent ) ;
1446 _Events.pop_front() ;
1447 theState = _States.front() ;
1448 aState = AutomatonGraphState( theState ) ;
1449 _States.pop_front() ;
1452 *aNodeName = NodeName ;
1453 if ( IsSuspended() && _EventNodes.size() == 0 ) {
1456 if ( anEvent != SUPERV::NoEvent ) {
1457 // cdebug << pthread_self() << "EventLoop "
1458 // << NodeName << " " << theAutomaton->StateName( theState )
1459 // << " _EventNodes.size() " << _EventNodes.size()
1460 // << " Threads " << Threads() << " SuspendedThreads "
1461 // << SuspendedThreads() << " RetVal " << RetVal << endl ;
1463 if ( pthread_mutex_unlock( &_MutexWait ) ) {
1464 perror("EventLoop pthread_mutex_lock ") ;
1467 if ( cdebuginout ) {
1468 // cdebug_out << "GraphExecutor::OutNode::Event " << _EventNodes.size() << " in queue"
1469 // << *aNodeName << " " << anEvent << " " << aState << endl ;
1474 bool GraphExecutor::OutNode::EventW( char ** aNodeName ,
1475 SUPERV::GraphEvent & anEvent ,
1476 SUPERV::GraphState & aState ) {
1479 aState = SUPERV::UndefinedState ;
1481 aState != SUPERV::SuspendReadyState &&
1482 aState != SUPERV::RunningState &&
1483 aState != SUPERV::SuspendDoneState &&
1484 aState != SUPERV::SuspendErroredState ) {
1486 while ( sts && !strcmp( NodeName , Name() ) ) {
1487 sts = EventWait( aNodeName , anEvent , aState ) ;
1488 NodeName = *aNodeName ;
1494 bool GraphExecutor::OutNode::EventWait( char ** aNodeName ,
1495 SUPERV::GraphEvent & anEvent ,
1496 SUPERV::GraphState & aState ) {
1497 if ( pthread_mutex_lock( &_MutexWait ) ) {
1498 perror("EventW pthread_mutex_lock ") ;
1502 int SuspendedThreadsNumber ;
1503 ThreadsNumber = Threads() ;
1504 SuspendedThreadsNumber = SuspendedThreads() ;
1505 bool RetVal = ( ThreadsNumber - SuspendedThreadsNumber) != 0 ||
1506 _EventNodes.size() > 0 ;
1507 cdebug << "--> EventW RetVal " << RetVal << endl ;
1508 char * NodeName = "" ;
1509 GraphExecutor::NodeEvent theEvent = GraphExecutor::UndefinedEvent ;
1510 GraphExecutor::AutomatonState theState = GraphExecutor::UnKnownState ;
1511 anEvent = SUPERV::UndefinedEvent ;
1512 aState = SUPERV::UndefinedState ;
1513 if ( IsDone() && _EventNodes.size() == 0 ) {
1514 cdebug << "EventW IsDone() && _EventNodes.size() == 0" << endl ;
1517 else if ( RetVal ) {
1518 GraphExecutor::InNode * aNode = NULL ;
1519 while ( aNode == NULL && RetVal ) {
1520 NodeName = _EventNodes.front() ;
1521 theEvent = _Events.front() ;
1522 anEvent = AutomatonGraphEvent( theEvent ) ;
1523 theState = _States.front() ;
1524 aState = AutomatonGraphState( theState ) ;
1526 if ( _JustStarted ) {
1527 _JustStarted = false ;
1530 _EventNodes.pop_front() ;
1531 _Events.pop_front() ;
1532 _States.pop_front() ;
1535 aNode = ((GraphExecutor::InNode *) Graph()->GetGraphNode( NodeName )->GetInNode()) ;
1536 cdebug << "EventW Previous Node " << NodeName << " ThreadsNumber "
1538 << " _EventNodes.size() " << _EventNodes.size() << " "
1539 << theAutomaton->StateName( theState )
1540 << " Threads " << Threads() << " SuspendedThreads "
1541 << SuspendedThreads() << endl ;
1544 else if ( IsDone() && _EventNodes.size() == 0 ) {
1545 cdebug << "EventW IsDone() && _EventNodes.size() == 0" << endl ;
1549 cdebug << "EventW Not InNode " << NodeName
1550 << " _EventNodes.size() " << _EventNodes.size() << endl ;
1551 while ( _EventNodes.size() == 0 ) {
1552 pthread_cond_wait( &_EventWait , &_MutexWait );
1554 cdebug << "EventW pthread_cond_waited Not InNode " << NodeName
1555 << " _EventNodes.size() " << _EventNodes.size() << endl ;
1560 if ( aState == SUPERV::SuspendState ||
1561 aState == SUPERV::SuspendReadyState ||
1562 aState == SUPERV::SuspendDoneState ||
1563 aState == SUPERV::SuspendErroredState ) {
1564 aNode->ControlState( SUPERV::ToSuspendState ) ;
1565 if ( aNode->IsSuspended() ) {
1566 if ( pthread_mutex_unlock( &_MutexWait ) ) {
1567 perror("EventW pthread_mutex_lock ") ;
1570 cdebug << "EventW " << aNode->Name() << " ResumeAction" << endl ;
1571 aNode->ResumeAction( GraphExecutor::ToResumeEvent ) ;
1572 cdebug << "EventW " << aNode->Name() << " ResumedAction" << endl ;
1573 if ( pthread_mutex_lock( &_MutexWait ) ) {
1574 perror("EventW pthread_mutex_lock ") ;
1579 cdebug << "EventW inconsistent SuspendState" << endl ;
1584 if ( aNode->IsDone() ) {
1588 cdebug << "EventW NOT SuspendedState _EventNodes.size() "
1589 << _EventNodes.size() << endl ;
1594 cdebug << "EventW " << aNode->Name() << " pthread_cond_wait" << endl ;
1595 while ( _EventNodes.size() == 0 ) {
1596 pthread_cond_wait( &_EventWait , &_MutexWait );
1598 ThreadsNumber = Threads() ;
1599 NodeName = _EventNodes.front() ;
1600 theEvent = _Events.front() ;
1601 anEvent = AutomatonGraphEvent( theEvent ) ;
1602 theState = _States.front() ;
1603 aState = AutomatonGraphState( theState ) ;
1607 *aNodeName = NodeName ;
1608 cdebug << "<-- EventW RetVal " << RetVal << " " << NodeName
1609 << " Threads " << Threads() << " SuspendedThreads "
1610 << SuspendedThreads()
1611 << " _EventNodes.size() " << _EventNodes.size()
1612 << " " << theAutomaton->EventName( theEvent ) << " "
1613 << theAutomaton->StateName( theState ) << endl ;
1614 if ( pthread_mutex_unlock( &_MutexWait ) ) {
1615 perror("EventW pthread_mutex_lock ") ;
1620 long GraphExecutor::OutNode::EventQSize() {
1621 return _EventNodes.size() ;
1624 void GraphExecutor::OutNode::EventList() {
1625 if ( pthread_mutex_lock( &_MutexWait ) ) {
1626 perror("EventList pthread_mutex_lock ") ;
1629 list< char * >::iterator itEventNodes = _EventNodes.begin() ;
1630 list< GraphExecutor::NodeEvent >::iterator itEvents = _Events.begin() ;
1631 list< GraphExecutor::AutomatonState >::iterator itStates = _States.begin() ;
1632 while ( itEventNodes != _EventNodes.end() ) {
1633 cdebug << pthread_self() << "EVENTSTACK "
1634 << *itEventNodes << " " << *itEvents << " "
1635 << theAutomaton->StateName( *itStates )
1636 << " Threads " << Threads() << " SuspendedThreads " << SuspendedThreads() << endl ;
1641 if ( pthread_mutex_unlock( &_MutexWait ) ) {
1642 perror("EventList pthread_mutex_lock ") ;
1647 void GraphExecutor::OutNode::SendSomeDataReady( const char * aNodeName ) {
1648 cdebug_in << "GraphExecutor::OutNode::SendSomeDataReady " << aNodeName << "->SendSomeDataReady( "
1649 << Name() << " )" << endl;
1651 sts = ((GraphExecutor::InNode * ) Graph()->GetChangeGraphNode( aNodeName )->GetInNode())->SendSomeDataReady( Name() ) ;
1652 cdebug_out << "GraphExecutor::OutNode::SendSomeDataReady sts " << sts << endl ;
1655 void GraphExecutor::OutNode::State(GraphExecutor::AutomatonState aState ) {
1656 // cdebug << "GraphExecutor::OutNode::State " << Name() << " "
1657 // << theAutomaton->StateName( AutomatonGraphState( _State ) ) << " ---> "
1658 // << theAutomaton->StateName( AutomatonGraphState( aState ) ) << endl ;
1662 SUPERV::GraphState GraphExecutor::OutNode::State() {
1663 // cdebug_in << "GraphExecutor::OutNode::State" << endl;
1664 // cdebug_out << "GraphExecutor::OutNode::State" << endl ;
1665 // cdebug << "GraphExecutor::OutNode::State GraphState "
1666 // << theAutomaton->StateName( AutomatonGraphState( _State ) ) << endl ;
1667 return AutomatonGraphState( _State ) ;
1670 SUPERV::GraphState GraphExecutor::OutNode::State( const char * NodeName ) {
1671 // cdebug_in << "GraphExecutor::OutNode::State " << NodeName << endl;
1672 GraphExecutor::AutomatonState aret = GraphExecutor::UnKnownState ;
1673 const GraphBase::ComputingNode * aCNode = Graph()->GetGraphNode( NodeName ) ;
1675 GraphExecutor::InNode *anInNode = (GraphExecutor::InNode *)aCNode->GetInNode() ;
1677 aret = anInNode->State() ;
1678 // asv 27.01.05 - fix for PAL7849, return "Loading" state only if internal state is SUPERV::RunningState
1679 if ( ( aret == GraphExecutor::ExecutingState ||
1680 aret == GraphExecutor::ResumedExecutingState ) &&
1681 anInNode->IsLoading() )
1682 aret = GraphExecutor::LoadingState;
1683 // cdebug << "GraphExecutor::OutNode::State( " << NodeName << " ) "
1684 // << theAutomaton->StateName( AutomatonGraphState( aret ) ) << endl ;
1687 // cdebug_out << "GraphExecutor::OutNode::State" << endl ;
1688 return AutomatonGraphState( aret ) ;
1691 SUPERV::GraphState GraphExecutor::OutNode::State( const char * NodeName ,
1692 const char * ServiceParameterName ) {
1693 // cdebug_in << "GraphExecutor::OutNode::State " << NodeName << " "
1694 // << ServiceParameterName<< endl;
1695 SUPERV::GraphState aret = Graph()->PortState( NodeName , ServiceParameterName ) ;
1696 // cdebug_out << "GraphExecutor::OutNode::State" << endl ;
1700 GraphExecutor::AutomatonState GraphExecutor::OutNode::AutomatonState() {
1701 // cdebug_in << "GraphExecutor::OutNode::AutomatonState" << endl;
1702 // cdebug_out << "GraphExecutor::OutNode::AutomatonState" << endl ;
1706 GraphExecutor::AutomatonState GraphExecutor::OutNode::AutomatonState( const char * NodeName ) {
1707 // cdebug_in << "GraphExecutor::OutNode::AutomatonState " << NodeName << endl;
1708 GraphExecutor::AutomatonState aret = GraphExecutor::UnKnownState ;
1709 const GraphBase::ComputingNode * aNode = Graph()->GetGraphNode( NodeName ) ;
1711 GraphExecutor::InNode *anInNode = (GraphExecutor::InNode *) aNode->GetInNode() ;
1713 aret = anInNode->State() ;
1716 // cdebug_out << "GraphExecutor::OutNode::AutomatonState" << endl ;
1720 SUPERV::ControlState GraphExecutor::OutNode::ControlState() {
1721 // cdebug_in << "GraphExecutor::OutNode::ControlState" << endl;
1722 // cdebug_out << "GraphExecutor::OutNode::ControlState" << endl ;
1723 return _ControlState ;
1726 SUPERV::ControlState GraphExecutor::OutNode::ControlState( const char * NodeName ) {
1727 // cdebug_in << "GraphExecutor::OutNode::ControlState " << NodeName << endl;
1728 SUPERV::ControlState aret = SUPERV::VoidState ;
1729 const GraphBase::ComputingNode * aNode = Graph()->GetGraphNode( NodeName ) ;
1731 GraphExecutor::InNode *anInNode = (GraphExecutor::InNode *) aNode->GetInNode() ;
1733 aret = anInNode->ControlState() ;
1736 // cdebug_out << "GraphExecutor::OutNode::ControlState" << endl ;
1740 void GraphExecutor::OutNode::ControlClear() {
1741 // cdebug_in << "GraphExecutor::OutNode::ControlClear" << endl;
1742 // cdebug_out << "GraphExecutor::OutNode::ControlClear" << endl ;
1743 _ControlState = SUPERV::VoidState;
1746 void GraphExecutor::OutNode::ControlClear( const char * NodeName ) {
1747 // cdebug_in << "GraphExecutor::OutNode::ControlClear " << NodeName << endl;
1748 const GraphBase::ComputingNode * aNode = Graph()->GetGraphNode( NodeName ) ;
1750 GraphExecutor::InNode *anInNode = (GraphExecutor::InNode *) aNode->GetInNode() ;
1752 anInNode->ControlClear() ;
1755 // cdebug_out << "GraphExecutor::OutNode::ControlClear" << endl ;
1758 bool GraphExecutor::OutNode::IsWaiting() {
1759 // cdebug_in << "GraphExecutor::OutNode::IsWaiting" << endl;
1760 // cdebug_out << "GraphExecutor::OutNode::IsWaiting" << endl ;
1764 bool GraphExecutor::OutNode::IsReady() {
1765 // cdebug_in << "GraphExecutor::OutNode::IsReady" << endl;
1766 // cdebug_out << "GraphExecutor::OutNode::IsReady" << endl ;
1770 bool GraphExecutor::OutNode::IsRunning() {
1771 // cdebug_in << "GraphExecutor::OutNode::IsRunning" << endl;
1772 // cdebug_out << "GraphExecutor::OutNode::IsRunning" << endl ;
1776 bool GraphExecutor::OutNode::IsDone() {
1777 // cdebug_in << "GraphExecutor::OutNode::IsDone" << endl;
1778 // cdebug_out << "GraphExecutor::OutNode::IsDone" << endl ;
1779 return ( Done() || IsKilled() || IsStopped() ) ;
1782 bool GraphExecutor::OutNode::IsSuspended() {
1783 // cdebug_in << "GraphExecutor::OutNode::IsSuspended" << endl;
1785 // if ( _SuspendedThreads == _Threads && _Threads != 0 ) {
1786 if ( AutomatonGraphState( _State ) == SUPERV::SuspendState ) {
1789 // cdebug_out << "GraphExecutor::OutNode::IsSuspended" << endl ;
1793 bool GraphExecutor::OutNode::IsKilled() {
1794 // cdebug_in << "GraphExecutor::OutNode::IsKilled" << endl;
1796 if ( AutomatonGraphState( _State ) == SUPERV::KillState ) {
1799 // cdebug_out << "GraphExecutor::OutNode::IsKilled" << endl ;
1803 bool GraphExecutor::OutNode::IsStopped() {
1804 // cdebug_in << "GraphExecutor::OutNode::IsStopped" << endl;
1806 if ( AutomatonGraphState( _State ) == SUPERV::StopState ) {
1809 // cdebug_out << "GraphExecutor::OutNode::IsStopped" << endl ;
1813 bool GraphExecutor::OutNode::IsWaiting( const char * NodeName ) {
1815 // cdebug_in << "GraphExecutor::OutNode::IsWaiting " << NodeName << endl;
1816 GraphExecutor::InNode *anInNode = (GraphExecutor::InNode *) Graph()->GetGraphNode( NodeName )->GetInNode() ;
1818 aret = anInNode->IsWaiting() ;
1820 // cdebug_out << "GraphExecutor::OutNode::IsWaiting" << endl ;
1824 bool GraphExecutor::OutNode::IsReady( const char * NodeName ) {
1826 // cdebug_in << "GraphExecutor::OutNode::IsReady " << NodeName << endl;
1827 GraphExecutor::InNode *anInNode = (GraphExecutor::InNode *) Graph()->GetGraphNode( NodeName )->GetInNode() ;
1829 aret = anInNode->IsReady() ;
1831 // cdebug_out << "GraphExecutor::OutNode::IsReady" << endl ;
1835 bool GraphExecutor::OutNode::IsRunning( const char * NodeName ) {
1837 // cdebug_in << "GraphExecutor::OutNode::IsRunning " << NodeName << endl;
1838 GraphExecutor::InNode *anInNode = (GraphExecutor::InNode *) Graph()->GetGraphNode( NodeName )->GetInNode() ;
1840 aret = anInNode->IsRunning() ;
1842 // cdebug_out << "GraphExecutor::OutNode::IsRunning" << endl ;
1846 bool GraphExecutor::OutNode::IsDone( const char * NodeName ) {
1848 // cdebug_in << "GraphExecutor::OutNode::IsDone " << NodeName << endl;
1849 GraphExecutor::InNode *anInNode = (GraphExecutor::InNode *) Graph()->GetGraphNode( NodeName )->GetInNode() ;
1851 aret = anInNode->IsDone() ;
1853 // cdebug_out << "GraphExecutor::OutNode::IsDone" << endl ;
1857 bool GraphExecutor::OutNode::IsSuspended( const char * NodeName ) {
1859 // cdebug_in << "GraphExecutor::OutNode::IsSuspended " << NodeName << endl;
1860 GraphExecutor::InNode *anInNode = (GraphExecutor::InNode *) Graph()->GetGraphNode( NodeName )->GetInNode() ;
1862 aret = anInNode->IsSuspended() ;
1864 // cdebug_out << "GraphExecutor::OutNode::IsSuspended" << endl ;
1868 bool GraphExecutor::OutNode::PortDone( const char * NodeName ,
1869 const char * ServiceParameterName ) {
1870 // cdebug_in << "GraphExecutor::OutNode::IsDone " << NodeName << " "
1871 // << ServiceParameterName<< endl;
1872 bool aret = Graph()->PortDone( NodeName , ServiceParameterName ) ;
1873 // cdebug_out << "GraphExecutor::OutNode::IsDone" << endl ;
1877 bool GraphExecutor::OutNode::ContainerKill() {
1878 bool RetVal = true ;
1879 cdebug_in << "GraphExecutor::OutNode::ContainerKill" << endl;
1880 _ControlState = SUPERV::ToSuspendState ;
1882 for ( i = 0 ; i < Graph()->GraphNodesSize() ; i++ ) {
1883 GraphExecutor::InNode * aNode = (GraphExecutor::InNode * ) Graph()->GraphNodes( i )->GetInNode() ;
1884 bool sts = aNode->ContainerKill() ;
1885 if ( sts && aNode->IsKilled() ) {
1886 cdebug << aNode->Name() << " killed" << endl ;
1888 else if ( aNode->IsWaiting() || aNode->IsDone() ) {
1889 cdebug << aNode->Name() << " not killed : "
1890 << theAutomaton->StateName( aNode->State() ) << endl ;
1893 cdebug << aNode->Name() << " cannot be killed : "
1894 << theAutomaton->StateName( aNode->State() ) << endl ;
1898 if ( !RetVal || Threads() != 0 ) {
1899 for ( i = 0 ; i < Graph()->GraphNodesSize() ; i++ ) {
1900 GraphExecutor::InNode * aNode = (GraphExecutor::InNode * ) Graph()->GraphNodes( i )->GetInNode() ;
1901 if ( !aNode->IsKilled() && !aNode->IsWaiting() && !aNode->IsDone() ) {
1902 aNode->KilledAction() ;
1907 State( GraphExecutor::KilledState ) ;
1908 cdebug_out << "GraphExecutor::OutNode::ContainerKill" << endl ;
1912 bool GraphExecutor::OutNode::Suspend() {
1914 cdebug_in << "GraphExecutor::OutNode::Suspend" << endl;
1915 // _ControlState = SUPERV::ToSuspendState ;
1917 for ( i = 0 ; i < Graph()->GraphNodesSize() ; i++ ) {
1918 GraphExecutor::InNode * aNode = (GraphExecutor::InNode * ) Graph()->GraphNodes( i )->GetInNode() ;
1919 bool sts = aNode->Suspend() ;
1920 if ( sts && aNode->IsSuspended() ) {
1922 cdebug << aNode->Name() << " Suspended" << endl ;
1924 else if ( aNode->IsWaiting() || aNode->IsReady() ) {
1926 cdebug << aNode->Name() << " will be Suspended" << endl ;
1928 else if ( aNode->IsDone() ) {
1929 cdebug << aNode->Name() << " not Suspended : "
1930 << theAutomaton->StateName( aNode->State() ) << endl ;
1934 cdebug << aNode->Name() << " cannot be Suspended : "
1935 << theAutomaton->StateName( aNode->State() ) << endl ;
1939 State( GraphExecutor::SuspendedState ) ;
1940 MESSAGE("================================================================================") ;
1941 MESSAGE( Name() << " IS SUSPENDED" ) ;
1942 MESSAGE("================================================================================") ;
1945 MESSAGE("================================================================================") ;
1946 MESSAGE( Name() << " IS NOT SUSPENDED" ) ;
1947 MESSAGE("================================================================================") ;
1949 for ( i = 0 ; i < Graph()->GraphNodesSize() ; i++ ) {
1950 GraphExecutor::InNode * aNode = (GraphExecutor::InNode * ) Graph()->GraphNodes( i )->GetInNode() ;
1951 MESSAGE(aNode->Name() << " " << theAutomaton->StateName( aNode->State() ) ) ;
1952 cdebug << aNode->Name() << " " << theAutomaton->StateName( aNode->State() ) << endl ;
1954 cdebug_out << "GraphExecutor::OutNode::Suspend " << theAutomaton->StateName( State() )
1955 << " EventQSize " << EventQSize() << endl ;
1959 bool GraphExecutor::OutNode::Resume() {
1961 cdebug_in << "GraphExecutor::OutNode::Resume "
1962 << theAutomaton->StateName( State() ) << endl;
1963 if ( IsSuspended() ) {
1964 State( GraphExecutor::ExecutingState ) ;
1966 for ( i = 0 ; i < Graph()->GraphNodesSize() ; i++ ) {
1967 GraphExecutor::InNode * aNode = (GraphExecutor::InNode * ) Graph()->GraphNodes( i )->GetInNode() ;
1968 aNode->ControlState( SUPERV::VoidState ) ;
1969 if ( aNode->IsSuspended() ) {
1970 cdebug << aNode->Name() << "->Resume " << theAutomaton->StateName( aNode->State() )
1972 if ( aNode->Resume() ) {
1973 cdebug << aNode->Name() << " Resumed " << theAutomaton->StateName( aNode->State() )
1978 cdebug << aNode->Name() << " Resume failed"
1979 << theAutomaton->StateName( aNode->State() ) << endl ;
1983 cdebug << aNode->Name() << " " << theAutomaton->StateName( aNode->State() )
1989 cdebug << Name() << " not suspended " << theAutomaton->StateName( State() ) << endl ;
1992 MESSAGE("================================================================================") ;
1993 MESSAGE( Name() << " IS RESUMED" ) ;
1994 MESSAGE("================================================================================") ;
1997 MESSAGE("================================================================================") ;
1998 MESSAGE( Name() << " IS NOT RESUMED" ) ;
1999 MESSAGE("================================================================================") ;
2002 for ( i = 0 ; i < Graph()->GraphNodesSize() ; i++ ) {
2003 GraphExecutor::InNode * aNode = (GraphExecutor::InNode * ) Graph()->GraphNodes( i )->GetInNode() ;
2004 MESSAGE(aNode->Name() << " " << theAutomaton->StateName( aNode->State() ) ) ;
2005 cdebug << aNode->Name() << " " << theAutomaton->StateName( aNode->State() ) << endl ;
2007 cdebug_out << "GraphExecutor::OutNode::Resume" << theAutomaton->StateName( State() ) << " " << RetVal
2008 << " EventQSize " << EventQSize() << endl ;
2012 bool GraphExecutor::OutNode::Kill() {
2013 bool RetVal = false ;
2014 cdebug_in << "GraphExecutor::OutNode::Kill"
2015 << " EventQSize " << EventQSize() << " State "
2016 << theAutomaton->StateName( State() ) << endl;
2018 cdebug_out << "GraphExecutor::OutNode::Kill " << RetVal
2019 << " Threads " << _Threads << " SuspendedThreads " << _SuspendedThreads
2020 << " EventQSize " << EventQSize() << " State "
2021 << theAutomaton->StateName( State() ) << endl ;
2024 _ControlState = SUPERV::ToSuspendState ;
2026 for ( i = 0 ; i < Graph()->GraphNodesSize() ; i++ ) {
2027 GraphExecutor::InNode * aNode = (GraphExecutor::InNode * ) Graph()->GraphNodes( i )->GetInNode() ;
2028 bool sts = aNode->Kill() ;
2029 if ( sts && Threads() != 0 ) {
2030 if ( !aNode->IsKilled() ) {
2031 cdebug << aNode->Name() << " not killed : "
2032 << theAutomaton->StateName( aNode->State() ) << " " << aNode->Name() << "->"
2033 << "KilledAction()" << endl ;
2034 MESSAGE( aNode->Name() << " not killed : KilledAction()" ) ;
2035 aNode->KilledAction() ;
2037 if ( aNode->IsKilled() ) {
2038 cdebug << aNode->Name() << " killed" << endl ;
2043 // JR 24.03.2005 Debug : the node may have been killed
2044 else if ( aNode->IsKilled() ) {
2045 cdebug << aNode->Name() << " killed" << endl ;
2048 else if ( aNode->IsWaiting() || aNode->IsDone() ) {
2049 cdebug << aNode->Name() << " not killed : "
2050 << theAutomaton->StateName( aNode->State() ) << endl ;
2053 cdebug << aNode->Name() << " cannot be killed : "
2054 << theAutomaton->StateName( aNode->State() ) << endl ;
2058 State( GraphExecutor::KilledState ) ;
2059 MESSAGE("================================================================================") ;
2060 MESSAGE( Name() << " IS KILLED" << theAutomaton->StateName( AutomatonState() ) << " EventQSize "
2062 MESSAGE("================================================================================") ;
2065 MESSAGE("================================================================================") ;
2066 MESSAGE( Name() << " IS NOT KILLED" ) ;
2067 MESSAGE("================================================================================") ;
2069 for ( i = 0 ; i < Graph()->GraphNodesSize() ; i++ ) {
2070 GraphExecutor::InNode * aNode = (GraphExecutor::InNode * ) Graph()->GraphNodes( i )->GetInNode() ;
2071 MESSAGE(aNode->Name() << " " << theAutomaton->StateName( aNode->State() ) ) ;
2072 cdebug << aNode->Name() << " " << theAutomaton->StateName( aNode->State() ) << endl ;
2075 if ( pthread_mutex_lock( &_MutexWait ) ) {
2076 perror("EventLoop pthread_mutex_lock ") ;
2080 //JR 23.02.2005, Debug : siftEvents() must be inside the pthread_mutex_lock
2081 // remove "extra" events from the event queue
2083 if ( pthread_mutex_unlock( &_MutexWait ) ) {
2084 perror("PushEvent pthread_mutex_unlock ") ;
2088 // asv : 25.10.04 : calling Editing() to indicate stop of execution
2089 if ( RetVal ) // mkr : IPAL10722 : we have to indicate stop of execution if only execution was successfully killed
2090 Graph()->GraphEditor()->Editing();
2092 cdebug_out << "GraphExecutor::OutNode::Kill " << RetVal
2093 << " Threads " << _Threads << " SuspendedThreads " << _SuspendedThreads
2094 << " EventQSize " << EventQSize() << endl ;
2099 bool GraphExecutor::OutNode::Stop() {
2100 bool RetVal = false ;
2101 cdebug_in << "GraphExecutor::OutNode::Stop" << endl;
2103 cdebug_out << "GraphExecutor::OutNode::Stop" << endl ;
2105 MESSAGE("================================================================================") ;
2106 MESSAGE( Name() << " IS STOPPED" ) ;
2107 MESSAGE("================================================================================") ;
2112 bool GraphExecutor::OutNode::ReadyWait() {
2113 cdebug_in << "GraphExecutor::OutNode::ReadyWait" << endl;
2115 if ( pthread_mutex_lock( &_MutexWait ) ) {
2116 perror("pthread_mutex_lock _ReadyWait") ;
2122 pthread_cond_wait( &_EventWait , &_MutexWait );
2125 if ( pthread_mutex_unlock( &_MutexWait ) ) {
2126 perror("pthread_mutex_lock _ReadyWait") ;
2129 cdebug_out << "GraphExecutor::OutNode::ReadyWait" << endl ;
2133 bool GraphExecutor::OutNode::RunningWait() {
2134 cdebug_in << "GraphExecutor::OutNode::RunningWait" << endl;
2136 if ( pthread_mutex_lock( &_MutexWait ) ) {
2137 perror("pthread_mutex_lock _RunningWait") ;
2140 aret = IsRunning() ;
2142 cdebug << "RunningWait pthread_cond_wait _EventWait" << endl;
2143 pthread_cond_wait( &_EventWait , &_MutexWait );
2144 aret = IsRunning() ;
2145 cdebug << "RunningWait pthread_cond_waited _EventWait " << aret << endl;
2147 if ( pthread_mutex_unlock( &_MutexWait ) ) {
2148 perror("pthread_mutex_lock _RunningWait") ;
2151 cdebug_out << "GraphExecutor::OutNode::RunningWait " << aret << endl ;
2155 bool GraphExecutor::OutNode::DoneWait() {
2156 cdebug_in << pthread_self() << " GraphExecutor::DoneWait " << this << " " << Name() << endl;
2158 if ( pthread_mutex_lock( &_MutexWait ) ) {
2159 perror("pthread_mutex_lock _DoneWait") ;
2163 while ( !aret && !IsSuspended() && IsRunning() ) {
2164 cdebug << pthread_self() << " GraphExecutor::DoneWait " << this << " " << Name()
2165 << " DoneWait pthread_cond_wait _EventWait " << &_EventWait << endl;
2166 pthread_cond_wait( &_EventWait , &_MutexWait );
2168 cdebug << pthread_self() << " GraphExecutor::DoneWait " << this << " " << Name()
2169 << " DoneWait pthread_cond_waited _EventWaited " << &_EventWait << " : "<< aret << endl;
2171 if ( pthread_mutex_unlock( &_MutexWait ) ) {
2172 perror("pthread_mutex_lock _DoneWait") ;
2175 while ( _run_func_thread || theAutomaton->ThreadsNumber() ) {
2177 // waiting for pthread_join in FiniteStateMachine
2179 if ( Done() || IsKilled() ) Graph()->GraphEditor()->Editing(); // mkr : IPAL14572 : calling Editing() to indicate stop of execution
2180 cdebug_out << pthread_self() << " GraphExecutor::DoneWait " << this << " " << Name()
2181 << " " << State() << " : " << aret << endl ;
2185 bool GraphExecutor::OutNode::SuspendedWait() {
2186 cdebug_in << "GraphExecutor::OutNode::SuspendedWait" << endl;
2188 if ( pthread_mutex_lock( &_MutexWait ) ) {
2189 perror("pthread_mutex_lock _SuspendedWait") ;
2192 aret = IsSuspended() ;
2193 while ( !aret && !IsDone() ) {
2194 pthread_cond_wait( &_EventWait , &_MutexWait );
2195 aret = IsSuspended() ;
2197 if ( pthread_mutex_unlock( &_MutexWait ) ) {
2198 perror("pthread_mutex_lock _SuspendedWait") ;
2201 cdebug_out << "GraphExecutor::OutNode::SuspendedWait" << endl ;
2205 bool GraphExecutor::OutNode::ReadyWait( const char * NodeName ) {
2207 cdebug_in << "GraphExecutor::OutNode::ReadyWait " << NodeName << endl;
2208 GraphExecutor::InNode *anInNode = (GraphExecutor::InNode *) Graph()->GetGraphNode( NodeName )->GetInNode() ;
2210 aret = anInNode->ReadyWait() ;
2212 cdebug_out << "GraphExecutor::OutNode::ReadyWait" << endl ;
2216 bool GraphExecutor::OutNode::RunningWait( const char * NodeName ) {
2218 cdebug_in << "GraphExecutor::OutNode::RunningWait " << NodeName << endl;
2219 GraphExecutor::InNode *anInNode = (GraphExecutor::InNode *) Graph()->GetGraphNode( NodeName )->GetInNode() ;
2221 aret = anInNode->RunningWait() ;
2223 cdebug_out << "GraphExecutor::OutNode::RunningWait" << endl ;
2227 bool GraphExecutor::OutNode::DoneWait( const char * NodeName ) {
2229 cdebug_in << "GraphExecutor::OutNode::DoneWait " << NodeName << endl;
2230 GraphExecutor::InNode *anInNode = (GraphExecutor::InNode *) Graph()->GetGraphNode( NodeName )->GetInNode() ;
2232 aret = anInNode->DoneWait() ;
2234 cdebug_out << "GraphExecutor::OutNode::DoneWait" << endl ;
2238 bool GraphExecutor::OutNode::SuspendedWait( const char * NodeName ) {
2240 cdebug_in << "GraphExecutor::OutNode::SuspendedWait " << NodeName << endl;
2241 GraphExecutor::InNode *anInNode = (GraphExecutor::InNode *) Graph()->GetGraphNode( NodeName )->GetInNode() ;
2243 aret = anInNode->SuspendedWait() ;
2245 cdebug_out << "GraphExecutor::OutNode::SuspendedWait" << endl ;
2249 long GraphExecutor::OutNode::LastLevelDone() {
2252 for ( i = 0 ; i <= Graph()->LevelMax() ; i++ ) {
2253 for ( j = 0 ; j <= Graph()->NodesNumber( i ) ; j++ ) {
2254 GraphBase::ComputingNode * aNode = Graph()->SortedNodes( i , j ) ;
2255 if ( !IsDone( aNode->Name() ) ) {
2259 if ( j != Graph()->NodesNumber( i ) + 1 )
2267 //JR 30.03.2005const CORBA::Any *GraphExecutor::OutNode::GetInData( const char * NodeName ,
2268 const CORBA::Any GraphExecutor::OutNode::GetInData( const char * NodeName ,
2269 const char * ServiceParameterName ) {
2270 // cdebug_in << "GraphExecutor::OutNode::GetInData " << NodeName << " "
2271 // << ServiceParameterName << endl ;
2272 //JR 30.03.2005 const CORBA::Any * retdata = Graph()->PortInData( NodeName , ServiceParameterName ) ;
2273 const CORBA::Any retdata = Graph()->PortInData( NodeName , ServiceParameterName ) ;
2274 // cdebug_out << "GraphExecutor::OutNode::GetInData" << endl ;
2278 //JR 30.03.2005const CORBA::Any *GraphExecutor::OutNode::GetOutData( const char * NodeName ,
2279 const CORBA::Any GraphExecutor::OutNode::GetOutData( const char * NodeName ,
2280 const char * ServiceParameterName ) {
2281 // cdebug_in << "GraphExecutor::OutNode::GetOutData " << NodeName << " "
2282 // << ServiceParameterName << endl ;
2283 //JR 30.03.2005 const CORBA::Any * retdata = Graph()->PortOutData( NodeName , ServiceParameterName ) ;
2284 const CORBA::Any retdata = Graph()->PortOutData( NodeName , ServiceParameterName ) ;
2285 // cdebug_out << "GraphExecutor::OutNode::GetOutData" << endl ;
2289 const long GraphExecutor::OutNode::CpuUsed() {
2290 return Graph()->CpuUsed() ;
2293 const long GraphExecutor::OutNode::CpuUsed( const char * aNodeName ) {
2294 GraphBase::ComputingNode * aNode = Graph()->GetChangeGraphNode( aNodeName ) ;
2296 GraphExecutor::InNode * anInNode = (GraphExecutor::InNode * ) aNode->GetInNode() ;
2298 return anInNode->CpuUsed() ;
2304 // remove equal sets "Node-Event-State" from _EventNodes/_Events/_States queues
2305 void GraphExecutor::OutNode::siftEvents() {
2306 list<char*>::reverse_iterator itNodes = _EventNodes.rbegin();
2307 list<GraphExecutor::NodeEvent>::reverse_iterator itEvents = _Events.rbegin();
2308 list<GraphExecutor::AutomatonState>::reverse_iterator itStates = _States.rbegin();
2309 list<char*> _NewEventNodes;
2310 list<GraphExecutor::NodeEvent> _NewEvents;
2311 list<GraphExecutor::AutomatonState> _NewStates;
2312 for ( ; itNodes != _EventNodes.rend() ; ++itNodes, ++itEvents, ++itStates) {
2313 //cout << "----- aNodeName ==> " << *itNodes;
2314 list<char*>::reverse_iterator itNewNodes = _NewEventNodes.rbegin();
2316 for ( ; itNewNodes != _NewEventNodes.rend() ; ++itNewNodes ) {
2317 if ( !strcmp( *itNewNodes, *itNodes ) ) {
2327 _NewEventNodes.push_back( *itNodes );
2328 _NewEvents.push_back( *itEvents );
2329 _NewStates.push_back( *itStates );
2333 _EventNodes = _NewEventNodes;
2334 _Events = _NewEvents;
2335 _States = _NewStates;