]> 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     cdebug << pthread_self() << "/" << ThreadNo() << " " << Name() << " InPort " << anInPort->PortName() << endl ;
784     if ( anInPort->IsGate() && anOutPort == NULL ) {
785       InReady += 1 ;
786       anInPort->State( SUPERV::ReadyState ) ;
787       cdebug << pthread_self() << "/" << ThreadNo() << " " << Name() << " "
788              << anInPort->PortName() << " ControlPort inactive." << endl ;
789     }
790     else if ( strcmp( DataFromNode() , anOutPort->NodeName() ) ) {
791       if ( anInPort->State() == SUPERV::ReadyState ) {
792         InReady += 1 ;
793         cdebug << pthread_self() << "/" << ThreadNo() << " " << Name() << " "
794                << anInPort->PortName() << " Was Done from "
795                << anOutPort->NodeName() << " " << anOutPort->PortName()
796                << " ReadyState " ;
797 #ifdef _DEBUG_
798         if ( GraphBase::Base::_prof_debug ) {
799           anOutPort->StringValue( *GraphBase::Base::_fdebug ) ;
800         }
801 #endif
802         cdebug << endl ;
803       }
804       else if ( IsLoopNode() && anInPort->IsDataConnected() ) {
805         anInPort->State( SUPERV::ReadyState ) ;
806         InReady += 1 ;
807         cdebug << pthread_self() << "/" << ThreadNo() << " " << Name() << " "
808                << anInPort->PortName() << " Was Done from "
809                << anOutPort->NodeName() << " " << anOutPort->PortName()
810                << " LoopBeginning " << LoopBeginning ;
811 #ifdef _DEBUG_
812         if ( GraphBase::Base::_prof_debug ) {
813           anOutPort->StringValue( *GraphBase::Base::_fdebug ) ;
814         }
815 #endif
816         cdebug << endl ;
817       }
818       else if ( LoopFinished ) {
819         anInPort->State( SUPERV::ReadyState ) ;
820         InReady += 1 ;
821         cdebug << pthread_self() << "/" << ThreadNo() << " " << Name() << " "
822                << anInPort->PortName() << " Was Done from "
823                << anOutPort->NodeName() << " " << anOutPort->PortName()
824                << " LoopFinished" ;
825 #ifdef _DEBUG_
826         if ( GraphBase::Base::_prof_debug ) {
827           anOutPort->StringValue( *GraphBase::Base::_fdebug ) ;
828         }
829 #endif
830         cdebug << endl ;
831       }
832       else if ( anInPort->IsGate() && SwitchFinished ) {
833         anInPort->State( SUPERV::ReadyState ) ;
834         InReady += 1 ;
835         cdebug << pthread_self() << "/" << ThreadNo() << " " << Name() << " "
836                << anInPort->PortName() << " Was Done from "
837                << anOutPort->NodeName() << " " << anOutPort->PortName()
838                << " SwitchFinished" ;
839 #ifdef _DEBUG_
840         if ( GraphBase::Base::_prof_debug ) {
841           anOutPort->StringValue( *GraphBase::Base::_fdebug ) ;
842         }
843 #endif
844         cdebug << endl ;
845       }
846       else {
847         cdebug << pthread_self() << "/" << ThreadNo() << " " << Name() << " "
848                << anInPort->PortName() << " Was NOT Done from "
849                << anOutPort->NodeName() << " " << anOutPort->PortName() << " "
850                << " " << Automaton()->StateName( State() ) << " DataConnected "
851                << anInPort->IsDataConnected() << " LoopBeginning "
852                << LoopBeginning << endl ;
853       }
854     }
855     else if ( anInPort->IsGate() ) {
856       const CORBA::Any * theValue = anOutPort->Value() ;
857       long GateOpened ;
858       (*theValue) >>= GateOpened ;
859       if ( GateOpened != 0 ) {
860         InReady += 1 ;
861         anInPort->State( SUPERV::ReadyState ) ;
862         cdebug << pthread_self() << "/" << ThreadNo() << " " << Name() << " "
863                << anInPort->PortName() << " Gate is Opened from "
864                << anOutPort->NodeName() << " " << anOutPort->PortName()
865                << " " ;
866 #ifdef _DEBUG_
867         if ( GraphBase::Base::_prof_debug ) {
868           anOutPort->StringValue( *GraphBase::Base::_fdebug ) ;
869         }
870 #endif
871         cdebug << endl ;
872       }
873       else if ( LoopFinished ) {
874         anInPort->State( SUPERV::ReadyState ) ;
875         cdebug << pthread_self() << "/" << ThreadNo() << " " << Name() << " "
876                << anInPort->PortName() << " GATE IS CLOSED from "
877                << anOutPort->NodeName() << " " << anOutPort->PortName()
878                << " LoopFinished" ;
879 #ifdef _DEBUG_
880         if ( GraphBase::Base::_prof_debug ) {
881           anOutPort->StringValue( *GraphBase::Base::_fdebug ) ;
882         }
883 #endif
884         cdebug << endl ;
885       }
886       else {
887         cdebug << pthread_self() << "/" << ThreadNo() << " " << Name() << " "
888                << anInPort->PortName() << " GATE IS CLOSED from "
889                << anOutPort->NodeName() << " " << anOutPort->PortName()
890                << " " ;
891 #ifdef _DEBUG_
892         if ( GraphBase::Base::_prof_debug ) {
893           anOutPort->StringValue( *GraphBase::Base::_fdebug ) ;
894         }
895 #endif
896         cdebug << endl ;
897       }
898     }
899     else {
900       InReady += 1 ;
901       anInPort->State( SUPERV::ReadyState ) ;
902       cdebug << pthread_self() << "/" << ThreadNo() << " " << Name() << " "
903              << anInPort->PortName() << " is Done from "
904              << anOutPort->NodeName() << " " << anOutPort->PortName() << " " ;
905 #ifdef _DEBUG_
906         if ( GraphBase::Base::_prof_debug ) {
907           anOutPort->StringValue( *GraphBase::Base::_fdebug ) ;
908         }
909 #endif
910         cdebug << endl ;
911     }
912   }
913   
914   if ( InReady == GetNodeInPortsSize() ) { // All Flags != 0 :
915     res = SendEvent( GraphExecutor::AllDataReadyEvent ); // ==> Ready to execute
916   }
917   else { // At least one Flag == 0 :
918     res = SendEvent( GraphExecutor::NotAllDataReadyEvent );
919   }
920
921   cdebug << pthread_self() << "/" << ThreadNo()
922          << " <-- DataWaiting_SomeDataReadyAction "  << Name() << endl;
923   return res ;
924
925 }
926
927 int GraphExecutor::InNode::DataUndef_NotAllDataReadyAction() {
928   CreateNewThreadIf( false ) ;
929 //  cdebug << pthread_self() << " for " << ThreadNo()
930 //         << " DataUndef_NotAllDataReadyAction " << Name() << endl;
931   return 1;
932 }
933
934 int GraphExecutor::InNode::DataUndef_AllDataReadyAction() {
935 //  cdebug << pthread_self() << "/" << ThreadNo()
936 //         << " --> DataUndef_AllDataReadyAction " << Name()
937 //         << " CreateNewThreadIf " << CreateNewThreadIf() << " IsLockedDataWait "
938 //         << IsLockedDataWait() ;
939   if ( IsLockedDataWait() ) {
940 //    cdebug << " WOULD DEAD-LOCK" << endl ;
941     return 0 ; // ==> DataUndef_AllDataReadyAction() after UnLockDataWait()
942   }
943 //  cdebug << endl ;
944   CreateNewThread( CreateNewThreadIf() ) ;
945   if ( !CreateNewThread() ) {
946 //    cdebug << "Thread " << ThreadNo() << "-->" << pthread_self() << endl ;
947     ThreadNo( pthread_self() ) ;
948   }
949   _OutNode->PushEvent( this , GraphExecutor::AllDataReadyEvent ,
950                        SUPERV::DataReadyState ) ; 
951   ReadyAction() ;
952   SUPERV::ControlState aControl = ControlState() ;
953   switch ( aControl ) {
954   case SUPERV::VoidState : {
955     SendEvent( GraphExecutor::ExecuteEvent ) ;
956     break ;
957   }
958   case SUPERV::ToSuspendState : {
959     SendEvent( GraphExecutor::SuspendEvent ) ;
960     break ;
961   }
962   case SUPERV::ToSuspendStartState : {
963     SendEvent( GraphExecutor::SuspendEvent ) ;
964     break ;
965   }
966   case SUPERV::ToSuspendDoneState : {
967     SendEvent( GraphExecutor::ExecuteEvent ) ;
968     break ;
969   }
970   case SUPERV::ToKillState : {
971     SendEvent( GraphExecutor::KillEvent ) ;
972     break ;
973   }
974   case SUPERV::ToKillDoneState : {
975     SendEvent( GraphExecutor::ExecuteEvent ) ;
976     break ;
977   }
978   case SUPERV::ToStopState : {
979     SendEvent( GraphExecutor::StopEvent ) ;
980     break ;
981   }
982   default : {
983     cdebug << ThreadNo()
984            << " GraphExecutor::InNodeThreads::DataUndef_AllDataReadyAction Error Undefined Control : "
985            << aControl << endl ;
986     return 0;
987   }
988   }
989 //  cdebug << pthread_self() << "/" << ThreadNo()
990 //         << " <-- DataUndef_AllDataReadyAction " << Name() << endl;
991   return 1;
992 }
993
994 int GraphExecutor::InNode::DataReady_SuspendAction() {
995   cdebug << pthread_self() << "/" << ThreadNo()
996          << "DataReady_SuspendAction --> Suspend " << Name()
997          << " Threads " << _OutNode->Threads() << " SuspendedThreads "
998          << _OutNode->SuspendedThreads() << endl;
999   _OutNode->PushEvent( this , GraphExecutor::SuspendedReadyEvent ,
1000                        SUPERV::SuspendedReadyState ) ;
1001   GraphExecutor::InNode * aReStartNode = SuspendAction() ;
1002   cdebug << pthread_self() << "/" << ThreadNo()
1003          << "DataReady_SuspendAction Resumed " << Name() << endl;
1004   if ( aReStartNode ) {
1005     _aReStartNode = NULL ;
1006     aReStartNode->SendEvent( _aReStartEvent ) ;
1007   }
1008   else {
1009     SendEvent( GraphExecutor::ExecuteEvent ) ;
1010   }
1011   return 1 ;
1012 }
1013
1014 int GraphExecutor::InNode::SuspendedReady_ResumeAction() {
1015   cdebug << pthread_self() << "/" << ThreadNo() << "SuspendedReady_ResumeAction "
1016          << Name() << endl;
1017 //  ResumeAction() ;
1018   _OutNode->PushEvent( this , GraphExecutor::ResumedReadyEvent ,
1019                        SUPERV::ResumedReadyState ) ; 
1020   return 1 ;
1021 }
1022
1023 int GraphExecutor::InNode::DataReady_KillAction() {
1024   _OutNode->PushEvent( this , GraphExecutor::KilledReadyEvent ,
1025                        SUPERV::KilledReadyState ) ;
1026   KillAction() ;
1027   cdebug << pthread_self() << "/" << ThreadNo() << "DataReady_KillAction " << Name()
1028          << " will pthread_exit()" << endl;
1029   return 1 ;
1030 }
1031
1032 int GraphExecutor::InNode::DataReady_StopAction() {
1033   _OutNode->PushEvent( this , GraphExecutor::StoppedReadyEvent ,
1034                        SUPERV::StoppedReadyState ) ; 
1035   StopAction() ;
1036   cdebug << pthread_self() << "/" << ThreadNo() << "DataReady_StopAction " << Name()
1037          << " will pthread_exit()" << endl;
1038   return 1 ;
1039 }
1040
1041 #include <CORBA.h>
1042
1043 int GraphExecutor::InNode::DataReady_ExecuteAction() {
1044   int i;
1045
1046 //  cdebug << pthread_self() << "/" << ThreadNo() << " --> DataReady_ExecuteAction "
1047 //         << Name() << endl;
1048   _OutNode->PushEvent( this , GraphExecutor::ExecuteEvent ,
1049                        SUPERV::ExecutingState ) ; 
1050
1051   RunningAction() ;
1052   SUPERV::GraphState PortState = SUPERV::ReadyState ;
1053   SUPERV::AutomatonState NewState = SUPERV::DataUndefState ;
1054   GraphExecutor::NodeEvent NewEvent = GraphExecutor::UndefinedEvent ;
1055
1056   bool Err = false ;
1057
1058   int nInParams = GetNodeInPortsSize()  ;
1059   ServicesAnyData * InParametersList = new ServicesAnyData[nInParams];
1060   InParametersSet( Err , nInParams , InParametersList ) ;
1061
1062   Engines::Container_var myContainer ;
1063   Engines::Component_var myObjComponent ;
1064   if ( !IsFactoryNode() ) {
1065 //    cdebug << ThreadNo() << "No Component : NO StartComponent & No Ping" << endl ;
1066     if ( IsComputingNode() ) {
1067       ObjInterface( true ) ;
1068       CORBA::Object_ptr obj ;
1069       InParametersList[0].Value >>= obj ;
1070       CORBA::Object_var objvar = CORBA::Object_var( obj ) ;
1071       myObjComponent = Engines::Component::_narrow( objvar ) ;
1072     }
1073     else {
1074     }
1075   }
1076   else if ( CORBA::is_nil( Component() ) ) {
1077     ostringstream astr ;
1078     astr << "Graph " << _OutNode->Graph()->Name() << " Node " << Name()
1079          << " : load of component " << ComponentName() << " in container "
1080          << Computer() ;
1081     _OutNode->Graph()->ObjImpl()->sendMessage( NOTIF_STEP, astr.str().c_str() ) ;
1082     Err = !_OutNode->Graph()->StartComponent( ThreadNo() , Computer() ,
1083                                               my_strdup( ComponentName() ) ,
1084                                               myContainer , myObjComponent ) ;
1085     ObjInterface( false ) ;
1086     SetContainer( myContainer ) ;
1087     SetComponent( myObjComponent ) ;
1088   }
1089   else {
1090     myContainer = Container() ;
1091     myObjComponent = Component() ;
1092 //    cdebug << ThreadNo() << "Component known : NO StartComponent & Ping"
1093 //           << endl ;
1094     myObjComponent->ping() ;
1095   }
1096
1097   int nOutParams = GetNodeOutPortsSize()  ;
1098   ServicesAnyData * OutParametersList = new ServicesAnyData[nOutParams];
1099   InOutParametersSet( nOutParams , OutParametersList ) ;
1100
1101     if ( Err || ControlState() == SUPERV::ToKillState ||
1102                 ControlState() == SUPERV::ToKillDoneState ||
1103                 ControlState() == SUPERV::ToStopState ) {
1104       cdebug << ThreadNo() << "StartComponent Error or ToKillState" << endl ;
1105       Err = true ;
1106     }
1107     else {
1108       if ( !Err ) {
1109         ostringstream astr ;
1110         astr << "Graph " << _OutNode->Graph()->Name() << " Run of Node " << Name() ;
1111         _OutNode->Graph()->ObjImpl()->sendMessage( NOTIF_STEP, astr.str().c_str() ) ;
1112         cdebug << ThreadNo() << " Run( '" << ServiceName() << "'" ;
1113         for ( i = 0 ; i < (int ) ServiceInParameter().length() ; i++ ) {
1114           cdebug << " , " << InParametersList[ i ].Name << "[kind"
1115                  << InParametersList[ i ].Value.type()->kind() << "]" ;
1116         }
1117         for ( i = 0 ; i < (int ) ServiceOutParameter().length() ; i++ ) {
1118           cdebug << " , " << OutParametersList[ i ].Name << "[kind"
1119                  << OutParametersList[ i ].Value.type()->kind() << "]" ;
1120         }
1121         if ( IsOneOfInLineNodes() ) {
1122           cdebug << " , PyFuncName '" << InLineNode()->PyFuncName() << "' PyRunMethod "
1123                  << InLineNode()->PyRunMethod() << " length " << (*InLineNode()->PythonFunction()).length() ;
1124         }
1125         cdebug << ")" << endl ;
1126
1127         if ( IsOneOfInLineNodes() ) {
1128           bool StsPyDynInvoke = true;
1129           _OutNode->PyThreadLock() ;
1130           SetPyCpuUsed() ;
1131           try {
1132 //            if ( IsInLineNode() && (*InLineNode()->PythonFunction()).length() &&
1133             bool CopyInOut = false ;
1134             if ( IsInLineNode() && /*InLineNode()->PyRunMethod() &&*/
1135                  strlen( InLineNode()->PyFuncName() ) ) {
1136 //              cdebug << ThreadNo() << " !ObjInterface " << Name() << " PyFuncName '"
1137 //                     << InLineNode()->PyFuncName()
1138 //                     << "' IsInLineNode PyDynInvoke"  << endl ;
1139               StsPyDynInvoke = PyDynInvoke( InLineNode()->PyRunMethod() ,
1140                                             InLineNode()->PyFuncName() ,
1141                                             &InParametersList[0] , ServiceInParameter().length() ,
1142                                             &OutParametersList[0] , ServiceOutParameter().length() ) ;
1143             }
1144             else if ( IsLoopNode() ) {
1145               bool CopyOutIn = false ;
1146               if ( GetNodeInLoop()->GetOutPort()->BoolValue() && /*InLineNode()->PyRunMethod() &&*/
1147                    strlen( InLineNode()->PyFuncName() ) ) { // InLoop Port
1148 //                cdebug << ThreadNo() << " !ObjInterface " << Name()
1149 //                       << " IsLoopNode PyDynInvoke '" << InLineNode()->PyFuncName()
1150 //                       << "'" << endl ;
1151                 StsPyDynInvoke = PyDynInvoke( InLineNode()->PyRunMethod() ,
1152                                               InLineNode()->PyFuncName() ,
1153                                               &InParametersList[1] , ServiceInParameter().length() ,
1154                                               &OutParametersList[1] , ServiceOutParameter().length() ) ;
1155                 CopyOutIn = true ;
1156               }
1157               else if ( LoopNode()->PyNextMethod() &&
1158                         strlen( LoopNode()->PyNextName() ) ){
1159 //                cdebug << ThreadNo() << " !ObjInterface " << Name()
1160 //                       << " IsLoopNode PyDynInvoke '" << LoopNode()->PyNextName()
1161 //                       << "'" << endl ;
1162                 StsPyDynInvoke = PyDynInvoke( LoopNode()->PyNextMethod() ,
1163                                               LoopNode()->PyNextName() ,
1164                                               &InParametersList[1] , ServiceInParameter().length() ,
1165                                               &OutParametersList[1] , ServiceOutParameter().length() ) ;
1166                 CopyOutIn = true ;
1167               }
1168               if ( StsPyDynInvoke && CopyOutIn ) {
1169 //                cdebug << ThreadNo() << " !ObjInterface " << Name()
1170 //                       << " IsLoopNode PyDynInvoke '" << LoopNode()->PyMoreName()
1171 //                       << "' Copy of " << ServiceInParameter().length()
1172 //                       << " OutParameters" << endl ;
1173                 int i ;
1174                 for ( i = 1 ; i <= (int ) ServiceInParameter().length() ; i++ ) {
1175                   InParametersList[i].Value = OutParametersList[i].Value ;
1176                   InParametersList[i].Name = OutParametersList[i].Name ;
1177 //#if 0
1178                   switch ( InParametersList[i].Value.type()->kind() ) {
1179                   case CORBA::tk_string :
1180                     char * t;
1181                     InParametersList[i].Value >>= t ;
1182                     cdebug << "ArgOut->In" << i << " : "
1183                            << InParametersList[i].Name.c_str()
1184                            << " Value(string) " << t << endl ;
1185                     break ;
1186                   case CORBA::tk_double :
1187                     double d;
1188                     InParametersList[i].Value >>= d;
1189                     cdebug << "ArgOut->In" << i << " : "
1190                            << InParametersList[i].Name.c_str()
1191                            << " Value(double) " << d << endl ;
1192                     break ;
1193                   case CORBA::tk_long :
1194                     long l;
1195                     InParametersList[i].Value >>= l;
1196                     cdebug << "ArgOut->In" << i << " : "
1197                            << InParametersList[i].Name.c_str()
1198                            << " Value(long) " << l << endl ;
1199                     break ;
1200                   case CORBA::tk_objref :
1201                     CORBA::Object_ptr obj ;
1202                     char * retstr ;
1203                     try {
1204                       InParametersList[i].Value >>= obj ;
1205                       retstr = ObjectToString( obj );
1206                       cdebug << "ArgOut->In" << i << " : "
1207                              << InParametersList[i].Name.c_str()
1208                              << " Value(object reference) " << retstr << endl ;
1209                      }
1210                     catch ( ... ) {
1211                       cdebug << "ArgOut->In" << i << " : "
1212                              << InParametersList[i].Name.c_str()
1213                              << " Value(object reference) Catched ERROR" << endl ;
1214                     }
1215                     break ;
1216                   default :
1217                     cdebug << "ArgOut->In" << i << " : "
1218                            << InParametersList[i].Name.c_str()
1219                            << " Value(other) ERROR" << endl ;
1220                   }
1221 //#endif
1222                 }
1223                 if ( LoopNode()->PyMoreMethod() && strlen( LoopNode()->PyMoreName() ) ) {
1224                   StsPyDynInvoke = PyDynInvoke( LoopNode()->PyMoreMethod() ,
1225                                                 LoopNode()->PyMoreName() ,
1226                                                 &InParametersList[1] , ServiceInParameter().length() ,
1227                                                 &OutParametersList[0] , ServiceOutParameter().length()+1 ) ;
1228                 }
1229                 else {
1230                   CopyInOut = true ;
1231                 }
1232               }
1233               else  if ( !StsPyDynInvoke ) {
1234                 Err = true ;
1235                 cdebug << ThreadNo() << " InLineNode " << Name() << " "
1236                        << InLineNode()->PyFuncName() << "/" << LoopNode()->PyNextName()
1237                        << " Python Dynamic Call Error"
1238                        << endl ;
1239               }
1240             }
1241             else if ( IsSwitchNode() && /*InLineNode()->PyRunMethod() &&*/
1242                       strlen( InLineNode()->PyFuncName() ) ) {
1243 //              cdebug << ThreadNo() << " !ObjInterface " << Name() << " PyFuncName '"
1244 //                     << InLineNode()->PyFuncName()
1245 //                     << "' IsSwitchNode PyDynInvoke"  << endl ;
1246               StsPyDynInvoke = PyDynInvoke( InLineNode()->PyRunMethod() ,
1247                                             InLineNode()->PyFuncName() ,
1248                                             &InParametersList[0] , ServiceInParameter().length() ,
1249                                             &OutParametersList[0] , ServiceOutParameter().length() ) ;
1250             }
1251 //            else if ( IsGOTONode() && (*GOTONode()->PythonFunction()).length() &&
1252             else if ( IsGOTONode() && /*InLineNode()->PyRunMethod() &&*/
1253                       strlen( InLineNode()->PyFuncName() ) ) {
1254 //              cdebug << ThreadNo() << " !ObjInterface " << Name() << " PyFuncName '"
1255 //                     << InLineNode()->PyFuncName()
1256 //                     << "' IsGOTONode PyDynInvoke"  << endl ;
1257               StsPyDynInvoke = PyDynInvoke( InLineNode()->PyRunMethod() ,
1258                                             InLineNode()->PyFuncName() ,
1259                                             &InParametersList[0] , ServiceInParameter().length() ,
1260                                             &OutParametersList[0] , ServiceOutParameter().length() ) ;
1261             }
1262 //            else if ( IsEndSwitchNode() && (*InLineNode()->PythonFunction()).length() &&
1263             else if ( ( IsEndSwitchNode() ) &&
1264                       InLineNode()->PyRunMethod() && strlen( InLineNode()->PyFuncName() ) ) {
1265 //              cdebug << ThreadNo() << " !ObjInterface " << Name() << " PyFuncName '"
1266 //                     << InLineNode()->PyFuncName()
1267 //                     << "' IsSwitchNode PyDynInvoke"  << endl ;
1268               StsPyDynInvoke = PyDynInvoke( InLineNode()->PyRunMethod() ,
1269                                             InLineNode()->PyFuncName() ,
1270                                             &InParametersList[0] , ServiceInParameter().length() ,
1271                                             &OutParametersList[0] , ServiceOutParameter().length() ) ;
1272             }
1273             else if ( ( IsEndLoopNode() ) &&
1274                       InLineNode()->PyRunMethod() && strlen( InLineNode()->PyFuncName() ) ) {
1275 //              cdebug << ThreadNo() << " !ObjInterface " << Name() << " PyFuncName '"
1276 //                     << InLineNode()->PyFuncName()
1277 //                     << "' IsSwitchNode PyDynInvoke"  << endl ;
1278               StsPyDynInvoke = PyDynInvoke( InLineNode()->PyRunMethod() ,
1279                                             InLineNode()->PyFuncName() ,
1280                                             &InParametersList[0] , ServiceInParameter().length() + 1 ,
1281                                             &OutParametersList[0] , ServiceOutParameter().length() + 1 ) ;
1282             }
1283 //            else if ( (*InLineNode()->PythonFunction()).length() == 0 ||
1284             if ( InLineNode()->PyRunMethod() == NULL ||
1285                  strlen( InLineNode()->PyFuncName() ) == 0 || CopyInOut ) {
1286 //              cdebug << ThreadNo() << " !ObjInterface " << Name()
1287 //                     << " Copy of " << ServiceInParameter().length()
1288 //                     << " OutParameters" << endl ;
1289               int i ;
1290               int argout0 = 0 ;
1291               int argin0 = 0 ;
1292               if ( IsLoopNode() || IsEndLoopNode() ) {
1293                 argout0 = 1 ;
1294                 argin0 = 1 ; // after DoLoop
1295                 if ( IsLoopNode() ) {
1296                   OutParametersList[0].Value = InParametersList[0].Value ; // DoLoop
1297                 }
1298               }
1299               for ( i = 0 ; i < (int ) ServiceInParameter().length() ; i++ ) {
1300                 OutParametersList[argout0 + i].Value = InParametersList[argin0 + i].Value ;
1301 //#if 0
1302                 switch ( InParametersList[argin0 + i].Value.type()->kind() ) {
1303                 case CORBA::tk_string :
1304                   cdebug << "ArgOut->In" << argin0 + i << " : "
1305                          << InParametersList[argin0 + i].Name.c_str()
1306                          << " Value(string) "
1307                          << OutParametersList[argout0 + i].Name.c_str() << endl ;
1308                   break ;
1309                 case CORBA::tk_double :
1310                   cdebug << "ArgOut->In" << argin0 + i << " : "
1311                          << InParametersList[argin0 + i].Name.c_str()
1312                          << " Value(double) "
1313                          << OutParametersList[argout0 + i].Name.c_str() << endl ;
1314                   break ;
1315                 case CORBA::tk_long :
1316                   cdebug << "ArgOut->In" << argin0 + i << " : "
1317                          << InParametersList[argin0 + i].Name.c_str()
1318                          << " Value(long) "
1319                          << OutParametersList[argout0 + i ].Name.c_str() << endl ;
1320                   break ;
1321                 case CORBA::tk_objref :
1322                   cdebug << "ArgOut->In" << argin0 + i << " : "
1323                          << InParametersList[argin0 + i].Name.c_str()
1324                          << " Value(object reference) "
1325                          << OutParametersList[argout0 + i].Name.c_str() << endl ;
1326                   break ;
1327                 default :
1328                   cdebug << "ArgOut->In" << argin0 + i << " : "
1329                          << InParametersList[argin0 + i].Name.c_str()
1330                          << " Value(other) ERROR "
1331                          << OutParametersList[argout0 + i].Name.c_str() << endl ;
1332                 }
1333 //#endif
1334               }
1335             }
1336             if ( !StsPyDynInvoke ) {
1337               Err = true ;
1338               cdebug << ThreadNo() << " InLineNode " << Name()
1339                      << " Python Dynamic Call Error"
1340                      << endl ;
1341             }
1342           }
1343           catch( ... ) {
1344             Err = true ;
1345             cdebug << ThreadNo() << " InLineNode " << Name()
1346                    << " Python Dynamic Call Exception catched ERROR"
1347                    << endl ;
1348           }
1349           CpuUsed( true ) ;
1350           _OutNode->PyThreadUnLock() ;
1351         }
1352         else {
1353           try {
1354             try {
1355               cdebug << "DynInvoke -> Names " << _OutNode->Graph()->Name() << " " << Name() << endl ;
1356               DynInvoke( myObjComponent, "Names" ,
1357                          _OutNode->Graph()->Name() , Name() ) ;
1358             }
1359             catch( ... ) {
1360               cdebug << "DynInvoke Names catched ERROR" << endl ;
1361             }
1362             if ( IsComputingNode() ) {
1363               cdebug << ThreadNo() << " !ObjInterface " << Name()
1364                      << " IsComputingNode DynInvoke"  << endl ;
1365               cdebug << ServiceInParameter().length()-1 << " input parameters and "
1366                      << ServiceOutParameter().length() << " output parameters" << endl ;
1367               DynInvoke( myObjComponent,
1368                          ServiceName() ,
1369                          &InParametersList[1] , ServiceInParameter().length()-1 ,
1370                          &OutParametersList[0] , ServiceOutParameter().length() ) ;
1371             }
1372             else if ( IsFactoryNode() ) {
1373               cdebug << ThreadNo() << " !ObjInterface " << Name()
1374                      << " IsFactoryNode DynInvoke"  << endl ;
1375               cdebug << ServiceInParameter().length() << " input parameters and "
1376                      << ServiceOutParameter().length() << " output parameters" << endl ;
1377               DynInvoke( myObjComponent,
1378                          ServiceName() ,
1379                          &InParametersList[0] , ServiceInParameter().length() ,
1380                          &OutParametersList[0] , ServiceOutParameter().length() ) ;
1381             }
1382 //            cdebug << ThreadNo() << " Component::CpuUsed " << Name() << " "
1383 //                   << myObjComponent->CpuUsed_impl() << endl ;
1384           }
1385           catch( ... ) {
1386             Err = true ;
1387             cdebug << ThreadNo() << " !ObjInterface " << Name()
1388                    << " Node(Component) Dynamic Call Exception catched ERROR"
1389                    << endl ;
1390           }
1391         }
1392       }
1393     }
1394 //  }
1395 //  else {
1396 //    sleep( 1 ) ;
1397 //  }
1398
1399   ostringstream astr ;
1400   astr << "Graph " << _OutNode->Graph()->Name() << " Node " << Name() << " is done : "
1401        << Automaton()->StateName( State() ) ;
1402   _OutNode->Graph()->ObjImpl()->sendMessage( NOTIF_STEP, astr.str().c_str() ) ;
1403   if ( Err ) {
1404     if ( ControlState() == SUPERV::ToKillState ||
1405          ControlState() == SUPERV::ToKillDoneState ||
1406          ControlState() == SUPERV::ToStopState ) {
1407       PortState = SUPERV::ErrorState ;
1408       NewState = SUPERV::KilledState ;
1409       NewEvent = GraphExecutor::KillEvent ;
1410     }
1411     else {
1412       PortState = SUPERV::ErrorState ;
1413       NewState = SUPERV::ErroredState ;
1414       NewEvent = GraphExecutor::ErrorEvent ;
1415     }
1416   }
1417   else {
1418     PortState = SUPERV::ReadyState ;
1419     NewState = SUPERV::DataReadyState ;
1420     NewEvent = GraphExecutor::SuccessEvent ;
1421   }
1422
1423   bool ErrOut = OutParametersSet( Err , PortState , nOutParams , OutParametersList ) ;
1424               
1425   if ( !ErrOut ) {
1426     NewEvent = GraphExecutor::ErrorEvent ;
1427   }
1428           
1429   delete [] InParametersList ;
1430   delete [] OutParametersList ;
1431
1432               
1433   SendEvent( NewEvent );
1434
1435 //  cdebug << ThreadNo() << " <-- DataReady_ExecuteAction " << Name() << endl;
1436   return 1 ;
1437 }
1438
1439 int GraphExecutor::InNode::Executing_SuspendAction() {
1440   _OutNode->PushEvent( this , GraphExecutor::SuspendedExecutingEvent ,
1441                        SUPERV::SuspendedExecutingState ) ; 
1442   cdebug << ThreadNo() << " Executing_SuspendAction " << Name() << endl;
1443   return 1 ;
1444 }
1445
1446 int GraphExecutor::InNode::SuspendedExecuting_ResumeAction() {
1447   cdebug << ThreadNo() << " SuspendedExecuting_ResumeAction " << Name() << endl;
1448   SUPERV::AutomatonState next_state ;
1449   next_state = Automaton()->NextState( State() , GraphExecutor::ExecutingEvent ) ;
1450   _OutNode->NewThread() ; // Only for Threads count
1451   _OutNode->PushEvent( this , GraphExecutor::ResumedExecutingEvent ,
1452                        next_state ) ; 
1453   State( next_state ) ;
1454   return 1 ;
1455 }
1456
1457 int GraphExecutor::InNode::Executing_KillAction() {
1458   cdebug << ThreadNo() << " Executing_KillAction " << Name() << endl;
1459   int RetVal = 0 ;
1460   if ( pthread_self() == ThreadNo() ) {
1461     cdebug << "Executing_KillAction would pthread_canceled itself" << endl ;
1462     KillAction() ;
1463     _OutNode->PushEvent( this , GraphExecutor::KilledExecutingEvent ,
1464                          SUPERV::KilledExecutingState ) ; 
1465     RetVal = 1 ;
1466   }
1467   else if ( pthread_cancel( ThreadNo() ) ) {
1468     perror("Executing_KillAction pthread_cancel error") ;
1469   }
1470   else {
1471     cdebug << "Executing_KillAction : ThreadId " << ThreadNo()
1472            << " pthread_canceled" << endl ;
1473     KillAction() ;
1474     _OutNode->ExitThread() ;
1475     _OutNode->PushEvent( this , GraphExecutor::KilledExecutingEvent ,
1476                          SUPERV::KilledExecutingState ) ; 
1477   }
1478   return RetVal ;
1479 }
1480
1481 int GraphExecutor::InNode::Executing_StopAction() {
1482   cdebug << ThreadNo() << " Executing_StopAction " << Name() << endl;
1483   int RetVal = 0 ;
1484   if ( pthread_cancel( ThreadNo() ) ) {
1485     perror("Executing_KillAction pthread_cancel error") ;
1486   }
1487   else {
1488     cdebug << "Executing_KillAction : ThreadId " << ThreadNo()
1489            << " pthread_canceled" << endl ;
1490     StopAction() ;
1491     _OutNode->ExitThread() ;
1492     _OutNode->PushEvent( this , GraphExecutor::StoppedExecutingEvent ,
1493                          SUPERV::StoppedExecutingState ) ; 
1494   }
1495   return RetVal ;
1496 }
1497
1498 int GraphExecutor::InNode::Executing_SuccessAction() {
1499 //  cdebug << ThreadNo() << " --> Executing_SuccessAction " << Name() << endl;
1500   _OutNode->PushEvent( this , GraphExecutor::SuccessedExecutingEvent ,
1501                        SUPERV::SuccessedState ) ; 
1502   SUPERV::ControlState aControl = ControlState() ;
1503   switch ( aControl ) {
1504   case SUPERV::VoidState : {
1505     SendEvent( SuccessEvent ) ;
1506     break ;
1507   }
1508   case SUPERV::ToSuspendState : {
1509     SendEvent( SuccessEvent ) ;
1510     break ;
1511   }
1512   case SUPERV::ToSuspendDoneState : {
1513     SendEvent( GraphExecutor::SuspendEvent ) ;
1514     return 1 ;
1515   }
1516   case SUPERV::ToKillState : {
1517     SendEvent( GraphExecutor::KillEvent ) ;
1518     return 1 ;
1519   }
1520   case SUPERV::ToKillDoneState : {
1521     SendEvent( GraphExecutor::KillEvent ) ;
1522     return 1 ;
1523   }
1524   case SUPERV::ToStopState : {
1525     SendEvent( GraphExecutor::StopEvent ) ;
1526     return 1 ;
1527   }
1528   default : {
1529     cdebug << ThreadNo()
1530            << " GraphExecutor::InNodeThreads::Executing_SuccessAction Error Undefined Control : "
1531            << aControl << endl ;
1532     return 0;
1533   }
1534   }
1535 //  cdebug << ThreadNo() << " <-- Executing_SuccessAction "  << Name() << endl;
1536   return 1 ;
1537 }
1538
1539 int GraphExecutor::InNode::Executing_ErrorAction() {
1540   cdebug << ThreadNo() << " --> Executing_ErrorAction " << Name() << endl;
1541   _OutNode->PushEvent( this , GraphExecutor::ErroredExecutingEvent ,
1542                        SUPERV::ErroredState ) ; 
1543
1544   SUPERV::ControlState aControl = ControlState() ;
1545   switch ( aControl ) {
1546   case SUPERV::VoidState : {
1547     SendEvent( ErrorEvent ) ;
1548     break ;
1549   }
1550   case SUPERV::ToSuspendState : {
1551     SendEvent( ErrorEvent ) ;
1552     break ;
1553   }
1554   case SUPERV::ToSuspendDoneState : {
1555     SendEvent( GraphExecutor::SuspendEvent ) ;
1556     return 1 ;
1557   }
1558   case SUPERV::ToKillState : {
1559     SendEvent( GraphExecutor::KillEvent ) ;
1560     return 1 ;
1561   }
1562   case SUPERV::ToKillDoneState : {
1563     SendEvent( GraphExecutor::KillEvent ) ;
1564     return 1 ;
1565   }
1566   case SUPERV::ToStopState : {
1567     SendEvent( GraphExecutor::StopEvent ) ;
1568     return 1 ;
1569   }
1570   default : {
1571     cdebug << ThreadNo()
1572            << " GraphExecutor::InNodeThreads::Executing_ErrorAction Error Undefined Control : "
1573            << aControl << endl ;
1574     return 0;
1575   }
1576   }
1577   cdebug << ThreadNo() << " <-- Executing_ErrorAction "  << Name() << endl;
1578   return 1 ;
1579 }
1580
1581 // Set SUPERV::WaitingState to all InPorts 
1582 void GraphExecutor::InNode::SetWaitingStates(GraphExecutor::InNode * EndNode ) {
1583   int i ;
1584   int j ;
1585   bool docdebug = false ;
1586   State( SUPERV::DataWaitingState ) ;
1587   for ( i = 0 ; i < GetNodeInPortsSize() ; i++ ) {
1588     GraphBase::InPort * anInPort = GetChangeNodeInPort( i ) ;
1589     if ( anInPort->IsGate() ) { // Loop : Open the doors
1590       GraphBase::OutPort * anOutPort = anInPort->GetOutPort() ;
1591       if ( anOutPort ) {
1592         CORBA::Any * anAny = new CORBA::Any() ;
1593         *anAny <<= (long ) 1 ;
1594         anOutPort->Value( anAny ) ;
1595         anInPort->State( SUPERV::ReadyState ) ;
1596       }
1597     }
1598     else if ( anInPort->State() != SUPERV::WaitingState ) {
1599       if ( !docdebug ) {
1600 //        cdebug << ThreadNo()
1601 //               << " --> GraphExecutor::InNodeThreads::SetWaitingStates " << Name() << endl;
1602         docdebug = true ;
1603       }
1604       if ( !anInPort->IsDataStream() ) {
1605         anInPort->State( SUPERV::WaitingState ) ;
1606       }
1607     }
1608   }
1609   for ( i = 0 ; i < GetNodeOutPortsSize() ; i++ ) {
1610     GraphBase::OutPort * anOutPort = GetChangeNodeOutPort( i ) ;
1611     for ( j = 0 ; j < anOutPort->InPortsSize() ; j++ ) {
1612       if ( !( IsGOTONode() && anOutPort->IsGate() ) &&
1613            !( IsEndLoopNode() && ( anOutPort->IsGate() ||
1614               anOutPort->IsLoop() ) ) &&
1615            !anOutPort->IsDataStream() &&
1616            !anOutPort->ChangeInPorts( j )->IsDataStream() ) {
1617 //        cdebug << ThreadNo()
1618 //               << " GraphExecutor::InNodeThreads::SetWaitingStates "
1619 //               << Name() << "( " << anOutPort->PortName() << " ) --> InPort "
1620 //               << anOutPort->ChangeInPorts( j )->PortName() << " from Node "
1621 //               << anOutPort->ChangeInPorts( j )->NodeName() << endl;
1622         GraphExecutor::InNode * aNode = (GraphExecutor::InNode * ) _OutNode->Graph()->GetChangeGraphNode( anOutPort->ChangeInPorts( j )->NodeName() )->GetInNode() ;
1623         if ( aNode != EndNode ) {
1624           aNode->SetWaitingStates( EndNode ) ;
1625         }
1626       }
1627     }
1628   }
1629 }
1630
1631 int GraphExecutor::InNode::Successed_SuccessAction() {
1632 //  cdebug << ThreadNo() << " --> Successed_SuccessAction "  << Name() << endl;
1633   int res = 1;
1634   int linkednodesnumber = LinkedNodesSize() ;
1635   GraphExecutor::InNode *firstzeroNode = NULL ;
1636   GraphExecutor::InNode *firsttoNode = NULL ;
1637   GraphExecutor::InNode *toNode ;
1638   int i ;
1639   int j ;
1640   list<GraphExecutor::InNode *> SomeDataNodes ;
1641
1642   DoneAction() ;
1643
1644   if ( IsGOTONode() ||
1645        ( IsEndLoopNode() && GetNodeInLoop()->GetOutPort()->BoolValue() ) ) {
1646     cdebug << ThreadNo() << " Successed_SuccessAction " << Name()
1647            << " SetWaitingStates " << endl ;
1648     const GraphBase::OutPort * aGateOutPort ;
1649     if ( IsGOTONode() ) {
1650       aGateOutPort = GetNodeOutGate() ;
1651     }
1652     else {
1653       aGateOutPort = GetNodeOutLoop() ;
1654     }
1655     for ( i = 0 ; i < aGateOutPort->InPortsSize() ; i++ ) {
1656       const GraphBase::InPort * anInPort = aGateOutPort->InPorts( i ) ;
1657       GraphExecutor::InNode * aLabelNode = (GraphExecutor::InNode *) _OutNode->Graph()->GetChangeGraphNode( anInPort->NodeName() )->GetInNode() ;
1658 //      cdebug << ThreadNo() << " Successed_SuccessAction " << Name() << " will Loop to HeadNode "
1659 //             << aLabelNode->Name() << " from port " << anInPort->PortName() << endl ;
1660       aLabelNode->SetWaitingStates( this ) ;
1661       for ( j = 0 ; j < aLabelNode->GetNodeInPortsSize() ; j++ ) {
1662         const GraphBase::InPort * anInPort = aLabelNode->GetNodeInPort( j ) ;
1663         if ( anInPort->GetOutPort() ) {
1664 //          cdebug << aLabelNode->Name() << "(" << anInPort->PortName() << ") value : "
1665 //                 << anInPort->GetOutPort()->NodeName() << "(" << anInPort->GetOutPort()->PortName() << ")"
1666 //                 << endl ;
1667         }
1668       }
1669       for ( j = 0 ; j < GetNodeOutPortsSize() ; j++ ) {
1670         GraphBase::OutPort * aBusParamOutPort = GetChangeNodeOutPort( j ) ;
1671         if ( !aBusParamOutPort->IsGate() ) {
1672           GraphBase::InPort * aBusParamChangeInPort = NULL ;
1673           if ( aBusParamOutPort->IsLoop() ) {
1674             aBusParamChangeInPort = aLabelNode->GetChangeNodeInLoop() ;
1675           }
1676           else {
1677             aBusParamChangeInPort = aLabelNode->GetChangeInPort( aBusParamOutPort->PortName() ) ;
1678           }
1679           if ( aBusParamChangeInPort ) {
1680             aBusParamChangeInPort->ChangeOutPort( aBusParamOutPort ) ;
1681 //            cdebug << ThreadNo() << " Successed_SuccessAction " << Name() << " ChangeOutPort to HeadNode "
1682 //                   << aLabelNode->Name() << "(" << aBusParamChangeInPort->PortName() << ") from port "
1683 //                   << aBusParamOutPort->PortName() << endl ;
1684             if ( !aLabelNode->IsLockedDataWait() ) {
1685               res = aLabelNode->SendSomeDataReady( Name() ) ;
1686               if ( res ) {
1687                 if ( firsttoNode == NULL &&
1688                      aLabelNode->ThreadNo() == pthread_self() ) {
1689                   firsttoNode = aLabelNode ;
1690 //                  cdebug << ThreadNo() << " Successed_SuccessAction firsttoNode "
1691 //                         << aLabelNode->Name() << endl ;
1692                 }
1693                 else if ( firstzeroNode == NULL &&
1694                           aLabelNode->ThreadNo() == 0 ) {
1695                   firstzeroNode = aLabelNode ;
1696                 }
1697                 else {
1698                   SomeDataNodes.push_back( aLabelNode ) ;
1699 //                  cdebug << ThreadNo() << " Successed_SuccessAction " << Name() << " push "
1700 //                         << aLabelNode->Name() << " " << SomeDataNodes.size() 
1701 //                         << endl ;
1702                 }
1703               }
1704             }
1705             else {
1706 //              cdebug << ThreadNo()
1707 //                     << " Successed_SuccessAction Loop to HeadNode "
1708 //                     << aLabelNode->Name() << " with datas from " << Name() << "("
1709 //                     << aBusParamOutPort->PortName() << ") to port "
1710 //                     << aBusParamChangeInPort->PortName() << endl;
1711             }
1712           }
1713           else {
1714 //            cdebug << ThreadNo() << " ERROR in Successed_SuccessAction of " << Name()
1715 //                   << " NO port " << aBusParamOutPort->PortName() << " in "
1716 //                   << aLabelNode->Name() << endl;
1717           }
1718         }
1719       }
1720       for ( j = 0 ; j < aLabelNode->GetNodeInPortsSize() ; j++ ) {
1721         const GraphBase::InPort * anInPort = aLabelNode->GetNodeInPort( j ) ;
1722         if ( anInPort->GetOutPort() ) {
1723 //          cdebug << aLabelNode->Name() << "(" << anInPort->PortName() << ") value : "
1724 //                 << anInPort->GetOutPort()->NodeName() << "(" << anInPort->GetOutPort()->PortName() << ")"
1725 //                 << endl ;
1726         }
1727       }
1728       const GraphBase::InPort * aGateInPort = aLabelNode->GetNodeInGate() ;
1729       if ( aGateInPort ) {
1730         if ( aGateInPort->GetOutPort() ) {
1731           aGateInPort->GetOutPort()->Value( aGateOutPort->Value() ) ;
1732         }
1733         if ( !aLabelNode->IsLockedDataWait() ) {
1734           res = aLabelNode->SendSomeDataReady( Name() ) ;
1735           if ( res ) {
1736             if ( firsttoNode == NULL &&
1737                  aLabelNode->ThreadNo() == pthread_self() ) {
1738               firsttoNode = aLabelNode ;
1739 //              cdebug << ThreadNo() << " Successed_SuccessAction firsttoNode "
1740 //                     << aLabelNode->Name() << endl ;
1741             }
1742             else if ( firstzeroNode == NULL &&
1743                       aLabelNode->ThreadNo() == 0 ) {
1744               firstzeroNode = aLabelNode ;
1745             }
1746             else {
1747               SomeDataNodes.push_back( aLabelNode ) ;
1748 //              cdebug << ThreadNo() << " Successed_SuccessAction " << Name() << " push "
1749 //                     << aLabelNode->Name() << " " << SomeDataNodes.size()
1750 //                     << endl ;
1751             }
1752           }
1753         }
1754       }
1755       else {
1756         cdebug << ThreadNo() << " ERROR in Successed_SuccessAction of " << Name()
1757                << " NO port " << aGateOutPort->PortName() << " in "
1758                << aLabelNode->Name() << endl;
1759       }
1760     }
1761   }
1762
1763   else {
1764 //    cdebug << ThreadNo() << " Successed_SuccessAction of " << Name()
1765 //           << " with " << LinkedNodesSize() << " linked nodes :" ;
1766     for ( i = 0 ; i < LinkedNodesSize() ; i++ ) {
1767       if ( LinkedNodes( i )->IsDataFlowNode() ) {
1768         linkednodesnumber -= 1 ;
1769       }
1770 //      cdebug << " " << LinkedNodes( i )->Name() ;
1771     }
1772 //    cdebug << endl;
1773     for ( i = 0 ; i < LinkedNodesSize() ; i++ ) {
1774       bool IgnoreForEndLoop = false ;
1775       GraphBase::ComputingNode * aComputingNode ;
1776       aComputingNode = (GraphBase::ComputingNode * ) LinkedNodes( i ) ;
1777       toNode = (GraphExecutor::InNode *) aComputingNode->GetInNode() ;
1778 //      cdebug << ThreadNo() << " Successed_SuccessAction of " << Name()
1779 //             << " [" << i << "] " << LinkedNodes( i )->Name() << endl ;
1780       if ( toNode && !toNode->IsDataFlowNode() ) {
1781         if ( IsComputingNode() && toNode->IsInLineNode() ) {
1782           GraphBase::InPort * toGateInPort = toNode->GetChangeNodeInGate() ;
1783           toGateInPort->State( SUPERV::ReadyState ) ;
1784           GraphBase::OutPort * GateOutPort = toGateInPort->GetOutPort() ;
1785           if ( GateOutPort ) {
1786             GateOutPort->PortStatus( DataConnected );
1787             GateOutPort->State( SUPERV::ReadyState ) ;
1788             GateOutPort->Done( true ) ;
1789           }
1790         }
1791       }
1792       if ( toNode && IsLoopNode() ) {
1793         GraphBase::OutPort * fromLoopOutPort = GetChangeNodeOutLoop() ;
1794         if ( !fromLoopOutPort->BoolValue() ) { // Ne pas faire la boucle
1795           if ( strcmp( toNode->Name() , CoupledNode()->Name() ) ) {
1796             IgnoreForEndLoop = true ;
1797           }
1798           else { // toNode is the EndLoopNode
1799             GraphBase::InPort * toLoopInPort ;
1800             toLoopInPort = toNode->GetChangeNodeInLoop() ;
1801             if ( toLoopInPort->State() != SUPERV::ReadyState ) {
1802               toLoopInPort->State( SUPERV::ReadyState ) ;
1803             }
1804           }
1805         }
1806       }
1807       else if ( toNode && IsSwitchNode() ) {
1808       }
1809       else if ( toNode && toNode->IsInLineNode() ) {
1810         int j ;
1811         for ( j = 0 ; j < toNode->GetNodeInPortsSize() ; j++ ) {
1812           toNode->GetChangeNodeInPort( j )->InitialOutPort() ;
1813         }
1814       }
1815       if ( toNode && !IgnoreForEndLoop ) {
1816         if ( toNode && toNode->IsLoopNode() ) {
1817           GraphBase::InPort * toLoopInPort = toNode->GetChangeNodeInLoop() ;
1818           toLoopInPort->State( SUPERV::ReadyState ) ;
1819           GraphBase::OutPort * LoopOutPort = toLoopInPort->GetOutPort() ;
1820           LoopOutPort->PortStatus( DataConnected );
1821           LoopOutPort->State( SUPERV::ReadyState ) ;
1822           LoopOutPort->Done( true ) ;
1823           CORBA::Any * anAny = new CORBA::Any() ;
1824           *anAny <<= (long ) 1 ;
1825           LoopOutPort->Value( anAny ) ;
1826           int j ;
1827           for ( j = 0 ; j < toNode->GetNodeInPortsSize() ; j++ ) {
1828             toNode->GetChangeNodeInPort( j )->InitialOutPort() ;
1829           }
1830         }
1831         res = toNode->SendSomeDataReady( Name() ) ;
1832         if ( res ) {
1833           if ( firsttoNode == NULL &&
1834                toNode->ThreadNo() == pthread_self() ) {
1835             firsttoNode = toNode ;
1836 //            cdebug << ThreadNo() << " Successed_SuccessAction firsttoNode "
1837 //                   << toNode->Name() << endl ;
1838           }
1839           else if ( firstzeroNode == NULL &&
1840                     toNode->ThreadNo() == 0 ) {
1841             firstzeroNode = toNode ;
1842           }
1843           else {
1844             SomeDataNodes.push_back( toNode ) ;
1845 //            cdebug << ThreadNo() << " Successed_SuccessAction " << Name() << " push "
1846 //                   << toNode->Name() << " " << SomeDataNodes.size() << endl ;
1847           }
1848         }
1849       }
1850     }
1851   }
1852
1853   if ( firsttoNode == NULL && firstzeroNode ) {
1854     firsttoNode = firstzeroNode ;
1855 //    cdebug << ThreadNo()
1856 //           << " Successed_SuccessAction firsttoNode = firstzeroNode "
1857 //           << endl ;
1858   }
1859   else if ( firsttoNode && firstzeroNode ) {
1860     SomeDataNodes.push_back( firstzeroNode ) ;
1861 //    cdebug << ThreadNo() << " Successed_SuccessAction " << Name() << " push firstzeroNode "
1862 //           << firstzeroNode->Name() << " " << SomeDataNodes.size() << endl ;
1863   }
1864
1865   while ( SomeDataNodes.size() ) {
1866     GraphExecutor::InNode *aNode = SomeDataNodes.front() ;
1867     SomeDataNodes.pop_front() ;
1868 //    cdebug << pthread_self() << "/" << ThreadNo()
1869 //           << " Successed_SuccessAction pop "
1870 //           << SomeDataNodes.size() << " " << aNode->Name() << endl ;
1871     if ( aNode->State() == SUPERV::DataReadyState ) {
1872       aNode->CreateNewThreadIf( true ) ;
1873       aNode->UnLockDataWait() ;
1874       res = aNode->DataUndef_AllDataReadyAction() ;
1875     }
1876     else {
1877 //      cdebug << pthread_self() << "/" << ThreadNo() << " ERROR "
1878 //             << aNode->Name() << " "
1879 //             << Automaton()->StateName( aNode->State() ) << endl ;
1880     }
1881   }
1882
1883   if ( firsttoNode ) {
1884 //    cdebug << pthread_self() << "/" << ThreadNo()
1885 //           << " Successed_SuccessAction start firsttoNode "
1886 //           << SomeDataNodes.size() << " " << firsttoNode->Name() << endl ;
1887     firsttoNode->CreateNewThreadIf( false ) ;
1888     firsttoNode->RewindStack( RewindStack() ) ;
1889     if ( firsttoNode->State() == SUPERV::SuccessedState ) {
1890 //      cdebug << pthread_self() << "/" << ThreadNo() << " " << Name()
1891 //             << " : " << firsttoNode->Name() << " "
1892 //             << Automaton()->StateName( firsttoNode->State() )
1893 //             << " --> DataWaitingState for Thread "
1894 //             << firsttoNode->ThreadNo() << endl ;
1895       firsttoNode->State( SUPERV::DataWaitingState ) ;
1896     }
1897 //    pthread_t OldT = firsttoNode->ThreadNo() ;
1898     firsttoNode->ThreadNo( pthread_self() ) ;
1899 // On continue avec le meme thread
1900 //    cdebug << pthread_self() << "/" << ThreadNo() << " firsttoNode "
1901 //           << firsttoNode->Name() << "Thread(" << OldT << "-->"
1902 //           << firsttoNode->ThreadNo() << ")" << endl ;
1903     ThreadNo( 0 ) ;
1904 //    cdebug << ThreadNo() << " Successed_SuccessAction " << Name()
1905 //           << " for " << firsttoNode->Name()
1906 //           << " !firsttoNode->CreateNewThreadIf() "
1907 //           << !firsttoNode->CreateNewThreadIf()
1908 //           << " " << Automaton()->StateName( firsttoNode->State() ) ;
1909     if ( firsttoNode->State() == SUPERV::DataReadyState ) {
1910       cdebug << endl ;
1911       firsttoNode->UnLockDataWait() ;
1912       res = firsttoNode->DataUndef_AllDataReadyAction() ;
1913     }
1914     else {
1915       cdebug << " ERROR " << endl ;
1916     }
1917   }
1918   else {
1919 //    cdebug << ThreadNo() << " Successed_SuccessAction " << Name()
1920 //           << " NO DataReady ==> ThreadNo( 0 ) firsttoNode == NULL LINKEDnodesnumber " << linkednodesnumber << endl ;
1921     ThreadNo( 0 ) ;
1922   }
1923
1924 //  if ( linkednodesnumber == 0 && firsttoNode == NULL ) {
1925 //    cdebug << ThreadNo() << " Successed_SuccessAction " << Name() << " LinkedNodesSize " << LinkedNodesSize()
1926 //           << " firsttoNode == NULL LINKEDnodesnumber " << linkednodesnumber << " CHECK" << endl ;
1927 //    _OutNode->CheckAllDone() ;
1928 //  }
1929
1930 //  cdebug << pthread_self() << "/" << ThreadNo()
1931 //         << " <-- Successed_SuccessAction " << Name() << " linkednodesnumber "
1932 //         << linkednodesnumber << endl;
1933   return 1 ;
1934 }
1935
1936 bool GraphExecutor::InNode::SendSomeDataReady( char * FromNodeName ) {
1937   bool RetVal = false ;
1938   if ( IsDataFlowNode() ) {
1939 //    cdebug << ThreadNo() << " ----> " << Name()
1940 //         << " send Result to graph " << Name() << endl;
1941   }
1942   else {
1943 //    cdebug << pthread_self() << "/" << ThreadNo() << " ----> " << FromNodeName
1944 //           << " send SomeDataReady to " << Name() << " "
1945 //           << Automaton()->StateName( State() ) 
1946 //           << " CreateNewThreadIf() " << CreateNewThreadIf()
1947 //           << " LockedDataWait " << IsLockedDataWait() << endl;
1948 #if 0
1949     cout << pthread_self() << "/" << ThreadNo() << " ----> " << FromNodeName
1950          << " send SomeDataReady to " << Name() << " "
1951          << Automaton()->StateName( State() ) 
1952          << " CreateNewThreadIf() " << CreateNewThreadIf()
1953          << " LockedDataWait " << IsLockedDataWait() << endl;
1954 #endif
1955     if ( State() == SUPERV::SuccessedState ||
1956          State() == SUPERV::SuspendedSuccessedState ||
1957          State() == SUPERV::SuspendedSuccessedToReStartState ) {
1958 //      cdebug << ThreadNo() << " " << FromNodeName
1959 //             << " : " << Name() << " " << Automaton()->StateName( State() )
1960 //             << " --> DataWaitingState for Thread "
1961 //             << ThreadNo() << " " << endl ;
1962       State( SUPERV::DataWaitingState ) ;
1963     }
1964     LockDataWait() ;
1965     DataFromNode( FromNodeName ) ;
1966     RetVal = !SendEvent( GraphExecutor::SomeDataReadyEvent );
1967     if ( !RetVal ) {
1968       UnLockDataWait() ;
1969     }
1970   }
1971   return RetVal ;
1972 }
1973
1974 int GraphExecutor::InNode::Errored_ErrorAction() {
1975   cdebug << ThreadNo() << " Errored_ErrorAction " << Name()
1976          << " will pthread_exit" << endl;
1977   DoneAction() ;
1978   return 1 ;
1979 }
1980
1981 int GraphExecutor::InNode::Successed_SuspendAction() {
1982   cdebug << ThreadNo() << " Successed_SuspendAction -->Suspend " << Name()
1983          << " Threads " << _OutNode->Threads() << " SuspendedThreads "
1984          << _OutNode->SuspendedThreads() << endl;
1985   _OutNode->PushEvent( this , GraphExecutor::SuspendedSuccessedEvent ,
1986                        SUPERV::SuspendedSuccessedState ) ; 
1987   DoneAction() ;
1988   GraphExecutor::InNode * aReStartNode = SuspendAction() ;
1989   cdebug << ThreadNo() << " Successed_SuspendAction Resumed " << Name() ;
1990   if ( aReStartNode ) {
1991     _aReStartNode = NULL ;
1992     cdebug << " for " << aReStartNode->Name() << endl;
1993     aReStartNode->SendEvent( _aReStartEvent ) ;
1994   }
1995   else {
1996     cdebug << endl;
1997     SendEvent( GraphExecutor::ResumeEvent ) ;
1998   }
1999   return 1 ;
2000 }
2001
2002 int GraphExecutor::InNode::Errored_SuspendAction() {
2003   cdebug << ThreadNo() << " Errored_SuspendAction -->Suspend " << Name()
2004          << " Threads " << _OutNode->Threads() << " SuspendedThreads "
2005          << _OutNode->SuspendedThreads() << endl;
2006   _OutNode->PushEvent( this , GraphExecutor::SuspendedErroredEvent ,
2007                        SUPERV::SuspendedErroredState ) ; 
2008   DoneAction() ;
2009   GraphExecutor::InNode * aReStartNode = SuspendAction() ;
2010   cdebug << ThreadNo() << " Errored_SuspendAction Resumed " << Name()
2011          << endl;
2012   if ( aReStartNode ) {
2013     _aReStartNode = NULL ;
2014     aReStartNode->SendEvent( _aReStartEvent ) ;
2015   }
2016   else {
2017     SendEvent( GraphExecutor::ResumeEvent ) ;
2018   }
2019   return 1 ;
2020 }
2021
2022 int GraphExecutor::InNode::SuspendedSuccessed_ResumeAction() {
2023   cdebug << ThreadNo() << " SuspendedSuccessed_ResumeAction " << Name() << endl;
2024 //  ResumeAction() ;
2025   _OutNode->PushEvent( this , GraphExecutor::ResumedSuccessedEvent ,
2026                        SUPERV::ResumedSuccessedState ) ; 
2027   SendEvent( ResumedSuccessedEvent ) ;
2028   return 1 ;
2029 }
2030
2031 int GraphExecutor::InNode::SuspendedErrored_ResumeAction() {
2032   cdebug << ThreadNo() << " SuspendedErrored_ResumeAction " << Name() << endl;
2033 //  ResumeAction() ;
2034   _OutNode->PushEvent( this , GraphExecutor::ResumedErroredEvent ,
2035                        SUPERV::ResumedErroredState ) ; 
2036   SendEvent( ResumedErroredEvent ) ;
2037   return 1 ;
2038 }
2039
2040 int GraphExecutor::InNode::Successed_KillAction() {
2041   KillAction() ;
2042   _OutNode->PushEvent( this , GraphExecutor::KilledEvent ,
2043                        SUPERV::KilledSuccessedState ) ; 
2044   cdebug << ThreadNo() << " Successed_KillAction " << Name() << endl;
2045   return 1 ;
2046 }
2047
2048 int GraphExecutor::InNode::Errored_KillAction() {
2049   KillAction() ;
2050   _OutNode->PushEvent( this , GraphExecutor::KilledEvent ,
2051                        SUPERV::KilledErroredState ) ; 
2052   cdebug << ThreadNo() << " Errored_KillAction " << Name() << endl;
2053   return 1 ;
2054 }
2055
2056 int GraphExecutor::InNode::Successed_StopAction() {
2057   StopAction() ;
2058   _OutNode->PushEvent( this , GraphExecutor::StoppedEvent ,
2059                        SUPERV::StoppedSuccessedState ) ; 
2060   cdebug << ThreadNo() << " Successed_StopAction " << Name() << endl;
2061   return 1 ;
2062 }
2063
2064 int GraphExecutor::InNode::Errored_StopAction() {
2065   StopAction() ;
2066   _OutNode->PushEvent( this , GraphExecutor::StoppedEvent ,
2067                        SUPERV::StoppedErroredState ) ; 
2068   cdebug << ThreadNo() << " Errored_StopAction " << Name() << endl;
2069   return 1 ;
2070 }
2071
2072 int GraphExecutor::InNode::SuspendedSuccessed_ReStartAction() {
2073   cdebug << ThreadNo() << " SuspendedSuccessed_ReStartAction " << Name() << endl;
2074   _OutNode->PushEvent( this , GraphExecutor::ReStartedEvent ,
2075                        SUPERV::ReStartedState ) ;
2076   int i ;
2077   for ( i = 0 ; i < GetNodeInPortsSize() ; i++ ) {
2078     GetChangeNodeInPort( i )->State( SUPERV::ReadyState ) ;
2079   }
2080   SendEvent( ExecuteEvent ) ;
2081   cdebug << ThreadNo() << " SuspendedSuccessed_ReStartAction "  << Name() << endl;
2082   return 1 ;
2083 }
2084
2085 int GraphExecutor::InNode::SuspendedErrored_ReStartAction() {
2086   cdebug << ThreadNo() << " SuspendedErrored_ReStartAction " << Name() << endl;
2087   _OutNode->PushEvent( this , GraphExecutor::ReStartedEvent ,
2088                        SUPERV::ReStartedState ) ; 
2089   int i ;
2090   for ( i = 0 ; i < GetNodeInPortsSize() ; i++ ) {
2091     GetChangeNodeInPort( i )->State( SUPERV::ReadyState ) ;
2092   }
2093   SendEvent( ExecuteEvent ) ;
2094   cdebug << ThreadNo() << " SuspendedErrored_ReStartAction "  << Name() << endl;
2095   return 1 ;
2096 }
2097
2098 int GraphExecutor::InNode::SuspendedSuccessed_ReStartAndSuspendAction() {
2099   cdebug << ThreadNo() << " SuspendedSuccessed_ReStartAndSuspendAction " << Name()
2100          << endl;
2101   _OutNode->PushEvent( this , GraphExecutor::ReStartedAndSuspendEvent ,
2102                        SUPERV::ReStartedState ) ; 
2103   State( SUPERV::DataWaitingState ) ;
2104   if ( !Suspend() ) {
2105     cdebug << "InNode::Suspend() Node " << Name() << endl ;
2106     return false ;
2107   }
2108   else if ( SendEvent( GraphExecutor::SomeDataReadyEvent ) ) {
2109     cdebug << "InNode::SendEvent( SomeDataReadyEvent ) Node "
2110            << Name() << endl ;
2111     return false ;
2112   }
2113   cdebug << ThreadNo() << " SuspendedSuccessed_ReStartAndSuspendAction "  << Name()
2114          << endl;
2115   return 1 ;
2116 }
2117
2118 int GraphExecutor::InNode::SuspendedErrored_ReStartAndSuspendAction() {
2119   cdebug << ThreadNo() << " SuspendedErrored_ReStartAndSuspendAction " << Name()
2120          << endl;
2121   _OutNode->PushEvent( this , GraphExecutor::ReStartedAndSuspendEvent ,
2122                        SUPERV::ReStartedState ) ; 
2123   State( SUPERV::DataWaitingState ) ;
2124   if ( !Suspend() ) {
2125     cdebug << "InNode::Suspend() Node " << Name() << endl ;
2126     return false ;
2127   }
2128   else if ( SendEvent( GraphExecutor::SomeDataReadyEvent ) ) {
2129     cdebug << "InNode::SendEvent( SomeDataReadyEvent ) Node "
2130            << Name() << endl ;
2131     return false ;
2132   }
2133   cdebug << ThreadNo() << " SuspendedErrored_ReStartAndSuspendAction "  << Name()
2134          << endl;
2135   return 1 ;
2136 }
2137
2138 void GraphExecutor::InNode::InParametersSet( bool & Err ,
2139                                              int  nInParams ,
2140                                              ServicesAnyData * InParametersList ) {
2141   int i ;
2142   for ( i = 0 ; i < nInParams ; i++ ) {
2143     ServicesAnyData D = InParametersList[i];
2144     GraphBase::InPort * anInPort = GetChangeNodeInPort(i) ;
2145     GraphBase::OutPort * theOutPort = anInPort->GetOutPort() ;
2146     if ( anInPort->IsGate() && theOutPort == NULL ) {
2147       cdebug << ThreadNo() << " ArgIn" << i << " " << D.Name << " "
2148              << anInPort->GetServicesParameter().Parametertype
2149              << " is inactive. " << anInPort->Kind() << endl ;
2150     }
2151     else if ( anInPort->State() == SUPERV::ReadyState ) {
2152       if ( anInPort->IsGate() ) {
2153         CORBA::Any * anAny = new CORBA::Any() ;
2154         *anAny <<= (long ) 0 ;
2155         theOutPort->Value( anAny ) ;
2156       }
2157       if ( !anInPort->IsDataStream() ) {
2158         anInPort->State( SUPERV::WaitingState ) ;
2159       }
2160       D.Name = CORBA::string_dup( anInPort->GetServicesParameter().Parametername ) ;
2161       cdebug << ThreadNo() << " ArgIn" << i << " " << anInPort->Kind() ;
2162       cdebug << "      " << D.Name << " " << anInPort->GetServicesParameter().Parametertype << " : " ;
2163       D.Value = *theOutPort->Value() ; // CORBA::Any
2164       string _Type = CORBA::string_dup( anInPort->GetServicesParameter().Parametertype ) ;
2165       const char * Type = _Type.c_str() ;
2166       switch ( D.Value.type()->kind() ) { // { string , long , double , objref }
2167       case CORBA::tk_string:
2168         char * t;
2169         D.Value >>= t;
2170         cdebug << t << " (string)" ;
2171         if ( !strcmp( Type , "string" ) ) {
2172         }
2173         else if ( !strcmp( Type , "boolean" ) ) {
2174           bool b ;
2175           long d ;
2176           sscanf( t , "%ld" , &d ) ;
2177           b = (bool ) d ;
2178           D.Value <<=  (CORBA::Any::from_boolean ) b ;
2179 //          theOutPort->Value( D.Value ) ;
2180         }
2181         else if ( !strcmp( Type , "char" ) ) {
2182           unsigned char c ;
2183           long d ;
2184           sscanf( t , "%ld" , &d ) ;
2185           c = (short ) d ;
2186           D.Value <<=  (CORBA::Any::from_char ) c ;
2187           cdebug << "string '" << t << "' --> " << d << " --> char " << c ;
2188 //          theOutPort->Value( D.Value ) ;
2189         }
2190         else if ( !strcmp( Type , "short" ) ) {
2191           short s ;
2192           long d ;
2193           sscanf( t , "%ld" , &d ) ;
2194           s = (short ) d ;
2195           D.Value <<=  s ;
2196           cdebug << "string '" << t << "' --> " << d << " --> short " << s ;
2197 //          theOutPort->Value( D.Value ) ;
2198         }
2199         else if ( !strcmp( Type , "int" ) || !strcmp( Type , "long" ) ) {
2200           long l ;
2201           sscanf( t , "%ld" , &l ) ;
2202           D.Value <<=  l ;
2203           cdebug << "string '" << t << " --> long " << l ;
2204 //          theOutPort->Value( D.Value ) ;
2205         }
2206         else if ( !strcmp( Type , "float" ) ) {
2207           double d ;
2208           sscanf( t , "%lf" , &d ) ;
2209           float f = d ;
2210           D.Value <<= f ;
2211           cdebug << "string '" << t << "' --> " << setw(25) << setprecision(18) << d << " --> float " << " = "
2212                  << setw(25) << setprecision(18) << f ;
2213 //          theOutPort->Value( D.Value ) ;
2214         }
2215         else if ( !strcmp( Type , "double" ) ) {
2216           double d ;
2217           sscanf( t , "%lf" , &d ) ;
2218           D.Value <<= d ;
2219           cdebug << "string '" << t << " --> double " << setw(25) << setprecision(18) << d ;
2220 //          theOutPort->Value( D.Value ) ;
2221         }
2222 //        else if ( !strcmp( Type , "objref" ) ) {
2223         else { // Default
2224           CORBA::Object_ptr ObjRef ;
2225           try {
2226             ObjRef = StringToObject( t ) ;
2227             D.Value <<= ObjRef ;
2228           }
2229           catch( ... ) {
2230             D.Value <<= CORBA::Object::_nil() ;
2231           }
2232 //          theOutPort->Value( D.Value ) ;
2233         }
2234 //        else {
2235 //          cdebug << " (other ERROR)" << endl ;
2236 //        }
2237         cdebug << " --> call_kind " << D.Value.type()->kind() << endl ;
2238         break;
2239       case CORBA::tk_long:
2240         long l;
2241         D.Value >>= l;
2242         cdebug << l << " (long)" << endl ;
2243         if ( !strcmp( Type , "string" ) ) {
2244           char t[40] ;
2245           sprintf( t , "%ld" , l ) ;
2246           D.Value <<= t ;
2247 //          theOutPort->Value( D.Value ) ;
2248         }
2249         else if ( !strcmp( Type , "boolean" ) ) {
2250           bool b ;
2251           b = (bool ) l ;
2252           D.Value <<=  (CORBA::Any::from_boolean ) b ;
2253 //          theOutPort->Value( D.Value ) ;
2254         }
2255         else if ( !strcmp( Type , "char" ) ) {
2256           unsigned char c ;
2257           c = (unsigned char ) l ;
2258           D.Value <<=  (CORBA::Any::from_char ) c ;
2259 //          theOutPort->Value( D.Value ) ;
2260         }
2261         else if ( !strcmp( Type , "short" ) ) {
2262           short s ;
2263           s = (short ) l ;
2264           D.Value <<=  s ;
2265 //          theOutPort->Value( D.Value ) ;
2266         }
2267         else if ( !strcmp( Type , "int" ) || !strcmp( Type , "long" ) ) {
2268         }
2269         else if ( !strcmp( Type , "float" ) ) {
2270           float f ;
2271           f = (float ) l ;
2272           D.Value <<= f ;
2273 //          theOutPort->Value( D.Value ) ;
2274         }
2275         else if ( !strcmp( Type , "double" ) ) {
2276           double d ;
2277           d = (double ) l ;
2278           D.Value <<= d ;
2279 //          theOutPort->Value( D.Value ) ;
2280         }
2281 //        else if ( !strcmp( Type , "objref" ) ) {
2282         else { // Default
2283           D.Value <<= CORBA::Object::_nil() ;
2284 //          theOutPort->Value( D.Value ) ;
2285         }
2286 //        else {
2287 //          cdebug << " (other ERROR)" << endl ;
2288 //        }
2289         cdebug << " --> call_kind " << D.Value.type()->kind() << endl ;
2290         break;
2291       case CORBA::tk_double:
2292         double d;
2293         D.Value >>= d;
2294         cdebug << d << " (double)" << endl ;
2295         if ( !strcmp( Type , "string" ) ) {
2296           char t[40] ;
2297           sprintf( t , "%lf" , d ) ;
2298           D.Value <<= t ;
2299 //          theOutPort->Value( D.Value ) ;
2300         }
2301         else if ( !strcmp( Type , "boolean" ) ) {
2302           bool b ;
2303           b = (bool ) d ;
2304           D.Value <<=  (CORBA::Any::from_boolean ) b ;
2305 //          theOutPort->Value( D.Value ) ;
2306         }
2307         else if ( !strcmp( Type , "char" ) ) {
2308           unsigned char c ;
2309           c = (unsigned char ) d ;
2310           D.Value <<=  (CORBA::Any::from_char ) c ;
2311 //          theOutPort->Value( D.Value ) ;
2312         }
2313         else if ( !strcmp( Type , "short" ) ) {
2314           short s ;
2315           s = (short ) d ;
2316           D.Value <<=  s ;
2317 //          theOutPort->Value( D.Value ) ;
2318         }
2319         else if ( !strcmp( Type , "int" ) || !strcmp( Type , "long" ) ) {
2320           long l ;
2321           l = (long ) d ;
2322           D.Value <<= l ;
2323 //          theOutPort->Value( D.Value ) ;
2324         }
2325         else if ( !strcmp( Type , "float" ) ) {
2326           float f ;
2327           f = (float ) d ;
2328           D.Value <<= f ;
2329 //          theOutPort->Value( D.Value ) ;
2330         }
2331         else if ( !strcmp( Type , "double" ) ) {
2332         }
2333 //        else if ( !strcmp( Type , "objref" ) ) {
2334         else { // Default
2335           D.Value <<= CORBA::Object::_nil() ;
2336 //          theOutPort->Value( D.Value ) ;
2337         }
2338 //        else {
2339 //          cdebug << " (other ERROR)" << endl ;
2340 //        }
2341         cdebug << " --> call_kind " << D.Value.type()->kind() << endl ;
2342         break;
2343       case CORBA::tk_objref:
2344         if ( !strcmp( Type , "string" ) ) {
2345           CORBA::Object_ptr ObjRef ;
2346           char * retstr ;
2347           try {
2348             D.Value >>= ObjRef ;
2349             retstr = ObjectToString( ObjRef ) ;
2350             D.Value <<= retstr ;
2351 //            theOutPort->Value( D.Value ) ;
2352           }
2353           catch( ... ) {
2354             if ( i != 0 ) {
2355               Err = true ;
2356             }
2357             cdebug << "ToString( object ) Catched ERROR" << endl ;
2358           }
2359         }
2360         else if ( !strcmp( Type , "boolean" ) ) {
2361           bool b = 0 ;
2362           D.Value <<=  (CORBA::Any::from_boolean ) b ;
2363 //          theOutPort->Value( D.Value ) ;
2364         }
2365         else if ( !strcmp( Type , "char" ) ) {
2366           unsigned char c = 0 ;
2367           D.Value <<=  (CORBA::Any::from_char ) c ;
2368 //          theOutPort->Value( D.Value ) ;
2369         }
2370         else if ( !strcmp( Type , "short" ) ) {
2371           short s = 0 ;
2372           D.Value <<=  s ;
2373 //          theOutPort->Value( D.Value ) ;
2374         }
2375         else if ( !strcmp( Type , "int" ) || !strcmp( Type , "long" ) ) {
2376           long l = 0 ;
2377           D.Value <<= l ;
2378 //          theOutPort->Value( D.Value ) ;
2379         }
2380         else if ( !strcmp( Type , "float" ) ) {
2381           float f = 0 ;
2382           D.Value <<= f ;
2383 //          theOutPort->Value( D.Value ) ;
2384         }
2385         else if ( !strcmp( Type , "double" ) ) {
2386           double d = 0 ;
2387           D.Value <<= d ;
2388 //          theOutPort->Value( D.Value ) ;
2389         }
2390 //        else if ( !strcmp( Type , "objref" ) ) {
2391         else { // Default
2392           CORBA::Object_ptr obj ;
2393           char * retstr ;
2394           try {
2395             D.Value >>= obj ;
2396             retstr = ObjectToString( obj ) ;
2397             cdebug << retstr << endl ;
2398           }
2399           catch( ... ) {
2400             if ( i != 0 ) {
2401               Err = true ;
2402             }
2403             cdebug << "ToString( object ) Catched ERROR" << endl ;
2404           }
2405         }
2406 //        else {
2407 //          cdebug << " (other ERROR)" << endl ;
2408 //        }
2409         cdebug << " --> call_kind " << D.Value.type()->kind() << endl ;
2410         break;
2411       default:
2412         cdebug << " (other ERROR) " << D.Value.type()->kind() << endl ;
2413       }
2414     }
2415     else {
2416       cdebug << ThreadNo() << " In" << i << " : wrong state ERROR State "
2417              << anInPort->State() << " NameState "
2418              << Automaton()->StateName( anInPort->State() ) << " PortName "
2419              << anInPort->PortName() << " Parametername "
2420              << anInPort->GetServicesParameter().Parametername << endl ;
2421       Err = true ;
2422     }
2423     InParametersList[i] = D ;
2424   }
2425 }
2426
2427 void GraphExecutor::InNode::InOutParametersSet( int nOutParams ,
2428                                                 ServicesAnyData * OutParametersList ) {
2429   int i ;
2430   for ( i = 0 ; i < nOutParams ; i++ ) {
2431     ServicesAnyData D = OutParametersList[i] ;
2432
2433     D.Name = GetChangeNodeOutPort(i)->GetServicesParameter().Parametername;
2434     string _Type = CORBA::string_dup(GetChangeNodeOutPort(i)->GetServicesParameter().Parametertype) ;
2435     const char * Type = _Type.c_str() ;
2436     bool OutDone = GetChangeNodeOutPort(i)->Done() ;
2437     cdebug << ThreadNo() << " ArgOut" << i << " " << D.Name << " Done("
2438            << OutDone << ") " << Type << " : " << endl ;
2439     if ( !strcmp( Type , "string" ) ) {
2440       D.Value <<= (char *) NULL ;
2441     }
2442     else if ( !strcmp( Type , "boolean" ) ) {
2443       bool b = 0 ;
2444       D.Value <<=  (CORBA::Any::from_boolean ) b ;
2445     }
2446     else if ( !strcmp( Type , "char" ) ) {
2447       unsigned char c = 0 ;
2448       D.Value <<=  (CORBA::Any::from_char ) c ;
2449     }
2450     else if ( !strcmp( Type , "short" ) ) {
2451       short s = 0 ;
2452       D.Value <<=  s ;
2453     }
2454     else if ( !strcmp( Type , "int" ) || !strcmp( Type , "long" ) ) {
2455       D.Value <<= (long ) 0 ;
2456     }
2457     else if ( !strcmp( Type , "float" ) ) {
2458       float f = 0 ;
2459       D.Value <<= f ;
2460     }
2461     else if ( !strcmp( Type , "double" ) ) {
2462       double d = 0 ;
2463       D.Value <<= d ;
2464     }
2465     else {
2466       D.Value <<= CORBA::Object::_nil() ;
2467     }
2468 //#if 0
2469     switch (D.Value.type()->kind()) { // { string , long , double , objref }
2470     case CORBA::tk_string:
2471       char * t;
2472       D.Value >>= t;
2473       cdebug << ThreadNo() << " " << t << "(string)" << endl ;
2474       break;
2475     case CORBA::tk_boolean:
2476       bool b ;
2477       D.Value >>= (CORBA::Any::to_boolean ) b;
2478       cdebug << ThreadNo() << " " << b << "(boolean)" << endl ;
2479       break;
2480     case CORBA::tk_char:
2481       unsigned char c ;
2482       D.Value >>= (CORBA::Any::to_char ) c;
2483       cdebug << ThreadNo() << " " << c << "(char)" << endl ;
2484       break;
2485     case CORBA::tk_short:
2486       short s;
2487       D.Value >>= s;
2488       cdebug << ThreadNo() << " " << s << "(short)" << endl ;
2489       break;
2490     case CORBA::tk_long:
2491       long l;
2492       D.Value >>= l;
2493       cdebug << ThreadNo() << " " << l << "(long)" << endl ;
2494       break;
2495     case CORBA::tk_float:
2496       float f;
2497       D.Value >>= f;
2498       cdebug << ThreadNo() << " " << f << "(float)" << endl ;
2499       break;
2500     case CORBA::tk_double:
2501       double d;
2502       D.Value >>= d;
2503       cdebug << ThreadNo() << " " << d << "(double)" << endl ;
2504       break;
2505     case CORBA::tk_objref:
2506       try {
2507         CORBA::Object_ptr obj ;
2508         char * retstr ;
2509         D.Value >>= obj ;
2510         retstr = ObjectToString( obj ) ;
2511         cdebug << ThreadNo() << retstr << endl ;
2512       }
2513       catch( ... ) {
2514         cdebug << "ToString( object ) Catched ERROR" << endl ;
2515       }
2516       break;
2517     default:
2518       cdebug << ThreadNo() << " " << "(other ERROR)" << endl ;
2519     }
2520 //#endif
2521     OutParametersList[i] = D ;
2522   }
2523 }
2524
2525 bool GraphExecutor::InNode::OutParametersSet( bool Err ,
2526                                               SUPERV::GraphState NewState ,
2527                                               int nOutParams ,
2528                                               ServicesAnyData * OutParametersList ) {
2529   bool RetVal = true ;
2530   int i ;
2531   GraphBase::OutPort * aGateOutPort = NULL ;
2532   bool OrSwitch = false ;
2533   if ( nOutParams ) {
2534     GraphBase::OutPort * anOutPort ;
2535     for ( i = 0 ; i < nOutParams ; i++ ) {
2536       anOutPort = GetChangeNodeOutPort(i) ;
2537       if ( Err ) {
2538         anOutPort->State( NewState ) ;
2539         anOutPort->Done( true ) ;
2540       }
2541       else {
2542         cdebug << ThreadNo() << " " << "Out" << i << " " << Name() << " "
2543                << anOutPort->PortName() << " " << anOutPort->Kind() ;
2544         ServicesAnyData D = OutParametersList[i] ;
2545         switch (D.Value.type()->kind()) { // { string , long , double , objref }
2546         case CORBA::tk_string: {
2547           char * t;
2548           D.Value >>= t;
2549           cdebug << ThreadNo() << " " << t << "(string)" << endl ;
2550           break;
2551         }
2552         case CORBA::tk_boolean: {
2553           bool b ;
2554           D.Value >>= (CORBA::Any::to_boolean ) b;
2555           long l = (long ) b ;
2556           D.Value <<= l ;
2557           cdebug << ThreadNo() << " " << b << "(boolean)" << endl ;
2558           break;
2559         }
2560         case CORBA::tk_char: {
2561           unsigned char c ;
2562           D.Value >>= (CORBA::Any::to_char ) c;
2563           long l = (long ) c ;
2564           D.Value <<= l ;
2565           cdebug << ThreadNo() << " " << c << "(char)" << endl ;
2566           break;
2567         }
2568         case CORBA::tk_short: {
2569           short s;
2570           D.Value >>= s;
2571           long l = (long ) s ;
2572           D.Value <<= l ;
2573           cdebug << ThreadNo() << " " << s << "(short)" << endl ;
2574           break;
2575         }
2576         case CORBA::tk_long: {
2577           long l;
2578           D.Value >>= l;
2579           cdebug << ThreadNo() << " " << l << "(long)" << endl ;
2580           break;
2581         }
2582         case CORBA::tk_float: {
2583           float f;
2584           D.Value >>= f;
2585           double d = (double ) f ;
2586           D.Value <<= d ;
2587           cdebug << ThreadNo() << " " << f << "(float)" << endl ;
2588           break;
2589         }
2590         case CORBA::tk_double: {
2591           double d;
2592           D.Value >>= d;
2593           cdebug << ThreadNo() << " " << d << "(double)" << endl ;
2594           break;
2595         }
2596         case CORBA::tk_objref: {
2597           try {
2598             CORBA::Object_ptr obj ;
2599             char * retstr ;
2600             D.Value >>= obj ;
2601             retstr = ObjectToString( obj ) ;
2602             cdebug << ThreadNo() << retstr << endl ;
2603           }
2604           catch( ... ) {
2605             cdebug << "ToString( object ) Catched ERROR" << endl ;
2606           }
2607           break;
2608         }
2609         default: {
2610           cdebug << ThreadNo() << " " << "(other ERROR)" << endl ;
2611         }
2612         }
2613         OutParametersList[i] = D ;
2614         if ( !anOutPort->IsDataStream() ) {
2615           if ( anOutPort->IsGate() ) {
2616             aGateOutPort = anOutPort ;
2617             cdebug << " Gate " ;
2618             long l = 1;
2619             OutParametersList[i].Value <<= l;
2620             anOutPort->Value( OutParametersList[i].Value );
2621           }
2622           else if ( anOutPort->IsLoop() ) {
2623             cdebug << " Loop " ;
2624             anOutPort->Value( OutParametersList[i].Value );
2625 // InLoop Port of EndLoopNode is ready :
2626             anOutPort->ChangeInPorts(0)->State( SUPERV::ReadyState ) ;
2627           }
2628           else if ( anOutPort->IsSwitch() ) {
2629             cdebug << " Switch " ;
2630             anOutPort->Value( OutParametersList[i].Value );
2631             if ( anOutPort->InPortsSize() && anOutPort->ChangeInPorts( 0 )->IsGate() ) {
2632               if ( OrSwitch && anOutPort->BoolValue() ) {
2633                 cdebug << "GraphExecutor::InNodeThreads::OutParameters more than one switch is true WARNING"
2634                        << endl ;
2635               }
2636               else {
2637                 OrSwitch = OrSwitch | anOutPort->BoolValue() ;
2638               }
2639             }
2640             cdebug << "OrSwitch " << OrSwitch ;
2641           }
2642           else {
2643             cdebug << " Param " ;
2644             anOutPort->Value( OutParametersList[i].Value );
2645           }
2646           anOutPort->State( NewState ) ;
2647           anOutPort->Done( true ) ;
2648         }
2649         int j ;
2650         for ( j = 0 ; j < anOutPort->InPortsSize() ; j++ ) {
2651           bool fromGOTO = false ;
2652           GraphBase::OutPort * aGOTOPort = _OutNode->Graph()->GetChangeGraphNode( anOutPort->ChangeInPorts( j )->NodeName() )->GetChangeNodeInGate()->GetOutPort() ;
2653           if ( aGOTOPort ) {
2654             fromGOTO = aGOTOPort->IsGOTO() ;
2655           }
2656           if ( anOutPort->ChangeInPorts( j )->IsEndSwitch() || fromGOTO ) {
2657             cdebug << anOutPort->ChangeInPorts( j )->NodeName() << "("
2658                    << anOutPort->ChangeInPorts( j )->PortName() << ","
2659                    << anOutPort->ChangeInPorts( j )->Kind() << ") WILL BE changed from "
2660                    << anOutPort->ChangeInPorts( j )->GetOutPort()->NodeName()
2661                    << "("
2662                    << anOutPort->ChangeInPorts( j )->GetOutPort()->PortName()
2663                    << ") to " << anOutPort->NodeName() << "("
2664                    << anOutPort->PortName() << ")" << endl ;
2665             anOutPort->ChangeInPorts( j )->ChangeOutPort( anOutPort ) ;
2666           }
2667           else {
2668             cdebug << anOutPort->ChangeInPorts( j )->NodeName() << "("
2669                    << anOutPort->ChangeInPorts( j )->PortName() << ","
2670                    << anOutPort->ChangeInPorts( j )->Kind() << ") NOT changed from "
2671                    << anOutPort->ChangeInPorts( j )->GetOutPort()->NodeName()
2672                    << "("
2673                    << anOutPort->ChangeInPorts( j )->GetOutPort()->PortName()
2674                    << ") to " << anOutPort->NodeName() << "("
2675                    << anOutPort->PortName() << ")" << endl ;
2676           }
2677         }
2678 //#if 0
2679         switch (anOutPort->Value()->type()->kind()) {
2680         case CORBA::tk_string:
2681           char * t;
2682           (*anOutPort->Value()) >>= t;
2683           cdebug << ThreadNo() << " Out" << i << " : " << t << "(string)" << endl ;
2684           break;
2685         case CORBA::tk_boolean:
2686           bool b ;
2687           (*anOutPort->Value()) >>= (CORBA::Any::to_boolean ) b;
2688           cdebug << ThreadNo() << " Out" << i << " : " << b << "(boolean)" << endl ;
2689           break;
2690         case CORBA::tk_char:
2691           unsigned char c ;
2692           (*anOutPort->Value()) >>= (CORBA::Any::to_char ) c;
2693           cdebug << ThreadNo() << " Out" << i << " : " << c << "(char)" << endl ;
2694           break;
2695         case CORBA::tk_short:
2696           short s;
2697           (*anOutPort->Value()) >>= s;
2698           cdebug << ThreadNo() << " Out" << i << " : " << s << "(short)" << endl ;
2699           break;
2700         case CORBA::tk_long:
2701           long l;
2702           (*anOutPort->Value()) >>= l;
2703           cdebug << ThreadNo() << " Out" << i << " : " << l << "(long)" << endl ;
2704           break;
2705         case CORBA::tk_float:
2706           float f;
2707           (*anOutPort->Value()) >>= f;
2708           cdebug << ThreadNo() << " Out" << i << " : " << f << "(float)" << endl ;
2709           break;
2710         case CORBA::tk_double:
2711           double d;
2712           (*anOutPort->Value()) >>= d;
2713           cdebug << ThreadNo() << " Out" << i << " : " << d << "(double)" << endl ;
2714           break;
2715         case CORBA::tk_objref:
2716           CORBA::Object_ptr obj ;
2717           char * retstr ;
2718           try {
2719             (*anOutPort->Value()) >>= obj ;
2720             retstr = ObjectToString( obj );
2721             cdebug << ThreadNo() << " Out" << i << " : " << "ToString( object ) "
2722                    << retstr << endl ;
2723           }
2724           catch ( ... ) {
2725             cdebug << ThreadNo() << " Out" << i << " : " << "ToString( object ) "
2726                    << "Catched ERROR" << endl ;
2727           }
2728           break;
2729         default:
2730           cdebug << ThreadNo() << " Out" << i << " : " << "(other ERROR)" << endl ;
2731           RetVal = false ;
2732         }
2733 //#endif
2734       }
2735     }
2736     if ( aGateOutPort && IsSwitchNode() ) {
2737       if ( OrSwitch ) {
2738 //        cdebug << ThreadNo() << " " << "Out0 " << Name() << " Close of "
2739 //               << aGateOutPort->PortName() << " " << aGateOutPort->Kind() ;
2740         long l = 0;
2741         OutParametersList[0].Value <<= l ;
2742         aGateOutPort->Value( OutParametersList[0].Value ) ;
2743       }
2744       else {
2745 //        cdebug << ThreadNo() << " " << "Out0 " << Name() << " Open of "
2746 //               << aGateOutPort->PortName() << " " << aGateOutPort->Kind() ;
2747         long l = 1;
2748         OutParametersList[0].Value <<= l ;
2749         aGateOutPort->Value( OutParametersList[0].Value ) ;
2750         int i ;
2751         for ( i = 0 ; i < GetNodeOutPortsSize() ; i++ ) {
2752           GraphBase::InPort * anInPort ;
2753           anInPort = CoupledNode()->GetChangeInPort( GetNodeOutPort( i )->PortName() ) ;
2754           if ( anInPort ) {
2755             anInPort->ChangeOutPort( GetChangeNodeOutPort( i ) ) ;
2756           }
2757         }
2758       }
2759     }
2760   }
2761   return RetVal ;
2762 }