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