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