Salome HOME
PAL8624
[modules/superv.git] / src / GraphExecutor / DataFlowExecutor_InNode.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   : DataFlowExecutor_InNode.cxx
25 //  Author : Jean Rahuel, CEA
26 //  Module : SUPERV
27 //  $Header:
28
29 using namespace std;
30
31 #include <stdlib.h>
32 #include <iostream>
33 #include <unistd.h>
34 #include <stdio.h>
35 #include <errno.h>
36
37 #include "OpUtil.hxx"
38
39 #include <SALOMEconfig.h>
40 #include CORBA_CLIENT_HEADER(SALOME_Component)
41 //#include "SALOME_NamingService.hxx"
42 #include "SALOME_LifeCycleCORBA.hxx"
43
44 #include "DataFlowBase_FactoryNode.hxx"
45 #include "DataFlowBase_GOTONode.hxx"
46 #include "DataFlowBase_LoopNode.hxx"
47 #include "DataFlowBase_EndOfLoopNode.hxx"
48 #include "DataFlowBase_SwitchNode.hxx"
49 #include "DataFlowBase_EndOfSwitchNode.hxx"
50
51 #include "DataFlowExecutor_DataFlow.hxx"
52 #include "DataFlowEditor_DataFlow.hxx"   // GraphEditor package must be built BEFORE
53
54 static void InitInNode( int &_RewindStack ,
55                         SUPERV::ControlState &_ControlState ,
56                         GraphExecutor::AutomatonState &_currentState ,
57                         GraphExecutor::InNode ** _aReStartNode ,
58                         bool & _PyFuncRunned ,
59                         PyObject ** _MyPyRunMethod ,
60 //                        pthread_mutex_t &_MutexDataWait ,
61 //                        bool &_DataWait ,
62                         pthread_mutex_t &_MutexDataReady ,
63                         pthread_mutex_t &_MutexWait ,
64                         pthread_cond_t &_ReadyWait ,
65                         pthread_cond_t &_RunningWait ,
66                         pthread_cond_t &_DoneWait ,
67                         pthread_cond_t &_SuspendedWait ,
68                         pthread_cond_t &_SuspendWait ,
69                         bool &_SuspendSync ,
70                         pthread_cond_t &_ResumeWait ,
71                         bool &_ResumeSync ,
72                         pthread_cond_t &_KillWait ,
73                         bool &_KillSync ,
74                         pthread_cond_t &_ThreadStartedWait ,
75                         bool &_ThreadStartedSync ,
76                         pthread_cond_t &_StopWait ,
77                         GraphExecutor::FiniteStateMachine ** _Automaton ,
78                         GraphExecutor::FiniteStateMachine * theAutomaton ,
79                         CORBA::ORB_ptr * _Orb ,
80                         CORBA::ORB_ptr ORB,
81                         bool &_Loading ) {
82   _RewindStack = 0 ;
83   _ControlState = SUPERV::VoidState ;
84   _currentState = GraphExecutor::UnKnownState ;
85   *_aReStartNode = NULL ;
86   _PyFuncRunned = false ;
87   *_MyPyRunMethod = NULL ;
88 //  pthread_mutex_init( &_MutexDataWait , NULL ) ;
89 //  _DataWait = false ;
90   pthread_mutex_init( &_MutexDataReady , NULL ) ;
91   pthread_mutex_init( &_MutexWait , NULL ) ;
92   if ( pthread_cond_init( &_ReadyWait , NULL ) ) {
93     perror("pthread_cond_init( &_ReadyWait , NULL )") ;
94     exit( 0 ) ;
95   }
96   if ( pthread_cond_init( &_RunningWait , NULL ) ) {
97     perror("pthread_cond_init( &_RunningWait , NULL )") ;
98     exit( 0 ) ;
99   }
100   if ( pthread_cond_init( &_DoneWait , NULL ) ) {
101     perror("pthread_cond_init( &_DoneWait , NULL )") ;
102     exit( 0 ) ;
103   }
104   if ( pthread_cond_init( &_SuspendedWait , NULL ) ) {
105     perror("pthread_cond_init( &_SuspendedWait , NULL )") ;
106     exit( 0 ) ;
107   }
108   if ( pthread_cond_init( &_SuspendWait , NULL ) ) {
109     perror("pthread_cond_init( &_SuspendWait , NULL )") ;
110     exit( 0 ) ;
111   }
112   _SuspendSync = false ;
113   if ( pthread_cond_init( &_ResumeWait , NULL ) ) {
114     perror("pthread_cond_init( &_ResumeWait , NULL )") ;
115     exit( 0 ) ;
116   }
117   _ResumeSync = false ;
118   if ( pthread_cond_init( &_KillWait , NULL ) ) {
119     perror("pthread_cond_init( &_KillWait , NULL )") ;
120     exit( 0 ) ;
121   }
122   _KillSync = false ;
123   if ( pthread_cond_init( &_ThreadStartedWait , NULL ) ) {
124     perror("pthread_cond_init( &_ThreadStartedWait , NULL )") ;
125     exit( 0 ) ;
126   }
127   _ThreadStartedSync = false ;
128   if ( pthread_cond_init( &_StopWait , NULL ) ) {
129     perror("pthread_cond_init( &_StopWait , NULL )") ;
130     exit( 0 ) ;
131   }
132   *_Automaton = theAutomaton ;
133   *_Orb = CORBA::ORB::_nil();
134   _Loading = false;
135 }
136
137 GraphExecutor::FiniteStateMachine * theAutomaton = new GraphExecutor::FiniteStateMachine() ;
138
139 //GraphExecutor::InNode::InNode() :
140 //     GraphBase::FactoryNode() {
141 GraphExecutor::InNode::InNode() {
142   InitInNode( _RewindStack ,
143               _ControlState ,
144               _currentState ,
145               &_aReStartNode ,
146               _PyFuncRunned ,
147               &_MyPyRunMethod ,
148 //              _MutexDataWait ,
149 //              _DataWait ,
150               _MutexDataReady ,
151               _MutexWait ,
152               _ReadyWait ,
153               _RunningWait ,
154               _DoneWait ,
155               _SuspendedWait ,
156               _SuspendWait ,
157               _SuspendSync ,
158               _ResumeWait ,
159               _ResumeSync ,
160               _KillWait ,
161               _KillSync ,
162               _ThreadStartedWait ,
163               _ThreadStartedSync ,
164               _StopWait ,
165               &_Automaton ,
166               theAutomaton ,
167               &_Orb ,
168               CORBA::ORB::_nil(),
169               _Loading ) ;
170 }
171
172 GraphExecutor::InNode::InNode( CORBA::ORB_ptr ORB,
173                                SALOME_NamingService* ptrNamingService ,
174                                const SALOME_ModuleCatalog::Service& aService ,
175                                const char * ComponentName ,
176                                const char * NodeInterfaceName ,
177                                const char * NodeName ,
178                                const SUPERV::KindOfNode akind ,
179                                GraphBase::ListOfFuncName aFuncName ,
180                                GraphBase::ListOfPythonFunctions aPythonFunction ,
181                                const SUPERV::SDate NodeFirstCreation ,
182                                const SUPERV::SDate NodeLastModification  ,
183                                const char * NodeEditorRelease ,
184                                const char * NodeAuthor ,
185                                const char * NodeComputer ,
186                                const char * NodeComment ,
187                                const bool   GeneratedName ,
188                                const int NodeX ,
189                                const int NodeY ,
190                                int * Graph_prof_debug,
191                                ofstream * Graph_fdebug) {
192 //               ostream * Graph_fdebug = NULL ) :
193 //             GraphBase::FactoryNode( ORB , ptrNamingService , aService ,
194 //                                     ComponentName , NodeInterfaceName ,
195 //                                     NodeName , akind ,
196 //                                     NodeFirstCreation , NodeLastModification  ,
197 //                                     NodeEditorRelease , NodeAuthor ,
198 //                                     NodeComputer , NodeComment , GeneratedName ,
199 //                                     0 , 0 ,
200 //                                     Graph_prof_debug , Graph_fdebug ) {
201   InitInNode( _RewindStack ,
202               _ControlState ,
203               _currentState ,
204               &_aReStartNode ,
205               _PyFuncRunned ,
206               &_MyPyRunMethod ,
207 //              _MutexDataWait ,
208 //              _DataWait ,
209               _MutexDataReady ,
210               _MutexWait ,
211               _ReadyWait ,
212               _RunningWait ,
213               _DoneWait ,
214               _SuspendedWait ,
215               _SuspendWait ,
216               _SuspendSync ,
217               _ResumeWait ,
218               _ResumeSync ,
219               _KillWait ,
220               _KillSync ,
221               _ThreadStartedWait ,
222               _ThreadStartedSync ,
223               _StopWait ,
224               &_Automaton ,
225               theAutomaton ,
226               &_Orb ,
227               ORB,
228               _Loading ) ;
229   SetDebug( ORB , Graph_prof_debug , Graph_fdebug ) ;
230
231   _ComputingNode = NULL ;
232   _FactoryNode = NULL ;
233   _InLineNode = NULL ;
234   _GOTONode = NULL ;
235   _LoopNode = NULL ;
236   _EndOfLoopNode = NULL ;
237   _SwitchNode = NULL ;
238   _EndOfSwitchNode = NULL ;
239   switch ( akind ) {
240   case SUPERV::ComputingNode : {
241     cdebug << "GraphExecutor::InNode::InNode SUPERV::ComputingNode : " << NodeName ;
242     _ComputingNode = new GraphBase::ComputingNode( ORB , ptrNamingService ,
243                                                    aService ,
244                                                    NodeName , akind ,
245                                                    NodeFirstCreation ,
246                                                    NodeLastModification  ,
247                                                    NodeEditorRelease , NodeAuthor ,
248                                                    NodeComment , GeneratedName ,
249                                                    NodeX , NodeY ,
250                                                    Graph_prof_debug , Graph_fdebug ) ;
251     break ;
252   }
253   case SUPERV::FactoryNode : {
254     cdebug << "GraphExecutor::InNode::InNode SUPERV::FactoryNode : " << NodeName ;
255     _FactoryNode = new GraphBase::FactoryNode( ORB , ptrNamingService , aService ,
256                                                ComponentName , NodeInterfaceName ,
257                                                NodeName , akind ,
258                                                NodeFirstCreation ,
259                                                NodeLastModification  ,
260                                                NodeEditorRelease , NodeAuthor ,
261                                                NodeComputer , NodeComment ,
262                                                GeneratedName , NodeX , NodeY ,
263                                                Graph_prof_debug , Graph_fdebug ) ;
264     _ComputingNode = (GraphBase::ComputingNode *) _FactoryNode ;
265     break ;
266   }
267   case SUPERV::InLineNode : {
268     cdebug << "GraphExecutor::InNode::InNode SUPERV::InLineNode : " << NodeName ;
269     _InLineNode = new GraphBase::InLineNode( ORB , ptrNamingService ,
270                                              aFuncName[0].c_str() , *aPythonFunction[0] ,
271                                              NodeName , akind ,
272                                              NodeFirstCreation , NodeLastModification  ,
273                                              NodeEditorRelease , NodeAuthor ,
274                                              NodeComment , GeneratedName ,
275                                              NodeX , NodeY ,
276                                              Graph_prof_debug , Graph_fdebug ) ;
277     _ComputingNode = (GraphBase::ComputingNode *) _InLineNode ;
278     break ;
279   }
280   case SUPERV::MacroNode : {
281     cdebug << "GraphExecutor::InNode::InNode SUPERV::MacroNode : " << NodeName << endl ;
282     _GraphMacroNode = new GraphBase::Graph( ORB , ptrNamingService ,
283 //                                            aFuncName[0].c_str() , *aPythonFunction[0] ,
284                                             NodeName , akind ,
285 //                                            NodeFirstCreation , NodeLastModification  ,
286 //                                            NodeEditorRelease , NodeAuthor ,
287 //                                            NodeComment , GeneratedName ,
288 //                                            NodeX , NodeY ,
289                                             Graph_prof_debug , Graph_fdebug ) ;
290     _ComputingNode = (GraphBase::ComputingNode *) _GraphMacroNode ;
291     _InLineNode = (GraphBase::InLineNode *) _ComputingNode ;
292     _GOTONode = (GraphBase::GOTONode *) _InLineNode ;
293     _GraphMacroNode->Coordinates( NodeX , NodeY ) ;
294     break ;
295   }
296   case SUPERV::GOTONode : {
297     cdebug << "GraphEditor::InNode::InNode SUPERV::GOTONode : " << NodeName ;
298     _GOTONode = new GraphBase::GOTONode( ORB , ptrNamingService ,
299                                          aFuncName[0].c_str() , *aPythonFunction[0] ,
300                                          NodeName , akind ,
301                                          NodeFirstCreation , NodeLastModification  ,
302                                          NodeEditorRelease , NodeAuthor ,
303                                          NodeComment , GeneratedName ,
304                                          NodeX , NodeY ,
305                                          Graph_prof_debug , Graph_fdebug ) ;
306     _ComputingNode = (GraphBase::ComputingNode *) _GOTONode ;
307     _InLineNode = (GraphBase::InLineNode *) _ComputingNode ;
308     break ;
309   }
310   case SUPERV::LoopNode : {
311     cdebug << "GraphExecutor::InNode::InNode SUPERV::LoopNode : " << NodeName ;
312     _LoopNode = new GraphBase::LoopNode( ORB , ptrNamingService ,
313                                          aFuncName[0].c_str() , *aPythonFunction[0] ,
314                                          aFuncName[1].c_str() , *aPythonFunction[1] ,
315                                          aFuncName[2].c_str() , *aPythonFunction[2] ,
316                                          NodeName , akind ,
317                                          NodeFirstCreation , NodeLastModification  ,
318                                          NodeEditorRelease , NodeAuthor ,
319                                          NodeComment , GeneratedName ,
320                                          NodeX , NodeY ,
321                                          Graph_prof_debug , Graph_fdebug ) ;
322     _ComputingNode = (GraphBase::ComputingNode *) _LoopNode ;
323     _GOTONode = (GraphBase::GOTONode *) _ComputingNode ;
324     _InLineNode = (GraphBase::InLineNode *) _ComputingNode ;
325     break ;
326   }
327   case SUPERV::EndLoopNode : {
328     cdebug << "GraphEditor::InNode::InNode SUPERV::EndOfLoopNode : " << NodeName ;
329     _EndOfLoopNode = new GraphBase::EndOfLoopNode(
330                                          ORB , ptrNamingService ,
331                                          aFuncName[0].c_str() , *aPythonFunction[0] ,
332                                          NodeName , akind ,
333                                          NodeFirstCreation , NodeLastModification  ,
334                                          NodeEditorRelease , NodeAuthor ,
335                                          NodeComment , GeneratedName ,
336                                          NodeX , NodeY ,
337                                          Graph_prof_debug , Graph_fdebug ) ;
338     _ComputingNode = (GraphBase::ComputingNode *) _EndOfLoopNode ;
339     _GOTONode = (GraphBase::GOTONode *) _ComputingNode ;
340     _InLineNode = (GraphBase::InLineNode *) _ComputingNode ;
341     break ;
342   }
343   case SUPERV::SwitchNode : {
344     cdebug << "GraphExecutor::InNode::InNode SUPERV::SwitchNode : " << NodeName ;
345     _SwitchNode = new GraphBase::SwitchNode( ORB , ptrNamingService ,
346                                              aFuncName[0].c_str() , *aPythonFunction[0] ,
347                                              NodeName , akind ,
348                                              NodeFirstCreation , NodeLastModification  ,
349                                              NodeEditorRelease , NodeAuthor ,
350                                              NodeComment , GeneratedName ,
351                                              NodeX , NodeY ,
352                                              Graph_prof_debug , Graph_fdebug ) ;
353     _ComputingNode = (GraphBase::ComputingNode *) _SwitchNode ;
354     _GOTONode = (GraphBase::GOTONode *) _ComputingNode ;
355     _InLineNode = (GraphBase::InLineNode *) _ComputingNode ;
356     break ;
357   }
358   case SUPERV::EndSwitchNode : {
359     cdebug << "GraphEditor::InNode::InNode SUPERV::EndOfSwitchNode : " << NodeName ;
360     _EndOfSwitchNode = new GraphBase::EndOfSwitchNode(
361                                              ORB , ptrNamingService ,
362                                              aFuncName[0].c_str() , *aPythonFunction[0] ,
363                                              NodeName , akind ,
364                                              NodeFirstCreation , NodeLastModification  ,
365                                              NodeEditorRelease , NodeAuthor ,
366                                              NodeComment , GeneratedName ,
367                                              NodeX , NodeY ,
368                                              Graph_prof_debug , Graph_fdebug ) ;
369     _ComputingNode = (GraphBase::ComputingNode *) _EndOfSwitchNode ;
370     _GOTONode = (GraphBase::GOTONode *) _ComputingNode ;
371     _InLineNode = (GraphBase::InLineNode *) _ComputingNode ;
372     break ;
373   }
374   case SUPERV::DataFlowGraph : {
375     cdebug << "GraphEditor::InNode::InNode SUPERV::DataFlowGraph ERROR : " << NodeName ;
376   }
377   case SUPERV::DataStreamGraph : {
378     cdebug << "GraphEditor::InNode::InNode SUPERV::DataStreamGraph ERROR : " << NodeName ;
379   }
380   case SUPERV::UnknownNode : {
381     cdebug << "GraphEditor::InNode::InNode SUPERV::UnknownNode ERROR : " << NodeName ;
382   }
383   }
384   cdebug << "GraphExecutor::InNode::InNode "  << (void *) this
385          << " _ComputingNode " << (void *) _ComputingNode  ;
386   _ComputingNode->InNode( this ) ;
387 }
388
389 GraphExecutor::InNode::~InNode() {
390 }
391
392 //JR 15.04.2005 Debug PAL8624 RetroConception :
393 #if 0
394 void GraphExecutor::InNode::LockDataWait() {
395 //  cdebug_in << "GraphExecutor::InNode::LockDataWait " << endl ;
396   if ( pthread_mutex_lock( &_MutexDataWait ) ) {
397     perror("Ready pthread_mutex_lock ") ;
398     exit( 0 ) ;
399   }
400   _DataWait = true ;
401 //  cdebug_out << "GraphExecutor::InNode::LockDataWait " << endl ;
402 }
403 void GraphExecutor::InNode::UnLockDataWait() {
404 //  cdebug_in << "GraphExecutor::InNode::UnLockDataWait " << endl ;
405   _DataWait = false ;
406   if ( pthread_mutex_unlock( &_MutexDataWait ) ) {
407     perror("Ready pthread_mutex_unlock ") ;
408     exit( 0 ) ;
409   }
410 //  cdebug_out << "GraphExecutor::InNode::UnLockDataWait " << endl ;
411 }
412 #endif
413
414 //JR 15.04.2005 Debug PAL8624 RetroConception :
415 void GraphExecutor::InNode::LockDataReady() {
416 //  cdebug_in << pthread_self() << "/" << ThreadNo()
417 //            << "GraphExecutor::InNode::LockDataReady : " << Name() << " _MutexDataReadyLocked "
418 //            << _MutexDataReadyLocked << " HasAllDataReady " << HasAllDataReady() << endl ;
419   if ( pthread_mutex_lock( &_MutexDataReady ) ) {
420     perror("MutexDataReady pthread_mutex_lock ") ;
421     exit( 0 ) ;
422   }
423   _MutexDataReadyLocked = true ;
424 //  cdebug_out << pthread_self() << "/" << ThreadNo()
425 //             << "GraphExecutor::InNode::LockDataReady : " << Name() << endl ;
426 }
427 void GraphExecutor::InNode::UnLockDataReady() {
428 //  cdebug_in << pthread_self() << "/" << ThreadNo()
429 //            << "GraphExecutor::InNode::UnLockDataReady : " << Name() << " _MutexDataReadyLocked "
430 //            << _MutexDataReadyLocked << " HasAllDataReady " << HasAllDataReady() << endl ;
431   if ( pthread_mutex_unlock( &_MutexDataReady ) ) {
432     perror("MutexDataReady pthread_mutex_unlock ") ;
433     exit( 0 ) ;
434   }
435   _MutexDataReadyLocked = false ;
436 //  cdebug_out << pthread_self() << "/" << ThreadNo()
437 //             << "GraphExecutor::InNode::UnLockDataReady : " << Name() << endl ;
438 }
439
440 Engines::Component_var GraphExecutor::InNode::Component() const {
441   if ( IsFactoryNode() ) {
442     return _FactoryNode->Component() ;
443   }
444   else {
445 //JR 30.03.2005    CORBA::Any const * anAnyComponent = GetChangeNodeInPort( 0 )->GetOutPort()->Value() ; // this
446     const CORBA::Any anAnyComponent = GetChangeNodeInPort( 0 )->GetOutPort()->Value() ; // this
447     CORBA::Object_ptr obj ;
448     try {
449 //JR 30.03.2005      *anAnyComponent >>= obj ;
450       anAnyComponent >>= obj ;
451       return Engines::Component::_narrow( obj ) ;
452     }
453     catch( ... ) {
454       cdebug << "GraphExecutor::InNode::Component Component catch" << endl ;
455     }
456   }
457   return Engines::Component::_nil() ;
458 }
459
460 Engines::Container_var GraphExecutor::InNode::Container() const {
461   if ( IsFactoryNode() ) {
462     return _FactoryNode->Container() ;
463   }
464   return Engines::Container::_nil() ;
465 }
466
467
468 bool GraphExecutor::InNode::Ping() {
469   cdebug_in << "GraphExecutor::InNode::Ping" << endl;
470   bool RetVal = true ;
471   if ( IsFactoryNode() ) {
472     RetVal = !CORBA::is_nil( _FactoryNode->Component() ) ;
473     if ( RetVal ) {
474       if ( State() != GraphExecutor::SuspendedExecutingState ) {
475         try {
476           _FactoryNode->Component()->ping() ;
477         }
478         catch( ... ) {
479           cdebug << "InNode::Ping() ERROR catched" << endl ;
480           State( GraphExecutor::ErroredState ) ;
481           _OutNode->State( GraphExecutor::ErroredState ) ;
482           RetVal = false ;
483         }
484       }
485       else {
486         RetVal = false ;
487       }
488     }
489     else {
490       cdebug << "GraphExecutor::InNode::Ping Component ObjRef is NIL" << endl;
491     }
492   }
493   cdebug_out << "GraphExecutor::InNode::Ping" << endl ;
494   return RetVal ;
495 }
496
497 void GraphExecutor::InNode::NewThread( pthread_t aThread ) {
498   ThreadNo ( aThread ) ; 
499   if ( aThread )
500     _OutNode->NewThread() ;
501 }
502 void GraphExecutor::InNode::ExitThread() {
503   ThreadNo( 0 ) ;
504   _OutNode->ExitThread() ;
505
506
507 bool GraphExecutor::InNode::Suspend() {
508   cdebug_in << "GraphExecutor::InNode::Suspend " << Name() << " " << ThreadNo()
509             << " " << Automaton()->StateName( State() ) << endl;
510   bool RetVal = false ;
511   if ( IsDone() ) {
512 //If loop we need to suspend also    ControlState( SUPERV::VoidState ) ;
513     ControlState( SUPERV::ToSuspendState ) ;
514     RetVal = true ;
515     if ( _OutNode->IsDone() ) {
516       ControlState( SUPERV::VoidState ) ;
517       RetVal = false ;
518     }
519   }
520   else if ( IsWaiting() || IsReady() ) {
521     ControlState( SUPERV::ToSuspendState ) ;
522     RetVal = true ;
523   }
524   else  if ( IsRunning() ) {
525     ControlState( SUPERV::ToSuspendState ) ;
526     if ( IsFactoryNode() || IsComputingNode() ) {
527 // We have to suspend in the container of that node
528       int TrySuspend = 10 ;
529       while ( TrySuspend ) {
530         if ( !CORBA::is_nil( Component() ) ) {
531 // We can call that component
532           try {
533             RetVal = Component()->Suspend_impl() ;
534           }
535           catch( ... ) {
536             cdebug << "InNode::Suspend() ERROR catched" << endl ;
537             State( GraphExecutor::ErroredState ) ;
538             _OutNode->State( GraphExecutor::ErroredState ) ;
539             RetVal = false ;
540             TrySuspend = 1 ;
541           }
542           cdebug << "Component()->Suspend_impl() returns status " << RetVal << endl ;
543           if ( RetVal ) {
544             if ( IsRunning() ) {
545               cdebug << pthread_self() << "GraphExecutor::InNode::Suspend_impl " << Name()
546                      << " --> thread" << ThreadNo() << " SuspendEvent " << endl;
547               SendEvent( GraphExecutor::SuspendEvent ) ;
548               cdebug << pthread_self() << "GraphExecutor::InNode::Suspended_impl in Container"
549                      << Name() << " --> thread" << ThreadNo() << endl;
550               TrySuspend = 1 ;
551             }
552             else if ( IsDone() ) {
553               ControlState( SUPERV::VoidState ) ;
554               RetVal = false ; // Too late ...
555               TrySuspend = 1 ;
556             }
557             else {
558               cdebug << "InNode::Suspend component Suspended and !IsDone and !IsRunning !"
559                      << endl ;
560               MESSAGE("InNode::Suspend component Suspended and !IsDone and !IsRunning !") ;
561               TrySuspend = 1 ;
562             }
563           }
564           else {
565 // Suspend in the Container failed : it is always false if it is a Python Container
566             cdebug << "InNode::Suspend cannot Suspend component ! Python Component ?"
567                    << endl ;
568             if ( TrySuspend == 1 ) {
569               if ( IsSuspended() ) {
570                 RetVal = true ;
571               }
572               else {
573                 RetVal = false ;
574               }
575             }
576           }
577         }
578         else {
579           cdebug << "InNode::Suspend with nilComponent while RunningState !. Loading Component ?"
580                  << endl ;
581 // Wait for the end of loading of the component
582           while ( IsLoading() ) {
583             sleep( 1 ) ;
584           }
585           if ( TrySuspend == 1 ) {
586             if ( IsSuspended() ) {
587               RetVal = true ;
588             }
589             else {
590               RetVal = false ;
591             }
592           }
593         }
594         TrySuspend -= 1 ;
595         if ( TrySuspend ) {
596           sleep( 1 ) ;
597         }
598       }
599     }
600     else if ( IsMacroNode() ) {
601 // It should be like that but it is not completely implemented
602       GraphBase::Graph * aGraph = (GraphBase::Graph * ) GraphMacroNode()->CoupledNode() ;
603       RetVal = aGraph->GraphEditor()->Executor()->Suspend() ;
604       if ( RetVal ) {
605         State( GraphExecutor::SuspendedState ) ;
606       }
607     }
608     else {
609 // Now we can suspend an InLineNode with the handler of the SuperVision Container
610       // asv : 20.01.05 : changes involved with switching to old (HEAD) KERNEL 
611       State( GraphExecutor::ErroredState ) ;
612       _OutNode->State( GraphExecutor::ErroredState ) ;      RetVal = false;
613       cdebug << "Suspend of InLine nodes is NOT implemented." << endl;
614       MESSAGE( "Suspend of InLine nodes is NOT implemented." );
615       /*   
616       if ( pthread_kill( _OutNode->MainThreadId() , SIGUSR2 ) == -1 ) {
617         perror("Suspend pthread_kill error") ;
618         State( GraphExecutor::ErroredState ) ;
619         _OutNode->State( GraphExecutor::ErroredState ) ;
620         RetVal = false ;
621       }
622       else {
623         RetVal = true ;
624       }
625       if ( RetVal ) {
626         if ( IsRunning() ) {
627           cdebug << pthread_self() << "GraphExecutor::InNode::Suspend " << Name()
628                  << " --> thread" << ThreadNo() << " SuspendEvent " << endl;
629           SendEvent( GraphExecutor::SuspendEvent ) ;
630           cdebug << pthread_self() << "GraphExecutor::InNode::Suspended in SuperVision Container"
631                  << Name() << " --> thread" << ThreadNo() << endl;
632         }
633         else if ( IsDone() ) {
634           ControlState( SUPERV::VoidState ) ;
635           RetVal = false ; // Too late ...
636         }
637         else {
638           cdebug << "component Suspended and !IsDone and !IsRunning !"
639                  << endl ;
640         }
641       }
642       */
643     }
644   }
645   else {
646     cdebug << "Suspend and IsDone " << IsDone() << " and IsRunning " << IsRunning()
647            << " and IsWaiting " << IsWaiting() << " and IsReady " << IsReady()
648            << " ?" << endl ;
649     RetVal = false ;
650   }
651   cdebug_out << "GraphExecutor::InNode::Suspend " << RetVal << " "
652              << Automaton()->StateName( State() ) << endl ;
653   return RetVal ;
654 }
655
656 bool GraphExecutor::InNode::ContainerKill() {
657   cdebug_in << "GraphExecutor::InNode::ContainerKill " << Name() << " "
658             << ThreadNo() << endl;
659   bool RetVal ;
660   if ( IsFactoryNode() ) {
661     Kill() ;
662     RetVal = Container()->Kill_impl() ;
663   }
664   cdebug_out << "GraphExecutor::InNode::ContainerKill" << endl ;
665   return RetVal ;
666 }
667
668 bool GraphExecutor::InNode::Kill() {
669   cdebug_in << "GraphExecutor::InNode::Kill " << Name() << " " << ThreadNo() << " " 
670             << Automaton()->StateName( State() ) << " Threads " << _OutNode->Threads()
671             << " SuspendedThreads " << _OutNode->SuspendedThreads()
672             << " EventQSize " << _OutNode->EventQSize() << endl;
673   bool RetVal ;
674   if ( IsDone() ) {
675     ControlState( SUPERV::ToKillState ) ; // if loop
676     if ( _OutNode->IsDone() ) {
677       ControlState( SUPERV::VoidState ) ;
678     }
679     RetVal = false ;
680   }
681   else {
682     ControlState( SUPERV::ToKillState ) ;
683     if ( IsDone() ) {
684       if ( _OutNode->IsDone() ) {
685         ControlState( SUPERV::VoidState ) ;
686       }
687       RetVal = false ;
688     }
689     else {
690       if ( IsRunning() ) {
691         if ( IsFactoryNode() || IsComputingNode() ) {
692 // We have to suspend in the container of that node
693           int TryKill = 10 ;
694           while ( TryKill ) {
695             if ( !CORBA::is_nil( Component() ) ) {
696 // We can call that component
697               try {
698                 RetVal = Component()->Kill_impl() ;
699               }
700               catch( ... ) {
701                 cdebug << "InNode::Kill_impl ERROR catched" << endl ;
702                 State( GraphExecutor::ErroredState ) ;
703                 _OutNode->State( GraphExecutor::ErroredState ) ;
704                 RetVal = false ;
705                 TryKill = 1 ;
706               }
707               cdebug << "Component()->Kill_impl() returns status " << RetVal << endl ;
708               if ( RetVal ) {
709                 if ( IsRunning() ) {
710                   cdebug << pthread_self() << "GraphExecutor::InNode::Kill_impl " << Name()
711                          << " --> thread" << ThreadNo() << " KillEvent " << endl;
712                   SendEvent( GraphExecutor::KillEvent ) ;
713                   cdebug << pthread_self() << "GraphExecutor::InNode::Killed_impl in Container"
714                          << Name() << " --> thread" << ThreadNo() << endl;
715                   TryKill = 1 ;
716                 }
717                 else if ( IsDone() ) {
718                   ControlState( SUPERV::VoidState ) ;
719                   RetVal = false ; // Too late ...
720                   TryKill = 1 ;
721                 }
722                 else {
723                   cdebug << "Kill component Killed and !IsDone and !IsRunning !"
724                          << endl ;
725                   TryKill = 1 ;
726                 }
727               }
728               else {
729 //  Kill in the Container failed : it is always false if it is a Python Container
730                 cdebug << "InNode::Suspend cannot  Kill component ! Python Component ?"
731                        << endl ;
732                 if ( TryKill == 1 ) {
733                   if ( IsKilled() ) {
734                     RetVal = true ;
735                   }
736                   else {
737                     RetVal = false ;
738                   }
739                 }
740               }
741             }
742             else {
743               cdebug << "InNode::Kill with nilComponent while RunningState !. Loading Component ?"
744                      << endl ;
745 // Wait for the end of loading of the component
746               while ( IsLoading() ) {
747                 sleep( 1 ) ;
748               }
749               if ( TryKill == 1 ) {
750                 if ( IsKilled() ) {
751                   RetVal = true ;
752                 }
753                 else {
754                   RetVal = false ;
755                 }
756               }
757             }
758             TryKill -= 1 ;
759             if ( TryKill ) {
760               sleep( 1 ) ;
761             }
762           }
763         }
764         else if ( IsMacroNode() ) {
765 // It should be like that but it is not completely implemented
766           GraphBase::Graph * aGraph = (GraphBase::Graph * ) GraphMacroNode()->CoupledNode() ;
767           RetVal = aGraph->GraphEditor()->Executor()->Kill() ;
768           if ( RetVal ) {
769             State( GraphExecutor::KilledState ) ;
770           }
771         }
772         else {
773 //PAL6886
774 // Now we can kill an InLineNode with the handler of the SuperVision Container
775           // asv : 20.01.05 : changes involved with switching to old (HEAD) KERNEL    
776           State( GraphExecutor::ErroredState ) ;
777           _OutNode->State( GraphExecutor::ErroredState ) ;
778           RetVal = false ;
779           cdebug << "Kill of InLine nodes is NOT implemented." << endl;
780           MESSAGE( "Kill of InLine nodes is NOT implemented." );
781           /*
782           cdebug << pthread_self() << "Kill of InLineNode " << Name() << " MainThreadId "
783                  << _OutNode->MainThreadId() << " :" << endl ;
784           MESSAGE( pthread_self() << "Kill of InLineNode " << Name() << " MainThreadId "
785                  << _OutNode->MainThreadId() << " :" ) ;
786           if ( pthread_kill( _OutNode->MainThreadId() , SIGINT ) == -1 ) {
787 // python signals run only in main thread ...
788             perror("Kill pthread_kill error") ;
789             State( GraphExecutor::ErroredState ) ;
790             _OutNode->State( GraphExecutor::ErroredState ) ;
791             RetVal = false ;
792           }
793           else {
794             cdebug << pthread_self() << "pthread_kill of InLineNode " << Name()
795                    << " done. MainThreadId " << _OutNode->MainThreadId() << endl ;
796             MESSAGE( pthread_self() << "pthread_kill of InLineNode " << Name()
797                    << " done. MainThreadId " << _OutNode->MainThreadId() ) ;
798             RetVal = true ;
799           }
800           */
801         }
802       }
803       else if ( IsSuspended() ) {
804         cdebug << pthread_self() << "GraphExecutor::InNode::Kill " << Name()
805                << " --> thread" << ThreadNo() << " Resume()" << endl;
806         if ( Resume() ) {
807           RetVal = Kill() ;
808         }
809         else {
810           RetVal = false ;
811         }
812       }
813       else if ( IsWaiting() ) {
814         RetVal = false ;
815       }
816       else if ( IsReady() ) {
817         RetVal = true ;
818       }
819       else {
820        cdebug << "Kill and IsDone " << IsDone() << " and IsRunning " << IsRunning()
821               << " and IsWaiting " << IsWaiting() << " and IsReady " << IsReady()
822               << " ?" << endl ;
823         RetVal = false ;
824       }
825     }
826   }
827 // PAL8003
828 // JR 24.03.2005 Debug it may have be killed if we have Suspend-Resume-Kill
829   if ( !RetVal && IsKilled() ) {
830     RetVal = true ;
831   }
832   cdebug_out << "GraphExecutor::InNode::Kill " << Name() << " " << ThreadNo() << " " 
833              << Automaton()->StateName( State() ) << " Threads " << _OutNode->Threads()
834              << " SuspendedThreads " << _OutNode->SuspendedThreads()
835              << " EventQSize " << _OutNode->EventQSize() << " returns " << RetVal << endl ;
836   return RetVal ;
837 }
838
839 bool GraphExecutor::InNode::KillDone() {
840   cdebug_in << "GraphExecutor::InNode::KillDone " << Name() << " " << ThreadNo()
841             << endl;
842   bool RetVal ;
843   if ( ControlState() == SUPERV::ToKillDoneState || IsDone() ) {
844     RetVal = false ;
845   }
846   else {
847     ControlState( SUPERV::ToKillDoneState ) ;
848     if ( IsDone() ) {
849       if ( _OutNode->IsDone() ) {
850         ControlState( SUPERV::VoidState ) ;
851       }
852       RetVal = false ;
853     }
854     else {
855       if ( IsRunning() ) {
856         RetVal = true ;
857       }
858       else if ( IsWaiting() ) {
859         RetVal = true ;
860       }
861       else {
862         cdebug << "KillDone and !IsDone and !IsRunning and !IsWaiting ?"
863                << endl ;
864         RetVal = false ;
865       }
866     }
867   }
868   cdebug_out << "GraphExecutor::InNode::KillDone" << endl ;
869   return RetVal ;
870 }
871
872 bool GraphExecutor::InNode::Stop() {
873   cdebug_in << "GraphExecutor::InNode::Stop " << Name() << " " << ThreadNo()
874             << endl;
875   bool RetVal ;
876   if ( ControlState() == SUPERV::ToStopState || IsDone() ) {
877     RetVal = false ;
878   }
879   else {
880     ControlState( SUPERV::ToStopState ) ;
881     if ( IsDone() ) {
882       if ( _OutNode->IsDone() ) {
883         ControlState( SUPERV::VoidState ) ;
884       }
885       RetVal = false ;
886     }
887     else {
888       if ( IsRunning() ) {
889         if ( IsFactoryNode() || IsComputingNode() ) {
890           if ( !CORBA::is_nil( Component() ) ) {
891             try {
892               RetVal = Component()->Stop_impl() ;
893             }
894             catch( ... ) {
895               cdebug << "InNode::Stop() ERROR catched" << endl ;
896               State( GraphExecutor::ErroredState ) ;
897               _OutNode->State( GraphExecutor::ErroredState ) ;
898               RetVal = false ;
899             }
900             if ( RetVal ) {
901               if ( IsRunning() ) {
902                 SendEvent( GraphExecutor::StopEvent ) ;
903               }
904               else if ( IsDone() ) {
905                 ControlState( SUPERV::VoidState ) ;
906                 RetVal = false ; // Too late ...
907               }
908               else {
909                 cdebug << "component Suspended and !IsDone and !IsRunning !"
910                        << endl ;
911               }
912             }
913           }
914           else {
915             cdebug << "Suspend cannot Stop component ! Python Component ?" << endl ;
916             RetVal = false ;
917           }
918         }
919         else {
920           cdebug << "Suspend with nilComponent while RunningState !" << endl ;
921           RetVal = false ;
922         }
923       }
924       else if ( IsWaiting() ) {
925         RetVal = true ;
926       }
927       else {
928         cdebug << "Suspend and !IsDone and !IsRunning and !IsWaiting ?"
929                << endl ;
930         RetVal = false ;
931       }
932     }
933   }
934   cdebug_out << "GraphExecutor::InNode::Stop" << endl ;
935   return RetVal ;
936 }
937
938 bool GraphExecutor::InNode::SuspendDone() {
939   cdebug_in << "GraphExecutor::InNode::SuspendDone " << Name() << " "
940             << ThreadNo() << endl;
941   bool RetVal ;
942   if ( ControlState() == SUPERV::ToSuspendDoneState || IsDone() ) {
943     RetVal = false ;
944   }
945   else {
946     ControlState( SUPERV::ToSuspendDoneState ) ;
947     if ( IsDone() ) {
948       if ( _OutNode->IsDone() ) {
949         ControlState( SUPERV::VoidState ) ;
950       }
951       RetVal = false ;
952     }
953     else {
954       RetVal = true ;
955     }
956   }
957   cdebug_out << "GraphExecutor::InNode::SuspendDone" << endl ;
958   return RetVal ;
959 }
960
961 bool GraphExecutor::InNode::Resume() {
962   cdebug_in << pthread_self() << "/" << ThreadNo()
963             << " GraphExecutor::InNode::Resume " << Name() << " "
964             << Automaton()->StateName( State() ) << endl;
965   bool RetVal = false ;
966   if ( IsSuspended() ) {
967     if ( State() == GraphExecutor::SuspendedReadyState ) {
968       ResumeAction( GraphExecutor::ToResumeEvent ) ;
969       RetVal = true ;
970     }
971     else if ( State() == GraphExecutor::SuspendedExecutingState ) {
972       if ( IsFactoryNode() || IsComputingNode() ) {
973         if ( pthread_mutex_lock( &_MutexWait ) ) {
974           perror("ResumeAction pthread_mutex_lock ") ;
975           exit( 0 ) ;
976         }
977         try {
978           RetVal = Component()->Resume_impl() ;
979           if ( RetVal ) {
980             State( GraphExecutor::ExecutingState ) ;
981           }
982         }
983         catch( ... ) {
984           cdebug << "InNode::Resume() ERROR catched" << endl ;
985           State( GraphExecutor::ErroredState ) ;
986           _OutNode->State( GraphExecutor::ErroredState ) ;
987           RetVal = false ;
988         }
989         if ( pthread_mutex_unlock( &_MutexWait ) ) {
990           perror("ResumeAction pthread_mutex_unlock ") ;
991           exit( 0 ) ;
992         }
993       }
994       else if ( IsMacroNode() ) {
995         cdebug << "Suspend of MacroNode not yet implemented ? Trying" << endl ;
996         GraphBase::Graph * aGraph = (GraphBase::Graph * ) GraphMacroNode()->CoupledNode() ;
997         RetVal = aGraph->GraphEditor()->Executor()->Resume() ;
998         if ( RetVal ) {
999           State( GraphExecutor::ExecutingState ) ;
1000         }
1001       }
1002       else {
1003 // Resume of InLinePythonNode in the Node of the SuperVisionContainer ...
1004         // asv : 20.01.05 : changes involved with switching to old (HEAD) KERNEL    
1005         State( GraphExecutor::ErroredState ) ;
1006         _OutNode->State( GraphExecutor::ErroredState ) ;
1007         RetVal = false ;
1008         cdebug << "Resume of InLine nodes is NOT implemented." << endl;
1009         MESSAGE( "Resume of InLine nodes is NOT implemented." );
1010         /*
1011         cdebug << ThreadNo() << "/" << pthread_self()
1012                << "Resume of InLineNode pthread_kill" << Name() << endl ;
1013         if ( pthread_kill( _OutNode->MainThreadId() , SIGCONT ) == -1 ) {
1014           perror("Resume pthread_kill error") ;
1015           State( GraphExecutor::ErroredState ) ;
1016           _OutNode->State( GraphExecutor::ErroredState ) ;
1017           RetVal = false ;
1018         }
1019         else {
1020           State( GraphExecutor::ExecutingState ) ;
1021           RetVal = true ;
1022         }
1023         */
1024       }
1025     }
1026     else if ( State() == GraphExecutor::SuspendedSuccessedState ) {
1027       ResumeAction( GraphExecutor::ResumeEvent ) ;
1028       RetVal = true ;
1029     }
1030     else if ( State() == GraphExecutor::SuspendedErroredState ) {
1031       ResumeAction( GraphExecutor::ResumeEvent ) ;
1032       RetVal = true ;
1033     }
1034     else {
1035       cdebug << "GraphExecutor::InNode::Resume Not SuspendedReady/Executing/Successed/ErroredState "
1036              << Automaton()->StateName( State() ) << endl ;
1037       RetVal = false ;
1038     }
1039   }
1040   else {
1041     cdebug << "GraphExecutor::InNode::Resume Not Suspended State "
1042            << Automaton()->StateName( State() ) << endl ;
1043     RetVal = false ;
1044   }
1045   if ( ControlState() == SUPERV::ToSuspendStartState ) {
1046     ControlState( SUPERV::VoidState ) ;
1047   }
1048
1049 #if 0
1050   if ( ControlState() == SUPERV::ToSuspendRunState ||
1051        ( ControlState() == SUPERV::ToSuspendState &&
1052          State() == GraphExecutor::SuspendedReadyState) ) {
1053     if ( IsSuspended() ) {
1054       if ( State() == GraphExecutor::SuspendedReadyState ) {
1055         ResumeAction() ;
1056         RetVal = true ;
1057       }
1058       else if ( State() == GraphExecutor::SuspendedExecutingState ) {
1059         ResumeAction() ;
1060         RetVal = Component()->Resume_impl() ;
1061       }
1062       else {
1063         cdebug << "GraphExecutor::InNode::Resume State "
1064                << Automaton()->StateName( State() ) << endl ;
1065         RetVal = false ;
1066       }
1067       if ( ControlState() != SUPERV::ToSuspendState ) {
1068         ControlState( SUPERV::VoidState ) ;
1069       }
1070     }
1071     else if ( IsRunning() ) {
1072       RetVal = true ;
1073     }
1074     else if ( IsWaiting() ) {
1075       ControlState( SUPERV::VoidState ) ;
1076       RetVal = true ;
1077     }
1078     else if ( IsDone() ) {
1079       RetVal = true ;
1080     }
1081   }
1082   else if ( ControlState() == SUPERV::ToSuspendDoneState ||
1083             ( ControlState() == SUPERV::ToSuspendState &&
1084               State() == GraphExecutor::SuspendedSuccessedState) ) {
1085     if ( IsSuspended() ) {
1086       if ( State() == GraphExecutor::SuspendedSuccessedState ) {
1087         ResumeAction() ;
1088         RetVal = true ;
1089       }
1090       else if ( State() == GraphExecutor::SuspendedErroredState ) {
1091         ResumeAction() ;
1092         RetVal = true ;
1093       }
1094       else {
1095         cdebug << "GraphExecutor::InNode::Resume State " << State() << endl ;
1096         RetVal = false ;
1097       }
1098       if ( ControlState() != SUPERV::ToSuspendState ) {
1099         ControlState( SUPERV::VoidState ) ;
1100       }
1101     }
1102     else if ( IsRunning() ) {
1103       ControlState( SUPERV::VoidState ) ;
1104       RetVal = true ;
1105     }
1106     else if ( IsWaiting() ) {
1107       ControlState( SUPERV::VoidState ) ;
1108       RetVal = true ;
1109     }
1110     else if ( IsDone() ) {
1111       ControlState( SUPERV::VoidState ) ;
1112       RetVal = true ;
1113     }
1114   }
1115 #endif
1116   cdebug_out << "GraphExecutor::InNode::Resume " << Name() << " " << RetVal << " "
1117              << Automaton()->StateName( State() ) << endl ;
1118   return RetVal ;
1119 }
1120
1121 bool GraphExecutor::InNode::IsWaiting() {
1122   bool aret = false ;
1123 //  cdebug_in << "GraphExecutor::InNode::IsWaiting " << Name() << endl;
1124   GraphExecutor::AutomatonState aState = State() ;
1125   if ( aState == GraphExecutor::DataUndefState ||
1126        aState == GraphExecutor::DataWaitingState ||
1127        aState == GraphExecutor::SuspendedReadyState )
1128 //       aState == GraphExecutor::SuspendedExecutingState ||
1129 //       aState == GraphExecutor::SuspendedSuccessedState ||
1130 //       aState == GraphExecutor::SuspendedErroredState ||
1131 //       aState == GraphExecutor::SuspendedState
1132     aret = true ;
1133 //  cdebug_out << "GraphExecutor::InNode::IsWaiting" << endl ;
1134   return aret ;
1135 }
1136
1137 bool GraphExecutor::InNode::IsReady() {
1138   bool aret = false ;
1139 //  cdebug_in << "GraphExecutor::InNode::IsReady " << Name() << endl;
1140   GraphExecutor::AutomatonState aState = State() ;
1141 //  if ( aState == GraphExecutor::DataUndefState ||
1142 //       aState == GraphExecutor::DataWaitingState ||
1143   if ( aState == GraphExecutor::DataReadyState ||
1144        aState == GraphExecutor::ResumedReadyState )
1145     aret = true ;
1146 //  cdebug_out << "GraphExecutor::InNode::IsReady" << endl ;
1147   return aret ;
1148 }
1149
1150 bool GraphExecutor::InNode::IsRunning() {
1151   bool aret = false ;
1152 //  cdebug_in << "GraphExecutor::InNode::IsRunning " << Name() << endl;
1153   GraphExecutor::AutomatonState aState = State() ;
1154   if ( aState == GraphExecutor::ExecutingState ||
1155        aState == GraphExecutor::ResumedExecutingState )
1156     aret = true ;
1157 //  cdebug_out << "GraphExecutor::InNode::IsRunning" << endl ;
1158   return aret ;
1159 }
1160
1161 bool GraphExecutor::InNode::IsDone() {
1162   bool aret = false ;
1163 //  cdebug_in << "GraphExecutor::InNode::IsDone " << Name() << endl;
1164   GraphExecutor::AutomatonState aState = State() ;
1165   if ( aState == GraphExecutor::KilledReadyState ||
1166        aState == GraphExecutor::StoppedReadyState ||
1167        aState == GraphExecutor::KilledExecutingState ||
1168        aState == GraphExecutor::StoppedExecutingState ||
1169        aState == GraphExecutor::SuspendedSuccessedState ||
1170        aState == GraphExecutor::SuspendedErroredState ||
1171 //       aState == GraphExecutor::SuccessedExecutingState ||
1172 //       aState == GraphExecutor::ErroredExecutingState ||
1173        aState == GraphExecutor::SuccessedState ||
1174        aState == GraphExecutor::ErroredState ||
1175        aState == GraphExecutor::ResumedSuccessedState ||
1176        aState == GraphExecutor::ResumedErroredState ||
1177        aState == GraphExecutor::KilledSuccessedState ||
1178        aState == GraphExecutor::StoppedSuccessedState )
1179     aret = true ;
1180 //  cdebug_out << "GraphExecutor::InNode::IsDone" << endl ;
1181   return aret ;
1182 }
1183
1184 bool GraphExecutor::InNode::IsSuspended() {
1185   bool aret = false ;
1186 //  cdebug_in << "GraphExecutor::InNode::IsSuspended " << Name() << endl;
1187   GraphExecutor::AutomatonState aState = State() ;
1188   if ( aState == GraphExecutor::SuspendedReadyState ||
1189        aState == GraphExecutor::SuspendedExecutingState ||
1190        aState == GraphExecutor::SuspendedSuccessedState ||
1191        aState == GraphExecutor::SuspendedErroredState ||
1192        aState == GraphExecutor::SuspendedState )
1193     aret = true ;
1194 //  cdebug_out << "GraphExecutor::InNode::IsSuspended" << endl ;
1195   return aret ;
1196 }
1197 bool GraphExecutor::InNode::IsKilled() {
1198   bool aret = false ;
1199 //  cdebug_in << "GraphExecutor::InNode::IsKilled " << Name() << endl;
1200   GraphExecutor::AutomatonState aState = State() ;
1201   if ( aState == GraphExecutor::KilledReadyState ||
1202        aState == GraphExecutor::KilledExecutingState ||
1203        aState == GraphExecutor::KilledSuccessedState ||
1204        aState == GraphExecutor::KilledErroredState ||
1205        aState == GraphExecutor::KilledState )
1206     aret = true ;
1207 //  cdebug_out << "GraphExecutor::InNode::IsKilled" << endl ;
1208   return aret ;
1209 }
1210 bool GraphExecutor::InNode::IsStopped() {
1211   bool aret = false ;
1212 //  cdebug_in << "GraphExecutor::InNode::IsStopped " << Name() << endl;
1213   GraphExecutor::AutomatonState aState = State() ;
1214   if ( aState == GraphExecutor::StoppedReadyState ||
1215        aState == GraphExecutor::StoppedExecutingState ||
1216        aState == GraphExecutor::StoppedSuccessedState ||
1217        aState == GraphExecutor::StoppedErroredState ||
1218        aState == GraphExecutor::StoppedState )
1219     aret = true ;
1220 //  cdebug_out << "GraphExecutor::InNode::IsStopped" << endl ;
1221   return aret ;
1222 }
1223
1224 bool GraphExecutor::InNode::StateWait( SUPERV::GraphState aState ) {
1225   bool RetVal = false ;
1226   if ( pthread_mutex_lock( &_MutexWait ) ) {
1227     perror("pthread_mutex_lock _Wait") ;
1228     exit( 0 ) ;
1229   }
1230   switch ( aState ) {
1231   case SUPERV::ReadyState : {
1232     RetVal = IsReady() ;
1233     cdebug_in << pthread_self() << " StateWait( Ready ) " << RetVal
1234               << " " << Automaton()->StateName( _currentState )
1235               << " pthread_cond_wait _ReadyWait " << Name() << endl ;
1236     while ( !RetVal && !IsDone() ) {
1237       cdebug << pthread_self() << " pthread_cond_wait ReadyWait" << endl ;
1238       pthread_cond_wait( &_ReadyWait , &_MutexWait );
1239       RetVal = IsReady() ;
1240       cdebug << pthread_self() << " pthread_cond_waited ReadyWait "
1241              << Automaton()->StateName( _currentState ) << " " << RetVal
1242              << endl ;
1243     }
1244     cdebug_out << pthread_self() << " StateWait( Ready ) " << RetVal
1245                << " " << Automaton()->StateName( _currentState )
1246                << " pthread_cond_wait _ReadyWait " << Name() << endl ;
1247     break ;
1248   }
1249   case SUPERV::RunningState : {
1250     RetVal = IsRunning() ;
1251     cdebug_in << pthread_self() << " StateWait( Running ) " << RetVal
1252               << " " << Automaton()->StateName( _currentState )
1253               << " pthread_cond_wait _RunningWait " << Name() << endl ;
1254     while ( !RetVal && !IsDone() ) {
1255       cdebug << pthread_self() << " pthread_cond_wait RunningWait " << Name() << endl ;
1256       pthread_cond_wait( &_RunningWait , &_MutexWait );
1257 //We may have pthread_cond_waited but !IsRunning and !IsDone :
1258       RetVal = IsRunning() || State() == GraphExecutor::SuccessedExecutingState ||
1259                State() == GraphExecutor::ErroredExecutingState ;
1260       cdebug << pthread_self() << " pthread_cond_waited RunningWait "
1261              << Automaton()->StateName( _currentState ) << " " << RetVal
1262              << " " << Name() << endl ;
1263     }
1264     cdebug_out << pthread_self() << " StateWait( Running ) " << RetVal
1265                << " " << Automaton()->StateName( _currentState )
1266                << " pthread_cond_wait _RunningWait " << Name() << endl ;
1267     break ;
1268   }
1269   case SUPERV::DoneState : {
1270     RetVal = IsDone() ;
1271     cdebug_in << pthread_self() << " StateWait( Done ) " << RetVal
1272               << " " << Automaton()->StateName( _currentState )
1273               << " pthread_cond_wait _DoneWait " << Name() << endl ;
1274     while ( !RetVal ) {
1275       cdebug << pthread_self() << " pthread_cond_wait DoneWait" << endl ;
1276       pthread_cond_wait( &_DoneWait , &_MutexWait );
1277       RetVal = IsDone() ;
1278       cdebug << pthread_self() << " pthread_cond_waited DoneWait "
1279              << Automaton()->StateName( _currentState ) << " " << RetVal
1280              << endl ;
1281     }
1282     cdebug_out << pthread_self() << " StateWait( Done ) " << RetVal
1283                << " " << Automaton()->StateName( _currentState )
1284                << " pthread_cond_wait _DoneWait " << Name() << endl ;
1285     break ;
1286   }
1287   case SUPERV::SuspendState : {
1288     RetVal = IsSuspended() ;
1289     cdebug_in << pthread_self() << " StateWait( Suspend ) " << RetVal
1290               << " " << Automaton()->StateName( _currentState )
1291               << " pthread_cond_wait _SuspendedWait " << Name() << endl ;
1292     while ( !RetVal && !IsDone() ) {
1293       cdebug << pthread_self() << " pthread_cond_wait SuspendedWait" << endl ;
1294       pthread_cond_wait( &_SuspendedWait , &_MutexWait );
1295       RetVal = IsSuspended() ;
1296       cdebug << pthread_self() << " pthread_cond_waited SuspendedWait "
1297              << Automaton()->StateName( _currentState ) << " " << RetVal
1298              << endl ;
1299     }
1300     cdebug_out << pthread_self() << " StateWait( Suspend ) " << RetVal
1301                << " " << Automaton()->StateName( _currentState )
1302                << " pthread_cond_wait _SuspendedWait " << Name() << endl ;
1303     break ;
1304   }
1305   default : {
1306     cdebug << " SUPERV::OutNode::StateWait Error Undefined State : "
1307            << aState << endl ;
1308   }
1309   }
1310   if ( pthread_mutex_unlock( &_MutexWait ) ) {
1311     perror("pthread_mutex_lock _Wait") ;
1312     exit( 0 ) ;
1313   }
1314   return RetVal ;
1315 }
1316
1317 bool GraphExecutor::InNode::ReadyWait() {
1318 //  cdebug_in << "GraphExecutor::InNode::ReadyWait " << Name() << endl;
1319   bool aret ;
1320   aret = StateWait( SUPERV::ReadyState ) ;
1321 //  cdebug_out << "GraphExecutor::InNode::ReadyWait" << endl ;
1322   return aret ;
1323 }
1324
1325 bool GraphExecutor::InNode::RunningWait() {
1326   cdebug_in << pthread_self() << "GraphExecutor::InNode::RunningWait " << Name()
1327             << " " << Automaton()->StateName( State() ) << endl;
1328   bool aret ;
1329   aret = StateWait( SUPERV::RunningState ) ;
1330   cdebug_out << pthread_self() << "GraphExecutor::InNode::RunningWait " << Name()
1331              << " " << Automaton()->StateName( State() ) << endl;
1332   return aret ;
1333 }
1334
1335 bool GraphExecutor::InNode::DoneWait() {
1336 //  cdebug_in << "GraphExecutor::InNode::DoneWait " << Name() << endl;
1337   bool aret ;
1338   aret = StateWait( SUPERV::DoneState ) ;
1339   return aret ;
1340 }
1341
1342 bool GraphExecutor::InNode::SuspendedWait() {
1343 //  cdebug_in << "GraphExecutor::InNode::SuspendedWait " << Name() << endl;
1344   bool aret ;
1345   aret = StateWait( SUPERV::SuspendState ) ;
1346   return aret ;
1347 }
1348
1349 void GraphExecutor::InNode::InitialState()
1350 {
1351   cdebug_in << "GraphExecutor::InNode::InitialState Node " << Name() << endl;
1352
1353   int i;
1354   _ControlState = SUPERV::VoidState ;
1355   CreateNewThread( false ) ;
1356 //JR 15.04.2005 Debug PAL8624 RetroConception :
1357 //  CreateNewThreadIf( false ) ;
1358   HasAllDataReady( false ) ;
1359   _SuspendSync = false ;
1360   _ResumeSync = false ;
1361   _InitLoop = false ;
1362
1363   // asv : 13.12.04 : Decided to set "Loading" state for factory and computing nodes ONLY.
1364   //                  See extended comment in p.2.19 of "Bugs and Improvements" about IsLoading for InLine.
1365   if ( IsComputingNode() || IsFactoryNode() ) {
1366     IsLoading( true ) ;
1367   }
1368
1369 //  ThreadNo( pthread_self() ) ;
1370   ThreadNo( 0 ) ;
1371
1372   for ( i = 0 ; i < GetNodeOutPortsSize() ; i++ ) {
1373     if ( GetNodeOutPort(i)->IsDataStream() ) {
1374       GetChangeNodeOutPort(i)->PortState(  SUPERV::ReadyState ) ;
1375       GetChangeNodeOutPort(i)->PortDone( true ) ;
1376     }
1377 //JR Debug 01.07.2005 :
1378 //    else if ( i != 0 || !IsGOTONode() ) {
1379     else {
1380       GetChangeNodeOutPort(i)->PortState(  SUPERV::WaitingState ) ;
1381       GetChangeNodeOutPort(i)->PortDone( false ) ;
1382     }
1383   }
1384
1385   int InPortsCount = GetNodeInPortsSize() ;
1386   for ( i = 0 ; i < GetNodeInPortsSize() ; i++ ) {
1387     GraphBase::InPort * anInPort = GetChangeNodeInPort(i) ;
1388     anInPort->PortState( SUPERV::WaitingState ) ;
1389     GraphBase::OutPort * anOutPort = anInPort->GetOutPort() ;
1390     if ( IsHeadNode() && IsLoopNode() && anInPort->IsLoop() ) {
1391       anOutPort->PortStatus( DataConnected );
1392       anOutPort->PortState( SUPERV::ReadyState ) ;
1393       anOutPort->PortDone( true ) ;
1394 //JR 21.02.2005 Debug Memory leak :      CORBA::Any * anAny = new CORBA::Any() ;
1395       CORBA::Any anAny = CORBA::Any() ;
1396 //JR 21.02.2005 Debug Memory leak :      *anAny <<= (long ) 1 ;
1397       anAny <<= (long ) 1 ;
1398       anOutPort->SetValue( anAny ) ;
1399       _InitLoop = true ;
1400       cdebug << "InPort" << i << " " << anInPort->PortName() << " " << anInPort->PortStatus()
1401              << " OutPort " << anOutPort->PortStatus() << theAutomaton->StateName( anOutPort->PortState() )
1402              << " InitLoop HeadNode" << endl ;
1403     }
1404 // JR 15_09_2004 if backward link from GOTONode or EndLoopNode ==> DataConnected
1405     else if ( anInPort->IsGate() && anOutPort ) {
1406       anOutPort->PortState( SUPERV::WaitingState ) ;
1407       anOutPort->PortDone( false ) ;
1408       const GraphBase::ComputingNode * aFromNode =  _OutNode->Graph()->GetGraphNode( anOutPort->NodeName() ) ; 
1409 //JR      if ( aFromNode->IsGOTONode() || aFromNode->IsEndLoopNode() ) {
1410       if ( aFromNode->IsGOTONode() || ( IsLoopNode() && CoupledNode() == aFromNode ) ) {
1411 // ASV: bug with synchronization of Inline nodes (via Gate ports) fixed.  
1412 // before was "else if ( IsOneOfInlineNodes() )"
1413 // IsOneOfInline() == ( Inline || IsOneOfGOTO() ), so Inline are removed..
1414         anOutPort->PortStatus( DataConnected );
1415         anOutPort->PortState( SUPERV::ReadyState ) ;
1416         anOutPort->PortDone( true ) ;
1417       }
1418       cdebug << "InPort" << i << " " << anInPort->PortName() << " " << anInPort->PortStatus()
1419              << " OutPort " << anOutPort->PortStatus() << theAutomaton->StateName( anOutPort->PortState() )
1420              << " Gate HeadNode" << endl ;
1421     }
1422     else {
1423       cdebug << Name() << " IsHeadNode " << IsHeadNode() << " InPort" << i << " "
1424              << anInPort->PortName() << " " << anInPort->PortStatus() << endl ;
1425     }
1426     if ( anInPort->IsGate() && anOutPort == NULL ) {
1427       InPortsCount-- ;
1428       cdebug << "InPort" << i << " " << anInPort->PortName() << " Not connected InPortsCount "
1429              << InPortsCount << endl ;
1430     }
1431     else if ( anOutPort ) {
1432       if ( anOutPort->IsDataConnected() || anOutPort->IsDataStream() ) {
1433         InPortsCount-- ;
1434         anOutPort->PortState( SUPERV::ReadyState ) ;
1435         anOutPort->PortDone( true ) ;
1436         cdebug << "InPort" << i << " " << anInPort->PortName() << " " << anInPort->PortStatus()
1437                << " " << theAutomaton->StateName( anOutPort->PortState() ) << " InPortsCount "
1438                << InPortsCount << endl ;
1439       }
1440       else if ( anOutPort->IsPortConnected() ) {
1441         anOutPort->PortState( SUPERV::WaitingState ) ;
1442         anOutPort->PortDone( false ) ;
1443         cdebug << "InPort" << i << " " << anInPort->PortName() << " " << " "
1444                << anInPort->PortStatus()
1445                << " " << theAutomaton->StateName( anOutPort->PortState() ) << " InPortsCount "
1446                << InPortsCount << endl ;
1447       }
1448       else {
1449         cdebug << "InPort" << i << " " << anInPort->PortName() << " " << anInPort->PortStatus()
1450                << " OutPort " << anOutPort->NodeName() << " " << anOutPort->PortName() << " "
1451                << theAutomaton->StateName( anOutPort->PortState() ) << " InPortsCount "
1452                << InPortsCount << endl ;
1453       }
1454     }
1455     else {
1456       cdebug << "InPort" << i << " " << anInPort->PortName() << " " << " " << anInPort->PortStatus()
1457              << " no corresponding OutPort InPortsCount " << InPortsCount << endl ;
1458     }
1459     if ( anOutPort ) {
1460       if ( !anOutPort->IsDataStream() || anInPort->IsDataStream() ) {
1461         cdebug << "InPort" << i << " state change : " << anInPort->PortName() << " from OutPort "
1462                << anOutPort->PortName() << " from Node " << anOutPort->NodeName()
1463                << " with state of OutPort : " << theAutomaton->StateName( anOutPort->PortState() ) << endl ;
1464         GetChangeNodeInPort(i)->PortState( anOutPort->PortState() ) ;
1465       }
1466       else if ( anOutPort->IsDataConnected() ) {
1467         cdebug << "InPort" << i << " state change : " << anInPort->PortName() << " from OutPort "
1468                << anOutPort->PortName() << " from Node " << anOutPort->NodeName()
1469                << " with state ReadyState" << endl ;
1470         GetChangeNodeInPort(i)->PortState( SUPERV::ReadyState ) ;
1471       }
1472       else {
1473         cdebug << "InPort" << i << " state NOT changed : " << anInPort->PortName() << " from OutPort "
1474                << anOutPort->PortName() << " " << anOutPort->PortStatus() << " from Node " << anOutPort->NodeName()
1475                << " with state " << theAutomaton->StateName( anOutPort->PortState() ) << endl ;
1476       }
1477     }
1478     if ( anOutPort ) {
1479       cdebug << "InPort" << i << " : " << anInPort->PortName() << " from OutPort "
1480              << anOutPort->PortName() << " from Node " << anOutPort->NodeName()
1481              << " with state " ;
1482       if ( anOutPort->PortState() == SUPERV::WaitingState ) {
1483         cdebug << "WaitingState" ;
1484       }
1485       else if ( anOutPort->PortState() == SUPERV::ReadyState ) {
1486         cdebug << "ReadyState" ;
1487       }
1488       else {
1489         cdebug << "???" ;
1490       }
1491       cdebug << " OutPortStatus " << anOutPort->PortStatus() << " State "
1492              << theAutomaton->StateName( anOutPort->PortState() ) << endl ;
1493     }
1494   }
1495
1496   _currentState = InPortsCount > 0 ? GraphExecutor::DataWaitingState 
1497                          : GraphExecutor::DataReadyState ;
1498   if ( InPortsCount == GetNodeInPortsSize() ) {
1499     _OutNode->PushEvent( this , GraphExecutor::NoDataReadyEvent ,
1500                          _currentState ) ; 
1501   }
1502   else if ( InPortsCount != 0 ) {
1503     _OutNode->PushEvent( this , GraphExecutor::SomeDataReadyEvent ,
1504                          _currentState ) ; 
1505   }
1506   else {
1507     _OutNode->PushEvent( this , GraphExecutor::AllDataReadyEvent ,
1508                          _currentState ) ; 
1509   }
1510
1511   for ( i = 0 ; i < GetNodeOutPortsSize() ; i++ ) {
1512     cdebug << "OutPort" << i << " : " << GetNodeOutPort(i)->PortName() << " "
1513            << theAutomaton->StateName( GetChangeNodeOutPort(i)->PortState() )
1514            << " " << GetNodeOutPort(i)->Kind() << endl ;
1515   }
1516
1517   cdebug_out << "GraphExecutor::InNode::InitialState Node " << Name() << " CurrentState = "
1518              << theAutomaton->StateName( _currentState ) << " HasAllDataReady "
1519              << HasAllDataReady() << endl;
1520 }
1521
1522 bool GraphExecutor::InNode::InitPythonFunctions(bool WithErr ) {
1523   cdebug_in << "GraphExecutor::InNode::InitPythonFunctions " << Name() << " WithErr " << WithErr
1524             << " PyFuncRunned() " << PyFuncRunned() << endl;
1525   bool Err = false ;
1526   bool OneErr ;
1527   if ( !PyFuncRunned() && IsOneOfInLineNodes() ) {
1528     if ( IsLoopNode() ) {
1529       PyObject * PyRunMethod = InLineNode()->PyRunMethod() ;
1530       PyObject * PyMoreMethod = NULL ;
1531       PyObject * PyNextMethod = NULL ;
1532       if ( PyRunMethod ) {
1533         OneErr = false ;
1534       }
1535       else {
1536         PyRunMethod = InitPyDynInvoke( InLineNode()->PyFuncName() ,
1537                                        InLineNode()->PythonFunction() ,
1538                                        OneErr ) ;
1539         InLineNode()->PyRunMethod( PyRunMethod ) ;
1540       }
1541       Err = Err || OneErr ;
1542       if ( OneErr && WithErr ) {
1543         string anErrorMessage = string( "Error while declaring the Python function " ) +
1544                                 string( LoopNode()->PyFuncName() ) + string( " in Node " ) +
1545                                 string( Name() ) ;
1546         _OutNode->Graph()->SetMessages( anErrorMessage ) ;
1547       }
1548       PyMoreMethod = LoopNode()->PyMoreMethod() ;
1549       if ( PyMoreMethod ) {
1550         OneErr = false ;
1551       }
1552       else {
1553         PyMoreMethod = InitPyDynInvoke( LoopNode()->PyMoreName() ,
1554                                         LoopNode()->MorePythonFunction() ,
1555                                         OneErr ) ;
1556         LoopNode()->PyMoreMethod( PyMoreMethod ) ;
1557       }
1558       Err = Err || OneErr ;
1559       if ( OneErr && WithErr ) {
1560         string anErrorMessage = string( "Error while declaring the Python function " ) +
1561                                 string( LoopNode()->PyMoreName() ) + string( " in Node " ) +
1562                                 string( Name() ) ;
1563         _OutNode->Graph()->SetMessages( anErrorMessage ) ;
1564       }
1565       PyNextMethod = LoopNode()->PyNextMethod() ;
1566       if ( PyNextMethod ) {
1567         OneErr = false ;
1568       }
1569       else {
1570         PyNextMethod = InitPyDynInvoke( LoopNode()->PyNextName() ,
1571                                         LoopNode()->NextPythonFunction() ,
1572                                         OneErr ) ;
1573         LoopNode()->PyNextMethod( PyNextMethod ) ;
1574       }
1575       Err = Err || OneErr ;
1576       if ( OneErr && WithErr ) {
1577         string anErrorMessage = string( "Error while declaring the Python function " ) +
1578                                 string( LoopNode()->PyNextName() ) + string( " in Node " ) +
1579                                 string( Name() ) ;
1580         _OutNode->Graph()->SetMessages( anErrorMessage ) ;
1581       }
1582       cdebug << "GraphExecutor::InNode::InitPythonFunctions " << Name() << " PyRunMethod(Init) "
1583              << PyRunMethod << " PyMoreMethod " << PyMoreMethod << " PyNextMethod " << PyNextMethod
1584              << endl;
1585     }
1586     else if ( IsInLineNode() || IsSwitchNode() ) {
1587       PyObject * PyRunMethod = InLineNode()->PyRunMethod() ;
1588       if ( PyRunMethod ) {
1589         OneErr = false ;
1590       }
1591       else {
1592         PyRunMethod = InitPyDynInvoke( InLineNode()->PyFuncName() ,
1593                                        InLineNode()->PythonFunction() ,
1594                                        OneErr ) ;
1595         InLineNode()->PyRunMethod( PyRunMethod ) ;
1596       }
1597       Err = Err || OneErr ;
1598       if ( OneErr && WithErr ) {
1599         string anErrorMessage = string( "Error while declaring the Python function " ) +
1600                                 string( InLineNode()->PyFuncName() ) + string( " in Node " ) +
1601                                 string( Name() ) ;
1602         _OutNode->Graph()->SetMessages( anErrorMessage ) ;
1603       }
1604       cdebug << "GraphExecutor::InNode::InitPythonFunctions " << Name() << " PyRunMethod " << PyRunMethod << endl;
1605     }
1606     else if ( ( IsEndLoopNode() || IsEndSwitchNode() || IsGOTONode() ) &&
1607               (*InLineNode()->PythonFunction()).length() ) {
1608       PyObject * PyRunMethod = InLineNode()->PyRunMethod() ;
1609       if ( PyRunMethod ) {
1610         OneErr = false ;
1611       }
1612       else {
1613         PyRunMethod = InitPyDynInvoke( InLineNode()->PyFuncName() ,
1614                                        InLineNode()->PythonFunction() ,
1615                                        OneErr ) ;
1616         InLineNode()->PyRunMethod( PyRunMethod ) ;
1617       }
1618       Err = Err || OneErr ;
1619       if ( OneErr && WithErr ) {
1620         string anErrorMessage = string( "Error while declaring the Python function " ) +
1621                                 string( InLineNode()->PyFuncName() ) + string( " in Node " ) +
1622                                 string( Name() )  ;
1623         _OutNode->Graph()->SetMessages( anErrorMessage ) ;
1624       }
1625       cdebug << "GraphExecutor::InNode::InitPythonFunctions " << Name() << " PyRunMethod " << PyRunMethod << endl;
1626     }
1627   }
1628   Err = WithErr && Err ;
1629   cdebug_out << "GraphExecutor::InNode::InitPythonFunctions " << Name() ;
1630   if ( Err ) {
1631     cdebug << " Error " << Err ;
1632   }
1633   cdebug << endl;
1634   return !Err ;
1635 }
1636
1637 const long GraphExecutor::InNode::CpuUsed( bool tot ) {
1638   CORBA::Long cpu = 0 ;
1639 //  cdebug_in << "GraphExecutor::InNode::CpuUsed( " << tot << " ) " << Name() << endl ;
1640 //  cout << "Begin CpuUsed " << Name() << " CpuUsed : " << cpu << " State "
1641 //       << theAutomaton->StateName( _currentState ) << endl ;
1642   if ( IsOneOfInLineNodes() ) {
1643 //    cdebug << "CpuUsed " << Name() << " --> PyCpuUsed()" << endl ;
1644 //    cout << "CpuUsed " << Name() << " --> PyCpuUsed()" << endl ;
1645     cpu = PyCpuUsed( tot ) ;
1646   }
1647   else {
1648     if ( !CORBA::is_nil( Component() ) ) {
1649 //      cdebug << "CpuUsed " << Name() << " --> Component()->CpuUsed_impl()" << endl ;
1650 //      cout << "CpuUsed " << Name() << " --> Component()->CpuUsed_impl()" << endl ;
1651       try {
1652         cpu = Component()->CpuUsed_impl() ;
1653       }
1654       catch ( ... ) {
1655         cdebug << "CpuUsed " << Name() << " --> Component()->CpuUsed_impl() ERROR catched "
1656                << endl ;
1657         State( GraphExecutor::ErroredState ) ;
1658         _OutNode->State( GraphExecutor::ErroredState ) ;
1659         cpu = -1 ;
1660       }
1661     }
1662     else {
1663       cdebug << "CpuUsed " << Name() << " Component() is NIL" << endl ;
1664       cpu = -1 ;
1665     }
1666   }
1667 //  cdebug_out << "GraphExecutor::InNode::CpuUsed " << Name() << " CpuUsed : " << cpu << endl ;
1668 //  cout << "End CpuUsed " << Name() << " CpuUsed : " << cpu << " State "
1669 //       << theAutomaton->StateName( _currentState ) << endl ;
1670   return cpu ;
1671 }
1672
1673 #include <sys/time.h>
1674 #include <sys/resource.h>
1675 #include <unistd.h>
1676
1677 long GraphExecutor::InNode::PyCpu() {
1678   struct rusage usage ;
1679   long cpu ;
1680   if ( getrusage( RUSAGE_SELF , &usage ) == -1 ) {
1681     perror("GraphExecutor::InNode::PyCpu") ;
1682     return 0 ;
1683   }
1684 //  return usage.ru_utime.__time_t tv_sec ;
1685 //  cdebug << pthread_self() << "PyCpu " << Name() << " " << usage.ru_utime.tv_sec << " "
1686 //         << usage.ru_utime.tv_usec << " " << usage.ru_stime.tv_sec << " " << usage.ru_stime.tv_usec
1687 //         << endl ;
1688   cpu = usage.ru_utime.tv_sec ;
1689   return cpu ;
1690 }
1691
1692 long GraphExecutor::InNode::PyCpuUsed( bool tot ) {
1693   long cpu ;
1694   if ( _PyTotCpuUsed == -1 ) {
1695     if ( _Pythread == pthread_self() ) {
1696 //      cdebug << pthread_self() << "GraphExecutor::InNode::PyCpuUsed(" << tot << ") " << Name()
1697 //             << " _PyTotCpuUsed " <<  _PyTotCpuUsed << " PyCpu() " << PyCpu() << " - " << " _PyCpuUsed "
1698 //             << _PyCpuUsed << endl ;
1699       cpu = PyCpu() - _PyCpuUsed ;
1700       if ( tot ) {
1701         _PyTotCpuUsed = cpu ;
1702       }
1703     }
1704     else {
1705       cpu = 0 ;
1706     }
1707   }
1708   else {
1709     cpu = _PyTotCpuUsed ;
1710   }
1711 //  cdebug << pthread_self() << "GraphExecutor::InNode::PyCpuUsed(" << tot << ") " << Name() << "_PyTotCpuUsed"
1712 //         <<  _PyTotCpuUsed << " CpuUsed : " << cpu << endl ;
1713   return cpu ;
1714 }
1715
1716 void GraphExecutor::InNode::SetPyCpuUsed() {
1717   _PyTotCpuUsed = -1 ;
1718   _PyCpuUsed = 0 ;
1719   _Pythread = pthread_self() ;
1720   _PyCpuUsed = PyCpu() ;
1721 //  cdebug << pthread_self() << "GraphExecutor::InNode::SetPyCpuUsed " << Name() << " _PyCpuUsed : "
1722 //         << _PyCpuUsed << endl ;
1723 }
1724
1725 void GraphExecutor::InNode::IsLoading( bool Loading ) {
1726   _Loading = Loading ;
1727   
1728   // asv : 09.12.04 : "Bugs and Improvents" 2.19 : how it works: 
1729   // LoadingState is returned by OutNode::State( NodeName ) if InNode->IsLoading()
1730   // after Loading is finished (here below), ExecutingState must be pushed for GUI.  
1731   if ( !Loading )
1732     _OutNode->PushEvent( this, GraphExecutor::ExecuteEvent, GraphExecutor::ExecutingState );
1733 }
1734