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