Salome HOME
The following methods and constants were removed as never being used:
[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 << "This DataFlow has invalid type(s)." << endl ;
452     return false ;
453   }
454   int SubStreamGraphsNumber = 0 ;
455   if ( !Graph()->Sort( SubStreamGraphsNumber ) ) {
456     cdebug << "This DataFlow is not valid." << endl ;
457     return false ;
458   }
459   if ( Graph()->IsDataStreamNode() ) {
460     StreamGraph()->SubStreamGraphsNumber( SubStreamGraphsNumber ) ;
461   }
462
463 //  CreateService() ;
464
465   Graph()->InLineServices() ;
466
467   Graph()->ComputingNodes() ;
468   
469   _Valid = true ;
470
471   cdebug_out << "GraphExecutor::OutNode::Valid" << endl;
472   return _Valid ;
473 }
474
475
476 bool GraphExecutor::OutNode::Executable() {
477
478   cdebug_in << "GraphExecutor::OutNode::Executable" << endl;
479   if ( !IsValid() )
480     return false ;
481
482   if ( Graph()->DataServerNodes() )
483     _Executable = true ;
484   else {
485     cdebug << "This DataFlow is not executable." << endl ;
486     _Executable = false ;
487   }
488
489   cdebug_out << "GraphExecutor::OutNode::Executable " << _Executable << endl;
490   return _Executable ;
491 }
492
493 bool GraphExecutor::OutNode::Run( const bool AndSuspend ) {
494   bool RetVal = false ;
495   cdebug_in << pthread_self() << "GraphExecutor::OutNode::Run( AndSuspend " << AndSuspend << " )"
496             << endl;
497
498   if ( Executable() ) {
499     _ControlState = SUPERV::VoidState ;
500     _SuspendedThreads = 0 ;
501     Graph()->ThreadNo( pthread_self() ) ;
502     Done( false ) ;
503     _JustStarted = true ;
504     RetVal = true ;
505     int i ;
506     for ( i = 0 ; i < Graph()->GraphNodesSize() ; i++ ) {
507       GraphExecutor::InNode * anInNode = (GraphExecutor::InNode *) Graph()->GraphNodes( i )->GetInNode() ;
508       anInNode->OutNode( this ) ;
509       if ( !PyInitialized() && anInNode->IsOneOfInLineNodes() ) {
510         if ( !Py_IsInitialized() ) {
511 //          PyEval_InitThreads() ;
512 //          Py_Initialize() ;
513 //          PySys_SetArgv( _ArgC , _ArgV ) ;
514         }
515         anInNode->InitPython() ;
516         PyInitialized( true ) ;
517       }
518       anInNode->InitialState() ;
519       if ( anInNode->IsOneOfInLineNodes() ) {
520         anInNode->InitPythonFunctions( false ) ;
521       }
522     }
523 // One more time because inline nodes may share one definition of the same function
524     for ( i = 0 ; i < Graph()->GraphNodesSize() ; i++ ) {
525       GraphExecutor::InNode * anInNode = (GraphExecutor::InNode *) Graph()->GraphNodes( i )->GetInNode() ;
526       if ( anInNode->IsOneOfInLineNodes() ) {
527         if ( !anInNode->InitPythonFunctions( true ) ) {
528           anInNode->State( GraphExecutor::ErroredState ) ;
529           State( GraphExecutor::ErroredState ) ;
530           cdebug_out << "GraphExecutor::OutNode::Run InitPythonFunctions ERROR "
531                      << anInNode->Name() << endl ;
532           return false ;
533         }
534       }
535     }
536     /* asv : 29.09.04 : commented out because it does not do anything useful 
537     for ( i = 0 ; i < Graph()->GraphNodesSize() ; i++ ) {
538       GraphExecutor::InNode * anInNode = (GraphExecutor::InNode *) Graph()->GraphNodes( i )->GetInNode() ;
539       if ( RetVal && anInNode->IsMacroNode() ) {
540         GraphBase::Graph * aMacroGraph = anInNode->GraphMacroNode() ;
541         cdebug << "GraphExecutor::OutNode::Run " << anInNode << " MacroNode " << aMacroGraph
542                << aMacroGraph->Name() << endl ;
543         SUPERV::Graph_var iobject = anInNode->GraphMacroNode()->MacroObject() ;
544         if ( CORBA::is_nil( iobject ) ) {
545           cdebug << "GraphExecutor::OutNode::Run MacroObject() is a nil object. Error" << endl ;
546           RetVal = false ;
547         }
548         else {
549           cdebug << "GraphExecutor::OutNode::Run MacroObject() is NOT a nil object." << endl ;
550         }
551       }
552     }
553     */
554     if ( Graph()->GraphMacroLevel() != 0 ) {
555       cdebug << "GraphExecutor::OutNode::Run Execution starting GraphExecutor::Action_DataOk_RunService Node "
556              << Graph()->Name() << " GraphMacroLevel " << Graph()->GraphMacroLevel() << endl ;
557       PushEvent( NULL , GraphExecutor::NoDataReadyEvent ,
558                  GraphExecutor::DataUndefState ) ; 
559     }
560     else {
561       cdebug << "Execution starting GraphExecutor::Action_DataOk_RunService Node "
562              << Graph()->Name() << " GraphMacroLevel " << Graph()->GraphMacroLevel() << endl ;
563       PushEvent( NULL , GraphExecutor::ReadyEvent ,
564                  GraphExecutor::DataReadyState ) ; 
565       State( GraphExecutor::DataReadyState ) ;
566
567       cdebug << pthread_self() << " GraphExecutor::OutNode::Run Start of the " << Graph()->HeadNodesSize()
568              << " HeadNodes" << endl ;
569       for ( i = 0 ; i < Graph()->HeadNodesSize() ; i++ ) {
570         GraphExecutor::InNode * anInNode = (GraphExecutor::InNode *) Graph()->HeadNodes( i )->GetInNode() ;
571         cdebug << pthread_self() <<  "GraphExecutor::OutNode::Run Start of HeadNode " << i << " "
572                << anInNode->Name() << endl ;
573         if ( anInNode->State() != GraphExecutor::DataReadyState ) {
574           cdebug << "GraphExecutor::OutNode::Run inconsistency State of Node "
575                  << anInNode->Name() << " : " << anInNode->State() << endl ;
576           cdebug_out << "GraphExecutor::OutNode::Run State ERROR" << endl ;
577           return false ;
578         }
579 //        PushEvent( anInNode , GraphExecutor::ReadyEvent ,
580 //                   GraphExecutor::DataReadyState ) ; 
581         anInNode->CreateNewThread( true ) ;
582         anInNode->DataFromNode( Graph()->Name() ) ;
583         if ( AndSuspend ) {
584           anInNode->State( GraphExecutor::DataWaitingState ) ;
585           anInNode->ControlState( SUPERV::ToSuspendStartState ) ;
586           if ( !anInNode->SendEvent( GraphExecutor::SomeDataReadyEvent ) ) {
587             cdebug << "InNode::SendEvent( SomeDataReadyEvent ) ERROR Node "
588                    << anInNode->Name() << endl ;
589             cdebug_out << "GraphExecutor::OutNode::Run SendEvent ERROR" << endl ;
590             return false ;
591           }
592           anInNode->SuspendedWait() ;
593         }
594         else if ( anInNode->IsMacroNode() ) {
595           if ( !anInNode->SendEvent( GraphExecutor::SomeDataReadyEvent ) ) {
596             cdebug << "InNode::SendEvent( SomeDataReadyEvent ) ERROR Node "
597                    << anInNode->Name() << endl ;
598             cdebug_out << "GraphExecutor::OutNode::Run SendEvent ERROR" << endl ;
599             return false ;
600           }
601           cdebug << pthread_self() << " GraphExecutor::OutNode::Run " << anInNode->Name() << "->RunningWait"
602                  << endl ;
603           anInNode->RunningWait() ;
604           cdebug << pthread_self() << " GraphExecutor::OutNode::Run " << anInNode->Name() << "->RunningWaited"
605                  << endl ;
606         }
607         else if ( !anInNode->IsMacroNode() ) {
608           if ( !anInNode->SendEvent( GraphExecutor::ExecuteEvent ) ) {
609             cdebug << "InNode::SendEvent( ExecuteEvent ) ERROR Node "
610                    << anInNode->Name() << endl ;
611             cdebug_out << "GraphExecutor::OutNode::Run SendEvent ERROR" << endl ;
612             return false ;
613           }
614           anInNode->RunningWait() ;
615         }
616       }
617
618       if ( AndSuspend ) {
619         PushEvent( NULL , GraphExecutor::SuspendedReadyEvent ,
620                    GraphExecutor::SuspendedReadyState ) ; 
621       }
622       else {
623         PushEvent( NULL , GraphExecutor::ExecutingEvent ,
624                    GraphExecutor::ExecutingState ) ; 
625         if (AutomatonState() == GraphExecutor::DataReadyState) {
626             State( GraphExecutor::ExecutingState ) ;
627         };
628       }
629 //      ostringstream astr ;
630 //      astr << "Graph " << Graph()->Name() << " is running" ;
631 //      Graph()->ObjImpl()->sendMessage( NOTIF_STEP, astr.str().c_str() ) ;
632       RetVal = true ;
633     }
634   }
635
636   cdebug_out << pthread_self() << "GraphExecutor::OutNode::Run " << Graph()->Name()
637              << " GraphMacroLevel "
638              << Graph()->GraphMacroLevel() << " RetVal " << RetVal << endl ;
639   return RetVal ;
640 }
641
642 void GraphExecutor::OutNode::CheckAllDone() {
643   int j ;
644   cdebug_in << "GraphExecutor::OutNode::CheckAllDone " << endl;
645   GraphExecutor::AutomatonState OutNodeState = GraphExecutor::SuccessedState ;
646   GraphExecutor::AutomatonState InNodeState ;
647   bool AllDone = true ;
648   if ( !Done() ) {
649     for ( j = 0 ; j < Graph()->QueueNodesSize() ; j++ ) {
650       InNodeState = ( (GraphExecutor::InNode * ) Graph()->QueueNodes( j )->GetInNode() )->State() ;
651       cdebug << j << ". "
652              << ( (GraphExecutor::InNode * ) Graph()->QueueNodes( j )->GetInNode() )->Name()
653              << " " << theAutomaton->StateName( InNodeState ) << endl ;
654       if ( InNodeState != GraphExecutor::SuccessedState &&
655            InNodeState != GraphExecutor::ErroredState &&
656            InNodeState != GraphExecutor::DataWaitingState ) {
657         AllDone = false ;
658       }
659       if ( InNodeState != GraphExecutor::SuccessedState &&
660            InNodeState != GraphExecutor::DataWaitingState &&
661            InNodeState != GraphExecutor::DataReadyState ) {
662         OutNodeState = InNodeState ;
663       }
664     }
665     if ( AllDone ) {
666       if( _Threads == 0 && _SuspendedThreads == 0 ) {
667         if ( OutNodeState != GraphExecutor::ErroredState ) {
668           OutNodeState = GraphExecutor::SuccessedState ;
669         }
670       }
671       else {
672         AllDone = false ;
673       }
674     }
675     if ( AllDone ) {
676       int alivenodes = 0 ;
677       for ( j = 0 ; j < Graph()->GraphNodesSize()  ; j++ ) {
678         GraphExecutor::InNode * aNode ;
679         aNode = (GraphExecutor::InNode * ) Graph()->GraphNodes( j )->GetInNode() ;
680         SUPERV::GraphState aState = AutomatonGraphState( aNode->State() ) ;
681         cdebug << "GraphExecutor::OutNode::CheckAllDone " << aNode->Name() << " "
682                << theAutomaton->StateName( aNode->State() ) << " CreateNewThread " << aNode->CreateNewThread()
683                << endl ;
684         if ( aState == SUPERV::ErrorState ||
685              aState == SUPERV::SuspendErroredState ||
686              aState == SUPERV::KillState ||
687              aState == SUPERV::StopState ) {
688           OutNodeState = aNode->State() ;
689           State( OutNodeState ) ;
690         }
691         else if ( aState == SUPERV::ReadyState ||
692                   aState == SUPERV::SuspendReadyState ||
693                   aState == SUPERV::RunningState ||
694                   aState == SUPERV::SuspendDoneState ||
695                   aState == SUPERV::SuspendErroredState ||
696                   aState == SUPERV::SuspendState ) {
697           alivenodes += 1 ;
698         }
699         aNode->SuspendedAction() ;
700         aNode->DoneAction() ;
701       }
702 // PushEvent AFTER State and _Done ! ...
703       if ( alivenodes == 0 ) {
704         State( OutNodeState ) ;
705         Done( true ) ;
706         _JustStarted = false ;
707       }
708       cdebug << Graph()->Name() << " alivenodes " << alivenodes << " OutNodeState " << OutNodeState
709              << endl ;
710       PushEvent( NULL , GraphExecutor::EndExecuteEvent ,
711                  OutNodeState ) ;
712 //      Py_Finalize() ;
713 //      PyInitialized( false ) ;
714     }
715   }
716   if ( IsDone() ) {
717     MESSAGE("================================================================================") ;
718     MESSAGE( Graph()->Name() << " IS DONE : " <<  theAutomaton->StateName( AutomatonState() ) << " EventQSize "
719              << EventQSize() ) ;
720     MESSAGE("================================================================================") ;
721     cdebug << "================================================================================" << endl ;
722     cdebug << Graph()->Name() << " IS DONE : " <<  theAutomaton->StateName( AutomatonState() ) << " EventQSize "
723              << EventQSize() << endl  ;
724     cdebug << "================================================================================" << endl ;
725
726     // asv : fix for 6798 and other bugs: "sift" the event queue after execution
727     siftEvents();
728
729     // asv : 25.10.04 : calling Editing() to indicate stop of execution
730     Graph()->GraphEditor()->Editing();
731   }
732   cdebug_out << "GraphExecutor::OutNode::CheckAllDone " << IsDone() << " this " << this << " "
733              << Graph()->Name() << " GraphAutomatonState "
734              << theAutomaton->StateName( AutomatonState() )
735              << " State " << State() << " Threads " << _Threads << " SuspendedThreads "
736              << _SuspendedThreads << " EventQSize " << EventQSize() << endl ;
737 }
738
739 Engines_Container_i * GraphExecutor::OutNode::SuperVisionContainer() {
740   return _SuperVisionContainer ;
741 }
742
743 const pthread_t GraphExecutor::OutNode::MainThreadId() const {
744   return _MainThreadId ;
745 }
746
747 void GraphExecutor::OutNode::PThreadLock( pthread_mutex_t * aMutex , char * errmsg ) {
748 //  if ( strcmp( errmsg , "EventLoop" ) && strcmp( errmsg , "EventW" ) ) {
749 //    cdebug << "GraphExecutor::OutNode::PThreadLock " << pthread_self() << " " << aMutex << " "
750 //           << errmsg << endl ;
751 //  }
752   if ( pthread_mutex_lock( aMutex ) ) {
753     perror( errmsg ) ;
754     exit( 0 ) ;
755   }
756 //  if ( strcmp( errmsg , "EventLoop" ) && strcmp( errmsg , "EventW" ) ) {
757 //    cdebug << "GraphExecutor::OutNode::PThreadLocked " << pthread_self() << " " << aMutex << " "
758 //           << errmsg << endl ;
759 //  }
760 }
761
762 void GraphExecutor::OutNode::PThreadUnLock( pthread_mutex_t * aMutex , char * errmsg ) {
763 //  if ( strcmp( errmsg , "EventLoop" ) && strcmp( errmsg , "EventW" ) ) {
764 //    cdebug << " GraphExecutor::OutNode::PThreadUnLock " << pthread_self() << " " << aMutex << " "
765 //           << errmsg << endl ;
766 //  }
767   if ( pthread_mutex_unlock( aMutex ) ) {
768     perror( errmsg ) ;
769     exit( 0 ) ;
770   }
771 }
772
773 void GraphExecutor::OutNode::PyThreadLock() {
774 //  cout << " GraphExecutor::OutNode::PyThreadLock " << pthread_self() << endl ;
775   if ( pthread_mutex_lock( &_PyMutexWait ) ) {
776     perror( "GraphExecutor::OutNode::PyThreadLock" ) ;
777     exit( 0 ) ;
778   }
779   theAutomaton->PyLock() ;
780 //  cout << " GraphExecutor::OutNode::PyThreadLocked " << pthread_self() << endl ;
781 }
782
783 void GraphExecutor::OutNode::PyThreadUnLock() {
784 //  cout << " GraphExecutor::OutNode::PyThreadUnLock " << pthread_self() << endl ;
785   if ( pthread_mutex_unlock( &_PyMutexWait ) ) {
786     perror( "GraphExecutor::OutNode::PyThreadUnLock" ) ;
787     exit( 0 ) ;
788   }
789   theAutomaton->PyUnLock() ;
790 //  cout << " GraphExecutor::OutNode::PyThreadUnLocked " << pthread_self() << endl ;
791 }
792
793 void GraphExecutor::OutNode::NewThread() {
794   if ( pthread_mutex_lock( &_MutexWait ) ) {
795     perror("pthread_mutex_lock _NewThread") ;
796     exit( 0 ) ;
797   }
798   _Threads += 1 ;
799   cdebug << "NewThread : " << _Threads << " running threads "
800          << _SuspendedThreads << " suspended threads"
801          << endl ;
802   if ( pthread_mutex_unlock( &_MutexWait ) ) {
803     perror("pthread_mutex_unlock _NewThread") ;
804     exit( 0 ) ;
805   }
806 }
807
808 void GraphExecutor::OutNode::ExitThread( pthread_t ThreadNumber ) {
809   if ( pthread_mutex_lock( &_MutexWait ) ) {
810     perror("pthread_mutex_lock _ExitThread") ;
811     exit( 0 ) ;
812   }
813   if ( ThreadNumber == 0 ) {
814     ThreadNumber = pthread_self() ;
815   }
816   _Threads -= 1 ;
817   cdebug << pthread_self() << " ExitThread( " << ThreadNumber << " ) " << _Threads << " running threads "
818          << _SuspendedThreads << " suspended threads"
819          << endl ;
820   theAutomaton->JoinThread( ThreadNumber ) ;
821   if ( pthread_cond_signal( &_JoinWait ) ) {
822     perror("ExitThread pthread_cond_signal ") ;
823   }
824   if ( pthread_mutex_unlock( &_MutexWait ) ) {
825     perror("pthread_mutex_unlock _ExitThread") ;
826     exit( 0 ) ;
827   }
828   if ( _Threads == 0 && _SuspendedThreads == 0 ) {
829     CheckAllDone() ;
830     if ( IsDone() ) {
831       theAutomaton->Executed() ;
832     }
833   }
834 }
835 void GraphExecutor::OutNode::JoinedWait() {
836   if ( pthread_mutex_lock( &_MutexWait ) ) {
837     perror("pthread_mutex_lock JoinedWait") ;
838     exit( 0 ) ;
839   }
840   while ( _Threads ) {
841     if ( pthread_cond_wait( &_JoinWait , &_MutexWait ) ) {
842       perror("JoinedWait pthread_cond_wait ") ;
843     }
844   }
845   if ( pthread_mutex_unlock( &_MutexWait ) ) {
846     perror("pthread_mutex_unlock JoinedWait") ;
847     exit( 0 ) ;
848   }
849 }
850
851 void GraphExecutor::OutNode::SuspendThread() {
852   if ( pthread_mutex_lock( &_MutexWait ) ) {
853     perror("pthread_mutex_lock _SuspendThread") ;
854     exit( 0 ) ;
855   }
856   _SuspendedThreads += 1 ;
857   cdebug << "SuspendThread : " << _Threads << " running threads "
858          << _SuspendedThreads << " suspended threads"
859          << endl ;
860   if ( pthread_mutex_unlock( &_MutexWait ) ) {
861     perror("pthread_mutex_unlock _SuspendThread") ;
862     exit( 0 ) ;
863   }
864   if ( IsSuspended() ) {
865     PushEvent( NULL , GraphExecutor::SuspendEvent , GraphExecutor::SuspendedState ) ;
866   }
867 }
868 void GraphExecutor::OutNode::ResumeThread() {
869   if ( pthread_mutex_lock( &_MutexWait ) ) {
870     perror("pthread_mutex_lock _ResumeThread") ;
871     exit( 0 ) ;
872   }
873   _SuspendedThreads -= 1 ;
874   cdebug << "ResumeThread : " << _Threads << " running threads "
875          << _SuspendedThreads << " suspended threads"
876          << endl ;
877   if ( pthread_mutex_unlock( &_MutexWait ) ) {
878     perror("pthread_mutex_unlock _ResumeThread") ;
879     exit( 0 ) ;
880   }
881 }
882
883 long GraphExecutor::OutNode::Thread( const char * aNodeName ) {
884   long RetVal = 0 ;
885   GraphExecutor::InNode *anInNode = (GraphExecutor::InNode *) Graph()->GetGraphNode( aNodeName )->GetInNode() ;
886   if ( anInNode ) {
887     RetVal = anInNode->ThreadNo() ;
888   }
889   return RetVal ;
890 }
891
892 SUPERV::GraphEvent GraphExecutor::OutNode::AutomatonGraphEvent(GraphExecutor::NodeEvent anEvent ) {
893   SUPERV::GraphEvent aGraphEvent ;
894   switch ( anEvent ) {
895   case GraphExecutor::UndefinedEvent : {
896     aGraphEvent = SUPERV::UndefinedEvent ;
897     break ;
898   }
899   case GraphExecutor::NewThreadEvent : {
900     aGraphEvent = SUPERV::NewThreadEvent ;
901     break ;
902   }
903   case GraphExecutor::SuspendEvent : {
904     aGraphEvent = SUPERV::SuspendEvent ;
905     break ;
906   }
907   case GraphExecutor::ResumeEvent : {
908     aGraphEvent = SUPERV::ResumeEvent ;
909     break ;
910   }
911   case GraphExecutor::KillEvent : {
912     aGraphEvent = SUPERV::KillEvent ;
913     break ;
914   }
915   case GraphExecutor::StopEvent : {
916     aGraphEvent = SUPERV::StopEvent ;
917     break ;
918   }
919   case GraphExecutor::ExecuteEvent : {
920     aGraphEvent = SUPERV::RunningEvent ;
921     break ;
922   }
923   case GraphExecutor::SuccessEvent : {
924     aGraphEvent = SUPERV::DoneEvent ;
925     break ;
926   }
927   case GraphExecutor::ErrorEvent : {
928     aGraphEvent = SUPERV::ErroredEvent ;
929     break ;
930   }
931   case GraphExecutor::NoDataReadyEvent : {
932     aGraphEvent = SUPERV::WaitingEvent ;
933     break ;
934   }
935   case GraphExecutor::SomeDataReadyEvent : {
936     aGraphEvent = SUPERV::WaitingEvent ;
937     break ;
938   }
939   case GraphExecutor::NotAllDataReadyEvent : {
940     aGraphEvent = SUPERV::WaitingEvent ;
941     break ;
942   }
943   case GraphExecutor::AllDataReadyEvent : {
944     aGraphEvent = SUPERV::ReadyEvent ;
945     break ;
946   }
947   case GraphExecutor::ReadyEvent : {
948     aGraphEvent = SUPERV::ReadyEvent ;
949     break ;
950   }
951   case GraphExecutor::SuspendedReadyEvent : {
952     aGraphEvent = SUPERV::SuspendEvent ;
953     break ;
954   }
955   case GraphExecutor::ResumedReadyEvent : {
956     aGraphEvent = SUPERV::ResumeEvent ;
957     break ;
958   }
959   case GraphExecutor::KilledReadyEvent : {
960     aGraphEvent = SUPERV::KillEvent ;
961     break ;
962   }
963   case GraphExecutor::StoppedReadyEvent : {
964     aGraphEvent = SUPERV::StopEvent ;
965     break ;
966   }
967   case GraphExecutor::ExecutingEvent : {
968     aGraphEvent = SUPERV::RunningEvent ;
969     break ;
970   }
971   case GraphExecutor::SuspendedExecutingEvent : {
972     aGraphEvent = SUPERV::SuspendEvent ;
973     break ;
974   }
975   case GraphExecutor::ResumedExecutingEvent : {
976     aGraphEvent = SUPERV::ResumeEvent ;
977     break ;
978   }
979   case GraphExecutor::KilledExecutingEvent : {
980     aGraphEvent = SUPERV::KillEvent ;
981     break ;
982   }
983   case GraphExecutor::StoppedExecutingEvent : {
984     aGraphEvent = SUPERV::StopEvent ;
985     break ;
986   }
987   case GraphExecutor::SuccessedExecutingEvent : {
988     aGraphEvent = SUPERV::DoneEvent ;
989     break ;
990   }
991   case GraphExecutor::ErroredExecutingEvent : {
992     aGraphEvent = SUPERV:: ErroredEvent;
993     break ;
994   }
995   case GraphExecutor::SuspendedSuccessedEvent : {
996     aGraphEvent = SUPERV::SuspendEvent ;
997     break ;
998   }
999   case GraphExecutor::SuspendedErroredEvent : {
1000     aGraphEvent = SUPERV::SuspendEvent ;
1001     break ;
1002   }
1003   case GraphExecutor::ResumedSuccessedEvent : {
1004     aGraphEvent = SUPERV::ResumeEvent ;
1005     break ;
1006   }
1007   case GraphExecutor::ResumedErroredEvent : {
1008     aGraphEvent = SUPERV::ResumeEvent ;
1009     break ;
1010   }
1011   case GraphExecutor::KilledEvent : {
1012     aGraphEvent = SUPERV::KillEvent ;
1013     break ;
1014   }
1015   case GraphExecutor::StoppedEvent : {
1016     aGraphEvent = SUPERV::StopEvent ;
1017     break ;
1018   }
1019   case GraphExecutor::EndExecuteEvent : {
1020     aGraphEvent = SUPERV::DoneEvent ;
1021     break ;
1022   }
1023   default : {
1024     cdebug << " GraphExecutor::OutNode::AutomatonGraphEvent Error Undefined Event : "
1025            << anEvent << endl ;
1026     aGraphEvent = SUPERV::UndefinedEvent ;
1027   }
1028   }
1029   return aGraphEvent ;
1030 }
1031
1032 SUPERV::GraphState GraphExecutor::OutNode::AutomatonGraphState(GraphExecutor::AutomatonState aState ) {
1033   SUPERV::GraphState aGraphState ;
1034   switch ( aState ) {
1035   case GraphExecutor::UnKnownState : {
1036     aGraphState = SUPERV::UndefinedState ;
1037     break ;
1038   }
1039   case GraphExecutor::DataUndefState : {
1040     aGraphState = SUPERV::UndefinedState ;
1041     break ;
1042   }
1043   case GraphExecutor::DataWaitingState : {
1044     aGraphState = SUPERV::WaitingState ;
1045     break ;
1046   }
1047   case GraphExecutor::DataReadyState : {
1048     aGraphState = SUPERV::ReadyState ;
1049     break ;
1050   }
1051   case GraphExecutor::SuspendedReadyState : {
1052     aGraphState = SUPERV::SuspendReadyState ;
1053     break ;
1054   }
1055   case GraphExecutor::ResumedReadyState : {
1056     aGraphState = SUPERV::ReadyState ;
1057     break ;
1058   }
1059   case GraphExecutor::KilledReadyState : {
1060     aGraphState = SUPERV::KillState ;
1061     break ;
1062   }
1063   case GraphExecutor::StoppedReadyState : {
1064     aGraphState = SUPERV::StopState ;
1065     break ;
1066   }
1067   case GraphExecutor::ExecutingState : {
1068     aGraphState = SUPERV::RunningState ;
1069     break ;
1070   }
1071   case GraphExecutor::SuspendedExecutingState : {
1072     aGraphState = SUPERV::SuspendState ;
1073     break ;
1074   }
1075   case GraphExecutor::ResumedExecutingState : {
1076     aGraphState = SUPERV::RunningState ;
1077     break ;
1078   }
1079   case GraphExecutor::KilledExecutingState : {
1080     aGraphState = SUPERV::KillState ;
1081     break ;
1082   }
1083   case GraphExecutor::StoppedExecutingState : {
1084     aGraphState = SUPERV::StopState ;
1085     break ;
1086   }
1087   case GraphExecutor::SuccessedExecutingState : {
1088     aGraphState = SUPERV::DoneState ;
1089     break ;
1090   }
1091   case GraphExecutor::ErroredExecutingState : {
1092     aGraphState = SUPERV::ErrorState ;
1093     break ;
1094   }
1095   case GraphExecutor::SuspendedSuccessedState : {
1096     aGraphState = SUPERV::SuspendDoneState ;
1097     break ;
1098   }
1099   case GraphExecutor::SuspendedErroredState : {
1100     aGraphState = SUPERV::SuspendErroredState ;
1101     break ;
1102   }
1103   case GraphExecutor::ResumedSuccessedState : {
1104     aGraphState = SUPERV::DoneState ;
1105     break ;
1106   }
1107   case GraphExecutor::ResumedErroredState : {
1108     aGraphState = SUPERV::ErrorState ;
1109     break ;
1110   }
1111   case GraphExecutor::KilledSuccessedState : {
1112     aGraphState = SUPERV::KillState ;
1113     break ;
1114   }
1115   case GraphExecutor::KilledErroredState : {
1116     aGraphState = SUPERV::KillState ;
1117     break ;
1118   }
1119   case GraphExecutor::StoppedSuccessedState : {
1120     aGraphState = SUPERV::StopState ;
1121     break ;
1122   }
1123   case GraphExecutor::StoppedErroredState : {
1124     aGraphState = SUPERV::StopState ;
1125     break ;
1126   }
1127   case GraphExecutor::SuccessedState : {
1128     aGraphState = SUPERV::DoneState ;
1129     break ;
1130   }
1131   case GraphExecutor::ErroredState : {
1132     aGraphState = SUPERV::ErrorState ;
1133     break ;
1134   }
1135   case GraphExecutor::SuspendedState : {
1136     aGraphState = SUPERV::SuspendState ;
1137     break ;
1138   }
1139   case GraphExecutor::KilledState : {
1140     aGraphState = SUPERV::KillState ;
1141     break ;
1142   }
1143   case GraphExecutor::StoppedState : {
1144     aGraphState = SUPERV::StopState ;
1145     break ;
1146   }
1147   case GraphExecutor::LoadingState : {
1148     aGraphState = SUPERV::LoadingState ;
1149     break;
1150   }
1151   default : {
1152     cdebug << " GraphExecutor::OutNode::AutomatonGraphState Error Undefined State : "
1153            << aGraphState << endl ;
1154     aGraphState = SUPERV::UndefinedState ;
1155   }
1156   }
1157   return aGraphState ;
1158 }
1159
1160 int GraphExecutor::OutNode::GetListSize() {
1161   return _EventNodes.size();
1162 }
1163
1164 bool GraphExecutor::OutNode::PushEvent( GraphExecutor::InNode * aNode ,
1165                                         GraphExecutor::NodeEvent anEvent ,
1166                                         GraphExecutor::AutomatonState aState ) {
1167 //  cdebug_in << "PushEvent Threads " << Threads() << " SuspendedThreads "
1168 //            << SuspendedThreads() << endl ;
1169   if ( pthread_mutex_lock( &_MutexWait ) ) {
1170     perror("PushEvent pthread_mutex_lock ") ;
1171     exit( 0 ) ;
1172   }
1173   char* aNodeName = aNode ? aNode->Name() : Graph()->Name() ;
1174   _EventNodes.push_back( aNodeName ) ;
1175   _Events.push_back( anEvent ) ;
1176   _States.push_back( aState ) ;
1177
1178   pthread_cond_broadcast( &_EventWait );
1179   cdebug << pthread_self() << " PushEvent Threads " << Threads() << " SuspendedThreads "
1180          << SuspendedThreads() << " pthread_cond_broadcast _EventWait " << &_EventWait << endl ;
1181   if ( aNode ) {
1182 //    cdebug << aNode->ThreadNo() << " PushEvent " << aNode->Name() ;
1183 //    cdebug << " " << aNode->Automaton()->EventName( anEvent )
1184 //           << " " << aNode->Automaton()->StateName( aState )
1185 //           << " ControleState "
1186 //           << aNode->Automaton()->ControlStateName( aNode->ControlState() ) ;
1187   }
1188   else {
1189 //    cdebug << "PushEvent " << Graph()->Name() ;
1190 //    cdebug << " " << theAutomaton->EventName( anEvent ) << " "
1191 //           << theAutomaton->StateName( aState ) ;
1192   }
1193 //  cdebug_out << "PushEvent Threads " << Threads() << " SuspendedThreads "
1194 //             << SuspendedThreads() << endl ;
1195 #if 0
1196   if ( _EventNodes.size() > 101 ) {
1197     while ( _EventNodes.size() > 31 ) {
1198       _EventNodes.pop_front() ;
1199       _Events.pop_front() ;
1200       _States.pop_front() ;
1201     }
1202   }
1203 #endif
1204   if ( pthread_mutex_unlock( &_MutexWait ) ) {
1205     perror("PushEvent pthread_mutex_unlock ") ;
1206     exit( 0 ) ;
1207   }
1208   return true ;
1209 }
1210
1211 bool GraphExecutor::OutNode::StateWait( SUPERV::GraphState aState ) {
1212   return false ;
1213 }
1214
1215 bool GraphExecutor::OutNode::Event( char ** aNodeName ,
1216                                     SUPERV::GraphEvent & anEvent ,
1217                                     SUPERV::GraphState & aState ,
1218                                     bool WithWait ) {
1219   // asv : fixing problem of loops with large number of iterations (>5000)
1220   // experimentally was found that number of non-handled by GUI events = (number_of_nodes x 7)
1221   // or 7 events for each node - so what we want to do here is remove "old" events for nodes
1222   // "on the fly".  Once again it is done in Stop(), Kill(), Done() functions.
1223   if ( _EventNodes.size() > (unsigned int)Graph()->GraphNodesSize()*7 )
1224     siftEvents();
1225
1226   int ThreadsNumber ;
1227   int SuspendedThreadsNumber ;
1228   bool cdebuginout = false ;
1229   if ( _EventNodes.size() > 0 ) {
1230 //    cdebug_in << "GraphExecutor::OutNode::Event " << _EventNodes.size() << " in queue" << endl ;
1231     cdebuginout = true ;
1232   }
1233   if ( pthread_mutex_lock( &_MutexWait ) ) {
1234     perror("EventLoop pthread_mutex_lock ") ;
1235     exit( 0 ) ;
1236   }
1237   _JustStarted = false ;
1238   ThreadsNumber = Threads() ;
1239   SuspendedThreadsNumber = SuspendedThreads() ;
1240   bool RetVal = ( ThreadsNumber - SuspendedThreadsNumber) != 0 ||
1241                 _EventNodes.size() > 0 ;
1242   char * NodeName = "" ;
1243   GraphExecutor::NodeEvent theEvent = GraphExecutor::UndefinedEvent ;
1244   GraphExecutor::AutomatonState theState = GraphExecutor::UnKnownState ;
1245   anEvent = SUPERV::UndefinedEvent ;
1246   aState = SUPERV::UndefinedState ;
1247   if ( ( Done() || IsKilled() || IsStopped() ) && _EventNodes.size() == 0 ) {
1248 //    cdebug << "EventLoop Done()/IsKilled()/IsStopped() && _EventNodes.size() == 0" << endl ;
1249     RetVal = false ;
1250   }
1251   else if ( !WithWait && _EventNodes.size() == 0 ) {
1252     anEvent = SUPERV::NoEvent ;
1253     aState = SUPERV::NoState ;
1254     RetVal = true ;
1255   }
1256   else if ( RetVal ) {
1257     while ( !IsSuspended() && _EventNodes.size() == 0 ) {
1258 //      cdebug << "EventLoop pthread_cond_wait _EventWait" << endl ;
1259       pthread_cond_wait( &_EventWait , &_MutexWait );
1260 //      cdebug << "EventLoop pthread_cond_waited _EventWait"
1261 //             << " _EventNodes.size() " << _EventNodes.size() << endl ;
1262     }
1263     if ( _EventNodes.size() ) {
1264       ThreadsNumber = Threads() ;
1265       NodeName = _EventNodes.front() ;
1266       _EventNodes.pop_front() ;
1267       theEvent = _Events.front() ;
1268       anEvent = AutomatonGraphEvent( theEvent ) ;
1269       _Events.pop_front() ;
1270       theState = _States.front() ;
1271       aState = AutomatonGraphState( theState ) ;
1272       _States.pop_front() ;
1273     }
1274   }
1275   *aNodeName = NodeName ;
1276   if ( IsSuspended() && _EventNodes.size() == 0 ) {
1277     RetVal = false ;
1278   }
1279   if ( anEvent != SUPERV::NoEvent ) {
1280 //    cdebug << pthread_self() << "EventLoop "
1281 //           << NodeName << " " << theAutomaton->StateName( theState )
1282 //           << " _EventNodes.size() " << _EventNodes.size()
1283 //           << " Threads " << Threads() << " SuspendedThreads "
1284 //           << SuspendedThreads() << " RetVal " << RetVal << endl ;
1285   }
1286   if ( pthread_mutex_unlock( &_MutexWait ) ) {
1287     perror("EventLoop pthread_mutex_lock ") ;
1288     exit( 0 ) ;
1289   }
1290   if ( cdebuginout ) {
1291 //    cdebug_out << "GraphExecutor::OutNode::Event " << _EventNodes.size() << " in queue"
1292 //               << *aNodeName << " " << anEvent << " " << aState << endl ;
1293   }
1294   return RetVal ;
1295 }
1296
1297 bool GraphExecutor::OutNode::EventW( char ** aNodeName ,
1298                                      SUPERV::GraphEvent & anEvent ,
1299                                      SUPERV::GraphState & aState ) {
1300   bool sts = true ;
1301   char * NodeName ;
1302   aState = SUPERV::UndefinedState ;
1303   while ( sts &&
1304           aState != SUPERV::SuspendReadyState &&
1305           aState != SUPERV::RunningState &&
1306           aState != SUPERV::SuspendDoneState &&
1307           aState != SUPERV::SuspendErroredState ) {
1308     NodeName = Graph()->Name() ;
1309     while ( sts && !strcmp( NodeName , Graph()->Name() ) ) {
1310       sts = EventWait( aNodeName , anEvent , aState ) ;
1311       NodeName = *aNodeName ;
1312     }
1313   }
1314   return sts ;
1315 }
1316
1317 bool GraphExecutor::OutNode::EventWait( char ** aNodeName ,
1318                                         SUPERV::GraphEvent & anEvent ,
1319                                         SUPERV::GraphState & aState ) {
1320   if ( pthread_mutex_lock( &_MutexWait ) ) {
1321     perror("EventW pthread_mutex_lock ") ;
1322     exit( 0 ) ;
1323   }
1324   int ThreadsNumber ;
1325   int SuspendedThreadsNumber ;
1326   ThreadsNumber = Threads() ;
1327   SuspendedThreadsNumber = SuspendedThreads() ;
1328   bool RetVal = ( ThreadsNumber - SuspendedThreadsNumber) != 0 ||
1329                 _EventNodes.size() > 0 ;
1330   cdebug << "--> EventW RetVal " << RetVal << endl ;
1331   char * NodeName = "" ;
1332   GraphExecutor::NodeEvent theEvent = GraphExecutor::UndefinedEvent ;
1333   GraphExecutor::AutomatonState theState = GraphExecutor::UnKnownState ;
1334   anEvent = SUPERV::UndefinedEvent ;
1335   aState = SUPERV::UndefinedState ;
1336   if ( IsDone() && _EventNodes.size() == 0 ) {
1337     cdebug << "EventW IsDone() && _EventNodes.size() == 0" << endl ;
1338     RetVal = 0 ;
1339   }
1340   else if ( RetVal ) {
1341     GraphExecutor::InNode * aNode = NULL ;
1342     while ( aNode == NULL && RetVal ) {
1343       NodeName = _EventNodes.front() ;
1344       theEvent = _Events.front() ;
1345       anEvent = AutomatonGraphEvent( theEvent ) ;
1346       theState = _States.front() ;
1347       aState = AutomatonGraphState( theState ) ;
1348
1349       if ( _JustStarted ) {
1350         _JustStarted = false ;
1351       }
1352       else {
1353         _EventNodes.pop_front() ;
1354         _Events.pop_front() ;
1355         _States.pop_front() ;
1356       }
1357
1358       aNode = ((GraphExecutor::InNode *) Graph()->GetGraphNode( NodeName )->GetInNode()) ;
1359       cdebug << "EventW Previous Node " << NodeName << " ThreadsNumber "
1360              << ThreadsNumber
1361              << " _EventNodes.size() " << _EventNodes.size() << " "
1362              << theAutomaton->StateName( theState )
1363              << " Threads " << Threads() << " SuspendedThreads "
1364              << SuspendedThreads() << endl ;
1365       if ( aNode ) {
1366       }
1367       else if ( IsDone() && _EventNodes.size() == 0 ) {
1368         cdebug << "EventW IsDone() && _EventNodes.size() == 0" << endl ;
1369         RetVal = 0 ;
1370       }
1371       else {
1372         cdebug << "EventW Not InNode " << NodeName
1373                << " _EventNodes.size() " << _EventNodes.size() << endl ;
1374         while ( _EventNodes.size() == 0 ) {
1375           pthread_cond_wait( &_EventWait , &_MutexWait );
1376         }
1377         cdebug << "EventW pthread_cond_waited Not InNode " << NodeName
1378                << " _EventNodes.size() " << _EventNodes.size() << endl ;
1379       }
1380     }
1381
1382     if ( aNode ) {
1383       if ( aState == SUPERV::SuspendState ||
1384            aState == SUPERV::SuspendReadyState ||
1385            aState == SUPERV::SuspendDoneState ||
1386            aState == SUPERV::SuspendErroredState ) {
1387         aNode->ControlState( SUPERV::ToSuspendState ) ;
1388         if ( aNode->IsSuspended() ) {
1389           if ( pthread_mutex_unlock( &_MutexWait ) ) {
1390             perror("EventW pthread_mutex_lock ") ;
1391             exit( 0 ) ;
1392           }
1393           cdebug << "EventW " << aNode->Name() << " ResumeAction" << endl ;
1394           aNode->ResumeAction( GraphExecutor::ToResumeEvent ) ;
1395           cdebug << "EventW " << aNode->Name() << " ResumedAction" << endl ;
1396           if ( pthread_mutex_lock( &_MutexWait ) ) {
1397             perror("EventW pthread_mutex_lock ") ;
1398             exit( 0 ) ;
1399           }
1400         }
1401         else {
1402           cdebug << "EventW inconsistent SuspendState" << endl ;
1403           RetVal = false ; 
1404         }
1405       }
1406       else {
1407         if ( aNode->IsDone() ) {
1408           RetVal = true ;
1409         }
1410         else {
1411           cdebug << "EventW NOT SuspendedState _EventNodes.size() "
1412                  << _EventNodes.size() << endl ;
1413           RetVal = true ;
1414         }
1415       }
1416       if ( RetVal ) {
1417         cdebug << "EventW " << aNode->Name() << " pthread_cond_wait" << endl ;
1418         while ( _EventNodes.size() == 0 ) {
1419           pthread_cond_wait( &_EventWait , &_MutexWait );
1420         }
1421         ThreadsNumber = Threads() ;
1422         NodeName = _EventNodes.front() ;
1423         theEvent = _Events.front() ;
1424         anEvent = AutomatonGraphEvent( theEvent ) ;
1425         theState = _States.front() ;
1426         aState = AutomatonGraphState( theState ) ;
1427       }
1428     }
1429   }
1430   *aNodeName = NodeName ;
1431   cdebug << "<-- EventW RetVal " << RetVal << " " << NodeName
1432          << " Threads " << Threads() << " SuspendedThreads "
1433          << SuspendedThreads()
1434          << " _EventNodes.size() " << _EventNodes.size()
1435          << " " << theAutomaton->EventName( theEvent ) << " "
1436          << theAutomaton->StateName( theState ) << endl ;
1437   if ( pthread_mutex_unlock( &_MutexWait ) ) {
1438     perror("EventW pthread_mutex_lock ") ;
1439     exit( 0 ) ;
1440   }
1441   return RetVal ;
1442 }
1443 long GraphExecutor::OutNode::EventQSize() {
1444   return _EventNodes.size() ;
1445 }
1446
1447 void GraphExecutor::OutNode::EventList() {
1448   if ( pthread_mutex_lock( &_MutexWait ) ) {
1449     perror("EventList pthread_mutex_lock ") ;
1450     exit( 0 ) ;
1451   }
1452   list< char * >::iterator itEventNodes = _EventNodes.begin() ;
1453   list< GraphExecutor::NodeEvent >::iterator itEvents = _Events.begin() ;
1454   list< GraphExecutor::AutomatonState >::iterator itStates = _States.begin() ;
1455   while ( itEventNodes != _EventNodes.end() ) {
1456     cdebug << pthread_self() << "EVENTSTACK "
1457            << *itEventNodes << " " << *itEvents << " "
1458            << theAutomaton->StateName( *itStates )
1459            << " Threads " << Threads() << " SuspendedThreads " << SuspendedThreads() << endl ;
1460     itEventNodes++ ;
1461     itEvents++ ;
1462     itStates++ ;
1463   }
1464   if ( pthread_mutex_unlock( &_MutexWait ) ) {
1465     perror("EventList pthread_mutex_lock ") ;
1466     exit( 0 ) ;
1467   }
1468 }
1469
1470 void GraphExecutor::OutNode::SendSomeDataReady( const char * aNodeName ) {
1471   cdebug_in << "GraphExecutor::OutNode::SendSomeDataReady " << aNodeName << "->SendSomeDataReady( "
1472             << Graph()->Name() << " )" << endl;
1473   int sts ;
1474   sts = ((GraphExecutor::InNode * ) Graph()->GetChangeGraphNode( aNodeName )->GetInNode())->SendSomeDataReady( Graph()->Name() ) ;
1475   cdebug_out << "GraphExecutor::OutNode::SendSomeDataReady sts " << sts << endl ;
1476 }
1477
1478 void GraphExecutor::OutNode::State(GraphExecutor::AutomatonState aState ) {
1479 //  cdebug << "GraphExecutor::OutNode::State " << Graph()->Name() << " "
1480 //         << theAutomaton->StateName( AutomatonGraphState( _State ) ) << " ---> "
1481 //         << theAutomaton->StateName( AutomatonGraphState( aState ) ) << endl ;
1482   _State = aState ;
1483 }
1484
1485 SUPERV::GraphState GraphExecutor::OutNode::State() {
1486 //  cdebug_in << "GraphExecutor::OutNode::State" << endl;
1487 //  cdebug_out << "GraphExecutor::OutNode::State" << endl ;
1488 //  cdebug << "GraphExecutor::OutNode::State GraphState "
1489 //         << theAutomaton->StateName( AutomatonGraphState( _State ) ) << endl ;
1490   return AutomatonGraphState( _State ) ;
1491 }
1492
1493 SUPERV::GraphState GraphExecutor::OutNode::State( const char * NodeName ) {
1494 //  cdebug_in << "GraphExecutor::OutNode::State " << NodeName << endl;
1495   GraphExecutor::AutomatonState aret = GraphExecutor::UnKnownState ;
1496   const GraphBase::ComputingNode * aCNode =  Graph()->GetGraphNode( NodeName ) ;
1497   if ( aCNode ) {
1498     GraphExecutor::InNode *anInNode = (GraphExecutor::InNode *)aCNode->GetInNode() ;
1499     if ( anInNode ) {
1500       if ( anInNode->IsLoading() )
1501         aret = GraphExecutor::LoadingState;
1502       else
1503         aret = anInNode->State() ;
1504 //      cdebug << "GraphExecutor::OutNode::State( " << NodeName << " ) "
1505 //             << theAutomaton->StateName( AutomatonGraphState( aret ) ) << endl ;
1506     }
1507   }
1508 //  cdebug_out << "GraphExecutor::OutNode::State" << endl ;
1509   return AutomatonGraphState( aret ) ;
1510 }
1511
1512 SUPERV::GraphState GraphExecutor::OutNode::State( const char * NodeName ,
1513                                                   const char * ServiceParameterName )  {
1514 //  cdebug_in << "GraphExecutor::OutNode::State " << NodeName << " "
1515 //            << ServiceParameterName<< endl;
1516   SUPERV::GraphState aret = Graph()->PortState( NodeName , ServiceParameterName ) ;
1517 //  cdebug_out << "GraphExecutor::OutNode::State" << endl ;
1518   return aret ;
1519 }
1520
1521 GraphExecutor::AutomatonState GraphExecutor::OutNode::AutomatonState() {
1522 //  cdebug_in << "GraphExecutor::OutNode::AutomatonState" << endl;
1523 //  cdebug_out << "GraphExecutor::OutNode::AutomatonState" << endl ;
1524   return _State ;
1525 }
1526
1527 GraphExecutor::AutomatonState GraphExecutor::OutNode::AutomatonState( const char * NodeName ) {
1528 //  cdebug_in << "GraphExecutor::OutNode::AutomatonState " << NodeName << endl;
1529   GraphExecutor::AutomatonState aret = GraphExecutor::UnKnownState ;
1530   const GraphBase::ComputingNode * aNode = Graph()->GetGraphNode( NodeName ) ;
1531   if ( aNode ) {
1532     GraphExecutor::InNode *anInNode = (GraphExecutor::InNode *) aNode->GetInNode() ;
1533     if ( anInNode ) {
1534       aret = anInNode->State() ;
1535     }
1536   }
1537 //  cdebug_out << "GraphExecutor::OutNode::AutomatonState" << endl ;
1538   return aret ;
1539 }
1540
1541 SUPERV::ControlState GraphExecutor::OutNode::ControlState() {
1542 //  cdebug_in << "GraphExecutor::OutNode::ControlState" << endl;
1543 //  cdebug_out << "GraphExecutor::OutNode::ControlState" << endl ;
1544   return _ControlState ;
1545 }
1546
1547 SUPERV::ControlState GraphExecutor::OutNode::ControlState( const char * NodeName ) {
1548 //  cdebug_in << "GraphExecutor::OutNode::ControlState " << NodeName << endl;
1549   SUPERV::ControlState aret = SUPERV::VoidState ;
1550   const GraphBase::ComputingNode * aNode = Graph()->GetGraphNode( NodeName ) ;
1551   if ( aNode ) {
1552     GraphExecutor::InNode *anInNode = (GraphExecutor::InNode *) aNode->GetInNode() ;
1553     if ( anInNode ) {
1554       aret = anInNode->ControlState() ;
1555     }
1556   }
1557 //  cdebug_out << "GraphExecutor::OutNode::ControlState" << endl ;
1558   return aret ;
1559 }
1560
1561 void GraphExecutor::OutNode::ControlClear() {
1562 //  cdebug_in << "GraphExecutor::OutNode::ControlClear" << endl;
1563 //  cdebug_out << "GraphExecutor::OutNode::ControlClear" << endl ;
1564   _ControlState = SUPERV::VoidState;
1565 }
1566
1567 void GraphExecutor::OutNode::ControlClear( const char * NodeName ) {
1568 //  cdebug_in << "GraphExecutor::OutNode::ControlClear " << NodeName << endl;
1569   const GraphBase::ComputingNode * aNode = Graph()->GetGraphNode( NodeName ) ;
1570   if ( aNode ) {
1571     GraphExecutor::InNode *anInNode = (GraphExecutor::InNode *) aNode->GetInNode() ;
1572     if ( anInNode ) {
1573       anInNode->ControlClear() ;
1574     }
1575   }
1576 //  cdebug_out << "GraphExecutor::OutNode::ControlClear" << endl ;
1577 }
1578
1579 bool GraphExecutor::OutNode::IsWaiting() {
1580 //  cdebug_in << "GraphExecutor::OutNode::IsWaiting" << endl;
1581 //  cdebug_out << "GraphExecutor::OutNode::IsWaiting" << endl ;
1582   return !IsDone() ;
1583 }
1584
1585 bool GraphExecutor::OutNode::IsReady() {
1586 //  cdebug_in << "GraphExecutor::OutNode::IsReady" << endl;
1587 //  cdebug_out << "GraphExecutor::OutNode::IsReady" << endl ;
1588   return !IsDone() ;
1589 }
1590
1591 bool GraphExecutor::OutNode::IsRunning() {
1592 //  cdebug_in << "GraphExecutor::OutNode::IsRunning" << endl;
1593 //  cdebug_out << "GraphExecutor::OutNode::IsRunning" << endl ;
1594   return !IsDone() ;
1595 }
1596
1597 bool GraphExecutor::OutNode::IsDone() {
1598 //  cdebug_in << "GraphExecutor::OutNode::IsDone" << endl;
1599 //  cdebug_out << "GraphExecutor::OutNode::IsDone" << endl ;
1600   return ( Done() || IsKilled() || IsStopped() ) ;
1601 }
1602
1603 bool GraphExecutor::OutNode::IsSuspended() {
1604 //  cdebug_in << "GraphExecutor::OutNode::IsSuspended" << endl;
1605   bool aret = false ;
1606 //  if ( _SuspendedThreads == _Threads && _Threads != 0 ) {
1607   if ( AutomatonGraphState( _State ) ==  SUPERV::SuspendState ) {
1608     aret = true ;
1609   }
1610 //  cdebug_out << "GraphExecutor::OutNode::IsSuspended" << endl ;
1611   return aret ;
1612 }
1613
1614 bool GraphExecutor::OutNode::IsKilled() {
1615 //  cdebug_in << "GraphExecutor::OutNode::IsKilled" << endl;
1616   bool aret = false ;
1617   if ( AutomatonGraphState( _State ) == SUPERV::KillState ) {
1618     aret = true ;
1619   }
1620 //  cdebug_out << "GraphExecutor::OutNode::IsKilled" << endl ;
1621   return aret ;
1622 }
1623
1624 bool GraphExecutor::OutNode::IsStopped() {
1625 //  cdebug_in << "GraphExecutor::OutNode::IsStopped" << endl;
1626   bool aret = false ;
1627   if ( AutomatonGraphState( _State ) == SUPERV::StopState ) {
1628     aret = true ;
1629   }
1630 //  cdebug_out << "GraphExecutor::OutNode::IsStopped" << endl ;
1631   return aret ;
1632 }
1633
1634 bool GraphExecutor::OutNode::IsWaiting( const char * NodeName ) {
1635   bool aret = false ;
1636 //  cdebug_in << "GraphExecutor::OutNode::IsWaiting " << NodeName << endl;
1637   GraphExecutor::InNode *anInNode = (GraphExecutor::InNode *) Graph()->GetGraphNode( NodeName )->GetInNode() ;
1638   if ( anInNode ) {
1639     aret = anInNode->IsWaiting() ;
1640   }
1641 //  cdebug_out << "GraphExecutor::OutNode::IsWaiting" << endl ;
1642   return aret ;
1643 }
1644
1645 bool GraphExecutor::OutNode::IsReady( const char * NodeName ) {
1646   bool aret = false ;
1647 //  cdebug_in << "GraphExecutor::OutNode::IsReady " << NodeName << endl;
1648   GraphExecutor::InNode *anInNode = (GraphExecutor::InNode *) Graph()->GetGraphNode( NodeName )->GetInNode() ;
1649   if ( anInNode ) {
1650     aret = anInNode->IsReady() ;
1651   }
1652 //  cdebug_out << "GraphExecutor::OutNode::IsReady" << endl ;
1653   return aret ;
1654 }
1655
1656 bool GraphExecutor::OutNode::IsRunning( const char * NodeName ) {
1657   bool aret = false ;
1658 //  cdebug_in << "GraphExecutor::OutNode::IsRunning " << NodeName << endl;
1659   GraphExecutor::InNode *anInNode = (GraphExecutor::InNode *) Graph()->GetGraphNode( NodeName )->GetInNode() ;
1660   if ( anInNode ) {
1661     aret = anInNode->IsRunning() ;
1662   }
1663 //  cdebug_out << "GraphExecutor::OutNode::IsRunning" << endl ;
1664   return aret ;
1665 }
1666
1667 bool GraphExecutor::OutNode::IsDone( const char * NodeName ) {
1668   bool aret = false ;
1669 //  cdebug_in << "GraphExecutor::OutNode::IsDone " << NodeName << endl;
1670   GraphExecutor::InNode *anInNode = (GraphExecutor::InNode *) Graph()->GetGraphNode( NodeName )->GetInNode() ;
1671   if ( anInNode ) {
1672     aret = anInNode->IsDone() ;
1673   }
1674 //  cdebug_out << "GraphExecutor::OutNode::IsDone" << endl ;
1675   return aret ;
1676 }
1677
1678 bool GraphExecutor::OutNode::IsSuspended( const char * NodeName ) {
1679   bool aret = false ;
1680 //  cdebug_in << "GraphExecutor::OutNode::IsSuspended " << NodeName << endl;
1681   GraphExecutor::InNode *anInNode = (GraphExecutor::InNode *) Graph()->GetGraphNode( NodeName )->GetInNode() ;
1682   if ( anInNode ) {
1683     aret = anInNode->IsSuspended() ;
1684   }
1685 //  cdebug_out << "GraphExecutor::OutNode::IsSuspended" << endl ;
1686   return aret ;
1687 }
1688
1689 bool GraphExecutor::OutNode::IsDone( const char * NodeName ,
1690                                      const char * ServiceParameterName )  {
1691 //  cdebug_in << "GraphExecutor::OutNode::IsDone " << NodeName << " "
1692 //            << ServiceParameterName<< endl;
1693   bool aret = Graph()->PortDone( NodeName , ServiceParameterName ) ;
1694 //  cdebug_out << "GraphExecutor::OutNode::IsDone" << endl ;
1695   return aret ;
1696 }
1697
1698 bool GraphExecutor::OutNode::ContainerKill() {
1699   bool RetVal = true ;
1700   cdebug_in << "GraphExecutor::OutNode::ContainerKill" << endl;
1701   _ControlState = SUPERV::ToSuspendState ;
1702   int i ;
1703   for ( i = 0 ; i < Graph()->GraphNodesSize() ; i++ ) {
1704     GraphExecutor::InNode * aNode = (GraphExecutor::InNode * ) Graph()->GraphNodes( i )->GetInNode() ;
1705     bool sts = aNode->ContainerKill() ;
1706     if ( sts && aNode->IsKilled() ) {
1707       cdebug << aNode->Name() << " killed" << endl ;
1708     }
1709     else if ( aNode->IsWaiting() || aNode->IsDone() ) {
1710       cdebug << aNode->Name() << " not killed : "
1711              << theAutomaton->StateName( aNode->State() ) << endl ;
1712     }
1713     else {
1714       cdebug << aNode->Name() << " cannot be killed : "
1715              << theAutomaton->StateName( aNode->State() ) << endl ;
1716       RetVal = false ;
1717     }
1718   }
1719   if ( !RetVal || Threads() != 0 ) {
1720     for ( i = 0 ; i < Graph()->GraphNodesSize() ; i++ ) {
1721       GraphExecutor::InNode * aNode = (GraphExecutor::InNode * ) Graph()->GraphNodes( i )->GetInNode() ;
1722       if ( !aNode->IsKilled() && !aNode->IsWaiting() && !aNode->IsDone() ) {
1723         aNode->KilledAction() ;
1724       }
1725     }
1726     RetVal = true ;
1727   }
1728   State( GraphExecutor::KilledState ) ;
1729   cdebug_out << "GraphExecutor::OutNode::ContainerKill" << endl ;
1730   return RetVal ;
1731 }
1732
1733 bool GraphExecutor::OutNode::Suspend() {
1734   int RetVal = 0 ;
1735   cdebug_in << "GraphExecutor::OutNode::Suspend" << endl;
1736 //  _ControlState = SUPERV::ToSuspendState ;
1737   int i ;
1738   for ( i = 0 ; i < Graph()->GraphNodesSize() ; i++ ) {
1739     GraphExecutor::InNode * aNode = (GraphExecutor::InNode * ) Graph()->GraphNodes( i )->GetInNode() ;
1740     bool sts = aNode->Suspend() ;
1741     if ( sts && aNode->IsSuspended() ) {
1742       RetVal += 1 ;
1743       cdebug << aNode->Name() << " Suspended" << endl ;
1744     }
1745     else if ( aNode->IsWaiting() || aNode->IsReady() ) {
1746       RetVal += 1 ;
1747       cdebug << aNode->Name() << " will be Suspended" << endl ;
1748     }
1749     else if ( aNode->IsDone() ) {
1750       cdebug << aNode->Name() << " not Suspended : "
1751              << theAutomaton->StateName( aNode->State() ) << endl ;
1752     }
1753     else {
1754 //      RetVal += 1 ;
1755       cdebug << aNode->Name() << " cannot be Suspended : "
1756              << theAutomaton->StateName( aNode->State() ) << endl ;
1757     }
1758   }
1759   if ( RetVal ) {
1760     State( GraphExecutor::SuspendedState ) ;
1761     MESSAGE("================================================================================") ;
1762     MESSAGE( Graph()->Name() << " IS SUSPENDED" ) ;
1763     MESSAGE("================================================================================") ;
1764   }
1765   else {
1766     MESSAGE("================================================================================") ;
1767     MESSAGE( Graph()->Name() << " IS NOT SUSPENDED" ) ;
1768     MESSAGE("================================================================================") ;
1769   }
1770   for ( i = 0 ; i < Graph()->GraphNodesSize() ; i++ ) {
1771     GraphExecutor::InNode * aNode = (GraphExecutor::InNode * ) Graph()->GraphNodes( i )->GetInNode() ;
1772     MESSAGE(aNode->Name() << " " << theAutomaton->StateName( aNode->State() ) ) ;
1773     cdebug << aNode->Name() << " " << theAutomaton->StateName( aNode->State() ) << endl ;
1774   }
1775   cdebug_out << "GraphExecutor::OutNode::Suspend " << theAutomaton->StateName( State() )
1776              << " EventQSize " << EventQSize() << endl ;
1777   return RetVal ;
1778 }
1779
1780 bool GraphExecutor::OutNode::Resume() {
1781   int RetVal = 0 ;
1782   cdebug_in << "GraphExecutor::OutNode::Resume "
1783             << theAutomaton->StateName( State() ) << endl;
1784   if ( IsSuspended() ) {
1785     State( GraphExecutor::ExecutingState ) ;
1786     int i ;
1787     for ( i = 0 ; i < Graph()->GraphNodesSize() ; i++ ) {
1788       GraphExecutor::InNode * aNode = (GraphExecutor::InNode * ) Graph()->GraphNodes( i )->GetInNode() ;
1789       aNode->ControlState( SUPERV::VoidState ) ;
1790       if ( aNode->IsSuspended() ) {
1791         cdebug << aNode->Name() << "->Resume " << theAutomaton->StateName( aNode->State() )
1792                << endl ;
1793         if ( aNode->Resume() ) {
1794           cdebug << aNode->Name() << " Resumed " << theAutomaton->StateName( aNode->State() )
1795                  << endl ;
1796           RetVal += 1 ;
1797         }
1798         else {
1799           cdebug << aNode->Name() << " Resume failed"
1800                  << theAutomaton->StateName( aNode->State() ) << endl ;
1801         }
1802       }
1803       else {
1804         cdebug << aNode->Name() << " " << theAutomaton->StateName( aNode->State() )
1805                << endl ;
1806       }
1807     }
1808   }
1809   else {
1810     cdebug << Graph()->Name() << " not suspended " << theAutomaton->StateName( State() ) << endl ;
1811   }
1812   if ( RetVal ) {
1813     MESSAGE("================================================================================") ;
1814     MESSAGE( Graph()->Name() << " IS RESUMED" ) ;
1815     MESSAGE("================================================================================") ;
1816   }
1817   else {
1818     MESSAGE("================================================================================") ;
1819     MESSAGE( Graph()->Name() << " IS NOT RESUMED" ) ;
1820     MESSAGE("================================================================================") ;
1821   }
1822   int i ;
1823   for ( i = 0 ; i < Graph()->GraphNodesSize() ; i++ ) {
1824     GraphExecutor::InNode * aNode = (GraphExecutor::InNode * ) Graph()->GraphNodes( i )->GetInNode() ;
1825     MESSAGE(aNode->Name() << " " << theAutomaton->StateName( aNode->State() ) ) ;
1826     cdebug << aNode->Name() << " " << theAutomaton->StateName( aNode->State() ) << endl ;
1827   }
1828   cdebug_out << "GraphExecutor::OutNode::Resume" << theAutomaton->StateName( State() ) << " " << RetVal
1829              << " EventQSize " << EventQSize() << endl ;
1830   return RetVal ;
1831 }
1832
1833 bool GraphExecutor::OutNode::Kill() {
1834   bool RetVal = false ;
1835   cdebug_in << "GraphExecutor::OutNode::Kill"
1836              << " EventQSize " << EventQSize() << endl;
1837   _ControlState = SUPERV::ToSuspendState ;
1838   int i ;
1839   for ( i = 0 ; i < Graph()->GraphNodesSize() ; i++ ) {
1840     GraphExecutor::InNode * aNode = (GraphExecutor::InNode * ) Graph()->GraphNodes( i )->GetInNode() ;
1841     bool sts = aNode->Kill() ;
1842     if ( sts ) {
1843       if ( !aNode->IsKilled() ) {
1844         cdebug << aNode->Name() << " not killed : "
1845                << theAutomaton->StateName( aNode->State() ) << " " << aNode->Name() << "->"
1846                << "KilledAction()" << endl ;
1847         MESSAGE( aNode->Name() << " not killed : KilledAction()" ) ;
1848         aNode->KilledAction() ;
1849       }
1850       if ( aNode->IsKilled() ) {
1851         cdebug << aNode->Name() << " killed" << endl ;
1852         RetVal = true ;
1853       }
1854     }
1855     else if ( aNode->IsWaiting() || aNode->IsDone() ) {
1856       cdebug << aNode->Name() << " not killed : "
1857              << theAutomaton->StateName( aNode->State() ) << endl ;
1858     }
1859     else {
1860       cdebug << aNode->Name() << " cannot be killed : "
1861              << theAutomaton->StateName( aNode->State() ) << endl ;
1862     }
1863   }
1864   if ( RetVal ) {
1865     State( GraphExecutor::KilledState ) ;
1866     MESSAGE("================================================================================") ;
1867     MESSAGE( Graph()->Name() << " IS KILLED" <<  theAutomaton->StateName( AutomatonState() ) << " EventQSize "
1868              << EventQSize() ) ;
1869     MESSAGE("================================================================================") ;
1870   }
1871   else {
1872     MESSAGE("================================================================================") ;
1873     MESSAGE( Graph()->Name() << " IS NOT KILLED" ) ;
1874     MESSAGE("================================================================================") ;
1875   }
1876   for ( i = 0 ; i < Graph()->GraphNodesSize() ; i++ ) {
1877     GraphExecutor::InNode * aNode = (GraphExecutor::InNode * ) Graph()->GraphNodes( i )->GetInNode() ;
1878     MESSAGE(aNode->Name() << " " << theAutomaton->StateName( aNode->State() ) ) ;
1879     cdebug << aNode->Name() << " " << theAutomaton->StateName( aNode->State() ) << endl ;
1880   }
1881   cdebug_out << "GraphExecutor::OutNode::Kill " << RetVal
1882              << " Threads " << _Threads << " SuspendedThreads " << _SuspendedThreads
1883              << " EventQSize " << EventQSize() << endl ;
1884
1885   // remove "extra" events from the event queue
1886   siftEvents();
1887
1888   // asv : 25.10.04 : calling Editing() to indicate stop of execution
1889   Graph()->GraphEditor()->Editing();
1890
1891   return RetVal ;
1892 }
1893
1894 bool GraphExecutor::OutNode::Stop() {
1895   bool RetVal = false ;
1896   cdebug_in << "GraphExecutor::OutNode::Stop" << endl;
1897   RetVal = Kill() ;
1898   cdebug_out << "GraphExecutor::OutNode::Stop" << endl ;
1899   if ( RetVal ) {
1900     MESSAGE("================================================================================") ;
1901     MESSAGE( Graph()->Name() << " IS STOPPED" ) ;
1902     MESSAGE("================================================================================") ;
1903   }
1904   return RetVal ;
1905 }
1906
1907 bool GraphExecutor::OutNode::ReadyWait() {
1908   cdebug_in << "GraphExecutor::OutNode::ReadyWait" << endl;
1909   bool aret ;
1910   if ( pthread_mutex_lock( &_MutexWait ) ) {
1911     perror("pthread_mutex_lock _ReadyWait") ;
1912     exit( 0 ) ;
1913   }
1914   aret = IsReady() ;
1915   if ( !aret ) {
1916     Suspend() ;
1917     pthread_cond_wait( &_EventWait , &_MutexWait );
1918     aret = IsReady() ;
1919   }
1920   if ( pthread_mutex_unlock( &_MutexWait ) ) {
1921     perror("pthread_mutex_lock _ReadyWait") ;
1922     exit( 0 ) ;
1923   }
1924   cdebug_out << "GraphExecutor::OutNode::ReadyWait" << endl ;
1925   return aret ;
1926 }
1927
1928 bool GraphExecutor::OutNode::RunningWait() {
1929   cdebug_in << "GraphExecutor::OutNode::RunningWait" << endl;
1930   bool aret ;
1931   if ( pthread_mutex_lock( &_MutexWait ) ) {
1932     perror("pthread_mutex_lock _RunningWait") ;
1933     exit( 0 ) ;
1934   }
1935   aret = IsRunning() ;
1936   if ( !aret ) {
1937     cdebug << "RunningWait pthread_cond_wait _EventWait" << endl;
1938     pthread_cond_wait( &_EventWait , &_MutexWait );
1939     aret = IsRunning() ;
1940     cdebug << "RunningWait pthread_cond_waited _EventWait " << aret << endl;
1941   }
1942   if ( pthread_mutex_unlock( &_MutexWait ) ) {
1943     perror("pthread_mutex_lock _RunningWait") ;
1944     exit( 0 ) ;
1945   }
1946   cdebug_out << "GraphExecutor::OutNode::RunningWait " << aret << endl ;
1947   return aret ;
1948 }
1949
1950 bool GraphExecutor::OutNode::DoneWait() {
1951   cdebug_in << pthread_self() << " GraphExecutor::DoneWait " << this << " " << Graph()->Name() << endl;
1952   bool aret ;
1953   if ( pthread_mutex_lock( &_MutexWait ) ) {
1954     perror("pthread_mutex_lock _DoneWait") ;
1955     exit( 0 ) ;
1956   }
1957   aret = IsDone() ;
1958   while ( !aret && !IsSuspended() && IsRunning() ) {
1959     cdebug << pthread_self() << " GraphExecutor::DoneWait " << this << " " << Graph()->Name()
1960            << " DoneWait pthread_cond_wait _EventWait " << &_EventWait << endl;
1961     pthread_cond_wait( &_EventWait , &_MutexWait );
1962     aret = IsDone() ;
1963     cdebug << pthread_self() << " GraphExecutor::DoneWait " << this << " " << Graph()->Name()
1964            << " DoneWait pthread_cond_waited _EventWaited " << &_EventWait << " : "<< aret << endl;
1965   }
1966   if ( pthread_mutex_unlock( &_MutexWait ) ) {
1967     perror("pthread_mutex_lock _DoneWait") ;
1968     exit( 0 ) ;
1969   }
1970   cdebug_out << pthread_self() << " GraphExecutor::DoneWait " << this << " " << Graph()->Name()
1971              << " " << State() << " : " << aret << endl ;
1972   return aret ;
1973 }
1974
1975 bool GraphExecutor::OutNode::SuspendedWait() {
1976   cdebug_in << "GraphExecutor::OutNode::SuspendedWait" << endl;
1977   bool aret ;
1978   if ( pthread_mutex_lock( &_MutexWait ) ) {
1979     perror("pthread_mutex_lock _SuspendedWait") ;
1980     exit( 0 ) ;
1981   }
1982   aret = IsSuspended() ;
1983   while ( !aret && !IsDone() ) {
1984     pthread_cond_wait( &_EventWait , &_MutexWait );
1985     aret = IsSuspended() ;
1986   }
1987   if ( pthread_mutex_unlock( &_MutexWait ) ) {
1988     perror("pthread_mutex_lock _SuspendedWait") ;
1989     exit( 0 ) ;
1990   }
1991   cdebug_out << "GraphExecutor::OutNode::SuspendedWait" << endl ;
1992   return aret ;
1993 }
1994
1995 bool GraphExecutor::OutNode::ReadyWait( const char * NodeName ) {
1996   bool aret = false ;
1997   cdebug_in << "GraphExecutor::OutNode::ReadyWait " << NodeName << endl;
1998   GraphExecutor::InNode *anInNode = (GraphExecutor::InNode *) Graph()->GetGraphNode( NodeName )->GetInNode() ;
1999   if ( anInNode ) {
2000     aret = anInNode->ReadyWait() ;
2001   }
2002   cdebug_out << "GraphExecutor::OutNode::ReadyWait" << endl ;
2003   return aret ;
2004 }
2005
2006 bool GraphExecutor::OutNode::RunningWait( const char * NodeName ) {
2007   bool aret = false ;
2008   cdebug_in << "GraphExecutor::OutNode::RunningWait " << NodeName << endl;
2009   GraphExecutor::InNode *anInNode = (GraphExecutor::InNode *) Graph()->GetGraphNode( NodeName )->GetInNode() ;
2010   if ( anInNode ) {
2011     aret = anInNode->RunningWait() ;
2012   }
2013   cdebug_out << "GraphExecutor::OutNode::RunningWait" << endl ;
2014   return aret ;
2015 }
2016
2017 bool GraphExecutor::OutNode::DoneWait( const char * NodeName ) {
2018   bool aret = false ;
2019   cdebug_in << "GraphExecutor::OutNode::DoneWait " << NodeName << endl;
2020   GraphExecutor::InNode *anInNode = (GraphExecutor::InNode *) Graph()->GetGraphNode( NodeName )->GetInNode() ;
2021   if ( anInNode ) {
2022     aret = anInNode->DoneWait() ;
2023   }
2024   cdebug_out << "GraphExecutor::OutNode::DoneWait" << endl ;
2025   return aret ;
2026 }
2027
2028 bool GraphExecutor::OutNode::SuspendedWait( const char * NodeName ) {
2029   bool aret = false ;
2030   cdebug_in << "GraphExecutor::OutNode::SuspendedWait " << NodeName << endl;
2031   GraphExecutor::InNode *anInNode = (GraphExecutor::InNode *) Graph()->GetGraphNode( NodeName )->GetInNode() ;
2032   if ( anInNode ) {
2033     aret = anInNode->SuspendedWait() ;
2034   }
2035   cdebug_out << "GraphExecutor::OutNode::SuspendedWait" << endl ;
2036   return aret ;
2037 }
2038
2039 long GraphExecutor::OutNode::LastLevelDone() {
2040   int RetVal = -1 ;
2041   int i , j ;
2042   for ( i = 0 ; i <= Graph()->LevelMax() ; i++ ) {
2043     for ( j = 0 ; j <= Graph()->NodesNumber( i ) ; j++ ) {
2044       GraphBase::ComputingNode * aNode = Graph()->SortedNodes( i , j ) ;
2045       if ( !IsDone( aNode->Name() ) ) {
2046         break ;
2047       }
2048     }
2049     if ( j != Graph()->NodesNumber( i ) + 1 )
2050       break ;
2051     RetVal = i ;
2052   }
2053   return RetVal ;
2054 }
2055
2056
2057 const CORBA::Any *GraphExecutor::OutNode::GetInData( const char * NodeName ,
2058                                                      const char * ServiceParameterName ) {
2059 //  cdebug_in << "GraphExecutor::OutNode::GetInData " << NodeName << " "
2060 //            << ServiceParameterName << endl ;
2061   const CORBA::Any * retdata = Graph()->PortInData( NodeName , ServiceParameterName ) ;
2062 //  cdebug_out << "GraphExecutor::OutNode::GetInData" << endl ;
2063   return retdata ;
2064 }
2065
2066 const CORBA::Any *GraphExecutor::OutNode::GetOutData( const char * NodeName ,
2067                                                       const char * ServiceParameterName ) {
2068 //  cdebug_in << "GraphExecutor::OutNode::GetOutData " << NodeName << " "
2069 //            << ServiceParameterName << endl ;
2070   const CORBA::Any * retdata = Graph()->PortOutData( NodeName , ServiceParameterName ) ;
2071 //  cdebug_out << "GraphExecutor::OutNode::GetOutData" << endl ;
2072   return retdata ;
2073 }
2074
2075 const long GraphExecutor::OutNode::CpuUsed() {
2076   return Graph()->CpuUsed() ;
2077 }
2078
2079 const long GraphExecutor::OutNode::CpuUsed( const char * aNodeName ) {
2080   GraphBase::ComputingNode * aNode = Graph()->GetChangeGraphNode( aNodeName ) ;
2081   if ( aNode ) {
2082     GraphExecutor::InNode * anInNode = (GraphExecutor::InNode * ) aNode->GetInNode() ;
2083     if ( anInNode ) {
2084       return anInNode->CpuUsed() ;
2085     }
2086   }
2087   return 0 ;
2088 }
2089
2090 // remove equal sets "Node-Event-State" from _EventNodes/_Events/_States queues
2091 void GraphExecutor::OutNode::siftEvents() {
2092   list<char*>::reverse_iterator itNodes = _EventNodes.rbegin();
2093   list<GraphExecutor::NodeEvent>::reverse_iterator itEvents = _Events.rbegin();
2094   list<GraphExecutor::AutomatonState>::reverse_iterator itStates = _States.rbegin();
2095   list<char*> _NewEventNodes;
2096   list<GraphExecutor::NodeEvent> _NewEvents;
2097   list<GraphExecutor::AutomatonState> _NewStates;
2098   for ( ; itNodes != _EventNodes.rend() ; ++itNodes, ++itEvents, ++itStates) {
2099     //cout << "----- aNodeName ==> " << *itNodes;
2100     list<char*>::reverse_iterator itNewNodes = _NewEventNodes.rbegin();
2101     bool found = false;
2102     for ( ; itNewNodes != _NewEventNodes.rend() ; ++itNewNodes ) {
2103       if ( !strcmp( *itNewNodes, *itNodes ) ) {
2104         found = true;
2105         break;
2106       }
2107     }
2108
2109     if ( found ) {
2110       //cout << "   FOUND";
2111     }
2112     else {
2113       _NewEventNodes.push_back( *itNodes );
2114       _NewEvents.push_back( *itEvents );
2115       _NewStates.push_back( *itStates );
2116     }
2117     //cout << endl;
2118   }
2119   _EventNodes = _NewEventNodes;
2120   _Events = _NewEvents;
2121   _States = _NewStates;
2122 }