Salome HOME
DCQ : Merge with Ecole_Ete_a6.
[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 #include "Python.h"
37
38 #include "OpUtil.hxx"
39
40 #include <SALOMEconfig.h>
41 #include CORBA_CLIENT_HEADER(SALOME_Component)
42 #include "SALOME_LifeCycleCORBA.hxx"
43
44 //#include "StreamGraph_Impl.hxx"
45
46 #include "DataFlowExecutor_OutNode.hxx"
47
48
49 static void UpperCase(std::string& rstr)
50 {
51         std::transform(rstr.begin(), rstr.end(), rstr.begin(), towupper);
52 }
53
54
55 int GraphExecutor::InNode::SendEvent( const GraphExecutor::NodeEvent anEvent ) {  
56
57   _CurrentEvent = (GraphExecutor::NodeEvent ) anEvent ;
58   cdebug << pthread_self() << "/" << ThreadNo() << " -->SendEvent Node "  << Name() 
59          << " ControlState : "
60          << Automaton()->ControlStateName( ControlState() )
61          << " Event : " << Automaton()->EventName( anEvent )
62          << " State : " << Automaton()->StateName( State() ) << " _RewindStack " << _RewindStack  << endl;
63
64   _OldState = State() ;
65   _NextState = Automaton()->NextState( _OldState , anEvent ) ;
66   if ( _NextState == _OldState ) {
67     cdebug << pthread_self() << "/" << ThreadNo()
68            << " GraphExecutor::InNodeThreads::SendEvent SameStates "
69            << _OldState << endl ;
70     _NextAction = GraphExecutor::VoidAction ;
71   }
72   else {
73     _NextAction = Automaton()->NextAction( _NextState , anEvent ) ;
74   }
75
76 //  State( _NextState ) ;
77 //  if ( _OldState == SUPERV::SuccessedExecutingState ||
78 //       _OldState == SUPERV::ErroredExecutingState ) {
79 //    DoneAction() ;
80 //  }
81
82   cdebug << pthread_self() << "/" << ThreadNo() << " SendedEvent Node "
83          << Name() << endl << " ControlState : "
84          << Automaton()->ControlStateName( ControlState() ) << endl
85          << " OldState : " << Automaton()->StateName( _OldState ) << endl
86          << " Event : " << Automaton()->EventName( anEvent ) << endl
87          << " NextState : " << Automaton()->StateName( _NextState ) << endl
88          << " Action : " << Automaton()->ActionName( _NextAction ) << endl
89          << " CreateNewThread " << CreateNewThread() << endl
90          << " _RewindStack " << _RewindStack  << endl ;
91
92 #if 0
93   cout << pthread_self() << "/" << ThreadNo() << " SendedEvent Node " << Name()
94        << endl << " ControlState : "
95        << Automaton()->ControlStateName( ControlState() ) << endl
96        << " OldState : " << Automaton()->StateName( _OldState ) << endl
97        << " Event : " << Automaton()->EventName( anEvent ) << endl
98        << " NextState : " << Automaton()->StateName( _NextState ) << endl
99        << " Action : " << Automaton()->ActionName( _NextAction ) << endl
100        << " CreateNewThread " << CreateNewThread() << endl ;
101 #endif
102
103   int sts = executeAction() ;
104   
105   cdebug << pthread_self() << "/" << ThreadNo() << " <--- SendEvent Node " << Name() 
106          << " Event : " << Automaton()->EventName( anEvent )
107          << " State : " << Automaton()->StateName( State() )
108          << endl;
109
110   return sts ;
111
112 }
113
114 // ReadyAction - RunningAction - DoneAction - SuspendedAction :
115 // for StateWait( ReadyW - RunningW - DoneW - SuspendedW )
116 void GraphExecutor::InNode::ReadyAction() {
117   if ( pthread_mutex_lock( &_MutexWait ) ) {
118     perror("Ready pthread_mutex_lock ") ;
119     exit( 0 ) ;
120   }
121   cdebug << pthread_self() << "/" << ThreadNo()
122          << "ReadyAction pthread_cond_broadcast _ReadyWait "
123          << Name() << endl ;
124   if ( pthread_cond_broadcast( &_ReadyWait ) ) {
125     perror("Ready pthread_cond_broadcast ") ;
126   }
127   if ( pthread_mutex_unlock( &_MutexWait ) ) {
128     perror("Ready pthread_mutex_unlock ") ;
129     exit( 0 ) ;
130   }
131 }
132
133 void GraphExecutor::InNode::RunningAction() {
134   if ( pthread_mutex_lock( &_MutexWait ) ) {
135     perror("Running pthread_mutex_lock ") ;
136     exit( 0 ) ;
137   }
138   cdebug << pthread_self() << "/" << ThreadNo()
139          << "RunningAction pthread_cond_broadcast _RunningWait "
140          << Name() << endl ;
141   if ( pthread_cond_broadcast( &_RunningWait ) ) {
142     perror("Running pthread_cond_broadcast ") ;
143   }
144   if ( pthread_mutex_unlock( &_MutexWait ) ) {
145     perror("Running pthread_mutex_unlock ") ;
146     exit( 0 ) ;
147   }
148 }
149
150 void GraphExecutor::InNode::DoneAction() {
151   if ( pthread_mutex_lock( &_MutexWait ) ) {
152     perror("Done pthread_mutex_lock ") ;
153     exit( 0 ) ;
154   }
155   cdebug << pthread_self() << "/" << ThreadNo()
156          << "DoneAction pthread_cond_broadcast _DoneWait "
157          << Name() << endl ;
158   if ( pthread_cond_broadcast( &_DoneWait ) ) {
159     perror("Done pthread_cond_broadcast ") ;
160   }
161   if ( pthread_mutex_unlock( &_MutexWait ) ) {
162     perror("Done pthread_mutex_unlock ") ;
163     exit( 0 ) ;
164   }
165 }
166
167 void GraphExecutor::InNode::SuspendedAction() {
168   if ( pthread_mutex_lock( &_MutexWait ) ) {
169     perror("Suspended pthread_mutex_lock ") ;
170     exit( 0 ) ;
171   }
172   cdebug << pthread_self() << "/" << ThreadNo()
173          << "SuspendedAction pthread_cond_broadcast _SuspendedWait "
174          << Name() << endl ;
175   if ( pthread_cond_broadcast( &_SuspendedWait ) ) {
176     perror("Suspended pthread_cond_broadcast ") ;
177   }
178   if ( pthread_mutex_unlock( &_MutexWait ) ) {
179     perror("Suspended pthread_mutex_unlock ") ;
180     exit( 0 ) ;
181   }
182 }
183
184 // SuspendAction <--> { ResumeAction - ReStartAction }
185 GraphExecutor::InNode * GraphExecutor::InNode::SuspendAction() {
186   SuspendedAction() ;
187   if ( pthread_mutex_lock( &_MutexWait ) ) {
188     perror("Suspend pthread_mutex_lock ") ;
189     exit( 0 ) ;
190   }
191   if ( !_SuspendSync ) {
192     cdebug << pthread_self() << "/" << ThreadNo() << " pthread_cond " << Name()
193            << " SuspendAction pthread_cond_wait _SuspendWait "
194            << Automaton()->StateName( State() ) << endl ;
195     _SuspendSync = true ;
196     _OutNode->SuspendThread() ;
197     if ( pthread_cond_wait( &_SuspendWait , &_MutexWait ) ) {
198       perror("SuspendAction pthread_cond_wait ") ;
199     }
200     _OutNode->ResumeThread() ;
201     cdebug << pthread_self() << "/" << ThreadNo() << " pthread_cond " << Name()
202            << " SuspendAction pthread_cond_waited"  
203            << Automaton()->StateName( State() ) << endl ;
204   }
205   else {
206     cdebug << pthread_self() << "/" << ThreadNo() << " pthread_cond " << Name()
207            << " NO SuspendAction pthread_cond_wait"  
208            << Automaton()->StateName( State() ) << endl ;
209   }
210 //  SendEvent( _aResumeEvent ) ; ===> Mutex with myself !
211   _SuspendSync = false ;  
212   if ( ControlState() == SUPERV::ToSuspendStartState ||
213        ControlState() == SUPERV::ToSuspendState ) {
214     ControlState( SUPERV::VoidState ) ;
215   }
216   if ( pthread_mutex_unlock( &_MutexWait ) ) {
217     perror("SuspendAction pthread_mutex_unlock ") ;
218     exit( 0 ) ;
219   }
220
221   SendEvent( _aResumeEvent ) ;
222 //  if ( ControlState() == SUPERV::ToSuspendStartState ) {
223 //    ControlState( SUPERV::VoidState ) ;
224 //  }
225
226   if ( pthread_mutex_lock( &_MutexWait ) ) {
227     perror("SuspendAction pthread_mutex_lock ") ;
228     exit( 0 ) ;
229   }
230   if ( _ResumeSync ) {
231     cdebug << pthread_self() << "/" << ThreadNo() << " pthread_cond " << Name()
232            << " SuspendAction pthread_cond_signal _ResumeWait" << endl ;
233     if ( pthread_cond_signal( &_ResumeWait ) ) {
234       perror("SuspendAction pthread_cond_signal _ResumeWait ") ;
235     }
236     cdebug << pthread_self() << "/" << ThreadNo() << " pthread_cond " << Name()
237            << " SuspendAction pthread_cond_signaled _ResumeWait " << endl ;
238   }
239   else {
240     cdebug << pthread_self() << "/" << ThreadNo() << " pthread_cond " << Name()
241            << " NO SuspendAction pthread_cond_signal _ResumeWait" << endl ;
242     _ResumeSync = true ;  
243   }
244   if ( pthread_mutex_unlock( &_MutexWait ) ) {
245     perror("SuspendAction pthread_mutex_unlock ") ;
246     exit( 0 ) ;
247   }
248   if ( _aReStartNode ) {
249     cdebug << Name() << " " << Automaton()->StateName( State() )
250            << "aReStartNode : " << _aReStartNode->Name() << " "
251            << Automaton()->StateName( _aReStartNode->State() ) << endl ;
252     _aReStartNode->SendEvent( _aResumeEvent ) ;
253   }
254   else {
255     cdebug << "NO aReStartNode" 
256            << Automaton()->StateName( State() ) << endl ;
257   }
258   return _aReStartNode ;
259 }
260
261 bool GraphExecutor::InNode::ResumeAction( GraphExecutor::NodeEvent aResumeEvent ) {
262   bool RetVal ;
263   if ( pthread_mutex_lock( &_MutexWait ) ) {
264     perror("ResumeAction pthread_mutex_lock ") ;
265     exit( 0 ) ;
266   }
267   _aResumeEvent = aResumeEvent ;
268   if ( _SuspendSync ) {
269     cdebug << pthread_self() << "/" << ThreadNo() << " pthread_cond " << Name()
270            << " ResumeAction pthread_cond_signal" << endl ;
271     if ( pthread_cond_signal( &_SuspendWait ) ) {
272       perror("ResumeAction pthread_cond_signal ") ;
273     }
274     cdebug << pthread_self() << "/" << ThreadNo() << " pthread_cond " << Name()
275            << " ResumeAction pthread_cond_signaled _SuspendWait " << endl ;
276     RetVal = true ;
277   }
278   else {
279     cdebug << pthread_self() << "/" << ThreadNo() << " pthread_cond " << Name()
280            << " NO ResumeAction pthread_cond_signal" << endl ;
281     if ( pthread_self() == ThreadNo() ) {
282       RetVal = false ; /*/ Ne pas s'attendre soi-meme !...*/
283     }
284     else {
285       _SuspendSync = true ;
286       RetVal = true ; // Il faut tout de meme attendre ci-apres ...
287     }
288   }
289   if ( pthread_mutex_unlock( &_MutexWait ) ) {
290     perror("ResumeAction pthread_mutex_unlock ") ;
291     exit( 0 ) ;
292   }
293
294   if ( RetVal ) {
295     if ( pthread_mutex_lock( &_MutexWait ) ) {
296       perror("ResumeAction pthread_mutex_lock ") ;
297       exit( 0 ) ;
298     }
299     if ( !_ResumeSync ) {
300       cdebug << pthread_self() << "/" << ThreadNo() << " pthread_cond "
301              << Name() << " ResumeAction pthread_cond_wait _ResumeWait " 
302              << Automaton()->StateName( State() ) << endl ;
303       _ResumeSync = true ;
304       if ( pthread_cond_wait( &_ResumeWait , &_MutexWait ) ) {
305         perror("ResumeAction pthread_cond_wait ") ;
306       }
307       cdebug << pthread_self() << "/" << ThreadNo() << " pthread_cond "
308              << Name() << " ResumeAction pthread_cond_waited _ResumeWait"  
309              << Automaton()->StateName( State() ) << endl ;
310       RetVal = true ;
311     }
312     else {
313       cdebug << pthread_self() << "/" << ThreadNo() << " pthread_cond "
314              << Name() << " NO ResumeAction pthread_cond_wait _ResumeWait" 
315              << Automaton()->StateName( State() ) << endl ;
316       RetVal = false ;
317     }
318     _ResumeSync = false ;  
319     if ( pthread_mutex_unlock( &_MutexWait ) ) {
320       perror("ResumeAction pthread_mutex_unlock ") ;
321       exit( 0 ) ;
322     }
323   }
324   cdebug << pthread_self() << "/" << ThreadNo()
325          << "GraphExecutor::InNodeThreads::ResumeAction RetVal " << RetVal << endl ;
326   return RetVal ;
327 }
328
329 bool GraphExecutor::InNode::ReStartAction( GraphExecutor::InNode * aReStartNode ,
330                                            GraphExecutor::NodeEvent anEvent ) {
331   GraphExecutor::InNode * oldReStartNode = _aReStartNode ;
332   _aReStartNode = aReStartNode ;
333   _aReStartEvent = anEvent ;
334   cdebug << pthread_self() << " GraphExecutor::InNodeThreads::ReStartAction from "
335          << Name() << " " << Automaton()->StateName( State() ) << " to "
336          << aReStartNode->ThreadNo() << " " << aReStartNode->Name() << " "
337          << Automaton()->StateName( aReStartNode->State() ) ;
338   if ( oldReStartNode ) {
339     cdebug << " oldReStartNode " << oldReStartNode->Name() << endl ;
340   }
341   else {
342     cdebug << endl ;
343   }
344   return ResumeAction( GraphExecutor::ToReStartEvent ) ;
345 }
346
347 void GraphExecutor::InNode::KilledAction() {
348   if ( pthread_mutex_lock( &_MutexWait ) ) {
349     perror("Killed pthread_mutex_lock ") ;
350     exit( 0 ) ;
351   }
352   if ( !_KillSync ) {
353     cdebug << "pthread_cond " << Name() << " Killed pthread_cond_wait"
354            << endl ;
355     _KillSync = true ;
356     if ( pthread_cond_wait( &_KillWait , &_MutexWait ) ) {
357       perror("Killed pthread_cond_wait ") ;
358     }
359     cdebug << "pthread_cond " << Name() << " Killed pthread_cond_waited"
360            << endl ;
361   }
362   else {
363     cdebug << "pthread_cond " << Name() << " NO Killed pthread_cond_wait"
364            << endl ;
365   }
366   _KillSync = false ;  
367   if ( pthread_mutex_unlock( &_MutexWait ) ) {
368     perror("Killed pthread_mutex_unlock ") ;
369     exit( 0 ) ;
370   }
371 }
372
373 void GraphExecutor::InNode::KillAction() {
374   if ( pthread_mutex_lock( &_MutexWait ) ) {
375     perror("Kill pthread_mutex_lock ") ;
376     exit( 0 ) ;
377   }
378   if ( _KillSync ) {
379     cdebug << "pthread_cond " << Name() << " Kill pthread_cond_signal"
380            << endl ;
381 //    if ( pthread_cond_broadcast( &_KillWait ) ) {
382     if ( pthread_cond_signal( &_KillWait ) ) {
383       perror("Kill pthread_cond_broadcast ") ;
384     }
385     cdebug << "pthread_cond " << Name() << " Kill pthread_cond_signaled"
386            << endl ;
387   }
388   else {
389     cdebug << "pthread_cond " << Name() << " NO Kill pthread_cond_signal"
390            << endl ;
391     _KillSync = true ;  
392   }
393   if ( pthread_mutex_unlock( &_MutexWait ) ) {
394     perror("Kill pthread_mutex_unlock ") ;
395     exit( 0 ) ;
396   }
397 }
398
399 void GraphExecutor::InNode::StoppedAction() {
400   if ( pthread_mutex_lock( &_MutexWait ) ) {
401     perror("Stopped pthread_mutex_lock ") ;
402     exit( 0 ) ;
403   }
404   if ( pthread_cond_wait( &_StopWait , &_MutexWait ) ) {
405     perror("Stopped pthread_cond_wait ") ;
406   }
407   if ( pthread_mutex_unlock( &_MutexWait ) ) {
408     perror("Stopped pthread_mutex_unlock ") ;
409     exit( 0 ) ;
410   }
411 }
412
413 void GraphExecutor::InNode::StopAction() {
414   if ( pthread_mutex_lock( &_MutexWait ) ) {
415     perror("Stop pthread_mutex_lock ") ;
416     exit( 0 ) ;
417   }
418   if ( pthread_cond_broadcast( &_StopWait ) ) {
419     perror("Stop pthread_cond_broadcast ") ;
420   }
421   if ( pthread_mutex_unlock( &_MutexWait ) ) {
422     perror("Stop pthread_mutex_unlock ") ;
423     exit( 0 ) ;
424   }
425 }
426
427 void GraphExecutor::InNode::ThreadStartedAction() {
428   if ( pthread_mutex_lock( &_MutexWait ) ) {
429     perror("ThreadStarted pthread_mutex_lock ") ;
430     exit( 0 ) ;
431   }
432   if ( !_ThreadStartedSync ) {
433     cdebug << "pthread_cond " << Name() << " ThreadStarted pthread_cond_wait"
434            << endl ;
435     _ThreadStartedSync = true ;
436     if ( pthread_cond_wait( &_ThreadStartedWait , &_MutexWait ) ) {
437       perror("ThreadStarted pthread_cond_wait ") ;
438     }
439     cdebug << "pthread_cond " << Name() << " ThreadStarted pthread_cond_waited"
440            << endl ;
441   }
442   else {
443     cdebug << "pthread_cond " << Name() << " NO ThreadStarted pthread_cond_wait"
444            << endl ;
445 //Debug :
446     _ThreadStartedSync = false ;  
447     if ( pthread_cond_signal( &_ThreadStartedWait ) ) {
448       perror("ThreadStart pthread_cond_signal ") ;
449     }
450 //Debug
451     cdebug << "pthread_cond " << Name() << " NO ThreadStarted pthread_cond_signaled"
452            << endl ;
453   }
454   if ( pthread_mutex_unlock( &_MutexWait ) ) {
455     perror("ThreadStarted pthread_mutex_unlock ") ;
456     exit( 0 ) ;
457   }
458 }
459
460 void GraphExecutor::InNode::ThreadStartAction() {
461   if ( pthread_mutex_lock( &_MutexWait ) ) {
462     perror("ThreadStart pthread_mutex_lock ") ;
463     exit( 0 ) ;
464   }
465   if ( _ThreadStartedSync ) {
466     cdebug << "pthread_cond " << Name() << " ThreadStart pthread_cond_signal"
467            << endl ;
468     _ThreadStartedSync = false ;  
469     if ( pthread_cond_signal( &_ThreadStartedWait ) ) {
470       perror("ThreadStart pthread_cond_broadcast ") ;
471     }
472     cdebug << "pthread_cond " << Name() << " ThreadStart pthread_cond_signaled"
473            << endl ;
474   }
475   else {
476     cdebug << "pthread_cond " << Name() << " NO ThreadStart pthread_cond_signal"
477            << endl ;
478     _ThreadStartedSync = true ;
479 //Debug :
480     if ( pthread_cond_wait( &_ThreadStartedWait , &_MutexWait ) ) {
481       perror("ThreadStarted pthread_cond_wait ") ;
482     }
483 //Debug
484     cdebug << "pthread_cond " << Name() << " NO ThreadStart pthread_cond_waited"
485            << endl ;
486   }
487   if ( pthread_mutex_unlock( &_MutexWait ) ) {
488     perror("ThreadStart pthread_mutex_unlock ") ;
489     exit( 0 ) ;
490   }
491 }
492
493 int GraphExecutor::InNode::executeAction() {
494   int oldRewindStack = ( _RewindStack > MAXSTACKTHREADSIZE ) ;
495   if ( !CreateNewThread() && oldRewindStack ) {
496     cdebug << pthread_self() << "/" << ThreadNo()
497            << " executeAction start Thread _RewindStack " << _RewindStack << " > "
498            << MAXSTACKTHREADSIZE << " CreateNewThread "
499            << CreateNewThread() << " " << Automaton()->ActionName( _NextAction ) << "(" << Name() << ")"
500            << endl;
501     CreateNewThread( true ) ;
502     ThreadNo( 0 ) ;
503   }
504   if ( CreateNewThread() ) {
505     CreateNewThread( false ) ;
506     if ( ThreadNo() == 0 ) {
507       _RewindStack = 1 ;
508       cdebug << pthread_self() << "/" << ThreadNo()
509              << " executeAction start Thread _RewindStack " << _RewindStack << " "
510              << Automaton()->ActionName( _NextAction ) << "(" << Name() << ")"
511              << endl;
512       pthread_t T;
513       int pthread_sts = 1 ;
514 //      _OutNode->PushEvent( NULL , GraphExecutor::NewThreadEvent ,
515 //                           SUPERV::ExecutingState ) ; 
516       while ( (pthread_sts = pthread_create(&T, NULL, run_function, this )) ) {
517         char * msg = "Cannot pthread_create " ;
518         perror( msg ) ;
519         cdebug << ThreadNo() << " " << msg << " --> sleep(5)" << endl ;
520         cdebug << ThreadNo() << " PTHREAD_THREADS_MAX : "
521                << PTHREAD_THREADS_MAX << " pthread_create status : " ;
522         if ( pthread_sts == EAGAIN ) {
523           cdebug << "EAGAIN(" << pthread_sts << ")" << endl ;
524           cdebug << "It seems to me that with gdb we are limited to 256 threads because of defunct" << endl ;
525         }
526         else {
527           cdebug << pthread_sts << endl ;
528         }
529         string smsg = msg ;
530         delete [] msg ;
531         pthread_exit( msg ) ;
532       }
533       cdebug << pthread_self() << "/" << ThreadNo()
534              << "executeAction has created thread " << T << endl ;
535       ThreadStartedAction() ;
536       cdebug << pthread_self() << "/" << ThreadNo()
537              << "executeAction the thread " << T << " has called NewThread and will call ExecuteAction for node "
538              << Name() << endl ;
539     }
540     else {
541       cdebug << pthread_self() << "/" << ThreadNo()
542              << " executeAction restart Thread _RewindStack " << _RewindStack << " "
543              << Automaton()->StateName( State() ) << " "
544              << Automaton()->ActionName( _NextAction ) << "(" << Name()
545              << ") ReStartAction ==>" << endl;
546       State( SUPERV::SuspendedSuccessedState ) ;
547       if ( !ReStartAction( this , GraphExecutor::ReStartEvent ) ) {
548         cdebug << pthread_self() << "/" << ThreadNo()
549                << " executeAction STATE & CALLED "
550                << Automaton()->ActionName( _NextAction ) << "(" << Name()
551                << ") ERROR-DEBUG " << endl;
552       }
553       else {
554         cdebug << pthread_self() << "/" << ThreadNo() << " executeAction NO CALL "
555                << Automaton()->ActionName( _NextAction ) << "(" << Name()
556                << ")" << endl;
557       }
558     }
559   }
560   else {
561     if ( _CurrentEvent == ExecuteEvent ) {
562       _RewindStack += 1 ;
563     }
564     cdebug << pthread_self() << "/" << ThreadNo() << " executeAction call "
565            << Automaton()->ActionName( _NextAction ) << "(" << Name() << ") _RewindStack " << _RewindStack
566            << endl;
567     return ExecuteAction() ;
568   }
569   return 1 ;
570 }
571
572 void GraphExecutor::InNode::coutbegin() {
573   cdebug << ThreadNo() << " " << pthread_self() << " run_function begin"
574          << " " << Name() << " " << Automaton()->StateName( State() ) << endl ;
575 }
576 void GraphExecutor::InNode::coutexit() {
577   cdebug << pthread_self() << "/" << ThreadNo() << " run_function pthread_exit _RewindStack " << _RewindStack
578          << " " << Name() << " " << Automaton()->StateName( State() ) << endl ;
579 }
580 void * run_function(void *p) {
581   GraphExecutor::InNode *aNode = (GraphExecutor::InNode *) p;
582   aNode->coutbegin() ;
583   aNode->NewThread( pthread_self() ) ;
584   if ( pthread_setcanceltype( PTHREAD_CANCEL_ASYNCHRONOUS , NULL ) ) {
585     perror("pthread_setcanceltype ") ;
586     exit(0) ;
587   }
588   if ( pthread_setcancelstate( PTHREAD_CANCEL_ENABLE , NULL ) ) {
589     perror("pthread_setcancelstate ") ;
590     exit(0) ;
591   }
592   aNode->ThreadStartAction() ;
593   aNode->ExecuteAction() ;
594   char * msg = new char[40] ;
595   sprintf( msg , "%d" , (int ) aNode->ThreadNo() ) ;
596   strcat( msg , " thread exit" ) ;
597   aNode->coutexit() ;
598   aNode->ExitThread() ;
599   string smsg = msg ;
600   delete [] msg ;
601   pthread_exit( (void * ) smsg.c_str() ) ;
602   return msg ;
603 }
604
605 int GraphExecutor::InNode::ExecuteAction() {
606   int sts ;
607
608 //  const char * nextactionname = Automaton()->ActionName( _NextAction ) ;
609 //  const char * statename = Automaton()->StateName( State() ) ;
610 //  const char * nextstatename = Automaton()->StateName( _NextState ) ;
611 //  cdebug << pthread_self() << "/" << ThreadNo() << " --> ExecuteAction "
612 //         << nextactionname << " "  << statename << " NextState "
613 //         << nextstatename << endl ;
614
615   State( _NextState ) ;
616   switch ( _NextAction ) {
617   case GraphExecutor::ErrorAction : {
618     sts = ErrorAction() ;
619     break ;
620   }
621   case GraphExecutor::VoidAction : {
622     sts = VoidAction() ;
623     break ;
624   }
625   case GraphExecutor::DataWaiting_SomeDataReadyAction : {
626     sts = DataWaiting_SomeDataReadyAction() ;
627     break ;
628   }
629   case GraphExecutor::DataUndef_NotAllDataReadyAction : {
630     sts = DataUndef_NotAllDataReadyAction() ;
631     break ;
632   }
633   case GraphExecutor::DataUndef_AllDataReadyAction : {
634     sts = DataUndef_AllDataReadyAction() ;
635     break ;
636   }
637   case GraphExecutor::DataReady_SuspendAction : {
638     sts = DataReady_SuspendAction() ;
639     break ;
640   }
641   case GraphExecutor::SuspendedReady_ResumeAction : {
642     sts = SuspendedReady_ResumeAction() ;
643     break ;
644   }
645   case GraphExecutor::DataReady_KillAction : {
646     sts = DataReady_KillAction() ;
647     break ;
648   }
649   case GraphExecutor::DataReady_StopAction : {
650     sts = DataReady_StopAction() ;
651     break ;
652   }
653   case GraphExecutor::DataReady_ExecuteAction : {
654     sts = DataReady_ExecuteAction() ;
655     break ;
656   }
657   case GraphExecutor::Executing_SuspendAction : {
658     sts = Executing_SuspendAction() ;
659     break ;
660   }
661   case GraphExecutor::SuspendedExecuting_ResumeAction : {
662     sts = SuspendedExecuting_ResumeAction() ;
663     break ;
664   }
665   case GraphExecutor::Executing_KillAction : {
666     sts = Executing_KillAction() ;
667     break ;
668   }
669   case GraphExecutor::Executing_StopAction : {
670     sts = Executing_StopAction() ;
671     break ;
672   }
673   case GraphExecutor::Executing_SuccessAction : {
674     sts = Executing_SuccessAction() ;
675     break ;
676   }
677   case GraphExecutor::Executing_ErrorAction : {
678     sts = Executing_ErrorAction() ;
679     break ;
680   }
681   case GraphExecutor::Successed_SuccessAction : {
682     sts = Successed_SuccessAction() ;
683     break ;
684   }
685   case GraphExecutor::Errored_ErrorAction : {
686     sts = Errored_ErrorAction() ;
687     break ;
688   }
689   case GraphExecutor::Successed_SuspendAction : {
690     sts = Successed_SuspendAction() ;
691     break ;
692   }
693   case GraphExecutor::Errored_SuspendAction : {
694     sts = Errored_SuspendAction() ;
695     break ;
696   }
697   case GraphExecutor::SuspendedSuccessed_ResumeAction : {
698     sts = SuspendedSuccessed_ResumeAction() ;
699     break ;
700   }
701   case GraphExecutor::SuspendedErrored_ResumeAction : {
702     sts = SuspendedErrored_ResumeAction() ;
703     break ;
704   }
705   case GraphExecutor::Successed_KillAction : {
706     sts = Successed_KillAction() ;
707     break ;
708   }
709   case GraphExecutor::Errored_KillAction : {
710     sts = Errored_KillAction() ;
711     break ;
712   }
713   case GraphExecutor::Successed_StopAction : {
714     sts = Successed_StopAction() ;
715     break ;
716   }
717   case GraphExecutor::Errored_StopAction : {
718     sts = Errored_StopAction() ;
719     break ;
720   }
721   case GraphExecutor::SuspendedSuccessed_ReStartAction : {
722     sts = SuspendedSuccessed_ReStartAction() ;
723     break ;
724   }
725   case GraphExecutor::SuspendedErrored_ReStartAction : {
726     sts = SuspendedErrored_ReStartAction() ;
727     break ;
728   }
729   case GraphExecutor::SuspendedSuccessed_ReStartAndSuspendAction : {
730     sts = SuspendedSuccessed_ReStartAndSuspendAction() ;
731     break ;
732   }
733   case GraphExecutor::SuspendedErrored_ReStartAndSuspendAction : {
734     sts = SuspendedErrored_ReStartAndSuspendAction() ;
735     break ;
736   }
737   default : {
738     cdebug << pthread_self() << "/" << ThreadNo()
739            << " GraphExecutor::InNodeThreads::SendEvent Error Undefined Action : "
740            << _NextAction << endl ;
741     return 0 ;
742   }
743   }
744 //  cdebug << pthread_self() << "/" << ThreadNo() << "<-- ExecuteAction "
745 //         << Automaton()->ActionName( nextaction ) << endl ;
746   return sts ;
747 }
748
749 int GraphExecutor::InNode::ErrorAction() {
750   cdebug << pthread_self() << "/" << ThreadNo() << " Automaton ErrorAction Node "
751          << Name() << endl;
752   return 0;
753 }
754
755 int GraphExecutor::InNode::VoidAction() {
756   cdebug << pthread_self() << "/" << ThreadNo() << " VoidAction "  << Name() << endl;
757   return 1;
758 }
759
760
761 int GraphExecutor::InNode::DataWaiting_SomeDataReadyAction() {
762   cdebug << pthread_self() << "/" << ThreadNo()
763          << " --> DataWaiting_SomeDataReadyAction from " << DataFromNode()
764          << " to " << Name() << endl;
765   unsigned int k;
766   int InReady = 0 ;
767   int res = 1;
768   bool LoopFinished = false ;
769   bool LoopBeginning = false ;
770   bool SwitchFinished = false ;
771
772   if ( IsEndLoopNode() && !GetChangeNodeInLoop()->GetOutPort()->BoolValue() ) {
773     LoopFinished = true ; // End of Loop
774   }
775   if ( IsLoopNode() && GetChangeNodeInLoop()->GetOutPort()->BoolValue() ) {
776     LoopBeginning = true ; // Beginning of Loop
777   }
778   if ( IsEndSwitchNode() && !GetChangeNodeInGate()->GetOutPort()->BoolValue() ) {
779     SwitchFinished = true ; // End of Switch
780   }
781   cdebug << pthread_self() << "/" << ThreadNo() << " " << Name() << " LoopFinished " << LoopFinished
782          << " LoopBeginning " << LoopBeginning << " SwitchFinished " << SwitchFinished << endl ;
783   for ( k = 0 ; k < (unsigned int ) GetNodeInPortsSize() ; k++ ) {
784     GraphBase::InPort * anInPort = GetChangeNodeInPort(k) ;
785     GraphBase::OutPort * anOutPort = anInPort->GetOutPort() ;
786     cdebug << pthread_self() << "/" << ThreadNo() << " " << Name() << " InPort " << anInPort->PortName() << endl ;
787     if ( anInPort->IsGate() && anOutPort == NULL ) {
788       InReady += 1 ;
789       anInPort->State( SUPERV::ReadyState ) ;
790       cdebug << pthread_self() << "/" << ThreadNo() << " " << Name() << " "
791              << anInPort->PortName() << " ControlPort inactive." << endl ;
792     }
793     else if ( strcmp( DataFromNode() , anOutPort->NodeName() ) ) {
794       if ( anInPort->State() == SUPERV::ReadyState ) {
795         InReady += 1 ;
796         cdebug << pthread_self() << "/" << ThreadNo() << " " << Name() << " "
797                << anInPort->PortName() << " Was Done from "
798                << anOutPort->NodeName() << " " << anOutPort->PortName()
799                << " ReadyState " ;
800 #ifdef _DEBUG_
801         if ( GraphBase::Base::_prof_debug ) {
802           anOutPort->StringValue( *GraphBase::Base::_fdebug ) ;
803         }
804 #endif
805         cdebug << endl ;
806       }
807       else if ( IsLoopNode() && anInPort->IsDataConnected() ) {
808         anInPort->State( SUPERV::ReadyState ) ;
809         InReady += 1 ;
810         cdebug << pthread_self() << "/" << ThreadNo() << " " << Name() << " "
811                << anInPort->PortName() << " Was Done from "
812                << anOutPort->NodeName() << " " << anOutPort->PortName()
813                << " LoopBeginning " << LoopBeginning ;
814 #ifdef _DEBUG_
815         if ( GraphBase::Base::_prof_debug ) {
816           anOutPort->StringValue( *GraphBase::Base::_fdebug ) ;
817         }
818 #endif
819         cdebug << endl ;
820       }
821       else if ( LoopFinished ) {
822         anInPort->State( SUPERV::ReadyState ) ;
823         InReady += 1 ;
824         cdebug << pthread_self() << "/" << ThreadNo() << " " << Name() << " "
825                << anInPort->PortName() << " Was Done from "
826                << anOutPort->NodeName() << " " << anOutPort->PortName()
827                << " LoopFinished" ;
828 #ifdef _DEBUG_
829         if ( GraphBase::Base::_prof_debug ) {
830           anOutPort->StringValue( *GraphBase::Base::_fdebug ) ;
831         }
832 #endif
833         cdebug << endl ;
834       }
835       else if ( anInPort->IsGate() && SwitchFinished ) {
836         anInPort->State( SUPERV::ReadyState ) ;
837         InReady += 1 ;
838         cdebug << pthread_self() << "/" << ThreadNo() << " " << Name() << " "
839                << anInPort->PortName() << " Was Done from "
840                << anOutPort->NodeName() << " " << anOutPort->PortName()
841                << " SwitchFinished" ;
842 #ifdef _DEBUG_
843         if ( GraphBase::Base::_prof_debug ) {
844           anOutPort->StringValue( *GraphBase::Base::_fdebug ) ;
845         }
846 #endif
847         cdebug << endl ;
848       }
849       else {
850         cdebug << pthread_self() << "/" << ThreadNo() << " " << Name() << " "
851                << anInPort->PortName() << " Was NOT Done from "
852                << anOutPort->NodeName() << " " << anOutPort->PortName() << " "
853                << " " << Automaton()->StateName( State() ) << " DataConnected "
854                << anInPort->IsDataConnected() << " LoopBeginning "
855                << LoopBeginning << endl ;
856       }
857     }
858     else if ( anInPort->IsGate() ) {
859       const CORBA::Any * theValue = anOutPort->Value() ;
860       long GateOpened ;
861       (*theValue) >>= GateOpened ;
862       if ( GateOpened != 0 ) {
863         InReady += 1 ;
864         anInPort->State( SUPERV::ReadyState ) ;
865         cdebug << pthread_self() << "/" << ThreadNo() << " " << Name() << " "
866                << anInPort->PortName() << " Gate is Opened from "
867                << anOutPort->NodeName() << " " << anOutPort->PortName()
868                << " " ;
869 #ifdef _DEBUG_
870         if ( GraphBase::Base::_prof_debug ) {
871           anOutPort->StringValue( *GraphBase::Base::_fdebug ) ;
872         }
873 #endif
874         cdebug << endl ;
875       }
876       else if ( LoopFinished ) {
877         anInPort->State( SUPERV::ReadyState ) ;
878         cdebug << pthread_self() << "/" << ThreadNo() << " " << Name() << " "
879                << anInPort->PortName() << " GATE IS CLOSED from "
880                << anOutPort->NodeName() << " " << anOutPort->PortName()
881                << " LoopFinished" ;
882 #ifdef _DEBUG_
883         if ( GraphBase::Base::_prof_debug ) {
884           anOutPort->StringValue( *GraphBase::Base::_fdebug ) ;
885         }
886 #endif
887         cdebug << endl ;
888       }
889       else {
890         cdebug << pthread_self() << "/" << ThreadNo() << " " << Name() << " "
891                << anInPort->PortName() << " GATE IS CLOSED from "
892                << anOutPort->NodeName() << " " << anOutPort->PortName()
893                << " " ;
894 #ifdef _DEBUG_
895         if ( GraphBase::Base::_prof_debug ) {
896           anOutPort->StringValue( *GraphBase::Base::_fdebug ) ;
897         }
898 #endif
899         cdebug << endl ;
900       }
901     }
902     else {
903       InReady += 1 ;
904       anInPort->State( SUPERV::ReadyState ) ;
905       cdebug << pthread_self() << "/" << ThreadNo() << " " << Name() << " "
906              << anInPort->PortName() << " is Done from "
907              << anOutPort->NodeName() << " " << anOutPort->PortName() << " " ;
908 #ifdef _DEBUG_
909         if ( GraphBase::Base::_prof_debug ) {
910           anOutPort->StringValue( *GraphBase::Base::_fdebug ) ;
911         }
912 #endif
913         cdebug << endl ;
914     }
915   }
916   
917   if ( InReady == GetNodeInPortsSize() ) { // All Flags != 0 :
918     res = SendEvent( GraphExecutor::AllDataReadyEvent ); // ==> Ready to execute
919   }
920   else { // At least one Flag == 0 :
921     res = SendEvent( GraphExecutor::NotAllDataReadyEvent );
922   }
923
924   cdebug << pthread_self() << "/" << ThreadNo()
925          << " <-- DataWaiting_SomeDataReadyAction "  << Name() << endl;
926   return res ;
927
928 }
929
930 int GraphExecutor::InNode::DataUndef_NotAllDataReadyAction() {
931   CreateNewThreadIf( false ) ;
932 //  cdebug << pthread_self() << " for " << ThreadNo()
933 //         << " DataUndef_NotAllDataReadyAction " << Name() << endl;
934   return 1;
935 }
936
937 int GraphExecutor::InNode::DataUndef_AllDataReadyAction() {
938 //  cdebug << pthread_self() << "/" << ThreadNo()
939 //         << " --> DataUndef_AllDataReadyAction " << Name()
940 //         << " CreateNewThreadIf " << CreateNewThreadIf() << " IsLockedDataWait "
941 //         << IsLockedDataWait() ;
942   if ( IsLockedDataWait() ) {
943 //    cdebug << " WOULD DEAD-LOCK" << endl ;
944     return 0 ; // ==> DataUndef_AllDataReadyAction() after UnLockDataWait()
945   }
946 //  cdebug << endl ;
947   CreateNewThread( CreateNewThreadIf() ) ;
948   if ( !CreateNewThread() ) {
949 //    cdebug << "Thread " << ThreadNo() << "-->" << pthread_self() << endl ;
950     ThreadNo( pthread_self() ) ;
951   }
952   _OutNode->PushEvent( this , GraphExecutor::AllDataReadyEvent ,
953                        SUPERV::DataReadyState ) ; 
954   ReadyAction() ;
955   SUPERV::ControlState aControl = ControlState() ;
956   switch ( aControl ) {
957   case SUPERV::VoidState : {
958     SendEvent( GraphExecutor::ExecuteEvent ) ;
959     break ;
960   }
961   case SUPERV::ToSuspendState : {
962     SendEvent( GraphExecutor::SuspendEvent ) ;
963     break ;
964   }
965   case SUPERV::ToSuspendStartState : {
966     SendEvent( GraphExecutor::SuspendEvent ) ;
967     break ;
968   }
969   case SUPERV::ToSuspendDoneState : {
970     SendEvent( GraphExecutor::ExecuteEvent ) ;
971     break ;
972   }
973   case SUPERV::ToKillState : {
974     SendEvent( GraphExecutor::KillEvent ) ;
975     break ;
976   }
977   case SUPERV::ToKillDoneState : {
978     SendEvent( GraphExecutor::ExecuteEvent ) ;
979     break ;
980   }
981   case SUPERV::ToStopState : {
982     SendEvent( GraphExecutor::StopEvent ) ;
983     break ;
984   }
985   default : {
986     cdebug << ThreadNo()
987            << " GraphExecutor::InNodeThreads::DataUndef_AllDataReadyAction Error Undefined Control : "
988            << aControl << endl ;
989     return 0;
990   }
991   }
992 //  cdebug << pthread_self() << "/" << ThreadNo()
993 //         << " <-- DataUndef_AllDataReadyAction " << Name() << endl;
994   return 1;
995 }
996
997 int GraphExecutor::InNode::DataReady_SuspendAction() {
998   cdebug << pthread_self() << "/" << ThreadNo()
999          << "DataReady_SuspendAction --> Suspend " << Name()
1000          << " Threads " << _OutNode->Threads() << " SuspendedThreads "
1001          << _OutNode->SuspendedThreads() << endl;
1002   _OutNode->PushEvent( this , GraphExecutor::SuspendedReadyEvent ,
1003                        SUPERV::SuspendedReadyState ) ;
1004   GraphExecutor::InNode * aReStartNode = SuspendAction() ;
1005   cdebug << pthread_self() << "/" << ThreadNo()
1006          << "DataReady_SuspendAction Resumed " << Name() << endl;
1007   if ( aReStartNode ) {
1008     _aReStartNode = NULL ;
1009     aReStartNode->SendEvent( _aReStartEvent ) ;
1010   }
1011   else {
1012     SendEvent( GraphExecutor::ExecuteEvent ) ;
1013   }
1014   return 1 ;
1015 }
1016
1017 int GraphExecutor::InNode::SuspendedReady_ResumeAction() {
1018   cdebug << pthread_self() << "/" << ThreadNo() << "SuspendedReady_ResumeAction "
1019          << Name() << endl;
1020 //  ResumeAction() ;
1021   _OutNode->PushEvent( this , GraphExecutor::ResumedReadyEvent ,
1022                        SUPERV::ResumedReadyState ) ; 
1023   return 1 ;
1024 }
1025
1026 int GraphExecutor::InNode::DataReady_KillAction() {
1027   _OutNode->PushEvent( this , GraphExecutor::KilledReadyEvent ,
1028                        SUPERV::KilledReadyState ) ;
1029   KillAction() ;
1030   cdebug << pthread_self() << "/" << ThreadNo() << "DataReady_KillAction " << Name()
1031          << " will pthread_exit()" << endl;
1032   return 1 ;
1033 }
1034
1035 int GraphExecutor::InNode::DataReady_StopAction() {
1036   _OutNode->PushEvent( this , GraphExecutor::StoppedReadyEvent ,
1037                        SUPERV::StoppedReadyState ) ; 
1038   StopAction() ;
1039   cdebug << pthread_self() << "/" << ThreadNo() << "DataReady_StopAction " << Name()
1040          << " will pthread_exit()" << endl;
1041   return 1 ;
1042 }
1043
1044 #include <CORBA.h>
1045
1046 int GraphExecutor::InNode::DataReady_ExecuteAction() {
1047   int i;
1048
1049 //  cdebug << pthread_self() << "/" << ThreadNo() << " --> DataReady_ExecuteAction "
1050 //         << Name() << endl;
1051   _OutNode->PushEvent( this , GraphExecutor::ExecuteEvent ,
1052                        SUPERV::ExecutingState ) ; 
1053
1054   RunningAction() ;
1055   SUPERV::GraphState PortState = SUPERV::ReadyState ;
1056   SUPERV::AutomatonState NewState = SUPERV::DataUndefState ;
1057   GraphExecutor::NodeEvent NewEvent = GraphExecutor::UndefinedEvent ;
1058
1059   bool Err = false ;
1060
1061   int nInParams = GetNodeInPortsSize()  ;
1062   ServicesAnyData * InParametersList = new ServicesAnyData[nInParams];
1063   InParametersSet( Err , nInParams , InParametersList ) ;
1064
1065   Engines::Container_var myContainer ;
1066   Engines::Component_var myObjComponent ;
1067   if ( !IsFactoryNode() ) {
1068 //    cdebug << ThreadNo() << "No Component : NO StartComponent & No Ping" << endl ;
1069     if ( IsComputingNode() ) {
1070       ObjInterface( true ) ;
1071       CORBA::Object_ptr obj ;
1072       InParametersList[0].Value >>= obj ;
1073       CORBA::Object_var objvar = CORBA::Object_var( obj ) ;
1074       myObjComponent = Engines::Component::_narrow( objvar ) ;
1075     }
1076     else {
1077     }
1078   }
1079   else if ( CORBA::is_nil( Component() ) ) {
1080     ostringstream astr ;
1081     astr << "Graph " << _OutNode->Graph()->Name() << " Node " << Name()
1082          << " : load of component " << ComponentName() << " in container "
1083          << Computer() ;
1084 //    _OutNode->Graph()->ObjImpl()->sendMessage( NOTIF_STEP, astr.str().c_str() ) ;
1085     Err = !_OutNode->Graph()->StartComponent( ThreadNo() , Computer() ,
1086                                               my_strdup( ComponentName() ) ,
1087                                               myContainer , myObjComponent ) ;
1088     ObjInterface( false ) ;
1089     SetContainer( myContainer ) ;
1090     SetComponent( myObjComponent ) ;
1091   }
1092   else {
1093     myContainer = Container() ;
1094     myObjComponent = Component() ;
1095 //    cdebug << ThreadNo() << "Component known : NO StartComponent & Ping"
1096 //           << endl ;
1097     try {
1098       myObjComponent->ping() ;
1099     }
1100     catch( ... ) {
1101       cdebug << "ping() catched" << endl ;
1102       Err = true ;
1103     }
1104   }
1105
1106   int nOutParams = GetNodeOutPortsSize()  ;
1107   ServicesAnyData * OutParametersList = new ServicesAnyData[nOutParams];
1108   InOutParametersSet( nOutParams , OutParametersList ) ;
1109
1110     if ( Err || ControlState() == SUPERV::ToKillState ||
1111                 ControlState() == SUPERV::ToKillDoneState ||
1112                 ControlState() == SUPERV::ToStopState ) {
1113       cdebug << ThreadNo() << "StartComponent Error or ToKillState" << endl ;
1114       Err = true ;
1115     }
1116     else {
1117       if ( !Err ) {
1118         ostringstream astr ;
1119         astr << "Graph " << _OutNode->Graph()->Name() << " Run of Node " << Name() ;
1120 //        _OutNode->Graph()->ObjImpl()->sendMessage( NOTIF_STEP, astr.str().c_str() ) ;
1121         cdebug << ThreadNo() << " Run( '" << ServiceName() << "'" ;
1122         for ( i = 0 ; i < (int ) ServiceInParameter().length() ; i++ ) {
1123           cdebug << " , " << InParametersList[ i ].Name << "[kind"
1124                  << InParametersList[ i ].Value.type()->kind() << "]" ;
1125         }
1126         for ( i = 0 ; i < (int ) ServiceOutParameter().length() ; i++ ) {
1127           cdebug << " , " << OutParametersList[ i ].Name << "[kind"
1128                  << OutParametersList[ i ].Value.type()->kind() << "]" ;
1129         }
1130         if ( IsOneOfInLineNodes() ) {
1131           cdebug << " , PyFuncName '" << InLineNode()->PyFuncName() << "' PyRunMethod "
1132                  << InLineNode()->PyRunMethod() << " length " << (*InLineNode()->PythonFunction()).length() ;
1133         }
1134         cdebug << ")" << endl ;
1135
1136         if ( IsOneOfInLineNodes() ) {
1137           bool StsPyDynInvoke = true;
1138           _OutNode->PyThreadLock() ;
1139           SetPyCpuUsed() ;
1140           try {
1141 //            if ( IsInLineNode() && (*InLineNode()->PythonFunction()).length() &&
1142             bool CopyInOut = false ;
1143             if ( IsInLineNode() && /*InLineNode()->PyRunMethod() &&*/
1144                  strlen( InLineNode()->PyFuncName() ) ) {
1145 //              cdebug << ThreadNo() << " !ObjInterface " << Name() << " PyFuncName '"
1146 //                     << InLineNode()->PyFuncName()
1147 //                     << "' IsInLineNode PyDynInvoke"  << endl ;
1148               StsPyDynInvoke = PyDynInvoke( InLineNode()->PyRunMethod() ,
1149                                             InLineNode()->PyFuncName() ,
1150                                             &InParametersList[0] , ServiceInParameter().length() ,
1151                                             &OutParametersList[0] , ServiceOutParameter().length() ) ;
1152             }
1153             else if ( IsLoopNode() ) {
1154               bool CopyOutIn = false ;
1155               if ( GetNodeInLoop()->GetOutPort()->BoolValue() && /*InLineNode()->PyRunMethod() &&*/
1156                    strlen( InLineNode()->PyFuncName() ) ) { // InLoop Port
1157 //                cdebug << ThreadNo() << " !ObjInterface " << Name()
1158 //                       << " IsLoopNode PyDynInvoke '" << InLineNode()->PyFuncName()
1159 //                       << "'" << endl ;
1160                 StsPyDynInvoke = PyDynInvoke( InLineNode()->PyRunMethod() ,
1161                                               InLineNode()->PyFuncName() ,
1162                                               &InParametersList[1] , ServiceInParameter().length() ,
1163                                               &OutParametersList[1] , ServiceOutParameter().length() ) ;
1164                 CopyOutIn = true ;
1165               }
1166               else if ( LoopNode()->PyNextMethod() &&
1167                         strlen( LoopNode()->PyNextName() ) ){
1168 //                cdebug << ThreadNo() << " !ObjInterface " << Name()
1169 //                       << " IsLoopNode PyDynInvoke '" << LoopNode()->PyNextName()
1170 //                       << "'" << endl ;
1171                 StsPyDynInvoke = PyDynInvoke( LoopNode()->PyNextMethod() ,
1172                                               LoopNode()->PyNextName() ,
1173                                               &InParametersList[1] , ServiceInParameter().length() ,
1174                                               &OutParametersList[1] , ServiceOutParameter().length() ) ;
1175                 CopyOutIn = true ;
1176               }
1177               if ( StsPyDynInvoke && CopyOutIn ) {
1178 //                cdebug << ThreadNo() << " !ObjInterface " << Name()
1179 //                       << " IsLoopNode PyDynInvoke '" << LoopNode()->PyMoreName()
1180 //                       << "' Copy of " << ServiceInParameter().length()
1181 //                       << " OutParameters" << endl ;
1182                 int i ;
1183                 for ( i = 1 ; i <= (int ) ServiceInParameter().length() ; i++ ) {
1184                   InParametersList[i].Value = OutParametersList[i].Value ;
1185                   InParametersList[i].Name = OutParametersList[i].Name ;
1186 //#if 0
1187                   switch ( InParametersList[i].Value.type()->kind() ) {
1188                   case CORBA::tk_string :
1189                     char * t;
1190                     InParametersList[i].Value >>= t ;
1191                     cdebug << "ArgOut->In" << i << " : "
1192                            << InParametersList[i].Name.c_str()
1193                            << " Value(string) " << t << endl ;
1194                     break ;
1195                   case CORBA::tk_double :
1196                     double d;
1197                     InParametersList[i].Value >>= d;
1198                     cdebug << "ArgOut->In" << i << " : "
1199                            << InParametersList[i].Name.c_str()
1200                            << " Value(double) " << d << endl ;
1201                     break ;
1202                   case CORBA::tk_long :
1203                     long l;
1204                     InParametersList[i].Value >>= l;
1205                     cdebug << "ArgOut->In" << i << " : "
1206                            << InParametersList[i].Name.c_str()
1207                            << " Value(long) " << l << endl ;
1208                     break ;
1209                   case CORBA::tk_objref :
1210                     CORBA::Object_ptr obj ;
1211                     char * retstr ;
1212                     try {
1213                       InParametersList[i].Value >>= obj ;
1214                       retstr = ObjectToString( obj );
1215                       cdebug << "ArgOut->In" << i << " : "
1216                              << InParametersList[i].Name.c_str()
1217                              << " Value(object reference) " << retstr << endl ;
1218                      }
1219                     catch ( ... ) {
1220                       cdebug << "ArgOut->In" << i << " : "
1221                              << InParametersList[i].Name.c_str()
1222                              << " Value(object reference) Catched ERROR" << endl ;
1223                     }
1224                     break ;
1225                   default :
1226                     cdebug << "ArgOut->In" << i << " : "
1227                            << InParametersList[i].Name.c_str()
1228                            << " Value(other) ERROR" << endl ;
1229                   }
1230 //#endif
1231                 }
1232                 if ( LoopNode()->PyMoreMethod() && strlen( LoopNode()->PyMoreName() ) ) {
1233                   StsPyDynInvoke = PyDynInvoke( LoopNode()->PyMoreMethod() ,
1234                                                 LoopNode()->PyMoreName() ,
1235                                                 &InParametersList[1] , ServiceInParameter().length() ,
1236                                                 &OutParametersList[0] , ServiceOutParameter().length()+1 ) ;
1237                 }
1238                 else {
1239                   CopyInOut = true ;
1240                 }
1241               }
1242               else  if ( !StsPyDynInvoke ) {
1243                 Err = true ;
1244                 cdebug << ThreadNo() << " InLineNode " << Name() << " "
1245                        << InLineNode()->PyFuncName() << "/" << LoopNode()->PyNextName()
1246                        << " Python Dynamic Call Error"
1247                        << endl ;
1248               }
1249             }
1250             else if ( IsSwitchNode() && /*InLineNode()->PyRunMethod() &&*/
1251                       strlen( InLineNode()->PyFuncName() ) ) {
1252 //              cdebug << ThreadNo() << " !ObjInterface " << Name() << " PyFuncName '"
1253 //                     << InLineNode()->PyFuncName()
1254 //                     << "' IsSwitchNode PyDynInvoke"  << endl ;
1255               StsPyDynInvoke = PyDynInvoke( InLineNode()->PyRunMethod() ,
1256                                             InLineNode()->PyFuncName() ,
1257                                             &InParametersList[0] , ServiceInParameter().length() ,
1258                                             &OutParametersList[0] , ServiceOutParameter().length() ) ;
1259             }
1260 //            else if ( IsGOTONode() && (*GOTONode()->PythonFunction()).length() &&
1261             else if ( IsGOTONode() && /*InLineNode()->PyRunMethod() &&*/
1262                       strlen( InLineNode()->PyFuncName() ) ) {
1263 //              cdebug << ThreadNo() << " !ObjInterface " << Name() << " PyFuncName '"
1264 //                     << InLineNode()->PyFuncName()
1265 //                     << "' IsGOTONode PyDynInvoke"  << endl ;
1266               StsPyDynInvoke = PyDynInvoke( InLineNode()->PyRunMethod() ,
1267                                             InLineNode()->PyFuncName() ,
1268                                             &InParametersList[0] , ServiceInParameter().length() ,
1269                                             &OutParametersList[0] , ServiceOutParameter().length() ) ;
1270             }
1271 //            else if ( IsEndSwitchNode() && (*InLineNode()->PythonFunction()).length() &&
1272             else if ( ( IsEndSwitchNode() ) &&
1273                       InLineNode()->PyRunMethod() && strlen( InLineNode()->PyFuncName() ) ) {
1274 //              cdebug << ThreadNo() << " !ObjInterface " << Name() << " PyFuncName '"
1275 //                     << InLineNode()->PyFuncName()
1276 //                     << "' IsSwitchNode PyDynInvoke"  << endl ;
1277               StsPyDynInvoke = PyDynInvoke( InLineNode()->PyRunMethod() ,
1278                                             InLineNode()->PyFuncName() ,
1279                                             &InParametersList[0] , ServiceInParameter().length() ,
1280                                             &OutParametersList[0] , ServiceOutParameter().length() ) ;
1281             }
1282             else if ( ( IsEndLoopNode() ) &&
1283                       InLineNode()->PyRunMethod() && strlen( InLineNode()->PyFuncName() ) ) {
1284 //              cdebug << ThreadNo() << " !ObjInterface " << Name() << " PyFuncName '"
1285 //                     << InLineNode()->PyFuncName()
1286 //                     << "' IsSwitchNode PyDynInvoke"  << endl ;
1287               StsPyDynInvoke = PyDynInvoke( InLineNode()->PyRunMethod() ,
1288                                             InLineNode()->PyFuncName() ,
1289                                             &InParametersList[0] , ServiceInParameter().length() + 1 ,
1290                                             &OutParametersList[0] , ServiceOutParameter().length() + 1 ) ;
1291             }
1292 //            else if ( (*InLineNode()->PythonFunction()).length() == 0 ||
1293             if ( InLineNode()->PyRunMethod() == NULL ||
1294                  strlen( InLineNode()->PyFuncName() ) == 0 || CopyInOut ) {
1295 //              cdebug << ThreadNo() << " !ObjInterface " << Name()
1296 //                     << " Copy of " << ServiceInParameter().length()
1297 //                     << " OutParameters" << endl ;
1298               int i ;
1299               int argout0 = 0 ;
1300               int argin0 = 0 ;
1301               if ( IsLoopNode() || IsEndLoopNode() ) {
1302                 argout0 = 1 ;
1303                 argin0 = 1 ; // after DoLoop
1304                 if ( IsLoopNode() ) {
1305                   OutParametersList[0].Value = InParametersList[0].Value ; // DoLoop
1306                 }
1307               }
1308               for ( i = 0 ; i < (int ) ServiceInParameter().length() ; i++ ) {
1309                 OutParametersList[argout0 + i].Value = InParametersList[argin0 + i].Value ;
1310 //#if 0
1311                 switch ( InParametersList[argin0 + i].Value.type()->kind() ) {
1312                 case CORBA::tk_string :
1313                   cdebug << "ArgOut->In" << argin0 + i << " : "
1314                          << InParametersList[argin0 + i].Name.c_str()
1315                          << " Value(string) "
1316                          << OutParametersList[argout0 + i].Name.c_str() << endl ;
1317                   break ;
1318                 case CORBA::tk_double :
1319                   cdebug << "ArgOut->In" << argin0 + i << " : "
1320                          << InParametersList[argin0 + i].Name.c_str()
1321                          << " Value(double) "
1322                          << OutParametersList[argout0 + i].Name.c_str() << endl ;
1323                   break ;
1324                 case CORBA::tk_long :
1325                   cdebug << "ArgOut->In" << argin0 + i << " : "
1326                          << InParametersList[argin0 + i].Name.c_str()
1327                          << " Value(long) "
1328                          << OutParametersList[argout0 + i ].Name.c_str() << endl ;
1329                   break ;
1330                 case CORBA::tk_objref :
1331                   cdebug << "ArgOut->In" << argin0 + i << " : "
1332                          << InParametersList[argin0 + i].Name.c_str()
1333                          << " Value(object reference) "
1334                          << OutParametersList[argout0 + i].Name.c_str() << endl ;
1335                   break ;
1336                 default :
1337                   cdebug << "ArgOut->In" << argin0 + i << " : "
1338                          << InParametersList[argin0 + i].Name.c_str()
1339                          << " Value(other) ERROR "
1340                          << OutParametersList[argout0 + i].Name.c_str() << endl ;
1341                 }
1342 //#endif
1343               }
1344             }
1345             if ( !StsPyDynInvoke ) {
1346               Err = true ;
1347               cdebug << ThreadNo() << " InLineNode " << Name()
1348                      << " Python Dynamic Call Error"
1349                      << endl ;
1350             }
1351           }
1352           catch( ... ) {
1353             Err = true ;
1354             cdebug << ThreadNo() << " InLineNode " << Name()
1355                    << " Python Dynamic Call Exception catched ERROR"
1356                    << endl ;
1357           }
1358           CpuUsed( true ) ;
1359           _OutNode->PyThreadUnLock() ;
1360         }
1361         else {
1362           try {
1363             try {
1364               cdebug << "DynInvoke -> Names " << _OutNode->Graph()->Name() << " " << Name() << endl ;
1365               DynInvoke( myObjComponent, "Names" ,
1366                          _OutNode->Graph()->Name() , Name() ) ;
1367             }
1368             catch( ... ) {
1369               cdebug << "DynInvoke Names catched ERROR" << endl ;
1370             }
1371 // for DataStreamNodes : call of SetProperties ===> environment variables in the component/container
1372             if ( ComputingNode()->HasDataStream() ) {
1373               try {
1374                 cdebug << "DynInvoke -> SetProperties " << _OutNode->Graph()->Name() << " " << Name() << endl ;
1375                 Engines::FieldsDict_var dict = new Engines::FieldsDict;
1376                 dict->length( 4 );
1377                 dict[ 0 ].key = CORBA::string_dup( "CAL_MACHINE");
1378                 // myContainer->getHostName() ne renvoit pas le nom complet (avec domaine).
1379                 //              dict[ 0 ].value <<= myContainer->getHostName() ;
1380                 char FullyQualifiedDomainName[256]="";
1381                 gethostname(FullyQualifiedDomainName,255);
1382                 dict[ 0 ].value <<=  FullyQualifiedDomainName ;
1383                 dict[ 1 ].key = CORBA::string_dup( "CAL_REPERTOIRE");
1384                 dict[ 1 ].value <<= "/tmp" ;
1385                 dict[ 2 ].key = CORBA::string_dup( "CAL_COUPLAGE");
1386                 stringstream ofst1 ;
1387                 ofst1 << ComputingNode()->SubStreamGraph() ;
1388                 string cpl = string( "/tmp/" ) + string( _OutNode->Graph()->Name() ) + string( "_" ) + 
1389                              ofst1.str() + string( ".cpl" );
1390                 dict[ 2 ].value <<= cpl.c_str() ;
1391                 dict[ 3 ].key = CORBA::string_dup( "SALOME_INSTANCE_NAME");
1392                 string uname = Name();
1393                 UpperCase( uname);
1394                 dict[ 3 ].value <<= uname.c_str() ;
1395
1396                 myObjComponent->setProperties( dict ) ;
1397               }
1398               catch( ... ) {
1399                 cdebug << "DynInvoke setProperties catched ERROR" << endl ;
1400                 Err = true ;
1401               }
1402             }
1403             if ( !Err && IsComputingNode() ) {
1404               cdebug << ThreadNo() << " !ObjInterface " << Name()
1405                      << " IsComputingNode DynInvoke"  << endl ;
1406               cdebug << ServiceInParameter().length()-1 << " input parameters and "
1407                      << ServiceOutParameter().length() << " output parameters" << endl ;
1408               DynInvoke( myObjComponent,
1409                          ServiceName() ,
1410                          &InParametersList[1] , ServiceInParameter().length()-1 ,
1411                          &OutParametersList[0] , ServiceOutParameter().length() ) ;
1412             }
1413             else if ( !Err &&IsFactoryNode() ) {
1414               cdebug << ThreadNo() << " !ObjInterface " << Name()
1415                      << " IsFactoryNode DynInvoke"  << endl ;
1416               cdebug << ServiceInParameter().length() << " input parameters and "
1417                      << ServiceOutParameter().length() << " output parameters" << endl ;
1418               DynInvoke( myObjComponent,
1419                          ServiceName() ,
1420                          &InParametersList[0] , ServiceInParameter().length() ,
1421                          &OutParametersList[0] , ServiceOutParameter().length() ) ;
1422             }
1423 //            cdebug << ThreadNo() << " Component::CpuUsed " << Name() << " "
1424 //                   << myObjComponent->CpuUsed_impl() << endl ;
1425           }
1426           catch( ... ) {
1427             Err = true ;
1428             cdebug << ThreadNo() << " !ObjInterface " << Name()
1429                    << " Node(Component) Dynamic Call Exception catched ERROR"
1430                    << endl ;
1431           }
1432         }
1433       }
1434     }
1435 //  }
1436 //  else {
1437 //    sleep( 1 ) ;
1438 //  }
1439
1440   ostringstream astr ;
1441   astr << "Graph " << _OutNode->Graph()->Name() << " Node " << Name() << " is done : "
1442        << Automaton()->StateName( State() ) ;
1443 //  _OutNode->Graph()->ObjImpl()->sendMessage( NOTIF_STEP, astr.str().c_str() ) ;
1444   if ( Err ) {
1445     if ( ControlState() == SUPERV::ToKillState ||
1446          ControlState() == SUPERV::ToKillDoneState ||
1447          ControlState() == SUPERV::ToStopState ) {
1448       PortState = SUPERV::ErrorState ;
1449       NewState = SUPERV::KilledState ;
1450       NewEvent = GraphExecutor::KillEvent ;
1451     }
1452     else {
1453       PortState = SUPERV::ErrorState ;
1454       NewState = SUPERV::ErroredState ;
1455       NewEvent = GraphExecutor::ErrorEvent ;
1456     }
1457   }
1458   else {
1459     PortState = SUPERV::ReadyState ;
1460     NewState = SUPERV::DataReadyState ;
1461     NewEvent = GraphExecutor::SuccessEvent ;
1462   }
1463
1464   bool ErrOut = OutParametersSet( Err , PortState , nOutParams , OutParametersList ) ;
1465               
1466   if ( !ErrOut ) {
1467     NewEvent = GraphExecutor::ErrorEvent ;
1468   }
1469           
1470   delete [] InParametersList ;
1471   delete [] OutParametersList ;
1472
1473               
1474   SendEvent( NewEvent );
1475
1476 //  cdebug << ThreadNo() << " <-- DataReady_ExecuteAction " << Name() << endl;
1477   return 1 ;
1478 }
1479
1480 int GraphExecutor::InNode::Executing_SuspendAction() {
1481   _OutNode->PushEvent( this , GraphExecutor::SuspendedExecutingEvent ,
1482                        SUPERV::SuspendedExecutingState ) ; 
1483   cdebug << ThreadNo() << " Executing_SuspendAction " << Name() << endl;
1484   return 1 ;
1485 }
1486
1487 int GraphExecutor::InNode::SuspendedExecuting_ResumeAction() {
1488   cdebug << ThreadNo() << " SuspendedExecuting_ResumeAction " << Name() << endl;
1489   SUPERV::AutomatonState next_state ;
1490   next_state = Automaton()->NextState( State() , GraphExecutor::ExecutingEvent ) ;
1491   _OutNode->NewThread() ; // Only for Threads count
1492   _OutNode->PushEvent( this , GraphExecutor::ResumedExecutingEvent ,
1493                        next_state ) ; 
1494   State( next_state ) ;
1495   return 1 ;
1496 }
1497
1498 int GraphExecutor::InNode::Executing_KillAction() {
1499   cdebug << ThreadNo() << " Executing_KillAction " << Name() << endl;
1500   int RetVal = 0 ;
1501   if ( pthread_self() == ThreadNo() ) {
1502     cdebug << "Executing_KillAction would pthread_canceled itself" << endl ;
1503     KillAction() ;
1504     _OutNode->PushEvent( this , GraphExecutor::KilledExecutingEvent ,
1505                          SUPERV::KilledExecutingState ) ; 
1506     RetVal = 1 ;
1507   }
1508   else if ( pthread_cancel( ThreadNo() ) ) {
1509     perror("Executing_KillAction pthread_cancel error") ;
1510   }
1511   else {
1512     cdebug << "Executing_KillAction : ThreadId " << ThreadNo()
1513            << " pthread_canceled" << endl ;
1514     KillAction() ;
1515     _OutNode->ExitThread() ;
1516     _OutNode->PushEvent( this , GraphExecutor::KilledExecutingEvent ,
1517                          SUPERV::KilledExecutingState ) ; 
1518   }
1519   return RetVal ;
1520 }
1521
1522 int GraphExecutor::InNode::Executing_StopAction() {
1523   cdebug << ThreadNo() << " Executing_StopAction " << Name() << endl;
1524   int RetVal = 0 ;
1525   if ( pthread_cancel( ThreadNo() ) ) {
1526     perror("Executing_KillAction pthread_cancel error") ;
1527   }
1528   else {
1529     cdebug << "Executing_KillAction : ThreadId " << ThreadNo()
1530            << " pthread_canceled" << endl ;
1531     StopAction() ;
1532     _OutNode->ExitThread() ;
1533     _OutNode->PushEvent( this , GraphExecutor::StoppedExecutingEvent ,
1534                          SUPERV::StoppedExecutingState ) ; 
1535   }
1536   return RetVal ;
1537 }
1538
1539 int GraphExecutor::InNode::Executing_SuccessAction() {
1540 //  cdebug << ThreadNo() << " --> Executing_SuccessAction " << Name() << endl;
1541   _OutNode->PushEvent( this , GraphExecutor::SuccessedExecutingEvent ,
1542                        SUPERV::SuccessedState ) ; 
1543   SUPERV::ControlState aControl = ControlState() ;
1544   switch ( aControl ) {
1545   case SUPERV::VoidState : {
1546     SendEvent( SuccessEvent ) ;
1547     break ;
1548   }
1549   case SUPERV::ToSuspendState : {
1550     SendEvent( SuccessEvent ) ;
1551     break ;
1552   }
1553   case SUPERV::ToSuspendDoneState : {
1554     SendEvent( GraphExecutor::SuspendEvent ) ;
1555     return 1 ;
1556   }
1557   case SUPERV::ToKillState : {
1558     SendEvent( GraphExecutor::KillEvent ) ;
1559     return 1 ;
1560   }
1561   case SUPERV::ToKillDoneState : {
1562     SendEvent( GraphExecutor::KillEvent ) ;
1563     return 1 ;
1564   }
1565   case SUPERV::ToStopState : {
1566     SendEvent( GraphExecutor::StopEvent ) ;
1567     return 1 ;
1568   }
1569   default : {
1570     cdebug << ThreadNo()
1571            << " GraphExecutor::InNodeThreads::Executing_SuccessAction Error Undefined Control : "
1572            << aControl << endl ;
1573     return 0;
1574   }
1575   }
1576 //  cdebug << ThreadNo() << " <-- Executing_SuccessAction "  << Name() << endl;
1577   return 1 ;
1578 }
1579
1580 int GraphExecutor::InNode::Executing_ErrorAction() {
1581   cdebug << ThreadNo() << " --> Executing_ErrorAction " << Name() << endl;
1582   _OutNode->PushEvent( this , GraphExecutor::ErroredExecutingEvent ,
1583                        SUPERV::ErroredState ) ; 
1584
1585   SUPERV::ControlState aControl = ControlState() ;
1586   switch ( aControl ) {
1587   case SUPERV::VoidState : {
1588     SendEvent( ErrorEvent ) ;
1589     break ;
1590   }
1591   case SUPERV::ToSuspendState : {
1592     SendEvent( ErrorEvent ) ;
1593     break ;
1594   }
1595   case SUPERV::ToSuspendDoneState : {
1596     SendEvent( GraphExecutor::SuspendEvent ) ;
1597     return 1 ;
1598   }
1599   case SUPERV::ToKillState : {
1600     SendEvent( GraphExecutor::KillEvent ) ;
1601     return 1 ;
1602   }
1603   case SUPERV::ToKillDoneState : {
1604     SendEvent( GraphExecutor::KillEvent ) ;
1605     return 1 ;
1606   }
1607   case SUPERV::ToStopState : {
1608     SendEvent( GraphExecutor::StopEvent ) ;
1609     return 1 ;
1610   }
1611   default : {
1612     cdebug << ThreadNo()
1613            << " GraphExecutor::InNodeThreads::Executing_ErrorAction Error Undefined Control : "
1614            << aControl << endl ;
1615     return 0;
1616   }
1617   }
1618   cdebug << ThreadNo() << " <-- Executing_ErrorAction "  << Name() << endl;
1619   return 1 ;
1620 }
1621
1622 // Set SUPERV::WaitingState to all InPorts 
1623 void GraphExecutor::InNode::SetWaitingStates(GraphExecutor::InNode * EndNode ) {
1624   int i ;
1625   int j ;
1626   bool docdebug = false ;
1627   State( SUPERV::DataWaitingState ) ;
1628   for ( i = 0 ; i < GetNodeInPortsSize() ; i++ ) {
1629     GraphBase::InPort * anInPort = GetChangeNodeInPort( i ) ;
1630     if ( anInPort->IsGate() ) { // Loop : Open the doors
1631       GraphBase::OutPort * anOutPort = anInPort->GetOutPort() ;
1632       if ( anOutPort ) {
1633         CORBA::Any * anAny = new CORBA::Any() ;
1634         *anAny <<= (long ) 1 ;
1635         anOutPort->Value( anAny ) ;
1636         anInPort->State( SUPERV::ReadyState ) ;
1637       }
1638     }
1639     else if ( anInPort->State() != SUPERV::WaitingState ) {
1640       if ( !docdebug ) {
1641 //        cdebug << ThreadNo()
1642 //               << " --> GraphExecutor::InNodeThreads::SetWaitingStates " << Name() << endl;
1643         docdebug = true ;
1644       }
1645       if ( !anInPort->IsDataStream() ) {
1646         anInPort->State( SUPERV::WaitingState ) ;
1647       }
1648     }
1649   }
1650   for ( i = 0 ; i < GetNodeOutPortsSize() ; i++ ) {
1651     GraphBase::OutPort * anOutPort = GetChangeNodeOutPort( i ) ;
1652     for ( j = 0 ; j < anOutPort->InPortsSize() ; j++ ) {
1653       if ( !( IsGOTONode() && anOutPort->IsGate() ) &&
1654            !( IsEndLoopNode() && ( anOutPort->IsGate() ||
1655               anOutPort->IsLoop() ) ) &&
1656            !anOutPort->IsDataStream() &&
1657            !anOutPort->ChangeInPorts( j )->IsDataStream() ) {
1658 //        cdebug << ThreadNo()
1659 //               << " GraphExecutor::InNodeThreads::SetWaitingStates "
1660 //               << Name() << "( " << anOutPort->PortName() << " ) --> InPort "
1661 //               << anOutPort->ChangeInPorts( j )->PortName() << " from Node "
1662 //               << anOutPort->ChangeInPorts( j )->NodeName() << endl;
1663         GraphExecutor::InNode * aNode = (GraphExecutor::InNode * ) _OutNode->Graph()->GetChangeGraphNode( anOutPort->ChangeInPorts( j )->NodeName() )->GetInNode() ;
1664         if ( aNode != EndNode ) {
1665           aNode->SetWaitingStates( EndNode ) ;
1666         }
1667       }
1668     }
1669   }
1670 }
1671
1672 int GraphExecutor::InNode::Successed_SuccessAction() {
1673 //  cdebug << ThreadNo() << " --> Successed_SuccessAction "  << Name() << endl;
1674   int res = 1;
1675   int linkednodesnumber = LinkedNodesSize() ;
1676   GraphExecutor::InNode *firstzeroNode = NULL ;
1677   GraphExecutor::InNode *firsttoNode = NULL ;
1678   GraphExecutor::InNode *toNode ;
1679   int i ;
1680   int j ;
1681   list<GraphExecutor::InNode *> SomeDataNodes ;
1682
1683   DoneAction() ;
1684
1685   if ( IsGOTONode() ||
1686        ( IsEndLoopNode() && GetNodeInLoop()->GetOutPort()->BoolValue() ) ) {
1687     cdebug << ThreadNo() << " Successed_SuccessAction " << Name()
1688            << " SetWaitingStates " << endl ;
1689     const GraphBase::OutPort * aGateOutPort ;
1690     if ( IsGOTONode() ) {
1691       aGateOutPort = GetNodeOutGate() ;
1692     }
1693     else {
1694       aGateOutPort = GetNodeOutLoop() ;
1695     }
1696     for ( i = 0 ; i < aGateOutPort->InPortsSize() ; i++ ) {
1697       const GraphBase::InPort * anInPort = aGateOutPort->InPorts( i ) ;
1698       GraphExecutor::InNode * aLabelNode = (GraphExecutor::InNode *) _OutNode->Graph()->GetChangeGraphNode( anInPort->NodeName() )->GetInNode() ;
1699 //      cdebug << ThreadNo() << " Successed_SuccessAction " << Name() << " will Loop to HeadNode "
1700 //             << aLabelNode->Name() << " from port " << anInPort->PortName() << endl ;
1701       aLabelNode->SetWaitingStates( this ) ;
1702       for ( j = 0 ; j < aLabelNode->GetNodeInPortsSize() ; j++ ) {
1703         const GraphBase::InPort * anInPort = aLabelNode->GetNodeInPort( j ) ;
1704         if ( anInPort->GetOutPort() ) {
1705 //          cdebug << aLabelNode->Name() << "(" << anInPort->PortName() << ") value : "
1706 //                 << anInPort->GetOutPort()->NodeName() << "(" << anInPort->GetOutPort()->PortName() << ")"
1707 //                 << endl ;
1708         }
1709       }
1710       for ( j = 0 ; j < GetNodeOutPortsSize() ; j++ ) {
1711         GraphBase::OutPort * aBusParamOutPort = GetChangeNodeOutPort( j ) ;
1712         if ( !aBusParamOutPort->IsGate() ) {
1713           GraphBase::InPort * aBusParamChangeInPort = NULL ;
1714           if ( aBusParamOutPort->IsLoop() ) {
1715             aBusParamChangeInPort = aLabelNode->GetChangeNodeInLoop() ;
1716           }
1717           else {
1718             aBusParamChangeInPort = aLabelNode->GetChangeInPort( aBusParamOutPort->PortName() ) ;
1719           }
1720           if ( aBusParamChangeInPort ) {
1721             aBusParamChangeInPort->ChangeOutPort( aBusParamOutPort ) ;
1722 //            cdebug << ThreadNo() << " Successed_SuccessAction " << Name() << " ChangeOutPort to HeadNode "
1723 //                   << aLabelNode->Name() << "(" << aBusParamChangeInPort->PortName() << ") from port "
1724 //                   << aBusParamOutPort->PortName() << endl ;
1725             if ( !aLabelNode->IsLockedDataWait() ) {
1726               res = aLabelNode->SendSomeDataReady( Name() ) ;
1727               if ( res ) {
1728                 if ( firsttoNode == NULL &&
1729                      aLabelNode->ThreadNo() == pthread_self() ) {
1730                   firsttoNode = aLabelNode ;
1731 //                  cdebug << ThreadNo() << " Successed_SuccessAction firsttoNode "
1732 //                         << aLabelNode->Name() << endl ;
1733                 }
1734                 else if ( firstzeroNode == NULL &&
1735                           aLabelNode->ThreadNo() == 0 ) {
1736                   firstzeroNode = aLabelNode ;
1737                 }
1738                 else {
1739                   SomeDataNodes.push_back( aLabelNode ) ;
1740 //                  cdebug << ThreadNo() << " Successed_SuccessAction " << Name() << " push "
1741 //                         << aLabelNode->Name() << " " << SomeDataNodes.size() 
1742 //                         << endl ;
1743                 }
1744               }
1745             }
1746             else {
1747 //              cdebug << ThreadNo()
1748 //                     << " Successed_SuccessAction Loop to HeadNode "
1749 //                     << aLabelNode->Name() << " with datas from " << Name() << "("
1750 //                     << aBusParamOutPort->PortName() << ") to port "
1751 //                     << aBusParamChangeInPort->PortName() << endl;
1752             }
1753           }
1754           else {
1755 //            cdebug << ThreadNo() << " ERROR in Successed_SuccessAction of " << Name()
1756 //                   << " NO port " << aBusParamOutPort->PortName() << " in "
1757 //                   << aLabelNode->Name() << endl;
1758           }
1759         }
1760       }
1761       for ( j = 0 ; j < aLabelNode->GetNodeInPortsSize() ; j++ ) {
1762         const GraphBase::InPort * anInPort = aLabelNode->GetNodeInPort( j ) ;
1763         if ( anInPort->GetOutPort() ) {
1764 //          cdebug << aLabelNode->Name() << "(" << anInPort->PortName() << ") value : "
1765 //                 << anInPort->GetOutPort()->NodeName() << "(" << anInPort->GetOutPort()->PortName() << ")"
1766 //                 << endl ;
1767         }
1768       }
1769       const GraphBase::InPort * aGateInPort = aLabelNode->GetNodeInGate() ;
1770       if ( aGateInPort ) {
1771         if ( aGateInPort->GetOutPort() ) {
1772           aGateInPort->GetOutPort()->Value( aGateOutPort->Value() ) ;
1773         }
1774         if ( !aLabelNode->IsLockedDataWait() ) {
1775           res = aLabelNode->SendSomeDataReady( Name() ) ;
1776           if ( res ) {
1777             if ( firsttoNode == NULL &&
1778                  aLabelNode->ThreadNo() == pthread_self() ) {
1779               firsttoNode = aLabelNode ;
1780 //              cdebug << ThreadNo() << " Successed_SuccessAction firsttoNode "
1781 //                     << aLabelNode->Name() << endl ;
1782             }
1783             else if ( firstzeroNode == NULL &&
1784                       aLabelNode->ThreadNo() == 0 ) {
1785               firstzeroNode = aLabelNode ;
1786             }
1787             else {
1788               SomeDataNodes.push_back( aLabelNode ) ;
1789 //              cdebug << ThreadNo() << " Successed_SuccessAction " << Name() << " push "
1790 //                     << aLabelNode->Name() << " " << SomeDataNodes.size()
1791 //                     << endl ;
1792             }
1793           }
1794         }
1795       }
1796       else {
1797         cdebug << ThreadNo() << " ERROR in Successed_SuccessAction of " << Name()
1798                << " NO port " << aGateOutPort->PortName() << " in "
1799                << aLabelNode->Name() << endl;
1800       }
1801     }
1802   }
1803
1804   else {
1805 //    cdebug << ThreadNo() << " Successed_SuccessAction of " << Name()
1806 //           << " with " << LinkedNodesSize() << " linked nodes :" ;
1807     for ( i = 0 ; i < LinkedNodesSize() ; i++ ) {
1808       if ( LinkedNodes( i )->IsDataFlowNode() ) {
1809         linkednodesnumber -= 1 ;
1810       }
1811 //      cdebug << " " << LinkedNodes( i )->Name() ;
1812     }
1813 //    cdebug << endl;
1814     for ( i = 0 ; i < LinkedNodesSize() ; i++ ) {
1815       bool IgnoreForEndLoop = false ;
1816       GraphBase::ComputingNode * aComputingNode ;
1817       aComputingNode = (GraphBase::ComputingNode * ) LinkedNodes( i ) ;
1818       toNode = (GraphExecutor::InNode *) aComputingNode->GetInNode() ;
1819 //      cdebug << ThreadNo() << " Successed_SuccessAction of " << Name()
1820 //             << " [" << i << "] " << LinkedNodes( i )->Name() << endl ;
1821       if ( toNode && !toNode->IsDataFlowNode() ) {
1822         if ( IsComputingNode() && toNode->IsInLineNode() ) {
1823           GraphBase::InPort * toGateInPort = toNode->GetChangeNodeInGate() ;
1824           toGateInPort->State( SUPERV::ReadyState ) ;
1825           GraphBase::OutPort * GateOutPort = toGateInPort->GetOutPort() ;
1826           if ( GateOutPort ) {
1827             GateOutPort->PortStatus( DataConnected );
1828             GateOutPort->State( SUPERV::ReadyState ) ;
1829             GateOutPort->Done( true ) ;
1830           }
1831         }
1832       }
1833       if ( toNode && IsLoopNode() ) {
1834         GraphBase::OutPort * fromLoopOutPort = GetChangeNodeOutLoop() ;
1835         if ( !fromLoopOutPort->BoolValue() ) { // Ne pas faire la boucle
1836           if ( strcmp( toNode->Name() , CoupledNode()->Name() ) ) {
1837             IgnoreForEndLoop = true ;
1838           }
1839           else { // toNode is the EndLoopNode
1840             GraphBase::InPort * toLoopInPort ;
1841             toLoopInPort = toNode->GetChangeNodeInLoop() ;
1842             if ( toLoopInPort->State() != SUPERV::ReadyState ) {
1843               toLoopInPort->State( SUPERV::ReadyState ) ;
1844             }
1845           }
1846         }
1847       }
1848       else if ( toNode && IsSwitchNode() ) {
1849       }
1850       else if ( toNode && toNode->IsInLineNode() ) {
1851         int j ;
1852         for ( j = 0 ; j < toNode->GetNodeInPortsSize() ; j++ ) {
1853           toNode->GetChangeNodeInPort( j )->InitialOutPort() ;
1854         }
1855       }
1856       if ( toNode && !IgnoreForEndLoop ) {
1857         if ( toNode && toNode->IsLoopNode() ) {
1858           GraphBase::InPort * toLoopInPort = toNode->GetChangeNodeInLoop() ;
1859           toLoopInPort->State( SUPERV::ReadyState ) ;
1860           GraphBase::OutPort * LoopOutPort = toLoopInPort->GetOutPort() ;
1861           LoopOutPort->PortStatus( DataConnected );
1862           LoopOutPort->State( SUPERV::ReadyState ) ;
1863           LoopOutPort->Done( true ) ;
1864           CORBA::Any * anAny = new CORBA::Any() ;
1865           *anAny <<= (long ) 1 ;
1866           LoopOutPort->Value( anAny ) ;
1867           int j ;
1868           for ( j = 0 ; j < toNode->GetNodeInPortsSize() ; j++ ) {
1869             toNode->GetChangeNodeInPort( j )->InitialOutPort() ;
1870           }
1871         }
1872         res = toNode->SendSomeDataReady( Name() ) ;
1873         if ( res ) {
1874           if ( firsttoNode == NULL &&
1875                toNode->ThreadNo() == pthread_self() ) {
1876             firsttoNode = toNode ;
1877 //            cdebug << ThreadNo() << " Successed_SuccessAction firsttoNode "
1878 //                   << toNode->Name() << endl ;
1879           }
1880           else if ( firstzeroNode == NULL &&
1881                     toNode->ThreadNo() == 0 ) {
1882             firstzeroNode = toNode ;
1883           }
1884           else {
1885             SomeDataNodes.push_back( toNode ) ;
1886 //            cdebug << ThreadNo() << " Successed_SuccessAction " << Name() << " push "
1887 //                   << toNode->Name() << " " << SomeDataNodes.size() << endl ;
1888           }
1889         }
1890       }
1891     }
1892   }
1893
1894   if ( firsttoNode == NULL && firstzeroNode ) {
1895     firsttoNode = firstzeroNode ;
1896 //    cdebug << ThreadNo()
1897 //           << " Successed_SuccessAction firsttoNode = firstzeroNode "
1898 //           << endl ;
1899   }
1900   else if ( firsttoNode && firstzeroNode ) {
1901     SomeDataNodes.push_back( firstzeroNode ) ;
1902 //    cdebug << ThreadNo() << " Successed_SuccessAction " << Name() << " push firstzeroNode "
1903 //           << firstzeroNode->Name() << " " << SomeDataNodes.size() << endl ;
1904   }
1905
1906   while ( SomeDataNodes.size() ) {
1907     GraphExecutor::InNode *aNode = SomeDataNodes.front() ;
1908     SomeDataNodes.pop_front() ;
1909 //    cdebug << pthread_self() << "/" << ThreadNo()
1910 //           << " Successed_SuccessAction pop "
1911 //           << SomeDataNodes.size() << " " << aNode->Name() << endl ;
1912     if ( aNode->State() == SUPERV::DataReadyState ) {
1913       aNode->CreateNewThreadIf( true ) ;
1914       aNode->UnLockDataWait() ;
1915       res = aNode->DataUndef_AllDataReadyAction() ;
1916     }
1917     else {
1918 //      cdebug << pthread_self() << "/" << ThreadNo() << " ERROR "
1919 //             << aNode->Name() << " "
1920 //             << Automaton()->StateName( aNode->State() ) << endl ;
1921     }
1922   }
1923
1924   if ( firsttoNode ) {
1925 //    cdebug << pthread_self() << "/" << ThreadNo()
1926 //           << " Successed_SuccessAction start firsttoNode "
1927 //           << SomeDataNodes.size() << " " << firsttoNode->Name() << endl ;
1928     firsttoNode->CreateNewThreadIf( false ) ;
1929     firsttoNode->RewindStack( RewindStack() ) ;
1930     if ( firsttoNode->State() == SUPERV::SuccessedState ) {
1931 //      cdebug << pthread_self() << "/" << ThreadNo() << " " << Name()
1932 //             << " : " << firsttoNode->Name() << " "
1933 //             << Automaton()->StateName( firsttoNode->State() )
1934 //             << " --> DataWaitingState for Thread "
1935 //             << firsttoNode->ThreadNo() << endl ;
1936       firsttoNode->State( SUPERV::DataWaitingState ) ;
1937     }
1938 //    pthread_t OldT = firsttoNode->ThreadNo() ;
1939     firsttoNode->ThreadNo( pthread_self() ) ;
1940 // On continue avec le meme thread
1941 //    cdebug << pthread_self() << "/" << ThreadNo() << " firsttoNode "
1942 //           << firsttoNode->Name() << "Thread(" << OldT << "-->"
1943 //           << firsttoNode->ThreadNo() << ")" << endl ;
1944     ThreadNo( 0 ) ;
1945 //    cdebug << ThreadNo() << " Successed_SuccessAction " << Name()
1946 //           << " for " << firsttoNode->Name()
1947 //           << " !firsttoNode->CreateNewThreadIf() "
1948 //           << !firsttoNode->CreateNewThreadIf()
1949 //           << " " << Automaton()->StateName( firsttoNode->State() ) ;
1950     if ( firsttoNode->State() == SUPERV::DataReadyState ) {
1951       cdebug << endl ;
1952       firsttoNode->UnLockDataWait() ;
1953       res = firsttoNode->DataUndef_AllDataReadyAction() ;
1954     }
1955     else {
1956       cdebug << " ERROR " << endl ;
1957     }
1958   }
1959   else {
1960 //    cdebug << ThreadNo() << " Successed_SuccessAction " << Name()
1961 //           << " NO DataReady ==> ThreadNo( 0 ) firsttoNode == NULL LINKEDnodesnumber " << linkednodesnumber << endl ;
1962     ThreadNo( 0 ) ;
1963   }
1964
1965 //  if ( linkednodesnumber == 0 && firsttoNode == NULL ) {
1966 //    cdebug << ThreadNo() << " Successed_SuccessAction " << Name() << " LinkedNodesSize " << LinkedNodesSize()
1967 //           << " firsttoNode == NULL LINKEDnodesnumber " << linkednodesnumber << " CHECK" << endl ;
1968 //    _OutNode->CheckAllDone() ;
1969 //  }
1970
1971 //  cdebug << pthread_self() << "/" << ThreadNo()
1972 //         << " <-- Successed_SuccessAction " << Name() << " linkednodesnumber "
1973 //         << linkednodesnumber << endl;
1974   return 1 ;
1975 }
1976
1977 bool GraphExecutor::InNode::SendSomeDataReady( char * FromNodeName ) {
1978   bool RetVal = false ;
1979   if ( IsDataFlowNode() ) {
1980 //    cdebug << ThreadNo() << " ----> " << Name()
1981 //         << " send Result to graph " << Name() << endl;
1982   }
1983   else {
1984 //    cdebug << pthread_self() << "/" << ThreadNo() << " ----> " << FromNodeName
1985 //           << " send SomeDataReady to " << Name() << " "
1986 //           << Automaton()->StateName( State() ) 
1987 //           << " CreateNewThreadIf() " << CreateNewThreadIf()
1988 //           << " LockedDataWait " << IsLockedDataWait() << endl;
1989 #if 0
1990     cout << pthread_self() << "/" << ThreadNo() << " ----> " << FromNodeName
1991          << " send SomeDataReady to " << Name() << " "
1992          << Automaton()->StateName( State() ) 
1993          << " CreateNewThreadIf() " << CreateNewThreadIf()
1994          << " LockedDataWait " << IsLockedDataWait() << endl;
1995 #endif
1996     if ( State() == SUPERV::SuccessedState ||
1997          State() == SUPERV::SuspendedSuccessedState ||
1998          State() == SUPERV::SuspendedSuccessedToReStartState ) {
1999 //      cdebug << ThreadNo() << " " << FromNodeName
2000 //             << " : " << Name() << " " << Automaton()->StateName( State() )
2001 //             << " --> DataWaitingState for Thread "
2002 //             << ThreadNo() << " " << endl ;
2003       State( SUPERV::DataWaitingState ) ;
2004     }
2005     LockDataWait() ;
2006     DataFromNode( FromNodeName ) ;
2007     RetVal = !SendEvent( GraphExecutor::SomeDataReadyEvent );
2008     if ( !RetVal ) {
2009       UnLockDataWait() ;
2010     }
2011   }
2012   return RetVal ;
2013 }
2014
2015 int GraphExecutor::InNode::Errored_ErrorAction() {
2016   cdebug << ThreadNo() << " Errored_ErrorAction " << Name()
2017          << " will pthread_exit" << endl;
2018   DoneAction() ;
2019   return 1 ;
2020 }
2021
2022 int GraphExecutor::InNode::Successed_SuspendAction() {
2023   cdebug << ThreadNo() << " Successed_SuspendAction -->Suspend " << Name()
2024          << " Threads " << _OutNode->Threads() << " SuspendedThreads "
2025          << _OutNode->SuspendedThreads() << endl;
2026   _OutNode->PushEvent( this , GraphExecutor::SuspendedSuccessedEvent ,
2027                        SUPERV::SuspendedSuccessedState ) ; 
2028   DoneAction() ;
2029   GraphExecutor::InNode * aReStartNode = SuspendAction() ;
2030   cdebug << ThreadNo() << " Successed_SuspendAction Resumed " << Name() ;
2031   if ( aReStartNode ) {
2032     _aReStartNode = NULL ;
2033     cdebug << " for " << aReStartNode->Name() << endl;
2034     aReStartNode->SendEvent( _aReStartEvent ) ;
2035   }
2036   else {
2037     cdebug << endl;
2038     SendEvent( GraphExecutor::ResumeEvent ) ;
2039   }
2040   return 1 ;
2041 }
2042
2043 int GraphExecutor::InNode::Errored_SuspendAction() {
2044   cdebug << ThreadNo() << " Errored_SuspendAction -->Suspend " << Name()
2045          << " Threads " << _OutNode->Threads() << " SuspendedThreads "
2046          << _OutNode->SuspendedThreads() << endl;
2047   _OutNode->PushEvent( this , GraphExecutor::SuspendedErroredEvent ,
2048                        SUPERV::SuspendedErroredState ) ; 
2049   DoneAction() ;
2050   GraphExecutor::InNode * aReStartNode = SuspendAction() ;
2051   cdebug << ThreadNo() << " Errored_SuspendAction Resumed " << Name()
2052          << endl;
2053   if ( aReStartNode ) {
2054     _aReStartNode = NULL ;
2055     aReStartNode->SendEvent( _aReStartEvent ) ;
2056   }
2057   else {
2058     SendEvent( GraphExecutor::ResumeEvent ) ;
2059   }
2060   return 1 ;
2061 }
2062
2063 int GraphExecutor::InNode::SuspendedSuccessed_ResumeAction() {
2064   cdebug << ThreadNo() << " SuspendedSuccessed_ResumeAction " << Name() << endl;
2065 //  ResumeAction() ;
2066   _OutNode->PushEvent( this , GraphExecutor::ResumedSuccessedEvent ,
2067                        SUPERV::ResumedSuccessedState ) ; 
2068   SendEvent( ResumedSuccessedEvent ) ;
2069   return 1 ;
2070 }
2071
2072 int GraphExecutor::InNode::SuspendedErrored_ResumeAction() {
2073   cdebug << ThreadNo() << " SuspendedErrored_ResumeAction " << Name() << endl;
2074 //  ResumeAction() ;
2075   _OutNode->PushEvent( this , GraphExecutor::ResumedErroredEvent ,
2076                        SUPERV::ResumedErroredState ) ; 
2077   SendEvent( ResumedErroredEvent ) ;
2078   return 1 ;
2079 }
2080
2081 int GraphExecutor::InNode::Successed_KillAction() {
2082   KillAction() ;
2083   _OutNode->PushEvent( this , GraphExecutor::KilledEvent ,
2084                        SUPERV::KilledSuccessedState ) ; 
2085   cdebug << ThreadNo() << " Successed_KillAction " << Name() << endl;
2086   return 1 ;
2087 }
2088
2089 int GraphExecutor::InNode::Errored_KillAction() {
2090   KillAction() ;
2091   _OutNode->PushEvent( this , GraphExecutor::KilledEvent ,
2092                        SUPERV::KilledErroredState ) ; 
2093   cdebug << ThreadNo() << " Errored_KillAction " << Name() << endl;
2094   return 1 ;
2095 }
2096
2097 int GraphExecutor::InNode::Successed_StopAction() {
2098   StopAction() ;
2099   _OutNode->PushEvent( this , GraphExecutor::StoppedEvent ,
2100                        SUPERV::StoppedSuccessedState ) ; 
2101   cdebug << ThreadNo() << " Successed_StopAction " << Name() << endl;
2102   return 1 ;
2103 }
2104
2105 int GraphExecutor::InNode::Errored_StopAction() {
2106   StopAction() ;
2107   _OutNode->PushEvent( this , GraphExecutor::StoppedEvent ,
2108                        SUPERV::StoppedErroredState ) ; 
2109   cdebug << ThreadNo() << " Errored_StopAction " << Name() << endl;
2110   return 1 ;
2111 }
2112
2113 int GraphExecutor::InNode::SuspendedSuccessed_ReStartAction() {
2114   cdebug << ThreadNo() << " SuspendedSuccessed_ReStartAction " << Name() << endl;
2115   _OutNode->PushEvent( this , GraphExecutor::ReStartedEvent ,
2116                        SUPERV::ReStartedState ) ;
2117   int i ;
2118   for ( i = 0 ; i < GetNodeInPortsSize() ; i++ ) {
2119     GetChangeNodeInPort( i )->State( SUPERV::ReadyState ) ;
2120   }
2121   SendEvent( ExecuteEvent ) ;
2122   cdebug << ThreadNo() << " SuspendedSuccessed_ReStartAction "  << Name() << endl;
2123   return 1 ;
2124 }
2125
2126 int GraphExecutor::InNode::SuspendedErrored_ReStartAction() {
2127   cdebug << ThreadNo() << " SuspendedErrored_ReStartAction " << Name() << endl;
2128   _OutNode->PushEvent( this , GraphExecutor::ReStartedEvent ,
2129                        SUPERV::ReStartedState ) ; 
2130   int i ;
2131   for ( i = 0 ; i < GetNodeInPortsSize() ; i++ ) {
2132     GetChangeNodeInPort( i )->State( SUPERV::ReadyState ) ;
2133   }
2134   SendEvent( ExecuteEvent ) ;
2135   cdebug << ThreadNo() << " SuspendedErrored_ReStartAction "  << Name() << endl;
2136   return 1 ;
2137 }
2138
2139 int GraphExecutor::InNode::SuspendedSuccessed_ReStartAndSuspendAction() {
2140   cdebug << ThreadNo() << " SuspendedSuccessed_ReStartAndSuspendAction " << Name()
2141          << endl;
2142   _OutNode->PushEvent( this , GraphExecutor::ReStartedAndSuspendEvent ,
2143                        SUPERV::ReStartedState ) ; 
2144   State( SUPERV::DataWaitingState ) ;
2145   if ( !Suspend() ) {
2146     cdebug << "InNode::Suspend() Node " << Name() << endl ;
2147     return false ;
2148   }
2149   else if ( SendEvent( GraphExecutor::SomeDataReadyEvent ) ) {
2150     cdebug << "InNode::SendEvent( SomeDataReadyEvent ) Node "
2151            << Name() << endl ;
2152     return false ;
2153   }
2154   cdebug << ThreadNo() << " SuspendedSuccessed_ReStartAndSuspendAction "  << Name()
2155          << endl;
2156   return 1 ;
2157 }
2158
2159 int GraphExecutor::InNode::SuspendedErrored_ReStartAndSuspendAction() {
2160   cdebug << ThreadNo() << " SuspendedErrored_ReStartAndSuspendAction " << Name()
2161          << endl;
2162   _OutNode->PushEvent( this , GraphExecutor::ReStartedAndSuspendEvent ,
2163                        SUPERV::ReStartedState ) ; 
2164   State( SUPERV::DataWaitingState ) ;
2165   if ( !Suspend() ) {
2166     cdebug << "InNode::Suspend() Node " << Name() << endl ;
2167     return false ;
2168   }
2169   else if ( SendEvent( GraphExecutor::SomeDataReadyEvent ) ) {
2170     cdebug << "InNode::SendEvent( SomeDataReadyEvent ) Node "
2171            << Name() << endl ;
2172     return false ;
2173   }
2174   cdebug << ThreadNo() << " SuspendedErrored_ReStartAndSuspendAction "  << Name()
2175          << endl;
2176   return 1 ;
2177 }
2178
2179 void GraphExecutor::InNode::InParametersSet( bool & Err ,
2180                                              int  nInParams ,
2181                                              ServicesAnyData * InParametersList ) {
2182   int i ;
2183   for ( i = 0 ; i < nInParams ; i++ ) {
2184     ServicesAnyData D = InParametersList[i];
2185     GraphBase::InPort * anInPort = GetChangeNodeInPort(i) ;
2186     GraphBase::OutPort * theOutPort = anInPort->GetOutPort() ;
2187     if ( anInPort->IsGate() && theOutPort == NULL ) {
2188       cdebug << ThreadNo() << " ArgIn" << i << " " << D.Name << " "
2189              << anInPort->GetServicesParameter().Parametertype
2190              << " is inactive. " << anInPort->Kind() << endl ;
2191     }
2192     else if ( anInPort->State() == SUPERV::ReadyState ) {
2193       if ( anInPort->IsGate() ) {
2194         CORBA::Any * anAny = new CORBA::Any() ;
2195         *anAny <<= (long ) 0 ;
2196         theOutPort->Value( anAny ) ;
2197       }
2198       if ( !anInPort->IsDataStream() ) {
2199         anInPort->State( SUPERV::WaitingState ) ;
2200       }
2201       D.Name = CORBA::string_dup( anInPort->GetServicesParameter().Parametername ) ;
2202       cdebug << ThreadNo() << " ArgIn" << i << " " << anInPort->Kind() ;
2203       cdebug << "      " << D.Name << " " << anInPort->GetServicesParameter().Parametertype << " : " ;
2204       D.Value = *theOutPort->Value() ; // CORBA::Any
2205       string _Type = CORBA::string_dup( anInPort->GetServicesParameter().Parametertype ) ;
2206       const char * Type = _Type.c_str() ;
2207       switch ( D.Value.type()->kind() ) { // { string , long , double , objref }
2208       case CORBA::tk_string:
2209         char * t;
2210         D.Value >>= t;
2211         cdebug << t << " (string)" ;
2212         if ( !strcmp( Type , "string" ) ) {
2213         }
2214         else if ( !strcmp( Type , "boolean" ) ) {
2215           bool b ;
2216           long d ;
2217           sscanf( t , "%ld" , &d ) ;
2218           b = (bool ) d ;
2219           D.Value <<=  (CORBA::Any::from_boolean ) b ;
2220 //          theOutPort->Value( D.Value ) ;
2221         }
2222         else if ( !strcmp( Type , "char" ) ) {
2223           unsigned char c ;
2224           long d ;
2225           sscanf( t , "%ld" , &d ) ;
2226           c = (short ) d ;
2227           D.Value <<=  (CORBA::Any::from_char ) c ;
2228           cdebug << "string '" << t << "' --> " << d << " --> char " << c ;
2229 //          theOutPort->Value( D.Value ) ;
2230         }
2231         else if ( !strcmp( Type , "short" ) ) {
2232           short s ;
2233           long d ;
2234           sscanf( t , "%ld" , &d ) ;
2235           s = (short ) d ;
2236           D.Value <<=  s ;
2237           cdebug << "string '" << t << "' --> " << d << " --> short " << s ;
2238 //          theOutPort->Value( D.Value ) ;
2239         }
2240         else if ( !strcmp( Type , "int" ) || !strcmp( Type , "long" ) ) {
2241           long l ;
2242           sscanf( t , "%ld" , &l ) ;
2243           D.Value <<=  l ;
2244           cdebug << "string '" << t << " --> long " << l ;
2245 //          theOutPort->Value( D.Value ) ;
2246         }
2247         else if ( !strcmp( Type , "float" ) ) {
2248           double d ;
2249           sscanf( t , "%lf" , &d ) ;
2250           float f = d ;
2251           D.Value <<= f ;
2252           cdebug << "string '" << t << "' --> " << setw(25) << setprecision(18) << d << " --> float " << " = "
2253                  << setw(25) << setprecision(18) << f ;
2254 //          theOutPort->Value( D.Value ) ;
2255         }
2256         else if ( !strcmp( Type , "double" ) ) {
2257           double d ;
2258           sscanf( t , "%lf" , &d ) ;
2259           D.Value <<= d ;
2260           cdebug << "string '" << t << " --> double " << setw(25) << setprecision(18) << d ;
2261 //          theOutPort->Value( D.Value ) ;
2262         }
2263 //        else if ( !strcmp( Type , "objref" ) ) {
2264         else { // Default
2265           CORBA::Object_ptr ObjRef ;
2266           try {
2267             ObjRef = StringToObject( t ) ;
2268             D.Value <<= ObjRef ;
2269           }
2270           catch( ... ) {
2271             D.Value <<= CORBA::Object::_nil() ;
2272           }
2273 //          theOutPort->Value( D.Value ) ;
2274         }
2275 //        else {
2276 //          cdebug << " (other ERROR)" << endl ;
2277 //        }
2278         cdebug << " --> call_kind " << D.Value.type()->kind() << endl ;
2279         break;
2280       case CORBA::tk_long:
2281         long l;
2282         D.Value >>= l;
2283         cdebug << l << " (long)" << endl ;
2284         if ( !strcmp( Type , "string" ) ) {
2285           char t[40] ;
2286           sprintf( t , "%ld" , l ) ;
2287           D.Value <<= t ;
2288 //          theOutPort->Value( D.Value ) ;
2289         }
2290         else if ( !strcmp( Type , "boolean" ) ) {
2291           bool b ;
2292           b = (bool ) l ;
2293           D.Value <<=  (CORBA::Any::from_boolean ) b ;
2294 //          theOutPort->Value( D.Value ) ;
2295         }
2296         else if ( !strcmp( Type , "char" ) ) {
2297           unsigned char c ;
2298           c = (unsigned char ) l ;
2299           D.Value <<=  (CORBA::Any::from_char ) c ;
2300 //          theOutPort->Value( D.Value ) ;
2301         }
2302         else if ( !strcmp( Type , "short" ) ) {
2303           short s ;
2304           s = (short ) l ;
2305           D.Value <<=  s ;
2306 //          theOutPort->Value( D.Value ) ;
2307         }
2308         else if ( !strcmp( Type , "int" ) || !strcmp( Type , "long" ) ) {
2309         }
2310         else if ( !strcmp( Type , "float" ) ) {
2311           float f ;
2312           f = (float ) l ;
2313           D.Value <<= f ;
2314 //          theOutPort->Value( D.Value ) ;
2315         }
2316         else if ( !strcmp( Type , "double" ) ) {
2317           double d ;
2318           d = (double ) l ;
2319           D.Value <<= d ;
2320 //          theOutPort->Value( D.Value ) ;
2321         }
2322 //        else if ( !strcmp( Type , "objref" ) ) {
2323         else { // Default
2324           D.Value <<= CORBA::Object::_nil() ;
2325 //          theOutPort->Value( D.Value ) ;
2326         }
2327 //        else {
2328 //          cdebug << " (other ERROR)" << endl ;
2329 //        }
2330         cdebug << " --> call_kind " << D.Value.type()->kind() << endl ;
2331         break;
2332       case CORBA::tk_double:
2333         double d;
2334         D.Value >>= d;
2335         cdebug << d << " (double)" << endl ;
2336         if ( !strcmp( Type , "string" ) ) {
2337           char t[40] ;
2338           sprintf( t , "%lf" , d ) ;
2339           D.Value <<= t ;
2340 //          theOutPort->Value( D.Value ) ;
2341         }
2342         else if ( !strcmp( Type , "boolean" ) ) {
2343           bool b ;
2344           b = (bool ) d ;
2345           D.Value <<=  (CORBA::Any::from_boolean ) b ;
2346 //          theOutPort->Value( D.Value ) ;
2347         }
2348         else if ( !strcmp( Type , "char" ) ) {
2349           unsigned char c ;
2350           c = (unsigned char ) d ;
2351           D.Value <<=  (CORBA::Any::from_char ) c ;
2352 //          theOutPort->Value( D.Value ) ;
2353         }
2354         else if ( !strcmp( Type , "short" ) ) {
2355           short s ;
2356           s = (short ) d ;
2357           D.Value <<=  s ;
2358 //          theOutPort->Value( D.Value ) ;
2359         }
2360         else if ( !strcmp( Type , "int" ) || !strcmp( Type , "long" ) ) {
2361           long l ;
2362           l = (long ) d ;
2363           D.Value <<= l ;
2364 //          theOutPort->Value( D.Value ) ;
2365         }
2366         else if ( !strcmp( Type , "float" ) ) {
2367           float f ;
2368           f = (float ) d ;
2369           D.Value <<= f ;
2370 //          theOutPort->Value( D.Value ) ;
2371         }
2372         else if ( !strcmp( Type , "double" ) ) {
2373         }
2374 //        else if ( !strcmp( Type , "objref" ) ) {
2375         else { // Default
2376           D.Value <<= CORBA::Object::_nil() ;
2377 //          theOutPort->Value( D.Value ) ;
2378         }
2379 //        else {
2380 //          cdebug << " (other ERROR)" << endl ;
2381 //        }
2382         cdebug << " --> call_kind " << D.Value.type()->kind() << endl ;
2383         break;
2384       case CORBA::tk_objref:
2385         if ( !strcmp( Type , "string" ) ) {
2386           CORBA::Object_ptr ObjRef ;
2387           char * retstr ;
2388           try {
2389             D.Value >>= ObjRef ;
2390             retstr = ObjectToString( ObjRef ) ;
2391             D.Value <<= retstr ;
2392 //            theOutPort->Value( D.Value ) ;
2393           }
2394           catch( ... ) {
2395             if ( i != 0 ) {
2396               Err = true ;
2397             }
2398             cdebug << "ToString( object ) Catched ERROR" << endl ;
2399           }
2400         }
2401         else if ( !strcmp( Type , "boolean" ) ) {
2402           bool b = 0 ;
2403           D.Value <<=  (CORBA::Any::from_boolean ) b ;
2404 //          theOutPort->Value( D.Value ) ;
2405         }
2406         else if ( !strcmp( Type , "char" ) ) {
2407           unsigned char c = 0 ;
2408           D.Value <<=  (CORBA::Any::from_char ) c ;
2409 //          theOutPort->Value( D.Value ) ;
2410         }
2411         else if ( !strcmp( Type , "short" ) ) {
2412           short s = 0 ;
2413           D.Value <<=  s ;
2414 //          theOutPort->Value( D.Value ) ;
2415         }
2416         else if ( !strcmp( Type , "int" ) || !strcmp( Type , "long" ) ) {
2417           long l = 0 ;
2418           D.Value <<= l ;
2419 //          theOutPort->Value( D.Value ) ;
2420         }
2421         else if ( !strcmp( Type , "float" ) ) {
2422           float f = 0 ;
2423           D.Value <<= f ;
2424 //          theOutPort->Value( D.Value ) ;
2425         }
2426         else if ( !strcmp( Type , "double" ) ) {
2427           double d = 0 ;
2428           D.Value <<= d ;
2429 //          theOutPort->Value( D.Value ) ;
2430         }
2431 //        else if ( !strcmp( Type , "objref" ) ) {
2432         else { // Default
2433           CORBA::Object_ptr obj ;
2434           char * retstr ;
2435           try {
2436             D.Value >>= obj ;
2437             retstr = ObjectToString( obj ) ;
2438             cdebug << retstr << endl ;
2439           }
2440           catch( ... ) {
2441             if ( i != 0 ) {
2442               Err = true ;
2443             }
2444             cdebug << "ToString( object ) Catched ERROR" << endl ;
2445           }
2446         }
2447 //        else {
2448 //          cdebug << " (other ERROR)" << endl ;
2449 //        }
2450         cdebug << " --> call_kind " << D.Value.type()->kind() << endl ;
2451         break;
2452       default:
2453         cdebug << " (other ERROR) " << D.Value.type()->kind() << endl ;
2454       }
2455     }
2456     else {
2457       cdebug << ThreadNo() << " In" << i << " : wrong state ERROR State "
2458              << anInPort->State() << " NameState "
2459              << Automaton()->StateName( anInPort->State() ) << " PortName "
2460              << anInPort->PortName() << " Parametername "
2461              << anInPort->GetServicesParameter().Parametername << endl ;
2462       Err = true ;
2463     }
2464     InParametersList[i] = D ;
2465   }
2466 }
2467
2468 void GraphExecutor::InNode::InOutParametersSet( int nOutParams ,
2469                                                 ServicesAnyData * OutParametersList ) {
2470   int i ;
2471   for ( i = 0 ; i < nOutParams ; i++ ) {
2472     ServicesAnyData D = OutParametersList[i] ;
2473
2474     D.Name = GetChangeNodeOutPort(i)->GetServicesParameter().Parametername;
2475     string _Type = CORBA::string_dup(GetChangeNodeOutPort(i)->GetServicesParameter().Parametertype) ;
2476     const char * Type = _Type.c_str() ;
2477     bool OutDone = GetChangeNodeOutPort(i)->Done() ;
2478     cdebug << ThreadNo() << " ArgOut" << i << " " << D.Name << " Done("
2479            << OutDone << ") " << Type << " : " << endl ;
2480     if ( !strcmp( Type , "string" ) ) {
2481       D.Value <<= (char *) NULL ;
2482     }
2483     else if ( !strcmp( Type , "boolean" ) ) {
2484       bool b = 0 ;
2485       D.Value <<=  (CORBA::Any::from_boolean ) b ;
2486     }
2487     else if ( !strcmp( Type , "char" ) ) {
2488       unsigned char c = 0 ;
2489       D.Value <<=  (CORBA::Any::from_char ) c ;
2490     }
2491     else if ( !strcmp( Type , "short" ) ) {
2492       short s = 0 ;
2493       D.Value <<=  s ;
2494     }
2495     else if ( !strcmp( Type , "int" ) || !strcmp( Type , "long" ) ) {
2496       D.Value <<= (long ) 0 ;
2497     }
2498     else if ( !strcmp( Type , "float" ) ) {
2499       float f = 0 ;
2500       D.Value <<= f ;
2501     }
2502     else if ( !strcmp( Type , "double" ) ) {
2503       double d = 0 ;
2504       D.Value <<= d ;
2505     }
2506     else {
2507       D.Value <<= CORBA::Object::_nil() ;
2508     }
2509 //#if 0
2510     switch (D.Value.type()->kind()) { // { string , long , double , objref }
2511     case CORBA::tk_string:
2512       char * t;
2513       D.Value >>= t;
2514       cdebug << ThreadNo() << " " << t << "(string)" << endl ;
2515       break;
2516     case CORBA::tk_boolean:
2517       bool b ;
2518       D.Value >>= (CORBA::Any::to_boolean ) b;
2519       cdebug << ThreadNo() << " " << b << "(boolean)" << endl ;
2520       break;
2521     case CORBA::tk_char:
2522       unsigned char c ;
2523       D.Value >>= (CORBA::Any::to_char ) c;
2524       cdebug << ThreadNo() << " " << c << "(char)" << endl ;
2525       break;
2526     case CORBA::tk_short:
2527       short s;
2528       D.Value >>= s;
2529       cdebug << ThreadNo() << " " << s << "(short)" << endl ;
2530       break;
2531     case CORBA::tk_long:
2532       long l;
2533       D.Value >>= l;
2534       cdebug << ThreadNo() << " " << l << "(long)" << endl ;
2535       break;
2536     case CORBA::tk_float:
2537       float f;
2538       D.Value >>= f;
2539       cdebug << ThreadNo() << " " << f << "(float)" << endl ;
2540       break;
2541     case CORBA::tk_double:
2542       double d;
2543       D.Value >>= d;
2544       cdebug << ThreadNo() << " " << d << "(double)" << endl ;
2545       break;
2546     case CORBA::tk_objref:
2547       try {
2548         CORBA::Object_ptr obj ;
2549         char * retstr ;
2550         D.Value >>= obj ;
2551         retstr = ObjectToString( obj ) ;
2552         cdebug << ThreadNo() << retstr << endl ;
2553       }
2554       catch( ... ) {
2555         cdebug << "ToString( object ) Catched ERROR" << endl ;
2556       }
2557       break;
2558     default:
2559       cdebug << ThreadNo() << " " << "(other ERROR)" << endl ;
2560     }
2561 //#endif
2562     OutParametersList[i] = D ;
2563   }
2564 }
2565
2566 bool GraphExecutor::InNode::OutParametersSet( bool Err ,
2567                                               SUPERV::GraphState NewState ,
2568                                               int nOutParams ,
2569                                               ServicesAnyData * OutParametersList ) {
2570   bool RetVal = true ;
2571   int i ;
2572   GraphBase::OutPort * aGateOutPort = NULL ;
2573   bool OrSwitch = false ;
2574   if ( nOutParams ) {
2575     GraphBase::OutPort * anOutPort ;
2576     for ( i = 0 ; i < nOutParams ; i++ ) {
2577       anOutPort = GetChangeNodeOutPort(i) ;
2578       if ( Err ) {
2579         anOutPort->State( NewState ) ;
2580         anOutPort->Done( true ) ;
2581       }
2582       else {
2583         cdebug << ThreadNo() << " " << "Out" << i << " " << Name() << " "
2584                << anOutPort->PortName() << " " << anOutPort->Kind() ;
2585         ServicesAnyData D = OutParametersList[i] ;
2586         switch (D.Value.type()->kind()) { // { string , long , double , objref }
2587         case CORBA::tk_string: {
2588           char * t;
2589           D.Value >>= t;
2590           cdebug << ThreadNo() << " " << t << "(string)" << endl ;
2591           break;
2592         }
2593         case CORBA::tk_boolean: {
2594           bool b ;
2595           D.Value >>= (CORBA::Any::to_boolean ) b;
2596           long l = (long ) b ;
2597           D.Value <<= l ;
2598           cdebug << ThreadNo() << " " << b << "(boolean)" << endl ;
2599           break;
2600         }
2601         case CORBA::tk_char: {
2602           unsigned char c ;
2603           D.Value >>= (CORBA::Any::to_char ) c;
2604           long l = (long ) c ;
2605           D.Value <<= l ;
2606           cdebug << ThreadNo() << " " << c << "(char)" << endl ;
2607           break;
2608         }
2609         case CORBA::tk_short: {
2610           short s;
2611           D.Value >>= s;
2612           long l = (long ) s ;
2613           D.Value <<= l ;
2614           cdebug << ThreadNo() << " " << s << "(short)" << endl ;
2615           break;
2616         }
2617         case CORBA::tk_long: {
2618           long l;
2619           D.Value >>= l;
2620           cdebug << ThreadNo() << " " << l << "(long)" << endl ;
2621           break;
2622         }
2623         case CORBA::tk_float: {
2624           float f;
2625           D.Value >>= f;
2626           double d = (double ) f ;
2627           D.Value <<= d ;
2628           cdebug << ThreadNo() << " " << f << "(float)" << endl ;
2629           break;
2630         }
2631         case CORBA::tk_double: {
2632           double d;
2633           D.Value >>= d;
2634           cdebug << ThreadNo() << " " << d << "(double)" << endl ;
2635           break;
2636         }
2637         case CORBA::tk_objref: {
2638           try {
2639             CORBA::Object_ptr obj ;
2640             char * retstr ;
2641             D.Value >>= obj ;
2642             retstr = ObjectToString( obj ) ;
2643             cdebug << ThreadNo() << retstr << endl ;
2644           }
2645           catch( ... ) {
2646             cdebug << "ToString( object ) Catched ERROR" << endl ;
2647           }
2648           break;
2649         }
2650         default: {
2651           cdebug << ThreadNo() << " " << "(other ERROR)" << endl ;
2652         }
2653         }
2654         OutParametersList[i] = D ;
2655         if ( !anOutPort->IsDataStream() ) {
2656           if ( anOutPort->IsGate() ) {
2657             aGateOutPort = anOutPort ;
2658             cdebug << " Gate " ;
2659             long l = 1;
2660             OutParametersList[i].Value <<= l;
2661             anOutPort->Value( OutParametersList[i].Value );
2662           }
2663           else if ( anOutPort->IsLoop() ) {
2664             cdebug << " Loop " ;
2665             anOutPort->Value( OutParametersList[i].Value );
2666 // InLoop Port of EndLoopNode is ready :
2667             anOutPort->ChangeInPorts(0)->State( SUPERV::ReadyState ) ;
2668           }
2669           else if ( anOutPort->IsSwitch() ) {
2670             cdebug << " Switch " ;
2671             anOutPort->Value( OutParametersList[i].Value );
2672             if ( anOutPort->InPortsSize() && anOutPort->ChangeInPorts( 0 )->IsGate() ) {
2673               if ( OrSwitch && anOutPort->BoolValue() ) {
2674                 cdebug << "GraphExecutor::InNodeThreads::OutParameters more than one switch is true WARNING"
2675                        << endl ;
2676               }
2677               else {
2678                 OrSwitch = OrSwitch | anOutPort->BoolValue() ;
2679               }
2680             }
2681             cdebug << "OrSwitch " << OrSwitch ;
2682           }
2683           else {
2684             cdebug << " Param " ;
2685             anOutPort->Value( OutParametersList[i].Value );
2686           }
2687           anOutPort->State( NewState ) ;
2688           anOutPort->Done( true ) ;
2689         }
2690         int j ;
2691         for ( j = 0 ; j < anOutPort->InPortsSize() ; j++ ) {
2692           bool fromGOTO = false ;
2693           GraphBase::OutPort * aGOTOPort = _OutNode->Graph()->GetChangeGraphNode( anOutPort->ChangeInPorts( j )->NodeName() )->GetChangeNodeInGate()->GetOutPort() ;
2694           if ( aGOTOPort ) {
2695             fromGOTO = aGOTOPort->IsGOTO() ;
2696           }
2697           if ( anOutPort->ChangeInPorts( j )->IsEndSwitch() || fromGOTO ) {
2698             cdebug << anOutPort->ChangeInPorts( j )->NodeName() << "("
2699                    << anOutPort->ChangeInPorts( j )->PortName() << ","
2700                    << anOutPort->ChangeInPorts( j )->Kind() << ") WILL BE changed from "
2701                    << anOutPort->ChangeInPorts( j )->GetOutPort()->NodeName()
2702                    << "("
2703                    << anOutPort->ChangeInPorts( j )->GetOutPort()->PortName()
2704                    << ") to " << anOutPort->NodeName() << "("
2705                    << anOutPort->PortName() << ")" << endl ;
2706             anOutPort->ChangeInPorts( j )->ChangeOutPort( anOutPort ) ;
2707           }
2708           else {
2709             cdebug << anOutPort->ChangeInPorts( j )->NodeName() << "("
2710                    << anOutPort->ChangeInPorts( j )->PortName() << ","
2711                    << anOutPort->ChangeInPorts( j )->Kind() << ") NOT changed from "
2712                    << anOutPort->ChangeInPorts( j )->GetOutPort()->NodeName()
2713                    << "("
2714                    << anOutPort->ChangeInPorts( j )->GetOutPort()->PortName()
2715                    << ") to " << anOutPort->NodeName() << "("
2716                    << anOutPort->PortName() << ")" << endl ;
2717           }
2718         }
2719 //#if 0
2720         switch (anOutPort->Value()->type()->kind()) {
2721         case CORBA::tk_string:
2722           char * t;
2723           (*anOutPort->Value()) >>= t;
2724           cdebug << ThreadNo() << " Out" << i << " : " << t << "(string)" << endl ;
2725           break;
2726         case CORBA::tk_boolean:
2727           bool b ;
2728           (*anOutPort->Value()) >>= (CORBA::Any::to_boolean ) b;
2729           cdebug << ThreadNo() << " Out" << i << " : " << b << "(boolean)" << endl ;
2730           break;
2731         case CORBA::tk_char:
2732           unsigned char c ;
2733           (*anOutPort->Value()) >>= (CORBA::Any::to_char ) c;
2734           cdebug << ThreadNo() << " Out" << i << " : " << c << "(char)" << endl ;
2735           break;
2736         case CORBA::tk_short:
2737           short s;
2738           (*anOutPort->Value()) >>= s;
2739           cdebug << ThreadNo() << " Out" << i << " : " << s << "(short)" << endl ;
2740           break;
2741         case CORBA::tk_long:
2742           long l;
2743           (*anOutPort->Value()) >>= l;
2744           cdebug << ThreadNo() << " Out" << i << " : " << l << "(long)" << endl ;
2745           break;
2746         case CORBA::tk_float:
2747           float f;
2748           (*anOutPort->Value()) >>= f;
2749           cdebug << ThreadNo() << " Out" << i << " : " << f << "(float)" << endl ;
2750           break;
2751         case CORBA::tk_double:
2752           double d;
2753           (*anOutPort->Value()) >>= d;
2754           cdebug << ThreadNo() << " Out" << i << " : " << d << "(double)" << endl ;
2755           break;
2756         case CORBA::tk_objref:
2757           CORBA::Object_ptr obj ;
2758           char * retstr ;
2759           try {
2760             (*anOutPort->Value()) >>= obj ;
2761             retstr = ObjectToString( obj );
2762             cdebug << ThreadNo() << " Out" << i << " : " << "ToString( object ) "
2763                    << retstr << endl ;
2764           }
2765           catch ( ... ) {
2766             cdebug << ThreadNo() << " Out" << i << " : " << "ToString( object ) "
2767                    << "Catched ERROR" << endl ;
2768           }
2769           break;
2770         default:
2771           cdebug << ThreadNo() << " Out" << i << " : " << "(other ERROR)" << endl ;
2772           RetVal = false ;
2773         }
2774 //#endif
2775       }
2776     }
2777     if ( aGateOutPort && IsSwitchNode() ) {
2778       if ( OrSwitch ) {
2779 //        cdebug << ThreadNo() << " " << "Out0 " << Name() << " Close of "
2780 //               << aGateOutPort->PortName() << " " << aGateOutPort->Kind() ;
2781         long l = 0;
2782         OutParametersList[0].Value <<= l ;
2783         aGateOutPort->Value( OutParametersList[0].Value ) ;
2784       }
2785       else {
2786 //        cdebug << ThreadNo() << " " << "Out0 " << Name() << " Open of "
2787 //               << aGateOutPort->PortName() << " " << aGateOutPort->Kind() ;
2788         long l = 1;
2789         OutParametersList[0].Value <<= l ;
2790         aGateOutPort->Value( OutParametersList[0].Value ) ;
2791         int i ;
2792         for ( i = 0 ; i < GetNodeOutPortsSize() ; i++ ) {
2793           GraphBase::InPort * anInPort ;
2794           anInPort = CoupledNode()->GetChangeInPort( GetNodeOutPort( i )->PortName() ) ;
2795           if ( anInPort ) {
2796             anInPort->ChangeOutPort( GetChangeNodeOutPort( i ) ) ;
2797           }
2798         }
2799       }
2800     }
2801   }
2802   return RetVal ;
2803 }