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