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 extern Engines_Container_i * _TheContainer ;
37 extern GraphExecutor::FiniteStateMachine * theAutomaton ;
39 // static const char *ComponentName = "SalomeSuperVisionComponent" ;
42 extern char ** _ArgV ;
44 GraphExecutor::OutNode::OutNode() {
46 _SuperVisionContainer = _TheContainer ;
47 _MainThreadId = SuperVisionContainer()->MainThreadId() ;
52 _ControlState = SUPERV::VoidState ;
53 _State = GraphExecutor::UnKnownState ;
54 _PyInitialized = false ;
55 pthread_mutex_init( &_MutexWait , NULL ) ;
56 pthread_mutex_init( &_PyMutexWait , NULL ) ;
57 if ( pthread_cond_init( &_EventWait , NULL ) ) {
58 perror("pthread_cond_init( &_EventWait , NULL )") ;
61 if ( pthread_cond_init( &_JoinWait , NULL ) ) {
62 perror("pthread_cond_init( &_JoinWait , NULL )") ;
67 GraphExecutor::OutNode::OutNode( CORBA::ORB_ptr ORB,
68 SALOME_NamingService* ptrNamingService ,
69 const char *DataFlowName ,
70 const char * DebugFileName ,
71 const SUPERV::KindOfNode aKindOfNode ) {
72 // Graph( ORB , ptrNamingService , DataFlowName , DebugFileName ) {
73 Set_prof_debug( ORB , DebugFileName ) ;
74 cdebug_in << "GraphExecutor::OutNode::OutNode(" << DataFlowName << " , " << aKindOfNode << ")" << endl;
75 if ( aKindOfNode == SUPERV::DataFlowGraph ) {
77 // _Graph = new GraphBase::Graph( ORB , ptrNamingService , DataFlowName , DebugFileName ) ;
78 _Graph = new GraphBase::Graph( ORB , ptrNamingService , DataFlowName , aKindOfNode ,
79 _prof_debug , _fdebug ) ;
81 else if ( aKindOfNode == SUPERV::DataStreamGraph ) {
82 // _StreamGraph = new GraphBase::StreamGraph( ORB , ptrNamingService , DataFlowName , DebugFileName ) ;;
83 _StreamGraph = new GraphBase::StreamGraph( ORB , ptrNamingService , DataFlowName , aKindOfNode ,
84 _prof_debug , _fdebug ) ;
85 _Graph = _StreamGraph ;
87 _SuperVisionContainer = _TheContainer ;
88 _MainThreadId = SuperVisionContainer()->MainThreadId() ;
93 _ControlState = SUPERV::VoidState ;
94 _State = GraphExecutor::UnKnownState ;
95 _PyInitialized = false ;
96 _Orb = CORBA::ORB::_duplicate( ORB ) ;
97 pthread_mutex_init( &_MutexWait , NULL ) ;
98 pthread_mutex_init( &_PyMutexWait , NULL ) ;
99 if ( pthread_cond_init( &_EventWait , NULL ) ) {
100 perror("pthread_cond_init( &_EventWait , NULL )") ;
103 if ( pthread_cond_init( &_JoinWait , NULL ) ) {
104 perror("pthread_cond_init( &_JoinWait , NULL )") ;
107 cdebug_out << "GraphExecutor::OutNode::OutNode" << endl;
110 GraphExecutor::OutNode::OutNode( CORBA::ORB_ptr ORB,
111 SALOME_NamingService* ptrNamingService ,
112 const SALOME_ModuleCatalog::Service& DataFlowService ,
113 const char *DataFlowComponentName ,
114 const char *DataFlowInterfaceName ,
115 const char *DataFlowName ,
116 const SUPERV::KindOfNode DataFlowkind ,
117 const SUPERV::SDate DataFlowFirstCreation ,
118 const SUPERV::SDate DataFlowLastModification ,
119 const char * DataFlowEditorRelease ,
120 const char * DataFlowAuthor ,
121 const char * DataFlowComputer ,
122 const char * DataFlowComment ,
123 const char * DebugFileName ) {
124 // Graph( ORB , ptrNamingService , DataFlowService , DataFlowComponentName ,
125 // DataFlowInterfaceName , DataFlowName , DataFlowkind ,
126 // DataFlowFirstCreation , DataFlowLastModification ,
127 // DataFlowEditorRelease , DataFlowAuthor ,
128 // DataFlowComputer , DataFlowComment , DebugFileName ) {
129 Set_prof_debug( ORB , DebugFileName ) ;
131 cdebug_in << "GraphExecutor::OutNode::OutNode(" << DataFlowName << " , " << DataFlowkind << ")" << endl;
132 if ( DataFlowkind == SUPERV::DataFlowGraph ) {
133 _StreamGraph = NULL ;
134 _Graph = new GraphBase::Graph( ORB , ptrNamingService , DataFlowService , DataFlowComponentName ,
135 DataFlowInterfaceName , DataFlowName , DataFlowkind ,
136 DataFlowFirstCreation , DataFlowLastModification ,
137 DataFlowEditorRelease , DataFlowAuthor ,
138 DataFlowComputer , DataFlowComment ,
139 _prof_debug , _fdebug ) ;
140 // DataFlowComputer , DataFlowComment , DebugFileName ) ;
142 else if ( DataFlowkind == SUPERV::DataStreamGraph ) {
143 _StreamGraph = new GraphBase::StreamGraph( ORB , ptrNamingService , DataFlowService , DataFlowComponentName ,
144 DataFlowInterfaceName , DataFlowName , DataFlowkind ,
145 DataFlowFirstCreation , DataFlowLastModification ,
146 DataFlowEditorRelease , DataFlowAuthor ,
147 DataFlowComputer , DataFlowComment ,
148 _prof_debug , _fdebug ) ;
149 _Graph = _StreamGraph ;
151 _SuperVisionContainer = _TheContainer ;
152 _MainThreadId = SuperVisionContainer()->MainThreadId() ;
154 _Executable = false ;
157 _ControlState = SUPERV::VoidState ;
158 _State = GraphExecutor::UnKnownState ;
159 _PyInitialized = false ;
160 _Orb = CORBA::ORB::_duplicate( ORB ) ;
161 pthread_mutex_init( &_MutexWait , NULL ) ;
162 pthread_mutex_init( &_PyMutexWait , NULL ) ;
163 if ( pthread_cond_init( &_EventWait , NULL ) ) {
164 perror("pthread_cond_init( &_EventWait , NULL )") ;
167 if ( pthread_cond_init( &_JoinWait , NULL ) ) {
168 perror("pthread_cond_init( &_JoinWait , NULL )") ;
173 GraphExecutor::OutNode::~OutNode() {
176 void GraphExecutor::OutNode::Set_prof_debug( CORBA::ORB_ptr ORB ,
177 const char * DebugFileName ) {
178 _Graph_prof_debug = 0 ;
179 if ( DebugFileName ) {
180 _fdebug = new ofstream( DebugFileName );
181 SetDebug( ORB , &_Graph_prof_debug , _fdebug ) ;
182 MESSAGE( endl << "Trace redirected to file " << DebugFileName << endl)
186 bool GraphExecutor::OutNode::LoadDataFlow(const GraphBase::SGraph * aDataFlow ) {
187 bool RetVal = false ;
188 cdebug_in << "GraphExecutor::OutNode::LoadDataFlow " << (*aDataFlow).Info.theName << endl ;
189 RetVal = LoadInfo( (*aDataFlow).Info ) ;
190 if ( Graph()->ServiceName() != NULL ) {
191 // MESSAGE( "GraphExecutor::OutNode::LoadDataFlow" );
193 RetVal = LoadNodes( (*aDataFlow).Nodes ) ;
195 RetVal = LoadLinks( (*aDataFlow).Links ) ;
198 RetVal = LoadDatas( (*aDataFlow).Datas ) ;
201 cdebug << "GraphExecutor::OutNode::LoadDataFlow LoadDatas Error."
206 cdebug << "GraphExecutor::OutNode::LoadDataFlow LoadLinks Error."
211 cdebug << "GraphExecutor::OutNode::LoadDataFlow LoadNodes Error."
216 cdebug << "GraphExecutor::OutNode::LoadDataFlow LoadInfo Error."
221 cdebug << "GraphExecutor::OutNode::LoadDataFlow ServiceName Error." << endl ;
223 cdebug_out << "GraphExecutor::OutNode::LoadDataFlow " << Graph()->Name() << " RetVal "
229 bool GraphExecutor::OutNode::LoadXml( const char* myFileName ) {
230 bool RetVal = false ;
231 GraphBase::ListOfSGraphs aListOfDataFlows ;
232 if ( Graph()->LoadXml( _Orb , myFileName , aListOfDataFlows ) ) {
233 RetVal = LoadDataFlow( aListOfDataFlows ) ;
234 // if ( aConstructor && RetVal )
235 // RetVal = Name( aDataFlow.Info.theName.c_str() ) ;
241 bool GraphExecutor::OutNode::LoadInfo(const GraphBase::SNode &aDataFlowInfo ) {
242 cdebug << "GraphExecutor::OutNode::LoadInfo _StreamGraph " << _StreamGraph << endl ;
243 // ComponentName( aDataFlowInfo.theComponentName.c_str() ) ;
244 Graph()->Name( aDataFlowInfo.theName.c_str() ) ;
245 Graph()->Kind( aDataFlowInfo.theKind ) ;
246 if ( Graph()->IsDataStreamNode() && aDataFlowInfo.theKind == SUPERV::DataStreamGraph ) {
247 StreamGraph()->SetStreamParams( aDataFlowInfo.theTimeout , aDataFlowInfo.theDataStreamTrace , aDataFlowInfo.theDeltaTime ) ;
249 Graph()->DataService( _Orb , aDataFlowInfo.theService , _prof_debug , _fdebug ) ;
250 Graph()->FirstCreation( aDataFlowInfo.theFirstCreation ) ;
251 Graph()->LastModification( aDataFlowInfo.theLastModification ) ;
252 Graph()->EditorRelease( aDataFlowInfo.theEditorRelease.c_str() ) ;
253 Graph()->Author( aDataFlowInfo.theAuthor.c_str() ) ;
254 // Graph()->Computer( aDataFlowInfo.theContainer.c_str() ) ;
255 Graph()->Comment( aDataFlowInfo.theComment.c_str() ) ;
256 // Not in OutNode/DataFlow but in InNode/DataFlow_in_an_other_DataFlow
257 // Graph()->Coordinates( aDataFlowInfo.theX , aDataFlowInfo.theY ) ;
261 bool GraphExecutor::OutNode::LoadNodes(const GraphBase::ListOfSNodes &aListOfNodes ) {
263 GraphExecutor::InNode * anInNode ;
264 cdebug << "GraphExecutor::OutNode::LoadNodes" << endl ;
266 for ( i = 0 ; i < (int ) aListOfNodes.size() ; i++ ) {
267 GraphBase::SNode aNode = aListOfNodes[ i ] ;
268 anInNode = AddNode( aNode.theService ,
269 aNode.theListOfFuncName ,
270 aNode.theListOfPythonFunctions ,
271 aNode.theComponentName.c_str() ,
272 aNode.theInterfaceName.c_str() , aNode.theName.c_str() ,
274 aNode.theFirstCreation , aNode.theLastModification ,
275 aNode.theEditorRelease.c_str() ,
276 aNode.theAuthor.c_str() , aNode.theContainer.c_str() ,
277 aNode.theComment.c_str() ,
278 aNode.theCoords.theX , aNode.theCoords.theY ) ;
283 if ( anInNode->IsOneOfInLineNodes() || anInNode->IsMacroNode() ) {
284 anInNode->GraphExecutor::InNode::InLineNode()->DefPortsOfNode(
285 _Orb , aNode.theService , anInNode->NamePtr() ,
287 _prof_debug , _fdebug ) ;
289 // GraphBase::ComputingNode * theNode = Graph()->GetChangeGraphNode( aNode.theName.c_str() ) ;
292 for ( j = 0 ; j < aNode.theListOfInDataStreams.size() ; j++ ) {
293 GraphBase::InPort * anInPort ;
294 anInPort = anInNode->ComputingNode()->AddInDataStreamPort( aNode.theListOfInDataStreams[ j ].theDataStreamParameter.Parametername ,
295 aNode.theListOfInDataStreams[ j ].theDataStreamParameter.Parametertype ,
296 aNode.theListOfInDataStreams[ j ].theDataStreamParameter.Parameterdependency ,
297 SUPERV::DataStreamParameter ) ;
298 ((GraphBase::InDataStreamPort * ) anInPort)->SetParams( aNode.theListOfInDataStreams[ j ].theKindOfSchema ,
299 aNode.theListOfInDataStreams[ j ].theKindOfInterpolation ,
300 aNode.theListOfInDataStreams[ j ].theKindOfExtrapolation ) ;
302 for ( j = 0 ; j < aNode.theListOfOutDataStreams.size() ; j++ ) {
303 GraphBase::OutPort * anOutPort ;
304 anOutPort = anInNode->ComputingNode()->AddOutDataStreamPort( aNode.theListOfOutDataStreams[ j ].theDataStreamParameter.Parametername ,
305 aNode.theListOfOutDataStreams[ j ].theDataStreamParameter.Parametertype ,
306 aNode.theListOfOutDataStreams[ j ].theDataStreamParameter.Parameterdependency ,
307 SUPERV::DataStreamParameter ) ;
308 ((GraphBase::OutDataStreamPort * ) anOutPort)->NumberOfValues( aNode.theListOfOutDataStreams[ j ].theNumberOfValues ) ;
312 // theNode->DataStreamInPortsNumber( aNode.theDataStreamInArgsNumber ) ;
313 // theNode->DataStreamOutPortsNumber( aNode.theDataStreamOutArgsNumber ) ;
314 // cdebug << "GraphExecutor::OutNode::LoadNodes " << anInNode->Name()
315 // << " InPortsSize " << theNode->GetNodeInPortsSize()
316 // << " OutPortsSize " << theNode->GetNodeOutPortsSize()
317 // << " DataStreamInPortsNumber " << aNode.theDataStreamInArgsNumber
318 // << " DataStreamOutPortsNumber " << aNode.theDataStreamOutArgsNumber
321 // if ( aNode.theDataStreamInArgsNumber ) { // -1 because of Gates
322 // for ( j = theNode->GetNodeInPortsSize() - aNode.theDataStreamInArgsNumber - 1 ; j < theNode->GetNodeInPortsSize() - 1 ; j++ ) {
323 // cdebug << "GraphExecutor::OutNode::LoadNodes " << anInNode->Name()
324 // << " InPort " << theNode->GetChangeNodeInPort( j )->PortName()
325 // << " Kind( DataStreamParameter)" << endl ;
326 // theNode->GetChangeNodeInPort( j )->Kind( SUPERV::DataStreamParameter ) ;
329 // if ( aNode.theDataStreamOutArgsNumber ) {
330 // int withgate = 1 ;
331 // if ( theNode->IsLoopNode() || theNode->IsEndLoopNode() ) {
334 // for ( j = theNode->GetNodeOutPortsSize() - aNode.theDataStreamOutArgsNumber - withgate ; j < theNode->GetNodeOutPortsSize() - withgate ; j++ ) {
335 // cdebug << "GraphExecutor::OutNode::LoadNodes " << anInNode->Name()
336 // << " OutPort " << theNode->GetChangeNodeOutPort( j )->PortName()
337 // << " Kind( DataStreamParameter)" << endl ;
338 // theNode->GetChangeNodeOutPort( j )->Kind( SUPERV::DataStreamParameter ) ;
342 for ( i = 0 ; i < (int ) aListOfNodes.size() ; i++ ) {
343 GraphBase::SNode aNode = aListOfNodes[ i ] ;
344 anInNode = (GraphExecutor::InNode * ) Graph()->GetChangeGraphNode( aNode.theName.c_str() )->GetInNode() ;
345 cdebug << "GraphExecutor::OutNode::LoadNodes " << anInNode->Name() << " IsOneOfGOTONodes "
346 << anInNode->IsOneOfGOTONodes() << " " << aNode.theCoupledNode.c_str() << endl ;
347 if ( anInNode->IsOneOfGOTONodes() && strlen( aNode.theCoupledNode.c_str() ) ) {
348 GraphBase::GOTONode * aCoupledNode ;
349 aCoupledNode = (GraphBase::GOTONode * ) Graph()->GetGraphNode( aNode.theName.c_str() ) ;
350 GraphBase::GOTONode * aCoupledCoupledNode ;
351 aCoupledCoupledNode = (GraphBase::GOTONode * ) Graph()->GetChangeGraphNode( aNode.theCoupledNode.c_str() ) ;
352 if ( aCoupledCoupledNode != NULL ) {
353 aCoupledNode->CoupledNode( aCoupledCoupledNode ) ;
356 aCoupledNode->CoupledNodeName( aNode.theCoupledNode.c_str() ) ;
363 bool GraphExecutor::OutNode::LoadLinks(const GraphBase::ListOfSLinks &aListOfLinks ) {
365 cdebug << "GraphExecutor::OutNode::LoadLinks " << aListOfLinks.size()
368 for ( i = 0 ; i < (int ) aListOfLinks.size() ; i++ ) {
369 GraphBase::SLink aLink = aListOfLinks[ i ] ;
370 RetVal = Graph()->AddLink( aLink.FromNodeName.c_str() ,
371 aLink.FromServiceParameterName.c_str() ,
372 aLink.ToNodeName.c_str() ,
373 aLink.ToServiceParameterName.c_str() ) ;
374 // , aLink.aLinkValue ) ;
381 bool GraphExecutor::OutNode::LoadDatas(const GraphBase::ListOfSLinks &aListOfDatas ) {
383 cdebug << "GraphExecutor::OutNode::LoadDatas " << aListOfDatas.size()
386 for ( i = 0 ; i < (int ) aListOfDatas.size() ; i++ ) {
387 GraphBase::SLink aLink = aListOfDatas[ i ] ;
388 if ( !strcmp( aLink.FromNodeName.c_str() , Graph()->Name() ) )
389 RetVal = Graph()->AddInputData( aLink.ToNodeName.c_str() ,
390 aLink.ToServiceParameterName.c_str() ,
392 // else if ( !strcmp( aLink.ToNodeName.c_str() , Graph()->Name() ) ) {
393 // RetVal = Graph()->AddOutputData( aLink.FromNodeName.c_str() ,
394 // aLink.FromServiceParameterName.c_str() ) ;
395 // Graph()->AddLink( aLink.FromNodeName.c_str() , (GraphBase::ComputingNode *) this ) ;
398 cdebug << "GraphExecutor::OutNode::LoadDatas Error " << aLink.FromNodeName
399 << " and " << aLink.ToNodeName << " differents from " << Graph()->Name()
409 GraphExecutor::InNode *GraphExecutor::OutNode::AddNode(
410 const SALOME_ModuleCatalog::Service& NodeService ,
411 GraphBase::ListOfFuncName aFuncName ,
412 GraphBase::ListOfPythonFunctions aPythonFunction ,
413 const char * NodeComponentName ,
414 const char * NodeInterfaceName ,
415 const char * NodeName ,
416 const SUPERV::KindOfNode NodeKindOfNode ,
417 const SUPERV::SDate NodeFirstCreation ,
418 const SUPERV::SDate NodeLastModification ,
419 const char * NodeEditorRelease ,
420 const char * NodeAuthor ,
421 const char * NodeComputer ,
422 const char * NodeComment ,
425 cdebug_in << "GraphExecutor::OutNode::AddNode(" << NodeComponentName << " , "
426 << NodeName << ")" << endl;
427 GraphExecutor::InNode *Nd = NULL ;
428 Nd = new GraphExecutor::InNode( _Orb, Graph()->NamingService() , NodeService ,
429 NodeComponentName , NodeInterfaceName ,
430 NodeName , NodeKindOfNode ,
431 aFuncName , aPythonFunction ,
432 NodeFirstCreation , NodeLastModification ,
433 NodeEditorRelease , NodeAuthor ,
434 NodeComputer , NodeComment , false , NodeX , NodeY ,
435 _prof_debug , _fdebug ) ;
436 Graph()->AddNode( Nd->ComputingNode() ) ;
437 cdebug_out << "GraphExecutor::OutNode::AddNode" << endl;
442 bool GraphExecutor::OutNode::Valid() {
443 cdebug_in << "GraphExecutor::OutNode::Valid" << endl;
448 _Executable = false ;
450 if ( !Graph()->CreateService() ) {
451 cdebug << "This DataFlow has invalid type(s)." << endl ;
454 int SubStreamGraphsNumber = 0 ;
455 if ( !Graph()->Sort( SubStreamGraphsNumber ) ) {
456 cdebug << "This DataFlow is not valid." << endl ;
459 if ( Graph()->IsDataStreamNode() ) {
460 StreamGraph()->SubStreamGraphsNumber( SubStreamGraphsNumber ) ;
465 Graph()->InLineServices() ;
467 Graph()->ComputingNodes() ;
471 cdebug_out << "GraphExecutor::OutNode::Valid" << endl;
476 bool GraphExecutor::OutNode::Executable() {
478 cdebug_in << "GraphExecutor::OutNode::Executable" << endl;
482 if ( Graph()->DataServerNodes() )
485 cdebug << "This DataFlow is not executable." << endl ;
486 _Executable = false ;
489 cdebug_out << "GraphExecutor::OutNode::Executable " << _Executable << endl;
493 bool GraphExecutor::OutNode::Run( const bool AndSuspend ) {
494 bool RetVal = false ;
495 cdebug_in << pthread_self() << "GraphExecutor::OutNode::Run( AndSuspend " << AndSuspend << " )"
498 if ( Executable() ) {
499 _ControlState = SUPERV::VoidState ;
500 _SuspendedThreads = 0 ;
501 Graph()->ThreadNo( pthread_self() ) ;
503 _JustStarted = true ;
506 for ( i = 0 ; i < Graph()->GraphNodesSize() ; i++ ) {
507 GraphExecutor::InNode * anInNode = (GraphExecutor::InNode *) Graph()->GraphNodes( i )->GetInNode() ;
508 anInNode->OutNode( this ) ;
509 if ( !PyInitialized() && anInNode->IsOneOfInLineNodes() ) {
510 if ( !Py_IsInitialized() ) {
511 // PyEval_InitThreads() ;
513 // PySys_SetArgv( _ArgC , _ArgV ) ;
515 anInNode->InitPython() ;
516 PyInitialized( true ) ;
518 anInNode->InitialState() ;
519 if ( anInNode->IsOneOfInLineNodes() ) {
520 anInNode->InitPythonFunctions( false ) ;
523 // One more time because inline nodes may share one definition of the same function
524 for ( i = 0 ; i < Graph()->GraphNodesSize() ; i++ ) {
525 GraphExecutor::InNode * anInNode = (GraphExecutor::InNode *) Graph()->GraphNodes( i )->GetInNode() ;
526 if ( anInNode->IsOneOfInLineNodes() ) {
527 if ( !anInNode->InitPythonFunctions( true ) ) {
528 anInNode->State( GraphExecutor::ErroredState ) ;
529 State( GraphExecutor::ErroredState ) ;
530 cdebug_out << "GraphExecutor::OutNode::Run InitPythonFunctions ERROR "
531 << anInNode->Name() << endl ;
536 /* asv : 29.09.04 : commented out because it does not do anything useful
537 for ( i = 0 ; i < Graph()->GraphNodesSize() ; i++ ) {
538 GraphExecutor::InNode * anInNode = (GraphExecutor::InNode *) Graph()->GraphNodes( i )->GetInNode() ;
539 if ( RetVal && anInNode->IsMacroNode() ) {
540 GraphBase::Graph * aMacroGraph = anInNode->GraphMacroNode() ;
541 cdebug << "GraphExecutor::OutNode::Run " << anInNode << " MacroNode " << aMacroGraph
542 << aMacroGraph->Name() << endl ;
543 SUPERV::Graph_var iobject = anInNode->GraphMacroNode()->MacroObject() ;
544 if ( CORBA::is_nil( iobject ) ) {
545 cdebug << "GraphExecutor::OutNode::Run MacroObject() is a nil object. Error" << endl ;
549 cdebug << "GraphExecutor::OutNode::Run MacroObject() is NOT a nil object." << endl ;
554 if ( Graph()->GraphMacroLevel() != 0 ) {
555 cdebug << "GraphExecutor::OutNode::Run Execution starting GraphExecutor::Action_DataOk_RunService Node "
556 << Graph()->Name() << " GraphMacroLevel " << Graph()->GraphMacroLevel() << endl ;
557 PushEvent( NULL , GraphExecutor::NoDataReadyEvent ,
558 GraphExecutor::DataUndefState ) ;
561 cdebug << "Execution starting GraphExecutor::Action_DataOk_RunService Node "
562 << Graph()->Name() << " GraphMacroLevel " << Graph()->GraphMacroLevel() << endl ;
563 PushEvent( NULL , GraphExecutor::ReadyEvent ,
564 GraphExecutor::DataReadyState ) ;
565 State( GraphExecutor::DataReadyState ) ;
567 cdebug << pthread_self() << " GraphExecutor::OutNode::Run Start of the " << Graph()->HeadNodesSize()
568 << " HeadNodes" << endl ;
569 for ( i = 0 ; i < Graph()->HeadNodesSize() ; i++ ) {
570 GraphExecutor::InNode * anInNode = (GraphExecutor::InNode *) Graph()->HeadNodes( i )->GetInNode() ;
571 cdebug << pthread_self() << "GraphExecutor::OutNode::Run Start of HeadNode " << i << " "
572 << anInNode->Name() << endl ;
573 if ( anInNode->State() != GraphExecutor::DataReadyState ) {
574 cdebug << "GraphExecutor::OutNode::Run inconsistency State of Node "
575 << anInNode->Name() << " : " << anInNode->State() << endl ;
576 cdebug_out << "GraphExecutor::OutNode::Run State ERROR" << endl ;
579 // PushEvent( anInNode , GraphExecutor::ReadyEvent ,
580 // GraphExecutor::DataReadyState ) ;
581 anInNode->CreateNewThread( true ) ;
582 anInNode->DataFromNode( Graph()->Name() ) ;
584 anInNode->State( GraphExecutor::DataWaitingState ) ;
585 anInNode->ControlState( SUPERV::ToSuspendStartState ) ;
586 if ( !anInNode->SendEvent( GraphExecutor::SomeDataReadyEvent ) ) {
587 cdebug << "InNode::SendEvent( SomeDataReadyEvent ) ERROR Node "
588 << anInNode->Name() << endl ;
589 cdebug_out << "GraphExecutor::OutNode::Run SendEvent ERROR" << endl ;
592 anInNode->SuspendedWait() ;
594 else if ( anInNode->IsMacroNode() ) {
595 if ( !anInNode->SendEvent( GraphExecutor::SomeDataReadyEvent ) ) {
596 cdebug << "InNode::SendEvent( SomeDataReadyEvent ) ERROR Node "
597 << anInNode->Name() << endl ;
598 cdebug_out << "GraphExecutor::OutNode::Run SendEvent ERROR" << endl ;
601 cdebug << pthread_self() << " GraphExecutor::OutNode::Run " << anInNode->Name() << "->RunningWait"
603 anInNode->RunningWait() ;
604 cdebug << pthread_self() << " GraphExecutor::OutNode::Run " << anInNode->Name() << "->RunningWaited"
607 else if ( !anInNode->IsMacroNode() ) {
608 if ( !anInNode->SendEvent( GraphExecutor::ExecuteEvent ) ) {
609 cdebug << "InNode::SendEvent( ExecuteEvent ) ERROR Node "
610 << anInNode->Name() << endl ;
611 cdebug_out << "GraphExecutor::OutNode::Run SendEvent ERROR" << endl ;
614 anInNode->RunningWait() ;
619 PushEvent( NULL , GraphExecutor::SuspendedReadyEvent ,
620 GraphExecutor::SuspendedReadyState ) ;
623 PushEvent( NULL , GraphExecutor::ExecutingEvent ,
624 GraphExecutor::ExecutingState ) ;
625 if (AutomatonState() == GraphExecutor::DataReadyState) {
626 State( GraphExecutor::ExecutingState ) ;
629 // ostringstream astr ;
630 // astr << "Graph " << Graph()->Name() << " is running" ;
631 // Graph()->ObjImpl()->sendMessage( NOTIF_STEP, astr.str().c_str() ) ;
636 cdebug_out << pthread_self() << "GraphExecutor::OutNode::Run " << Graph()->Name()
637 << " GraphMacroLevel "
638 << Graph()->GraphMacroLevel() << " RetVal " << RetVal << endl ;
642 bool GraphExecutor::OutNode::Run( const char * aNodeName ,
643 const char * AtNodeName ,
644 const bool AndSuspend ) {
645 bool RetVal = false ;
646 cdebug_in << "GraphExecutor::OutNode::Run( " << aNodeName << " , "
647 << AtNodeName << " , " << AndSuspend << ")" << endl;
648 GraphExecutor::InNode *anInNode = (GraphExecutor::InNode *) Graph()->GetGraphNode( aNodeName )->GetInNode() ;
650 RetVal = anInNode->ReStart( AtNodeName , AndSuspend ) ;
652 cdebug_out << "GraphExecutor::OutNode::Run" << endl ;
656 void GraphExecutor::OutNode::CheckAllDone() {
658 cdebug_in << "GraphExecutor::OutNode::CheckAllDone " << endl;
659 GraphExecutor::AutomatonState OutNodeState = GraphExecutor::SuccessedState ;
660 GraphExecutor::AutomatonState InNodeState ;
661 bool AllDone = true ;
663 for ( j = 0 ; j < Graph()->QueueNodesSize() ; j++ ) {
664 InNodeState = ( (GraphExecutor::InNode * ) Graph()->QueueNodes( j )->GetInNode() )->State() ;
666 << ( (GraphExecutor::InNode * ) Graph()->QueueNodes( j )->GetInNode() )->Name()
667 << " " << theAutomaton->StateName( InNodeState ) << endl ;
668 if ( InNodeState != GraphExecutor::SuccessedState &&
669 InNodeState != GraphExecutor::ErroredState &&
670 InNodeState != GraphExecutor::DataWaitingState ) {
673 if ( InNodeState != GraphExecutor::SuccessedState &&
674 InNodeState != GraphExecutor::DataWaitingState &&
675 InNodeState != GraphExecutor::DataReadyState ) {
676 OutNodeState = InNodeState ;
680 if( _Threads == 0 && _SuspendedThreads == 0 ) {
681 if ( OutNodeState != GraphExecutor::ErroredState ) {
682 OutNodeState = GraphExecutor::SuccessedState ;
691 for ( j = 0 ; j < Graph()->GraphNodesSize() ; j++ ) {
692 GraphExecutor::InNode * aNode ;
693 aNode = (GraphExecutor::InNode * ) Graph()->GraphNodes( j )->GetInNode() ;
694 SUPERV::GraphState aState = AutomatonGraphState( aNode->State() ) ;
695 cdebug << "GraphExecutor::OutNode::CheckAllDone " << aNode->Name() << " "
696 << theAutomaton->StateName( aNode->State() ) << " CreateNewThread " << aNode->CreateNewThread()
698 if ( aState == SUPERV::ErrorState ||
699 aState == SUPERV::SuspendErroredState ||
700 aState == SUPERV::KillState ||
701 aState == SUPERV::StopState ) {
702 OutNodeState = aNode->State() ;
703 State( OutNodeState ) ;
705 else if ( aState == SUPERV::ReadyState ||
706 aState == SUPERV::SuspendReadyState ||
707 aState == SUPERV::RunningState ||
708 aState == SUPERV::SuspendDoneState ||
709 aState == SUPERV::SuspendErroredState ||
710 aState == SUPERV::ReRunState ||
711 aState == SUPERV::ReStartState ||
712 aState == SUPERV::SuspendState ) {
715 aNode->SuspendedAction() ;
716 aNode->DoneAction() ;
718 // PushEvent AFTER State and _Done ! ...
719 if ( alivenodes == 0 ) {
720 State( OutNodeState ) ;
722 _JustStarted = false ;
724 cdebug << Graph()->Name() << " alivenodes " << alivenodes << " OutNodeState " << OutNodeState
726 PushEvent( NULL , GraphExecutor::EndExecuteEvent ,
729 // PyInitialized( false ) ;
733 MESSAGE("================================================================================") ;
734 MESSAGE( Graph()->Name() << " IS DONE : " << theAutomaton->StateName( AutomatonState() ) << " EventQSize "
736 MESSAGE("================================================================================") ;
737 cdebug << "================================================================================" << endl ;
738 cdebug << Graph()->Name() << " IS DONE : " << theAutomaton->StateName( AutomatonState() ) << " EventQSize "
739 << EventQSize() << endl ;
740 cdebug << "================================================================================" << endl ;
742 // asv : fix for 6798 and other bugs: "sift" the event queue after execution
745 // asv : 25.10.04 : calling Editing() to indicate stop of execution
746 Graph()->GraphEditor()->Editing();
748 cdebug_out << "GraphExecutor::OutNode::CheckAllDone " << IsDone() << " this " << this << " "
749 << Graph()->Name() << " GraphAutomatonState "
750 << theAutomaton->StateName( AutomatonState() )
751 << " State " << State() << " Threads " << _Threads << " SuspendedThreads "
752 << _SuspendedThreads << " EventQSize " << EventQSize() << endl ;
755 Engines_Container_i * GraphExecutor::OutNode::SuperVisionContainer() {
756 return _SuperVisionContainer ;
759 const pthread_t GraphExecutor::OutNode::MainThreadId() const {
760 return _MainThreadId ;
763 void GraphExecutor::OutNode::PThreadLock( pthread_mutex_t * aMutex , char * errmsg ) {
764 // if ( strcmp( errmsg , "EventLoop" ) && strcmp( errmsg , "EventW" ) ) {
765 // cdebug << "GraphExecutor::OutNode::PThreadLock " << pthread_self() << " " << aMutex << " "
766 // << errmsg << endl ;
768 if ( pthread_mutex_lock( aMutex ) ) {
772 // if ( strcmp( errmsg , "EventLoop" ) && strcmp( errmsg , "EventW" ) ) {
773 // cdebug << "GraphExecutor::OutNode::PThreadLocked " << pthread_self() << " " << aMutex << " "
774 // << errmsg << endl ;
778 void GraphExecutor::OutNode::PThreadUnLock( pthread_mutex_t * aMutex , char * errmsg ) {
779 // if ( strcmp( errmsg , "EventLoop" ) && strcmp( errmsg , "EventW" ) ) {
780 // cdebug << " GraphExecutor::OutNode::PThreadUnLock " << pthread_self() << " " << aMutex << " "
781 // << errmsg << endl ;
783 if ( pthread_mutex_unlock( aMutex ) ) {
789 void GraphExecutor::OutNode::PyThreadLock() {
790 // cout << " GraphExecutor::OutNode::PyThreadLock " << pthread_self() << endl ;
791 if ( pthread_mutex_lock( &_PyMutexWait ) ) {
792 perror( "GraphExecutor::OutNode::PyThreadLock" ) ;
795 theAutomaton->PyLock() ;
796 // cout << " GraphExecutor::OutNode::PyThreadLocked " << pthread_self() << endl ;
799 void GraphExecutor::OutNode::PyThreadUnLock() {
800 // cout << " GraphExecutor::OutNode::PyThreadUnLock " << pthread_self() << endl ;
801 if ( pthread_mutex_unlock( &_PyMutexWait ) ) {
802 perror( "GraphExecutor::OutNode::PyThreadUnLock" ) ;
805 theAutomaton->PyUnLock() ;
806 // cout << " GraphExecutor::OutNode::PyThreadUnLocked " << pthread_self() << endl ;
809 void GraphExecutor::OutNode::NewThread() {
810 if ( pthread_mutex_lock( &_MutexWait ) ) {
811 perror("pthread_mutex_lock _NewThread") ;
815 cdebug << "NewThread : " << _Threads << " running threads "
816 << _SuspendedThreads << " suspended threads"
818 if ( pthread_mutex_unlock( &_MutexWait ) ) {
819 perror("pthread_mutex_unlock _NewThread") ;
824 void GraphExecutor::OutNode::ExitThread( pthread_t ThreadNumber ) {
825 if ( pthread_mutex_lock( &_MutexWait ) ) {
826 perror("pthread_mutex_lock _ExitThread") ;
829 if ( ThreadNumber == 0 ) {
830 ThreadNumber = pthread_self() ;
833 cdebug << pthread_self() << " ExitThread( " << ThreadNumber << " ) " << _Threads << " running threads "
834 << _SuspendedThreads << " suspended threads"
836 theAutomaton->JoinThread( ThreadNumber ) ;
837 if ( pthread_cond_signal( &_JoinWait ) ) {
838 perror("ExitThread pthread_cond_signal ") ;
840 if ( pthread_mutex_unlock( &_MutexWait ) ) {
841 perror("pthread_mutex_unlock _ExitThread") ;
844 if ( _Threads == 0 && _SuspendedThreads == 0 ) {
847 theAutomaton->Executed() ;
851 void GraphExecutor::OutNode::JoinedWait() {
852 if ( pthread_mutex_lock( &_MutexWait ) ) {
853 perror("pthread_mutex_lock JoinedWait") ;
857 if ( pthread_cond_wait( &_JoinWait , &_MutexWait ) ) {
858 perror("JoinedWait pthread_cond_wait ") ;
861 if ( pthread_mutex_unlock( &_MutexWait ) ) {
862 perror("pthread_mutex_unlock JoinedWait") ;
867 void GraphExecutor::OutNode::SuspendThread() {
868 if ( pthread_mutex_lock( &_MutexWait ) ) {
869 perror("pthread_mutex_lock _SuspendThread") ;
872 _SuspendedThreads += 1 ;
873 cdebug << "SuspendThread : " << _Threads << " running threads "
874 << _SuspendedThreads << " suspended threads"
876 if ( pthread_mutex_unlock( &_MutexWait ) ) {
877 perror("pthread_mutex_unlock _SuspendThread") ;
880 if ( IsSuspended() ) {
881 PushEvent( NULL , GraphExecutor::SuspendEvent , GraphExecutor::SuspendedState ) ;
884 void GraphExecutor::OutNode::ResumeThread() {
885 if ( pthread_mutex_lock( &_MutexWait ) ) {
886 perror("pthread_mutex_lock _ResumeThread") ;
889 _SuspendedThreads -= 1 ;
890 cdebug << "ResumeThread : " << _Threads << " running threads "
891 << _SuspendedThreads << " suspended threads"
893 if ( pthread_mutex_unlock( &_MutexWait ) ) {
894 perror("pthread_mutex_unlock _ResumeThread") ;
899 long GraphExecutor::OutNode::Thread( const char * aNodeName ) {
901 GraphExecutor::InNode *anInNode = (GraphExecutor::InNode *) Graph()->GetGraphNode( aNodeName )->GetInNode() ;
903 RetVal = anInNode->ThreadNo() ;
908 SUPERV::GraphEvent GraphExecutor::OutNode::AutomatonGraphEvent(GraphExecutor::NodeEvent anEvent ) {
909 SUPERV::GraphEvent aGraphEvent ;
911 case GraphExecutor::UndefinedEvent : {
912 aGraphEvent = SUPERV::UndefinedEvent ;
915 case GraphExecutor::NewThreadEvent : {
916 aGraphEvent = SUPERV::NewThreadEvent ;
919 case GraphExecutor::SuspendEvent : {
920 aGraphEvent = SUPERV::SuspendEvent ;
923 case GraphExecutor::ResumeEvent : {
924 aGraphEvent = SUPERV::ResumeEvent ;
927 case GraphExecutor::KillEvent : {
928 aGraphEvent = SUPERV::KillEvent ;
931 case GraphExecutor::StopEvent : {
932 aGraphEvent = SUPERV::StopEvent ;
935 case GraphExecutor::ExecuteEvent : {
936 aGraphEvent = SUPERV::RunningEvent ;
939 case GraphExecutor::SuccessEvent : {
940 aGraphEvent = SUPERV::DoneEvent ;
943 case GraphExecutor::ErrorEvent : {
944 aGraphEvent = SUPERV::ErroredEvent ;
947 case GraphExecutor::ReStartEvent : {
948 aGraphEvent = SUPERV::ReRunEvent ;
951 case GraphExecutor::ReStartAndSuspendEvent : {
952 aGraphEvent = SUPERV::ReStartEvent ;
955 case GraphExecutor::NoDataReadyEvent : {
956 aGraphEvent = SUPERV::WaitingEvent ;
959 case GraphExecutor::SomeDataReadyEvent : {
960 aGraphEvent = SUPERV::WaitingEvent ;
963 case GraphExecutor::NotAllDataReadyEvent : {
964 aGraphEvent = SUPERV::WaitingEvent ;
967 case GraphExecutor::AllDataReadyEvent : {
968 aGraphEvent = SUPERV::ReadyEvent ;
971 case GraphExecutor::ReadyEvent : {
972 aGraphEvent = SUPERV::ReadyEvent ;
975 case GraphExecutor::SuspendedReadyEvent : {
976 aGraphEvent = SUPERV::SuspendEvent ;
979 case GraphExecutor::ResumedReadyEvent : {
980 aGraphEvent = SUPERV::ResumeEvent ;
983 case GraphExecutor::KilledReadyEvent : {
984 aGraphEvent = SUPERV::KillEvent ;
987 case GraphExecutor::StoppedReadyEvent : {
988 aGraphEvent = SUPERV::StopEvent ;
991 case GraphExecutor::ExecutingEvent : {
992 aGraphEvent = SUPERV::RunningEvent ;
995 case GraphExecutor::SuspendedExecutingEvent : {
996 aGraphEvent = SUPERV::SuspendEvent ;
999 case GraphExecutor::ResumedExecutingEvent : {
1000 aGraphEvent = SUPERV::ResumeEvent ;
1003 case GraphExecutor::KilledExecutingEvent : {
1004 aGraphEvent = SUPERV::KillEvent ;
1007 case GraphExecutor::StoppedExecutingEvent : {
1008 aGraphEvent = SUPERV::StopEvent ;
1011 case GraphExecutor::SuccessedExecutingEvent : {
1012 aGraphEvent = SUPERV::DoneEvent ;
1015 case GraphExecutor::ErroredExecutingEvent : {
1016 aGraphEvent = SUPERV:: ErroredEvent;
1019 case GraphExecutor::SuspendedSuccessedEvent : {
1020 aGraphEvent = SUPERV::SuspendEvent ;
1023 case GraphExecutor::SuspendedErroredEvent : {
1024 aGraphEvent = SUPERV::SuspendEvent ;
1027 case GraphExecutor::ResumedSuccessedEvent : {
1028 aGraphEvent = SUPERV::ResumeEvent ;
1031 case GraphExecutor::ResumedErroredEvent : {
1032 aGraphEvent = SUPERV::ResumeEvent ;
1035 case GraphExecutor::KilledEvent : {
1036 aGraphEvent = SUPERV::KillEvent ;
1039 case GraphExecutor::StoppedEvent : {
1040 aGraphEvent = SUPERV::StopEvent ;
1043 case GraphExecutor::ReStartedEvent : {
1044 aGraphEvent = SUPERV::ReRunEvent ;
1047 case GraphExecutor::ReStartedAndSuspendEvent : {
1048 aGraphEvent = SUPERV::ReStartEvent ;
1051 case GraphExecutor::EndExecuteEvent : {
1052 aGraphEvent = SUPERV::DoneEvent ;
1056 cdebug << " GraphExecutor::OutNode::AutomatonGraphEvent Error Undefined Event : "
1057 << anEvent << endl ;
1058 aGraphEvent = SUPERV::UndefinedEvent ;
1061 return aGraphEvent ;
1064 SUPERV::GraphState GraphExecutor::OutNode::AutomatonGraphState(GraphExecutor::AutomatonState aState ) {
1065 SUPERV::GraphState aGraphState ;
1067 case GraphExecutor::UnKnownState : {
1068 aGraphState = SUPERV::UndefinedState ;
1071 case GraphExecutor::DataUndefState : {
1072 aGraphState = SUPERV::UndefinedState ;
1075 case GraphExecutor::DataWaitingState : {
1076 aGraphState = SUPERV::WaitingState ;
1079 case GraphExecutor::DataReadyState : {
1080 aGraphState = SUPERV::ReadyState ;
1083 case GraphExecutor::SuspendedReadyState : {
1084 aGraphState = SUPERV::SuspendReadyState ;
1087 case GraphExecutor::ResumedReadyState : {
1088 aGraphState = SUPERV::ReadyState ;
1091 case GraphExecutor::KilledReadyState : {
1092 aGraphState = SUPERV::KillState ;
1095 case GraphExecutor::StoppedReadyState : {
1096 aGraphState = SUPERV::StopState ;
1099 case GraphExecutor::ExecutingState : {
1100 aGraphState = SUPERV::RunningState ;
1103 case GraphExecutor::SuspendedExecutingState : {
1104 aGraphState = SUPERV::SuspendState ;
1107 case GraphExecutor::ResumedExecutingState : {
1108 aGraphState = SUPERV::RunningState ;
1111 case GraphExecutor::KilledExecutingState : {
1112 aGraphState = SUPERV::KillState ;
1115 case GraphExecutor::StoppedExecutingState : {
1116 aGraphState = SUPERV::StopState ;
1119 case GraphExecutor::SuccessedExecutingState : {
1120 aGraphState = SUPERV::DoneState ;
1123 case GraphExecutor::ErroredExecutingState : {
1124 aGraphState = SUPERV::ErrorState ;
1127 case GraphExecutor::SuspendedSuccessedState : {
1128 aGraphState = SUPERV::SuspendDoneState ;
1131 case GraphExecutor::SuspendedErroredState : {
1132 aGraphState = SUPERV::SuspendErroredState ;
1135 case GraphExecutor::ResumedSuccessedState : {
1136 aGraphState = SUPERV::DoneState ;
1139 case GraphExecutor::ResumedErroredState : {
1140 aGraphState = SUPERV::ErrorState ;
1143 case GraphExecutor::KilledSuccessedState : {
1144 aGraphState = SUPERV::KillState ;
1147 case GraphExecutor::KilledErroredState : {
1148 aGraphState = SUPERV::KillState ;
1151 case GraphExecutor::StoppedSuccessedState : {
1152 aGraphState = SUPERV::StopState ;
1155 case GraphExecutor::StoppedErroredState : {
1156 aGraphState = SUPERV::StopState ;
1159 case GraphExecutor::SuccessedState : {
1160 aGraphState = SUPERV::DoneState ;
1163 case GraphExecutor::ErroredState : {
1164 aGraphState = SUPERV::ErrorState ;
1167 case GraphExecutor::SuspendedState : {
1168 aGraphState = SUPERV::SuspendState ;
1171 case GraphExecutor::KilledState : {
1172 aGraphState = SUPERV::KillState ;
1175 case GraphExecutor::StoppedState : {
1176 aGraphState = SUPERV::StopState ;
1179 case GraphExecutor::ReRunnedState : {
1180 aGraphState = SUPERV::ReRunState ;
1183 case GraphExecutor::ReStartedState : {
1184 aGraphState = SUPERV::ReStartState ;
1188 cdebug << " GraphExecutor::OutNode::AutomatonGraphState Error Undefined State : "
1189 << aGraphState << endl ;
1190 aGraphState = SUPERV::UndefinedState ;
1193 return aGraphState ;
1196 int GraphExecutor::OutNode::GetListSize() {
1197 return _EventNodes.size();
1200 bool GraphExecutor::OutNode::PushEvent( GraphExecutor::InNode * aNode ,
1201 GraphExecutor::NodeEvent anEvent ,
1202 GraphExecutor::AutomatonState aState ) {
1203 // cdebug_in << "PushEvent Threads " << Threads() << " SuspendedThreads "
1204 // << SuspendedThreads() << endl ;
1205 if ( pthread_mutex_lock( &_MutexWait ) ) {
1206 perror("PushEvent pthread_mutex_lock ") ;
1209 char* aNodeName = aNode ? aNode->Name() : Graph()->Name() ;
1210 _EventNodes.push_back( aNodeName ) ;
1211 _Events.push_back( anEvent ) ;
1212 _States.push_back( aState ) ;
1214 pthread_cond_broadcast( &_EventWait );
1215 cdebug << pthread_self() << " PushEvent Threads " << Threads() << " SuspendedThreads "
1216 << SuspendedThreads() << " pthread_cond_broadcast _EventWait " << &_EventWait << endl ;
1218 // cdebug << aNode->ThreadNo() << " PushEvent " << aNode->Name() ;
1219 // cdebug << " " << aNode->Automaton()->EventName( anEvent )
1220 // << " " << aNode->Automaton()->StateName( aState )
1221 // << " ControleState "
1222 // << aNode->Automaton()->ControlStateName( aNode->ControlState() ) ;
1225 // cdebug << "PushEvent " << Graph()->Name() ;
1226 // cdebug << " " << theAutomaton->EventName( anEvent ) << " "
1227 // << theAutomaton->StateName( aState ) ;
1229 // cdebug_out << "PushEvent Threads " << Threads() << " SuspendedThreads "
1230 // << SuspendedThreads() << endl ;
1232 if ( _EventNodes.size() > 101 ) {
1233 while ( _EventNodes.size() > 31 ) {
1234 _EventNodes.pop_front() ;
1235 _Events.pop_front() ;
1236 _States.pop_front() ;
1240 if ( pthread_mutex_unlock( &_MutexWait ) ) {
1241 perror("PushEvent pthread_mutex_unlock ") ;
1247 bool GraphExecutor::OutNode::StateWait( SUPERV::GraphState aState ) {
1251 bool GraphExecutor::OutNode::Event( char ** aNodeName ,
1252 SUPERV::GraphEvent & anEvent ,
1253 SUPERV::GraphState & aState ,
1255 // asv : fixing problem of loops with large number of iterations (>5000)
1256 // experimentally was found that number of non-handled by GUI events = (number_of_nodes x 7)
1257 // or 7 events for each node - so what we want to do here is remove "old" events for nodes
1258 // "on the fly". Once again it is done in Stop(), Kill(), Done() functions.
1259 if ( _EventNodes.size() > (unsigned int)Graph()->GraphNodesSize()*7 )
1263 int SuspendedThreadsNumber ;
1264 bool cdebuginout = false ;
1265 if ( _EventNodes.size() > 0 ) {
1266 // cdebug_in << "GraphExecutor::OutNode::Event " << _EventNodes.size() << " in queue" << endl ;
1267 cdebuginout = true ;
1269 if ( pthread_mutex_lock( &_MutexWait ) ) {
1270 perror("EventLoop pthread_mutex_lock ") ;
1273 _JustStarted = false ;
1274 ThreadsNumber = Threads() ;
1275 SuspendedThreadsNumber = SuspendedThreads() ;
1276 bool RetVal = ( ThreadsNumber - SuspendedThreadsNumber) != 0 ||
1277 _EventNodes.size() > 0 ;
1278 char * NodeName = "" ;
1279 GraphExecutor::NodeEvent theEvent = GraphExecutor::UndefinedEvent ;
1280 GraphExecutor::AutomatonState theState = GraphExecutor::UnKnownState ;
1281 anEvent = SUPERV::UndefinedEvent ;
1282 aState = SUPERV::UndefinedState ;
1283 if ( ( Done() || IsKilled() || IsStopped() ) && _EventNodes.size() == 0 ) {
1284 // cdebug << "EventLoop Done()/IsKilled()/IsStopped() && _EventNodes.size() == 0" << endl ;
1287 else if ( !WithWait && _EventNodes.size() == 0 ) {
1288 anEvent = SUPERV::NoEvent ;
1289 aState = SUPERV::NoState ;
1292 else if ( RetVal ) {
1293 while ( !IsSuspended() && _EventNodes.size() == 0 ) {
1294 // cdebug << "EventLoop pthread_cond_wait _EventWait" << endl ;
1295 pthread_cond_wait( &_EventWait , &_MutexWait );
1296 // cdebug << "EventLoop pthread_cond_waited _EventWait"
1297 // << " _EventNodes.size() " << _EventNodes.size() << endl ;
1299 if ( _EventNodes.size() ) {
1300 ThreadsNumber = Threads() ;
1301 NodeName = _EventNodes.front() ;
1302 _EventNodes.pop_front() ;
1303 theEvent = _Events.front() ;
1304 anEvent = AutomatonGraphEvent( theEvent ) ;
1305 _Events.pop_front() ;
1306 theState = _States.front() ;
1307 aState = AutomatonGraphState( theState ) ;
1308 _States.pop_front() ;
1311 *aNodeName = NodeName ;
1312 if ( IsSuspended() && _EventNodes.size() == 0 ) {
1315 if ( anEvent != SUPERV::NoEvent ) {
1316 // cdebug << pthread_self() << "EventLoop "
1317 // << NodeName << " " << theAutomaton->StateName( theState )
1318 // << " _EventNodes.size() " << _EventNodes.size()
1319 // << " Threads " << Threads() << " SuspendedThreads "
1320 // << SuspendedThreads() << " RetVal " << RetVal << endl ;
1322 if ( pthread_mutex_unlock( &_MutexWait ) ) {
1323 perror("EventLoop pthread_mutex_lock ") ;
1326 if ( cdebuginout ) {
1327 // cdebug_out << "GraphExecutor::OutNode::Event " << _EventNodes.size() << " in queue"
1328 // << *aNodeName << " " << anEvent << " " << aState << endl ;
1333 bool GraphExecutor::OutNode::EventW( char ** aNodeName ,
1334 SUPERV::GraphEvent & anEvent ,
1335 SUPERV::GraphState & aState ) {
1338 aState = SUPERV::UndefinedState ;
1340 aState != SUPERV::SuspendReadyState &&
1341 aState != SUPERV::RunningState &&
1342 aState != SUPERV::SuspendDoneState &&
1343 aState != SUPERV::SuspendErroredState ) {
1344 NodeName = Graph()->Name() ;
1345 while ( sts && !strcmp( NodeName , Graph()->Name() ) ) {
1346 sts = EventWait( aNodeName , anEvent , aState ) ;
1347 NodeName = *aNodeName ;
1353 bool GraphExecutor::OutNode::EventWait( char ** aNodeName ,
1354 SUPERV::GraphEvent & anEvent ,
1355 SUPERV::GraphState & aState ) {
1356 if ( pthread_mutex_lock( &_MutexWait ) ) {
1357 perror("EventW pthread_mutex_lock ") ;
1361 int SuspendedThreadsNumber ;
1362 ThreadsNumber = Threads() ;
1363 SuspendedThreadsNumber = SuspendedThreads() ;
1364 bool RetVal = ( ThreadsNumber - SuspendedThreadsNumber) != 0 ||
1365 _EventNodes.size() > 0 ;
1366 cdebug << "--> EventW RetVal " << RetVal << endl ;
1367 char * NodeName = "" ;
1368 GraphExecutor::NodeEvent theEvent = GraphExecutor::UndefinedEvent ;
1369 GraphExecutor::AutomatonState theState = GraphExecutor::UnKnownState ;
1370 anEvent = SUPERV::UndefinedEvent ;
1371 aState = SUPERV::UndefinedState ;
1372 if ( IsDone() && _EventNodes.size() == 0 ) {
1373 cdebug << "EventW IsDone() && _EventNodes.size() == 0" << endl ;
1376 else if ( RetVal ) {
1377 GraphExecutor::InNode * aNode = NULL ;
1378 while ( aNode == NULL && RetVal ) {
1379 NodeName = _EventNodes.front() ;
1380 theEvent = _Events.front() ;
1381 anEvent = AutomatonGraphEvent( theEvent ) ;
1382 theState = _States.front() ;
1383 aState = AutomatonGraphState( theState ) ;
1385 if ( _JustStarted ) {
1386 _JustStarted = false ;
1389 _EventNodes.pop_front() ;
1390 _Events.pop_front() ;
1391 _States.pop_front() ;
1394 aNode = ((GraphExecutor::InNode *) Graph()->GetGraphNode( NodeName )->GetInNode()) ;
1395 cdebug << "EventW Previous Node " << NodeName << " ThreadsNumber "
1397 << " _EventNodes.size() " << _EventNodes.size() << " "
1398 << theAutomaton->StateName( theState )
1399 << " Threads " << Threads() << " SuspendedThreads "
1400 << SuspendedThreads() << endl ;
1403 else if ( IsDone() && _EventNodes.size() == 0 ) {
1404 cdebug << "EventW IsDone() && _EventNodes.size() == 0" << endl ;
1408 cdebug << "EventW Not InNode " << NodeName
1409 << " _EventNodes.size() " << _EventNodes.size() << endl ;
1410 while ( _EventNodes.size() == 0 ) {
1411 pthread_cond_wait( &_EventWait , &_MutexWait );
1413 cdebug << "EventW pthread_cond_waited Not InNode " << NodeName
1414 << " _EventNodes.size() " << _EventNodes.size() << endl ;
1419 if ( aState == SUPERV::SuspendState ||
1420 aState == SUPERV::SuspendReadyState ||
1421 aState == SUPERV::SuspendDoneState ||
1422 aState == SUPERV::SuspendErroredState ) {
1423 aNode->ControlState( SUPERV::ToSuspendState ) ;
1424 if ( aNode->IsSuspended() ) {
1425 if ( pthread_mutex_unlock( &_MutexWait ) ) {
1426 perror("EventW pthread_mutex_lock ") ;
1429 cdebug << "EventW " << aNode->Name() << " ResumeAction" << endl ;
1430 aNode->ResumeAction( GraphExecutor::ToResumeEvent ) ;
1431 cdebug << "EventW " << aNode->Name() << " ResumedAction" << endl ;
1432 if ( pthread_mutex_lock( &_MutexWait ) ) {
1433 perror("EventW pthread_mutex_lock ") ;
1438 cdebug << "EventW inconsistent SuspendState" << endl ;
1443 if ( aNode->IsDone() ) {
1447 cdebug << "EventW NOT SuspendedState _EventNodes.size() "
1448 << _EventNodes.size() << endl ;
1453 cdebug << "EventW " << aNode->Name() << " pthread_cond_wait" << endl ;
1454 while ( _EventNodes.size() == 0 ) {
1455 pthread_cond_wait( &_EventWait , &_MutexWait );
1457 ThreadsNumber = Threads() ;
1458 NodeName = _EventNodes.front() ;
1459 theEvent = _Events.front() ;
1460 anEvent = AutomatonGraphEvent( theEvent ) ;
1461 theState = _States.front() ;
1462 aState = AutomatonGraphState( theState ) ;
1466 *aNodeName = NodeName ;
1467 cdebug << "<-- EventW RetVal " << RetVal << " " << NodeName
1468 << " Threads " << Threads() << " SuspendedThreads "
1469 << SuspendedThreads()
1470 << " _EventNodes.size() " << _EventNodes.size()
1471 << " " << theAutomaton->EventName( theEvent ) << " "
1472 << theAutomaton->StateName( theState ) << endl ;
1473 if ( pthread_mutex_unlock( &_MutexWait ) ) {
1474 perror("EventW pthread_mutex_lock ") ;
1479 long GraphExecutor::OutNode::EventQSize() {
1480 return _EventNodes.size() ;
1483 void GraphExecutor::OutNode::EventList() {
1484 if ( pthread_mutex_lock( &_MutexWait ) ) {
1485 perror("EventList pthread_mutex_lock ") ;
1488 list< char * >::iterator itEventNodes = _EventNodes.begin() ;
1489 list< GraphExecutor::NodeEvent >::iterator itEvents = _Events.begin() ;
1490 list< GraphExecutor::AutomatonState >::iterator itStates = _States.begin() ;
1491 while ( itEventNodes != _EventNodes.end() ) {
1492 cdebug << pthread_self() << "EVENTSTACK "
1493 << *itEventNodes << " " << *itEvents << " "
1494 << theAutomaton->StateName( *itStates )
1495 << " Threads " << Threads() << " SuspendedThreads " << SuspendedThreads() << endl ;
1500 if ( pthread_mutex_unlock( &_MutexWait ) ) {
1501 perror("EventList pthread_mutex_lock ") ;
1506 void GraphExecutor::OutNode::SendSomeDataReady( const char * aNodeName ) {
1507 cdebug_in << "GraphExecutor::OutNode::SendSomeDataReady " << aNodeName << "->SendSomeDataReady( "
1508 << Graph()->Name() << " )" << endl;
1510 sts = ((GraphExecutor::InNode * ) Graph()->GetChangeGraphNode( aNodeName )->GetInNode())->SendSomeDataReady( Graph()->Name() ) ;
1511 cdebug_out << "GraphExecutor::OutNode::SendSomeDataReady sts " << sts << endl ;
1514 void GraphExecutor::OutNode::State(GraphExecutor::AutomatonState aState ) {
1515 // cdebug << "GraphExecutor::OutNode::State " << Graph()->Name() << " "
1516 // << theAutomaton->StateName( AutomatonGraphState( _State ) ) << " ---> "
1517 // << theAutomaton->StateName( AutomatonGraphState( aState ) ) << endl ;
1521 SUPERV::GraphState GraphExecutor::OutNode::State() {
1522 // cdebug_in << "GraphExecutor::OutNode::State" << endl;
1523 // cdebug_out << "GraphExecutor::OutNode::State" << endl ;
1524 // cdebug << "GraphExecutor::OutNode::State GraphState "
1525 // << theAutomaton->StateName( AutomatonGraphState( _State ) ) << endl ;
1526 return AutomatonGraphState( _State ) ;
1529 SUPERV::GraphState GraphExecutor::OutNode::State( const char * NodeName ) {
1530 // cdebug_in << "GraphExecutor::OutNode::State " << NodeName << endl;
1531 GraphExecutor::AutomatonState aret = GraphExecutor::UnKnownState ;
1532 const GraphBase::ComputingNode * aCNode = Graph()->GetGraphNode( NodeName ) ;
1534 GraphExecutor::InNode *anInNode = (GraphExecutor::InNode *)aCNode->GetInNode() ;
1536 aret = anInNode->State() ;
1537 // cdebug << "GraphExecutor::OutNode::State( " << NodeName << " ) "
1538 // << theAutomaton->StateName( AutomatonGraphState( aret ) ) << endl ;
1541 // cdebug_out << "GraphExecutor::OutNode::State" << endl ;
1542 return AutomatonGraphState( aret ) ;
1545 SUPERV::GraphState GraphExecutor::OutNode::State( const char * NodeName ,
1546 const char * ServiceParameterName ) {
1547 // cdebug_in << "GraphExecutor::OutNode::State " << NodeName << " "
1548 // << ServiceParameterName<< endl;
1549 SUPERV::GraphState aret = Graph()->PortState( NodeName , ServiceParameterName ) ;
1550 // cdebug_out << "GraphExecutor::OutNode::State" << endl ;
1554 GraphExecutor::AutomatonState GraphExecutor::OutNode::AutomatonState() {
1555 // cdebug_in << "GraphExecutor::OutNode::AutomatonState" << endl;
1556 // cdebug_out << "GraphExecutor::OutNode::AutomatonState" << endl ;
1560 GraphExecutor::AutomatonState GraphExecutor::OutNode::AutomatonState( const char * NodeName ) {
1561 // cdebug_in << "GraphExecutor::OutNode::AutomatonState " << NodeName << endl;
1562 GraphExecutor::AutomatonState aret = GraphExecutor::UnKnownState ;
1563 const GraphBase::ComputingNode * aNode = Graph()->GetGraphNode( NodeName ) ;
1565 GraphExecutor::InNode *anInNode = (GraphExecutor::InNode *) aNode->GetInNode() ;
1567 aret = anInNode->State() ;
1570 // cdebug_out << "GraphExecutor::OutNode::AutomatonState" << endl ;
1574 SUPERV::ControlState GraphExecutor::OutNode::ControlState() {
1575 // cdebug_in << "GraphExecutor::OutNode::ControlState" << endl;
1576 // cdebug_out << "GraphExecutor::OutNode::ControlState" << endl ;
1577 return _ControlState ;
1580 SUPERV::ControlState GraphExecutor::OutNode::ControlState( const char * NodeName ) {
1581 // cdebug_in << "GraphExecutor::OutNode::ControlState " << NodeName << endl;
1582 SUPERV::ControlState aret = SUPERV::VoidState ;
1583 const GraphBase::ComputingNode * aNode = Graph()->GetGraphNode( NodeName ) ;
1585 GraphExecutor::InNode *anInNode = (GraphExecutor::InNode *) aNode->GetInNode() ;
1587 aret = anInNode->ControlState() ;
1590 // cdebug_out << "GraphExecutor::OutNode::ControlState" << endl ;
1594 void GraphExecutor::OutNode::ControlClear() {
1595 // cdebug_in << "GraphExecutor::OutNode::ControlClear" << endl;
1596 // cdebug_out << "GraphExecutor::OutNode::ControlClear" << endl ;
1597 _ControlState = SUPERV::VoidState;
1600 void GraphExecutor::OutNode::ControlClear( const char * NodeName ) {
1601 // cdebug_in << "GraphExecutor::OutNode::ControlClear " << NodeName << endl;
1602 const GraphBase::ComputingNode * aNode = Graph()->GetGraphNode( NodeName ) ;
1604 GraphExecutor::InNode *anInNode = (GraphExecutor::InNode *) aNode->GetInNode() ;
1606 anInNode->ControlClear() ;
1609 // cdebug_out << "GraphExecutor::OutNode::ControlClear" << endl ;
1612 bool GraphExecutor::OutNode::IsWaiting() {
1613 // cdebug_in << "GraphExecutor::OutNode::IsWaiting" << endl;
1614 // cdebug_out << "GraphExecutor::OutNode::IsWaiting" << endl ;
1618 bool GraphExecutor::OutNode::IsReady() {
1619 // cdebug_in << "GraphExecutor::OutNode::IsReady" << endl;
1620 // cdebug_out << "GraphExecutor::OutNode::IsReady" << endl ;
1624 bool GraphExecutor::OutNode::IsRunning() {
1625 // cdebug_in << "GraphExecutor::OutNode::IsRunning" << endl;
1626 // cdebug_out << "GraphExecutor::OutNode::IsRunning" << endl ;
1630 bool GraphExecutor::OutNode::IsDone() {
1631 // cdebug_in << "GraphExecutor::OutNode::IsDone" << endl;
1632 // cdebug_out << "GraphExecutor::OutNode::IsDone" << endl ;
1633 return ( Done() || IsKilled() || IsStopped() ) ;
1636 bool GraphExecutor::OutNode::IsSuspended() {
1637 // cdebug_in << "GraphExecutor::OutNode::IsSuspended" << endl;
1639 // if ( _SuspendedThreads == _Threads && _Threads != 0 ) {
1640 if ( AutomatonGraphState( _State ) == SUPERV::SuspendState ) {
1643 // cdebug_out << "GraphExecutor::OutNode::IsSuspended" << endl ;
1647 bool GraphExecutor::OutNode::IsKilled() {
1648 // cdebug_in << "GraphExecutor::OutNode::IsKilled" << endl;
1650 if ( AutomatonGraphState( _State ) == SUPERV::KillState ) {
1653 // cdebug_out << "GraphExecutor::OutNode::IsKilled" << endl ;
1657 bool GraphExecutor::OutNode::IsStopped() {
1658 // cdebug_in << "GraphExecutor::OutNode::IsStopped" << endl;
1660 if ( AutomatonGraphState( _State ) == SUPERV::StopState ) {
1663 // cdebug_out << "GraphExecutor::OutNode::IsStopped" << endl ;
1667 bool GraphExecutor::OutNode::IsWaiting( const char * NodeName ) {
1669 // cdebug_in << "GraphExecutor::OutNode::IsWaiting " << NodeName << endl;
1670 GraphExecutor::InNode *anInNode = (GraphExecutor::InNode *) Graph()->GetGraphNode( NodeName )->GetInNode() ;
1672 aret = anInNode->IsWaiting() ;
1674 // cdebug_out << "GraphExecutor::OutNode::IsWaiting" << endl ;
1678 bool GraphExecutor::OutNode::IsReady( const char * NodeName ) {
1680 // cdebug_in << "GraphExecutor::OutNode::IsReady " << NodeName << endl;
1681 GraphExecutor::InNode *anInNode = (GraphExecutor::InNode *) Graph()->GetGraphNode( NodeName )->GetInNode() ;
1683 aret = anInNode->IsReady() ;
1685 // cdebug_out << "GraphExecutor::OutNode::IsReady" << endl ;
1689 bool GraphExecutor::OutNode::IsRunning( const char * NodeName ) {
1691 // cdebug_in << "GraphExecutor::OutNode::IsRunning " << NodeName << endl;
1692 GraphExecutor::InNode *anInNode = (GraphExecutor::InNode *) Graph()->GetGraphNode( NodeName )->GetInNode() ;
1694 aret = anInNode->IsRunning() ;
1696 // cdebug_out << "GraphExecutor::OutNode::IsRunning" << endl ;
1700 bool GraphExecutor::OutNode::IsDone( const char * NodeName ) {
1702 // cdebug_in << "GraphExecutor::OutNode::IsDone " << NodeName << endl;
1703 GraphExecutor::InNode *anInNode = (GraphExecutor::InNode *) Graph()->GetGraphNode( NodeName )->GetInNode() ;
1705 aret = anInNode->IsDone() ;
1707 // cdebug_out << "GraphExecutor::OutNode::IsDone" << endl ;
1711 bool GraphExecutor::OutNode::IsSuspended( const char * NodeName ) {
1713 // cdebug_in << "GraphExecutor::OutNode::IsSuspended " << NodeName << endl;
1714 GraphExecutor::InNode *anInNode = (GraphExecutor::InNode *) Graph()->GetGraphNode( NodeName )->GetInNode() ;
1716 aret = anInNode->IsSuspended() ;
1718 // cdebug_out << "GraphExecutor::OutNode::IsSuspended" << endl ;
1722 bool GraphExecutor::OutNode::IsDone( const char * NodeName ,
1723 const char * ServiceParameterName ) {
1724 // cdebug_in << "GraphExecutor::OutNode::IsDone " << NodeName << " "
1725 // << ServiceParameterName<< endl;
1726 bool aret = Graph()->PortDone( NodeName , ServiceParameterName ) ;
1727 // cdebug_out << "GraphExecutor::OutNode::IsDone" << endl ;
1731 bool GraphExecutor::OutNode::ContainerKill() {
1732 bool RetVal = true ;
1733 cdebug_in << "GraphExecutor::OutNode::ContainerKill" << endl;
1734 _ControlState = SUPERV::ToSuspendState ;
1736 for ( i = 0 ; i < Graph()->GraphNodesSize() ; i++ ) {
1737 GraphExecutor::InNode * aNode = (GraphExecutor::InNode * ) Graph()->GraphNodes( i )->GetInNode() ;
1738 bool sts = aNode->ContainerKill() ;
1739 if ( sts && aNode->IsKilled() ) {
1740 cdebug << aNode->Name() << " killed" << endl ;
1742 else if ( aNode->IsWaiting() || aNode->IsDone() ) {
1743 cdebug << aNode->Name() << " not killed : "
1744 << theAutomaton->StateName( aNode->State() ) << endl ;
1747 cdebug << aNode->Name() << " cannot be killed : "
1748 << theAutomaton->StateName( aNode->State() ) << endl ;
1752 if ( !RetVal || Threads() != 0 ) {
1753 for ( i = 0 ; i < Graph()->GraphNodesSize() ; i++ ) {
1754 GraphExecutor::InNode * aNode = (GraphExecutor::InNode * ) Graph()->GraphNodes( i )->GetInNode() ;
1755 if ( !aNode->IsKilled() && !aNode->IsWaiting() && !aNode->IsDone() ) {
1756 aNode->KilledAction() ;
1761 State( GraphExecutor::KilledState ) ;
1762 cdebug_out << "GraphExecutor::OutNode::ContainerKill" << endl ;
1766 bool GraphExecutor::OutNode::Suspend() {
1768 cdebug_in << "GraphExecutor::OutNode::Suspend" << endl;
1769 // _ControlState = SUPERV::ToSuspendState ;
1771 for ( i = 0 ; i < Graph()->GraphNodesSize() ; i++ ) {
1772 GraphExecutor::InNode * aNode = (GraphExecutor::InNode * ) Graph()->GraphNodes( i )->GetInNode() ;
1773 bool sts = aNode->Suspend() ;
1774 if ( sts && aNode->IsSuspended() ) {
1776 cdebug << aNode->Name() << " Suspended" << endl ;
1778 else if ( aNode->IsWaiting() || aNode->IsReady() ) {
1780 cdebug << aNode->Name() << " will be Suspended" << endl ;
1782 else if ( aNode->IsDone() ) {
1783 cdebug << aNode->Name() << " not Suspended : "
1784 << theAutomaton->StateName( aNode->State() ) << endl ;
1788 cdebug << aNode->Name() << " cannot be Suspended : "
1789 << theAutomaton->StateName( aNode->State() ) << endl ;
1793 State( GraphExecutor::SuspendedState ) ;
1794 MESSAGE("================================================================================") ;
1795 MESSAGE( Graph()->Name() << " IS SUSPENDED" ) ;
1796 MESSAGE("================================================================================") ;
1799 MESSAGE("================================================================================") ;
1800 MESSAGE( Graph()->Name() << " IS NOT SUSPENDED" ) ;
1801 MESSAGE("================================================================================") ;
1803 for ( i = 0 ; i < Graph()->GraphNodesSize() ; i++ ) {
1804 GraphExecutor::InNode * aNode = (GraphExecutor::InNode * ) Graph()->GraphNodes( i )->GetInNode() ;
1805 MESSAGE(aNode->Name() << " " << theAutomaton->StateName( aNode->State() ) ) ;
1806 cdebug << aNode->Name() << " " << theAutomaton->StateName( aNode->State() ) << endl ;
1808 cdebug_out << "GraphExecutor::OutNode::Suspend " << theAutomaton->StateName( State() )
1809 << " EventQSize " << EventQSize() << endl ;
1813 bool GraphExecutor::OutNode::Resume() {
1815 cdebug_in << "GraphExecutor::OutNode::Resume "
1816 << theAutomaton->StateName( State() ) << endl;
1817 if ( IsSuspended() ) {
1818 State( GraphExecutor::ExecutingState ) ;
1820 for ( i = 0 ; i < Graph()->GraphNodesSize() ; i++ ) {
1821 GraphExecutor::InNode * aNode = (GraphExecutor::InNode * ) Graph()->GraphNodes( i )->GetInNode() ;
1822 aNode->ControlState( SUPERV::VoidState ) ;
1823 if ( aNode->IsSuspended() ) {
1824 cdebug << aNode->Name() << "->Resume " << theAutomaton->StateName( aNode->State() )
1826 if ( aNode->Resume() ) {
1827 cdebug << aNode->Name() << " Resumed " << theAutomaton->StateName( aNode->State() )
1832 cdebug << aNode->Name() << " Resume failed"
1833 << theAutomaton->StateName( aNode->State() ) << endl ;
1837 cdebug << aNode->Name() << " " << theAutomaton->StateName( aNode->State() )
1843 cdebug << Graph()->Name() << " not suspended " << theAutomaton->StateName( State() ) << endl ;
1846 MESSAGE("================================================================================") ;
1847 MESSAGE( Graph()->Name() << " IS RESUMED" ) ;
1848 MESSAGE("================================================================================") ;
1851 MESSAGE("================================================================================") ;
1852 MESSAGE( Graph()->Name() << " IS NOT RESUMED" ) ;
1853 MESSAGE("================================================================================") ;
1856 for ( i = 0 ; i < Graph()->GraphNodesSize() ; i++ ) {
1857 GraphExecutor::InNode * aNode = (GraphExecutor::InNode * ) Graph()->GraphNodes( i )->GetInNode() ;
1858 MESSAGE(aNode->Name() << " " << theAutomaton->StateName( aNode->State() ) ) ;
1859 cdebug << aNode->Name() << " " << theAutomaton->StateName( aNode->State() ) << endl ;
1861 cdebug_out << "GraphExecutor::OutNode::Resume" << theAutomaton->StateName( State() ) << " " << RetVal
1862 << " EventQSize " << EventQSize() << endl ;
1866 bool GraphExecutor::OutNode::Kill() {
1867 bool RetVal = false ;
1868 cdebug_in << "GraphExecutor::OutNode::Kill"
1869 << " EventQSize " << EventQSize() << endl;
1870 _ControlState = SUPERV::ToSuspendState ;
1872 for ( i = 0 ; i < Graph()->GraphNodesSize() ; i++ ) {
1873 GraphExecutor::InNode * aNode = (GraphExecutor::InNode * ) Graph()->GraphNodes( i )->GetInNode() ;
1874 bool sts = aNode->Kill() ;
1876 if ( !aNode->IsKilled() ) {
1877 cdebug << aNode->Name() << " not killed : "
1878 << theAutomaton->StateName( aNode->State() ) << " " << aNode->Name() << "->"
1879 << "KilledAction()" << endl ;
1880 MESSAGE( aNode->Name() << " not killed : KilledAction()" ) ;
1881 aNode->KilledAction() ;
1883 if ( aNode->IsKilled() ) {
1884 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 State( GraphExecutor::KilledState ) ;
1899 MESSAGE("================================================================================") ;
1900 MESSAGE( Graph()->Name() << " IS KILLED" << theAutomaton->StateName( AutomatonState() ) << " EventQSize "
1902 MESSAGE("================================================================================") ;
1905 MESSAGE("================================================================================") ;
1906 MESSAGE( Graph()->Name() << " IS NOT KILLED" ) ;
1907 MESSAGE("================================================================================") ;
1909 for ( i = 0 ; i < Graph()->GraphNodesSize() ; i++ ) {
1910 GraphExecutor::InNode * aNode = (GraphExecutor::InNode * ) Graph()->GraphNodes( i )->GetInNode() ;
1911 MESSAGE(aNode->Name() << " " << theAutomaton->StateName( aNode->State() ) ) ;
1912 cdebug << aNode->Name() << " " << theAutomaton->StateName( aNode->State() ) << endl ;
1914 cdebug_out << "GraphExecutor::OutNode::Kill " << RetVal
1915 << " Threads " << _Threads << " SuspendedThreads " << _SuspendedThreads
1916 << " EventQSize " << EventQSize() << endl ;
1918 // remove "extra" events from the event queue
1921 // asv : 25.10.04 : calling Editing() to indicate stop of execution
1922 Graph()->GraphEditor()->Editing();
1927 bool GraphExecutor::OutNode::Stop() {
1928 bool RetVal = false ;
1929 cdebug_in << "GraphExecutor::OutNode::Stop" << endl;
1931 cdebug_out << "GraphExecutor::OutNode::Stop" << endl ;
1933 MESSAGE("================================================================================") ;
1934 MESSAGE( Graph()->Name() << " IS STOPPED" ) ;
1935 MESSAGE("================================================================================") ;
1939 bool GraphExecutor::OutNode::ReRun() {
1940 bool RetVal = false ;
1941 cdebug_in << "GraphExecutor::OutNode::ReRun" << endl;
1942 if ( IsSuspended() ) {
1944 cdebug_out << "GraphExecutor::OutNode::ReRun" << endl ;
1947 bool GraphExecutor::OutNode::ReStart() {
1948 bool RetVal = false ;
1949 cdebug_in << "GraphExecutor::OutNode::ReStart" << endl;
1950 if ( IsSuspended() ) {
1952 cdebug_out << "GraphExecutor::OutNode::ReStart" << endl ;
1956 bool GraphExecutor::OutNode::ReadyWait() {
1957 cdebug_in << "GraphExecutor::OutNode::ReadyWait" << endl;
1959 if ( pthread_mutex_lock( &_MutexWait ) ) {
1960 perror("pthread_mutex_lock _ReadyWait") ;
1966 pthread_cond_wait( &_EventWait , &_MutexWait );
1969 if ( pthread_mutex_unlock( &_MutexWait ) ) {
1970 perror("pthread_mutex_lock _ReadyWait") ;
1973 cdebug_out << "GraphExecutor::OutNode::ReadyWait" << endl ;
1977 bool GraphExecutor::OutNode::RunningWait() {
1978 cdebug_in << "GraphExecutor::OutNode::RunningWait" << endl;
1980 if ( pthread_mutex_lock( &_MutexWait ) ) {
1981 perror("pthread_mutex_lock _RunningWait") ;
1984 aret = IsRunning() ;
1986 cdebug << "RunningWait pthread_cond_wait _EventWait" << endl;
1987 pthread_cond_wait( &_EventWait , &_MutexWait );
1988 aret = IsRunning() ;
1989 cdebug << "RunningWait pthread_cond_waited _EventWait " << aret << endl;
1991 if ( pthread_mutex_unlock( &_MutexWait ) ) {
1992 perror("pthread_mutex_lock _RunningWait") ;
1995 cdebug_out << "GraphExecutor::OutNode::RunningWait " << aret << endl ;
1999 bool GraphExecutor::OutNode::DoneWait() {
2000 cdebug_in << pthread_self() << " GraphExecutor::DoneWait " << this << " " << Graph()->Name() << endl;
2002 if ( pthread_mutex_lock( &_MutexWait ) ) {
2003 perror("pthread_mutex_lock _DoneWait") ;
2007 while ( !aret && !IsSuspended() && IsRunning() ) {
2008 cdebug << pthread_self() << " GraphExecutor::DoneWait " << this << " " << Graph()->Name()
2009 << " DoneWait pthread_cond_wait _EventWait " << &_EventWait << endl;
2010 pthread_cond_wait( &_EventWait , &_MutexWait );
2012 cdebug << pthread_self() << " GraphExecutor::DoneWait " << this << " " << Graph()->Name()
2013 << " DoneWait pthread_cond_waited _EventWaited " << &_EventWait << " : "<< aret << endl;
2015 if ( pthread_mutex_unlock( &_MutexWait ) ) {
2016 perror("pthread_mutex_lock _DoneWait") ;
2019 cdebug_out << pthread_self() << " GraphExecutor::DoneWait " << this << " " << Graph()->Name()
2020 << " " << State() << " : " << aret << endl ;
2024 bool GraphExecutor::OutNode::SuspendedWait() {
2025 cdebug_in << "GraphExecutor::OutNode::SuspendedWait" << endl;
2027 if ( pthread_mutex_lock( &_MutexWait ) ) {
2028 perror("pthread_mutex_lock _SuspendedWait") ;
2031 aret = IsSuspended() ;
2032 while ( !aret && !IsDone() ) {
2033 pthread_cond_wait( &_EventWait , &_MutexWait );
2034 aret = IsSuspended() ;
2036 if ( pthread_mutex_unlock( &_MutexWait ) ) {
2037 perror("pthread_mutex_lock _SuspendedWait") ;
2040 cdebug_out << "GraphExecutor::OutNode::SuspendedWait" << endl ;
2044 bool GraphExecutor::OutNode::ReadyWait( const char * NodeName ) {
2046 cdebug_in << "GraphExecutor::OutNode::ReadyWait " << NodeName << endl;
2047 GraphExecutor::InNode *anInNode = (GraphExecutor::InNode *) Graph()->GetGraphNode( NodeName )->GetInNode() ;
2049 aret = anInNode->ReadyWait() ;
2051 cdebug_out << "GraphExecutor::OutNode::ReadyWait" << endl ;
2055 bool GraphExecutor::OutNode::RunningWait( const char * NodeName ) {
2057 cdebug_in << "GraphExecutor::OutNode::RunningWait " << NodeName << endl;
2058 GraphExecutor::InNode *anInNode = (GraphExecutor::InNode *) Graph()->GetGraphNode( NodeName )->GetInNode() ;
2060 aret = anInNode->RunningWait() ;
2062 cdebug_out << "GraphExecutor::OutNode::RunningWait" << endl ;
2066 bool GraphExecutor::OutNode::DoneWait( const char * NodeName ) {
2068 cdebug_in << "GraphExecutor::OutNode::DoneWait " << NodeName << endl;
2069 GraphExecutor::InNode *anInNode = (GraphExecutor::InNode *) Graph()->GetGraphNode( NodeName )->GetInNode() ;
2071 aret = anInNode->DoneWait() ;
2073 cdebug_out << "GraphExecutor::OutNode::DoneWait" << endl ;
2077 bool GraphExecutor::OutNode::SuspendedWait( const char * NodeName ) {
2079 cdebug_in << "GraphExecutor::OutNode::SuspendedWait " << NodeName << endl;
2080 GraphExecutor::InNode *anInNode = (GraphExecutor::InNode *) Graph()->GetGraphNode( NodeName )->GetInNode() ;
2082 aret = anInNode->SuspendedWait() ;
2084 cdebug_out << "GraphExecutor::OutNode::SuspendedWait" << endl ;
2088 long GraphExecutor::OutNode::LastLevelDone() {
2091 for ( i = 0 ; i <= Graph()->LevelMax() ; i++ ) {
2092 for ( j = 0 ; j <= Graph()->NodesNumber( i ) ; j++ ) {
2093 GraphBase::ComputingNode * aNode = Graph()->SortedNodes( i , j ) ;
2094 if ( !IsDone( aNode->Name() ) ) {
2098 if ( j != Graph()->NodesNumber( i ) + 1 )
2106 const CORBA::Any *GraphExecutor::OutNode::GetInData( const char * NodeName ,
2107 const char * ServiceParameterName ) {
2108 // cdebug_in << "GraphExecutor::OutNode::GetInData " << NodeName << " "
2109 // << ServiceParameterName << endl ;
2110 const CORBA::Any * retdata = Graph()->PortInData( NodeName , ServiceParameterName ) ;
2111 // cdebug_out << "GraphExecutor::OutNode::GetInData" << endl ;
2115 const CORBA::Any *GraphExecutor::OutNode::GetOutData( const char * NodeName ,
2116 const char * ServiceParameterName ) {
2117 // cdebug_in << "GraphExecutor::OutNode::GetOutData " << NodeName << " "
2118 // << ServiceParameterName << endl ;
2119 const CORBA::Any * retdata = Graph()->PortOutData( NodeName , ServiceParameterName ) ;
2120 // cdebug_out << "GraphExecutor::OutNode::GetOutData" << endl ;
2124 const long GraphExecutor::OutNode::CpuUsed() {
2125 return Graph()->CpuUsed() ;
2128 const long GraphExecutor::OutNode::CpuUsed( const char * aNodeName ) {
2129 GraphBase::ComputingNode * aNode = Graph()->GetChangeGraphNode( aNodeName ) ;
2131 GraphExecutor::InNode * anInNode = (GraphExecutor::InNode * ) aNode->GetInNode() ;
2133 return anInNode->CpuUsed() ;
2139 // remove equal sets "Node-Event-State" from _EventNodes/_Events/_States queues
2140 void GraphExecutor::OutNode::siftEvents() {
2141 list<char*>::reverse_iterator itNodes = _EventNodes.rbegin();
2142 list<GraphExecutor::NodeEvent>::reverse_iterator itEvents = _Events.rbegin();
2143 list<GraphExecutor::AutomatonState>::reverse_iterator itStates = _States.rbegin();
2144 list<char*> _NewEventNodes;
2145 list<GraphExecutor::NodeEvent> _NewEvents;
2146 list<GraphExecutor::AutomatonState> _NewStates;
2147 for ( ; itNodes != _EventNodes.rend() ; ++itNodes, ++itEvents, ++itStates) {
2148 //cout << "----- aNodeName ==> " << *itNodes;
2149 list<char*>::reverse_iterator itNewNodes = _NewEventNodes.rbegin();
2151 for ( ; itNewNodes != _NewEventNodes.rend() ; ++itNewNodes ) {
2152 if ( !strcmp( *itNewNodes, *itNodes ) ) {
2162 _NewEventNodes.push_back( *itNodes );
2163 _NewEvents.push_back( *itEvents );
2164 _NewStates.push_back( *itStates );
2168 _EventNodes = _NewEventNodes;
2169 _Events = _NewEvents;
2170 _States = _NewStates;