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