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