]> SALOME platform Git repositories - modules/superv.git/blob - src/GraphExecutor/DataFlowExecutor_OutNode.cxx
Salome HOME
A special "Loading" state was implemented. It is returned to GUI if the correspondin...
[modules/superv.git] / src / GraphExecutor / DataFlowExecutor_OutNode.cxx
1 //  SUPERV GraphExecutor : contains classes that permit execution of graphs and particularly the execution automaton
2 //
3 //  Copyright (C) 2003  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 //  CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS 
5 // 
6 //  This library is free software; you can redistribute it and/or 
7 //  modify it under the terms of the GNU Lesser General Public 
8 //  License as published by the Free Software Foundation; either 
9 //  version 2.1 of the License. 
10 // 
11 //  This library is distributed in the hope that it will be useful, 
12 //  but WITHOUT ANY WARRANTY; without even the implied warranty of 
13 //  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU 
14 //  Lesser General Public License for more details. 
15 // 
16 //  You should have received a copy of the GNU Lesser General Public 
17 //  License along with this library; if not, write to the Free Software 
18 //  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA 
19 // 
20 //  See http://www.opencascade.org/SALOME/ or email : webmaster.salome@opencascade.org 
21 //
22 //
23 //
24 //  File   : DataFlowBase_OutNode.cxx
25 //  Author : Jean Rahuel, CEA
26 //  Module : SUPERV
27 //  $Header:
28
29 using namespace std;
30
31 #include "DataFlowExecutor_OutNode.hxx"
32
33 #include "DataFlowEditor_DataFlow.hxx"
34
35 extern Engines_Container_i * _TheContainer ;
36
37 extern GraphExecutor::FiniteStateMachine * theAutomaton ;
38
39 // static const char *ComponentName = "SalomeSuperVisionComponent" ;
40
41 extern int _ArgC ;
42 extern char ** _ArgV ;
43
44 GraphExecutor::OutNode::OutNode() {
45 //               Graph() {
46   _SuperVisionContainer = _TheContainer ;
47   _MainThreadId = SuperVisionContainer()->MainThreadId() ;
48   _Valid = false ;
49   _Executable = false ;
50   _Done = false ;
51   _Threads = 0 ;
52   _ControlState = SUPERV::VoidState ;
53   _State = GraphExecutor::UnKnownState ;
54   _PyInitialized = false ;
55   pthread_mutex_init( &_MutexWait , NULL ) ;
56   pthread_mutex_init( &_PyMutexWait , NULL ) ;
57   if ( pthread_cond_init( &_EventWait , NULL ) ) {
58     perror("pthread_cond_init( &_EventWait , NULL )") ;
59     exit( 0 ) ;
60   }
61   if ( pthread_cond_init( &_JoinWait , NULL ) ) {
62     perror("pthread_cond_init( &_JoinWait , NULL )") ;
63     exit( 0 ) ;
64   }
65 }
66
67 GraphExecutor::OutNode::OutNode( CORBA::ORB_ptr ORB, 
68                                  SALOME_NamingService* ptrNamingService ,
69                                  const char *DataFlowName ,
70                                  const char * DebugFileName ,
71                                  const SUPERV::KindOfNode aKindOfNode ) {
72 //               Graph( ORB , ptrNamingService , DataFlowName , DebugFileName ) {
73   Set_prof_debug( ORB , DebugFileName ) ;
74   cdebug_in << "GraphExecutor::OutNode::OutNode(" << DataFlowName << " , " << aKindOfNode << ")" << endl;
75   if ( aKindOfNode == SUPERV::DataFlowGraph ) {
76     _StreamGraph = NULL ;
77 //    _Graph = new GraphBase::Graph( ORB , ptrNamingService , DataFlowName , DebugFileName ) ;
78     _Graph = new GraphBase::Graph( ORB , ptrNamingService , DataFlowName , aKindOfNode ,
79                                    _prof_debug , _fdebug ) ;
80   }
81   else if ( aKindOfNode == SUPERV::DataStreamGraph ) {
82 //    _StreamGraph = new GraphBase::StreamGraph( ORB , ptrNamingService , DataFlowName , DebugFileName ) ;;
83     _StreamGraph = new GraphBase::StreamGraph( ORB , ptrNamingService , DataFlowName , aKindOfNode ,
84                                                _prof_debug , _fdebug ) ;
85     _Graph = _StreamGraph ;
86   }
87   _SuperVisionContainer = _TheContainer ;
88   _MainThreadId = SuperVisionContainer()->MainThreadId() ;
89   _Valid = false ;
90   _Executable = false ;
91   _Done = false ;
92   _Threads = 0 ;
93   _ControlState = SUPERV::VoidState ;
94   _State = GraphExecutor::UnKnownState ;
95   _PyInitialized = false ;
96   _Orb = CORBA::ORB::_duplicate( ORB ) ;
97   pthread_mutex_init( &_MutexWait , NULL ) ;
98   pthread_mutex_init( &_PyMutexWait , NULL ) ;
99   if ( pthread_cond_init( &_EventWait , NULL ) ) {
100     perror("pthread_cond_init( &_EventWait , NULL )") ;
101     exit( 0 ) ;
102   }
103   if ( pthread_cond_init( &_JoinWait , NULL ) ) {
104     perror("pthread_cond_init( &_JoinWait , NULL )") ;
105     exit( 0 ) ;
106   }
107   cdebug_out << "GraphExecutor::OutNode::OutNode" << endl;
108 }
109
110 GraphExecutor::OutNode::OutNode( CORBA::ORB_ptr ORB, 
111                                  SALOME_NamingService* ptrNamingService ,
112                                  const SALOME_ModuleCatalog::Service& DataFlowService ,
113                                  const char *DataFlowComponentName ,
114                                  const char *DataFlowInterfaceName ,
115                                  const char *DataFlowName ,
116                                  const SUPERV::KindOfNode DataFlowkind ,
117                                  const SUPERV::SDate DataFlowFirstCreation ,
118                                  const SUPERV::SDate DataFlowLastModification ,
119                                  const char * DataFlowEditorRelease ,
120                                  const char * DataFlowAuthor ,
121                                  const char * DataFlowComputer ,
122                                  const char * DataFlowComment ,
123                                  const char * DebugFileName ) {
124 //                                 Graph( ORB , ptrNamingService , DataFlowService , DataFlowComponentName ,
125 //                                        DataFlowInterfaceName , DataFlowName , DataFlowkind ,
126 //                                        DataFlowFirstCreation , DataFlowLastModification  ,
127 //                                        DataFlowEditorRelease , DataFlowAuthor ,
128 //                                        DataFlowComputer , DataFlowComment , DebugFileName ) {
129   Set_prof_debug( ORB , DebugFileName ) ;
130
131   cdebug_in << "GraphExecutor::OutNode::OutNode(" << DataFlowName << " , " << DataFlowkind << ")" << endl;
132   if ( DataFlowkind == SUPERV::DataFlowGraph ) {
133     _StreamGraph = NULL ;
134     _Graph = new GraphBase::Graph( ORB , ptrNamingService , DataFlowService , DataFlowComponentName ,
135                                    DataFlowInterfaceName , DataFlowName , DataFlowkind ,
136                                    DataFlowFirstCreation , DataFlowLastModification  ,
137                                    DataFlowEditorRelease , DataFlowAuthor ,
138                                    DataFlowComputer , DataFlowComment ,
139                                    _prof_debug , _fdebug ) ;
140 //                                   DataFlowComputer , DataFlowComment , DebugFileName ) ;
141   }
142   else if ( DataFlowkind == SUPERV::DataStreamGraph ) {
143     _StreamGraph = new GraphBase::StreamGraph( ORB , ptrNamingService , DataFlowService , DataFlowComponentName ,
144                                                DataFlowInterfaceName , DataFlowName , DataFlowkind ,
145                                                DataFlowFirstCreation , DataFlowLastModification  ,
146                                                DataFlowEditorRelease , DataFlowAuthor ,
147                                                DataFlowComputer , DataFlowComment ,
148                                                _prof_debug , _fdebug ) ;
149     _Graph = _StreamGraph ;
150   }
151   _SuperVisionContainer = _TheContainer ;
152   _MainThreadId = SuperVisionContainer()->MainThreadId() ;
153   _Valid = false ;
154   _Executable = false ;
155   _Done = false ;
156   _Threads = 0 ;
157   _ControlState = SUPERV::VoidState ;
158   _State = GraphExecutor::UnKnownState ;
159   _PyInitialized = false ;
160   _Orb = CORBA::ORB::_duplicate( ORB ) ;
161   pthread_mutex_init( &_MutexWait , NULL ) ;
162   pthread_mutex_init( &_PyMutexWait , NULL ) ;
163   if ( pthread_cond_init( &_EventWait , NULL ) ) {
164     perror("pthread_cond_init( &_EventWait , NULL )") ;
165     exit( 0 ) ;
166   }
167   if ( pthread_cond_init( &_JoinWait , NULL ) ) {
168     perror("pthread_cond_init( &_JoinWait , NULL )") ;
169     exit( 0 ) ;
170   }
171 }
172
173 GraphExecutor::OutNode::~OutNode() {
174 }
175
176 void GraphExecutor::OutNode::Set_prof_debug( CORBA::ORB_ptr ORB ,
177                                              const char * DebugFileName ) {
178   _Graph_prof_debug = 0 ;
179   if ( DebugFileName ) {
180     _fdebug = new ofstream( DebugFileName );
181     SetDebug( ORB , &_Graph_prof_debug , _fdebug ) ;
182     MESSAGE( endl << "Trace redirected to file " << DebugFileName << endl)
183   }
184 }
185
186 bool GraphExecutor::OutNode::LoadDataFlow(const GraphBase::SGraph * aDataFlow ) {
187   bool RetVal = false ;
188   cdebug_in << "GraphExecutor::OutNode::LoadDataFlow " << (*aDataFlow).Info.theName << endl ;
189   RetVal = LoadInfo( (*aDataFlow).Info ) ;
190   if ( Graph()->ServiceName() != NULL ) {
191 //    MESSAGE( "GraphExecutor::OutNode::LoadDataFlow" );
192     if ( RetVal ) {
193       RetVal = LoadNodes( (*aDataFlow).Nodes ) ;
194       if ( RetVal ) {
195         RetVal = LoadLinks( (*aDataFlow).Links ) ;
196         if ( RetVal ) {
197           IsValid() ;
198           RetVal = LoadDatas( (*aDataFlow).Datas ) ;
199           IsExecutable() ;
200           if ( !RetVal) {
201             cdebug << "GraphExecutor::OutNode::LoadDataFlow LoadDatas Error."
202                    << endl ;
203           }
204         }
205         else {
206           cdebug << "GraphExecutor::OutNode::LoadDataFlow LoadLinks Error."
207                << endl ;
208         }
209       }
210       else {
211         cdebug << "GraphExecutor::OutNode::LoadDataFlow LoadNodes Error."
212              << endl ;
213       }
214     }
215     else {
216       cdebug << "GraphExecutor::OutNode::LoadDataFlow LoadInfo Error."
217            << endl ;
218     }
219   }
220   else {
221     cdebug << "GraphExecutor::OutNode::LoadDataFlow ServiceName Error." << endl ;
222   }
223   cdebug_out << "GraphExecutor::OutNode::LoadDataFlow " << Graph()->Name() << " RetVal "
224              << RetVal << endl ;
225   return RetVal ;
226 }
227
228 #if 0
229 bool GraphExecutor::OutNode::LoadXml( const char* myFileName ) {
230   bool RetVal = false ;
231   GraphBase::ListOfSGraphs aListOfDataFlows ;
232   if ( Graph()->LoadXml( _Orb , myFileName , aListOfDataFlows ) ) {
233     RetVal = LoadDataFlow( aListOfDataFlows ) ;
234 //    if ( aConstructor && RetVal )
235 //      RetVal = Name( aDataFlow.Info.theName.c_str() ) ;
236   }
237   return RetVal ;
238 }
239 #endif
240
241 bool GraphExecutor::OutNode::LoadInfo(const GraphBase::SNode &aDataFlowInfo ) {
242   cdebug << "GraphExecutor::OutNode::LoadInfo _StreamGraph " << _StreamGraph << endl ;
243 //  ComponentName( aDataFlowInfo.theComponentName.c_str()  ) ;
244   Graph()->Name( aDataFlowInfo.theName.c_str()  ) ;
245   Graph()->Kind( aDataFlowInfo.theKind ) ;
246   if ( Graph()->IsDataStreamNode() && aDataFlowInfo.theKind == SUPERV::DataStreamGraph ) {
247     StreamGraph()->SetStreamParams( aDataFlowInfo.theTimeout , aDataFlowInfo.theDataStreamTrace , aDataFlowInfo.theDeltaTime ) ;
248   }
249   Graph()->DataService( _Orb , aDataFlowInfo.theService , _prof_debug , _fdebug ) ;
250   Graph()->FirstCreation( aDataFlowInfo.theFirstCreation ) ;
251   Graph()->LastModification( aDataFlowInfo.theLastModification ) ;
252   Graph()->EditorRelease( aDataFlowInfo.theEditorRelease.c_str()  ) ;
253   Graph()->Author( aDataFlowInfo.theAuthor.c_str()   ) ;
254 //  Graph()->Computer( aDataFlowInfo.theContainer.c_str()  ) ;
255   Graph()->Comment( aDataFlowInfo.theComment.c_str()  ) ;
256 // Not in OutNode/DataFlow but in InNode/DataFlow_in_an_other_DataFlow
257 //  Graph()->Coordinates( aDataFlowInfo.theX , aDataFlowInfo.theY ) ;
258   return true ;
259 }
260
261 bool GraphExecutor::OutNode::LoadNodes(const GraphBase::ListOfSNodes &aListOfNodes ) {
262   bool RetVal = true ;
263   GraphExecutor::InNode * anInNode ;
264   cdebug << "GraphExecutor::OutNode::LoadNodes" << endl ;
265   int i ;
266   for ( i = 0 ; i < (int ) aListOfNodes.size() ; i++ ) {
267     GraphBase::SNode aNode = aListOfNodes[ i ] ;
268     anInNode = AddNode( aNode.theService ,
269                         aNode.theListOfFuncName ,
270                         aNode.theListOfPythonFunctions ,
271                         aNode.theComponentName.c_str() ,
272                         aNode.theInterfaceName.c_str()  , aNode.theName.c_str() ,
273                         aNode.theKind ,
274                         aNode.theFirstCreation , aNode.theLastModification ,
275                         aNode.theEditorRelease.c_str() ,
276                         aNode.theAuthor.c_str()  , aNode.theContainer.c_str() ,
277                         aNode.theComment.c_str() ,
278                         aNode.theCoords.theX , aNode.theCoords.theY ) ;
279     if ( !anInNode ) {
280       RetVal = false ;
281       break ;
282     }
283     if ( anInNode->IsOneOfInLineNodes() || anInNode->IsMacroNode() ) {
284       anInNode->GraphExecutor::InNode::InLineNode()->DefPortsOfNode(
285                                 _Orb , aNode.theService , anInNode->NamePtr() ,
286                                 anInNode->Kind() ,
287                                 _prof_debug , _fdebug ) ;
288     }
289 //    GraphBase::ComputingNode * theNode = Graph()->GetChangeGraphNode( aNode.theName.c_str() ) ;
290
291     unsigned int j ;
292     for ( j = 0 ; j < aNode.theListOfInDataStreams.size() ; j++ ) {
293       GraphBase::InPort * anInPort ;
294       anInPort = anInNode->ComputingNode()->AddInDataStreamPort( aNode.theListOfInDataStreams[ j ].theDataStreamParameter.Parametername ,
295                                                                  aNode.theListOfInDataStreams[ j ].theDataStreamParameter.Parametertype ,
296                                                                  aNode.theListOfInDataStreams[ j ].theDataStreamParameter.Parameterdependency ,
297                                                                  SUPERV::DataStreamParameter ) ;
298       ((GraphBase::InDataStreamPort * ) anInPort)->SetParams( aNode.theListOfInDataStreams[ j ].theKindOfSchema ,
299                                                               aNode.theListOfInDataStreams[ j ].theKindOfInterpolation ,
300                                                               aNode.theListOfInDataStreams[ j ].theKindOfExtrapolation ) ;
301     }
302     for ( j = 0 ; j < aNode.theListOfOutDataStreams.size() ; j++ ) {
303       GraphBase::OutPort * anOutPort ;
304       anOutPort = anInNode->ComputingNode()->AddOutDataStreamPort( aNode.theListOfOutDataStreams[ j ].theDataStreamParameter.Parametername ,
305                                                                    aNode.theListOfOutDataStreams[ j ].theDataStreamParameter.Parametertype ,
306                                                                    aNode.theListOfOutDataStreams[ j ].theDataStreamParameter.Parameterdependency ,
307                                                                    SUPERV::DataStreamParameter ) ;
308       ((GraphBase::OutDataStreamPort * ) anOutPort)->NumberOfValues( aNode.theListOfOutDataStreams[ j ].theNumberOfValues ) ;
309     }
310
311
312 //    theNode->DataStreamInPortsNumber( aNode.theDataStreamInArgsNumber ) ;
313 //    theNode->DataStreamOutPortsNumber( aNode.theDataStreamOutArgsNumber ) ;
314 //    cdebug << "GraphExecutor::OutNode::LoadNodes " << anInNode->Name()
315 //           << " InPortsSize " << theNode->GetNodeInPortsSize()
316 //           << " OutPortsSize " << theNode->GetNodeOutPortsSize()
317 //           << " DataStreamInPortsNumber " << aNode.theDataStreamInArgsNumber
318 //           << " DataStreamOutPortsNumber " << aNode.theDataStreamOutArgsNumber
319 //           << endl ;
320 //    int j ;
321 //    if ( aNode.theDataStreamInArgsNumber ) { // -1 because of Gates
322 //      for ( j = theNode->GetNodeInPortsSize() - aNode.theDataStreamInArgsNumber - 1 ; j < theNode->GetNodeInPortsSize() - 1 ; j++ ) {
323 //        cdebug << "GraphExecutor::OutNode::LoadNodes " << anInNode->Name()
324 //               << " InPort " << theNode->GetChangeNodeInPort( j )->PortName()
325 //               << " Kind( DataStreamParameter)" << endl ;
326 //        theNode->GetChangeNodeInPort( j )->Kind( SUPERV::DataStreamParameter ) ;
327 //      }
328 //    }
329 //    if ( aNode.theDataStreamOutArgsNumber ) {
330 //      int withgate = 1 ;
331 //      if ( theNode->IsLoopNode() || theNode->IsEndLoopNode() ) {
332 //        withgate = 0 ;
333 //      }
334 //      for ( j = theNode->GetNodeOutPortsSize() - aNode.theDataStreamOutArgsNumber - withgate ; j < theNode->GetNodeOutPortsSize() - withgate ; j++ ) {
335 //        cdebug << "GraphExecutor::OutNode::LoadNodes " << anInNode->Name()
336 //               << " OutPort " << theNode->GetChangeNodeOutPort( j )->PortName()
337 //               << " Kind( DataStreamParameter)" << endl ;
338 //        theNode->GetChangeNodeOutPort( j )->Kind( SUPERV::DataStreamParameter ) ;
339 //      }
340 //    }
341   }
342   for ( i = 0 ; i < (int ) aListOfNodes.size() ; i++ ) {
343     GraphBase::SNode aNode = aListOfNodes[ i ] ;
344     anInNode = (GraphExecutor::InNode * ) Graph()->GetChangeGraphNode( aNode.theName.c_str() )->GetInNode() ;
345     cdebug << "GraphExecutor::OutNode::LoadNodes " << anInNode->Name() << " IsOneOfGOTONodes "
346            << anInNode->IsOneOfGOTONodes() << " " << aNode.theCoupledNode.c_str() << endl ;
347     if ( anInNode->IsOneOfGOTONodes() && strlen( aNode.theCoupledNode.c_str() ) ) {
348       GraphBase::GOTONode * aCoupledNode ;
349       aCoupledNode = (GraphBase::GOTONode * ) Graph()->GetGraphNode( aNode.theName.c_str() ) ;
350       GraphBase::GOTONode * aCoupledCoupledNode ;
351       aCoupledCoupledNode = (GraphBase::GOTONode * ) Graph()->GetChangeGraphNode( aNode.theCoupledNode.c_str() ) ;
352       if ( aCoupledCoupledNode != NULL ) {
353         aCoupledNode->CoupledNode( aCoupledCoupledNode ) ;
354       }
355       else {
356         aCoupledNode->CoupledNodeName( aNode.theCoupledNode.c_str() ) ;
357       }
358     }
359   }
360   return RetVal ;
361 }
362
363 bool GraphExecutor::OutNode::LoadLinks(const GraphBase::ListOfSLinks &aListOfLinks ) {
364   bool RetVal = true ;
365   cdebug << "GraphExecutor::OutNode::LoadLinks " << aListOfLinks.size()
366          << endl ;
367   int i ;
368   for ( i = 0 ; i < (int ) aListOfLinks.size() ; i++ ) {
369     GraphBase::SLink aLink = aListOfLinks[ i ] ;
370     RetVal = Graph()->AddLink( aLink.FromNodeName.c_str() ,
371                                aLink.FromServiceParameterName.c_str() ,
372                                aLink.ToNodeName.c_str() ,
373                                aLink.ToServiceParameterName.c_str() ) ;
374 //                               , aLink.aLinkValue ) ;
375     if ( !RetVal )
376       break ;
377   }
378   return RetVal ;
379 }
380
381 bool GraphExecutor::OutNode::LoadDatas(const GraphBase::ListOfSLinks &aListOfDatas ) {
382   bool RetVal = true ;
383   cdebug << "GraphExecutor::OutNode::LoadDatas " << aListOfDatas.size()
384          << endl ;
385   int i ;
386   for ( i = 0 ; i < (int ) aListOfDatas.size() ; i++ ) {
387     GraphBase::SLink aLink = aListOfDatas[ i ] ;
388     if ( !strcmp( aLink.FromNodeName.c_str() , Graph()->Name() ) )
389       RetVal = Graph()->AddInputData( aLink.ToNodeName.c_str() ,
390                                       aLink.ToServiceParameterName.c_str() ,
391                                       aLink.aLinkValue ) ;
392 //    else if ( !strcmp( aLink.ToNodeName.c_str() , Graph()->Name() ) ) {
393 //      RetVal = Graph()->AddOutputData( aLink.FromNodeName.c_str() ,
394 //                                       aLink.FromServiceParameterName.c_str() ) ;
395 //      Graph()->AddLink( aLink.FromNodeName.c_str() , (GraphBase::ComputingNode *) this ) ;
396 //    }
397     else {
398       cdebug << "GraphExecutor::OutNode::LoadDatas Error " << aLink.FromNodeName
399            << " and " << aLink.ToNodeName << " differents from " << Graph()->Name()
400            << endl ;
401       RetVal = false ;
402     }
403     if ( !RetVal )
404       break ;
405   }
406   return RetVal ;
407 }
408
409 GraphExecutor::InNode *GraphExecutor::OutNode::AddNode(
410                       const SALOME_ModuleCatalog::Service& NodeService ,
411                       GraphBase::ListOfFuncName aFuncName ,
412                       GraphBase::ListOfPythonFunctions aPythonFunction ,
413                       const char * NodeComponentName ,
414                       const char * NodeInterfaceName ,
415                       const char * NodeName ,
416                       const SUPERV::KindOfNode NodeKindOfNode ,
417                       const SUPERV::SDate NodeFirstCreation ,
418                       const SUPERV::SDate NodeLastModification  ,
419                       const char * NodeEditorRelease ,
420                       const char * NodeAuthor ,
421                       const char * NodeComputer ,
422                       const char * NodeComment ,
423                       const int NodeX ,
424                       const int NodeY ) {
425   cdebug_in << "GraphExecutor::OutNode::AddNode(" << NodeComponentName << " , "
426             << NodeName << ")" << endl;
427   GraphExecutor::InNode *Nd = NULL ;
428   Nd = new GraphExecutor::InNode( _Orb, Graph()->NamingService() , NodeService ,
429                                   NodeComponentName , NodeInterfaceName ,
430                                   NodeName , NodeKindOfNode ,
431                                   aFuncName , aPythonFunction ,
432                                   NodeFirstCreation , NodeLastModification ,
433                                   NodeEditorRelease , NodeAuthor ,
434                                   NodeComputer , NodeComment , false , NodeX , NodeY ,
435                                   _prof_debug , _fdebug ) ;
436   Graph()->AddNode( Nd->ComputingNode() ) ;
437   cdebug_out << "GraphExecutor::OutNode::AddNode" << endl;
438   return Nd ;
439 }
440
441
442 bool GraphExecutor::OutNode::Valid() {
443   cdebug_in << "GraphExecutor::OutNode::Valid" << endl;
444
445   if ( _Valid )
446     return true ;
447
448   _Executable = false ;
449
450   if ( !Graph()->CreateService() ) {
451     cdebug << "This DataFlow has invalid type(s)." << endl ;
452     return false ;
453   }
454   int SubStreamGraphsNumber = 0 ;
455   if ( !Graph()->Sort( SubStreamGraphsNumber ) ) {
456     cdebug << "This DataFlow is not valid." << endl ;
457     return false ;
458   }
459   if ( Graph()->IsDataStreamNode() ) {
460     StreamGraph()->SubStreamGraphsNumber( SubStreamGraphsNumber ) ;
461   }
462
463 //  CreateService() ;
464
465   Graph()->InLineServices() ;
466
467   Graph()->ComputingNodes() ;
468   
469   _Valid = true ;
470
471   cdebug_out << "GraphExecutor::OutNode::Valid" << endl;
472   return _Valid ;
473 }
474
475
476 bool GraphExecutor::OutNode::Executable() {
477
478   cdebug_in << "GraphExecutor::OutNode::Executable" << endl;
479   if ( !IsValid() )
480     return false ;
481
482   if ( Graph()->DataServerNodes() )
483     _Executable = true ;
484   else {
485     cdebug << "This DataFlow is not executable." << endl ;
486     _Executable = false ;
487   }
488
489   cdebug_out << "GraphExecutor::OutNode::Executable " << _Executable << endl;
490   return _Executable ;
491 }
492
493 bool GraphExecutor::OutNode::Run( const bool AndSuspend ) {
494   bool RetVal = false ;
495   cdebug_in << pthread_self() << "GraphExecutor::OutNode::Run( AndSuspend " << AndSuspend << " )"
496             << endl;
497
498   if ( Executable() ) {
499     _ControlState = SUPERV::VoidState ;
500     _SuspendedThreads = 0 ;
501     Graph()->ThreadNo( pthread_self() ) ;
502     Done( false ) ;
503     _JustStarted = true ;
504     RetVal = true ;
505     int i ;
506     for ( i = 0 ; i < Graph()->GraphNodesSize() ; i++ ) {
507       GraphExecutor::InNode * anInNode = (GraphExecutor::InNode *) Graph()->GraphNodes( i )->GetInNode() ;
508       anInNode->OutNode( this ) ;
509       if ( !PyInitialized() && anInNode->IsOneOfInLineNodes() ) {
510         if ( !Py_IsInitialized() ) {
511 //          PyEval_InitThreads() ;
512 //          Py_Initialize() ;
513 //          PySys_SetArgv( _ArgC , _ArgV ) ;
514         }
515         anInNode->InitPython() ;
516         PyInitialized( true ) ;
517       }
518       anInNode->InitialState() ;
519       if ( anInNode->IsOneOfInLineNodes() ) {
520         anInNode->InitPythonFunctions( false ) ;
521       }
522     }
523 // One more time because inline nodes may share one definition of the same function
524     for ( i = 0 ; i < Graph()->GraphNodesSize() ; i++ ) {
525       GraphExecutor::InNode * anInNode = (GraphExecutor::InNode *) Graph()->GraphNodes( i )->GetInNode() ;
526       if ( anInNode->IsOneOfInLineNodes() ) {
527         if ( !anInNode->InitPythonFunctions( true ) ) {
528           anInNode->State( GraphExecutor::ErroredState ) ;
529           State( GraphExecutor::ErroredState ) ;
530           cdebug_out << "GraphExecutor::OutNode::Run InitPythonFunctions ERROR "
531                      << anInNode->Name() << endl ;
532           return false ;
533         }
534       }
535     }
536     /* asv : 29.09.04 : commented out because it does not do anything useful 
537     for ( i = 0 ; i < Graph()->GraphNodesSize() ; i++ ) {
538       GraphExecutor::InNode * anInNode = (GraphExecutor::InNode *) Graph()->GraphNodes( i )->GetInNode() ;
539       if ( RetVal && anInNode->IsMacroNode() ) {
540         GraphBase::Graph * aMacroGraph = anInNode->GraphMacroNode() ;
541         cdebug << "GraphExecutor::OutNode::Run " << anInNode << " MacroNode " << aMacroGraph
542                << aMacroGraph->Name() << endl ;
543         SUPERV::Graph_var iobject = anInNode->GraphMacroNode()->MacroObject() ;
544         if ( CORBA::is_nil( iobject ) ) {
545           cdebug << "GraphExecutor::OutNode::Run MacroObject() is a nil object. Error" << endl ;
546           RetVal = false ;
547         }
548         else {
549           cdebug << "GraphExecutor::OutNode::Run MacroObject() is NOT a nil object." << endl ;
550         }
551       }
552     }
553     */
554     if ( Graph()->GraphMacroLevel() != 0 ) {
555       cdebug << "GraphExecutor::OutNode::Run Execution starting GraphExecutor::Action_DataOk_RunService Node "
556              << Graph()->Name() << " GraphMacroLevel " << Graph()->GraphMacroLevel() << endl ;
557       PushEvent( NULL , GraphExecutor::NoDataReadyEvent ,
558                  GraphExecutor::DataUndefState ) ; 
559     }
560     else {
561       cdebug << "Execution starting GraphExecutor::Action_DataOk_RunService Node "
562              << Graph()->Name() << " GraphMacroLevel " << Graph()->GraphMacroLevel() << endl ;
563       PushEvent( NULL , GraphExecutor::ReadyEvent ,
564                  GraphExecutor::DataReadyState ) ; 
565       State( GraphExecutor::DataReadyState ) ;
566
567       cdebug << pthread_self() << " GraphExecutor::OutNode::Run Start of the " << Graph()->HeadNodesSize()
568              << " HeadNodes" << endl ;
569       for ( i = 0 ; i < Graph()->HeadNodesSize() ; i++ ) {
570         GraphExecutor::InNode * anInNode = (GraphExecutor::InNode *) Graph()->HeadNodes( i )->GetInNode() ;
571         cdebug << pthread_self() <<  "GraphExecutor::OutNode::Run Start of HeadNode " << i << " "
572                << anInNode->Name() << endl ;
573         if ( anInNode->State() != GraphExecutor::DataReadyState ) {
574           cdebug << "GraphExecutor::OutNode::Run inconsistency State of Node "
575                  << anInNode->Name() << " : " << anInNode->State() << endl ;
576           cdebug_out << "GraphExecutor::OutNode::Run State ERROR" << endl ;
577           return false ;
578         }
579 //        PushEvent( anInNode , GraphExecutor::ReadyEvent ,
580 //                   GraphExecutor::DataReadyState ) ; 
581         anInNode->CreateNewThread( true ) ;
582         anInNode->DataFromNode( Graph()->Name() ) ;
583         if ( AndSuspend ) {
584           anInNode->State( GraphExecutor::DataWaitingState ) ;
585           anInNode->ControlState( SUPERV::ToSuspendStartState ) ;
586           if ( !anInNode->SendEvent( GraphExecutor::SomeDataReadyEvent ) ) {
587             cdebug << "InNode::SendEvent( SomeDataReadyEvent ) ERROR Node "
588                    << anInNode->Name() << endl ;
589             cdebug_out << "GraphExecutor::OutNode::Run SendEvent ERROR" << endl ;
590             return false ;
591           }
592           anInNode->SuspendedWait() ;
593         }
594         else if ( anInNode->IsMacroNode() ) {
595           if ( !anInNode->SendEvent( GraphExecutor::SomeDataReadyEvent ) ) {
596             cdebug << "InNode::SendEvent( SomeDataReadyEvent ) ERROR Node "
597                    << anInNode->Name() << endl ;
598             cdebug_out << "GraphExecutor::OutNode::Run SendEvent ERROR" << endl ;
599             return false ;
600           }
601           cdebug << pthread_self() << " GraphExecutor::OutNode::Run " << anInNode->Name() << "->RunningWait"
602                  << endl ;
603           anInNode->RunningWait() ;
604           cdebug << pthread_self() << " GraphExecutor::OutNode::Run " << anInNode->Name() << "->RunningWaited"
605                  << endl ;
606         }
607         else if ( !anInNode->IsMacroNode() ) {
608           if ( !anInNode->SendEvent( GraphExecutor::ExecuteEvent ) ) {
609             cdebug << "InNode::SendEvent( ExecuteEvent ) ERROR Node "
610                    << anInNode->Name() << endl ;
611             cdebug_out << "GraphExecutor::OutNode::Run SendEvent ERROR" << endl ;
612             return false ;
613           }
614           anInNode->RunningWait() ;
615         }
616       }
617
618       if ( AndSuspend ) {
619         PushEvent( NULL , GraphExecutor::SuspendedReadyEvent ,
620                    GraphExecutor::SuspendedReadyState ) ; 
621       }
622       else {
623         PushEvent( NULL , GraphExecutor::ExecutingEvent ,
624                    GraphExecutor::ExecutingState ) ; 
625         if (AutomatonState() == GraphExecutor::DataReadyState) {
626             State( GraphExecutor::ExecutingState ) ;
627         };
628       }
629 //      ostringstream astr ;
630 //      astr << "Graph " << Graph()->Name() << " is running" ;
631 //      Graph()->ObjImpl()->sendMessage( NOTIF_STEP, astr.str().c_str() ) ;
632       RetVal = true ;
633     }
634   }
635
636   cdebug_out << pthread_self() << "GraphExecutor::OutNode::Run " << Graph()->Name()
637              << " GraphMacroLevel "
638              << Graph()->GraphMacroLevel() << " RetVal " << RetVal << endl ;
639   return RetVal ;
640 }
641
642 bool GraphExecutor::OutNode::Run( const char * aNodeName ,
643                                   const char * AtNodeName ,
644                                   const bool AndSuspend ) {
645   bool RetVal = false ;
646   cdebug_in << "GraphExecutor::OutNode::Run( " << aNodeName << " , "
647             << AtNodeName << " , " << AndSuspend << ")" << endl;
648   GraphExecutor::InNode *anInNode = (GraphExecutor::InNode *) Graph()->GetGraphNode( aNodeName )->GetInNode() ;
649   if ( anInNode ) {
650     RetVal = anInNode->ReStart( AtNodeName , AndSuspend ) ;
651   }
652   cdebug_out << "GraphExecutor::OutNode::Run" << endl ;
653   return RetVal ;
654 }
655
656 void GraphExecutor::OutNode::CheckAllDone() {
657   int j ;
658   cdebug_in << "GraphExecutor::OutNode::CheckAllDone " << endl;
659   GraphExecutor::AutomatonState OutNodeState = GraphExecutor::SuccessedState ;
660   GraphExecutor::AutomatonState InNodeState ;
661   bool AllDone = true ;
662   if ( !Done() ) {
663     for ( j = 0 ; j < Graph()->QueueNodesSize() ; j++ ) {
664       InNodeState = ( (GraphExecutor::InNode * ) Graph()->QueueNodes( j )->GetInNode() )->State() ;
665       cdebug << j << ". "
666              << ( (GraphExecutor::InNode * ) Graph()->QueueNodes( j )->GetInNode() )->Name()
667              << " " << theAutomaton->StateName( InNodeState ) << endl ;
668       if ( InNodeState != GraphExecutor::SuccessedState &&
669            InNodeState != GraphExecutor::ErroredState &&
670            InNodeState != GraphExecutor::DataWaitingState ) {
671         AllDone = false ;
672       }
673       if ( InNodeState != GraphExecutor::SuccessedState &&
674            InNodeState != GraphExecutor::DataWaitingState &&
675            InNodeState != GraphExecutor::DataReadyState ) {
676         OutNodeState = InNodeState ;
677       }
678     }
679     if ( AllDone ) {
680       if( _Threads == 0 && _SuspendedThreads == 0 ) {
681         if ( OutNodeState != GraphExecutor::ErroredState ) {
682           OutNodeState = GraphExecutor::SuccessedState ;
683         }
684       }
685       else {
686         AllDone = false ;
687       }
688     }
689     if ( AllDone ) {
690       int alivenodes = 0 ;
691       for ( j = 0 ; j < Graph()->GraphNodesSize()  ; j++ ) {
692         GraphExecutor::InNode * aNode ;
693         aNode = (GraphExecutor::InNode * ) Graph()->GraphNodes( j )->GetInNode() ;
694         SUPERV::GraphState aState = AutomatonGraphState( aNode->State() ) ;
695         cdebug << "GraphExecutor::OutNode::CheckAllDone " << aNode->Name() << " "
696                << theAutomaton->StateName( aNode->State() ) << " CreateNewThread " << aNode->CreateNewThread()
697                << endl ;
698         if ( aState == SUPERV::ErrorState ||
699              aState == SUPERV::SuspendErroredState ||
700              aState == SUPERV::KillState ||
701              aState == SUPERV::StopState ) {
702           OutNodeState = aNode->State() ;
703           State( OutNodeState ) ;
704         }
705         else if ( aState == SUPERV::ReadyState ||
706                   aState == SUPERV::SuspendReadyState ||
707                   aState == SUPERV::RunningState ||
708                   aState == SUPERV::SuspendDoneState ||
709                   aState == SUPERV::SuspendErroredState ||
710                   aState == SUPERV::ReRunState ||
711                   aState == SUPERV::ReStartState ||
712                   aState == SUPERV::SuspendState ) {
713           alivenodes += 1 ;
714         }
715         aNode->SuspendedAction() ;
716         aNode->DoneAction() ;
717       }
718 // PushEvent AFTER State and _Done ! ...
719       if ( alivenodes == 0 ) {
720         State( OutNodeState ) ;
721         Done( true ) ;
722         _JustStarted = false ;
723       }
724       cdebug << Graph()->Name() << " alivenodes " << alivenodes << " OutNodeState " << OutNodeState
725              << endl ;
726       PushEvent( NULL , GraphExecutor::EndExecuteEvent ,
727                  OutNodeState ) ;
728 //      Py_Finalize() ;
729 //      PyInitialized( false ) ;
730     }
731   }
732   if ( IsDone() ) {
733     MESSAGE("================================================================================") ;
734     MESSAGE( Graph()->Name() << " IS DONE : " <<  theAutomaton->StateName( AutomatonState() ) << " EventQSize "
735              << EventQSize() ) ;
736     MESSAGE("================================================================================") ;
737     cdebug << "================================================================================" << endl ;
738     cdebug << Graph()->Name() << " IS DONE : " <<  theAutomaton->StateName( AutomatonState() ) << " EventQSize "
739              << EventQSize() << endl  ;
740     cdebug << "================================================================================" << endl ;
741
742     // asv : fix for 6798 and other bugs: "sift" the event queue after execution
743     siftEvents();
744
745     // asv : 25.10.04 : calling Editing() to indicate stop of execution
746     Graph()->GraphEditor()->Editing();
747   }
748   cdebug_out << "GraphExecutor::OutNode::CheckAllDone " << IsDone() << " this " << this << " "
749              << Graph()->Name() << " GraphAutomatonState "
750              << theAutomaton->StateName( AutomatonState() )
751              << " State " << State() << " Threads " << _Threads << " SuspendedThreads "
752              << _SuspendedThreads << " EventQSize " << EventQSize() << endl ;
753 }
754
755 Engines_Container_i * GraphExecutor::OutNode::SuperVisionContainer() {
756   return _SuperVisionContainer ;
757 }
758
759 const pthread_t GraphExecutor::OutNode::MainThreadId() const {
760   return _MainThreadId ;
761 }
762
763 void GraphExecutor::OutNode::PThreadLock( pthread_mutex_t * aMutex , char * errmsg ) {
764 //  if ( strcmp( errmsg , "EventLoop" ) && strcmp( errmsg , "EventW" ) ) {
765 //    cdebug << "GraphExecutor::OutNode::PThreadLock " << pthread_self() << " " << aMutex << " "
766 //           << errmsg << endl ;
767 //  }
768   if ( pthread_mutex_lock( aMutex ) ) {
769     perror( errmsg ) ;
770     exit( 0 ) ;
771   }
772 //  if ( strcmp( errmsg , "EventLoop" ) && strcmp( errmsg , "EventW" ) ) {
773 //    cdebug << "GraphExecutor::OutNode::PThreadLocked " << pthread_self() << " " << aMutex << " "
774 //           << errmsg << endl ;
775 //  }
776 }
777
778 void GraphExecutor::OutNode::PThreadUnLock( pthread_mutex_t * aMutex , char * errmsg ) {
779 //  if ( strcmp( errmsg , "EventLoop" ) && strcmp( errmsg , "EventW" ) ) {
780 //    cdebug << " GraphExecutor::OutNode::PThreadUnLock " << pthread_self() << " " << aMutex << " "
781 //           << errmsg << endl ;
782 //  }
783   if ( pthread_mutex_unlock( aMutex ) ) {
784     perror( errmsg ) ;
785     exit( 0 ) ;
786   }
787 }
788
789 void GraphExecutor::OutNode::PyThreadLock() {
790 //  cout << " GraphExecutor::OutNode::PyThreadLock " << pthread_self() << endl ;
791   if ( pthread_mutex_lock( &_PyMutexWait ) ) {
792     perror( "GraphExecutor::OutNode::PyThreadLock" ) ;
793     exit( 0 ) ;
794   }
795   theAutomaton->PyLock() ;
796 //  cout << " GraphExecutor::OutNode::PyThreadLocked " << pthread_self() << endl ;
797 }
798
799 void GraphExecutor::OutNode::PyThreadUnLock() {
800 //  cout << " GraphExecutor::OutNode::PyThreadUnLock " << pthread_self() << endl ;
801   if ( pthread_mutex_unlock( &_PyMutexWait ) ) {
802     perror( "GraphExecutor::OutNode::PyThreadUnLock" ) ;
803     exit( 0 ) ;
804   }
805   theAutomaton->PyUnLock() ;
806 //  cout << " GraphExecutor::OutNode::PyThreadUnLocked " << pthread_self() << endl ;
807 }
808
809 void GraphExecutor::OutNode::NewThread() {
810   if ( pthread_mutex_lock( &_MutexWait ) ) {
811     perror("pthread_mutex_lock _NewThread") ;
812     exit( 0 ) ;
813   }
814   _Threads += 1 ;
815   cdebug << "NewThread : " << _Threads << " running threads "
816          << _SuspendedThreads << " suspended threads"
817          << endl ;
818   if ( pthread_mutex_unlock( &_MutexWait ) ) {
819     perror("pthread_mutex_unlock _NewThread") ;
820     exit( 0 ) ;
821   }
822 }
823
824 void GraphExecutor::OutNode::ExitThread( pthread_t ThreadNumber ) {
825   if ( pthread_mutex_lock( &_MutexWait ) ) {
826     perror("pthread_mutex_lock _ExitThread") ;
827     exit( 0 ) ;
828   }
829   if ( ThreadNumber == 0 ) {
830     ThreadNumber = pthread_self() ;
831   }
832   _Threads -= 1 ;
833   cdebug << pthread_self() << " ExitThread( " << ThreadNumber << " ) " << _Threads << " running threads "
834          << _SuspendedThreads << " suspended threads"
835          << endl ;
836   theAutomaton->JoinThread( ThreadNumber ) ;
837   if ( pthread_cond_signal( &_JoinWait ) ) {
838     perror("ExitThread pthread_cond_signal ") ;
839   }
840   if ( pthread_mutex_unlock( &_MutexWait ) ) {
841     perror("pthread_mutex_unlock _ExitThread") ;
842     exit( 0 ) ;
843   }
844   if ( _Threads == 0 && _SuspendedThreads == 0 ) {
845     CheckAllDone() ;
846     if ( IsDone() ) {
847       theAutomaton->Executed() ;
848     }
849   }
850 }
851 void GraphExecutor::OutNode::JoinedWait() {
852   if ( pthread_mutex_lock( &_MutexWait ) ) {
853     perror("pthread_mutex_lock JoinedWait") ;
854     exit( 0 ) ;
855   }
856   while ( _Threads ) {
857     if ( pthread_cond_wait( &_JoinWait , &_MutexWait ) ) {
858       perror("JoinedWait pthread_cond_wait ") ;
859     }
860   }
861   if ( pthread_mutex_unlock( &_MutexWait ) ) {
862     perror("pthread_mutex_unlock JoinedWait") ;
863     exit( 0 ) ;
864   }
865 }
866
867 void GraphExecutor::OutNode::SuspendThread() {
868   if ( pthread_mutex_lock( &_MutexWait ) ) {
869     perror("pthread_mutex_lock _SuspendThread") ;
870     exit( 0 ) ;
871   }
872   _SuspendedThreads += 1 ;
873   cdebug << "SuspendThread : " << _Threads << " running threads "
874          << _SuspendedThreads << " suspended threads"
875          << endl ;
876   if ( pthread_mutex_unlock( &_MutexWait ) ) {
877     perror("pthread_mutex_unlock _SuspendThread") ;
878     exit( 0 ) ;
879   }
880   if ( IsSuspended() ) {
881     PushEvent( NULL , GraphExecutor::SuspendEvent , GraphExecutor::SuspendedState ) ;
882   }
883 }
884 void GraphExecutor::OutNode::ResumeThread() {
885   if ( pthread_mutex_lock( &_MutexWait ) ) {
886     perror("pthread_mutex_lock _ResumeThread") ;
887     exit( 0 ) ;
888   }
889   _SuspendedThreads -= 1 ;
890   cdebug << "ResumeThread : " << _Threads << " running threads "
891          << _SuspendedThreads << " suspended threads"
892          << endl ;
893   if ( pthread_mutex_unlock( &_MutexWait ) ) {
894     perror("pthread_mutex_unlock _ResumeThread") ;
895     exit( 0 ) ;
896   }
897 }
898
899 long GraphExecutor::OutNode::Thread( const char * aNodeName ) {
900   long RetVal = 0 ;
901   GraphExecutor::InNode *anInNode = (GraphExecutor::InNode *) Graph()->GetGraphNode( aNodeName )->GetInNode() ;
902   if ( anInNode ) {
903     RetVal = anInNode->ThreadNo() ;
904   }
905   return RetVal ;
906 }
907
908 SUPERV::GraphEvent GraphExecutor::OutNode::AutomatonGraphEvent(GraphExecutor::NodeEvent anEvent ) {
909   SUPERV::GraphEvent aGraphEvent ;
910   switch ( anEvent ) {
911   case GraphExecutor::UndefinedEvent : {
912     aGraphEvent = SUPERV::UndefinedEvent ;
913     break ;
914   }
915   case GraphExecutor::NewThreadEvent : {
916     aGraphEvent = SUPERV::NewThreadEvent ;
917     break ;
918   }
919   case GraphExecutor::SuspendEvent : {
920     aGraphEvent = SUPERV::SuspendEvent ;
921     break ;
922   }
923   case GraphExecutor::ResumeEvent : {
924     aGraphEvent = SUPERV::ResumeEvent ;
925     break ;
926   }
927   case GraphExecutor::KillEvent : {
928     aGraphEvent = SUPERV::KillEvent ;
929     break ;
930   }
931   case GraphExecutor::StopEvent : {
932     aGraphEvent = SUPERV::StopEvent ;
933     break ;
934   }
935   case GraphExecutor::ExecuteEvent : {
936     aGraphEvent = SUPERV::RunningEvent ;
937     break ;
938   }
939   case GraphExecutor::SuccessEvent : {
940     aGraphEvent = SUPERV::DoneEvent ;
941     break ;
942   }
943   case GraphExecutor::ErrorEvent : {
944     aGraphEvent = SUPERV::ErroredEvent ;
945     break ;
946   }
947   case GraphExecutor::ReStartEvent : {
948     aGraphEvent = SUPERV::ReRunEvent ;
949     break ;
950   }
951   case GraphExecutor::ReStartAndSuspendEvent : {
952     aGraphEvent = SUPERV::ReStartEvent ;
953     break ;
954   }
955   case GraphExecutor::NoDataReadyEvent : {
956     aGraphEvent = SUPERV::WaitingEvent ;
957     break ;
958   }
959   case GraphExecutor::SomeDataReadyEvent : {
960     aGraphEvent = SUPERV::WaitingEvent ;
961     break ;
962   }
963   case GraphExecutor::NotAllDataReadyEvent : {
964     aGraphEvent = SUPERV::WaitingEvent ;
965     break ;
966   }
967   case GraphExecutor::AllDataReadyEvent : {
968     aGraphEvent = SUPERV::ReadyEvent ;
969     break ;
970   }
971   case GraphExecutor::ReadyEvent : {
972     aGraphEvent = SUPERV::ReadyEvent ;
973     break ;
974   }
975   case GraphExecutor::SuspendedReadyEvent : {
976     aGraphEvent = SUPERV::SuspendEvent ;
977     break ;
978   }
979   case GraphExecutor::ResumedReadyEvent : {
980     aGraphEvent = SUPERV::ResumeEvent ;
981     break ;
982   }
983   case GraphExecutor::KilledReadyEvent : {
984     aGraphEvent = SUPERV::KillEvent ;
985     break ;
986   }
987   case GraphExecutor::StoppedReadyEvent : {
988     aGraphEvent = SUPERV::StopEvent ;
989     break ;
990   }
991   case GraphExecutor::ExecutingEvent : {
992     aGraphEvent = SUPERV::RunningEvent ;
993     break ;
994   }
995   case GraphExecutor::SuspendedExecutingEvent : {
996     aGraphEvent = SUPERV::SuspendEvent ;
997     break ;
998   }
999   case GraphExecutor::ResumedExecutingEvent : {
1000     aGraphEvent = SUPERV::ResumeEvent ;
1001     break ;
1002   }
1003   case GraphExecutor::KilledExecutingEvent : {
1004     aGraphEvent = SUPERV::KillEvent ;
1005     break ;
1006   }
1007   case GraphExecutor::StoppedExecutingEvent : {
1008     aGraphEvent = SUPERV::StopEvent ;
1009     break ;
1010   }
1011   case GraphExecutor::SuccessedExecutingEvent : {
1012     aGraphEvent = SUPERV::DoneEvent ;
1013     break ;
1014   }
1015   case GraphExecutor::ErroredExecutingEvent : {
1016     aGraphEvent = SUPERV:: ErroredEvent;
1017     break ;
1018   }
1019   case GraphExecutor::SuspendedSuccessedEvent : {
1020     aGraphEvent = SUPERV::SuspendEvent ;
1021     break ;
1022   }
1023   case GraphExecutor::SuspendedErroredEvent : {
1024     aGraphEvent = SUPERV::SuspendEvent ;
1025     break ;
1026   }
1027   case GraphExecutor::ResumedSuccessedEvent : {
1028     aGraphEvent = SUPERV::ResumeEvent ;
1029     break ;
1030   }
1031   case GraphExecutor::ResumedErroredEvent : {
1032     aGraphEvent = SUPERV::ResumeEvent ;
1033     break ;
1034   }
1035   case GraphExecutor::KilledEvent : {
1036     aGraphEvent = SUPERV::KillEvent ;
1037     break ;
1038   }
1039   case GraphExecutor::StoppedEvent : {
1040     aGraphEvent = SUPERV::StopEvent ;
1041     break ;
1042   }
1043   case GraphExecutor::ReStartedEvent : {
1044     aGraphEvent = SUPERV::ReRunEvent ;
1045     break ;
1046   }
1047   case GraphExecutor::ReStartedAndSuspendEvent : {
1048     aGraphEvent = SUPERV::ReStartEvent ;
1049     break ;
1050   }
1051   case GraphExecutor::EndExecuteEvent : {
1052     aGraphEvent = SUPERV::DoneEvent ;
1053     break ;
1054   }
1055   default : {
1056     cdebug << " GraphExecutor::OutNode::AutomatonGraphEvent Error Undefined Event : "
1057            << anEvent << endl ;
1058     aGraphEvent = SUPERV::UndefinedEvent ;
1059   }
1060   }
1061   return aGraphEvent ;
1062 }
1063
1064 SUPERV::GraphState GraphExecutor::OutNode::AutomatonGraphState(GraphExecutor::AutomatonState aState ) {
1065   SUPERV::GraphState aGraphState ;
1066   switch ( aState ) {
1067   case GraphExecutor::UnKnownState : {
1068     aGraphState = SUPERV::UndefinedState ;
1069     break ;
1070   }
1071   case GraphExecutor::DataUndefState : {
1072     aGraphState = SUPERV::UndefinedState ;
1073     break ;
1074   }
1075   case GraphExecutor::DataWaitingState : {
1076     aGraphState = SUPERV::WaitingState ;
1077     break ;
1078   }
1079   case GraphExecutor::DataReadyState : {
1080     aGraphState = SUPERV::ReadyState ;
1081     break ;
1082   }
1083   case GraphExecutor::SuspendedReadyState : {
1084     aGraphState = SUPERV::SuspendReadyState ;
1085     break ;
1086   }
1087   case GraphExecutor::ResumedReadyState : {
1088     aGraphState = SUPERV::ReadyState ;
1089     break ;
1090   }
1091   case GraphExecutor::KilledReadyState : {
1092     aGraphState = SUPERV::KillState ;
1093     break ;
1094   }
1095   case GraphExecutor::StoppedReadyState : {
1096     aGraphState = SUPERV::StopState ;
1097     break ;
1098   }
1099   case GraphExecutor::ExecutingState : {
1100     aGraphState = SUPERV::RunningState ;
1101     break ;
1102   }
1103   case GraphExecutor::SuspendedExecutingState : {
1104     aGraphState = SUPERV::SuspendState ;
1105     break ;
1106   }
1107   case GraphExecutor::ResumedExecutingState : {
1108     aGraphState = SUPERV::RunningState ;
1109     break ;
1110   }
1111   case GraphExecutor::KilledExecutingState : {
1112     aGraphState = SUPERV::KillState ;
1113     break ;
1114   }
1115   case GraphExecutor::StoppedExecutingState : {
1116     aGraphState = SUPERV::StopState ;
1117     break ;
1118   }
1119   case GraphExecutor::SuccessedExecutingState : {
1120     aGraphState = SUPERV::DoneState ;
1121     break ;
1122   }
1123   case GraphExecutor::ErroredExecutingState : {
1124     aGraphState = SUPERV::ErrorState ;
1125     break ;
1126   }
1127   case GraphExecutor::SuspendedSuccessedState : {
1128     aGraphState = SUPERV::SuspendDoneState ;
1129     break ;
1130   }
1131   case GraphExecutor::SuspendedErroredState : {
1132     aGraphState = SUPERV::SuspendErroredState ;
1133     break ;
1134   }
1135   case GraphExecutor::ResumedSuccessedState : {
1136     aGraphState = SUPERV::DoneState ;
1137     break ;
1138   }
1139   case GraphExecutor::ResumedErroredState : {
1140     aGraphState = SUPERV::ErrorState ;
1141     break ;
1142   }
1143   case GraphExecutor::KilledSuccessedState : {
1144     aGraphState = SUPERV::KillState ;
1145     break ;
1146   }
1147   case GraphExecutor::KilledErroredState : {
1148     aGraphState = SUPERV::KillState ;
1149     break ;
1150   }
1151   case GraphExecutor::StoppedSuccessedState : {
1152     aGraphState = SUPERV::StopState ;
1153     break ;
1154   }
1155   case GraphExecutor::StoppedErroredState : {
1156     aGraphState = SUPERV::StopState ;
1157     break ;
1158   }
1159   case GraphExecutor::SuccessedState : {
1160     aGraphState = SUPERV::DoneState ;
1161     break ;
1162   }
1163   case GraphExecutor::ErroredState : {
1164     aGraphState = SUPERV::ErrorState ;
1165     break ;
1166   }
1167   case GraphExecutor::SuspendedState : {
1168     aGraphState = SUPERV::SuspendState ;
1169     break ;
1170   }
1171   case GraphExecutor::KilledState : {
1172     aGraphState = SUPERV::KillState ;
1173     break ;
1174   }
1175   case GraphExecutor::StoppedState : {
1176     aGraphState = SUPERV::StopState ;
1177     break ;
1178   }
1179   case GraphExecutor::ReRunnedState : {
1180     aGraphState = SUPERV::ReRunState ;
1181     break ;
1182   }
1183   case GraphExecutor::ReStartedState : {
1184     aGraphState = SUPERV::ReStartState ;
1185     break ;
1186   }
1187   case GraphExecutor::LoadingState : {
1188     aGraphState = SUPERV::LoadingState ;
1189     break;
1190   }
1191   default : {
1192     cdebug << " GraphExecutor::OutNode::AutomatonGraphState Error Undefined State : "
1193            << aGraphState << endl ;
1194     aGraphState = SUPERV::UndefinedState ;
1195   }
1196   }
1197   return aGraphState ;
1198 }
1199
1200 int GraphExecutor::OutNode::GetListSize() {
1201   return _EventNodes.size();
1202 }
1203
1204 bool GraphExecutor::OutNode::PushEvent( GraphExecutor::InNode * aNode ,
1205                                         GraphExecutor::NodeEvent anEvent ,
1206                                         GraphExecutor::AutomatonState aState ) {
1207 //  cdebug_in << "PushEvent Threads " << Threads() << " SuspendedThreads "
1208 //            << SuspendedThreads() << endl ;
1209   if ( pthread_mutex_lock( &_MutexWait ) ) {
1210     perror("PushEvent pthread_mutex_lock ") ;
1211     exit( 0 ) ;
1212   }
1213   char* aNodeName = aNode ? aNode->Name() : Graph()->Name() ;
1214   _EventNodes.push_back( aNodeName ) ;
1215   _Events.push_back( anEvent ) ;
1216   _States.push_back( aState ) ;
1217
1218   pthread_cond_broadcast( &_EventWait );
1219   cdebug << pthread_self() << " PushEvent Threads " << Threads() << " SuspendedThreads "
1220          << SuspendedThreads() << " pthread_cond_broadcast _EventWait " << &_EventWait << endl ;
1221   if ( aNode ) {
1222 //    cdebug << aNode->ThreadNo() << " PushEvent " << aNode->Name() ;
1223 //    cdebug << " " << aNode->Automaton()->EventName( anEvent )
1224 //           << " " << aNode->Automaton()->StateName( aState )
1225 //           << " ControleState "
1226 //           << aNode->Automaton()->ControlStateName( aNode->ControlState() ) ;
1227   }
1228   else {
1229 //    cdebug << "PushEvent " << Graph()->Name() ;
1230 //    cdebug << " " << theAutomaton->EventName( anEvent ) << " "
1231 //           << theAutomaton->StateName( aState ) ;
1232   }
1233 //  cdebug_out << "PushEvent Threads " << Threads() << " SuspendedThreads "
1234 //             << SuspendedThreads() << endl ;
1235 #if 0
1236   if ( _EventNodes.size() > 101 ) {
1237     while ( _EventNodes.size() > 31 ) {
1238       _EventNodes.pop_front() ;
1239       _Events.pop_front() ;
1240       _States.pop_front() ;
1241     }
1242   }
1243 #endif
1244   if ( pthread_mutex_unlock( &_MutexWait ) ) {
1245     perror("PushEvent pthread_mutex_unlock ") ;
1246     exit( 0 ) ;
1247   }
1248   return true ;
1249 }
1250
1251 bool GraphExecutor::OutNode::StateWait( SUPERV::GraphState aState ) {
1252   return false ;
1253 }
1254
1255 bool GraphExecutor::OutNode::Event( char ** aNodeName ,
1256                                     SUPERV::GraphEvent & anEvent ,
1257                                     SUPERV::GraphState & aState ,
1258                                     bool WithWait ) {
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   if ( _EventNodes.size() > (unsigned int)Graph()->GraphNodesSize()*7 )
1264     siftEvents();
1265
1266   int ThreadsNumber ;
1267   int SuspendedThreadsNumber ;
1268   bool cdebuginout = false ;
1269   if ( _EventNodes.size() > 0 ) {
1270 //    cdebug_in << "GraphExecutor::OutNode::Event " << _EventNodes.size() << " in queue" << endl ;
1271     cdebuginout = true ;
1272   }
1273   if ( pthread_mutex_lock( &_MutexWait ) ) {
1274     perror("EventLoop pthread_mutex_lock ") ;
1275     exit( 0 ) ;
1276   }
1277   _JustStarted = false ;
1278   ThreadsNumber = Threads() ;
1279   SuspendedThreadsNumber = SuspendedThreads() ;
1280   bool RetVal = ( ThreadsNumber - SuspendedThreadsNumber) != 0 ||
1281                 _EventNodes.size() > 0 ;
1282   char * NodeName = "" ;
1283   GraphExecutor::NodeEvent theEvent = GraphExecutor::UndefinedEvent ;
1284   GraphExecutor::AutomatonState theState = GraphExecutor::UnKnownState ;
1285   anEvent = SUPERV::UndefinedEvent ;
1286   aState = SUPERV::UndefinedState ;
1287   if ( ( Done() || IsKilled() || IsStopped() ) && _EventNodes.size() == 0 ) {
1288 //    cdebug << "EventLoop Done()/IsKilled()/IsStopped() && _EventNodes.size() == 0" << endl ;
1289     RetVal = false ;
1290   }
1291   else if ( !WithWait && _EventNodes.size() == 0 ) {
1292     anEvent = SUPERV::NoEvent ;
1293     aState = SUPERV::NoState ;
1294     RetVal = true ;
1295   }
1296   else if ( RetVal ) {
1297     while ( !IsSuspended() && _EventNodes.size() == 0 ) {
1298 //      cdebug << "EventLoop pthread_cond_wait _EventWait" << endl ;
1299       pthread_cond_wait( &_EventWait , &_MutexWait );
1300 //      cdebug << "EventLoop pthread_cond_waited _EventWait"
1301 //             << " _EventNodes.size() " << _EventNodes.size() << endl ;
1302     }
1303     if ( _EventNodes.size() ) {
1304       ThreadsNumber = Threads() ;
1305       NodeName = _EventNodes.front() ;
1306       _EventNodes.pop_front() ;
1307       theEvent = _Events.front() ;
1308       anEvent = AutomatonGraphEvent( theEvent ) ;
1309       _Events.pop_front() ;
1310       theState = _States.front() ;
1311       aState = AutomatonGraphState( theState ) ;
1312       _States.pop_front() ;
1313     }
1314   }
1315   *aNodeName = NodeName ;
1316   if ( IsSuspended() && _EventNodes.size() == 0 ) {
1317     RetVal = false ;
1318   }
1319   if ( anEvent != SUPERV::NoEvent ) {
1320 //    cdebug << pthread_self() << "EventLoop "
1321 //           << NodeName << " " << theAutomaton->StateName( theState )
1322 //           << " _EventNodes.size() " << _EventNodes.size()
1323 //           << " Threads " << Threads() << " SuspendedThreads "
1324 //           << SuspendedThreads() << " RetVal " << RetVal << endl ;
1325   }
1326   if ( pthread_mutex_unlock( &_MutexWait ) ) {
1327     perror("EventLoop pthread_mutex_lock ") ;
1328     exit( 0 ) ;
1329   }
1330   if ( cdebuginout ) {
1331 //    cdebug_out << "GraphExecutor::OutNode::Event " << _EventNodes.size() << " in queue"
1332 //               << *aNodeName << " " << anEvent << " " << aState << endl ;
1333   }
1334   return RetVal ;
1335 }
1336
1337 bool GraphExecutor::OutNode::EventW( char ** aNodeName ,
1338                                      SUPERV::GraphEvent & anEvent ,
1339                                      SUPERV::GraphState & aState ) {
1340   bool sts = true ;
1341   char * NodeName ;
1342   aState = SUPERV::UndefinedState ;
1343   while ( sts &&
1344           aState != SUPERV::SuspendReadyState &&
1345           aState != SUPERV::RunningState &&
1346           aState != SUPERV::SuspendDoneState &&
1347           aState != SUPERV::SuspendErroredState ) {
1348     NodeName = Graph()->Name() ;
1349     while ( sts && !strcmp( NodeName , Graph()->Name() ) ) {
1350       sts = EventWait( aNodeName , anEvent , aState ) ;
1351       NodeName = *aNodeName ;
1352     }
1353   }
1354   return sts ;
1355 }
1356
1357 bool GraphExecutor::OutNode::EventWait( char ** aNodeName ,
1358                                         SUPERV::GraphEvent & anEvent ,
1359                                         SUPERV::GraphState & aState ) {
1360   if ( pthread_mutex_lock( &_MutexWait ) ) {
1361     perror("EventW pthread_mutex_lock ") ;
1362     exit( 0 ) ;
1363   }
1364   int ThreadsNumber ;
1365   int SuspendedThreadsNumber ;
1366   ThreadsNumber = Threads() ;
1367   SuspendedThreadsNumber = SuspendedThreads() ;
1368   bool RetVal = ( ThreadsNumber - SuspendedThreadsNumber) != 0 ||
1369                 _EventNodes.size() > 0 ;
1370   cdebug << "--> EventW RetVal " << RetVal << endl ;
1371   char * NodeName = "" ;
1372   GraphExecutor::NodeEvent theEvent = GraphExecutor::UndefinedEvent ;
1373   GraphExecutor::AutomatonState theState = GraphExecutor::UnKnownState ;
1374   anEvent = SUPERV::UndefinedEvent ;
1375   aState = SUPERV::UndefinedState ;
1376   if ( IsDone() && _EventNodes.size() == 0 ) {
1377     cdebug << "EventW IsDone() && _EventNodes.size() == 0" << endl ;
1378     RetVal = 0 ;
1379   }
1380   else if ( RetVal ) {
1381     GraphExecutor::InNode * aNode = NULL ;
1382     while ( aNode == NULL && RetVal ) {
1383       NodeName = _EventNodes.front() ;
1384       theEvent = _Events.front() ;
1385       anEvent = AutomatonGraphEvent( theEvent ) ;
1386       theState = _States.front() ;
1387       aState = AutomatonGraphState( theState ) ;
1388
1389       if ( _JustStarted ) {
1390         _JustStarted = false ;
1391       }
1392       else {
1393         _EventNodes.pop_front() ;
1394         _Events.pop_front() ;
1395         _States.pop_front() ;
1396       }
1397
1398       aNode = ((GraphExecutor::InNode *) Graph()->GetGraphNode( NodeName )->GetInNode()) ;
1399       cdebug << "EventW Previous Node " << NodeName << " ThreadsNumber "
1400              << ThreadsNumber
1401              << " _EventNodes.size() " << _EventNodes.size() << " "
1402              << theAutomaton->StateName( theState )
1403              << " Threads " << Threads() << " SuspendedThreads "
1404              << SuspendedThreads() << endl ;
1405       if ( aNode ) {
1406       }
1407       else if ( IsDone() && _EventNodes.size() == 0 ) {
1408         cdebug << "EventW IsDone() && _EventNodes.size() == 0" << endl ;
1409         RetVal = 0 ;
1410       }
1411       else {
1412         cdebug << "EventW Not InNode " << NodeName
1413                << " _EventNodes.size() " << _EventNodes.size() << endl ;
1414         while ( _EventNodes.size() == 0 ) {
1415           pthread_cond_wait( &_EventWait , &_MutexWait );
1416         }
1417         cdebug << "EventW pthread_cond_waited Not InNode " << NodeName
1418                << " _EventNodes.size() " << _EventNodes.size() << endl ;
1419       }
1420     }
1421
1422     if ( aNode ) {
1423       if ( aState == SUPERV::SuspendState ||
1424            aState == SUPERV::SuspendReadyState ||
1425            aState == SUPERV::SuspendDoneState ||
1426            aState == SUPERV::SuspendErroredState ) {
1427         aNode->ControlState( SUPERV::ToSuspendState ) ;
1428         if ( aNode->IsSuspended() ) {
1429           if ( pthread_mutex_unlock( &_MutexWait ) ) {
1430             perror("EventW pthread_mutex_lock ") ;
1431             exit( 0 ) ;
1432           }
1433           cdebug << "EventW " << aNode->Name() << " ResumeAction" << endl ;
1434           aNode->ResumeAction( GraphExecutor::ToResumeEvent ) ;
1435           cdebug << "EventW " << aNode->Name() << " ResumedAction" << endl ;
1436           if ( pthread_mutex_lock( &_MutexWait ) ) {
1437             perror("EventW pthread_mutex_lock ") ;
1438             exit( 0 ) ;
1439           }
1440         }
1441         else {
1442           cdebug << "EventW inconsistent SuspendState" << endl ;
1443           RetVal = false ; 
1444         }
1445       }
1446       else {
1447         if ( aNode->IsDone() ) {
1448           RetVal = true ;
1449         }
1450         else {
1451           cdebug << "EventW NOT SuspendedState _EventNodes.size() "
1452                  << _EventNodes.size() << endl ;
1453           RetVal = true ;
1454         }
1455       }
1456       if ( RetVal ) {
1457         cdebug << "EventW " << aNode->Name() << " pthread_cond_wait" << endl ;
1458         while ( _EventNodes.size() == 0 ) {
1459           pthread_cond_wait( &_EventWait , &_MutexWait );
1460         }
1461         ThreadsNumber = Threads() ;
1462         NodeName = _EventNodes.front() ;
1463         theEvent = _Events.front() ;
1464         anEvent = AutomatonGraphEvent( theEvent ) ;
1465         theState = _States.front() ;
1466         aState = AutomatonGraphState( theState ) ;
1467       }
1468     }
1469   }
1470   *aNodeName = NodeName ;
1471   cdebug << "<-- EventW RetVal " << RetVal << " " << NodeName
1472          << " Threads " << Threads() << " SuspendedThreads "
1473          << SuspendedThreads()
1474          << " _EventNodes.size() " << _EventNodes.size()
1475          << " " << theAutomaton->EventName( theEvent ) << " "
1476          << theAutomaton->StateName( theState ) << endl ;
1477   if ( pthread_mutex_unlock( &_MutexWait ) ) {
1478     perror("EventW pthread_mutex_lock ") ;
1479     exit( 0 ) ;
1480   }
1481   return RetVal ;
1482 }
1483 long GraphExecutor::OutNode::EventQSize() {
1484   return _EventNodes.size() ;
1485 }
1486
1487 void GraphExecutor::OutNode::EventList() {
1488   if ( pthread_mutex_lock( &_MutexWait ) ) {
1489     perror("EventList pthread_mutex_lock ") ;
1490     exit( 0 ) ;
1491   }
1492   list< char * >::iterator itEventNodes = _EventNodes.begin() ;
1493   list< GraphExecutor::NodeEvent >::iterator itEvents = _Events.begin() ;
1494   list< GraphExecutor::AutomatonState >::iterator itStates = _States.begin() ;
1495   while ( itEventNodes != _EventNodes.end() ) {
1496     cdebug << pthread_self() << "EVENTSTACK "
1497            << *itEventNodes << " " << *itEvents << " "
1498            << theAutomaton->StateName( *itStates )
1499            << " Threads " << Threads() << " SuspendedThreads " << SuspendedThreads() << endl ;
1500     itEventNodes++ ;
1501     itEvents++ ;
1502     itStates++ ;
1503   }
1504   if ( pthread_mutex_unlock( &_MutexWait ) ) {
1505     perror("EventList pthread_mutex_lock ") ;
1506     exit( 0 ) ;
1507   }
1508 }
1509
1510 void GraphExecutor::OutNode::SendSomeDataReady( const char * aNodeName ) {
1511   cdebug_in << "GraphExecutor::OutNode::SendSomeDataReady " << aNodeName << "->SendSomeDataReady( "
1512             << Graph()->Name() << " )" << endl;
1513   int sts ;
1514   sts = ((GraphExecutor::InNode * ) Graph()->GetChangeGraphNode( aNodeName )->GetInNode())->SendSomeDataReady( Graph()->Name() ) ;
1515   cdebug_out << "GraphExecutor::OutNode::SendSomeDataReady sts " << sts << endl ;
1516 }
1517
1518 void GraphExecutor::OutNode::State(GraphExecutor::AutomatonState aState ) {
1519 //  cdebug << "GraphExecutor::OutNode::State " << Graph()->Name() << " "
1520 //         << theAutomaton->StateName( AutomatonGraphState( _State ) ) << " ---> "
1521 //         << theAutomaton->StateName( AutomatonGraphState( aState ) ) << endl ;
1522   _State = aState ;
1523 }
1524
1525 SUPERV::GraphState GraphExecutor::OutNode::State() {
1526 //  cdebug_in << "GraphExecutor::OutNode::State" << endl;
1527 //  cdebug_out << "GraphExecutor::OutNode::State" << endl ;
1528 //  cdebug << "GraphExecutor::OutNode::State GraphState "
1529 //         << theAutomaton->StateName( AutomatonGraphState( _State ) ) << endl ;
1530   return AutomatonGraphState( _State ) ;
1531 }
1532
1533 SUPERV::GraphState GraphExecutor::OutNode::State( const char * NodeName ) {
1534 //  cdebug_in << "GraphExecutor::OutNode::State " << NodeName << endl;
1535   GraphExecutor::AutomatonState aret = GraphExecutor::UnKnownState ;
1536   const GraphBase::ComputingNode * aCNode =  Graph()->GetGraphNode( NodeName ) ;
1537   if ( aCNode ) {
1538     GraphExecutor::InNode *anInNode = (GraphExecutor::InNode *)aCNode->GetInNode() ;
1539     if ( anInNode ) {
1540       if ( anInNode->IsLoading() )
1541         aret = GraphExecutor::LoadingState;
1542       else
1543         aret = anInNode->State() ;
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::IsDone( 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 ) {
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   // remove "extra" events from the event queue
1926   siftEvents();
1927
1928   // asv : 25.10.04 : calling Editing() to indicate stop of execution
1929   Graph()->GraphEditor()->Editing();
1930
1931   return RetVal ;
1932 }
1933
1934 bool GraphExecutor::OutNode::Stop() {
1935   bool RetVal = false ;
1936   cdebug_in << "GraphExecutor::OutNode::Stop" << endl;
1937   RetVal = Kill() ;
1938   cdebug_out << "GraphExecutor::OutNode::Stop" << endl ;
1939   if ( RetVal ) {
1940     MESSAGE("================================================================================") ;
1941     MESSAGE( Graph()->Name() << " IS STOPPED" ) ;
1942     MESSAGE("================================================================================") ;
1943   }
1944   return RetVal ;
1945 }
1946 bool GraphExecutor::OutNode::ReRun() {
1947   bool RetVal = false ;
1948   cdebug_in << "GraphExecutor::OutNode::ReRun" << endl;
1949   if ( IsSuspended() ) {
1950   }
1951   cdebug_out << "GraphExecutor::OutNode::ReRun" << endl ;
1952   return RetVal ;
1953 }
1954 bool GraphExecutor::OutNode::ReStart() {
1955   bool RetVal = false ;
1956   cdebug_in << "GraphExecutor::OutNode::ReStart" << endl;
1957   if ( IsSuspended() ) {
1958   }
1959   cdebug_out << "GraphExecutor::OutNode::ReStart" << endl ;
1960   return RetVal ;
1961 }
1962
1963 bool GraphExecutor::OutNode::ReadyWait() {
1964   cdebug_in << "GraphExecutor::OutNode::ReadyWait" << endl;
1965   bool aret ;
1966   if ( pthread_mutex_lock( &_MutexWait ) ) {
1967     perror("pthread_mutex_lock _ReadyWait") ;
1968     exit( 0 ) ;
1969   }
1970   aret = IsReady() ;
1971   if ( !aret ) {
1972     Suspend() ;
1973     pthread_cond_wait( &_EventWait , &_MutexWait );
1974     aret = IsReady() ;
1975   }
1976   if ( pthread_mutex_unlock( &_MutexWait ) ) {
1977     perror("pthread_mutex_lock _ReadyWait") ;
1978     exit( 0 ) ;
1979   }
1980   cdebug_out << "GraphExecutor::OutNode::ReadyWait" << endl ;
1981   return aret ;
1982 }
1983
1984 bool GraphExecutor::OutNode::RunningWait() {
1985   cdebug_in << "GraphExecutor::OutNode::RunningWait" << endl;
1986   bool aret ;
1987   if ( pthread_mutex_lock( &_MutexWait ) ) {
1988     perror("pthread_mutex_lock _RunningWait") ;
1989     exit( 0 ) ;
1990   }
1991   aret = IsRunning() ;
1992   if ( !aret ) {
1993     cdebug << "RunningWait pthread_cond_wait _EventWait" << endl;
1994     pthread_cond_wait( &_EventWait , &_MutexWait );
1995     aret = IsRunning() ;
1996     cdebug << "RunningWait pthread_cond_waited _EventWait " << aret << endl;
1997   }
1998   if ( pthread_mutex_unlock( &_MutexWait ) ) {
1999     perror("pthread_mutex_lock _RunningWait") ;
2000     exit( 0 ) ;
2001   }
2002   cdebug_out << "GraphExecutor::OutNode::RunningWait " << aret << endl ;
2003   return aret ;
2004 }
2005
2006 bool GraphExecutor::OutNode::DoneWait() {
2007   cdebug_in << pthread_self() << " GraphExecutor::DoneWait " << this << " " << Graph()->Name() << endl;
2008   bool aret ;
2009   if ( pthread_mutex_lock( &_MutexWait ) ) {
2010     perror("pthread_mutex_lock _DoneWait") ;
2011     exit( 0 ) ;
2012   }
2013   aret = IsDone() ;
2014   while ( !aret && !IsSuspended() && IsRunning() ) {
2015     cdebug << pthread_self() << " GraphExecutor::DoneWait " << this << " " << Graph()->Name()
2016            << " DoneWait pthread_cond_wait _EventWait " << &_EventWait << endl;
2017     pthread_cond_wait( &_EventWait , &_MutexWait );
2018     aret = IsDone() ;
2019     cdebug << pthread_self() << " GraphExecutor::DoneWait " << this << " " << Graph()->Name()
2020            << " DoneWait pthread_cond_waited _EventWaited " << &_EventWait << " : "<< aret << endl;
2021   }
2022   if ( pthread_mutex_unlock( &_MutexWait ) ) {
2023     perror("pthread_mutex_lock _DoneWait") ;
2024     exit( 0 ) ;
2025   }
2026   cdebug_out << pthread_self() << " GraphExecutor::DoneWait " << this << " " << Graph()->Name()
2027              << " " << State() << " : " << aret << endl ;
2028   return aret ;
2029 }
2030
2031 bool GraphExecutor::OutNode::SuspendedWait() {
2032   cdebug_in << "GraphExecutor::OutNode::SuspendedWait" << endl;
2033   bool aret ;
2034   if ( pthread_mutex_lock( &_MutexWait ) ) {
2035     perror("pthread_mutex_lock _SuspendedWait") ;
2036     exit( 0 ) ;
2037   }
2038   aret = IsSuspended() ;
2039   while ( !aret && !IsDone() ) {
2040     pthread_cond_wait( &_EventWait , &_MutexWait );
2041     aret = IsSuspended() ;
2042   }
2043   if ( pthread_mutex_unlock( &_MutexWait ) ) {
2044     perror("pthread_mutex_lock _SuspendedWait") ;
2045     exit( 0 ) ;
2046   }
2047   cdebug_out << "GraphExecutor::OutNode::SuspendedWait" << endl ;
2048   return aret ;
2049 }
2050
2051 bool GraphExecutor::OutNode::ReadyWait( const char * NodeName ) {
2052   bool aret = false ;
2053   cdebug_in << "GraphExecutor::OutNode::ReadyWait " << NodeName << endl;
2054   GraphExecutor::InNode *anInNode = (GraphExecutor::InNode *) Graph()->GetGraphNode( NodeName )->GetInNode() ;
2055   if ( anInNode ) {
2056     aret = anInNode->ReadyWait() ;
2057   }
2058   cdebug_out << "GraphExecutor::OutNode::ReadyWait" << endl ;
2059   return aret ;
2060 }
2061
2062 bool GraphExecutor::OutNode::RunningWait( const char * NodeName ) {
2063   bool aret = false ;
2064   cdebug_in << "GraphExecutor::OutNode::RunningWait " << NodeName << endl;
2065   GraphExecutor::InNode *anInNode = (GraphExecutor::InNode *) Graph()->GetGraphNode( NodeName )->GetInNode() ;
2066   if ( anInNode ) {
2067     aret = anInNode->RunningWait() ;
2068   }
2069   cdebug_out << "GraphExecutor::OutNode::RunningWait" << endl ;
2070   return aret ;
2071 }
2072
2073 bool GraphExecutor::OutNode::DoneWait( const char * NodeName ) {
2074   bool aret = false ;
2075   cdebug_in << "GraphExecutor::OutNode::DoneWait " << NodeName << endl;
2076   GraphExecutor::InNode *anInNode = (GraphExecutor::InNode *) Graph()->GetGraphNode( NodeName )->GetInNode() ;
2077   if ( anInNode ) {
2078     aret = anInNode->DoneWait() ;
2079   }
2080   cdebug_out << "GraphExecutor::OutNode::DoneWait" << endl ;
2081   return aret ;
2082 }
2083
2084 bool GraphExecutor::OutNode::SuspendedWait( const char * NodeName ) {
2085   bool aret = false ;
2086   cdebug_in << "GraphExecutor::OutNode::SuspendedWait " << NodeName << endl;
2087   GraphExecutor::InNode *anInNode = (GraphExecutor::InNode *) Graph()->GetGraphNode( NodeName )->GetInNode() ;
2088   if ( anInNode ) {
2089     aret = anInNode->SuspendedWait() ;
2090   }
2091   cdebug_out << "GraphExecutor::OutNode::SuspendedWait" << endl ;
2092   return aret ;
2093 }
2094
2095 long GraphExecutor::OutNode::LastLevelDone() {
2096   int RetVal = -1 ;
2097   int i , j ;
2098   for ( i = 0 ; i <= Graph()->LevelMax() ; i++ ) {
2099     for ( j = 0 ; j <= Graph()->NodesNumber( i ) ; j++ ) {
2100       GraphBase::ComputingNode * aNode = Graph()->SortedNodes( i , j ) ;
2101       if ( !IsDone( aNode->Name() ) ) {
2102         break ;
2103       }
2104     }
2105     if ( j != Graph()->NodesNumber( i ) + 1 )
2106       break ;
2107     RetVal = i ;
2108   }
2109   return RetVal ;
2110 }
2111
2112
2113 const CORBA::Any *GraphExecutor::OutNode::GetInData( const char * NodeName ,
2114                                                      const char * ServiceParameterName ) {
2115 //  cdebug_in << "GraphExecutor::OutNode::GetInData " << NodeName << " "
2116 //            << ServiceParameterName << endl ;
2117   const CORBA::Any * retdata = Graph()->PortInData( NodeName , ServiceParameterName ) ;
2118 //  cdebug_out << "GraphExecutor::OutNode::GetInData" << endl ;
2119   return retdata ;
2120 }
2121
2122 const CORBA::Any *GraphExecutor::OutNode::GetOutData( const char * NodeName ,
2123                                                       const char * ServiceParameterName ) {
2124 //  cdebug_in << "GraphExecutor::OutNode::GetOutData " << NodeName << " "
2125 //            << ServiceParameterName << endl ;
2126   const CORBA::Any * retdata = Graph()->PortOutData( NodeName , ServiceParameterName ) ;
2127 //  cdebug_out << "GraphExecutor::OutNode::GetOutData" << endl ;
2128   return retdata ;
2129 }
2130
2131 const long GraphExecutor::OutNode::CpuUsed() {
2132   return Graph()->CpuUsed() ;
2133 }
2134
2135 const long GraphExecutor::OutNode::CpuUsed( const char * aNodeName ) {
2136   GraphBase::ComputingNode * aNode = Graph()->GetChangeGraphNode( aNodeName ) ;
2137   if ( aNode ) {
2138     GraphExecutor::InNode * anInNode = (GraphExecutor::InNode * ) aNode->GetInNode() ;
2139     if ( anInNode ) {
2140       return anInNode->CpuUsed() ;
2141     }
2142   }
2143   return 0 ;
2144 }
2145
2146 // remove equal sets "Node-Event-State" from _EventNodes/_Events/_States queues
2147 void GraphExecutor::OutNode::siftEvents() {
2148   list<char*>::reverse_iterator itNodes = _EventNodes.rbegin();
2149   list<GraphExecutor::NodeEvent>::reverse_iterator itEvents = _Events.rbegin();
2150   list<GraphExecutor::AutomatonState>::reverse_iterator itStates = _States.rbegin();
2151   list<char*> _NewEventNodes;
2152   list<GraphExecutor::NodeEvent> _NewEvents;
2153   list<GraphExecutor::AutomatonState> _NewStates;
2154   for ( ; itNodes != _EventNodes.rend() ; ++itNodes, ++itEvents, ++itStates) {
2155     //cout << "----- aNodeName ==> " << *itNodes;
2156     list<char*>::reverse_iterator itNewNodes = _NewEventNodes.rbegin();
2157     bool found = false;
2158     for ( ; itNewNodes != _NewEventNodes.rend() ; ++itNewNodes ) {
2159       if ( !strcmp( *itNewNodes, *itNodes ) ) {
2160         found = true;
2161         break;
2162       }
2163     }
2164
2165     if ( found ) {
2166       //cout << "   FOUND";
2167     }
2168     else {
2169       _NewEventNodes.push_back( *itNodes );
2170       _NewEvents.push_back( *itEvents );
2171       _NewStates.push_back( *itStates );
2172     }
2173     //cout << endl;
2174   }
2175   _EventNodes = _NewEventNodes;
2176   _Events = _NewEvents;
2177   _States = _NewStates;
2178 }