]> SALOME platform Git repositories - modules/superv.git/blob - src/GraphExecutor/DataFlowExecutor_InNodeThreads.cxx
Salome HOME
NRI : First integration.
[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( 1 )->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           try {
1005             if ( IsInLineNode() && (*InLineNode()->PythonFunction()).length() &&
1006                  strlen( InLineNode()->PyFuncName() ) ) {
1007               cdebug << ThreadNo() << " !ObjInterface " << Name() << " PyFuncName '"
1008                      << InLineNode()->PyFuncName()
1009                      << "' IsInLineNode PyDynInvoke"  << endl ;
1010               StsPyDynInvoke = PyDynInvoke( InLineNode()->PyRunMethod() ,
1011                                InLineNode()->PyFuncName() ,
1012                                &aListOfInParameters[1] , ServiceInParameter().length() ,
1013                                &aListOfOutParameters[1] , ServiceOutParameter().length() ) ;
1014             }
1015             else if ( IsLoopNode() ) {
1016               if ( GetNodeInPort( 1 )->GetOutPort()->BoolValue() ) { // InLoop Port
1017                 cdebug << ThreadNo() << " !ObjInterface " << Name()
1018                        << " IsLoopNode PyDynInvoke '" << InLineNode()->PyFuncName()
1019                        << "'" << endl ;
1020                 StsPyDynInvoke = PyDynInvoke( InLineNode()->PyRunMethod() ,
1021                                InLineNode()->PyFuncName() ,
1022                                &aListOfInParameters[2] , ServiceInParameter().length() ,
1023                                &aListOfOutParameters[2] , ServiceOutParameter().length() ) ;
1024               }
1025               else {
1026                 cdebug << ThreadNo() << " !ObjInterface " << Name()
1027                        << " IsLoopNode PyDynInvoke '" << LoopNode()->PyNextName()
1028                        << "'" << endl ;
1029                 StsPyDynInvoke = PyDynInvoke( LoopNode()->PyNextMethod() ,
1030                              LoopNode()->PyNextName() ,
1031                              &aListOfInParameters[2] , ServiceInParameter().length() ,
1032                              &aListOfOutParameters[2] , ServiceOutParameter().length() ) ;
1033               }
1034               if ( StsPyDynInvoke ) {
1035                 cdebug << ThreadNo() << " !ObjInterface " << Name()
1036                        << " IsLoopNode PyDynInvoke '" << LoopNode()->PyMoreName()
1037                        << "' Copy of " << ServiceInParameter().length()
1038                        << " OutParameters" << endl ;
1039                 int i ;
1040                 for ( i = 0 ; i < ServiceInParameter().length() ; i++ ) {
1041                   aListOfInParameters[2 + i].Value = aListOfOutParameters[2+ i].Value ;
1042                   aListOfInParameters[2 + i].Name = aListOfOutParameters[2+ i].Name ;
1043                   switch ( aListOfInParameters[2 + i].Value.type()->kind() ) {
1044                   case CORBA::tk_string :
1045                     cdebug << "Arg" << i << " : "
1046                            << aListOfInParameters[2 + i].Name.c_str()
1047                            << " Value(string) " << endl ;
1048                     break ;
1049                   case CORBA::tk_double :
1050                     cdebug << "Arg" << i << " : "
1051                            << aListOfInParameters[2 + i].Name.c_str()
1052                            << " Value(double) " << endl ;
1053                     break ;
1054                   case CORBA::tk_long :
1055                     cdebug << "Arg" << i << " : "
1056                            << aListOfInParameters[2 + i].Name.c_str()
1057                            << " Value(long) " << endl ;
1058                     break ;
1059                   case CORBA::tk_objref :
1060                     cdebug << "Arg" << i << " : "
1061                            << aListOfInParameters[2 + i].Name.c_str()
1062                            << " Value(object reference) " << endl ;
1063                     break ;
1064                   default :
1065                     cdebug << "Arg" << i << " : "
1066                            << aListOfInParameters[2 + i].Name.c_str()
1067                            << " Value(other) ERROR" << endl ;
1068                   }
1069                 }
1070                 StsPyDynInvoke = PyDynInvoke( LoopNode()->PyMoreMethod() ,
1071                            LoopNode()->PyMoreName() ,
1072                            &aListOfInParameters[2] , ServiceInParameter().length() ,
1073                            &aListOfOutParameters[1] , ServiceOutParameter().length()+1 ) ;
1074               }
1075               else {
1076                 Err = true ;
1077                 cdebug << ThreadNo() << " InLineNode " << Name() << " "
1078                        << InLineNode()->PyFuncName() << "/" << LoopNode()->PyNextName()
1079                        << " Python Dynamic Call Error"
1080                        << endl ;
1081               }
1082             }
1083             else if ( IsSwitchNode() ) {
1084               cdebug << ThreadNo() << " !ObjInterface " << Name() << " PyFuncName '"
1085                      << InLineNode()->PyFuncName()
1086                      << "' IsSwitchNode PyDynInvoke"  << endl ;
1087               StsPyDynInvoke = PyDynInvoke( InLineNode()->PyRunMethod() ,
1088                                InLineNode()->PyFuncName() ,
1089                                &aListOfInParameters[1] , ServiceInParameter().length() ,
1090                                &aListOfOutParameters[1] , ServiceOutParameter().length() ) ;
1091             }
1092             else if ( IsGOTONode() && (*GOTONode()->PythonFunction()).length() &&
1093                       strlen( InLineNode()->PyFuncName() ) ) {
1094               cdebug << ThreadNo() << " !ObjInterface " << Name() << " PyFuncName '"
1095                      << InLineNode()->PyFuncName()
1096                      << "' IsGOTONode PyDynInvoke"  << endl ;
1097               StsPyDynInvoke = PyDynInvoke( InLineNode()->PyRunMethod() ,
1098                                InLineNode()->PyFuncName() ,
1099                                &aListOfInParameters[1] , ServiceInParameter().length() ,
1100                                &aListOfOutParameters[1] , ServiceOutParameter().length() ) ;
1101             }
1102             else if ( IsEndSwitchNode() && (*InLineNode()->PythonFunction()).length() &&
1103                       strlen( InLineNode()->PyFuncName() ) ) {
1104               cdebug << ThreadNo() << " !ObjInterface " << Name() << " PyFuncName '"
1105                      << InLineNode()->PyFuncName()
1106                      << "' IsSwitchNode PyDynInvoke"  << endl ;
1107               StsPyDynInvoke = PyDynInvoke( InLineNode()->PyRunMethod() ,
1108                                InLineNode()->PyFuncName() ,
1109                                &aListOfInParameters[1] , ServiceInParameter().length() ,
1110                                &aListOfOutParameters[1] , ServiceOutParameter().length() ) ;
1111             }
1112             else if ( (*InLineNode()->PythonFunction()).length() == 0 ||
1113                       strlen( InLineNode()->PyFuncName() ) == 0 ) {
1114               cdebug << ThreadNo() << " !ObjInterface " << Name()
1115                      << " Copy of " << ServiceInParameter().length()
1116                      << " OutParameters" << endl ;
1117               int i ;
1118               int argind0 = 1 ;
1119               if ( IsEndLoopNode() ) {
1120                 argind0 = 2 ;
1121               }
1122               for ( i = 0 ; i < ServiceInParameter().length() ; i++ ) {
1123                 aListOfOutParameters[argind0 + i].Value = aListOfInParameters[argind0 + i].Value ;
1124 //                aListOfOutParameters[argind0 + i].Name = aListOfInParameters[argind0 + i].Name ;
1125                 switch ( aListOfInParameters[argind0 + i].Value.type()->kind() ) {
1126                 case CORBA::tk_string :
1127                   cdebug << "Arg" << i << " : "
1128                          << aListOfInParameters[argind0 + i].Name.c_str()
1129                          << " Value(string) "
1130                          << aListOfOutParameters[argind0 + i].Name.c_str() << endl ;
1131                   break ;
1132                 case CORBA::tk_double :
1133                   cdebug << "Arg" << i << " : "
1134                          << aListOfInParameters[argind0 + i].Name.c_str()
1135                          << " Value(double) "
1136                          << aListOfOutParameters[argind0 + i].Name.c_str() << endl ;
1137                   break ;
1138                 case CORBA::tk_long :
1139                   cdebug << "Arg" << i << " : "
1140                          << aListOfInParameters[argind0 + i].Name.c_str()
1141                          << " Value(long) "
1142                          << aListOfOutParameters[argind0 + i].Name.c_str() << endl ;
1143                   break ;
1144                 case CORBA::tk_objref :
1145                   cdebug << "Arg" << i << " : "
1146                          << aListOfInParameters[argind0 + i].Name.c_str()
1147                          << " Value(object reference) "
1148                          << aListOfOutParameters[argind0 + i].Name.c_str() << endl ;
1149                   break ;
1150                 default :
1151                   cdebug << "Arg" << i << " : "
1152                          << aListOfInParameters[argind0 + i].Name.c_str()
1153                          << " Value(other) ERROR "
1154                          << aListOfOutParameters[argind0 + i].Name.c_str() << endl ;
1155                 }
1156               }
1157             }
1158             if ( !StsPyDynInvoke ) {
1159               Err = true ;
1160               cdebug << ThreadNo() << " InLineNode " << Name()
1161                      << " Python Dynamic Call Error"
1162                      << endl ;
1163             }
1164           }
1165           catch( ... ) {
1166             Err = true ;
1167             cdebug << ThreadNo() << " InLineNode " << Name()
1168                    << " Python Dynamic Call Exception catched ERROR"
1169                    << endl ;
1170           }
1171         }
1172 //        else if ( !ObjInterface() ) {
1173         else if ( IsFactoryNode() ) {
1174           try {
1175             try {
1176               DynInvoke( myObjComponent, "Names" ,
1177                          _OutNode->Name() , Name() ) ;
1178             }
1179             catch( ... ) {
1180               cdebug << "DynInvoke Names catched ERROR" << endl ;
1181             }
1182             cdebug << ServiceInParameter().length() << " input parameters and "
1183                    << ServiceOutParameter().length() << " output parameters" << endl ;
1184             if ( IsComputingNode() ) {
1185               cdebug << ThreadNo() << " !ObjInterface " << Name()
1186                      << " IsComputingNode DynInvoke"  << endl ;
1187               DynInvoke( myObjComponent,
1188                          ServiceName() ,
1189                          &aListOfInParameters[1] , ServiceInParameter().length() ,
1190                          &aListOfOutParameters[1] , ServiceOutParameter().length() ) ;
1191             }
1192             else if ( IsFactoryNode() ) {
1193               cdebug << ThreadNo() << " !ObjInterface " << Name()
1194                      << " IsFactoryNode DynInvoke"  << endl ;
1195               DynInvoke( myObjComponent,
1196                          ServiceName() ,
1197                          &aListOfInParameters[1] , ServiceInParameter().length() ,
1198                          &aListOfOutParameters[1] , ServiceOutParameter().length() ) ;
1199             }
1200           }
1201           catch( ... ) {
1202             Err = true ;
1203             cdebug << ThreadNo() << " !ObjInterface " << Name()
1204                    << " Node(Component) Dynamic Call Exception catched ERROR"
1205                    << endl ;
1206           }
1207         }
1208         else {
1209           try {
1210             try {
1211               DynInvoke( myObjComponent, "Names" ,
1212                          _OutNode->Name() , Name() ) ;
1213             }
1214             catch( ... ) {
1215             }
1216             cdebug << ThreadNo() << " ObjInterface " << Name() << " DynInvoke"
1217                    << endl ;
1218             DynInvoke( myObjComponent ,
1219                        ServiceName() ,
1220                        &aListOfInParameters[2] , ServiceInParameter().length()-1 ,
1221                        &aListOfOutParameters[1] , ServiceOutParameter().length() ) ;
1222           }
1223           catch( ... ) {
1224             Err = true ;
1225             cdebug << ThreadNo() << " ObjInterface " << Name()
1226                    << " Node(Interface) Dynamic Call Exception catched ERROR"
1227                    << endl ;
1228           }
1229         }
1230       }
1231     }
1232 //  }
1233 //  else {
1234 //    sleep( 1 ) ;
1235 //  }
1236
1237   if ( Err ) {
1238     if ( ControlState() == SUPERV::ToKillState ||
1239          ControlState() == SUPERV::ToKillDoneState ||
1240          ControlState() == SUPERV::ToStopState ) {
1241       PortState = SUPERV::ErrorState ;
1242       NewState = SUPERV::KilledState ;
1243       NewEvent = GraphExecutor::KillEvent ;
1244     }
1245     else {
1246       PortState = SUPERV::ErrorState ;
1247       NewState = SUPERV::ErroredState ;
1248       NewEvent = GraphExecutor::ErrorEvent ;
1249     }
1250   }
1251   else {
1252     PortState = SUPERV::ReadyState ;
1253     NewState = SUPERV::DataReadyState ;
1254     NewEvent = GraphExecutor::SuccessEvent ;
1255   }
1256
1257   bool ErrOut = OutParameters( Err , PortState , nOutParams , aListOfOutParameters ) ;
1258   if ( !ErrOut ) {
1259     NewEvent = GraphExecutor::ErrorEvent ;
1260   }
1261   delete [] aListOfInParameters ;
1262   delete [] aListOfOutParameters ;
1263
1264   SendEvent( NewEvent );
1265
1266   cdebug << ThreadNo() << " <-- DataReady_ExecuteAction " << Name() << endl;
1267   return 1 ;
1268 }
1269
1270 int GraphExecutor::InNode::Executing_SuspendAction() {
1271   _OutNode->PushEvent( this , GraphExecutor::SuspendedExecutingEvent ,
1272                        SUPERV::SuspendedExecutingState ) ; 
1273   cdebug << ThreadNo() << " Executing_SuspendAction " << Name() << endl;
1274   return 1 ;
1275 }
1276
1277 int GraphExecutor::InNode::SuspendedExecuting_ResumeAction() {
1278   cdebug << ThreadNo() << " SuspendedExecuting_ResumeAction " << Name() << endl;
1279   SUPERV::AutomatonState next_state ;
1280   next_state = Automaton()->NextState( State() , GraphExecutor::ExecutingEvent ) ;
1281   _OutNode->NewThread() ; // Only for Threads count
1282   _OutNode->PushEvent( this , GraphExecutor::ResumedExecutingEvent ,
1283                        next_state ) ; 
1284   State( next_state ) ;
1285   return 1 ;
1286 }
1287
1288 int GraphExecutor::InNode::Executing_KillAction() {
1289   cdebug << ThreadNo() << " Executing_KillAction " << Name() << endl;
1290   int RetVal = 0 ;
1291   if ( pthread_self() == ThreadNo() ) {
1292     cdebug << "Executing_KillAction would pthread_canceled itself" << endl ;
1293     KillAction() ;
1294     _OutNode->PushEvent( this , GraphExecutor::KilledExecutingEvent ,
1295                          SUPERV::KilledExecutingState ) ; 
1296     RetVal = 1 ;
1297   }
1298   else if ( pthread_cancel( ThreadNo() ) ) {
1299     perror("Executing_KillAction pthread_cancel error") ;
1300   }
1301   else {
1302     cdebug << "Executing_KillAction : ThreadId " << ThreadNo()
1303            << " pthread_canceled" << endl ;
1304     KillAction() ;
1305     _OutNode->ExitThread() ;
1306     _OutNode->PushEvent( this , GraphExecutor::KilledExecutingEvent ,
1307                          SUPERV::KilledExecutingState ) ; 
1308   }
1309   return RetVal ;
1310 }
1311
1312 int GraphExecutor::InNode::Executing_StopAction() {
1313   cdebug << ThreadNo() << " Executing_StopAction " << Name() << endl;
1314   int RetVal = 0 ;
1315   if ( pthread_cancel( ThreadNo() ) ) {
1316     perror("Executing_KillAction pthread_cancel error") ;
1317   }
1318   else {
1319     cdebug << "Executing_KillAction : ThreadId " << ThreadNo()
1320            << " pthread_canceled" << endl ;
1321     StopAction() ;
1322     _OutNode->ExitThread() ;
1323     _OutNode->PushEvent( this , GraphExecutor::StoppedExecutingEvent ,
1324                          SUPERV::StoppedExecutingState ) ; 
1325   }
1326   return RetVal ;
1327 }
1328
1329 int GraphExecutor::InNode::Executing_SuccessAction() {
1330   cdebug << ThreadNo() << " --> Executing_SuccessAction " << Name() << endl;
1331   _OutNode->PushEvent( this , GraphExecutor::SuccessedExecutingEvent ,
1332                        SUPERV::SuccessedState ) ; 
1333 //  DoneAction() ;
1334   SUPERV::ControlState aControl = ControlState() ;
1335   switch ( aControl ) {
1336   case SUPERV::VoidState : {
1337     SendEvent( SuccessEvent ) ;
1338     break ;
1339   }
1340   case SUPERV::ToSuspendState : {
1341     SendEvent( SuccessEvent ) ;
1342     break ;
1343   }
1344   case SUPERV::ToSuspendDoneState : {
1345     SendEvent( GraphExecutor::SuspendEvent ) ;
1346     return 1 ;
1347   }
1348   case SUPERV::ToKillState : {
1349     SendEvent( GraphExecutor::KillEvent ) ;
1350     return 1 ;
1351   }
1352   case SUPERV::ToKillDoneState : {
1353     SendEvent( GraphExecutor::KillEvent ) ;
1354     return 1 ;
1355   }
1356   case SUPERV::ToStopState : {
1357     SendEvent( GraphExecutor::StopEvent ) ;
1358     return 1 ;
1359   }
1360   default : {
1361     cdebug << ThreadNo()
1362            << " GraphExecutor::InNodeThreads::Executing_SuccessAction Error Undefined Control : "
1363            << aControl << endl ;
1364     return 0;
1365   }
1366   }
1367   cdebug << ThreadNo() << " <-- Executing_SuccessAction "  << Name() << endl;
1368   return 1 ;
1369 }
1370
1371 int GraphExecutor::InNode::Executing_ErrorAction() {
1372   cdebug << ThreadNo() << " --> Executing_ErrorAction " << Name() << endl;
1373   _OutNode->PushEvent( this , GraphExecutor::ErroredExecutingEvent ,
1374                        SUPERV::ErroredState ) ; 
1375 //  DoneAction() ;
1376
1377   SUPERV::ControlState aControl = ControlState() ;
1378   switch ( aControl ) {
1379   case SUPERV::VoidState : {
1380     SendEvent( ErrorEvent ) ;
1381     break ;
1382   }
1383   case SUPERV::ToSuspendState : {
1384     SendEvent( ErrorEvent ) ;
1385     break ;
1386   }
1387   case SUPERV::ToSuspendDoneState : {
1388     SendEvent( GraphExecutor::SuspendEvent ) ;
1389     return 1 ;
1390   }
1391   case SUPERV::ToKillState : {
1392     SendEvent( GraphExecutor::KillEvent ) ;
1393     return 1 ;
1394   }
1395   case SUPERV::ToKillDoneState : {
1396     SendEvent( GraphExecutor::KillEvent ) ;
1397     return 1 ;
1398   }
1399   case SUPERV::ToStopState : {
1400     SendEvent( GraphExecutor::StopEvent ) ;
1401     return 1 ;
1402   }
1403   default : {
1404     cdebug << ThreadNo()
1405            << " GraphExecutor::InNodeThreads::Executing_ErrorAction Error Undefined Control : "
1406            << aControl << endl ;
1407     return 0;
1408   }
1409   }
1410   cdebug << ThreadNo() << " <-- Executing_ErrorAction "  << Name() << endl;
1411   return 1 ;
1412 }
1413
1414 // Set SUPERV::WaitingState to all InPorts 
1415 void GraphExecutor::InNode::SetWaitingStates(GraphExecutor::InNode * EndNode ) {
1416   int i ;
1417   int j ;
1418   bool docdebug = false ;
1419   State( SUPERV::DataWaitingState ) ;
1420   for ( i = 0 ; i < GetNodeInPortsSize() ; i++ ) {
1421     GraphBase::InPort * anInPort = GetChangeNodeInPort( i ) ;
1422     if ( anInPort->IsGate() ) { // Loop : Open the doors
1423       GraphBase::OutPort * anOutPort = anInPort->GetOutPort() ;
1424       if ( anOutPort ) {
1425         CORBA::Any * anAny = new CORBA::Any() ;
1426         *anAny <<= (long ) 1 ;
1427         anOutPort->Value( anAny ) ;
1428         anInPort->State( SUPERV::ReadyState ) ;
1429       }
1430     }
1431     else if ( anInPort->State() != SUPERV::WaitingState ) {
1432       if ( !docdebug ) {
1433         cdebug << ThreadNo()
1434                << " --> GraphExecutor::InNodeThreads::SetWaitingStates "
1435                << Name() << endl;
1436         docdebug = true ;
1437       }
1438       anInPort->State( SUPERV::WaitingState ) ;
1439     }
1440   }
1441   for ( i = 0 ; i < GetNodeOutPortsSize() ; i++ ) {
1442     if ( !( IsGOTONode() && i == 0 ) && !( IsEndLoopNode() && i <= 1 ) ) {
1443       for ( j = 0 ; j < GetChangeNodeOutPort( i )->InPortsSize() ; j++ ) {
1444         GraphExecutor::InNode * aNode = (GraphExecutor::InNode * ) _OutNode->GetChangeGraphNode( GetChangeNodeOutPort( i )->ChangeInPorts( j )->NodeName() )->GetInNode() ;
1445         if ( aNode != EndNode ) {
1446           aNode->SetWaitingStates( EndNode ) ;
1447         }
1448       }
1449     }
1450   }
1451 }
1452
1453 int GraphExecutor::InNode::Successed_SuccessAction() {
1454   cdebug << ThreadNo() << " --> Successed_SuccessAction "  << Name() << endl;
1455   int res = 1;
1456   int linkednodesnumber = LinkedNodesSize() ;
1457   GraphExecutor::InNode *firstzeroNode = NULL ;
1458   GraphExecutor::InNode *firsttoNode = NULL ;
1459   GraphExecutor::InNode *toNode ;
1460   int i ;
1461   int j ;
1462   list<GraphExecutor::InNode *> SomeDataNodes ;
1463
1464   DoneAction() ;
1465
1466   if ( IsGOTONode() ||
1467        ( IsEndLoopNode() && GetNodeInPort(1)->GetOutPort()->BoolValue() ) ) {
1468     int index ;
1469     if ( IsGOTONode() ) {
1470       index = 0 ;
1471     }
1472     else {
1473       index = 1 ;
1474       CORBA::Any * anAny = new CORBA::Any() ;
1475       *anAny <<= (long ) 0 ;
1476       GetChangeNodeOutPort(1)->Value( anAny ) ; // Loop(InLoop) = false 
1477     }
1478     const GraphBase::OutPort * GateOutPort = GetNodeOutPort(index) ;
1479     for ( i = 0 ; i < GateOutPort->InPortsSize() ; i++ ) {
1480       const GraphBase::InPort * anInPort = GateOutPort->InPorts( i ) ;
1481       GraphExecutor::InNode * aLabelNode = (GraphExecutor::InNode *) _OutNode->GetChangeGraphNode( anInPort->NodeName() )->GetInNode() ;
1482       aLabelNode->SetWaitingStates( this ) ;
1483       for ( j = 1 ; j < GetNodeOutPortsSize() ; j++ ) {
1484         GraphBase::OutPort * aBusParamOutPort = GetChangeNodeOutPort( j ) ;
1485         GraphBase::InPort * aBusParamChangeInPort = NULL ;
1486         if ( aBusParamOutPort->IsLoop() ) {
1487           aBusParamChangeInPort = aLabelNode->GetChangeInPort( "InitLoop" ) ;
1488         }
1489         else {
1490           aBusParamChangeInPort = aLabelNode->GetChangeInPort( aBusParamOutPort->PortName() ) ;
1491         }
1492 //        const GraphBase::InPort * aBusParamInPort = aBusParamChangeInPort ;
1493 //        if ( aBusParamInPort ) {
1494 //          GraphBase::OutPort * anOutPort = aBusParamInPort->GetOutPort() ;
1495 //          anOutPort->Value( aBusParamOutPort->Value() ) ;
1496 //          GraphExecutor::InNode * aFromLabelNode = (GraphExecutor::InNode *) _OutNode->GetChangeGraphNode( anOutPort->NodeName() )->GetInNode() ;
1497 //          if ( aFromLabelNode && !aLabelNode->IsLockedDataWait() ) {
1498 //            res = aLabelNode->SendSomeDataReady( aFromLabelNode->Name() , EndTest ) ;
1499         if ( aBusParamChangeInPort ) {
1500           aBusParamChangeInPort->ChangeOutPort( aBusParamOutPort ) ;
1501           if ( !aLabelNode->IsLockedDataWait() ) {
1502             res = aLabelNode->SendSomeDataReady( Name() ) ;
1503             if ( res ) {
1504               if ( firsttoNode == NULL &&
1505                    aLabelNode->ThreadNo() == pthread_self() ) {
1506                 firsttoNode = aLabelNode ;
1507                 cdebug << ThreadNo() << " Successed_SuccessAction firsttoNode "
1508                        << aLabelNode->Name() << endl ;
1509               }
1510               else if ( firstzeroNode == NULL &&
1511                         aLabelNode->ThreadNo() == 0 ) {
1512                 firstzeroNode = aLabelNode ;
1513               }
1514               else {
1515                 SomeDataNodes.push_back( aLabelNode ) ;
1516                 cdebug << ThreadNo() << " Successed_SuccessAction push "
1517                        << SomeDataNodes.size() << " " << aLabelNode->Name()
1518                        << endl ;
1519               }
1520             }
1521           }
1522           else {
1523             cdebug << ThreadNo()
1524                    << " Successed_SuccessAction Loop to HeadNode "
1525                    << aLabelNode->Name() << " with datas from "
1526                    << aBusParamOutPort->PortName() << " to port "
1527                    << aBusParamChangeInPort->PortName() << endl;
1528 //            aBusParamChangeInPort->State( SUPERV::ReadyState ) ;
1529           }
1530         }
1531         else {
1532           cdebug << ThreadNo() << " ERROR in Successed_SuccessAction of " << Name()
1533                  << " NO port " << aBusParamOutPort->PortName() << " in "
1534                  << aLabelNode->Name() << endl;
1535         }
1536       }
1537       const GraphBase::OutPort * aGateOutPort = GetNodeOutPort( index ) ;
1538       const GraphBase::InPort * aGateInPort = aLabelNode->GetNodeInPort( index ) ;
1539       if ( aGateInPort ) {
1540         aGateInPort->GetOutPort()->Value( aGateOutPort->Value() ) ;
1541         if ( !aLabelNode->IsLockedDataWait() ) {
1542           res = aLabelNode->SendSomeDataReady( Name() ) ;
1543           if ( res ) {
1544             if ( firsttoNode == NULL &&
1545                  aLabelNode->ThreadNo() == pthread_self() ) {
1546               firsttoNode = aLabelNode ;
1547               cdebug << ThreadNo() << " Successed_SuccessAction firsttoNode "
1548                      << aLabelNode->Name() << endl ;
1549             }
1550             else if ( firstzeroNode == NULL &&
1551                       aLabelNode->ThreadNo() == 0 ) {
1552               firstzeroNode = aLabelNode ;
1553             }
1554             else {
1555               SomeDataNodes.push_back( aLabelNode ) ;
1556               cdebug << ThreadNo() << " Successed_SuccessAction push "
1557                      << SomeDataNodes.size() << " " << aLabelNode->Name()
1558                      << endl ;
1559             }
1560           }
1561         }
1562       }
1563       else {
1564         cdebug << ThreadNo() << " ERROR in Successed_SuccessAction of " << Name()
1565                << " NO port " << aGateOutPort->PortName() << " in "
1566                << aLabelNode->Name() << endl;
1567       }
1568     }
1569   }
1570
1571   else {
1572     cdebug << ThreadNo() << " Successed_SuccessAction of " << Name()
1573            << " with " << LinkedNodesSize() << " linked nodes :" ;
1574     for ( i = 0 ; i < LinkedNodesSize() ; i++ ) {
1575       if ( LinkedNodes( i )->IsDataFlowNode() ) {
1576         linkednodesnumber -= 1 ;
1577       }
1578       cdebug << " " << LinkedNodes( i )->Name() ;
1579     }
1580     cdebug << endl;
1581     SUPERV::ControlState aControl = ControlState() ;
1582     for ( i = 0 ; i < LinkedNodesSize() ; i++ ) {
1583       bool IgnoreForEndLoop = false ;
1584       toNode = (GraphExecutor::InNode *) LinkedNodes( i )->GetInNode() ;
1585       cdebug << ThreadNo() << " Successed_SuccessAction of " << Name()
1586              << " [" << i << "] " << LinkedNodes( i )->Name() << endl ;
1587       if ( toNode && !toNode->IsDataFlowNode() ) {
1588         GraphBase::InPort * toGateInPort = toNode->GetChangeNodeInPort(0) ;
1589         if ( IsComputingNode() && toNode->IsInLineNode() ) {
1590           toGateInPort->State( SUPERV::ReadyState ) ;
1591           GraphBase::OutPort * GateOutPort = toGateInPort->GetOutPort() ;
1592           if ( GateOutPort ) {
1593             GateOutPort->PortStatus( DataConnected );
1594             GateOutPort->State( SUPERV::ReadyState ) ;
1595             GateOutPort->Done( true ) ;
1596           }
1597         }
1598       }
1599       if ( toNode && IsLoopNode() ) {
1600         GraphBase::OutPort * fromLoopOutPort = GetChangeNodeOutPort(1) ;
1601         if ( !fromLoopOutPort->BoolValue() ) {
1602           if ( strcmp( toNode->Name() , CoupledNode()->Name() ) ) {
1603             IgnoreForEndLoop = true ; // toNode is the EndLoopNode
1604           }
1605           else {
1606             GraphBase::InPort * toLoopInPort ;
1607             toLoopInPort = toNode->GetChangeNodeInPort(1) ;
1608             if ( toLoopInPort->State() != SUPERV::ReadyState ) {
1609               toLoopInPort->State( SUPERV::ReadyState ) ;
1610             }
1611           }
1612         }
1613       }
1614       else if ( toNode && IsSwitchNode() ) {
1615       }
1616       else if ( toNode && toNode->IsInLineNode() ) {
1617         int j ;
1618         for ( j = 0 ; j < toNode->GetNodeInPortsSize() ; j++ ) {
1619           toNode->GetChangeNodeInPort( j )->InitialOutPort() ;
1620         }
1621       }
1622       if ( toNode && !IgnoreForEndLoop ) {
1623         if ( toNode && toNode->IsLoopNode() ) {
1624           GraphBase::InPort * toLoopInPort = toNode->GetChangeNodeInPort(1) ;
1625           toLoopInPort->State( SUPERV::ReadyState ) ;
1626           GraphBase::OutPort * LoopOutPort = toLoopInPort->GetOutPort() ;
1627           LoopOutPort->PortStatus( DataConnected );
1628           LoopOutPort->State( SUPERV::ReadyState ) ;
1629           LoopOutPort->Done( true ) ;
1630           CORBA::Any * anAny = new CORBA::Any() ;
1631           *anAny <<= (long ) 1 ;
1632           LoopOutPort->Value( anAny ) ;
1633           int j ;
1634           for ( j = 0 ; j < toNode->GetNodeInPortsSize() ; j++ ) {
1635             toNode->GetChangeNodeInPort( j )->InitialOutPort() ;
1636           }
1637         }
1638         res = toNode->SendSomeDataReady( Name() ) ;
1639         if ( res ) {
1640           if ( firsttoNode == NULL &&
1641                toNode->ThreadNo() == pthread_self() ) {
1642             firsttoNode = toNode ;
1643             cdebug << ThreadNo() << " Successed_SuccessAction firsttoNode "
1644                    << toNode->Name() << endl ;
1645           }
1646           else if ( firstzeroNode == NULL &&
1647                     toNode->ThreadNo() == 0 ) {
1648             firstzeroNode = toNode ;
1649           }
1650           else {
1651             SomeDataNodes.push_back( toNode ) ;
1652             cdebug << ThreadNo() << " Successed_SuccessAction push "
1653                    << SomeDataNodes.size() << " " << toNode->Name() << endl ;
1654           }
1655         }
1656       }
1657     }
1658   }
1659
1660   if ( firsttoNode == NULL && firstzeroNode ) {
1661     firsttoNode = firstzeroNode ;
1662     cdebug << ThreadNo()
1663            << " Successed_SuccessAction firsttoNode = firstzeroNode "
1664            << endl ;
1665   }
1666   else if ( firsttoNode && firstzeroNode ) {
1667     SomeDataNodes.push_back( firstzeroNode ) ;
1668     cdebug << ThreadNo() << " Successed_SuccessAction push firstzeroNode "
1669            << SomeDataNodes.size() << " " << firstzeroNode->Name() << endl ;
1670   }
1671
1672   while ( SomeDataNodes.size() ) {
1673     GraphExecutor::InNode *aNode = SomeDataNodes.front() ;
1674     SomeDataNodes.pop_front() ;
1675     cdebug << pthread_self() << "/" << ThreadNo()
1676            << " Successed_SuccessAction pop "
1677            << SomeDataNodes.size() << " " << aNode->Name() << endl ;
1678     if ( aNode->State() == SUPERV::DataReadyState ) {
1679       aNode->CreateNewThreadIf( true ) ;
1680       aNode->UnLockDataWait() ;
1681       res = aNode->DataUndef_AllDataReadyAction() ;
1682     }
1683     else {
1684       cdebug << pthread_self() << "/" << ThreadNo() << " ERROR "
1685              << aNode->Name() << " "
1686              << Automaton()->StateName( aNode->State() ) << endl ;
1687     }
1688   }
1689
1690   if ( firsttoNode ) {
1691 //    firsttoNode = SomeDataNodes.front() ;
1692 //    SomeDataNodes.pop_front() ;
1693     cdebug << pthread_self() << "/" << ThreadNo()
1694            << " Successed_SuccessAction pop firsttoNode "
1695            << SomeDataNodes.size() << " " << firsttoNode->Name() << endl ;
1696     firsttoNode->CreateNewThreadIf( false ) ;
1697     if ( firsttoNode->State() == SUPERV::SuccessedState ) {
1698       cdebug << pthread_self() << "/" << ThreadNo() << " " << Name()
1699              << " : " << firsttoNode->Name() << " "
1700              << Automaton()->StateName( firsttoNode->State() )
1701              << " --> DataWaitingState for Thread "
1702              << firsttoNode->ThreadNo() << endl ;
1703       firsttoNode->State( SUPERV::DataWaitingState ) ;
1704     }
1705     pthread_t OldT = firsttoNode->ThreadNo() ;
1706     firsttoNode->ThreadNo( pthread_self() ) ;
1707 // On continue avec le meme thread
1708     cdebug << pthread_self() << "/" << ThreadNo() << " firsttoNode "
1709            << firsttoNode->Name() << "Thread(" << OldT << "-->"
1710            << firsttoNode->ThreadNo() << ")" << endl ;
1711     ThreadNo( 0 ) ;
1712     cdebug << ThreadNo() << " Successed_SuccessAction " << Name()
1713            << " for " << firsttoNode->Name()
1714            << " !firsttoNode->CreateNewThreadIf() "
1715            << !firsttoNode->CreateNewThreadIf()
1716            << " " << Automaton()->StateName( firsttoNode->State() ) ;
1717     if ( firsttoNode->State() == SUPERV::DataReadyState ) {
1718       cdebug << endl ;
1719       firsttoNode->UnLockDataWait() ;
1720       res = firsttoNode->DataUndef_AllDataReadyAction() ;
1721     }
1722     else {
1723       cdebug << " ERROR " << endl ;
1724     }
1725   }
1726   else {
1727     cdebug << ThreadNo() << " Successed_SuccessAction " << Name()
1728            << " NO DataReady ==> ThreadNo( 0 )" << endl ;
1729     ThreadNo( 0 ) ;
1730   }
1731
1732   if ( linkednodesnumber == 0 ) {
1733     _OutNode->CheckAllDone() ;
1734   }
1735
1736   cdebug << pthread_self() << "/" << ThreadNo()
1737          << " <-- Successed_SuccessAction " << Name() << " linkednodesnumber "
1738          << linkednodesnumber << endl;
1739   return 1 ;
1740 }
1741
1742 bool GraphExecutor::InNode::SendSomeDataReady( char * FromNodeName ) {
1743   bool RetVal = false ;
1744   if ( IsDataFlowNode() ) {
1745     cdebug << ThreadNo() << " ----> " << Name()
1746          << " send Result to graph " << Name() << endl;
1747   }
1748   else {
1749     cdebug << pthread_self() << "/" << ThreadNo() << " ----> " << FromNodeName
1750            << " send SomeDataReady to " << Name() << " "
1751            << Automaton()->StateName( State() ) 
1752            << " CreateNewThreadIf() " << CreateNewThreadIf()
1753            << " LockedDataWait " << IsLockedDataWait() << endl;
1754 #if 0
1755     cout << pthread_self() << "/" << ThreadNo() << " ----> " << FromNodeName
1756          << " send SomeDataReady to " << Name() << " "
1757          << Automaton()->StateName( State() ) 
1758          << " CreateNewThreadIf() " << CreateNewThreadIf()
1759          << " LockedDataWait " << IsLockedDataWait() << endl;
1760 #endif
1761     if ( State() == SUPERV::SuccessedState ||
1762          State() == SUPERV::SuspendedSuccessedState ||
1763          State() == SUPERV::SuspendedSuccessedToReStartState ) {
1764       cdebug << ThreadNo() << " " << FromNodeName
1765              << " : " << Name() << " " << Automaton()->StateName( State() )
1766              << " --> DataWaitingState for Thread "
1767              << ThreadNo() << " " << endl ;
1768       State( SUPERV::DataWaitingState ) ;
1769     }
1770     LockDataWait() ;
1771     DataFromNode( FromNodeName ) ;
1772     RetVal = !SendEvent( GraphExecutor::SomeDataReadyEvent );
1773     if ( !RetVal ) {
1774       UnLockDataWait() ;
1775     }
1776   }
1777   return RetVal ;
1778 }
1779
1780 int GraphExecutor::InNode::Errored_ErrorAction() {
1781   cdebug << ThreadNo() << " Errored_ErrorAction " << Name()
1782          << " will pthread_exit" << endl;
1783   DoneAction() ;
1784   return 1 ;
1785 }
1786
1787 int GraphExecutor::InNode::Successed_SuspendAction() {
1788   cdebug << ThreadNo() << " Successed_SuspendAction -->Suspend " << Name()
1789          << " Threads " << _OutNode->Threads() << " SuspendedThreads "
1790          << _OutNode->SuspendedThreads() << endl;
1791   _OutNode->PushEvent( this , GraphExecutor::SuspendedSuccessedEvent ,
1792                        SUPERV::SuspendedSuccessedState ) ; 
1793   DoneAction() ;
1794   GraphExecutor::InNode * aReStartNode = SuspendAction() ;
1795   cdebug << ThreadNo() << " Successed_SuspendAction Resumed " << Name() ;
1796   if ( aReStartNode ) {
1797     _aReStartNode = NULL ;
1798     cdebug << " for " << aReStartNode->Name() << endl;
1799     aReStartNode->SendEvent( _aReStartEvent ) ;
1800   }
1801   else {
1802     cdebug << endl;
1803     SendEvent( GraphExecutor::ResumeEvent ) ;
1804   }
1805   return 1 ;
1806 }
1807
1808 int GraphExecutor::InNode::Errored_SuspendAction() {
1809   cdebug << ThreadNo() << " Errored_SuspendAction -->Suspend " << Name()
1810          << " Threads " << _OutNode->Threads() << " SuspendedThreads "
1811          << _OutNode->SuspendedThreads() << endl;
1812   _OutNode->PushEvent( this , GraphExecutor::SuspendedErroredEvent ,
1813                        SUPERV::SuspendedErroredState ) ; 
1814   DoneAction() ;
1815   GraphExecutor::InNode * aReStartNode = SuspendAction() ;
1816   cdebug << ThreadNo() << " Errored_SuspendAction Resumed " << Name()
1817          << endl;
1818   if ( aReStartNode ) {
1819     _aReStartNode = NULL ;
1820     aReStartNode->SendEvent( _aReStartEvent ) ;
1821   }
1822   else {
1823     SendEvent( GraphExecutor::ResumeEvent ) ;
1824   }
1825   return 1 ;
1826 }
1827
1828 int GraphExecutor::InNode::SuspendedSuccessed_ResumeAction() {
1829   cdebug << ThreadNo() << " SuspendedSuccessed_ResumeAction " << Name() << endl;
1830 //  ResumeAction() ;
1831   _OutNode->PushEvent( this , GraphExecutor::ResumedSuccessedEvent ,
1832                        SUPERV::ResumedSuccessedState ) ; 
1833   SendEvent( ResumedSuccessedEvent ) ;
1834   return 1 ;
1835 }
1836
1837 int GraphExecutor::InNode::SuspendedErrored_ResumeAction() {
1838   cdebug << ThreadNo() << " SuspendedErrored_ResumeAction " << Name() << endl;
1839 //  ResumeAction() ;
1840   _OutNode->PushEvent( this , GraphExecutor::ResumedErroredEvent ,
1841                        SUPERV::ResumedErroredState ) ; 
1842   SendEvent( ResumedErroredEvent ) ;
1843   return 1 ;
1844 }
1845
1846 int GraphExecutor::InNode::Successed_KillAction() {
1847   KillAction() ;
1848   _OutNode->PushEvent( this , GraphExecutor::KilledEvent ,
1849                        SUPERV::KilledSuccessedState ) ; 
1850   cdebug << ThreadNo() << " Successed_KillAction " << Name() << endl;
1851   return 1 ;
1852 }
1853
1854 int GraphExecutor::InNode::Errored_KillAction() {
1855   KillAction() ;
1856   _OutNode->PushEvent( this , GraphExecutor::KilledEvent ,
1857                        SUPERV::KilledErroredState ) ; 
1858   cdebug << ThreadNo() << " Errored_KillAction " << Name() << endl;
1859   return 1 ;
1860 }
1861
1862 int GraphExecutor::InNode::Successed_StopAction() {
1863   StopAction() ;
1864   _OutNode->PushEvent( this , GraphExecutor::StoppedEvent ,
1865                        SUPERV::StoppedSuccessedState ) ; 
1866   cdebug << ThreadNo() << " Successed_StopAction " << Name() << endl;
1867   return 1 ;
1868 }
1869
1870 int GraphExecutor::InNode::Errored_StopAction() {
1871   StopAction() ;
1872   _OutNode->PushEvent( this , GraphExecutor::StoppedEvent ,
1873                        SUPERV::StoppedErroredState ) ; 
1874   cdebug << ThreadNo() << " Errored_StopAction " << Name() << endl;
1875   return 1 ;
1876 }
1877
1878 int GraphExecutor::InNode::SuspendedSuccessed_ReStartAction() {
1879   cdebug << ThreadNo() << " SuspendedSuccessed_ReStartAction " << Name() << endl;
1880   _OutNode->PushEvent( this , GraphExecutor::ReStartedEvent ,
1881                        SUPERV::ReStartedState ) ;
1882   int i ;
1883   for ( i = 0 ; i < GetNodeInPortsSize() ; i++ ) {
1884     GetChangeNodeInPort( i )->State( SUPERV::ReadyState ) ;
1885   }
1886   SendEvent( ExecuteEvent ) ;
1887   cdebug << ThreadNo() << " SuspendedSuccessed_ReStartAction "  << Name() << endl;
1888   return 1 ;
1889 }
1890
1891 int GraphExecutor::InNode::SuspendedErrored_ReStartAction() {
1892   cdebug << ThreadNo() << " SuspendedErrored_ReStartAction " << Name() << endl;
1893   _OutNode->PushEvent( this , GraphExecutor::ReStartedEvent ,
1894                        SUPERV::ReStartedState ) ; 
1895   int i ;
1896   for ( i = 0 ; i < GetNodeInPortsSize() ; i++ ) {
1897     GetChangeNodeInPort( i )->State( SUPERV::ReadyState ) ;
1898   }
1899   SendEvent( ExecuteEvent ) ;
1900   cdebug << ThreadNo() << " SuspendedErrored_ReStartAction "  << Name() << endl;
1901   return 1 ;
1902 }
1903
1904 int GraphExecutor::InNode::SuspendedSuccessed_ReStartAndSuspendAction() {
1905   cdebug << ThreadNo() << " SuspendedSuccessed_ReStartAndSuspendAction " << Name()
1906          << endl;
1907   _OutNode->PushEvent( this , GraphExecutor::ReStartedAndSuspendEvent ,
1908                        SUPERV::ReStartedState ) ; 
1909   State( SUPERV::DataWaitingState ) ;
1910   if ( !Suspend() ) {
1911     cdebug << "InNode::Suspend() Node " << Name() << endl ;
1912     return false ;
1913   }
1914   else if ( SendEvent( GraphExecutor::SomeDataReadyEvent ) ) {
1915     cdebug << "InNode::SendEvent( SomeDataReadyEvent ) Node "
1916            << Name() << endl ;
1917     return false ;
1918   }
1919   cdebug << ThreadNo() << " SuspendedSuccessed_ReStartAndSuspendAction "  << Name()
1920          << endl;
1921   return 1 ;
1922 }
1923
1924 int GraphExecutor::InNode::SuspendedErrored_ReStartAndSuspendAction() {
1925   cdebug << ThreadNo() << " SuspendedErrored_ReStartAndSuspendAction " << Name()
1926          << endl;
1927   _OutNode->PushEvent( this , GraphExecutor::ReStartedAndSuspendEvent ,
1928                        SUPERV::ReStartedState ) ; 
1929   State( SUPERV::DataWaitingState ) ;
1930   if ( !Suspend() ) {
1931     cdebug << "InNode::Suspend() Node " << Name() << endl ;
1932     return false ;
1933   }
1934   else if ( SendEvent( GraphExecutor::SomeDataReadyEvent ) ) {
1935     cdebug << "InNode::SendEvent( SomeDataReadyEvent ) Node "
1936            << Name() << endl ;
1937     return false ;
1938   }
1939   cdebug << ThreadNo() << " SuspendedErrored_ReStartAndSuspendAction "  << Name()
1940          << endl;
1941   return 1 ;
1942 }
1943
1944 void GraphExecutor::InNode::InParametersSet(
1945                             bool & Err ,
1946                             int  nInParams ,
1947                             ServicesAnyData * aListOfInParameters ) {
1948   int i ;
1949   for ( i = 0 ; i < nInParams ; i++ ) {
1950     ServicesAnyData D = aListOfInParameters[i];
1951     GraphBase::InPort * anInPort = GetChangeNodeInPort(i) ;
1952     GraphBase::OutPort * theOutPort = anInPort->GetOutPort() ;
1953     if ( anInPort->IsGate() && theOutPort == NULL ) {
1954       cdebug << ThreadNo() << " ArgIn" << i << " " << D.Name << " "
1955              << anInPort->GetServicesParameter().Parametertype
1956              << " is inactive. " << anInPort->Kind() << endl ;
1957     }
1958 //    else if ( theOutPort->State() == SUPERV::ReadyState ) {
1959     else if ( anInPort->State() == SUPERV::ReadyState ) {
1960       if ( anInPort->IsGate() ) {
1961         CORBA::Any * anAny = new CORBA::Any() ;
1962         *anAny <<= (long ) 0 ;
1963         theOutPort->Value( anAny ) ;
1964       }
1965       anInPort->State( SUPERV::WaitingState ) ;
1966 //      const CORBA::Any * theValue = theOutPort->Value() ;
1967       D.Name = CORBA::string_dup( anInPort->GetServicesParameter().Parametername ) ;
1968 //      D.Value = *theValue ; // CORBA::Any
1969       D.Value = *theOutPort->Value() ; // CORBA::Any
1970       cdebug << ThreadNo() << " ArgIn" << i << " " << anInPort->Kind() ;
1971       cdebug << D.Name << " " << anInPort->GetServicesParameter().Parametertype
1972              << " : " ;
1973       string _Type = CORBA::string_dup( anInPort->GetServicesParameter().Parametertype ) ;
1974       const char * Type = _Type.c_str() ;
1975       switch (D.Value.type()->kind()) {
1976       case CORBA::tk_string:
1977         char * t;
1978         D.Value >>= t;
1979         cdebug << t << " (string)" << endl ;
1980         if ( !strcmp( Type , "string" ) ) {
1981         }
1982         else if ( !strcmp( Type , "double" ) ) {
1983           double d ;
1984           sscanf( t , "%lf" , &d ) ;
1985           D.Value <<= d ;
1986           theOutPort->Value( D.Value ) ;
1987         }
1988         else if ( !strcmp( Type , "long" ) || !strcmp( Type , "bool" ) ) {
1989           long l ;
1990           sscanf( t , "%ld" , &l ) ;
1991           D.Value <<=  l ;
1992           theOutPort->Value( D.Value ) ;
1993         }
1994         else if ( !strcmp( Type , "objref" ) ) {
1995           CORBA::Object_ptr ObjRef ;
1996           ObjRef = StringToObject( t ) ;
1997           D.Value <<= ObjRef ;
1998           theOutPort->Value( D.Value ) ;
1999         }
2000         else {
2001         }
2002         break;
2003       case CORBA::tk_double:
2004         double d;
2005         D.Value >>= d;
2006         cdebug << d << " (double)" << endl ;
2007         if ( !strcmp( Type , "string" ) ) {
2008           char t[40] ;
2009           sprintf( t , "lf" , d ) ;
2010           D.Value <<= t ;
2011           theOutPort->Value( D.Value ) ;
2012         }
2013         else if ( !strcmp( Type , "double" ) ) {
2014         }
2015         else if ( !strcmp( Type , "long" ) || !strcmp( Type , "bool" ) ) {
2016           long l ;
2017           l = (long ) d ;
2018           D.Value <<= l ;
2019           theOutPort->Value( D.Value ) ;
2020         }
2021         else if ( !strcmp( Type , "objref" ) ) {
2022         }
2023         else {
2024         }
2025         break;
2026       case CORBA::tk_long:
2027         long l;
2028         D.Value >>= l;
2029         cdebug << l << " (long)" << endl ;
2030         if ( !strcmp( Type , "string" ) ) {
2031           char t[40] ;
2032           sprintf( t , "lf" , l ) ;
2033           D.Value <<= t ;
2034           theOutPort->Value( D.Value ) ;
2035         }
2036         else if ( !strcmp( Type , "double" ) ) {
2037           double d ;
2038           d = l ;
2039           D.Value <<= d ;
2040           theOutPort->Value( D.Value ) ;
2041         }
2042         else if ( !strcmp( Type , "long" ) || !strcmp( Type , "bool" ) ) {
2043         }
2044         else if ( !strcmp( Type , "objref" ) ) {
2045         }
2046         else {
2047         }
2048         break;
2049       case CORBA::tk_objref:
2050         CORBA::Object_ptr obj ;
2051         char * retstr ;
2052         try {
2053           D.Value >>= obj ;
2054 //          retstr = _Orb->object_to_string(obj );
2055           retstr = ObjectToString( obj ) ;
2056           cdebug << retstr << endl ;
2057         }
2058         catch( ... ) {
2059           if ( i != 0 ) {
2060             Err = true ;
2061           }
2062           cdebug << "ToString( object ) Catched ERROR" << endl ;
2063         }
2064         break;
2065       default:
2066         cdebug << " (other ERROR)" << endl ;
2067       }
2068     }
2069     else {
2070       cdebug << ThreadNo() << " In" << i << " : wrong state ERROR State "
2071              << anInPort->State() << " NameState "
2072              << Automaton()->StateName( anInPort->State() ) << " PortName "
2073              << anInPort->PortName() << " Parametername "
2074              << anInPort->GetServicesParameter().Parametername << endl ;
2075       Err = true ;
2076     }
2077     aListOfInParameters[i] = D ;
2078   }
2079 }
2080
2081 void GraphExecutor::InNode::InOutParameters(
2082                             int nOutParams ,
2083                             ServicesAnyData * aListOfOutParameters ) {
2084   int i ;
2085   for ( i = 0 ; i < nOutParams ; i++ ) {
2086     ServicesAnyData D = aListOfOutParameters[i] ;
2087
2088     D.Name = GetChangeNodeOutPort(i)->GetServicesParameter().Parametername;
2089     string _Type = CORBA::string_dup(GetChangeNodeOutPort(i)->GetServicesParameter().Parametertype) ;
2090     const char * Type = _Type.c_str() ;
2091     bool OutDone = GetChangeNodeOutPort(i)->Done() ;
2092 //      cdebug << ThreadNo() << " ArgOut" << i << " " << D.Name << " Done("
2093 //             << OutDone << ") " << Type << " : " << endl ;
2094     if ( !strcmp( Type , "string" ) ) {
2095       D.Value <<= (char *) NULL ;
2096     }
2097     else if ( !strcmp( Type , "double" ) ) {
2098       D.Value <<= 0. ;
2099     }
2100     else if ( !strcmp( Type , "long" ) || !strcmp( Type , "bool" ) ) {
2101       D.Value <<= (long ) 0 ;
2102     }
2103     else {
2104       D.Value.replace(CORBA::_tc_Object, NULL);
2105     }
2106 //    GetChangeNodeOutPort(i)->Value( D.Value ) ;
2107 #if 0
2108     switch (D.Value.type()->kind()) {
2109     case CORBA::tk_string:
2110       char * t;
2111       D.Value >>= t;
2112       cdebug << ThreadNo() << " " << t << "(string)" << endl ;
2113       break;
2114     case CORBA::tk_double:
2115       double d;
2116       D.Value >>= d;
2117       cdebug << ThreadNo() << " " << d << "(double)" << endl ;
2118       break;
2119     case CORBA::tk_long:
2120       long l;
2121       D.Value >>= l;
2122       cdebug << ThreadNo() << " " << l << "(long)" << endl ;
2123       break;
2124     case CORBA::tk_objref:
2125       cdebug << ThreadNo() << " " << "(object)" << endl ;
2126       break;
2127     default:
2128       cdebug << ThreadNo() << " " << "(other ERROR)" << endl ;
2129     }
2130 #endif
2131     aListOfOutParameters[i] = D ;
2132   }
2133 }
2134
2135 bool GraphExecutor::InNode::OutParameters(
2136                             bool Err ,
2137                             SUPERV::GraphState NewState ,
2138                             int nOutParams ,
2139                             ServicesAnyData * aListOfOutParameters ) {
2140   bool RetVal = true ;
2141   int i ;
2142   GraphBase::OutPort * aGateOutPort = NULL ;
2143   bool OrSwitch = false ;
2144   GraphBase::OutPort * anOutPort = GetChangeNodeOutPort(0) ;
2145   for ( i = 0 ; i < nOutParams ; i++ ) {
2146     anOutPort = GetChangeNodeOutPort(i) ;
2147     if ( Err ) {
2148       anOutPort->State( NewState ) ;
2149       anOutPort->Done( true ) ;
2150     }
2151     else {
2152       cdebug << ThreadNo() << " " << "Out" << i << " " << Name() << " "
2153              << anOutPort->PortName() << " " << anOutPort->Kind() ;
2154       if ( anOutPort->IsGate() ) {
2155         aGateOutPort = anOutPort ;
2156         cdebug << " Gate " ;
2157         long l = 1;
2158         aListOfOutParameters[i].Value <<= l;
2159         anOutPort->Value( aListOfOutParameters[i].Value );
2160       }
2161       else if ( anOutPort->IsLoop() ) {
2162         cdebug << " Loop " ;
2163         anOutPort->Value( aListOfOutParameters[i].Value );
2164 // InLoop Port of EndLoopNode is ready :
2165         anOutPort->ChangeInPorts(0)->State( SUPERV::ReadyState ) ;
2166       }
2167       else if ( anOutPort->IsSwitch() ) {
2168         cdebug << " Switch " ;
2169         anOutPort->Value( aListOfOutParameters[i].Value );
2170         if ( anOutPort->InPortsSize() && anOutPort->ChangeInPorts( 0 )->IsGate() ) {
2171           if ( OrSwitch && anOutPort->BoolValue() ) {
2172             cdebug << "GraphExecutor::InNodeThreads::OutParameters more than one switch is true WARNING"
2173                    << endl ;
2174 //            RetVal = false ;
2175           }
2176           else {
2177             OrSwitch = OrSwitch | anOutPort->BoolValue() ;
2178           }
2179         }
2180         cdebug << "OrSwitch " << OrSwitch ;
2181       }
2182       else {
2183         cdebug << " Param " ;
2184         anOutPort->Value( aListOfOutParameters[i].Value );
2185       }
2186 //      else if ( anOutPort->IsBus() ) {
2187 //        cdebug << " Bus " ;
2188 //        anOutPort->Value( GetNodeInPort( anOutPort->PortIndex() )->GetOutPort()->Value() );
2189 //      }
2190       anOutPort->State( NewState ) ;
2191       anOutPort->Done( true ) ;
2192       int j ;
2193       for ( j = 0 ; j < anOutPort->InPortsSize() ; j++ ) {
2194         bool fromGOTO = false ;
2195         GraphBase::OutPort * aGOTOPort = _OutNode->GetChangeGraphNode( anOutPort->ChangeInPorts( j )->NodeName() )->GetChangeNodeInPort( 0 )->GetOutPort() ;
2196         if ( aGOTOPort ) {
2197           fromGOTO = aGOTOPort->IsGOTO() ;
2198         }
2199         if ( anOutPort->ChangeInPorts( j )->IsEndSwitch() || fromGOTO ) {
2200           cdebug << anOutPort->ChangeInPorts( j )->NodeName() << "("
2201                  << anOutPort->ChangeInPorts( j )->PortName() << ","
2202                  << anOutPort->ChangeInPorts( j )->Kind() << ") WILL BE changed from "
2203                  << anOutPort->ChangeInPorts( j )->GetOutPort()->NodeName()
2204                  << "("
2205                  << anOutPort->ChangeInPorts( j )->GetOutPort()->PortName()
2206                  << ") to " << anOutPort->NodeName() << "("
2207                  << anOutPort->PortName() << ")" << endl ;
2208           anOutPort->ChangeInPorts( j )->ChangeOutPort( anOutPort ) ;
2209         }
2210         else {
2211           cdebug << anOutPort->ChangeInPorts( j )->NodeName() << "("
2212                  << anOutPort->ChangeInPorts( j )->PortName() << ","
2213                  << anOutPort->ChangeInPorts( j )->Kind() << ") NOT changed from "
2214                  << anOutPort->ChangeInPorts( j )->GetOutPort()->NodeName()
2215                  << "("
2216                  << anOutPort->ChangeInPorts( j )->GetOutPort()->PortName()
2217                  << ") to " << anOutPort->NodeName() << "("
2218                  << anOutPort->PortName() << ")" << endl ;
2219         }
2220       }
2221 #if 0
2222       switch (anOutPort->Value()->type()->kind()) {
2223       case CORBA::tk_string:
2224         char * t;
2225         (*anOutPort->Value()) >>= t;
2226         cdebug << ThreadNo() << " Out" << i << " : " << t << "(string)" << endl ;
2227         break;
2228       case CORBA::tk_double:
2229         double d;
2230         (*anOutPort->Value()) >>= d;
2231         cdebug << ThreadNo() << " Out" << i << " : " << d << "(double)" << endl ;
2232         break;
2233       case CORBA::tk_long:
2234         long l;
2235         (*anOutPort->Value()) >>= l;
2236         cdebug << ThreadNo() << " Out" << i << " : " << l << "(long)" << endl ;
2237         break;
2238       case CORBA::tk_objref:
2239         CORBA::Object_ptr obj ;
2240         char * retstr ;
2241         try {
2242           (*anOutPort->Value()) >>= obj ;
2243           retstr = _Orb->object_to_string(obj );
2244           cdebug << ThreadNo() << " Out" << i << " : " << "ToString( object ) "
2245                  << retstr << endl ;
2246         }
2247         catch ( ... ) {
2248           cdebug << ThreadNo() << " Out" << i << " : " << "ToString( object ) "
2249                  << "Catched ERROR" << endl ;
2250         }
2251         break;
2252       default:
2253         cdebug << ThreadNo() << " Out" << i << " : " << "(other ERROR)" << endl ;
2254         RetVal = false ;
2255       }
2256 #endif
2257     }
2258   }
2259   if ( aGateOutPort && IsSwitchNode() ) {
2260     if ( OrSwitch ) {
2261       cdebug << ThreadNo() << " " << "Out0 " << Name() << " Close of "
2262              << aGateOutPort->PortName() << " " << aGateOutPort->Kind() ;
2263       long l = 0;
2264       aListOfOutParameters[0].Value <<= l ;
2265       aGateOutPort->Value( aListOfOutParameters[0].Value ) ;
2266     }
2267     else {
2268       cdebug << ThreadNo() << " " << "Out0 " << Name() << " Open of "
2269              << aGateOutPort->PortName() << " " << aGateOutPort->Kind() ;
2270       long l = 1;
2271       aListOfOutParameters[0].Value <<= l ;
2272       aGateOutPort->Value( aListOfOutParameters[0].Value ) ;
2273       int i ;
2274       for ( i = 0 ; i < GetNodeOutPortsSize() ; i++ ) {
2275         GraphBase::InPort * anInPort ;
2276         anInPort = CoupledNode()->GetChangeInPort( GetNodeOutPort( i )->PortName() ) ;
2277         if ( anInPort ) {
2278           anInPort->ChangeOutPort( GetChangeNodeOutPort( i ) ) ;
2279         }
2280       }
2281     }
2282   }
2283   return RetVal ;
2284 }