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