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