]> SALOME platform Git repositories - modules/superv.git/blob - src/GraphExecutor/DataFlowExecutor_OutNode.cxx
Salome HOME
*** empty log message ***
[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 "Graph_Impl.hxx"
34
35 // Implementation de la classe GraphEditor::GraphControl
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   _Valid = false ;
47   _Executable = false ;
48   _Done = false ;
49   _Threads = 0 ;
50   _ControlState = SUPERV::VoidState ;
51   _State = SUPERV::UnKnownState ;
52   _PyInitialized = false ;
53   pthread_mutex_init( &_MutexWait , NULL ) ;
54   pthread_mutex_init( &_PyMutexWait , NULL ) ;
55   if ( pthread_cond_init( &_EventWait , NULL ) ) {
56     perror("pthread_cond_init( &_EventWait , NULL )") ;
57     exit( 0 ) ;
58   }
59   if ( pthread_cond_init( &_JoinWait , NULL ) ) {
60     perror("pthread_cond_init( &_JoinWait , NULL )") ;
61     exit( 0 ) ;
62   }
63 }
64
65 GraphExecutor::OutNode::OutNode( CORBA::ORB_ptr ORB, 
66                                  SALOME_NamingService* ptrNamingService ,
67                                  const char *DataFlowName ,
68                                  const char * DebugFileName ,
69                                  const SUPERV::KindOfNode aKindOfNode ) {
70 //               Graph( ORB , ptrNamingService , DataFlowName , DebugFileName ) {
71   Set_prof_debug( ORB , DebugFileName ) ;
72   cdebug_in << "GraphEditor::OutNode::OutNode(" << DataFlowName << " , " << aKindOfNode << ")" << endl;
73   if ( aKindOfNode == SUPERV::DataFlowGraph ) {
74     _StreamGraph = NULL ;
75 //    _Graph = new GraphBase::Graph( ORB , ptrNamingService , DataFlowName , DebugFileName ) ;
76     _Graph = new GraphBase::Graph( ORB , ptrNamingService , DataFlowName ,
77                                    _prof_debug , _fdebug ) ;
78   }
79   else if ( aKindOfNode == SUPERV::DataStreamGraph ) {
80 //    _StreamGraph = new GraphBase::StreamGraph( ORB , ptrNamingService , DataFlowName , DebugFileName ) ;;
81     _StreamGraph = new GraphBase::StreamGraph( ORB , ptrNamingService , DataFlowName ,
82                                                _prof_debug , _fdebug ) ;
83     _Graph = _StreamGraph ;
84   }
85   _Valid = false ;
86   _Executable = false ;
87   _Done = false ;
88   _Threads = 0 ;
89   _ControlState = SUPERV::VoidState ;
90   _State = SUPERV::UnKnownState ;
91   _PyInitialized = false ;
92   _Orb = CORBA::ORB::_duplicate( ORB ) ;
93   pthread_mutex_init( &_MutexWait , NULL ) ;
94   pthread_mutex_init( &_PyMutexWait , NULL ) ;
95   if ( pthread_cond_init( &_EventWait , NULL ) ) {
96     perror("pthread_cond_init( &_EventWait , NULL )") ;
97     exit( 0 ) ;
98   }
99   if ( pthread_cond_init( &_JoinWait , NULL ) ) {
100     perror("pthread_cond_init( &_JoinWait , NULL )") ;
101     exit( 0 ) ;
102   }
103   cdebug_out << "GraphEditor::OutNode::OutNode" << endl;
104 }
105
106 GraphExecutor::OutNode::OutNode(
107                CORBA::ORB_ptr ORB, 
108                SALOME_NamingService* ptrNamingService ,
109                const SALOME_ModuleCatalog::Service& DataFlowService ,
110                const char *DataFlowComponentName ,
111                const char *DataFlowInterfaceName ,
112                const char *DataFlowName ,
113                const SUPERV::KindOfNode DataFlowkind ,
114                const SUPERV::SDate DataFlowFirstCreation ,
115                const SUPERV::SDate DataFlowLastModification ,
116                const char * DataFlowEditorRelease ,
117                const char * DataFlowAuthor ,
118                const char * DataFlowComputer ,
119                const char * DataFlowComment ,
120                const char * DebugFileName ) {
121 //               Graph( ORB , ptrNamingService , DataFlowService , DataFlowComponentName ,
122 //                      DataFlowInterfaceName , DataFlowName , DataFlowkind ,
123 //                      DataFlowFirstCreation , DataFlowLastModification  ,
124 //                      DataFlowEditorRelease , DataFlowAuthor ,
125 //                      DataFlowComputer , DataFlowComment , DebugFileName ) {
126   Set_prof_debug( ORB , DebugFileName ) ;
127
128   cdebug_in << "GraphEditor::OutNode::OutNode(" << DataFlowName << " , " << DataFlowkind << ")" << endl;
129   if ( DataFlowkind == SUPERV::DataFlowGraph ) {
130     _StreamGraph = NULL ;
131     _Graph = new GraphBase::Graph( ORB , ptrNamingService , DataFlowService , DataFlowComponentName ,
132                     DataFlowInterfaceName , DataFlowName , DataFlowkind ,
133                     DataFlowFirstCreation , DataFlowLastModification  ,
134                     DataFlowEditorRelease , DataFlowAuthor ,
135                     DataFlowComputer , DataFlowComment ,
136                     _prof_debug , _fdebug ) ;
137 //                    DataFlowComputer , DataFlowComment , DebugFileName ) ;
138   }
139   else if ( DataFlowkind == SUPERV::DataStreamGraph ) {
140     _StreamGraph = new GraphBase::StreamGraph( ORB , ptrNamingService , DataFlowService , DataFlowComponentName ,
141                     DataFlowInterfaceName , DataFlowName , DataFlowkind ,
142                     DataFlowFirstCreation , DataFlowLastModification  ,
143                     DataFlowEditorRelease , DataFlowAuthor ,
144                     DataFlowComputer , DataFlowComment ,
145                     _prof_debug , _fdebug ) ;
146     _Graph = _StreamGraph ;
147   }
148   _Valid = false ;
149   _Executable = false ;
150   _Done = false ;
151   _Threads = 0 ;
152   _ControlState = SUPERV::VoidState ;
153   _State = SUPERV::UnKnownState ;
154   _PyInitialized = false ;
155   _Orb = CORBA::ORB::_duplicate( ORB ) ;
156   pthread_mutex_init( &_MutexWait , NULL ) ;
157   pthread_mutex_init( &_PyMutexWait , NULL ) ;
158   if ( pthread_cond_init( &_EventWait , NULL ) ) {
159     perror("pthread_cond_init( &_EventWait , NULL )") ;
160     exit( 0 ) ;
161   }
162   if ( pthread_cond_init( &_JoinWait , NULL ) ) {
163     perror("pthread_cond_init( &_JoinWait , NULL )") ;
164     exit( 0 ) ;
165   }
166 }
167
168 GraphExecutor::OutNode::~OutNode() {
169 }
170
171 void GraphExecutor::OutNode::Set_prof_debug( CORBA::ORB_ptr ORB ,
172                                              const char * DebugFileName ) {
173   _Graph_prof_debug = 0 ;
174   if ( DebugFileName ) {
175     _fdebug = new ofstream( DebugFileName );
176     SetDebug( ORB , &_Graph_prof_debug , _fdebug ) ;
177     MESSAGE( endl << "Trace redirected to file " << DebugFileName << endl)
178   }
179 }
180
181 bool GraphExecutor::OutNode::LoadDataFlow(const GraphBase::SGraph &aDataFlow ) {
182   bool RetVal = false ;
183   RetVal = LoadInfo( aDataFlow.Info ) ;
184   if ( Graph()->ServiceName() != NULL ) {
185 //    MESSAGE( "GraphExecutor::OutNode::LoadDataFlow" );
186     if ( RetVal ) {
187       RetVal = LoadNodes( aDataFlow.Nodes ) ;
188       if ( RetVal ) {
189         RetVal = LoadLinks( aDataFlow.Links ) ;
190         if ( RetVal ) {
191           IsValid() ;
192           RetVal = LoadDatas( aDataFlow.Datas ) ;
193           IsExecutable() ;
194           if ( !RetVal) {
195             cdebug << "GraphExecutor::OutNode::LoadDataFlow LoadDatas Error."
196                    << endl ;
197           }
198         }
199         else {
200           cdebug << "GraphExecutor::OutNode::LoadDataFlow LoadLinks Error."
201                << endl ;
202         }
203       }
204       else {
205         cdebug << "GraphExecutor::OutNode::LoadDataFlow LoadNodes Error."
206              << endl ;
207       }
208     }
209     else {
210       cdebug << "GraphExecutor::OutNode::LoadDataFlow LoadInfo Error."
211            << endl ;
212     }
213   }
214   else {
215     cdebug << "GraphExecutor::OutNode::LoadDataFlow ServiceName Error." << endl ;
216   }
217   return RetVal ;
218 }
219
220 bool GraphExecutor::OutNode::LoadXml( const char* myFileName ) {
221   bool RetVal = false ;
222   GraphBase::SGraph aDataFlow ;
223   if ( Graph()->LoadXml( _Orb , myFileName , aDataFlow ) ) {
224     RetVal = LoadDataFlow( aDataFlow ) ;
225 //    if ( aConstructor && RetVal )
226 //      RetVal = Name( aDataFlow.Info.theName.c_str() ) ;
227   }
228   return RetVal ;
229
230
231 bool GraphExecutor::OutNode::LoadInfo(const GraphBase::SNode &aDataFlowInfo ) {
232   cdebug << "GraphExecutor::OutNode::LoadInfo _StreamGraph " << _StreamGraph << endl ;
233 //  ComponentName( aDataFlowInfo.theComponentName.c_str()  ) ;
234   Graph()->Name( aDataFlowInfo.theName.c_str()  ) ;
235   Graph()->Kind( aDataFlowInfo.theKind ) ;
236   if ( Graph()->IsDataStreamNode() ) {
237     StreamGraph()->SetStreamParams( aDataFlowInfo.theTimeout , aDataFlowInfo.theDataStreamTrace , aDataFlowInfo.theDeltaTime ) ;
238   }
239   Graph()->DataService( _Orb , aDataFlowInfo.theService , _prof_debug , _fdebug ) ;
240   Graph()->FirstCreation( aDataFlowInfo.theFirstCreation ) ;
241   Graph()->LastModification( aDataFlowInfo.theLastModification ) ;
242   Graph()->EditorRelease( aDataFlowInfo.theEditorRelease.c_str()  ) ;
243   Graph()->Author( aDataFlowInfo.theAuthor.c_str()   ) ;
244 //  Graph()->Computer( aDataFlowInfo.theContainer.c_str()  ) ;
245   Graph()->Comment( aDataFlowInfo.theComment.c_str()  ) ;
246 // Not in OutNode/DataFlow but in InNode/DataFlow_in_an_other_DataFlow
247 //  Graph()->Coordinates( aDataFlowInfo.theX , aDataFlowInfo.theY ) ;
248   return true ;
249 }
250
251 bool GraphExecutor::OutNode::LoadNodes(const GraphBase::ListOfNodes &aListOfNodes ) {
252   bool RetVal = true ;
253   GraphExecutor::InNode * anInNode ;
254   cdebug << "GraphExecutor::OutNode::LoadNodes" << endl ;
255   int i ;
256   for ( i = 0 ; i < (int ) aListOfNodes.size() ; i++ ) {
257     GraphBase::SNode aNode = aListOfNodes[ i ] ;
258     anInNode = AddNode( aNode.theService ,
259                         aNode.theListOfFuncName ,
260                         aNode.theListOfPythonFunctions ,
261                         aNode.theComponentName.c_str() ,
262                         aNode.theInterfaceName.c_str()  , aNode.theName.c_str() ,
263                         aNode.theKind ,
264                         aNode.theFirstCreation , aNode.theLastModification ,
265                         aNode.theEditorRelease.c_str() ,
266                         aNode.theAuthor.c_str()  , aNode.theContainer.c_str() ,
267                         aNode.theComment.c_str() ,
268                         aNode.theCoords.theX , aNode.theCoords.theY ) ;
269     if ( !anInNode ) {
270       RetVal = false ;
271       break ;
272     }
273     if ( anInNode->IsOneOfInLineNodes() ) {
274       anInNode->GraphExecutor::InNode::InLineNode()->DefPortsOfNode(
275                                 _Orb , aNode.theService , anInNode->NamePtr() ,
276                                 anInNode->Kind() ,
277                                 _prof_debug , _fdebug ) ;
278     }
279 //    GraphBase::ComputingNode * theNode = Graph()->GetChangeGraphNode( aNode.theName.c_str() ) ;
280
281     unsigned int j ;
282     for ( j = 0 ; j < aNode.theListOfInDataStreams.size() ; j++ ) {
283       GraphBase::InPort * anInPort ;
284       anInPort = anInNode->ComputingNode()->AddInDataStreamPort( aNode.theListOfInDataStreams[ j ].theDataStreamParameter.Parametername ,
285                                                                  aNode.theListOfInDataStreams[ j ].theDataStreamParameter.Parametertype ,
286                                                                  aNode.theListOfInDataStreams[ j ].theDataStreamParameter.Parameterdependency ,
287                                                                  SUPERV::DataStreamParameter ) ;
288       ((GraphBase::InDataStreamPort * ) anInPort)->SetParams( aNode.theListOfInDataStreams[ j ].theKindOfSchema ,
289                                                               aNode.theListOfInDataStreams[ j ].theKindOfInterpolation ,
290                                                               aNode.theListOfInDataStreams[ j ].theKindOfExtrapolation ) ;
291     }
292     for ( j = 0 ; j < aNode.theListOfOutDataStreams.size() ; j++ ) {
293       GraphBase::OutPort * anOutPort ;
294       anOutPort = anInNode->ComputingNode()->AddOutDataStreamPort( aNode.theListOfOutDataStreams[ j ].theDataStreamParameter.Parametername ,
295                                                                    aNode.theListOfOutDataStreams[ j ].theDataStreamParameter.Parametertype ,
296                                                                    aNode.theListOfOutDataStreams[ j ].theDataStreamParameter.Parameterdependency ,
297                                                                    SUPERV::DataStreamParameter ) ;
298       ((GraphBase::OutDataStreamPort * ) anOutPort)->NumberOfValues( aNode.theListOfOutDataStreams[ j ].theNumberOfValues ) ;
299     }
300
301
302 //    theNode->DataStreamInPortsNumber( aNode.theDataStreamInArgsNumber ) ;
303 //    theNode->DataStreamOutPortsNumber( aNode.theDataStreamOutArgsNumber ) ;
304 //    cdebug << "GraphExecutor::OutNode::LoadNodes " << anInNode->Name()
305 //           << " InPortsSize " << theNode->GetNodeInPortsSize()
306 //           << " OutPortsSize " << theNode->GetNodeOutPortsSize()
307 //           << " DataStreamInPortsNumber " << aNode.theDataStreamInArgsNumber
308 //           << " DataStreamOutPortsNumber " << aNode.theDataStreamOutArgsNumber
309 //           << endl ;
310 //    int j ;
311 //    if ( aNode.theDataStreamInArgsNumber ) { // -1 because of Gates
312 //      for ( j = theNode->GetNodeInPortsSize() - aNode.theDataStreamInArgsNumber - 1 ; j < theNode->GetNodeInPortsSize() - 1 ; j++ ) {
313 //        cdebug << "GraphExecutor::OutNode::LoadNodes " << anInNode->Name()
314 //               << " InPort " << theNode->GetChangeNodeInPort( j )->PortName()
315 //               << " Kind( DataStreamParameter)" << endl ;
316 //        theNode->GetChangeNodeInPort( j )->Kind( SUPERV::DataStreamParameter ) ;
317 //      }
318 //    }
319 //    if ( aNode.theDataStreamOutArgsNumber ) {
320 //      int withgate = 1 ;
321 //      if ( theNode->IsLoopNode() || theNode->IsEndLoopNode() ) {
322 //        withgate = 0 ;
323 //      }
324 //      for ( j = theNode->GetNodeOutPortsSize() - aNode.theDataStreamOutArgsNumber - withgate ; j < theNode->GetNodeOutPortsSize() - withgate ; j++ ) {
325 //        cdebug << "GraphExecutor::OutNode::LoadNodes " << anInNode->Name()
326 //               << " OutPort " << theNode->GetChangeNodeOutPort( j )->PortName()
327 //               << " Kind( DataStreamParameter)" << endl ;
328 //        theNode->GetChangeNodeOutPort( j )->Kind( SUPERV::DataStreamParameter ) ;
329 //      }
330 //    }
331   }
332   for ( i = 0 ; i < (int ) aListOfNodes.size() ; i++ ) {
333     GraphBase::SNode aNode = aListOfNodes[ i ] ;
334     anInNode = (GraphExecutor::InNode * ) Graph()->GetChangeGraphNode( aNode.theName.c_str() )->GetInNode() ;
335     cdebug << "GraphExecutor::OutNode::LoadNodes " << anInNode->Name() << " IsOneOfGOTONodes "
336            << anInNode->IsOneOfGOTONodes() << " " << aNode.theCoupledNode.c_str() << endl ;
337     if ( anInNode->IsOneOfGOTONodes() && strlen( aNode.theCoupledNode.c_str() ) ) {
338       GraphBase::GOTONode * aCoupledNode ;
339       aCoupledNode = (GraphBase::GOTONode * ) Graph()->GetGraphNode( aNode.theName.c_str() ) ;
340       aCoupledNode->CoupledNode( (GraphBase::GOTONode * ) Graph()->GetChangeGraphNode( aNode.theCoupledNode.c_str() ) ) ; 
341     }
342   }
343   return RetVal ;
344 }
345
346 bool GraphExecutor::OutNode::LoadLinks(const GraphBase::ListOfLinks &aListOfLinks ) {
347   bool RetVal = true ;
348   cdebug << "GraphExecutor::OutNode::LoadLinks " << aListOfLinks.size()
349          << endl ;
350   int i ;
351   for ( i = 0 ; i < (int ) aListOfLinks.size() ; i++ ) {
352     GraphBase::SLink aLink = aListOfLinks[ i ] ;
353     RetVal = Graph()->AddLink( aLink.FromNodeName.c_str() ,
354                                aLink.FromServiceParameterName.c_str() ,
355                                aLink.ToNodeName.c_str() ,
356                                aLink.ToServiceParameterName.c_str() ,
357                                aLink.aLinkValue ) ;
358 //                      aLink.aLinkValue.Value , aLink.aLinkValue.Kind ) ;
359     if ( !RetVal )
360       break ;
361   }
362   return RetVal ;
363 }
364
365 bool GraphExecutor::OutNode::LoadDatas(const GraphBase::ListOfLinks &aListOfDatas ) {
366   bool RetVal = true ;
367   cdebug << "GraphExecutor::OutNode::LoadDatas " << aListOfDatas.size()
368          << endl ;
369   int i ;
370   for ( i = 0 ; i < (int ) aListOfDatas.size() ; i++ ) {
371     GraphBase::SLink aLink = aListOfDatas[ i ] ;
372     if ( !strcmp( aLink.FromNodeName.c_str() , Graph()->Name() ) )
373       RetVal = Graph()->AddInputData( aLink.ToNodeName.c_str() ,
374                                       aLink.ToServiceParameterName.c_str() ,
375                                       aLink.aLinkValue ) ;
376 //                        aLink.aLinkValue.Value , aLink.aLinkValue.Kind ) ;
377     else if ( !strcmp( aLink.ToNodeName.c_str() , Graph()->Name() ) ) {
378       RetVal = Graph()->AddOutputData( aLink.FromNodeName.c_str() ,
379                                        aLink.FromServiceParameterName.c_str() ,
380                                        aLink.aLinkValue ) ;
381 //                              aLink.aLinkValue.Value ,
382 //                              aLink.aLinkValue.Kind ) ;
383       Graph()->AddLink( aLink.FromNodeName.c_str() , (GraphBase::ComputingNode *) this ) ;
384     }
385     else {
386       cdebug << "GraphExecutor::OutNode::LoadDatas Error " << aLink.FromNodeName
387            << " and " << aLink.ToNodeName << " differents from " << Graph()->Name()
388            << endl ;
389       RetVal = false ;
390     }
391     if ( !RetVal )
392       break ;
393   }
394   return RetVal ;
395 }
396
397 GraphExecutor::InNode *GraphExecutor::OutNode::AddNode(
398                       const SALOME_ModuleCatalog::Service& NodeService ,
399                       GraphBase::ListOfFuncName aFuncName ,
400                       GraphBase::ListOfPythonFunctions aPythonFunction ,
401                       const char * NodeComponentName ,
402                       const char * NodeInterfaceName ,
403                       const char * NodeName ,
404                       const SUPERV::KindOfNode NodeKindOfNode ,
405                       const SUPERV::SDate NodeFirstCreation ,
406                       const SUPERV::SDate NodeLastModification  ,
407                       const char * NodeEditorRelease ,
408                       const char * NodeAuthor ,
409                       const char * NodeComputer ,
410                       const char * NodeComment ,
411                       const int NodeX ,
412                       const int NodeY ) {
413   cdebug_in << "GraphExecutor::OutNode::AddNode(" << NodeComponentName << " , "
414             << NodeName << ")" << endl;
415   GraphExecutor::InNode *Nd = NULL ;
416   Nd = new GraphExecutor::InNode( _Orb, Graph()->NamingService() , NodeService ,
417                                   NodeComponentName , NodeInterfaceName ,
418                                   NodeName , NodeKindOfNode ,
419                                   aFuncName , aPythonFunction ,
420                                   NodeFirstCreation , NodeLastModification ,
421                                   NodeEditorRelease , NodeAuthor ,
422                                   NodeComputer , NodeComment , false , NodeX , NodeY ,
423                                   _prof_debug , _fdebug ) ;
424   Graph()->AddNode( Nd->ComputingNode() ) ;
425   cdebug_out << "GraphExecutor::OutNode::AddNode" << endl;
426   return Nd ;
427 }
428
429
430 bool GraphExecutor::OutNode::AddInputData( const char* ToNodeName1 ,
431                                            const char* ToParameterName1 ,
432                                            const char* ToNodeName2 ,
433                                            const char* ToParameterName2 ) {
434   cdebug_in << "GraphExecutor::OutNode::AddInputData" << endl;
435   bool RetVal = Graph()->AddInputData( ToNodeName1 ,
436                                        ToParameterName1 ,
437                                        ToNodeName2 ,
438                                        ToParameterName2 ) ;
439   cdebug_out << "GraphExecutor::OutNode::AddInputData" << endl;
440   _Valid = false ;
441   return RetVal ;
442 }
443
444 bool GraphExecutor::OutNode::Valid() {
445   cdebug_in << "GraphExecutor::OutNode::Valid" << endl;
446
447   if ( _Valid )
448     return true ;
449
450   _Executable = false ;
451
452   if ( !Graph()->CreateService() ) {
453     cdebug << "This DataFlow has invalid type(s)." << endl ;
454     return false ;
455   }
456   int SubStreamGraphsNumber = 0 ;
457   if ( !Graph()->Sort( SubStreamGraphsNumber ) ) {
458     cdebug << "This DataFlow is not valid." << endl ;
459     return false ;
460   }
461   if ( Graph()->IsDataStreamNode() ) {
462     StreamGraph()->SubStreamGraphsNumber( SubStreamGraphsNumber ) ;
463   }
464
465 //  CreateService() ;
466
467   Graph()->InLineServices() ;
468
469   Graph()->ComputingNodes() ;
470   
471   _Valid = true ;
472
473   cdebug_out << "GraphExecutor::OutNode::Valid" << endl;
474   return _Valid ;
475 }
476
477
478 bool GraphExecutor::OutNode::Executable() {
479
480   cdebug_in << "GraphExecutor::OutNode::Executable" << endl;
481   if ( !IsValid() )
482     return false ;
483
484   if ( Graph()->DataServerNodes() )
485     _Executable = true ;
486   else {
487     cdebug << "This DataFlow is not executable." << endl ;
488     _Executable = false ;
489   }
490
491   cdebug_out << "GraphExecutor::OutNode::Executable" << endl;
492   return _Executable ;
493 }
494
495 bool GraphExecutor::OutNode::Run( const bool AndSuspend ) {
496   bool RetVal = false ;
497   cdebug_in << "GraphExecutor::OutNode::Run" << endl;
498
499   if ( Executable() ) {
500     _ControlState = SUPERV::VoidState ;
501     _SuspendedThreads = 0 ;
502     Graph()->ThreadNo( pthread_self() ) ;
503     Done( false ) ;
504     _JustStarted = true ;
505     int i ;
506     for ( i = 0 ; i < Graph()->GraphNodesSize() ; i++ ) {
507       GraphExecutor::InNode * anInNode = (GraphExecutor::InNode *) Graph()->GraphNodes( i )->GetInNode() ;
508       if ( !PyInitialized() && anInNode->IsOneOfInLineNodes() ) {
509         if ( !Py_IsInitialized() ) {
510 //          Py_Initialize() ;
511           PySys_SetArgv( _ArgC , _ArgV ) ;
512         }
513         anInNode->InitPython() ;
514         PyInitialized( true ) ;
515       }
516       anInNode->InitialState( this ) ;
517       if ( anInNode->IsOneOfInLineNodes() ) {
518         anInNode->InitPythonFunctions( false ) ;
519       }
520     }
521 // One more time because inline nodes may share one definition of the same function
522     for ( i = 0 ; i < Graph()->GraphNodesSize() ; i++ ) {
523       GraphExecutor::InNode * anInNode = (GraphExecutor::InNode *) Graph()->GraphNodes( i )->GetInNode() ;
524       if ( anInNode->IsOneOfInLineNodes() ) {
525         if ( !anInNode->InitPythonFunctions( true ) ) {
526           cdebug << "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" ) ;
1798     MESSAGE("================================================================================") ;
1799   }
1800   else {
1801     MESSAGE("================================================================================") ;
1802     MESSAGE( Graph()->Name() << " IS NOT KILLED" ) ;
1803     MESSAGE("================================================================================") ;
1804   }
1805   cdebug_out << "GraphExecutor::OutNode::Kill" << endl ;
1806   return RetVal ;
1807 }
1808
1809 bool GraphExecutor::OutNode::Stop() {
1810   bool RetVal = false ;
1811   cdebug_in << "GraphExecutor::OutNode::Stop" << endl;
1812   RetVal = Kill() ;
1813   cdebug_out << "GraphExecutor::OutNode::Stop" << endl ;
1814   if ( RetVal ) {
1815     MESSAGE("================================================================================") ;
1816     MESSAGE( Graph()->Name() << " IS STOPPED" ) ;
1817     MESSAGE("================================================================================") ;
1818   }
1819   return RetVal ;
1820 }
1821 bool GraphExecutor::OutNode::ReRun() {
1822   bool RetVal = false ;
1823   cdebug_in << "GraphExecutor::OutNode::ReRun" << endl;
1824   if ( IsSuspended() ) {
1825   }
1826   cdebug_out << "GraphExecutor::OutNode::ReRun" << endl ;
1827   return RetVal ;
1828 }
1829 bool GraphExecutor::OutNode::ReStart() {
1830   bool RetVal = false ;
1831   cdebug_in << "GraphExecutor::OutNode::ReStart" << endl;
1832   if ( IsSuspended() ) {
1833   }
1834   cdebug_out << "GraphExecutor::OutNode::ReStart" << endl ;
1835   return RetVal ;
1836 }
1837
1838 bool GraphExecutor::OutNode::ReadyWait() {
1839   cdebug_in << "GraphExecutor::OutNode::ReadyWait" << endl;
1840   bool aret ;
1841   if ( pthread_mutex_lock( &_MutexWait ) ) {
1842     perror("pthread_mutex_lock _ReadyWait") ;
1843     exit( 0 ) ;
1844   }
1845   aret = IsReady() ;
1846   if ( !aret ) {
1847     Suspend() ;
1848     pthread_cond_wait( &_EventWait , &_MutexWait );
1849     aret = IsReady() ;
1850   }
1851   if ( pthread_mutex_unlock( &_MutexWait ) ) {
1852     perror("pthread_mutex_lock _ReadyWait") ;
1853     exit( 0 ) ;
1854   }
1855   cdebug_out << "GraphExecutor::OutNode::ReadyWait" << endl ;
1856   return aret ;
1857 }
1858
1859 bool GraphExecutor::OutNode::RunningWait() {
1860   cdebug_in << "GraphExecutor::OutNode::RunningWait" << endl;
1861   bool aret ;
1862   if ( pthread_mutex_lock( &_MutexWait ) ) {
1863     perror("pthread_mutex_lock _RunningWait") ;
1864     exit( 0 ) ;
1865   }
1866   aret = IsRunning() ;
1867   if ( !aret ) {
1868     cdebug << "RunningWait pthread_cond_wait _EventWait" << endl;
1869     pthread_cond_wait( &_EventWait , &_MutexWait );
1870     aret = IsRunning() ;
1871     cdebug << "RunningWait pthread_cond_waited _EventWait " << aret << endl;
1872   }
1873   if ( pthread_mutex_unlock( &_MutexWait ) ) {
1874     perror("pthread_mutex_lock _RunningWait") ;
1875     exit( 0 ) ;
1876   }
1877   cdebug_out << "GraphExecutor::OutNode::RunningWait " << aret << endl ;
1878   return aret ;
1879 }
1880
1881 bool GraphExecutor::OutNode::DoneWait() {
1882   cdebug_in << "GraphExecutor::OutNode::DoneWait" << endl;
1883   bool aret ;
1884   if ( pthread_mutex_lock( &_MutexWait ) ) {
1885     perror("pthread_mutex_lock _DoneWait") ;
1886     exit( 0 ) ;
1887   }
1888   aret = IsDone() ;
1889   while ( !aret && !IsSuspended() && IsRunning() ) {
1890     cdebug << "DoneWait pthread_cond_wait _EventWait" << endl;
1891     pthread_cond_wait( &_EventWait , &_MutexWait );
1892     aret = IsDone() ;
1893     cdebug << "DoneWait pthread_cond_waited _EventWait " << aret << endl;
1894   }
1895   if ( pthread_mutex_unlock( &_MutexWait ) ) {
1896     perror("pthread_mutex_lock _DoneWait") ;
1897     exit( 0 ) ;
1898   }
1899   cdebug_out << "GraphExecutor::OutNode::DoneWait " << aret << endl ;
1900   return aret ;
1901 }
1902
1903 bool GraphExecutor::OutNode::SuspendedWait() {
1904   cdebug_in << "GraphExecutor::OutNode::SuspendedWait" << endl;
1905   bool aret ;
1906   if ( pthread_mutex_lock( &_MutexWait ) ) {
1907     perror("pthread_mutex_lock _SuspendedWait") ;
1908     exit( 0 ) ;
1909   }
1910   aret = IsSuspended() ;
1911   while ( !aret && !IsDone() ) {
1912     pthread_cond_wait( &_EventWait , &_MutexWait );
1913     aret = IsSuspended() ;
1914   }
1915   if ( pthread_mutex_unlock( &_MutexWait ) ) {
1916     perror("pthread_mutex_lock _SuspendedWait") ;
1917     exit( 0 ) ;
1918   }
1919   cdebug_out << "GraphExecutor::OutNode::SuspendedWait" << endl ;
1920   return aret ;
1921 }
1922
1923 bool GraphExecutor::OutNode::ReadyWait( const char * NodeName ) {
1924   bool aret = false ;
1925   cdebug_in << "GraphExecutor::OutNode::ReadyWait " << NodeName << endl;
1926   GraphExecutor::InNode *anInNode = (GraphExecutor::InNode *) Graph()->GetGraphNode( NodeName )->GetInNode() ;
1927   if ( anInNode ) {
1928     aret = anInNode->ReadyWait() ;
1929   }
1930   cdebug_out << "GraphExecutor::OutNode::ReadyWait" << endl ;
1931   return aret ;
1932 }
1933
1934 bool GraphExecutor::OutNode::RunningWait( const char * NodeName ) {
1935   bool aret = false ;
1936   cdebug_in << "GraphExecutor::OutNode::RunningWait " << NodeName << endl;
1937   GraphExecutor::InNode *anInNode = (GraphExecutor::InNode *) Graph()->GetGraphNode( NodeName )->GetInNode() ;
1938   if ( anInNode ) {
1939     aret = anInNode->RunningWait() ;
1940   }
1941   cdebug_out << "GraphExecutor::OutNode::RunningWait" << endl ;
1942   return aret ;
1943 }
1944
1945 bool GraphExecutor::OutNode::DoneWait( const char * NodeName ) {
1946   bool aret = false ;
1947   cdebug_in << "GraphExecutor::OutNode::DoneWait " << NodeName << endl;
1948   GraphExecutor::InNode *anInNode = (GraphExecutor::InNode *) Graph()->GetGraphNode( NodeName )->GetInNode() ;
1949   if ( anInNode ) {
1950     aret = anInNode->DoneWait() ;
1951   }
1952   cdebug_out << "GraphExecutor::OutNode::DoneWait" << endl ;
1953   return aret ;
1954 }
1955
1956 bool GraphExecutor::OutNode::SuspendedWait( const char * NodeName ) {
1957   bool aret = false ;
1958   cdebug_in << "GraphExecutor::OutNode::SuspendedWait " << NodeName << endl;
1959   GraphExecutor::InNode *anInNode = (GraphExecutor::InNode *) Graph()->GetGraphNode( NodeName )->GetInNode() ;
1960   if ( anInNode ) {
1961     aret = anInNode->SuspendedWait() ;
1962   }
1963   cdebug_out << "GraphExecutor::OutNode::SuspendedWait" << endl ;
1964   return aret ;
1965 }
1966
1967 long GraphExecutor::OutNode::LastLevelDone() {
1968   int RetVal = -1 ;
1969   int i , j ;
1970   for ( i = 0 ; i <= Graph()->LevelMax() ; i++ ) {
1971     for ( j = 0 ; j <= Graph()->NodesNumber( i ) ; j++ ) {
1972       GraphBase::ComputingNode * aNode = Graph()->SortedNodes( i , j ) ;
1973       if ( !IsDone( aNode->Name() ) ) {
1974         break ;
1975       }
1976     }
1977     if ( j != Graph()->NodesNumber( i ) + 1 )
1978       break ;
1979     RetVal = i ;
1980   }
1981   return RetVal ;
1982 }
1983
1984
1985 const CORBA::Any *GraphExecutor::OutNode::GetInData( const char * NodeName ,
1986                                                      const char * ServiceParameterName ) {
1987 //  cdebug_in << "GraphExecutor::OutNode::GetInData " << NodeName << " "
1988 //            << ServiceParameterName << endl ;
1989   const CORBA::Any * retdata = Graph()->PortInData( NodeName , ServiceParameterName ) ;
1990 //  cdebug_out << "GraphExecutor::OutNode::GetInData" << endl ;
1991   return retdata ;
1992 }
1993
1994 const CORBA::Any *GraphExecutor::OutNode::GetOutData( const char * NodeName ,
1995                                                       const char * ServiceParameterName ) {
1996 //  cdebug_in << "GraphExecutor::OutNode::GetOutData " << NodeName << " "
1997 //            << ServiceParameterName << endl ;
1998   const CORBA::Any * retdata = Graph()->PortOutData( NodeName , ServiceParameterName ) ;
1999 //  cdebug_out << "GraphExecutor::OutNode::GetOutData" << endl ;
2000   return retdata ;
2001 }
2002
2003 const long GraphExecutor::OutNode::CpuUsed() {
2004   return Graph()->CpuUsed() ;
2005 }
2006
2007 const long GraphExecutor::OutNode::CpuUsed( const char * aNodeName ) {
2008   GraphBase::ComputingNode * aNode = Graph()->GetChangeGraphNode( aNodeName ) ;
2009   if ( aNode ) {
2010     GraphExecutor::InNode * anInNode = (GraphExecutor::InNode * ) aNode->GetInNode() ;
2011     if ( anInNode ) {
2012       return anInNode->CpuUsed() ;
2013     }
2014   }
2015   return 0 ;
2016 }
2017
2018