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