Salome HOME
A bug was fixed: _Loading field is set to "false" (as it normally should be except...
[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       IsLoading( false ) ;
1164       Err = true ;
1165     }
1166     else {
1167       if ( ControlState() == SUPERV::ToSuspendState ) {
1168         cdebug << ThreadNo() << "ToSuspendState before running." << endl ;
1169         MESSAGE(ThreadNo() << "ToSuspendState before running.") ;
1170       }
1171       if ( !Err ) {
1172 //        ostringstream astr ;
1173 //        astr << "Graph " << _OutNode->Graph()->Name() << " Run of Node " << Name() ;
1174 //        _OutNode->Graph()->ObjImpl()->sendMessage( NOTIF_STEP, astr.str().c_str() ) ;
1175         cdebug << ThreadNo() << " Run( '" << ServiceName() << "'" ;
1176         for ( i = 0 ; i < (int ) ServiceInParameter().length() ; i++ ) {
1177           cdebug << " , " << InParametersList[ i ].Name << "[kind"
1178                  << InParametersList[ i ].Value.type()->kind() << "]" ;
1179         }
1180         for ( i = 0 ; i < (int ) ServiceOutParameter().length() ; i++ ) {
1181           cdebug << " , " << OutParametersList[ i ].Name << "[kind"
1182                  << OutParametersList[ i ].Value.type()->kind() << "]" ;
1183         }
1184         if ( IsOneOfInLineNodes() ) {
1185           cdebug << " , PyFuncName '" << InLineNode()->PyFuncName() << "' PyRunMethod "
1186                  << InLineNode()->PyRunMethod() << " length " << (*InLineNode()->PythonFunction()).length() ;
1187         }
1188         cdebug << ")" << endl ;
1189
1190         if ( IsOneOfInLineNodes() ) {
1191           bool StsPyDynInvoke = true;
1192           _OutNode->PyThreadLock() ;
1193           SetPyCpuUsed() ;
1194           IsLoading( false ); // loading complete for InLine nodes. For Computing and Factory - there still
1195                               // is some work to be done..  IsLoading( false ) for them is called later just before
1196                               // calling DynInvoke()..  but for InLine PyDynInvoke() is called just right here below..  
1197           try {
1198 //            if ( IsInLineNode() && (*InLineNode()->PythonFunction()).length() &&
1199             bool CopyInOut = false ;
1200             if ( IsInLineNode() && /*InLineNode()->PyRunMethod() &&*/
1201                  strlen( InLineNode()->PyFuncName() ) ) {
1202 //              cdebug << ThreadNo() << " !ObjInterface " << Name() << " PyFuncName '"
1203 //                     << InLineNode()->PyFuncName()
1204 //                     << "' IsInLineNode PyDynInvoke"  << endl ;
1205               StsPyDynInvoke = PyDynInvoke( InLineNode()->PyRunMethod() ,
1206                                             InLineNode()->PyFuncName() ,
1207                                             &InParametersList[0] , ServiceInParameter().length() ,
1208                                             &OutParametersList[0] , ServiceOutParameter().length() ) ;
1209             }
1210             else if ( IsLoopNode() ) {
1211               bool CopyOutIn = false ;
1212               if ( GetNodeInLoop()->GetOutPort()->BoolValue() && /*InLineNode()->PyRunMethod() &&*/
1213                    strlen( InLineNode()->PyFuncName() ) ) { // InLoop Port
1214 //                cdebug << ThreadNo() << " !ObjInterface " << Name()
1215 //                       << " IsLoopNode PyDynInvoke '" << InLineNode()->PyFuncName()
1216 //                       << "'" << endl ;
1217                 StsPyDynInvoke = PyDynInvoke( InLineNode()->PyRunMethod() ,
1218                                               InLineNode()->PyFuncName() ,
1219                                               &InParametersList[1] , ServiceInParameter().length() ,
1220                                               &OutParametersList[1] , ServiceOutParameter().length() ) ;
1221                 CopyOutIn = true ;
1222               }
1223               else if ( LoopNode()->PyNextMethod() &&
1224                         strlen( LoopNode()->PyNextName() ) ){
1225 //                cdebug << ThreadNo() << " !ObjInterface " << Name()
1226 //                       << " IsLoopNode PyDynInvoke '" << LoopNode()->PyNextName()
1227 //                       << "'" << endl ;
1228                 StsPyDynInvoke = PyDynInvoke( LoopNode()->PyNextMethod() ,
1229                                               LoopNode()->PyNextName() ,
1230                                               &InParametersList[1] , ServiceInParameter().length() ,
1231                                               &OutParametersList[1] , ServiceOutParameter().length() ) ;
1232                 CopyOutIn = true ;
1233               }
1234               if ( StsPyDynInvoke && CopyOutIn ) {
1235 //                cdebug << ThreadNo() << " !ObjInterface " << Name()
1236 //                       << " IsLoopNode PyDynInvoke '" << LoopNode()->PyMoreName()
1237 //                       << "' Copy of " << ServiceInParameter().length()
1238 //                       << " OutParameters" << endl ;
1239                 int i ;
1240                 for ( i = 1 ; i <= (int ) ServiceInParameter().length() ; i++ ) {
1241                   InParametersList[i].Value = OutParametersList[i].Value ;
1242                   InParametersList[i].Name = OutParametersList[i].Name ;
1243 //#if 0
1244                   switch ( InParametersList[i].Value.type()->kind() ) {
1245                   case CORBA::tk_string :
1246                     char * t;
1247                     InParametersList[i].Value >>= t ;
1248                     cdebug << "ArgOut->In" << i << " : "
1249                            << InParametersList[i].Name.c_str()
1250                            << " Value(string) " << t << endl ;
1251                     break ;
1252                   case CORBA::tk_double :
1253                     double d;
1254                     InParametersList[i].Value >>= d;
1255                     cdebug << "ArgOut->In" << i << " : "
1256                            << InParametersList[i].Name.c_str()
1257                            << " Value(double) " << d << endl ;
1258                     break ;
1259                   case CORBA::tk_long :
1260                     long l;
1261                     InParametersList[i].Value >>= l;
1262                     cdebug << "ArgOut->In" << i << " : "
1263                            << InParametersList[i].Name.c_str()
1264                            << " Value(long) " << l << endl ;
1265                     break ;
1266                   case CORBA::tk_objref :
1267                     CORBA::Object_ptr obj ;
1268                     char * retstr ;
1269                     try {
1270                       InParametersList[i].Value >>= obj ;
1271                       retstr = ObjectToString( obj );
1272                       cdebug << "ArgOut->In" << i << " : "
1273                              << InParametersList[i].Name.c_str()
1274                              << " Value(object reference) " << retstr << endl ;
1275                      }
1276                     catch ( ... ) {
1277                       cdebug << "ArgOut->In" << i << " : "
1278                              << InParametersList[i].Name.c_str()
1279                              << " Value(object reference) Catched ERROR" << endl ;
1280                     }
1281                     break ;
1282                   default :
1283                     cdebug << "ArgOut->In" << i << " : "
1284                            << InParametersList[i].Name.c_str()
1285                            << " Value(other) ERROR" << endl ;
1286                   }
1287 //#endif
1288                 }
1289                 if ( LoopNode()->PyMoreMethod() && strlen( LoopNode()->PyMoreName() ) ) {
1290                   StsPyDynInvoke = PyDynInvoke( LoopNode()->PyMoreMethod() ,
1291                                                 LoopNode()->PyMoreName() ,
1292                                                 &InParametersList[1] , ServiceInParameter().length() ,
1293                                                 &OutParametersList[0] , ServiceOutParameter().length()+1 ) ;
1294                 }
1295                 else {
1296                   CopyInOut = true ;
1297                 }
1298               }
1299               else  if ( !StsPyDynInvoke ) {
1300                 Err = true ;
1301                 cdebug << ThreadNo() << " InLineNode " << Name() << " "
1302                        << InLineNode()->PyFuncName() << "/" << LoopNode()->PyNextName()
1303                        << " Python Dynamic Call Error"
1304                        << endl ;
1305               }
1306             }
1307             else if ( IsSwitchNode() && /*InLineNode()->PyRunMethod() &&*/
1308                       strlen( InLineNode()->PyFuncName() ) ) {
1309 //              cdebug << ThreadNo() << " !ObjInterface " << Name() << " PyFuncName '"
1310 //                     << InLineNode()->PyFuncName()
1311 //                     << "' IsSwitchNode PyDynInvoke"  << endl ;
1312               StsPyDynInvoke = PyDynInvoke( InLineNode()->PyRunMethod() ,
1313                                             InLineNode()->PyFuncName() ,
1314                                             &InParametersList[0] , ServiceInParameter().length() ,
1315                                             &OutParametersList[0] , ServiceOutParameter().length() ) ;
1316             }
1317 //            else if ( IsGOTONode() && (*GOTONode()->PythonFunction()).length() &&
1318             else if ( IsGOTONode() && /*InLineNode()->PyRunMethod() &&*/
1319                       strlen( InLineNode()->PyFuncName() ) ) {
1320 //              cdebug << ThreadNo() << " !ObjInterface " << Name() << " PyFuncName '"
1321 //                     << InLineNode()->PyFuncName()
1322 //                     << "' IsGOTONode PyDynInvoke"  << endl ;
1323               StsPyDynInvoke = PyDynInvoke( InLineNode()->PyRunMethod() ,
1324                                             InLineNode()->PyFuncName() ,
1325                                             &InParametersList[0] , ServiceInParameter().length() ,
1326                                             &OutParametersList[0] , ServiceOutParameter().length() ) ;
1327             }
1328 //            else if ( IsEndSwitchNode() && (*InLineNode()->PythonFunction()).length() &&
1329             else if ( ( IsEndSwitchNode() ) &&
1330                       InLineNode()->PyRunMethod() && strlen( InLineNode()->PyFuncName() ) ) {
1331 //              cdebug << ThreadNo() << " !ObjInterface " << Name() << " PyFuncName '"
1332 //                     << InLineNode()->PyFuncName()
1333 //                     << "' IsSwitchNode PyDynInvoke"  << endl ;
1334               StsPyDynInvoke = PyDynInvoke( InLineNode()->PyRunMethod() ,
1335                                             InLineNode()->PyFuncName() ,
1336                                             &InParametersList[0] , ServiceInParameter().length() ,
1337                                             &OutParametersList[0] , ServiceOutParameter().length() ) ;
1338             }
1339             else if ( ( IsEndLoopNode() ) &&
1340                       InLineNode()->PyRunMethod() && strlen( InLineNode()->PyFuncName() ) ) {
1341 //              cdebug << ThreadNo() << " !ObjInterface " << Name() << " PyFuncName '"
1342 //                     << InLineNode()->PyFuncName()
1343 //                     << "' IsSwitchNode PyDynInvoke"  << endl ;
1344               StsPyDynInvoke = PyDynInvoke( InLineNode()->PyRunMethod() ,
1345                                             InLineNode()->PyFuncName() ,
1346                                             &InParametersList[0] , ServiceInParameter().length() + 1 ,
1347                                             &OutParametersList[0] , ServiceOutParameter().length() + 1 ) ;
1348             }
1349 //            else if ( (*InLineNode()->PythonFunction()).length() == 0 ||
1350             if ( InLineNode()->PyRunMethod() == NULL ||
1351                  strlen( InLineNode()->PyFuncName() ) == 0 || CopyInOut ) {
1352 //              cdebug << ThreadNo() << " !ObjInterface " << Name()
1353 //                     << " Copy of " << ServiceInParameter().length()
1354 //                     << " OutParameters" << endl ;
1355               int i ;
1356               int argout0 = 0 ;
1357               int argin0 = 0 ;
1358               if ( IsLoopNode() || IsEndLoopNode() ) {
1359                 argout0 = 1 ;
1360                 argin0 = 1 ; // after DoLoop
1361                 if ( IsLoopNode() ) {
1362                   OutParametersList[0].Value = InParametersList[0].Value ; // DoLoop
1363                 }
1364               }
1365               for ( i = 0 ; i < (int ) ServiceInParameter().length() ; i++ ) {
1366                 OutParametersList[argout0 + i].Value = InParametersList[argin0 + i].Value ;
1367 //#if 0
1368                 switch ( InParametersList[argin0 + i].Value.type()->kind() ) {
1369                 case CORBA::tk_string :
1370                   cdebug << "ArgOut->In" << argin0 + i << " : "
1371                          << InParametersList[argin0 + i].Name.c_str()
1372                          << " Value(string) "
1373                          << OutParametersList[argout0 + i].Name.c_str() << endl ;
1374                   break ;
1375                 case CORBA::tk_double :
1376                   cdebug << "ArgOut->In" << argin0 + i << " : "
1377                          << InParametersList[argin0 + i].Name.c_str()
1378                          << " Value(double) "
1379                          << OutParametersList[argout0 + i].Name.c_str() << endl ;
1380                   break ;
1381                 case CORBA::tk_long :
1382                   cdebug << "ArgOut->In" << argin0 + i << " : "
1383                          << InParametersList[argin0 + i].Name.c_str()
1384                          << " Value(long) "
1385                          << OutParametersList[argout0 + i ].Name.c_str() << endl ;
1386                   break ;
1387                 case CORBA::tk_objref :
1388                   cdebug << "ArgOut->In" << argin0 + i << " : "
1389                          << InParametersList[argin0 + i].Name.c_str()
1390                          << " Value(object reference) "
1391                          << OutParametersList[argout0 + i].Name.c_str() << endl ;
1392                   break ;
1393                 default :
1394                   cdebug << "ArgOut->In" << argin0 + i << " : "
1395                          << InParametersList[argin0 + i].Name.c_str()
1396                          << " Value(other) ERROR "
1397                          << OutParametersList[argout0 + i].Name.c_str() << endl ;
1398                 }
1399 //#endif
1400               }
1401             }
1402             if ( !StsPyDynInvoke ) {
1403               Err = true ;
1404               cdebug << ThreadNo() << " InLineNode " << Name()
1405                      << " Python Dynamic Call Error"
1406                      << endl ;
1407             }
1408           }
1409           catch( ... ) {
1410             Err = true ;
1411             cdebug << ThreadNo() << " InLineNode " << Name()
1412                    << " Python Dynamic Call Exception catched ERROR"
1413                    << endl ;
1414           }
1415           CpuUsed( true ) ;
1416           _OutNode->PyThreadUnLock() ;
1417         }
1418         else {
1419           try {
1420             try {
1421               cdebug << "DynInvoke -> Names " << _OutNode->Graph()->Name() << " " << Name() << endl ;
1422               DynInvoke( myObjComponent, "Names" ,
1423                          _OutNode->Graph()->Name() , Name() ) ;
1424             }
1425             catch( ... ) {
1426               cdebug << "DynInvoke Names catched ERROR" << endl ;
1427             }
1428 // for DataStreamNodes : call of SetProperties ===> environment variables in the component/container
1429             if ( ComputingNode()->HasDataStream() ) {
1430               try {
1431                 cdebug << "DynInvoke -> SetProperties " << _OutNode->Graph()->Name() << " " << Name() << endl ;
1432                 Engines::FieldsDict_var dict = new Engines::FieldsDict;
1433                 dict->length( 4 );
1434                 dict[ 0 ].key = CORBA::string_dup( "CAL_MACHINE");
1435                 // myContainer->getHostName() ne renvoit pas le nom complet (avec domaine).
1436                 //              dict[ 0 ].value <<= myContainer->getHostName() ;
1437                 char FullyQualifiedDomainName[256]="";
1438                 gethostname(FullyQualifiedDomainName,255);
1439                 dict[ 0 ].value <<=  FullyQualifiedDomainName ;
1440                 dict[ 1 ].key = CORBA::string_dup( "CAL_REPERTOIRE");
1441                 dict[ 1 ].value <<= "/tmp" ;
1442                 dict[ 2 ].key = CORBA::string_dup( "CAL_COUPLAGE");
1443                 stringstream ofst1 ;
1444                 ofst1 << ComputingNode()->SubStreamGraph() ;
1445                 string cpl = string( "/tmp/" ) + string( _OutNode->Graph()->Name() ) + string( "_" ) + 
1446                              ofst1.str() + string( ".cpl" );
1447                 dict[ 2 ].value <<= cpl.c_str() ;
1448                 dict[ 3 ].key = CORBA::string_dup( "SALOME_INSTANCE_NAME");
1449                 string uname = Name();
1450                 UpperCase( uname);
1451                 dict[ 3 ].value <<= uname.c_str() ;
1452
1453                 myObjComponent->setProperties( dict ) ;
1454               }
1455               catch( ... ) {
1456                 cdebug << "DynInvoke setProperties catched ERROR" << endl ;
1457                 Err = true ;
1458               }
1459             }
1460             if ( !Err && IsComputingNode() ) {
1461               cdebug << ThreadNo() << " !ObjInterface " << Name()
1462                      << " IsComputingNode DynInvoke"  << endl ;
1463               cdebug << ServiceInParameter().length()-1 << " input parameters and "
1464                      << ServiceOutParameter().length() << " output parameters" << endl ;
1465               IsLoading( false ) ;
1466               DynInvoke( myObjComponent,
1467                          ServiceName() ,
1468                          &InParametersList[1] , ServiceInParameter().length()-1 ,
1469                          &OutParametersList[0] , ServiceOutParameter().length() ) ;
1470             }
1471             else if ( !Err &&IsFactoryNode() ) {
1472               cdebug << ThreadNo() << " !ObjInterface " << Name()
1473                      << " IsFactoryNode DynInvoke"  << endl ;
1474               cdebug << ServiceInParameter().length() << " input parameters and "
1475                      << ServiceOutParameter().length() << " output parameters" << endl ;
1476               IsLoading( false ) ;
1477               DynInvoke( myObjComponent,
1478                          ServiceName() ,
1479                          &InParametersList[0] , ServiceInParameter().length() ,
1480                          &OutParametersList[0] , ServiceOutParameter().length() ) ;
1481             }
1482 //            cdebug << ThreadNo() << " Component::CpuUsed " << Name() << " "
1483 //                   << myObjComponent->CpuUsed_impl() << endl ;
1484           }
1485           catch( ... ) {
1486             Err = true ;
1487             cdebug << ThreadNo() << " !ObjInterface " << Name()
1488                    << " Node(Component) Dynamic Call Exception catched ERROR"
1489                    << endl ;
1490 //Reset of _ThreadId in the Container ...
1491             myObjComponent->Kill_impl() ;
1492           }
1493         }
1494       }
1495     }
1496   }
1497 //  else {
1498 //    sleep( 1 ) ;
1499 //  }
1500
1501 //  ostringstream astr ;
1502 //  astr << "Graph " << _OutNode->Graph()->Name() << " Node " << Name() << " is done : "
1503 //       << Automaton()->StateName( State() ) ;
1504 //  _OutNode->Graph()->ObjImpl()->sendMessage( NOTIF_STEP, astr.str().c_str() ) ;
1505   if ( Err ) {
1506     if ( ControlState() == SUPERV::ToKillState ||
1507          ControlState() == SUPERV::ToKillDoneState ||
1508          ControlState() == SUPERV::ToStopState ) {
1509       PortState = SUPERV::ErrorState ;
1510       NewState = GraphExecutor::KilledState ;
1511       NewEvent = GraphExecutor::KillEvent ;
1512     }
1513     else {
1514       PortState = SUPERV::ErrorState ;
1515       NewState = GraphExecutor::ErroredState ;
1516       NewEvent = GraphExecutor::ErrorEvent ;
1517     }
1518   }
1519   else {
1520     PortState = SUPERV::ReadyState ;
1521     NewState = GraphExecutor::DataReadyState ;
1522     NewEvent = GraphExecutor::SuccessEvent ;
1523   }
1524
1525   if ( !IsMacroNode() ) {
1526     bool ErrOut = OutParametersSet( Err , PortState , nOutParams , OutParametersList ) ;
1527     if ( !ErrOut ) {
1528       NewEvent = GraphExecutor::ErrorEvent ;
1529     }
1530     delete [] InParametersList ;
1531     delete [] OutParametersList ;
1532   }
1533           
1534   if ( !IsMacroNode() ) {              
1535     SendEvent( NewEvent ) ;
1536   }
1537   else {
1538     GraphExecutor::DataFlow * aMacroGraph = GraphMacroNode()->CoupledNode()->GraphEditor()->Executor() ;
1539     cdebug << ThreadNo() << " DataReady_ExecuteAction " << aMacroGraph << " "
1540            << aMacroGraph->Graph()->Name() << " ->DoneWait()"
1541            << " State " << aMacroGraph->State() << endl;
1542     aMacroGraph->DoneWait() ;
1543     cdebug << ThreadNo() << " DataReady_ExecuteAction " << Name() << " State " << aMacroGraph->State() << endl;
1544     if ( aMacroGraph->State() == SUPERV::DoneState ) {
1545       PortState = SUPERV::ReadyState ;
1546       NewState = GraphExecutor::DataReadyState ;
1547       NewEvent = GraphExecutor::SuccessEvent ;
1548     }
1549     else {
1550       Err = true ;
1551       if ( ControlState() == SUPERV::ToKillState ||
1552            ControlState() == SUPERV::ToKillDoneState ||
1553            ControlState() == SUPERV::ToStopState ) {
1554         PortState = SUPERV::ErrorState ;
1555         NewState = GraphExecutor::KilledState ;
1556         NewEvent = GraphExecutor::KillEvent ;
1557       }
1558       else {
1559         PortState = SUPERV::ErrorState ;
1560         NewState = GraphExecutor::ErroredState ;
1561         NewEvent = GraphExecutor::ErrorEvent ;
1562       }
1563     }
1564     bool ErrOut = OutParametersSet( Err , PortState , nOutParams , OutParametersList ) ;
1565     if ( !ErrOut ) {
1566       NewEvent = GraphExecutor::ErrorEvent ;
1567     }
1568     delete [] InParametersList ;
1569     delete [] OutParametersList ;
1570     SendEvent( NewEvent ) ;
1571   }
1572
1573 //  cdebug << ThreadNo() << " <-- DataReady_ExecuteAction " << Name() << endl;
1574   return 1 ;
1575 }
1576
1577 int GraphExecutor::InNode::Executing_SuspendAction() {
1578   _OutNode->PushEvent( this , GraphExecutor::SuspendedExecutingEvent ,
1579                        GraphExecutor::SuspendedExecutingState ) ; 
1580   cdebug << ThreadNo() << " Executing_SuspendAction " << Name() << endl;
1581   return 1 ;
1582 }
1583
1584 int GraphExecutor::InNode::SuspendedExecuting_ResumeAction() {
1585   cdebug << ThreadNo() << " SuspendedExecuting_ResumeAction " << Name() << endl;
1586   GraphExecutor::AutomatonState next_state ;
1587   next_state = Automaton()->NextState( State() , GraphExecutor::ExecutingEvent ) ;
1588   _OutNode->NewThread() ; // Only for Threads count
1589   _OutNode->PushEvent( this , GraphExecutor::ResumedExecutingEvent ,
1590                        next_state ) ; 
1591   State( next_state ) ;
1592   return 1 ;
1593 }
1594
1595 int GraphExecutor::InNode::Executing_KillAction() {
1596   cdebug << ThreadNo() << " Executing_KillAction " << Name() << " Thread " << ThreadNo()<< endl;
1597   int RetVal = 0 ;
1598   if ( pthread_self() == ThreadNo() ) {
1599     cdebug << "Executing_KillAction would pthread_canceled itself" << endl ;
1600     KillAction() ;
1601     _OutNode->PushEvent( this , GraphExecutor::KilledExecutingEvent ,
1602                          GraphExecutor::KilledExecutingState ) ; 
1603     RetVal = 1 ;
1604   }
1605   else if ( pthread_cancel( ThreadNo() ) ) {
1606     perror("Executing_KillAction pthread_cancel error") ;
1607   }
1608   else {
1609     cdebug << pthread_self() << " Executing_KillAction : ThreadId " << ThreadNo()
1610            << " pthread_canceled" << endl ;
1611     KillAction() ;
1612     _OutNode->ExitThread( ThreadNo() ) ;
1613     _OutNode->PushEvent( this , GraphExecutor::KilledExecutingEvent ,
1614                          GraphExecutor::KilledExecutingState ) ; 
1615   }
1616   return RetVal ;
1617 }
1618
1619 int GraphExecutor::InNode::Executing_StopAction() {
1620   cdebug << ThreadNo() << " Executing_StopAction " << Name() << " Thread " << ThreadNo() << endl;
1621   int RetVal = 0 ;
1622   if ( pthread_cancel( ThreadNo() ) ) {
1623     perror("Executing_KillAction pthread_cancel error") ;
1624   }
1625   else {
1626     cdebug << pthread_self() << " Executing_KillAction : ThreadId " << ThreadNo()
1627            << " pthread_canceled" << endl ;
1628     StopAction() ;
1629     _OutNode->ExitThread( ThreadNo() ) ;
1630     _OutNode->PushEvent( this , GraphExecutor::StoppedExecutingEvent ,
1631                          GraphExecutor::StoppedExecutingState ) ; 
1632   }
1633   return RetVal ;
1634 }
1635
1636 int GraphExecutor::InNode::Executing_SuccessAction() {
1637 //  cdebug << ThreadNo() << " --> Executing_SuccessAction " << Name() << endl;
1638   _OutNode->PushEvent( this , GraphExecutor::SuccessedExecutingEvent ,
1639                        GraphExecutor::SuccessedState ) ; 
1640   MESSAGE(pthread_self() << "Executor::InNode::Executing_SuccessAction of " << Name()
1641           << " ControlState " << Automaton()->ControlStateName( ControlState() )
1642           << " AFTER execution ThreadNo " << ThreadNo() ) ;
1643   SUPERV::ControlState aControl = ControlState() ;
1644   switch ( aControl ) {
1645   case SUPERV::VoidState : {
1646     SendEvent( SuccessEvent ) ;
1647     break ;
1648   }
1649   case SUPERV::ToSuspendState : {
1650     SendEvent( SuccessEvent ) ;
1651     break ;
1652   }
1653   case SUPERV::ToSuspendDoneState : {
1654     SendEvent( GraphExecutor::SuspendEvent ) ;
1655     return 1 ;
1656   }
1657   case SUPERV::ToKillState : {
1658     SendEvent( GraphExecutor::KillEvent ) ;
1659     return 1 ;
1660   }
1661   case SUPERV::ToKillDoneState : {
1662     SendEvent( GraphExecutor::KillEvent ) ;
1663     return 1 ;
1664   }
1665   case SUPERV::ToStopState : {
1666     SendEvent( GraphExecutor::StopEvent ) ;
1667     return 1 ;
1668   }
1669   default : {
1670     cdebug << ThreadNo()
1671            << " GraphExecutor::InNodeThreads::Executing_SuccessAction Error Undefined Control : "
1672            << aControl << endl ;
1673     return 0;
1674   }
1675   }
1676 //  cdebug << ThreadNo() << " <-- Executing_SuccessAction "  << Name() << endl;
1677   return 1 ;
1678 }
1679
1680 int GraphExecutor::InNode::Executing_ErrorAction() {
1681   cdebug << ThreadNo() << " --> Executing_ErrorAction " << Name() << endl;
1682   _OutNode->PushEvent( this , GraphExecutor::ErroredExecutingEvent ,
1683                        GraphExecutor::ErroredState ) ; 
1684
1685   SUPERV::ControlState aControl = ControlState() ;
1686   switch ( aControl ) {
1687   case SUPERV::VoidState : {
1688     SendEvent( ErrorEvent ) ;
1689     break ;
1690   }
1691   case SUPERV::ToSuspendState : {
1692     SendEvent( ErrorEvent ) ;
1693     break ;
1694   }
1695   case SUPERV::ToSuspendDoneState : {
1696     SendEvent( GraphExecutor::SuspendEvent ) ;
1697     return 1 ;
1698   }
1699   case SUPERV::ToKillState : {
1700     SendEvent( GraphExecutor::KillEvent ) ;
1701     return 1 ;
1702   }
1703   case SUPERV::ToKillDoneState : {
1704     SendEvent( GraphExecutor::KillEvent ) ;
1705     return 1 ;
1706   }
1707   case SUPERV::ToStopState : {
1708     SendEvent( GraphExecutor::StopEvent ) ;
1709     return 1 ;
1710   }
1711   default : {
1712     cdebug << ThreadNo()
1713            << " GraphExecutor::InNodeThreads::Executing_ErrorAction Error Undefined Control : "
1714            << aControl << endl ;
1715     return 0;
1716   }
1717   }
1718   cdebug << ThreadNo() << " <-- Executing_ErrorAction "  << Name() << endl;
1719   return 1 ;
1720 }
1721
1722 // Set SUPERV::WaitingState to all InPorts 
1723 void GraphExecutor::InNode::SetWaitingStates(GraphExecutor::InNode * EndNode ) {
1724   int i ;
1725   int j ;
1726   bool docdebug = false ;
1727   State( GraphExecutor::DataWaitingState ) ;
1728   for ( i = 0 ; i < GetNodeInPortsSize() ; i++ ) {
1729     GraphBase::InPort * anInPort = GetChangeNodeInPort( i ) ;
1730     if ( anInPort->IsGate() ) { // Loop : Open the doors
1731       GraphBase::OutPort * anOutPort = anInPort->GetOutPort() ;
1732       if ( anOutPort ) {
1733         CORBA::Any * anAny = new CORBA::Any() ;
1734         *anAny <<= (long ) 1 ;
1735         anOutPort->Value( anAny ) ;
1736         anInPort->State( SUPERV::ReadyState ) ;
1737       }
1738     }
1739     else if ( anInPort->State() != SUPERV::WaitingState ) {
1740       if ( !docdebug ) {
1741         cdebug << ThreadNo()
1742                << " --> GraphExecutor::InNodeThreads::SetWaitingStates " << Name() << endl;
1743         docdebug = true ;
1744       }
1745       if ( !anInPort->IsDataStream() ) {
1746         anInPort->State( SUPERV::WaitingState ) ;
1747       }
1748     }
1749   }
1750   for ( i = 0 ; i < GetNodeOutPortsSize() ; i++ ) {
1751     GraphBase::OutPort * anOutPort = GetChangeNodeOutPort( i ) ;
1752     for ( j = 0 ; j < anOutPort->InPortsSize() ; j++ ) {
1753       if ( !( IsGOTONode() && anOutPort->IsGate() ) &&
1754            !( IsEndLoopNode() && ( anOutPort->IsGate() ||
1755               anOutPort->IsLoop() ) ) &&
1756            !anOutPort->IsDataStream() &&
1757            !anOutPort->ChangeInPorts( j )->IsDataStream() &&
1758            !anOutPort->ChangeInPorts( j )->IsExternConnected() ) {
1759         cdebug << ThreadNo()
1760                << " InNodeThreads::SetWaitingStates OutPort "
1761                << Name() << "/" << anOutPort->ChangeInPorts( j )->NodeName() << "( "
1762                << anOutPort->PortName() << " " << anOutPort->PortStatus() << " ) --> InPort "
1763                << anOutPort->ChangeInPorts( j )->NodeName() << "( "
1764                << anOutPort->ChangeInPorts( j )->PortName() << " "
1765                << anOutPort->ChangeInPorts( j )->PortStatus() << " )" << endl;
1766         if ( strcmp( anOutPort->ChangeInPorts( j )->GetOutPort()->NodeName() , Name() ) ) {
1767 // After EndLoopNode or GOTONode the Input Ports of LoopNode or LabelNode have their values from
1768 // EndLoopNode or GOTONode. But if there is several nested loops we should re-establish.
1769           cdebug << ThreadNo()
1770                  << " InNodeThreads::SetWaitingStates OutPort->ChangeInPorts( j )->OutPort()->NodeName "
1771                  << anOutPort->ChangeInPorts( j )->GetOutPort()->NodeName() << " != "
1772                  << Name() << " : Restored to " << anOutPort->NodeName() << "( "
1773                  << anOutPort->PortName() << " )" << endl ;
1774           anOutPort->ChangeInPorts( j )->ChangeOutPort( anOutPort ) ;
1775         }
1776         GraphExecutor::InNode * aNode = (GraphExecutor::InNode * ) _OutNode->Graph()->GetChangeGraphNode( anOutPort->ChangeInPorts( j )->NodeName() )->GetInNode() ;
1777         if ( aNode != EndNode ) {
1778           aNode->SetWaitingStates( EndNode ) ;
1779         }
1780       }
1781     }
1782   }
1783 }
1784
1785 int GraphExecutor::InNode::Successed_SuccessAction() {
1786   cdebug << ThreadNo() << " --> Successed_SuccessAction "  << Name() << endl;
1787   int res = 1;
1788   int linkednodesnumber = LinkedNodesSize() ;
1789   GraphExecutor::InNode *firstzeroNode = NULL ;
1790   GraphExecutor::InNode *firsttoNode = NULL ;
1791   GraphExecutor::InNode *toNode ;
1792   int i ;
1793   int j ;
1794   list<GraphExecutor::InNode *> SomeDataNodes ;
1795
1796   DoneAction() ;
1797
1798   if ( IsMacroNode() ) {
1799       cdebug << ThreadNo() << " Successed_SuccessAction " << Name() << " LinkedNodes->SomeDataReady already done"
1800              << endl ;
1801     return 1;
1802   }
1803
1804   if ( IsGOTONode() ||
1805        ( IsEndLoopNode() && GetNodeInLoop()->GetOutPort()->BoolValue() ) ) {
1806     cdebug << ThreadNo() << " Successed_SuccessAction " << Name()
1807            << " SetWaitingStates " << endl ;
1808     const GraphBase::OutPort * aGateOutPort ;
1809     if ( IsGOTONode() ) {
1810       aGateOutPort = GetNodeOutGate() ;
1811     }
1812     else {
1813       aGateOutPort = GetNodeOutLoop() ;
1814     }
1815     for ( i = 0 ; i < aGateOutPort->InPortsSize() ; i++ ) {
1816       const GraphBase::InPort * anInPort = aGateOutPort->InPorts( i ) ;
1817       GraphExecutor::InNode * aLabelNode = (GraphExecutor::InNode *) _OutNode->Graph()->GetChangeGraphNode( anInPort->NodeName() )->GetInNode() ;
1818       cdebug << ThreadNo() << " Successed_SuccessAction " << Name() << " will Loop to HeadNode "
1819              << aLabelNode->Name() << " from port " << anInPort->PortName() << endl ;
1820       aLabelNode->SetWaitingStates( this ) ;
1821       for ( j = 0 ; j < aLabelNode->GetNodeInPortsSize() ; j++ ) {
1822         const GraphBase::InPort * anInPort = aLabelNode->GetNodeInPort( j ) ;
1823         if ( anInPort->GetOutPort() ) {
1824           cdebug << aLabelNode->Name() << "(" << anInPort->PortName() << ") value : "
1825                  << anInPort->GetOutPort()->NodeName() << "(" << anInPort->GetOutPort()->PortName() << ")"
1826                  << endl ;
1827         }
1828       }
1829       for ( j = 0 ; j < GetNodeOutPortsSize() ; j++ ) {
1830         GraphBase::OutPort * aBusParamOutPort = GetChangeNodeOutPort( j ) ;
1831         if ( !aBusParamOutPort->IsGate() ) {
1832           GraphBase::InPort * aBusParamChangeInPort = NULL ;
1833           if ( aBusParamOutPort->IsLoop() ) {
1834             aBusParamChangeInPort = aLabelNode->GetChangeNodeInLoop() ;
1835           }
1836           else {
1837             aBusParamChangeInPort = aLabelNode->GetChangeInPort( aBusParamOutPort->PortName() ) ;
1838           }
1839           if ( aBusParamChangeInPort ) {
1840             aBusParamChangeInPort->ChangeOutPort( aBusParamOutPort ) ;
1841             cdebug << ThreadNo() << " Successed_SuccessAction " << Name() << " ChangeOutPort to HeadNode "
1842                    << aLabelNode->Name() << "(" << aBusParamChangeInPort->PortName() << ") from port "
1843                    << aBusParamOutPort->PortName() << endl ;
1844             if ( !aLabelNode->IsLockedDataWait() ) {
1845               res = aLabelNode->SendSomeDataReady( Name() ) ;
1846               if ( res ) {
1847                 if ( firsttoNode == NULL &&
1848                      aLabelNode->ThreadNo() == pthread_self() ) {
1849                   firsttoNode = aLabelNode ;
1850                   cdebug << ThreadNo() << " Successed_SuccessAction firsttoNode "
1851                          << aLabelNode->Name() << endl ;
1852                 }
1853                 else if ( firstzeroNode == NULL &&
1854                           aLabelNode->ThreadNo() == 0 ) {
1855                   firstzeroNode = aLabelNode ;
1856                 }
1857                 else {
1858                   SomeDataNodes.push_back( aLabelNode ) ;
1859                   cdebug << ThreadNo() << " Successed_SuccessAction " << Name() << " push "
1860                          << aLabelNode->Name() << " " << SomeDataNodes.size() 
1861                          << endl ;
1862                 }
1863               }
1864             }
1865             else {
1866               cdebug << ThreadNo()
1867                      << " Successed_SuccessAction Loop to HeadNode "
1868                      << aLabelNode->Name() << " with datas from " << Name() << "("
1869                      << aBusParamOutPort->PortName() << ") to port "
1870                      << aBusParamChangeInPort->PortName() << endl;
1871             }
1872           }
1873           else {
1874             cdebug << ThreadNo() << " ERROR in Successed_SuccessAction of " << Name()
1875                    << " NO port " << aBusParamOutPort->PortName() << " in "
1876                    << aLabelNode->Name() << endl;
1877           }
1878         }
1879       }
1880       for ( j = 0 ; j < aLabelNode->GetNodeInPortsSize() ; j++ ) {
1881         const GraphBase::InPort * anInPort = aLabelNode->GetNodeInPort( j ) ;
1882         if ( anInPort->GetOutPort() ) {
1883           cdebug << aLabelNode->Name() << "(" << anInPort->PortName() << ") value : "
1884                  << anInPort->GetOutPort()->NodeName() << "(" << anInPort->GetOutPort()->PortName() << ")"
1885                  << endl ;
1886         }
1887       }
1888       const GraphBase::InPort * aGateInPort = aLabelNode->GetNodeInGate() ;
1889       if ( aGateInPort ) {
1890         if ( aGateInPort->GetOutPort() ) {
1891           aGateInPort->GetOutPort()->Value( aGateOutPort->Value() ) ;
1892         }
1893         if ( !aLabelNode->IsLockedDataWait() ) {
1894           res = aLabelNode->SendSomeDataReady( Name() ) ;
1895           if ( res ) {
1896             if ( firsttoNode == NULL &&
1897                  aLabelNode->ThreadNo() == pthread_self() ) {
1898               firsttoNode = aLabelNode ;
1899               cdebug << ThreadNo() << " Successed_SuccessAction firsttoNode "
1900                      << aLabelNode->Name() << endl ;
1901             }
1902             else if ( firstzeroNode == NULL &&
1903                       aLabelNode->ThreadNo() == 0 ) {
1904               firstzeroNode = aLabelNode ;
1905             }
1906             else {
1907               SomeDataNodes.push_back( aLabelNode ) ;
1908               cdebug << ThreadNo() << " Successed_SuccessAction " << Name() << " push "
1909                      << aLabelNode->Name() << " " << SomeDataNodes.size()
1910                      << endl ;
1911             }
1912           }
1913         }
1914       }
1915       else {
1916         cdebug << ThreadNo() << " ERROR in Successed_SuccessAction of " << Name()
1917                << " NO port " << aGateOutPort->PortName() << " in "
1918                << aLabelNode->Name() << endl;
1919       }
1920     }
1921   }
1922
1923   else {
1924     cdebug << ThreadNo() << " Successed_SuccessAction of " << Name()
1925            << " with " << LinkedNodesSize() << " linked nodes :" ;
1926     for ( i = 0 ; i < LinkedNodesSize() ; i++ ) {
1927       if ( LinkedNodes( i )->IsDataFlowNode() ) {
1928         linkednodesnumber -= 1 ;
1929       }
1930       cdebug << " " << LinkedNodes( i )->Name() ;
1931     }
1932     cdebug << endl;
1933     for ( i = 0 ; i < LinkedNodesSize() ; i++ ) {
1934       bool IgnoreForEndLoop = false ;
1935       GraphBase::ComputingNode * aComputingNode ;
1936       aComputingNode = (GraphBase::ComputingNode * ) LinkedNodes( i ) ;
1937       toNode = (GraphExecutor::InNode *) aComputingNode->GetInNode() ;
1938       cdebug << ThreadNo() << " Successed_SuccessAction of " << Name()
1939              << " [" << i << "] " << LinkedNodes( i )->Name() << " toNode " << toNode << " IgnoreForEndLoop "
1940              << IgnoreForEndLoop ;
1941       if ( toNode ) {
1942         cdebug << " " << toNode->Kind() << endl ;
1943       }
1944       if ( toNode && !toNode->IsDataFlowNode() ) {
1945         if ( IsComputingNode() && toNode->IsInLineNode() ) {
1946           GraphBase::InPort * toGateInPort = toNode->GetChangeNodeInGate() ;
1947           toGateInPort->State( SUPERV::ReadyState ) ;
1948           GraphBase::OutPort * GateOutPort = toGateInPort->GetOutPort() ;
1949           if ( GateOutPort ) {
1950             GateOutPort->PortStatus( DataConnected );
1951             GateOutPort->State( SUPERV::ReadyState ) ;
1952             GateOutPort->Done( true ) ;
1953           }
1954         }
1955       }
1956       if ( toNode && IsLoopNode() ) {
1957         GraphBase::OutPort * fromLoopOutPort = GetChangeNodeOutLoop() ;
1958         if ( !fromLoopOutPort->BoolValue() ) { // Ne pas faire la boucle
1959           if ( strcmp( toNode->Name() , CoupledNode()->Name() ) ) {
1960             IgnoreForEndLoop = true ;
1961           }
1962           else { // toNode is the EndLoopNode
1963             GraphBase::InPort * toLoopInPort ;
1964             toLoopInPort = toNode->GetChangeNodeInLoop() ;
1965             if ( toLoopInPort->State() != SUPERV::ReadyState ) {
1966               toLoopInPort->State( SUPERV::ReadyState ) ;
1967             }
1968           }
1969         }
1970       }
1971       else if ( toNode && IsSwitchNode() ) {
1972       }
1973       else if ( toNode && toNode->IsInLineNode() ) {
1974         int j ;
1975         for ( j = 0 ; j < toNode->GetNodeInPortsSize() ; j++ ) {
1976           toNode->GetChangeNodeInPort( j )->InitialOutPort() ;
1977         }
1978       }
1979       if ( toNode && !IgnoreForEndLoop ) {
1980         if ( toNode && toNode->IsLoopNode() ) {
1981           GraphBase::InPort * toLoopInPort = toNode->GetChangeNodeInLoop() ;
1982           toLoopInPort->State( SUPERV::ReadyState ) ;
1983           GraphBase::OutPort * LoopOutPort = toLoopInPort->GetOutPort() ;
1984           LoopOutPort->PortStatus( DataConnected );
1985           LoopOutPort->State( SUPERV::ReadyState ) ;
1986           LoopOutPort->Done( true ) ;
1987           CORBA::Any * anAny = new CORBA::Any() ;
1988           *anAny <<= (long ) 1 ;
1989           LoopOutPort->Value( anAny ) ;
1990           int j ;
1991           for ( j = 0 ; j < toNode->GetNodeInPortsSize() ; j++ ) {
1992             toNode->GetChangeNodeInPort( j )->InitialOutPort() ;
1993           }
1994         }
1995         cdebug << ThreadNo() << " Successed_SuccessAction " << toNode->Name() << "->SendSomeDataReady( "
1996                << Name() << " )" << endl ;
1997         res = toNode->SendSomeDataReady( Name() ) ;
1998         if ( res ) {
1999           if ( firsttoNode == NULL &&
2000                toNode->ThreadNo() == pthread_self() ) {
2001             firsttoNode = toNode ;
2002             cdebug << ThreadNo() << " Successed_SuccessAction firsttoNode "
2003                    << toNode->Name() << endl ;
2004           }
2005           else if ( firstzeroNode == NULL &&
2006                     toNode->ThreadNo() == 0 ) {
2007             firstzeroNode = toNode ;
2008           }
2009           else {
2010             SomeDataNodes.push_back( toNode ) ;
2011             cdebug << ThreadNo() << " Successed_SuccessAction " << Name() << " push "
2012                    << toNode->Name() << " " << SomeDataNodes.size() << endl ;
2013           }
2014         }
2015       }
2016     }
2017   }
2018
2019   if ( firsttoNode == NULL && firstzeroNode ) {
2020     firsttoNode = firstzeroNode ;
2021     cdebug << ThreadNo()
2022            << " Successed_SuccessAction firsttoNode = firstzeroNode "
2023            << endl ;
2024   }
2025   else if ( firsttoNode && firstzeroNode ) {
2026     SomeDataNodes.push_back( firstzeroNode ) ;
2027     cdebug << ThreadNo() << " Successed_SuccessAction " << Name() << " push firstzeroNode "
2028            << firstzeroNode->Name() << " " << SomeDataNodes.size() << endl ;
2029   }
2030   else {
2031     cdebug << ThreadNo() << " Successed_SuccessAction " << Name() << " firsttoNode " << firsttoNode
2032            << " firstzeroNode " << firstzeroNode << endl ;
2033   }
2034
2035   while ( SomeDataNodes.size() ) {
2036     GraphExecutor::InNode *aNode = SomeDataNodes.front() ;
2037     SomeDataNodes.pop_front() ;
2038 //    cdebug << pthread_self() << "/" << ThreadNo()
2039 //           << " Successed_SuccessAction pop "
2040 //           << SomeDataNodes.size() << " " << aNode->Name() << endl ;
2041     if ( aNode->State() == GraphExecutor::DataReadyState ) {
2042       aNode->CreateNewThreadIf( true ) ;
2043       aNode->UnLockDataWait() ;
2044       res = aNode->DataUndef_AllDataReadyAction() ;
2045     }
2046     else {
2047 //      cdebug << pthread_self() << "/" << ThreadNo() << " ERROR "
2048 //             << aNode->Name() << " "
2049 //             << Automaton()->StateName( aNode->State() ) << endl ;
2050     }
2051   }
2052
2053   if ( firsttoNode ) {
2054 //    cdebug << pthread_self() << "/" << ThreadNo()
2055 //           << " Successed_SuccessAction start firsttoNode "
2056 //           << SomeDataNodes.size() << " " << firsttoNode->Name() << endl ;
2057     firsttoNode->CreateNewThreadIf( false ) ;
2058     firsttoNode->RewindStack( RewindStack() ) ;
2059     if ( firsttoNode->State() == GraphExecutor::SuccessedState ) {
2060 //      cdebug << pthread_self() << "/" << ThreadNo() << " " << Name()
2061 //             << " : " << firsttoNode->Name() << " "
2062 //             << Automaton()->StateName( firsttoNode->State() )
2063 //             << " --> DataWaitingState for Thread "
2064 //             << firsttoNode->ThreadNo() << endl ;
2065       firsttoNode->State( GraphExecutor::DataWaitingState ) ;
2066     }
2067 //    pthread_t OldT = firsttoNode->ThreadNo() ;
2068     firsttoNode->ThreadNo( pthread_self() ) ;
2069 // On continue avec le meme thread
2070 //    cdebug << pthread_self() << "/" << ThreadNo() << " firsttoNode "
2071 //           << firsttoNode->Name() << "Thread(" << OldT << "-->"
2072 //           << firsttoNode->ThreadNo() << ")" << endl ;
2073     ThreadNo( 0 ) ;
2074 //    cdebug << ThreadNo() << " Successed_SuccessAction " << Name()
2075 //           << " for " << firsttoNode->Name()
2076 //           << " !firsttoNode->CreateNewThreadIf() "
2077 //           << !firsttoNode->CreateNewThreadIf()
2078 //           << " " << Automaton()->StateName( firsttoNode->State() ) ;
2079     if ( firsttoNode->State() == GraphExecutor::DataReadyState ) {
2080       cdebug << endl ;
2081       firsttoNode->UnLockDataWait() ;
2082       res = firsttoNode->DataUndef_AllDataReadyAction() ;
2083     }
2084     else {
2085       cdebug << " ERROR " << endl ;
2086     }
2087   }
2088   else {
2089 //    cdebug << ThreadNo() << " Successed_SuccessAction " << Name()
2090 //           << " NO DataReady ==> ThreadNo( 0 ) firsttoNode == NULL LINKEDnodesnumber " << linkednodesnumber << endl ;
2091     ThreadNo( 0 ) ;
2092   }
2093
2094 //  if ( linkednodesnumber == 0 && firsttoNode == NULL ) {
2095 //    cdebug << ThreadNo() << " Successed_SuccessAction " << Name() << " LinkedNodesSize " << LinkedNodesSize()
2096 //           << " firsttoNode == NULL LINKEDnodesnumber " << linkednodesnumber << " CHECK" << endl ;
2097 //    _OutNode->CheckAllDone() ;
2098 //  }
2099
2100 //  cdebug << pthread_self() << "/" << ThreadNo()
2101 //         << " <-- Successed_SuccessAction " << Name() << " linkednodesnumber "
2102 //         << linkednodesnumber << endl;
2103   return 1 ;
2104 }
2105
2106 bool GraphExecutor::InNode::SendSomeDataReady( char * FromNodeName ) {
2107   bool RetVal = false ;
2108   if ( IsDataFlowNode() ) {
2109     cdebug << ThreadNo() << " ----> " << Name()
2110          << " send Result to graph " << Name() << endl;
2111   }
2112   else {
2113 //    cdebug << pthread_self() << "/" << ThreadNo() << " ----> " << FromNodeName
2114 //           << " send SomeDataReady to " << Name() << " "
2115 //           << Automaton()->StateName( State() ) 
2116 //           << " CreateNewThreadIf() " << CreateNewThreadIf()
2117 //           << " LockedDataWait " << IsLockedDataWait() << endl;
2118 #if 0
2119   //cout << pthread_self() << "/" << ThreadNo() << " ----> " << FromNodeName
2120          << " send SomeDataReady to " << Name() << " "
2121          << Automaton()->StateName( State() ) 
2122          << " CreateNewThreadIf() " << CreateNewThreadIf()
2123          << " LockedDataWait " << IsLockedDataWait() << endl;
2124 #endif
2125     if ( State() == GraphExecutor::SuccessedState ||
2126          State() == GraphExecutor::SuspendedSuccessedState ||
2127          State() == GraphExecutor::SuspendedSuccessedToReStartState ) {
2128 //      cdebug << ThreadNo() << " " << FromNodeName
2129 //             << " : " << Name() << " " << Automaton()->StateName( State() )
2130 //             << " --> DataWaitingState for Thread "
2131 //             << ThreadNo() << " " << endl ;
2132       State( GraphExecutor::DataWaitingState ) ;
2133     }
2134     LockDataWait() ;
2135     DataFromNode( FromNodeName ) ;
2136     RetVal = !SendEvent( GraphExecutor::SomeDataReadyEvent );
2137     if ( !RetVal ) {
2138       UnLockDataWait() ;
2139     }
2140   }
2141   return RetVal ;
2142 }
2143
2144 int GraphExecutor::InNode::Errored_ErrorAction() {
2145   cdebug << ThreadNo() << " Errored_ErrorAction " << Name()
2146          << " will pthread_exit" << endl;
2147   DoneAction() ;
2148   return 1 ;
2149 }
2150
2151 int GraphExecutor::InNode::Successed_SuspendAction() {
2152   cdebug << ThreadNo() << " Successed_SuspendAction -->Suspend " << Name()
2153          << " Threads " << _OutNode->Threads() << " SuspendedThreads "
2154          << _OutNode->SuspendedThreads() << endl;
2155   _OutNode->PushEvent( this , GraphExecutor::SuspendedSuccessedEvent ,
2156                        GraphExecutor::SuspendedSuccessedState ) ; 
2157   DoneAction() ;
2158   GraphExecutor::InNode * aReStartNode = SuspendAction() ;
2159   cdebug << ThreadNo() << " Successed_SuspendAction Resumed " << Name() ;
2160   if ( aReStartNode ) {
2161     _aReStartNode = NULL ;
2162     cdebug << " for " << aReStartNode->Name() << endl;
2163     aReStartNode->SendEvent( _aReStartEvent ) ;
2164   }
2165   else {
2166     cdebug << endl;
2167     SendEvent( GraphExecutor::ResumeEvent ) ;
2168   }
2169   return 1 ;
2170 }
2171
2172 int GraphExecutor::InNode::Errored_SuspendAction() {
2173   cdebug << ThreadNo() << " Errored_SuspendAction -->Suspend " << Name()
2174          << " Threads " << _OutNode->Threads() << " SuspendedThreads "
2175          << _OutNode->SuspendedThreads() << endl;
2176   _OutNode->PushEvent( this , GraphExecutor::SuspendedErroredEvent ,
2177                        GraphExecutor::SuspendedErroredState ) ; 
2178   DoneAction() ;
2179   GraphExecutor::InNode * aReStartNode = SuspendAction() ;
2180   cdebug << ThreadNo() << " Errored_SuspendAction Resumed " << Name()
2181          << endl;
2182   if ( aReStartNode ) {
2183     _aReStartNode = NULL ;
2184     aReStartNode->SendEvent( _aReStartEvent ) ;
2185   }
2186   else {
2187     SendEvent( GraphExecutor::ResumeEvent ) ;
2188   }
2189   return 1 ;
2190 }
2191
2192 int GraphExecutor::InNode::SuspendedSuccessed_ResumeAction() {
2193   cdebug << ThreadNo() << " SuspendedSuccessed_ResumeAction " << Name() << endl;
2194 //  ResumeAction() ;
2195   _OutNode->PushEvent( this , GraphExecutor::ResumedSuccessedEvent ,
2196                        GraphExecutor::ResumedSuccessedState ) ; 
2197   SendEvent( ResumedSuccessedEvent ) ;
2198   return 1 ;
2199 }
2200
2201 int GraphExecutor::InNode::SuspendedErrored_ResumeAction() {
2202   cdebug << ThreadNo() << " SuspendedErrored_ResumeAction " << Name() << endl;
2203 //  ResumeAction() ;
2204   _OutNode->PushEvent( this , GraphExecutor::ResumedErroredEvent ,
2205                        GraphExecutor::ResumedErroredState ) ; 
2206   SendEvent( ResumedErroredEvent ) ;
2207   return 1 ;
2208 }
2209
2210 int GraphExecutor::InNode::Successed_KillAction() {
2211   KillAction() ;
2212   _OutNode->PushEvent( this , GraphExecutor::KilledEvent ,
2213                        GraphExecutor::KilledSuccessedState ) ; 
2214   cdebug << ThreadNo() << " Successed_KillAction " << Name() << endl;
2215   return 1 ;
2216 }
2217
2218 int GraphExecutor::InNode::Errored_KillAction() {
2219   KillAction() ;
2220   _OutNode->PushEvent( this , GraphExecutor::KilledEvent ,
2221                        GraphExecutor::KilledErroredState ) ; 
2222   cdebug << ThreadNo() << " Errored_KillAction " << Name() << endl;
2223   return 1 ;
2224 }
2225
2226 int GraphExecutor::InNode::Successed_StopAction() {
2227   StopAction() ;
2228   _OutNode->PushEvent( this , GraphExecutor::StoppedEvent ,
2229                        GraphExecutor::StoppedSuccessedState ) ; 
2230   cdebug << ThreadNo() << " Successed_StopAction " << Name() << endl;
2231   return 1 ;
2232 }
2233
2234 int GraphExecutor::InNode::Errored_StopAction() {
2235   StopAction() ;
2236   _OutNode->PushEvent( this , GraphExecutor::StoppedEvent ,
2237                        GraphExecutor::StoppedErroredState ) ; 
2238   cdebug << ThreadNo() << " Errored_StopAction " << Name() << endl;
2239   return 1 ;
2240 }
2241
2242 int GraphExecutor::InNode::SuspendedSuccessed_ReStartAction() {
2243   cdebug << ThreadNo() << " SuspendedSuccessed_ReStartAction " << Name() << endl;
2244   _OutNode->PushEvent( this , GraphExecutor::ReStartedEvent ,
2245                        GraphExecutor::ReStartedState ) ;
2246   int i ;
2247   for ( i = 0 ; i < GetNodeInPortsSize() ; i++ ) {
2248     GetChangeNodeInPort( i )->State( SUPERV::ReadyState ) ;
2249   }
2250   SendEvent( ExecuteEvent ) ;
2251   cdebug << ThreadNo() << " SuspendedSuccessed_ReStartAction "  << Name() << endl;
2252   return 1 ;
2253 }
2254
2255 int GraphExecutor::InNode::SuspendedErrored_ReStartAction() {
2256   cdebug << ThreadNo() << " SuspendedErrored_ReStartAction " << Name() << endl;
2257   _OutNode->PushEvent( this , GraphExecutor::ReStartedEvent ,
2258                        GraphExecutor::ReStartedState ) ; 
2259   int i ;
2260   for ( i = 0 ; i < GetNodeInPortsSize() ; i++ ) {
2261     GetChangeNodeInPort( i )->State( SUPERV::ReadyState ) ;
2262   }
2263   SendEvent( ExecuteEvent ) ;
2264   cdebug << ThreadNo() << " SuspendedErrored_ReStartAction "  << Name() << endl;
2265   return 1 ;
2266 }
2267
2268 int GraphExecutor::InNode::SuspendedSuccessed_ReStartAndSuspendAction() {
2269   cdebug << ThreadNo() << " SuspendedSuccessed_ReStartAndSuspendAction " << Name()
2270          << endl;
2271   _OutNode->PushEvent( this , GraphExecutor::ReStartedAndSuspendEvent ,
2272                        GraphExecutor::ReStartedState ) ; 
2273   State( GraphExecutor::DataWaitingState ) ;
2274   if ( !Suspend() ) {
2275     cdebug << "InNode::Suspend() Node " << Name() << endl ;
2276     return false ;
2277   }
2278   else if ( SendEvent( GraphExecutor::SomeDataReadyEvent ) ) {
2279     cdebug << "InNode::SendEvent( SomeDataReadyEvent ) Node "
2280            << Name() << endl ;
2281     return false ;
2282   }
2283   cdebug << ThreadNo() << " SuspendedSuccessed_ReStartAndSuspendAction "  << Name()
2284          << endl;
2285   return 1 ;
2286 }
2287
2288 int GraphExecutor::InNode::SuspendedErrored_ReStartAndSuspendAction() {
2289   cdebug << ThreadNo() << " SuspendedErrored_ReStartAndSuspendAction " << Name()
2290          << endl;
2291   _OutNode->PushEvent( this , GraphExecutor::ReStartedAndSuspendEvent ,
2292                        GraphExecutor::ReStartedState ) ; 
2293   State( GraphExecutor::DataWaitingState ) ;
2294   if ( !Suspend() ) {
2295     cdebug << "InNode::Suspend() Node " << Name() << endl ;
2296     return false ;
2297   }
2298   else if ( SendEvent( GraphExecutor::SomeDataReadyEvent ) ) {
2299     cdebug << "InNode::SendEvent( SomeDataReadyEvent ) Node "
2300            << Name() << endl ;
2301     return false ;
2302   }
2303   cdebug << ThreadNo() << " SuspendedErrored_ReStartAndSuspendAction "  << Name()
2304          << endl;
2305   return 1 ;
2306 }
2307
2308 void GraphExecutor::InNode::InParametersSet( bool & Err ,
2309                                              int  nInParams ,
2310                                              ServicesAnyData * InParametersList ) {
2311   int i ;
2312   cdebug << ThreadNo() << " InParametersSet " << Name() << endl ;
2313   for ( i = 0 ; i < nInParams ; i++ ) {
2314     ServicesAnyData D = InParametersList[i];
2315     GraphBase::InPort * anInPort = GetChangeNodeInPort(i) ;
2316     GraphBase::OutPort * theOutPort = anInPort->GetOutPort() ;
2317     if ( anInPort->IsGate() && theOutPort == NULL ) {
2318       cdebug << ThreadNo() << " ArgIn" << i << " " << D.Name << " "
2319              << anInPort->GetServicesParameter().Parametertype
2320              << " is inactive. " << anInPort->Kind() << endl ;
2321     }
2322     else if ( anInPort->State() == SUPERV::ReadyState ) {
2323       if ( anInPort->IsGate() ) {
2324         CORBA::Any * anAny = new CORBA::Any() ;
2325         *anAny <<= (long ) 0 ;
2326         theOutPort->Value( anAny ) ;
2327       }
2328       if ( !anInPort->IsDataStream() ) {
2329         anInPort->State( SUPERV::WaitingState ) ;
2330       }
2331       D.Name = CORBA::string_dup( anInPort->GetServicesParameter().Parametername ) ;
2332       cdebug << ThreadNo() << " ArgIn" << i << " " << anInPort->Kind()
2333              << " " << anInPort->State() ;
2334       cdebug << "      " << D.Name << " " << anInPort->GetServicesParameter().Parametertype << " : " ;
2335       D.Value = *theOutPort->Value() ; // CORBA::Any
2336       string _Type = CORBA::string_dup( anInPort->GetServicesParameter().Parametertype ) ;
2337       const char * Type = _Type.c_str() ;
2338       switch ( D.Value.type()->kind() ) { // { string , long , double , objref }
2339       case CORBA::tk_string:
2340         char * t;
2341         D.Value >>= t;
2342         cdebug << t << " (string)" ;
2343         if ( !strcmp( Type , "string" ) ) {
2344         }
2345         else if ( !strcmp( Type , "boolean" ) ) {
2346           bool b ;
2347           long d ;
2348           sscanf( t , "%ld" , &d ) ;
2349           b = (bool ) d ;
2350           D.Value <<=  (CORBA::Any::from_boolean ) b ;
2351 //          theOutPort->Value( D.Value ) ;
2352         }
2353         else if ( !strcmp( Type , "char" ) ) {
2354           unsigned char c ;
2355           long d ;
2356           sscanf( t , "%ld" , &d ) ;
2357           c = (short ) d ;
2358           D.Value <<=  (CORBA::Any::from_char ) c ;
2359           cdebug << "string '" << t << "' --> " << d << " --> char " << c ;
2360 //          theOutPort->Value( D.Value ) ;
2361         }
2362         else if ( !strcmp( Type , "short" ) ) {
2363           short s ;
2364           long d ;
2365           sscanf( t , "%ld" , &d ) ;
2366           s = (short ) d ;
2367           D.Value <<=  s ;
2368           cdebug << "string '" << t << "' --> " << d << " --> short " << s ;
2369 //          theOutPort->Value( D.Value ) ;
2370         }
2371         else if ( !strcmp( Type , "int" ) || !strcmp( Type , "long" ) ) {
2372           long l ;
2373           sscanf( t , "%ld" , &l ) ;
2374           D.Value <<=  l ;
2375           cdebug << "string '" << t << " --> long " << l ;
2376 //          theOutPort->Value( D.Value ) ;
2377         }
2378         else if ( !strcmp( Type , "float" ) ) {
2379           double d ;
2380           sscanf( t , "%lf" , &d ) ;
2381           float f = d ;
2382           D.Value <<= f ;
2383           cdebug << "string '" << t << "' --> " << setw(25) << setprecision(18) << d << " --> float " << " = "
2384                  << setw(25) << setprecision(18) << f ;
2385 //          theOutPort->Value( D.Value ) ;
2386         }
2387         else if ( !strcmp( Type , "double" ) ) {
2388           double d ;
2389           sscanf( t , "%lf" , &d ) ;
2390           D.Value <<= d ;
2391           cdebug << "string '" << t << " --> double " << setw(25) << setprecision(18) << d ;
2392 //          theOutPort->Value( D.Value ) ;
2393         }
2394 //        else if ( !strcmp( Type , "objref" ) ) {
2395         else { // Default
2396           CORBA::Object_ptr ObjRef ;
2397           try {
2398             ObjRef = StringToObject( t ) ;
2399             D.Value <<= ObjRef ;
2400           }
2401           catch( ... ) {
2402             D.Value <<= CORBA::Object::_nil() ;
2403           }
2404 //          theOutPort->Value( D.Value ) ;
2405         }
2406 //        else {
2407 //          cdebug << " (other ERROR)" << endl ;
2408 //        }
2409         cdebug << " --> call_kind " << D.Value.type()->kind() << endl ;
2410         break;
2411       case CORBA::tk_long:
2412         long l;
2413         D.Value >>= l;
2414         cdebug << l << " (long)" << endl ;
2415         if ( !strcmp( Type , "string" ) ) {
2416           char t[40] ;
2417           sprintf( t , "%ld" , l ) ;
2418           D.Value <<= t ;
2419 //          theOutPort->Value( D.Value ) ;
2420         }
2421         else if ( !strcmp( Type , "boolean" ) ) {
2422           bool b ;
2423           b = (bool ) l ;
2424           D.Value <<=  (CORBA::Any::from_boolean ) b ;
2425 //          theOutPort->Value( D.Value ) ;
2426         }
2427         else if ( !strcmp( Type , "char" ) ) {
2428           unsigned char c ;
2429           c = (unsigned char ) l ;
2430           D.Value <<=  (CORBA::Any::from_char ) c ;
2431 //          theOutPort->Value( D.Value ) ;
2432         }
2433         else if ( !strcmp( Type , "short" ) ) {
2434           short s ;
2435           s = (short ) l ;
2436           D.Value <<=  s ;
2437 //          theOutPort->Value( D.Value ) ;
2438         }
2439         else if ( !strcmp( Type , "int" ) || !strcmp( Type , "long" ) ) {
2440         }
2441         else if ( !strcmp( Type , "float" ) ) {
2442           float f ;
2443           f = (float ) l ;
2444           D.Value <<= f ;
2445 //          theOutPort->Value( D.Value ) ;
2446         }
2447         else if ( !strcmp( Type , "double" ) ) {
2448           double d ;
2449           d = (double ) l ;
2450           D.Value <<= d ;
2451 //          theOutPort->Value( D.Value ) ;
2452         }
2453 //        else if ( !strcmp( Type , "objref" ) ) {
2454         else { // Default
2455           D.Value <<= CORBA::Object::_nil() ;
2456 //          theOutPort->Value( D.Value ) ;
2457         }
2458 //        else {
2459 //          cdebug << " (other ERROR)" << endl ;
2460 //        }
2461         cdebug << " --> call_kind " << D.Value.type()->kind() << endl ;
2462         break;
2463       case CORBA::tk_double:
2464         double d;
2465         D.Value >>= d;
2466         cdebug << d << " (double)" << endl ;
2467         if ( !strcmp( Type , "string" ) ) {
2468           char t[40] ;
2469           sprintf( t , "%lf" , d ) ;
2470           D.Value <<= t ;
2471 //          theOutPort->Value( D.Value ) ;
2472         }
2473         else if ( !strcmp( Type , "boolean" ) ) {
2474           bool b ;
2475           b = (bool ) d ;
2476           D.Value <<=  (CORBA::Any::from_boolean ) b ;
2477 //          theOutPort->Value( D.Value ) ;
2478         }
2479         else if ( !strcmp( Type , "char" ) ) {
2480           unsigned char c ;
2481           c = (unsigned char ) d ;
2482           D.Value <<=  (CORBA::Any::from_char ) c ;
2483 //          theOutPort->Value( D.Value ) ;
2484         }
2485         else if ( !strcmp( Type , "short" ) ) {
2486           short s ;
2487           s = (short ) d ;
2488           D.Value <<=  s ;
2489 //          theOutPort->Value( D.Value ) ;
2490         }
2491         else if ( !strcmp( Type , "int" ) || !strcmp( Type , "long" ) ) {
2492           long l ;
2493           l = (long ) d ;
2494           D.Value <<= l ;
2495 //          theOutPort->Value( D.Value ) ;
2496         }
2497         else if ( !strcmp( Type , "float" ) ) {
2498           float f ;
2499           f = (float ) d ;
2500           D.Value <<= f ;
2501 //          theOutPort->Value( D.Value ) ;
2502         }
2503         else if ( !strcmp( Type , "double" ) ) {
2504         }
2505 //        else if ( !strcmp( Type , "objref" ) ) {
2506         else { // Default
2507           D.Value <<= CORBA::Object::_nil() ;
2508 //          theOutPort->Value( D.Value ) ;
2509         }
2510 //        else {
2511 //          cdebug << " (other ERROR)" << endl ;
2512 //        }
2513         cdebug << " --> call_kind " << D.Value.type()->kind() << endl ;
2514         break;
2515       case CORBA::tk_objref:
2516         if ( !strcmp( Type , "string" ) ) {
2517           CORBA::Object_ptr ObjRef ;
2518           char * retstr ;
2519           try {
2520             D.Value >>= ObjRef ;
2521             retstr = ObjectToString( ObjRef ) ;
2522             D.Value <<= retstr ;
2523 //            theOutPort->Value( D.Value ) ;
2524           }
2525           catch( ... ) {
2526             if ( i != 0 ) {
2527               Err = true ;
2528             }
2529             cdebug << "ToString( object ) Catched ERROR" << endl ;
2530           }
2531         }
2532         else if ( !strcmp( Type , "boolean" ) ) {
2533           bool b = 0 ;
2534           D.Value <<=  (CORBA::Any::from_boolean ) b ;
2535 //          theOutPort->Value( D.Value ) ;
2536         }
2537         else if ( !strcmp( Type , "char" ) ) {
2538           unsigned char c = 0 ;
2539           D.Value <<=  (CORBA::Any::from_char ) c ;
2540 //          theOutPort->Value( D.Value ) ;
2541         }
2542         else if ( !strcmp( Type , "short" ) ) {
2543           short s = 0 ;
2544           D.Value <<=  s ;
2545 //          theOutPort->Value( D.Value ) ;
2546         }
2547         else if ( !strcmp( Type , "int" ) || !strcmp( Type , "long" ) ) {
2548           long l = 0 ;
2549           D.Value <<= l ;
2550 //          theOutPort->Value( D.Value ) ;
2551         }
2552         else if ( !strcmp( Type , "float" ) ) {
2553           float f = 0 ;
2554           D.Value <<= f ;
2555 //          theOutPort->Value( D.Value ) ;
2556         }
2557         else if ( !strcmp( Type , "double" ) ) {
2558           double d = 0 ;
2559           D.Value <<= d ;
2560 //          theOutPort->Value( D.Value ) ;
2561         }
2562 //        else if ( !strcmp( Type , "objref" ) ) {
2563         else { // Default
2564           CORBA::Object_ptr obj ;
2565           char * retstr ;
2566           try {
2567             D.Value >>= obj ;
2568             retstr = ObjectToString( obj ) ;
2569             cdebug << retstr << endl ;
2570           }
2571           catch( ... ) {
2572             if ( i != 0 ) {
2573               Err = true ;
2574             }
2575             cdebug << "ToString( object ) Catched ERROR" << endl ;
2576           }
2577         }
2578 //        else {
2579 //          cdebug << " (other ERROR)" << endl ;
2580 //        }
2581         cdebug << " --> call_kind " << D.Value.type()->kind() << endl ;
2582         break;
2583       default:
2584         cdebug << " (other ERROR) " << D.Value.type()->kind() << endl ;
2585       }
2586     }
2587     else {
2588       cdebug << ThreadNo() << " In" << i << " : wrong state ERROR State "
2589              << anInPort->State() << " NameState "
2590              << Automaton()->StateName( anInPort->State() ) << " PortName "
2591              << anInPort->PortName() << " Parametername "
2592              << anInPort->GetServicesParameter().Parametername << endl ;
2593       Err = true ;
2594     }
2595     InParametersList[i] = D ;
2596   }
2597 }
2598
2599 void GraphExecutor::InNode::InOutParametersSet( int nOutParams ,
2600                                                 ServicesAnyData * OutParametersList ) {
2601   int i ;
2602   for ( i = 0 ; i < nOutParams ; i++ ) {
2603     ServicesAnyData D = OutParametersList[i] ;
2604
2605     D.Name = GetChangeNodeOutPort(i)->GetServicesParameter().Parametername;
2606     string _Type = CORBA::string_dup(GetChangeNodeOutPort(i)->GetServicesParameter().Parametertype) ;
2607     const char * Type = _Type.c_str() ;
2608     bool OutDone = GetChangeNodeOutPort(i)->Done() ;
2609     cdebug << ThreadNo() << " ArgOut" << i << " " << D.Name << " Done("
2610            << OutDone << ") " << Type << " : " << endl ;
2611     if ( !strcmp( Type , "string" ) ) {
2612       D.Value <<= (char *) NULL ;
2613     }
2614     else if ( !strcmp( Type , "boolean" ) ) {
2615       bool b = 0 ;
2616       D.Value <<=  (CORBA::Any::from_boolean ) b ;
2617     }
2618     else if ( !strcmp( Type , "char" ) ) {
2619       unsigned char c = 0 ;
2620       D.Value <<=  (CORBA::Any::from_char ) c ;
2621     }
2622     else if ( !strcmp( Type , "short" ) ) {
2623       short s = 0 ;
2624       D.Value <<=  s ;
2625     }
2626     else if ( !strcmp( Type , "int" ) || !strcmp( Type , "long" ) ) {
2627       D.Value <<= (long ) 0 ;
2628     }
2629     else if ( !strcmp( Type , "float" ) ) {
2630       float f = 0 ;
2631       D.Value <<= f ;
2632     }
2633     else if ( !strcmp( Type , "double" ) ) {
2634       double d = 0 ;
2635       D.Value <<= d ;
2636     }
2637     else {
2638       D.Value <<= CORBA::Object::_nil() ;
2639     }
2640 //#if 0
2641     switch (D.Value.type()->kind()) { // { string , long , double , objref }
2642     case CORBA::tk_string:
2643       char * t;
2644       D.Value >>= t;
2645       cdebug << ThreadNo() << " " << t << "(string)" << endl ;
2646       break;
2647     case CORBA::tk_boolean:
2648       bool b ;
2649       D.Value >>= (CORBA::Any::to_boolean ) b;
2650       cdebug << ThreadNo() << " " << b << "(boolean)" << endl ;
2651       break;
2652     case CORBA::tk_char:
2653       unsigned char c ;
2654       D.Value >>= (CORBA::Any::to_char ) c;
2655       cdebug << ThreadNo() << " " << c << "(char)" << endl ;
2656       break;
2657     case CORBA::tk_short:
2658       short s;
2659       D.Value >>= s;
2660       cdebug << ThreadNo() << " " << s << "(short)" << endl ;
2661       break;
2662     case CORBA::tk_long:
2663       long l;
2664       D.Value >>= l;
2665       cdebug << ThreadNo() << " " << l << "(long)" << endl ;
2666       break;
2667     case CORBA::tk_float:
2668       float f;
2669       D.Value >>= f;
2670       cdebug << ThreadNo() << " " << f << "(float)" << endl ;
2671       break;
2672     case CORBA::tk_double:
2673       double d;
2674       D.Value >>= d;
2675       cdebug << ThreadNo() << " " << d << "(double)" << endl ;
2676       break;
2677     case CORBA::tk_objref:
2678       try {
2679         CORBA::Object_ptr obj ;
2680         char * retstr ;
2681         D.Value >>= obj ;
2682         retstr = ObjectToString( obj ) ;
2683         cdebug << ThreadNo() << retstr << endl ;
2684       }
2685       catch( ... ) {
2686         cdebug << "ToString( object ) Catched ERROR" << endl ;
2687       }
2688       break;
2689     default:
2690       cdebug << ThreadNo() << " " << "(other ERROR)" << endl ;
2691     }
2692 //#endif
2693     OutParametersList[i] = D ;
2694   }
2695 }
2696
2697 bool GraphExecutor::InNode::OutParametersSet( bool Err ,
2698                                               SUPERV::GraphState NewState ,
2699                                               int nOutParams ,
2700                                               ServicesAnyData * OutParametersList ) {
2701   bool RetVal = true ;
2702   int i ;
2703   GraphBase::OutPort * aGateOutPort = NULL ;
2704   bool OrSwitch = false ;
2705   cdebug << "OutParametersSet " << Name() << " nOutParams " << nOutParams << " NewState " << NewState << endl ;
2706 //  cout << "OutParametersSet " << Name() << " nOutParams " << nOutParams << " NewState " << NewState << endl ;
2707   if ( nOutParams && !IsMacroNode() ) {
2708     GraphBase::OutPort * anOutPort ;
2709     for ( i = 0 ; i < nOutParams ; i++ ) {
2710       anOutPort = GetChangeNodeOutPort(i) ;
2711       if ( Err ) {
2712         anOutPort->State( NewState ) ;
2713         anOutPort->Done( true ) ;
2714       }
2715       else {
2716         cdebug << ThreadNo() << " " << "Out" << i << " " << Name() << " "
2717                << anOutPort->PortName() << " " << anOutPort->Kind() ;
2718         ServicesAnyData D = OutParametersList[i] ;
2719         switch (D.Value.type()->kind()) { // { string , long , double , objref }
2720         case CORBA::tk_string: {
2721           char * t;
2722           D.Value >>= t;
2723           cdebug << ThreadNo() << " " << t << "(string)" << endl ;
2724           break;
2725         }
2726         case CORBA::tk_boolean: {
2727           bool b ;
2728           D.Value >>= (CORBA::Any::to_boolean ) b;
2729           long l = (long ) b ;
2730           D.Value <<= l ;
2731           cdebug << ThreadNo() << " " << b << "(boolean)" << endl ;
2732           break;
2733         }
2734         case CORBA::tk_char: {
2735           unsigned char c ;
2736           D.Value >>= (CORBA::Any::to_char ) c;
2737           long l = (long ) c ;
2738           D.Value <<= l ;
2739           cdebug << ThreadNo() << " " << c << "(char)" << endl ;
2740           break;
2741         }
2742         case CORBA::tk_short: {
2743           short s;
2744           D.Value >>= s;
2745           long l = (long ) s ;
2746           D.Value <<= l ;
2747           cdebug << ThreadNo() << " " << s << "(short)" << endl ;
2748           break;
2749         }
2750         case CORBA::tk_long: {
2751           long l;
2752           D.Value >>= l;
2753           cdebug << ThreadNo() << " " << l << "(long)" << endl ;
2754           break;
2755         }
2756         case CORBA::tk_float: {
2757           float f;
2758           D.Value >>= f;
2759           double d = (double ) f ;
2760           D.Value <<= d ;
2761           cdebug << ThreadNo() << " " << f << "(float)" << endl ;
2762           break;
2763         }
2764         case CORBA::tk_double: {
2765           double d;
2766           D.Value >>= d;
2767           cdebug << ThreadNo() << " " << d << "(double)" << endl ;
2768           break;
2769         }
2770         case CORBA::tk_objref: {
2771           try {
2772             CORBA::Object_ptr obj ;
2773             char * retstr ;
2774             D.Value >>= obj ;
2775             retstr = ObjectToString( obj ) ;
2776             cdebug << ThreadNo() << retstr << endl ;
2777           }
2778           catch( ... ) {
2779             cdebug << "ToString( object ) Catched ERROR" << endl ;
2780           }
2781           break;
2782         }
2783         default: {
2784           cdebug << ThreadNo() << " " << "(other ERROR)" << endl ;
2785         }
2786         }
2787         OutParametersList[i] = D ;
2788         if ( !anOutPort->IsDataStream() ) {
2789           if ( anOutPort->IsGate() ) {
2790             aGateOutPort = anOutPort ;
2791             cdebug << " Gate " ;
2792             long l = 1;
2793             OutParametersList[i].Value <<= l;
2794             anOutPort->Value( OutParametersList[i].Value );
2795           }
2796           else if ( anOutPort->IsLoop() ) {
2797             cdebug << " Loop " ;
2798             anOutPort->Value( OutParametersList[i].Value );
2799 // InLoop Port of EndLoopNode is ready :
2800             anOutPort->ChangeInPorts(0)->State( SUPERV::ReadyState ) ;
2801           }
2802           else if ( anOutPort->IsSwitch() ) {
2803             cdebug << " Switch " ;
2804             anOutPort->Value( OutParametersList[i].Value );
2805             if ( anOutPort->InPortsSize() && anOutPort->ChangeInPorts( 0 )->IsGate() ) {
2806               if ( OrSwitch && anOutPort->BoolValue() ) {
2807                 cdebug << "GraphExecutor::InNodeThreads::OutParameters more than one switch is true WARNING"
2808                        << endl ;
2809               }
2810               else {
2811                 OrSwitch = OrSwitch | anOutPort->BoolValue() ;
2812               }
2813             }
2814             cdebug << "OrSwitch " << OrSwitch ;
2815           }
2816           else {
2817             cdebug << " Param " ;
2818             anOutPort->Value( OutParametersList[i].Value );
2819           }
2820           anOutPort->State( NewState ) ;
2821           anOutPort->Done( true ) ;
2822         }
2823         int j ;
2824         for ( j = 0 ; j < anOutPort->InPortsSize() ; j++ ) {
2825           bool fromGOTO = false ;
2826           const char * ToNodeName = anOutPort->ChangeInPorts( j )->NodeName() ;
2827           if ( !strcmp( ToNodeName , _OutNode->Graph()->Name() ) && _OutNode->Graph()->GraphMacroLevel() != 0 ) {
2828             cdebug << "OutParametersSet ToNodeName " << _OutNode->Graph()->Name() << " CoupledNode "
2829                    << _OutNode->Graph()->CoupledNodeName() << _OutNode->Graph()->CoupledNode()
2830                    << endl ;
2831             cdebug << " GraphExecutor " << _OutNode->Graph()->CoupledNode()->GraphEditor()->Executor() << endl ;
2832             _OutNode->Graph()->CoupledNode()->GraphEditor()->Executor()->OutputOfAny( _OutNode->Graph()->CoupledNodeName() ,
2833                                                                             anOutPort->ChangeInPorts( j )->PortName() ,
2834                                                                             *anOutPort->Value() ) ;
2835           }
2836           else {
2837             GraphBase::ComputingNode * ToNode = _OutNode->Graph()->GetChangeGraphNode( ToNodeName ) ;
2838             if ( ToNode ) {
2839 //              cout << "OutParametersSet ToNodeName " << ToNodeName << endl ;
2840               cdebug << "OutParametersSet ToNodeName " << ToNodeName << " " << ToNode->Name() << endl ;
2841               GraphBase::OutPort * aGOTOPort = ToNode->GetChangeNodeInGate()->GetOutPort() ;
2842               if ( aGOTOPort ) {
2843                 fromGOTO = aGOTOPort->IsGOTO() ;
2844               }
2845               if ( anOutPort->ChangeInPorts( j )->IsEndSwitch() || fromGOTO ) {
2846                 cdebug << anOutPort->ChangeInPorts( j )->NodeName() << "("
2847                        << anOutPort->ChangeInPorts( j )->PortName() << ","
2848                        << anOutPort->ChangeInPorts( j )->Kind() << ") WILL BE changed from "
2849                        << anOutPort->ChangeInPorts( j )->GetOutPort()->NodeName()
2850                        << "("
2851                        << anOutPort->ChangeInPorts( j )->GetOutPort()->PortName()
2852                        << ") to " << anOutPort->NodeName() << "("
2853                        << anOutPort->PortName() << ")" << endl ;
2854                 anOutPort->ChangeInPorts( j )->ChangeOutPort( anOutPort ) ;
2855               }
2856               else {
2857                 cdebug << anOutPort->ChangeInPorts( j )->NodeName() << "("
2858                        << anOutPort->ChangeInPorts( j )->PortName() << ","
2859                        << anOutPort->ChangeInPorts( j )->Kind() << ") NOT changed from "
2860                        << anOutPort->ChangeInPorts( j )->GetOutPort()->NodeName()
2861                        << "("
2862                        << anOutPort->ChangeInPorts( j )->GetOutPort()->PortName()
2863                        << ") to " << anOutPort->NodeName() << "("
2864                        << anOutPort->PortName() << ")" << endl ;
2865               }
2866             }
2867           }
2868         }
2869 //#if 0
2870         switch (anOutPort->Value()->type()->kind()) {
2871         case CORBA::tk_string:
2872           char * t;
2873           (*anOutPort->Value()) >>= t;
2874           cdebug << ThreadNo() << " Out" << i << " : " << t << "(string)" << endl ;
2875           break;
2876         case CORBA::tk_boolean:
2877           bool b ;
2878           (*anOutPort->Value()) >>= (CORBA::Any::to_boolean ) b;
2879           cdebug << ThreadNo() << " Out" << i << " : " << b << "(boolean)" << endl ;
2880           break;
2881         case CORBA::tk_char:
2882           unsigned char c ;
2883           (*anOutPort->Value()) >>= (CORBA::Any::to_char ) c;
2884           cdebug << ThreadNo() << " Out" << i << " : " << c << "(char)" << endl ;
2885           break;
2886         case CORBA::tk_short:
2887           short s;
2888           (*anOutPort->Value()) >>= s;
2889           cdebug << ThreadNo() << " Out" << i << " : " << s << "(short)" << endl ;
2890           break;
2891         case CORBA::tk_long:
2892           long l;
2893           (*anOutPort->Value()) >>= l;
2894           cdebug << ThreadNo() << " Out" << i << " : " << l << "(long)" << endl ;
2895           break;
2896         case CORBA::tk_float:
2897           float f;
2898           (*anOutPort->Value()) >>= f;
2899           cdebug << ThreadNo() << " Out" << i << " : " << f << "(float)" << endl ;
2900           break;
2901         case CORBA::tk_double:
2902           double d;
2903           (*anOutPort->Value()) >>= d;
2904           cdebug << ThreadNo() << " Out" << i << " : " << d << "(double)" << endl ;
2905           break;
2906         case CORBA::tk_objref:
2907           CORBA::Object_ptr obj ;
2908           char * retstr ;
2909           try {
2910             (*anOutPort->Value()) >>= obj ;
2911             retstr = ObjectToString( obj );
2912             cdebug << ThreadNo() << " Out" << i << " : " << "ToString( object ) "
2913                    << retstr << endl ;
2914           }
2915           catch ( ... ) {
2916             cdebug << ThreadNo() << " Out" << i << " : " << "ToString( object ) "
2917                    << "Catched ERROR" << endl ;
2918           }
2919           break;
2920         default:
2921           cdebug << ThreadNo() << " Out" << i << " : " << "(other ERROR)" << endl ;
2922           RetVal = false ;
2923         }
2924 //#endif
2925       }
2926     }
2927     if ( aGateOutPort && IsSwitchNode() ) {
2928       if ( OrSwitch ) {
2929 //        cdebug << ThreadNo() << " " << "Out0 " << Name() << " Close of "
2930 //               << aGateOutPort->PortName() << " " << aGateOutPort->Kind() ;
2931         long l = 0;
2932         OutParametersList[0].Value <<= l ;
2933         aGateOutPort->Value( OutParametersList[0].Value ) ;
2934       }
2935       else {
2936 //        cdebug << ThreadNo() << " " << "Out0 " << Name() << " Open of "
2937 //               << aGateOutPort->PortName() << " " << aGateOutPort->Kind() ;
2938         long l = 1;
2939         OutParametersList[0].Value <<= l ;
2940         aGateOutPort->Value( OutParametersList[0].Value ) ;
2941         int i ;
2942         for ( i = 0 ; i < GetNodeOutPortsSize() ; i++ ) {
2943           GraphBase::InPort * anInPort ;
2944           anInPort = CoupledNode()->GetChangeInPort( GetNodeOutPort( i )->PortName() ) ;
2945           if ( anInPort ) {
2946             anInPort->ChangeOutPort( GetChangeNodeOutPort( i ) ) ;
2947           }
2948         }
2949       }
2950     }
2951   }
2952   return RetVal ;
2953 }