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