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