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