Salome HOME
ab2e17f93aae5ba94da278cc678877baa49e9002
[modules/superv.git] / src / GraphExecutor / DataFlowExecutor_InNodeThreads.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_InNodeThreads.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
36 #include "Python.h"
37
38 #include "OpUtil.hxx"
39
40 #include <SALOMEconfig.h>
41 #include CORBA_CLIENT_HEADER(SALOME_Component)
42 //#include "SALOME_NamingService.hxx"
43 #include "SALOME_LifeCycleCORBA.hxx"
44
45 //#include "DataFlowExecutor_InNode.hxx"
46
47 #include "DataFlowExecutor_OutNode.hxx"
48
49 //static char *containerName = "FactoryServer" ;
50
51 int GraphExecutor::InNode::SendEvent( const GraphExecutor::NodeEvent anEvent ) {  
52
53   _CurrentEvent = (GraphExecutor::NodeEvent ) anEvent ;
54   cdebug << pthread_self() << "/" << ThreadNo() << " -->SendEvent Node "  << Name() 
55          << " ControlState : "
56          << Automaton()->ControlStateName( ControlState() )
57          << " Event : " << Automaton()->EventName( anEvent )
58          << " State : " << Automaton()->StateName( State() ) << " _RewindStack " << _RewindStack  << endl;
59
60   _OldState = State() ;
61   _NextState = Automaton()->NextState( _OldState , anEvent ) ;
62   if ( _NextState == _OldState ) {
63     cdebug << pthread_self() << "/" << ThreadNo()
64            << " GraphExecutor::InNodeThreads::SendEvent SameStates "
65            << _OldState << endl ;
66     _NextAction = GraphExecutor::VoidAction ;
67   }
68   else {
69     _NextAction = Automaton()->NextAction( _NextState , anEvent ) ;
70   }
71
72 //  State( _NextState ) ;
73 //  if ( _OldState == SUPERV::SuccessedExecutingState ||
74 //       _OldState == SUPERV::ErroredExecutingState ) {
75 //    DoneAction() ;
76 //  }
77
78   cdebug << pthread_self() << "/" << ThreadNo() << " SendedEvent Node "
79          << Name() << endl << " ControlState : "
80          << Automaton()->ControlStateName( ControlState() ) << endl
81          << " OldState : " << Automaton()->StateName( _OldState ) << endl
82          << " Event : " << Automaton()->EventName( anEvent ) << endl
83          << " NextState : " << Automaton()->StateName( _NextState ) << endl
84          << " Action : " << Automaton()->ActionName( _NextAction ) << endl
85          << " CreateNewThread " << CreateNewThread() << endl
86          << " _RewindStack " << _RewindStack  << endl ;
87
88 #if 0
89   cout << pthread_self() << "/" << ThreadNo() << " SendedEvent Node " << Name()
90        << endl << " ControlState : "
91        << Automaton()->ControlStateName( ControlState() ) << endl
92        << " OldState : " << Automaton()->StateName( _OldState ) << endl
93        << " Event : " << Automaton()->EventName( anEvent ) << endl
94        << " NextState : " << Automaton()->StateName( _NextState ) << endl
95        << " Action : " << Automaton()->ActionName( _NextAction ) << endl
96        << " CreateNewThread " << CreateNewThread() << endl ;
97 #endif
98
99   int sts = executeAction() ;
100   
101   cdebug << pthread_self() << "/" << ThreadNo() << " <--- SendEvent Node " << Name() 
102          << " Event : " << Automaton()->EventName( anEvent )
103          << " State : " << Automaton()->StateName( State() )
104          << endl;
105
106   return sts ;
107
108 }
109
110 // ReadyAction - RunningAction - DoneAction - SuspendedAction :
111 // for StateWait( ReadyW - RunningW - DoneW - SuspendedW )
112 void GraphExecutor::InNode::ReadyAction() {
113   if ( pthread_mutex_lock( &_MutexWait ) ) {
114     perror("Ready pthread_mutex_lock ") ;
115     exit( 0 ) ;
116   }
117   cdebug << pthread_self() << "/" << ThreadNo()
118          << "ReadyAction pthread_cond_broadcast _ReadyWait "
119          << Name() << endl ;
120   if ( pthread_cond_broadcast( &_ReadyWait ) ) {
121     perror("Ready pthread_cond_broadcast ") ;
122   }
123   if ( pthread_mutex_unlock( &_MutexWait ) ) {
124     perror("Ready pthread_mutex_unlock ") ;
125     exit( 0 ) ;
126   }
127 }
128
129 void GraphExecutor::InNode::RunningAction() {
130   if ( pthread_mutex_lock( &_MutexWait ) ) {
131     perror("Running pthread_mutex_lock ") ;
132     exit( 0 ) ;
133   }
134   cdebug << pthread_self() << "/" << ThreadNo()
135          << "RunningAction pthread_cond_broadcast _RunningWait "
136          << Name() << endl ;
137   if ( pthread_cond_broadcast( &_RunningWait ) ) {
138     perror("Running pthread_cond_broadcast ") ;
139   }
140   if ( pthread_mutex_unlock( &_MutexWait ) ) {
141     perror("Running pthread_mutex_unlock ") ;
142     exit( 0 ) ;
143   }
144 }
145
146 void GraphExecutor::InNode::DoneAction() {
147   if ( pthread_mutex_lock( &_MutexWait ) ) {
148     perror("Done pthread_mutex_lock ") ;
149     exit( 0 ) ;
150   }
151   cdebug << pthread_self() << "/" << ThreadNo()
152          << "DoneAction pthread_cond_broadcast _DoneWait "
153          << Name() << endl ;
154   if ( pthread_cond_broadcast( &_DoneWait ) ) {
155     perror("Done pthread_cond_broadcast ") ;
156   }
157   if ( pthread_mutex_unlock( &_MutexWait ) ) {
158     perror("Done pthread_mutex_unlock ") ;
159     exit( 0 ) ;
160   }
161 }
162
163 void GraphExecutor::InNode::SuspendedAction() {
164   if ( pthread_mutex_lock( &_MutexWait ) ) {
165     perror("Suspended pthread_mutex_lock ") ;
166     exit( 0 ) ;
167   }
168   cdebug << pthread_self() << "/" << ThreadNo()
169          << "SuspendedAction pthread_cond_broadcast _SuspendedWait "
170          << Name() << endl ;
171   if ( pthread_cond_broadcast( &_SuspendedWait ) ) {
172     perror("Suspended pthread_cond_broadcast ") ;
173   }
174   if ( pthread_mutex_unlock( &_MutexWait ) ) {
175     perror("Suspended pthread_mutex_unlock ") ;
176     exit( 0 ) ;
177   }
178 }
179
180 // SuspendAction <--> { ResumeAction - ReStartAction }
181 GraphExecutor::InNode * GraphExecutor::InNode::SuspendAction() {
182   SuspendedAction() ;
183   if ( pthread_mutex_lock( &_MutexWait ) ) {
184     perror("Suspend pthread_mutex_lock ") ;
185     exit( 0 ) ;
186   }
187   if ( !_SuspendSync ) {
188     cdebug << pthread_self() << "/" << ThreadNo() << " pthread_cond " << Name()
189            << " SuspendAction pthread_cond_wait _SuspendWait "
190            << Automaton()->StateName( State() ) << endl ;
191     _SuspendSync = true ;
192     _OutNode->SuspendThread() ;
193     if ( pthread_cond_wait( &_SuspendWait , &_MutexWait ) ) {
194       perror("SuspendAction pthread_cond_wait ") ;
195     }
196     _OutNode->ResumeThread() ;
197     cdebug << pthread_self() << "/" << ThreadNo() << " pthread_cond " << Name()
198            << " SuspendAction pthread_cond_waited"  
199            << Automaton()->StateName( State() ) << endl ;
200   }
201   else {
202     cdebug << pthread_self() << "/" << ThreadNo() << " pthread_cond " << Name()
203            << " NO SuspendAction pthread_cond_wait"  
204            << Automaton()->StateName( State() ) << endl ;
205   }
206 //  SendEvent( _aResumeEvent ) ; ===> Mutex with myself !
207   _SuspendSync = false ;  
208   if ( ControlState() == SUPERV::ToSuspendStartState ||
209        ControlState() == SUPERV::ToSuspendState ) {
210     ControlState( SUPERV::VoidState ) ;
211   }
212   if ( pthread_mutex_unlock( &_MutexWait ) ) {
213     perror("SuspendAction pthread_mutex_unlock ") ;
214     exit( 0 ) ;
215   }
216
217   SendEvent( _aResumeEvent ) ;
218 //  if ( ControlState() == SUPERV::ToSuspendStartState ) {
219 //    ControlState( SUPERV::VoidState ) ;
220 //  }
221
222   if ( pthread_mutex_lock( &_MutexWait ) ) {
223     perror("SuspendAction pthread_mutex_lock ") ;
224     exit( 0 ) ;
225   }
226   if ( _ResumeSync ) {
227     cdebug << pthread_self() << "/" << ThreadNo() << " pthread_cond " << Name()
228            << " SuspendAction pthread_cond_signal _ResumeWait" << endl ;
229     if ( pthread_cond_signal( &_ResumeWait ) ) {
230       perror("SuspendAction pthread_cond_signal _ResumeWait ") ;
231     }
232     cdebug << pthread_self() << "/" << ThreadNo() << " pthread_cond " << Name()
233            << " SuspendAction pthread_cond_signaled _ResumeWait " << endl ;
234   }
235   else {
236     cdebug << pthread_self() << "/" << ThreadNo() << " pthread_cond " << Name()
237            << " NO SuspendAction pthread_cond_signal _ResumeWait" << endl ;
238     _ResumeSync = true ;  
239   }
240   if ( pthread_mutex_unlock( &_MutexWait ) ) {
241     perror("SuspendAction pthread_mutex_unlock ") ;
242     exit( 0 ) ;
243   }
244   if ( _aReStartNode ) {
245     cdebug << Name() << " " << Automaton()->StateName( State() )
246            << "aReStartNode : " << _aReStartNode->Name() << " "
247            << Automaton()->StateName( _aReStartNode->State() ) << endl ;
248     _aReStartNode->SendEvent( _aResumeEvent ) ;
249   }
250   else {
251     cdebug << "NO aReStartNode" 
252            << Automaton()->StateName( State() ) << endl ;
253   }
254   return _aReStartNode ;
255 }
256
257 bool GraphExecutor::InNode::ResumeAction( GraphExecutor::NodeEvent aResumeEvent ) {
258   bool RetVal ;
259   if ( pthread_mutex_lock( &_MutexWait ) ) {
260     perror("ResumeAction pthread_mutex_lock ") ;
261     exit( 0 ) ;
262   }
263   _aResumeEvent = aResumeEvent ;
264   if ( _SuspendSync ) {
265     cdebug << pthread_self() << "/" << ThreadNo() << " pthread_cond " << Name()
266            << " ResumeAction pthread_cond_signal" << endl ;
267     if ( pthread_cond_signal( &_SuspendWait ) ) {
268       perror("ResumeAction pthread_cond_signal ") ;
269     }
270     cdebug << pthread_self() << "/" << ThreadNo() << " pthread_cond " << Name()
271            << " ResumeAction pthread_cond_signaled _SuspendWait " << endl ;
272     RetVal = true ;
273   }
274   else {
275     cdebug << pthread_self() << "/" << ThreadNo() << " pthread_cond " << Name()
276            << " NO ResumeAction pthread_cond_signal" << endl ;
277     if ( pthread_self() == ThreadNo() ) {
278       RetVal = false ; /*/ Ne pas s'attendre soi-meme !...*/
279     }
280     else {
281       _SuspendSync = true ;
282       RetVal = true ; // Il faut tout de meme attendre ci-apres ...
283     }
284   }
285   if ( pthread_mutex_unlock( &_MutexWait ) ) {
286     perror("ResumeAction pthread_mutex_unlock ") ;
287     exit( 0 ) ;
288   }
289
290   if ( RetVal ) {
291     if ( pthread_mutex_lock( &_MutexWait ) ) {
292       perror("ResumeAction pthread_mutex_lock ") ;
293       exit( 0 ) ;
294     }
295     if ( !_ResumeSync ) {
296       cdebug << pthread_self() << "/" << ThreadNo() << " pthread_cond "
297              << Name() << " ResumeAction pthread_cond_wait _ResumeWait " 
298              << Automaton()->StateName( State() ) << endl ;
299       _ResumeSync = true ;
300       if ( pthread_cond_wait( &_ResumeWait , &_MutexWait ) ) {
301         perror("ResumeAction pthread_cond_wait ") ;
302       }
303       cdebug << pthread_self() << "/" << ThreadNo() << " pthread_cond "
304              << Name() << " ResumeAction pthread_cond_waited _ResumeWait"  
305              << Automaton()->StateName( State() ) << endl ;
306       RetVal = true ;
307     }
308     else {
309       cdebug << pthread_self() << "/" << ThreadNo() << " pthread_cond "
310              << Name() << " NO ResumeAction pthread_cond_wait _ResumeWait" 
311              << Automaton()->StateName( State() ) << endl ;
312       RetVal = false ;
313     }
314     _ResumeSync = false ;  
315     if ( pthread_mutex_unlock( &_MutexWait ) ) {
316       perror("ResumeAction pthread_mutex_unlock ") ;
317       exit( 0 ) ;
318     }
319   }
320   cdebug << pthread_self() << "/" << ThreadNo()
321          << "GraphExecutor::InNodeThreads::ResumeAction RetVal " << RetVal << endl ;
322   return RetVal ;
323 }
324
325 bool GraphExecutor::InNode::ReStartAction( GraphExecutor::InNode * aReStartNode ,
326                                            GraphExecutor::NodeEvent anEvent ) {
327   GraphExecutor::InNode * oldReStartNode = _aReStartNode ;
328   _aReStartNode = aReStartNode ;
329   _aReStartEvent = anEvent ;
330   cdebug << pthread_self() << " GraphExecutor::InNodeThreads::ReStartAction from "
331          << Name() << " " << Automaton()->StateName( State() ) << " to "
332          << aReStartNode->ThreadNo() << " " << aReStartNode->Name() << " "
333          << Automaton()->StateName( aReStartNode->State() ) ;
334   if ( oldReStartNode ) {
335     cdebug << " oldReStartNode " << oldReStartNode->Name() << endl ;
336   }
337   else {
338     cdebug << endl ;
339   }
340   return ResumeAction( GraphExecutor::ToReStartEvent ) ;
341 }
342
343 void GraphExecutor::InNode::KilledAction() {
344   if ( pthread_mutex_lock( &_MutexWait ) ) {
345     perror("Killed pthread_mutex_lock ") ;
346     exit( 0 ) ;
347   }
348   if ( !_KillSync ) {
349     cdebug << "pthread_cond " << Name() << " Killed pthread_cond_wait"
350            << endl ;
351     _KillSync = true ;
352     if ( pthread_cond_wait( &_KillWait , &_MutexWait ) ) {
353       perror("Killed pthread_cond_wait ") ;
354     }
355     cdebug << "pthread_cond " << Name() << " Killed pthread_cond_waited"
356            << endl ;
357   }
358   else {
359     cdebug << "pthread_cond " << Name() << " NO Killed pthread_cond_wait"
360            << endl ;
361   }
362   _KillSync = false ;  
363   if ( pthread_mutex_unlock( &_MutexWait ) ) {
364     perror("Killed pthread_mutex_unlock ") ;
365     exit( 0 ) ;
366   }
367 }
368
369 void GraphExecutor::InNode::KillAction() {
370   if ( pthread_mutex_lock( &_MutexWait ) ) {
371     perror("Kill pthread_mutex_lock ") ;
372     exit( 0 ) ;
373   }
374   if ( _KillSync ) {
375     cdebug << "pthread_cond " << Name() << " Kill pthread_cond_signal"
376            << endl ;
377 //    if ( pthread_cond_broadcast( &_KillWait ) ) {
378     if ( pthread_cond_signal( &_KillWait ) ) {
379       perror("Kill pthread_cond_broadcast ") ;
380     }
381     cdebug << "pthread_cond " << Name() << " Kill pthread_cond_signaled"
382            << endl ;
383   }
384   else {
385     cdebug << "pthread_cond " << Name() << " NO Kill pthread_cond_signal"
386            << endl ;
387     _KillSync = true ;  
388   }
389   if ( pthread_mutex_unlock( &_MutexWait ) ) {
390     perror("Kill pthread_mutex_unlock ") ;
391     exit( 0 ) ;
392   }
393 }
394
395 void GraphExecutor::InNode::StoppedAction() {
396   if ( pthread_mutex_lock( &_MutexWait ) ) {
397     perror("Stopped pthread_mutex_lock ") ;
398     exit( 0 ) ;
399   }
400   if ( pthread_cond_wait( &_StopWait , &_MutexWait ) ) {
401     perror("Stopped pthread_cond_wait ") ;
402   }
403   if ( pthread_mutex_unlock( &_MutexWait ) ) {
404     perror("Stopped pthread_mutex_unlock ") ;
405     exit( 0 ) ;
406   }
407 }
408
409 void GraphExecutor::InNode::StopAction() {
410   if ( pthread_mutex_lock( &_MutexWait ) ) {
411     perror("Stop pthread_mutex_lock ") ;
412     exit( 0 ) ;
413   }
414   if ( pthread_cond_broadcast( &_StopWait ) ) {
415     perror("Stop pthread_cond_broadcast ") ;
416   }
417   if ( pthread_mutex_unlock( &_MutexWait ) ) {
418     perror("Stop pthread_mutex_unlock ") ;
419     exit( 0 ) ;
420   }
421 }
422
423 void GraphExecutor::InNode::ThreadStartedAction() {
424   if ( pthread_mutex_lock( &_MutexWait ) ) {
425     perror("ThreadStarted pthread_mutex_lock ") ;
426     exit( 0 ) ;
427   }
428   if ( !_ThreadStartedSync ) {
429     cdebug << "pthread_cond " << Name() << " ThreadStarted pthread_cond_wait"
430            << endl ;
431     _ThreadStartedSync = true ;
432     if ( pthread_cond_wait( &_ThreadStartedWait , &_MutexWait ) ) {
433       perror("ThreadStarted pthread_cond_wait ") ;
434     }
435     cdebug << "pthread_cond " << Name() << " ThreadStarted pthread_cond_waited"
436            << endl ;
437   }
438   else {
439     cdebug << "pthread_cond " << Name() << " NO ThreadStarted pthread_cond_wait"
440            << endl ;
441 //Debug :
442     _ThreadStartedSync = false ;  
443     if ( pthread_cond_signal( &_ThreadStartedWait ) ) {
444       perror("ThreadStart pthread_cond_signal ") ;
445     }
446 //Debug
447     cdebug << "pthread_cond " << Name() << " NO ThreadStarted pthread_cond_signaled"
448            << endl ;
449   }
450   if ( pthread_mutex_unlock( &_MutexWait ) ) {
451     perror("ThreadStarted pthread_mutex_unlock ") ;
452     exit( 0 ) ;
453   }
454 }
455
456 void GraphExecutor::InNode::ThreadStartAction() {
457   if ( pthread_mutex_lock( &_MutexWait ) ) {
458     perror("ThreadStart pthread_mutex_lock ") ;
459     exit( 0 ) ;
460   }
461   if ( _ThreadStartedSync ) {
462     cdebug << "pthread_cond " << Name() << " ThreadStart pthread_cond_signal"
463            << endl ;
464     _ThreadStartedSync = false ;  
465     if ( pthread_cond_signal( &_ThreadStartedWait ) ) {
466       perror("ThreadStart pthread_cond_broadcast ") ;
467     }
468     cdebug << "pthread_cond " << Name() << " ThreadStart pthread_cond_signaled"
469            << endl ;
470   }
471   else {
472     cdebug << "pthread_cond " << Name() << " NO ThreadStart pthread_cond_signal"
473            << endl ;
474     _ThreadStartedSync = true ;
475 //Debug :
476     if ( pthread_cond_wait( &_ThreadStartedWait , &_MutexWait ) ) {
477       perror("ThreadStarted pthread_cond_wait ") ;
478     }
479 //Debug
480     cdebug << "pthread_cond " << Name() << " NO ThreadStart pthread_cond_waited"
481            << endl ;
482   }
483   if ( pthread_mutex_unlock( &_MutexWait ) ) {
484     perror("ThreadStart pthread_mutex_unlock ") ;
485     exit( 0 ) ;
486   }
487 }
488
489 int GraphExecutor::InNode::executeAction() {
490   int oldRewindStack = ( _RewindStack > 101 ) ;
491   if ( !CreateNewThread() && oldRewindStack ) {
492     cdebug << pthread_self() << "/" << ThreadNo()
493            << " executeAction start Thread _RewindStack " << _RewindStack << " > 101 CreateNewThread "
494            << CreateNewThread() << " " << Automaton()->ActionName( _NextAction ) << "(" << Name() << ")"
495            << endl;
496     CreateNewThread( true ) ;
497     ThreadNo( 0 ) ;
498   }
499   if ( CreateNewThread() ) {
500     CreateNewThread( false ) ;
501     if ( ThreadNo() == 0 ) {
502       _RewindStack = 1 ;
503       cdebug << pthread_self() << "/" << ThreadNo()
504              << " executeAction start Thread _RewindStack " << _RewindStack << " "
505              << Automaton()->ActionName( _NextAction ) << "(" << Name() << ")"
506              << endl;
507       pthread_t T;
508       int pthread_sts = 1 ;
509 //      _OutNode->PushEvent( NULL , GraphExecutor::NewThreadEvent ,
510 //                           SUPERV::ExecutingState ) ; 
511       while ( (pthread_sts = pthread_create(&T, NULL, run_function, this )) ) {
512         char * msg = "Cannot pthread_create " ;
513         perror( msg ) ;
514         cdebug << ThreadNo() << " " << msg << " --> sleep(5)" << endl ;
515         cdebug << ThreadNo() << " PTHREAD_THREADS_MAX : "
516                << PTHREAD_THREADS_MAX << " pthread_create status : " ;
517         if ( pthread_sts == EAGAIN ) {
518           cdebug << "EAGAIN(" << pthread_sts << ")" << endl ;
519           cdebug << "It seems to me that with gdb we are limited to 256 threads because of defunct" << endl ;
520         }
521         else {
522           cdebug << pthread_sts << endl ;
523         }
524         string smsg = msg ;
525         delete [] msg ;
526         pthread_exit( msg ) ;
527       }
528       cdebug << pthread_self() << "/" << ThreadNo()
529              << "executeAction has created thread " << T << endl ;
530       ThreadStartedAction() ;
531       cdebug << pthread_self() << "/" << ThreadNo()
532              << "executeAction the thread " << T << " has called NewThread and will call ExecuteAction for node "
533              << Name() << endl ;
534     }
535     else {
536       cdebug << pthread_self() << "/" << ThreadNo()
537              << " executeAction restart Thread _RewindStack " << _RewindStack << " "
538              << Automaton()->StateName( State() ) << " "
539              << Automaton()->ActionName( _NextAction ) << "(" << Name()
540              << ") ReStartAction ==>" << endl;
541       State( SUPERV::SuspendedSuccessedState ) ;
542       if ( !ReStartAction( this , GraphExecutor::ReStartEvent ) ) {
543         cdebug << pthread_self() << "/" << ThreadNo()
544                << " executeAction STATE & CALLED "
545                << Automaton()->ActionName( _NextAction ) << "(" << Name()
546                << ") ERROR-DEBUG " << endl;
547       }
548       else {
549         cdebug << pthread_self() << "/" << ThreadNo() << " executeAction NO CALL "
550                << Automaton()->ActionName( _NextAction ) << "(" << Name()
551                << ")" << endl;
552       }
553     }
554   }
555   else {
556     if ( _CurrentEvent == ExecuteEvent ) {
557       _RewindStack += 1 ;
558     }
559     cdebug << pthread_self() << "/" << ThreadNo() << " executeAction call "
560            << Automaton()->ActionName( _NextAction ) << "(" << Name() << ") _RewindStack " << _RewindStack
561            << endl;
562     return ExecuteAction() ;
563   }
564   return 1 ;
565 }
566
567 void GraphExecutor::InNode::coutbegin() {
568   cdebug << ThreadNo() << " " << pthread_self() << " run_function begin"
569          << " " << Name() << " " << Automaton()->StateName( State() ) << endl ;
570 }
571 void GraphExecutor::InNode::coutexit() {
572   cdebug << pthread_self() << "/" << ThreadNo() << " run_function pthread_exit _RewindStack " << _RewindStack
573          << " " << Name() << " " << Automaton()->StateName( State() ) << endl ;
574 }
575 void * run_function(void *p) {
576   GraphExecutor::InNode *aNode = (GraphExecutor::InNode *) p;
577   aNode->coutbegin() ;
578   aNode->NewThread( pthread_self() ) ;
579   if ( pthread_setcanceltype( PTHREAD_CANCEL_ASYNCHRONOUS , NULL ) ) {
580     perror("pthread_setcanceltype ") ;
581     exit(0) ;
582   }
583   if ( pthread_setcancelstate( PTHREAD_CANCEL_ENABLE , NULL ) ) {
584     perror("pthread_setcancelstate ") ;
585     exit(0) ;
586   }
587   aNode->ThreadStartAction() ;
588   aNode->ExecuteAction() ;
589   char * msg = new char[40] ;
590   sprintf( msg , "%d" , (int ) aNode->ThreadNo() ) ;
591   strcat( msg , " thread exit" ) ;
592   aNode->coutexit() ;
593   aNode->ExitThread() ;
594   string smsg = msg ;
595   delete [] msg ;
596   pthread_exit( (void * ) smsg.c_str() ) ;
597   return msg ;
598 }
599
600 int GraphExecutor::InNode::ExecuteAction() {
601   int sts ;
602
603 //  const char * nextactionname = Automaton()->ActionName( _NextAction ) ;
604 //  const char * statename = Automaton()->StateName( State() ) ;
605 //  const char * nextstatename = Automaton()->StateName( _NextState ) ;
606 //  cdebug << pthread_self() << "/" << ThreadNo() << " --> ExecuteAction "
607 //         << nextactionname << " "  << statename << " NextState "
608 //         << nextstatename << endl ;
609
610   State( _NextState ) ;
611   switch ( _NextAction ) {
612   case GraphExecutor::ErrorAction : {
613     sts = ErrorAction() ;
614     break ;
615   }
616   case GraphExecutor::VoidAction : {
617     sts = VoidAction() ;
618     break ;
619   }
620   case GraphExecutor::DataWaiting_SomeDataReadyAction : {
621     sts = DataWaiting_SomeDataReadyAction() ;
622     break ;
623   }
624   case GraphExecutor::DataUndef_NotAllDataReadyAction : {
625     sts = DataUndef_NotAllDataReadyAction() ;
626     break ;
627   }
628   case GraphExecutor::DataUndef_AllDataReadyAction : {
629     sts = DataUndef_AllDataReadyAction() ;
630     break ;
631   }
632   case GraphExecutor::DataReady_SuspendAction : {
633     sts = DataReady_SuspendAction() ;
634     break ;
635   }
636   case GraphExecutor::SuspendedReady_ResumeAction : {
637     sts = SuspendedReady_ResumeAction() ;
638     break ;
639   }
640   case GraphExecutor::DataReady_KillAction : {
641     sts = DataReady_KillAction() ;
642     break ;
643   }
644   case GraphExecutor::DataReady_StopAction : {
645     sts = DataReady_StopAction() ;
646     break ;
647   }
648   case GraphExecutor::DataReady_ExecuteAction : {
649     sts = DataReady_ExecuteAction() ;
650     break ;
651   }
652   case GraphExecutor::Executing_SuspendAction : {
653     sts = Executing_SuspendAction() ;
654     break ;
655   }
656   case GraphExecutor::SuspendedExecuting_ResumeAction : {
657     sts = SuspendedExecuting_ResumeAction() ;
658     break ;
659   }
660   case GraphExecutor::Executing_KillAction : {
661     sts = Executing_KillAction() ;
662     break ;
663   }
664   case GraphExecutor::Executing_StopAction : {
665     sts = Executing_StopAction() ;
666     break ;
667   }
668   case GraphExecutor::Executing_SuccessAction : {
669     sts = Executing_SuccessAction() ;
670     break ;
671   }
672   case GraphExecutor::Executing_ErrorAction : {
673     sts = Executing_ErrorAction() ;
674     break ;
675   }
676   case GraphExecutor::Successed_SuccessAction : {
677     sts = Successed_SuccessAction() ;
678     break ;
679   }
680   case GraphExecutor::Errored_ErrorAction : {
681     sts = Errored_ErrorAction() ;
682     break ;
683   }
684   case GraphExecutor::Successed_SuspendAction : {
685     sts = Successed_SuspendAction() ;
686     break ;
687   }
688   case GraphExecutor::Errored_SuspendAction : {
689     sts = Errored_SuspendAction() ;
690     break ;
691   }
692   case GraphExecutor::SuspendedSuccessed_ResumeAction : {
693     sts = SuspendedSuccessed_ResumeAction() ;
694     break ;
695   }
696   case GraphExecutor::SuspendedErrored_ResumeAction : {
697     sts = SuspendedErrored_ResumeAction() ;
698     break ;
699   }
700   case GraphExecutor::Successed_KillAction : {
701     sts = Successed_KillAction() ;
702     break ;
703   }
704   case GraphExecutor::Errored_KillAction : {
705     sts = Errored_KillAction() ;
706     break ;
707   }
708   case GraphExecutor::Successed_StopAction : {
709     sts = Successed_StopAction() ;
710     break ;
711   }
712   case GraphExecutor::Errored_StopAction : {
713     sts = Errored_StopAction() ;
714     break ;
715   }
716   case GraphExecutor::SuspendedSuccessed_ReStartAction : {
717     sts = SuspendedSuccessed_ReStartAction() ;
718     break ;
719   }
720   case GraphExecutor::SuspendedErrored_ReStartAction : {
721     sts = SuspendedErrored_ReStartAction() ;
722     break ;
723   }
724   case GraphExecutor::SuspendedSuccessed_ReStartAndSuspendAction : {
725     sts = SuspendedSuccessed_ReStartAndSuspendAction() ;
726     break ;
727   }
728   case GraphExecutor::SuspendedErrored_ReStartAndSuspendAction : {
729     sts = SuspendedErrored_ReStartAndSuspendAction() ;
730     break ;
731   }
732   default : {
733     cdebug << pthread_self() << "/" << ThreadNo()
734            << " GraphExecutor::InNodeThreads::SendEvent Error Undefined Action : "
735            << _NextAction << endl ;
736     return 0 ;
737   }
738   }
739 //  cdebug << pthread_self() << "/" << ThreadNo() << "<-- ExecuteAction "
740 //         << Automaton()->ActionName( nextaction ) << endl ;
741   return sts ;
742 }
743
744 int GraphExecutor::InNode::ErrorAction() {
745   cdebug << pthread_self() << "/" << ThreadNo() << " Automaton ErrorAction Node "
746          << Name() << endl;
747   return 0;
748 }
749
750 int GraphExecutor::InNode::VoidAction() {
751   cdebug << pthread_self() << "/" << ThreadNo() << " VoidAction "  << Name() << endl;
752   return 1;
753 }
754
755
756 int GraphExecutor::InNode::DataWaiting_SomeDataReadyAction() {
757 //  cdebug << pthread_self() << "/" << ThreadNo()
758 //         << " --> DataWaiting_SomeDataReadyAction from " << DataFromNode()
759 //         << " to " << Name() << endl;
760   unsigned int k;
761   int InReady = 0 ;
762   int res = 1;
763   bool LoopFinished = false ;
764   bool LoopBeginning = false ;
765   bool SwitchFinished = false ;
766
767   if ( IsEndLoopNode() && !GetChangeNodeInLoop()->GetOutPort()->BoolValue() ) {
768     LoopFinished = true ; // End of Loop
769   }
770   if ( IsLoopNode() && GetChangeNodeInLoop()->GetOutPort()->BoolValue() ) {
771     LoopBeginning = true ; // Beginning of Loop
772   }
773   if ( IsEndSwitchNode() && !GetChangeNodeInGate()->GetOutPort()->BoolValue() ) {
774     SwitchFinished = true ; // End of Switch
775   }
776   cdebug << pthread_self() << "/" << ThreadNo() << " " << Name() << " LoopFinished " << LoopFinished
777          << " LoopBeginning " << LoopBeginning << " SwitchFinished " << SwitchFinished << endl ;
778   for ( k = 0 ; k < (unsigned int ) GetNodeInPortsSize() ; k++ ) {
779     GraphBase::InPort * anInPort = GetChangeNodeInPort(k) ;
780     GraphBase::OutPort * anOutPort = anInPort->GetOutPort() ;
781     if ( anInPort->IsGate() && anOutPort == NULL ) {
782       InReady += 1 ;
783       anInPort->State( SUPERV::ReadyState ) ;
784       cdebug << pthread_self() << "/" << ThreadNo() << " " << Name() << " "
785              << anInPort->PortName() << " ControlPort inactive." << endl ;
786     }
787     else if ( strcmp( DataFromNode() , anOutPort->NodeName() ) ) {
788       if ( anInPort->State() == SUPERV::ReadyState ) {
789         InReady += 1 ;
790         cdebug << pthread_self() << "/" << ThreadNo() << " " << Name() << " "
791                << anInPort->PortName() << " Was Done from "
792                << anOutPort->NodeName() << " " << anOutPort->PortName()
793                << " ReadyState " ;
794 #ifdef _DEBUG_
795         if ( GraphBase::Base::_prof_debug ) {
796           anOutPort->StringValue( *GraphBase::Base::_fdebug ) ;
797         }
798 #endif
799         cdebug << endl ;
800       }
801       else if ( IsLoopNode() && anInPort->IsDataConnected() ) {
802         anInPort->State( SUPERV::ReadyState ) ;
803         InReady += 1 ;
804         cdebug << pthread_self() << "/" << ThreadNo() << " " << Name() << " "
805                << anInPort->PortName() << " Was Done from "
806                << anOutPort->NodeName() << " " << anOutPort->PortName()
807                << " LoopBeginning " << LoopBeginning ;
808 #ifdef _DEBUG_
809         if ( GraphBase::Base::_prof_debug ) {
810           anOutPort->StringValue( *GraphBase::Base::_fdebug ) ;
811         }
812 #endif
813         cdebug << endl ;
814       }
815       else if ( LoopFinished ) {
816         anInPort->State( SUPERV::ReadyState ) ;
817         InReady += 1 ;
818         cdebug << pthread_self() << "/" << ThreadNo() << " " << Name() << " "
819                << anInPort->PortName() << " Was Done from "
820                << anOutPort->NodeName() << " " << anOutPort->PortName()
821                << " LoopFinished" ;
822 #ifdef _DEBUG_
823         if ( GraphBase::Base::_prof_debug ) {
824           anOutPort->StringValue( *GraphBase::Base::_fdebug ) ;
825         }
826 #endif
827         cdebug << endl ;
828       }
829       else if ( anInPort->IsGate() && SwitchFinished ) {
830         anInPort->State( SUPERV::ReadyState ) ;
831         InReady += 1 ;
832         cdebug << pthread_self() << "/" << ThreadNo() << " " << Name() << " "
833                << anInPort->PortName() << " Was Done from "
834                << anOutPort->NodeName() << " " << anOutPort->PortName()
835                << " SwitchFinished" ;
836 #ifdef _DEBUG_
837         if ( GraphBase::Base::_prof_debug ) {
838           anOutPort->StringValue( *GraphBase::Base::_fdebug ) ;
839         }
840 #endif
841         cdebug << endl ;
842       }
843       else {
844         cdebug << pthread_self() << "/" << ThreadNo() << " " << Name() << " "
845                << anInPort->PortName() << " Was NOT Done from "
846                << anOutPort->NodeName() << " " << anOutPort->PortName() << " "
847                << " " << Automaton()->StateName( State() ) << " DataConnected "
848                << anInPort->IsDataConnected() << " LoopBeginning "
849                << LoopBeginning << endl ;
850       }
851     }
852     else if ( anInPort->IsGate() ) {
853       const CORBA::Any * theValue = anOutPort->Value() ;
854       long GateOpened ;
855       (*theValue) >>= GateOpened ;
856       if ( GateOpened != 0 ) {
857         InReady += 1 ;
858         anInPort->State( SUPERV::ReadyState ) ;
859         cdebug << pthread_self() << "/" << ThreadNo() << " " << Name() << " "
860                << anInPort->PortName() << " Gate is Opened from "
861                << anOutPort->NodeName() << " " << anOutPort->PortName()
862                << " " ;
863 #ifdef _DEBUG_
864         if ( GraphBase::Base::_prof_debug ) {
865           anOutPort->StringValue( *GraphBase::Base::_fdebug ) ;
866         }
867 #endif
868         cdebug << endl ;
869       }
870       else if ( LoopFinished ) {
871         anInPort->State( SUPERV::ReadyState ) ;
872         cdebug << pthread_self() << "/" << ThreadNo() << " " << Name() << " "
873                << anInPort->PortName() << " GATE IS CLOSED from "
874                << anOutPort->NodeName() << " " << anOutPort->PortName()
875                << " LoopFinished" ;
876 #ifdef _DEBUG_
877         if ( GraphBase::Base::_prof_debug ) {
878           anOutPort->StringValue( *GraphBase::Base::_fdebug ) ;
879         }
880 #endif
881         cdebug << endl ;
882       }
883       else {
884         cdebug << pthread_self() << "/" << ThreadNo() << " " << Name() << " "
885                << anInPort->PortName() << " GATE IS CLOSED from "
886                << anOutPort->NodeName() << " " << anOutPort->PortName()
887                << " " ;
888 #ifdef _DEBUG_
889         if ( GraphBase::Base::_prof_debug ) {
890           anOutPort->StringValue( *GraphBase::Base::_fdebug ) ;
891         }
892 #endif
893         cdebug << endl ;
894       }
895     }
896     else {
897       InReady += 1 ;
898       anInPort->State( SUPERV::ReadyState ) ;
899       cdebug << pthread_self() << "/" << ThreadNo() << " " << Name() << " "
900              << anInPort->PortName() << " is Done from "
901              << anOutPort->NodeName() << " " << anOutPort->PortName() << " " ;
902 #ifdef _DEBUG_
903         if ( GraphBase::Base::_prof_debug ) {
904           anOutPort->StringValue( *GraphBase::Base::_fdebug ) ;
905         }
906 #endif
907         cdebug << endl ;
908     }
909   }
910   
911   if ( InReady == GetNodeInPortsSize() ) { // All Flags != 0 :
912     res = SendEvent( GraphExecutor::AllDataReadyEvent ); // ==> Ready to execute
913   }
914   else { // At least one Flag == 0 :
915     res = SendEvent( GraphExecutor::NotAllDataReadyEvent );
916   }
917
918   cdebug << pthread_self() << "/" << ThreadNo()
919          << " <-- DataWaiting_SomeDataReadyAction "  << Name() << endl;
920   return res ;
921
922 }
923
924 int GraphExecutor::InNode::DataUndef_NotAllDataReadyAction() {
925   CreateNewThreadIf( false ) ;
926 //  cdebug << pthread_self() << " for " << ThreadNo()
927 //         << " DataUndef_NotAllDataReadyAction " << Name() << endl;
928   return 1;
929 }
930
931 int GraphExecutor::InNode::DataUndef_AllDataReadyAction() {
932 //  cdebug << pthread_self() << "/" << ThreadNo()
933 //         << " --> DataUndef_AllDataReadyAction " << Name()
934 //         << " CreateNewThreadIf " << CreateNewThreadIf() << " IsLockedDataWait "
935 //         << IsLockedDataWait() ;
936   if ( IsLockedDataWait() ) {
937 //    cdebug << " WOULD DEAD-LOCK" << endl ;
938     return 0 ; // ==> DataUndef_AllDataReadyAction() after UnLockDataWait()
939   }
940 //  cdebug << endl ;
941   CreateNewThread( CreateNewThreadIf() ) ;
942   if ( !CreateNewThread() ) {
943 //    cdebug << "Thread " << ThreadNo() << "-->" << pthread_self() << endl ;
944     ThreadNo( pthread_self() ) ;
945   }
946   _OutNode->PushEvent( this , GraphExecutor::AllDataReadyEvent ,
947                        SUPERV::DataReadyState ) ; 
948   ReadyAction() ;
949   SUPERV::ControlState aControl = ControlState() ;
950   switch ( aControl ) {
951   case SUPERV::VoidState : {
952     SendEvent( GraphExecutor::ExecuteEvent ) ;
953     break ;
954   }
955   case SUPERV::ToSuspendState : {
956     SendEvent( GraphExecutor::SuspendEvent ) ;
957     break ;
958   }
959   case SUPERV::ToSuspendStartState : {
960     SendEvent( GraphExecutor::SuspendEvent ) ;
961     break ;
962   }
963   case SUPERV::ToSuspendDoneState : {
964     SendEvent( GraphExecutor::ExecuteEvent ) ;
965     break ;
966   }
967   case SUPERV::ToKillState : {
968     SendEvent( GraphExecutor::KillEvent ) ;
969     break ;
970   }
971   case SUPERV::ToKillDoneState : {
972     SendEvent( GraphExecutor::ExecuteEvent ) ;
973     break ;
974   }
975   case SUPERV::ToStopState : {
976     SendEvent( GraphExecutor::StopEvent ) ;
977     break ;
978   }
979   default : {
980     cdebug << ThreadNo()
981            << " GraphExecutor::InNodeThreads::DataUndef_AllDataReadyAction Error Undefined Control : "
982            << aControl << endl ;
983     return 0;
984   }
985   }
986 //  cdebug << pthread_self() << "/" << ThreadNo()
987 //         << " <-- DataUndef_AllDataReadyAction " << Name() << endl;
988   return 1;
989 }
990
991 int GraphExecutor::InNode::DataReady_SuspendAction() {
992   cdebug << pthread_self() << "/" << ThreadNo()
993          << "DataReady_SuspendAction --> Suspend " << Name()
994          << " Threads " << _OutNode->Threads() << " SuspendedThreads "
995          << _OutNode->SuspendedThreads() << endl;
996   _OutNode->PushEvent( this , GraphExecutor::SuspendedReadyEvent ,
997                        SUPERV::SuspendedReadyState ) ;
998   GraphExecutor::InNode * aReStartNode = SuspendAction() ;
999   cdebug << pthread_self() << "/" << ThreadNo()
1000          << "DataReady_SuspendAction Resumed " << Name() << endl;
1001   if ( aReStartNode ) {
1002     _aReStartNode = NULL ;
1003     aReStartNode->SendEvent( _aReStartEvent ) ;
1004   }
1005   else {
1006     SendEvent( GraphExecutor::ExecuteEvent ) ;
1007   }
1008   return 1 ;
1009 }
1010
1011 int GraphExecutor::InNode::SuspendedReady_ResumeAction() {
1012   cdebug << pthread_self() << "/" << ThreadNo() << "SuspendedReady_ResumeAction "
1013          << Name() << endl;
1014 //  ResumeAction() ;
1015   _OutNode->PushEvent( this , GraphExecutor::ResumedReadyEvent ,
1016                        SUPERV::ResumedReadyState ) ; 
1017   return 1 ;
1018 }
1019
1020 int GraphExecutor::InNode::DataReady_KillAction() {
1021   _OutNode->PushEvent( this , GraphExecutor::KilledReadyEvent ,
1022                        SUPERV::KilledReadyState ) ;
1023   KillAction() ;
1024   cdebug << pthread_self() << "/" << ThreadNo() << "DataReady_KillAction " << Name()
1025          << " will pthread_exit()" << endl;
1026   return 1 ;
1027 }
1028
1029 int GraphExecutor::InNode::DataReady_StopAction() {
1030   _OutNode->PushEvent( this , GraphExecutor::StoppedReadyEvent ,
1031                        SUPERV::StoppedReadyState ) ; 
1032   StopAction() ;
1033   cdebug << pthread_self() << "/" << ThreadNo() << "DataReady_StopAction " << Name()
1034          << " will pthread_exit()" << endl;
1035   return 1 ;
1036 }
1037
1038 #include <CORBA.h>
1039
1040 int GraphExecutor::InNode::DataReady_ExecuteAction() {
1041   int i;
1042
1043 //  cdebug << pthread_self() << "/" << ThreadNo() << " --> DataReady_ExecuteAction "
1044 //         << Name() << endl;
1045   _OutNode->PushEvent( this , GraphExecutor::ExecuteEvent ,
1046                        SUPERV::ExecutingState ) ; 
1047
1048   RunningAction() ;
1049   SUPERV::GraphState PortState = SUPERV::ReadyState ;
1050   SUPERV::AutomatonState NewState = SUPERV::DataUndefState ;
1051   GraphExecutor::NodeEvent NewEvent = GraphExecutor::UndefinedEvent ;
1052
1053   bool Err = false ;
1054
1055   int nInParams = GetNodeInPortsSize()  ;
1056   ServicesAnyData * InParametersList = new ServicesAnyData[nInParams];
1057   InParametersSet( Err , nInParams , InParametersList ) ;
1058
1059   Engines::Container_var myContainer ;
1060   Engines::Component_var myObjComponent ;
1061   if ( !IsFactoryNode() ) {
1062 //    cdebug << ThreadNo() << "No Component : NO StartComponent & No Ping" << endl ;
1063     if ( IsComputingNode() ) {
1064       ObjInterface( true ) ;
1065       CORBA::Object_ptr obj ;
1066       InParametersList[0].Value >>= obj ;
1067       CORBA::Object_var objvar = CORBA::Object_var( obj ) ;
1068       myObjComponent = Engines::Component::_narrow( objvar ) ;
1069     }
1070     else {
1071     }
1072   }
1073   else if ( CORBA::is_nil( Component() ) ) {
1074     Err = !_OutNode->StartComponent( ThreadNo() , Computer() ,
1075                                      my_strdup( ComponentName() ) ,
1076                                      myContainer , myObjComponent ) ;
1077     ObjInterface( false ) ;
1078     SetContainer( myContainer ) ;
1079     SetComponent( myObjComponent ) ;
1080   }
1081   else {
1082     myContainer = Container() ;
1083     myObjComponent = Component() ;
1084 //    cdebug << ThreadNo() << "Component known : NO StartComponent & Ping"
1085 //           << endl ;
1086     myObjComponent->ping() ;
1087   }
1088
1089   int nOutParams = GetNodeOutPortsSize()  ;
1090   ServicesAnyData * OutParametersList = new ServicesAnyData[nOutParams];
1091   InOutParametersSet( nOutParams , OutParametersList ) ;
1092
1093     if ( Err || ControlState() == SUPERV::ToKillState ||
1094                 ControlState() == SUPERV::ToKillDoneState ||
1095                 ControlState() == SUPERV::ToStopState ) {
1096       cdebug << ThreadNo() << "StartComponent Error or ToKillState" << endl ;
1097       Err = true ;
1098     }
1099     else {
1100       if ( !Err ) {
1101         cdebug << ThreadNo() << " Run( '" << ServiceName() << "'" ;
1102         for ( i = 0 ; i < (int ) ServiceInParameter().length() ; i++ ) {
1103           cdebug << " , " << InParametersList[ i ].Name << "[kind"
1104                  << InParametersList[ i ].Value.type()->kind() << "]" ;
1105         }
1106         for ( i = 0 ; i < (int ) ServiceOutParameter().length() ; i++ ) {
1107           cdebug << " , " << OutParametersList[ i ].Name << "[kind"
1108                  << OutParametersList[ i ].Value.type()->kind() << "]" ;
1109         }
1110         if ( IsOneOfInLineNodes() ) {
1111           cdebug << " , PyFuncName '" << InLineNode()->PyFuncName() << "' PyRunMethod "
1112                  << InLineNode()->PyRunMethod() << " length " << (*InLineNode()->PythonFunction()).length() ;
1113         }
1114         cdebug << ")" << endl ;
1115
1116         if ( IsOneOfInLineNodes() ) {
1117           bool StsPyDynInvoke = true;
1118           _OutNode->PyThreadLock() ;
1119           SetPyCpuUsed() ;
1120           try {
1121 //            if ( IsInLineNode() && (*InLineNode()->PythonFunction()).length() &&
1122             bool CopyInOut = false ;
1123             if ( IsInLineNode() && /*InLineNode()->PyRunMethod() &&*/
1124                  strlen( InLineNode()->PyFuncName() ) ) {
1125 //              cdebug << ThreadNo() << " !ObjInterface " << Name() << " PyFuncName '"
1126 //                     << InLineNode()->PyFuncName()
1127 //                     << "' IsInLineNode PyDynInvoke"  << endl ;
1128               StsPyDynInvoke = PyDynInvoke( InLineNode()->PyRunMethod() ,
1129                                             InLineNode()->PyFuncName() ,
1130                                             &InParametersList[0] , ServiceInParameter().length() ,
1131                                             &OutParametersList[0] , ServiceOutParameter().length() ) ;
1132             }
1133             else if ( IsLoopNode() ) {
1134               bool CopyOutIn = false ;
1135               if ( GetNodeInLoop()->GetOutPort()->BoolValue() && /*InLineNode()->PyRunMethod() &&*/
1136                    strlen( InLineNode()->PyFuncName() ) ) { // InLoop Port
1137 //                cdebug << ThreadNo() << " !ObjInterface " << Name()
1138 //                       << " IsLoopNode PyDynInvoke '" << InLineNode()->PyFuncName()
1139 //                       << "'" << endl ;
1140                 StsPyDynInvoke = PyDynInvoke( InLineNode()->PyRunMethod() ,
1141                                               InLineNode()->PyFuncName() ,
1142                                               &InParametersList[1] , ServiceInParameter().length() ,
1143                                               &OutParametersList[1] , ServiceOutParameter().length() ) ;
1144                 CopyOutIn = true ;
1145               }
1146               else if ( LoopNode()->PyNextMethod() &&
1147                         strlen( LoopNode()->PyNextName() ) ){
1148 //                cdebug << ThreadNo() << " !ObjInterface " << Name()
1149 //                       << " IsLoopNode PyDynInvoke '" << LoopNode()->PyNextName()
1150 //                       << "'" << endl ;
1151                 StsPyDynInvoke = PyDynInvoke( LoopNode()->PyNextMethod() ,
1152                                               LoopNode()->PyNextName() ,
1153                                               &InParametersList[1] , ServiceInParameter().length() ,
1154                                               &OutParametersList[1] , ServiceOutParameter().length() ) ;
1155                 CopyOutIn = true ;
1156               }
1157               if ( StsPyDynInvoke && CopyOutIn ) {
1158 //                cdebug << ThreadNo() << " !ObjInterface " << Name()
1159 //                       << " IsLoopNode PyDynInvoke '" << LoopNode()->PyMoreName()
1160 //                       << "' Copy of " << ServiceInParameter().length()
1161 //                       << " OutParameters" << endl ;
1162                 int i ;
1163                 for ( i = 1 ; i <= (int ) ServiceInParameter().length() ; i++ ) {
1164                   InParametersList[i].Value = OutParametersList[i].Value ;
1165                   InParametersList[i].Name = OutParametersList[i].Name ;
1166 //#if 0
1167                   switch ( InParametersList[i].Value.type()->kind() ) {
1168                   case CORBA::tk_string :
1169                     char * t;
1170                     InParametersList[i].Value >>= t ;
1171                     cdebug << "ArgOut->In" << i << " : "
1172                            << InParametersList[i].Name.c_str()
1173                            << " Value(string) " << t << endl ;
1174                     break ;
1175                   case CORBA::tk_double :
1176                     double d;
1177                     InParametersList[i].Value >>= d;
1178                     cdebug << "ArgOut->In" << i << " : "
1179                            << InParametersList[i].Name.c_str()
1180                            << " Value(double) " << d << endl ;
1181                     break ;
1182                   case CORBA::tk_long :
1183                     long l;
1184                     InParametersList[i].Value >>= l;
1185                     cdebug << "ArgOut->In" << i << " : "
1186                            << InParametersList[i].Name.c_str()
1187                            << " Value(long) " << l << endl ;
1188                     break ;
1189                   case CORBA::tk_objref :
1190                     CORBA::Object_ptr obj ;
1191                     char * retstr ;
1192                     try {
1193                       InParametersList[i].Value >>= obj ;
1194                       retstr = ObjectToString( obj );
1195                       cdebug << "ArgOut->In" << i << " : "
1196                              << InParametersList[i].Name.c_str()
1197                              << " Value(object reference) " << retstr << endl ;
1198                      }
1199                     catch ( ... ) {
1200                       cdebug << "ArgOut->In" << i << " : "
1201                              << InParametersList[i].Name.c_str()
1202                              << " Value(object reference) Catched ERROR" << endl ;
1203                     }
1204                     break ;
1205                   default :
1206                     cdebug << "ArgOut->In" << i << " : "
1207                            << InParametersList[i].Name.c_str()
1208                            << " Value(other) ERROR" << endl ;
1209                   }
1210 //#endif
1211                 }
1212                 if ( LoopNode()->PyMoreMethod() && strlen( LoopNode()->PyMoreName() ) ) {
1213                   StsPyDynInvoke = PyDynInvoke( LoopNode()->PyMoreMethod() ,
1214                                                 LoopNode()->PyMoreName() ,
1215                                                 &InParametersList[1] , ServiceInParameter().length() ,
1216                                                 &OutParametersList[0] , ServiceOutParameter().length()+1 ) ;
1217                 }
1218                 else {
1219                   CopyInOut = true ;
1220                 }
1221               }
1222               else  if ( !StsPyDynInvoke ) {
1223                 Err = true ;
1224                 cdebug << ThreadNo() << " InLineNode " << Name() << " "
1225                        << InLineNode()->PyFuncName() << "/" << LoopNode()->PyNextName()
1226                        << " Python Dynamic Call Error"
1227                        << endl ;
1228               }
1229             }
1230             else if ( IsSwitchNode() && /*InLineNode()->PyRunMethod() &&*/
1231                       strlen( InLineNode()->PyFuncName() ) ) {
1232 //              cdebug << ThreadNo() << " !ObjInterface " << Name() << " PyFuncName '"
1233 //                     << InLineNode()->PyFuncName()
1234 //                     << "' IsSwitchNode PyDynInvoke"  << endl ;
1235               StsPyDynInvoke = PyDynInvoke( InLineNode()->PyRunMethod() ,
1236                                             InLineNode()->PyFuncName() ,
1237                                             &InParametersList[0] , ServiceInParameter().length() ,
1238                                             &OutParametersList[0] , ServiceOutParameter().length() ) ;
1239             }
1240 //            else if ( IsGOTONode() && (*GOTONode()->PythonFunction()).length() &&
1241             else if ( IsGOTONode() && /*InLineNode()->PyRunMethod() &&*/
1242                       strlen( InLineNode()->PyFuncName() ) ) {
1243 //              cdebug << ThreadNo() << " !ObjInterface " << Name() << " PyFuncName '"
1244 //                     << InLineNode()->PyFuncName()
1245 //                     << "' IsGOTONode PyDynInvoke"  << endl ;
1246               StsPyDynInvoke = PyDynInvoke( InLineNode()->PyRunMethod() ,
1247                                             InLineNode()->PyFuncName() ,
1248                                             &InParametersList[0] , ServiceInParameter().length() ,
1249                                             &OutParametersList[0] , ServiceOutParameter().length() ) ;
1250             }
1251 //            else if ( IsEndSwitchNode() && (*InLineNode()->PythonFunction()).length() &&
1252             else if ( ( IsEndSwitchNode() ) &&
1253                       InLineNode()->PyRunMethod() && strlen( InLineNode()->PyFuncName() ) ) {
1254 //              cdebug << ThreadNo() << " !ObjInterface " << Name() << " PyFuncName '"
1255 //                     << InLineNode()->PyFuncName()
1256 //                     << "' IsSwitchNode PyDynInvoke"  << endl ;
1257               StsPyDynInvoke = PyDynInvoke( InLineNode()->PyRunMethod() ,
1258                                             InLineNode()->PyFuncName() ,
1259                                             &InParametersList[0] , ServiceInParameter().length() ,
1260                                             &OutParametersList[0] , ServiceOutParameter().length() ) ;
1261             }
1262             else if ( ( IsEndLoopNode() ) &&
1263                       InLineNode()->PyRunMethod() && strlen( InLineNode()->PyFuncName() ) ) {
1264 //              cdebug << ThreadNo() << " !ObjInterface " << Name() << " PyFuncName '"
1265 //                     << InLineNode()->PyFuncName()
1266 //                     << "' IsSwitchNode PyDynInvoke"  << endl ;
1267               StsPyDynInvoke = PyDynInvoke( InLineNode()->PyRunMethod() ,
1268                                             InLineNode()->PyFuncName() ,
1269                                             &InParametersList[0] , ServiceInParameter().length() + 1 ,
1270                                             &OutParametersList[0] , ServiceOutParameter().length() + 1 ) ;
1271             }
1272 //            else if ( (*InLineNode()->PythonFunction()).length() == 0 ||
1273             if ( InLineNode()->PyRunMethod() == NULL ||
1274                  strlen( InLineNode()->PyFuncName() ) == 0 || CopyInOut ) {
1275 //              cdebug << ThreadNo() << " !ObjInterface " << Name()
1276 //                     << " Copy of " << ServiceInParameter().length()
1277 //                     << " OutParameters" << endl ;
1278               int i ;
1279               int argout0 = 0 ;
1280               int argin0 = 0 ;
1281               if ( IsLoopNode() || IsEndLoopNode() ) {
1282                 argout0 = 1 ;
1283                 argin0 = 1 ; // after DoLoop
1284                 if ( IsLoopNode() ) {
1285                   OutParametersList[0].Value = InParametersList[0].Value ; // DoLoop
1286                 }
1287               }
1288               for ( i = 0 ; i < (int ) ServiceInParameter().length() ; i++ ) {
1289                 OutParametersList[argout0 + i].Value = InParametersList[argin0 + i].Value ;
1290 //#if 0
1291                 switch ( InParametersList[argin0 + i].Value.type()->kind() ) {
1292                 case CORBA::tk_string :
1293                   cdebug << "ArgOut->In" << argin0 + i << " : "
1294                          << InParametersList[argin0 + i].Name.c_str()
1295                          << " Value(string) "
1296                          << OutParametersList[argout0 + i].Name.c_str() << endl ;
1297                   break ;
1298                 case CORBA::tk_double :
1299                   cdebug << "ArgOut->In" << argin0 + i << " : "
1300                          << InParametersList[argin0 + i].Name.c_str()
1301                          << " Value(double) "
1302                          << OutParametersList[argout0 + i].Name.c_str() << endl ;
1303                   break ;
1304                 case CORBA::tk_long :
1305                   cdebug << "ArgOut->In" << argin0 + i << " : "
1306                          << InParametersList[argin0 + i].Name.c_str()
1307                          << " Value(long) "
1308                          << OutParametersList[argout0 + i ].Name.c_str() << endl ;
1309                   break ;
1310                 case CORBA::tk_objref :
1311                   cdebug << "ArgOut->In" << argin0 + i << " : "
1312                          << InParametersList[argin0 + i].Name.c_str()
1313                          << " Value(object reference) "
1314                          << OutParametersList[argout0 + i].Name.c_str() << endl ;
1315                   break ;
1316                 default :
1317                   cdebug << "ArgOut->In" << argin0 + i << " : "
1318                          << InParametersList[argin0 + i].Name.c_str()
1319                          << " Value(other) ERROR "
1320                          << OutParametersList[argout0 + i].Name.c_str() << endl ;
1321                 }
1322 //#endif
1323               }
1324             }
1325             if ( !StsPyDynInvoke ) {
1326               Err = true ;
1327               cdebug << ThreadNo() << " InLineNode " << Name()
1328                      << " Python Dynamic Call Error"
1329                      << endl ;
1330             }
1331           }
1332           catch( ... ) {
1333             Err = true ;
1334             cdebug << ThreadNo() << " InLineNode " << Name()
1335                    << " Python Dynamic Call Exception catched ERROR"
1336                    << endl ;
1337           }
1338           CpuUsed( true ) ;
1339           _OutNode->PyThreadUnLock() ;
1340         }
1341         else {
1342           try {
1343             try {
1344               cdebug << "DynInvoke -> Names " << _OutNode->Name() << " " << Name() << endl ;
1345               DynInvoke( myObjComponent, "Names" ,
1346                          _OutNode->Name() , Name() ) ;
1347             }
1348             catch( ... ) {
1349               cdebug << "DynInvoke Names catched ERROR" << endl ;
1350             }
1351             cdebug << ServiceInParameter().length() << " input parameters and "
1352                    << ServiceOutParameter().length() << " output parameters" << endl ;
1353             if ( IsComputingNode() ) {
1354               cdebug << ThreadNo() << " !ObjInterface " << Name()
1355                      << " IsComputingNode DynInvoke"  << endl ;
1356               DynInvoke( myObjComponent,
1357                          ServiceName() ,
1358                          &InParametersList[1] , ServiceInParameter().length()-1 ,
1359                          &OutParametersList[0] , ServiceOutParameter().length() ) ;
1360             }
1361             else if ( IsFactoryNode() ) {
1362               cdebug << ThreadNo() << " !ObjInterface " << Name()
1363                      << " IsFactoryNode DynInvoke"  << endl ;
1364               DynInvoke( myObjComponent,
1365                          ServiceName() ,
1366                          &InParametersList[0] , ServiceInParameter().length() ,
1367                          &OutParametersList[0] , ServiceOutParameter().length() ) ;
1368             }
1369 //            cdebug << ThreadNo() << " Component::CpuUsed " << Name() << " "
1370 //                   << myObjComponent->CpuUsed_impl() << endl ;
1371           }
1372           catch( ... ) {
1373             Err = true ;
1374             cdebug << ThreadNo() << " !ObjInterface " << Name()
1375                    << " Node(Component) Dynamic Call Exception catched ERROR"
1376                    << endl ;
1377           }
1378         }
1379       }
1380     }
1381 //  }
1382 //  else {
1383 //    sleep( 1 ) ;
1384 //  }
1385
1386   if ( Err ) {
1387     if ( ControlState() == SUPERV::ToKillState ||
1388          ControlState() == SUPERV::ToKillDoneState ||
1389          ControlState() == SUPERV::ToStopState ) {
1390       PortState = SUPERV::ErrorState ;
1391       NewState = SUPERV::KilledState ;
1392       NewEvent = GraphExecutor::KillEvent ;
1393     }
1394     else {
1395       PortState = SUPERV::ErrorState ;
1396       NewState = SUPERV::ErroredState ;
1397       NewEvent = GraphExecutor::ErrorEvent ;
1398     }
1399   }
1400   else {
1401     PortState = SUPERV::ReadyState ;
1402     NewState = SUPERV::DataReadyState ;
1403     NewEvent = GraphExecutor::SuccessEvent ;
1404   }
1405
1406   bool ErrOut = OutParametersSet( Err , PortState , nOutParams , OutParametersList ) ;
1407               
1408   if ( !ErrOut ) {
1409     NewEvent = GraphExecutor::ErrorEvent ;
1410   }
1411           
1412   delete [] InParametersList ;
1413   delete [] OutParametersList ;
1414
1415               
1416   SendEvent( NewEvent );
1417
1418 //  cdebug << ThreadNo() << " <-- DataReady_ExecuteAction " << Name() << endl;
1419   return 1 ;
1420 }
1421
1422 int GraphExecutor::InNode::Executing_SuspendAction() {
1423   _OutNode->PushEvent( this , GraphExecutor::SuspendedExecutingEvent ,
1424                        SUPERV::SuspendedExecutingState ) ; 
1425   cdebug << ThreadNo() << " Executing_SuspendAction " << Name() << endl;
1426   return 1 ;
1427 }
1428
1429 int GraphExecutor::InNode::SuspendedExecuting_ResumeAction() {
1430   cdebug << ThreadNo() << " SuspendedExecuting_ResumeAction " << Name() << endl;
1431   SUPERV::AutomatonState next_state ;
1432   next_state = Automaton()->NextState( State() , GraphExecutor::ExecutingEvent ) ;
1433   _OutNode->NewThread() ; // Only for Threads count
1434   _OutNode->PushEvent( this , GraphExecutor::ResumedExecutingEvent ,
1435                        next_state ) ; 
1436   State( next_state ) ;
1437   return 1 ;
1438 }
1439
1440 int GraphExecutor::InNode::Executing_KillAction() {
1441   cdebug << ThreadNo() << " Executing_KillAction " << Name() << endl;
1442   int RetVal = 0 ;
1443   if ( pthread_self() == ThreadNo() ) {
1444     cdebug << "Executing_KillAction would pthread_canceled itself" << endl ;
1445     KillAction() ;
1446     _OutNode->PushEvent( this , GraphExecutor::KilledExecutingEvent ,
1447                          SUPERV::KilledExecutingState ) ; 
1448     RetVal = 1 ;
1449   }
1450   else if ( pthread_cancel( ThreadNo() ) ) {
1451     perror("Executing_KillAction pthread_cancel error") ;
1452   }
1453   else {
1454     cdebug << "Executing_KillAction : ThreadId " << ThreadNo()
1455            << " pthread_canceled" << endl ;
1456     KillAction() ;
1457     _OutNode->ExitThread() ;
1458     _OutNode->PushEvent( this , GraphExecutor::KilledExecutingEvent ,
1459                          SUPERV::KilledExecutingState ) ; 
1460   }
1461   return RetVal ;
1462 }
1463
1464 int GraphExecutor::InNode::Executing_StopAction() {
1465   cdebug << ThreadNo() << " Executing_StopAction " << Name() << endl;
1466   int RetVal = 0 ;
1467   if ( pthread_cancel( ThreadNo() ) ) {
1468     perror("Executing_KillAction pthread_cancel error") ;
1469   }
1470   else {
1471     cdebug << "Executing_KillAction : ThreadId " << ThreadNo()
1472            << " pthread_canceled" << endl ;
1473     StopAction() ;
1474     _OutNode->ExitThread() ;
1475     _OutNode->PushEvent( this , GraphExecutor::StoppedExecutingEvent ,
1476                          SUPERV::StoppedExecutingState ) ; 
1477   }
1478   return RetVal ;
1479 }
1480
1481 int GraphExecutor::InNode::Executing_SuccessAction() {
1482 //  cdebug << ThreadNo() << " --> Executing_SuccessAction " << Name() << endl;
1483   _OutNode->PushEvent( this , GraphExecutor::SuccessedExecutingEvent ,
1484                        SUPERV::SuccessedState ) ; 
1485   SUPERV::ControlState aControl = ControlState() ;
1486   switch ( aControl ) {
1487   case SUPERV::VoidState : {
1488     SendEvent( SuccessEvent ) ;
1489     break ;
1490   }
1491   case SUPERV::ToSuspendState : {
1492     SendEvent( SuccessEvent ) ;
1493     break ;
1494   }
1495   case SUPERV::ToSuspendDoneState : {
1496     SendEvent( GraphExecutor::SuspendEvent ) ;
1497     return 1 ;
1498   }
1499   case SUPERV::ToKillState : {
1500     SendEvent( GraphExecutor::KillEvent ) ;
1501     return 1 ;
1502   }
1503   case SUPERV::ToKillDoneState : {
1504     SendEvent( GraphExecutor::KillEvent ) ;
1505     return 1 ;
1506   }
1507   case SUPERV::ToStopState : {
1508     SendEvent( GraphExecutor::StopEvent ) ;
1509     return 1 ;
1510   }
1511   default : {
1512     cdebug << ThreadNo()
1513            << " GraphExecutor::InNodeThreads::Executing_SuccessAction Error Undefined Control : "
1514            << aControl << endl ;
1515     return 0;
1516   }
1517   }
1518 //  cdebug << ThreadNo() << " <-- Executing_SuccessAction "  << Name() << endl;
1519   return 1 ;
1520 }
1521
1522 int GraphExecutor::InNode::Executing_ErrorAction() {
1523   cdebug << ThreadNo() << " --> Executing_ErrorAction " << Name() << endl;
1524   _OutNode->PushEvent( this , GraphExecutor::ErroredExecutingEvent ,
1525                        SUPERV::ErroredState ) ; 
1526
1527   SUPERV::ControlState aControl = ControlState() ;
1528   switch ( aControl ) {
1529   case SUPERV::VoidState : {
1530     SendEvent( ErrorEvent ) ;
1531     break ;
1532   }
1533   case SUPERV::ToSuspendState : {
1534     SendEvent( ErrorEvent ) ;
1535     break ;
1536   }
1537   case SUPERV::ToSuspendDoneState : {
1538     SendEvent( GraphExecutor::SuspendEvent ) ;
1539     return 1 ;
1540   }
1541   case SUPERV::ToKillState : {
1542     SendEvent( GraphExecutor::KillEvent ) ;
1543     return 1 ;
1544   }
1545   case SUPERV::ToKillDoneState : {
1546     SendEvent( GraphExecutor::KillEvent ) ;
1547     return 1 ;
1548   }
1549   case SUPERV::ToStopState : {
1550     SendEvent( GraphExecutor::StopEvent ) ;
1551     return 1 ;
1552   }
1553   default : {
1554     cdebug << ThreadNo()
1555            << " GraphExecutor::InNodeThreads::Executing_ErrorAction Error Undefined Control : "
1556            << aControl << endl ;
1557     return 0;
1558   }
1559   }
1560   cdebug << ThreadNo() << " <-- Executing_ErrorAction "  << Name() << endl;
1561   return 1 ;
1562 }
1563
1564 // Set SUPERV::WaitingState to all InPorts 
1565 void GraphExecutor::InNode::SetWaitingStates(GraphExecutor::InNode * EndNode ) {
1566   int i ;
1567   int j ;
1568   bool docdebug = false ;
1569   State( SUPERV::DataWaitingState ) ;
1570   for ( i = 0 ; i < GetNodeInPortsSize() ; i++ ) {
1571     GraphBase::InPort * anInPort = GetChangeNodeInPort( i ) ;
1572     if ( anInPort->IsGate() ) { // Loop : Open the doors
1573       GraphBase::OutPort * anOutPort = anInPort->GetOutPort() ;
1574       if ( anOutPort ) {
1575         CORBA::Any * anAny = new CORBA::Any() ;
1576         *anAny <<= (long ) 1 ;
1577         anOutPort->Value( anAny ) ;
1578         anInPort->State( SUPERV::ReadyState ) ;
1579       }
1580     }
1581     else if ( anInPort->State() != SUPERV::WaitingState ) {
1582       if ( !docdebug ) {
1583 //        cdebug << ThreadNo()
1584 //               << " --> GraphExecutor::InNodeThreads::SetWaitingStates " << Name() << endl;
1585         docdebug = true ;
1586       }
1587       anInPort->State( SUPERV::WaitingState ) ;
1588     }
1589   }
1590   for ( i = 0 ; i < GetNodeOutPortsSize() ; i++ ) {
1591     for ( j = 0 ; j < GetChangeNodeOutPort( i )->InPortsSize() ; j++ ) {
1592       GraphBase::OutPort * anOutPort = GetChangeNodeOutPort( i ) ;
1593       if ( !( IsGOTONode() && anOutPort->IsGate() ) &&
1594            !( IsEndLoopNode() && ( anOutPort->IsGate() || anOutPort->IsLoop() ) ) ) {
1595         GraphExecutor::InNode * aNode = (GraphExecutor::InNode * ) _OutNode->GetChangeGraphNode( anOutPort->ChangeInPorts( j )->NodeName() )->GetInNode() ;
1596         if ( aNode != EndNode ) {
1597           aNode->SetWaitingStates( EndNode ) ;
1598         }
1599       }
1600     }
1601   }
1602 }
1603
1604 int GraphExecutor::InNode::Successed_SuccessAction() {
1605 //  cdebug << ThreadNo() << " --> Successed_SuccessAction "  << Name() << endl;
1606   int res = 1;
1607   int linkednodesnumber = LinkedNodesSize() ;
1608   GraphExecutor::InNode *firstzeroNode = NULL ;
1609   GraphExecutor::InNode *firsttoNode = NULL ;
1610   GraphExecutor::InNode *toNode ;
1611   int i ;
1612   int j ;
1613   list<GraphExecutor::InNode *> SomeDataNodes ;
1614
1615   DoneAction() ;
1616
1617   if ( IsGOTONode() ||
1618        ( IsEndLoopNode() && GetNodeInLoop()->GetOutPort()->BoolValue() ) ) {
1619     const GraphBase::OutPort * aGateOutPort ;
1620     if ( IsGOTONode() ) {
1621       aGateOutPort = GetNodeOutGate() ;
1622     }
1623     else {
1624       aGateOutPort = GetNodeOutLoop() ;
1625     }
1626     for ( i = 0 ; i < aGateOutPort->InPortsSize() ; i++ ) {
1627       const GraphBase::InPort * anInPort = aGateOutPort->InPorts( i ) ;
1628       GraphExecutor::InNode * aLabelNode = (GraphExecutor::InNode *) _OutNode->GetChangeGraphNode( anInPort->NodeName() )->GetInNode() ;
1629 //      cdebug << ThreadNo() << " Successed_SuccessAction " << Name() << " will Loop to HeadNode "
1630 //             << aLabelNode->Name() << " from port " << anInPort->PortName() << endl ;
1631       aLabelNode->SetWaitingStates( this ) ;
1632       for ( j = 0 ; j < aLabelNode->GetNodeInPortsSize() ; j++ ) {
1633         const GraphBase::InPort * anInPort = aLabelNode->GetNodeInPort( j ) ;
1634         if ( anInPort->GetOutPort() ) {
1635 //          cdebug << aLabelNode->Name() << "(" << anInPort->PortName() << ") value : "
1636 //                 << anInPort->GetOutPort()->NodeName() << "(" << anInPort->GetOutPort()->PortName() << ")"
1637 //                 << endl ;
1638         }
1639       }
1640       for ( j = 0 ; j < GetNodeOutPortsSize() ; j++ ) {
1641         GraphBase::OutPort * aBusParamOutPort = GetChangeNodeOutPort( j ) ;
1642         if ( !aBusParamOutPort->IsGate() ) {
1643           GraphBase::InPort * aBusParamChangeInPort = NULL ;
1644           if ( aBusParamOutPort->IsLoop() ) {
1645             aBusParamChangeInPort = aLabelNode->GetChangeNodeInLoop() ;
1646           }
1647           else {
1648             aBusParamChangeInPort = aLabelNode->GetChangeInPort( aBusParamOutPort->PortName() ) ;
1649           }
1650           if ( aBusParamChangeInPort ) {
1651             aBusParamChangeInPort->ChangeOutPort( aBusParamOutPort ) ;
1652 //            cdebug << ThreadNo() << " Successed_SuccessAction " << Name() << " ChangeOutPort to HeadNode "
1653 //                   << aLabelNode->Name() << "(" << aBusParamChangeInPort->PortName() << ") from port "
1654 //                   << aBusParamOutPort->PortName() << endl ;
1655             if ( !aLabelNode->IsLockedDataWait() ) {
1656               res = aLabelNode->SendSomeDataReady( Name() ) ;
1657               if ( res ) {
1658                 if ( firsttoNode == NULL &&
1659                      aLabelNode->ThreadNo() == pthread_self() ) {
1660                   firsttoNode = aLabelNode ;
1661 //                  cdebug << ThreadNo() << " Successed_SuccessAction firsttoNode "
1662 //                         << aLabelNode->Name() << endl ;
1663                 }
1664                 else if ( firstzeroNode == NULL &&
1665                           aLabelNode->ThreadNo() == 0 ) {
1666                   firstzeroNode = aLabelNode ;
1667                 }
1668                 else {
1669                   SomeDataNodes.push_back( aLabelNode ) ;
1670 //                  cdebug << ThreadNo() << " Successed_SuccessAction " << Name() << " push "
1671 //                         << aLabelNode->Name() << " " << SomeDataNodes.size() 
1672 //                         << endl ;
1673                 }
1674               }
1675             }
1676             else {
1677 //              cdebug << ThreadNo()
1678 //                     << " Successed_SuccessAction Loop to HeadNode "
1679 //                     << aLabelNode->Name() << " with datas from " << Name() << "("
1680 //                     << aBusParamOutPort->PortName() << ") to port "
1681 //                     << aBusParamChangeInPort->PortName() << endl;
1682             }
1683           }
1684           else {
1685 //            cdebug << ThreadNo() << " ERROR in Successed_SuccessAction of " << Name()
1686 //                   << " NO port " << aBusParamOutPort->PortName() << " in "
1687 //                   << aLabelNode->Name() << endl;
1688           }
1689         }
1690       }
1691       for ( j = 0 ; j < aLabelNode->GetNodeInPortsSize() ; j++ ) {
1692         const GraphBase::InPort * anInPort = aLabelNode->GetNodeInPort( j ) ;
1693         if ( anInPort->GetOutPort() ) {
1694 //          cdebug << aLabelNode->Name() << "(" << anInPort->PortName() << ") value : "
1695 //                 << anInPort->GetOutPort()->NodeName() << "(" << anInPort->GetOutPort()->PortName() << ")"
1696 //                 << endl ;
1697         }
1698       }
1699       const GraphBase::InPort * aGateInPort = aLabelNode->GetNodeInGate() ;
1700       if ( aGateInPort ) {
1701         if ( aGateInPort->GetOutPort() ) {
1702           aGateInPort->GetOutPort()->Value( aGateOutPort->Value() ) ;
1703         }
1704         if ( !aLabelNode->IsLockedDataWait() ) {
1705           res = aLabelNode->SendSomeDataReady( Name() ) ;
1706           if ( res ) {
1707             if ( firsttoNode == NULL &&
1708                  aLabelNode->ThreadNo() == pthread_self() ) {
1709               firsttoNode = aLabelNode ;
1710 //              cdebug << ThreadNo() << " Successed_SuccessAction firsttoNode "
1711 //                     << aLabelNode->Name() << endl ;
1712             }
1713             else if ( firstzeroNode == NULL &&
1714                       aLabelNode->ThreadNo() == 0 ) {
1715               firstzeroNode = aLabelNode ;
1716             }
1717             else {
1718               SomeDataNodes.push_back( aLabelNode ) ;
1719 //              cdebug << ThreadNo() << " Successed_SuccessAction " << Name() << " push "
1720 //                     << aLabelNode->Name() << " " << SomeDataNodes.size()
1721 //                     << endl ;
1722             }
1723           }
1724         }
1725       }
1726       else {
1727         cdebug << ThreadNo() << " ERROR in Successed_SuccessAction of " << Name()
1728                << " NO port " << aGateOutPort->PortName() << " in "
1729                << aLabelNode->Name() << endl;
1730       }
1731     }
1732   }
1733
1734   else {
1735 //    cdebug << ThreadNo() << " Successed_SuccessAction of " << Name()
1736 //           << " with " << LinkedNodesSize() << " linked nodes :" ;
1737     for ( i = 0 ; i < LinkedNodesSize() ; i++ ) {
1738       if ( LinkedNodes( i )->IsDataFlowNode() ) {
1739         linkednodesnumber -= 1 ;
1740       }
1741 //      cdebug << " " << LinkedNodes( i )->Name() ;
1742     }
1743 //    cdebug << endl;
1744     for ( i = 0 ; i < LinkedNodesSize() ; i++ ) {
1745       bool IgnoreForEndLoop = false ;
1746       toNode = (GraphExecutor::InNode *) LinkedNodes( i )->GetInNode() ;
1747 //      cdebug << ThreadNo() << " Successed_SuccessAction of " << Name()
1748 //             << " [" << i << "] " << LinkedNodes( i )->Name() << endl ;
1749       if ( toNode && !toNode->IsDataFlowNode() ) {
1750         if ( IsComputingNode() && toNode->IsInLineNode() ) {
1751           GraphBase::InPort * toGateInPort = toNode->GetChangeNodeInGate() ;
1752           toGateInPort->State( SUPERV::ReadyState ) ;
1753           GraphBase::OutPort * GateOutPort = toGateInPort->GetOutPort() ;
1754           if ( GateOutPort ) {
1755             GateOutPort->PortStatus( DataConnected );
1756             GateOutPort->State( SUPERV::ReadyState ) ;
1757             GateOutPort->Done( true ) ;
1758           }
1759         }
1760       }
1761       if ( toNode && IsLoopNode() ) {
1762         GraphBase::OutPort * fromLoopOutPort = GetChangeNodeOutLoop() ;
1763         if ( !fromLoopOutPort->BoolValue() ) { // Ne pas faire la boucle
1764           if ( strcmp( toNode->Name() , CoupledNode()->Name() ) ) {
1765             IgnoreForEndLoop = true ;
1766           }
1767           else { // toNode is the EndLoopNode
1768             GraphBase::InPort * toLoopInPort ;
1769             toLoopInPort = toNode->GetChangeNodeInLoop() ;
1770             if ( toLoopInPort->State() != SUPERV::ReadyState ) {
1771               toLoopInPort->State( SUPERV::ReadyState ) ;
1772             }
1773           }
1774         }
1775       }
1776       else if ( toNode && IsSwitchNode() ) {
1777       }
1778       else if ( toNode && toNode->IsInLineNode() ) {
1779         int j ;
1780         for ( j = 0 ; j < toNode->GetNodeInPortsSize() ; j++ ) {
1781           toNode->GetChangeNodeInPort( j )->InitialOutPort() ;
1782         }
1783       }
1784       if ( toNode && !IgnoreForEndLoop ) {
1785         if ( toNode && toNode->IsLoopNode() ) {
1786           GraphBase::InPort * toLoopInPort = toNode->GetChangeNodeInLoop() ;
1787           toLoopInPort->State( SUPERV::ReadyState ) ;
1788           GraphBase::OutPort * LoopOutPort = toLoopInPort->GetOutPort() ;
1789           LoopOutPort->PortStatus( DataConnected );
1790           LoopOutPort->State( SUPERV::ReadyState ) ;
1791           LoopOutPort->Done( true ) ;
1792           CORBA::Any * anAny = new CORBA::Any() ;
1793           *anAny <<= (long ) 1 ;
1794           LoopOutPort->Value( anAny ) ;
1795           int j ;
1796           for ( j = 0 ; j < toNode->GetNodeInPortsSize() ; j++ ) {
1797             toNode->GetChangeNodeInPort( j )->InitialOutPort() ;
1798           }
1799         }
1800         res = toNode->SendSomeDataReady( Name() ) ;
1801         if ( res ) {
1802           if ( firsttoNode == NULL &&
1803                toNode->ThreadNo() == pthread_self() ) {
1804             firsttoNode = toNode ;
1805 //            cdebug << ThreadNo() << " Successed_SuccessAction firsttoNode "
1806 //                   << toNode->Name() << endl ;
1807           }
1808           else if ( firstzeroNode == NULL &&
1809                     toNode->ThreadNo() == 0 ) {
1810             firstzeroNode = toNode ;
1811           }
1812           else {
1813             SomeDataNodes.push_back( toNode ) ;
1814 //            cdebug << ThreadNo() << " Successed_SuccessAction " << Name() << " push "
1815 //                   << toNode->Name() << " " << SomeDataNodes.size() << endl ;
1816           }
1817         }
1818       }
1819     }
1820   }
1821
1822   if ( firsttoNode == NULL && firstzeroNode ) {
1823     firsttoNode = firstzeroNode ;
1824 //    cdebug << ThreadNo()
1825 //           << " Successed_SuccessAction firsttoNode = firstzeroNode "
1826 //           << endl ;
1827   }
1828   else if ( firsttoNode && firstzeroNode ) {
1829     SomeDataNodes.push_back( firstzeroNode ) ;
1830 //    cdebug << ThreadNo() << " Successed_SuccessAction " << Name() << " push firstzeroNode "
1831 //           << firstzeroNode->Name() << " " << SomeDataNodes.size() << endl ;
1832   }
1833
1834   while ( SomeDataNodes.size() ) {
1835     GraphExecutor::InNode *aNode = SomeDataNodes.front() ;
1836     SomeDataNodes.pop_front() ;
1837 //    cdebug << pthread_self() << "/" << ThreadNo()
1838 //           << " Successed_SuccessAction pop "
1839 //           << SomeDataNodes.size() << " " << aNode->Name() << endl ;
1840     if ( aNode->State() == SUPERV::DataReadyState ) {
1841       aNode->CreateNewThreadIf( true ) ;
1842       aNode->UnLockDataWait() ;
1843       res = aNode->DataUndef_AllDataReadyAction() ;
1844     }
1845     else {
1846 //      cdebug << pthread_self() << "/" << ThreadNo() << " ERROR "
1847 //             << aNode->Name() << " "
1848 //             << Automaton()->StateName( aNode->State() ) << endl ;
1849     }
1850   }
1851
1852   if ( firsttoNode ) {
1853 //    cdebug << pthread_self() << "/" << ThreadNo()
1854 //           << " Successed_SuccessAction start firsttoNode "
1855 //           << SomeDataNodes.size() << " " << firsttoNode->Name() << endl ;
1856     firsttoNode->CreateNewThreadIf( false ) ;
1857     firsttoNode->RewindStack( RewindStack() ) ;
1858     if ( firsttoNode->State() == SUPERV::SuccessedState ) {
1859 //      cdebug << pthread_self() << "/" << ThreadNo() << " " << Name()
1860 //             << " : " << firsttoNode->Name() << " "
1861 //             << Automaton()->StateName( firsttoNode->State() )
1862 //             << " --> DataWaitingState for Thread "
1863 //             << firsttoNode->ThreadNo() << endl ;
1864       firsttoNode->State( SUPERV::DataWaitingState ) ;
1865     }
1866 //    pthread_t OldT = firsttoNode->ThreadNo() ;
1867     firsttoNode->ThreadNo( pthread_self() ) ;
1868 // On continue avec le meme thread
1869 //    cdebug << pthread_self() << "/" << ThreadNo() << " firsttoNode "
1870 //           << firsttoNode->Name() << "Thread(" << OldT << "-->"
1871 //           << firsttoNode->ThreadNo() << ")" << endl ;
1872     ThreadNo( 0 ) ;
1873 //    cdebug << ThreadNo() << " Successed_SuccessAction " << Name()
1874 //           << " for " << firsttoNode->Name()
1875 //           << " !firsttoNode->CreateNewThreadIf() "
1876 //           << !firsttoNode->CreateNewThreadIf()
1877 //           << " " << Automaton()->StateName( firsttoNode->State() ) ;
1878     if ( firsttoNode->State() == SUPERV::DataReadyState ) {
1879       cdebug << endl ;
1880       firsttoNode->UnLockDataWait() ;
1881       res = firsttoNode->DataUndef_AllDataReadyAction() ;
1882     }
1883     else {
1884       cdebug << " ERROR " << endl ;
1885     }
1886   }
1887   else {
1888 //    cdebug << ThreadNo() << " Successed_SuccessAction " << Name()
1889 //           << " NO DataReady ==> ThreadNo( 0 ) firsttoNode == NULL LINKEDnodesnumber " << linkednodesnumber << endl ;
1890     ThreadNo( 0 ) ;
1891   }
1892
1893 //  if ( linkednodesnumber == 0 && firsttoNode == NULL ) {
1894 //    cdebug << ThreadNo() << " Successed_SuccessAction " << Name() << " LinkedNodesSize " << LinkedNodesSize()
1895 //           << " firsttoNode == NULL LINKEDnodesnumber " << linkednodesnumber << " CHECK" << endl ;
1896 //    _OutNode->CheckAllDone() ;
1897 //  }
1898
1899 //  cdebug << pthread_self() << "/" << ThreadNo()
1900 //         << " <-- Successed_SuccessAction " << Name() << " linkednodesnumber "
1901 //         << linkednodesnumber << endl;
1902   return 1 ;
1903 }
1904
1905 bool GraphExecutor::InNode::SendSomeDataReady( char * FromNodeName ) {
1906   bool RetVal = false ;
1907   if ( IsDataFlowNode() ) {
1908 //    cdebug << ThreadNo() << " ----> " << Name()
1909 //         << " send Result to graph " << Name() << endl;
1910   }
1911   else {
1912 //    cdebug << pthread_self() << "/" << ThreadNo() << " ----> " << FromNodeName
1913 //           << " send SomeDataReady to " << Name() << " "
1914 //           << Automaton()->StateName( State() ) 
1915 //           << " CreateNewThreadIf() " << CreateNewThreadIf()
1916 //           << " LockedDataWait " << IsLockedDataWait() << endl;
1917 #if 0
1918     cout << pthread_self() << "/" << ThreadNo() << " ----> " << FromNodeName
1919          << " send SomeDataReady to " << Name() << " "
1920          << Automaton()->StateName( State() ) 
1921          << " CreateNewThreadIf() " << CreateNewThreadIf()
1922          << " LockedDataWait " << IsLockedDataWait() << endl;
1923 #endif
1924     if ( State() == SUPERV::SuccessedState ||
1925          State() == SUPERV::SuspendedSuccessedState ||
1926          State() == SUPERV::SuspendedSuccessedToReStartState ) {
1927 //      cdebug << ThreadNo() << " " << FromNodeName
1928 //             << " : " << Name() << " " << Automaton()->StateName( State() )
1929 //             << " --> DataWaitingState for Thread "
1930 //             << ThreadNo() << " " << endl ;
1931       State( SUPERV::DataWaitingState ) ;
1932     }
1933     LockDataWait() ;
1934     DataFromNode( FromNodeName ) ;
1935     RetVal = !SendEvent( GraphExecutor::SomeDataReadyEvent );
1936     if ( !RetVal ) {
1937       UnLockDataWait() ;
1938     }
1939   }
1940   return RetVal ;
1941 }
1942
1943 int GraphExecutor::InNode::Errored_ErrorAction() {
1944   cdebug << ThreadNo() << " Errored_ErrorAction " << Name()
1945          << " will pthread_exit" << endl;
1946   DoneAction() ;
1947   return 1 ;
1948 }
1949
1950 int GraphExecutor::InNode::Successed_SuspendAction() {
1951   cdebug << ThreadNo() << " Successed_SuspendAction -->Suspend " << Name()
1952          << " Threads " << _OutNode->Threads() << " SuspendedThreads "
1953          << _OutNode->SuspendedThreads() << endl;
1954   _OutNode->PushEvent( this , GraphExecutor::SuspendedSuccessedEvent ,
1955                        SUPERV::SuspendedSuccessedState ) ; 
1956   DoneAction() ;
1957   GraphExecutor::InNode * aReStartNode = SuspendAction() ;
1958   cdebug << ThreadNo() << " Successed_SuspendAction Resumed " << Name() ;
1959   if ( aReStartNode ) {
1960     _aReStartNode = NULL ;
1961     cdebug << " for " << aReStartNode->Name() << endl;
1962     aReStartNode->SendEvent( _aReStartEvent ) ;
1963   }
1964   else {
1965     cdebug << endl;
1966     SendEvent( GraphExecutor::ResumeEvent ) ;
1967   }
1968   return 1 ;
1969 }
1970
1971 int GraphExecutor::InNode::Errored_SuspendAction() {
1972   cdebug << ThreadNo() << " Errored_SuspendAction -->Suspend " << Name()
1973          << " Threads " << _OutNode->Threads() << " SuspendedThreads "
1974          << _OutNode->SuspendedThreads() << endl;
1975   _OutNode->PushEvent( this , GraphExecutor::SuspendedErroredEvent ,
1976                        SUPERV::SuspendedErroredState ) ; 
1977   DoneAction() ;
1978   GraphExecutor::InNode * aReStartNode = SuspendAction() ;
1979   cdebug << ThreadNo() << " Errored_SuspendAction Resumed " << Name()
1980          << endl;
1981   if ( aReStartNode ) {
1982     _aReStartNode = NULL ;
1983     aReStartNode->SendEvent( _aReStartEvent ) ;
1984   }
1985   else {
1986     SendEvent( GraphExecutor::ResumeEvent ) ;
1987   }
1988   return 1 ;
1989 }
1990
1991 int GraphExecutor::InNode::SuspendedSuccessed_ResumeAction() {
1992   cdebug << ThreadNo() << " SuspendedSuccessed_ResumeAction " << Name() << endl;
1993 //  ResumeAction() ;
1994   _OutNode->PushEvent( this , GraphExecutor::ResumedSuccessedEvent ,
1995                        SUPERV::ResumedSuccessedState ) ; 
1996   SendEvent( ResumedSuccessedEvent ) ;
1997   return 1 ;
1998 }
1999
2000 int GraphExecutor::InNode::SuspendedErrored_ResumeAction() {
2001   cdebug << ThreadNo() << " SuspendedErrored_ResumeAction " << Name() << endl;
2002 //  ResumeAction() ;
2003   _OutNode->PushEvent( this , GraphExecutor::ResumedErroredEvent ,
2004                        SUPERV::ResumedErroredState ) ; 
2005   SendEvent( ResumedErroredEvent ) ;
2006   return 1 ;
2007 }
2008
2009 int GraphExecutor::InNode::Successed_KillAction() {
2010   KillAction() ;
2011   _OutNode->PushEvent( this , GraphExecutor::KilledEvent ,
2012                        SUPERV::KilledSuccessedState ) ; 
2013   cdebug << ThreadNo() << " Successed_KillAction " << Name() << endl;
2014   return 1 ;
2015 }
2016
2017 int GraphExecutor::InNode::Errored_KillAction() {
2018   KillAction() ;
2019   _OutNode->PushEvent( this , GraphExecutor::KilledEvent ,
2020                        SUPERV::KilledErroredState ) ; 
2021   cdebug << ThreadNo() << " Errored_KillAction " << Name() << endl;
2022   return 1 ;
2023 }
2024
2025 int GraphExecutor::InNode::Successed_StopAction() {
2026   StopAction() ;
2027   _OutNode->PushEvent( this , GraphExecutor::StoppedEvent ,
2028                        SUPERV::StoppedSuccessedState ) ; 
2029   cdebug << ThreadNo() << " Successed_StopAction " << Name() << endl;
2030   return 1 ;
2031 }
2032
2033 int GraphExecutor::InNode::Errored_StopAction() {
2034   StopAction() ;
2035   _OutNode->PushEvent( this , GraphExecutor::StoppedEvent ,
2036                        SUPERV::StoppedErroredState ) ; 
2037   cdebug << ThreadNo() << " Errored_StopAction " << Name() << endl;
2038   return 1 ;
2039 }
2040
2041 int GraphExecutor::InNode::SuspendedSuccessed_ReStartAction() {
2042   cdebug << ThreadNo() << " SuspendedSuccessed_ReStartAction " << Name() << endl;
2043   _OutNode->PushEvent( this , GraphExecutor::ReStartedEvent ,
2044                        SUPERV::ReStartedState ) ;
2045   int i ;
2046   for ( i = 0 ; i < GetNodeInPortsSize() ; i++ ) {
2047     GetChangeNodeInPort( i )->State( SUPERV::ReadyState ) ;
2048   }
2049   SendEvent( ExecuteEvent ) ;
2050   cdebug << ThreadNo() << " SuspendedSuccessed_ReStartAction "  << Name() << endl;
2051   return 1 ;
2052 }
2053
2054 int GraphExecutor::InNode::SuspendedErrored_ReStartAction() {
2055   cdebug << ThreadNo() << " SuspendedErrored_ReStartAction " << Name() << endl;
2056   _OutNode->PushEvent( this , GraphExecutor::ReStartedEvent ,
2057                        SUPERV::ReStartedState ) ; 
2058   int i ;
2059   for ( i = 0 ; i < GetNodeInPortsSize() ; i++ ) {
2060     GetChangeNodeInPort( i )->State( SUPERV::ReadyState ) ;
2061   }
2062   SendEvent( ExecuteEvent ) ;
2063   cdebug << ThreadNo() << " SuspendedErrored_ReStartAction "  << Name() << endl;
2064   return 1 ;
2065 }
2066
2067 int GraphExecutor::InNode::SuspendedSuccessed_ReStartAndSuspendAction() {
2068   cdebug << ThreadNo() << " SuspendedSuccessed_ReStartAndSuspendAction " << Name()
2069          << endl;
2070   _OutNode->PushEvent( this , GraphExecutor::ReStartedAndSuspendEvent ,
2071                        SUPERV::ReStartedState ) ; 
2072   State( SUPERV::DataWaitingState ) ;
2073   if ( !Suspend() ) {
2074     cdebug << "InNode::Suspend() Node " << Name() << endl ;
2075     return false ;
2076   }
2077   else if ( SendEvent( GraphExecutor::SomeDataReadyEvent ) ) {
2078     cdebug << "InNode::SendEvent( SomeDataReadyEvent ) Node "
2079            << Name() << endl ;
2080     return false ;
2081   }
2082   cdebug << ThreadNo() << " SuspendedSuccessed_ReStartAndSuspendAction "  << Name()
2083          << endl;
2084   return 1 ;
2085 }
2086
2087 int GraphExecutor::InNode::SuspendedErrored_ReStartAndSuspendAction() {
2088   cdebug << ThreadNo() << " SuspendedErrored_ReStartAndSuspendAction " << Name()
2089          << endl;
2090   _OutNode->PushEvent( this , GraphExecutor::ReStartedAndSuspendEvent ,
2091                        SUPERV::ReStartedState ) ; 
2092   State( SUPERV::DataWaitingState ) ;
2093   if ( !Suspend() ) {
2094     cdebug << "InNode::Suspend() Node " << Name() << endl ;
2095     return false ;
2096   }
2097   else if ( SendEvent( GraphExecutor::SomeDataReadyEvent ) ) {
2098     cdebug << "InNode::SendEvent( SomeDataReadyEvent ) Node "
2099            << Name() << endl ;
2100     return false ;
2101   }
2102   cdebug << ThreadNo() << " SuspendedErrored_ReStartAndSuspendAction "  << Name()
2103          << endl;
2104   return 1 ;
2105 }
2106
2107 void GraphExecutor::InNode::InParametersSet( bool & Err ,
2108                                              int  nInParams ,
2109                                              ServicesAnyData * InParametersList ) {
2110   int i ;
2111   for ( i = 0 ; i < nInParams ; i++ ) {
2112     ServicesAnyData D = InParametersList[i];
2113     GraphBase::InPort * anInPort = GetChangeNodeInPort(i) ;
2114     GraphBase::OutPort * theOutPort = anInPort->GetOutPort() ;
2115     if ( anInPort->IsGate() && theOutPort == NULL ) {
2116       cdebug << ThreadNo() << " ArgIn" << i << " " << D.Name << " "
2117              << anInPort->GetServicesParameter().Parametertype
2118              << " is inactive. " << anInPort->Kind() << endl ;
2119     }
2120     else if ( anInPort->State() == SUPERV::ReadyState ) {
2121       if ( anInPort->IsGate() ) {
2122         CORBA::Any * anAny = new CORBA::Any() ;
2123         *anAny <<= (long ) 0 ;
2124         theOutPort->Value( anAny ) ;
2125       }
2126       anInPort->State( SUPERV::WaitingState ) ;
2127       D.Name = CORBA::string_dup( anInPort->GetServicesParameter().Parametername ) ;
2128       cdebug << ThreadNo() << " ArgIn" << i << " " << anInPort->Kind() ;
2129       cdebug << "      " << D.Name << " " << anInPort->GetServicesParameter().Parametertype << " : " ;
2130       D.Value = *theOutPort->Value() ; // CORBA::Any
2131       string _Type = CORBA::string_dup( anInPort->GetServicesParameter().Parametertype ) ;
2132       const char * Type = _Type.c_str() ;
2133       switch ( D.Value.type()->kind() ) { // { string , long , double , objref }
2134       case CORBA::tk_string:
2135         char * t;
2136         D.Value >>= t;
2137         cdebug << t << " (string)" ;
2138         if ( !strcmp( Type , "string" ) ) {
2139         }
2140         else if ( !strcmp( Type , "boolean" ) ) {
2141           bool b ;
2142           long d ;
2143           sscanf( t , "%ld" , &d ) ;
2144           b = (bool ) d ;
2145           D.Value <<=  (CORBA::Any::from_boolean ) b ;
2146 //          theOutPort->Value( D.Value ) ;
2147         }
2148         else if ( !strcmp( Type , "char" ) ) {
2149           unsigned char c ;
2150           long d ;
2151           sscanf( t , "%ld" , &d ) ;
2152           c = (short ) d ;
2153           D.Value <<=  (CORBA::Any::from_char ) c ;
2154           cdebug << "string '" << t << "' --> " << d << " --> char " << c ;
2155 //          theOutPort->Value( D.Value ) ;
2156         }
2157         else if ( !strcmp( Type , "short" ) ) {
2158           short s ;
2159           long d ;
2160           sscanf( t , "%ld" , &d ) ;
2161           s = (short ) d ;
2162           D.Value <<=  s ;
2163           cdebug << "string '" << t << "' --> " << d << " --> short " << s ;
2164 //          theOutPort->Value( D.Value ) ;
2165         }
2166         else if ( !strcmp( Type , "int" ) || !strcmp( Type , "long" ) ) {
2167           long l ;
2168           sscanf( t , "%ld" , &l ) ;
2169           D.Value <<=  l ;
2170           cdebug << "string '" << t << " --> long " << l ;
2171 //          theOutPort->Value( D.Value ) ;
2172         }
2173         else if ( !strcmp( Type , "float" ) ) {
2174           double d ;
2175           sscanf( t , "%lf" , &d ) ;
2176           float f = d ;
2177           D.Value <<= f ;
2178           cdebug << "string '" << t << "' --> " << setw(25) << setprecision(18) << d << " --> float " << " = "
2179                  << setw(25) << setprecision(18) << f ;
2180 //          theOutPort->Value( D.Value ) ;
2181         }
2182         else if ( !strcmp( Type , "double" ) ) {
2183           double d ;
2184           sscanf( t , "%lf" , &d ) ;
2185           D.Value <<= d ;
2186           cdebug << "string '" << t << " --> double " << setw(25) << setprecision(18) << d ;
2187 //          theOutPort->Value( D.Value ) ;
2188         }
2189 //        else if ( !strcmp( Type , "objref" ) ) {
2190         else { // Default
2191           CORBA::Object_ptr ObjRef ;
2192           try {
2193             ObjRef = StringToObject( t ) ;
2194             D.Value <<= ObjRef ;
2195           }
2196           catch( ... ) {
2197             D.Value <<= CORBA::Object::_nil() ;
2198           }
2199 //          theOutPort->Value( D.Value ) ;
2200         }
2201 //        else {
2202 //          cdebug << " (other ERROR)" << endl ;
2203 //        }
2204         cdebug << " --> call_kind " << D.Value.type()->kind() << endl ;
2205         break;
2206       case CORBA::tk_long:
2207         long l;
2208         D.Value >>= l;
2209         cdebug << l << " (long)" << endl ;
2210         if ( !strcmp( Type , "string" ) ) {
2211           char t[40] ;
2212           sprintf( t , "%ld" , l ) ;
2213           D.Value <<= t ;
2214 //          theOutPort->Value( D.Value ) ;
2215         }
2216         else if ( !strcmp( Type , "boolean" ) ) {
2217           bool b ;
2218           b = (bool ) l ;
2219           D.Value <<=  (CORBA::Any::from_boolean ) b ;
2220 //          theOutPort->Value( D.Value ) ;
2221         }
2222         else if ( !strcmp( Type , "char" ) ) {
2223           unsigned char c ;
2224           c = (unsigned char ) l ;
2225           D.Value <<=  (CORBA::Any::from_char ) c ;
2226 //          theOutPort->Value( D.Value ) ;
2227         }
2228         else if ( !strcmp( Type , "short" ) ) {
2229           short s ;
2230           s = (short ) l ;
2231           D.Value <<=  s ;
2232 //          theOutPort->Value( D.Value ) ;
2233         }
2234         else if ( !strcmp( Type , "int" ) || !strcmp( Type , "long" ) ) {
2235         }
2236         else if ( !strcmp( Type , "float" ) ) {
2237           float f ;
2238           f = (float ) l ;
2239           D.Value <<= f ;
2240 //          theOutPort->Value( D.Value ) ;
2241         }
2242         else if ( !strcmp( Type , "double" ) ) {
2243           double d ;
2244           d = (double ) l ;
2245           D.Value <<= d ;
2246 //          theOutPort->Value( D.Value ) ;
2247         }
2248 //        else if ( !strcmp( Type , "objref" ) ) {
2249         else { // Default
2250           D.Value <<= CORBA::Object::_nil() ;
2251 //          theOutPort->Value( D.Value ) ;
2252         }
2253 //        else {
2254 //          cdebug << " (other ERROR)" << endl ;
2255 //        }
2256         cdebug << " --> call_kind " << D.Value.type()->kind() << endl ;
2257         break;
2258       case CORBA::tk_double:
2259         double d;
2260         D.Value >>= d;
2261         cdebug << d << " (double)" << endl ;
2262         if ( !strcmp( Type , "string" ) ) {
2263           char t[40] ;
2264           sprintf( t , "%lf" , d ) ;
2265           D.Value <<= t ;
2266 //          theOutPort->Value( D.Value ) ;
2267         }
2268         else if ( !strcmp( Type , "boolean" ) ) {
2269           bool b ;
2270           b = (bool ) d ;
2271           D.Value <<=  (CORBA::Any::from_boolean ) b ;
2272 //          theOutPort->Value( D.Value ) ;
2273         }
2274         else if ( !strcmp( Type , "char" ) ) {
2275           unsigned char c ;
2276           c = (unsigned char ) d ;
2277           D.Value <<=  (CORBA::Any::from_char ) c ;
2278 //          theOutPort->Value( D.Value ) ;
2279         }
2280         else if ( !strcmp( Type , "short" ) ) {
2281           short s ;
2282           s = (short ) d ;
2283           D.Value <<=  s ;
2284 //          theOutPort->Value( D.Value ) ;
2285         }
2286         else if ( !strcmp( Type , "int" ) || !strcmp( Type , "long" ) ) {
2287           long l ;
2288           l = (long ) d ;
2289           D.Value <<= l ;
2290 //          theOutPort->Value( D.Value ) ;
2291         }
2292         else if ( !strcmp( Type , "float" ) ) {
2293           float f ;
2294           f = (float ) d ;
2295           D.Value <<= f ;
2296 //          theOutPort->Value( D.Value ) ;
2297         }
2298         else if ( !strcmp( Type , "double" ) ) {
2299         }
2300 //        else if ( !strcmp( Type , "objref" ) ) {
2301         else { // Default
2302           D.Value <<= CORBA::Object::_nil() ;
2303 //          theOutPort->Value( D.Value ) ;
2304         }
2305 //        else {
2306 //          cdebug << " (other ERROR)" << endl ;
2307 //        }
2308         cdebug << " --> call_kind " << D.Value.type()->kind() << endl ;
2309         break;
2310       case CORBA::tk_objref:
2311         if ( !strcmp( Type , "string" ) ) {
2312           CORBA::Object_ptr ObjRef ;
2313           char * retstr ;
2314           try {
2315             D.Value >>= ObjRef ;
2316             retstr = ObjectToString( ObjRef ) ;
2317             D.Value <<= retstr ;
2318 //            theOutPort->Value( D.Value ) ;
2319           }
2320           catch( ... ) {
2321             if ( i != 0 ) {
2322               Err = true ;
2323             }
2324             cdebug << "ToString( object ) Catched ERROR" << endl ;
2325           }
2326         }
2327         else if ( !strcmp( Type , "boolean" ) ) {
2328           bool b = 0 ;
2329           D.Value <<=  (CORBA::Any::from_boolean ) b ;
2330 //          theOutPort->Value( D.Value ) ;
2331         }
2332         else if ( !strcmp( Type , "char" ) ) {
2333           unsigned char c = 0 ;
2334           D.Value <<=  (CORBA::Any::from_char ) c ;
2335 //          theOutPort->Value( D.Value ) ;
2336         }
2337         else if ( !strcmp( Type , "short" ) ) {
2338           short s = 0 ;
2339           D.Value <<=  s ;
2340 //          theOutPort->Value( D.Value ) ;
2341         }
2342         else if ( !strcmp( Type , "int" ) || !strcmp( Type , "long" ) ) {
2343           long l = 0 ;
2344           D.Value <<= l ;
2345 //          theOutPort->Value( D.Value ) ;
2346         }
2347         else if ( !strcmp( Type , "float" ) ) {
2348           float f = 0 ;
2349           D.Value <<= f ;
2350 //          theOutPort->Value( D.Value ) ;
2351         }
2352         else if ( !strcmp( Type , "double" ) ) {
2353           double d = 0 ;
2354           D.Value <<= d ;
2355 //          theOutPort->Value( D.Value ) ;
2356         }
2357 //        else if ( !strcmp( Type , "objref" ) ) {
2358         else { // Default
2359           CORBA::Object_ptr obj ;
2360           char * retstr ;
2361           try {
2362             D.Value >>= obj ;
2363             retstr = ObjectToString( obj ) ;
2364             cdebug << retstr << endl ;
2365           }
2366           catch( ... ) {
2367             if ( i != 0 ) {
2368               Err = true ;
2369             }
2370             cdebug << "ToString( object ) Catched ERROR" << endl ;
2371           }
2372         }
2373 //        else {
2374 //          cdebug << " (other ERROR)" << endl ;
2375 //        }
2376         cdebug << " --> call_kind " << D.Value.type()->kind() << endl ;
2377         break;
2378       default:
2379         cdebug << " (other ERROR) " << D.Value.type()->kind() << endl ;
2380       }
2381     }
2382     else {
2383       cdebug << ThreadNo() << " In" << i << " : wrong state ERROR State "
2384              << anInPort->State() << " NameState "
2385              << Automaton()->StateName( anInPort->State() ) << " PortName "
2386              << anInPort->PortName() << " Parametername "
2387              << anInPort->GetServicesParameter().Parametername << endl ;
2388       Err = true ;
2389     }
2390     InParametersList[i] = D ;
2391   }
2392 }
2393
2394 void GraphExecutor::InNode::InOutParametersSet( int nOutParams ,
2395                                                 ServicesAnyData * OutParametersList ) {
2396   int i ;
2397   for ( i = 0 ; i < nOutParams ; i++ ) {
2398     ServicesAnyData D = OutParametersList[i] ;
2399
2400     D.Name = GetChangeNodeOutPort(i)->GetServicesParameter().Parametername;
2401     string _Type = CORBA::string_dup(GetChangeNodeOutPort(i)->GetServicesParameter().Parametertype) ;
2402     const char * Type = _Type.c_str() ;
2403     bool OutDone = GetChangeNodeOutPort(i)->Done() ;
2404     cdebug << ThreadNo() << " ArgOut" << i << " " << D.Name << " Done("
2405            << OutDone << ") " << Type << " : " << endl ;
2406     if ( !strcmp( Type , "string" ) ) {
2407       D.Value <<= (char *) NULL ;
2408     }
2409     else if ( !strcmp( Type , "boolean" ) ) {
2410       bool b = 0 ;
2411       D.Value <<=  (CORBA::Any::from_boolean ) b ;
2412     }
2413     else if ( !strcmp( Type , "char" ) ) {
2414       unsigned char c = 0 ;
2415       D.Value <<=  (CORBA::Any::from_char ) c ;
2416     }
2417     else if ( !strcmp( Type , "short" ) ) {
2418       short s = 0 ;
2419       D.Value <<=  s ;
2420     }
2421     else if ( !strcmp( Type , "int" ) || !strcmp( Type , "long" ) ) {
2422       D.Value <<= (long ) 0 ;
2423     }
2424     else if ( !strcmp( Type , "float" ) ) {
2425       float f = 0 ;
2426       D.Value <<= f ;
2427     }
2428     else if ( !strcmp( Type , "double" ) ) {
2429       double d = 0 ;
2430       D.Value <<= d ;
2431     }
2432     else {
2433       D.Value <<= CORBA::Object::_nil() ;
2434     }
2435 //#if 0
2436     switch (D.Value.type()->kind()) { // { string , long , double , objref }
2437     case CORBA::tk_string:
2438       char * t;
2439       D.Value >>= t;
2440       cdebug << ThreadNo() << " " << t << "(string)" << endl ;
2441       break;
2442     case CORBA::tk_boolean:
2443       bool b ;
2444       D.Value >>= (CORBA::Any::to_boolean ) b;
2445       cdebug << ThreadNo() << " " << b << "(boolean)" << endl ;
2446       break;
2447     case CORBA::tk_char:
2448       unsigned char c ;
2449       D.Value >>= (CORBA::Any::to_char ) c;
2450       cdebug << ThreadNo() << " " << c << "(char)" << endl ;
2451       break;
2452     case CORBA::tk_short:
2453       short s;
2454       D.Value >>= s;
2455       cdebug << ThreadNo() << " " << s << "(short)" << endl ;
2456       break;
2457     case CORBA::tk_long:
2458       long l;
2459       D.Value >>= l;
2460       cdebug << ThreadNo() << " " << l << "(long)" << endl ;
2461       break;
2462     case CORBA::tk_float:
2463       float f;
2464       D.Value >>= f;
2465       cdebug << ThreadNo() << " " << f << "(float)" << endl ;
2466       break;
2467     case CORBA::tk_double:
2468       double d;
2469       D.Value >>= d;
2470       cdebug << ThreadNo() << " " << d << "(double)" << endl ;
2471       break;
2472     case CORBA::tk_objref:
2473       try {
2474         CORBA::Object_ptr obj ;
2475         char * retstr ;
2476         D.Value >>= obj ;
2477         retstr = ObjectToString( obj ) ;
2478         cdebug << ThreadNo() << retstr << endl ;
2479       }
2480       catch( ... ) {
2481         cdebug << "ToString( object ) Catched ERROR" << endl ;
2482       }
2483       break;
2484     default:
2485       cdebug << ThreadNo() << " " << "(other ERROR)" << endl ;
2486     }
2487 //#endif
2488     OutParametersList[i] = D ;
2489   }
2490 }
2491
2492 bool GraphExecutor::InNode::OutParametersSet( bool Err ,
2493                                               SUPERV::GraphState NewState ,
2494                                               int nOutParams ,
2495                                               ServicesAnyData * OutParametersList ) {
2496   bool RetVal = true ;
2497   int i ;
2498   GraphBase::OutPort * aGateOutPort = NULL ;
2499   bool OrSwitch = false ;
2500   if ( nOutParams ) {
2501     GraphBase::OutPort * anOutPort ;
2502     for ( i = 0 ; i < nOutParams ; i++ ) {
2503       anOutPort = GetChangeNodeOutPort(i) ;
2504       if ( Err ) {
2505         anOutPort->State( NewState ) ;
2506         anOutPort->Done( true ) ;
2507       }
2508       else {
2509         cdebug << ThreadNo() << " " << "Out" << i << " " << Name() << " "
2510                << anOutPort->PortName() << " " << anOutPort->Kind() ;
2511         ServicesAnyData D = OutParametersList[i] ;
2512         switch (D.Value.type()->kind()) { // { string , long , double , objref }
2513         case CORBA::tk_string: {
2514           char * t;
2515           D.Value >>= t;
2516           cdebug << ThreadNo() << " " << t << "(string)" << endl ;
2517           break;
2518         }
2519         case CORBA::tk_boolean: {
2520           bool b ;
2521           D.Value >>= (CORBA::Any::to_boolean ) b;
2522           long l = (long ) b ;
2523           D.Value <<= l ;
2524           cdebug << ThreadNo() << " " << b << "(boolean)" << endl ;
2525           break;
2526         }
2527         case CORBA::tk_char: {
2528           unsigned char c ;
2529           D.Value >>= (CORBA::Any::to_char ) c;
2530           long l = (long ) c ;
2531           D.Value <<= l ;
2532           cdebug << ThreadNo() << " " << c << "(char)" << endl ;
2533           break;
2534         }
2535         case CORBA::tk_short: {
2536           short s;
2537           D.Value >>= s;
2538           long l = (long ) s ;
2539           D.Value <<= l ;
2540           cdebug << ThreadNo() << " " << s << "(short)" << endl ;
2541           break;
2542         }
2543         case CORBA::tk_long: {
2544           long l;
2545           D.Value >>= l;
2546           cdebug << ThreadNo() << " " << l << "(long)" << endl ;
2547           break;
2548         }
2549         case CORBA::tk_float: {
2550           float f;
2551           D.Value >>= f;
2552           double d = (double ) f ;
2553           D.Value <<= d ;
2554           cdebug << ThreadNo() << " " << f << "(float)" << endl ;
2555           break;
2556         }
2557         case CORBA::tk_double: {
2558           double d;
2559           D.Value >>= d;
2560           cdebug << ThreadNo() << " " << d << "(double)" << endl ;
2561           break;
2562         }
2563         case CORBA::tk_objref: {
2564           try {
2565             CORBA::Object_ptr obj ;
2566             char * retstr ;
2567             D.Value >>= obj ;
2568             retstr = ObjectToString( obj ) ;
2569             cdebug << ThreadNo() << retstr << endl ;
2570           }
2571           catch( ... ) {
2572             cdebug << "ToString( object ) Catched ERROR" << endl ;
2573           }
2574           break;
2575         }
2576         default: {
2577           cdebug << ThreadNo() << " " << "(other ERROR)" << endl ;
2578         }
2579         }
2580         OutParametersList[i] = D ;
2581         if ( anOutPort->IsGate() ) {
2582           aGateOutPort = anOutPort ;
2583           cdebug << " Gate " ;
2584           long l = 1;
2585           OutParametersList[i].Value <<= l;
2586           anOutPort->Value( OutParametersList[i].Value );
2587         }
2588         else if ( anOutPort->IsLoop() ) {
2589           cdebug << " Loop " ;
2590           anOutPort->Value( OutParametersList[i].Value );
2591 // InLoop Port of EndLoopNode is ready :
2592           anOutPort->ChangeInPorts(0)->State( SUPERV::ReadyState ) ;
2593         }
2594         else if ( anOutPort->IsSwitch() ) {
2595           cdebug << " Switch " ;
2596           anOutPort->Value( OutParametersList[i].Value );
2597           if ( anOutPort->InPortsSize() && anOutPort->ChangeInPorts( 0 )->IsGate() ) {
2598             if ( OrSwitch && anOutPort->BoolValue() ) {
2599               cdebug << "GraphExecutor::InNodeThreads::OutParameters more than one switch is true WARNING"
2600                      << endl ;
2601             }
2602             else {
2603               OrSwitch = OrSwitch | anOutPort->BoolValue() ;
2604             }
2605           }
2606           cdebug << "OrSwitch " << OrSwitch ;
2607         }
2608         else {
2609           cdebug << " Param " ;
2610           anOutPort->Value( OutParametersList[i].Value );
2611         }
2612         anOutPort->State( NewState ) ;
2613         anOutPort->Done( true ) ;
2614         int j ;
2615         for ( j = 0 ; j < anOutPort->InPortsSize() ; j++ ) {
2616           bool fromGOTO = false ;
2617           GraphBase::OutPort * aGOTOPort = _OutNode->GetChangeGraphNode( anOutPort->ChangeInPorts( j )->NodeName() )->GetChangeNodeInGate()->GetOutPort() ;
2618           if ( aGOTOPort ) {
2619             fromGOTO = aGOTOPort->IsGOTO() ;
2620           }
2621           if ( anOutPort->ChangeInPorts( j )->IsEndSwitch() || fromGOTO ) {
2622             cdebug << anOutPort->ChangeInPorts( j )->NodeName() << "("
2623                    << anOutPort->ChangeInPorts( j )->PortName() << ","
2624                    << anOutPort->ChangeInPorts( j )->Kind() << ") WILL BE changed from "
2625                    << anOutPort->ChangeInPorts( j )->GetOutPort()->NodeName()
2626                    << "("
2627                    << anOutPort->ChangeInPorts( j )->GetOutPort()->PortName()
2628                    << ") to " << anOutPort->NodeName() << "("
2629                    << anOutPort->PortName() << ")" << endl ;
2630             anOutPort->ChangeInPorts( j )->ChangeOutPort( anOutPort ) ;
2631           }
2632           else {
2633             cdebug << anOutPort->ChangeInPorts( j )->NodeName() << "("
2634                    << anOutPort->ChangeInPorts( j )->PortName() << ","
2635                    << anOutPort->ChangeInPorts( j )->Kind() << ") NOT changed from "
2636                    << anOutPort->ChangeInPorts( j )->GetOutPort()->NodeName()
2637                    << "("
2638                    << anOutPort->ChangeInPorts( j )->GetOutPort()->PortName()
2639                    << ") to " << anOutPort->NodeName() << "("
2640                    << anOutPort->PortName() << ")" << endl ;
2641           }
2642         }
2643 //#if 0
2644         switch (anOutPort->Value()->type()->kind()) {
2645         case CORBA::tk_string:
2646           char * t;
2647           (*anOutPort->Value()) >>= t;
2648           cdebug << ThreadNo() << " Out" << i << " : " << t << "(string)" << endl ;
2649           break;
2650         case CORBA::tk_boolean:
2651           bool b ;
2652           (*anOutPort->Value()) >>= (CORBA::Any::to_boolean ) b;
2653           cdebug << ThreadNo() << " Out" << i << " : " << b << "(boolean)" << endl ;
2654           break;
2655         case CORBA::tk_char:
2656           unsigned char c ;
2657           (*anOutPort->Value()) >>= (CORBA::Any::to_char ) c;
2658           cdebug << ThreadNo() << " Out" << i << " : " << c << "(char)" << endl ;
2659           break;
2660         case CORBA::tk_short:
2661           short s;
2662           (*anOutPort->Value()) >>= s;
2663           cdebug << ThreadNo() << " Out" << i << " : " << s << "(short)" << endl ;
2664           break;
2665         case CORBA::tk_long:
2666           long l;
2667           (*anOutPort->Value()) >>= l;
2668           cdebug << ThreadNo() << " Out" << i << " : " << l << "(long)" << endl ;
2669           break;
2670         case CORBA::tk_float:
2671           float f;
2672           (*anOutPort->Value()) >>= f;
2673           cdebug << ThreadNo() << " Out" << i << " : " << f << "(float)" << endl ;
2674           break;
2675         case CORBA::tk_double:
2676           double d;
2677           (*anOutPort->Value()) >>= d;
2678           cdebug << ThreadNo() << " Out" << i << " : " << d << "(double)" << endl ;
2679           break;
2680         case CORBA::tk_objref:
2681           CORBA::Object_ptr obj ;
2682           char * retstr ;
2683           try {
2684             (*anOutPort->Value()) >>= obj ;
2685             retstr = ObjectToString( obj );
2686             cdebug << ThreadNo() << " Out" << i << " : " << "ToString( object ) "
2687                    << retstr << endl ;
2688           }
2689           catch ( ... ) {
2690             cdebug << ThreadNo() << " Out" << i << " : " << "ToString( object ) "
2691                    << "Catched ERROR" << endl ;
2692           }
2693           break;
2694         default:
2695           cdebug << ThreadNo() << " Out" << i << " : " << "(other ERROR)" << endl ;
2696           RetVal = false ;
2697         }
2698 //#endif
2699       }
2700     }
2701     if ( aGateOutPort && IsSwitchNode() ) {
2702       if ( OrSwitch ) {
2703 //        cdebug << ThreadNo() << " " << "Out0 " << Name() << " Close of "
2704 //               << aGateOutPort->PortName() << " " << aGateOutPort->Kind() ;
2705         long l = 0;
2706         OutParametersList[0].Value <<= l ;
2707         aGateOutPort->Value( OutParametersList[0].Value ) ;
2708       }
2709       else {
2710 //        cdebug << ThreadNo() << " " << "Out0 " << Name() << " Open of "
2711 //               << aGateOutPort->PortName() << " " << aGateOutPort->Kind() ;
2712         long l = 1;
2713         OutParametersList[0].Value <<= l ;
2714         aGateOutPort->Value( OutParametersList[0].Value ) ;
2715         int i ;
2716         for ( i = 0 ; i < GetNodeOutPortsSize() ; i++ ) {
2717           GraphBase::InPort * anInPort ;
2718           anInPort = CoupledNode()->GetChangeInPort( GetNodeOutPort( i )->PortName() ) ;
2719           if ( anInPort ) {
2720             anInPort->ChangeOutPort( GetChangeNodeOutPort( i ) ) ;
2721           }
2722         }
2723       }
2724     }
2725   }
2726   return RetVal ;
2727 }