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 GraphExecutor::FiniteStateMachine * theAutomaton ;
37 // static const char *ComponentName = "SalomeSuperVisionComponent" ;
40 extern char ** _ArgV ;
42 GraphExecutor::OutNode::OutNode() {
48 _ControlState = SUPERV::VoidState ;
49 _State = GraphExecutor::UnKnownState ;
50 _PyInitialized = false ;
51 pthread_mutex_init( &_MutexWait , NULL ) ;
52 pthread_mutex_init( &_PyMutexWait , NULL ) ;
53 if ( pthread_cond_init( &_EventWait , NULL ) ) {
54 perror("pthread_cond_init( &_EventWait , NULL )") ;
57 if ( pthread_cond_init( &_JoinWait , NULL ) ) {
58 perror("pthread_cond_init( &_JoinWait , NULL )") ;
63 GraphExecutor::OutNode::OutNode( CORBA::ORB_ptr ORB,
64 SALOME_NamingService* ptrNamingService ,
65 const char *DataFlowName ,
66 const char * DebugFileName ,
67 const SUPERV::KindOfNode aKindOfNode ) {
68 // Graph( ORB , ptrNamingService , DataFlowName , DebugFileName ) {
69 Set_prof_debug( ORB , DebugFileName ) ;
70 cdebug_in << "GraphExecutor::OutNode::OutNode(" << DataFlowName << " , " << aKindOfNode << ")" << endl;
71 if ( aKindOfNode == SUPERV::DataFlowGraph ) {
73 // _Graph = new GraphBase::Graph( ORB , ptrNamingService , DataFlowName , DebugFileName ) ;
74 _Graph = new GraphBase::Graph( ORB , ptrNamingService , DataFlowName , aKindOfNode ,
75 _prof_debug , _fdebug ) ;
77 else if ( aKindOfNode == SUPERV::DataStreamGraph ) {
78 // _StreamGraph = new GraphBase::StreamGraph( ORB , ptrNamingService , DataFlowName , DebugFileName ) ;;
79 _StreamGraph = new GraphBase::StreamGraph( ORB , ptrNamingService , DataFlowName , aKindOfNode ,
80 _prof_debug , _fdebug ) ;
81 _Graph = _StreamGraph ;
87 _ControlState = SUPERV::VoidState ;
88 _State = GraphExecutor::UnKnownState ;
89 _PyInitialized = false ;
90 _Orb = CORBA::ORB::_duplicate( ORB ) ;
91 pthread_mutex_init( &_MutexWait , NULL ) ;
92 pthread_mutex_init( &_PyMutexWait , NULL ) ;
93 if ( pthread_cond_init( &_EventWait , NULL ) ) {
94 perror("pthread_cond_init( &_EventWait , NULL )") ;
97 if ( pthread_cond_init( &_JoinWait , NULL ) ) {
98 perror("pthread_cond_init( &_JoinWait , NULL )") ;
101 cdebug_out << "GraphExecutor::OutNode::OutNode" << endl;
104 GraphExecutor::OutNode::OutNode( CORBA::ORB_ptr ORB,
105 SALOME_NamingService* ptrNamingService ,
106 const SALOME_ModuleCatalog::Service& DataFlowService ,
107 const char *DataFlowComponentName ,
108 const char *DataFlowInterfaceName ,
109 const char *DataFlowName ,
110 const SUPERV::KindOfNode DataFlowkind ,
111 const SUPERV::SDate DataFlowFirstCreation ,
112 const SUPERV::SDate DataFlowLastModification ,
113 const char * DataFlowEditorRelease ,
114 const char * DataFlowAuthor ,
115 const char * DataFlowComputer ,
116 const char * DataFlowComment ,
117 const char * DebugFileName ) {
118 // Graph( ORB , ptrNamingService , DataFlowService , DataFlowComponentName ,
119 // DataFlowInterfaceName , DataFlowName , DataFlowkind ,
120 // DataFlowFirstCreation , DataFlowLastModification ,
121 // DataFlowEditorRelease , DataFlowAuthor ,
122 // DataFlowComputer , DataFlowComment , DebugFileName ) {
123 Set_prof_debug( ORB , DebugFileName ) ;
125 cdebug_in << "GraphExecutor::OutNode::OutNode(" << DataFlowName << " , " << DataFlowkind << ")" << endl;
126 if ( DataFlowkind == SUPERV::DataFlowGraph ) {
127 _StreamGraph = NULL ;
128 _Graph = new GraphBase::Graph( ORB , ptrNamingService , DataFlowService , DataFlowComponentName ,
129 DataFlowInterfaceName , DataFlowName , DataFlowkind ,
130 DataFlowFirstCreation , DataFlowLastModification ,
131 DataFlowEditorRelease , DataFlowAuthor ,
132 DataFlowComputer , DataFlowComment ,
133 _prof_debug , _fdebug ) ;
134 // DataFlowComputer , DataFlowComment , DebugFileName ) ;
136 else if ( DataFlowkind == SUPERV::DataStreamGraph ) {
137 _StreamGraph = new GraphBase::StreamGraph( ORB , ptrNamingService , DataFlowService , DataFlowComponentName ,
138 DataFlowInterfaceName , DataFlowName , DataFlowkind ,
139 DataFlowFirstCreation , DataFlowLastModification ,
140 DataFlowEditorRelease , DataFlowAuthor ,
141 DataFlowComputer , DataFlowComment ,
142 _prof_debug , _fdebug ) ;
143 _Graph = _StreamGraph ;
146 _Executable = false ;
149 _ControlState = SUPERV::VoidState ;
150 _State = GraphExecutor::UnKnownState ;
151 _PyInitialized = false ;
152 _Orb = CORBA::ORB::_duplicate( ORB ) ;
153 pthread_mutex_init( &_MutexWait , NULL ) ;
154 pthread_mutex_init( &_PyMutexWait , NULL ) ;
155 if ( pthread_cond_init( &_EventWait , NULL ) ) {
156 perror("pthread_cond_init( &_EventWait , NULL )") ;
159 if ( pthread_cond_init( &_JoinWait , NULL ) ) {
160 perror("pthread_cond_init( &_JoinWait , NULL )") ;
165 GraphExecutor::OutNode::~OutNode() {
168 void GraphExecutor::OutNode::Set_prof_debug( CORBA::ORB_ptr ORB ,
169 const char * DebugFileName ) {
170 _Graph_prof_debug = 0 ;
171 if ( DebugFileName ) {
172 _fdebug = new ofstream( DebugFileName );
173 SetDebug( ORB , &_Graph_prof_debug , _fdebug ) ;
174 MESSAGE( endl << "Trace redirected to file " << DebugFileName << endl)
178 bool GraphExecutor::OutNode::LoadDataFlow(const GraphBase::SGraph * aDataFlow ) {
179 bool RetVal = false ;
180 cdebug_in << "GraphExecutor::OutNode::LoadDataFlow " << (*aDataFlow).Info.theName << endl ;
181 RetVal = LoadInfo( (*aDataFlow).Info ) ;
182 if ( Graph()->ServiceName() != NULL ) {
183 // MESSAGE( "GraphExecutor::OutNode::LoadDataFlow" );
185 RetVal = LoadNodes( (*aDataFlow).Nodes ) ;
187 RetVal = LoadLinks( (*aDataFlow).Links ) ;
190 RetVal = LoadDatas( (*aDataFlow).Datas ) ;
193 cdebug << "GraphExecutor::OutNode::LoadDataFlow LoadDatas Error."
198 cdebug << "GraphExecutor::OutNode::LoadDataFlow LoadLinks Error."
203 cdebug << "GraphExecutor::OutNode::LoadDataFlow LoadNodes Error."
208 cdebug << "GraphExecutor::OutNode::LoadDataFlow LoadInfo Error."
213 cdebug << "GraphExecutor::OutNode::LoadDataFlow ServiceName Error." << endl ;
215 cdebug_out << "GraphExecutor::OutNode::LoadDataFlow " << Graph()->Name() << " RetVal "
221 bool GraphExecutor::OutNode::LoadXml( const char* myFileName ) {
222 bool RetVal = false ;
223 GraphBase::ListOfSGraphs aListOfDataFlows ;
224 if ( Graph()->LoadXml( _Orb , myFileName , aListOfDataFlows ) ) {
225 RetVal = LoadDataFlow( aListOfDataFlows ) ;
226 // if ( aConstructor && RetVal )
227 // RetVal = Name( aDataFlow.Info.theName.c_str() ) ;
233 bool GraphExecutor::OutNode::LoadInfo(const GraphBase::SNode &aDataFlowInfo ) {
234 cdebug << "GraphExecutor::OutNode::LoadInfo _StreamGraph " << _StreamGraph << endl ;
235 // ComponentName( aDataFlowInfo.theComponentName.c_str() ) ;
236 Graph()->Name( aDataFlowInfo.theName.c_str() ) ;
237 Graph()->Kind( aDataFlowInfo.theKind ) ;
238 if ( Graph()->IsDataStreamNode() && aDataFlowInfo.theKind == SUPERV::DataStreamGraph ) {
239 StreamGraph()->SetStreamParams( aDataFlowInfo.theTimeout , aDataFlowInfo.theDataStreamTrace , aDataFlowInfo.theDeltaTime ) ;
241 Graph()->DataService( _Orb , aDataFlowInfo.theService , _prof_debug , _fdebug ) ;
242 Graph()->FirstCreation( aDataFlowInfo.theFirstCreation ) ;
243 Graph()->LastModification( aDataFlowInfo.theLastModification ) ;
244 Graph()->EditorRelease( aDataFlowInfo.theEditorRelease.c_str() ) ;
245 Graph()->Author( aDataFlowInfo.theAuthor.c_str() ) ;
246 // Graph()->Computer( aDataFlowInfo.theContainer.c_str() ) ;
247 Graph()->Comment( aDataFlowInfo.theComment.c_str() ) ;
248 // Not in OutNode/DataFlow but in InNode/DataFlow_in_an_other_DataFlow
249 // Graph()->Coordinates( aDataFlowInfo.theX , aDataFlowInfo.theY ) ;
253 bool GraphExecutor::OutNode::LoadNodes(const GraphBase::ListOfSNodes &aListOfNodes ) {
255 GraphExecutor::InNode * anInNode ;
256 cdebug << "GraphExecutor::OutNode::LoadNodes" << endl ;
258 for ( i = 0 ; i < (int ) aListOfNodes.size() ; i++ ) {
259 GraphBase::SNode aNode = aListOfNodes[ i ] ;
260 anInNode = AddNode( aNode.theService ,
261 aNode.theListOfFuncName ,
262 aNode.theListOfPythonFunctions ,
263 aNode.theComponentName.c_str() ,
264 aNode.theInterfaceName.c_str() , aNode.theName.c_str() ,
266 aNode.theFirstCreation , aNode.theLastModification ,
267 aNode.theEditorRelease.c_str() ,
268 aNode.theAuthor.c_str() , aNode.theContainer.c_str() ,
269 aNode.theComment.c_str() ,
270 aNode.theCoords.theX , aNode.theCoords.theY ) ;
275 if ( anInNode->IsOneOfInLineNodes() || anInNode->IsMacroNode() ) {
276 anInNode->GraphExecutor::InNode::InLineNode()->DefPortsOfNode(
277 _Orb , aNode.theService , anInNode->NamePtr() ,
279 _prof_debug , _fdebug ) ;
281 // GraphBase::ComputingNode * theNode = Graph()->GetChangeGraphNode( aNode.theName.c_str() ) ;
284 for ( j = 0 ; j < aNode.theListOfInDataStreams.size() ; j++ ) {
285 GraphBase::InPort * anInPort ;
286 anInPort = anInNode->ComputingNode()->AddInDataStreamPort( aNode.theListOfInDataStreams[ j ].theDataStreamParameter.Parametername ,
287 aNode.theListOfInDataStreams[ j ].theDataStreamParameter.Parametertype ,
288 aNode.theListOfInDataStreams[ j ].theDataStreamParameter.Parameterdependency ,
289 SUPERV::DataStreamParameter ) ;
290 ((GraphBase::InDataStreamPort * ) anInPort)->SetParams( aNode.theListOfInDataStreams[ j ].theKindOfSchema ,
291 aNode.theListOfInDataStreams[ j ].theKindOfInterpolation ,
292 aNode.theListOfInDataStreams[ j ].theKindOfExtrapolation ) ;
294 for ( j = 0 ; j < aNode.theListOfOutDataStreams.size() ; j++ ) {
295 GraphBase::OutPort * anOutPort ;
296 anOutPort = anInNode->ComputingNode()->AddOutDataStreamPort( aNode.theListOfOutDataStreams[ j ].theDataStreamParameter.Parametername ,
297 aNode.theListOfOutDataStreams[ j ].theDataStreamParameter.Parametertype ,
298 aNode.theListOfOutDataStreams[ j ].theDataStreamParameter.Parameterdependency ,
299 SUPERV::DataStreamParameter ) ;
300 ((GraphBase::OutDataStreamPort * ) anOutPort)->NumberOfValues( aNode.theListOfOutDataStreams[ j ].theNumberOfValues ) ;
304 // theNode->DataStreamInPortsNumber( aNode.theDataStreamInArgsNumber ) ;
305 // theNode->DataStreamOutPortsNumber( aNode.theDataStreamOutArgsNumber ) ;
306 // cdebug << "GraphExecutor::OutNode::LoadNodes " << anInNode->Name()
307 // << " InPortsSize " << theNode->GetNodeInPortsSize()
308 // << " OutPortsSize " << theNode->GetNodeOutPortsSize()
309 // << " DataStreamInPortsNumber " << aNode.theDataStreamInArgsNumber
310 // << " DataStreamOutPortsNumber " << aNode.theDataStreamOutArgsNumber
313 // if ( aNode.theDataStreamInArgsNumber ) { // -1 because of Gates
314 // for ( j = theNode->GetNodeInPortsSize() - aNode.theDataStreamInArgsNumber - 1 ; j < theNode->GetNodeInPortsSize() - 1 ; j++ ) {
315 // cdebug << "GraphExecutor::OutNode::LoadNodes " << anInNode->Name()
316 // << " InPort " << theNode->GetChangeNodeInPort( j )->PortName()
317 // << " Kind( DataStreamParameter)" << endl ;
318 // theNode->GetChangeNodeInPort( j )->Kind( SUPERV::DataStreamParameter ) ;
321 // if ( aNode.theDataStreamOutArgsNumber ) {
322 // int withgate = 1 ;
323 // if ( theNode->IsLoopNode() || theNode->IsEndLoopNode() ) {
326 // for ( j = theNode->GetNodeOutPortsSize() - aNode.theDataStreamOutArgsNumber - withgate ; j < theNode->GetNodeOutPortsSize() - withgate ; j++ ) {
327 // cdebug << "GraphExecutor::OutNode::LoadNodes " << anInNode->Name()
328 // << " OutPort " << theNode->GetChangeNodeOutPort( j )->PortName()
329 // << " Kind( DataStreamParameter)" << endl ;
330 // theNode->GetChangeNodeOutPort( j )->Kind( SUPERV::DataStreamParameter ) ;
334 for ( i = 0 ; i < (int ) aListOfNodes.size() ; i++ ) {
335 GraphBase::SNode aNode = aListOfNodes[ i ] ;
336 anInNode = (GraphExecutor::InNode * ) Graph()->GetChangeGraphNode( aNode.theName.c_str() )->GetInNode() ;
337 cdebug << "GraphExecutor::OutNode::LoadNodes " << anInNode->Name() << " IsOneOfGOTONodes "
338 << anInNode->IsOneOfGOTONodes() << " " << aNode.theCoupledNode.c_str() << endl ;
339 if ( anInNode->IsOneOfGOTONodes() && strlen( aNode.theCoupledNode.c_str() ) ) {
340 GraphBase::GOTONode * aCoupledNode ;
341 aCoupledNode = (GraphBase::GOTONode * ) Graph()->GetGraphNode( aNode.theName.c_str() ) ;
342 GraphBase::GOTONode * aCoupledCoupledNode ;
343 aCoupledCoupledNode = (GraphBase::GOTONode * ) Graph()->GetChangeGraphNode( aNode.theCoupledNode.c_str() ) ;
344 if ( aCoupledCoupledNode != NULL ) {
345 aCoupledNode->CoupledNode( aCoupledCoupledNode ) ;
348 aCoupledNode->CoupledNodeName( aNode.theCoupledNode.c_str() ) ;
355 bool GraphExecutor::OutNode::LoadLinks(const GraphBase::ListOfSLinks &aListOfLinks ) {
357 cdebug << "GraphExecutor::OutNode::LoadLinks " << aListOfLinks.size()
360 for ( i = 0 ; i < (int ) aListOfLinks.size() ; i++ ) {
361 GraphBase::SLink aLink = aListOfLinks[ i ] ;
362 RetVal = Graph()->AddLink( aLink.FromNodeName.c_str() ,
363 aLink.FromServiceParameterName.c_str() ,
364 aLink.ToNodeName.c_str() ,
365 aLink.ToServiceParameterName.c_str() ) ;
366 // , aLink.aLinkValue ) ;
373 bool GraphExecutor::OutNode::LoadDatas(const GraphBase::ListOfSLinks &aListOfDatas ) {
375 cdebug << "GraphExecutor::OutNode::LoadDatas " << aListOfDatas.size()
378 for ( i = 0 ; i < (int ) aListOfDatas.size() ; i++ ) {
379 GraphBase::SLink aLink = aListOfDatas[ i ] ;
380 if ( !strcmp( aLink.FromNodeName.c_str() , Graph()->Name() ) )
381 RetVal = Graph()->AddInputData( aLink.ToNodeName.c_str() ,
382 aLink.ToServiceParameterName.c_str() ,
384 // else if ( !strcmp( aLink.ToNodeName.c_str() , Graph()->Name() ) ) {
385 // RetVal = Graph()->AddOutputData( aLink.FromNodeName.c_str() ,
386 // aLink.FromServiceParameterName.c_str() ) ;
387 // Graph()->AddLink( aLink.FromNodeName.c_str() , (GraphBase::ComputingNode *) this ) ;
390 cdebug << "GraphExecutor::OutNode::LoadDatas Error " << aLink.FromNodeName
391 << " and " << aLink.ToNodeName << " differents from " << Graph()->Name()
401 GraphExecutor::InNode *GraphExecutor::OutNode::AddNode(
402 const SALOME_ModuleCatalog::Service& NodeService ,
403 GraphBase::ListOfFuncName aFuncName ,
404 GraphBase::ListOfPythonFunctions aPythonFunction ,
405 const char * NodeComponentName ,
406 const char * NodeInterfaceName ,
407 const char * NodeName ,
408 const SUPERV::KindOfNode NodeKindOfNode ,
409 const SUPERV::SDate NodeFirstCreation ,
410 const SUPERV::SDate NodeLastModification ,
411 const char * NodeEditorRelease ,
412 const char * NodeAuthor ,
413 const char * NodeComputer ,
414 const char * NodeComment ,
417 cdebug_in << "GraphExecutor::OutNode::AddNode(" << NodeComponentName << " , "
418 << NodeName << ")" << endl;
419 GraphExecutor::InNode *Nd = NULL ;
420 Nd = new GraphExecutor::InNode( _Orb, Graph()->NamingService() , NodeService ,
421 NodeComponentName , NodeInterfaceName ,
422 NodeName , NodeKindOfNode ,
423 aFuncName , aPythonFunction ,
424 NodeFirstCreation , NodeLastModification ,
425 NodeEditorRelease , NodeAuthor ,
426 NodeComputer , NodeComment , false , NodeX , NodeY ,
427 _prof_debug , _fdebug ) ;
428 Graph()->AddNode( Nd->ComputingNode() ) ;
429 cdebug_out << "GraphExecutor::OutNode::AddNode" << endl;
434 bool GraphExecutor::OutNode::Valid() {
435 cdebug_in << "GraphExecutor::OutNode::Valid" << endl;
440 _Executable = false ;
442 if ( !Graph()->CreateService() ) {
443 cdebug << "This DataFlow has invalid type(s)." << endl ;
446 int SubStreamGraphsNumber = 0 ;
447 if ( !Graph()->Sort( SubStreamGraphsNumber ) ) {
448 cdebug << "This DataFlow is not valid." << endl ;
451 if ( Graph()->IsDataStreamNode() ) {
452 StreamGraph()->SubStreamGraphsNumber( SubStreamGraphsNumber ) ;
457 Graph()->InLineServices() ;
459 Graph()->ComputingNodes() ;
463 cdebug_out << "GraphExecutor::OutNode::Valid" << endl;
468 bool GraphExecutor::OutNode::Executable() {
470 cdebug_in << "GraphExecutor::OutNode::Executable" << endl;
474 if ( Graph()->DataServerNodes() )
477 cdebug << "This DataFlow is not executable." << endl ;
478 _Executable = false ;
481 cdebug_out << "GraphExecutor::OutNode::Executable " << _Executable << endl;
485 bool GraphExecutor::OutNode::Run( const bool AndSuspend ) {
486 bool RetVal = false ;
487 cdebug_in << "GraphExecutor::OutNode::Run( AndSuspend " << AndSuspend << " )" << endl;
489 if ( Executable() ) {
490 _ControlState = SUPERV::VoidState ;
491 _SuspendedThreads = 0 ;
492 Graph()->ThreadNo( pthread_self() ) ;
494 _JustStarted = true ;
497 for ( i = 0 ; i < Graph()->GraphNodesSize() ; i++ ) {
498 GraphExecutor::InNode * anInNode = (GraphExecutor::InNode *) Graph()->GraphNodes( i )->GetInNode() ;
499 if ( !PyInitialized() && anInNode->IsOneOfInLineNodes() ) {
500 if ( !Py_IsInitialized() ) {
502 PySys_SetArgv( _ArgC , _ArgV ) ;
504 anInNode->InitPython() ;
505 PyInitialized( true ) ;
507 anInNode->InitialState( this ) ;
508 if ( anInNode->IsOneOfInLineNodes() ) {
509 anInNode->InitPythonFunctions( false ) ;
512 // One more time because inline nodes may share one definition of the same function
513 for ( i = 0 ; i < Graph()->GraphNodesSize() ; i++ ) {
514 GraphExecutor::InNode * anInNode = (GraphExecutor::InNode *) Graph()->GraphNodes( i )->GetInNode() ;
515 if ( anInNode->IsOneOfInLineNodes() ) {
516 if ( !anInNode->InitPythonFunctions( true ) ) {
517 anInNode->State( GraphExecutor::ErroredState ) ;
518 State( GraphExecutor::ErroredState ) ;
519 cdebug_out << "GraphExecutor::OutNode::Run InitPythonFunctions ERROR "
520 << anInNode->Name() << endl ;
525 /* asv : 29.09.04 : commented out because it does not do anything useful
526 for ( i = 0 ; i < Graph()->GraphNodesSize() ; i++ ) {
527 GraphExecutor::InNode * anInNode = (GraphExecutor::InNode *) Graph()->GraphNodes( i )->GetInNode() ;
528 if ( RetVal && anInNode->IsMacroNode() ) {
529 GraphBase::Graph * aMacroGraph = anInNode->GraphMacroNode() ;
530 cdebug << "GraphExecutor::OutNode::Run " << anInNode << " MacroNode " << aMacroGraph
531 << aMacroGraph->Name() << endl ;
532 SUPERV::Graph_var iobject = anInNode->GraphMacroNode()->MacroObject() ;
533 if ( CORBA::is_nil( iobject ) ) {
534 cdebug << "GraphExecutor::OutNode::Run MacroObject() is a nil object. Error" << endl ;
538 cdebug << "GraphExecutor::OutNode::Run MacroObject() is NOT a nil object." << endl ;
543 if ( Graph()->GraphMacroLevel() != 0 ) {
544 cdebug << "GraphExecutor::OutNode::Run Execution starting GraphExecutor::Action_DataOk_RunService Node "
545 << Graph()->Name() << " GraphMacroLevel " << Graph()->GraphMacroLevel() << endl ;
546 PushEvent( NULL , GraphExecutor::NoDataReadyEvent ,
547 GraphExecutor::DataUndefState ) ;
550 cdebug << "Execution starting GraphExecutor::Action_DataOk_RunService Node "
551 << Graph()->Name() << " GraphMacroLevel " << Graph()->GraphMacroLevel() << endl ;
552 PushEvent( NULL , GraphExecutor::ReadyEvent ,
553 GraphExecutor::DataReadyState ) ;
554 State( GraphExecutor::DataReadyState ) ;
556 cdebug << pthread_self() << " GraphExecutor::OutNode::Run Start of the " << Graph()->HeadNodesSize()
557 << " HeadNodes" << endl ;
558 for ( i = 0 ; i < Graph()->HeadNodesSize() ; i++ ) {
559 GraphExecutor::InNode * anInNode = (GraphExecutor::InNode *) Graph()->HeadNodes( i )->GetInNode() ;
560 cdebug << pthread_self() << "GraphExecutor::OutNode::Run Start of HeadNode " << i << " "
561 << anInNode->Name() << endl ;
562 if ( anInNode->State() != GraphExecutor::DataReadyState ) {
563 cdebug << "GraphExecutor::OutNode::Run inconsistency State of Node "
564 << anInNode->Name() << " : " << anInNode->State() << endl ;
565 cdebug_out << "GraphExecutor::OutNode::Run State ERROR" << endl ;
568 // PushEvent( anInNode , GraphExecutor::ReadyEvent ,
569 // GraphExecutor::DataReadyState ) ;
570 anInNode->CreateNewThread( true ) ;
571 anInNode->DataFromNode( Graph()->Name() ) ;
573 anInNode->State( GraphExecutor::DataWaitingState ) ;
574 anInNode->ControlState( SUPERV::ToSuspendStartState ) ;
575 if ( !anInNode->SendEvent( GraphExecutor::SomeDataReadyEvent ) ) {
576 cdebug << "InNode::SendEvent( SomeDataReadyEvent ) ERROR Node "
577 << anInNode->Name() << endl ;
578 cdebug_out << "GraphExecutor::OutNode::Run SendEvent ERROR" << endl ;
581 anInNode->SuspendedWait() ;
583 else if ( anInNode->IsMacroNode() ) {
584 if ( !anInNode->SendEvent( GraphExecutor::SomeDataReadyEvent ) ) {
585 cdebug << "InNode::SendEvent( SomeDataReadyEvent ) ERROR Node "
586 << anInNode->Name() << endl ;
587 cdebug_out << "GraphExecutor::OutNode::Run SendEvent ERROR" << endl ;
590 cdebug << pthread_self() << " GraphExecutor::OutNode::Run " << anInNode->Name() << "->RunningWait"
592 anInNode->RunningWait() ;
593 cdebug << pthread_self() << " GraphExecutor::OutNode::Run " << anInNode->Name() << "->RunningWaited"
596 else if ( !anInNode->IsMacroNode() ) {
597 if ( !anInNode->SendEvent( GraphExecutor::ExecuteEvent ) ) {
598 cdebug << "InNode::SendEvent( ExecuteEvent ) ERROR Node "
599 << anInNode->Name() << endl ;
600 cdebug_out << "GraphExecutor::OutNode::Run SendEvent ERROR" << endl ;
603 anInNode->RunningWait() ;
608 PushEvent( NULL , GraphExecutor::SuspendedReadyEvent ,
609 GraphExecutor::SuspendedReadyState ) ;
612 PushEvent( NULL , GraphExecutor::ExecutingEvent ,
613 GraphExecutor::ExecutingState ) ;
614 if (AutomatonState() == GraphExecutor::DataReadyState) {
615 State( GraphExecutor::ExecutingState ) ;
618 // ostringstream astr ;
619 // astr << "Graph " << Graph()->Name() << " is running" ;
620 // Graph()->ObjImpl()->sendMessage( NOTIF_STEP, astr.str().c_str() ) ;
625 cdebug_out << "GraphExecutor::OutNode::Run " << Graph()->Name() << " GraphMacroLevel "
626 << Graph()->GraphMacroLevel() << " RetVal " << RetVal << endl ;
630 bool GraphExecutor::OutNode::Run( const char * aNodeName ,
631 const char * AtNodeName ,
632 const bool AndSuspend ) {
633 bool RetVal = false ;
634 cdebug_in << "GraphExecutor::OutNode::Run( " << aNodeName << " , "
635 << AtNodeName << " , " << AndSuspend << ")" << endl;
636 GraphExecutor::InNode *anInNode = (GraphExecutor::InNode *) Graph()->GetGraphNode( aNodeName )->GetInNode() ;
638 RetVal = anInNode->ReStart( AtNodeName , AndSuspend ) ;
640 cdebug_out << "GraphExecutor::OutNode::Run" << endl ;
644 void GraphExecutor::OutNode::CheckAllDone() {
646 cdebug_in << "GraphExecutor::OutNode::CheckAllDone " << endl;
647 GraphExecutor::AutomatonState OutNodeState = GraphExecutor::SuccessedState ;
648 GraphExecutor::AutomatonState InNodeState ;
649 bool AllDone = true ;
651 for ( j = 0 ; j < Graph()->QueueNodesSize() ; j++ ) {
652 InNodeState = ( (GraphExecutor::InNode * ) Graph()->QueueNodes( j )->GetInNode() )->State() ;
654 << ( (GraphExecutor::InNode * ) Graph()->QueueNodes( j )->GetInNode() )->Name()
655 << " " << theAutomaton->StateName( InNodeState ) << endl ;
656 if ( InNodeState != GraphExecutor::SuccessedState &&
657 InNodeState != GraphExecutor::ErroredState &&
658 InNodeState != GraphExecutor::DataWaitingState ) {
661 if ( InNodeState != GraphExecutor::SuccessedState &&
662 InNodeState != GraphExecutor::DataWaitingState &&
663 InNodeState != GraphExecutor::DataReadyState ) {
664 OutNodeState = InNodeState ;
668 if( _Threads == 0 && _SuspendedThreads == 0 ) {
669 if ( OutNodeState != GraphExecutor::ErroredState ) {
670 OutNodeState = GraphExecutor::SuccessedState ;
679 for ( j = 0 ; j < Graph()->GraphNodesSize() ; j++ ) {
680 GraphExecutor::InNode * aNode ;
681 aNode = (GraphExecutor::InNode * ) Graph()->GraphNodes( j )->GetInNode() ;
682 SUPERV::GraphState aState = AutomatonGraphState( aNode->State() ) ;
683 cdebug << "GraphExecutor::OutNode::CheckAllDone " << aNode->Name() << " "
684 << theAutomaton->StateName( aNode->State() ) << " CreateNewThread " << aNode->CreateNewThread()
686 if ( aState == SUPERV::ErrorState ||
687 aState == SUPERV::SuspendErroredState ||
688 aState == SUPERV::KillState ||
689 aState == SUPERV::StopState ) {
690 OutNodeState = aNode->State() ;
691 State( OutNodeState ) ;
693 else if ( aState == SUPERV::ReadyState ||
694 aState == SUPERV::SuspendReadyState ||
695 aState == SUPERV::RunningState ||
696 aState == SUPERV::SuspendDoneState ||
697 aState == SUPERV::SuspendErroredState ||
698 aState == SUPERV::ReRunState ||
699 aState == SUPERV::ReStartState ||
700 aState == SUPERV::SuspendState ) {
703 aNode->SuspendedAction() ;
704 aNode->DoneAction() ;
706 // PushEvent AFTER State and _Done ! ...
707 if ( alivenodes == 0 ) {
708 State( OutNodeState ) ;
710 _JustStarted = false ;
712 cdebug << Graph()->Name() << " alivenodes " << alivenodes << " OutNodeState " << OutNodeState
714 PushEvent( NULL , GraphExecutor::EndExecuteEvent ,
717 // PyInitialized( false ) ;
721 MESSAGE("================================================================================") ;
722 MESSAGE( Graph()->Name() << " IS DONE : " << theAutomaton->StateName( AutomatonState() ) << " EventQSize "
724 MESSAGE("================================================================================") ;
725 cdebug << "================================================================================" << endl ;
726 cdebug << Graph()->Name() << " IS DONE : " << theAutomaton->StateName( AutomatonState() ) << " EventQSize "
727 << EventQSize() << endl ;
728 cdebug << "================================================================================" << endl ;
730 // asv : fix for 6798 and other bugs: "sift" the event queue after execution
733 // asv : 25.10.04 : calling Editing() to indicate stop of execution
734 Graph()->GraphEditor()->Editing();
736 cdebug_out << "GraphExecutor::OutNode::CheckAllDone " << IsDone() << " this " << this << " "
737 << Graph()->Name() << " GraphAutomatonState "
738 << theAutomaton->StateName( AutomatonState() )
739 << " State " << State() << " Threads " << _Threads << " SuspendedThreads "
740 << _SuspendedThreads << " EventQSize " << EventQSize() << endl ;
743 void GraphExecutor::OutNode::PThreadLock( pthread_mutex_t * aMutex , char * errmsg ) {
744 // if ( strcmp( errmsg , "EventLoop" ) && strcmp( errmsg , "EventW" ) ) {
745 // cdebug << "GraphExecutor::OutNode::PThreadLock " << pthread_self() << " " << aMutex << " "
746 // << errmsg << endl ;
748 if ( pthread_mutex_lock( aMutex ) ) {
752 // if ( strcmp( errmsg , "EventLoop" ) && strcmp( errmsg , "EventW" ) ) {
753 // cdebug << "GraphExecutor::OutNode::PThreadLocked " << pthread_self() << " " << aMutex << " "
754 // << errmsg << endl ;
758 void GraphExecutor::OutNode::PThreadUnLock( pthread_mutex_t * aMutex , char * errmsg ) {
759 // if ( strcmp( errmsg , "EventLoop" ) && strcmp( errmsg , "EventW" ) ) {
760 // cdebug << " GraphExecutor::OutNode::PThreadUnLock " << pthread_self() << " " << aMutex << " "
761 // << errmsg << endl ;
763 if ( pthread_mutex_unlock( aMutex ) ) {
769 void GraphExecutor::OutNode::PyThreadLock() {
770 // cout << " GraphExecutor::OutNode::PyThreadLock " << pthread_self() << endl ;
771 if ( pthread_mutex_lock( &_PyMutexWait ) ) {
772 perror( "GraphExecutor::OutNode::PyThreadLock" ) ;
775 theAutomaton->PyLock() ;
776 // cout << " GraphExecutor::OutNode::PyThreadLocked " << pthread_self() << endl ;
779 void GraphExecutor::OutNode::PyThreadUnLock() {
780 // cout << " GraphExecutor::OutNode::PyThreadUnLock " << pthread_self() << endl ;
781 if ( pthread_mutex_unlock( &_PyMutexWait ) ) {
782 perror( "GraphExecutor::OutNode::PyThreadUnLock" ) ;
785 theAutomaton->PyUnLock() ;
786 // cout << " GraphExecutor::OutNode::PyThreadUnLocked " << pthread_self() << endl ;
789 void GraphExecutor::OutNode::NewThread() {
790 if ( pthread_mutex_lock( &_MutexWait ) ) {
791 perror("pthread_mutex_lock _NewThread") ;
795 cdebug << "NewThread : " << _Threads << " running threads "
796 << _SuspendedThreads << " suspended threads"
798 if ( pthread_mutex_unlock( &_MutexWait ) ) {
799 perror("pthread_mutex_unlock _NewThread") ;
804 void GraphExecutor::OutNode::ExitThread( pthread_t ThreadNumber ) {
805 if ( pthread_mutex_lock( &_MutexWait ) ) {
806 perror("pthread_mutex_lock _ExitThread") ;
809 if ( ThreadNumber == 0 ) {
810 ThreadNumber = pthread_self() ;
813 cdebug << pthread_self() << " ExitThread( " << ThreadNumber << " ) " << _Threads << " running threads "
814 << _SuspendedThreads << " suspended threads"
816 theAutomaton->JoinThread( ThreadNumber ) ;
817 if ( pthread_cond_signal( &_JoinWait ) ) {
818 perror("ExitThread pthread_cond_signal ") ;
820 if ( pthread_mutex_unlock( &_MutexWait ) ) {
821 perror("pthread_mutex_unlock _ExitThread") ;
824 if ( _Threads == 0 && _SuspendedThreads == 0 ) {
827 theAutomaton->Executed() ;
831 void GraphExecutor::OutNode::JoinedWait() {
832 if ( pthread_mutex_lock( &_MutexWait ) ) {
833 perror("pthread_mutex_lock JoinedWait") ;
837 if ( pthread_cond_wait( &_JoinWait , &_MutexWait ) ) {
838 perror("JoinedWait pthread_cond_wait ") ;
841 if ( pthread_mutex_unlock( &_MutexWait ) ) {
842 perror("pthread_mutex_unlock JoinedWait") ;
847 void GraphExecutor::OutNode::SuspendThread() {
848 if ( pthread_mutex_lock( &_MutexWait ) ) {
849 perror("pthread_mutex_lock _SuspendThread") ;
852 _SuspendedThreads += 1 ;
853 cdebug << "SuspendThread : " << _Threads << " running threads "
854 << _SuspendedThreads << " suspended threads"
856 if ( pthread_mutex_unlock( &_MutexWait ) ) {
857 perror("pthread_mutex_unlock _SuspendThread") ;
860 if ( IsSuspended() ) {
861 PushEvent( NULL , GraphExecutor::SuspendEvent , GraphExecutor::SuspendedState ) ;
864 void GraphExecutor::OutNode::ResumeThread() {
865 if ( pthread_mutex_lock( &_MutexWait ) ) {
866 perror("pthread_mutex_lock _ResumeThread") ;
869 _SuspendedThreads -= 1 ;
870 cdebug << "ResumeThread : " << _Threads << " running threads "
871 << _SuspendedThreads << " suspended threads"
873 if ( pthread_mutex_unlock( &_MutexWait ) ) {
874 perror("pthread_mutex_unlock _ResumeThread") ;
879 long GraphExecutor::OutNode::Thread( const char * aNodeName ) {
881 GraphExecutor::InNode *anInNode = (GraphExecutor::InNode *) Graph()->GetGraphNode( aNodeName )->GetInNode() ;
883 RetVal = anInNode->ThreadNo() ;
888 SUPERV::GraphEvent GraphExecutor::OutNode::AutomatonGraphEvent(GraphExecutor::NodeEvent anEvent ) {
889 SUPERV::GraphEvent aGraphEvent ;
891 case GraphExecutor::UndefinedEvent : {
892 aGraphEvent = SUPERV::UndefinedEvent ;
895 case GraphExecutor::NewThreadEvent : {
896 aGraphEvent = SUPERV::NewThreadEvent ;
899 case GraphExecutor::SuspendEvent : {
900 aGraphEvent = SUPERV::SuspendEvent ;
903 case GraphExecutor::ResumeEvent : {
904 aGraphEvent = SUPERV::ResumeEvent ;
907 case GraphExecutor::KillEvent : {
908 aGraphEvent = SUPERV::KillEvent ;
911 case GraphExecutor::StopEvent : {
912 aGraphEvent = SUPERV::StopEvent ;
915 case GraphExecutor::ExecuteEvent : {
916 aGraphEvent = SUPERV::RunningEvent ;
919 case GraphExecutor::SuccessEvent : {
920 aGraphEvent = SUPERV::DoneEvent ;
923 case GraphExecutor::ErrorEvent : {
924 aGraphEvent = SUPERV::ErroredEvent ;
927 case GraphExecutor::ReStartEvent : {
928 aGraphEvent = SUPERV::ReRunEvent ;
931 case GraphExecutor::ReStartAndSuspendEvent : {
932 aGraphEvent = SUPERV::ReStartEvent ;
935 case GraphExecutor::NoDataReadyEvent : {
936 aGraphEvent = SUPERV::WaitingEvent ;
939 case GraphExecutor::SomeDataReadyEvent : {
940 aGraphEvent = SUPERV::WaitingEvent ;
943 case GraphExecutor::NotAllDataReadyEvent : {
944 aGraphEvent = SUPERV::WaitingEvent ;
947 case GraphExecutor::AllDataReadyEvent : {
948 aGraphEvent = SUPERV::ReadyEvent ;
951 case GraphExecutor::ReadyEvent : {
952 aGraphEvent = SUPERV::ReadyEvent ;
955 case GraphExecutor::SuspendedReadyEvent : {
956 aGraphEvent = SUPERV::SuspendEvent ;
959 case GraphExecutor::ResumedReadyEvent : {
960 aGraphEvent = SUPERV::ResumeEvent ;
963 case GraphExecutor::KilledReadyEvent : {
964 aGraphEvent = SUPERV::KillEvent ;
967 case GraphExecutor::StoppedReadyEvent : {
968 aGraphEvent = SUPERV::StopEvent ;
971 case GraphExecutor::ExecutingEvent : {
972 aGraphEvent = SUPERV::RunningEvent ;
975 case GraphExecutor::SuspendedExecutingEvent : {
976 aGraphEvent = SUPERV::SuspendEvent ;
979 case GraphExecutor::ResumedExecutingEvent : {
980 aGraphEvent = SUPERV::ResumeEvent ;
983 case GraphExecutor::KilledExecutingEvent : {
984 aGraphEvent = SUPERV::KillEvent ;
987 case GraphExecutor::StoppedExecutingEvent : {
988 aGraphEvent = SUPERV::StopEvent ;
991 case GraphExecutor::SuccessedExecutingEvent : {
992 aGraphEvent = SUPERV::DoneEvent ;
995 case GraphExecutor::ErroredExecutingEvent : {
996 aGraphEvent = SUPERV:: ErroredEvent;
999 case GraphExecutor::SuspendedSuccessedEvent : {
1000 aGraphEvent = SUPERV::SuspendEvent ;
1003 case GraphExecutor::SuspendedErroredEvent : {
1004 aGraphEvent = SUPERV::SuspendEvent ;
1007 case GraphExecutor::ResumedSuccessedEvent : {
1008 aGraphEvent = SUPERV::ResumeEvent ;
1011 case GraphExecutor::ResumedErroredEvent : {
1012 aGraphEvent = SUPERV::ResumeEvent ;
1015 case GraphExecutor::KilledEvent : {
1016 aGraphEvent = SUPERV::KillEvent ;
1019 case GraphExecutor::StoppedEvent : {
1020 aGraphEvent = SUPERV::StopEvent ;
1023 case GraphExecutor::ReStartedEvent : {
1024 aGraphEvent = SUPERV::ReRunEvent ;
1027 case GraphExecutor::ReStartedAndSuspendEvent : {
1028 aGraphEvent = SUPERV::ReStartEvent ;
1031 case GraphExecutor::EndExecuteEvent : {
1032 aGraphEvent = SUPERV::DoneEvent ;
1036 cdebug << " GraphExecutor::OutNode::AutomatonGraphEvent Error Undefined Event : "
1037 << anEvent << endl ;
1038 aGraphEvent = SUPERV::UndefinedEvent ;
1041 return aGraphEvent ;
1044 SUPERV::GraphState GraphExecutor::OutNode::AutomatonGraphState(GraphExecutor::AutomatonState aState ) {
1045 SUPERV::GraphState aGraphState ;
1047 case GraphExecutor::UnKnownState : {
1048 aGraphState = SUPERV::UndefinedState ;
1051 case GraphExecutor::DataUndefState : {
1052 aGraphState = SUPERV::UndefinedState ;
1055 case GraphExecutor::DataWaitingState : {
1056 aGraphState = SUPERV::WaitingState ;
1059 case GraphExecutor::DataReadyState : {
1060 aGraphState = SUPERV::ReadyState ;
1063 case GraphExecutor::SuspendedReadyState : {
1064 aGraphState = SUPERV::SuspendReadyState ;
1067 case GraphExecutor::ResumedReadyState : {
1068 aGraphState = SUPERV::ReadyState ;
1071 case GraphExecutor::KilledReadyState : {
1072 aGraphState = SUPERV::KillState ;
1075 case GraphExecutor::StoppedReadyState : {
1076 aGraphState = SUPERV::StopState ;
1079 case GraphExecutor::ExecutingState : {
1080 aGraphState = SUPERV::RunningState ;
1083 case GraphExecutor::SuspendedExecutingState : {
1084 aGraphState = SUPERV::SuspendState ;
1087 case GraphExecutor::ResumedExecutingState : {
1088 aGraphState = SUPERV::RunningState ;
1091 case GraphExecutor::KilledExecutingState : {
1092 aGraphState = SUPERV::KillState ;
1095 case GraphExecutor::StoppedExecutingState : {
1096 aGraphState = SUPERV::StopState ;
1099 case GraphExecutor::SuccessedExecutingState : {
1100 aGraphState = SUPERV::DoneState ;
1103 case GraphExecutor::ErroredExecutingState : {
1104 aGraphState = SUPERV::ErrorState ;
1107 case GraphExecutor::SuspendedSuccessedState : {
1108 aGraphState = SUPERV::SuspendDoneState ;
1111 case GraphExecutor::SuspendedErroredState : {
1112 aGraphState = SUPERV::SuspendErroredState ;
1115 case GraphExecutor::ResumedSuccessedState : {
1116 aGraphState = SUPERV::DoneState ;
1119 case GraphExecutor::ResumedErroredState : {
1120 aGraphState = SUPERV::ErrorState ;
1123 case GraphExecutor::KilledSuccessedState : {
1124 aGraphState = SUPERV::KillState ;
1127 case GraphExecutor::KilledErroredState : {
1128 aGraphState = SUPERV::KillState ;
1131 case GraphExecutor::StoppedSuccessedState : {
1132 aGraphState = SUPERV::StopState ;
1135 case GraphExecutor::StoppedErroredState : {
1136 aGraphState = SUPERV::StopState ;
1139 case GraphExecutor::SuccessedState : {
1140 aGraphState = SUPERV::DoneState ;
1143 case GraphExecutor::ErroredState : {
1144 aGraphState = SUPERV::ErrorState ;
1147 case GraphExecutor::SuspendedState : {
1148 aGraphState = SUPERV::SuspendState ;
1151 case GraphExecutor::KilledState : {
1152 aGraphState = SUPERV::KillState ;
1155 case GraphExecutor::StoppedState : {
1156 aGraphState = SUPERV::StopState ;
1159 case GraphExecutor::ReRunnedState : {
1160 aGraphState = SUPERV::ReRunState ;
1163 case GraphExecutor::ReStartedState : {
1164 aGraphState = SUPERV::ReStartState ;
1168 cdebug << " GraphExecutor::OutNode::AutomatonGraphState Error Undefined State : "
1169 << aGraphState << endl ;
1170 aGraphState = SUPERV::UndefinedState ;
1173 return aGraphState ;
1176 int GraphExecutor::OutNode::GetListSize() {
1177 return _EventNodes.size();
1180 bool GraphExecutor::OutNode::PushEvent( GraphExecutor::InNode * aNode ,
1181 GraphExecutor::NodeEvent anEvent ,
1182 GraphExecutor::AutomatonState aState ) {
1183 // cdebug_in << "PushEvent Threads " << Threads() << " SuspendedThreads "
1184 // << SuspendedThreads() << endl ;
1185 if ( pthread_mutex_lock( &_MutexWait ) ) {
1186 perror("PushEvent pthread_mutex_lock ") ;
1189 char* aNodeName = aNode ? aNode->Name() : Graph()->Name() ;
1190 _EventNodes.push_back( aNodeName ) ;
1191 _Events.push_back( anEvent ) ;
1192 _States.push_back( aState ) ;
1194 pthread_cond_broadcast( &_EventWait );
1195 cdebug << pthread_self() << " PushEvent Threads " << Threads() << " SuspendedThreads "
1196 << SuspendedThreads() << " pthread_cond_broadcast _EventWait " << &_EventWait << endl ;
1198 // cdebug << aNode->ThreadNo() << " PushEvent " << aNode->Name() ;
1199 // cdebug << " " << aNode->Automaton()->EventName( anEvent )
1200 // << " " << aNode->Automaton()->StateName( aState )
1201 // << " ControleState "
1202 // << aNode->Automaton()->ControlStateName( aNode->ControlState() ) ;
1205 // cdebug << "PushEvent " << Graph()->Name() ;
1206 // cdebug << " " << theAutomaton->EventName( anEvent ) << " "
1207 // << theAutomaton->StateName( aState ) ;
1209 // cdebug_out << "PushEvent Threads " << Threads() << " SuspendedThreads "
1210 // << SuspendedThreads() << endl ;
1212 if ( _EventNodes.size() > 101 ) {
1213 while ( _EventNodes.size() > 31 ) {
1214 _EventNodes.pop_front() ;
1215 _Events.pop_front() ;
1216 _States.pop_front() ;
1220 if ( pthread_mutex_unlock( &_MutexWait ) ) {
1221 perror("PushEvent pthread_mutex_unlock ") ;
1227 bool GraphExecutor::OutNode::StateWait( SUPERV::GraphState aState ) {
1231 bool GraphExecutor::OutNode::Event( char ** aNodeName ,
1232 SUPERV::GraphEvent & anEvent ,
1233 SUPERV::GraphState & aState ,
1235 // asv : fixing problem of loops with large number of iterations (>5000)
1236 // experimentally was found that number of non-handled by GUI events = (number_of_nodes x 7)
1237 // or 7 events for each node - so what we want to do here is remove "old" events for nodes
1238 // "on the fly". Once again it is done in Stop(), Kill(), Done() functions.
1239 if ( _EventNodes.size() > (unsigned int)Graph()->GraphNodesSize()*7 )
1243 int SuspendedThreadsNumber ;
1244 if ( _EventNodes.size() > 0 ) {
1245 cdebug_in << "GraphExecutor::OutNode::Event " << _EventNodes.size() << " in queue" << endl ;
1247 if ( pthread_mutex_lock( &_MutexWait ) ) {
1248 perror("EventLoop pthread_mutex_lock ") ;
1251 _JustStarted = false ;
1252 ThreadsNumber = Threads() ;
1253 SuspendedThreadsNumber = SuspendedThreads() ;
1254 bool RetVal = ( ThreadsNumber - SuspendedThreadsNumber) != 0 ||
1255 _EventNodes.size() > 0 ;
1256 char * NodeName = "" ;
1257 GraphExecutor::NodeEvent theEvent = GraphExecutor::UndefinedEvent ;
1258 GraphExecutor::AutomatonState theState = GraphExecutor::UnKnownState ;
1259 anEvent = SUPERV::UndefinedEvent ;
1260 aState = SUPERV::UndefinedState ;
1261 if ( ( Done() || IsKilled() || IsStopped() ) && _EventNodes.size() == 0 ) {
1262 // cdebug << "EventLoop Done()/IsKilled()/IsStopped() && _EventNodes.size() == 0" << endl ;
1265 else if ( !WithWait && _EventNodes.size() == 0 ) {
1266 anEvent = SUPERV::NoEvent ;
1267 aState = SUPERV::NoState ;
1270 else if ( RetVal ) {
1271 while ( !IsSuspended() && _EventNodes.size() == 0 ) {
1272 // cdebug << "EventLoop pthread_cond_wait _EventWait" << endl ;
1273 pthread_cond_wait( &_EventWait , &_MutexWait );
1274 // cdebug << "EventLoop pthread_cond_waited _EventWait"
1275 // << " _EventNodes.size() " << _EventNodes.size() << endl ;
1277 if ( _EventNodes.size() ) {
1278 ThreadsNumber = Threads() ;
1279 NodeName = _EventNodes.front() ;
1280 _EventNodes.pop_front() ;
1281 theEvent = _Events.front() ;
1282 anEvent = AutomatonGraphEvent( theEvent ) ;
1283 _Events.pop_front() ;
1284 theState = _States.front() ;
1285 aState = AutomatonGraphState( theState ) ;
1286 _States.pop_front() ;
1289 *aNodeName = NodeName ;
1290 if ( IsSuspended() && _EventNodes.size() == 0 ) {
1293 if ( anEvent != SUPERV::NoEvent ) {
1294 // cdebug << pthread_self() << "EventLoop "
1295 // << NodeName << " " << theAutomaton->StateName( theState )
1296 // << " _EventNodes.size() " << _EventNodes.size()
1297 // << " Threads " << Threads() << " SuspendedThreads "
1298 // << SuspendedThreads() << " RetVal " << RetVal << endl ;
1300 if ( pthread_mutex_unlock( &_MutexWait ) ) {
1301 perror("EventLoop pthread_mutex_lock ") ;
1304 if ( _EventNodes.size() > 0 ) {
1305 cdebug_out << "GraphExecutor::OutNode::Event " << _EventNodes.size() << " in queue"
1306 << *aNodeName << " " << anEvent << " " << aState << endl ;
1311 bool GraphExecutor::OutNode::EventW( char ** aNodeName ,
1312 SUPERV::GraphEvent & anEvent ,
1313 SUPERV::GraphState & aState ) {
1316 aState = SUPERV::UndefinedState ;
1318 aState != SUPERV::SuspendReadyState &&
1319 aState != SUPERV::RunningState &&
1320 aState != SUPERV::SuspendDoneState &&
1321 aState != SUPERV::SuspendErroredState ) {
1322 NodeName = Graph()->Name() ;
1323 while ( sts && !strcmp( NodeName , Graph()->Name() ) ) {
1324 sts = EventWait( aNodeName , anEvent , aState ) ;
1325 NodeName = *aNodeName ;
1331 bool GraphExecutor::OutNode::EventWait( char ** aNodeName ,
1332 SUPERV::GraphEvent & anEvent ,
1333 SUPERV::GraphState & aState ) {
1334 if ( pthread_mutex_lock( &_MutexWait ) ) {
1335 perror("EventW pthread_mutex_lock ") ;
1339 int SuspendedThreadsNumber ;
1340 ThreadsNumber = Threads() ;
1341 SuspendedThreadsNumber = SuspendedThreads() ;
1342 bool RetVal = ( ThreadsNumber - SuspendedThreadsNumber) != 0 ||
1343 _EventNodes.size() > 0 ;
1344 cdebug << "--> EventW RetVal " << RetVal << endl ;
1345 char * NodeName = "" ;
1346 GraphExecutor::NodeEvent theEvent = GraphExecutor::UndefinedEvent ;
1347 GraphExecutor::AutomatonState theState = GraphExecutor::UnKnownState ;
1348 anEvent = SUPERV::UndefinedEvent ;
1349 aState = SUPERV::UndefinedState ;
1350 if ( IsDone() && _EventNodes.size() == 0 ) {
1351 cdebug << "EventW IsDone() && _EventNodes.size() == 0" << endl ;
1354 else if ( RetVal ) {
1355 GraphExecutor::InNode * aNode = NULL ;
1356 while ( aNode == NULL && RetVal ) {
1357 NodeName = _EventNodes.front() ;
1358 theEvent = _Events.front() ;
1359 anEvent = AutomatonGraphEvent( theEvent ) ;
1360 theState = _States.front() ;
1361 aState = AutomatonGraphState( theState ) ;
1363 if ( _JustStarted ) {
1364 _JustStarted = false ;
1367 _EventNodes.pop_front() ;
1368 _Events.pop_front() ;
1369 _States.pop_front() ;
1372 aNode = ((GraphExecutor::InNode *) Graph()->GetGraphNode( NodeName )->GetInNode()) ;
1373 cdebug << "EventW Previous Node " << NodeName << " ThreadsNumber "
1375 << " _EventNodes.size() " << _EventNodes.size() << " "
1376 << theAutomaton->StateName( theState )
1377 << " Threads " << Threads() << " SuspendedThreads "
1378 << SuspendedThreads() << endl ;
1381 else if ( IsDone() && _EventNodes.size() == 0 ) {
1382 cdebug << "EventW IsDone() && _EventNodes.size() == 0" << endl ;
1386 cdebug << "EventW Not InNode " << NodeName
1387 << " _EventNodes.size() " << _EventNodes.size() << endl ;
1388 while ( _EventNodes.size() == 0 ) {
1389 pthread_cond_wait( &_EventWait , &_MutexWait );
1391 cdebug << "EventW pthread_cond_waited Not InNode " << NodeName
1392 << " _EventNodes.size() " << _EventNodes.size() << endl ;
1397 if ( aState == SUPERV::SuspendState ||
1398 aState == SUPERV::SuspendReadyState ||
1399 aState == SUPERV::SuspendDoneState ||
1400 aState == SUPERV::SuspendErroredState ) {
1401 aNode->ControlState( SUPERV::ToSuspendState ) ;
1402 if ( aNode->IsSuspended() ) {
1403 if ( pthread_mutex_unlock( &_MutexWait ) ) {
1404 perror("EventW pthread_mutex_lock ") ;
1407 cdebug << "EventW " << aNode->Name() << " ResumeAction" << endl ;
1408 aNode->ResumeAction( GraphExecutor::ToResumeEvent ) ;
1409 cdebug << "EventW " << aNode->Name() << " ResumedAction" << endl ;
1410 if ( pthread_mutex_lock( &_MutexWait ) ) {
1411 perror("EventW pthread_mutex_lock ") ;
1416 cdebug << "EventW inconsistent SuspendState" << endl ;
1421 if ( aNode->IsDone() ) {
1425 cdebug << "EventW NOT SuspendedState _EventNodes.size() "
1426 << _EventNodes.size() << endl ;
1431 cdebug << "EventW " << aNode->Name() << " pthread_cond_wait" << endl ;
1432 while ( _EventNodes.size() == 0 ) {
1433 pthread_cond_wait( &_EventWait , &_MutexWait );
1435 ThreadsNumber = Threads() ;
1436 NodeName = _EventNodes.front() ;
1437 theEvent = _Events.front() ;
1438 anEvent = AutomatonGraphEvent( theEvent ) ;
1439 theState = _States.front() ;
1440 aState = AutomatonGraphState( theState ) ;
1444 *aNodeName = NodeName ;
1445 cdebug << "<-- EventW RetVal " << RetVal << " " << NodeName
1446 << " Threads " << Threads() << " SuspendedThreads "
1447 << SuspendedThreads()
1448 << " _EventNodes.size() " << _EventNodes.size()
1449 << " " << theAutomaton->EventName( theEvent ) << " "
1450 << theAutomaton->StateName( theState ) << endl ;
1451 if ( pthread_mutex_unlock( &_MutexWait ) ) {
1452 perror("EventW pthread_mutex_lock ") ;
1457 long GraphExecutor::OutNode::EventQSize() {
1458 return _EventNodes.size() ;
1461 void GraphExecutor::OutNode::EventList() {
1462 if ( pthread_mutex_lock( &_MutexWait ) ) {
1463 perror("EventList pthread_mutex_lock ") ;
1466 list< char * >::iterator itEventNodes = _EventNodes.begin() ;
1467 list< GraphExecutor::NodeEvent >::iterator itEvents = _Events.begin() ;
1468 list< GraphExecutor::AutomatonState >::iterator itStates = _States.begin() ;
1469 while ( itEventNodes != _EventNodes.end() ) {
1470 cdebug << pthread_self() << "EVENTSTACK "
1471 << *itEventNodes << " " << *itEvents << " "
1472 << theAutomaton->StateName( *itStates )
1473 << " Threads " << Threads() << " SuspendedThreads " << SuspendedThreads() << endl ;
1478 if ( pthread_mutex_unlock( &_MutexWait ) ) {
1479 perror("EventList pthread_mutex_lock ") ;
1484 void GraphExecutor::OutNode::SendSomeDataReady( const char * aNodeName ) {
1485 cdebug_in << "GraphExecutor::OutNode::SendSomeDataReady " << aNodeName << "->SendSomeDataReady( "
1486 << Graph()->Name() << " )" << endl;
1488 sts = ((GraphExecutor::InNode * ) Graph()->GetChangeGraphNode( aNodeName )->GetInNode())->SendSomeDataReady( Graph()->Name() ) ;
1489 cdebug_out << "GraphExecutor::OutNode::SendSomeDataReady sts " << sts << endl ;
1492 void GraphExecutor::OutNode::State(GraphExecutor::AutomatonState aState ) {
1493 // cdebug << "GraphExecutor::OutNode::State " << Graph()->Name() << " "
1494 // << theAutomaton->StateName( AutomatonGraphState( _State ) ) << " ---> "
1495 // << theAutomaton->StateName( AutomatonGraphState( aState ) ) << endl ;
1499 SUPERV::GraphState GraphExecutor::OutNode::State() {
1500 // cdebug_in << "GraphExecutor::OutNode::State" << endl;
1501 // cdebug_out << "GraphExecutor::OutNode::State" << endl ;
1502 // cdebug << "GraphExecutor::OutNode::State GraphState "
1503 // << theAutomaton->StateName( AutomatonGraphState( _State ) ) << endl ;
1504 return AutomatonGraphState( _State ) ;
1507 SUPERV::GraphState GraphExecutor::OutNode::State( const char * NodeName ) {
1508 // cdebug_in << "GraphExecutor::OutNode::State " << NodeName << endl;
1509 GraphExecutor::AutomatonState aret = GraphExecutor::UnKnownState ;
1510 const GraphBase::ComputingNode * aCNode = Graph()->GetGraphNode( NodeName ) ;
1512 GraphExecutor::InNode *anInNode = (GraphExecutor::InNode *)aCNode->GetInNode() ;
1514 aret = anInNode->State() ;
1515 // cdebug << "GraphExecutor::OutNode::State( " << NodeName << " ) "
1516 // << theAutomaton->StateName( AutomatonGraphState( aret ) ) << endl ;
1519 // cdebug_out << "GraphExecutor::OutNode::State" << endl ;
1520 return AutomatonGraphState( aret ) ;
1523 SUPERV::GraphState GraphExecutor::OutNode::State( const char * NodeName ,
1524 const char * ServiceParameterName ) {
1525 // cdebug_in << "GraphExecutor::OutNode::State " << NodeName << " "
1526 // << ServiceParameterName<< endl;
1527 SUPERV::GraphState aret = Graph()->PortState( NodeName , ServiceParameterName ) ;
1528 // cdebug_out << "GraphExecutor::OutNode::State" << endl ;
1532 GraphExecutor::AutomatonState GraphExecutor::OutNode::AutomatonState() {
1533 // cdebug_in << "GraphExecutor::OutNode::AutomatonState" << endl;
1534 // cdebug_out << "GraphExecutor::OutNode::AutomatonState" << endl ;
1538 GraphExecutor::AutomatonState GraphExecutor::OutNode::AutomatonState( const char * NodeName ) {
1539 // cdebug_in << "GraphExecutor::OutNode::AutomatonState " << NodeName << endl;
1540 GraphExecutor::AutomatonState aret = GraphExecutor::UnKnownState ;
1541 const GraphBase::ComputingNode * aNode = Graph()->GetGraphNode( NodeName ) ;
1543 GraphExecutor::InNode *anInNode = (GraphExecutor::InNode *) aNode->GetInNode() ;
1545 aret = anInNode->State() ;
1548 // cdebug_out << "GraphExecutor::OutNode::AutomatonState" << endl ;
1552 SUPERV::ControlState GraphExecutor::OutNode::ControlState() {
1553 // cdebug_in << "GraphExecutor::OutNode::ControlState" << endl;
1554 // cdebug_out << "GraphExecutor::OutNode::ControlState" << endl ;
1555 return _ControlState ;
1558 SUPERV::ControlState GraphExecutor::OutNode::ControlState( const char * NodeName ) {
1559 // cdebug_in << "GraphExecutor::OutNode::ControlState " << NodeName << endl;
1560 SUPERV::ControlState aret = SUPERV::VoidState ;
1561 const GraphBase::ComputingNode * aNode = Graph()->GetGraphNode( NodeName ) ;
1563 GraphExecutor::InNode *anInNode = (GraphExecutor::InNode *) aNode->GetInNode() ;
1565 aret = anInNode->ControlState() ;
1568 // cdebug_out << "GraphExecutor::OutNode::ControlState" << endl ;
1572 void GraphExecutor::OutNode::ControlClear() {
1573 // cdebug_in << "GraphExecutor::OutNode::ControlClear" << endl;
1574 // cdebug_out << "GraphExecutor::OutNode::ControlClear" << endl ;
1575 _ControlState = SUPERV::VoidState;
1578 void GraphExecutor::OutNode::ControlClear( const char * NodeName ) {
1579 // cdebug_in << "GraphExecutor::OutNode::ControlClear " << NodeName << endl;
1580 const GraphBase::ComputingNode * aNode = Graph()->GetGraphNode( NodeName ) ;
1582 GraphExecutor::InNode *anInNode = (GraphExecutor::InNode *) aNode->GetInNode() ;
1584 anInNode->ControlClear() ;
1587 // cdebug_out << "GraphExecutor::OutNode::ControlClear" << endl ;
1590 bool GraphExecutor::OutNode::IsWaiting() {
1591 // cdebug_in << "GraphExecutor::OutNode::IsWaiting" << endl;
1592 // cdebug_out << "GraphExecutor::OutNode::IsWaiting" << endl ;
1596 bool GraphExecutor::OutNode::IsReady() {
1597 // cdebug_in << "GraphExecutor::OutNode::IsReady" << endl;
1598 // cdebug_out << "GraphExecutor::OutNode::IsReady" << endl ;
1602 bool GraphExecutor::OutNode::IsRunning() {
1603 // cdebug_in << "GraphExecutor::OutNode::IsRunning" << endl;
1604 // cdebug_out << "GraphExecutor::OutNode::IsRunning" << endl ;
1608 bool GraphExecutor::OutNode::IsDone() {
1609 // cdebug_in << "GraphExecutor::OutNode::IsDone" << endl;
1610 // cdebug_out << "GraphExecutor::OutNode::IsDone" << endl ;
1611 return ( Done() || IsKilled() || IsStopped() ) ;
1614 bool GraphExecutor::OutNode::IsSuspended() {
1615 // cdebug_in << "GraphExecutor::OutNode::IsSuspended" << endl;
1617 if ( _SuspendedThreads == _Threads && _Threads != 0 ) {
1620 // cdebug_out << "GraphExecutor::OutNode::IsSuspended" << endl ;
1624 bool GraphExecutor::OutNode::IsKilled() {
1625 // cdebug_in << "GraphExecutor::OutNode::IsKilled" << endl;
1627 if ( AutomatonGraphState( _State ) == SUPERV::KillState ) {
1630 // cdebug_out << "GraphExecutor::OutNode::IsKilled" << endl ;
1634 bool GraphExecutor::OutNode::IsStopped() {
1635 // cdebug_in << "GraphExecutor::OutNode::IsStopped" << endl;
1637 if ( AutomatonGraphState( _State ) == SUPERV::StopState ) {
1640 // cdebug_out << "GraphExecutor::OutNode::IsStopped" << endl ;
1644 bool GraphExecutor::OutNode::IsWaiting( const char * NodeName ) {
1646 // cdebug_in << "GraphExecutor::OutNode::IsWaiting " << NodeName << endl;
1647 GraphExecutor::InNode *anInNode = (GraphExecutor::InNode *) Graph()->GetGraphNode( NodeName )->GetInNode() ;
1649 aret = anInNode->IsWaiting() ;
1651 // cdebug_out << "GraphExecutor::OutNode::IsWaiting" << endl ;
1655 bool GraphExecutor::OutNode::IsReady( const char * NodeName ) {
1657 // cdebug_in << "GraphExecutor::OutNode::IsReady " << NodeName << endl;
1658 GraphExecutor::InNode *anInNode = (GraphExecutor::InNode *) Graph()->GetGraphNode( NodeName )->GetInNode() ;
1660 aret = anInNode->IsReady() ;
1662 // cdebug_out << "GraphExecutor::OutNode::IsReady" << endl ;
1666 bool GraphExecutor::OutNode::IsRunning( const char * NodeName ) {
1668 // cdebug_in << "GraphExecutor::OutNode::IsRunning " << NodeName << endl;
1669 GraphExecutor::InNode *anInNode = (GraphExecutor::InNode *) Graph()->GetGraphNode( NodeName )->GetInNode() ;
1671 aret = anInNode->IsRunning() ;
1673 // cdebug_out << "GraphExecutor::OutNode::IsRunning" << endl ;
1677 bool GraphExecutor::OutNode::IsDone( const char * NodeName ) {
1679 // cdebug_in << "GraphExecutor::OutNode::IsDone " << NodeName << endl;
1680 GraphExecutor::InNode *anInNode = (GraphExecutor::InNode *) Graph()->GetGraphNode( NodeName )->GetInNode() ;
1682 aret = anInNode->IsDone() ;
1684 // cdebug_out << "GraphExecutor::OutNode::IsDone" << endl ;
1688 bool GraphExecutor::OutNode::IsSuspended( const char * NodeName ) {
1690 // cdebug_in << "GraphExecutor::OutNode::IsSuspended " << NodeName << endl;
1691 GraphExecutor::InNode *anInNode = (GraphExecutor::InNode *) Graph()->GetGraphNode( NodeName )->GetInNode() ;
1693 aret = anInNode->IsSuspended() ;
1695 // cdebug_out << "GraphExecutor::OutNode::IsSuspended" << endl ;
1699 bool GraphExecutor::OutNode::IsDone( const char * NodeName ,
1700 const char * ServiceParameterName ) {
1701 // cdebug_in << "GraphExecutor::OutNode::IsDone " << NodeName << " "
1702 // << ServiceParameterName<< endl;
1703 bool aret = Graph()->PortDone( NodeName , ServiceParameterName ) ;
1704 // cdebug_out << "GraphExecutor::OutNode::IsDone" << endl ;
1708 bool GraphExecutor::OutNode::ContainerKill() {
1709 bool RetVal = true ;
1710 cdebug_in << "GraphExecutor::OutNode::ContainerKill" << endl;
1711 _ControlState = SUPERV::ToSuspendState ;
1713 for ( i = 0 ; i < Graph()->GraphNodesSize() ; i++ ) {
1714 GraphExecutor::InNode * aNode = (GraphExecutor::InNode * ) Graph()->GraphNodes( i )->GetInNode() ;
1715 bool sts = aNode->ContainerKill() ;
1716 if ( sts && aNode->IsKilled() ) {
1717 cdebug << aNode->Name() << " killed" << endl ;
1719 else if ( aNode->IsWaiting() || aNode->IsDone() ) {
1720 cdebug << aNode->Name() << " not killed : "
1721 << theAutomaton->StateName( aNode->State() ) << endl ;
1724 cdebug << aNode->Name() << " cannot be killed : "
1725 << theAutomaton->StateName( aNode->State() ) << endl ;
1729 if ( !RetVal || Threads() != 0 ) {
1730 for ( i = 0 ; i < Graph()->GraphNodesSize() ; i++ ) {
1731 GraphExecutor::InNode * aNode = (GraphExecutor::InNode * ) Graph()->GraphNodes( i )->GetInNode() ;
1732 if ( !aNode->IsKilled() && !aNode->IsWaiting() && !aNode->IsDone() ) {
1733 aNode->KilledAction() ;
1738 State( GraphExecutor::KilledState ) ;
1739 cdebug_out << "GraphExecutor::OutNode::ContainerKill" << endl ;
1743 bool GraphExecutor::OutNode::Suspend() {
1745 cdebug_in << "GraphExecutor::OutNode::Suspend" << endl;
1746 // _ControlState = SUPERV::ToSuspendState ;
1748 for ( i = 0 ; i < Graph()->GraphNodesSize() ; i++ ) {
1749 GraphExecutor::InNode * aNode = (GraphExecutor::InNode * ) Graph()->GraphNodes( i )->GetInNode() ;
1750 bool sts = aNode->Suspend() ;
1751 if ( sts && aNode->IsSuspended() ) {
1753 cdebug << aNode->Name() << " Suspended" << endl ;
1755 else if ( aNode->IsWaiting() || aNode->IsDone() ) {
1756 cdebug << aNode->Name() << " not Suspended : "
1757 << theAutomaton->StateName( aNode->State() ) << endl ;
1761 cdebug << aNode->Name() << " cannot be Suspended : "
1762 << theAutomaton->StateName( aNode->State() ) << endl ;
1766 State( GraphExecutor::SuspendedState ) ;
1767 MESSAGE("================================================================================") ;
1768 MESSAGE( Graph()->Name() << " IS SUSPENDED" ) ;
1769 MESSAGE("================================================================================") ;
1772 MESSAGE("================================================================================") ;
1773 MESSAGE( Graph()->Name() << " IS NOT SUSPENDED" ) ;
1774 MESSAGE("================================================================================") ;
1776 cdebug_out << "GraphExecutor::OutNode::Suspend" << theAutomaton->StateName( State() ) << endl ;
1780 bool GraphExecutor::OutNode::Resume() {
1782 cdebug_in << "GraphExecutor::OutNode::Resume" << endl;
1783 if ( IsSuspended() ) {
1784 State( GraphExecutor::ExecutingState ) ;
1786 for ( i = 0 ; i < Graph()->GraphNodesSize() ; i++ ) {
1787 GraphExecutor::InNode * aNode = (GraphExecutor::InNode * ) Graph()->GraphNodes( i )->GetInNode() ;
1788 aNode->ControlState( SUPERV::VoidState ) ;
1789 if ( aNode->IsSuspended() ) {
1790 cdebug << aNode->Name() << "->Resume " << theAutomaton->StateName( aNode->State() )
1792 if ( aNode->Resume() ) {
1793 cdebug << aNode->Name() << " Resumed " << theAutomaton->StateName( aNode->State() )
1798 cdebug << aNode->Name() << " Resume failed"
1799 << theAutomaton->StateName( aNode->State() ) << endl ;
1803 cdebug << aNode->Name() << " " << theAutomaton->StateName( aNode->State() )
1809 cdebug << Graph()->Name() << " not suspended " << theAutomaton->StateName( State() ) << endl ;
1812 MESSAGE("================================================================================") ;
1813 MESSAGE( Graph()->Name() << " IS RESUMED" ) ;
1814 MESSAGE("================================================================================") ;
1817 MESSAGE("================================================================================") ;
1818 MESSAGE( Graph()->Name() << " IS NOT RESUMED" ) ;
1819 MESSAGE("================================================================================") ;
1821 cdebug_out << "GraphExecutor::OutNode::Resume" << theAutomaton->StateName( State() ) << " " << RetVal << endl ;
1825 bool GraphExecutor::OutNode::Kill() {
1826 bool RetVal = true ;
1827 cdebug_in << "GraphExecutor::OutNode::Kill" << endl;
1828 _ControlState = SUPERV::ToSuspendState ;
1830 for ( i = 0 ; i < Graph()->GraphNodesSize() ; i++ ) {
1831 GraphExecutor::InNode * aNode = (GraphExecutor::InNode * ) Graph()->GraphNodes( i )->GetInNode() ;
1832 bool sts = aNode->Kill() ;
1833 if ( sts && aNode->IsKilled() ) {
1834 cdebug << aNode->Name() << " killed" << endl ;
1836 else if ( aNode->IsWaiting() || aNode->IsDone() ) {
1837 cdebug << aNode->Name() << " not killed : "
1838 << theAutomaton->StateName( aNode->State() ) << endl ;
1841 cdebug << aNode->Name() << " cannot be killed : "
1842 << theAutomaton->StateName( aNode->State() ) << endl ;
1846 if ( !RetVal || Threads() != 0 ) {
1847 for ( i = 0 ; i < Graph()->GraphNodesSize() ; i++ ) {
1848 GraphExecutor::InNode * aNode = (GraphExecutor::InNode * ) Graph()->GraphNodes( i )->GetInNode() ;
1849 if ( !aNode->IsKilled() && !aNode->IsWaiting() && !aNode->IsDone() ) {
1850 cdebug << aNode->Name() << " not killed : "
1851 << theAutomaton->StateName( aNode->State() ) << " " << aNode->Name() << "->"
1852 << "KilledAction()" << endl ;
1853 aNode->KilledAction() ;
1858 State( GraphExecutor::KilledState ) ;
1860 MESSAGE("================================================================================") ;
1861 MESSAGE( Graph()->Name() << " IS KILLED" << theAutomaton->StateName( AutomatonState() ) << " EventQSize "
1863 MESSAGE("================================================================================") ;
1866 MESSAGE("================================================================================") ;
1867 MESSAGE( Graph()->Name() << " IS NOT KILLED" ) ;
1868 MESSAGE("================================================================================") ;
1870 cdebug_out << "GraphExecutor::OutNode::Kill " << RetVal
1871 << " Threads " << _Threads << " SuspendedThreads " << _SuspendedThreads << endl ;
1873 // remove "extra" events from the event queue
1876 // asv : 25.10.04 : calling Editing() to indicate stop of execution
1877 Graph()->GraphEditor()->Editing();
1882 bool GraphExecutor::OutNode::Stop() {
1883 bool RetVal = false ;
1884 cdebug_in << "GraphExecutor::OutNode::Stop" << endl;
1886 cdebug_out << "GraphExecutor::OutNode::Stop" << endl ;
1888 MESSAGE("================================================================================") ;
1889 MESSAGE( Graph()->Name() << " IS STOPPED" ) ;
1890 MESSAGE("================================================================================") ;
1894 bool GraphExecutor::OutNode::ReRun() {
1895 bool RetVal = false ;
1896 cdebug_in << "GraphExecutor::OutNode::ReRun" << endl;
1897 if ( IsSuspended() ) {
1899 cdebug_out << "GraphExecutor::OutNode::ReRun" << endl ;
1902 bool GraphExecutor::OutNode::ReStart() {
1903 bool RetVal = false ;
1904 cdebug_in << "GraphExecutor::OutNode::ReStart" << endl;
1905 if ( IsSuspended() ) {
1907 cdebug_out << "GraphExecutor::OutNode::ReStart" << endl ;
1911 bool GraphExecutor::OutNode::ReadyWait() {
1912 cdebug_in << "GraphExecutor::OutNode::ReadyWait" << endl;
1914 if ( pthread_mutex_lock( &_MutexWait ) ) {
1915 perror("pthread_mutex_lock _ReadyWait") ;
1921 pthread_cond_wait( &_EventWait , &_MutexWait );
1924 if ( pthread_mutex_unlock( &_MutexWait ) ) {
1925 perror("pthread_mutex_lock _ReadyWait") ;
1928 cdebug_out << "GraphExecutor::OutNode::ReadyWait" << endl ;
1932 bool GraphExecutor::OutNode::RunningWait() {
1933 cdebug_in << "GraphExecutor::OutNode::RunningWait" << endl;
1935 if ( pthread_mutex_lock( &_MutexWait ) ) {
1936 perror("pthread_mutex_lock _RunningWait") ;
1939 aret = IsRunning() ;
1941 cdebug << "RunningWait pthread_cond_wait _EventWait" << endl;
1942 pthread_cond_wait( &_EventWait , &_MutexWait );
1943 aret = IsRunning() ;
1944 cdebug << "RunningWait pthread_cond_waited _EventWait " << aret << endl;
1946 if ( pthread_mutex_unlock( &_MutexWait ) ) {
1947 perror("pthread_mutex_lock _RunningWait") ;
1950 cdebug_out << "GraphExecutor::OutNode::RunningWait " << aret << endl ;
1954 bool GraphExecutor::OutNode::DoneWait() {
1955 cdebug_in << pthread_self() << " GraphExecutor::DoneWait " << this << " " << Graph()->Name() << endl;
1957 if ( pthread_mutex_lock( &_MutexWait ) ) {
1958 perror("pthread_mutex_lock _DoneWait") ;
1962 while ( !aret && !IsSuspended() && IsRunning() ) {
1963 cdebug << pthread_self() << " GraphExecutor::DoneWait " << this << " " << Graph()->Name()
1964 << " DoneWait pthread_cond_wait _EventWait " << &_EventWait << endl;
1965 pthread_cond_wait( &_EventWait , &_MutexWait );
1967 cdebug << pthread_self() << " GraphExecutor::DoneWait " << this << " " << Graph()->Name()
1968 << " DoneWait pthread_cond_waited _EventWaited " << &_EventWait << " : "<< aret << endl;
1970 if ( pthread_mutex_unlock( &_MutexWait ) ) {
1971 perror("pthread_mutex_lock _DoneWait") ;
1974 cdebug_out << pthread_self() << " GraphExecutor::DoneWait " << this << " " << Graph()->Name()
1975 << " " << State() << " : " << aret << endl ;
1979 bool GraphExecutor::OutNode::SuspendedWait() {
1980 cdebug_in << "GraphExecutor::OutNode::SuspendedWait" << endl;
1982 if ( pthread_mutex_lock( &_MutexWait ) ) {
1983 perror("pthread_mutex_lock _SuspendedWait") ;
1986 aret = IsSuspended() ;
1987 while ( !aret && !IsDone() ) {
1988 pthread_cond_wait( &_EventWait , &_MutexWait );
1989 aret = IsSuspended() ;
1991 if ( pthread_mutex_unlock( &_MutexWait ) ) {
1992 perror("pthread_mutex_lock _SuspendedWait") ;
1995 cdebug_out << "GraphExecutor::OutNode::SuspendedWait" << endl ;
1999 bool GraphExecutor::OutNode::ReadyWait( const char * NodeName ) {
2001 cdebug_in << "GraphExecutor::OutNode::ReadyWait " << NodeName << endl;
2002 GraphExecutor::InNode *anInNode = (GraphExecutor::InNode *) Graph()->GetGraphNode( NodeName )->GetInNode() ;
2004 aret = anInNode->ReadyWait() ;
2006 cdebug_out << "GraphExecutor::OutNode::ReadyWait" << endl ;
2010 bool GraphExecutor::OutNode::RunningWait( const char * NodeName ) {
2012 cdebug_in << "GraphExecutor::OutNode::RunningWait " << NodeName << endl;
2013 GraphExecutor::InNode *anInNode = (GraphExecutor::InNode *) Graph()->GetGraphNode( NodeName )->GetInNode() ;
2015 aret = anInNode->RunningWait() ;
2017 cdebug_out << "GraphExecutor::OutNode::RunningWait" << endl ;
2021 bool GraphExecutor::OutNode::DoneWait( const char * NodeName ) {
2023 cdebug_in << "GraphExecutor::OutNode::DoneWait " << NodeName << endl;
2024 GraphExecutor::InNode *anInNode = (GraphExecutor::InNode *) Graph()->GetGraphNode( NodeName )->GetInNode() ;
2026 aret = anInNode->DoneWait() ;
2028 cdebug_out << "GraphExecutor::OutNode::DoneWait" << endl ;
2032 bool GraphExecutor::OutNode::SuspendedWait( const char * NodeName ) {
2034 cdebug_in << "GraphExecutor::OutNode::SuspendedWait " << NodeName << endl;
2035 GraphExecutor::InNode *anInNode = (GraphExecutor::InNode *) Graph()->GetGraphNode( NodeName )->GetInNode() ;
2037 aret = anInNode->SuspendedWait() ;
2039 cdebug_out << "GraphExecutor::OutNode::SuspendedWait" << endl ;
2043 long GraphExecutor::OutNode::LastLevelDone() {
2046 for ( i = 0 ; i <= Graph()->LevelMax() ; i++ ) {
2047 for ( j = 0 ; j <= Graph()->NodesNumber( i ) ; j++ ) {
2048 GraphBase::ComputingNode * aNode = Graph()->SortedNodes( i , j ) ;
2049 if ( !IsDone( aNode->Name() ) ) {
2053 if ( j != Graph()->NodesNumber( i ) + 1 )
2061 const CORBA::Any *GraphExecutor::OutNode::GetInData( const char * NodeName ,
2062 const char * ServiceParameterName ) {
2063 // cdebug_in << "GraphExecutor::OutNode::GetInData " << NodeName << " "
2064 // << ServiceParameterName << endl ;
2065 const CORBA::Any * retdata = Graph()->PortInData( NodeName , ServiceParameterName ) ;
2066 // cdebug_out << "GraphExecutor::OutNode::GetInData" << endl ;
2070 const CORBA::Any *GraphExecutor::OutNode::GetOutData( const char * NodeName ,
2071 const char * ServiceParameterName ) {
2072 // cdebug_in << "GraphExecutor::OutNode::GetOutData " << NodeName << " "
2073 // << ServiceParameterName << endl ;
2074 const CORBA::Any * retdata = Graph()->PortOutData( NodeName , ServiceParameterName ) ;
2075 // cdebug_out << "GraphExecutor::OutNode::GetOutData" << endl ;
2079 const long GraphExecutor::OutNode::CpuUsed() {
2080 return Graph()->CpuUsed() ;
2083 const long GraphExecutor::OutNode::CpuUsed( const char * aNodeName ) {
2084 GraphBase::ComputingNode * aNode = Graph()->GetChangeGraphNode( aNodeName ) ;
2086 GraphExecutor::InNode * anInNode = (GraphExecutor::InNode * ) aNode->GetInNode() ;
2088 return anInNode->CpuUsed() ;
2094 // remove equal sets "Node-Event-State" from _EventNodes/_Events/_States queues
2095 void GraphExecutor::OutNode::siftEvents() {
2096 list<char*>::reverse_iterator itNodes = _EventNodes.rbegin();
2097 list<GraphExecutor::NodeEvent>::reverse_iterator itEvents = _Events.rbegin();
2098 list<GraphExecutor::AutomatonState>::reverse_iterator itStates = _States.rbegin();
2099 list<char*> _NewEventNodes;
2100 list<GraphExecutor::NodeEvent> _NewEvents;
2101 list<GraphExecutor::AutomatonState> _NewStates;
2102 for ( ; itNodes != _EventNodes.rend() ; ++itNodes, ++itEvents, ++itStates) {
2103 //cout << "----- aNodeName ==> " << *itNodes;
2104 list<char*>::reverse_iterator itNewNodes = _NewEventNodes.rbegin();
2106 for ( ; itNewNodes != _NewEventNodes.rend() ; ++itNewNodes ) {
2107 if ( !strcmp( *itNewNodes, *itNodes ) ) {
2117 _NewEventNodes.push_back( *itNodes );
2118 _NewEvents.push_back( *itEvents );
2119 _NewStates.push_back( *itStates );
2123 _EventNodes = _NewEventNodes;
2124 _Events = _NewEvents;
2125 _States = _NewStates;