1 // SUPERV GraphExecutor : contains classes that permit execution of graphs and particularly the execution automaton
3 // Copyright (C) 2003 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
6 // This library is free software; you can redistribute it and/or
7 // modify it under the terms of the GNU Lesser General Public
8 // License as published by the Free Software Foundation; either
9 // version 2.1 of the License.
11 // This library is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 // Lesser General Public License for more details.
16 // You should have received a copy of the GNU Lesser General Public
17 // License along with this library; if not, write to the Free Software
18 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20 // See http://www.opencascade.org/SALOME/ or email : webmaster.salome@opencascade.org
24 // File : DataFlowBase_OutNode.cxx
25 // Author : Jean Rahuel, CEA
31 #include "DataFlowExecutor_OutNode.hxx"
33 #include "DataFlowEditor_DataFlow.hxx"
35 // asv : 20.01.05 : changes involved with switching to old (HEAD) KERNEL
36 //extern Engines_Container_i * _TheContainer ;
38 extern GraphExecutor::FiniteStateMachine * theAutomaton ;
40 // static const char *ComponentName = "SalomeSuperVisionComponent" ;
43 extern char ** _ArgV ;
45 GraphExecutor::OutNode::OutNode() {
47 // asv : 20.01.05 : changes involved with switching to old (HEAD) KERNEL
48 //_SuperVisionContainer = _TheContainer ;
49 //_MainThreadId = SuperVisionContainer()->MainThreadId() ;
54 _ControlState = SUPERV::VoidState ;
55 _State = GraphExecutor::UnKnownState ;
56 _PyInitialized = false ;
57 pthread_mutex_init( &_MutexWait , NULL ) ;
58 pthread_mutex_init( &_PyMutexWait , NULL ) ;
59 if ( pthread_cond_init( &_EventWait , NULL ) ) {
60 perror("pthread_cond_init( &_EventWait , NULL )") ;
63 if ( pthread_cond_init( &_JoinWait , NULL ) ) {
64 perror("pthread_cond_init( &_JoinWait , NULL )") ;
69 GraphExecutor::OutNode::OutNode( CORBA::ORB_ptr ORB,
70 SALOME_NamingService* ptrNamingService ,
71 const char *DataFlowName ,
72 const char * DebugFileName ,
73 const SUPERV::KindOfNode aKindOfNode ) {
74 // Graph( ORB , ptrNamingService , DataFlowName , DebugFileName ) {
75 Set_prof_debug( ORB , DebugFileName ) ;
76 cdebug_in << "GraphExecutor::OutNode::OutNode(" << DataFlowName << " , " << aKindOfNode << ")" << endl;
77 if ( aKindOfNode == SUPERV::DataFlowGraph ) {
79 // _Graph = new GraphBase::Graph( ORB , ptrNamingService , DataFlowName , DebugFileName ) ;
80 _Graph = new GraphBase::Graph( ORB , ptrNamingService , DataFlowName , aKindOfNode ,
81 _prof_debug , _fdebug ) ;
83 else if ( aKindOfNode == SUPERV::DataStreamGraph ) {
84 // _StreamGraph = new GraphBase::StreamGraph( ORB , ptrNamingService , DataFlowName , DebugFileName ) ;;
85 _StreamGraph = new GraphBase::StreamGraph( ORB , ptrNamingService , DataFlowName , aKindOfNode ,
86 _prof_debug , _fdebug ) ;
87 _Graph = _StreamGraph ;
89 // asv : 20.01.05 : changes involved with switching to old (HEAD) KERNEL
90 //_SuperVisionContainer = _TheContainer ;
91 //_MainThreadId = SuperVisionContainer()->MainThreadId() ;
96 _ControlState = SUPERV::VoidState ;
97 _State = GraphExecutor::UnKnownState ;
98 _PyInitialized = false ;
99 _Orb = CORBA::ORB::_duplicate( ORB ) ;
100 pthread_mutex_init( &_MutexWait , NULL ) ;
101 pthread_mutex_init( &_PyMutexWait , NULL ) ;
102 if ( pthread_cond_init( &_EventWait , NULL ) ) {
103 perror("pthread_cond_init( &_EventWait , NULL )") ;
106 if ( pthread_cond_init( &_JoinWait , NULL ) ) {
107 perror("pthread_cond_init( &_JoinWait , NULL )") ;
110 cdebug_out << "GraphExecutor::OutNode::OutNode" << endl;
113 GraphExecutor::OutNode::OutNode( CORBA::ORB_ptr ORB,
114 SALOME_NamingService* ptrNamingService ,
115 const SALOME_ModuleCatalog::Service& DataFlowService ,
116 const char *DataFlowComponentName ,
117 const char *DataFlowInterfaceName ,
118 const char *DataFlowName ,
119 const SUPERV::KindOfNode DataFlowkind ,
120 const SUPERV::SDate DataFlowFirstCreation ,
121 const SUPERV::SDate DataFlowLastModification ,
122 const char * DataFlowEditorRelease ,
123 const char * DataFlowAuthor ,
124 const char * DataFlowComputer ,
125 const char * DataFlowComment ,
126 const char * DebugFileName ) {
127 // Graph( ORB , ptrNamingService , DataFlowService , DataFlowComponentName ,
128 // DataFlowInterfaceName , DataFlowName , DataFlowkind ,
129 // DataFlowFirstCreation , DataFlowLastModification ,
130 // DataFlowEditorRelease , DataFlowAuthor ,
131 // DataFlowComputer , DataFlowComment , DebugFileName ) {
132 Set_prof_debug( ORB , DebugFileName ) ;
134 cdebug_in << "GraphExecutor::OutNode::OutNode(" << DataFlowName << " , " << DataFlowkind << ")" << endl;
135 if ( DataFlowkind == SUPERV::DataFlowGraph ) {
136 _StreamGraph = NULL ;
137 _Graph = new GraphBase::Graph( ORB , ptrNamingService , DataFlowService , DataFlowComponentName ,
138 DataFlowInterfaceName , DataFlowName , DataFlowkind ,
139 DataFlowFirstCreation , DataFlowLastModification ,
140 DataFlowEditorRelease , DataFlowAuthor ,
141 DataFlowComputer , DataFlowComment ,
142 _prof_debug , _fdebug ) ;
143 // DataFlowComputer , DataFlowComment , DebugFileName ) ;
145 else if ( DataFlowkind == SUPERV::DataStreamGraph ) {
146 _StreamGraph = new GraphBase::StreamGraph( ORB , ptrNamingService , DataFlowService , DataFlowComponentName ,
147 DataFlowInterfaceName , DataFlowName , DataFlowkind ,
148 DataFlowFirstCreation , DataFlowLastModification ,
149 DataFlowEditorRelease , DataFlowAuthor ,
150 DataFlowComputer , DataFlowComment ,
151 _prof_debug , _fdebug ) ;
152 _Graph = _StreamGraph ;
154 // asv : 20.01.05 : changes involved with switching to old (HEAD) KERNEL
155 //_SuperVisionContainer = _TheContainer ;
156 //_MainThreadId = SuperVisionContainer()->MainThreadId() ;
158 _Executable = false ;
161 _ControlState = SUPERV::VoidState ;
162 _State = GraphExecutor::UnKnownState ;
163 _PyInitialized = false ;
164 _Orb = CORBA::ORB::_duplicate( ORB ) ;
165 pthread_mutex_init( &_MutexWait , NULL ) ;
166 pthread_mutex_init( &_PyMutexWait , NULL ) ;
167 if ( pthread_cond_init( &_EventWait , NULL ) ) {
168 perror("pthread_cond_init( &_EventWait , NULL )") ;
171 if ( pthread_cond_init( &_JoinWait , NULL ) ) {
172 perror("pthread_cond_init( &_JoinWait , NULL )") ;
177 GraphExecutor::OutNode::~OutNode() {
180 void GraphExecutor::OutNode::Set_prof_debug( CORBA::ORB_ptr ORB ,
181 const char * DebugFileName ) {
182 _Graph_prof_debug = 0 ;
183 if ( DebugFileName ) {
184 _fdebug = new ofstream( DebugFileName );
185 SetDebug( ORB , &_Graph_prof_debug , _fdebug ) ;
186 MESSAGE( endl << "Trace redirected to file " << DebugFileName << endl)
190 bool GraphExecutor::OutNode::LoadDataFlow(const GraphBase::SGraph * aDataFlow ) {
191 bool RetVal = false ;
192 cdebug_in << "GraphExecutor::OutNode::LoadDataFlow " << (*aDataFlow).Info.theName << endl ;
193 RetVal = LoadInfo( (*aDataFlow).Info ) ;
194 if ( Graph()->ServiceName() != NULL ) {
195 // MESSAGE( "GraphExecutor::OutNode::LoadDataFlow" );
197 RetVal = LoadNodes( (*aDataFlow).Nodes ) ;
199 RetVal = LoadLinks( (*aDataFlow).Links ) ;
202 RetVal = LoadDatas( (*aDataFlow).Datas ) ;
205 cdebug << "GraphExecutor::OutNode::LoadDataFlow LoadDatas Error."
210 cdebug << "GraphExecutor::OutNode::LoadDataFlow LoadLinks Error."
215 cdebug << "GraphExecutor::OutNode::LoadDataFlow LoadNodes Error."
220 cdebug << "GraphExecutor::OutNode::LoadDataFlow LoadInfo Error."
225 cdebug << "GraphExecutor::OutNode::LoadDataFlow ServiceName Error." << endl ;
227 cdebug_out << "GraphExecutor::OutNode::LoadDataFlow " << Graph()->Name() << " RetVal "
233 bool GraphExecutor::OutNode::LoadXml( const char* myFileName ) {
234 bool RetVal = false ;
235 GraphBase::ListOfSGraphs aListOfDataFlows ;
236 if ( Graph()->LoadXml( _Orb , myFileName , aListOfDataFlows ) ) {
237 RetVal = LoadDataFlow( aListOfDataFlows ) ;
238 // if ( aConstructor && RetVal )
239 // RetVal = Name( aDataFlow.Info.theName.c_str() ) ;
245 bool GraphExecutor::OutNode::LoadInfo(const GraphBase::SNode &aDataFlowInfo ) {
246 cdebug << "GraphExecutor::OutNode::LoadInfo _StreamGraph " << _StreamGraph << endl ;
247 // ComponentName( aDataFlowInfo.theComponentName.c_str() ) ;
248 Graph()->Name( aDataFlowInfo.theName.c_str() ) ;
249 Graph()->Kind( aDataFlowInfo.theKind ) ;
250 if ( Graph()->IsDataStreamNode() && aDataFlowInfo.theKind == SUPERV::DataStreamGraph ) {
251 StreamGraph()->SetStreamParams( aDataFlowInfo.theTimeout , aDataFlowInfo.theDataStreamTrace , aDataFlowInfo.theDeltaTime ) ;
253 Graph()->DataService( _Orb , aDataFlowInfo.theService , _prof_debug , _fdebug ) ;
254 Graph()->FirstCreation( aDataFlowInfo.theFirstCreation ) ;
255 Graph()->LastModification( aDataFlowInfo.theLastModification ) ;
256 Graph()->EditorRelease( aDataFlowInfo.theEditorRelease.c_str() ) ;
257 Graph()->Author( aDataFlowInfo.theAuthor.c_str() ) ;
258 // Graph()->Computer( aDataFlowInfo.theContainer.c_str() ) ;
259 Graph()->Comment( aDataFlowInfo.theComment.c_str() ) ;
260 // Not in OutNode/DataFlow but in InNode/DataFlow_in_an_other_DataFlow
261 // Graph()->Coordinates( aDataFlowInfo.theX , aDataFlowInfo.theY ) ;
265 bool GraphExecutor::OutNode::LoadNodes(const GraphBase::ListOfSNodes &aListOfNodes ) {
267 GraphExecutor::InNode * anInNode ;
268 cdebug << "GraphExecutor::OutNode::LoadNodes" << endl ;
270 for ( i = 0 ; i < (int ) aListOfNodes.size() ; i++ ) {
271 GraphBase::SNode aNode = aListOfNodes[ i ] ;
272 anInNode = AddNode( aNode.theService ,
273 aNode.theListOfFuncName ,
274 aNode.theListOfPythonFunctions ,
275 aNode.theComponentName.c_str() ,
276 aNode.theInterfaceName.c_str() , aNode.theName.c_str() ,
278 aNode.theFirstCreation , aNode.theLastModification ,
279 aNode.theEditorRelease.c_str() ,
280 aNode.theAuthor.c_str() , aNode.theContainer.c_str() ,
281 aNode.theComment.c_str() ,
282 aNode.theCoords.theX , aNode.theCoords.theY ) ;
287 if ( anInNode->IsOneOfInLineNodes() || anInNode->IsMacroNode() ) {
288 anInNode->GraphExecutor::InNode::InLineNode()->DefPortsOfNode(
289 _Orb , aNode.theService , anInNode->NamePtr() ,
291 _prof_debug , _fdebug ) ;
293 // GraphBase::ComputingNode * theNode = Graph()->GetChangeGraphNode( aNode.theName.c_str() ) ;
296 for ( j = 0 ; j < aNode.theListOfInDataStreams.size() ; j++ ) {
297 GraphBase::InPort * anInPort ;
298 anInPort = anInNode->ComputingNode()->AddInDataStreamPort( aNode.theListOfInDataStreams[ j ].theDataStreamParameter.Parametername ,
299 aNode.theListOfInDataStreams[ j ].theDataStreamParameter.Parametertype ,
300 aNode.theListOfInDataStreams[ j ].theDataStreamParameter.Parameterdependency ,
301 SUPERV::DataStreamParameter ) ;
302 ((GraphBase::InDataStreamPort * ) anInPort)->SetParams( aNode.theListOfInDataStreams[ j ].theKindOfSchema ,
303 aNode.theListOfInDataStreams[ j ].theKindOfInterpolation ,
304 aNode.theListOfInDataStreams[ j ].theKindOfExtrapolation ) ;
306 for ( j = 0 ; j < aNode.theListOfOutDataStreams.size() ; j++ ) {
307 GraphBase::OutPort * anOutPort ;
308 anOutPort = anInNode->ComputingNode()->AddOutDataStreamPort( aNode.theListOfOutDataStreams[ j ].theDataStreamParameter.Parametername ,
309 aNode.theListOfOutDataStreams[ j ].theDataStreamParameter.Parametertype ,
310 aNode.theListOfOutDataStreams[ j ].theDataStreamParameter.Parameterdependency ,
311 SUPERV::DataStreamParameter ) ;
312 ((GraphBase::OutDataStreamPort * ) anOutPort)->NumberOfValues( aNode.theListOfOutDataStreams[ j ].theNumberOfValues ) ;
316 // theNode->DataStreamInPortsNumber( aNode.theDataStreamInArgsNumber ) ;
317 // theNode->DataStreamOutPortsNumber( aNode.theDataStreamOutArgsNumber ) ;
318 // cdebug << "GraphExecutor::OutNode::LoadNodes " << anInNode->Name()
319 // << " InPortsSize " << theNode->GetNodeInPortsSize()
320 // << " OutPortsSize " << theNode->GetNodeOutPortsSize()
321 // << " DataStreamInPortsNumber " << aNode.theDataStreamInArgsNumber
322 // << " DataStreamOutPortsNumber " << aNode.theDataStreamOutArgsNumber
325 // if ( aNode.theDataStreamInArgsNumber ) { // -1 because of Gates
326 // for ( j = theNode->GetNodeInPortsSize() - aNode.theDataStreamInArgsNumber - 1 ; j < theNode->GetNodeInPortsSize() - 1 ; j++ ) {
327 // cdebug << "GraphExecutor::OutNode::LoadNodes " << anInNode->Name()
328 // << " InPort " << theNode->GetChangeNodeInPort( j )->PortName()
329 // << " Kind( DataStreamParameter)" << endl ;
330 // theNode->GetChangeNodeInPort( j )->Kind( SUPERV::DataStreamParameter ) ;
333 // if ( aNode.theDataStreamOutArgsNumber ) {
334 // int withgate = 1 ;
335 // if ( theNode->IsLoopNode() || theNode->IsEndLoopNode() ) {
338 // for ( j = theNode->GetNodeOutPortsSize() - aNode.theDataStreamOutArgsNumber - withgate ; j < theNode->GetNodeOutPortsSize() - withgate ; j++ ) {
339 // cdebug << "GraphExecutor::OutNode::LoadNodes " << anInNode->Name()
340 // << " OutPort " << theNode->GetChangeNodeOutPort( j )->PortName()
341 // << " Kind( DataStreamParameter)" << endl ;
342 // theNode->GetChangeNodeOutPort( j )->Kind( SUPERV::DataStreamParameter ) ;
346 for ( i = 0 ; i < (int ) aListOfNodes.size() ; i++ ) {
347 GraphBase::SNode aNode = aListOfNodes[ i ] ;
348 anInNode = (GraphExecutor::InNode * ) Graph()->GetChangeGraphNode( aNode.theName.c_str() )->GetInNode() ;
349 cdebug << "GraphExecutor::OutNode::LoadNodes " << anInNode->Name() << " IsOneOfGOTONodes "
350 << anInNode->IsOneOfGOTONodes() << " " << aNode.theCoupledNode.c_str() << endl ;
351 if ( anInNode->IsOneOfGOTONodes() && strlen( aNode.theCoupledNode.c_str() ) ) {
352 GraphBase::GOTONode * aCoupledNode ;
353 aCoupledNode = (GraphBase::GOTONode * ) Graph()->GetGraphNode( aNode.theName.c_str() ) ;
354 GraphBase::GOTONode * aCoupledCoupledNode ;
355 aCoupledCoupledNode = (GraphBase::GOTONode * ) Graph()->GetChangeGraphNode( aNode.theCoupledNode.c_str() ) ;
356 if ( aCoupledCoupledNode != NULL ) {
357 aCoupledNode->CoupledNode( aCoupledCoupledNode ) ;
360 aCoupledNode->CoupledNodeName( aNode.theCoupledNode.c_str() ) ;
367 bool GraphExecutor::OutNode::LoadLinks(const GraphBase::ListOfSLinks &aListOfLinks ) {
369 cdebug << "GraphExecutor::OutNode::LoadLinks " << aListOfLinks.size()
372 for ( i = 0 ; i < (int ) aListOfLinks.size() ; i++ ) {
373 GraphBase::SLink aLink = aListOfLinks[ i ] ;
374 RetVal = Graph()->AddLink( aLink.FromNodeName.c_str() ,
375 aLink.FromServiceParameterName.c_str() ,
376 aLink.ToNodeName.c_str() ,
377 aLink.ToServiceParameterName.c_str() ) ;
378 // , aLink.aLinkValue ) ;
385 bool GraphExecutor::OutNode::LoadDatas(const GraphBase::ListOfSLinks &aListOfDatas ) {
387 cdebug << "GraphExecutor::OutNode::LoadDatas " << aListOfDatas.size()
390 for ( i = 0 ; i < (int ) aListOfDatas.size() ; i++ ) {
391 GraphBase::SLink aLink = aListOfDatas[ i ] ;
392 if ( !strcmp( aLink.FromNodeName.c_str() , Graph()->Name() ) )
393 RetVal = Graph()->AddInputData( aLink.ToNodeName.c_str() ,
394 aLink.ToServiceParameterName.c_str() ,
396 // else if ( !strcmp( aLink.ToNodeName.c_str() , Graph()->Name() ) ) {
397 // RetVal = Graph()->AddOutputData( aLink.FromNodeName.c_str() ,
398 // aLink.FromServiceParameterName.c_str() ) ;
399 // Graph()->AddLink( aLink.FromNodeName.c_str() , (GraphBase::ComputingNode *) this ) ;
402 cdebug << "GraphExecutor::OutNode::LoadDatas Error " << aLink.FromNodeName
403 << " and " << aLink.ToNodeName << " differents from " << Graph()->Name()
413 GraphExecutor::InNode *GraphExecutor::OutNode::AddNode(
414 const SALOME_ModuleCatalog::Service& NodeService ,
415 GraphBase::ListOfFuncName aFuncName ,
416 GraphBase::ListOfPythonFunctions aPythonFunction ,
417 const char * NodeComponentName ,
418 const char * NodeInterfaceName ,
419 const char * NodeName ,
420 const SUPERV::KindOfNode NodeKindOfNode ,
421 const SUPERV::SDate NodeFirstCreation ,
422 const SUPERV::SDate NodeLastModification ,
423 const char * NodeEditorRelease ,
424 const char * NodeAuthor ,
425 const char * NodeComputer ,
426 const char * NodeComment ,
429 cdebug_in << "GraphExecutor::OutNode::AddNode(" << NodeComponentName << " , "
430 << NodeName << ")" << endl;
431 GraphExecutor::InNode *Nd = NULL ;
432 Nd = new GraphExecutor::InNode( _Orb, Graph()->NamingService() , NodeService ,
433 NodeComponentName , NodeInterfaceName ,
434 NodeName , NodeKindOfNode ,
435 aFuncName , aPythonFunction ,
436 NodeFirstCreation , NodeLastModification ,
437 NodeEditorRelease , NodeAuthor ,
438 NodeComputer , NodeComment , false , NodeX , NodeY ,
439 _prof_debug , _fdebug ) ;
440 Graph()->AddNode( Nd->ComputingNode() ) ;
441 cdebug_out << "GraphExecutor::OutNode::AddNode" << endl;
446 bool GraphExecutor::OutNode::Valid() {
447 cdebug_in << "GraphExecutor::OutNode::Valid" << endl;
452 _Executable = false ;
454 if ( !Graph()->CreateService() ) {
455 cdebug_out << "This DataFlow has invalid type(s)." << endl ;
458 int SubStreamGraphsNumber = 0 ;
459 if ( !Graph()->Sort( SubStreamGraphsNumber ) ) {
460 cdebug_out << "This DataFlow is not valid." << endl ;
463 if ( Graph()->IsDataStreamNode() ) {
464 StreamGraph()->SubStreamGraphsNumber( SubStreamGraphsNumber ) ;
466 if ( !Graph()->ValidLoops() ) {
467 cdebug_out << "This DataFlow have not valid Loops." << endl ;
473 Graph()->InLineServices() ;
475 Graph()->ComputingNodes() ;
479 cdebug_out << "GraphExecutor::OutNode::Valid" << endl;
484 bool GraphExecutor::OutNode::Executable() {
486 cdebug_in << "GraphExecutor::OutNode::Executable" << endl;
490 if ( Graph()->DataServerNodes() )
493 cdebug << "This DataFlow is not executable." << endl ;
494 _Executable = false ;
497 cdebug_out << "GraphExecutor::OutNode::Executable " << _Executable << endl;
501 bool GraphExecutor::OutNode::Run( const bool AndSuspend ) {
502 bool RetVal = false ;
503 cdebug_in << pthread_self() << "GraphExecutor::OutNode::Run( AndSuspend " << AndSuspend << " )"
506 if ( Executable() ) {
507 _ControlState = SUPERV::VoidState ;
508 _SuspendedThreads = 0 ;
509 Graph()->ThreadNo( pthread_self() ) ;
511 _JustStarted = true ;
514 for ( i = 0 ; i < Graph()->GraphNodesSize() ; i++ ) {
515 GraphExecutor::InNode * anInNode = (GraphExecutor::InNode *) Graph()->GraphNodes( i )->GetInNode() ;
516 anInNode->OutNode( this ) ;
517 // Initialize in python interpretor the python functions
518 if ( !PyInitialized() && anInNode->IsOneOfInLineNodes() ) {
519 if ( !Py_IsInitialized() ) {
520 // PyEval_InitThreads() ;
522 // asv : 20.01.05 : changes involved with switching to old (HEAD) KERNEL
523 // 1 line below uncommented
524 PySys_SetArgv( _ArgC , _ArgV ) ;
526 anInNode->InitPython() ;
527 PyInitialized( true ) ;
529 anInNode->InitialState() ;
530 if ( anInNode->IsOneOfInLineNodes() ) {
531 anInNode->InitPythonFunctions( false ) ;
534 // One more time because inline nodes may share one definition of the same function
535 for ( i = 0 ; i < Graph()->GraphNodesSize() ; i++ ) {
536 GraphExecutor::InNode * anInNode = (GraphExecutor::InNode *) Graph()->GraphNodes( i )->GetInNode() ;
537 if ( anInNode->IsOneOfInLineNodes() ) {
538 if ( !anInNode->InitPythonFunctions( true ) ) {
539 anInNode->State( GraphExecutor::ErroredState ) ;
540 State( GraphExecutor::ErroredState ) ;
541 cdebug_out << "GraphExecutor::OutNode::Run InitPythonFunctions ERROR "
542 << anInNode->Name() << endl ;
547 /* asv : 29.09.04 : commented out because it does not do anything useful
548 for ( i = 0 ; i < Graph()->GraphNodesSize() ; i++ ) {
549 GraphExecutor::InNode * anInNode = (GraphExecutor::InNode *) Graph()->GraphNodes( i )->GetInNode() ;
550 if ( RetVal && anInNode->IsMacroNode() ) {
551 GraphBase::Graph * aMacroGraph = anInNode->GraphMacroNode() ;
552 cdebug << "GraphExecutor::OutNode::Run " << anInNode << " MacroNode " << aMacroGraph
553 << aMacroGraph->Name() << endl ;
554 SUPERV::Graph_var iobject = anInNode->GraphMacroNode()->MacroObject() ;
555 if ( CORBA::is_nil( iobject ) ) {
556 cdebug << "GraphExecutor::OutNode::Run MacroObject() is a nil object. Error" << endl ;
560 cdebug << "GraphExecutor::OutNode::Run MacroObject() is NOT a nil object." << endl ;
565 if ( Graph()->GraphMacroLevel() != 0 ) {
566 cdebug << "GraphExecutor::OutNode::Run Execution starting GraphExecutor::Action_DataOk_RunService Node "
567 << Graph()->Name() << " GraphMacroLevel " << Graph()->GraphMacroLevel() << endl ;
568 PushEvent( NULL , GraphExecutor::NoDataReadyEvent ,
569 GraphExecutor::DataUndefState ) ;
572 cdebug << "Execution starting GraphExecutor::Action_DataOk_RunService Node "
573 << Graph()->Name() << " GraphMacroLevel " << Graph()->GraphMacroLevel() << endl ;
574 PushEvent( NULL , GraphExecutor::ReadyEvent ,
575 GraphExecutor::DataReadyState ) ;
576 State( GraphExecutor::DataReadyState ) ;
578 cdebug << pthread_self() << " GraphExecutor::OutNode::Run Start of the " << Graph()->HeadNodesSize()
579 << " HeadNodes" << endl ;
580 for ( i = 0 ; i < Graph()->HeadNodesSize() ; i++ ) {
581 GraphExecutor::InNode * anInNode = (GraphExecutor::InNode *) Graph()->HeadNodes( i )->GetInNode() ;
582 cdebug << pthread_self() << "GraphExecutor::OutNode::Run Start of HeadNode " << i << " "
583 << anInNode->Name() << endl ;
584 if ( anInNode->State() != GraphExecutor::DataReadyState ) {
585 cdebug << "GraphExecutor::OutNode::Run inconsistency State of Node "
586 << anInNode->Name() << " : " << anInNode->State() << endl ;
587 cdebug_out << "GraphExecutor::OutNode::Run State ERROR" << endl ;
590 // PushEvent( anInNode , GraphExecutor::ReadyEvent ,
591 // GraphExecutor::DataReadyState ) ;
592 // We say that we have to create a thread for that HeadNode 'anInNode'
593 anInNode->CreateNewThread( true ) ;
594 anInNode->DataFromNode( Graph()->Name() ) ;
595 // AndSuspend == true <==> Start()
597 anInNode->State( GraphExecutor::DataWaitingState ) ;
598 anInNode->ControlState( SUPERV::ToSuspendStartState ) ;
599 // We send SomeDataReadyEvent
600 // It is a HeadNode ==> AllDataReadyEvent ==> InNode::executeAction() ==> pthread_create
601 if ( !anInNode->SendEvent( GraphExecutor::SomeDataReadyEvent ) ) {
602 cdebug << "InNode::SendEvent( SomeDataReadyEvent ) ERROR Node "
603 << anInNode->Name() << endl ;
604 cdebug_out << "GraphExecutor::OutNode::Run SendEvent ERROR" << endl ;
607 // ==> We wait for SuspendedState
608 anInNode->SuspendedWait() ;
610 // AndSuspend == false <==> Run()
611 else if ( anInNode->IsMacroNode() ) {
612 if ( !anInNode->SendEvent( GraphExecutor::SomeDataReadyEvent ) ) {
613 cdebug << "InNode::SendEvent( SomeDataReadyEvent ) ERROR Node "
614 << anInNode->Name() << endl ;
615 cdebug_out << "GraphExecutor::OutNode::Run SendEvent ERROR" << endl ;
618 cdebug << pthread_self() << " GraphExecutor::OutNode::Run " << anInNode->Name() << "->RunningWait"
620 // ==> We wait for RunningState
621 anInNode->RunningWait() ;
622 cdebug << pthread_self() << " GraphExecutor::OutNode::Run " << anInNode->Name() << "->RunningWaited"
625 else if ( !anInNode->IsMacroNode() ) {
626 // It is a HeadNode ==> AllDataReadyEvent ==> InNode::executeAction() ==> pthread_create
627 if ( !anInNode->SendEvent( GraphExecutor::ExecuteEvent ) ) {
628 cdebug << "InNode::SendEvent( ExecuteEvent ) ERROR Node "
629 << anInNode->Name() << endl ;
630 cdebug_out << "GraphExecutor::OutNode::Run SendEvent ERROR" << endl ;
633 // ==> We wait for RunningState
634 anInNode->RunningWait() ;
639 PushEvent( NULL , GraphExecutor::SuspendedReadyEvent ,
640 GraphExecutor::SuspendedReadyState ) ;
643 PushEvent( NULL , GraphExecutor::ExecutingEvent ,
644 GraphExecutor::ExecutingState ) ;
645 if (AutomatonState() == GraphExecutor::DataReadyState) {
646 State( GraphExecutor::ExecutingState ) ;
649 // ostringstream astr ;
650 // astr << "Graph " << Graph()->Name() << " is running" ;
651 // Graph()->ObjImpl()->sendMessage( NOTIF_STEP, astr.str().c_str() ) ;
656 cdebug_out << pthread_self() << "GraphExecutor::OutNode::Run " << Graph()->Name()
657 << " GraphMacroLevel "
658 << Graph()->GraphMacroLevel() << " RetVal " << RetVal << endl ;
662 void GraphExecutor::OutNode::CheckAllDone() {
664 cdebug_in << "GraphExecutor::OutNode::CheckAllDone " << endl;
665 GraphExecutor::AutomatonState OutNodeState = GraphExecutor::SuccessedState ;
666 GraphExecutor::AutomatonState InNodeState ;
667 bool AllDone = true ;
669 for ( j = 0 ; j < Graph()->QueueNodesSize() ; j++ ) {
670 InNodeState = ( (GraphExecutor::InNode * ) Graph()->QueueNodes( j )->GetInNode() )->State() ;
672 << ( (GraphExecutor::InNode * ) Graph()->QueueNodes( j )->GetInNode() )->Name()
673 << " " << theAutomaton->StateName( InNodeState ) << endl ;
674 if ( InNodeState != GraphExecutor::SuccessedState &&
675 InNodeState != GraphExecutor::ErroredState &&
676 InNodeState != GraphExecutor::DataWaitingState ) {
679 if ( InNodeState != GraphExecutor::SuccessedState &&
680 InNodeState != GraphExecutor::DataWaitingState &&
681 InNodeState != GraphExecutor::DataReadyState ) {
682 OutNodeState = InNodeState ;
686 if( _Threads == 0 && _SuspendedThreads == 0 ) {
687 if ( OutNodeState != GraphExecutor::ErroredState ) {
688 OutNodeState = GraphExecutor::SuccessedState ;
697 for ( j = 0 ; j < Graph()->GraphNodesSize() ; j++ ) {
698 GraphExecutor::InNode * aNode ;
699 aNode = (GraphExecutor::InNode * ) Graph()->GraphNodes( j )->GetInNode() ;
700 SUPERV::GraphState aState = AutomatonGraphState( aNode->State() ) ;
701 cdebug << "GraphExecutor::OutNode::CheckAllDone " << aNode->Name() << " "
702 << theAutomaton->StateName( aNode->State() ) << " CreateNewThread " << aNode->CreateNewThread()
704 if ( aState == SUPERV::ErrorState ||
705 aState == SUPERV::SuspendErroredState ||
706 aState == SUPERV::KillState ||
707 aState == SUPERV::StopState ) {
708 OutNodeState = aNode->State() ;
709 State( OutNodeState ) ;
711 else if ( aState == SUPERV::ReadyState ||
712 aState == SUPERV::SuspendReadyState ||
713 aState == SUPERV::RunningState ||
714 aState == SUPERV::SuspendDoneState ||
715 aState == SUPERV::SuspendErroredState ||
716 aState == SUPERV::SuspendState ) {
719 aNode->SuspendedAction() ;
720 aNode->DoneAction() ;
722 // PushEvent AFTER State and _Done ! ...
723 if ( alivenodes == 0 ) {
724 State( OutNodeState ) ;
726 _JustStarted = false ;
728 cdebug << Graph()->Name() << " alivenodes " << alivenodes << " OutNodeState " << OutNodeState
730 PushEvent( NULL , GraphExecutor::EndExecuteEvent ,
733 // PyInitialized( false ) ;
737 MESSAGE("================================================================================") ;
738 MESSAGE( Graph()->Name() << " IS DONE : " << theAutomaton->StateName( AutomatonState() ) << " EventQSize "
740 MESSAGE("================================================================================") ;
741 cdebug << "================================================================================" << endl ;
742 cdebug << Graph()->Name() << " IS DONE : " << theAutomaton->StateName( AutomatonState() ) << " EventQSize "
743 << EventQSize() << endl ;
744 cdebug << "================================================================================" << endl ;
746 // asv : fix for 6798 and other bugs: "sift" the event queue after execution
749 // asv : 25.10.04 : calling Editing() to indicate stop of execution
750 Graph()->GraphEditor()->Editing();
752 cdebug_out << "GraphExecutor::OutNode::CheckAllDone " << IsDone() << " this " << this << " "
753 << Graph()->Name() << " GraphAutomatonState "
754 << theAutomaton->StateName( AutomatonState() )
755 << " State " << State() << " Threads " << _Threads << " SuspendedThreads "
756 << _SuspendedThreads << " EventQSize " << EventQSize() << endl ;
759 // asv : 20.01.05 : changes involved with switching to old (HEAD) KERNEL
760 //Engines_Container_i * GraphExecutor::OutNode::SuperVisionContainer() {
761 // return _SuperVisionContainer ;
764 //const pthread_t GraphExecutor::OutNode::MainThreadId() const {
765 // return _MainThreadId ;
768 void GraphExecutor::OutNode::PThreadLock( pthread_mutex_t * aMutex , char * errmsg ) {
769 // if ( strcmp( errmsg , "EventLoop" ) && strcmp( errmsg , "EventW" ) ) {
770 // cdebug << "GraphExecutor::OutNode::PThreadLock " << pthread_self() << " " << aMutex << " "
771 // << errmsg << endl ;
773 if ( pthread_mutex_lock( aMutex ) ) {
777 // if ( strcmp( errmsg , "EventLoop" ) && strcmp( errmsg , "EventW" ) ) {
778 // cdebug << "GraphExecutor::OutNode::PThreadLocked " << pthread_self() << " " << aMutex << " "
779 // << errmsg << endl ;
783 void GraphExecutor::OutNode::PThreadUnLock( pthread_mutex_t * aMutex , char * errmsg ) {
784 // if ( strcmp( errmsg , "EventLoop" ) && strcmp( errmsg , "EventW" ) ) {
785 // cdebug << " GraphExecutor::OutNode::PThreadUnLock " << pthread_self() << " " << aMutex << " "
786 // << errmsg << endl ;
788 if ( pthread_mutex_unlock( aMutex ) ) {
794 void GraphExecutor::OutNode::PyThreadLock() {
795 // cout << " GraphExecutor::OutNode::PyThreadLock " << pthread_self() << endl ;
796 if ( pthread_mutex_lock( &_PyMutexWait ) ) {
797 perror( "GraphExecutor::OutNode::PyThreadLock" ) ;
800 theAutomaton->PyLock() ;
801 // cout << " GraphExecutor::OutNode::PyThreadLocked " << pthread_self() << endl ;
804 void GraphExecutor::OutNode::PyThreadUnLock() {
805 // cout << " GraphExecutor::OutNode::PyThreadUnLock " << pthread_self() << endl ;
806 if ( pthread_mutex_unlock( &_PyMutexWait ) ) {
807 perror( "GraphExecutor::OutNode::PyThreadUnLock" ) ;
810 theAutomaton->PyUnLock() ;
811 // cout << " GraphExecutor::OutNode::PyThreadUnLocked " << pthread_self() << endl ;
814 void GraphExecutor::OutNode::NewThread() {
815 if ( pthread_mutex_lock( &_MutexWait ) ) {
816 perror("pthread_mutex_lock _NewThread") ;
820 cdebug << "NewThread : " << _Threads << " running threads "
821 << _SuspendedThreads << " suspended threads"
823 if ( pthread_mutex_unlock( &_MutexWait ) ) {
824 perror("pthread_mutex_unlock _NewThread") ;
829 void GraphExecutor::OutNode::ExitThread( pthread_t ThreadNumber ) {
830 if ( pthread_mutex_lock( &_MutexWait ) ) {
831 perror("pthread_mutex_lock _ExitThread") ;
834 if ( ThreadNumber == 0 ) {
835 ThreadNumber = pthread_self() ;
838 cdebug << pthread_self() << " ExitThread( " << ThreadNumber << " ) " << _Threads << " running threads "
839 << _SuspendedThreads << " suspended threads"
841 theAutomaton->JoinThread( ThreadNumber ) ;
842 if ( pthread_cond_signal( &_JoinWait ) ) {
843 perror("ExitThread pthread_cond_signal ") ;
845 if ( pthread_mutex_unlock( &_MutexWait ) ) {
846 perror("pthread_mutex_unlock _ExitThread") ;
849 if ( _Threads == 0 && _SuspendedThreads == 0 ) {
852 theAutomaton->Executed() ;
856 void GraphExecutor::OutNode::JoinedWait() {
857 if ( pthread_mutex_lock( &_MutexWait ) ) {
858 perror("pthread_mutex_lock JoinedWait") ;
862 if ( pthread_cond_wait( &_JoinWait , &_MutexWait ) ) {
863 perror("JoinedWait pthread_cond_wait ") ;
866 if ( pthread_mutex_unlock( &_MutexWait ) ) {
867 perror("pthread_mutex_unlock JoinedWait") ;
872 void GraphExecutor::OutNode::SuspendThread() {
873 if ( pthread_mutex_lock( &_MutexWait ) ) {
874 perror("pthread_mutex_lock _SuspendThread") ;
877 _SuspendedThreads += 1 ;
878 cdebug << "SuspendThread : " << _Threads << " running threads "
879 << _SuspendedThreads << " suspended threads"
881 if ( pthread_mutex_unlock( &_MutexWait ) ) {
882 perror("pthread_mutex_unlock _SuspendThread") ;
885 if ( IsSuspended() ) {
886 PushEvent( NULL , GraphExecutor::SuspendEvent , GraphExecutor::SuspendedState ) ;
889 void GraphExecutor::OutNode::ResumeThread() {
890 if ( pthread_mutex_lock( &_MutexWait ) ) {
891 perror("pthread_mutex_lock _ResumeThread") ;
894 _SuspendedThreads -= 1 ;
895 cdebug << "ResumeThread : " << _Threads << " running threads "
896 << _SuspendedThreads << " suspended threads"
898 if ( pthread_mutex_unlock( &_MutexWait ) ) {
899 perror("pthread_mutex_unlock _ResumeThread") ;
904 long GraphExecutor::OutNode::Thread( const char * aNodeName ) {
906 GraphExecutor::InNode *anInNode = (GraphExecutor::InNode *) Graph()->GetGraphNode( aNodeName )->GetInNode() ;
908 RetVal = anInNode->ThreadNo() ;
913 SUPERV::GraphEvent GraphExecutor::OutNode::AutomatonGraphEvent(GraphExecutor::NodeEvent anEvent ) {
914 SUPERV::GraphEvent aGraphEvent ;
916 case GraphExecutor::UndefinedEvent : {
917 aGraphEvent = SUPERV::UndefinedEvent ;
920 case GraphExecutor::NewThreadEvent : {
921 aGraphEvent = SUPERV::NewThreadEvent ;
924 case GraphExecutor::SuspendEvent : {
925 aGraphEvent = SUPERV::SuspendEvent ;
928 case GraphExecutor::ResumeEvent : {
929 aGraphEvent = SUPERV::ResumeEvent ;
932 case GraphExecutor::KillEvent : {
933 aGraphEvent = SUPERV::KillEvent ;
936 case GraphExecutor::StopEvent : {
937 aGraphEvent = SUPERV::StopEvent ;
940 case GraphExecutor::ExecuteEvent : {
941 aGraphEvent = SUPERV::RunningEvent ;
944 case GraphExecutor::SuccessEvent : {
945 aGraphEvent = SUPERV::DoneEvent ;
948 case GraphExecutor::ErrorEvent : {
949 aGraphEvent = SUPERV::ErroredEvent ;
952 case GraphExecutor::NoDataReadyEvent : {
953 aGraphEvent = SUPERV::WaitingEvent ;
956 case GraphExecutor::SomeDataReadyEvent : {
957 aGraphEvent = SUPERV::WaitingEvent ;
960 case GraphExecutor::NotAllDataReadyEvent : {
961 aGraphEvent = SUPERV::WaitingEvent ;
964 case GraphExecutor::AllDataReadyEvent : {
965 aGraphEvent = SUPERV::ReadyEvent ;
968 case GraphExecutor::ReadyEvent : {
969 aGraphEvent = SUPERV::ReadyEvent ;
972 case GraphExecutor::SuspendedReadyEvent : {
973 aGraphEvent = SUPERV::SuspendEvent ;
976 case GraphExecutor::ResumedReadyEvent : {
977 aGraphEvent = SUPERV::ResumeEvent ;
980 case GraphExecutor::KilledReadyEvent : {
981 aGraphEvent = SUPERV::KillEvent ;
984 case GraphExecutor::StoppedReadyEvent : {
985 aGraphEvent = SUPERV::StopEvent ;
988 case GraphExecutor::ExecutingEvent : {
989 aGraphEvent = SUPERV::RunningEvent ;
992 case GraphExecutor::SuspendedExecutingEvent : {
993 aGraphEvent = SUPERV::SuspendEvent ;
996 case GraphExecutor::ResumedExecutingEvent : {
997 aGraphEvent = SUPERV::ResumeEvent ;
1000 case GraphExecutor::KilledExecutingEvent : {
1001 aGraphEvent = SUPERV::KillEvent ;
1004 case GraphExecutor::StoppedExecutingEvent : {
1005 aGraphEvent = SUPERV::StopEvent ;
1008 case GraphExecutor::SuccessedExecutingEvent : {
1009 aGraphEvent = SUPERV::DoneEvent ;
1012 case GraphExecutor::ErroredExecutingEvent : {
1013 aGraphEvent = SUPERV:: ErroredEvent;
1016 case GraphExecutor::SuspendedSuccessedEvent : {
1017 aGraphEvent = SUPERV::SuspendEvent ;
1020 case GraphExecutor::SuspendedErroredEvent : {
1021 aGraphEvent = SUPERV::SuspendEvent ;
1024 case GraphExecutor::ResumedSuccessedEvent : {
1025 aGraphEvent = SUPERV::ResumeEvent ;
1028 case GraphExecutor::ResumedErroredEvent : {
1029 aGraphEvent = SUPERV::ResumeEvent ;
1032 case GraphExecutor::KilledEvent : {
1033 aGraphEvent = SUPERV::KillEvent ;
1036 case GraphExecutor::StoppedEvent : {
1037 aGraphEvent = SUPERV::StopEvent ;
1040 case GraphExecutor::EndExecuteEvent : {
1041 aGraphEvent = SUPERV::DoneEvent ;
1045 cdebug << " GraphExecutor::OutNode::AutomatonGraphEvent Error Undefined Event : "
1046 << anEvent << endl ;
1047 aGraphEvent = SUPERV::UndefinedEvent ;
1050 return aGraphEvent ;
1053 SUPERV::GraphState GraphExecutor::OutNode::AutomatonGraphState(GraphExecutor::AutomatonState aState ) {
1054 SUPERV::GraphState aGraphState ;
1056 case GraphExecutor::UnKnownState : {
1057 aGraphState = SUPERV::UndefinedState ;
1060 case GraphExecutor::DataUndefState : {
1061 aGraphState = SUPERV::UndefinedState ;
1064 case GraphExecutor::DataWaitingState : {
1065 aGraphState = SUPERV::WaitingState ;
1068 case GraphExecutor::DataReadyState : {
1069 aGraphState = SUPERV::ReadyState ;
1072 case GraphExecutor::SuspendedReadyState : {
1073 aGraphState = SUPERV::SuspendReadyState ;
1076 case GraphExecutor::ResumedReadyState : {
1077 aGraphState = SUPERV::ReadyState ;
1080 case GraphExecutor::KilledReadyState : {
1081 aGraphState = SUPERV::KillState ;
1084 case GraphExecutor::StoppedReadyState : {
1085 aGraphState = SUPERV::StopState ;
1088 case GraphExecutor::ExecutingState : {
1089 aGraphState = SUPERV::RunningState ;
1092 case GraphExecutor::SuspendedExecutingState : {
1093 aGraphState = SUPERV::SuspendState ;
1096 case GraphExecutor::ResumedExecutingState : {
1097 aGraphState = SUPERV::RunningState ;
1100 case GraphExecutor::KilledExecutingState : {
1101 aGraphState = SUPERV::KillState ;
1104 case GraphExecutor::StoppedExecutingState : {
1105 aGraphState = SUPERV::StopState ;
1108 case GraphExecutor::SuccessedExecutingState : {
1109 aGraphState = SUPERV::DoneState ;
1112 case GraphExecutor::ErroredExecutingState : {
1113 aGraphState = SUPERV::ErrorState ;
1116 case GraphExecutor::SuspendedSuccessedState : {
1117 aGraphState = SUPERV::SuspendDoneState ;
1120 case GraphExecutor::SuspendedErroredState : {
1121 aGraphState = SUPERV::SuspendErroredState ;
1124 case GraphExecutor::ResumedSuccessedState : {
1125 aGraphState = SUPERV::DoneState ;
1128 case GraphExecutor::ResumedErroredState : {
1129 aGraphState = SUPERV::ErrorState ;
1132 case GraphExecutor::KilledSuccessedState : {
1133 aGraphState = SUPERV::KillState ;
1136 case GraphExecutor::KilledErroredState : {
1137 aGraphState = SUPERV::KillState ;
1140 case GraphExecutor::StoppedSuccessedState : {
1141 aGraphState = SUPERV::StopState ;
1144 case GraphExecutor::StoppedErroredState : {
1145 aGraphState = SUPERV::StopState ;
1148 case GraphExecutor::SuccessedState : {
1149 aGraphState = SUPERV::DoneState ;
1152 case GraphExecutor::ErroredState : {
1153 aGraphState = SUPERV::ErrorState ;
1156 case GraphExecutor::SuspendedState : {
1157 aGraphState = SUPERV::SuspendState ;
1160 case GraphExecutor::KilledState : {
1161 aGraphState = SUPERV::KillState ;
1164 case GraphExecutor::StoppedState : {
1165 aGraphState = SUPERV::StopState ;
1168 case GraphExecutor::LoadingState : {
1169 aGraphState = SUPERV::LoadingState ;
1173 cdebug << " GraphExecutor::OutNode::AutomatonGraphState Error Undefined State : "
1174 << aGraphState << endl ;
1175 aGraphState = SUPERV::UndefinedState ;
1178 return aGraphState ;
1181 int GraphExecutor::OutNode::GetListSize() {
1182 return _EventNodes.size();
1185 bool GraphExecutor::OutNode::PushEvent( GraphExecutor::InNode * aNode ,
1186 GraphExecutor::NodeEvent anEvent ,
1187 GraphExecutor::AutomatonState aState ) {
1188 // cdebug_in << "PushEvent Threads " << Threads() << " SuspendedThreads "
1189 // << SuspendedThreads() << endl ;
1190 if ( pthread_mutex_lock( &_MutexWait ) ) {
1191 perror("PushEvent pthread_mutex_lock ") ;
1194 char* aNodeName = aNode ? aNode->Name() : Graph()->Name() ;
1195 _EventNodes.push_back( aNodeName ) ;
1196 _Events.push_back( anEvent ) ;
1197 _States.push_back( aState ) ;
1199 pthread_cond_broadcast( &_EventWait );
1200 cdebug << pthread_self() << " PushEvent Threads " << Threads() << " SuspendedThreads "
1201 << SuspendedThreads() << " pthread_cond_broadcast _EventWait " << &_EventWait << endl ;
1203 // cdebug << aNode->ThreadNo() << " PushEvent " << aNode->Name() ;
1204 // cdebug << " " << aNode->Automaton()->EventName( anEvent )
1205 // << " " << aNode->Automaton()->StateName( aState )
1206 // << " ControleState "
1207 // << aNode->Automaton()->ControlStateName( aNode->ControlState() ) ;
1210 // cdebug << "PushEvent " << Graph()->Name() ;
1211 // cdebug << " " << theAutomaton->EventName( anEvent ) << " "
1212 // << theAutomaton->StateName( aState ) ;
1214 // cdebug_out << "PushEvent Threads " << Threads() << " SuspendedThreads "
1215 // << SuspendedThreads() << endl ;
1217 if ( _EventNodes.size() > 101 ) {
1218 while ( _EventNodes.size() > 31 ) {
1219 _EventNodes.pop_front() ;
1220 _Events.pop_front() ;
1221 _States.pop_front() ;
1225 if ( pthread_mutex_unlock( &_MutexWait ) ) {
1226 perror("PushEvent pthread_mutex_unlock ") ;
1232 bool GraphExecutor::OutNode::StateWait( SUPERV::GraphState aState ) {
1236 bool GraphExecutor::OutNode::Event( char ** aNodeName ,
1237 SUPERV::GraphEvent & anEvent ,
1238 SUPERV::GraphState & aState ,
1240 // asv : fixing problem of loops with large number of iterations (>5000)
1241 // experimentally was found that number of non-handled by GUI events = (number_of_nodes x 7)
1242 // or 7 events for each node - so what we want to do here is remove "old" events for nodes
1243 // "on the fly". Once again it is done in Stop(), Kill(), Done() functions.
1244 if ( _EventNodes.size() > (unsigned int)Graph()->GraphNodesSize()*7 )
1248 int SuspendedThreadsNumber ;
1249 bool cdebuginout = false ;
1250 if ( _EventNodes.size() > 0 ) {
1251 // cdebug_in << "GraphExecutor::OutNode::Event " << _EventNodes.size() << " in queue" << endl ;
1252 cdebuginout = true ;
1254 if ( pthread_mutex_lock( &_MutexWait ) ) {
1255 perror("EventLoop pthread_mutex_lock ") ;
1258 _JustStarted = false ;
1259 ThreadsNumber = Threads() ;
1260 SuspendedThreadsNumber = SuspendedThreads() ;
1261 bool RetVal = ( ThreadsNumber - SuspendedThreadsNumber) != 0 ||
1262 _EventNodes.size() > 0 ;
1263 char * NodeName = "" ;
1264 GraphExecutor::NodeEvent theEvent = GraphExecutor::UndefinedEvent ;
1265 GraphExecutor::AutomatonState theState = GraphExecutor::UnKnownState ;
1266 anEvent = SUPERV::UndefinedEvent ;
1267 aState = SUPERV::UndefinedState ;
1268 if ( ( Done() || IsKilled() || IsStopped() ) && _EventNodes.size() == 0 ) {
1269 // cdebug << "EventLoop Done()/IsKilled()/IsStopped() && _EventNodes.size() == 0" << endl ;
1272 else if ( !WithWait && _EventNodes.size() == 0 ) {
1273 anEvent = SUPERV::NoEvent ;
1274 aState = SUPERV::NoState ;
1277 else if ( RetVal ) {
1278 while ( !IsSuspended() && _EventNodes.size() == 0 ) {
1279 // cdebug << "EventLoop pthread_cond_wait _EventWait" << endl ;
1280 pthread_cond_wait( &_EventWait , &_MutexWait );
1281 // cdebug << "EventLoop pthread_cond_waited _EventWait"
1282 // << " _EventNodes.size() " << _EventNodes.size() << endl ;
1284 if ( _EventNodes.size() ) {
1285 ThreadsNumber = Threads() ;
1286 NodeName = _EventNodes.front() ;
1287 _EventNodes.pop_front() ;
1288 theEvent = _Events.front() ;
1289 anEvent = AutomatonGraphEvent( theEvent ) ;
1290 _Events.pop_front() ;
1291 theState = _States.front() ;
1292 aState = AutomatonGraphState( theState ) ;
1293 _States.pop_front() ;
1296 *aNodeName = NodeName ;
1297 if ( IsSuspended() && _EventNodes.size() == 0 ) {
1300 if ( anEvent != SUPERV::NoEvent ) {
1301 // cdebug << pthread_self() << "EventLoop "
1302 // << NodeName << " " << theAutomaton->StateName( theState )
1303 // << " _EventNodes.size() " << _EventNodes.size()
1304 // << " Threads " << Threads() << " SuspendedThreads "
1305 // << SuspendedThreads() << " RetVal " << RetVal << endl ;
1307 if ( pthread_mutex_unlock( &_MutexWait ) ) {
1308 perror("EventLoop pthread_mutex_lock ") ;
1311 if ( cdebuginout ) {
1312 // cdebug_out << "GraphExecutor::OutNode::Event " << _EventNodes.size() << " in queue"
1313 // << *aNodeName << " " << anEvent << " " << aState << endl ;
1318 bool GraphExecutor::OutNode::EventW( char ** aNodeName ,
1319 SUPERV::GraphEvent & anEvent ,
1320 SUPERV::GraphState & aState ) {
1323 aState = SUPERV::UndefinedState ;
1325 aState != SUPERV::SuspendReadyState &&
1326 aState != SUPERV::RunningState &&
1327 aState != SUPERV::SuspendDoneState &&
1328 aState != SUPERV::SuspendErroredState ) {
1329 NodeName = Graph()->Name() ;
1330 while ( sts && !strcmp( NodeName , Graph()->Name() ) ) {
1331 sts = EventWait( aNodeName , anEvent , aState ) ;
1332 NodeName = *aNodeName ;
1338 bool GraphExecutor::OutNode::EventWait( char ** aNodeName ,
1339 SUPERV::GraphEvent & anEvent ,
1340 SUPERV::GraphState & aState ) {
1341 if ( pthread_mutex_lock( &_MutexWait ) ) {
1342 perror("EventW pthread_mutex_lock ") ;
1346 int SuspendedThreadsNumber ;
1347 ThreadsNumber = Threads() ;
1348 SuspendedThreadsNumber = SuspendedThreads() ;
1349 bool RetVal = ( ThreadsNumber - SuspendedThreadsNumber) != 0 ||
1350 _EventNodes.size() > 0 ;
1351 cdebug << "--> EventW RetVal " << RetVal << endl ;
1352 char * NodeName = "" ;
1353 GraphExecutor::NodeEvent theEvent = GraphExecutor::UndefinedEvent ;
1354 GraphExecutor::AutomatonState theState = GraphExecutor::UnKnownState ;
1355 anEvent = SUPERV::UndefinedEvent ;
1356 aState = SUPERV::UndefinedState ;
1357 if ( IsDone() && _EventNodes.size() == 0 ) {
1358 cdebug << "EventW IsDone() && _EventNodes.size() == 0" << endl ;
1361 else if ( RetVal ) {
1362 GraphExecutor::InNode * aNode = NULL ;
1363 while ( aNode == NULL && RetVal ) {
1364 NodeName = _EventNodes.front() ;
1365 theEvent = _Events.front() ;
1366 anEvent = AutomatonGraphEvent( theEvent ) ;
1367 theState = _States.front() ;
1368 aState = AutomatonGraphState( theState ) ;
1370 if ( _JustStarted ) {
1371 _JustStarted = false ;
1374 _EventNodes.pop_front() ;
1375 _Events.pop_front() ;
1376 _States.pop_front() ;
1379 aNode = ((GraphExecutor::InNode *) Graph()->GetGraphNode( NodeName )->GetInNode()) ;
1380 cdebug << "EventW Previous Node " << NodeName << " ThreadsNumber "
1382 << " _EventNodes.size() " << _EventNodes.size() << " "
1383 << theAutomaton->StateName( theState )
1384 << " Threads " << Threads() << " SuspendedThreads "
1385 << SuspendedThreads() << endl ;
1388 else if ( IsDone() && _EventNodes.size() == 0 ) {
1389 cdebug << "EventW IsDone() && _EventNodes.size() == 0" << endl ;
1393 cdebug << "EventW Not InNode " << NodeName
1394 << " _EventNodes.size() " << _EventNodes.size() << endl ;
1395 while ( _EventNodes.size() == 0 ) {
1396 pthread_cond_wait( &_EventWait , &_MutexWait );
1398 cdebug << "EventW pthread_cond_waited Not InNode " << NodeName
1399 << " _EventNodes.size() " << _EventNodes.size() << endl ;
1404 if ( aState == SUPERV::SuspendState ||
1405 aState == SUPERV::SuspendReadyState ||
1406 aState == SUPERV::SuspendDoneState ||
1407 aState == SUPERV::SuspendErroredState ) {
1408 aNode->ControlState( SUPERV::ToSuspendState ) ;
1409 if ( aNode->IsSuspended() ) {
1410 if ( pthread_mutex_unlock( &_MutexWait ) ) {
1411 perror("EventW pthread_mutex_lock ") ;
1414 cdebug << "EventW " << aNode->Name() << " ResumeAction" << endl ;
1415 aNode->ResumeAction( GraphExecutor::ToResumeEvent ) ;
1416 cdebug << "EventW " << aNode->Name() << " ResumedAction" << endl ;
1417 if ( pthread_mutex_lock( &_MutexWait ) ) {
1418 perror("EventW pthread_mutex_lock ") ;
1423 cdebug << "EventW inconsistent SuspendState" << endl ;
1428 if ( aNode->IsDone() ) {
1432 cdebug << "EventW NOT SuspendedState _EventNodes.size() "
1433 << _EventNodes.size() << endl ;
1438 cdebug << "EventW " << aNode->Name() << " pthread_cond_wait" << endl ;
1439 while ( _EventNodes.size() == 0 ) {
1440 pthread_cond_wait( &_EventWait , &_MutexWait );
1442 ThreadsNumber = Threads() ;
1443 NodeName = _EventNodes.front() ;
1444 theEvent = _Events.front() ;
1445 anEvent = AutomatonGraphEvent( theEvent ) ;
1446 theState = _States.front() ;
1447 aState = AutomatonGraphState( theState ) ;
1451 *aNodeName = NodeName ;
1452 cdebug << "<-- EventW RetVal " << RetVal << " " << NodeName
1453 << " Threads " << Threads() << " SuspendedThreads "
1454 << SuspendedThreads()
1455 << " _EventNodes.size() " << _EventNodes.size()
1456 << " " << theAutomaton->EventName( theEvent ) << " "
1457 << theAutomaton->StateName( theState ) << endl ;
1458 if ( pthread_mutex_unlock( &_MutexWait ) ) {
1459 perror("EventW pthread_mutex_lock ") ;
1464 long GraphExecutor::OutNode::EventQSize() {
1465 return _EventNodes.size() ;
1468 void GraphExecutor::OutNode::EventList() {
1469 if ( pthread_mutex_lock( &_MutexWait ) ) {
1470 perror("EventList pthread_mutex_lock ") ;
1473 list< char * >::iterator itEventNodes = _EventNodes.begin() ;
1474 list< GraphExecutor::NodeEvent >::iterator itEvents = _Events.begin() ;
1475 list< GraphExecutor::AutomatonState >::iterator itStates = _States.begin() ;
1476 while ( itEventNodes != _EventNodes.end() ) {
1477 cdebug << pthread_self() << "EVENTSTACK "
1478 << *itEventNodes << " " << *itEvents << " "
1479 << theAutomaton->StateName( *itStates )
1480 << " Threads " << Threads() << " SuspendedThreads " << SuspendedThreads() << endl ;
1485 if ( pthread_mutex_unlock( &_MutexWait ) ) {
1486 perror("EventList pthread_mutex_lock ") ;
1491 void GraphExecutor::OutNode::SendSomeDataReady( const char * aNodeName ) {
1492 cdebug_in << "GraphExecutor::OutNode::SendSomeDataReady " << aNodeName << "->SendSomeDataReady( "
1493 << Graph()->Name() << " )" << endl;
1495 sts = ((GraphExecutor::InNode * ) Graph()->GetChangeGraphNode( aNodeName )->GetInNode())->SendSomeDataReady( Graph()->Name() ) ;
1496 cdebug_out << "GraphExecutor::OutNode::SendSomeDataReady sts " << sts << endl ;
1499 void GraphExecutor::OutNode::State(GraphExecutor::AutomatonState aState ) {
1500 // cdebug << "GraphExecutor::OutNode::State " << Graph()->Name() << " "
1501 // << theAutomaton->StateName( AutomatonGraphState( _State ) ) << " ---> "
1502 // << theAutomaton->StateName( AutomatonGraphState( aState ) ) << endl ;
1506 SUPERV::GraphState GraphExecutor::OutNode::State() {
1507 // cdebug_in << "GraphExecutor::OutNode::State" << endl;
1508 // cdebug_out << "GraphExecutor::OutNode::State" << endl ;
1509 // cdebug << "GraphExecutor::OutNode::State GraphState "
1510 // << theAutomaton->StateName( AutomatonGraphState( _State ) ) << endl ;
1511 return AutomatonGraphState( _State ) ;
1514 SUPERV::GraphState GraphExecutor::OutNode::State( const char * NodeName ) {
1515 // cdebug_in << "GraphExecutor::OutNode::State " << NodeName << endl;
1516 GraphExecutor::AutomatonState aret = GraphExecutor::UnKnownState ;
1517 const GraphBase::ComputingNode * aCNode = Graph()->GetGraphNode( NodeName ) ;
1519 GraphExecutor::InNode *anInNode = (GraphExecutor::InNode *)aCNode->GetInNode() ;
1521 if ( anInNode->IsLoading() )
1522 aret = GraphExecutor::LoadingState;
1524 aret = anInNode->State() ;
1525 // cdebug << "GraphExecutor::OutNode::State( " << NodeName << " ) "
1526 // << theAutomaton->StateName( AutomatonGraphState( aret ) ) << endl ;
1529 // cdebug_out << "GraphExecutor::OutNode::State" << endl ;
1530 return AutomatonGraphState( aret ) ;
1533 SUPERV::GraphState GraphExecutor::OutNode::State( const char * NodeName ,
1534 const char * ServiceParameterName ) {
1535 // cdebug_in << "GraphExecutor::OutNode::State " << NodeName << " "
1536 // << ServiceParameterName<< endl;
1537 SUPERV::GraphState aret = Graph()->PortState( NodeName , ServiceParameterName ) ;
1538 // cdebug_out << "GraphExecutor::OutNode::State" << endl ;
1542 GraphExecutor::AutomatonState GraphExecutor::OutNode::AutomatonState() {
1543 // cdebug_in << "GraphExecutor::OutNode::AutomatonState" << endl;
1544 // cdebug_out << "GraphExecutor::OutNode::AutomatonState" << endl ;
1548 GraphExecutor::AutomatonState GraphExecutor::OutNode::AutomatonState( const char * NodeName ) {
1549 // cdebug_in << "GraphExecutor::OutNode::AutomatonState " << NodeName << endl;
1550 GraphExecutor::AutomatonState aret = GraphExecutor::UnKnownState ;
1551 const GraphBase::ComputingNode * aNode = Graph()->GetGraphNode( NodeName ) ;
1553 GraphExecutor::InNode *anInNode = (GraphExecutor::InNode *) aNode->GetInNode() ;
1555 aret = anInNode->State() ;
1558 // cdebug_out << "GraphExecutor::OutNode::AutomatonState" << endl ;
1562 SUPERV::ControlState GraphExecutor::OutNode::ControlState() {
1563 // cdebug_in << "GraphExecutor::OutNode::ControlState" << endl;
1564 // cdebug_out << "GraphExecutor::OutNode::ControlState" << endl ;
1565 return _ControlState ;
1568 SUPERV::ControlState GraphExecutor::OutNode::ControlState( const char * NodeName ) {
1569 // cdebug_in << "GraphExecutor::OutNode::ControlState " << NodeName << endl;
1570 SUPERV::ControlState aret = SUPERV::VoidState ;
1571 const GraphBase::ComputingNode * aNode = Graph()->GetGraphNode( NodeName ) ;
1573 GraphExecutor::InNode *anInNode = (GraphExecutor::InNode *) aNode->GetInNode() ;
1575 aret = anInNode->ControlState() ;
1578 // cdebug_out << "GraphExecutor::OutNode::ControlState" << endl ;
1582 void GraphExecutor::OutNode::ControlClear() {
1583 // cdebug_in << "GraphExecutor::OutNode::ControlClear" << endl;
1584 // cdebug_out << "GraphExecutor::OutNode::ControlClear" << endl ;
1585 _ControlState = SUPERV::VoidState;
1588 void GraphExecutor::OutNode::ControlClear( const char * NodeName ) {
1589 // cdebug_in << "GraphExecutor::OutNode::ControlClear " << NodeName << endl;
1590 const GraphBase::ComputingNode * aNode = Graph()->GetGraphNode( NodeName ) ;
1592 GraphExecutor::InNode *anInNode = (GraphExecutor::InNode *) aNode->GetInNode() ;
1594 anInNode->ControlClear() ;
1597 // cdebug_out << "GraphExecutor::OutNode::ControlClear" << endl ;
1600 bool GraphExecutor::OutNode::IsWaiting() {
1601 // cdebug_in << "GraphExecutor::OutNode::IsWaiting" << endl;
1602 // cdebug_out << "GraphExecutor::OutNode::IsWaiting" << endl ;
1606 bool GraphExecutor::OutNode::IsReady() {
1607 // cdebug_in << "GraphExecutor::OutNode::IsReady" << endl;
1608 // cdebug_out << "GraphExecutor::OutNode::IsReady" << endl ;
1612 bool GraphExecutor::OutNode::IsRunning() {
1613 // cdebug_in << "GraphExecutor::OutNode::IsRunning" << endl;
1614 // cdebug_out << "GraphExecutor::OutNode::IsRunning" << endl ;
1618 bool GraphExecutor::OutNode::IsDone() {
1619 // cdebug_in << "GraphExecutor::OutNode::IsDone" << endl;
1620 // cdebug_out << "GraphExecutor::OutNode::IsDone" << endl ;
1621 return ( Done() || IsKilled() || IsStopped() ) ;
1624 bool GraphExecutor::OutNode::IsSuspended() {
1625 // cdebug_in << "GraphExecutor::OutNode::IsSuspended" << endl;
1627 // if ( _SuspendedThreads == _Threads && _Threads != 0 ) {
1628 if ( AutomatonGraphState( _State ) == SUPERV::SuspendState ) {
1631 // cdebug_out << "GraphExecutor::OutNode::IsSuspended" << endl ;
1635 bool GraphExecutor::OutNode::IsKilled() {
1636 // cdebug_in << "GraphExecutor::OutNode::IsKilled" << endl;
1638 if ( AutomatonGraphState( _State ) == SUPERV::KillState ) {
1641 // cdebug_out << "GraphExecutor::OutNode::IsKilled" << endl ;
1645 bool GraphExecutor::OutNode::IsStopped() {
1646 // cdebug_in << "GraphExecutor::OutNode::IsStopped" << endl;
1648 if ( AutomatonGraphState( _State ) == SUPERV::StopState ) {
1651 // cdebug_out << "GraphExecutor::OutNode::IsStopped" << endl ;
1655 bool GraphExecutor::OutNode::IsWaiting( const char * NodeName ) {
1657 // cdebug_in << "GraphExecutor::OutNode::IsWaiting " << NodeName << endl;
1658 GraphExecutor::InNode *anInNode = (GraphExecutor::InNode *) Graph()->GetGraphNode( NodeName )->GetInNode() ;
1660 aret = anInNode->IsWaiting() ;
1662 // cdebug_out << "GraphExecutor::OutNode::IsWaiting" << endl ;
1666 bool GraphExecutor::OutNode::IsReady( const char * NodeName ) {
1668 // cdebug_in << "GraphExecutor::OutNode::IsReady " << NodeName << endl;
1669 GraphExecutor::InNode *anInNode = (GraphExecutor::InNode *) Graph()->GetGraphNode( NodeName )->GetInNode() ;
1671 aret = anInNode->IsReady() ;
1673 // cdebug_out << "GraphExecutor::OutNode::IsReady" << endl ;
1677 bool GraphExecutor::OutNode::IsRunning( const char * NodeName ) {
1679 // cdebug_in << "GraphExecutor::OutNode::IsRunning " << NodeName << endl;
1680 GraphExecutor::InNode *anInNode = (GraphExecutor::InNode *) Graph()->GetGraphNode( NodeName )->GetInNode() ;
1682 aret = anInNode->IsRunning() ;
1684 // cdebug_out << "GraphExecutor::OutNode::IsRunning" << endl ;
1688 bool GraphExecutor::OutNode::IsDone( const char * NodeName ) {
1690 // cdebug_in << "GraphExecutor::OutNode::IsDone " << NodeName << endl;
1691 GraphExecutor::InNode *anInNode = (GraphExecutor::InNode *) Graph()->GetGraphNode( NodeName )->GetInNode() ;
1693 aret = anInNode->IsDone() ;
1695 // cdebug_out << "GraphExecutor::OutNode::IsDone" << endl ;
1699 bool GraphExecutor::OutNode::IsSuspended( const char * NodeName ) {
1701 // cdebug_in << "GraphExecutor::OutNode::IsSuspended " << NodeName << endl;
1702 GraphExecutor::InNode *anInNode = (GraphExecutor::InNode *) Graph()->GetGraphNode( NodeName )->GetInNode() ;
1704 aret = anInNode->IsSuspended() ;
1706 // cdebug_out << "GraphExecutor::OutNode::IsSuspended" << endl ;
1710 bool GraphExecutor::OutNode::IsDone( const char * NodeName ,
1711 const char * ServiceParameterName ) {
1712 // cdebug_in << "GraphExecutor::OutNode::IsDone " << NodeName << " "
1713 // << ServiceParameterName<< endl;
1714 bool aret = Graph()->PortDone( NodeName , ServiceParameterName ) ;
1715 // cdebug_out << "GraphExecutor::OutNode::IsDone" << endl ;
1719 bool GraphExecutor::OutNode::ContainerKill() {
1720 bool RetVal = true ;
1721 cdebug_in << "GraphExecutor::OutNode::ContainerKill" << endl;
1722 _ControlState = SUPERV::ToSuspendState ;
1724 for ( i = 0 ; i < Graph()->GraphNodesSize() ; i++ ) {
1725 GraphExecutor::InNode * aNode = (GraphExecutor::InNode * ) Graph()->GraphNodes( i )->GetInNode() ;
1726 bool sts = aNode->ContainerKill() ;
1727 if ( sts && aNode->IsKilled() ) {
1728 cdebug << aNode->Name() << " killed" << endl ;
1730 else if ( aNode->IsWaiting() || aNode->IsDone() ) {
1731 cdebug << aNode->Name() << " not killed : "
1732 << theAutomaton->StateName( aNode->State() ) << endl ;
1735 cdebug << aNode->Name() << " cannot be killed : "
1736 << theAutomaton->StateName( aNode->State() ) << endl ;
1740 if ( !RetVal || Threads() != 0 ) {
1741 for ( i = 0 ; i < Graph()->GraphNodesSize() ; i++ ) {
1742 GraphExecutor::InNode * aNode = (GraphExecutor::InNode * ) Graph()->GraphNodes( i )->GetInNode() ;
1743 if ( !aNode->IsKilled() && !aNode->IsWaiting() && !aNode->IsDone() ) {
1744 aNode->KilledAction() ;
1749 State( GraphExecutor::KilledState ) ;
1750 cdebug_out << "GraphExecutor::OutNode::ContainerKill" << endl ;
1754 bool GraphExecutor::OutNode::Suspend() {
1756 cdebug_in << "GraphExecutor::OutNode::Suspend" << endl;
1757 // _ControlState = SUPERV::ToSuspendState ;
1759 for ( i = 0 ; i < Graph()->GraphNodesSize() ; i++ ) {
1760 GraphExecutor::InNode * aNode = (GraphExecutor::InNode * ) Graph()->GraphNodes( i )->GetInNode() ;
1761 bool sts = aNode->Suspend() ;
1762 if ( sts && aNode->IsSuspended() ) {
1764 cdebug << aNode->Name() << " Suspended" << endl ;
1766 else if ( aNode->IsWaiting() || aNode->IsReady() ) {
1768 cdebug << aNode->Name() << " will be Suspended" << endl ;
1770 else if ( aNode->IsDone() ) {
1771 cdebug << aNode->Name() << " not Suspended : "
1772 << theAutomaton->StateName( aNode->State() ) << endl ;
1776 cdebug << aNode->Name() << " cannot be Suspended : "
1777 << theAutomaton->StateName( aNode->State() ) << endl ;
1781 State( GraphExecutor::SuspendedState ) ;
1782 MESSAGE("================================================================================") ;
1783 MESSAGE( Graph()->Name() << " IS SUSPENDED" ) ;
1784 MESSAGE("================================================================================") ;
1787 MESSAGE("================================================================================") ;
1788 MESSAGE( Graph()->Name() << " IS NOT SUSPENDED" ) ;
1789 MESSAGE("================================================================================") ;
1791 for ( i = 0 ; i < Graph()->GraphNodesSize() ; i++ ) {
1792 GraphExecutor::InNode * aNode = (GraphExecutor::InNode * ) Graph()->GraphNodes( i )->GetInNode() ;
1793 MESSAGE(aNode->Name() << " " << theAutomaton->StateName( aNode->State() ) ) ;
1794 cdebug << aNode->Name() << " " << theAutomaton->StateName( aNode->State() ) << endl ;
1796 cdebug_out << "GraphExecutor::OutNode::Suspend " << theAutomaton->StateName( State() )
1797 << " EventQSize " << EventQSize() << endl ;
1801 bool GraphExecutor::OutNode::Resume() {
1803 cdebug_in << "GraphExecutor::OutNode::Resume "
1804 << theAutomaton->StateName( State() ) << endl;
1805 if ( IsSuspended() ) {
1806 State( GraphExecutor::ExecutingState ) ;
1808 for ( i = 0 ; i < Graph()->GraphNodesSize() ; i++ ) {
1809 GraphExecutor::InNode * aNode = (GraphExecutor::InNode * ) Graph()->GraphNodes( i )->GetInNode() ;
1810 aNode->ControlState( SUPERV::VoidState ) ;
1811 if ( aNode->IsSuspended() ) {
1812 cdebug << aNode->Name() << "->Resume " << theAutomaton->StateName( aNode->State() )
1814 if ( aNode->Resume() ) {
1815 cdebug << aNode->Name() << " Resumed " << theAutomaton->StateName( aNode->State() )
1820 cdebug << aNode->Name() << " Resume failed"
1821 << theAutomaton->StateName( aNode->State() ) << endl ;
1825 cdebug << aNode->Name() << " " << theAutomaton->StateName( aNode->State() )
1831 cdebug << Graph()->Name() << " not suspended " << theAutomaton->StateName( State() ) << endl ;
1834 MESSAGE("================================================================================") ;
1835 MESSAGE( Graph()->Name() << " IS RESUMED" ) ;
1836 MESSAGE("================================================================================") ;
1839 MESSAGE("================================================================================") ;
1840 MESSAGE( Graph()->Name() << " IS NOT RESUMED" ) ;
1841 MESSAGE("================================================================================") ;
1844 for ( i = 0 ; i < Graph()->GraphNodesSize() ; i++ ) {
1845 GraphExecutor::InNode * aNode = (GraphExecutor::InNode * ) Graph()->GraphNodes( i )->GetInNode() ;
1846 MESSAGE(aNode->Name() << " " << theAutomaton->StateName( aNode->State() ) ) ;
1847 cdebug << aNode->Name() << " " << theAutomaton->StateName( aNode->State() ) << endl ;
1849 cdebug_out << "GraphExecutor::OutNode::Resume" << theAutomaton->StateName( State() ) << " " << RetVal
1850 << " EventQSize " << EventQSize() << endl ;
1854 bool GraphExecutor::OutNode::Kill() {
1855 bool RetVal = false ;
1856 cdebug_in << "GraphExecutor::OutNode::Kill"
1857 << " EventQSize " << EventQSize() << endl;
1858 _ControlState = SUPERV::ToSuspendState ;
1860 for ( i = 0 ; i < Graph()->GraphNodesSize() ; i++ ) {
1861 GraphExecutor::InNode * aNode = (GraphExecutor::InNode * ) Graph()->GraphNodes( i )->GetInNode() ;
1862 bool sts = aNode->Kill() ;
1863 if ( sts && Threads() != 0 ) {
1864 if ( !aNode->IsKilled() ) {
1865 cdebug << aNode->Name() << " not killed : "
1866 << theAutomaton->StateName( aNode->State() ) << " " << aNode->Name() << "->"
1867 << "KilledAction()" << endl ;
1868 MESSAGE( aNode->Name() << " not killed : KilledAction()" ) ;
1869 aNode->KilledAction() ;
1871 if ( aNode->IsKilled() ) {
1872 cdebug << aNode->Name() << " killed" << endl ;
1876 else if ( aNode->IsWaiting() || aNode->IsDone() ) {
1877 cdebug << aNode->Name() << " not killed : "
1878 << theAutomaton->StateName( aNode->State() ) << endl ;
1881 cdebug << aNode->Name() << " cannot be killed : "
1882 << theAutomaton->StateName( aNode->State() ) << endl ;
1886 State( GraphExecutor::KilledState ) ;
1887 MESSAGE("================================================================================") ;
1888 MESSAGE( Graph()->Name() << " IS KILLED" << theAutomaton->StateName( AutomatonState() ) << " EventQSize "
1890 MESSAGE("================================================================================") ;
1893 MESSAGE("================================================================================") ;
1894 MESSAGE( Graph()->Name() << " IS NOT KILLED" ) ;
1895 MESSAGE("================================================================================") ;
1897 for ( i = 0 ; i < Graph()->GraphNodesSize() ; i++ ) {
1898 GraphExecutor::InNode * aNode = (GraphExecutor::InNode * ) Graph()->GraphNodes( i )->GetInNode() ;
1899 MESSAGE(aNode->Name() << " " << theAutomaton->StateName( aNode->State() ) ) ;
1900 cdebug << aNode->Name() << " " << theAutomaton->StateName( aNode->State() ) << endl ;
1902 cdebug_out << "GraphExecutor::OutNode::Kill " << RetVal
1903 << " Threads " << _Threads << " SuspendedThreads " << _SuspendedThreads
1904 << " EventQSize " << EventQSize() << endl ;
1906 // remove "extra" events from the event queue
1909 // asv : 25.10.04 : calling Editing() to indicate stop of execution
1910 Graph()->GraphEditor()->Editing();
1915 bool GraphExecutor::OutNode::Stop() {
1916 bool RetVal = false ;
1917 cdebug_in << "GraphExecutor::OutNode::Stop" << endl;
1919 cdebug_out << "GraphExecutor::OutNode::Stop" << endl ;
1921 MESSAGE("================================================================================") ;
1922 MESSAGE( Graph()->Name() << " IS STOPPED" ) ;
1923 MESSAGE("================================================================================") ;
1928 bool GraphExecutor::OutNode::ReadyWait() {
1929 cdebug_in << "GraphExecutor::OutNode::ReadyWait" << endl;
1931 if ( pthread_mutex_lock( &_MutexWait ) ) {
1932 perror("pthread_mutex_lock _ReadyWait") ;
1938 pthread_cond_wait( &_EventWait , &_MutexWait );
1941 if ( pthread_mutex_unlock( &_MutexWait ) ) {
1942 perror("pthread_mutex_lock _ReadyWait") ;
1945 cdebug_out << "GraphExecutor::OutNode::ReadyWait" << endl ;
1949 bool GraphExecutor::OutNode::RunningWait() {
1950 cdebug_in << "GraphExecutor::OutNode::RunningWait" << endl;
1952 if ( pthread_mutex_lock( &_MutexWait ) ) {
1953 perror("pthread_mutex_lock _RunningWait") ;
1956 aret = IsRunning() ;
1958 cdebug << "RunningWait pthread_cond_wait _EventWait" << endl;
1959 pthread_cond_wait( &_EventWait , &_MutexWait );
1960 aret = IsRunning() ;
1961 cdebug << "RunningWait pthread_cond_waited _EventWait " << aret << endl;
1963 if ( pthread_mutex_unlock( &_MutexWait ) ) {
1964 perror("pthread_mutex_lock _RunningWait") ;
1967 cdebug_out << "GraphExecutor::OutNode::RunningWait " << aret << endl ;
1971 bool GraphExecutor::OutNode::DoneWait() {
1972 cdebug_in << pthread_self() << " GraphExecutor::DoneWait " << this << " " << Graph()->Name() << endl;
1974 if ( pthread_mutex_lock( &_MutexWait ) ) {
1975 perror("pthread_mutex_lock _DoneWait") ;
1979 while ( !aret && !IsSuspended() && IsRunning() ) {
1980 cdebug << pthread_self() << " GraphExecutor::DoneWait " << this << " " << Graph()->Name()
1981 << " DoneWait pthread_cond_wait _EventWait " << &_EventWait << endl;
1982 pthread_cond_wait( &_EventWait , &_MutexWait );
1984 cdebug << pthread_self() << " GraphExecutor::DoneWait " << this << " " << Graph()->Name()
1985 << " DoneWait pthread_cond_waited _EventWaited " << &_EventWait << " : "<< aret << endl;
1987 if ( pthread_mutex_unlock( &_MutexWait ) ) {
1988 perror("pthread_mutex_lock _DoneWait") ;
1991 cdebug_out << pthread_self() << " GraphExecutor::DoneWait " << this << " " << Graph()->Name()
1992 << " " << State() << " : " << aret << endl ;
1996 bool GraphExecutor::OutNode::SuspendedWait() {
1997 cdebug_in << "GraphExecutor::OutNode::SuspendedWait" << endl;
1999 if ( pthread_mutex_lock( &_MutexWait ) ) {
2000 perror("pthread_mutex_lock _SuspendedWait") ;
2003 aret = IsSuspended() ;
2004 while ( !aret && !IsDone() ) {
2005 pthread_cond_wait( &_EventWait , &_MutexWait );
2006 aret = IsSuspended() ;
2008 if ( pthread_mutex_unlock( &_MutexWait ) ) {
2009 perror("pthread_mutex_lock _SuspendedWait") ;
2012 cdebug_out << "GraphExecutor::OutNode::SuspendedWait" << endl ;
2016 bool GraphExecutor::OutNode::ReadyWait( const char * NodeName ) {
2018 cdebug_in << "GraphExecutor::OutNode::ReadyWait " << NodeName << endl;
2019 GraphExecutor::InNode *anInNode = (GraphExecutor::InNode *) Graph()->GetGraphNode( NodeName )->GetInNode() ;
2021 aret = anInNode->ReadyWait() ;
2023 cdebug_out << "GraphExecutor::OutNode::ReadyWait" << endl ;
2027 bool GraphExecutor::OutNode::RunningWait( const char * NodeName ) {
2029 cdebug_in << "GraphExecutor::OutNode::RunningWait " << NodeName << endl;
2030 GraphExecutor::InNode *anInNode = (GraphExecutor::InNode *) Graph()->GetGraphNode( NodeName )->GetInNode() ;
2032 aret = anInNode->RunningWait() ;
2034 cdebug_out << "GraphExecutor::OutNode::RunningWait" << endl ;
2038 bool GraphExecutor::OutNode::DoneWait( const char * NodeName ) {
2040 cdebug_in << "GraphExecutor::OutNode::DoneWait " << NodeName << endl;
2041 GraphExecutor::InNode *anInNode = (GraphExecutor::InNode *) Graph()->GetGraphNode( NodeName )->GetInNode() ;
2043 aret = anInNode->DoneWait() ;
2045 cdebug_out << "GraphExecutor::OutNode::DoneWait" << endl ;
2049 bool GraphExecutor::OutNode::SuspendedWait( const char * NodeName ) {
2051 cdebug_in << "GraphExecutor::OutNode::SuspendedWait " << NodeName << endl;
2052 GraphExecutor::InNode *anInNode = (GraphExecutor::InNode *) Graph()->GetGraphNode( NodeName )->GetInNode() ;
2054 aret = anInNode->SuspendedWait() ;
2056 cdebug_out << "GraphExecutor::OutNode::SuspendedWait" << endl ;
2060 long GraphExecutor::OutNode::LastLevelDone() {
2063 for ( i = 0 ; i <= Graph()->LevelMax() ; i++ ) {
2064 for ( j = 0 ; j <= Graph()->NodesNumber( i ) ; j++ ) {
2065 GraphBase::ComputingNode * aNode = Graph()->SortedNodes( i , j ) ;
2066 if ( !IsDone( aNode->Name() ) ) {
2070 if ( j != Graph()->NodesNumber( i ) + 1 )
2078 const CORBA::Any *GraphExecutor::OutNode::GetInData( const char * NodeName ,
2079 const char * ServiceParameterName ) {
2080 // cdebug_in << "GraphExecutor::OutNode::GetInData " << NodeName << " "
2081 // << ServiceParameterName << endl ;
2082 const CORBA::Any * retdata = Graph()->PortInData( NodeName , ServiceParameterName ) ;
2083 // cdebug_out << "GraphExecutor::OutNode::GetInData" << endl ;
2087 const CORBA::Any *GraphExecutor::OutNode::GetOutData( const char * NodeName ,
2088 const char * ServiceParameterName ) {
2089 // cdebug_in << "GraphExecutor::OutNode::GetOutData " << NodeName << " "
2090 // << ServiceParameterName << endl ;
2091 const CORBA::Any * retdata = Graph()->PortOutData( NodeName , ServiceParameterName ) ;
2092 // cdebug_out << "GraphExecutor::OutNode::GetOutData" << endl ;
2096 const long GraphExecutor::OutNode::CpuUsed() {
2097 return Graph()->CpuUsed() ;
2100 const long GraphExecutor::OutNode::CpuUsed( const char * aNodeName ) {
2101 GraphBase::ComputingNode * aNode = Graph()->GetChangeGraphNode( aNodeName ) ;
2103 GraphExecutor::InNode * anInNode = (GraphExecutor::InNode * ) aNode->GetInNode() ;
2105 return anInNode->CpuUsed() ;
2111 // remove equal sets "Node-Event-State" from _EventNodes/_Events/_States queues
2112 void GraphExecutor::OutNode::siftEvents() {
2113 list<char*>::reverse_iterator itNodes = _EventNodes.rbegin();
2114 list<GraphExecutor::NodeEvent>::reverse_iterator itEvents = _Events.rbegin();
2115 list<GraphExecutor::AutomatonState>::reverse_iterator itStates = _States.rbegin();
2116 list<char*> _NewEventNodes;
2117 list<GraphExecutor::NodeEvent> _NewEvents;
2118 list<GraphExecutor::AutomatonState> _NewStates;
2119 for ( ; itNodes != _EventNodes.rend() ; ++itNodes, ++itEvents, ++itStates) {
2120 //cout << "----- aNodeName ==> " << *itNodes;
2121 list<char*>::reverse_iterator itNewNodes = _NewEventNodes.rbegin();
2123 for ( ; itNewNodes != _NewEventNodes.rend() ; ++itNewNodes ) {
2124 if ( !strcmp( *itNewNodes, *itNodes ) ) {
2134 _NewEventNodes.push_back( *itNodes );
2135 _NewEvents.push_back( *itEvents );
2136 _NewStates.push_back( *itStates );
2140 _EventNodes = _NewEventNodes;
2141 _Events = _NewEvents;
2142 _States = _NewStates;