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