]> SALOME platform Git repositories - modules/superv.git/blob - src/GraphExecutor/DataFlowExecutor_OutNode.cxx
Salome HOME
InitLoop and DoLoop parameters names
[modules/superv.git] / src / GraphExecutor / DataFlowExecutor_OutNode.cxx
1 //  SUPERV GraphExecutor : contains classes that permit execution of graphs and particularly the execution automaton
2 //
3 //  Copyright (C) 2003  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 //  CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS 
5 // 
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. 
10 // 
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. 
15 // 
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 
19 // 
20 //  See http://www.opencascade.org/SALOME/ or email : webmaster.salome@opencascade.org 
21 //
22 //
23 //
24 //  File   : DataFlowBase_OutNode.cxx
25 //  Author : Jean Rahuel, CEA
26 //  Module : SUPERV
27 //  $Header:
28
29 using namespace std;
30
31 #include "DataFlowExecutor_OutNode.hxx"
32
33 #include "DataFlowEditor_DataFlow.hxx"
34
35 extern Engines_Container_i * _TheContainer ;
36
37 extern GraphExecutor::FiniteStateMachine * theAutomaton ;
38
39 // static const char *ComponentName = "SalomeSuperVisionComponent" ;
40
41 extern int _ArgC ;
42 extern char ** _ArgV ;
43
44 GraphExecutor::OutNode::OutNode() {
45 //               Graph() {
46   _SuperVisionContainer = _TheContainer ;
47   _MainThreadId = SuperVisionContainer()->MainThreadId() ;
48   _Valid = false ;
49   _Executable = false ;
50   _Done = false ;
51   _Threads = 0 ;
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 )") ;
59     exit( 0 ) ;
60   }
61   if ( pthread_cond_init( &_JoinWait , NULL ) ) {
62     perror("pthread_cond_init( &_JoinWait , NULL )") ;
63     exit( 0 ) ;
64   }
65 }
66
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 ) {
76     _StreamGraph = NULL ;
77 //    _Graph = new GraphBase::Graph( ORB , ptrNamingService , DataFlowName , DebugFileName ) ;
78     _Graph = new GraphBase::Graph( ORB , ptrNamingService , DataFlowName , aKindOfNode ,
79                                    _prof_debug , _fdebug ) ;
80   }
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 ;
86   }
87   _SuperVisionContainer = _TheContainer ;
88   _MainThreadId = SuperVisionContainer()->MainThreadId() ;
89   _Valid = false ;
90   _Executable = false ;
91   _Done = false ;
92   _Threads = 0 ;
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 )") ;
101     exit( 0 ) ;
102   }
103   if ( pthread_cond_init( &_JoinWait , NULL ) ) {
104     perror("pthread_cond_init( &_JoinWait , NULL )") ;
105     exit( 0 ) ;
106   }
107   cdebug_out << "GraphExecutor::OutNode::OutNode" << endl;
108 }
109
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 ) ;
130
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 ) ;
141   }
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 ;
150   }
151   _SuperVisionContainer = _TheContainer ;
152   _MainThreadId = SuperVisionContainer()->MainThreadId() ;
153   _Valid = false ;
154   _Executable = false ;
155   _Done = false ;
156   _Threads = 0 ;
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 )") ;
165     exit( 0 ) ;
166   }
167   if ( pthread_cond_init( &_JoinWait , NULL ) ) {
168     perror("pthread_cond_init( &_JoinWait , NULL )") ;
169     exit( 0 ) ;
170   }
171 }
172
173 GraphExecutor::OutNode::~OutNode() {
174 }
175
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)
183   }
184 }
185
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" );
192     if ( RetVal ) {
193       RetVal = LoadNodes( (*aDataFlow).Nodes ) ;
194       if ( RetVal ) {
195         RetVal = LoadLinks( (*aDataFlow).Links ) ;
196         if ( RetVal ) {
197           IsValid() ;
198           RetVal = LoadDatas( (*aDataFlow).Datas ) ;
199           IsExecutable() ;
200           if ( !RetVal) {
201             cdebug << "GraphExecutor::OutNode::LoadDataFlow LoadDatas Error."
202                    << endl ;
203           }
204         }
205         else {
206           cdebug << "GraphExecutor::OutNode::LoadDataFlow LoadLinks Error."
207                << endl ;
208         }
209       }
210       else {
211         cdebug << "GraphExecutor::OutNode::LoadDataFlow LoadNodes Error."
212              << endl ;
213       }
214     }
215     else {
216       cdebug << "GraphExecutor::OutNode::LoadDataFlow LoadInfo Error."
217            << endl ;
218     }
219   }
220   else {
221     cdebug << "GraphExecutor::OutNode::LoadDataFlow ServiceName Error." << endl ;
222   }
223   cdebug_out << "GraphExecutor::OutNode::LoadDataFlow " << Graph()->Name() << " RetVal "
224              << RetVal << endl ;
225   return RetVal ;
226 }
227
228 #if 0
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() ) ;
236   }
237   return RetVal ;
238 }
239 #endif
240
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 ) ;
248   }
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 ) ;
258   return true ;
259 }
260
261 bool GraphExecutor::OutNode::LoadNodes(const GraphBase::ListOfSNodes &aListOfNodes ) {
262   bool RetVal = true ;
263   GraphExecutor::InNode * anInNode ;
264   cdebug << "GraphExecutor::OutNode::LoadNodes" << endl ;
265   int i ;
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() ,
273                         aNode.theKind ,
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 ) ;
279     if ( !anInNode ) {
280       RetVal = false ;
281       break ;
282     }
283     if ( anInNode->IsOneOfInLineNodes() || anInNode->IsMacroNode() ) {
284       anInNode->GraphExecutor::InNode::InLineNode()->DefPortsOfNode(
285                                 _Orb , aNode.theService , anInNode->NamePtr() ,
286                                 anInNode->Kind() ,
287                                 _prof_debug , _fdebug ) ;
288     }
289 //    GraphBase::ComputingNode * theNode = Graph()->GetChangeGraphNode( aNode.theName.c_str() ) ;
290
291     unsigned int j ;
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 ) ;
301     }
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 ) ;
309     }
310
311
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
319 //           << endl ;
320 //    int j ;
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 ) ;
327 //      }
328 //    }
329 //    if ( aNode.theDataStreamOutArgsNumber ) {
330 //      int withgate = 1 ;
331 //      if ( theNode->IsLoopNode() || theNode->IsEndLoopNode() ) {
332 //        withgate = 0 ;
333 //      }
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 ) ;
339 //      }
340 //    }
341   }
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 ) ;
354       }
355       else {
356         aCoupledNode->CoupledNodeName( aNode.theCoupledNode.c_str() ) ;
357       }
358     }
359   }
360   return RetVal ;
361 }
362
363 bool GraphExecutor::OutNode::LoadLinks(const GraphBase::ListOfSLinks &aListOfLinks ) {
364   bool RetVal = true ;
365   cdebug << "GraphExecutor::OutNode::LoadLinks " << aListOfLinks.size()
366          << endl ;
367   int i ;
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 ) ;
375     if ( !RetVal )
376       break ;
377   }
378   return RetVal ;
379 }
380
381 bool GraphExecutor::OutNode::LoadDatas(const GraphBase::ListOfSLinks &aListOfDatas ) {
382   bool RetVal = true ;
383   cdebug << "GraphExecutor::OutNode::LoadDatas " << aListOfDatas.size()
384          << endl ;
385   int i ;
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() ,
391                                       aLink.aLinkValue ) ;
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 ) ;
396 //    }
397     else {
398       cdebug << "GraphExecutor::OutNode::LoadDatas Error " << aLink.FromNodeName
399            << " and " << aLink.ToNodeName << " differents from " << Graph()->Name()
400            << endl ;
401       RetVal = false ;
402     }
403     if ( !RetVal )
404       break ;
405   }
406   return RetVal ;
407 }
408
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 ,
423                       const int NodeX ,
424                       const int NodeY ) {
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;
438   return Nd ;
439 }
440
441
442 bool GraphExecutor::OutNode::Valid() {
443   cdebug_in << "GraphExecutor::OutNode::Valid" << endl;
444
445   if ( _Valid )
446     return true ;
447
448   _Executable = false ;
449
450   if ( !Graph()->CreateService() ) {
451     cdebug_out << "This DataFlow has invalid type(s)." << endl ;
452     return false ;
453   }
454   int SubStreamGraphsNumber = 0 ;
455   if ( !Graph()->Sort( SubStreamGraphsNumber ) ) {
456     cdebug_out << "This DataFlow is not valid." << endl ;
457     return false ;
458   }
459   if ( Graph()->IsDataStreamNode() ) {
460     StreamGraph()->SubStreamGraphsNumber( SubStreamGraphsNumber ) ;
461   }
462   if ( !Graph()->ValidLoops() ) {
463     cdebug_out << "This DataFlow have not valid Loops." << endl ;
464     return false ;
465   }
466
467 //  CreateService() ;
468
469   Graph()->InLineServices() ;
470
471   Graph()->ComputingNodes() ;
472   
473   _Valid = true ;
474
475   cdebug_out << "GraphExecutor::OutNode::Valid" << endl;
476   return _Valid ;
477 }
478
479
480 bool GraphExecutor::OutNode::Executable() {
481
482   cdebug_in << "GraphExecutor::OutNode::Executable" << endl;
483   if ( !IsValid() )
484     return false ;
485
486   if ( Graph()->DataServerNodes() )
487     _Executable = true ;
488   else {
489     cdebug << "This DataFlow is not executable." << endl ;
490     _Executable = false ;
491   }
492
493   cdebug_out << "GraphExecutor::OutNode::Executable " << _Executable << endl;
494   return _Executable ;
495 }
496
497 bool GraphExecutor::OutNode::Run( const bool AndSuspend ) {
498   bool RetVal = false ;
499   cdebug_in << pthread_self() << "GraphExecutor::OutNode::Run( AndSuspend " << AndSuspend << " )"
500             << endl;
501
502   if ( Executable() ) {
503     _ControlState = SUPERV::VoidState ;
504     _SuspendedThreads = 0 ;
505     Graph()->ThreadNo( pthread_self() ) ;
506     Done( false ) ;
507     _JustStarted = true ;
508     RetVal = true ;
509     int i ;
510     for ( i = 0 ; i < Graph()->GraphNodesSize() ; i++ ) {
511       GraphExecutor::InNode * anInNode = (GraphExecutor::InNode *) Graph()->GraphNodes( i )->GetInNode() ;
512       anInNode->OutNode( this ) ;
513 // Initialize in python interpretor the python functions
514       if ( !PyInitialized() && anInNode->IsOneOfInLineNodes() ) {
515         if ( !Py_IsInitialized() ) {
516 //          PyEval_InitThreads() ;
517 //          Py_Initialize() ;
518 //          PySys_SetArgv( _ArgC , _ArgV ) ;
519         }
520         anInNode->InitPython() ;
521         PyInitialized( true ) ;
522       }
523       anInNode->InitialState() ;
524       if ( anInNode->IsOneOfInLineNodes() ) {
525         anInNode->InitPythonFunctions( false ) ;
526       }
527     }
528 // One more time because inline nodes may share one definition of the same function
529     for ( i = 0 ; i < Graph()->GraphNodesSize() ; i++ ) {
530       GraphExecutor::InNode * anInNode = (GraphExecutor::InNode *) Graph()->GraphNodes( i )->GetInNode() ;
531       if ( anInNode->IsOneOfInLineNodes() ) {
532         if ( !anInNode->InitPythonFunctions( true ) ) {
533           anInNode->State( GraphExecutor::ErroredState ) ;
534           State( GraphExecutor::ErroredState ) ;
535           cdebug_out << "GraphExecutor::OutNode::Run InitPythonFunctions ERROR "
536                      << anInNode->Name() << endl ;
537           return false ;
538         }
539       }
540     }
541     /* asv : 29.09.04 : commented out because it does not do anything useful 
542     for ( i = 0 ; i < Graph()->GraphNodesSize() ; i++ ) {
543       GraphExecutor::InNode * anInNode = (GraphExecutor::InNode *) Graph()->GraphNodes( i )->GetInNode() ;
544       if ( RetVal && anInNode->IsMacroNode() ) {
545         GraphBase::Graph * aMacroGraph = anInNode->GraphMacroNode() ;
546         cdebug << "GraphExecutor::OutNode::Run " << anInNode << " MacroNode " << aMacroGraph
547                << aMacroGraph->Name() << endl ;
548         SUPERV::Graph_var iobject = anInNode->GraphMacroNode()->MacroObject() ;
549         if ( CORBA::is_nil( iobject ) ) {
550           cdebug << "GraphExecutor::OutNode::Run MacroObject() is a nil object. Error" << endl ;
551           RetVal = false ;
552         }
553         else {
554           cdebug << "GraphExecutor::OutNode::Run MacroObject() is NOT a nil object." << endl ;
555         }
556       }
557     }
558     */
559     if ( Graph()->GraphMacroLevel() != 0 ) {
560       cdebug << "GraphExecutor::OutNode::Run Execution starting GraphExecutor::Action_DataOk_RunService Node "
561              << Graph()->Name() << " GraphMacroLevel " << Graph()->GraphMacroLevel() << endl ;
562       PushEvent( NULL , GraphExecutor::NoDataReadyEvent ,
563                  GraphExecutor::DataUndefState ) ; 
564     }
565     else {
566       cdebug << "Execution starting GraphExecutor::Action_DataOk_RunService Node "
567              << Graph()->Name() << " GraphMacroLevel " << Graph()->GraphMacroLevel() << endl ;
568       PushEvent( NULL , GraphExecutor::ReadyEvent ,
569                  GraphExecutor::DataReadyState ) ; 
570       State( GraphExecutor::DataReadyState ) ;
571
572       cdebug << pthread_self() << " GraphExecutor::OutNode::Run Start of the " << Graph()->HeadNodesSize()
573              << " HeadNodes" << endl ;
574       for ( i = 0 ; i < Graph()->HeadNodesSize() ; i++ ) {
575         GraphExecutor::InNode * anInNode = (GraphExecutor::InNode *) Graph()->HeadNodes( i )->GetInNode() ;
576         cdebug << pthread_self() <<  "GraphExecutor::OutNode::Run Start of HeadNode " << i << " "
577                << anInNode->Name() << endl ;
578         if ( anInNode->State() != GraphExecutor::DataReadyState ) {
579           cdebug << "GraphExecutor::OutNode::Run inconsistency State of Node "
580                  << anInNode->Name() << " : " << anInNode->State() << endl ;
581           cdebug_out << "GraphExecutor::OutNode::Run State ERROR" << endl ;
582           return false ;
583         }
584 //        PushEvent( anInNode , GraphExecutor::ReadyEvent ,
585 //                   GraphExecutor::DataReadyState ) ; 
586 // We say that we have to create a thread for that HeadNode 'anInNode'
587         anInNode->CreateNewThread( true ) ;
588         anInNode->DataFromNode( Graph()->Name() ) ;
589 // AndSuspend == true <==> Start()
590         if ( AndSuspend ) {
591           anInNode->State( GraphExecutor::DataWaitingState ) ;
592           anInNode->ControlState( SUPERV::ToSuspendStartState ) ;
593 // We send SomeDataReadyEvent
594 // It is a HeadNode ==> AllDataReadyEvent ==> InNode::executeAction() ==> pthread_create
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 ;
599             return false ;
600           }
601 // ==> We wait for SuspendedState
602           anInNode->SuspendedWait() ;
603         }
604 // AndSuspend == false <==> Run()
605         else if ( anInNode->IsMacroNode() ) {
606           if ( !anInNode->SendEvent( GraphExecutor::SomeDataReadyEvent ) ) {
607             cdebug << "InNode::SendEvent( SomeDataReadyEvent ) ERROR Node "
608                    << anInNode->Name() << endl ;
609             cdebug_out << "GraphExecutor::OutNode::Run SendEvent ERROR" << endl ;
610             return false ;
611           }
612           cdebug << pthread_self() << " GraphExecutor::OutNode::Run " << anInNode->Name() << "->RunningWait"
613                  << endl ;
614 // ==> We wait for RunningState
615           anInNode->RunningWait() ;
616           cdebug << pthread_self() << " GraphExecutor::OutNode::Run " << anInNode->Name() << "->RunningWaited"
617                  << endl ;
618         }
619         else if ( !anInNode->IsMacroNode() ) {
620 // It is a HeadNode ==> AllDataReadyEvent ==> InNode::executeAction() ==> pthread_create
621           if ( !anInNode->SendEvent( GraphExecutor::ExecuteEvent ) ) {
622             cdebug << "InNode::SendEvent( ExecuteEvent ) ERROR Node "
623                    << anInNode->Name() << endl ;
624             cdebug_out << "GraphExecutor::OutNode::Run SendEvent ERROR" << endl ;
625             return false ;
626           }
627 // ==> We wait for RunningState
628           anInNode->RunningWait() ;
629         }
630       }
631
632       if ( AndSuspend ) {
633         PushEvent( NULL , GraphExecutor::SuspendedReadyEvent ,
634                    GraphExecutor::SuspendedReadyState ) ; 
635       }
636       else {
637         PushEvent( NULL , GraphExecutor::ExecutingEvent ,
638                    GraphExecutor::ExecutingState ) ; 
639         if (AutomatonState() == GraphExecutor::DataReadyState) {
640             State( GraphExecutor::ExecutingState ) ;
641         };
642       }
643 //      ostringstream astr ;
644 //      astr << "Graph " << Graph()->Name() << " is running" ;
645 //      Graph()->ObjImpl()->sendMessage( NOTIF_STEP, astr.str().c_str() ) ;
646       RetVal = true ;
647     }
648   }
649
650   cdebug_out << pthread_self() << "GraphExecutor::OutNode::Run " << Graph()->Name()
651              << " GraphMacroLevel "
652              << Graph()->GraphMacroLevel() << " RetVal " << RetVal << endl ;
653   return RetVal ;
654 }
655
656 void GraphExecutor::OutNode::CheckAllDone() {
657   int j ;
658   cdebug_in << "GraphExecutor::OutNode::CheckAllDone " << endl;
659   GraphExecutor::AutomatonState OutNodeState = GraphExecutor::SuccessedState ;
660   GraphExecutor::AutomatonState InNodeState ;
661   bool AllDone = true ;
662   if ( !Done() ) {
663     for ( j = 0 ; j < Graph()->QueueNodesSize() ; j++ ) {
664       InNodeState = ( (GraphExecutor::InNode * ) Graph()->QueueNodes( j )->GetInNode() )->State() ;
665       cdebug << j << ". "
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 ) {
671         AllDone = false ;
672       }
673       if ( InNodeState != GraphExecutor::SuccessedState &&
674            InNodeState != GraphExecutor::DataWaitingState &&
675            InNodeState != GraphExecutor::DataReadyState ) {
676         OutNodeState = InNodeState ;
677       }
678     }
679     if ( AllDone ) {
680       if( _Threads == 0 && _SuspendedThreads == 0 ) {
681         if ( OutNodeState != GraphExecutor::ErroredState ) {
682           OutNodeState = GraphExecutor::SuccessedState ;
683         }
684       }
685       else {
686         AllDone = false ;
687       }
688     }
689     if ( AllDone ) {
690       int alivenodes = 0 ;
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()
697                << endl ;
698         if ( aState == SUPERV::ErrorState ||
699              aState == SUPERV::SuspendErroredState ||
700              aState == SUPERV::KillState ||
701              aState == SUPERV::StopState ) {
702           OutNodeState = aNode->State() ;
703           State( OutNodeState ) ;
704         }
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::SuspendState ) {
711           alivenodes += 1 ;
712         }
713         aNode->SuspendedAction() ;
714         aNode->DoneAction() ;
715       }
716 // PushEvent AFTER State and _Done ! ...
717       if ( alivenodes == 0 ) {
718         State( OutNodeState ) ;
719         Done( true ) ;
720         _JustStarted = false ;
721       }
722       cdebug << Graph()->Name() << " alivenodes " << alivenodes << " OutNodeState " << OutNodeState
723              << endl ;
724       PushEvent( NULL , GraphExecutor::EndExecuteEvent ,
725                  OutNodeState ) ;
726 //      Py_Finalize() ;
727 //      PyInitialized( false ) ;
728     }
729   }
730   if ( IsDone() ) {
731     MESSAGE("================================================================================") ;
732     MESSAGE( Graph()->Name() << " IS DONE : " <<  theAutomaton->StateName( AutomatonState() ) << " EventQSize "
733              << EventQSize() ) ;
734     MESSAGE("================================================================================") ;
735     cdebug << "================================================================================" << endl ;
736     cdebug << Graph()->Name() << " IS DONE : " <<  theAutomaton->StateName( AutomatonState() ) << " EventQSize "
737              << EventQSize() << endl  ;
738     cdebug << "================================================================================" << endl ;
739
740     // asv : fix for 6798 and other bugs: "sift" the event queue after execution
741     siftEvents();
742
743     // asv : 25.10.04 : calling Editing() to indicate stop of execution
744     Graph()->GraphEditor()->Editing();
745   }
746   cdebug_out << "GraphExecutor::OutNode::CheckAllDone " << IsDone() << " this " << this << " "
747              << Graph()->Name() << " GraphAutomatonState "
748              << theAutomaton->StateName( AutomatonState() )
749              << " State " << State() << " Threads " << _Threads << " SuspendedThreads "
750              << _SuspendedThreads << " EventQSize " << EventQSize() << endl ;
751 }
752
753 Engines_Container_i * GraphExecutor::OutNode::SuperVisionContainer() {
754   return _SuperVisionContainer ;
755 }
756
757 const pthread_t GraphExecutor::OutNode::MainThreadId() const {
758   return _MainThreadId ;
759 }
760
761 void GraphExecutor::OutNode::PThreadLock( pthread_mutex_t * aMutex , char * errmsg ) {
762 //  if ( strcmp( errmsg , "EventLoop" ) && strcmp( errmsg , "EventW" ) ) {
763 //    cdebug << "GraphExecutor::OutNode::PThreadLock " << pthread_self() << " " << aMutex << " "
764 //           << errmsg << endl ;
765 //  }
766   if ( pthread_mutex_lock( aMutex ) ) {
767     perror( errmsg ) ;
768     exit( 0 ) ;
769   }
770 //  if ( strcmp( errmsg , "EventLoop" ) && strcmp( errmsg , "EventW" ) ) {
771 //    cdebug << "GraphExecutor::OutNode::PThreadLocked " << pthread_self() << " " << aMutex << " "
772 //           << errmsg << endl ;
773 //  }
774 }
775
776 void GraphExecutor::OutNode::PThreadUnLock( pthread_mutex_t * aMutex , char * errmsg ) {
777 //  if ( strcmp( errmsg , "EventLoop" ) && strcmp( errmsg , "EventW" ) ) {
778 //    cdebug << " GraphExecutor::OutNode::PThreadUnLock " << pthread_self() << " " << aMutex << " "
779 //           << errmsg << endl ;
780 //  }
781   if ( pthread_mutex_unlock( aMutex ) ) {
782     perror( errmsg ) ;
783     exit( 0 ) ;
784   }
785 }
786
787 void GraphExecutor::OutNode::PyThreadLock() {
788 //  cout << " GraphExecutor::OutNode::PyThreadLock " << pthread_self() << endl ;
789   if ( pthread_mutex_lock( &_PyMutexWait ) ) {
790     perror( "GraphExecutor::OutNode::PyThreadLock" ) ;
791     exit( 0 ) ;
792   }
793   theAutomaton->PyLock() ;
794 //  cout << " GraphExecutor::OutNode::PyThreadLocked " << pthread_self() << endl ;
795 }
796
797 void GraphExecutor::OutNode::PyThreadUnLock() {
798 //  cout << " GraphExecutor::OutNode::PyThreadUnLock " << pthread_self() << endl ;
799   if ( pthread_mutex_unlock( &_PyMutexWait ) ) {
800     perror( "GraphExecutor::OutNode::PyThreadUnLock" ) ;
801     exit( 0 ) ;
802   }
803   theAutomaton->PyUnLock() ;
804 //  cout << " GraphExecutor::OutNode::PyThreadUnLocked " << pthread_self() << endl ;
805 }
806
807 void GraphExecutor::OutNode::NewThread() {
808   if ( pthread_mutex_lock( &_MutexWait ) ) {
809     perror("pthread_mutex_lock _NewThread") ;
810     exit( 0 ) ;
811   }
812   _Threads += 1 ;
813   cdebug << "NewThread : " << _Threads << " running threads "
814          << _SuspendedThreads << " suspended threads"
815          << endl ;
816   if ( pthread_mutex_unlock( &_MutexWait ) ) {
817     perror("pthread_mutex_unlock _NewThread") ;
818     exit( 0 ) ;
819   }
820 }
821
822 void GraphExecutor::OutNode::ExitThread( pthread_t ThreadNumber ) {
823   if ( pthread_mutex_lock( &_MutexWait ) ) {
824     perror("pthread_mutex_lock _ExitThread") ;
825     exit( 0 ) ;
826   }
827   if ( ThreadNumber == 0 ) {
828     ThreadNumber = pthread_self() ;
829   }
830   _Threads -= 1 ;
831   cdebug << pthread_self() << " ExitThread( " << ThreadNumber << " ) " << _Threads << " running threads "
832          << _SuspendedThreads << " suspended threads"
833          << endl ;
834   theAutomaton->JoinThread( ThreadNumber ) ;
835   if ( pthread_cond_signal( &_JoinWait ) ) {
836     perror("ExitThread pthread_cond_signal ") ;
837   }
838   if ( pthread_mutex_unlock( &_MutexWait ) ) {
839     perror("pthread_mutex_unlock _ExitThread") ;
840     exit( 0 ) ;
841   }
842   if ( _Threads == 0 && _SuspendedThreads == 0 ) {
843     CheckAllDone() ;
844     if ( IsDone() ) {
845       theAutomaton->Executed() ;
846     }
847   }
848 }
849 void GraphExecutor::OutNode::JoinedWait() {
850   if ( pthread_mutex_lock( &_MutexWait ) ) {
851     perror("pthread_mutex_lock JoinedWait") ;
852     exit( 0 ) ;
853   }
854   while ( _Threads ) {
855     if ( pthread_cond_wait( &_JoinWait , &_MutexWait ) ) {
856       perror("JoinedWait pthread_cond_wait ") ;
857     }
858   }
859   if ( pthread_mutex_unlock( &_MutexWait ) ) {
860     perror("pthread_mutex_unlock JoinedWait") ;
861     exit( 0 ) ;
862   }
863 }
864
865 void GraphExecutor::OutNode::SuspendThread() {
866   if ( pthread_mutex_lock( &_MutexWait ) ) {
867     perror("pthread_mutex_lock _SuspendThread") ;
868     exit( 0 ) ;
869   }
870   _SuspendedThreads += 1 ;
871   cdebug << "SuspendThread : " << _Threads << " running threads "
872          << _SuspendedThreads << " suspended threads"
873          << endl ;
874   if ( pthread_mutex_unlock( &_MutexWait ) ) {
875     perror("pthread_mutex_unlock _SuspendThread") ;
876     exit( 0 ) ;
877   }
878   if ( IsSuspended() ) {
879     PushEvent( NULL , GraphExecutor::SuspendEvent , GraphExecutor::SuspendedState ) ;
880   }
881 }
882 void GraphExecutor::OutNode::ResumeThread() {
883   if ( pthread_mutex_lock( &_MutexWait ) ) {
884     perror("pthread_mutex_lock _ResumeThread") ;
885     exit( 0 ) ;
886   }
887   _SuspendedThreads -= 1 ;
888   cdebug << "ResumeThread : " << _Threads << " running threads "
889          << _SuspendedThreads << " suspended threads"
890          << endl ;
891   if ( pthread_mutex_unlock( &_MutexWait ) ) {
892     perror("pthread_mutex_unlock _ResumeThread") ;
893     exit( 0 ) ;
894   }
895 }
896
897 long GraphExecutor::OutNode::Thread( const char * aNodeName ) {
898   long RetVal = 0 ;
899   GraphExecutor::InNode *anInNode = (GraphExecutor::InNode *) Graph()->GetGraphNode( aNodeName )->GetInNode() ;
900   if ( anInNode ) {
901     RetVal = anInNode->ThreadNo() ;
902   }
903   return RetVal ;
904 }
905
906 SUPERV::GraphEvent GraphExecutor::OutNode::AutomatonGraphEvent(GraphExecutor::NodeEvent anEvent ) {
907   SUPERV::GraphEvent aGraphEvent ;
908   switch ( anEvent ) {
909   case GraphExecutor::UndefinedEvent : {
910     aGraphEvent = SUPERV::UndefinedEvent ;
911     break ;
912   }
913   case GraphExecutor::NewThreadEvent : {
914     aGraphEvent = SUPERV::NewThreadEvent ;
915     break ;
916   }
917   case GraphExecutor::SuspendEvent : {
918     aGraphEvent = SUPERV::SuspendEvent ;
919     break ;
920   }
921   case GraphExecutor::ResumeEvent : {
922     aGraphEvent = SUPERV::ResumeEvent ;
923     break ;
924   }
925   case GraphExecutor::KillEvent : {
926     aGraphEvent = SUPERV::KillEvent ;
927     break ;
928   }
929   case GraphExecutor::StopEvent : {
930     aGraphEvent = SUPERV::StopEvent ;
931     break ;
932   }
933   case GraphExecutor::ExecuteEvent : {
934     aGraphEvent = SUPERV::RunningEvent ;
935     break ;
936   }
937   case GraphExecutor::SuccessEvent : {
938     aGraphEvent = SUPERV::DoneEvent ;
939     break ;
940   }
941   case GraphExecutor::ErrorEvent : {
942     aGraphEvent = SUPERV::ErroredEvent ;
943     break ;
944   }
945   case GraphExecutor::NoDataReadyEvent : {
946     aGraphEvent = SUPERV::WaitingEvent ;
947     break ;
948   }
949   case GraphExecutor::SomeDataReadyEvent : {
950     aGraphEvent = SUPERV::WaitingEvent ;
951     break ;
952   }
953   case GraphExecutor::NotAllDataReadyEvent : {
954     aGraphEvent = SUPERV::WaitingEvent ;
955     break ;
956   }
957   case GraphExecutor::AllDataReadyEvent : {
958     aGraphEvent = SUPERV::ReadyEvent ;
959     break ;
960   }
961   case GraphExecutor::ReadyEvent : {
962     aGraphEvent = SUPERV::ReadyEvent ;
963     break ;
964   }
965   case GraphExecutor::SuspendedReadyEvent : {
966     aGraphEvent = SUPERV::SuspendEvent ;
967     break ;
968   }
969   case GraphExecutor::ResumedReadyEvent : {
970     aGraphEvent = SUPERV::ResumeEvent ;
971     break ;
972   }
973   case GraphExecutor::KilledReadyEvent : {
974     aGraphEvent = SUPERV::KillEvent ;
975     break ;
976   }
977   case GraphExecutor::StoppedReadyEvent : {
978     aGraphEvent = SUPERV::StopEvent ;
979     break ;
980   }
981   case GraphExecutor::ExecutingEvent : {
982     aGraphEvent = SUPERV::RunningEvent ;
983     break ;
984   }
985   case GraphExecutor::SuspendedExecutingEvent : {
986     aGraphEvent = SUPERV::SuspendEvent ;
987     break ;
988   }
989   case GraphExecutor::ResumedExecutingEvent : {
990     aGraphEvent = SUPERV::ResumeEvent ;
991     break ;
992   }
993   case GraphExecutor::KilledExecutingEvent : {
994     aGraphEvent = SUPERV::KillEvent ;
995     break ;
996   }
997   case GraphExecutor::StoppedExecutingEvent : {
998     aGraphEvent = SUPERV::StopEvent ;
999     break ;
1000   }
1001   case GraphExecutor::SuccessedExecutingEvent : {
1002     aGraphEvent = SUPERV::DoneEvent ;
1003     break ;
1004   }
1005   case GraphExecutor::ErroredExecutingEvent : {
1006     aGraphEvent = SUPERV:: ErroredEvent;
1007     break ;
1008   }
1009   case GraphExecutor::SuspendedSuccessedEvent : {
1010     aGraphEvent = SUPERV::SuspendEvent ;
1011     break ;
1012   }
1013   case GraphExecutor::SuspendedErroredEvent : {
1014     aGraphEvent = SUPERV::SuspendEvent ;
1015     break ;
1016   }
1017   case GraphExecutor::ResumedSuccessedEvent : {
1018     aGraphEvent = SUPERV::ResumeEvent ;
1019     break ;
1020   }
1021   case GraphExecutor::ResumedErroredEvent : {
1022     aGraphEvent = SUPERV::ResumeEvent ;
1023     break ;
1024   }
1025   case GraphExecutor::KilledEvent : {
1026     aGraphEvent = SUPERV::KillEvent ;
1027     break ;
1028   }
1029   case GraphExecutor::StoppedEvent : {
1030     aGraphEvent = SUPERV::StopEvent ;
1031     break ;
1032   }
1033   case GraphExecutor::EndExecuteEvent : {
1034     aGraphEvent = SUPERV::DoneEvent ;
1035     break ;
1036   }
1037   default : {
1038     cdebug << " GraphExecutor::OutNode::AutomatonGraphEvent Error Undefined Event : "
1039            << anEvent << endl ;
1040     aGraphEvent = SUPERV::UndefinedEvent ;
1041   }
1042   }
1043   return aGraphEvent ;
1044 }
1045
1046 SUPERV::GraphState GraphExecutor::OutNode::AutomatonGraphState(GraphExecutor::AutomatonState aState ) {
1047   SUPERV::GraphState aGraphState ;
1048   switch ( aState ) {
1049   case GraphExecutor::UnKnownState : {
1050     aGraphState = SUPERV::UndefinedState ;
1051     break ;
1052   }
1053   case GraphExecutor::DataUndefState : {
1054     aGraphState = SUPERV::UndefinedState ;
1055     break ;
1056   }
1057   case GraphExecutor::DataWaitingState : {
1058     aGraphState = SUPERV::WaitingState ;
1059     break ;
1060   }
1061   case GraphExecutor::DataReadyState : {
1062     aGraphState = SUPERV::ReadyState ;
1063     break ;
1064   }
1065   case GraphExecutor::SuspendedReadyState : {
1066     aGraphState = SUPERV::SuspendReadyState ;
1067     break ;
1068   }
1069   case GraphExecutor::ResumedReadyState : {
1070     aGraphState = SUPERV::ReadyState ;
1071     break ;
1072   }
1073   case GraphExecutor::KilledReadyState : {
1074     aGraphState = SUPERV::KillState ;
1075     break ;
1076   }
1077   case GraphExecutor::StoppedReadyState : {
1078     aGraphState = SUPERV::StopState ;
1079     break ;
1080   }
1081   case GraphExecutor::ExecutingState : {
1082     aGraphState = SUPERV::RunningState ;
1083     break ;
1084   }
1085   case GraphExecutor::SuspendedExecutingState : {
1086     aGraphState = SUPERV::SuspendState ;
1087     break ;
1088   }
1089   case GraphExecutor::ResumedExecutingState : {
1090     aGraphState = SUPERV::RunningState ;
1091     break ;
1092   }
1093   case GraphExecutor::KilledExecutingState : {
1094     aGraphState = SUPERV::KillState ;
1095     break ;
1096   }
1097   case GraphExecutor::StoppedExecutingState : {
1098     aGraphState = SUPERV::StopState ;
1099     break ;
1100   }
1101   case GraphExecutor::SuccessedExecutingState : {
1102     aGraphState = SUPERV::DoneState ;
1103     break ;
1104   }
1105   case GraphExecutor::ErroredExecutingState : {
1106     aGraphState = SUPERV::ErrorState ;
1107     break ;
1108   }
1109   case GraphExecutor::SuspendedSuccessedState : {
1110     aGraphState = SUPERV::SuspendDoneState ;
1111     break ;
1112   }
1113   case GraphExecutor::SuspendedErroredState : {
1114     aGraphState = SUPERV::SuspendErroredState ;
1115     break ;
1116   }
1117   case GraphExecutor::ResumedSuccessedState : {
1118     aGraphState = SUPERV::DoneState ;
1119     break ;
1120   }
1121   case GraphExecutor::ResumedErroredState : {
1122     aGraphState = SUPERV::ErrorState ;
1123     break ;
1124   }
1125   case GraphExecutor::KilledSuccessedState : {
1126     aGraphState = SUPERV::KillState ;
1127     break ;
1128   }
1129   case GraphExecutor::KilledErroredState : {
1130     aGraphState = SUPERV::KillState ;
1131     break ;
1132   }
1133   case GraphExecutor::StoppedSuccessedState : {
1134     aGraphState = SUPERV::StopState ;
1135     break ;
1136   }
1137   case GraphExecutor::StoppedErroredState : {
1138     aGraphState = SUPERV::StopState ;
1139     break ;
1140   }
1141   case GraphExecutor::SuccessedState : {
1142     aGraphState = SUPERV::DoneState ;
1143     break ;
1144   }
1145   case GraphExecutor::ErroredState : {
1146     aGraphState = SUPERV::ErrorState ;
1147     break ;
1148   }
1149   case GraphExecutor::SuspendedState : {
1150     aGraphState = SUPERV::SuspendState ;
1151     break ;
1152   }
1153   case GraphExecutor::KilledState : {
1154     aGraphState = SUPERV::KillState ;
1155     break ;
1156   }
1157   case GraphExecutor::StoppedState : {
1158     aGraphState = SUPERV::StopState ;
1159     break ;
1160   }
1161   case GraphExecutor::LoadingState : {
1162     aGraphState = SUPERV::LoadingState ;
1163     break;
1164   }
1165   default : {
1166     cdebug << " GraphExecutor::OutNode::AutomatonGraphState Error Undefined State : "
1167            << aGraphState << endl ;
1168     aGraphState = SUPERV::UndefinedState ;
1169   }
1170   }
1171   return aGraphState ;
1172 }
1173
1174 int GraphExecutor::OutNode::GetListSize() {
1175   return _EventNodes.size();
1176 }
1177
1178 bool GraphExecutor::OutNode::PushEvent( GraphExecutor::InNode * aNode ,
1179                                         GraphExecutor::NodeEvent anEvent ,
1180                                         GraphExecutor::AutomatonState aState ) {
1181 //  cdebug_in << "PushEvent Threads " << Threads() << " SuspendedThreads "
1182 //            << SuspendedThreads() << endl ;
1183   if ( pthread_mutex_lock( &_MutexWait ) ) {
1184     perror("PushEvent pthread_mutex_lock ") ;
1185     exit( 0 ) ;
1186   }
1187   char* aNodeName = aNode ? aNode->Name() : Graph()->Name() ;
1188   _EventNodes.push_back( aNodeName ) ;
1189   _Events.push_back( anEvent ) ;
1190   _States.push_back( aState ) ;
1191
1192   pthread_cond_broadcast( &_EventWait );
1193   cdebug << pthread_self() << " PushEvent Threads " << Threads() << " SuspendedThreads "
1194          << SuspendedThreads() << " pthread_cond_broadcast _EventWait " << &_EventWait << endl ;
1195   if ( aNode ) {
1196 //    cdebug << aNode->ThreadNo() << " PushEvent " << aNode->Name() ;
1197 //    cdebug << " " << aNode->Automaton()->EventName( anEvent )
1198 //           << " " << aNode->Automaton()->StateName( aState )
1199 //           << " ControleState "
1200 //           << aNode->Automaton()->ControlStateName( aNode->ControlState() ) ;
1201   }
1202   else {
1203 //    cdebug << "PushEvent " << Graph()->Name() ;
1204 //    cdebug << " " << theAutomaton->EventName( anEvent ) << " "
1205 //           << theAutomaton->StateName( aState ) ;
1206   }
1207 //  cdebug_out << "PushEvent Threads " << Threads() << " SuspendedThreads "
1208 //             << SuspendedThreads() << endl ;
1209 #if 0
1210   if ( _EventNodes.size() > 101 ) {
1211     while ( _EventNodes.size() > 31 ) {
1212       _EventNodes.pop_front() ;
1213       _Events.pop_front() ;
1214       _States.pop_front() ;
1215     }
1216   }
1217 #endif
1218   if ( pthread_mutex_unlock( &_MutexWait ) ) {
1219     perror("PushEvent pthread_mutex_unlock ") ;
1220     exit( 0 ) ;
1221   }
1222   return true ;
1223 }
1224
1225 bool GraphExecutor::OutNode::StateWait( SUPERV::GraphState aState ) {
1226   return false ;
1227 }
1228
1229 bool GraphExecutor::OutNode::Event( char ** aNodeName ,
1230                                     SUPERV::GraphEvent & anEvent ,
1231                                     SUPERV::GraphState & aState ,
1232                                     bool WithWait ) {
1233   // asv : fixing problem of loops with large number of iterations (>5000)
1234   // experimentally was found that number of non-handled by GUI events = (number_of_nodes x 7)
1235   // or 7 events for each node - so what we want to do here is remove "old" events for nodes
1236   // "on the fly".  Once again it is done in Stop(), Kill(), Done() functions.
1237   if ( _EventNodes.size() > (unsigned int)Graph()->GraphNodesSize()*7 )
1238     siftEvents();
1239
1240   int ThreadsNumber ;
1241   int SuspendedThreadsNumber ;
1242   bool cdebuginout = false ;
1243   if ( _EventNodes.size() > 0 ) {
1244 //    cdebug_in << "GraphExecutor::OutNode::Event " << _EventNodes.size() << " in queue" << endl ;
1245     cdebuginout = true ;
1246   }
1247   if ( pthread_mutex_lock( &_MutexWait ) ) {
1248     perror("EventLoop pthread_mutex_lock ") ;
1249     exit( 0 ) ;
1250   }
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 ;
1263     RetVal = false ;
1264   }
1265   else if ( !WithWait && _EventNodes.size() == 0 ) {
1266     anEvent = SUPERV::NoEvent ;
1267     aState = SUPERV::NoState ;
1268     RetVal = true ;
1269   }
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 ;
1276     }
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() ;
1287     }
1288   }
1289   *aNodeName = NodeName ;
1290   if ( IsSuspended() && _EventNodes.size() == 0 ) {
1291     RetVal = false ;
1292   }
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 ;
1299   }
1300   if ( pthread_mutex_unlock( &_MutexWait ) ) {
1301     perror("EventLoop pthread_mutex_lock ") ;
1302     exit( 0 ) ;
1303   }
1304   if ( cdebuginout ) {
1305 //    cdebug_out << "GraphExecutor::OutNode::Event " << _EventNodes.size() << " in queue"
1306 //               << *aNodeName << " " << anEvent << " " << aState << endl ;
1307   }
1308   return RetVal ;
1309 }
1310
1311 bool GraphExecutor::OutNode::EventW( char ** aNodeName ,
1312                                      SUPERV::GraphEvent & anEvent ,
1313                                      SUPERV::GraphState & aState ) {
1314   bool sts = true ;
1315   char * NodeName ;
1316   aState = SUPERV::UndefinedState ;
1317   while ( sts &&
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 ;
1326     }
1327   }
1328   return sts ;
1329 }
1330
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 ") ;
1336     exit( 0 ) ;
1337   }
1338   int ThreadsNumber ;
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 ;
1352     RetVal = 0 ;
1353   }
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 ) ;
1362
1363       if ( _JustStarted ) {
1364         _JustStarted = false ;
1365       }
1366       else {
1367         _EventNodes.pop_front() ;
1368         _Events.pop_front() ;
1369         _States.pop_front() ;
1370       }
1371
1372       aNode = ((GraphExecutor::InNode *) Graph()->GetGraphNode( NodeName )->GetInNode()) ;
1373       cdebug << "EventW Previous Node " << NodeName << " ThreadsNumber "
1374              << ThreadsNumber
1375              << " _EventNodes.size() " << _EventNodes.size() << " "
1376              << theAutomaton->StateName( theState )
1377              << " Threads " << Threads() << " SuspendedThreads "
1378              << SuspendedThreads() << endl ;
1379       if ( aNode ) {
1380       }
1381       else if ( IsDone() && _EventNodes.size() == 0 ) {
1382         cdebug << "EventW IsDone() && _EventNodes.size() == 0" << endl ;
1383         RetVal = 0 ;
1384       }
1385       else {
1386         cdebug << "EventW Not InNode " << NodeName
1387                << " _EventNodes.size() " << _EventNodes.size() << endl ;
1388         while ( _EventNodes.size() == 0 ) {
1389           pthread_cond_wait( &_EventWait , &_MutexWait );
1390         }
1391         cdebug << "EventW pthread_cond_waited Not InNode " << NodeName
1392                << " _EventNodes.size() " << _EventNodes.size() << endl ;
1393       }
1394     }
1395
1396     if ( aNode ) {
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 ") ;
1405             exit( 0 ) ;
1406           }
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 ") ;
1412             exit( 0 ) ;
1413           }
1414         }
1415         else {
1416           cdebug << "EventW inconsistent SuspendState" << endl ;
1417           RetVal = false ; 
1418         }
1419       }
1420       else {
1421         if ( aNode->IsDone() ) {
1422           RetVal = true ;
1423         }
1424         else {
1425           cdebug << "EventW NOT SuspendedState _EventNodes.size() "
1426                  << _EventNodes.size() << endl ;
1427           RetVal = true ;
1428         }
1429       }
1430       if ( RetVal ) {
1431         cdebug << "EventW " << aNode->Name() << " pthread_cond_wait" << endl ;
1432         while ( _EventNodes.size() == 0 ) {
1433           pthread_cond_wait( &_EventWait , &_MutexWait );
1434         }
1435         ThreadsNumber = Threads() ;
1436         NodeName = _EventNodes.front() ;
1437         theEvent = _Events.front() ;
1438         anEvent = AutomatonGraphEvent( theEvent ) ;
1439         theState = _States.front() ;
1440         aState = AutomatonGraphState( theState ) ;
1441       }
1442     }
1443   }
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 ") ;
1453     exit( 0 ) ;
1454   }
1455   return RetVal ;
1456 }
1457 long GraphExecutor::OutNode::EventQSize() {
1458   return _EventNodes.size() ;
1459 }
1460
1461 void GraphExecutor::OutNode::EventList() {
1462   if ( pthread_mutex_lock( &_MutexWait ) ) {
1463     perror("EventList pthread_mutex_lock ") ;
1464     exit( 0 ) ;
1465   }
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 ;
1474     itEventNodes++ ;
1475     itEvents++ ;
1476     itStates++ ;
1477   }
1478   if ( pthread_mutex_unlock( &_MutexWait ) ) {
1479     perror("EventList pthread_mutex_lock ") ;
1480     exit( 0 ) ;
1481   }
1482 }
1483
1484 void GraphExecutor::OutNode::SendSomeDataReady( const char * aNodeName ) {
1485   cdebug_in << "GraphExecutor::OutNode::SendSomeDataReady " << aNodeName << "->SendSomeDataReady( "
1486             << Graph()->Name() << " )" << endl;
1487   int sts ;
1488   sts = ((GraphExecutor::InNode * ) Graph()->GetChangeGraphNode( aNodeName )->GetInNode())->SendSomeDataReady( Graph()->Name() ) ;
1489   cdebug_out << "GraphExecutor::OutNode::SendSomeDataReady sts " << sts << endl ;
1490 }
1491
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 ;
1496   _State = aState ;
1497 }
1498
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 ) ;
1505 }
1506
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 ) ;
1511   if ( aCNode ) {
1512     GraphExecutor::InNode *anInNode = (GraphExecutor::InNode *)aCNode->GetInNode() ;
1513     if ( anInNode ) {
1514       if ( anInNode->IsLoading() )
1515         aret = GraphExecutor::LoadingState;
1516       else
1517         aret = anInNode->State() ;
1518 //      cdebug << "GraphExecutor::OutNode::State( " << NodeName << " ) "
1519 //             << theAutomaton->StateName( AutomatonGraphState( aret ) ) << endl ;
1520     }
1521   }
1522 //  cdebug_out << "GraphExecutor::OutNode::State" << endl ;
1523   return AutomatonGraphState( aret ) ;
1524 }
1525
1526 SUPERV::GraphState GraphExecutor::OutNode::State( const char * NodeName ,
1527                                                   const char * ServiceParameterName )  {
1528 //  cdebug_in << "GraphExecutor::OutNode::State " << NodeName << " "
1529 //            << ServiceParameterName<< endl;
1530   SUPERV::GraphState aret = Graph()->PortState( NodeName , ServiceParameterName ) ;
1531 //  cdebug_out << "GraphExecutor::OutNode::State" << endl ;
1532   return aret ;
1533 }
1534
1535 GraphExecutor::AutomatonState GraphExecutor::OutNode::AutomatonState() {
1536 //  cdebug_in << "GraphExecutor::OutNode::AutomatonState" << endl;
1537 //  cdebug_out << "GraphExecutor::OutNode::AutomatonState" << endl ;
1538   return _State ;
1539 }
1540
1541 GraphExecutor::AutomatonState GraphExecutor::OutNode::AutomatonState( const char * NodeName ) {
1542 //  cdebug_in << "GraphExecutor::OutNode::AutomatonState " << NodeName << endl;
1543   GraphExecutor::AutomatonState aret = GraphExecutor::UnKnownState ;
1544   const GraphBase::ComputingNode * aNode = Graph()->GetGraphNode( NodeName ) ;
1545   if ( aNode ) {
1546     GraphExecutor::InNode *anInNode = (GraphExecutor::InNode *) aNode->GetInNode() ;
1547     if ( anInNode ) {
1548       aret = anInNode->State() ;
1549     }
1550   }
1551 //  cdebug_out << "GraphExecutor::OutNode::AutomatonState" << endl ;
1552   return aret ;
1553 }
1554
1555 SUPERV::ControlState GraphExecutor::OutNode::ControlState() {
1556 //  cdebug_in << "GraphExecutor::OutNode::ControlState" << endl;
1557 //  cdebug_out << "GraphExecutor::OutNode::ControlState" << endl ;
1558   return _ControlState ;
1559 }
1560
1561 SUPERV::ControlState GraphExecutor::OutNode::ControlState( const char * NodeName ) {
1562 //  cdebug_in << "GraphExecutor::OutNode::ControlState " << NodeName << endl;
1563   SUPERV::ControlState aret = SUPERV::VoidState ;
1564   const GraphBase::ComputingNode * aNode = Graph()->GetGraphNode( NodeName ) ;
1565   if ( aNode ) {
1566     GraphExecutor::InNode *anInNode = (GraphExecutor::InNode *) aNode->GetInNode() ;
1567     if ( anInNode ) {
1568       aret = anInNode->ControlState() ;
1569     }
1570   }
1571 //  cdebug_out << "GraphExecutor::OutNode::ControlState" << endl ;
1572   return aret ;
1573 }
1574
1575 void GraphExecutor::OutNode::ControlClear() {
1576 //  cdebug_in << "GraphExecutor::OutNode::ControlClear" << endl;
1577 //  cdebug_out << "GraphExecutor::OutNode::ControlClear" << endl ;
1578   _ControlState = SUPERV::VoidState;
1579 }
1580
1581 void GraphExecutor::OutNode::ControlClear( const char * NodeName ) {
1582 //  cdebug_in << "GraphExecutor::OutNode::ControlClear " << NodeName << endl;
1583   const GraphBase::ComputingNode * aNode = Graph()->GetGraphNode( NodeName ) ;
1584   if ( aNode ) {
1585     GraphExecutor::InNode *anInNode = (GraphExecutor::InNode *) aNode->GetInNode() ;
1586     if ( anInNode ) {
1587       anInNode->ControlClear() ;
1588     }
1589   }
1590 //  cdebug_out << "GraphExecutor::OutNode::ControlClear" << endl ;
1591 }
1592
1593 bool GraphExecutor::OutNode::IsWaiting() {
1594 //  cdebug_in << "GraphExecutor::OutNode::IsWaiting" << endl;
1595 //  cdebug_out << "GraphExecutor::OutNode::IsWaiting" << endl ;
1596   return !IsDone() ;
1597 }
1598
1599 bool GraphExecutor::OutNode::IsReady() {
1600 //  cdebug_in << "GraphExecutor::OutNode::IsReady" << endl;
1601 //  cdebug_out << "GraphExecutor::OutNode::IsReady" << endl ;
1602   return !IsDone() ;
1603 }
1604
1605 bool GraphExecutor::OutNode::IsRunning() {
1606 //  cdebug_in << "GraphExecutor::OutNode::IsRunning" << endl;
1607 //  cdebug_out << "GraphExecutor::OutNode::IsRunning" << endl ;
1608   return !IsDone() ;
1609 }
1610
1611 bool GraphExecutor::OutNode::IsDone() {
1612 //  cdebug_in << "GraphExecutor::OutNode::IsDone" << endl;
1613 //  cdebug_out << "GraphExecutor::OutNode::IsDone" << endl ;
1614   return ( Done() || IsKilled() || IsStopped() ) ;
1615 }
1616
1617 bool GraphExecutor::OutNode::IsSuspended() {
1618 //  cdebug_in << "GraphExecutor::OutNode::IsSuspended" << endl;
1619   bool aret = false ;
1620 //  if ( _SuspendedThreads == _Threads && _Threads != 0 ) {
1621   if ( AutomatonGraphState( _State ) ==  SUPERV::SuspendState ) {
1622     aret = true ;
1623   }
1624 //  cdebug_out << "GraphExecutor::OutNode::IsSuspended" << endl ;
1625   return aret ;
1626 }
1627
1628 bool GraphExecutor::OutNode::IsKilled() {
1629 //  cdebug_in << "GraphExecutor::OutNode::IsKilled" << endl;
1630   bool aret = false ;
1631   if ( AutomatonGraphState( _State ) == SUPERV::KillState ) {
1632     aret = true ;
1633   }
1634 //  cdebug_out << "GraphExecutor::OutNode::IsKilled" << endl ;
1635   return aret ;
1636 }
1637
1638 bool GraphExecutor::OutNode::IsStopped() {
1639 //  cdebug_in << "GraphExecutor::OutNode::IsStopped" << endl;
1640   bool aret = false ;
1641   if ( AutomatonGraphState( _State ) == SUPERV::StopState ) {
1642     aret = true ;
1643   }
1644 //  cdebug_out << "GraphExecutor::OutNode::IsStopped" << endl ;
1645   return aret ;
1646 }
1647
1648 bool GraphExecutor::OutNode::IsWaiting( const char * NodeName ) {
1649   bool aret = false ;
1650 //  cdebug_in << "GraphExecutor::OutNode::IsWaiting " << NodeName << endl;
1651   GraphExecutor::InNode *anInNode = (GraphExecutor::InNode *) Graph()->GetGraphNode( NodeName )->GetInNode() ;
1652   if ( anInNode ) {
1653     aret = anInNode->IsWaiting() ;
1654   }
1655 //  cdebug_out << "GraphExecutor::OutNode::IsWaiting" << endl ;
1656   return aret ;
1657 }
1658
1659 bool GraphExecutor::OutNode::IsReady( const char * NodeName ) {
1660   bool aret = false ;
1661 //  cdebug_in << "GraphExecutor::OutNode::IsReady " << NodeName << endl;
1662   GraphExecutor::InNode *anInNode = (GraphExecutor::InNode *) Graph()->GetGraphNode( NodeName )->GetInNode() ;
1663   if ( anInNode ) {
1664     aret = anInNode->IsReady() ;
1665   }
1666 //  cdebug_out << "GraphExecutor::OutNode::IsReady" << endl ;
1667   return aret ;
1668 }
1669
1670 bool GraphExecutor::OutNode::IsRunning( const char * NodeName ) {
1671   bool aret = false ;
1672 //  cdebug_in << "GraphExecutor::OutNode::IsRunning " << NodeName << endl;
1673   GraphExecutor::InNode *anInNode = (GraphExecutor::InNode *) Graph()->GetGraphNode( NodeName )->GetInNode() ;
1674   if ( anInNode ) {
1675     aret = anInNode->IsRunning() ;
1676   }
1677 //  cdebug_out << "GraphExecutor::OutNode::IsRunning" << endl ;
1678   return aret ;
1679 }
1680
1681 bool GraphExecutor::OutNode::IsDone( const char * NodeName ) {
1682   bool aret = false ;
1683 //  cdebug_in << "GraphExecutor::OutNode::IsDone " << NodeName << endl;
1684   GraphExecutor::InNode *anInNode = (GraphExecutor::InNode *) Graph()->GetGraphNode( NodeName )->GetInNode() ;
1685   if ( anInNode ) {
1686     aret = anInNode->IsDone() ;
1687   }
1688 //  cdebug_out << "GraphExecutor::OutNode::IsDone" << endl ;
1689   return aret ;
1690 }
1691
1692 bool GraphExecutor::OutNode::IsSuspended( const char * NodeName ) {
1693   bool aret = false ;
1694 //  cdebug_in << "GraphExecutor::OutNode::IsSuspended " << NodeName << endl;
1695   GraphExecutor::InNode *anInNode = (GraphExecutor::InNode *) Graph()->GetGraphNode( NodeName )->GetInNode() ;
1696   if ( anInNode ) {
1697     aret = anInNode->IsSuspended() ;
1698   }
1699 //  cdebug_out << "GraphExecutor::OutNode::IsSuspended" << endl ;
1700   return aret ;
1701 }
1702
1703 bool GraphExecutor::OutNode::IsDone( const char * NodeName ,
1704                                      const char * ServiceParameterName )  {
1705 //  cdebug_in << "GraphExecutor::OutNode::IsDone " << NodeName << " "
1706 //            << ServiceParameterName<< endl;
1707   bool aret = Graph()->PortDone( NodeName , ServiceParameterName ) ;
1708 //  cdebug_out << "GraphExecutor::OutNode::IsDone" << endl ;
1709   return aret ;
1710 }
1711
1712 bool GraphExecutor::OutNode::ContainerKill() {
1713   bool RetVal = true ;
1714   cdebug_in << "GraphExecutor::OutNode::ContainerKill" << endl;
1715   _ControlState = SUPERV::ToSuspendState ;
1716   int i ;
1717   for ( i = 0 ; i < Graph()->GraphNodesSize() ; i++ ) {
1718     GraphExecutor::InNode * aNode = (GraphExecutor::InNode * ) Graph()->GraphNodes( i )->GetInNode() ;
1719     bool sts = aNode->ContainerKill() ;
1720     if ( sts && aNode->IsKilled() ) {
1721       cdebug << aNode->Name() << " killed" << endl ;
1722     }
1723     else if ( aNode->IsWaiting() || aNode->IsDone() ) {
1724       cdebug << aNode->Name() << " not killed : "
1725              << theAutomaton->StateName( aNode->State() ) << endl ;
1726     }
1727     else {
1728       cdebug << aNode->Name() << " cannot be killed : "
1729              << theAutomaton->StateName( aNode->State() ) << endl ;
1730       RetVal = false ;
1731     }
1732   }
1733   if ( !RetVal || Threads() != 0 ) {
1734     for ( i = 0 ; i < Graph()->GraphNodesSize() ; i++ ) {
1735       GraphExecutor::InNode * aNode = (GraphExecutor::InNode * ) Graph()->GraphNodes( i )->GetInNode() ;
1736       if ( !aNode->IsKilled() && !aNode->IsWaiting() && !aNode->IsDone() ) {
1737         aNode->KilledAction() ;
1738       }
1739     }
1740     RetVal = true ;
1741   }
1742   State( GraphExecutor::KilledState ) ;
1743   cdebug_out << "GraphExecutor::OutNode::ContainerKill" << endl ;
1744   return RetVal ;
1745 }
1746
1747 bool GraphExecutor::OutNode::Suspend() {
1748   int RetVal = 0 ;
1749   cdebug_in << "GraphExecutor::OutNode::Suspend" << endl;
1750 //  _ControlState = SUPERV::ToSuspendState ;
1751   int i ;
1752   for ( i = 0 ; i < Graph()->GraphNodesSize() ; i++ ) {
1753     GraphExecutor::InNode * aNode = (GraphExecutor::InNode * ) Graph()->GraphNodes( i )->GetInNode() ;
1754     bool sts = aNode->Suspend() ;
1755     if ( sts && aNode->IsSuspended() ) {
1756       RetVal += 1 ;
1757       cdebug << aNode->Name() << " Suspended" << endl ;
1758     }
1759     else if ( aNode->IsWaiting() || aNode->IsReady() ) {
1760       RetVal += 1 ;
1761       cdebug << aNode->Name() << " will be Suspended" << endl ;
1762     }
1763     else if ( aNode->IsDone() ) {
1764       cdebug << aNode->Name() << " not Suspended : "
1765              << theAutomaton->StateName( aNode->State() ) << endl ;
1766     }
1767     else {
1768 //      RetVal += 1 ;
1769       cdebug << aNode->Name() << " cannot be Suspended : "
1770              << theAutomaton->StateName( aNode->State() ) << endl ;
1771     }
1772   }
1773   if ( RetVal ) {
1774     State( GraphExecutor::SuspendedState ) ;
1775     MESSAGE("================================================================================") ;
1776     MESSAGE( Graph()->Name() << " IS SUSPENDED" ) ;
1777     MESSAGE("================================================================================") ;
1778   }
1779   else {
1780     MESSAGE("================================================================================") ;
1781     MESSAGE( Graph()->Name() << " IS NOT SUSPENDED" ) ;
1782     MESSAGE("================================================================================") ;
1783   }
1784   for ( i = 0 ; i < Graph()->GraphNodesSize() ; i++ ) {
1785     GraphExecutor::InNode * aNode = (GraphExecutor::InNode * ) Graph()->GraphNodes( i )->GetInNode() ;
1786     MESSAGE(aNode->Name() << " " << theAutomaton->StateName( aNode->State() ) ) ;
1787     cdebug << aNode->Name() << " " << theAutomaton->StateName( aNode->State() ) << endl ;
1788   }
1789   cdebug_out << "GraphExecutor::OutNode::Suspend " << theAutomaton->StateName( State() )
1790              << " EventQSize " << EventQSize() << endl ;
1791   return RetVal ;
1792 }
1793
1794 bool GraphExecutor::OutNode::Resume() {
1795   int RetVal = 0 ;
1796   cdebug_in << "GraphExecutor::OutNode::Resume "
1797             << theAutomaton->StateName( State() ) << endl;
1798   if ( IsSuspended() ) {
1799     State( GraphExecutor::ExecutingState ) ;
1800     int i ;
1801     for ( i = 0 ; i < Graph()->GraphNodesSize() ; i++ ) {
1802       GraphExecutor::InNode * aNode = (GraphExecutor::InNode * ) Graph()->GraphNodes( i )->GetInNode() ;
1803       aNode->ControlState( SUPERV::VoidState ) ;
1804       if ( aNode->IsSuspended() ) {
1805         cdebug << aNode->Name() << "->Resume " << theAutomaton->StateName( aNode->State() )
1806                << endl ;
1807         if ( aNode->Resume() ) {
1808           cdebug << aNode->Name() << " Resumed " << theAutomaton->StateName( aNode->State() )
1809                  << endl ;
1810           RetVal += 1 ;
1811         }
1812         else {
1813           cdebug << aNode->Name() << " Resume failed"
1814                  << theAutomaton->StateName( aNode->State() ) << endl ;
1815         }
1816       }
1817       else {
1818         cdebug << aNode->Name() << " " << theAutomaton->StateName( aNode->State() )
1819                << endl ;
1820       }
1821     }
1822   }
1823   else {
1824     cdebug << Graph()->Name() << " not suspended " << theAutomaton->StateName( State() ) << endl ;
1825   }
1826   if ( RetVal ) {
1827     MESSAGE("================================================================================") ;
1828     MESSAGE( Graph()->Name() << " IS RESUMED" ) ;
1829     MESSAGE("================================================================================") ;
1830   }
1831   else {
1832     MESSAGE("================================================================================") ;
1833     MESSAGE( Graph()->Name() << " IS NOT RESUMED" ) ;
1834     MESSAGE("================================================================================") ;
1835   }
1836   int i ;
1837   for ( i = 0 ; i < Graph()->GraphNodesSize() ; i++ ) {
1838     GraphExecutor::InNode * aNode = (GraphExecutor::InNode * ) Graph()->GraphNodes( i )->GetInNode() ;
1839     MESSAGE(aNode->Name() << " " << theAutomaton->StateName( aNode->State() ) ) ;
1840     cdebug << aNode->Name() << " " << theAutomaton->StateName( aNode->State() ) << endl ;
1841   }
1842   cdebug_out << "GraphExecutor::OutNode::Resume" << theAutomaton->StateName( State() ) << " " << RetVal
1843              << " EventQSize " << EventQSize() << endl ;
1844   return RetVal ;
1845 }
1846
1847 bool GraphExecutor::OutNode::Kill() {
1848   bool RetVal = false ;
1849   cdebug_in << "GraphExecutor::OutNode::Kill"
1850              << " EventQSize " << EventQSize() << endl;
1851   _ControlState = SUPERV::ToSuspendState ;
1852   int i ;
1853   for ( i = 0 ; i < Graph()->GraphNodesSize() ; i++ ) {
1854     GraphExecutor::InNode * aNode = (GraphExecutor::InNode * ) Graph()->GraphNodes( i )->GetInNode() ;
1855     bool sts = aNode->Kill() ;
1856     if ( sts && Threads() != 0 ) {
1857       if ( !aNode->IsKilled() ) {
1858         cdebug << aNode->Name() << " not killed : "
1859                << theAutomaton->StateName( aNode->State() ) << " " << aNode->Name() << "->"
1860                << "KilledAction()" << endl ;
1861         MESSAGE( aNode->Name() << " not killed : KilledAction()" ) ;
1862         aNode->KilledAction() ;
1863       }
1864       if ( aNode->IsKilled() ) {
1865         cdebug << aNode->Name() << " killed" << endl ;
1866         RetVal = true ;
1867       }
1868     }
1869     else if ( aNode->IsWaiting() || aNode->IsDone() ) {
1870       cdebug << aNode->Name() << " not killed : "
1871              << theAutomaton->StateName( aNode->State() ) << endl ;
1872     }
1873     else {
1874       cdebug << aNode->Name() << " cannot be killed : "
1875              << theAutomaton->StateName( aNode->State() ) << endl ;
1876     }
1877   }
1878   if ( RetVal ) {
1879     State( GraphExecutor::KilledState ) ;
1880     MESSAGE("================================================================================") ;
1881     MESSAGE( Graph()->Name() << " IS KILLED" <<  theAutomaton->StateName( AutomatonState() ) << " EventQSize "
1882              << EventQSize() ) ;
1883     MESSAGE("================================================================================") ;
1884   }
1885   else {
1886     MESSAGE("================================================================================") ;
1887     MESSAGE( Graph()->Name() << " IS NOT KILLED" ) ;
1888     MESSAGE("================================================================================") ;
1889   }
1890   for ( i = 0 ; i < Graph()->GraphNodesSize() ; i++ ) {
1891     GraphExecutor::InNode * aNode = (GraphExecutor::InNode * ) Graph()->GraphNodes( i )->GetInNode() ;
1892     MESSAGE(aNode->Name() << " " << theAutomaton->StateName( aNode->State() ) ) ;
1893     cdebug << aNode->Name() << " " << theAutomaton->StateName( aNode->State() ) << endl ;
1894   }
1895   cdebug_out << "GraphExecutor::OutNode::Kill " << RetVal
1896              << " Threads " << _Threads << " SuspendedThreads " << _SuspendedThreads
1897              << " EventQSize " << EventQSize() << endl ;
1898
1899   // remove "extra" events from the event queue
1900   siftEvents();
1901
1902   // asv : 25.10.04 : calling Editing() to indicate stop of execution
1903   Graph()->GraphEditor()->Editing();
1904
1905   return RetVal ;
1906 }
1907
1908 bool GraphExecutor::OutNode::Stop() {
1909   bool RetVal = false ;
1910   cdebug_in << "GraphExecutor::OutNode::Stop" << endl;
1911   RetVal = Kill() ;
1912   cdebug_out << "GraphExecutor::OutNode::Stop" << endl ;
1913   if ( RetVal ) {
1914     MESSAGE("================================================================================") ;
1915     MESSAGE( Graph()->Name() << " IS STOPPED" ) ;
1916     MESSAGE("================================================================================") ;
1917   }
1918   return RetVal ;
1919 }
1920
1921 bool GraphExecutor::OutNode::ReadyWait() {
1922   cdebug_in << "GraphExecutor::OutNode::ReadyWait" << endl;
1923   bool aret ;
1924   if ( pthread_mutex_lock( &_MutexWait ) ) {
1925     perror("pthread_mutex_lock _ReadyWait") ;
1926     exit( 0 ) ;
1927   }
1928   aret = IsReady() ;
1929   if ( !aret ) {
1930     Suspend() ;
1931     pthread_cond_wait( &_EventWait , &_MutexWait );
1932     aret = IsReady() ;
1933   }
1934   if ( pthread_mutex_unlock( &_MutexWait ) ) {
1935     perror("pthread_mutex_lock _ReadyWait") ;
1936     exit( 0 ) ;
1937   }
1938   cdebug_out << "GraphExecutor::OutNode::ReadyWait" << endl ;
1939   return aret ;
1940 }
1941
1942 bool GraphExecutor::OutNode::RunningWait() {
1943   cdebug_in << "GraphExecutor::OutNode::RunningWait" << endl;
1944   bool aret ;
1945   if ( pthread_mutex_lock( &_MutexWait ) ) {
1946     perror("pthread_mutex_lock _RunningWait") ;
1947     exit( 0 ) ;
1948   }
1949   aret = IsRunning() ;
1950   if ( !aret ) {
1951     cdebug << "RunningWait pthread_cond_wait _EventWait" << endl;
1952     pthread_cond_wait( &_EventWait , &_MutexWait );
1953     aret = IsRunning() ;
1954     cdebug << "RunningWait pthread_cond_waited _EventWait " << aret << endl;
1955   }
1956   if ( pthread_mutex_unlock( &_MutexWait ) ) {
1957     perror("pthread_mutex_lock _RunningWait") ;
1958     exit( 0 ) ;
1959   }
1960   cdebug_out << "GraphExecutor::OutNode::RunningWait " << aret << endl ;
1961   return aret ;
1962 }
1963
1964 bool GraphExecutor::OutNode::DoneWait() {
1965   cdebug_in << pthread_self() << " GraphExecutor::DoneWait " << this << " " << Graph()->Name() << endl;
1966   bool aret ;
1967   if ( pthread_mutex_lock( &_MutexWait ) ) {
1968     perror("pthread_mutex_lock _DoneWait") ;
1969     exit( 0 ) ;
1970   }
1971   aret = IsDone() ;
1972   while ( !aret && !IsSuspended() && IsRunning() ) {
1973     cdebug << pthread_self() << " GraphExecutor::DoneWait " << this << " " << Graph()->Name()
1974            << " DoneWait pthread_cond_wait _EventWait " << &_EventWait << endl;
1975     pthread_cond_wait( &_EventWait , &_MutexWait );
1976     aret = IsDone() ;
1977     cdebug << pthread_self() << " GraphExecutor::DoneWait " << this << " " << Graph()->Name()
1978            << " DoneWait pthread_cond_waited _EventWaited " << &_EventWait << " : "<< aret << endl;
1979   }
1980   if ( pthread_mutex_unlock( &_MutexWait ) ) {
1981     perror("pthread_mutex_lock _DoneWait") ;
1982     exit( 0 ) ;
1983   }
1984   cdebug_out << pthread_self() << " GraphExecutor::DoneWait " << this << " " << Graph()->Name()
1985              << " " << State() << " : " << aret << endl ;
1986   return aret ;
1987 }
1988
1989 bool GraphExecutor::OutNode::SuspendedWait() {
1990   cdebug_in << "GraphExecutor::OutNode::SuspendedWait" << endl;
1991   bool aret ;
1992   if ( pthread_mutex_lock( &_MutexWait ) ) {
1993     perror("pthread_mutex_lock _SuspendedWait") ;
1994     exit( 0 ) ;
1995   }
1996   aret = IsSuspended() ;
1997   while ( !aret && !IsDone() ) {
1998     pthread_cond_wait( &_EventWait , &_MutexWait );
1999     aret = IsSuspended() ;
2000   }
2001   if ( pthread_mutex_unlock( &_MutexWait ) ) {
2002     perror("pthread_mutex_lock _SuspendedWait") ;
2003     exit( 0 ) ;
2004   }
2005   cdebug_out << "GraphExecutor::OutNode::SuspendedWait" << endl ;
2006   return aret ;
2007 }
2008
2009 bool GraphExecutor::OutNode::ReadyWait( const char * NodeName ) {
2010   bool aret = false ;
2011   cdebug_in << "GraphExecutor::OutNode::ReadyWait " << NodeName << endl;
2012   GraphExecutor::InNode *anInNode = (GraphExecutor::InNode *) Graph()->GetGraphNode( NodeName )->GetInNode() ;
2013   if ( anInNode ) {
2014     aret = anInNode->ReadyWait() ;
2015   }
2016   cdebug_out << "GraphExecutor::OutNode::ReadyWait" << endl ;
2017   return aret ;
2018 }
2019
2020 bool GraphExecutor::OutNode::RunningWait( const char * NodeName ) {
2021   bool aret = false ;
2022   cdebug_in << "GraphExecutor::OutNode::RunningWait " << NodeName << endl;
2023   GraphExecutor::InNode *anInNode = (GraphExecutor::InNode *) Graph()->GetGraphNode( NodeName )->GetInNode() ;
2024   if ( anInNode ) {
2025     aret = anInNode->RunningWait() ;
2026   }
2027   cdebug_out << "GraphExecutor::OutNode::RunningWait" << endl ;
2028   return aret ;
2029 }
2030
2031 bool GraphExecutor::OutNode::DoneWait( const char * NodeName ) {
2032   bool aret = false ;
2033   cdebug_in << "GraphExecutor::OutNode::DoneWait " << NodeName << endl;
2034   GraphExecutor::InNode *anInNode = (GraphExecutor::InNode *) Graph()->GetGraphNode( NodeName )->GetInNode() ;
2035   if ( anInNode ) {
2036     aret = anInNode->DoneWait() ;
2037   }
2038   cdebug_out << "GraphExecutor::OutNode::DoneWait" << endl ;
2039   return aret ;
2040 }
2041
2042 bool GraphExecutor::OutNode::SuspendedWait( const char * NodeName ) {
2043   bool aret = false ;
2044   cdebug_in << "GraphExecutor::OutNode::SuspendedWait " << NodeName << endl;
2045   GraphExecutor::InNode *anInNode = (GraphExecutor::InNode *) Graph()->GetGraphNode( NodeName )->GetInNode() ;
2046   if ( anInNode ) {
2047     aret = anInNode->SuspendedWait() ;
2048   }
2049   cdebug_out << "GraphExecutor::OutNode::SuspendedWait" << endl ;
2050   return aret ;
2051 }
2052
2053 long GraphExecutor::OutNode::LastLevelDone() {
2054   int RetVal = -1 ;
2055   int i , j ;
2056   for ( i = 0 ; i <= Graph()->LevelMax() ; i++ ) {
2057     for ( j = 0 ; j <= Graph()->NodesNumber( i ) ; j++ ) {
2058       GraphBase::ComputingNode * aNode = Graph()->SortedNodes( i , j ) ;
2059       if ( !IsDone( aNode->Name() ) ) {
2060         break ;
2061       }
2062     }
2063     if ( j != Graph()->NodesNumber( i ) + 1 )
2064       break ;
2065     RetVal = i ;
2066   }
2067   return RetVal ;
2068 }
2069
2070
2071 const CORBA::Any *GraphExecutor::OutNode::GetInData( const char * NodeName ,
2072                                                      const char * ServiceParameterName ) {
2073 //  cdebug_in << "GraphExecutor::OutNode::GetInData " << NodeName << " "
2074 //            << ServiceParameterName << endl ;
2075   const CORBA::Any * retdata = Graph()->PortInData( NodeName , ServiceParameterName ) ;
2076 //  cdebug_out << "GraphExecutor::OutNode::GetInData" << endl ;
2077   return retdata ;
2078 }
2079
2080 const CORBA::Any *GraphExecutor::OutNode::GetOutData( const char * NodeName ,
2081                                                       const char * ServiceParameterName ) {
2082 //  cdebug_in << "GraphExecutor::OutNode::GetOutData " << NodeName << " "
2083 //            << ServiceParameterName << endl ;
2084   const CORBA::Any * retdata = Graph()->PortOutData( NodeName , ServiceParameterName ) ;
2085 //  cdebug_out << "GraphExecutor::OutNode::GetOutData" << endl ;
2086   return retdata ;
2087 }
2088
2089 const long GraphExecutor::OutNode::CpuUsed() {
2090   return Graph()->CpuUsed() ;
2091 }
2092
2093 const long GraphExecutor::OutNode::CpuUsed( const char * aNodeName ) {
2094   GraphBase::ComputingNode * aNode = Graph()->GetChangeGraphNode( aNodeName ) ;
2095   if ( aNode ) {
2096     GraphExecutor::InNode * anInNode = (GraphExecutor::InNode * ) aNode->GetInNode() ;
2097     if ( anInNode ) {
2098       return anInNode->CpuUsed() ;
2099     }
2100   }
2101   return 0 ;
2102 }
2103
2104 // remove equal sets "Node-Event-State" from _EventNodes/_Events/_States queues
2105 void GraphExecutor::OutNode::siftEvents() {
2106   list<char*>::reverse_iterator itNodes = _EventNodes.rbegin();
2107   list<GraphExecutor::NodeEvent>::reverse_iterator itEvents = _Events.rbegin();
2108   list<GraphExecutor::AutomatonState>::reverse_iterator itStates = _States.rbegin();
2109   list<char*> _NewEventNodes;
2110   list<GraphExecutor::NodeEvent> _NewEvents;
2111   list<GraphExecutor::AutomatonState> _NewStates;
2112   for ( ; itNodes != _EventNodes.rend() ; ++itNodes, ++itEvents, ++itStates) {
2113     //cout << "----- aNodeName ==> " << *itNodes;
2114     list<char*>::reverse_iterator itNewNodes = _NewEventNodes.rbegin();
2115     bool found = false;
2116     for ( ; itNewNodes != _NewEventNodes.rend() ; ++itNewNodes ) {
2117       if ( !strcmp( *itNewNodes, *itNodes ) ) {
2118         found = true;
2119         break;
2120       }
2121     }
2122
2123     if ( found ) {
2124       //cout << "   FOUND";
2125     }
2126     else {
2127       _NewEventNodes.push_back( *itNodes );
2128       _NewEvents.push_back( *itEvents );
2129       _NewStates.push_back( *itStates );
2130     }
2131     //cout << endl;
2132   }
2133   _EventNodes = _NewEventNodes;
2134   _Events = _NewEvents;
2135   _States = _NewStates;
2136 }