]> SALOME platform Git repositories - modules/superv.git/blob - src/GraphExecutor/DataFlowExecutor_InNodeThreads.cxx
Salome HOME
75e7d77a3210fbbc6068d91fb7d8a33c638cadfe
[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 #define SendEventTrace 1
74 int GraphExecutor::InNode::SendEvent( const GraphExecutor::NodeEvent anEvent ) {  
75
76   _CurrentEvent = (GraphExecutor::NodeEvent ) anEvent ;
77 #if SendEventTrace
78   cdebug_in << pthread_self() << "/" << ThreadNo() << " SendEvent Graph " << _OutNode->Name()
79             << " Node " << Name() << " Event : " << Automaton()->EventName( anEvent )
80             << " State : " << Automaton()->StateName( State() ) << " _RewindStack " << _RewindStack
81             << " ControlState : " << Automaton()->ControlStateName( ControlState() )
82             << endl;
83 #endif
84
85   _OldState = State() ;
86   _NextState = Automaton()->NextState( _OldState , anEvent ) ;
87   if ( _NextState == _OldState ) {
88     cdebug << pthread_self() << "/" << ThreadNo() << " " << Name()
89            << " GraphExecutor::InNodeThreads::SendEvent SameStates ERROR _OldState/_NextState "
90            << _OldState << " Event " << Automaton()->EventName( anEvent ) << endl ;
91     _NextAction = GraphExecutor::VoidAction ;
92     return 0 ;
93   }
94   else {
95     _NextAction = Automaton()->NextAction( _NextState , anEvent ) ;
96   }
97 #if SendEventTrace
98   cdebug << pthread_self() << "/" << ThreadNo() << "NextState( " << _OldState << " , "
99          << Automaton()->EventName( anEvent ) << " ) --> _NextState = " << _NextState
100          << " NextAction( " << _NextState << " , " << Automaton()->EventName( anEvent )
101          << " ) --> _NextAction = "
102          << Automaton()->ActionName( _NextAction ) << endl ;
103 #endif
104
105 //  State( _NextState ) ;
106 //  if ( _OldState == GraphExecutor::SuccessedExecutingState ||
107 //       _OldState == GraphExecutor::ErroredExecutingState ) {
108 //    DoneAction() ;
109 //  }
110
111 #if SendEventTrace
112   cdebug << pthread_self() << "/" << ThreadNo() << " SendedEvent Node "
113          << Name() << 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          << " _RewindStack " << _RewindStack  << endl ;
121 #endif
122
123   int sts = executeAction() ;
124   
125 #if SendEventTrace
126   cdebug_out << pthread_self() << "/" << ThreadNo() << " <--- SendEvent Node " << Name() 
127              << " Event : " << Automaton()->EventName( anEvent )
128              << " State : " << Automaton()->StateName( State() )
129              << endl;
130 #endif
131
132   return sts ;
133
134 }
135
136 #define ActionsTrace 1
137 // ReadyAction - RunningAction - DoneAction - SuspendedAction :
138 // for StateWait( ReadyW - RunningW - DoneW - SuspendedW )
139 void GraphExecutor::InNode::ReadyAction() {
140   if ( pthread_mutex_lock( &_MutexWait ) ) {
141     perror("Ready pthread_mutex_lock ") ;
142     exit( 0 ) ;
143   }
144 #if ActionsTrace
145   cdebug << pthread_self() << "/" << ThreadNo()
146          << "ReadyAction pthread_cond_broadcast _ReadyWait "
147          << Name() << endl ;
148 #endif
149   if ( pthread_cond_broadcast( &_ReadyWait ) ) {
150     perror("Ready pthread_cond_broadcast ") ;
151   }
152   if ( pthread_mutex_unlock( &_MutexWait ) ) {
153     perror("Ready pthread_mutex_unlock ") ;
154     exit( 0 ) ;
155   }
156 }
157
158 void GraphExecutor::InNode::RunningAction() {
159   if ( pthread_mutex_lock( &_MutexWait ) ) {
160     perror("Running pthread_mutex_lock ") ;
161     exit( 0 ) ;
162   }
163 #if ActionsTrace
164   cdebug << pthread_self() << "/" << ThreadNo()
165          << "RunningAction pthread_cond_broadcast _RunningWait "
166          << Name() << endl ;
167 #endif
168 // That activate the pthread_cond_wait for RunninWait
169   if ( pthread_cond_broadcast( &_RunningWait ) ) {
170     perror("Running pthread_cond_broadcast ") ;
171   }
172   if ( pthread_mutex_unlock( &_MutexWait ) ) {
173     perror("Running pthread_mutex_unlock ") ;
174     exit( 0 ) ;
175   }
176 }
177
178 void GraphExecutor::InNode::DoneAction() {
179   if ( pthread_mutex_lock( &_MutexWait ) ) {
180     perror("Done pthread_mutex_lock ") ;
181     exit( 0 ) ;
182   }
183 #if ActionsTrace
184   cdebug << pthread_self() << "/" << ThreadNo()
185          << "DoneAction pthread_cond_broadcast _DoneWait "
186          << Name() << endl ;
187 #endif
188   if ( pthread_cond_broadcast( &_DoneWait ) ) {
189     perror("Done pthread_cond_broadcast ") ;
190   }
191   if ( pthread_mutex_unlock( &_MutexWait ) ) {
192     perror("Done pthread_mutex_unlock ") ;
193     exit( 0 ) ;
194   }
195 }
196
197 void GraphExecutor::InNode::SuspendedAction() {
198   if ( pthread_mutex_lock( &_MutexWait ) ) {
199     perror("Suspended pthread_mutex_lock ") ;
200     exit( 0 ) ;
201   }
202 #if ActionsTrace
203   cdebug << pthread_self() << "/" << ThreadNo()
204          << "SuspendedAction pthread_cond_broadcast _SuspendedWait "
205          << Name() << endl ;
206 #endif
207   if ( pthread_cond_broadcast( &_SuspendedWait ) ) {
208     perror("Suspended pthread_cond_broadcast ") ;
209   }
210   if ( pthread_mutex_unlock( &_MutexWait ) ) {
211     perror("Suspended pthread_mutex_unlock ") ;
212     exit( 0 ) ;
213   }
214 }
215
216 // SuspendAction <--> { ResumeAction - ReStartAction }
217 GraphExecutor::InNode * GraphExecutor::InNode::SuspendAction() {
218   SuspendedAction() ;
219   if ( pthread_mutex_lock( &_MutexWait ) ) {
220     perror("Suspend pthread_mutex_lock ") ;
221     exit( 0 ) ;
222   }
223   if ( !_SuspendSync ) {
224     cdebug << pthread_self() << "/" << ThreadNo() << " pthread_cond " << Name()
225            << " SuspendAction pthread_cond_wait _SuspendWait "
226            << Automaton()->StateName( State() ) << endl ;
227     _SuspendSync = true ;
228     _OutNode->SuspendThread() ;
229     if ( pthread_cond_wait( &_SuspendWait , &_MutexWait ) ) {
230       perror("SuspendAction pthread_cond_wait ") ;
231     }
232     _OutNode->ResumeThread() ;
233 #if ActionsTrace
234     cdebug << pthread_self() << "/" << ThreadNo() << " pthread_cond " << Name()
235            << " SuspendAction pthread_cond_waited"  
236            << Automaton()->StateName( State() ) << endl ;
237 #endif
238   }
239   else {
240 #if ActionsTrace
241     cdebug << pthread_self() << "/" << ThreadNo() << " pthread_cond " << Name()
242            << " NO SuspendAction pthread_cond_wait"  
243            << Automaton()->StateName( State() ) << endl ;
244 #endif
245   }
246 //  SendEvent( _aResumeEvent ) ; ===> Mutex with myself !
247   _SuspendSync = false ;  
248   if ( ControlState() == SUPERV::ToSuspendStartState ||
249        ControlState() == SUPERV::ToSuspendState ) {
250     ControlState( SUPERV::VoidState ) ;
251   }
252   if ( pthread_mutex_unlock( &_MutexWait ) ) {
253     perror("SuspendAction pthread_mutex_unlock ") ;
254     exit( 0 ) ;
255   }
256
257   SendEvent( _aResumeEvent ) ;
258 //  if ( ControlState() == SUPERV::ToSuspendStartState ) {
259 //    ControlState( SUPERV::VoidState ) ;
260 //  }
261
262   if ( pthread_mutex_lock( &_MutexWait ) ) {
263     perror("SuspendAction pthread_mutex_lock ") ;
264     exit( 0 ) ;
265   }
266   if ( _ResumeSync ) {
267 #if ActionsTrace
268     cdebug << pthread_self() << "/" << ThreadNo() << " pthread_cond " << Name()
269            << " SuspendAction pthread_cond_signal _ResumeWait" << endl ;
270 #endif
271     if ( pthread_cond_signal( &_ResumeWait ) ) {
272       perror("SuspendAction pthread_cond_signal _ResumeWait ") ;
273     }
274 #if ActionsTrace
275     cdebug << pthread_self() << "/" << ThreadNo() << " pthread_cond " << Name()
276            << " SuspendAction pthread_cond_signaled _ResumeWait " << endl ;
277 #endif
278   }
279   else {
280 #if ActionsTrace
281     cdebug << pthread_self() << "/" << ThreadNo() << " pthread_cond " << Name()
282            << " NO SuspendAction pthread_cond_signal _ResumeWait" << endl ;
283 #endif
284     _ResumeSync = true ;  
285   }
286   if ( pthread_mutex_unlock( &_MutexWait ) ) {
287     perror("SuspendAction pthread_mutex_unlock ") ;
288     exit( 0 ) ;
289   }
290   if ( _aReStartNode ) {
291     cdebug << Name() << " " << Automaton()->StateName( State() )
292            << "aReStartNode : " << _aReStartNode->Name() << " "
293            << Automaton()->StateName( _aReStartNode->State() ) << endl ;
294     _aReStartNode->SendEvent( _aResumeEvent ) ;
295   }
296   else {
297     cdebug << "NO aReStartNode" 
298            << Automaton()->StateName( State() ) << endl ;
299   }
300   return _aReStartNode ;
301 }
302
303 bool GraphExecutor::InNode::ResumeAction( GraphExecutor::NodeEvent aResumeEvent ) {
304   bool RetVal ;
305   if ( pthread_mutex_lock( &_MutexWait ) ) {
306     perror("ResumeAction pthread_mutex_lock ") ;
307     exit( 0 ) ;
308   }
309   _aResumeEvent = aResumeEvent ;
310   if ( _SuspendSync ) {
311 #if ActionsTrace
312     cdebug << pthread_self() << "/" << ThreadNo() << " pthread_cond " << Name()
313            << " ResumeAction pthread_cond_signal" << endl ;
314 #endif
315     if ( pthread_cond_signal( &_SuspendWait ) ) {
316       perror("ResumeAction pthread_cond_signal ") ;
317     }
318 #if ActionsTrace
319     cdebug << pthread_self() << "/" << ThreadNo() << " pthread_cond " << Name()
320            << " ResumeAction pthread_cond_signaled _SuspendWait " << endl ;
321 #endif
322     RetVal = true ;
323   }
324   else {
325 #if ActionsTrace
326     cdebug << pthread_self() << "/" << ThreadNo() << " pthread_cond " << Name()
327            << " NO ResumeAction pthread_cond_signal" << endl ;
328 #endif
329     if ( pthread_self() == ThreadNo() ) {
330       RetVal = false ; /*/ Ne pas s'attendre soi-meme !...*/
331     }
332     else {
333       _SuspendSync = true ;
334       RetVal = true ; // Il faut tout de meme attendre ci-apres ...
335     }
336   }
337   if ( pthread_mutex_unlock( &_MutexWait ) ) {
338     perror("ResumeAction pthread_mutex_unlock ") ;
339     exit( 0 ) ;
340   }
341
342   if ( RetVal ) {
343     if ( pthread_mutex_lock( &_MutexWait ) ) {
344       perror("ResumeAction pthread_mutex_lock ") ;
345       exit( 0 ) ;
346     }
347     if ( !_ResumeSync ) {
348 #if ActionsTrace
349       cdebug << pthread_self() << "/" << ThreadNo() << " pthread_cond "
350              << Name() << " ResumeAction pthread_cond_wait _ResumeWait " 
351              << Automaton()->StateName( State() ) << endl ;
352 #endif
353       _ResumeSync = true ;
354       if ( pthread_cond_wait( &_ResumeWait , &_MutexWait ) ) {
355         perror("ResumeAction pthread_cond_wait ") ;
356       }
357 #if ActionsTrace
358       cdebug << pthread_self() << "/" << ThreadNo() << " pthread_cond "
359              << Name() << " ResumeAction pthread_cond_waited _ResumeWait"  
360              << Automaton()->StateName( State() ) << endl ;
361 #endif
362       RetVal = true ;
363     }
364     else {
365 #if ActionsTrace
366       cdebug << pthread_self() << "/" << ThreadNo() << " pthread_cond "
367              << Name() << " NO ResumeAction pthread_cond_wait _ResumeWait" 
368              << Automaton()->StateName( State() ) << endl ;
369 #endif
370       RetVal = false ;
371     }
372     _ResumeSync = false ;  
373     if ( pthread_mutex_unlock( &_MutexWait ) ) {
374       perror("ResumeAction pthread_mutex_unlock ") ;
375       exit( 0 ) ;
376     }
377   }
378 #if ActionsTrace
379   cdebug << pthread_self() << "/" << ThreadNo()
380          << "GraphExecutor::InNodeThreads::ResumeAction RetVal " << RetVal << endl ;
381 #endif
382   return RetVal ;
383 }
384
385 bool GraphExecutor::InNode::ReStartAction( GraphExecutor::InNode * aReStartNode ,
386                                            GraphExecutor::NodeEvent anEvent ) {
387   GraphExecutor::InNode * oldReStartNode = _aReStartNode ;
388   _aReStartNode = aReStartNode ;
389   _aReStartEvent = anEvent ;
390   cdebug << pthread_self() << "/" << ThreadNo()
391           << " GraphExecutor::InNodeThreads::ReStartAction from "
392          << Name() << " " << Automaton()->StateName( State() ) << " to "
393          << aReStartNode->ThreadNo() << " " << aReStartNode->Name() << " "
394          << Automaton()->StateName( aReStartNode->State() ) ;
395   if ( oldReStartNode ) {
396     cdebug << " oldReStartNode " << oldReStartNode->Name() << endl ;
397   }
398   else {
399     cdebug << endl ;
400   }
401   return ResumeAction( GraphExecutor::ToReStartEvent ) ;
402 }
403
404 void GraphExecutor::InNode::KilledAction() {
405   if ( pthread_mutex_lock( &_MutexWait ) ) {
406     perror("Killed pthread_mutex_lock ") ;
407     exit( 0 ) ;
408   }
409   if ( !_KillSync ) {
410     cdebug << "pthread_cond " << Name() << " Killed pthread_cond_wait"
411            << endl ;
412     _KillSync = true ;
413     if ( pthread_cond_wait( &_KillWait , &_MutexWait ) ) {
414       perror("Killed pthread_cond_wait ") ;
415     }
416     cdebug << "pthread_cond " << Name() << " Killed pthread_cond_waited"
417            << endl ;
418   }
419   else {
420     cdebug << "pthread_cond " << Name() << " NO Killed pthread_cond_wait"
421            << endl ;
422   }
423   _KillSync = false ;  
424   if ( pthread_mutex_unlock( &_MutexWait ) ) {
425     perror("Killed pthread_mutex_unlock ") ;
426     exit( 0 ) ;
427   }
428 }
429
430 void GraphExecutor::InNode::KillAction() {
431   if ( pthread_mutex_lock( &_MutexWait ) ) {
432     perror("Kill pthread_mutex_lock ") ;
433     exit( 0 ) ;
434   }
435   if ( _KillSync ) {
436     cdebug << "pthread_cond " << Name() << " Kill pthread_cond_signal"
437            << endl ;
438 //    if ( pthread_cond_broadcast( &_KillWait ) ) {
439     if ( pthread_cond_signal( &_KillWait ) ) {
440       perror("Kill pthread_cond_broadcast ") ;
441     }
442     cdebug << "pthread_cond " << Name() << " Kill pthread_cond_signaled"
443            << endl ;
444   }
445   else {
446     cdebug << "pthread_cond " << Name() << " NO Kill pthread_cond_signal"
447            << endl ;
448     _KillSync = true ;  
449   }
450   if ( pthread_mutex_unlock( &_MutexWait ) ) {
451     perror("Kill pthread_mutex_unlock ") ;
452     exit( 0 ) ;
453   }
454 }
455
456 void GraphExecutor::InNode::StoppedAction() {
457   if ( pthread_mutex_lock( &_MutexWait ) ) {
458     perror("Stopped pthread_mutex_lock ") ;
459     exit( 0 ) ;
460   }
461   if ( pthread_cond_wait( &_StopWait , &_MutexWait ) ) {
462     perror("Stopped pthread_cond_wait ") ;
463   }
464   if ( pthread_mutex_unlock( &_MutexWait ) ) {
465     perror("Stopped pthread_mutex_unlock ") ;
466     exit( 0 ) ;
467   }
468 }
469
470 void GraphExecutor::InNode::StopAction() {
471   if ( pthread_mutex_lock( &_MutexWait ) ) {
472     perror("Stop pthread_mutex_lock ") ;
473     exit( 0 ) ;
474   }
475   if ( pthread_cond_broadcast( &_StopWait ) ) {
476     perror("Stop pthread_cond_broadcast ") ;
477   }
478   if ( pthread_mutex_unlock( &_MutexWait ) ) {
479     perror("Stop pthread_mutex_unlock ") ;
480     exit( 0 ) ;
481   }
482 }
483
484 void GraphExecutor::InNode::ThreadStartedAction() {
485   if ( pthread_mutex_lock( &_MutexWait ) ) {
486     perror("ThreadStarted pthread_mutex_lock ") ;
487     exit( 0 ) ;
488   }
489   if ( !_ThreadStartedSync ) {
490 #if ActionsTrace
491     cdebug << pthread_self() << "/" << ThreadNo()
492            << "pthread_cond " << Name() << " ThreadStarted pthread_cond_wait"
493            << endl ;
494 #endif
495     _ThreadStartedSync = true ;
496     if ( pthread_cond_wait( &_ThreadStartedWait , &_MutexWait ) ) {
497       perror("ThreadStarted pthread_cond_wait ") ;
498     }
499 #if ActionsTrace
500     cdebug << pthread_self() << "/" << ThreadNo()
501            << "pthread_cond " << Name() << " ThreadStarted pthread_cond_waited"
502            << endl ;
503 #endif
504   }
505   else {
506 #if ActionsTrace
507     cdebug << pthread_self() << "/" << ThreadNo()
508            << "pthread_cond " << Name() << " NO ThreadStarted pthread_cond_wait"
509            << endl ;
510 #endif
511 //Debug :
512     _ThreadStartedSync = false ;  
513     if ( pthread_cond_signal( &_ThreadStartedWait ) ) {
514       perror("ThreadStart pthread_cond_signal ") ;
515     }
516 //Debug
517 #if ActionsTrace
518     cdebug << pthread_self() << "/" << ThreadNo()
519            << "pthread_cond " << Name() << " NO ThreadStarted pthread_cond_signaled"
520            << endl ;
521 #endif
522   }
523   if ( pthread_mutex_unlock( &_MutexWait ) ) {
524     perror("ThreadStarted pthread_mutex_unlock ") ;
525     exit( 0 ) ;
526   }
527 }
528
529 void GraphExecutor::InNode::ThreadStartAction() {
530   if ( pthread_mutex_lock( &_MutexWait ) ) {
531     perror("ThreadStart pthread_mutex_lock ") ;
532     exit( 0 ) ;
533   }
534   if ( _ThreadStartedSync ) {
535 #if ActionsTrace
536     cdebug << pthread_self() << "/" << ThreadNo()
537            << "pthread_cond " << Name() << " ThreadStart pthread_cond_signal"
538            << endl ;
539 #endif
540     _ThreadStartedSync = false ;  
541     if ( pthread_cond_signal( &_ThreadStartedWait ) ) {
542       perror("ThreadStart pthread_cond_broadcast ") ;
543     }
544 #if ActionsTrace
545     cdebug << pthread_self() << "/" << ThreadNo()
546            << "pthread_cond " << Name() << " ThreadStart pthread_cond_signaled"
547            << endl ;
548 #endif
549   }
550   else {
551 #if ActionsTrace
552     cdebug << pthread_self() << "/" << ThreadNo()
553            << "pthread_cond " << Name() << " NO ThreadStart pthread_cond_signal"
554            << endl ;
555 #endif
556     _ThreadStartedSync = true ;
557 //Debug :
558     if ( pthread_cond_wait( &_ThreadStartedWait , &_MutexWait ) ) {
559       perror("ThreadStarted pthread_cond_wait ") ;
560     }
561 //Debug
562 #if ActionsTrace
563     cdebug << pthread_self() << "/" << ThreadNo()
564            << "pthread_cond " << Name() << " NO ThreadStart pthread_cond_waited"
565            << endl ;
566 #endif
567   }
568   if ( pthread_mutex_unlock( &_MutexWait ) ) {
569     perror("ThreadStart pthread_mutex_unlock ") ;
570     exit( 0 ) ;
571   }
572 }
573
574 int GraphExecutor::InNode::executeAction() {
575   int oldRewindStack = ( _RewindStack > MAXSTACKTHREADSIZE ) ;
576   if ( !CreateNewThread() && oldRewindStack ) {
577 #if ActionsTrace
578     cdebug << pthread_self() << "/" << ThreadNo()
579            << " executeAction start Thread _RewindStack " << _RewindStack << " > "
580            << MAXSTACKTHREADSIZE << " CreateNewThread "
581            << CreateNewThread() << " " << Automaton()->ActionName( _NextAction ) << "("
582            << Name() << ")" << endl;
583 #endif
584     CreateNewThread( true ) ;
585     _OutNode->IncrCreatedThreads() ;
586     ThreadNo( 0 ) ;
587   }
588   if ( CreateNewThread() ) {
589     CreateNewThread( false ) ;
590 //JR 15.04.2005 Debug PAL8624 RetroConception :
591 //    if ( ThreadNo() == 0 ) {
592       _RewindStack = 1 ;
593 #if ActionsTrace
594       cdebug << pthread_self() << "/" << ThreadNo()
595              << " executeAction start Thread _RewindStack " << _RewindStack << " "
596              << Automaton()->ActionName( _NextAction ) << "(" << Name() << ")"
597              << endl;
598 #endif
599       pthread_t T;
600       int pthread_sts = 1 ;
601 //      _OutNode->PushEvent( NULL , GraphExecutor::NewThreadEvent ,
602 //                           GraphExecutor::ExecutingState ) ; 
603       while ( (pthread_sts = pthread_create(&T, NULL, run_function, this )) ) {
604         char * msg = "Cannot pthread_create " ;
605         perror( msg ) ;
606         cdebug << ThreadNo() << " " << msg << " --> sleep(5)" << endl ;
607         cdebug << ThreadNo() << " PTHREAD_THREADS_MAX : "
608                << PTHREAD_THREADS_MAX << " pthread_create status : " ;
609         if ( pthread_sts == EAGAIN ) {
610           cdebug << "EAGAIN(" << pthread_sts << ")" << endl ;
611           cdebug << _OutNode->CreatedThreads() << " was created (and exited)" << endl ;
612           cdebug << "It seems to me that with gdb we are limited to 256 threads" << endl ;
613         }
614         else {
615           cdebug << pthread_sts << endl ;
616         }
617         string smsg = msg ;
618         delete [] msg ;
619         pthread_exit( msg ) ;
620       }
621 #if ActionsTrace
622       cdebug << pthread_self() << "/" << ThreadNo() << " " << Name()
623              << " executeAction has created thread " << T << endl ;
624 #endif
625       ThreadStartedAction() ;
626 #if ActionsTrace
627       cdebug << pthread_self() << "/" << ThreadNo() << " " << Name()
628              << "executeAction the thread " << T << " has called NewThread and will call ExecuteAction for node "
629              << Name() << endl ;
630 #endif
631     }
632 //JR 15.04.2005 Debug PAL8624 RetroConception :
633 #if 0
634     else {
635 #if ActionsTrace
636       cdebug << pthread_self() << "/" << ThreadNo()
637              << " executeAction restart Thread _RewindStack " << _RewindStack << " "
638              << Automaton()->StateName( State() ) << " "
639              << Automaton()->ActionName( _NextAction ) << "(" << Name()
640              << ") ReStartAction ==>" << endl;
641 #endif
642       State( GraphExecutor::SuspendedSuccessedState ) ;
643       if ( !ReStartAction( this , GraphExecutor::ReStartEvent ) ) {
644         cdebug << pthread_self() << "/" << ThreadNo()
645                << " executeAction STATE & CALLED "
646                << Automaton()->ActionName( _NextAction ) << "(" << Name()
647                << ") ERROR-DEBUG " << endl;
648       }
649       else {
650 #if ActionsTrace
651         cdebug << pthread_self() << "/" << ThreadNo() << " executeAction NO CALL "
652                << Automaton()->ActionName( _NextAction ) << "(" << Name()
653                << ")" << endl;
654 #endif
655       }
656     }
657   }
658 #endif
659   else {
660     if ( _CurrentEvent == ExecuteEvent ) {
661       _RewindStack += 1 ;
662     }
663 #if ActionsTrace
664     cdebug << pthread_self() << "/" << ThreadNo() << " executeAction call "
665            << Automaton()->ActionName( _NextAction ) << "(" << Name() << ") _RewindStack " << _RewindStack
666            << endl;
667 #endif
668     return ExecuteAction() ;
669   }
670   return 1 ;
671 }
672
673 void GraphExecutor::InNode::coutbegin() {
674 #if ActionsTrace
675   cdebug << pthread_self() << "/" << ThreadNo() << " run_function begin"
676          << " " << Name() << " " << Automaton()->StateName( State() ) << endl ;
677 #endif
678 }
679 void GraphExecutor::InNode::coutexit() {
680 #if ActionsTrace
681   cdebug << pthread_self() << "/" << ThreadNo() << " run_function pthread_exit _RewindStack " << _RewindStack
682          << " " << Name() << " " << Automaton()->StateName( State() ) << endl ;
683 #endif
684 }
685 void * run_function(void *p) {
686   GraphExecutor::InNode *aNode = (GraphExecutor::InNode *) p;
687   aNode->coutbegin() ;
688   aNode->NewThread( pthread_self() ) ;
689   if ( pthread_setcanceltype( PTHREAD_CANCEL_ASYNCHRONOUS , NULL ) ) {
690     perror("pthread_setcanceltype ") ;
691     exit(0) ;
692   }
693   if ( pthread_setcancelstate( PTHREAD_CANCEL_ENABLE , NULL ) ) {
694     perror("pthread_setcancelstate ") ;
695     exit(0) ;
696   }
697   aNode->ThreadStartAction() ;
698 //  cout << "run_function " << aNode->Name() << "->ExecuteAction() Coupled : " << aNode->CoupledNode()
699 //       << endl ;
700   aNode->ExecuteAction() ;
701   char * msg = new char[40] ;
702   sprintf( msg , "%d" , (int ) aNode->ThreadNo() ) ;
703   strcat( msg , " thread exit" ) ;
704   aNode->coutexit() ;
705   aNode->ExitThread() ;
706   string smsg = msg ;
707   delete [] msg ;
708   pthread_exit( (void * ) smsg.c_str() ) ;
709   return msg ;
710 }
711
712 int GraphExecutor::InNode::ExecuteAction() {
713   int sts ;
714
715 #if ActionsTrace
716   const char * nextactionname = Automaton()->ActionName( _NextAction ) ;
717   const char * statename = Automaton()->StateName( State() ) ;
718   const char * nextstatename = Automaton()->StateName( _NextState ) ;
719   cdebug_in << pthread_self() << "/" << ThreadNo() << " " << Name() << " --> ExecuteAction "
720             << nextactionname << " "  << statename << " NextState "
721             << nextstatename << endl ;
722 #endif
723
724   State( _NextState ) ;
725   switch ( _NextAction ) {
726   case GraphExecutor::ErrorAction : {
727     sts = ErrorAction() ;
728     break ;
729   }
730   case GraphExecutor::VoidAction : {
731     sts = VoidAction() ;
732     break ;
733   }
734   case GraphExecutor::DataWaiting_SomeDataReadyAction : {
735     sts = DataWaiting_SomeDataReadyAction() ;
736     break ;
737   }
738   case GraphExecutor::DataUndef_NotAllDataReadyAction : {
739     sts = DataUndef_NotAllDataReadyAction() ;
740     break ;
741   }
742   case GraphExecutor::DataUndef_AllDataReadyAction : {
743     sts = DataUndef_AllDataReadyAction() ;
744     break ;
745   }
746   case GraphExecutor::DataReady_SuspendAction : {
747     sts = DataReady_SuspendAction() ;
748     break ;
749   }
750   case GraphExecutor::SuspendedReady_ResumeAction : {
751     sts = SuspendedReady_ResumeAction() ;
752     break ;
753   }
754   case GraphExecutor::DataReady_KillAction : {
755     sts = DataReady_KillAction() ;
756     break ;
757   }
758   case GraphExecutor::DataReady_StopAction : {
759     sts = DataReady_StopAction() ;
760     break ;
761   }
762   case GraphExecutor::DataReady_ExecuteAction : {
763     sts = DataReady_ExecuteAction() ;
764     break ;
765   }
766   case GraphExecutor::Executing_SuspendAction : {
767     sts = Executing_SuspendAction() ;
768     break ;
769   }
770   case GraphExecutor::SuspendedExecuting_ResumeAction : {
771     sts = SuspendedExecuting_ResumeAction() ;
772     break ;
773   }
774   case GraphExecutor::Executing_KillAction : {
775     sts = Executing_KillAction() ;
776     break ;
777   }
778   case GraphExecutor::Executing_StopAction : {
779     sts = Executing_StopAction() ;
780     break ;
781   }
782   case GraphExecutor::Executing_SuccessAction : {
783     sts = Executing_SuccessAction() ;
784     break ;
785   }
786   case GraphExecutor::Executing_ErrorAction : {
787     sts = Executing_ErrorAction() ;
788     break ;
789   }
790   case GraphExecutor::Successed_SuccessAction : {
791     sts = Successed_SuccessAction() ;
792     break ;
793   }
794   case GraphExecutor::Errored_ErrorAction : {
795     sts = Errored_ErrorAction() ;
796     break ;
797   }
798   case GraphExecutor::Successed_SuspendAction : {
799     sts = Successed_SuspendAction() ;
800     break ;
801   }
802   case GraphExecutor::Errored_SuspendAction : {
803     sts = Errored_SuspendAction() ;
804     break ;
805   }
806   case GraphExecutor::SuspendedSuccessed_ResumeAction : {
807     sts = SuspendedSuccessed_ResumeAction() ;
808     break ;
809   }
810   case GraphExecutor::SuspendedErrored_ResumeAction : {
811     sts = SuspendedErrored_ResumeAction() ;
812     break ;
813   }
814   case GraphExecutor::Successed_KillAction : {
815     sts = Successed_KillAction() ;
816     break ;
817   }
818   case GraphExecutor::Errored_KillAction : {
819     sts = Errored_KillAction() ;
820     break ;
821   }
822   case GraphExecutor::Successed_StopAction : {
823     sts = Successed_StopAction() ;
824     break ;
825   }
826   case GraphExecutor::Errored_StopAction : {
827     sts = Errored_StopAction() ;
828     break ;
829   }
830   case GraphExecutor::SuspendedSuccessed_ReStartAction : {
831     sts = SuspendedSuccessed_ReStartAction() ;
832     break ;
833   }
834   case GraphExecutor::SuspendedErrored_ReStartAction : {
835     sts = SuspendedErrored_ReStartAction() ;
836     break ;
837   }
838   case GraphExecutor::SuspendedSuccessed_ReStartAndSuspendAction : {
839     sts = SuspendedSuccessed_ReStartAndSuspendAction() ;
840     break ;
841   }
842   case GraphExecutor::SuspendedErrored_ReStartAndSuspendAction : {
843     sts = SuspendedErrored_ReStartAndSuspendAction() ;
844     break ;
845   }
846   default : {
847     cdebug << pthread_self() << "/" << ThreadNo()
848            << " GraphExecutor::InNodeThreads::SendEvent Error Undefined Action : "
849            << _NextAction << endl ;
850     return 0 ;
851   }
852   }
853 #if ActionsTrace
854   cdebug_out << pthread_self() << "/" << ThreadNo() << "<-- ExecuteAction "
855              << nextactionname << endl ;
856 #endif
857   return sts ;
858 }
859
860 int GraphExecutor::InNode::ErrorAction() {
861   cdebug << pthread_self() << "/" << ThreadNo() << " Automaton ErrorAction Node "
862          << Name() << endl;
863   return 0;
864 }
865
866 int GraphExecutor::InNode::VoidAction() {
867   cdebug << pthread_self() << "/" << ThreadNo() << " VoidAction "  << Name() << endl;
868   return 1;
869 }
870
871 #define SomeDataReadyActionTrace 1
872 int GraphExecutor::InNode::DataWaiting_SomeDataReadyAction() {
873 #if SomeDataReadyActionTrace
874   cdebug_in << pthread_self() << "/" << ThreadNo() << " " << Name()
875             << " DataWaiting_SomeDataReadyAction from " << DataFromNode() << endl;
876 #endif
877   unsigned int k;
878   int InReady = 0 ;
879   int res = 1;
880   bool LoopBeginning = false ;
881   bool LoopFinished = false ;
882   bool SwitchFinished = false ;
883   bool SwitchDefault = false ;
884   bool DoAllDataReadyIf = true ;
885
886   if ( IsLoopNode() ) {
887     GraphBase::OutPort * anOutLoopPort = GetChangeNodeInLoop()->GetOutPort() ; // DoLoop Port
888     if ( anOutLoopPort && anOutLoopPort->BoolValue() ) {
889       LoopBeginning = true ; // Beginning of Loop
890     }
891   }
892   else if ( IsEndLoopNode() ) {
893     GraphBase::OutPort * anOutLoopPort = GetChangeNodeInLoop()->GetOutPort() ; // DoLoop Port
894     if ( anOutLoopPort && !anOutLoopPort->BoolValue() ) {
895       LoopFinished = true ; // End of Loop
896     }
897   }
898   else if ( IsEndSwitchNode() ) {
899     if ( strcmp( GOTONode()->CoupledNode()->Name() , DataFromNode() ) ) {
900       GraphBase::OutPort * anOutGateSwitchPort = GetChangeNodeInGate()->GetOutPort() ; // Default Port
901 //JR 09.02.2005 : SomeDataReady is NOT from the SwitchNode
902       if ( anOutGateSwitchPort && !anOutGateSwitchPort->BoolValue() ) {
903 //JR 09.02.2005 : the OutPort of the SwitchNode connected to the default port is closed ===>
904 // Here after we consider that that DefaultPort is Ready (even if it's value is false)
905         SwitchFinished = true ; // End of Switch
906       }
907     }
908     else {
909 //JR 20.04.2005 : SomeDataReady is FROM the SwitchNode
910 //PAL8518
911 //JR 16.02.2005 Debug : Change InPorts of EndSwitchNode that have the same name as an OutPort of
912 // the SwitchNode even if it is the DefaultPort : GraphSwitchCheckDefault1.xml
913       GraphBase::OutPort * anOutGateSwitchPort = GetChangeNodeInGate()->GetOutPort() ; // Default P
914 //JR 20.04.2005 : SomeDataReady is from the SwitchNode and Default is activated :
915       if ( anOutGateSwitchPort ) {
916         if ( anOutGateSwitchPort->BoolValue() ) {
917           SwitchDefault = true ;
918         }
919 //JR 20.04.2005 : SomeDataReady is from the SwitchNode and Default is NOT activated :
920 //                a SwitchBranch should be activated
921         else {
922           DoAllDataReadyIf = false ;
923         }
924 #if SomeDataReadyActionTrace
925         cdebug << pthread_self() << "/" << ThreadNo() << " " << Name()
926                << " activated from CoupledNode " << GOTONode()->CoupledNode()->Name() << " "
927                << anOutGateSwitchPort->NodeName() << "( " << anOutGateSwitchPort->PortName()
928                << " ) to InDefault " ;
929 #ifdef _DEBUG_
930         if ( GraphBase::Base::_prof_debug ) {
931           anOutGateSwitchPort->StringValue( *GraphBase::Base::_fdebug ) ;
932         }
933 #endif
934         cdebug << endl ;
935 #endif
936       }
937     }
938   }
939
940 #if SomeDataReadyActionTrace
941   cdebug << pthread_self() << "/" << ThreadNo() << " " << Name() << " LoopFinished " << LoopFinished
942          << " LoopBeginning " << LoopBeginning << " SwitchFinished " << SwitchFinished
943          << " SwitchDefault " << SwitchDefault << " DoAllDataReadyIf " << DoAllDataReadyIf << endl ;
944 #endif
945   for ( k = 0 ; k < (unsigned int ) GetNodeInPortsSize() ; k++ ) {
946     GraphBase::InPort * anInPort = GetChangeNodeInPort(k) ;
947     GraphBase::OutPort * anOutPort ;
948     if ( SwitchDefault && !anInPort->IsDataStream() ) {
949 //Set the field OutPort of that InPort of the EndSwitchNode to the corresponding OutPort
950 // of the SwitchNode
951       anOutPort = CoupledNode()->GetChangeOutPort( anInPort->PortName() ) ;
952 #if SomeDataReadyActionTrace
953       cdebug << pthread_self() << "/" << ThreadNo() << " " << Name() << " InPort "
954              << anInPort->PortName() << " change of OutPort from "
955              << anInPort->GetOutPort()->NodeName() << "( " << anInPort->GetOutPort()->PortName()
956              << " ) to " << anOutPort->NodeName() << "( " << anOutPort->PortName() << " )"
957              << endl ;
958 #endif
959       anInPort->ChangeOutPort( anOutPort ) ;
960     }
961     else {
962       anOutPort = anInPort->GetOutPort() ;
963     }
964 #if SomeDataReadyActionTrace
965     cdebug << pthread_self() << "/" << ThreadNo() << " " << Name() << " InPort "
966            << anInPort->PortName() << " " << anInPort->PortState() << " "
967            << anInPort->PortStatus() << " " << anInPort->Kind()  ;
968     if ( anOutPort ) {
969       cdebug << " from OutPort " << anOutPort->NodeName() << "( " << anOutPort->PortName()
970              << " )" ;
971     }
972     else {
973       cdebug << " without OutPort " ;
974     }
975     cdebug<< endl ;
976 #endif
977     if ( anInPort->IsGate() && anOutPort == NULL ) {
978       InReady += 1 ;
979       anInPort->PortState( SUPERV::ReadyState ) ;
980 #if SomeDataReadyActionTrace
981       cdebug << pthread_self() << "/" << ThreadNo() << " " << Name() << " "
982              << anInPort->PortName() << " ControlPort inactive." << endl ;
983 #endif
984     }
985
986 // That InPort get its value from an other node : the node of anOutPort linked to that anInPort is
987 // different from the sender of SomeDataReady (DataFromNode)
988     else if ( strcmp( DataFromNode() , anOutPort->NodeName() ) ) {
989       if ( anInPort->PortState() == SUPERV::ReadyState ) {
990         InReady += 1 ;
991 #if SomeDataReadyActionTrace
992         cdebug << pthread_self() << "/" << ThreadNo() << " " << Name() << " "
993                << anInPort->PortName() << " " << anInPort->PortState() << " Was Done from Node "
994                << anOutPort->NodeName() << "( " << anOutPort->PortName() << " , "
995                << anOutPort->PortState() << " ) PortDone " << anOutPort->PortDone() << " " ;
996 #ifdef _DEBUG_
997         if ( GraphBase::Base::_prof_debug ) {
998           anOutPort->StringValue( *GraphBase::Base::_fdebug ) ;
999         }
1000 #endif
1001         cdebug << endl ;
1002 #endif
1003       }
1004       else if ( IsLoopNode() && anInPort->IsDataConnected() ) {
1005         anInPort->PortState( SUPERV::ReadyState ) ;
1006         InReady += 1 ;
1007 #if SomeDataReadyActionTrace
1008         cdebug << pthread_self() << "/" << ThreadNo() << " " << Name() << " "
1009                << anInPort->PortName() << " Was Done from Node "
1010                << anOutPort->NodeName() << "( " << anOutPort->PortName()
1011                << ") LoopBeginning " << LoopBeginning << " " ;
1012 #ifdef _DEBUG_
1013         if ( GraphBase::Base::_prof_debug ) {
1014           anOutPort->StringValue( *GraphBase::Base::_fdebug ) ;
1015         }
1016 #endif
1017         cdebug << endl ;
1018 #endif
1019       }
1020       else if ( LoopFinished ) {
1021         anInPort->PortState( SUPERV::ReadyState ) ;
1022         InReady += 1 ;
1023 #if SomeDataReadyActionTrace
1024         cdebug << pthread_self() << "/" << ThreadNo() << " " << Name() << " "
1025                << anInPort->PortName() << " Was Done from Node "
1026                << anOutPort->NodeName() << "( " << anOutPort->PortName()
1027                << ") LoopFinished " << LoopFinished << " " ;
1028 #ifdef _DEBUG_
1029         if ( GraphBase::Base::_prof_debug ) {
1030           anOutPort->StringValue( *GraphBase::Base::_fdebug ) ;
1031         }
1032 #endif
1033         cdebug << endl ;
1034 #endif
1035       }
1036       else if ( anInPort->IsGate() && SwitchFinished ) {
1037         anInPort->PortState( SUPERV::ReadyState ) ;
1038         InReady += 1 ;
1039 #if SomeDataReadyActionTrace
1040         cdebug << pthread_self() << "/" << ThreadNo() << " " << Name() << " "
1041                << anInPort->PortName() << " Was Done from Node "
1042                << anOutPort->NodeName() << "( " << anOutPort->PortName()
1043                << ") SwitchFinished " << SwitchFinished << " " ;
1044 #ifdef _DEBUG_
1045         if ( GraphBase::Base::_prof_debug ) {
1046           anOutPort->StringValue( *GraphBase::Base::_fdebug ) ;
1047         }
1048 #endif
1049         cdebug << endl ;
1050 #endif
1051       }
1052       else if ( anInPort->IsGate() &&
1053                 _OutNode->Graph()->GetGraphNode( anOutPort->NodeName() )->IsGOTONode() ) {
1054 // GateOutPort of GOTONodes are always opened
1055         anInPort->PortState( SUPERV::ReadyState ) ;
1056         InReady += 1 ;
1057 //JR 21.02.2005 Debug Memory leak :        CORBA::Any * anAny = new CORBA::Any() ;
1058         CORBA::Any anAny = CORBA::Any() ;
1059 //JR 21.02.2005 Debug Memory leak :        *anAny <<= (long ) 1 ;
1060         anAny <<= (long ) 1 ;
1061         _OutNode->Graph()->GetGraphNode( anOutPort->NodeName() )->GetChangeNodeOutGate()->SetValue( anAny ) ;
1062 #if SomeDataReadyActionTrace
1063         cdebug << pthread_self() << "/" << ThreadNo() << " " << Name() << " "
1064                << anInPort->PortName() << " Was Done from Node "
1065                << anOutPort->NodeName() << "( " << anOutPort->PortName()
1066                << ") GOTONode " ;
1067 #ifdef _DEBUG_
1068         if ( GraphBase::Base::_prof_debug ) {
1069           anOutPort->StringValue( *GraphBase::Base::_fdebug ) ;
1070         }
1071 #endif
1072         cdebug << endl ;
1073 #endif
1074       }
1075       else {
1076 #if SomeDataReadyActionTrace
1077         cdebug << pthread_self() << "/" << ThreadNo() << " " << Name() << " "
1078                << " " << Automaton()->StateName( State() ) << " LoopBeginning "
1079                << LoopBeginning << " " << anInPort->PortName() << " DataConnected "
1080                << anInPort->IsDataConnected() << " Was NOT Done from Node "
1081                << anOutPort->NodeName() << "( " << anOutPort->PortName() << " , "
1082                << anOutPort->PortState() << " , PortDone " << anOutPort->PortDone() << ") "
1083                << endl ;
1084 #endif
1085       }
1086     }
1087
1088 // That InPort get its value from the sending node (DataFromNode)
1089     else if ( anInPort->IsGate() ) {
1090 //JR 30.03.2005      const CORBA::Any * theValue = anOutPort->Value() ;
1091       const CORBA::Any theValue = anOutPort->Value() ;
1092       long GateOpened ;
1093 //JR 30.03.2005      (*theValue) >>= GateOpened ;
1094       theValue >>= GateOpened ;
1095       if ( GateOpened != 0 ) {
1096         InReady += 1 ;
1097         anInPort->PortState( SUPERV::ReadyState ) ;
1098 #if SomeDataReadyActionTrace
1099         cdebug << pthread_self() << "/" << ThreadNo() << " " << Name() << " "
1100                << anInPort->PortName() << " Gate is Opened from Node "
1101                << anOutPort->NodeName() << "( " << anOutPort->PortName()
1102                << ") " ;
1103 #ifdef _DEBUG_
1104         if ( GraphBase::Base::_prof_debug ) {
1105           anOutPort->StringValue( *GraphBase::Base::_fdebug ) ;
1106         }
1107 #endif
1108         cdebug << endl ;
1109 #endif
1110       }
1111       else if ( LoopFinished ) {
1112         anInPort->PortState( SUPERV::ReadyState ) ;
1113 #if SomeDataReadyActionTrace
1114         cdebug << pthread_self() << "/" << ThreadNo() << " " << Name() << " "
1115                << anInPort->PortName() << " GATE IS CLOSED from Node "
1116                << anOutPort->NodeName() << "( " << anOutPort->PortName()
1117                << ") LoopFinished" ;
1118 #ifdef _DEBUG_
1119         if ( GraphBase::Base::_prof_debug ) {
1120           anOutPort->StringValue( *GraphBase::Base::_fdebug ) ;
1121         }
1122 #endif
1123         cdebug << endl ;
1124 #endif
1125       }
1126       else {
1127 #if SomeDataReadyActionTrace
1128         cdebug << pthread_self() << "/" << ThreadNo() << " " << Name() << " "
1129                << anInPort->PortName() << " GATE IS CLOSED from Node "
1130                << anOutPort->NodeName() << "( " << anOutPort->PortName()
1131                << ") " ;
1132 #ifdef _DEBUG_
1133         if ( GraphBase::Base::_prof_debug ) {
1134           anOutPort->StringValue( *GraphBase::Base::_fdebug ) ;
1135         }
1136 #endif
1137         cdebug << endl ;
1138 #endif
1139       }
1140     }
1141     else if ( anOutPort->PortDone() ) {
1142 #if SomeDataReadyActionTrace
1143       cdebug << pthread_self() << "/" << ThreadNo() << " " << Name() << " InPort "
1144              << anInPort->PortName() << " " << anInPort->PortStatus() << " "
1145              << Automaton()->StateName( anInPort->PortState() ) << " is Done from Node "
1146              << anOutPort->NodeName() << "( " << anOutPort->PortName() << ") "
1147              << anOutPort->PortStatus() << " --> ReadyState " ;
1148 #ifdef _DEBUG_
1149       if ( GraphBase::Base::_prof_debug ) {
1150         anOutPort->StringValue( *GraphBase::Base::_fdebug ) ;
1151       }
1152 #endif
1153       cdebug << endl ;
1154 #endif
1155       InReady += 1 ;
1156       anInPort->PortState( SUPERV::ReadyState ) ;
1157 // MacroNode : give immediately the value to the corresponding graph
1158       if ( IsMacroNode() ) {
1159         GraphExecutor::DataFlow * aMacroGraph = GraphMacroNode()->CoupledNode()->GraphEditor()->Executor() ;
1160         cdebug << "SomeDataReadyAction MacroNode " << aMacroGraph->Name() << " --> InputOfAny "
1161                << InReady << "/" << GetNodeInPortsSize() << " InPorts are Ready ( "
1162                << anInPort->PortName() << " ) ===> InputOfAny" << endl ;
1163 //        GraphMacroNode()->MacroObject()->InputOfAny( anInPort->PortName() , *anOutPort->Value() ) ;
1164 //JR 30.03.2005        aMacroGraph->InputOfAny( anInPort->PortName() , *anOutPort->Value() ) ;
1165         aMacroGraph->InputOfAny( anInPort->PortName() , anOutPort->Value() ) ;
1166       }
1167     }
1168     else {
1169 #if SomeDataReadyActionTrace
1170       cdebug << pthread_self() << "/" << ThreadNo() << " Node " << Name() << "( "
1171              << anInPort->PortName() << ") " << anInPort->PortStatus()
1172              << " is NOT Done from Node "
1173              << anOutPort->NodeName() << "( " << anOutPort->PortName() << ") "
1174              << anOutPort->PortStatus() << " " << anOutPort->PortDone() << endl ;
1175 #endif
1176     }
1177   }
1178
1179   if ( InReady == GetNodeInPortsSize() && DoAllDataReadyIf ) { // All Flags != 0 :
1180 //JR 15.04.2005 Debug PAL8624 RetroConception :
1181 //    res = SendEvent( GraphExecutor::AllDataReadyEvent ); // ==> Ready to execute
1182 #if SomeDataReadyActionTrace
1183     cdebug << pthread_self() << "/" << ThreadNo() << " Node " << Name() << " HasAllDataReady"
1184            << endl ;
1185 #endif
1186     HasAllDataReady( true ) ; // ==> Ready to execute
1187     res = 1 ;
1188   }
1189   else { // At least one Flag == 0 :
1190     HasAllDataReady( false ) ;
1191     res = SendEvent( GraphExecutor::NotAllDataReadyEvent );
1192   }
1193
1194 #if SomeDataReadyActionTrace
1195   cdebug_out << pthread_self() << "/" << ThreadNo() << Name()
1196              << " DataWaiting_SomeDataReadyAction " << endl;
1197 #endif
1198   return res ;
1199
1200 }
1201
1202 #define TraceDataReadyAction 1
1203 int GraphExecutor::InNode::DataUndef_NotAllDataReadyAction() {
1204 //JR 15.04.2005 Debug PAL8624 RetroConception :
1205 //  CreateNewThreadIf( false ) ;
1206 #if TraceDataReadyAction
1207   cdebug << pthread_self() << " for " << ThreadNo()
1208          << " DataUndef_NotAllDataReadyAction " << Name() << endl;
1209 #endif
1210   return 1;
1211 }
1212
1213 int GraphExecutor::InNode::DataUndef_AllDataReadyAction() {
1214 #if TraceDataReadyAction
1215   cdebug << pthread_self() << "/" << ThreadNo()
1216          << " --> DataUndef_AllDataReadyAction " << Name() << endl ;
1217 //         << " CreateNewThreadIf " << CreateNewThreadIf() << " IsLockedDataWait "
1218 //         << IsLockedDataWait() ;
1219 #endif
1220 //JR 15.04.2005 Debug PAL8624 RetroConception :
1221   if ( !CreateNewThread() ) {
1222 #if TraceDataReadyAction
1223     cdebug << "Thread " << ThreadNo() << " --> " << pthread_self() << endl ;
1224 #endif
1225     ThreadNo( pthread_self() ) ;
1226   }
1227   else {
1228     _OutNode->IncrCreatedThreads() ;
1229   }
1230   _OutNode->PushEvent( this , GraphExecutor::AllDataReadyEvent ,
1231                        GraphExecutor::DataReadyState ) ; 
1232   ReadyAction() ;
1233   SUPERV::ControlState aControl = ControlState() ;
1234   switch ( aControl ) {
1235   case SUPERV::VoidState : {
1236     SendEvent( GraphExecutor::ExecuteEvent ) ;
1237     break ;
1238   }
1239   case SUPERV::ToSuspendState : {
1240     SendEvent( GraphExecutor::SuspendEvent ) ;
1241     break ;
1242   }
1243   case SUPERV::ToSuspendStartState : {
1244     SendEvent( GraphExecutor::SuspendEvent ) ;
1245     break ;
1246   }
1247   case SUPERV::ToSuspendDoneState : {
1248     SendEvent( GraphExecutor::ExecuteEvent ) ;
1249     break ;
1250   }
1251   case SUPERV::ToKillState : {
1252     SendEvent( GraphExecutor::KillEvent ) ;
1253     break ;
1254   }
1255   case SUPERV::ToKillDoneState : {
1256     SendEvent( GraphExecutor::ExecuteEvent ) ;
1257     break ;
1258   }
1259   case SUPERV::ToStopState : {
1260     SendEvent( GraphExecutor::StopEvent ) ;
1261     break ;
1262   }
1263   default : {
1264     cdebug << ThreadNo()
1265            << " GraphExecutor::InNodeThreads::DataUndef_AllDataReadyAction Error Undefined Control : "
1266            << aControl << endl ;
1267     return 0;
1268   }
1269   }
1270 #if TraceDataReadyAction
1271   cdebug << pthread_self() << "/" << ThreadNo()
1272          << " <-- DataUndef_AllDataReadyAction " << Name() << endl;
1273 #endif
1274   return 1;
1275 }
1276
1277 int GraphExecutor::InNode::DataReady_SuspendAction() {
1278   cdebug << pthread_self() << "/" << ThreadNo()
1279          << "DataReady_SuspendAction --> Suspend " << Name()
1280          << " Threads " << _OutNode->Threads() << " SuspendedThreads "
1281          << _OutNode->SuspendedThreads() << endl;
1282   _OutNode->PushEvent( this , GraphExecutor::SuspendedReadyEvent ,
1283                        GraphExecutor::SuspendedReadyState ) ;
1284   GraphExecutor::InNode * aReStartNode = SuspendAction() ;
1285   cdebug << pthread_self() << "/" << ThreadNo()
1286          << "DataReady_SuspendAction Resumed " << Name() << endl;
1287   if ( aReStartNode ) {
1288     _aReStartNode = NULL ;
1289     aReStartNode->SendEvent( _aReStartEvent ) ;
1290   }
1291   else {
1292     SendEvent( GraphExecutor::ExecuteEvent ) ;
1293   }
1294   return 1 ;
1295 }
1296
1297 int GraphExecutor::InNode::SuspendedReady_ResumeAction() {
1298   cdebug << pthread_self() << "/" << ThreadNo() << "SuspendedReady_ResumeAction "
1299          << Name() << endl;
1300 //  ResumeAction() ;
1301   _OutNode->PushEvent( this , GraphExecutor::ResumedReadyEvent ,
1302                        GraphExecutor::ResumedReadyState ) ; 
1303   return 1 ;
1304 }
1305
1306 int GraphExecutor::InNode::DataReady_KillAction() {
1307   _OutNode->PushEvent( this , GraphExecutor::KilledReadyEvent ,
1308                        GraphExecutor::KilledReadyState ) ;
1309   KillAction() ;
1310   cdebug << pthread_self() << "/" << ThreadNo() << "DataReady_KillAction " << Name()
1311          << " will pthread_exit()" << endl;
1312   return 1 ;
1313 }
1314
1315 int GraphExecutor::InNode::DataReady_StopAction() {
1316   _OutNode->PushEvent( this , GraphExecutor::StoppedReadyEvent ,
1317                        GraphExecutor::StoppedReadyState ) ; 
1318   StopAction() ;
1319   cdebug << pthread_self() << "/" << ThreadNo() << "DataReady_StopAction " << Name()
1320          << " will pthread_exit()" << endl;
1321   return 1 ;
1322 }
1323
1324 #include <CORBA.h>
1325
1326 #define TraceDataReady_ExecuteAction 1
1327 int GraphExecutor::InNode::DataReady_ExecuteAction() {
1328
1329 #if TraceDataReady_ExecuteAction
1330   cdebug << pthread_self() << "/" << ThreadNo() << " --> DataReady_ExecuteAction "
1331          << Name() << endl;
1332 #endif
1333   _OutNode->PushEvent( this , GraphExecutor::ExecuteEvent ,
1334                        GraphExecutor::ExecutingState ) ; 
1335
1336   RunningAction() ;
1337
1338   bool Err = false ;
1339
1340   SUPERV::GraphState PortState = SUPERV::ReadyState ;
1341   GraphExecutor::AutomatonState NewState = GraphExecutor::DataUndefState ;
1342   GraphExecutor::NodeEvent NewEvent = GraphExecutor::UndefinedEvent ;
1343
1344   int nInParams ;
1345   ServicesAnyData * InParametersList ;
1346   int nOutParams ;
1347   ServicesAnyData * OutParametersList ;
1348
1349   nInParams = GetNodeInPortsSize()  ;
1350   InParametersList = new ServicesAnyData[nInParams];
1351   InParametersSet( Err , nInParams , InParametersList ) ;
1352
1353   nOutParams = GetNodeOutPortsSize() ;
1354   OutParametersList = new ServicesAnyData[nOutParams];
1355   InOutParametersSet( nOutParams , OutParametersList ) ;
1356
1357   if ( !IsMacroNode() ) {
1358
1359     Engines::Container_var myContainer ;
1360     Engines::Component_var myObjComponent ;
1361     if ( !IsFactoryNode() ) {
1362 #if TraceDataReady_ExecuteAction
1363       cdebug << ThreadNo() << "No Component : NO StartComponent & No Ping" << endl ;
1364 #endif
1365       if ( IsComputingNode() ) {
1366         ObjInterface( true ) ;
1367         CORBA::Object_ptr obj ;
1368         InParametersList[0].Value >>= obj ;
1369         CORBA::Object_var objvar = CORBA::Object_var( obj ) ;
1370         myObjComponent = Engines::Component::_narrow( objvar ) ;
1371       }
1372       else {
1373       }
1374     }
1375     else if ( CORBA::is_nil( Component() ) ) {
1376 //      ostringstream astr ;
1377 //      astr << "Graph " << _OutNode->Name() << " Node " << Name()
1378 //           << " : load of component " << ComponentName() << " in container "
1379 //           << Computer() ;
1380 //      _OutNode->Graph()->ObjImpl()->sendMessage( NOTIF_STEP, astr.str().c_str() ) ;
1381       Err = !_OutNode->Graph()->StartComponent( ThreadNo() , Computer() ,
1382 //JR 17.02.2005 Memory Leak                                                my_strdup( ComponentName() ) ,
1383                                                 ComponentName() ,
1384                                                 myContainer , myObjComponent ) ;
1385       ObjInterface( false ) ;
1386       SetContainer( myContainer ) ;
1387       SetComponent( myObjComponent ) ;
1388     }
1389     else {
1390       myContainer = Container() ;
1391       myObjComponent = Component() ;
1392 #if TraceDataReady_ExecuteAction
1393       cdebug << ThreadNo() << "Component known : NO StartComponent & Ping"
1394              << endl ;
1395 #endif
1396       try {
1397         myObjComponent->ping() ;
1398       }
1399       catch( ... ) {
1400         cdebug << "ping() catched" << endl ;
1401         Err = true ;
1402       }
1403     }
1404
1405     if ( Err || ControlState() == SUPERV::ToKillState ||
1406                 ControlState() == SUPERV::ToKillDoneState ||
1407                 ControlState() == SUPERV::ToStopState ) {
1408 #if TraceDataReady_ExecuteAction
1409       cdebug << ThreadNo() << "StartComponent Error or ToKillState" << endl ;
1410 //      MESSAGE(pthread_self() << "Executor::InNode::DataReady_ExecuteAction of " << Name()
1411 //              << " ControlState " << Automaton()->ControlStateName( ControlState() )
1412 //              << " BEFORE execution ThreadNo " << ThreadNo() ) ;
1413 #endif
1414       Err = true ;
1415     }
1416     else {
1417       if ( ControlState() == SUPERV::ToSuspendState ) {
1418 #if TraceDataReady_ExecuteAction
1419         cdebug << ThreadNo() << "ToSuspendState before running." << endl ;
1420         MESSAGE(ThreadNo() << "ToSuspendState before running.") ;
1421 #endif
1422       }
1423       if ( !Err ) {
1424 //        ostringstream astr ;
1425 //        astr << "Graph " << _OutNode->Name() << " Run of Node " << Name() ;
1426 //        _OutNode->Graph()->ObjImpl()->sendMessage( NOTIF_STEP, astr.str().c_str() ) ;
1427 #if TraceDataReady_ExecuteAction
1428         int i;
1429         cdebug << ThreadNo() << " Run( '" << ServiceName() << "'" ;
1430         for ( i = 0 ; i < (int ) ServiceInParameter().length() ; i++ ) {
1431           cdebug << " , " << InParametersList[ i ].Name << "[kind"
1432                  << InParametersList[ i ].Value.type()->kind() << "]" ;
1433         }
1434         for ( i = 0 ; i < (int ) ServiceOutParameter().length() ; i++ ) {
1435           cdebug << " , " << OutParametersList[ i ].Name << "[kind"
1436                  << OutParametersList[ i ].Value.type()->kind() << "]" ;
1437         }
1438         if ( IsOneOfInLineNodes() ) {
1439           cdebug << " , PyFuncName '" << InLineNode()->PyFuncName() << "' PyRunMethod "
1440                  << InLineNode()->PyRunMethod() << " length "
1441                  << (*InLineNode()->PythonFunction()).length() ;
1442         }
1443         cdebug << ")" << endl ;
1444 #endif
1445
1446         if ( IsOneOfInLineNodes() ) {
1447           bool StsPyDynInvoke = true;
1448           _OutNode->PyThreadLock() ;
1449           SetPyCpuUsed() ;
1450           try {
1451 //            if ( IsInLineNode() && (*InLineNode()->PythonFunction()).length() &&
1452             bool ItIsaLoop = false ;
1453             bool CopyInOut = false ;
1454             if ( IsInLineNode() && /*InLineNode()->PyRunMethod() &&*/
1455                  strlen( InLineNode()->PyFuncName() ) ) {
1456 #if TraceDataReady_ExecuteAction
1457               cdebug << ThreadNo() << " !ObjInterface " << Name() << " PyFuncName '"
1458                      << InLineNode()->PyFuncName()
1459                      << "' IsInLineNode PyDynInvoke"  << endl ;
1460 #endif
1461               StsPyDynInvoke = PyDynInvoke( InLineNode()->PyRunMethod() ,
1462                                             InLineNode()->PyFuncName() ,
1463                                             &InParametersList[0] , ServiceInParameter().length() ,
1464                                             &OutParametersList[0] , ServiceOutParameter().length() ) ;
1465               if ( !StsPyDynInvoke ) {
1466                 RemovePyDynInvoke( InLineNode()->PyFuncName() ) ;
1467               }     }
1468             else if ( IsLoopNode() ) {
1469               ItIsaLoop = true ;
1470               bool CopyOutIn = false ;
1471 // Switch between Init() and Next()
1472 // if InLoop port is true and does not come from EndLoop ==> execute Init
1473 // if InLoop port is false or come from EndLoop ==> execute Next
1474 //              GraphExecutor::InNode * anEndLoopNode = (GraphExecutor::InNode * ) CoupledNode()->GetInNode() ;
1475 //              if ( GetNodeInLoop()->GetOutPort()->BoolValue() &&
1476               if ( _InitLoop ) {
1477                 if ( strlen( InLineNode()->PyFuncName() ) ) { // InLoop Port = true ==> Init()
1478 #if TraceDataReady_ExecuteAction
1479                   cdebug << ThreadNo() << " !ObjInterface " << Name()
1480                          << " IsLoopNode PyDynInvoke '" << InLineNode()->PyFuncName()
1481                          << "' InitLoop " << LoopNode()->PyRunMethod() << endl ;
1482 #endif
1483                   StsPyDynInvoke = PyDynInvoke( InLineNode()->PyRunMethod() ,
1484                                                 InLineNode()->PyFuncName() ,
1485                                                 &InParametersList[1] , ServiceInParameter().length() ,
1486                                                 &OutParametersList[1] , ServiceOutParameter().length() ) ;
1487                 if ( !StsPyDynInvoke ) {
1488                   RemovePyDynInvoke( InLineNode()->PyFuncName() ) ;
1489                 }
1490                   CopyOutIn = true ;
1491                 }
1492                 else {
1493 #if TraceDataReady_ExecuteAction
1494                   cdebug << ThreadNo() << " !ObjInterface " << Name()
1495                          << " IsLoopNode NO PyDynInvoke Void PyFuncName InitLoop" << endl ;
1496 #endif
1497                 }
1498 #if TraceDataReady_ExecuteAction
1499                 cdebug << ThreadNo() << " !ObjInterface " << Name()
1500                        << " IsLoopNode _InitLoop Reset after Init() Python Function" << endl ;
1501 #endif
1502                 _InitLoop = false ;
1503               }
1504               else if ( LoopNode()->PyNextMethod() &&
1505                         strlen( LoopNode()->PyNextName() ) ){ // InLoop Port = false ==> Next()
1506 #if TraceDataReady_ExecuteAction
1507                 cdebug << ThreadNo() << " !ObjInterface " << Name()
1508                        << " IsLoopNode PyDynInvoke '" << LoopNode()->PyNextName()
1509                        << "' " << LoopNode()->PyNextMethod() << endl ;
1510 #endif
1511                 StsPyDynInvoke = PyDynInvoke( LoopNode()->PyNextMethod() ,
1512                                               LoopNode()->PyNextName() ,
1513                                               &InParametersList[1] , ServiceInParameter().length() ,
1514                                               &OutParametersList[1] , ServiceOutParameter().length() ) ;
1515                 if ( !StsPyDynInvoke ) {
1516                   RemovePyDynInvoke( LoopNode()->PyNextName() ) ;
1517                 }
1518                 CopyOutIn = true ;
1519               }
1520               else {
1521 #if TraceDataReady_ExecuteAction
1522                 cdebug << ThreadNo() << " !ObjInterface " << Name()
1523                        << " IsLoopNode NO PyDynInvoke Void PyFuncName NextLoop" << endl ;
1524 #endif
1525               }
1526               if ( StsPyDynInvoke ) {
1527                 if ( CopyOutIn ) {
1528 #if TraceDataReady_ExecuteAction
1529                   cdebug << ThreadNo() << " !ObjInterface " << Name()
1530                          << " IsLoopNode PyDynInvoke '" << LoopNode()->PyMoreName()
1531                          << "' Copy of " << ServiceInParameter().length()
1532                          << " OutParameters" << endl ;
1533 #endif
1534                   int i ;
1535 // Start at 1 : Do not copy InLoop ( InLoop == true <==> Init ; InLoop == false <==> Next )
1536                   for ( i = 1 ; i <= (int ) ServiceInParameter().length() ; i++ ) {
1537                     InParametersList[i].Value = OutParametersList[i].Value ;
1538                     InParametersList[i].Name = OutParametersList[i].Name ;
1539 #if TraceDataReady_ExecuteAction
1540                     switch ( InParametersList[i].Value.type()->kind() ) {
1541                     case CORBA::tk_string :
1542                       char * t;
1543                       InParametersList[i].Value >>= t ;
1544                       cdebug << "ArgOut->In" << i << " : "
1545                              << InParametersList[i].Name.c_str()
1546                              << " Value(string) " << t << endl ;
1547                       break ;
1548                     case CORBA::tk_boolean:
1549                       bool b ;
1550                       InParametersList[i].Value >>= (CORBA::Any::to_boolean ) b;
1551                       cdebug << "ArgOut->In" << i << " : "
1552                              << InParametersList[i].Name.c_str()
1553                              << " Value(boolean) " << b << endl ;
1554                       break ;
1555                     case CORBA::tk_char:
1556                       unsigned char c ;
1557                       InParametersList[i].Value >>= (CORBA::Any::to_char ) c;
1558                       cdebug << "ArgOut->In" << i << " : "
1559                              << InParametersList[i].Name.c_str()
1560                              << " Value(char) " << c << endl ;
1561                       break ;
1562                     case CORBA::tk_short:
1563                       short s ;
1564                       InParametersList[i].Value >>= s;
1565                       cdebug << "ArgOut->In" << i << " : "
1566                              << InParametersList[i].Name.c_str()
1567                              << " Value(short) " << s << endl ;
1568                       break ;
1569                     case CORBA::tk_long :
1570                       long l;
1571                       InParametersList[i].Value >>= l;
1572                       cdebug << "ArgOut->In" << i << " : "
1573                              << InParametersList[i].Name.c_str()
1574                              << " Value(long) " << l << endl ;
1575                       break ;
1576                     case CORBA::tk_float :
1577                       float f;
1578                       InParametersList[i].Value >>= f;
1579                       cdebug << "ArgOut->In" << i << " : "
1580                              << InParametersList[i].Name.c_str()
1581                              << " Value(float) " << f << endl ;
1582                       break ;
1583                     case CORBA::tk_double :
1584                       double d;
1585                       InParametersList[i].Value >>= d;
1586                       cdebug << "ArgOut->In" << i << " : "
1587                              << InParametersList[i].Name.c_str()
1588                              << " Value(double) " << d << endl ;
1589                       break ;
1590                     case CORBA::tk_objref :
1591                       CORBA::Object_ptr obj ;
1592                       char * retstr ;
1593                       try {
1594                         InParametersList[i].Value >>= obj ;
1595                         retstr = ObjectToString( obj );
1596                         cdebug << "ArgOut->In" << i << " : "
1597                                << InParametersList[i].Name.c_str()
1598                                << " Value(object reference) " << retstr << endl ;
1599                        }
1600                       catch ( ... ) {
1601                         cdebug << "ArgOut->In" << i << " : "
1602                                << InParametersList[i].Name.c_str()
1603                                << " Value(object reference) Catched ERROR" << endl ;
1604                       }
1605                       break ;
1606                     default :
1607                       cdebug << "ArgOut->In" << i << " : "
1608                              << InParametersList[i].Name.c_str()
1609                              << " Value(other) ERROR" << endl ;
1610                     }
1611 #endif
1612                   }
1613                 }
1614                 if ( LoopNode()->PyMoreMethod() && strlen( LoopNode()->PyMoreName() ) ) {
1615 #if TraceDataReady_ExecuteAction
1616                   cdebug << ThreadNo() << " !ObjInterface " << Name()
1617                          << " IsLoopNode PyDynInvoke '" << LoopNode()->PyMoreName()
1618                          << "' " << LoopNode()->PyMoreMethod() << endl ;
1619 #endif
1620                   StsPyDynInvoke = PyDynInvoke( LoopNode()->PyMoreMethod() ,
1621                                                 LoopNode()->PyMoreName() ,
1622                                                 &InParametersList[1] , ServiceInParameter().length() ,
1623                                                 &OutParametersList[0] , ServiceOutParameter().length()+1 ) ;
1624                   if ( !StsPyDynInvoke ) {
1625                     RemovePyDynInvoke( LoopNode()->PyMoreName() ) ;
1626                   }
1627                 }
1628                 else {
1629 #if TraceDataReady_ExecuteAction
1630                   cdebug << ThreadNo() << " !ObjInterface " << Name()
1631                          << " IsLoopNode PyDynInvoke '" << LoopNode()->PyMoreName()
1632                          << "' No MoreMethod" << endl ;
1633 #endif
1634                   CopyInOut = true ;
1635                 }
1636               }
1637               else {
1638                 Err = true ;
1639                 cdebug << ThreadNo() << " InLineNode " << Name() << " "
1640                        << InLineNode()->PyFuncName() << "/" << LoopNode()->PyNextName()
1641                        << " Python Dynamic Call Error"
1642                        << endl ;
1643               }
1644             }
1645             else if ( IsSwitchNode() && /*InLineNode()->PyRunMethod() &&*/
1646                       strlen( InLineNode()->PyFuncName() ) ) {
1647 #if TraceDataReady_ExecuteAction
1648               cdebug << ThreadNo() << " !ObjInterface " << Name() << " PyFuncName '"
1649                      << InLineNode()->PyFuncName()
1650                      << "' IsSwitchNode PyDynInvoke"  << endl ;
1651 #endif
1652               StsPyDynInvoke = PyDynInvoke( InLineNode()->PyRunMethod() ,
1653                                             InLineNode()->PyFuncName() ,
1654                                             &InParametersList[0] , ServiceInParameter().length() ,
1655                                             &OutParametersList[0] , ServiceOutParameter().length() ) ;
1656               if ( !StsPyDynInvoke ) {
1657                 RemovePyDynInvoke( InLineNode()->PyFuncName() ) ;
1658               }
1659             }
1660 //            else if ( IsGOTONode() && (*GOTONode()->PythonFunction()).length() &&
1661             else if ( IsGOTONode() && /*InLineNode()->PyRunMethod() &&*/
1662                       strlen( InLineNode()->PyFuncName() ) ) {
1663 #if TraceDataReady_ExecuteAction
1664               cdebug << ThreadNo() << " !ObjInterface " << Name() << " PyFuncName '"
1665                      << InLineNode()->PyFuncName()
1666                      << "' IsGOTONode PyDynInvoke"  << endl ;
1667 #endif
1668               StsPyDynInvoke = PyDynInvoke( InLineNode()->PyRunMethod() ,
1669                                             InLineNode()->PyFuncName() ,
1670                                             &InParametersList[0] , ServiceInParameter().length() ,
1671                                             &OutParametersList[0] , ServiceOutParameter().length() ) ;
1672               if ( !StsPyDynInvoke ) {
1673                 RemovePyDynInvoke( GOTONode()->PyFuncName() ) ;
1674               }
1675             }
1676 //            else if ( IsEndSwitchNode() && (*InLineNode()->PythonFunction()).length() &&
1677             else if ( ( IsEndSwitchNode() ) &&
1678                       InLineNode()->PyRunMethod() && strlen( InLineNode()->PyFuncName() ) ) {
1679 #if TraceDataReady_ExecuteAction
1680               cdebug << ThreadNo() << " !ObjInterface " << Name() << " PyFuncName '"
1681                      << InLineNode()->PyFuncName()
1682                      << "' IsSwitchNode PyDynInvoke"  << endl ;
1683 #endif
1684               StsPyDynInvoke = PyDynInvoke( InLineNode()->PyRunMethod() ,
1685                                             InLineNode()->PyFuncName() ,
1686                                             &InParametersList[0] , ServiceInParameter().length() ,
1687                                             &OutParametersList[0] , ServiceOutParameter().length() ) ;
1688               if ( !StsPyDynInvoke ) {
1689                 RemovePyDynInvoke( InLineNode()->PyFuncName() ) ;
1690               }
1691             }
1692             else if ( ( IsEndLoopNode() ) &&
1693                       InLineNode()->PyRunMethod() && strlen( InLineNode()->PyFuncName() ) ) {
1694 #if TraceDataReady_ExecuteAction
1695               cdebug << ThreadNo() << " !ObjInterface " << Name() << " PyFuncName '"
1696                      << InLineNode()->PyFuncName()
1697                      << "' IsSwitchNode PyDynInvoke"  << endl ;
1698 #endif
1699               StsPyDynInvoke = PyDynInvoke( InLineNode()->PyRunMethod() ,
1700                                             InLineNode()->PyFuncName() ,
1701                                             &InParametersList[0] , ServiceInParameter().length() + 1 ,
1702                                             &OutParametersList[0] , ServiceOutParameter().length() + 1 ) ;
1703               if ( !StsPyDynInvoke ) {
1704                 RemovePyDynInvoke( InLineNode()->PyFuncName() ) ;
1705               }
1706             }
1707
1708 //            else if ( (*InLineNode()->PythonFunction()).length() == 0 ||
1709             if ( (!ItIsaLoop && ( InLineNode()->PyRunMethod() == NULL ||
1710                                   strlen( InLineNode()->PyFuncName() ) == 0 ) ) || CopyInOut ) {
1711 // This is a void Python Function : without code (No PyFuncName)
1712 #if TraceDataReady_ExecuteAction
1713               cdebug << ThreadNo() << " !ObjInterface " << Name()
1714                      << " Copy of " << ServiceInParameter().length()
1715                      << " OutParameters" << endl ;
1716 #endif
1717               int i ;
1718               int argout0 = 0 ;
1719               int argin0 = 0 ;
1720               if ( IsLoopNode() || IsEndLoopNode() ) {
1721                 argout0 = 1 ;
1722                 argin0 = 1 ; // after DoLoop
1723                 if ( IsLoopNode() ) { // More() is void
1724 //                  OutParametersList[0].Value = InParametersList[0].Value ; // DoLoop
1725 #if TraceDataReady_ExecuteAction
1726                   cdebug << Name() << " Not Beginning of loop and non void EndLoop : DoLoop = EndLoop(DoLoop)"
1727                          << endl ;
1728 #endif
1729                   GraphExecutor::InNode * anEndLoopNode = (GraphExecutor::InNode * ) CoupledNode()->GetInNode() ;
1730 //JR 30.03.2005                  OutParametersList[0].Value = *anEndLoopNode->GetNodeOutLoop()->Value() ; // DoLoop = EndLoop(DoLoop)
1731                   OutParametersList[0].Value = anEndLoopNode->GetNodeOutLoop()->Value() ; // DoLoop = EndLoop(DoLoop)
1732                 }
1733               }
1734 //PAL8072 ==> PAL8512
1735 //JR 24.03.2005 : Debug : void InLine Python function : check of the number of Input Ports
1736 //                        equals the number of Output Ports was missing
1737               if ( ServiceInParameter().length() != ServiceOutParameter().length() ) {
1738                 StsPyDynInvoke = false ;
1739               }
1740               else {
1741                 for ( i = 0 ; i < (int ) ServiceInParameter().length() ; i++ ) {
1742                   OutParametersList[argout0 + i].Value = InParametersList[argin0 + i].Value ;
1743 #if TraceDataReady_ExecuteAction
1744                   switch ( InParametersList[argin0 + i].Value.type()->kind() ) {
1745                   case CORBA::tk_string :
1746                     cdebug << "ArgOut->In" << argin0 + i << " : "
1747                            << InParametersList[argin0 + i].Name.c_str()
1748                            << " Value(string) "
1749                            << OutParametersList[argout0 + i].Name.c_str() << endl ;
1750                     break ;
1751                   case CORBA::tk_boolean:
1752                     cdebug << "ArgOut->In" << argin0 + i << " : "
1753                            << InParametersList[argin0 + i].Name.c_str()
1754                            << " Value(boolean) "
1755                            << OutParametersList[argout0 + i].Name.c_str() << endl ;
1756                     break ;
1757                   case CORBA::tk_char:
1758                     cdebug << "ArgOut->In" << argin0 + i << " : "
1759                            << InParametersList[argin0 + i].Name.c_str()
1760                            << " Value(char) "
1761                            << OutParametersList[argout0 + i].Name.c_str() << endl ;
1762                     break ;
1763                   case CORBA::tk_short:
1764                     cdebug << "ArgOut->In" << argin0 + i << " : "
1765                            << InParametersList[argin0 + i].Name.c_str()
1766                            << " Value(short) "
1767                            << OutParametersList[argout0 + i].Name.c_str() << endl ;
1768                     break ;
1769                   case CORBA::tk_long :
1770                     cdebug << "ArgOut->In" << argin0 + i << " : "
1771                            << InParametersList[argin0 + i].Name.c_str()
1772                            << " Value(long) "
1773                            << OutParametersList[argout0 + i ].Name.c_str() << endl ;
1774                     break ;
1775                   case CORBA::tk_double :
1776                     cdebug << "ArgOut->In" << argin0 + i << " : "
1777                            << InParametersList[argin0 + i].Name.c_str()
1778                            << " Value(double) "
1779                            << OutParametersList[argout0 + i].Name.c_str() << endl ;
1780                     break ;
1781                   case CORBA::tk_objref :
1782                     cdebug << "ArgOut->In" << argin0 + i << " : "
1783                            << InParametersList[argin0 + i].Name.c_str()
1784                            << " Value(object reference) "
1785                            << OutParametersList[argout0 + i].Name.c_str() << endl ;
1786                     break ;
1787                   default :
1788                     cdebug << "ArgOut->In" << argin0 + i << " : "
1789                            << InParametersList[argin0 + i].Name.c_str()
1790                            << " Value(other) ERROR "
1791                            << OutParametersList[argout0 + i].Name.c_str() << endl ;
1792                   }
1793 #endif
1794                 }
1795               }
1796             }
1797             if ( !StsPyDynInvoke ) {
1798               Err = true ;
1799               cdebug << ThreadNo() << " InLineNode " << Name()
1800                      << " Python Dynamic Call Error"
1801                      << endl ;
1802             }
1803           }
1804           catch( ... ) {
1805             Err = true ;
1806             cdebug << ThreadNo() << " InLineNode " << Name()
1807                    << " Python Dynamic Call Exception catched ERROR"
1808                    << endl ;
1809           }
1810           CpuUsed( true ) ;
1811           _OutNode->PyThreadUnLock() ;
1812         }
1813         else {
1814           try {
1815             try {
1816 #if TraceDataReady_ExecuteAction
1817               cdebug << "DynInvoke -> Names " << _OutNode->Name() << " " << Name() << endl ;
1818 #endif
1819               DynInvoke( myObjComponent, "Names" ,
1820                          _OutNode->Name() , Name() ) ;
1821             }
1822             catch( ... ) {
1823               cdebug << "DynInvoke Names catched ERROR" << endl ;
1824             }
1825 // for DataStreamNodes : call of SetProperties ===> environment variables in the component/container
1826             if ( ComputingNode()->HasDataStream() ) {
1827               try {
1828 #if TraceDataReady_ExecuteAction
1829                 cdebug << "DynInvoke -> SetProperties " << _OutNode->Name() << " " << Name() << endl ;
1830 #endif
1831                 Engines::FieldsDict_var dict = new Engines::FieldsDict;
1832                 dict->length( 4 );
1833                 dict[ 0 ].key = CORBA::string_dup( "CAL_MACHINE");
1834                 // myContainer->getHostName() ne renvoit pas le nom complet (avec domaine).
1835                 //              dict[ 0 ].value <<= myContainer->getHostName() ;
1836                 char FullyQualifiedDomainName[256]="";
1837                 gethostname(FullyQualifiedDomainName,255);
1838                 dict[ 0 ].value <<=  FullyQualifiedDomainName ;
1839                 dict[ 1 ].key = CORBA::string_dup( "CAL_REPERTOIRE");
1840                 dict[ 1 ].value <<= "/tmp" ;
1841                 dict[ 2 ].key = CORBA::string_dup( "CAL_COUPLAGE");
1842                 stringstream ofst1 ;
1843                 ofst1 << ComputingNode()->SubStreamGraph() ;
1844                 string cpl = string( "/tmp/" ) + string( _OutNode->Name() ) + string( "_" ) + 
1845                              ofst1.str() + string( ".cpl" );
1846                 dict[ 2 ].value <<= cpl.c_str() ;
1847                 dict[ 3 ].key = CORBA::string_dup( "SALOME_INSTANCE_NAME");
1848                 string uname = Name();
1849                 UpperCase( uname);
1850                 dict[ 3 ].value <<= uname.c_str() ;
1851
1852                 myObjComponent->setProperties( dict ) ;
1853               }
1854               catch( ... ) {
1855                 cdebug << "DynInvoke setProperties catched ERROR" << endl ;
1856                 Err = true;
1857               }
1858             }
1859             if ( !Err && IsComputingNode() ) {
1860 #if TraceDataReady_ExecuteAction
1861               cdebug << ThreadNo() << " !ObjInterface " << Name()
1862                      << " IsComputingNode DynInvoke"  << endl ;
1863               cdebug << ServiceInParameter().length()-1 << " input parameters and "
1864                      << ServiceOutParameter().length() << " output parameters" << endl ;
1865 #endif
1866               IsLoading( false ) ;
1867               DynInvoke( myObjComponent,
1868                          ServiceName() ,
1869                          &InParametersList[1] , ServiceInParameter().length()-1 ,
1870                          &OutParametersList[0] , ServiceOutParameter().length() ) ;
1871             }
1872             else if ( !Err && IsFactoryNode() ) {
1873 #if TraceDataReady_ExecuteAction
1874               cdebug << pthread_self() << "/" << ThreadNo() << " !ObjInterface " << Name()
1875                      << " IsFactoryNode DynInvoke"  << endl ;
1876               cdebug << ServiceInParameter().length() << " input parameters and "
1877                      << ServiceOutParameter().length() << " output parameters" << endl ;
1878 #endif
1879               IsLoading( false ) ;
1880               DynInvoke( myObjComponent,
1881                          ServiceName() ,
1882                          &InParametersList[0] , ServiceInParameter().length() ,
1883                          &OutParametersList[0] , ServiceOutParameter().length() ) ;
1884             }
1885 //            cdebug << ThreadNo() << " Component::CpuUsed " << Name() << " "
1886 //                   << myObjComponent->CpuUsed_impl() << endl ;
1887           }
1888           catch( ... ) {
1889             Err = true ;
1890             cdebug << pthread_self() << "/" << ThreadNo() << " !ObjInterface " << Name()
1891                    << " Node(Component) Dynamic Call Exception catched ERROR"
1892                    << endl ;
1893 //Reset of _ThreadId in the Container ...
1894             try {
1895               myObjComponent->Kill_impl() ;
1896             }
1897             catch( ... ) {
1898             }
1899           }
1900         }
1901       }
1902     }
1903   }
1904
1905 //  ostringstream astr ;
1906 //  astr << "Graph " << _OutNode->Name() << " Node " << Name() << " is done : "
1907 //       << Automaton()->StateName( State() ) ;
1908 //  _OutNode->Graph()->ObjImpl()->sendMessage( NOTIF_STEP, astr.str().c_str() ) ;
1909
1910   if ( Err ) {
1911     
1912     // if exception or something else - IsLoading( false ) may not NOT has been called
1913     if ( IsLoading() )
1914       IsLoading( false );
1915
1916     if ( ControlState() == SUPERV::ToKillState ||
1917          ControlState() == SUPERV::ToKillDoneState ||
1918          ControlState() == SUPERV::ToStopState ) {
1919       PortState = SUPERV::ErrorState ;
1920       NewState = GraphExecutor::KilledState ;
1921       NewEvent = GraphExecutor::KillEvent ;
1922     }
1923     else {
1924       PortState = SUPERV::ErrorState ;
1925       NewState = GraphExecutor::ErroredState ;
1926       NewEvent = GraphExecutor::ErrorEvent ;
1927     }
1928   }
1929   else {
1930     PortState = SUPERV::ReadyState ;
1931     NewState = GraphExecutor::DataReadyState ;
1932     NewEvent = GraphExecutor::SuccessEvent ;
1933   }
1934
1935   if ( !IsMacroNode() ) {
1936 //JRStep A
1937     bool ErrOut = OutParametersSet( Err , PortState , nOutParams , OutParametersList ) ;
1938     if ( !ErrOut ) {
1939       NewEvent = GraphExecutor::ErrorEvent ;
1940     }
1941     delete [] InParametersList ;
1942     delete [] OutParametersList ;
1943   }
1944           
1945   if ( !IsMacroNode() ) {              
1946 //JR ==> Step B
1947     SendEvent( NewEvent ) ;
1948   }
1949   else {
1950     GraphExecutor::DataFlow * aMacroGraph = GraphMacroNode()->CoupledNode()->GraphEditor()->Executor() ;
1951 #if TraceDataReady_ExecuteAction
1952     cdebug << ThreadNo() << " DataReady_ExecuteAction " << aMacroGraph << " "
1953            << aMacroGraph->Name() << " ->DoneWait()"
1954            << " State " << aMacroGraph->State() << endl;
1955 #endif
1956     aMacroGraph->DoneWait() ;
1957 #if TraceDataReady_ExecuteAction
1958     cdebug << ThreadNo() << " DataReady_ExecuteAction " << Name() << " State " << aMacroGraph->State() << endl;
1959 #endif
1960     if ( aMacroGraph->State() == SUPERV::DoneState ) {
1961       PortState = SUPERV::ReadyState ;
1962       NewState = GraphExecutor::DataReadyState ;
1963       NewEvent = GraphExecutor::SuccessEvent ;
1964     }
1965     else {
1966       Err = true ;
1967       if ( ControlState() == SUPERV::ToKillState ||
1968            ControlState() == SUPERV::ToKillDoneState ||
1969            ControlState() == SUPERV::ToStopState ) {
1970         PortState = SUPERV::ErrorState ;
1971         NewState = GraphExecutor::KilledState ;
1972         NewEvent = GraphExecutor::KillEvent ;
1973       }
1974       else {
1975         PortState = SUPERV::ErrorState ;
1976         NewState = GraphExecutor::ErroredState ;
1977         NewEvent = GraphExecutor::ErrorEvent ;
1978       }
1979     }
1980     bool ErrOut = OutParametersSet( Err , PortState , nOutParams , OutParametersList ) ;
1981     if ( !ErrOut ) {
1982       NewEvent = GraphExecutor::ErrorEvent ;
1983     }
1984     delete [] InParametersList ;
1985     delete [] OutParametersList ;
1986     SendEvent( NewEvent ) ;
1987   }
1988
1989 #if TraceDataReady_ExecuteAction
1990   cdebug << ThreadNo() << " <-- DataReady_ExecuteAction " << Name() << endl;
1991 #endif
1992   return 1 ;
1993 }
1994
1995 int GraphExecutor::InNode::Executing_SuspendAction() {
1996   _OutNode->PushEvent( this , GraphExecutor::SuspendedExecutingEvent ,
1997                        GraphExecutor::SuspendedExecutingState ) ; 
1998   cdebug << ThreadNo() << " Executing_SuspendAction " << Name() << endl;
1999   return 1 ;
2000 }
2001
2002 int GraphExecutor::InNode::SuspendedExecuting_ResumeAction() {
2003   cdebug << ThreadNo() << " SuspendedExecuting_ResumeAction " << Name() << endl;
2004   GraphExecutor::AutomatonState next_state ;
2005   next_state = Automaton()->NextState( State() , GraphExecutor::ExecutingEvent ) ;
2006   _OutNode->NewThread() ; // Only for Threads count
2007   _OutNode->PushEvent( this , GraphExecutor::ResumedExecutingEvent ,
2008                        next_state ) ; 
2009   State( next_state ) ;
2010   return 1 ;
2011 }
2012
2013 int GraphExecutor::InNode::Executing_KillAction() {
2014   cdebug << ThreadNo() << " Executing_KillAction " << Name() << " Thread " << ThreadNo()<< endl;
2015   int RetVal = 0 ;
2016   if ( pthread_self() == ThreadNo() ) {
2017     cdebug << "Executing_KillAction would pthread_canceled itself" << endl ;
2018     KillAction() ;
2019     _OutNode->PushEvent( this , GraphExecutor::KilledExecutingEvent ,
2020                          GraphExecutor::KilledExecutingState ) ; 
2021     RetVal = 1 ;
2022   }
2023   else if ( pthread_cancel( ThreadNo() ) ) {
2024     perror("Executing_KillAction pthread_cancel error") ;
2025   }
2026   else {
2027     cdebug << pthread_self() << " Executing_KillAction : ThreadId " << ThreadNo()
2028            << " pthread_canceled" << endl ;
2029     KillAction() ;
2030     _OutNode->ExitThread( ThreadNo() ) ;
2031     _OutNode->PushEvent( this , GraphExecutor::KilledExecutingEvent ,
2032                          GraphExecutor::KilledExecutingState ) ; 
2033   }
2034   return RetVal ;
2035 }
2036
2037 int GraphExecutor::InNode::Executing_StopAction() {
2038   cdebug << ThreadNo() << " Executing_StopAction " << Name() << " Thread " << ThreadNo() << endl;
2039   int RetVal = 0 ;
2040   if ( pthread_cancel( ThreadNo() ) ) {
2041     perror("Executing_KillAction pthread_cancel error") ;
2042   }
2043   else {
2044     cdebug << pthread_self() << " Executing_KillAction : ThreadId " << ThreadNo()
2045            << " pthread_canceled" << endl ;
2046     StopAction() ;
2047     _OutNode->ExitThread( ThreadNo() ) ;
2048     _OutNode->PushEvent( this , GraphExecutor::StoppedExecutingEvent ,
2049                          GraphExecutor::StoppedExecutingState ) ; 
2050   }
2051   return RetVal ;
2052 }
2053
2054 int GraphExecutor::InNode::Executing_SuccessAction() {
2055 //  cdebug << ThreadNo() << " --> Executing_SuccessAction " << Name() << endl;
2056   _OutNode->PushEvent( this , GraphExecutor::SuccessedExecutingEvent ,
2057                        GraphExecutor::SuccessedState ) ; 
2058 //  MESSAGE(pthread_self() << "Executor::InNode::Executing_SuccessAction of " << Name()
2059 //          << " ControlState " << Automaton()->ControlStateName( ControlState() )
2060 //          << " AFTER execution ThreadNo " << ThreadNo() ) ;
2061   SUPERV::ControlState aControl = ControlState() ;
2062   switch ( aControl ) {
2063   case SUPERV::VoidState : {
2064     SendEvent( SuccessEvent ) ;
2065     break ;
2066   }
2067   case SUPERV::ToSuspendState : {
2068     SendEvent( SuccessEvent ) ;
2069     break ;
2070   }
2071   case SUPERV::ToSuspendDoneState : {
2072     SendEvent( GraphExecutor::SuspendEvent ) ;
2073     return 1 ;
2074   }
2075   case SUPERV::ToKillState : {
2076     SendEvent( GraphExecutor::KillEvent ) ;
2077     return 1 ;
2078   }
2079   case SUPERV::ToKillDoneState : {
2080     SendEvent( GraphExecutor::KillEvent ) ;
2081     return 1 ;
2082   }
2083   case SUPERV::ToStopState : {
2084     SendEvent( GraphExecutor::StopEvent ) ;
2085     return 1 ;
2086   }
2087   default : {
2088     cdebug << ThreadNo()
2089            << " GraphExecutor::InNodeThreads::Executing_SuccessAction Error Undefined Control : "
2090            << aControl << endl ;
2091     return 0;
2092   }
2093   }
2094 //  cdebug << ThreadNo() << " <-- Executing_SuccessAction "  << Name() << endl;
2095   return 1 ;
2096 }
2097
2098 int GraphExecutor::InNode::Executing_ErrorAction() {
2099   cdebug << ThreadNo() << " --> Executing_ErrorAction " << Name() << endl;
2100   _OutNode->PushEvent( this , GraphExecutor::ErroredExecutingEvent ,
2101                        GraphExecutor::ErroredState ) ; 
2102
2103   SUPERV::ControlState aControl = ControlState() ;
2104   switch ( aControl ) {
2105   case SUPERV::VoidState : {
2106     SendEvent( ErrorEvent ) ;
2107     break ;
2108   }
2109   case SUPERV::ToSuspendState : {
2110     SendEvent( ErrorEvent ) ;
2111     break ;
2112   }
2113   case SUPERV::ToSuspendDoneState : {
2114     SendEvent( GraphExecutor::SuspendEvent ) ;
2115     return 1 ;
2116   }
2117   case SUPERV::ToKillState : {
2118     SendEvent( GraphExecutor::KillEvent ) ;
2119     return 1 ;
2120   }
2121   case SUPERV::ToKillDoneState : {
2122     SendEvent( GraphExecutor::KillEvent ) ;
2123     return 1 ;
2124   }
2125   case SUPERV::ToStopState : {
2126     SendEvent( GraphExecutor::StopEvent ) ;
2127     return 1 ;
2128   }
2129   default : {
2130     cdebug << ThreadNo()
2131            << " GraphExecutor::InNodeThreads::Executing_ErrorAction Error Undefined Control : "
2132            << aControl << endl ;
2133     return 0;
2134   }
2135   }
2136   cdebug << ThreadNo() << " <-- Executing_ErrorAction "  << Name() << endl;
2137   return 1 ;
2138 }
2139
2140 #define SetWaitingStatesTrace 0
2141 // Set SUPERV::WaitingState to all InPorts 
2142 void GraphExecutor::InNode::SetWaitingStates(GraphExecutor::InNode * EndNode ) {
2143   int i ;
2144   int j ;
2145   bool docdebug = false ;
2146   State( GraphExecutor::DataWaitingState ) ;
2147 #if SetWaitingStatesTrace
2148   cdebug << "SetWaitingStates " << Name() << " " << Automaton()->StateName( State() ) << endl ;
2149 #endif
2150   for ( i = 0 ; i < GetNodeInPortsSize() ; i++ ) {
2151     GraphBase::InPort * anInPort = GetChangeNodeInPort( i ) ;
2152 #if SetWaitingStatesTrace
2153     cdebug << "SetWaitingStates InPort " << Name() << "( " << anInPort->PortName() << " ) "
2154            << anInPort->PortStatus() << " " << anInPort->PortState() << endl ;
2155 #endif
2156 // PAL8513
2157 // JR Debug 07.01.2005 : Close the Gates instead of open !!!
2158     if ( anInPort->IsGate() ) { // Loop : Close the doors
2159       GraphBase::OutPort * anOutPort = anInPort->GetOutPort() ;
2160       if ( anOutPort ) {
2161 //JR 21.02.2005 Debug Memory leak :        CORBA::Any * anAny = new CORBA::Any() ;
2162         CORBA::Any anAny = CORBA::Any() ;
2163 //        *anAny <<= (long ) 1 ;
2164 //JR 21.02.2005 Debug Memory leak :        *anAny <<= (long ) 0 ;
2165         anAny <<= (long ) 0 ;
2166         anOutPort->SetValue( anAny ) ;
2167         anInPort->PortState( SUPERV::WaitingState ) ;
2168 //        delete anAny ;
2169       }
2170     }
2171     else if ( anInPort->PortState() != SUPERV::WaitingState &&
2172               !anInPort->IsDataConnected() ) {
2173       if ( !docdebug ) {
2174 #if SetWaitingStatesTrace
2175         cdebug << ThreadNo()
2176                << " --> GraphExecutor::InNodeThreads::SetWaitingStates " << Name() << endl;
2177 #endif
2178         docdebug = true ;
2179       }
2180       if ( !anInPort->IsDataStream() ) {
2181         anInPort->PortState( SUPERV::WaitingState ) ;
2182       }
2183     }
2184 #if SetWaitingStatesTrace
2185     cdebug << "               --> InPort " << Name() << "( " << anInPort->PortName() << " ) "
2186            << anInPort->PortStatus() << " " << anInPort->PortState() << endl ;
2187 #endif
2188   }
2189   for ( i = 0 ; i < GetNodeOutPortsSize() ; i++ ) {
2190     GraphBase::OutPort * anOutPort = GetChangeNodeOutPort( i ) ;
2191 // PAL8514
2192 //JR 07.03.2005 Debug : Reset of Done flag in OutPorts !... :
2193     if ( !anOutPort->IsDataStream() ) {
2194       anOutPort->PortDone( false ) ;
2195       anOutPort->PortState( SUPERV::WaitingState ) ;
2196     }
2197     for ( j = 0 ; j < anOutPort->InPortsSize() ; j++ ) {
2198       if ( !( IsGOTONode() && anOutPort->IsGate() ) &&
2199            !( IsEndLoopNode() && ( anOutPort->IsGate() || anOutPort->IsLoop() ) ) &&
2200            !anOutPort->IsDataStream() &&
2201            !anOutPort->ChangeInPorts( j )->IsDataStream() &&
2202            !anOutPort->ChangeInPorts( j )->IsExternConnected() ) {
2203 #if SetWaitingStatesTrace
2204         cdebug << ThreadNo()
2205                << " InNodeThreads::SetWaitingStates OutPort "
2206                << Name() << "/" << anOutPort->ChangeInPorts( j )->NodeName() << "( "
2207                << anOutPort->PortName() << " " << anOutPort->PortStatus() << " ) --> InPort "
2208                << anOutPort->ChangeInPorts( j )->NodeName() << "( "
2209                << anOutPort->ChangeInPorts( j )->PortName() << " "
2210                << anOutPort->ChangeInPorts( j )->PortStatus() << " )" << endl;
2211 #endif
2212         GraphBase::ComputingNode * aToNode ;
2213         aToNode = _OutNode->Graph()->GetChangeGraphNode( anOutPort->ChangeInPorts( j )->NodeName() ) ;
2214 // JR 12.01.2005 Debug : the OutPort linked to the InPort of a EndSwitchNode was changed so final
2215 //                       values of InPorts of EndSwitchNode may be wrong
2216 //                       (depending of order of linkednodes)
2217         if ( !aToNode->IsEndSwitchNode() && 
2218              strcmp( anOutPort->ChangeInPorts( j )->GetOutPort()->NodeName() , Name() ) ) {
2219 // After EndLoopNode or GOTONode the Input Ports of LoopNode or LabelNode have their values from
2220 // EndLoopNode or GOTONode. But if there is several nested loops we should re-establish.
2221 #if SetWaitingStatesTrace
2222           cdebug << ThreadNo()
2223                  << " InNodeThreads::SetWaitingStates Node " << Name() << " " 
2224                  << anOutPort->ChangeInPorts( j )->GetOutPort()->NodeName() << "( "
2225                  << anOutPort->ChangeInPorts( j )->GetOutPort()->PortName() << " ) != "
2226                  << Name() << " : Restored to " << anOutPort->NodeName() << "( "
2227                  << anOutPort->PortName() << " )" << endl ;
2228 #endif
2229           anOutPort->ChangeInPorts( j )->ChangeOutPort( anOutPort ) ;
2230         }
2231 //PAL8624
2232 //JR 21.04.2005 Debug : the OutPort field of InPorts of EndSwitchNodes must be an OutPort
2233 //                      of a SwitchBranch or of a NOTSwitchBranch if a link exist
2234 //                      (if not there is no change)
2235         else if ( !IsSwitchNode() && aToNode->IsEndSwitchNode() &&
2236                   strcmp( anOutPort->ChangeInPorts( j )->GetOutPort()->NodeName() , Name() ) ) {
2237 #if SetWaitingStatesTrace
2238           cdebug << ThreadNo()
2239                  << " InNodeThreads::SetWaitingStates Node " << Name() << " " 
2240                  << anOutPort->ChangeInPorts( j )->GetOutPort()->NodeName() << "( "
2241                  << anOutPort->ChangeInPorts( j )->GetOutPort()->PortName() << " ) != "
2242                  << Name() << " : Restored to " << anOutPort->NodeName() << "( "
2243                  << anOutPort->PortName() << " )" << endl ;
2244 #endif
2245           anOutPort->ChangeInPorts( j )->ChangeOutPort( anOutPort ) ;
2246         }
2247         GraphExecutor::InNode * aNode = (GraphExecutor::InNode * ) aToNode->GetInNode() ;
2248         if ( aNode != EndNode ) {
2249           aNode->SetWaitingStates( EndNode ) ;
2250         }
2251       }
2252     }
2253 #if SetWaitingStatesTrace
2254     cdebug << "               --> OutPort " << Name() << "( " << anOutPort->PortName() << " ) "
2255            << anOutPort->PortStatus() << " " << anOutPort->PortState() << endl ;
2256 #endif
2257   }
2258 }
2259
2260 #define SuccessActionTrace 1
2261 //JR Step B
2262 int GraphExecutor::InNode::Successed_SuccessAction() {
2263 #if SuccessActionTrace
2264   cdebug_in << pthread_self() << "/" << ThreadNo() << " Successed_SuccessAction "  << Name()
2265             << endl;
2266 #endif
2267   int res = 1;
2268 //PAL8624
2269 //JR 15.04.2005 Debug RetroConception :
2270 //The behavior of firstzeroNode and firsttoNode is not reliable and must be removed
2271 //The real problem is :
2272 // 1. send "SomeDataReady" event to linked nodes of the current node
2273 // 2. DO NOT send "AllDataReady" event even if all data are ready in SomeDataReady Action
2274 //    but register only that all data are ready :
2275 //    MAJOR ENHANCEMENT OF GRAPHEXECUTOR
2276 // 3. activate AllDataReady Action for each node (except the first one ) which have all
2277 //    its data ready with a creation of a new thread
2278 // 3. activate AllDataReady Action for the first node which have all its data
2279 //    ready in the current thread
2280 //The difficult problem (that I had in the past) was to clearly identify the above behavior ==>
2281 // firstzeroNode, firsttoNode, createnewthreadif, loackdatawait, "would dead lock" etc...
2282 // because if SomeDataReady Action see that all data were ready, it called immediately
2283 // AllDataReady Action ==> bugs difficult to understand and to reproduce
2284 //And the MAJOR DEBUG is (since the first "maquette") : we may have concurrent executions
2285 // of "SomeDataReady" in several threads and there WAS NO MUTEX to protect that
2286 // concurrent actions on the same node
2287 //  int linkednodesnumber = LinkedNodesSize() ;
2288 //  GraphExecutor::InNode *firstzeroNode = NULL ;
2289   GraphExecutor::InNode *firsttoNode = NULL ;
2290   GraphExecutor::InNode *toNode ;
2291   int i ;
2292   int j ;
2293   list<GraphExecutor::InNode *> SomeDataNodes ;
2294
2295   DoneAction() ;
2296
2297   if ( IsMacroNode() ) {
2298 #if SuccessActionTrace
2299       cdebug << pthread_self() << "/" << ThreadNo() << " Successed_SuccessAction " << Name() << " LinkedNodes->SomeDataReady already done"
2300              << endl ;
2301 #endif
2302     return 1;
2303   }
2304
2305 //JR 09.02.2005 : That complicated part of the code manages LOOPS and GOTO
2306   if ( IsGOTONode() ||
2307        ( IsEndLoopNode() && GetNodeInLoop()->GetOutPort()->BoolValue() ) ) {
2308 #if SuccessActionTrace
2309     cdebug << pthread_self() << "/" << ThreadNo() << " Successed_SuccessAction " << Name()
2310            << " SetWaitingStates " << endl ;
2311 #endif
2312     const GraphBase::OutPort * aGateOutPort ;
2313     if ( IsGOTONode() ) {
2314       aGateOutPort = GetNodeOutGate() ;
2315     }
2316     else {
2317       aGateOutPort = GetNodeOutLoop() ;
2318     }
2319     if ( aGateOutPort->InPortsSize() != 1 ) {
2320       cdebug << pthread_self() << "/" << ThreadNo() << " Successed_SuccessAction aGateOutPort->InPortsSize "
2321              << aGateOutPort->InPortsSize() << " != 1 ERROR " << Name() << endl ;
2322     }
2323     GraphExecutor::InNode * aLabelNode = NULL ;
2324     for ( i = 0 ; i < aGateOutPort->InPortsSize() ; i++ ) {
2325       const GraphBase::InPort * anInPort = aGateOutPort->InPorts( i ) ;
2326       aLabelNode = (GraphExecutor::InNode *) _OutNode->Graph()->GetChangeGraphNode( anInPort->NodeName() )->GetInNode() ;
2327 #if SuccessActionTrace
2328       cdebug << pthread_self() << "/" << ThreadNo() << " Successed_SuccessAction " << Name() << " will Loop to HeadNode "
2329              << aLabelNode->Name() << " from port " << anInPort->PortName() << endl ;
2330 #endif
2331       aLabelNode->SetWaitingStates( this ) ;
2332 // JR 07.01.2005 Debug : Open the Gate of the coupledNode closed by SetWaitingStates
2333       GraphBase::OutPort * anOutPort = aLabelNode->GetChangeNodeInGate()->GetOutPort() ;
2334       if ( anOutPort ) {
2335 //JR 21.02.2005 Debug Memory leak :        CORBA::Any * anAny = new CORBA::Any() ;
2336         CORBA::Any anAny = CORBA::Any() ;
2337 //JR 21.02.2005 Debug Memory leak :        *anAny <<= (long ) 1 ;
2338         anAny <<= (long ) 1 ;
2339         anOutPort->SetValue( anAny ) ;
2340         aLabelNode->GetChangeNodeInGate()->PortState( SUPERV::ReadyState ) ;
2341 //        delete anAny ;
2342       }
2343       for ( j = 0 ; j < aLabelNode->GetNodeInPortsSize() ; j++ ) {
2344         const GraphBase::InPort * anInPort = aLabelNode->GetNodeInPort( j ) ;
2345         if ( anInPort->GetOutPort() ) {
2346 #if SuccessActionTrace
2347           cdebug << aLabelNode->Name() << "(" << anInPort->PortName() << ") value : "
2348                  << anInPort->GetOutPort()->NodeName() << "(" << anInPort->GetOutPort()->PortName() << ")"
2349                  << endl ;
2350 #endif
2351         }
2352       }
2353 //PAL8176 ==> PAL8516
2354 //JR 24.03.2005 Debug : the number of OutPorts of a GOTONode and of InPorts of its linked
2355 //                      InLine node must be the same
2356       if ( GetNodeOutPortsSize() != aLabelNode-> GetNodeInPortsSize() ) {
2357         cdebug << pthread_self() << "/" << ThreadNo()
2358                << " Successed_SuccessAction # number of ports " << GetNodeOutPortsSize()
2359                << " != " << aLabelNode-> GetNodeInPortsSize() << endl ;
2360         SendEvent( GraphExecutor::ErrorEvent ) ;
2361         return 0 ;
2362       }
2363       else {
2364         for ( j = 0 ; j < GetNodeOutPortsSize() ; j++ ) {
2365           GraphBase::OutPort * aBusParamOutPort = GetChangeNodeOutPort( j ) ;
2366           if ( !aBusParamOutPort->IsGate() ) {
2367             GraphBase::InPort * aBusParamChangeInPort = NULL ;
2368             if ( aBusParamOutPort->IsLoop() ) {
2369 // For EndLoop do not copy EndLoop(DoLoop) in Loop(InLoop)
2370 //            aBusParamChangeInPort = aLabelNode->GetChangeNodeInLoop() ;
2371             }
2372             else {
2373               aBusParamChangeInPort = aLabelNode->GetChangeInPort( aBusParamOutPort->PortName() ) ;
2374             }
2375             if ( aBusParamChangeInPort ) {
2376               aBusParamChangeInPort->ChangeOutPort( aBusParamOutPort ) ;
2377 #if SuccessActionTrace
2378               cdebug << pthread_self() << "/" << ThreadNo() << " Successed_SuccessAction " << Name() << " ChangeOutPort to HeadNode "
2379                      << aLabelNode->Name() << "(" << aBusParamChangeInPort->PortName() << ") from port "
2380                      << aBusParamOutPort->PortName() << endl ;
2381 #endif
2382             }
2383             else if ( IsGOTONode() ) {
2384 //PAL8176 ==> PAL8516
2385 //JR 24.03.2005 Debug : the names of OutPorts of a GOTONode and of InPorts of its linked
2386 //                      InLine node must be the same
2387               cdebug << pthread_self() << "/" << ThreadNo()
2388                      << " Successed_SuccessAction # names of ports "
2389                      << aBusParamOutPort->PortName() << endl ;
2390               SendEvent( GraphExecutor::ErrorEvent ) ;
2391               return 0 ;
2392             }
2393           }
2394         }
2395       }
2396     }
2397
2398 //JR 15.04.2005 Debug PAL8624 RetroConception :
2399 // THERE IS ONLY ONE NODE COUPLED TO A GOTONODE OR AN ENDLOOPNODE BUT Mutex/Lock for consistency
2400     if ( aLabelNode ) {
2401       const GraphBase::InPort * aGateInPort = aLabelNode->GetNodeInGate() ;
2402       if ( aGateInPort ) {
2403         if ( aGateInPort->GetOutPort() ) {
2404 //JR 21.02.2005 Debug Memory leak :          aGateInPort->GetOutPort()->Value( aGateOutPort->Value() ) ;
2405 //JR 30.03.2005          aGateInPort->GetOutPort()->Value( *aGateOutPort->Value() ) ;
2406           aGateInPort->GetOutPort()->SetValue( aGateOutPort->Value() ) ;
2407         }
2408 //JR 15.04.2005 Debug PAL8624 RetroConception :
2409         if ( !aLabelNode->SendSomeDataReady( Name() ) ) {
2410           cdebug << pthread_self() << "/" << ThreadNo() << " Successed_SuccessAction "
2411                  << Name() << " SendSomeDataReady to " << aLabelNode->Name() << " ERROR"
2412                  << endl ;
2413           return 0 ;
2414         }
2415         if ( aLabelNode->HasAllDataReady() ) {
2416           aLabelNode->ThreadNo( pthread_self() ) ;
2417           aLabelNode->CreateNewThread( false ) ;
2418           aLabelNode->RewindStack( RewindStack() ) ;
2419           aLabelNode->HasAllDataReady( false ) ;
2420           res = aLabelNode->SendEvent( GraphExecutor::AllDataReadyEvent ); // ==> Ready to execute
2421         }
2422       }
2423       else {
2424         cdebug << pthread_self() << "/" << ThreadNo() << " ERROR in Successed_SuccessAction of " << Name()
2425                << " NO port " << aGateOutPort->PortName() << " in "
2426                << aLabelNode->Name() << endl;
2427       }
2428     }
2429   }
2430
2431 //JR Step B
2432 //==================================================
2433 // JR 09.02.2005 : this is not a EndLoop or a GOTO :
2434 //==================================================
2435   else { // Not a EndLoop or a GOTO
2436 #if SuccessActionTrace
2437     cdebug << ThreadNo() << " Successed_SuccessAction of " << Name()
2438            << " with " << LinkedNodesSize() << " linked nodes :" ;
2439     for ( i = 0 ; i < LinkedNodesSize() ; i++ ) {
2440       cdebug << " " << LinkedNodes( i )->Name() ;
2441     }
2442     cdebug << endl;
2443 #endif
2444 //JR 15.04.2005 Debug PAL8624 RetroConception :
2445 // If this is a LoopNode and if DoLoopPort == false, we go directly to the EndOfLoopNode and
2446 // we do not activate Nodes within the loop
2447     bool IgnoreForEndLoop = false ;
2448 // If this is a SwitchNode and if DefaultOutPort == true, we do not activate Nodes within Switch
2449 // We activate directly the EnSwitch
2450 // BUT the NotSwitchBranch(es) are NOT activated :
2451     bool IgnoreForDefaultSwitch = false ;
2452     if ( IsLoopNode() ) {
2453       GraphBase::OutPort * fromLoopOutPort = GetChangeNodeOutLoop() ;
2454       if ( !fromLoopOutPort->BoolValue() ) { // Ne pas faire la boucle
2455         IgnoreForEndLoop = true ;
2456       }
2457     }
2458     else if ( IsSwitchNode() ) {
2459       const GraphBase::OutPort * anOutGatePort = GetNodeOutGate() ;
2460       if ( anOutGatePort->BoolValue() && anOutGatePort->InPortsSize() ) { // DefaultPort is activated
2461 // The DefaultOutPort of that SwitchNode is true and is connected
2462         IgnoreForDefaultSwitch = true ;
2463       }
2464     }
2465
2466     for ( i = 0 ; i < LinkedNodesSize() ; i++ ) {
2467 //JR 15.04.2005 Debug PAL8624 RetroConception :
2468 // If this is a LoopNode and if DoLoopPort == false, we go directly to the EndOfLoopNode and
2469 // we do not activate Nodes within the loop
2470 //      bool IgnoreForEndLoop = false ;
2471 // If this is a SwitchNode and if DefaultOutPort == true, we do not activate Nodes within Switch
2472 // We activate directly the EnSwitch
2473 // BUT the NotSwitchBranch(es) are NOT activated :
2474 //      bool IgnoreForDefaultSwitch = false ;
2475       GraphBase::ComputingNode * aComputingNode ;
2476       aComputingNode = (GraphBase::ComputingNode * ) LinkedNodes( i ) ;
2477       toNode = (GraphExecutor::InNode *) aComputingNode->GetInNode() ;
2478 #if SuccessActionTrace
2479       cdebug << pthread_self() << "/" << ThreadNo() << " Successed_SuccessAction of " << Name()
2480              << " [" << i << "] " << LinkedNodes( i )->Name() << " toNode " << toNode
2481              << " IgnoreForEndLoop " << IgnoreForEndLoop ;
2482       if ( toNode ) {
2483         cdebug << " " << toNode->Kind() << endl ;
2484       }
2485 #endif
2486 //JR 15.04.2005 Debug PAL8624 RetroConception :
2487       if ( toNode ) {
2488 //JR 18.05.2005 : we must lock because of concurrent SendEvent if NotAllDataReady :
2489         toNode->LockDataReady() ;
2490         if ( IsComputingNode() && toNode->IsInLineNode() ) {
2491           GraphBase::InPort * toGateInPort = toNode->GetChangeNodeInGate() ;
2492           toGateInPort->PortState( SUPERV::ReadyState ) ;
2493           GraphBase::OutPort * GateOutPort = toGateInPort->GetOutPort() ;
2494           if ( GateOutPort ) {
2495             GateOutPort->PortStatus( DataConnected );
2496             GateOutPort->PortState( SUPERV::ReadyState ) ;
2497             GateOutPort->PortDone( true ) ;
2498           }
2499         }
2500 //JR 15.04.2005 Debug PAL8624 RetroConception :
2501         if ( IsLoopNode() ) {
2502 //          GraphBase::OutPort * fromLoopOutPort = GetChangeNodeOutLoop() ;
2503 //          if ( !fromLoopOutPort->BoolValue() ) { // Ne pas faire la boucle
2504 //            if ( strcmp( toNode->Name() , CoupledNode()->Name() ) ) {
2505           if ( IgnoreForEndLoop && !strcmp( toNode->Name() , CoupledNode()->Name() ) ) {
2506 //              IgnoreForEndLoop = true ;
2507 //          }
2508 //            else { // toNode is the EndLoopNode
2509             GraphBase::InPort * toLoopInPort ;
2510             toLoopInPort = toNode->GetChangeNodeInLoop() ;
2511             if ( toLoopInPort->PortState() != SUPERV::ReadyState ) {
2512               toLoopInPort->PortState( SUPERV::ReadyState ) ;
2513             }
2514           }
2515         }
2516 //JR 15.04.2005 Debug PAL8624 RetroConception :
2517 //        else if ( IsSwitchNode() ) {
2518 //          const GraphBase::OutPort * anOutGatePort = GetNodeOutGate() ;
2519 //          if ( anOutGatePort->BoolValue() && anOutGatePort->InPortsSize() ) { // DefaultPort is activated
2520 // The DefaultOutPort of that SwitchNode is true and is connected
2521 //            IgnoreForDefaultSwitch = true ;
2522 //        }
2523 //        }
2524         else if ( toNode->IsInLineNode() ) {
2525           int j ;
2526           for ( j = 0 ; j < toNode->GetNodeInPortsSize() ; j++ ) {
2527             toNode->GetChangeNodeInPort( j )->InitialOutPort() ;
2528           }
2529         }
2530
2531         bool activatetoNode = true ;
2532 //We have to execute the loop :
2533         if ( !IgnoreForEndLoop ) {
2534 //The loop is not finished :
2535           if (  toNode->IsLoopNode() ) {
2536 //We enter in a new loop :
2537             GraphBase::InPort * toLoopInPort = toNode->GetChangeNodeInLoop() ;
2538             toLoopInPort->PortState( SUPERV::ReadyState ) ;
2539             GraphBase::OutPort * LoopOutPort = toLoopInPort->GetOutPort() ;
2540             LoopOutPort->PortStatus( DataConnected );
2541             LoopOutPort->PortState( SUPERV::ReadyState ) ;
2542             LoopOutPort->PortDone( true ) ;
2543 //JR 21.02.2005 Debug Memory leak :          CORBA::Any * anAny = new CORBA::Any() ; // InitLoop
2544             CORBA::Any anAny = CORBA::Any() ; // InitLoop
2545 //JR 21.02.2005 Debug Memory leak :          *anAny <<= (long ) 1 ;
2546             anAny <<= (long ) 1 ;
2547             LoopOutPort->SetValue( anAny ) ;
2548             int j ;
2549             for ( j = 0 ; j < toNode->GetNodeInPortsSize() ; j++ ) {
2550               toNode->GetChangeNodeInPort( j )->InitialOutPort() ;
2551             }
2552           }
2553         }
2554 //The loop is finished :
2555         else if ( IsLoopNode() ) {
2556           if ( toNode->IsEndLoopNode() ) {
2557 //Not the corresponding EndLoopNode :
2558             if ( strcmp( toNode->Name() , CoupledNode()->Name() ) ) {
2559               cdebug << pthread_self() << "/" << ThreadNo()
2560                      << " Successed_SuccessAction NO activate EndLoopNode " << toNode->Name()
2561                      << endl ;
2562               activatetoNode = false ;
2563             }
2564           }
2565 //Not a EndLoopNode :
2566           else {
2567             cdebug << pthread_self() << "/" << ThreadNo()
2568                    << " Successed_SuccessAction NO activate node " << toNode->Name() << endl ;
2569             activatetoNode = false ;
2570           }
2571         }
2572 // If the DefaultPort of that SwitchNode is connected to the DefaultPort of the EndSwitchNode
2573 // the NotSwitchBranch(es) are NOT activated :
2574 // If the DefaultPort of that SwitchNode is connected to SwitchBranch(es)
2575 // the NotSwitchBranch(es) are NOT activated :
2576         if ( IgnoreForDefaultSwitch ) {
2577 //We have to activate Default to EndSwitchNode
2578 #if SuccessActionTrace
2579           cdebug << pthread_self() << "/" << ThreadNo() << " Successed_SuccessAction search "
2580                  << toNode->Name() << " among linked nodes to DefaultPort of " << Name()
2581                  << "IgnoreForDefaultSwitch" << IgnoreForDefaultSwitch << endl ;
2582 #endif
2583           activatetoNode = false ;
2584           const GraphBase::OutPort * anOutGatePort = GetNodeOutGate() ;
2585           const GraphBase::InPort * anInPort = NULL ;
2586           int j ;
2587           for ( j = 0 ; j < anOutGatePort->InPortsSize() ; j++ ) {
2588             anInPort = anOutGatePort->InPorts( j ) ;
2589             const GraphBase::ComputingNode * aNode ;
2590             aNode = _OutNode->Graph()->GetGraphNode( anInPort->NodeName() ) ;
2591             if ( aNode ) {
2592 #if SuccessActionTrace
2593               cdebug << pthread_self() << "/" << ThreadNo() << " Successed_SuccessAction try "
2594                      << aNode << " " << aNode->Name() << " == " << toNode << " " << toNode->Name()
2595                      << endl ;
2596 #endif
2597             }
2598             if ( aNode && (const GraphBase::ComputingNode * ) toNode->ComputingNode() == aNode ) {
2599 // toNode is connected to the DefaultPort of that SwitchNode :
2600               cdebug << pthread_self() << "/" << ThreadNo()
2601                      << " Successed_SuccessAction activate node " << aNode->Name() << endl ;
2602               activatetoNode = true ;
2603               break ;
2604             }
2605             else {
2606               cdebug << pthread_self() << "/" << ThreadNo()
2607                      << " Successed_SuccessAction NO activate node " << aNode->Name() << endl ;
2608             }
2609           }
2610         }
2611 //JR 19.04.2005 Debug : Do not activate the EndSwitchNode if DefaultGate is close.
2612 //JR 20.04.2005 : it is false : an outport of the SwitchNode may be connected to an
2613 //                              input port of the EndSwitchNode
2614         if ( activatetoNode ) {
2615 #if SuccessActionTrace
2616           cdebug << pthread_self() << "/" << ThreadNo() << " Successed_SuccessAction "
2617                  << toNode->Name() << "->SendSomeDataReady( " << Name() << " )" << endl ;
2618 #endif
2619           if ( !toNode->SendSomeDataReady( Name() ) ) {
2620             cdebug << pthread_self() << "/" << ThreadNo() << " Successed_SuccessAction "
2621                  << Name() << " SendSomeDataReady to " << toNode->Name() << " ERROR"
2622                  << endl ;
2623             return 0 ;
2624           }
2625         }
2626         toNode->UnLockDataReady() ;
2627       }
2628     }
2629
2630 //PAL8517
2631 //JR 10.02.2005 : Debug at the end of execution of a SwitchNode :
2632 // Here after we may start execution of only one SwitchBranch or of the Default
2633 // But with activation of only one SwitchBranch we may activate several nodes of that SwitchBranch and
2634 // we may activate several nodes of NotSwitchBranch ( a NotSwitchBranch is a Branch of the Switch
2635 // where GatePorts of Nodes are not connected ; that Branches are always executed for each of SwitchBranch
2636 // BUT are not executed when Default is activated).
2637 // So the bug is that all input ports of the corresponding EndSwitchNode must have the status NOTDONE !
2638 // (Only if Default OutPort is closed and Default InPort is closed)
2639     if ( IsSwitchNode() ) {
2640       GraphBase::InLineNode * anEndSwitchNode = GOTONode()->CoupledNode() ;
2641       if ( !GetNodeOutGate()->BoolValue() && anEndSwitchNode->GetNodeInGate()->GetOutPort() &&
2642            !anEndSwitchNode->GetNodeInGate()->GetOutPort()->BoolValue() ) {
2643 #if SuccessActionTrace
2644         cdebug << pthread_self() << "/" << ThreadNo() << " Successed_SuccessAction " << anEndSwitchNode->Name()
2645                << " reset of InPort()->OutPort()->Done flag in EndSwitch" << endl ;
2646 #endif
2647         int i ;
2648         for ( i = 0 ; i < anEndSwitchNode->GetNodeInPortsSize() ; i++ ) {
2649           GraphBase::OutPort * anOutPort = anEndSwitchNode->GetChangeNodeInPort( i )->GetOutPort() ;
2650 //PAL8519
2651 //JR 08.03.2005 Debug : update of state only if not a StreamPort
2652           if ( anOutPort && strcmp( anOutPort->NodeName() , Name() ) &&
2653                !anOutPort->IsDataStream() ) {
2654 #if SuccessActionTrace
2655             cdebug << pthread_self() << "/" << ThreadNo() << " Successed_SuccessAction "
2656                    << anEndSwitchNode->Name() << " InPort "
2657                    << anEndSwitchNode->GetChangeNodeInPort( i )->PortName() << " NOTDONE from "
2658                    << anOutPort->NodeName() << " " << anOutPort->PortName() << endl ;
2659 #endif
2660             anEndSwitchNode->GetChangeNodeInPort( i )->PortState( SUPERV::WaitingState ) ;
2661             anEndSwitchNode->GetChangeNodeInPort( i )->GetOutPort()->PortDone( false ) ;
2662           }
2663           else {
2664 #if SuccessActionTrace
2665             cdebug << pthread_self() << "/" << ThreadNo() << " Successed_SuccessAction "
2666                    << anEndSwitchNode->Name() << " InPort "
2667                    << anEndSwitchNode->GetChangeNodeInPort( i )->PortName() << " NOT Changed : directly from "
2668                    << anOutPort->NodeName() << " " << anOutPort->PortName() << endl ;
2669 #endif
2670           }
2671         }
2672       }
2673       else {
2674 #if SuccessActionTrace
2675         cdebug << pthread_self() << "/" << ThreadNo() << " Successed_SuccessAction " << Name()
2676                << " " << Kind() << " OutGate->Value " << GetNodeOutGate()->BoolValue()
2677                << " NO reset of InPort()->OutPort()->Done flag in EndSwitch" << endl ;
2678 #endif
2679       }
2680     }
2681
2682 //JR 15.04.2005 Debug PAL8624 RetroConception :
2683     for ( i = 0 ; i < LinkedNodesSize() ; i++ ) {
2684       GraphBase::ComputingNode * aComputingNode ;
2685       aComputingNode = (GraphBase::ComputingNode * ) LinkedNodes( i ) ;
2686       toNode = (GraphExecutor::InNode *) aComputingNode->GetInNode() ;
2687       if ( toNode ) { // Only Not DataFlowNode :
2688         toNode->LockDataReady() ;
2689         if ( toNode->HasAllDataReady() ) {
2690           SomeDataNodes.push_back( toNode ) ;
2691           toNode->HasAllDataReady( false ) ;
2692 #if SuccessActionTrace
2693           cdebug << pthread_self() << "/" << ThreadNo() << " Successed_SuccessAction "
2694                  << Name() << " push "
2695                  << toNode->Name() << " " << SomeDataNodes.size() << endl ;
2696 #endif
2697         }
2698         toNode->UnLockDataReady() ;
2699       }
2700     }
2701
2702 // firsttoNode : node that has the same ThreadNo() as the current node and that have to be activated
2703 // firstzeroNode : node that has a null ThreadNo() and that have to be activated
2704 //JR 15.04.2005 Debug PAL8624 RetroConception :
2705     while ( SomeDataNodes.size() > 1 ) {
2706       GraphExecutor::InNode *aNode = SomeDataNodes.front() ;
2707       SomeDataNodes.pop_front() ;
2708 #if SuccessActionTrace
2709       cdebug << pthread_self() << "/" << ThreadNo()
2710              << " Successed_SuccessAction pop size "
2711              << SomeDataNodes.size() << " " << aNode->Name() << endl ;
2712       cdebug << pthread_self() << "/" << ThreadNo() << " " << aNode->Name()
2713              << " Successed_SuccessAction poped and will start in a new thread" << endl ;
2714 #endif
2715       aNode->CreateNewThread( true ) ;
2716       _OutNode->IncrCreatedThreads() ;
2717 //JR 15.04.2005 Debug PAL8624 RetroConception :
2718       res = aNode->SendEvent( GraphExecutor::AllDataReadyEvent ); // ==> Ready to execute
2719     }
2720
2721     if ( SomeDataNodes.size() ) {
2722       firsttoNode = SomeDataNodes.front() ;
2723       SomeDataNodes.pop_front() ;
2724     }
2725
2726     if ( firsttoNode ) {
2727 #if SuccessActionTrace
2728       cdebug << pthread_self() << "/" << ThreadNo()
2729              << " Successed_SuccessAction start firsttoNode "
2730              << SomeDataNodes.size() << " " << firsttoNode->Name() << endl ;
2731 #endif
2732 //      firsttoNode->CreateNewThreadIf( false ) ;
2733       firsttoNode->CreateNewThread( false ) ;
2734       firsttoNode->RewindStack( RewindStack() ) ;
2735       if ( firsttoNode->State() == GraphExecutor::SuccessedState ) {
2736 #if SuccessActionTrace
2737         cdebug << pthread_self() << "/" << ThreadNo() << " " << Name()
2738                << " : " << firsttoNode->Name() << " "
2739                << Automaton()->StateName( firsttoNode->State() )
2740                << " --> DataWaitingState for Thread "
2741                << firsttoNode->ThreadNo() << endl ;
2742 #endif
2743         firsttoNode->State( GraphExecutor::DataWaitingState ) ;
2744       }
2745       firsttoNode->ThreadNo( pthread_self() ) ;
2746 // On continue avec le meme thread
2747       ThreadNo( 0 ) ;
2748 #if SuccessActionTrace
2749       cdebug << pthread_self() << "/" << ThreadNo() << " Successed_SuccessAction " << Name()
2750              << " for firsttoNode " << firsttoNode->Name()
2751              << " " << Automaton()->StateName( firsttoNode->State() ) << endl ;
2752 #endif
2753 //JR 15.04.2005 Debug PAL8624 RetroConception :
2754 //No creation of thread and with LockDataReady an other node in an other thread cannot be
2755 // waiting for that lock ( if it was the case we could not find AllDataReady for firsttoNode
2756       res = firsttoNode->SendEvent( GraphExecutor::AllDataReadyEvent ); // ==> Ready to execute
2757     }
2758     else {
2759 #if SuccessActionTrace
2760       cdebug << ThreadNo() << " Successed_SuccessAction " << Name()
2761              << " NO DataReady ==> ThreadNo( 0 ) firsttoNode == NULL" << endl ;
2762 #endif
2763       ThreadNo( 0 ) ;
2764     }
2765   }
2766 #if SuccessActionTrace
2767   cdebug_out << pthread_self() << "/" << ThreadNo()
2768              << " Successed_SuccessAction " << Name() << endl;
2769 #endif
2770   return 1 ;
2771 }
2772
2773 #define SendSomeDataReadyTrace 1
2774 bool GraphExecutor::InNode::SendSomeDataReady( char * FromNodeName ) {
2775   bool RetVal = false ;
2776   if ( IsDataFlowNode() ) {
2777 #if SendSomeDataReadyTrace
2778     cdebug_in << ThreadNo() << "InNode::SendSomeDataReady " << FromNodeName
2779               << " send Result to graph " << Name() << endl;
2780 #endif
2781   }
2782   else {
2783 #if SendSomeDataReadyTrace
2784     cdebug_in << pthread_self() << "/" << ThreadNo() << FromNodeName
2785               << " GraphExecutor::InNode::SendSomeDataReady to " << Name() << " State "
2786               << Automaton()->StateName( State() ) << endl;
2787 #endif
2788     if ( State() == GraphExecutor::SuccessedState ||
2789          State() == GraphExecutor::SuspendedSuccessedState ||
2790          State() == GraphExecutor::SuspendedSuccessedToReStartState ) {
2791 #if SendSomeDataReadyTrace
2792       cdebug << ThreadNo() << " " << FromNodeName
2793              << " : " << Name() << " " << Automaton()->StateName( State() )
2794              << " --> DataWaitingState for Thread "
2795              << ThreadNo() << " " << endl ;
2796 #endif
2797       State( GraphExecutor::DataWaitingState ) ;
2798     }
2799 // We begin that LoopNode if SendSomeDataReady does not come from the corresponding EndLoopNode
2800     if ( IsLoopNode() && strcmp( LoopNode()->CoupledNodeName() , FromNodeName ) ) {
2801 #if SendSomeDataReadyTrace
2802       cdebug << ThreadNo() << "InNode::SendSomeDataReady " << Name() << " Set _InitLoop from "
2803              << FromNodeName << endl ;
2804 #endif
2805       _InitLoop = true ;
2806     }
2807 #if SendSomeDataReadyTrace
2808     cdebug << "SendEvent( SomeDataReadyEvent )" << endl ;
2809 #endif
2810 //JR 15.04.2005 Debug PAL8624 RetroConception :
2811     DataFromNode( FromNodeName ) ;
2812 //    RetVal = !SendEvent( GraphExecutor::SomeDataReadyEvent );
2813     RetVal = SendEvent( GraphExecutor::SomeDataReadyEvent );
2814 //JR 15.04.2005 Debug PAL8624 RetroConception :
2815   }
2816 #if SendSomeDataReadyTrace
2817   cdebug_out << pthread_self() << "/" << ThreadNo() << FromNodeName
2818              << " GraphExecutor::InNode::SendSomeDataReady to " << Name() << " State "
2819              << Automaton()->StateName( State() ) << " " << RetVal << endl;
2820 #endif
2821   return RetVal ;
2822 }
2823
2824 int GraphExecutor::InNode::Errored_ErrorAction() {
2825   cdebug << ThreadNo() << " Errored_ErrorAction " << Name()
2826          << " will pthread_exit" << endl;
2827   DoneAction() ;
2828   return 1 ;
2829 }
2830
2831 int GraphExecutor::InNode::Successed_SuspendAction() {
2832   cdebug << ThreadNo() << " Successed_SuspendAction -->Suspend " << Name()
2833          << " Threads " << _OutNode->Threads() << " SuspendedThreads "
2834          << _OutNode->SuspendedThreads() << endl;
2835   _OutNode->PushEvent( this , GraphExecutor::SuspendedSuccessedEvent ,
2836                        GraphExecutor::SuspendedSuccessedState ) ; 
2837   DoneAction() ;
2838   GraphExecutor::InNode * aReStartNode = SuspendAction() ;
2839   cdebug << ThreadNo() << " Successed_SuspendAction Resumed " << Name() ;
2840   if ( aReStartNode ) {
2841     _aReStartNode = NULL ;
2842     cdebug << " for " << aReStartNode->Name() << endl;
2843     aReStartNode->SendEvent( _aReStartEvent ) ;
2844   }
2845   else {
2846     cdebug << endl;
2847     SendEvent( GraphExecutor::ResumeEvent ) ;
2848   }
2849   return 1 ;
2850 }
2851
2852 int GraphExecutor::InNode::Errored_SuspendAction() {
2853   cdebug << ThreadNo() << " Errored_SuspendAction -->Suspend " << Name()
2854          << " Threads " << _OutNode->Threads() << " SuspendedThreads "
2855          << _OutNode->SuspendedThreads() << endl;
2856   _OutNode->PushEvent( this , GraphExecutor::SuspendedErroredEvent ,
2857                        GraphExecutor::SuspendedErroredState ) ; 
2858   DoneAction() ;
2859   GraphExecutor::InNode * aReStartNode = SuspendAction() ;
2860   cdebug << ThreadNo() << " Errored_SuspendAction Resumed " << Name()
2861          << endl;
2862   if ( aReStartNode ) {
2863     _aReStartNode = NULL ;
2864     aReStartNode->SendEvent( _aReStartEvent ) ;
2865   }
2866   else {
2867     SendEvent( GraphExecutor::ResumeEvent ) ;
2868   }
2869   return 1 ;
2870 }
2871
2872 int GraphExecutor::InNode::SuspendedSuccessed_ResumeAction() {
2873   cdebug << ThreadNo() << " SuspendedSuccessed_ResumeAction " << Name() << endl;
2874 //  ResumeAction() ;
2875   _OutNode->PushEvent( this , GraphExecutor::ResumedSuccessedEvent ,
2876                        GraphExecutor::ResumedSuccessedState ) ; 
2877   SendEvent( ResumedSuccessedEvent ) ;
2878   return 1 ;
2879 }
2880
2881 int GraphExecutor::InNode::SuspendedErrored_ResumeAction() {
2882   cdebug << ThreadNo() << " SuspendedErrored_ResumeAction " << Name() << endl;
2883 //  ResumeAction() ;
2884   _OutNode->PushEvent( this , GraphExecutor::ResumedErroredEvent ,
2885                        GraphExecutor::ResumedErroredState ) ; 
2886   SendEvent( ResumedErroredEvent ) ;
2887   return 1 ;
2888 }
2889
2890 int GraphExecutor::InNode::Successed_KillAction() {
2891   KillAction() ;
2892   _OutNode->PushEvent( this , GraphExecutor::KilledEvent ,
2893                        GraphExecutor::KilledSuccessedState ) ; 
2894   cdebug << ThreadNo() << " Successed_KillAction " << Name() << endl;
2895   return 1 ;
2896 }
2897
2898 int GraphExecutor::InNode::Errored_KillAction() {
2899   KillAction() ;
2900   _OutNode->PushEvent( this , GraphExecutor::KilledEvent ,
2901                        GraphExecutor::KilledErroredState ) ; 
2902   cdebug << ThreadNo() << " Errored_KillAction " << Name() << endl;
2903   return 1 ;
2904 }
2905
2906 int GraphExecutor::InNode::Successed_StopAction() {
2907   StopAction() ;
2908   _OutNode->PushEvent( this , GraphExecutor::StoppedEvent ,
2909                        GraphExecutor::StoppedSuccessedState ) ; 
2910   cdebug << ThreadNo() << " Successed_StopAction " << Name() << endl;
2911   return 1 ;
2912 }
2913
2914 int GraphExecutor::InNode::Errored_StopAction() {
2915   StopAction() ;
2916   _OutNode->PushEvent( this , GraphExecutor::StoppedEvent ,
2917                        GraphExecutor::StoppedErroredState ) ; 
2918   cdebug << ThreadNo() << " Errored_StopAction " << Name() << endl;
2919   return 1 ;
2920 }
2921
2922 int GraphExecutor::InNode::SuspendedSuccessed_ReStartAction() {
2923   cdebug << ThreadNo() << " SuspendedSuccessed_ReStartAction " << Name() << endl;
2924   _OutNode->PushEvent( this , GraphExecutor::ReStartedEvent ,
2925                        GraphExecutor::ReStartedState ) ;
2926   int i ;
2927   for ( i = 0 ; i < GetNodeInPortsSize() ; i++ ) {
2928     GetChangeNodeInPort( i )->PortState( SUPERV::ReadyState ) ;
2929   }
2930   SendEvent( ExecuteEvent ) ;
2931   cdebug << ThreadNo() << " SuspendedSuccessed_ReStartAction "  << Name() << endl;
2932   return 1 ;
2933 }
2934
2935 int GraphExecutor::InNode::SuspendedErrored_ReStartAction() {
2936   cdebug << ThreadNo() << " SuspendedErrored_ReStartAction " << Name() << endl;
2937   _OutNode->PushEvent( this , GraphExecutor::ReStartedEvent ,
2938                        GraphExecutor::ReStartedState ) ; 
2939   int i ;
2940   for ( i = 0 ; i < GetNodeInPortsSize() ; i++ ) {
2941     GetChangeNodeInPort( i )->PortState( SUPERV::ReadyState ) ;
2942   }
2943   SendEvent( ExecuteEvent ) ;
2944   cdebug << ThreadNo() << " SuspendedErrored_ReStartAction "  << Name() << endl;
2945   return 1 ;
2946 }
2947
2948 int GraphExecutor::InNode::SuspendedSuccessed_ReStartAndSuspendAction() {
2949   cdebug << ThreadNo() << " SuspendedSuccessed_ReStartAndSuspendAction " << Name()
2950          << endl;
2951   _OutNode->PushEvent( this , GraphExecutor::ReStartedAndSuspendEvent ,
2952                        GraphExecutor::ReStartedState ) ; 
2953   State( GraphExecutor::DataWaitingState ) ;
2954   if ( !Suspend() ) {
2955     cdebug << "InNode::Suspend() Node " << Name() << endl ;
2956     return false ;
2957   }
2958   else if ( SendEvent( GraphExecutor::SomeDataReadyEvent ) ) {
2959     cdebug << "InNode::SendEvent( SomeDataReadyEvent ) Node "
2960            << Name() << endl ;
2961     return false ;
2962   }
2963   cdebug << ThreadNo() << " SuspendedSuccessed_ReStartAndSuspendAction "  << Name()
2964          << endl;
2965   return 1 ;
2966 }
2967
2968 int GraphExecutor::InNode::SuspendedErrored_ReStartAndSuspendAction() {
2969   cdebug << ThreadNo() << " SuspendedErrored_ReStartAndSuspendAction " << Name()
2970          << endl;
2971   _OutNode->PushEvent( this , GraphExecutor::ReStartedAndSuspendEvent ,
2972                        GraphExecutor::ReStartedState ) ; 
2973   State( GraphExecutor::DataWaitingState ) ;
2974   if ( !Suspend() ) {
2975     cdebug << "InNode::Suspend() Node " << Name() << endl ;
2976     return false ;
2977   }
2978   else if ( SendEvent( GraphExecutor::SomeDataReadyEvent ) ) {
2979     cdebug << "InNode::SendEvent( SomeDataReadyEvent ) Node "
2980            << Name() << endl ;
2981     return false ;
2982   }
2983   cdebug << ThreadNo() << " SuspendedErrored_ReStartAndSuspendAction "  << Name()
2984          << endl;
2985   return 1 ;
2986 }
2987
2988 #define InParametersSetTrace 1
2989 void GraphExecutor::InNode::InParametersSet( bool & Err ,
2990                                              int  nInParams ,
2991                                              ServicesAnyData * InParametersList ) {
2992   int i ;
2993 #if InParametersSetTrace
2994   cdebug << pthread_self() << "/" << ThreadNo() << " InParametersSet " << Name() << endl ;
2995 #endif
2996   for ( i = 0 ; i < nInParams ; i++ ) {
2997     ServicesAnyData D = InParametersList[i];
2998     GraphBase::InPort * anInPort = GetChangeNodeInPort(i) ;
2999     GraphBase::OutPort * theOutPort = anInPort->GetOutPort() ;
3000     if ( anInPort->IsGate() && theOutPort == NULL ) {
3001 #if InParametersSetTrace
3002       cdebug << ThreadNo() << " ArgIn" << i << " " << D.Name << " "
3003              << anInPort->GetServicesParameter().Parametertype
3004              << " is inactive. " << anInPort->Kind() << endl ;
3005 #endif
3006     }
3007     else if ( anInPort->PortState() == SUPERV::ReadyState ) {
3008       if ( anInPort->IsGate() ) {
3009 //JR 21.02.2005 Debug Memory leak :        CORBA::Any * anAny = new CORBA::Any() ;
3010         CORBA::Any anAny = CORBA::Any() ;
3011 //JR 21.02.2005 Debug Memory leak :        *anAny <<= (long ) 0 ;
3012         anAny <<= (long ) 0 ;
3013         theOutPort->SetValue( anAny ) ;
3014 //        delete anAny ;
3015       }
3016       if ( !anInPort->IsDataStream() &&
3017            !anInPort->IsDataConnected() ) {
3018         anInPort->PortState( SUPERV::WaitingState ) ;
3019       }
3020 //JR 18.02.2005 Debug Memory leak : delete does not destroy that string ...
3021 //      D.Name = CORBA::string_dup( anInPort->GetServicesParameter().Parametername ) ;
3022       D.Name = anInPort->PortName() ;
3023 //JR 30.03.2005      const CORBA::Any * AnyPtr = theOutPort->Value() ;
3024       const CORBA::Any AnyRef = theOutPort->Value() ;
3025 #if InParametersSetTrace
3026       cdebug << ThreadNo() << " ArgIn" << i << " " << anInPort->Kind() << " "
3027              << anInPort->PortState() << " " << D.Name << " "
3028              << anInPort->GetServicesParameter().Parametertype << endl ;
3029 #endif
3030 //JR 30.03.2005      D.Value = * AnyPtr ; // CORBA::Any
3031       D.Value = AnyRef ; // CORBA::Any
3032 //JR 18.02.2005 Debug Memory leak :       string _Type = CORBA::string_dup( anInPort->GetServicesParameter().Parametertype ) ;
3033 //      const char * Type = _Type.c_str() ;
3034       const char * Type = anInPort->GetServicesParameter().Parametertype ;
3035       switch ( D.Value.type()->kind() ) { // { string , long , double , objref }
3036       case CORBA::tk_string:
3037         char * t;
3038         D.Value >>= t;
3039 #if InParametersSetTrace
3040         cdebug << t << " (string)" ;
3041 #endif
3042         if ( !strcmp( Type , "string" ) ) {
3043         }
3044         else if ( !strcmp( Type , "boolean" ) ) {
3045           bool b ;
3046           long d ;
3047           sscanf( t , "%ld" , &d ) ;
3048           b = (bool ) d ;
3049           D.Value <<=  (CORBA::Any::from_boolean ) b ;
3050 //          theOutPort->Value( D.Value ) ;
3051         }
3052         else if ( !strcmp( Type , "char" ) ) {
3053           unsigned char c ;
3054           long d ;
3055           sscanf( t , "%ld" , &d ) ;
3056           c = (short ) d ;
3057           D.Value <<=  (CORBA::Any::from_char ) c ;
3058 #if InParametersSetTrace
3059           cdebug << "string '" << t << "' --> " << d << " --> char " << c ;
3060 #endif
3061 //          theOutPort->Value( D.Value ) ;
3062         }
3063         else if ( !strcmp( Type , "short" ) ) {
3064           short s ;
3065           long d ;
3066           sscanf( t , "%ld" , &d ) ;
3067           s = (short ) d ;
3068           D.Value <<=  s ;
3069 #if InParametersSetTrace
3070           cdebug << "string '" << t << "' --> " << d << " --> short " << s ;
3071 #endif
3072 //          theOutPort->Value( D.Value ) ;
3073         }
3074         else if ( !strcmp( Type , "int" ) || !strcmp( Type , "long" ) ) {
3075           long l ;
3076           sscanf( t , "%ld" , &l ) ;
3077           D.Value <<=  l ;
3078 #if InParametersSetTrace
3079           cdebug << "string '" << t << " --> long " << l ;
3080 #endif
3081 //          theOutPort->Value( D.Value ) ;
3082         }
3083         else if ( !strcmp( Type , "float" ) ) {
3084           double d ;
3085           sscanf( t , "%lf" , &d ) ;
3086           float f = d ;
3087           D.Value <<= f ;
3088 #if InParametersSetTrace
3089           cdebug << "string '" << t << "' --> " << setw(25) << setprecision(18) << d << " --> float " << " = "
3090                  << setw(25) << setprecision(18) << f ;
3091 #endif
3092 //          theOutPort->Value( D.Value ) ;
3093         }
3094         else if ( !strcmp( Type , "double" ) ) {
3095           double d ;
3096           sscanf( t , "%lf" , &d ) ;
3097           D.Value <<= d ;
3098 #if InParametersSetTrace
3099           cdebug << "string '" << t << " --> double " << setw(25) << setprecision(18) << d ;
3100 #endif
3101 //          theOutPort->Value( D.Value ) ;
3102         }
3103 //        else if ( !strcmp( Type , "objref" ) ) {
3104         else { // Default
3105           CORBA::Object_ptr ObjRef ;
3106           try {
3107             ObjRef = StringToObject( t ) ;
3108             D.Value <<= ObjRef ;
3109           }
3110           catch( ... ) {
3111             D.Value <<= CORBA::Object::_nil() ;
3112           }
3113 //          theOutPort->Value( D.Value ) ;
3114         }
3115 //        else {
3116 //          cdebug << " (other ERROR)" << endl ;
3117 //        }
3118 #if InParametersSetTrace
3119         cdebug << " --> call_kind " << D.Value.type()->kind() << endl ;
3120 #endif
3121         break;
3122       case CORBA::tk_long:
3123 #if InParametersSetTrace
3124         cdebug << ThreadNo() << " " << Name() << " ArgIn" << i << " " << D.Name << " "
3125                << anInPort->GetServicesParameter().Parametertype << " " << anInPort->Kind()
3126                << " " ;
3127         theOutPort->StringValue( *GraphBase::Base::_fdebug ) ;
3128         cdebug << endl ;
3129 #endif
3130         long l;
3131         D.Value >>= l;
3132 #if InParametersSetTrace
3133         cdebug << l << " (long)" << endl ;
3134 #endif
3135         if ( !strcmp( Type , "string" ) ) {
3136           char t[40] ;
3137           sprintf( t , "%ld" , l ) ;
3138           D.Value <<= t ;
3139 //          theOutPort->Value( D.Value ) ;
3140         }
3141         else if ( !strcmp( Type , "boolean" ) ) {
3142           bool b ;
3143           b = (bool ) l ;
3144           D.Value <<=  (CORBA::Any::from_boolean ) b ;
3145 //          theOutPort->Value( D.Value ) ;
3146         }
3147         else if ( !strcmp( Type , "char" ) ) {
3148           unsigned char c ;
3149           c = (unsigned char ) l ;
3150           D.Value <<=  (CORBA::Any::from_char ) c ;
3151 //          theOutPort->Value( D.Value ) ;
3152         }
3153         else if ( !strcmp( Type , "short" ) ) {
3154           short s ;
3155           s = (short ) l ;
3156           D.Value <<=  s ;
3157 //          theOutPort->Value( D.Value ) ;
3158         }
3159         else if ( !strcmp( Type , "int" ) || !strcmp( Type , "long" ) ) {
3160         }
3161         else if ( !strcmp( Type , "float" ) ) {
3162           float f ;
3163           f = (float ) l ;
3164           D.Value <<= f ;
3165 //          theOutPort->Value( D.Value ) ;
3166         }
3167         else if ( !strcmp( Type , "double" ) ) {
3168           double d ;
3169           d = (double ) l ;
3170           D.Value <<= d ;
3171 //          theOutPort->Value( D.Value ) ;
3172         }
3173 //        else if ( !strcmp( Type , "objref" ) ) {
3174         else { // Default
3175           D.Value <<= CORBA::Object::_nil() ;
3176 //          theOutPort->Value( D.Value ) ;
3177         }
3178 //        else {
3179 //          cdebug << " (other ERROR)" << endl ;
3180 //        }
3181 #if InParametersSetTrace
3182         cdebug << " --> call_kind " << D.Value.type()->kind() << endl ;
3183 #endif
3184         break;
3185       case CORBA::tk_double:
3186         double d;
3187         D.Value >>= d;
3188 #if InParametersSetTrace
3189         cdebug << d << " (double)" << endl ;
3190 #endif
3191         if ( !strcmp( Type , "string" ) ) {
3192           char t[40] ;
3193           sprintf( t , "%lf" , d ) ;
3194           D.Value <<= t ;
3195 //          theOutPort->Value( D.Value ) ;
3196         }
3197         else if ( !strcmp( Type , "boolean" ) ) {
3198           bool b ;
3199           b = (bool ) d ;
3200           D.Value <<=  (CORBA::Any::from_boolean ) b ;
3201 //          theOutPort->Value( D.Value ) ;
3202         }
3203         else if ( !strcmp( Type , "char" ) ) {
3204           unsigned char c ;
3205           c = (unsigned char ) d ;
3206           D.Value <<=  (CORBA::Any::from_char ) c ;
3207 //          theOutPort->Value( D.Value ) ;
3208         }
3209         else if ( !strcmp( Type , "short" ) ) {
3210           short s ;
3211           s = (short ) d ;
3212           D.Value <<=  s ;
3213 //          theOutPort->Value( D.Value ) ;
3214         }
3215         else if ( !strcmp( Type , "int" ) || !strcmp( Type , "long" ) ) {
3216           long l ;
3217           l = (long ) d ;
3218           D.Value <<= l ;
3219 //          theOutPort->Value( D.Value ) ;
3220         }
3221         else if ( !strcmp( Type , "float" ) ) {
3222           float f ;
3223           f = (float ) d ;
3224           D.Value <<= f ;
3225 //          theOutPort->Value( D.Value ) ;
3226         }
3227         else if ( !strcmp( Type , "double" ) ) {
3228         }
3229 //        else if ( !strcmp( Type , "objref" ) ) {
3230         else { // Default
3231           D.Value <<= CORBA::Object::_nil() ;
3232 //          theOutPort->Value( D.Value ) ;
3233         }
3234 //        else {
3235 //          cdebug << " (other ERROR)" << endl ;
3236 //        }
3237 #if InParametersSetTrace
3238         cdebug << " --> call_kind " << D.Value.type()->kind() << endl ;
3239 #endif
3240         break;
3241       case CORBA::tk_objref:
3242         if ( !strcmp( Type , "string" ) ) {
3243           CORBA::Object_ptr ObjRef ;
3244           char * retstr ;
3245           try {
3246             D.Value >>= ObjRef ;
3247             retstr = ObjectToString( ObjRef ) ;
3248             D.Value <<= retstr ;
3249 //            theOutPort->Value( D.Value ) ;
3250           }
3251           catch( ... ) {
3252             if ( i != 0 ) {
3253               Err = true ;
3254             }
3255             cdebug << "ToString( object ) Catched ERROR" << endl ;
3256           }
3257         }
3258         else if ( !strcmp( Type , "boolean" ) ) {
3259           bool b = 0 ;
3260           D.Value <<=  (CORBA::Any::from_boolean ) b ;
3261 //          theOutPort->Value( D.Value ) ;
3262         }
3263         else if ( !strcmp( Type , "char" ) ) {
3264           unsigned char c = 0 ;
3265           D.Value <<=  (CORBA::Any::from_char ) c ;
3266 //          theOutPort->Value( D.Value ) ;
3267         }
3268         else if ( !strcmp( Type , "short" ) ) {
3269           short s = 0 ;
3270           D.Value <<=  s ;
3271 //          theOutPort->Value( D.Value ) ;
3272         }
3273         else if ( !strcmp( Type , "int" ) || !strcmp( Type , "long" ) ) {
3274           long l = 0 ;
3275           D.Value <<= l ;
3276 //          theOutPort->Value( D.Value ) ;
3277         }
3278         else if ( !strcmp( Type , "float" ) ) {
3279           float f = 0 ;
3280           D.Value <<= f ;
3281 //          theOutPort->Value( D.Value ) ;
3282         }
3283         else if ( !strcmp( Type , "double" ) ) {
3284           double d = 0 ;
3285           D.Value <<= d ;
3286 //          theOutPort->Value( D.Value ) ;
3287         }
3288 //        else if ( !strcmp( Type , "objref" ) ) {
3289         else { // Default
3290           CORBA::Object_ptr obj ;
3291           char * retstr ;
3292           try {
3293             D.Value >>= obj ;
3294             retstr = ObjectToString( obj ) ;
3295 #if InParametersSetTrace
3296             cdebug << retstr << endl ;
3297 #endif
3298           }
3299           catch( ... ) {
3300             if ( i != 0 ) {
3301               Err = true ;
3302             }
3303             cdebug << "ToString( object ) Catched ERROR" << endl ;
3304           }
3305         }
3306 //        else {
3307 //          cdebug << " (other ERROR)" << endl ;
3308 //        }
3309 #if InParametersSetTrace
3310         cdebug << " --> call_kind " << D.Value.type()->kind() << endl ;
3311 #endif
3312         break;
3313       default:
3314         cdebug << " (other ERROR) " << D.Value.type()->kind() << endl ;
3315       }
3316     }
3317     else {
3318       cdebug << ThreadNo() << " In" << i << " : wrong state ERROR State "
3319              << anInPort->PortState() << " NameState "
3320              << Automaton()->StateName( anInPort->PortState() ) << " PortName "
3321              << anInPort->PortName() << " Parametername "
3322              << anInPort->GetServicesParameter().Parametername << endl ;
3323       Err = true ;
3324     }
3325     InParametersList[i] = D ;
3326   }
3327 }
3328
3329 void GraphExecutor::InNode::InOutParametersSet( int nOutParams ,
3330                                                 ServicesAnyData * OutParametersList ) {
3331 #if InParametersSetTrace
3332   cdebug << pthread_self() << "/" << ThreadNo() << " InOutParametersSet " << Name() << endl ;
3333 #endif
3334   int i ;
3335   for ( i = 0 ; i < nOutParams ; i++ ) {
3336     ServicesAnyData D = OutParametersList[i] ;
3337
3338 //JR 18.02.2005 Debug Memory leak : delete does not destroy that string ...
3339 //    D.Name = CORBA::string_dup(GetChangeNodeOutPort(i)->GetServicesParameter().Parametername);
3340     D.Name = GetChangeNodeOutPort(i)->PortName() ;
3341 //JR 18.02.2005 Debug Memory leak :     string _Type = CORBA::string_dup(GetChangeNodeOutPort(i)->GetServicesParameter().Parametertype) ;
3342     const char * Type = GetChangeNodeOutPort(i)->GetServicesParameter().Parametertype ;
3343 #if InParametersSetTrace
3344     bool OutDone = GetChangeNodeOutPort(i)->PortDone() ;
3345     cdebug << ThreadNo() << " ArgOut" << i << " " << D.Name << " PortDone( " << OutDone << " ) Type : "
3346            << Type << endl ;
3347 #endif
3348     if ( !strcmp( Type , "string" ) ) {
3349       D.Value <<= (char *) NULL ;
3350     }
3351     else if ( !strcmp( Type , "boolean" ) ) {
3352       bool b = 0 ;
3353       D.Value <<=  (CORBA::Any::from_boolean ) b ;
3354     }
3355     else if ( !strcmp( Type , "char" ) ) {
3356       unsigned char c = 0 ;
3357       D.Value <<=  (CORBA::Any::from_char ) c ;
3358     }
3359     else if ( !strcmp( Type , "short" ) ) {
3360       short s = 0 ;
3361       D.Value <<=  s ;
3362     }
3363     else if ( !strcmp( Type , "int" ) || !strcmp( Type , "long" ) ) {
3364       D.Value <<= (long ) 0 ;
3365     }
3366     else if ( !strcmp( Type , "float" ) ) {
3367       float f = 0 ;
3368       D.Value <<= f ;
3369     }
3370     else if ( !strcmp( Type , "double" ) ) {
3371       double d = 0 ;
3372       D.Value <<= d ;
3373     }
3374     else {
3375       D.Value <<= CORBA::Object::_nil() ;
3376     }
3377 #if InParametersSetTrace
3378     switch (D.Value.type()->kind()) { // { string , long , double , objref }
3379     case CORBA::tk_string:
3380       char * t;
3381       D.Value >>= t;
3382       cdebug << ThreadNo() << " " << t << "(string)" << endl ;
3383       break;
3384     case CORBA::tk_boolean:
3385       bool b ;
3386       D.Value >>= (CORBA::Any::to_boolean ) b;
3387       cdebug << ThreadNo() << " " << b << "(boolean)" << endl ;
3388       break;
3389     case CORBA::tk_char:
3390       unsigned char c ;
3391       D.Value >>= (CORBA::Any::to_char ) c;
3392       cdebug << ThreadNo() << " " << c << "(char)" << endl ;
3393       break;
3394     case CORBA::tk_short:
3395       short s;
3396       D.Value >>= s;
3397       cdebug << ThreadNo() << " " << s << "(short)" << endl ;
3398       break;
3399     case CORBA::tk_long:
3400       long l;
3401       D.Value >>= l;
3402       cdebug << ThreadNo() << " " << l << "(long)" << endl ;
3403       break;
3404     case CORBA::tk_float:
3405       float f;
3406       D.Value >>= f;
3407       cdebug << ThreadNo() << " " << f << "(float)" << endl ;
3408       break;
3409     case CORBA::tk_double:
3410       double d;
3411       D.Value >>= d;
3412       cdebug << ThreadNo() << " " << d << "(double)" << endl ;
3413       break;
3414     case CORBA::tk_objref:
3415       try {
3416         CORBA::Object_ptr obj ;
3417         char * retstr ;
3418         D.Value >>= obj ;
3419         retstr = ObjectToString( obj ) ;
3420         cdebug << ThreadNo() << retstr << endl ;
3421       }
3422       catch( ... ) {
3423         cdebug << "ToString( object ) Catched ERROR" << endl ;
3424       }
3425       break;
3426     default:
3427       cdebug << ThreadNo() << " " << "(other ERROR)" << endl ;
3428     }
3429 #endif
3430     OutParametersList[i] = D ;
3431   }
3432 }
3433
3434 #define OutParametersSetTrace 1
3435 bool GraphExecutor::InNode::OutParametersSet( bool Err ,
3436                                               SUPERV::GraphState PortState ,
3437                                               int nOutParams ,
3438                                               ServicesAnyData * OutParametersList ) {
3439   bool RetVal = true ;
3440   int i ;
3441   GraphBase::OutPort * aGateOutPort = NULL ;
3442   bool OrSwitch = false ;
3443   bool DefaultSwitch = false ;
3444 #if OutParametersSetTrace
3445   cdebug_in << "OutParametersSet " << Name() << " nOutParams " << nOutParams << " NewPortState "
3446             << PortState << endl ;
3447 #endif
3448 //  cout << "OutParametersSet " << Name() << " nOutParams " << nOutParams << " NewPortState " << PortState << endl ;
3449   if ( nOutParams && !IsMacroNode() ) {
3450     GraphBase::OutPort * anOutPort ;
3451     for ( i = 0 ; i < nOutParams ; i++ ) {
3452       anOutPort = GetChangeNodeOutPort(i) ;
3453       if ( Err ) {
3454         anOutPort->PortState( PortState ) ;
3455         anOutPort->PortDone( true ) ;
3456       }
3457       else {
3458 #if OutParametersSetTrace
3459         cdebug << ThreadNo() << "OutParametersSet " << "Out" << i << " " << Name() << " "
3460                << anOutPort->PortName() << " " << anOutPort->Kind() ;
3461 #endif
3462         ServicesAnyData D = OutParametersList[i] ;
3463         switch (D.Value.type()->kind()) { // { string , long , double , objref }
3464         case CORBA::tk_string: {
3465           char * t;
3466           D.Value >>= t;
3467 #if OutParametersSetTrace
3468           cdebug << ThreadNo() << " " << t << "(string)" << endl ;
3469 #endif
3470           break;
3471         }
3472         case CORBA::tk_boolean: {
3473           bool b ;
3474           D.Value >>= (CORBA::Any::to_boolean ) b;
3475           long l = (long ) b ;
3476           D.Value <<= l ;
3477 #if OutParametersSetTrace
3478           cdebug << ThreadNo() << " " << b << "(boolean)" << endl ;
3479 #endif
3480           break;
3481         }
3482         case CORBA::tk_char: {
3483           unsigned char c ;
3484           D.Value >>= (CORBA::Any::to_char ) c;
3485           long l = (long ) c ;
3486           D.Value <<= l ;
3487 #if OutParametersSetTrace
3488           cdebug << ThreadNo() << " " << c << "(char)" << endl ;
3489 #endif
3490           break;
3491         }
3492         case CORBA::tk_short: {
3493           short s;
3494           D.Value >>= s;
3495           long l = (long ) s ;
3496           D.Value <<= l ;
3497 #if OutParametersSetTrace
3498           cdebug << ThreadNo() << " " << s << "(short)" << endl ;
3499 #endif
3500           break;
3501         }
3502         case CORBA::tk_long: {
3503           long l;
3504           D.Value >>= l;
3505 #if OutParametersSetTrace
3506           cdebug << ThreadNo() << " " << l << "(long)" << endl ;
3507 #endif
3508           break;
3509         }
3510         case CORBA::tk_float: {
3511           float f;
3512           D.Value >>= f;
3513           double d = (double ) f ;
3514           D.Value <<= d ;
3515 #if OutParametersSetTrace
3516           cdebug << ThreadNo() << " " << f << "(float)" << endl ;
3517 #endif
3518           break;
3519         }
3520         case CORBA::tk_double: {
3521           double d;
3522           D.Value >>= d;
3523 #if OutParametersSetTrace
3524           cdebug << ThreadNo() << " " << d << "(double)" << endl ;
3525 #endif
3526           break;
3527         }
3528         case CORBA::tk_objref: {
3529           try {
3530             CORBA::Object_ptr obj ;
3531             D.Value >>= obj ;
3532 #if OutParametersSetTrace
3533             char * retstr ;
3534             retstr = ObjectToString( obj ) ;
3535             cdebug << ThreadNo() << retstr << endl ;
3536 #endif
3537           }
3538           catch( ... ) {
3539             cdebug << "ToString( object ) Catched ERROR" << endl ;
3540             RetVal = false ;
3541           }
3542           break;
3543         }
3544         default: {
3545           cdebug << ThreadNo() << " " << "(other ERROR)" << endl ;
3546           RetVal = false ;
3547         }
3548         }
3549         OutParametersList[i] = D ;
3550         if ( !anOutPort->IsDataStream() ) {
3551           if ( anOutPort->IsGate() ) {
3552             aGateOutPort = anOutPort ;
3553 #if OutParametersSetTrace
3554             cdebug << " Gate " ;
3555 #endif
3556             long l = 1;
3557             OutParametersList[i].Value <<= l;
3558             anOutPort->SetValue( OutParametersList[i].Value );
3559           }
3560           else if ( anOutPort->IsLoop() ) {
3561 #if OutParametersSetTrace
3562             cdebug << " Loop " ;
3563 #endif
3564             anOutPort->SetValue( OutParametersList[i].Value );
3565 // InLoop Port of EndLoopNode is ready :
3566             anOutPort->ChangeInPorts(0)->PortState( SUPERV::ReadyState ) ;
3567           }
3568           else if ( anOutPort->IsSwitch() ) {
3569 #if OutParametersSetTrace
3570             cdebug << " Switch " ;
3571 #endif
3572             anOutPort->SetValue( OutParametersList[i].Value );
3573             if ( anOutPort->InPortsSize() && anOutPort->ChangeInPorts( 0 )->IsGate() ) {
3574 //JR 09.02.2005 : OrSwitch is the OR of all SwitchBranches :
3575 //It controls that there is only one SwitchBranch activated
3576 //If it's final value is false ==> activation of the Default to GOTO to EndSwitchNode
3577 //DefaultSwitch is true if a SwitchPort is linked to the DefaultPort of the EndSwitchNode
3578               if ( OrSwitch && anOutPort->BoolValue() ) {
3579                 cdebug << "GraphExecutor::InNodeThreads::OutParameters more than one switch is true ERROR"
3580                        << endl ;
3581                 RetVal = false ;
3582               }
3583               else if ( anOutPort->BoolValue() ) {
3584 //JR 09.02.2005 Debug : case of a SwitchPort linked to the DefaultPort of the EndSwitchNode :
3585                 if ( !strcmp( anOutPort->ChangeInPorts( 0 )->NodeName() , GOTONode()->CoupledNodeName() ) ) {
3586                   DefaultSwitch = anOutPort->BoolValue() ;
3587                 }
3588                 else {
3589                   OrSwitch = OrSwitch | anOutPort->BoolValue() ;
3590                 }
3591 #if OutParametersSetTrace
3592                 cdebug << "InNodeThreads::OutParameters OrSwitch " << OrSwitch << "DefaultSwitch "
3593                        << DefaultSwitch << endl ;
3594 #endif
3595               }
3596             }
3597           }
3598           else {
3599 #if OutParametersSetTrace
3600             cdebug << " Param " ;
3601 #endif
3602             anOutPort->SetValue( OutParametersList[i].Value );
3603           }
3604           anOutPort->PortState( PortState ) ;
3605           anOutPort->PortDone( true ) ;
3606         }
3607 #if OutParametersSetTrace
3608         cdebug << "OutParametersSet OrSwitch " << OrSwitch << "DefaultSwitch "
3609                << DefaultSwitch << endl ;
3610 #endif
3611         int j ;
3612         for ( j = 0 ; j < anOutPort->InPortsSize() ; j++ ) {
3613 #if OutParametersSetTrace
3614           cdebug << ThreadNo() << "OutParametersSet " << "Out" << i << " " << Name() << " "
3615                  << anOutPort->PortName() << " " << anOutPort->Kind() << " --> "
3616                  << anOutPort->ChangeInPorts( j )->NodeName() << "( "
3617                  << anOutPort->ChangeInPorts( j )->PortName() << anOutPort->ChangeInPorts( j )->Kind()
3618                  << " )" << endl ;
3619 #endif
3620           bool fromGOTO = false ;
3621           const char * ToNodeName = anOutPort->ChangeInPorts( j )->NodeName() ;
3622           if ( !strcmp( ToNodeName , _OutNode->Name() ) &&
3623                _OutNode->Graph()->GraphMacroLevel() != 0 ) {
3624 #if OutParametersSetTrace
3625             cdebug << "OutParametersSet ToNodeName " << _OutNode->Name() << " CoupledNode "
3626                    << _OutNode->Graph()->CoupledNodeName() << _OutNode->Graph()->CoupledNode()
3627                    << endl ;
3628             cdebug << " GraphExecutor " << _OutNode->Graph()->CoupledNode()->GraphEditor()->Executor() << endl ;
3629 #endif
3630             _OutNode->Graph()->CoupledNode()->GraphEditor()->Executor()->OutputOfAny( _OutNode->Graph()->CoupledNodeName() ,
3631                                                                             anOutPort->ChangeInPorts( j )->PortName() ,
3632 //JR 30.03.2005                                                                            *anOutPort->Value() ) ;
3633                                                                             anOutPort->Value() ) ;
3634           }
3635           else {
3636             GraphBase::ComputingNode * ToNode = _OutNode->Graph()->GetChangeGraphNode( ToNodeName ) ;
3637             if ( ToNode ) {
3638 //              cout << "OutParametersSet ToNodeName " << ToNodeName << endl ;
3639 //              cdebug << "OutParametersSet ToNodeName " << ToNodeName << " " << ToNode->Name() << endl ;
3640               GraphBase::OutPort * aGOTOPort = ToNode->GetChangeNodeInGate()->GetOutPort() ;
3641               if ( aGOTOPort ) {
3642                 fromGOTO = aGOTOPort->IsGOTO() ;
3643               }
3644               if ( anOutPort->ChangeInPorts( j )->IsEndSwitch() || fromGOTO ) {
3645 #if OutParametersSetTrace
3646                 cdebug << anOutPort->ChangeInPorts( j )->NodeName() << "("
3647                        << anOutPort->ChangeInPorts( j )->PortName() << ","
3648                        << anOutPort->ChangeInPorts( j )->Kind() << ") CHANGED from "
3649                        << anOutPort->ChangeInPorts( j )->GetOutPort()->NodeName()
3650                        << "("
3651                        << anOutPort->ChangeInPorts( j )->GetOutPort()->PortName()
3652                        << " to " << anOutPort->ChangeInPorts( j )->GetOutPort()->Kind()
3653                        << ") : Done " << anOutPort->PortDone() << " State "
3654                        << Automaton()->StateName( anOutPort->ChangeInPorts( j )->PortState() ) << endl ;
3655 #endif
3656                 anOutPort->ChangeInPorts( j )->ChangeOutPort( anOutPort ) ;
3657               }
3658               else {
3659 #if OutParametersSetTrace
3660                 cdebug << anOutPort->ChangeInPorts( j )->NodeName() << "("
3661                        << anOutPort->ChangeInPorts( j )->PortName() << ","
3662                        << anOutPort->ChangeInPorts( j )->Kind() << ") NOT changed from "
3663                        << anOutPort->ChangeInPorts( j )->GetOutPort()->NodeName()
3664                        << "("
3665                        << anOutPort->ChangeInPorts( j )->GetOutPort()->PortName()
3666                        << " " << anOutPort->ChangeInPorts( j )->GetOutPort()->Kind()
3667                        << ") " << endl ;
3668 #endif
3669               }
3670             }
3671           }
3672         }
3673 #if OutParametersSetTrace
3674         switch ( anOutPort->Value().type()->kind() ) {
3675         case CORBA::tk_string:
3676           char * t;
3677           anOutPort->Value() >>= t;
3678           cdebug << ThreadNo() << " Out" << i << " : " << t << "(string)" << endl ;
3679           break;
3680         case CORBA::tk_boolean:
3681           bool b ;
3682           anOutPort->Value() >>= (CORBA::Any::to_boolean ) b;
3683           cdebug << ThreadNo() << " Out" << i << " : " << b << "(boolean)" << endl ;
3684           break;
3685         case CORBA::tk_char:
3686           unsigned char c ;
3687           anOutPort->Value() >>= (CORBA::Any::to_char ) c;
3688           cdebug << ThreadNo() << " Out" << i << " : " << c << "(char)" << endl ;
3689           break;
3690         case CORBA::tk_short:
3691           short s;
3692           anOutPort->Value() >>= s;
3693           cdebug << ThreadNo() << " Out" << i << " : " << s << "(short)" << endl ;
3694           break;
3695         case CORBA::tk_long:
3696           long l;
3697           anOutPort->Value() >>= l;
3698           cdebug << ThreadNo() << " Out" << i << " : " << l << "(long)" << endl ;
3699           break;
3700         case CORBA::tk_float:
3701           float f;
3702           anOutPort->Value() >>= f;
3703           cdebug << ThreadNo() << " Out" << i << " : " << f << "(float)" << endl ;
3704           break;
3705         case CORBA::tk_double:
3706           double d;
3707           anOutPort->Value() >>= d;
3708           cdebug << ThreadNo() << " Out" << i << " : " << d << "(double)" << endl ;
3709           break;
3710         case CORBA::tk_objref:
3711           CORBA::Object_ptr obj ;
3712           char * retstr ;
3713           try {
3714             anOutPort->Value() >>= obj ;
3715             retstr = ObjectToString( obj );
3716             cdebug << ThreadNo() << " Out" << i << " : " << "ToString( object ) "
3717                    << retstr << endl ;
3718           }
3719           catch ( ... ) {
3720             cdebug << ThreadNo() << " Out" << i << " : " << "ToString( object ) "
3721                    << "Catched ERROR" << endl ;
3722             RetVal = false ;
3723           }
3724           break;
3725         default:
3726           cdebug << ThreadNo() << " Out" << i << " : " << "(other ERROR)" << endl ;
3727           RetVal = false ;
3728         }
3729 #endif
3730       }
3731     }
3732     if ( aGateOutPort && IsSwitchNode() ) {
3733 //JR 09.02.2005 : OrSwitch is the OR of all SwitchBranches :
3734 //It controls that there is only one SwitchBranch activated
3735 //If it's final value is false ==> activation of the Default to GOTO to EndSwitchNode
3736 //DefaultSwitch is true if a SwitchPort (SwitchBranch) is linked to the DefaultPort of the EndSwitchNode
3737       if ( !OrSwitch && !DefaultSwitch ) {
3738         if ( aGateOutPort->InPortsSize() && aGateOutPort->ChangeInPorts( 0 ) ) {
3739 #if OutParametersSetTrace
3740           cdebug << ThreadNo() << " " << "OutGate " << Name() << " Open of "
3741                  << aGateOutPort->PortName() << " " << aGateOutPort->Kind() << " WITH DefaultPort"
3742                  << endl ;
3743 #endif
3744           long l = 1;
3745           OutParametersList[0].Value <<= l ;
3746           aGateOutPort->SetValue( OutParametersList[0].Value ) ;
3747         }
3748         else {
3749 #if OutParametersSetTrace
3750           cdebug << ThreadNo() << " " << "OutGate " << Name() << " "
3751                  << aGateOutPort->PortName() << " " << aGateOutPort->Kind() << " NOT CONNECTED ERROR"
3752                  << endl ;
3753 #endif
3754           RetVal = false ;
3755         }
3756       }
3757 //JR 07.04.2005 Debug : reset only if it is not a default switch (SwitchBranch or
3758 //                      SwitchParameter of SwitchNode connected to the InDefaultPort of
3759 //                      EndSwitchNode)
3760 //      else {
3761       else if ( !DefaultSwitch ) {
3762 #if OutParametersSetTrace
3763         cdebug << ThreadNo() << " " << "OutGate " << Name() << " Close of "
3764                << aGateOutPort->PortName() << " " << aGateOutPort->Kind() << " NO DefaultPort"
3765                << " OrSwitch " << OrSwitch << " DefaultSwitch " << DefaultSwitch << endl ;
3766 #endif
3767         long l = 0;
3768         OutParametersList[0].Value <<= l ;
3769         aGateOutPort->SetValue( OutParametersList[0].Value ) ;
3770       }
3771 // The OutPort field of InPorts of EndSwitchNode may be updated only in branches :
3772 // for the Default case they should not be changed (if they are changed ==> bug if we activate
3773 // a branch after a use of the Default)
3774       if ( !OrSwitch || DefaultSwitch ) { // DefaultPort or DefaultSwitch
3775         int i ;
3776         for ( i = 0 ; i < GetNodeOutPortsSize() ; i++ ) {
3777           GraphBase::InPort * anInPort ;
3778           anInPort = CoupledNode()->GetChangeInPort( GetNodeOutPort( i )->PortName() ) ;
3779 //PAL8518
3780 //JR 16.02.2005 Debug : Change InPorts of EndSwitchNode that have the same name as an OutPort of
3781 // the SwitchNode even if it is the DefaultPort : GraphSwitchCheckDefault1.xml
3782 //          if ( anInPort && !anInPort->IsGate() ) {
3783           if ( anInPort && anInPort->GetOutPort() ) {
3784 #if OutParametersSetTrace
3785             cdebug << "OutParametersSet " << Name() << " " << anInPort->NodeName() << "( "
3786                    << anInPort->PortName() << " , " << anInPort->Kind() << " ) linked from "
3787                    << anInPort->GetOutPort()->NodeName()
3788                    << "( " << anInPort->GetOutPort()->PortName() << " ) CHANGED TO linked from "
3789                    << GetChangeNodeOutPort( i )->NodeName() << "( "
3790                    << GetChangeNodeOutPort( i )->PortName() << " )" << endl ;
3791 #endif
3792             anInPort->ChangeOutPort( GetChangeNodeOutPort( i ) ) ;
3793           }
3794         }
3795       }
3796     }
3797   }
3798 #if OutParametersSetTrace
3799   cdebug_out << "OutParametersSet " << Name() << " nOutParams " << nOutParams << " NewPortState "
3800              << PortState << " RetVal " << RetVal << endl ;
3801 #endif
3802   return RetVal ;
3803 }