]> SALOME platform Git repositories - modules/superv.git/blob - src/GraphExecutor/DataFlowExecutor_InNodeThreads.cxx
Salome HOME
In case of error in a Container, Kill_impl() ===> Reset of ThreadId
[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() << " " << anInPort->State() << " " << anInPort->PortStatus() << 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       MESSAGE(pthread_self() << "Executor::InNode::DataReady_ExecuteAction of " << Name()
1161               << " ControlState " << Automaton()->ControlStateName( ControlState() )
1162               << " BEFORE execution ThreadNo " << ThreadNo() ) ;
1163       IsLoading( false ) ;
1164       Err = true ;
1165     }
1166     else {
1167       if ( ControlState() == SUPERV::ToSuspendState ) {
1168         cdebug << ThreadNo() << "ToSuspendState before running." << endl ;
1169         MESSAGE(ThreadNo() << "ToSuspendState before running.") ;
1170       }
1171       if ( !Err ) {
1172 //        ostringstream astr ;
1173 //        astr << "Graph " << _OutNode->Graph()->Name() << " Run of Node " << Name() ;
1174 //        _OutNode->Graph()->ObjImpl()->sendMessage( NOTIF_STEP, astr.str().c_str() ) ;
1175         cdebug << ThreadNo() << " Run( '" << ServiceName() << "'" ;
1176         for ( i = 0 ; i < (int ) ServiceInParameter().length() ; i++ ) {
1177           cdebug << " , " << InParametersList[ i ].Name << "[kind"
1178                  << InParametersList[ i ].Value.type()->kind() << "]" ;
1179         }
1180         for ( i = 0 ; i < (int ) ServiceOutParameter().length() ; i++ ) {
1181           cdebug << " , " << OutParametersList[ i ].Name << "[kind"
1182                  << OutParametersList[ i ].Value.type()->kind() << "]" ;
1183         }
1184         if ( IsOneOfInLineNodes() ) {
1185           cdebug << " , PyFuncName '" << InLineNode()->PyFuncName() << "' PyRunMethod "
1186                  << InLineNode()->PyRunMethod() << " length " << (*InLineNode()->PythonFunction()).length() ;
1187         }
1188         cdebug << ")" << endl ;
1189
1190         if ( IsOneOfInLineNodes() ) {
1191           bool StsPyDynInvoke = true;
1192           _OutNode->PyThreadLock() ;
1193           SetPyCpuUsed() ;
1194           try {
1195 //            if ( IsInLineNode() && (*InLineNode()->PythonFunction()).length() &&
1196             bool CopyInOut = false ;
1197             if ( IsInLineNode() && /*InLineNode()->PyRunMethod() &&*/
1198                  strlen( InLineNode()->PyFuncName() ) ) {
1199 //              cdebug << ThreadNo() << " !ObjInterface " << Name() << " PyFuncName '"
1200 //                     << InLineNode()->PyFuncName()
1201 //                     << "' IsInLineNode PyDynInvoke"  << endl ;
1202               StsPyDynInvoke = PyDynInvoke( InLineNode()->PyRunMethod() ,
1203                                             InLineNode()->PyFuncName() ,
1204                                             &InParametersList[0] , ServiceInParameter().length() ,
1205                                             &OutParametersList[0] , ServiceOutParameter().length() ) ;
1206             }
1207             else if ( IsLoopNode() ) {
1208               bool CopyOutIn = false ;
1209               if ( GetNodeInLoop()->GetOutPort()->BoolValue() && /*InLineNode()->PyRunMethod() &&*/
1210                    strlen( InLineNode()->PyFuncName() ) ) { // InLoop Port
1211 //                cdebug << ThreadNo() << " !ObjInterface " << Name()
1212 //                       << " IsLoopNode PyDynInvoke '" << InLineNode()->PyFuncName()
1213 //                       << "'" << endl ;
1214                 StsPyDynInvoke = PyDynInvoke( InLineNode()->PyRunMethod() ,
1215                                               InLineNode()->PyFuncName() ,
1216                                               &InParametersList[1] , ServiceInParameter().length() ,
1217                                               &OutParametersList[1] , ServiceOutParameter().length() ) ;
1218                 CopyOutIn = true ;
1219               }
1220               else if ( LoopNode()->PyNextMethod() &&
1221                         strlen( LoopNode()->PyNextName() ) ){
1222 //                cdebug << ThreadNo() << " !ObjInterface " << Name()
1223 //                       << " IsLoopNode PyDynInvoke '" << LoopNode()->PyNextName()
1224 //                       << "'" << endl ;
1225                 StsPyDynInvoke = PyDynInvoke( LoopNode()->PyNextMethod() ,
1226                                               LoopNode()->PyNextName() ,
1227                                               &InParametersList[1] , ServiceInParameter().length() ,
1228                                               &OutParametersList[1] , ServiceOutParameter().length() ) ;
1229                 CopyOutIn = true ;
1230               }
1231               if ( StsPyDynInvoke && CopyOutIn ) {
1232 //                cdebug << ThreadNo() << " !ObjInterface " << Name()
1233 //                       << " IsLoopNode PyDynInvoke '" << LoopNode()->PyMoreName()
1234 //                       << "' Copy of " << ServiceInParameter().length()
1235 //                       << " OutParameters" << endl ;
1236                 int i ;
1237                 for ( i = 1 ; i <= (int ) ServiceInParameter().length() ; i++ ) {
1238                   InParametersList[i].Value = OutParametersList[i].Value ;
1239                   InParametersList[i].Name = OutParametersList[i].Name ;
1240 //#if 0
1241                   switch ( InParametersList[i].Value.type()->kind() ) {
1242                   case CORBA::tk_string :
1243                     char * t;
1244                     InParametersList[i].Value >>= t ;
1245                     cdebug << "ArgOut->In" << i << " : "
1246                            << InParametersList[i].Name.c_str()
1247                            << " Value(string) " << t << endl ;
1248                     break ;
1249                   case CORBA::tk_double :
1250                     double d;
1251                     InParametersList[i].Value >>= d;
1252                     cdebug << "ArgOut->In" << i << " : "
1253                            << InParametersList[i].Name.c_str()
1254                            << " Value(double) " << d << endl ;
1255                     break ;
1256                   case CORBA::tk_long :
1257                     long l;
1258                     InParametersList[i].Value >>= l;
1259                     cdebug << "ArgOut->In" << i << " : "
1260                            << InParametersList[i].Name.c_str()
1261                            << " Value(long) " << l << endl ;
1262                     break ;
1263                   case CORBA::tk_objref :
1264                     CORBA::Object_ptr obj ;
1265                     char * retstr ;
1266                     try {
1267                       InParametersList[i].Value >>= obj ;
1268                       retstr = ObjectToString( obj );
1269                       cdebug << "ArgOut->In" << i << " : "
1270                              << InParametersList[i].Name.c_str()
1271                              << " Value(object reference) " << retstr << endl ;
1272                      }
1273                     catch ( ... ) {
1274                       cdebug << "ArgOut->In" << i << " : "
1275                              << InParametersList[i].Name.c_str()
1276                              << " Value(object reference) Catched ERROR" << endl ;
1277                     }
1278                     break ;
1279                   default :
1280                     cdebug << "ArgOut->In" << i << " : "
1281                            << InParametersList[i].Name.c_str()
1282                            << " Value(other) ERROR" << endl ;
1283                   }
1284 //#endif
1285                 }
1286                 if ( LoopNode()->PyMoreMethod() && strlen( LoopNode()->PyMoreName() ) ) {
1287                   StsPyDynInvoke = PyDynInvoke( LoopNode()->PyMoreMethod() ,
1288                                                 LoopNode()->PyMoreName() ,
1289                                                 &InParametersList[1] , ServiceInParameter().length() ,
1290                                                 &OutParametersList[0] , ServiceOutParameter().length()+1 ) ;
1291                 }
1292                 else {
1293                   CopyInOut = true ;
1294                 }
1295               }
1296               else  if ( !StsPyDynInvoke ) {
1297                 Err = true ;
1298                 cdebug << ThreadNo() << " InLineNode " << Name() << " "
1299                        << InLineNode()->PyFuncName() << "/" << LoopNode()->PyNextName()
1300                        << " Python Dynamic Call Error"
1301                        << endl ;
1302               }
1303             }
1304             else if ( IsSwitchNode() && /*InLineNode()->PyRunMethod() &&*/
1305                       strlen( InLineNode()->PyFuncName() ) ) {
1306 //              cdebug << ThreadNo() << " !ObjInterface " << Name() << " PyFuncName '"
1307 //                     << InLineNode()->PyFuncName()
1308 //                     << "' IsSwitchNode PyDynInvoke"  << endl ;
1309               StsPyDynInvoke = PyDynInvoke( InLineNode()->PyRunMethod() ,
1310                                             InLineNode()->PyFuncName() ,
1311                                             &InParametersList[0] , ServiceInParameter().length() ,
1312                                             &OutParametersList[0] , ServiceOutParameter().length() ) ;
1313             }
1314 //            else if ( IsGOTONode() && (*GOTONode()->PythonFunction()).length() &&
1315             else if ( IsGOTONode() && /*InLineNode()->PyRunMethod() &&*/
1316                       strlen( InLineNode()->PyFuncName() ) ) {
1317 //              cdebug << ThreadNo() << " !ObjInterface " << Name() << " PyFuncName '"
1318 //                     << InLineNode()->PyFuncName()
1319 //                     << "' IsGOTONode PyDynInvoke"  << endl ;
1320               StsPyDynInvoke = PyDynInvoke( InLineNode()->PyRunMethod() ,
1321                                             InLineNode()->PyFuncName() ,
1322                                             &InParametersList[0] , ServiceInParameter().length() ,
1323                                             &OutParametersList[0] , ServiceOutParameter().length() ) ;
1324             }
1325 //            else if ( IsEndSwitchNode() && (*InLineNode()->PythonFunction()).length() &&
1326             else if ( ( IsEndSwitchNode() ) &&
1327                       InLineNode()->PyRunMethod() && strlen( InLineNode()->PyFuncName() ) ) {
1328 //              cdebug << ThreadNo() << " !ObjInterface " << Name() << " PyFuncName '"
1329 //                     << InLineNode()->PyFuncName()
1330 //                     << "' IsSwitchNode PyDynInvoke"  << endl ;
1331               StsPyDynInvoke = PyDynInvoke( InLineNode()->PyRunMethod() ,
1332                                             InLineNode()->PyFuncName() ,
1333                                             &InParametersList[0] , ServiceInParameter().length() ,
1334                                             &OutParametersList[0] , ServiceOutParameter().length() ) ;
1335             }
1336             else if ( ( IsEndLoopNode() ) &&
1337                       InLineNode()->PyRunMethod() && strlen( InLineNode()->PyFuncName() ) ) {
1338 //              cdebug << ThreadNo() << " !ObjInterface " << Name() << " PyFuncName '"
1339 //                     << InLineNode()->PyFuncName()
1340 //                     << "' IsSwitchNode PyDynInvoke"  << endl ;
1341               StsPyDynInvoke = PyDynInvoke( InLineNode()->PyRunMethod() ,
1342                                             InLineNode()->PyFuncName() ,
1343                                             &InParametersList[0] , ServiceInParameter().length() + 1 ,
1344                                             &OutParametersList[0] , ServiceOutParameter().length() + 1 ) ;
1345             }
1346 //            else if ( (*InLineNode()->PythonFunction()).length() == 0 ||
1347             if ( InLineNode()->PyRunMethod() == NULL ||
1348                  strlen( InLineNode()->PyFuncName() ) == 0 || CopyInOut ) {
1349 //              cdebug << ThreadNo() << " !ObjInterface " << Name()
1350 //                     << " Copy of " << ServiceInParameter().length()
1351 //                     << " OutParameters" << endl ;
1352               int i ;
1353               int argout0 = 0 ;
1354               int argin0 = 0 ;
1355               if ( IsLoopNode() || IsEndLoopNode() ) {
1356                 argout0 = 1 ;
1357                 argin0 = 1 ; // after DoLoop
1358                 if ( IsLoopNode() ) {
1359                   OutParametersList[0].Value = InParametersList[0].Value ; // DoLoop
1360                 }
1361               }
1362               for ( i = 0 ; i < (int ) ServiceInParameter().length() ; i++ ) {
1363                 OutParametersList[argout0 + i].Value = InParametersList[argin0 + i].Value ;
1364 //#if 0
1365                 switch ( InParametersList[argin0 + i].Value.type()->kind() ) {
1366                 case CORBA::tk_string :
1367                   cdebug << "ArgOut->In" << argin0 + i << " : "
1368                          << InParametersList[argin0 + i].Name.c_str()
1369                          << " Value(string) "
1370                          << OutParametersList[argout0 + i].Name.c_str() << endl ;
1371                   break ;
1372                 case CORBA::tk_double :
1373                   cdebug << "ArgOut->In" << argin0 + i << " : "
1374                          << InParametersList[argin0 + i].Name.c_str()
1375                          << " Value(double) "
1376                          << OutParametersList[argout0 + i].Name.c_str() << endl ;
1377                   break ;
1378                 case CORBA::tk_long :
1379                   cdebug << "ArgOut->In" << argin0 + i << " : "
1380                          << InParametersList[argin0 + i].Name.c_str()
1381                          << " Value(long) "
1382                          << OutParametersList[argout0 + i ].Name.c_str() << endl ;
1383                   break ;
1384                 case CORBA::tk_objref :
1385                   cdebug << "ArgOut->In" << argin0 + i << " : "
1386                          << InParametersList[argin0 + i].Name.c_str()
1387                          << " Value(object reference) "
1388                          << OutParametersList[argout0 + i].Name.c_str() << endl ;
1389                   break ;
1390                 default :
1391                   cdebug << "ArgOut->In" << argin0 + i << " : "
1392                          << InParametersList[argin0 + i].Name.c_str()
1393                          << " Value(other) ERROR "
1394                          << OutParametersList[argout0 + i].Name.c_str() << endl ;
1395                 }
1396 //#endif
1397               }
1398             }
1399             if ( !StsPyDynInvoke ) {
1400               Err = true ;
1401               cdebug << ThreadNo() << " InLineNode " << Name()
1402                      << " Python Dynamic Call Error"
1403                      << endl ;
1404             }
1405           }
1406           catch( ... ) {
1407             Err = true ;
1408             cdebug << ThreadNo() << " InLineNode " << Name()
1409                    << " Python Dynamic Call Exception catched ERROR"
1410                    << endl ;
1411           }
1412           CpuUsed( true ) ;
1413           _OutNode->PyThreadUnLock() ;
1414         }
1415         else {
1416           try {
1417             try {
1418               cdebug << "DynInvoke -> Names " << _OutNode->Graph()->Name() << " " << Name() << endl ;
1419               DynInvoke( myObjComponent, "Names" ,
1420                          _OutNode->Graph()->Name() , Name() ) ;
1421             }
1422             catch( ... ) {
1423               cdebug << "DynInvoke Names catched ERROR" << endl ;
1424             }
1425 // for DataStreamNodes : call of SetProperties ===> environment variables in the component/container
1426             if ( ComputingNode()->HasDataStream() ) {
1427               try {
1428                 cdebug << "DynInvoke -> SetProperties " << _OutNode->Graph()->Name() << " " << Name() << endl ;
1429                 Engines::FieldsDict_var dict = new Engines::FieldsDict;
1430                 dict->length( 4 );
1431                 dict[ 0 ].key = CORBA::string_dup( "CAL_MACHINE");
1432                 // myContainer->getHostName() ne renvoit pas le nom complet (avec domaine).
1433                 //              dict[ 0 ].value <<= myContainer->getHostName() ;
1434                 char FullyQualifiedDomainName[256]="";
1435                 gethostname(FullyQualifiedDomainName,255);
1436                 dict[ 0 ].value <<=  FullyQualifiedDomainName ;
1437                 dict[ 1 ].key = CORBA::string_dup( "CAL_REPERTOIRE");
1438                 dict[ 1 ].value <<= "/tmp" ;
1439                 dict[ 2 ].key = CORBA::string_dup( "CAL_COUPLAGE");
1440                 stringstream ofst1 ;
1441                 ofst1 << ComputingNode()->SubStreamGraph() ;
1442                 string cpl = string( "/tmp/" ) + string( _OutNode->Graph()->Name() ) + string( "_" ) + 
1443                              ofst1.str() + string( ".cpl" );
1444                 dict[ 2 ].value <<= cpl.c_str() ;
1445                 dict[ 3 ].key = CORBA::string_dup( "SALOME_INSTANCE_NAME");
1446                 string uname = Name();
1447                 UpperCase( uname);
1448                 dict[ 3 ].value <<= uname.c_str() ;
1449
1450                 myObjComponent->setProperties( dict ) ;
1451               }
1452               catch( ... ) {
1453                 cdebug << "DynInvoke setProperties catched ERROR" << endl ;
1454                 Err = true ;
1455               }
1456             }
1457             if ( !Err && IsComputingNode() ) {
1458               cdebug << ThreadNo() << " !ObjInterface " << Name()
1459                      << " IsComputingNode DynInvoke"  << endl ;
1460               cdebug << ServiceInParameter().length()-1 << " input parameters and "
1461                      << ServiceOutParameter().length() << " output parameters" << endl ;
1462               IsLoading( false ) ;
1463               DynInvoke( myObjComponent,
1464                          ServiceName() ,
1465                          &InParametersList[1] , ServiceInParameter().length()-1 ,
1466                          &OutParametersList[0] , ServiceOutParameter().length() ) ;
1467             }
1468             else if ( !Err &&IsFactoryNode() ) {
1469               cdebug << ThreadNo() << " !ObjInterface " << Name()
1470                      << " IsFactoryNode DynInvoke"  << endl ;
1471               cdebug << ServiceInParameter().length() << " input parameters and "
1472                      << ServiceOutParameter().length() << " output parameters" << endl ;
1473               IsLoading( false ) ;
1474               DynInvoke( myObjComponent,
1475                          ServiceName() ,
1476                          &InParametersList[0] , ServiceInParameter().length() ,
1477                          &OutParametersList[0] , ServiceOutParameter().length() ) ;
1478             }
1479 //            cdebug << ThreadNo() << " Component::CpuUsed " << Name() << " "
1480 //                   << myObjComponent->CpuUsed_impl() << endl ;
1481           }
1482           catch( ... ) {
1483             Err = true ;
1484             cdebug << ThreadNo() << " !ObjInterface " << Name()
1485                    << " Node(Component) Dynamic Call Exception catched ERROR"
1486                    << endl ;
1487 //Reset of _ThreadId in the Container ...
1488             myObjComponent->Kill_impl() ;
1489           }
1490         }
1491       }
1492     }
1493   }
1494 //  else {
1495 //    sleep( 1 ) ;
1496 //  }
1497
1498 //  ostringstream astr ;
1499 //  astr << "Graph " << _OutNode->Graph()->Name() << " Node " << Name() << " is done : "
1500 //       << Automaton()->StateName( State() ) ;
1501 //  _OutNode->Graph()->ObjImpl()->sendMessage( NOTIF_STEP, astr.str().c_str() ) ;
1502   if ( Err ) {
1503     if ( ControlState() == SUPERV::ToKillState ||
1504          ControlState() == SUPERV::ToKillDoneState ||
1505          ControlState() == SUPERV::ToStopState ) {
1506       PortState = SUPERV::ErrorState ;
1507       NewState = GraphExecutor::KilledState ;
1508       NewEvent = GraphExecutor::KillEvent ;
1509     }
1510     else {
1511       PortState = SUPERV::ErrorState ;
1512       NewState = GraphExecutor::ErroredState ;
1513       NewEvent = GraphExecutor::ErrorEvent ;
1514     }
1515   }
1516   else {
1517     PortState = SUPERV::ReadyState ;
1518     NewState = GraphExecutor::DataReadyState ;
1519     NewEvent = GraphExecutor::SuccessEvent ;
1520   }
1521
1522   if ( !IsMacroNode() ) {
1523     bool ErrOut = OutParametersSet( Err , PortState , nOutParams , OutParametersList ) ;
1524     if ( !ErrOut ) {
1525       NewEvent = GraphExecutor::ErrorEvent ;
1526     }
1527     delete [] InParametersList ;
1528     delete [] OutParametersList ;
1529   }
1530           
1531   if ( !IsMacroNode() ) {              
1532     SendEvent( NewEvent ) ;
1533   }
1534   else {
1535     GraphExecutor::DataFlow * aMacroGraph = GraphMacroNode()->CoupledNode()->GraphEditor()->Executor() ;
1536     cdebug << ThreadNo() << " DataReady_ExecuteAction " << aMacroGraph << " "
1537            << aMacroGraph->Graph()->Name() << " ->DoneWait()"
1538            << " State " << aMacroGraph->State() << endl;
1539     aMacroGraph->DoneWait() ;
1540     cdebug << ThreadNo() << " DataReady_ExecuteAction " << Name() << " State " << aMacroGraph->State() << endl;
1541     if ( aMacroGraph->State() == SUPERV::DoneState ) {
1542       PortState = SUPERV::ReadyState ;
1543       NewState = GraphExecutor::DataReadyState ;
1544       NewEvent = GraphExecutor::SuccessEvent ;
1545     }
1546     else {
1547       Err = true ;
1548       if ( ControlState() == SUPERV::ToKillState ||
1549            ControlState() == SUPERV::ToKillDoneState ||
1550            ControlState() == SUPERV::ToStopState ) {
1551         PortState = SUPERV::ErrorState ;
1552         NewState = GraphExecutor::KilledState ;
1553         NewEvent = GraphExecutor::KillEvent ;
1554       }
1555       else {
1556         PortState = SUPERV::ErrorState ;
1557         NewState = GraphExecutor::ErroredState ;
1558         NewEvent = GraphExecutor::ErrorEvent ;
1559       }
1560     }
1561     bool ErrOut = OutParametersSet( Err , PortState , nOutParams , OutParametersList ) ;
1562     if ( !ErrOut ) {
1563       NewEvent = GraphExecutor::ErrorEvent ;
1564     }
1565     delete [] InParametersList ;
1566     delete [] OutParametersList ;
1567     SendEvent( NewEvent ) ;
1568   }
1569
1570 //  cdebug << ThreadNo() << " <-- DataReady_ExecuteAction " << Name() << endl;
1571   return 1 ;
1572 }
1573
1574 int GraphExecutor::InNode::Executing_SuspendAction() {
1575   _OutNode->PushEvent( this , GraphExecutor::SuspendedExecutingEvent ,
1576                        GraphExecutor::SuspendedExecutingState ) ; 
1577   cdebug << ThreadNo() << " Executing_SuspendAction " << Name() << endl;
1578   return 1 ;
1579 }
1580
1581 int GraphExecutor::InNode::SuspendedExecuting_ResumeAction() {
1582   cdebug << ThreadNo() << " SuspendedExecuting_ResumeAction " << Name() << endl;
1583   GraphExecutor::AutomatonState next_state ;
1584   next_state = Automaton()->NextState( State() , GraphExecutor::ExecutingEvent ) ;
1585   _OutNode->NewThread() ; // Only for Threads count
1586   _OutNode->PushEvent( this , GraphExecutor::ResumedExecutingEvent ,
1587                        next_state ) ; 
1588   State( next_state ) ;
1589   return 1 ;
1590 }
1591
1592 int GraphExecutor::InNode::Executing_KillAction() {
1593   cdebug << ThreadNo() << " Executing_KillAction " << Name() << " Thread " << ThreadNo()<< endl;
1594   int RetVal = 0 ;
1595   if ( pthread_self() == ThreadNo() ) {
1596     cdebug << "Executing_KillAction would pthread_canceled itself" << endl ;
1597     KillAction() ;
1598     _OutNode->PushEvent( this , GraphExecutor::KilledExecutingEvent ,
1599                          GraphExecutor::KilledExecutingState ) ; 
1600     RetVal = 1 ;
1601   }
1602   else if ( pthread_cancel( ThreadNo() ) ) {
1603     perror("Executing_KillAction pthread_cancel error") ;
1604   }
1605   else {
1606     cdebug << pthread_self() << " Executing_KillAction : ThreadId " << ThreadNo()
1607            << " pthread_canceled" << endl ;
1608     KillAction() ;
1609     _OutNode->ExitThread( ThreadNo() ) ;
1610     _OutNode->PushEvent( this , GraphExecutor::KilledExecutingEvent ,
1611                          GraphExecutor::KilledExecutingState ) ; 
1612   }
1613   return RetVal ;
1614 }
1615
1616 int GraphExecutor::InNode::Executing_StopAction() {
1617   cdebug << ThreadNo() << " Executing_StopAction " << Name() << " Thread " << ThreadNo() << endl;
1618   int RetVal = 0 ;
1619   if ( pthread_cancel( ThreadNo() ) ) {
1620     perror("Executing_KillAction pthread_cancel error") ;
1621   }
1622   else {
1623     cdebug << pthread_self() << " Executing_KillAction : ThreadId " << ThreadNo()
1624            << " pthread_canceled" << endl ;
1625     StopAction() ;
1626     _OutNode->ExitThread( ThreadNo() ) ;
1627     _OutNode->PushEvent( this , GraphExecutor::StoppedExecutingEvent ,
1628                          GraphExecutor::StoppedExecutingState ) ; 
1629   }
1630   return RetVal ;
1631 }
1632
1633 int GraphExecutor::InNode::Executing_SuccessAction() {
1634 //  cdebug << ThreadNo() << " --> Executing_SuccessAction " << Name() << endl;
1635   _OutNode->PushEvent( this , GraphExecutor::SuccessedExecutingEvent ,
1636                        GraphExecutor::SuccessedState ) ; 
1637   MESSAGE(pthread_self() << "Executor::InNode::Executing_SuccessAction of " << Name()
1638           << " ControlState " << Automaton()->ControlStateName( ControlState() )
1639           << " AFTER execution ThreadNo " << ThreadNo() ) ;
1640   SUPERV::ControlState aControl = ControlState() ;
1641   switch ( aControl ) {
1642   case SUPERV::VoidState : {
1643     SendEvent( SuccessEvent ) ;
1644     break ;
1645   }
1646   case SUPERV::ToSuspendState : {
1647     SendEvent( SuccessEvent ) ;
1648     break ;
1649   }
1650   case SUPERV::ToSuspendDoneState : {
1651     SendEvent( GraphExecutor::SuspendEvent ) ;
1652     return 1 ;
1653   }
1654   case SUPERV::ToKillState : {
1655     SendEvent( GraphExecutor::KillEvent ) ;
1656     return 1 ;
1657   }
1658   case SUPERV::ToKillDoneState : {
1659     SendEvent( GraphExecutor::KillEvent ) ;
1660     return 1 ;
1661   }
1662   case SUPERV::ToStopState : {
1663     SendEvent( GraphExecutor::StopEvent ) ;
1664     return 1 ;
1665   }
1666   default : {
1667     cdebug << ThreadNo()
1668            << " GraphExecutor::InNodeThreads::Executing_SuccessAction Error Undefined Control : "
1669            << aControl << endl ;
1670     return 0;
1671   }
1672   }
1673 //  cdebug << ThreadNo() << " <-- Executing_SuccessAction "  << Name() << endl;
1674   return 1 ;
1675 }
1676
1677 int GraphExecutor::InNode::Executing_ErrorAction() {
1678   cdebug << ThreadNo() << " --> Executing_ErrorAction " << Name() << endl;
1679   _OutNode->PushEvent( this , GraphExecutor::ErroredExecutingEvent ,
1680                        GraphExecutor::ErroredState ) ; 
1681
1682   SUPERV::ControlState aControl = ControlState() ;
1683   switch ( aControl ) {
1684   case SUPERV::VoidState : {
1685     SendEvent( ErrorEvent ) ;
1686     break ;
1687   }
1688   case SUPERV::ToSuspendState : {
1689     SendEvent( ErrorEvent ) ;
1690     break ;
1691   }
1692   case SUPERV::ToSuspendDoneState : {
1693     SendEvent( GraphExecutor::SuspendEvent ) ;
1694     return 1 ;
1695   }
1696   case SUPERV::ToKillState : {
1697     SendEvent( GraphExecutor::KillEvent ) ;
1698     return 1 ;
1699   }
1700   case SUPERV::ToKillDoneState : {
1701     SendEvent( GraphExecutor::KillEvent ) ;
1702     return 1 ;
1703   }
1704   case SUPERV::ToStopState : {
1705     SendEvent( GraphExecutor::StopEvent ) ;
1706     return 1 ;
1707   }
1708   default : {
1709     cdebug << ThreadNo()
1710            << " GraphExecutor::InNodeThreads::Executing_ErrorAction Error Undefined Control : "
1711            << aControl << endl ;
1712     return 0;
1713   }
1714   }
1715   cdebug << ThreadNo() << " <-- Executing_ErrorAction "  << Name() << endl;
1716   return 1 ;
1717 }
1718
1719 // Set SUPERV::WaitingState to all InPorts 
1720 void GraphExecutor::InNode::SetWaitingStates(GraphExecutor::InNode * EndNode ) {
1721   int i ;
1722   int j ;
1723   bool docdebug = false ;
1724   State( GraphExecutor::DataWaitingState ) ;
1725   for ( i = 0 ; i < GetNodeInPortsSize() ; i++ ) {
1726     GraphBase::InPort * anInPort = GetChangeNodeInPort( i ) ;
1727     if ( anInPort->IsGate() ) { // Loop : Open the doors
1728       GraphBase::OutPort * anOutPort = anInPort->GetOutPort() ;
1729       if ( anOutPort ) {
1730         CORBA::Any * anAny = new CORBA::Any() ;
1731         *anAny <<= (long ) 1 ;
1732         anOutPort->Value( anAny ) ;
1733         anInPort->State( SUPERV::ReadyState ) ;
1734       }
1735     }
1736     else if ( anInPort->State() != SUPERV::WaitingState ) {
1737       if ( !docdebug ) {
1738         cdebug << ThreadNo()
1739                << " --> GraphExecutor::InNodeThreads::SetWaitingStates " << Name() << endl;
1740         docdebug = true ;
1741       }
1742       if ( !anInPort->IsDataStream() ) {
1743         anInPort->State( SUPERV::WaitingState ) ;
1744       }
1745     }
1746   }
1747   for ( i = 0 ; i < GetNodeOutPortsSize() ; i++ ) {
1748     GraphBase::OutPort * anOutPort = GetChangeNodeOutPort( i ) ;
1749     for ( j = 0 ; j < anOutPort->InPortsSize() ; j++ ) {
1750       if ( !( IsGOTONode() && anOutPort->IsGate() ) &&
1751            !( IsEndLoopNode() && ( anOutPort->IsGate() ||
1752               anOutPort->IsLoop() ) ) &&
1753            !anOutPort->IsDataStream() &&
1754            !anOutPort->ChangeInPorts( j )->IsDataStream() &&
1755            !anOutPort->ChangeInPorts( j )->IsExternConnected() ) {
1756         cdebug << ThreadNo()
1757                << " InNodeThreads::SetWaitingStates OutPort "
1758                << Name() << "/" << anOutPort->ChangeInPorts( j )->NodeName() << "( "
1759                << anOutPort->PortName() << " " << anOutPort->PortStatus() << " ) --> InPort "
1760                << anOutPort->ChangeInPorts( j )->NodeName() << "( "
1761                << anOutPort->ChangeInPorts( j )->PortName() << " "
1762                << anOutPort->ChangeInPorts( j )->PortStatus() << " )" << endl;
1763         if ( strcmp( anOutPort->ChangeInPorts( j )->GetOutPort()->NodeName() , Name() ) ) {
1764 // After EndLoopNode or GOTONode the Input Ports of LoopNode or LabelNode have their values from
1765 // EndLoopNode or GOTONode. But if there is several nested loops we should re-establish.
1766           cdebug << ThreadNo()
1767                  << " InNodeThreads::SetWaitingStates OutPort->ChangeInPorts( j )->OutPort()->NodeName "
1768                  << anOutPort->ChangeInPorts( j )->GetOutPort()->NodeName() << " != "
1769                  << Name() << " : Restored to " << anOutPort->NodeName() << "( "
1770                  << anOutPort->PortName() << " )" << endl ;
1771           anOutPort->ChangeInPorts( j )->ChangeOutPort( anOutPort ) ;
1772         }
1773         GraphExecutor::InNode * aNode = (GraphExecutor::InNode * ) _OutNode->Graph()->GetChangeGraphNode( anOutPort->ChangeInPorts( j )->NodeName() )->GetInNode() ;
1774         if ( aNode != EndNode ) {
1775           aNode->SetWaitingStates( EndNode ) ;
1776         }
1777       }
1778     }
1779   }
1780 }
1781
1782 int GraphExecutor::InNode::Successed_SuccessAction() {
1783   cdebug << ThreadNo() << " --> Successed_SuccessAction "  << Name() << endl;
1784   int res = 1;
1785   int linkednodesnumber = LinkedNodesSize() ;
1786   GraphExecutor::InNode *firstzeroNode = NULL ;
1787   GraphExecutor::InNode *firsttoNode = NULL ;
1788   GraphExecutor::InNode *toNode ;
1789   int i ;
1790   int j ;
1791   list<GraphExecutor::InNode *> SomeDataNodes ;
1792
1793   DoneAction() ;
1794
1795   if ( IsMacroNode() ) {
1796       cdebug << ThreadNo() << " Successed_SuccessAction " << Name() << " LinkedNodes->SomeDataReady already done"
1797              << endl ;
1798     return 1;
1799   }
1800
1801   if ( IsGOTONode() ||
1802        ( IsEndLoopNode() && GetNodeInLoop()->GetOutPort()->BoolValue() ) ) {
1803     cdebug << ThreadNo() << " Successed_SuccessAction " << Name()
1804            << " SetWaitingStates " << endl ;
1805     const GraphBase::OutPort * aGateOutPort ;
1806     if ( IsGOTONode() ) {
1807       aGateOutPort = GetNodeOutGate() ;
1808     }
1809     else {
1810       aGateOutPort = GetNodeOutLoop() ;
1811     }
1812     for ( i = 0 ; i < aGateOutPort->InPortsSize() ; i++ ) {
1813       const GraphBase::InPort * anInPort = aGateOutPort->InPorts( i ) ;
1814       GraphExecutor::InNode * aLabelNode = (GraphExecutor::InNode *) _OutNode->Graph()->GetChangeGraphNode( anInPort->NodeName() )->GetInNode() ;
1815       cdebug << ThreadNo() << " Successed_SuccessAction " << Name() << " will Loop to HeadNode "
1816              << aLabelNode->Name() << " from port " << anInPort->PortName() << endl ;
1817       aLabelNode->SetWaitingStates( this ) ;
1818       for ( j = 0 ; j < aLabelNode->GetNodeInPortsSize() ; j++ ) {
1819         const GraphBase::InPort * anInPort = aLabelNode->GetNodeInPort( j ) ;
1820         if ( anInPort->GetOutPort() ) {
1821           cdebug << aLabelNode->Name() << "(" << anInPort->PortName() << ") value : "
1822                  << anInPort->GetOutPort()->NodeName() << "(" << anInPort->GetOutPort()->PortName() << ")"
1823                  << endl ;
1824         }
1825       }
1826       for ( j = 0 ; j < GetNodeOutPortsSize() ; j++ ) {
1827         GraphBase::OutPort * aBusParamOutPort = GetChangeNodeOutPort( j ) ;
1828         if ( !aBusParamOutPort->IsGate() ) {
1829           GraphBase::InPort * aBusParamChangeInPort = NULL ;
1830           if ( aBusParamOutPort->IsLoop() ) {
1831             aBusParamChangeInPort = aLabelNode->GetChangeNodeInLoop() ;
1832           }
1833           else {
1834             aBusParamChangeInPort = aLabelNode->GetChangeInPort( aBusParamOutPort->PortName() ) ;
1835           }
1836           if ( aBusParamChangeInPort ) {
1837             aBusParamChangeInPort->ChangeOutPort( aBusParamOutPort ) ;
1838             cdebug << ThreadNo() << " Successed_SuccessAction " << Name() << " ChangeOutPort to HeadNode "
1839                    << aLabelNode->Name() << "(" << aBusParamChangeInPort->PortName() << ") from port "
1840                    << aBusParamOutPort->PortName() << endl ;
1841             if ( !aLabelNode->IsLockedDataWait() ) {
1842               res = aLabelNode->SendSomeDataReady( Name() ) ;
1843               if ( res ) {
1844                 if ( firsttoNode == NULL &&
1845                      aLabelNode->ThreadNo() == pthread_self() ) {
1846                   firsttoNode = aLabelNode ;
1847                   cdebug << ThreadNo() << " Successed_SuccessAction firsttoNode "
1848                          << aLabelNode->Name() << endl ;
1849                 }
1850                 else if ( firstzeroNode == NULL &&
1851                           aLabelNode->ThreadNo() == 0 ) {
1852                   firstzeroNode = aLabelNode ;
1853                 }
1854                 else {
1855                   SomeDataNodes.push_back( aLabelNode ) ;
1856                   cdebug << ThreadNo() << " Successed_SuccessAction " << Name() << " push "
1857                          << aLabelNode->Name() << " " << SomeDataNodes.size() 
1858                          << endl ;
1859                 }
1860               }
1861             }
1862             else {
1863               cdebug << ThreadNo()
1864                      << " Successed_SuccessAction Loop to HeadNode "
1865                      << aLabelNode->Name() << " with datas from " << Name() << "("
1866                      << aBusParamOutPort->PortName() << ") to port "
1867                      << aBusParamChangeInPort->PortName() << endl;
1868             }
1869           }
1870           else {
1871             cdebug << ThreadNo() << " ERROR in Successed_SuccessAction of " << Name()
1872                    << " NO port " << aBusParamOutPort->PortName() << " in "
1873                    << aLabelNode->Name() << endl;
1874           }
1875         }
1876       }
1877       for ( j = 0 ; j < aLabelNode->GetNodeInPortsSize() ; j++ ) {
1878         const GraphBase::InPort * anInPort = aLabelNode->GetNodeInPort( j ) ;
1879         if ( anInPort->GetOutPort() ) {
1880           cdebug << aLabelNode->Name() << "(" << anInPort->PortName() << ") value : "
1881                  << anInPort->GetOutPort()->NodeName() << "(" << anInPort->GetOutPort()->PortName() << ")"
1882                  << endl ;
1883         }
1884       }
1885       const GraphBase::InPort * aGateInPort = aLabelNode->GetNodeInGate() ;
1886       if ( aGateInPort ) {
1887         if ( aGateInPort->GetOutPort() ) {
1888           aGateInPort->GetOutPort()->Value( aGateOutPort->Value() ) ;
1889         }
1890         if ( !aLabelNode->IsLockedDataWait() ) {
1891           res = aLabelNode->SendSomeDataReady( Name() ) ;
1892           if ( res ) {
1893             if ( firsttoNode == NULL &&
1894                  aLabelNode->ThreadNo() == pthread_self() ) {
1895               firsttoNode = aLabelNode ;
1896               cdebug << ThreadNo() << " Successed_SuccessAction firsttoNode "
1897                      << aLabelNode->Name() << endl ;
1898             }
1899             else if ( firstzeroNode == NULL &&
1900                       aLabelNode->ThreadNo() == 0 ) {
1901               firstzeroNode = aLabelNode ;
1902             }
1903             else {
1904               SomeDataNodes.push_back( aLabelNode ) ;
1905               cdebug << ThreadNo() << " Successed_SuccessAction " << Name() << " push "
1906                      << aLabelNode->Name() << " " << SomeDataNodes.size()
1907                      << endl ;
1908             }
1909           }
1910         }
1911       }
1912       else {
1913         cdebug << ThreadNo() << " ERROR in Successed_SuccessAction of " << Name()
1914                << " NO port " << aGateOutPort->PortName() << " in "
1915                << aLabelNode->Name() << endl;
1916       }
1917     }
1918   }
1919
1920   else {
1921     cdebug << ThreadNo() << " Successed_SuccessAction of " << Name()
1922            << " with " << LinkedNodesSize() << " linked nodes :" ;
1923     for ( i = 0 ; i < LinkedNodesSize() ; i++ ) {
1924       if ( LinkedNodes( i )->IsDataFlowNode() ) {
1925         linkednodesnumber -= 1 ;
1926       }
1927       cdebug << " " << LinkedNodes( i )->Name() ;
1928     }
1929     cdebug << endl;
1930     for ( i = 0 ; i < LinkedNodesSize() ; i++ ) {
1931       bool IgnoreForEndLoop = false ;
1932       GraphBase::ComputingNode * aComputingNode ;
1933       aComputingNode = (GraphBase::ComputingNode * ) LinkedNodes( i ) ;
1934       toNode = (GraphExecutor::InNode *) aComputingNode->GetInNode() ;
1935       cdebug << ThreadNo() << " Successed_SuccessAction of " << Name()
1936              << " [" << i << "] " << LinkedNodes( i )->Name() << " toNode " << toNode << " IgnoreForEndLoop "
1937              << IgnoreForEndLoop ;
1938       if ( toNode ) {
1939         cdebug << " " << toNode->Kind() << endl ;
1940       }
1941       if ( toNode && !toNode->IsDataFlowNode() ) {
1942         if ( IsComputingNode() && toNode->IsInLineNode() ) {
1943           GraphBase::InPort * toGateInPort = toNode->GetChangeNodeInGate() ;
1944           toGateInPort->State( SUPERV::ReadyState ) ;
1945           GraphBase::OutPort * GateOutPort = toGateInPort->GetOutPort() ;
1946           if ( GateOutPort ) {
1947             GateOutPort->PortStatus( DataConnected );
1948             GateOutPort->State( SUPERV::ReadyState ) ;
1949             GateOutPort->Done( true ) ;
1950           }
1951         }
1952       }
1953       if ( toNode && IsLoopNode() ) {
1954         GraphBase::OutPort * fromLoopOutPort = GetChangeNodeOutLoop() ;
1955         if ( !fromLoopOutPort->BoolValue() ) { // Ne pas faire la boucle
1956           if ( strcmp( toNode->Name() , CoupledNode()->Name() ) ) {
1957             IgnoreForEndLoop = true ;
1958           }
1959           else { // toNode is the EndLoopNode
1960             GraphBase::InPort * toLoopInPort ;
1961             toLoopInPort = toNode->GetChangeNodeInLoop() ;
1962             if ( toLoopInPort->State() != SUPERV::ReadyState ) {
1963               toLoopInPort->State( SUPERV::ReadyState ) ;
1964             }
1965           }
1966         }
1967       }
1968       else if ( toNode && IsSwitchNode() ) {
1969       }
1970       else if ( toNode && toNode->IsInLineNode() ) {
1971         int j ;
1972         for ( j = 0 ; j < toNode->GetNodeInPortsSize() ; j++ ) {
1973           toNode->GetChangeNodeInPort( j )->InitialOutPort() ;
1974         }
1975       }
1976       if ( toNode && !IgnoreForEndLoop ) {
1977         if ( toNode && toNode->IsLoopNode() ) {
1978           GraphBase::InPort * toLoopInPort = toNode->GetChangeNodeInLoop() ;
1979           toLoopInPort->State( SUPERV::ReadyState ) ;
1980           GraphBase::OutPort * LoopOutPort = toLoopInPort->GetOutPort() ;
1981           LoopOutPort->PortStatus( DataConnected );
1982           LoopOutPort->State( SUPERV::ReadyState ) ;
1983           LoopOutPort->Done( true ) ;
1984           CORBA::Any * anAny = new CORBA::Any() ;
1985           *anAny <<= (long ) 1 ;
1986           LoopOutPort->Value( anAny ) ;
1987           int j ;
1988           for ( j = 0 ; j < toNode->GetNodeInPortsSize() ; j++ ) {
1989             toNode->GetChangeNodeInPort( j )->InitialOutPort() ;
1990           }
1991         }
1992         cdebug << ThreadNo() << " Successed_SuccessAction " << toNode->Name() << "->SendSomeDataReady( "
1993                << Name() << " )" << endl ;
1994         res = toNode->SendSomeDataReady( Name() ) ;
1995         if ( res ) {
1996           if ( firsttoNode == NULL &&
1997                toNode->ThreadNo() == pthread_self() ) {
1998             firsttoNode = toNode ;
1999             cdebug << ThreadNo() << " Successed_SuccessAction firsttoNode "
2000                    << toNode->Name() << endl ;
2001           }
2002           else if ( firstzeroNode == NULL &&
2003                     toNode->ThreadNo() == 0 ) {
2004             firstzeroNode = toNode ;
2005           }
2006           else {
2007             SomeDataNodes.push_back( toNode ) ;
2008             cdebug << ThreadNo() << " Successed_SuccessAction " << Name() << " push "
2009                    << toNode->Name() << " " << SomeDataNodes.size() << endl ;
2010           }
2011         }
2012       }
2013     }
2014   }
2015
2016   if ( firsttoNode == NULL && firstzeroNode ) {
2017     firsttoNode = firstzeroNode ;
2018     cdebug << ThreadNo()
2019            << " Successed_SuccessAction firsttoNode = firstzeroNode "
2020            << endl ;
2021   }
2022   else if ( firsttoNode && firstzeroNode ) {
2023     SomeDataNodes.push_back( firstzeroNode ) ;
2024     cdebug << ThreadNo() << " Successed_SuccessAction " << Name() << " push firstzeroNode "
2025            << firstzeroNode->Name() << " " << SomeDataNodes.size() << endl ;
2026   }
2027   else {
2028     cdebug << ThreadNo() << " Successed_SuccessAction " << Name() << " firsttoNode " << firsttoNode
2029            << " firstzeroNode " << firstzeroNode << endl ;
2030   }
2031
2032   while ( SomeDataNodes.size() ) {
2033     GraphExecutor::InNode *aNode = SomeDataNodes.front() ;
2034     SomeDataNodes.pop_front() ;
2035 //    cdebug << pthread_self() << "/" << ThreadNo()
2036 //           << " Successed_SuccessAction pop "
2037 //           << SomeDataNodes.size() << " " << aNode->Name() << endl ;
2038     if ( aNode->State() == GraphExecutor::DataReadyState ) {
2039       aNode->CreateNewThreadIf( true ) ;
2040       aNode->UnLockDataWait() ;
2041       res = aNode->DataUndef_AllDataReadyAction() ;
2042     }
2043     else {
2044 //      cdebug << pthread_self() << "/" << ThreadNo() << " ERROR "
2045 //             << aNode->Name() << " "
2046 //             << Automaton()->StateName( aNode->State() ) << endl ;
2047     }
2048   }
2049
2050   if ( firsttoNode ) {
2051 //    cdebug << pthread_self() << "/" << ThreadNo()
2052 //           << " Successed_SuccessAction start firsttoNode "
2053 //           << SomeDataNodes.size() << " " << firsttoNode->Name() << endl ;
2054     firsttoNode->CreateNewThreadIf( false ) ;
2055     firsttoNode->RewindStack( RewindStack() ) ;
2056     if ( firsttoNode->State() == GraphExecutor::SuccessedState ) {
2057 //      cdebug << pthread_self() << "/" << ThreadNo() << " " << Name()
2058 //             << " : " << firsttoNode->Name() << " "
2059 //             << Automaton()->StateName( firsttoNode->State() )
2060 //             << " --> DataWaitingState for Thread "
2061 //             << firsttoNode->ThreadNo() << endl ;
2062       firsttoNode->State( GraphExecutor::DataWaitingState ) ;
2063     }
2064 //    pthread_t OldT = firsttoNode->ThreadNo() ;
2065     firsttoNode->ThreadNo( pthread_self() ) ;
2066 // On continue avec le meme thread
2067 //    cdebug << pthread_self() << "/" << ThreadNo() << " firsttoNode "
2068 //           << firsttoNode->Name() << "Thread(" << OldT << "-->"
2069 //           << firsttoNode->ThreadNo() << ")" << endl ;
2070     ThreadNo( 0 ) ;
2071 //    cdebug << ThreadNo() << " Successed_SuccessAction " << Name()
2072 //           << " for " << firsttoNode->Name()
2073 //           << " !firsttoNode->CreateNewThreadIf() "
2074 //           << !firsttoNode->CreateNewThreadIf()
2075 //           << " " << Automaton()->StateName( firsttoNode->State() ) ;
2076     if ( firsttoNode->State() == GraphExecutor::DataReadyState ) {
2077       cdebug << endl ;
2078       firsttoNode->UnLockDataWait() ;
2079       res = firsttoNode->DataUndef_AllDataReadyAction() ;
2080     }
2081     else {
2082       cdebug << " ERROR " << endl ;
2083     }
2084   }
2085   else {
2086 //    cdebug << ThreadNo() << " Successed_SuccessAction " << Name()
2087 //           << " NO DataReady ==> ThreadNo( 0 ) firsttoNode == NULL LINKEDnodesnumber " << linkednodesnumber << endl ;
2088     ThreadNo( 0 ) ;
2089   }
2090
2091 //  if ( linkednodesnumber == 0 && firsttoNode == NULL ) {
2092 //    cdebug << ThreadNo() << " Successed_SuccessAction " << Name() << " LinkedNodesSize " << LinkedNodesSize()
2093 //           << " firsttoNode == NULL LINKEDnodesnumber " << linkednodesnumber << " CHECK" << endl ;
2094 //    _OutNode->CheckAllDone() ;
2095 //  }
2096
2097 //  cdebug << pthread_self() << "/" << ThreadNo()
2098 //         << " <-- Successed_SuccessAction " << Name() << " linkednodesnumber "
2099 //         << linkednodesnumber << endl;
2100   return 1 ;
2101 }
2102
2103 bool GraphExecutor::InNode::SendSomeDataReady( char * FromNodeName ) {
2104   bool RetVal = false ;
2105   if ( IsDataFlowNode() ) {
2106     cdebug << ThreadNo() << " ----> " << Name()
2107          << " send Result to graph " << Name() << endl;
2108   }
2109   else {
2110 //    cdebug << pthread_self() << "/" << ThreadNo() << " ----> " << FromNodeName
2111 //           << " send SomeDataReady to " << Name() << " "
2112 //           << Automaton()->StateName( State() ) 
2113 //           << " CreateNewThreadIf() " << CreateNewThreadIf()
2114 //           << " LockedDataWait " << IsLockedDataWait() << endl;
2115 #if 0
2116   //cout << pthread_self() << "/" << ThreadNo() << " ----> " << FromNodeName
2117          << " send SomeDataReady to " << Name() << " "
2118          << Automaton()->StateName( State() ) 
2119          << " CreateNewThreadIf() " << CreateNewThreadIf()
2120          << " LockedDataWait " << IsLockedDataWait() << endl;
2121 #endif
2122     if ( State() == GraphExecutor::SuccessedState ||
2123          State() == GraphExecutor::SuspendedSuccessedState ||
2124          State() == GraphExecutor::SuspendedSuccessedToReStartState ) {
2125 //      cdebug << ThreadNo() << " " << FromNodeName
2126 //             << " : " << Name() << " " << Automaton()->StateName( State() )
2127 //             << " --> DataWaitingState for Thread "
2128 //             << ThreadNo() << " " << endl ;
2129       State( GraphExecutor::DataWaitingState ) ;
2130     }
2131     LockDataWait() ;
2132     DataFromNode( FromNodeName ) ;
2133     RetVal = !SendEvent( GraphExecutor::SomeDataReadyEvent );
2134     if ( !RetVal ) {
2135       UnLockDataWait() ;
2136     }
2137   }
2138   return RetVal ;
2139 }
2140
2141 int GraphExecutor::InNode::Errored_ErrorAction() {
2142   cdebug << ThreadNo() << " Errored_ErrorAction " << Name()
2143          << " will pthread_exit" << endl;
2144   DoneAction() ;
2145   return 1 ;
2146 }
2147
2148 int GraphExecutor::InNode::Successed_SuspendAction() {
2149   cdebug << ThreadNo() << " Successed_SuspendAction -->Suspend " << Name()
2150          << " Threads " << _OutNode->Threads() << " SuspendedThreads "
2151          << _OutNode->SuspendedThreads() << endl;
2152   _OutNode->PushEvent( this , GraphExecutor::SuspendedSuccessedEvent ,
2153                        GraphExecutor::SuspendedSuccessedState ) ; 
2154   DoneAction() ;
2155   GraphExecutor::InNode * aReStartNode = SuspendAction() ;
2156   cdebug << ThreadNo() << " Successed_SuspendAction Resumed " << Name() ;
2157   if ( aReStartNode ) {
2158     _aReStartNode = NULL ;
2159     cdebug << " for " << aReStartNode->Name() << endl;
2160     aReStartNode->SendEvent( _aReStartEvent ) ;
2161   }
2162   else {
2163     cdebug << endl;
2164     SendEvent( GraphExecutor::ResumeEvent ) ;
2165   }
2166   return 1 ;
2167 }
2168
2169 int GraphExecutor::InNode::Errored_SuspendAction() {
2170   cdebug << ThreadNo() << " Errored_SuspendAction -->Suspend " << Name()
2171          << " Threads " << _OutNode->Threads() << " SuspendedThreads "
2172          << _OutNode->SuspendedThreads() << endl;
2173   _OutNode->PushEvent( this , GraphExecutor::SuspendedErroredEvent ,
2174                        GraphExecutor::SuspendedErroredState ) ; 
2175   DoneAction() ;
2176   GraphExecutor::InNode * aReStartNode = SuspendAction() ;
2177   cdebug << ThreadNo() << " Errored_SuspendAction Resumed " << Name()
2178          << endl;
2179   if ( aReStartNode ) {
2180     _aReStartNode = NULL ;
2181     aReStartNode->SendEvent( _aReStartEvent ) ;
2182   }
2183   else {
2184     SendEvent( GraphExecutor::ResumeEvent ) ;
2185   }
2186   return 1 ;
2187 }
2188
2189 int GraphExecutor::InNode::SuspendedSuccessed_ResumeAction() {
2190   cdebug << ThreadNo() << " SuspendedSuccessed_ResumeAction " << Name() << endl;
2191 //  ResumeAction() ;
2192   _OutNode->PushEvent( this , GraphExecutor::ResumedSuccessedEvent ,
2193                        GraphExecutor::ResumedSuccessedState ) ; 
2194   SendEvent( ResumedSuccessedEvent ) ;
2195   return 1 ;
2196 }
2197
2198 int GraphExecutor::InNode::SuspendedErrored_ResumeAction() {
2199   cdebug << ThreadNo() << " SuspendedErrored_ResumeAction " << Name() << endl;
2200 //  ResumeAction() ;
2201   _OutNode->PushEvent( this , GraphExecutor::ResumedErroredEvent ,
2202                        GraphExecutor::ResumedErroredState ) ; 
2203   SendEvent( ResumedErroredEvent ) ;
2204   return 1 ;
2205 }
2206
2207 int GraphExecutor::InNode::Successed_KillAction() {
2208   KillAction() ;
2209   _OutNode->PushEvent( this , GraphExecutor::KilledEvent ,
2210                        GraphExecutor::KilledSuccessedState ) ; 
2211   cdebug << ThreadNo() << " Successed_KillAction " << Name() << endl;
2212   return 1 ;
2213 }
2214
2215 int GraphExecutor::InNode::Errored_KillAction() {
2216   KillAction() ;
2217   _OutNode->PushEvent( this , GraphExecutor::KilledEvent ,
2218                        GraphExecutor::KilledErroredState ) ; 
2219   cdebug << ThreadNo() << " Errored_KillAction " << Name() << endl;
2220   return 1 ;
2221 }
2222
2223 int GraphExecutor::InNode::Successed_StopAction() {
2224   StopAction() ;
2225   _OutNode->PushEvent( this , GraphExecutor::StoppedEvent ,
2226                        GraphExecutor::StoppedSuccessedState ) ; 
2227   cdebug << ThreadNo() << " Successed_StopAction " << Name() << endl;
2228   return 1 ;
2229 }
2230
2231 int GraphExecutor::InNode::Errored_StopAction() {
2232   StopAction() ;
2233   _OutNode->PushEvent( this , GraphExecutor::StoppedEvent ,
2234                        GraphExecutor::StoppedErroredState ) ; 
2235   cdebug << ThreadNo() << " Errored_StopAction " << Name() << endl;
2236   return 1 ;
2237 }
2238
2239 int GraphExecutor::InNode::SuspendedSuccessed_ReStartAction() {
2240   cdebug << ThreadNo() << " SuspendedSuccessed_ReStartAction " << Name() << endl;
2241   _OutNode->PushEvent( this , GraphExecutor::ReStartedEvent ,
2242                        GraphExecutor::ReStartedState ) ;
2243   int i ;
2244   for ( i = 0 ; i < GetNodeInPortsSize() ; i++ ) {
2245     GetChangeNodeInPort( i )->State( SUPERV::ReadyState ) ;
2246   }
2247   SendEvent( ExecuteEvent ) ;
2248   cdebug << ThreadNo() << " SuspendedSuccessed_ReStartAction "  << Name() << endl;
2249   return 1 ;
2250 }
2251
2252 int GraphExecutor::InNode::SuspendedErrored_ReStartAction() {
2253   cdebug << ThreadNo() << " SuspendedErrored_ReStartAction " << Name() << endl;
2254   _OutNode->PushEvent( this , GraphExecutor::ReStartedEvent ,
2255                        GraphExecutor::ReStartedState ) ; 
2256   int i ;
2257   for ( i = 0 ; i < GetNodeInPortsSize() ; i++ ) {
2258     GetChangeNodeInPort( i )->State( SUPERV::ReadyState ) ;
2259   }
2260   SendEvent( ExecuteEvent ) ;
2261   cdebug << ThreadNo() << " SuspendedErrored_ReStartAction "  << Name() << endl;
2262   return 1 ;
2263 }
2264
2265 int GraphExecutor::InNode::SuspendedSuccessed_ReStartAndSuspendAction() {
2266   cdebug << ThreadNo() << " SuspendedSuccessed_ReStartAndSuspendAction " << Name()
2267          << endl;
2268   _OutNode->PushEvent( this , GraphExecutor::ReStartedAndSuspendEvent ,
2269                        GraphExecutor::ReStartedState ) ; 
2270   State( GraphExecutor::DataWaitingState ) ;
2271   if ( !Suspend() ) {
2272     cdebug << "InNode::Suspend() Node " << Name() << endl ;
2273     return false ;
2274   }
2275   else if ( SendEvent( GraphExecutor::SomeDataReadyEvent ) ) {
2276     cdebug << "InNode::SendEvent( SomeDataReadyEvent ) Node "
2277            << Name() << endl ;
2278     return false ;
2279   }
2280   cdebug << ThreadNo() << " SuspendedSuccessed_ReStartAndSuspendAction "  << Name()
2281          << endl;
2282   return 1 ;
2283 }
2284
2285 int GraphExecutor::InNode::SuspendedErrored_ReStartAndSuspendAction() {
2286   cdebug << ThreadNo() << " SuspendedErrored_ReStartAndSuspendAction " << Name()
2287          << endl;
2288   _OutNode->PushEvent( this , GraphExecutor::ReStartedAndSuspendEvent ,
2289                        GraphExecutor::ReStartedState ) ; 
2290   State( GraphExecutor::DataWaitingState ) ;
2291   if ( !Suspend() ) {
2292     cdebug << "InNode::Suspend() Node " << Name() << endl ;
2293     return false ;
2294   }
2295   else if ( SendEvent( GraphExecutor::SomeDataReadyEvent ) ) {
2296     cdebug << "InNode::SendEvent( SomeDataReadyEvent ) Node "
2297            << Name() << endl ;
2298     return false ;
2299   }
2300   cdebug << ThreadNo() << " SuspendedErrored_ReStartAndSuspendAction "  << Name()
2301          << endl;
2302   return 1 ;
2303 }
2304
2305 void GraphExecutor::InNode::InParametersSet( bool & Err ,
2306                                              int  nInParams ,
2307                                              ServicesAnyData * InParametersList ) {
2308   int i ;
2309   cdebug << ThreadNo() << " InParametersSet " << Name() << endl ;
2310   for ( i = 0 ; i < nInParams ; i++ ) {
2311     ServicesAnyData D = InParametersList[i];
2312     GraphBase::InPort * anInPort = GetChangeNodeInPort(i) ;
2313     GraphBase::OutPort * theOutPort = anInPort->GetOutPort() ;
2314     if ( anInPort->IsGate() && theOutPort == NULL ) {
2315       cdebug << ThreadNo() << " ArgIn" << i << " " << D.Name << " "
2316              << anInPort->GetServicesParameter().Parametertype
2317              << " is inactive. " << anInPort->Kind() << endl ;
2318     }
2319     else if ( anInPort->State() == SUPERV::ReadyState ) {
2320       if ( anInPort->IsGate() ) {
2321         CORBA::Any * anAny = new CORBA::Any() ;
2322         *anAny <<= (long ) 0 ;
2323         theOutPort->Value( anAny ) ;
2324       }
2325       if ( !anInPort->IsDataStream() ) {
2326         anInPort->State( SUPERV::WaitingState ) ;
2327       }
2328       D.Name = CORBA::string_dup( anInPort->GetServicesParameter().Parametername ) ;
2329       cdebug << ThreadNo() << " ArgIn" << i << " " << anInPort->Kind()
2330              << " " << anInPort->State() ;
2331       cdebug << "      " << D.Name << " " << anInPort->GetServicesParameter().Parametertype << " : " ;
2332       D.Value = *theOutPort->Value() ; // CORBA::Any
2333       string _Type = CORBA::string_dup( anInPort->GetServicesParameter().Parametertype ) ;
2334       const char * Type = _Type.c_str() ;
2335       switch ( D.Value.type()->kind() ) { // { string , long , double , objref }
2336       case CORBA::tk_string:
2337         char * t;
2338         D.Value >>= t;
2339         cdebug << t << " (string)" ;
2340         if ( !strcmp( Type , "string" ) ) {
2341         }
2342         else if ( !strcmp( Type , "boolean" ) ) {
2343           bool b ;
2344           long d ;
2345           sscanf( t , "%ld" , &d ) ;
2346           b = (bool ) d ;
2347           D.Value <<=  (CORBA::Any::from_boolean ) b ;
2348 //          theOutPort->Value( D.Value ) ;
2349         }
2350         else if ( !strcmp( Type , "char" ) ) {
2351           unsigned char c ;
2352           long d ;
2353           sscanf( t , "%ld" , &d ) ;
2354           c = (short ) d ;
2355           D.Value <<=  (CORBA::Any::from_char ) c ;
2356           cdebug << "string '" << t << "' --> " << d << " --> char " << c ;
2357 //          theOutPort->Value( D.Value ) ;
2358         }
2359         else if ( !strcmp( Type , "short" ) ) {
2360           short s ;
2361           long d ;
2362           sscanf( t , "%ld" , &d ) ;
2363           s = (short ) d ;
2364           D.Value <<=  s ;
2365           cdebug << "string '" << t << "' --> " << d << " --> short " << s ;
2366 //          theOutPort->Value( D.Value ) ;
2367         }
2368         else if ( !strcmp( Type , "int" ) || !strcmp( Type , "long" ) ) {
2369           long l ;
2370           sscanf( t , "%ld" , &l ) ;
2371           D.Value <<=  l ;
2372           cdebug << "string '" << t << " --> long " << l ;
2373 //          theOutPort->Value( D.Value ) ;
2374         }
2375         else if ( !strcmp( Type , "float" ) ) {
2376           double d ;
2377           sscanf( t , "%lf" , &d ) ;
2378           float f = d ;
2379           D.Value <<= f ;
2380           cdebug << "string '" << t << "' --> " << setw(25) << setprecision(18) << d << " --> float " << " = "
2381                  << setw(25) << setprecision(18) << f ;
2382 //          theOutPort->Value( D.Value ) ;
2383         }
2384         else if ( !strcmp( Type , "double" ) ) {
2385           double d ;
2386           sscanf( t , "%lf" , &d ) ;
2387           D.Value <<= d ;
2388           cdebug << "string '" << t << " --> double " << setw(25) << setprecision(18) << d ;
2389 //          theOutPort->Value( D.Value ) ;
2390         }
2391 //        else if ( !strcmp( Type , "objref" ) ) {
2392         else { // Default
2393           CORBA::Object_ptr ObjRef ;
2394           try {
2395             ObjRef = StringToObject( t ) ;
2396             D.Value <<= ObjRef ;
2397           }
2398           catch( ... ) {
2399             D.Value <<= CORBA::Object::_nil() ;
2400           }
2401 //          theOutPort->Value( D.Value ) ;
2402         }
2403 //        else {
2404 //          cdebug << " (other ERROR)" << endl ;
2405 //        }
2406         cdebug << " --> call_kind " << D.Value.type()->kind() << endl ;
2407         break;
2408       case CORBA::tk_long:
2409         long l;
2410         D.Value >>= l;
2411         cdebug << l << " (long)" << endl ;
2412         if ( !strcmp( Type , "string" ) ) {
2413           char t[40] ;
2414           sprintf( t , "%ld" , l ) ;
2415           D.Value <<= t ;
2416 //          theOutPort->Value( D.Value ) ;
2417         }
2418         else if ( !strcmp( Type , "boolean" ) ) {
2419           bool b ;
2420           b = (bool ) l ;
2421           D.Value <<=  (CORBA::Any::from_boolean ) b ;
2422 //          theOutPort->Value( D.Value ) ;
2423         }
2424         else if ( !strcmp( Type , "char" ) ) {
2425           unsigned char c ;
2426           c = (unsigned char ) l ;
2427           D.Value <<=  (CORBA::Any::from_char ) c ;
2428 //          theOutPort->Value( D.Value ) ;
2429         }
2430         else if ( !strcmp( Type , "short" ) ) {
2431           short s ;
2432           s = (short ) l ;
2433           D.Value <<=  s ;
2434 //          theOutPort->Value( D.Value ) ;
2435         }
2436         else if ( !strcmp( Type , "int" ) || !strcmp( Type , "long" ) ) {
2437         }
2438         else if ( !strcmp( Type , "float" ) ) {
2439           float f ;
2440           f = (float ) l ;
2441           D.Value <<= f ;
2442 //          theOutPort->Value( D.Value ) ;
2443         }
2444         else if ( !strcmp( Type , "double" ) ) {
2445           double d ;
2446           d = (double ) l ;
2447           D.Value <<= d ;
2448 //          theOutPort->Value( D.Value ) ;
2449         }
2450 //        else if ( !strcmp( Type , "objref" ) ) {
2451         else { // Default
2452           D.Value <<= CORBA::Object::_nil() ;
2453 //          theOutPort->Value( D.Value ) ;
2454         }
2455 //        else {
2456 //          cdebug << " (other ERROR)" << endl ;
2457 //        }
2458         cdebug << " --> call_kind " << D.Value.type()->kind() << endl ;
2459         break;
2460       case CORBA::tk_double:
2461         double d;
2462         D.Value >>= d;
2463         cdebug << d << " (double)" << endl ;
2464         if ( !strcmp( Type , "string" ) ) {
2465           char t[40] ;
2466           sprintf( t , "%lf" , d ) ;
2467           D.Value <<= t ;
2468 //          theOutPort->Value( D.Value ) ;
2469         }
2470         else if ( !strcmp( Type , "boolean" ) ) {
2471           bool b ;
2472           b = (bool ) d ;
2473           D.Value <<=  (CORBA::Any::from_boolean ) b ;
2474 //          theOutPort->Value( D.Value ) ;
2475         }
2476         else if ( !strcmp( Type , "char" ) ) {
2477           unsigned char c ;
2478           c = (unsigned char ) d ;
2479           D.Value <<=  (CORBA::Any::from_char ) c ;
2480 //          theOutPort->Value( D.Value ) ;
2481         }
2482         else if ( !strcmp( Type , "short" ) ) {
2483           short s ;
2484           s = (short ) d ;
2485           D.Value <<=  s ;
2486 //          theOutPort->Value( D.Value ) ;
2487         }
2488         else if ( !strcmp( Type , "int" ) || !strcmp( Type , "long" ) ) {
2489           long l ;
2490           l = (long ) d ;
2491           D.Value <<= l ;
2492 //          theOutPort->Value( D.Value ) ;
2493         }
2494         else if ( !strcmp( Type , "float" ) ) {
2495           float f ;
2496           f = (float ) d ;
2497           D.Value <<= f ;
2498 //          theOutPort->Value( D.Value ) ;
2499         }
2500         else if ( !strcmp( Type , "double" ) ) {
2501         }
2502 //        else if ( !strcmp( Type , "objref" ) ) {
2503         else { // Default
2504           D.Value <<= CORBA::Object::_nil() ;
2505 //          theOutPort->Value( D.Value ) ;
2506         }
2507 //        else {
2508 //          cdebug << " (other ERROR)" << endl ;
2509 //        }
2510         cdebug << " --> call_kind " << D.Value.type()->kind() << endl ;
2511         break;
2512       case CORBA::tk_objref:
2513         if ( !strcmp( Type , "string" ) ) {
2514           CORBA::Object_ptr ObjRef ;
2515           char * retstr ;
2516           try {
2517             D.Value >>= ObjRef ;
2518             retstr = ObjectToString( ObjRef ) ;
2519             D.Value <<= retstr ;
2520 //            theOutPort->Value( D.Value ) ;
2521           }
2522           catch( ... ) {
2523             if ( i != 0 ) {
2524               Err = true ;
2525             }
2526             cdebug << "ToString( object ) Catched ERROR" << endl ;
2527           }
2528         }
2529         else if ( !strcmp( Type , "boolean" ) ) {
2530           bool b = 0 ;
2531           D.Value <<=  (CORBA::Any::from_boolean ) b ;
2532 //          theOutPort->Value( D.Value ) ;
2533         }
2534         else if ( !strcmp( Type , "char" ) ) {
2535           unsigned char c = 0 ;
2536           D.Value <<=  (CORBA::Any::from_char ) c ;
2537 //          theOutPort->Value( D.Value ) ;
2538         }
2539         else if ( !strcmp( Type , "short" ) ) {
2540           short s = 0 ;
2541           D.Value <<=  s ;
2542 //          theOutPort->Value( D.Value ) ;
2543         }
2544         else if ( !strcmp( Type , "int" ) || !strcmp( Type , "long" ) ) {
2545           long l = 0 ;
2546           D.Value <<= l ;
2547 //          theOutPort->Value( D.Value ) ;
2548         }
2549         else if ( !strcmp( Type , "float" ) ) {
2550           float f = 0 ;
2551           D.Value <<= f ;
2552 //          theOutPort->Value( D.Value ) ;
2553         }
2554         else if ( !strcmp( Type , "double" ) ) {
2555           double d = 0 ;
2556           D.Value <<= d ;
2557 //          theOutPort->Value( D.Value ) ;
2558         }
2559 //        else if ( !strcmp( Type , "objref" ) ) {
2560         else { // Default
2561           CORBA::Object_ptr obj ;
2562           char * retstr ;
2563           try {
2564             D.Value >>= obj ;
2565             retstr = ObjectToString( obj ) ;
2566             cdebug << retstr << endl ;
2567           }
2568           catch( ... ) {
2569             if ( i != 0 ) {
2570               Err = true ;
2571             }
2572             cdebug << "ToString( object ) Catched ERROR" << endl ;
2573           }
2574         }
2575 //        else {
2576 //          cdebug << " (other ERROR)" << endl ;
2577 //        }
2578         cdebug << " --> call_kind " << D.Value.type()->kind() << endl ;
2579         break;
2580       default:
2581         cdebug << " (other ERROR) " << D.Value.type()->kind() << endl ;
2582       }
2583     }
2584     else {
2585       cdebug << ThreadNo() << " In" << i << " : wrong state ERROR State "
2586              << anInPort->State() << " NameState "
2587              << Automaton()->StateName( anInPort->State() ) << " PortName "
2588              << anInPort->PortName() << " Parametername "
2589              << anInPort->GetServicesParameter().Parametername << endl ;
2590       Err = true ;
2591     }
2592     InParametersList[i] = D ;
2593   }
2594 }
2595
2596 void GraphExecutor::InNode::InOutParametersSet( int nOutParams ,
2597                                                 ServicesAnyData * OutParametersList ) {
2598   int i ;
2599   for ( i = 0 ; i < nOutParams ; i++ ) {
2600     ServicesAnyData D = OutParametersList[i] ;
2601
2602     D.Name = GetChangeNodeOutPort(i)->GetServicesParameter().Parametername;
2603     string _Type = CORBA::string_dup(GetChangeNodeOutPort(i)->GetServicesParameter().Parametertype) ;
2604     const char * Type = _Type.c_str() ;
2605     bool OutDone = GetChangeNodeOutPort(i)->Done() ;
2606     cdebug << ThreadNo() << " ArgOut" << i << " " << D.Name << " Done("
2607            << OutDone << ") " << Type << " : " << endl ;
2608     if ( !strcmp( Type , "string" ) ) {
2609       D.Value <<= (char *) NULL ;
2610     }
2611     else if ( !strcmp( Type , "boolean" ) ) {
2612       bool b = 0 ;
2613       D.Value <<=  (CORBA::Any::from_boolean ) b ;
2614     }
2615     else if ( !strcmp( Type , "char" ) ) {
2616       unsigned char c = 0 ;
2617       D.Value <<=  (CORBA::Any::from_char ) c ;
2618     }
2619     else if ( !strcmp( Type , "short" ) ) {
2620       short s = 0 ;
2621       D.Value <<=  s ;
2622     }
2623     else if ( !strcmp( Type , "int" ) || !strcmp( Type , "long" ) ) {
2624       D.Value <<= (long ) 0 ;
2625     }
2626     else if ( !strcmp( Type , "float" ) ) {
2627       float f = 0 ;
2628       D.Value <<= f ;
2629     }
2630     else if ( !strcmp( Type , "double" ) ) {
2631       double d = 0 ;
2632       D.Value <<= d ;
2633     }
2634     else {
2635       D.Value <<= CORBA::Object::_nil() ;
2636     }
2637 //#if 0
2638     switch (D.Value.type()->kind()) { // { string , long , double , objref }
2639     case CORBA::tk_string:
2640       char * t;
2641       D.Value >>= t;
2642       cdebug << ThreadNo() << " " << t << "(string)" << endl ;
2643       break;
2644     case CORBA::tk_boolean:
2645       bool b ;
2646       D.Value >>= (CORBA::Any::to_boolean ) b;
2647       cdebug << ThreadNo() << " " << b << "(boolean)" << endl ;
2648       break;
2649     case CORBA::tk_char:
2650       unsigned char c ;
2651       D.Value >>= (CORBA::Any::to_char ) c;
2652       cdebug << ThreadNo() << " " << c << "(char)" << endl ;
2653       break;
2654     case CORBA::tk_short:
2655       short s;
2656       D.Value >>= s;
2657       cdebug << ThreadNo() << " " << s << "(short)" << endl ;
2658       break;
2659     case CORBA::tk_long:
2660       long l;
2661       D.Value >>= l;
2662       cdebug << ThreadNo() << " " << l << "(long)" << endl ;
2663       break;
2664     case CORBA::tk_float:
2665       float f;
2666       D.Value >>= f;
2667       cdebug << ThreadNo() << " " << f << "(float)" << endl ;
2668       break;
2669     case CORBA::tk_double:
2670       double d;
2671       D.Value >>= d;
2672       cdebug << ThreadNo() << " " << d << "(double)" << endl ;
2673       break;
2674     case CORBA::tk_objref:
2675       try {
2676         CORBA::Object_ptr obj ;
2677         char * retstr ;
2678         D.Value >>= obj ;
2679         retstr = ObjectToString( obj ) ;
2680         cdebug << ThreadNo() << retstr << endl ;
2681       }
2682       catch( ... ) {
2683         cdebug << "ToString( object ) Catched ERROR" << endl ;
2684       }
2685       break;
2686     default:
2687       cdebug << ThreadNo() << " " << "(other ERROR)" << endl ;
2688     }
2689 //#endif
2690     OutParametersList[i] = D ;
2691   }
2692 }
2693
2694 bool GraphExecutor::InNode::OutParametersSet( bool Err ,
2695                                               SUPERV::GraphState NewState ,
2696                                               int nOutParams ,
2697                                               ServicesAnyData * OutParametersList ) {
2698   bool RetVal = true ;
2699   int i ;
2700   GraphBase::OutPort * aGateOutPort = NULL ;
2701   bool OrSwitch = false ;
2702   cdebug << "OutParametersSet " << Name() << " nOutParams " << nOutParams << " NewState " << NewState << endl ;
2703 //  cout << "OutParametersSet " << Name() << " nOutParams " << nOutParams << " NewState " << NewState << endl ;
2704   if ( nOutParams && !IsMacroNode() ) {
2705     GraphBase::OutPort * anOutPort ;
2706     for ( i = 0 ; i < nOutParams ; i++ ) {
2707       anOutPort = GetChangeNodeOutPort(i) ;
2708       if ( Err ) {
2709         anOutPort->State( NewState ) ;
2710         anOutPort->Done( true ) ;
2711       }
2712       else {
2713         cdebug << ThreadNo() << " " << "Out" << i << " " << Name() << " "
2714                << anOutPort->PortName() << " " << anOutPort->Kind() ;
2715         ServicesAnyData D = OutParametersList[i] ;
2716         switch (D.Value.type()->kind()) { // { string , long , double , objref }
2717         case CORBA::tk_string: {
2718           char * t;
2719           D.Value >>= t;
2720           cdebug << ThreadNo() << " " << t << "(string)" << endl ;
2721           break;
2722         }
2723         case CORBA::tk_boolean: {
2724           bool b ;
2725           D.Value >>= (CORBA::Any::to_boolean ) b;
2726           long l = (long ) b ;
2727           D.Value <<= l ;
2728           cdebug << ThreadNo() << " " << b << "(boolean)" << endl ;
2729           break;
2730         }
2731         case CORBA::tk_char: {
2732           unsigned char c ;
2733           D.Value >>= (CORBA::Any::to_char ) c;
2734           long l = (long ) c ;
2735           D.Value <<= l ;
2736           cdebug << ThreadNo() << " " << c << "(char)" << endl ;
2737           break;
2738         }
2739         case CORBA::tk_short: {
2740           short s;
2741           D.Value >>= s;
2742           long l = (long ) s ;
2743           D.Value <<= l ;
2744           cdebug << ThreadNo() << " " << s << "(short)" << endl ;
2745           break;
2746         }
2747         case CORBA::tk_long: {
2748           long l;
2749           D.Value >>= l;
2750           cdebug << ThreadNo() << " " << l << "(long)" << endl ;
2751           break;
2752         }
2753         case CORBA::tk_float: {
2754           float f;
2755           D.Value >>= f;
2756           double d = (double ) f ;
2757           D.Value <<= d ;
2758           cdebug << ThreadNo() << " " << f << "(float)" << endl ;
2759           break;
2760         }
2761         case CORBA::tk_double: {
2762           double d;
2763           D.Value >>= d;
2764           cdebug << ThreadNo() << " " << d << "(double)" << endl ;
2765           break;
2766         }
2767         case CORBA::tk_objref: {
2768           try {
2769             CORBA::Object_ptr obj ;
2770             char * retstr ;
2771             D.Value >>= obj ;
2772             retstr = ObjectToString( obj ) ;
2773             cdebug << ThreadNo() << retstr << endl ;
2774           }
2775           catch( ... ) {
2776             cdebug << "ToString( object ) Catched ERROR" << endl ;
2777           }
2778           break;
2779         }
2780         default: {
2781           cdebug << ThreadNo() << " " << "(other ERROR)" << endl ;
2782         }
2783         }
2784         OutParametersList[i] = D ;
2785         if ( !anOutPort->IsDataStream() ) {
2786           if ( anOutPort->IsGate() ) {
2787             aGateOutPort = anOutPort ;
2788             cdebug << " Gate " ;
2789             long l = 1;
2790             OutParametersList[i].Value <<= l;
2791             anOutPort->Value( OutParametersList[i].Value );
2792           }
2793           else if ( anOutPort->IsLoop() ) {
2794             cdebug << " Loop " ;
2795             anOutPort->Value( OutParametersList[i].Value );
2796 // InLoop Port of EndLoopNode is ready :
2797             anOutPort->ChangeInPorts(0)->State( SUPERV::ReadyState ) ;
2798           }
2799           else if ( anOutPort->IsSwitch() ) {
2800             cdebug << " Switch " ;
2801             anOutPort->Value( OutParametersList[i].Value );
2802             if ( anOutPort->InPortsSize() && anOutPort->ChangeInPorts( 0 )->IsGate() ) {
2803               if ( OrSwitch && anOutPort->BoolValue() ) {
2804                 cdebug << "GraphExecutor::InNodeThreads::OutParameters more than one switch is true WARNING"
2805                        << endl ;
2806               }
2807               else {
2808                 OrSwitch = OrSwitch | anOutPort->BoolValue() ;
2809               }
2810             }
2811             cdebug << "OrSwitch " << OrSwitch ;
2812           }
2813           else {
2814             cdebug << " Param " ;
2815             anOutPort->Value( OutParametersList[i].Value );
2816           }
2817           anOutPort->State( NewState ) ;
2818           anOutPort->Done( true ) ;
2819         }
2820         int j ;
2821         for ( j = 0 ; j < anOutPort->InPortsSize() ; j++ ) {
2822           bool fromGOTO = false ;
2823           const char * ToNodeName = anOutPort->ChangeInPorts( j )->NodeName() ;
2824           if ( !strcmp( ToNodeName , _OutNode->Graph()->Name() ) && _OutNode->Graph()->GraphMacroLevel() != 0 ) {
2825             cdebug << "OutParametersSet ToNodeName " << _OutNode->Graph()->Name() << " CoupledNode "
2826                    << _OutNode->Graph()->CoupledNodeName() << _OutNode->Graph()->CoupledNode()
2827                    << endl ;
2828             cdebug << " GraphExecutor " << _OutNode->Graph()->CoupledNode()->GraphEditor()->Executor() << endl ;
2829             _OutNode->Graph()->CoupledNode()->GraphEditor()->Executor()->OutputOfAny( _OutNode->Graph()->CoupledNodeName() ,
2830                                                                             anOutPort->ChangeInPorts( j )->PortName() ,
2831                                                                             *anOutPort->Value() ) ;
2832           }
2833           else {
2834             GraphBase::ComputingNode * ToNode = _OutNode->Graph()->GetChangeGraphNode( ToNodeName ) ;
2835             if ( ToNode ) {
2836 //              cout << "OutParametersSet ToNodeName " << ToNodeName << endl ;
2837               cdebug << "OutParametersSet ToNodeName " << ToNodeName << " " << ToNode->Name() << endl ;
2838               GraphBase::OutPort * aGOTOPort = ToNode->GetChangeNodeInGate()->GetOutPort() ;
2839               if ( aGOTOPort ) {
2840                 fromGOTO = aGOTOPort->IsGOTO() ;
2841               }
2842               if ( anOutPort->ChangeInPorts( j )->IsEndSwitch() || fromGOTO ) {
2843                 cdebug << anOutPort->ChangeInPorts( j )->NodeName() << "("
2844                        << anOutPort->ChangeInPorts( j )->PortName() << ","
2845                        << anOutPort->ChangeInPorts( j )->Kind() << ") WILL BE changed from "
2846                        << anOutPort->ChangeInPorts( j )->GetOutPort()->NodeName()
2847                        << "("
2848                        << anOutPort->ChangeInPorts( j )->GetOutPort()->PortName()
2849                        << ") to " << anOutPort->NodeName() << "("
2850                        << anOutPort->PortName() << ")" << endl ;
2851                 anOutPort->ChangeInPorts( j )->ChangeOutPort( anOutPort ) ;
2852               }
2853               else {
2854                 cdebug << anOutPort->ChangeInPorts( j )->NodeName() << "("
2855                        << anOutPort->ChangeInPorts( j )->PortName() << ","
2856                        << anOutPort->ChangeInPorts( j )->Kind() << ") NOT changed from "
2857                        << anOutPort->ChangeInPorts( j )->GetOutPort()->NodeName()
2858                        << "("
2859                        << anOutPort->ChangeInPorts( j )->GetOutPort()->PortName()
2860                        << ") to " << anOutPort->NodeName() << "("
2861                        << anOutPort->PortName() << ")" << endl ;
2862               }
2863             }
2864           }
2865         }
2866 //#if 0
2867         switch (anOutPort->Value()->type()->kind()) {
2868         case CORBA::tk_string:
2869           char * t;
2870           (*anOutPort->Value()) >>= t;
2871           cdebug << ThreadNo() << " Out" << i << " : " << t << "(string)" << endl ;
2872           break;
2873         case CORBA::tk_boolean:
2874           bool b ;
2875           (*anOutPort->Value()) >>= (CORBA::Any::to_boolean ) b;
2876           cdebug << ThreadNo() << " Out" << i << " : " << b << "(boolean)" << endl ;
2877           break;
2878         case CORBA::tk_char:
2879           unsigned char c ;
2880           (*anOutPort->Value()) >>= (CORBA::Any::to_char ) c;
2881           cdebug << ThreadNo() << " Out" << i << " : " << c << "(char)" << endl ;
2882           break;
2883         case CORBA::tk_short:
2884           short s;
2885           (*anOutPort->Value()) >>= s;
2886           cdebug << ThreadNo() << " Out" << i << " : " << s << "(short)" << endl ;
2887           break;
2888         case CORBA::tk_long:
2889           long l;
2890           (*anOutPort->Value()) >>= l;
2891           cdebug << ThreadNo() << " Out" << i << " : " << l << "(long)" << endl ;
2892           break;
2893         case CORBA::tk_float:
2894           float f;
2895           (*anOutPort->Value()) >>= f;
2896           cdebug << ThreadNo() << " Out" << i << " : " << f << "(float)" << endl ;
2897           break;
2898         case CORBA::tk_double:
2899           double d;
2900           (*anOutPort->Value()) >>= d;
2901           cdebug << ThreadNo() << " Out" << i << " : " << d << "(double)" << endl ;
2902           break;
2903         case CORBA::tk_objref:
2904           CORBA::Object_ptr obj ;
2905           char * retstr ;
2906           try {
2907             (*anOutPort->Value()) >>= obj ;
2908             retstr = ObjectToString( obj );
2909             cdebug << ThreadNo() << " Out" << i << " : " << "ToString( object ) "
2910                    << retstr << endl ;
2911           }
2912           catch ( ... ) {
2913             cdebug << ThreadNo() << " Out" << i << " : " << "ToString( object ) "
2914                    << "Catched ERROR" << endl ;
2915           }
2916           break;
2917         default:
2918           cdebug << ThreadNo() << " Out" << i << " : " << "(other ERROR)" << endl ;
2919           RetVal = false ;
2920         }
2921 //#endif
2922       }
2923     }
2924     if ( aGateOutPort && IsSwitchNode() ) {
2925       if ( OrSwitch ) {
2926 //        cdebug << ThreadNo() << " " << "Out0 " << Name() << " Close of "
2927 //               << aGateOutPort->PortName() << " " << aGateOutPort->Kind() ;
2928         long l = 0;
2929         OutParametersList[0].Value <<= l ;
2930         aGateOutPort->Value( OutParametersList[0].Value ) ;
2931       }
2932       else {
2933 //        cdebug << ThreadNo() << " " << "Out0 " << Name() << " Open of "
2934 //               << aGateOutPort->PortName() << " " << aGateOutPort->Kind() ;
2935         long l = 1;
2936         OutParametersList[0].Value <<= l ;
2937         aGateOutPort->Value( OutParametersList[0].Value ) ;
2938         int i ;
2939         for ( i = 0 ; i < GetNodeOutPortsSize() ; i++ ) {
2940           GraphBase::InPort * anInPort ;
2941           anInPort = CoupledNode()->GetChangeInPort( GetNodeOutPort( i )->PortName() ) ;
2942           if ( anInPort ) {
2943             anInPort->ChangeOutPort( GetChangeNodeOutPort( i ) ) ;
2944           }
2945         }
2946       }
2947     }
2948   }
2949   return RetVal ;
2950 }