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