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