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