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