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