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