1 // SUPERV GraphExecutor : contains classes that permit execution of graphs and particularly the execution automaton
3 // Copyright (C) 2003 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
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.
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.
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
20 // See http://www.opencascade.org/SALOME/ or email : webmaster.salome@opencascade.org
24 // File : DataFlowBase_InNodeThreads.cxx
25 // Author : Jean Rahuel, CEA
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
53 #include <SALOMEconfig.h>
54 #include CORBA_CLIENT_HEADER(SALOME_Component)
55 #include "SALOME_LifeCycleCORBA.hxx"
57 #include "DataFlowExecutor_DataFlow.hxx"
58 #include "DataFlowEditor_DataFlow.hxx" // GraphEditor package must be built BEFORE
61 static void UpperCase(std::string& rstr)
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);
69 std::transform(rstr.begin(), rstr.end(), rstr.begin(),towupper);
74 int GraphExecutor::InNode::SendEvent( const GraphExecutor::NodeEvent anEvent ) {
76 _CurrentEvent = (GraphExecutor::NodeEvent ) anEvent ;
77 cdebug << pthread_self() << "/" << ThreadNo() << " -->SendEvent Node " << Name()
79 << Automaton()->ControlStateName( ControlState() )
80 << " Event : " << Automaton()->EventName( anEvent )
81 << " State : " << Automaton()->StateName( State() ) << " _RewindStack " << _RewindStack << endl;
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 ;
92 _NextAction = Automaton()->NextAction( _NextState , anEvent ) ;
95 // State( _NextState ) ;
96 // if ( _OldState == GraphExecutor::SuccessedExecutingState ||
97 // _OldState == GraphExecutor::ErroredExecutingState ) {
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 ;
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 ;
122 int sts = executeAction() ;
124 cdebug << pthread_self() << "/" << ThreadNo() << " <--- SendEvent Node " << Name()
125 << " Event : " << Automaton()->EventName( anEvent )
126 << " State : " << Automaton()->StateName( State() )
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 ") ;
140 cdebug << pthread_self() << "/" << ThreadNo()
141 << "ReadyAction pthread_cond_broadcast _ReadyWait "
143 if ( pthread_cond_broadcast( &_ReadyWait ) ) {
144 perror("Ready pthread_cond_broadcast ") ;
146 if ( pthread_mutex_unlock( &_MutexWait ) ) {
147 perror("Ready pthread_mutex_unlock ") ;
152 void GraphExecutor::InNode::RunningAction() {
153 if ( pthread_mutex_lock( &_MutexWait ) ) {
154 perror("Running pthread_mutex_lock ") ;
157 cdebug << pthread_self() << "/" << ThreadNo()
158 << "RunningAction pthread_cond_broadcast _RunningWait "
160 // That activate the pthread_cond_wait for RunninWait
161 if ( pthread_cond_broadcast( &_RunningWait ) ) {
162 perror("Running pthread_cond_broadcast ") ;
164 if ( pthread_mutex_unlock( &_MutexWait ) ) {
165 perror("Running pthread_mutex_unlock ") ;
170 void GraphExecutor::InNode::DoneAction() {
171 if ( pthread_mutex_lock( &_MutexWait ) ) {
172 perror("Done pthread_mutex_lock ") ;
175 cdebug << pthread_self() << "/" << ThreadNo()
176 << "DoneAction pthread_cond_broadcast _DoneWait "
178 if ( pthread_cond_broadcast( &_DoneWait ) ) {
179 perror("Done pthread_cond_broadcast ") ;
181 if ( pthread_mutex_unlock( &_MutexWait ) ) {
182 perror("Done pthread_mutex_unlock ") ;
187 void GraphExecutor::InNode::SuspendedAction() {
188 if ( pthread_mutex_lock( &_MutexWait ) ) {
189 perror("Suspended pthread_mutex_lock ") ;
192 cdebug << pthread_self() << "/" << ThreadNo()
193 << "SuspendedAction pthread_cond_broadcast _SuspendedWait "
195 if ( pthread_cond_broadcast( &_SuspendedWait ) ) {
196 perror("Suspended pthread_cond_broadcast ") ;
198 if ( pthread_mutex_unlock( &_MutexWait ) ) {
199 perror("Suspended pthread_mutex_unlock ") ;
204 // SuspendAction <--> { ResumeAction - ReStartAction }
205 GraphExecutor::InNode * GraphExecutor::InNode::SuspendAction() {
207 if ( pthread_mutex_lock( &_MutexWait ) ) {
208 perror("Suspend pthread_mutex_lock ") ;
211 if ( !_SuspendSync ) {
212 cdebug << pthread_self() << "/" << ThreadNo() << " pthread_cond " << Name()
213 << " SuspendAction pthread_cond_wait _SuspendWait "
214 << Automaton()->StateName( State() ) << endl ;
215 _SuspendSync = true ;
216 _OutNode->SuspendThread() ;
217 if ( pthread_cond_wait( &_SuspendWait , &_MutexWait ) ) {
218 perror("SuspendAction pthread_cond_wait ") ;
220 _OutNode->ResumeThread() ;
221 cdebug << pthread_self() << "/" << ThreadNo() << " pthread_cond " << Name()
222 << " SuspendAction pthread_cond_waited"
223 << Automaton()->StateName( State() ) << endl ;
226 cdebug << pthread_self() << "/" << ThreadNo() << " pthread_cond " << Name()
227 << " NO SuspendAction pthread_cond_wait"
228 << Automaton()->StateName( State() ) << endl ;
230 // SendEvent( _aResumeEvent ) ; ===> Mutex with myself !
231 _SuspendSync = false ;
232 if ( ControlState() == SUPERV::ToSuspendStartState ||
233 ControlState() == SUPERV::ToSuspendState ) {
234 ControlState( SUPERV::VoidState ) ;
236 if ( pthread_mutex_unlock( &_MutexWait ) ) {
237 perror("SuspendAction pthread_mutex_unlock ") ;
241 SendEvent( _aResumeEvent ) ;
242 // if ( ControlState() == SUPERV::ToSuspendStartState ) {
243 // ControlState( SUPERV::VoidState ) ;
246 if ( pthread_mutex_lock( &_MutexWait ) ) {
247 perror("SuspendAction pthread_mutex_lock ") ;
251 cdebug << pthread_self() << "/" << ThreadNo() << " pthread_cond " << Name()
252 << " SuspendAction pthread_cond_signal _ResumeWait" << endl ;
253 if ( pthread_cond_signal( &_ResumeWait ) ) {
254 perror("SuspendAction pthread_cond_signal _ResumeWait ") ;
256 cdebug << pthread_self() << "/" << ThreadNo() << " pthread_cond " << Name()
257 << " SuspendAction pthread_cond_signaled _ResumeWait " << endl ;
260 cdebug << pthread_self() << "/" << ThreadNo() << " pthread_cond " << Name()
261 << " NO SuspendAction pthread_cond_signal _ResumeWait" << endl ;
264 if ( pthread_mutex_unlock( &_MutexWait ) ) {
265 perror("SuspendAction pthread_mutex_unlock ") ;
268 if ( _aReStartNode ) {
269 cdebug << Name() << " " << Automaton()->StateName( State() )
270 << "aReStartNode : " << _aReStartNode->Name() << " "
271 << Automaton()->StateName( _aReStartNode->State() ) << endl ;
272 _aReStartNode->SendEvent( _aResumeEvent ) ;
275 cdebug << "NO aReStartNode"
276 << Automaton()->StateName( State() ) << endl ;
278 return _aReStartNode ;
281 bool GraphExecutor::InNode::ResumeAction( GraphExecutor::NodeEvent aResumeEvent ) {
283 if ( pthread_mutex_lock( &_MutexWait ) ) {
284 perror("ResumeAction pthread_mutex_lock ") ;
287 _aResumeEvent = aResumeEvent ;
288 if ( _SuspendSync ) {
289 cdebug << pthread_self() << "/" << ThreadNo() << " pthread_cond " << Name()
290 << " ResumeAction pthread_cond_signal" << endl ;
291 if ( pthread_cond_signal( &_SuspendWait ) ) {
292 perror("ResumeAction pthread_cond_signal ") ;
294 cdebug << pthread_self() << "/" << ThreadNo() << " pthread_cond " << Name()
295 << " ResumeAction pthread_cond_signaled _SuspendWait " << endl ;
299 cdebug << pthread_self() << "/" << ThreadNo() << " pthread_cond " << Name()
300 << " NO ResumeAction pthread_cond_signal" << endl ;
301 if ( pthread_self() == ThreadNo() ) {
302 RetVal = false ; /*/ Ne pas s'attendre soi-meme !...*/
305 _SuspendSync = true ;
306 RetVal = true ; // Il faut tout de meme attendre ci-apres ...
309 if ( pthread_mutex_unlock( &_MutexWait ) ) {
310 perror("ResumeAction pthread_mutex_unlock ") ;
315 if ( pthread_mutex_lock( &_MutexWait ) ) {
316 perror("ResumeAction pthread_mutex_lock ") ;
319 if ( !_ResumeSync ) {
320 cdebug << pthread_self() << "/" << ThreadNo() << " pthread_cond "
321 << Name() << " ResumeAction pthread_cond_wait _ResumeWait "
322 << Automaton()->StateName( State() ) << endl ;
324 if ( pthread_cond_wait( &_ResumeWait , &_MutexWait ) ) {
325 perror("ResumeAction pthread_cond_wait ") ;
327 cdebug << pthread_self() << "/" << ThreadNo() << " pthread_cond "
328 << Name() << " ResumeAction pthread_cond_waited _ResumeWait"
329 << Automaton()->StateName( State() ) << endl ;
333 cdebug << pthread_self() << "/" << ThreadNo() << " pthread_cond "
334 << Name() << " NO ResumeAction pthread_cond_wait _ResumeWait"
335 << Automaton()->StateName( State() ) << endl ;
338 _ResumeSync = false ;
339 if ( pthread_mutex_unlock( &_MutexWait ) ) {
340 perror("ResumeAction pthread_mutex_unlock ") ;
344 cdebug << pthread_self() << "/" << ThreadNo()
345 << "GraphExecutor::InNodeThreads::ResumeAction RetVal " << RetVal << endl ;
349 bool GraphExecutor::InNode::ReStartAction( GraphExecutor::InNode * aReStartNode ,
350 GraphExecutor::NodeEvent anEvent ) {
351 GraphExecutor::InNode * oldReStartNode = _aReStartNode ;
352 _aReStartNode = aReStartNode ;
353 _aReStartEvent = anEvent ;
354 cdebug << pthread_self() << " GraphExecutor::InNodeThreads::ReStartAction from "
355 << Name() << " " << Automaton()->StateName( State() ) << " to "
356 << aReStartNode->ThreadNo() << " " << aReStartNode->Name() << " "
357 << Automaton()->StateName( aReStartNode->State() ) ;
358 if ( oldReStartNode ) {
359 cdebug << " oldReStartNode " << oldReStartNode->Name() << endl ;
364 return ResumeAction( GraphExecutor::ToReStartEvent ) ;
367 void GraphExecutor::InNode::KilledAction() {
368 if ( pthread_mutex_lock( &_MutexWait ) ) {
369 perror("Killed pthread_mutex_lock ") ;
373 cdebug << "pthread_cond " << Name() << " Killed pthread_cond_wait"
376 if ( pthread_cond_wait( &_KillWait , &_MutexWait ) ) {
377 perror("Killed pthread_cond_wait ") ;
379 cdebug << "pthread_cond " << Name() << " Killed pthread_cond_waited"
383 cdebug << "pthread_cond " << Name() << " NO Killed pthread_cond_wait"
387 if ( pthread_mutex_unlock( &_MutexWait ) ) {
388 perror("Killed pthread_mutex_unlock ") ;
393 void GraphExecutor::InNode::KillAction() {
394 if ( pthread_mutex_lock( &_MutexWait ) ) {
395 perror("Kill pthread_mutex_lock ") ;
399 cdebug << "pthread_cond " << Name() << " Kill pthread_cond_signal"
401 // if ( pthread_cond_broadcast( &_KillWait ) ) {
402 if ( pthread_cond_signal( &_KillWait ) ) {
403 perror("Kill pthread_cond_broadcast ") ;
405 cdebug << "pthread_cond " << Name() << " Kill pthread_cond_signaled"
409 cdebug << "pthread_cond " << Name() << " NO Kill pthread_cond_signal"
413 if ( pthread_mutex_unlock( &_MutexWait ) ) {
414 perror("Kill pthread_mutex_unlock ") ;
419 void GraphExecutor::InNode::StoppedAction() {
420 if ( pthread_mutex_lock( &_MutexWait ) ) {
421 perror("Stopped pthread_mutex_lock ") ;
424 if ( pthread_cond_wait( &_StopWait , &_MutexWait ) ) {
425 perror("Stopped pthread_cond_wait ") ;
427 if ( pthread_mutex_unlock( &_MutexWait ) ) {
428 perror("Stopped pthread_mutex_unlock ") ;
433 void GraphExecutor::InNode::StopAction() {
434 if ( pthread_mutex_lock( &_MutexWait ) ) {
435 perror("Stop pthread_mutex_lock ") ;
438 if ( pthread_cond_broadcast( &_StopWait ) ) {
439 perror("Stop pthread_cond_broadcast ") ;
441 if ( pthread_mutex_unlock( &_MutexWait ) ) {
442 perror("Stop pthread_mutex_unlock ") ;
447 void GraphExecutor::InNode::ThreadStartedAction() {
448 if ( pthread_mutex_lock( &_MutexWait ) ) {
449 perror("ThreadStarted pthread_mutex_lock ") ;
452 if ( !_ThreadStartedSync ) {
453 cdebug << pthread_self() << "/" << ThreadNo()
454 << "pthread_cond " << Name() << " ThreadStarted pthread_cond_wait"
456 _ThreadStartedSync = true ;
457 if ( pthread_cond_wait( &_ThreadStartedWait , &_MutexWait ) ) {
458 perror("ThreadStarted pthread_cond_wait ") ;
460 cdebug << pthread_self() << "/" << ThreadNo()
461 << "pthread_cond " << Name() << " ThreadStarted pthread_cond_waited"
465 cdebug << pthread_self() << "/" << ThreadNo()
466 << "pthread_cond " << Name() << " NO ThreadStarted pthread_cond_wait"
469 _ThreadStartedSync = false ;
470 if ( pthread_cond_signal( &_ThreadStartedWait ) ) {
471 perror("ThreadStart pthread_cond_signal ") ;
474 cdebug << pthread_self() << "/" << ThreadNo()
475 << "pthread_cond " << Name() << " NO ThreadStarted pthread_cond_signaled"
478 if ( pthread_mutex_unlock( &_MutexWait ) ) {
479 perror("ThreadStarted pthread_mutex_unlock ") ;
484 void GraphExecutor::InNode::ThreadStartAction() {
485 if ( pthread_mutex_lock( &_MutexWait ) ) {
486 perror("ThreadStart pthread_mutex_lock ") ;
489 if ( _ThreadStartedSync ) {
490 cdebug << pthread_self() << "/" << ThreadNo()
491 << "pthread_cond " << Name() << " ThreadStart pthread_cond_signal"
493 _ThreadStartedSync = false ;
494 if ( pthread_cond_signal( &_ThreadStartedWait ) ) {
495 perror("ThreadStart pthread_cond_broadcast ") ;
497 cdebug << pthread_self() << "/" << ThreadNo()
498 << "pthread_cond " << Name() << " ThreadStart pthread_cond_signaled"
502 cdebug << pthread_self() << "/" << ThreadNo()
503 << "pthread_cond " << Name() << " NO ThreadStart pthread_cond_signal"
505 _ThreadStartedSync = true ;
507 if ( pthread_cond_wait( &_ThreadStartedWait , &_MutexWait ) ) {
508 perror("ThreadStarted pthread_cond_wait ") ;
511 cdebug << pthread_self() << "/" << ThreadNo()
512 << "pthread_cond " << Name() << " NO ThreadStart pthread_cond_waited"
515 if ( pthread_mutex_unlock( &_MutexWait ) ) {
516 perror("ThreadStart pthread_mutex_unlock ") ;
521 int GraphExecutor::InNode::executeAction() {
522 int oldRewindStack = ( _RewindStack > MAXSTACKTHREADSIZE ) ;
523 if ( !CreateNewThread() && oldRewindStack ) {
524 cdebug << pthread_self() << "/" << ThreadNo()
525 << " executeAction start Thread _RewindStack " << _RewindStack << " > "
526 << MAXSTACKTHREADSIZE << " CreateNewThread "
527 << CreateNewThread() << " " << Automaton()->ActionName( _NextAction ) << "(" << Name() << ")"
529 CreateNewThread( true ) ;
532 if ( CreateNewThread() ) {
533 CreateNewThread( false ) ;
534 if ( ThreadNo() == 0 ) {
536 cdebug << pthread_self() << "/" << ThreadNo()
537 << " executeAction start Thread _RewindStack " << _RewindStack << " "
538 << Automaton()->ActionName( _NextAction ) << "(" << Name() << ")"
541 int pthread_sts = 1 ;
542 // _OutNode->PushEvent( NULL , GraphExecutor::NewThreadEvent ,
543 // GraphExecutor::ExecutingState ) ;
544 while ( (pthread_sts = pthread_create(&T, NULL, run_function, this )) ) {
545 char * msg = "Cannot pthread_create " ;
547 cdebug << ThreadNo() << " " << msg << " --> sleep(5)" << endl ;
548 cdebug << ThreadNo() << " PTHREAD_THREADS_MAX : "
549 << PTHREAD_THREADS_MAX << " pthread_create status : " ;
550 if ( pthread_sts == EAGAIN ) {
551 cdebug << "EAGAIN(" << pthread_sts << ")" << endl ;
552 cdebug << "It seems to me that with gdb we are limited to 256 threads because of defunct" << endl ;
555 cdebug << pthread_sts << endl ;
559 pthread_exit( msg ) ;
561 cdebug << pthread_self() << "/" << ThreadNo()
562 << "executeAction has created thread " << T << endl ;
563 ThreadStartedAction() ;
564 cdebug << pthread_self() << "/" << ThreadNo()
565 << "executeAction the thread " << T << " has called NewThread and will call ExecuteAction for node "
569 cdebug << pthread_self() << "/" << ThreadNo()
570 << " executeAction restart Thread _RewindStack " << _RewindStack << " "
571 << Automaton()->StateName( State() ) << " "
572 << Automaton()->ActionName( _NextAction ) << "(" << Name()
573 << ") ReStartAction ==>" << endl;
574 State( GraphExecutor::SuspendedSuccessedState ) ;
575 if ( !ReStartAction( this , GraphExecutor::ReStartEvent ) ) {
576 cdebug << pthread_self() << "/" << ThreadNo()
577 << " executeAction STATE & CALLED "
578 << Automaton()->ActionName( _NextAction ) << "(" << Name()
579 << ") ERROR-DEBUG " << endl;
582 cdebug << pthread_self() << "/" << ThreadNo() << " executeAction NO CALL "
583 << Automaton()->ActionName( _NextAction ) << "(" << Name()
589 if ( _CurrentEvent == ExecuteEvent ) {
592 cdebug << pthread_self() << "/" << ThreadNo() << " executeAction call "
593 << Automaton()->ActionName( _NextAction ) << "(" << Name() << ") _RewindStack " << _RewindStack
595 return ExecuteAction() ;
600 void GraphExecutor::InNode::coutbegin() {
601 cdebug << pthread_self() << "/" << ThreadNo() << " run_function begin"
602 << " " << Name() << " " << Automaton()->StateName( State() ) << endl ;
604 void GraphExecutor::InNode::coutexit() {
605 cdebug << pthread_self() << "/" << ThreadNo() << " run_function pthread_exit _RewindStack " << _RewindStack
606 << " " << Name() << " " << Automaton()->StateName( State() ) << endl ;
608 void * run_function(void *p) {
609 GraphExecutor::InNode *aNode = (GraphExecutor::InNode *) p;
611 aNode->NewThread( pthread_self() ) ;
612 if ( pthread_setcanceltype( PTHREAD_CANCEL_ASYNCHRONOUS , NULL ) ) {
613 perror("pthread_setcanceltype ") ;
616 if ( pthread_setcancelstate( PTHREAD_CANCEL_ENABLE , NULL ) ) {
617 perror("pthread_setcancelstate ") ;
620 aNode->ThreadStartAction() ;
621 // cout << "run_function " << aNode->Name() << "->ExecuteAction() Coupled : " << aNode->CoupledNode()
623 aNode->ExecuteAction() ;
624 char * msg = new char[40] ;
625 sprintf( msg , "%d" , (int ) aNode->ThreadNo() ) ;
626 strcat( msg , " thread exit" ) ;
628 aNode->ExitThread() ;
631 pthread_exit( (void * ) smsg.c_str() ) ;
635 int GraphExecutor::InNode::ExecuteAction() {
638 const char * nextactionname = Automaton()->ActionName( _NextAction ) ;
639 const char * statename = Automaton()->StateName( State() ) ;
640 const char * nextstatename = Automaton()->StateName( _NextState ) ;
641 cdebug_in << pthread_self() << "/" << ThreadNo() << " --> ExecuteAction "
642 << nextactionname << " " << statename << " NextState "
643 << nextstatename << endl ;
645 State( _NextState ) ;
646 switch ( _NextAction ) {
647 case GraphExecutor::ErrorAction : {
648 sts = ErrorAction() ;
651 case GraphExecutor::VoidAction : {
655 case GraphExecutor::DataWaiting_SomeDataReadyAction : {
656 sts = DataWaiting_SomeDataReadyAction() ;
659 case GraphExecutor::DataUndef_NotAllDataReadyAction : {
660 sts = DataUndef_NotAllDataReadyAction() ;
663 case GraphExecutor::DataUndef_AllDataReadyAction : {
664 sts = DataUndef_AllDataReadyAction() ;
667 case GraphExecutor::DataReady_SuspendAction : {
668 sts = DataReady_SuspendAction() ;
671 case GraphExecutor::SuspendedReady_ResumeAction : {
672 sts = SuspendedReady_ResumeAction() ;
675 case GraphExecutor::DataReady_KillAction : {
676 sts = DataReady_KillAction() ;
679 case GraphExecutor::DataReady_StopAction : {
680 sts = DataReady_StopAction() ;
683 case GraphExecutor::DataReady_ExecuteAction : {
684 sts = DataReady_ExecuteAction() ;
687 case GraphExecutor::Executing_SuspendAction : {
688 sts = Executing_SuspendAction() ;
691 case GraphExecutor::SuspendedExecuting_ResumeAction : {
692 sts = SuspendedExecuting_ResumeAction() ;
695 case GraphExecutor::Executing_KillAction : {
696 sts = Executing_KillAction() ;
699 case GraphExecutor::Executing_StopAction : {
700 sts = Executing_StopAction() ;
703 case GraphExecutor::Executing_SuccessAction : {
704 sts = Executing_SuccessAction() ;
707 case GraphExecutor::Executing_ErrorAction : {
708 sts = Executing_ErrorAction() ;
711 case GraphExecutor::Successed_SuccessAction : {
712 sts = Successed_SuccessAction() ;
715 case GraphExecutor::Errored_ErrorAction : {
716 sts = Errored_ErrorAction() ;
719 case GraphExecutor::Successed_SuspendAction : {
720 sts = Successed_SuspendAction() ;
723 case GraphExecutor::Errored_SuspendAction : {
724 sts = Errored_SuspendAction() ;
727 case GraphExecutor::SuspendedSuccessed_ResumeAction : {
728 sts = SuspendedSuccessed_ResumeAction() ;
731 case GraphExecutor::SuspendedErrored_ResumeAction : {
732 sts = SuspendedErrored_ResumeAction() ;
735 case GraphExecutor::Successed_KillAction : {
736 sts = Successed_KillAction() ;
739 case GraphExecutor::Errored_KillAction : {
740 sts = Errored_KillAction() ;
743 case GraphExecutor::Successed_StopAction : {
744 sts = Successed_StopAction() ;
747 case GraphExecutor::Errored_StopAction : {
748 sts = Errored_StopAction() ;
751 case GraphExecutor::SuspendedSuccessed_ReStartAction : {
752 sts = SuspendedSuccessed_ReStartAction() ;
755 case GraphExecutor::SuspendedErrored_ReStartAction : {
756 sts = SuspendedErrored_ReStartAction() ;
759 case GraphExecutor::SuspendedSuccessed_ReStartAndSuspendAction : {
760 sts = SuspendedSuccessed_ReStartAndSuspendAction() ;
763 case GraphExecutor::SuspendedErrored_ReStartAndSuspendAction : {
764 sts = SuspendedErrored_ReStartAndSuspendAction() ;
768 cdebug << pthread_self() << "/" << ThreadNo()
769 << " GraphExecutor::InNodeThreads::SendEvent Error Undefined Action : "
770 << _NextAction << endl ;
774 cdebug_out << pthread_self() << "/" << ThreadNo() << "<-- ExecuteAction "
775 << nextactionname << endl ;
779 int GraphExecutor::InNode::ErrorAction() {
780 cdebug << pthread_self() << "/" << ThreadNo() << " Automaton ErrorAction Node "
785 int GraphExecutor::InNode::VoidAction() {
786 cdebug << pthread_self() << "/" << ThreadNo() << " VoidAction " << Name() << endl;
791 int GraphExecutor::InNode::DataWaiting_SomeDataReadyAction() {
792 cdebug << pthread_self() << "/" << ThreadNo()
793 << " --> DataWaiting_SomeDataReadyAction from " << DataFromNode()
794 << " to " << Name() << endl;
798 bool LoopBeginning = false ;
799 bool LoopFinished = false ;
800 bool SwitchFinished = false ;
802 if ( IsLoopNode() && GetChangeNodeInLoop()->GetOutPort()->BoolValue() ) {
803 LoopBeginning = true ; // Beginning of Loop
805 if ( IsEndLoopNode() && !GetChangeNodeInLoop()->GetOutPort()->BoolValue() ) {
806 LoopFinished = true ; // End of Loop
808 if ( IsEndSwitchNode() && !GetChangeNodeInGate()->GetOutPort()->BoolValue() ) {
809 SwitchFinished = true ; // End of Switch
811 cdebug << pthread_self() << "/" << ThreadNo() << " " << Name() << " LoopFinished " << LoopFinished
812 << " LoopBeginning " << LoopBeginning << " SwitchFinished " << SwitchFinished << endl ;
813 for ( k = 0 ; k < (unsigned int ) GetNodeInPortsSize() ; k++ ) {
814 GraphBase::InPort * anInPort = GetChangeNodeInPort(k) ;
815 GraphBase::OutPort * anOutPort = anInPort->GetOutPort() ;
816 cdebug << pthread_self() << "/" << ThreadNo() << " " << Name() << " InPort " << anInPort->PortName() << " " << anInPort->State() << " " << anInPort->PortStatus() << endl ;
817 if ( anInPort->IsGate() && anOutPort == NULL ) {
819 anInPort->State( SUPERV::ReadyState ) ;
820 cdebug << pthread_self() << "/" << ThreadNo() << " " << Name() << " "
821 << anInPort->PortName() << " ControlPort inactive." << endl ;
823 // That InPort get its value from an other node
824 else if ( strcmp( DataFromNode() , anOutPort->NodeName() ) ) {
825 if ( anInPort->State() == SUPERV::ReadyState ) {
827 cdebug << pthread_self() << "/" << ThreadNo() << " " << Name() << " "
828 << anInPort->PortName() << " Was Done from Node "
829 << anOutPort->NodeName() << "( " << anOutPort->PortName()
832 if ( GraphBase::Base::_prof_debug ) {
833 anOutPort->StringValue( *GraphBase::Base::_fdebug ) ;
838 else if ( IsLoopNode() && anInPort->IsDataConnected() ) {
839 anInPort->State( SUPERV::ReadyState ) ;
841 cdebug << pthread_self() << "/" << ThreadNo() << " " << Name() << " "
842 << anInPort->PortName() << " Was Done from Node "
843 << anOutPort->NodeName() << "( " << anOutPort->PortName()
844 << ") LoopBeginning " << LoopBeginning ;
846 if ( GraphBase::Base::_prof_debug ) {
847 anOutPort->StringValue( *GraphBase::Base::_fdebug ) ;
852 else if ( LoopFinished ) {
853 anInPort->State( SUPERV::ReadyState ) ;
855 cdebug << pthread_self() << "/" << ThreadNo() << " " << Name() << " "
856 << anInPort->PortName() << " Was Done from Node "
857 << anOutPort->NodeName() << "( " << anOutPort->PortName()
858 << ") LoopFinished" ;
860 if ( GraphBase::Base::_prof_debug ) {
861 anOutPort->StringValue( *GraphBase::Base::_fdebug ) ;
866 else if ( anInPort->IsGate() && SwitchFinished ) {
867 anInPort->State( SUPERV::ReadyState ) ;
869 cdebug << pthread_self() << "/" << ThreadNo() << " " << Name() << " "
870 << anInPort->PortName() << " Was Done from Node "
871 << anOutPort->NodeName() << "( " << anOutPort->PortName()
872 << ") SwitchFinished" ;
874 if ( GraphBase::Base::_prof_debug ) {
875 anOutPort->StringValue( *GraphBase::Base::_fdebug ) ;
881 cdebug << pthread_self() << "/" << ThreadNo() << " " << Name() << " "
882 << anInPort->PortName() << " Was NOT Done from Node "
883 << anOutPort->NodeName() << "( " << anOutPort->PortName() << ") "
884 << " " << Automaton()->StateName( State() ) << " DataConnected "
885 << anInPort->IsDataConnected() << " LoopBeginning "
886 << LoopBeginning << endl ;
889 // That InPort get its value from the sending node
890 else if ( anInPort->IsGate() ) {
891 const CORBA::Any * theValue = anOutPort->Value() ;
893 (*theValue) >>= GateOpened ;
894 if ( GateOpened != 0 ) {
896 anInPort->State( SUPERV::ReadyState ) ;
897 cdebug << pthread_self() << "/" << ThreadNo() << " " << Name() << " "
898 << anInPort->PortName() << " Gate is Opened from Node "
899 << anOutPort->NodeName() << "( " << anOutPort->PortName()
902 if ( GraphBase::Base::_prof_debug ) {
903 anOutPort->StringValue( *GraphBase::Base::_fdebug ) ;
908 else if ( LoopFinished ) {
909 anInPort->State( SUPERV::ReadyState ) ;
910 cdebug << pthread_self() << "/" << ThreadNo() << " " << Name() << " "
911 << anInPort->PortName() << " GATE IS CLOSED from Node "
912 << anOutPort->NodeName() << "( " << anOutPort->PortName()
913 << ") LoopFinished" ;
915 if ( GraphBase::Base::_prof_debug ) {
916 anOutPort->StringValue( *GraphBase::Base::_fdebug ) ;
922 cdebug << pthread_self() << "/" << ThreadNo() << " " << Name() << " "
923 << anInPort->PortName() << " GATE IS CLOSED from Node "
924 << anOutPort->NodeName() << "( " << anOutPort->PortName()
927 if ( GraphBase::Base::_prof_debug ) {
928 anOutPort->StringValue( *GraphBase::Base::_fdebug ) ;
934 else if ( anOutPort->Done() ) {
936 anInPort->State( SUPERV::ReadyState ) ;
937 cdebug << pthread_self() << "/" << ThreadNo() << " " << Name() << " "
938 << anInPort->PortName() << " " << anInPort->PortStatus() << " is Done from Node "
939 << anOutPort->NodeName() << "( " << anOutPort->PortName() << ") "
940 << anOutPort->PortStatus() << " " ;
942 if ( GraphBase::Base::_prof_debug ) {
943 anOutPort->StringValue( *GraphBase::Base::_fdebug ) ;
947 // MacroNode : give immediately the value to the corresponding graph
948 if ( IsMacroNode() ) {
949 cout << "SomeDataReadyAction " << GraphMacroNode() << " " << GraphMacroNode()->Name()
950 << " coupled to " << GraphMacroNode()->CoupledNode() << endl ;
951 GraphExecutor::DataFlow * aMacroGraph = GraphMacroNode()->CoupledNode()->GraphEditor()->Executor() ;
952 cdebug << "SomeDataReadyAction MacroNode " << aMacroGraph->Graph()->Name() << " --> InputOfAny "
953 << InReady << "/" << GetNodeInPortsSize() << " InPorts are Ready" << endl ;
954 // GraphMacroNode()->MacroObject()->InputOfAny( anInPort->PortName() , *anOutPort->Value() ) ;
955 aMacroGraph->InputOfAny( anInPort->PortName() , *anOutPort->Value() ) ;
959 cdebug << pthread_self() << "/" << ThreadNo() << " Node " << Name() << "( "
960 << anInPort->PortName() << ") " << anInPort->PortStatus()
961 << " is NOT Done from Node "
962 << anOutPort->NodeName() << "( " << anOutPort->PortName() << ") "
963 << anOutPort->PortStatus() << " " ;
967 if ( InReady == GetNodeInPortsSize() ) { // All Flags != 0 :
968 res = SendEvent( GraphExecutor::AllDataReadyEvent ); // ==> Ready to execute
970 else { // At least one Flag == 0 :
971 res = SendEvent( GraphExecutor::NotAllDataReadyEvent );
974 cdebug << pthread_self() << "/" << ThreadNo()
975 << " <-- DataWaiting_SomeDataReadyAction " << Name() << endl;
980 int GraphExecutor::InNode::DataUndef_NotAllDataReadyAction() {
981 CreateNewThreadIf( false ) ;
982 // cdebug << pthread_self() << " for " << ThreadNo()
983 // << " DataUndef_NotAllDataReadyAction " << Name() << endl;
987 int GraphExecutor::InNode::DataUndef_AllDataReadyAction() {
988 // cdebug << pthread_self() << "/" << ThreadNo()
989 // << " --> DataUndef_AllDataReadyAction " << Name()
990 // << " CreateNewThreadIf " << CreateNewThreadIf() << " IsLockedDataWait "
991 // << IsLockedDataWait() ;
992 if ( IsLockedDataWait() ) {
993 cdebug << "DataUndef_AllDataReadyAction() WOULD DEAD-LOCK" << endl ;
994 return 0 ; // ==> DataUndef_AllDataReadyAction() after UnLockDataWait()
997 CreateNewThread( CreateNewThreadIf() ) ;
998 if ( !CreateNewThread() ) {
999 // cdebug << "Thread " << ThreadNo() << "-->" << pthread_self() << endl ;
1000 ThreadNo( pthread_self() ) ;
1002 _OutNode->PushEvent( this , GraphExecutor::AllDataReadyEvent ,
1003 GraphExecutor::DataReadyState ) ;
1005 SUPERV::ControlState aControl = ControlState() ;
1006 switch ( aControl ) {
1007 case SUPERV::VoidState : {
1008 SendEvent( GraphExecutor::ExecuteEvent ) ;
1011 case SUPERV::ToSuspendState : {
1012 SendEvent( GraphExecutor::SuspendEvent ) ;
1015 case SUPERV::ToSuspendStartState : {
1016 SendEvent( GraphExecutor::SuspendEvent ) ;
1019 case SUPERV::ToSuspendDoneState : {
1020 SendEvent( GraphExecutor::ExecuteEvent ) ;
1023 case SUPERV::ToKillState : {
1024 SendEvent( GraphExecutor::KillEvent ) ;
1027 case SUPERV::ToKillDoneState : {
1028 SendEvent( GraphExecutor::ExecuteEvent ) ;
1031 case SUPERV::ToStopState : {
1032 SendEvent( GraphExecutor::StopEvent ) ;
1036 cdebug << ThreadNo()
1037 << " GraphExecutor::InNodeThreads::DataUndef_AllDataReadyAction Error Undefined Control : "
1038 << aControl << endl ;
1042 // cdebug << pthread_self() << "/" << ThreadNo()
1043 // << " <-- DataUndef_AllDataReadyAction " << Name() << endl;
1047 int GraphExecutor::InNode::DataReady_SuspendAction() {
1048 cdebug << pthread_self() << "/" << ThreadNo()
1049 << "DataReady_SuspendAction --> Suspend " << Name()
1050 << " Threads " << _OutNode->Threads() << " SuspendedThreads "
1051 << _OutNode->SuspendedThreads() << endl;
1052 _OutNode->PushEvent( this , GraphExecutor::SuspendedReadyEvent ,
1053 GraphExecutor::SuspendedReadyState ) ;
1054 GraphExecutor::InNode * aReStartNode = SuspendAction() ;
1055 cdebug << pthread_self() << "/" << ThreadNo()
1056 << "DataReady_SuspendAction Resumed " << Name() << endl;
1057 if ( aReStartNode ) {
1058 _aReStartNode = NULL ;
1059 aReStartNode->SendEvent( _aReStartEvent ) ;
1062 SendEvent( GraphExecutor::ExecuteEvent ) ;
1067 int GraphExecutor::InNode::SuspendedReady_ResumeAction() {
1068 cdebug << pthread_self() << "/" << ThreadNo() << "SuspendedReady_ResumeAction "
1071 _OutNode->PushEvent( this , GraphExecutor::ResumedReadyEvent ,
1072 GraphExecutor::ResumedReadyState ) ;
1076 int GraphExecutor::InNode::DataReady_KillAction() {
1077 _OutNode->PushEvent( this , GraphExecutor::KilledReadyEvent ,
1078 GraphExecutor::KilledReadyState ) ;
1080 cdebug << pthread_self() << "/" << ThreadNo() << "DataReady_KillAction " << Name()
1081 << " will pthread_exit()" << endl;
1085 int GraphExecutor::InNode::DataReady_StopAction() {
1086 _OutNode->PushEvent( this , GraphExecutor::StoppedReadyEvent ,
1087 GraphExecutor::StoppedReadyState ) ;
1089 cdebug << pthread_self() << "/" << ThreadNo() << "DataReady_StopAction " << Name()
1090 << " will pthread_exit()" << endl;
1096 int GraphExecutor::InNode::DataReady_ExecuteAction() {
1099 // cdebug << pthread_self() << "/" << ThreadNo() << " --> DataReady_ExecuteAction "
1100 // << Name() << endl;
1101 _OutNode->PushEvent( this , GraphExecutor::ExecuteEvent ,
1102 GraphExecutor::ExecutingState ) ;
1108 SUPERV::GraphState PortState = SUPERV::ReadyState ;
1109 GraphExecutor::AutomatonState NewState = GraphExecutor::DataUndefState ;
1110 GraphExecutor::NodeEvent NewEvent = GraphExecutor::UndefinedEvent ;
1113 ServicesAnyData * InParametersList ;
1115 ServicesAnyData * OutParametersList ;
1117 nInParams = GetNodeInPortsSize() ;
1118 InParametersList = new ServicesAnyData[nInParams];
1119 InParametersSet( Err , nInParams , InParametersList ) ;
1121 nOutParams = GetNodeOutPortsSize() ;
1122 OutParametersList = new ServicesAnyData[nOutParams];
1123 InOutParametersSet( nOutParams , OutParametersList ) ;
1125 if ( !IsMacroNode() ) {
1127 Engines::Container_var myContainer ;
1128 Engines::Component_var myObjComponent ;
1129 if ( !IsFactoryNode() ) {
1130 // cdebug << ThreadNo() << "No Component : NO StartComponent & No Ping" << endl ;
1131 if ( IsComputingNode() ) {
1132 ObjInterface( true ) ;
1133 CORBA::Object_ptr obj ;
1134 InParametersList[0].Value >>= obj ;
1135 CORBA::Object_var objvar = CORBA::Object_var( obj ) ;
1136 myObjComponent = Engines::Component::_narrow( objvar ) ;
1141 else if ( CORBA::is_nil( Component() ) ) {
1142 // ostringstream astr ;
1143 // astr << "Graph " << _OutNode->Graph()->Name() << " Node " << Name()
1144 // << " : load of component " << ComponentName() << " in container "
1146 // _OutNode->Graph()->ObjImpl()->sendMessage( NOTIF_STEP, astr.str().c_str() ) ;
1147 Err = !_OutNode->Graph()->StartComponent( ThreadNo() , Computer() ,
1148 my_strdup( ComponentName() ) ,
1149 myContainer , myObjComponent ) ;
1150 ObjInterface( false ) ;
1151 SetContainer( myContainer ) ;
1152 SetComponent( myObjComponent ) ;
1155 myContainer = Container() ;
1156 myObjComponent = Component() ;
1157 // cdebug << ThreadNo() << "Component known : NO StartComponent & Ping"
1160 myObjComponent->ping() ;
1163 cdebug << "ping() catched" << endl ;
1168 if ( Err || ControlState() == SUPERV::ToKillState ||
1169 ControlState() == SUPERV::ToKillDoneState ||
1170 ControlState() == SUPERV::ToStopState ) {
1171 cdebug << ThreadNo() << "StartComponent Error or ToKillState" << endl ;
1172 MESSAGE(pthread_self() << "Executor::InNode::DataReady_ExecuteAction of " << Name()
1173 << " ControlState " << Automaton()->ControlStateName( ControlState() )
1174 << " BEFORE execution ThreadNo " << ThreadNo() ) ;
1178 if ( ControlState() == SUPERV::ToSuspendState ) {
1179 cdebug << ThreadNo() << "ToSuspendState before running." << endl ;
1180 MESSAGE(ThreadNo() << "ToSuspendState before running.") ;
1183 // ostringstream astr ;
1184 // astr << "Graph " << _OutNode->Graph()->Name() << " Run of Node " << Name() ;
1185 // _OutNode->Graph()->ObjImpl()->sendMessage( NOTIF_STEP, astr.str().c_str() ) ;
1186 cdebug << ThreadNo() << " Run( '" << ServiceName() << "'" ;
1187 for ( i = 0 ; i < (int ) ServiceInParameter().length() ; i++ ) {
1188 cdebug << " , " << InParametersList[ i ].Name << "[kind"
1189 << InParametersList[ i ].Value.type()->kind() << "]" ;
1191 for ( i = 0 ; i < (int ) ServiceOutParameter().length() ; i++ ) {
1192 cdebug << " , " << OutParametersList[ i ].Name << "[kind"
1193 << OutParametersList[ i ].Value.type()->kind() << "]" ;
1195 if ( IsOneOfInLineNodes() ) {
1196 cdebug << " , PyFuncName '" << InLineNode()->PyFuncName() << "' PyRunMethod "
1197 << InLineNode()->PyRunMethod() << " length "
1198 << (*InLineNode()->PythonFunction()).length() ;
1200 cdebug << ")" << endl ;
1202 if ( IsOneOfInLineNodes() ) {
1203 bool StsPyDynInvoke = true;
1204 _OutNode->PyThreadLock() ;
1207 // if ( IsInLineNode() && (*InLineNode()->PythonFunction()).length() &&
1208 bool ItIsaLoop = false ;
1209 bool CopyInOut = false ;
1210 if ( IsInLineNode() && /*InLineNode()->PyRunMethod() &&*/
1211 strlen( InLineNode()->PyFuncName() ) ) {
1212 cdebug << ThreadNo() << " !ObjInterface " << Name() << " PyFuncName '"
1213 << InLineNode()->PyFuncName()
1214 << "' IsInLineNode PyDynInvoke" << endl ;
1215 StsPyDynInvoke = PyDynInvoke( InLineNode()->PyRunMethod() ,
1216 InLineNode()->PyFuncName() ,
1217 &InParametersList[0] , ServiceInParameter().length() ,
1218 &OutParametersList[0] , ServiceOutParameter().length() ) ;
1219 if ( !StsPyDynInvoke ) {
1220 RemovePyDynInvoke( InLineNode()->PyFuncName() ) ;
1222 else if ( IsLoopNode() ) {
1224 bool CopyOutIn = false ;
1225 // Switch between Init() and Next()
1226 // if InLoop port is true and does not come from EndLoop ==> execute Init
1227 // if InLoop port is false or come from EndLoop ==> execute Next
1228 // GraphExecutor::InNode * anEndLoopNode = (GraphExecutor::InNode * ) CoupledNode()->GetInNode() ;
1229 // if ( GetNodeInLoop()->GetOutPort()->BoolValue() &&
1231 if ( strlen( InLineNode()->PyFuncName() ) ) { // InLoop Port = true ==> Init()
1232 cdebug << ThreadNo() << " !ObjInterface " << Name()
1233 << " IsLoopNode PyDynInvoke '" << InLineNode()->PyFuncName()
1234 << "' InitLoop " << LoopNode()->PyRunMethod() << endl ;
1235 StsPyDynInvoke = PyDynInvoke( InLineNode()->PyRunMethod() ,
1236 InLineNode()->PyFuncName() ,
1237 &InParametersList[1] , ServiceInParameter().length() ,
1238 &OutParametersList[1] , ServiceOutParameter().length() ) ;
1239 if ( !StsPyDynInvoke ) {
1240 RemovePyDynInvoke( InLineNode()->PyFuncName() ) ;
1245 cdebug << ThreadNo() << " !ObjInterface " << Name()
1246 << " IsLoopNode NO PyDynInvoke Void PyFuncName InitLoop" << endl ;
1248 cdebug << ThreadNo() << " !ObjInterface " << Name()
1249 << " IsLoopNode _InitLoop Reset after Init() Python Function" << endl ;
1252 else if ( LoopNode()->PyNextMethod() &&
1253 strlen( LoopNode()->PyNextName() ) ){ // InLoop Port = false ==> Next()
1254 cdebug << ThreadNo() << " !ObjInterface " << Name()
1255 << " IsLoopNode PyDynInvoke '" << LoopNode()->PyNextName()
1256 << "' " << LoopNode()->PyNextMethod() << endl ;
1257 StsPyDynInvoke = PyDynInvoke( LoopNode()->PyNextMethod() ,
1258 LoopNode()->PyNextName() ,
1259 &InParametersList[1] , ServiceInParameter().length() ,
1260 &OutParametersList[1] , ServiceOutParameter().length() ) ;
1261 if ( !StsPyDynInvoke ) {
1262 RemovePyDynInvoke( LoopNode()->PyNextName() ) ;
1267 cdebug << ThreadNo() << " !ObjInterface " << Name()
1268 << " IsLoopNode NO PyDynInvoke Void PyFuncName NextLoop" << endl ;
1270 if ( StsPyDynInvoke ) {
1272 cdebug << ThreadNo() << " !ObjInterface " << Name()
1273 << " IsLoopNode PyDynInvoke '" << LoopNode()->PyMoreName()
1274 << "' Copy of " << ServiceInParameter().length()
1275 << " OutParameters" << endl ;
1277 // Start at 1 : Do not copy InLoop ( InLoop == true <==> Init ; InLoop == false <==> Next )
1278 for ( i = 1 ; i <= (int ) ServiceInParameter().length() ; i++ ) {
1279 InParametersList[i].Value = OutParametersList[i].Value ;
1280 InParametersList[i].Name = OutParametersList[i].Name ;
1282 switch ( InParametersList[i].Value.type()->kind() ) {
1283 case CORBA::tk_string :
1285 InParametersList[i].Value >>= t ;
1286 cdebug << "ArgOut->In" << i << " : "
1287 << InParametersList[i].Name.c_str()
1288 << " Value(string) " << t << endl ;
1290 case CORBA::tk_double :
1292 InParametersList[i].Value >>= d;
1293 cdebug << "ArgOut->In" << i << " : "
1294 << InParametersList[i].Name.c_str()
1295 << " Value(double) " << d << endl ;
1297 case CORBA::tk_long :
1299 InParametersList[i].Value >>= l;
1300 cdebug << "ArgOut->In" << i << " : "
1301 << InParametersList[i].Name.c_str()
1302 << " Value(long) " << l << endl ;
1304 case CORBA::tk_objref :
1305 CORBA::Object_ptr obj ;
1308 InParametersList[i].Value >>= obj ;
1309 retstr = ObjectToString( obj );
1310 cdebug << "ArgOut->In" << i << " : "
1311 << InParametersList[i].Name.c_str()
1312 << " Value(object reference) " << retstr << endl ;
1315 cdebug << "ArgOut->In" << i << " : "
1316 << InParametersList[i].Name.c_str()
1317 << " Value(object reference) Catched ERROR" << endl ;
1321 cdebug << "ArgOut->In" << i << " : "
1322 << InParametersList[i].Name.c_str()
1323 << " Value(other) ERROR" << endl ;
1328 if ( LoopNode()->PyMoreMethod() && strlen( LoopNode()->PyMoreName() ) ) {
1329 cdebug << ThreadNo() << " !ObjInterface " << Name()
1330 << " IsLoopNode PyDynInvoke '" << LoopNode()->PyMoreName()
1331 << "' " << LoopNode()->PyMoreMethod() << endl ;
1332 StsPyDynInvoke = PyDynInvoke( LoopNode()->PyMoreMethod() ,
1333 LoopNode()->PyMoreName() ,
1334 &InParametersList[1] , ServiceInParameter().length() ,
1335 &OutParametersList[0] , ServiceOutParameter().length()+1 ) ;
1336 if ( !StsPyDynInvoke ) {
1337 RemovePyDynInvoke( LoopNode()->PyMoreName() ) ;
1341 cdebug << ThreadNo() << " !ObjInterface " << Name()
1342 << " IsLoopNode PyDynInvoke '" << LoopNode()->PyMoreName()
1343 << "' No MoreMethod" << endl ;
1349 cdebug << ThreadNo() << " InLineNode " << Name() << " "
1350 << InLineNode()->PyFuncName() << "/" << LoopNode()->PyNextName()
1351 << " Python Dynamic Call Error"
1355 else if ( IsSwitchNode() && /*InLineNode()->PyRunMethod() &&*/
1356 strlen( InLineNode()->PyFuncName() ) ) {
1357 // cdebug << ThreadNo() << " !ObjInterface " << Name() << " PyFuncName '"
1358 // << InLineNode()->PyFuncName()
1359 // << "' IsSwitchNode PyDynInvoke" << endl ;
1360 StsPyDynInvoke = PyDynInvoke( InLineNode()->PyRunMethod() ,
1361 InLineNode()->PyFuncName() ,
1362 &InParametersList[0] , ServiceInParameter().length() ,
1363 &OutParametersList[0] , ServiceOutParameter().length() ) ;
1364 if ( !StsPyDynInvoke ) {
1365 RemovePyDynInvoke( InLineNode()->PyFuncName() ) ;
1368 // else if ( IsGOTONode() && (*GOTONode()->PythonFunction()).length() &&
1369 else if ( IsGOTONode() && /*InLineNode()->PyRunMethod() &&*/
1370 strlen( InLineNode()->PyFuncName() ) ) {
1371 // cdebug << ThreadNo() << " !ObjInterface " << Name() << " PyFuncName '"
1372 // << InLineNode()->PyFuncName()
1373 // << "' IsGOTONode PyDynInvoke" << endl ;
1374 StsPyDynInvoke = PyDynInvoke( InLineNode()->PyRunMethod() ,
1375 InLineNode()->PyFuncName() ,
1376 &InParametersList[0] , ServiceInParameter().length() ,
1377 &OutParametersList[0] , ServiceOutParameter().length() ) ;
1378 if ( !StsPyDynInvoke ) {
1379 RemovePyDynInvoke( GOTONode()->PyFuncName() ) ;
1382 // else if ( IsEndSwitchNode() && (*InLineNode()->PythonFunction()).length() &&
1383 else if ( ( IsEndSwitchNode() ) &&
1384 InLineNode()->PyRunMethod() && strlen( InLineNode()->PyFuncName() ) ) {
1385 // cdebug << ThreadNo() << " !ObjInterface " << Name() << " PyFuncName '"
1386 // << InLineNode()->PyFuncName()
1387 // << "' IsSwitchNode PyDynInvoke" << endl ;
1388 StsPyDynInvoke = PyDynInvoke( InLineNode()->PyRunMethod() ,
1389 InLineNode()->PyFuncName() ,
1390 &InParametersList[0] , ServiceInParameter().length() ,
1391 &OutParametersList[0] , ServiceOutParameter().length() ) ;
1392 if ( !StsPyDynInvoke ) {
1393 RemovePyDynInvoke( InLineNode()->PyFuncName() ) ;
1396 else if ( ( IsEndLoopNode() ) &&
1397 InLineNode()->PyRunMethod() && strlen( InLineNode()->PyFuncName() ) ) {
1398 cdebug << ThreadNo() << " !ObjInterface " << Name() << " PyFuncName '"
1399 << InLineNode()->PyFuncName()
1400 << "' IsSwitchNode PyDynInvoke" << endl ;
1401 StsPyDynInvoke = PyDynInvoke( InLineNode()->PyRunMethod() ,
1402 InLineNode()->PyFuncName() ,
1403 &InParametersList[0] , ServiceInParameter().length() + 1 ,
1404 &OutParametersList[0] , ServiceOutParameter().length() + 1 ) ;
1405 if ( !StsPyDynInvoke ) {
1406 RemovePyDynInvoke( InLineNode()->PyFuncName() ) ;
1410 // else if ( (*InLineNode()->PythonFunction()).length() == 0 ||
1411 if ( (!ItIsaLoop && ( InLineNode()->PyRunMethod() == NULL ||
1412 strlen( InLineNode()->PyFuncName() ) == 0 ) ) || CopyInOut ) {
1413 // This is a void Python Function : without code (No PyFuncName)
1414 // cdebug << ThreadNo() << " !ObjInterface " << Name()
1415 // << " Copy of " << ServiceInParameter().length()
1416 // << " OutParameters" << endl ;
1420 if ( IsLoopNode() || IsEndLoopNode() ) {
1422 argin0 = 1 ; // after DoLoop
1423 if ( IsLoopNode() ) { // More() is void
1424 // OutParametersList[0].Value = InParametersList[0].Value ; // DoLoop
1425 cdebug << Name() << " Not Beginning of loop and non void EndLoop : DoLoop = EndLoop(DoLoop)"
1427 GraphExecutor::InNode * anEndLoopNode = (GraphExecutor::InNode * ) CoupledNode()->GetInNode() ;
1428 OutParametersList[0].Value = *anEndLoopNode->GetNodeOutLoop()->Value() ; // DoLoop = EndLoop(DoLoop)
1431 for ( i = 0 ; i < (int ) ServiceInParameter().length() ; i++ ) {
1432 OutParametersList[argout0 + i].Value = InParametersList[argin0 + i].Value ;
1434 switch ( InParametersList[argin0 + i].Value.type()->kind() ) {
1435 case CORBA::tk_string :
1436 cdebug << "ArgOut->In" << argin0 + i << " : "
1437 << InParametersList[argin0 + i].Name.c_str()
1438 << " Value(string) "
1439 << OutParametersList[argout0 + i].Name.c_str() << endl ;
1441 case CORBA::tk_double :
1442 cdebug << "ArgOut->In" << argin0 + i << " : "
1443 << InParametersList[argin0 + i].Name.c_str()
1444 << " Value(double) "
1445 << OutParametersList[argout0 + i].Name.c_str() << endl ;
1447 case CORBA::tk_long :
1448 cdebug << "ArgOut->In" << argin0 + i << " : "
1449 << InParametersList[argin0 + i].Name.c_str()
1451 << OutParametersList[argout0 + i ].Name.c_str() << endl ;
1453 case CORBA::tk_objref :
1454 cdebug << "ArgOut->In" << argin0 + i << " : "
1455 << InParametersList[argin0 + i].Name.c_str()
1456 << " Value(object reference) "
1457 << OutParametersList[argout0 + i].Name.c_str() << endl ;
1460 cdebug << "ArgOut->In" << argin0 + i << " : "
1461 << InParametersList[argin0 + i].Name.c_str()
1462 << " Value(other) ERROR "
1463 << OutParametersList[argout0 + i].Name.c_str() << endl ;
1468 if ( !StsPyDynInvoke ) {
1470 cdebug << ThreadNo() << " InLineNode " << Name()
1471 << " Python Dynamic Call Error"
1477 cdebug << ThreadNo() << " InLineNode " << Name()
1478 << " Python Dynamic Call Exception catched ERROR"
1482 _OutNode->PyThreadUnLock() ;
1487 cdebug << "DynInvoke -> Names " << _OutNode->Graph()->Name() << " " << Name() << endl ;
1488 DynInvoke( myObjComponent, "Names" ,
1489 _OutNode->Graph()->Name() , Name() ) ;
1492 cdebug << "DynInvoke Names catched ERROR" << endl ;
1494 // for DataStreamNodes : call of SetProperties ===> environment variables in the component/container
1495 if ( ComputingNode()->HasDataStream() ) {
1497 cdebug << "DynInvoke -> SetProperties " << _OutNode->Graph()->Name() << " " << Name() << endl ;
1498 Engines::FieldsDict_var dict = new Engines::FieldsDict;
1500 dict[ 0 ].key = CORBA::string_dup( "CAL_MACHINE");
1501 // myContainer->getHostName() ne renvoit pas le nom complet (avec domaine).
1502 // dict[ 0 ].value <<= myContainer->getHostName() ;
1503 char FullyQualifiedDomainName[256]="";
1504 gethostname(FullyQualifiedDomainName,255);
1505 dict[ 0 ].value <<= FullyQualifiedDomainName ;
1506 dict[ 1 ].key = CORBA::string_dup( "CAL_REPERTOIRE");
1507 dict[ 1 ].value <<= "/tmp" ;
1508 dict[ 2 ].key = CORBA::string_dup( "CAL_COUPLAGE");
1509 stringstream ofst1 ;
1510 ofst1 << ComputingNode()->SubStreamGraph() ;
1511 string cpl = string( "/tmp/" ) + string( _OutNode->Graph()->Name() ) + string( "_" ) +
1512 ofst1.str() + string( ".cpl" );
1513 dict[ 2 ].value <<= cpl.c_str() ;
1514 dict[ 3 ].key = CORBA::string_dup( "SALOME_INSTANCE_NAME");
1515 string uname = Name();
1517 dict[ 3 ].value <<= uname.c_str() ;
1519 myObjComponent->setProperties( dict ) ;
1522 cdebug << "DynInvoke setProperties catched ERROR" << endl ;
1526 if ( !Err && IsComputingNode() ) {
1527 cdebug << ThreadNo() << " !ObjInterface " << Name()
1528 << " IsComputingNode DynInvoke" << endl ;
1529 cdebug << ServiceInParameter().length()-1 << " input parameters and "
1530 << ServiceOutParameter().length() << " output parameters" << endl ;
1531 IsLoading( false ) ;
1532 DynInvoke( myObjComponent,
1534 &InParametersList[1] , ServiceInParameter().length()-1 ,
1535 &OutParametersList[0] , ServiceOutParameter().length() ) ;
1537 else if ( !Err && IsFactoryNode() ) {
1538 cdebug << ThreadNo() << " !ObjInterface " << Name()
1539 << " IsFactoryNode DynInvoke" << endl ;
1540 cdebug << ServiceInParameter().length() << " input parameters and "
1541 << ServiceOutParameter().length() << " output parameters" << endl ;
1542 IsLoading( false ) ;
1543 DynInvoke( myObjComponent,
1545 &InParametersList[0] , ServiceInParameter().length() ,
1546 &OutParametersList[0] , ServiceOutParameter().length() ) ;
1548 // cdebug << ThreadNo() << " Component::CpuUsed " << Name() << " "
1549 // << myObjComponent->CpuUsed_impl() << endl ;
1553 cdebug << ThreadNo() << " !ObjInterface " << Name()
1554 << " Node(Component) Dynamic Call Exception catched ERROR"
1556 //Reset of _ThreadId in the Container ...
1558 myObjComponent->Kill_impl() ;
1568 // ostringstream astr ;
1569 // astr << "Graph " << _OutNode->Graph()->Name() << " Node " << Name() << " is done : "
1570 // << Automaton()->StateName( State() ) ;
1571 // _OutNode->Graph()->ObjImpl()->sendMessage( NOTIF_STEP, astr.str().c_str() ) ;
1575 // if exception or something else - IsLoading( false ) may not NOT has been called
1579 if ( ControlState() == SUPERV::ToKillState ||
1580 ControlState() == SUPERV::ToKillDoneState ||
1581 ControlState() == SUPERV::ToStopState ) {
1582 PortState = SUPERV::ErrorState ;
1583 NewState = GraphExecutor::KilledState ;
1584 NewEvent = GraphExecutor::KillEvent ;
1587 PortState = SUPERV::ErrorState ;
1588 NewState = GraphExecutor::ErroredState ;
1589 NewEvent = GraphExecutor::ErrorEvent ;
1593 PortState = SUPERV::ReadyState ;
1594 NewState = GraphExecutor::DataReadyState ;
1595 NewEvent = GraphExecutor::SuccessEvent ;
1598 if ( !IsMacroNode() ) {
1599 bool ErrOut = OutParametersSet( Err , PortState , nOutParams , OutParametersList ) ;
1601 NewEvent = GraphExecutor::ErrorEvent ;
1603 delete [] InParametersList ;
1604 delete [] OutParametersList ;
1607 if ( !IsMacroNode() ) {
1608 SendEvent( NewEvent ) ;
1611 GraphExecutor::DataFlow * aMacroGraph = GraphMacroNode()->CoupledNode()->GraphEditor()->Executor() ;
1612 cdebug << ThreadNo() << " DataReady_ExecuteAction " << aMacroGraph << " "
1613 << aMacroGraph->Graph()->Name() << " ->DoneWait()"
1614 << " State " << aMacroGraph->State() << endl;
1615 aMacroGraph->DoneWait() ;
1616 cdebug << ThreadNo() << " DataReady_ExecuteAction " << Name() << " State " << aMacroGraph->State() << endl;
1617 if ( aMacroGraph->State() == SUPERV::DoneState ) {
1618 PortState = SUPERV::ReadyState ;
1619 NewState = GraphExecutor::DataReadyState ;
1620 NewEvent = GraphExecutor::SuccessEvent ;
1624 if ( ControlState() == SUPERV::ToKillState ||
1625 ControlState() == SUPERV::ToKillDoneState ||
1626 ControlState() == SUPERV::ToStopState ) {
1627 PortState = SUPERV::ErrorState ;
1628 NewState = GraphExecutor::KilledState ;
1629 NewEvent = GraphExecutor::KillEvent ;
1632 PortState = SUPERV::ErrorState ;
1633 NewState = GraphExecutor::ErroredState ;
1634 NewEvent = GraphExecutor::ErrorEvent ;
1637 bool ErrOut = OutParametersSet( Err , PortState , nOutParams , OutParametersList ) ;
1639 NewEvent = GraphExecutor::ErrorEvent ;
1641 delete [] InParametersList ;
1642 delete [] OutParametersList ;
1643 SendEvent( NewEvent ) ;
1646 // cdebug << ThreadNo() << " <-- DataReady_ExecuteAction " << Name() << endl;
1650 int GraphExecutor::InNode::Executing_SuspendAction() {
1651 _OutNode->PushEvent( this , GraphExecutor::SuspendedExecutingEvent ,
1652 GraphExecutor::SuspendedExecutingState ) ;
1653 cdebug << ThreadNo() << " Executing_SuspendAction " << Name() << endl;
1657 int GraphExecutor::InNode::SuspendedExecuting_ResumeAction() {
1658 cdebug << ThreadNo() << " SuspendedExecuting_ResumeAction " << Name() << endl;
1659 GraphExecutor::AutomatonState next_state ;
1660 next_state = Automaton()->NextState( State() , GraphExecutor::ExecutingEvent ) ;
1661 _OutNode->NewThread() ; // Only for Threads count
1662 _OutNode->PushEvent( this , GraphExecutor::ResumedExecutingEvent ,
1664 State( next_state ) ;
1668 int GraphExecutor::InNode::Executing_KillAction() {
1669 cdebug << ThreadNo() << " Executing_KillAction " << Name() << " Thread " << ThreadNo()<< endl;
1671 if ( pthread_self() == ThreadNo() ) {
1672 cdebug << "Executing_KillAction would pthread_canceled itself" << endl ;
1674 _OutNode->PushEvent( this , GraphExecutor::KilledExecutingEvent ,
1675 GraphExecutor::KilledExecutingState ) ;
1678 else if ( pthread_cancel( ThreadNo() ) ) {
1679 perror("Executing_KillAction pthread_cancel error") ;
1682 cdebug << pthread_self() << " Executing_KillAction : ThreadId " << ThreadNo()
1683 << " pthread_canceled" << endl ;
1685 _OutNode->ExitThread( ThreadNo() ) ;
1686 _OutNode->PushEvent( this , GraphExecutor::KilledExecutingEvent ,
1687 GraphExecutor::KilledExecutingState ) ;
1692 int GraphExecutor::InNode::Executing_StopAction() {
1693 cdebug << ThreadNo() << " Executing_StopAction " << Name() << " Thread " << ThreadNo() << endl;
1695 if ( pthread_cancel( ThreadNo() ) ) {
1696 perror("Executing_KillAction pthread_cancel error") ;
1699 cdebug << pthread_self() << " Executing_KillAction : ThreadId " << ThreadNo()
1700 << " pthread_canceled" << endl ;
1702 _OutNode->ExitThread( ThreadNo() ) ;
1703 _OutNode->PushEvent( this , GraphExecutor::StoppedExecutingEvent ,
1704 GraphExecutor::StoppedExecutingState ) ;
1709 int GraphExecutor::InNode::Executing_SuccessAction() {
1710 // cdebug << ThreadNo() << " --> Executing_SuccessAction " << Name() << endl;
1711 _OutNode->PushEvent( this , GraphExecutor::SuccessedExecutingEvent ,
1712 GraphExecutor::SuccessedState ) ;
1713 MESSAGE(pthread_self() << "Executor::InNode::Executing_SuccessAction of " << Name()
1714 << " ControlState " << Automaton()->ControlStateName( ControlState() )
1715 << " AFTER execution ThreadNo " << ThreadNo() ) ;
1716 SUPERV::ControlState aControl = ControlState() ;
1717 switch ( aControl ) {
1718 case SUPERV::VoidState : {
1719 SendEvent( SuccessEvent ) ;
1722 case SUPERV::ToSuspendState : {
1723 SendEvent( SuccessEvent ) ;
1726 case SUPERV::ToSuspendDoneState : {
1727 SendEvent( GraphExecutor::SuspendEvent ) ;
1730 case SUPERV::ToKillState : {
1731 SendEvent( GraphExecutor::KillEvent ) ;
1734 case SUPERV::ToKillDoneState : {
1735 SendEvent( GraphExecutor::KillEvent ) ;
1738 case SUPERV::ToStopState : {
1739 SendEvent( GraphExecutor::StopEvent ) ;
1743 cdebug << ThreadNo()
1744 << " GraphExecutor::InNodeThreads::Executing_SuccessAction Error Undefined Control : "
1745 << aControl << endl ;
1749 // cdebug << ThreadNo() << " <-- Executing_SuccessAction " << Name() << endl;
1753 int GraphExecutor::InNode::Executing_ErrorAction() {
1754 cdebug << ThreadNo() << " --> Executing_ErrorAction " << Name() << endl;
1755 _OutNode->PushEvent( this , GraphExecutor::ErroredExecutingEvent ,
1756 GraphExecutor::ErroredState ) ;
1758 SUPERV::ControlState aControl = ControlState() ;
1759 switch ( aControl ) {
1760 case SUPERV::VoidState : {
1761 SendEvent( ErrorEvent ) ;
1764 case SUPERV::ToSuspendState : {
1765 SendEvent( ErrorEvent ) ;
1768 case SUPERV::ToSuspendDoneState : {
1769 SendEvent( GraphExecutor::SuspendEvent ) ;
1772 case SUPERV::ToKillState : {
1773 SendEvent( GraphExecutor::KillEvent ) ;
1776 case SUPERV::ToKillDoneState : {
1777 SendEvent( GraphExecutor::KillEvent ) ;
1780 case SUPERV::ToStopState : {
1781 SendEvent( GraphExecutor::StopEvent ) ;
1785 cdebug << ThreadNo()
1786 << " GraphExecutor::InNodeThreads::Executing_ErrorAction Error Undefined Control : "
1787 << aControl << endl ;
1791 cdebug << ThreadNo() << " <-- Executing_ErrorAction " << Name() << endl;
1795 // Set SUPERV::WaitingState to all InPorts
1796 void GraphExecutor::InNode::SetWaitingStates(GraphExecutor::InNode * EndNode ) {
1799 bool docdebug = false ;
1800 State( GraphExecutor::DataWaitingState ) ;
1801 for ( i = 0 ; i < GetNodeInPortsSize() ; i++ ) {
1802 GraphBase::InPort * anInPort = GetChangeNodeInPort( i ) ;
1803 cdebug << "SetWaitingStates InPort " << Name() << "( " << anInPort->PortName() << " ) "
1804 << anInPort->PortStatus() << " " << anInPort->State() << endl ;
1805 // JR Debug 07.01.2005 : Close the Gates instead of open !!!
1806 if ( anInPort->IsGate() ) { // Loop : Close the doors
1807 GraphBase::OutPort * anOutPort = anInPort->GetOutPort() ;
1809 CORBA::Any * anAny = new CORBA::Any() ;
1810 // *anAny <<= (long ) 1 ;
1811 *anAny <<= (long ) 0 ;
1812 anOutPort->Value( anAny ) ;
1813 anInPort->State( SUPERV::WaitingState ) ;
1816 else if ( anInPort->State() != SUPERV::WaitingState &&
1817 !anInPort->IsDataConnected() ) {
1819 cdebug << ThreadNo()
1820 << " --> GraphExecutor::InNodeThreads::SetWaitingStates " << Name() << endl;
1823 if ( !anInPort->IsDataStream() ) {
1824 anInPort->State( SUPERV::WaitingState ) ;
1827 cdebug << " --> " << Name() << "( " << anInPort->PortName() << " ) "
1828 << anInPort->PortStatus() << " " << anInPort->State() << endl ;
1830 for ( i = 0 ; i < GetNodeOutPortsSize() ; i++ ) {
1831 GraphBase::OutPort * anOutPort = GetChangeNodeOutPort( i ) ;
1832 for ( j = 0 ; j < anOutPort->InPortsSize() ; j++ ) {
1833 if ( !( IsGOTONode() && anOutPort->IsGate() ) &&
1834 !( IsEndLoopNode() && ( anOutPort->IsGate() || anOutPort->IsLoop() ) ) &&
1835 !anOutPort->IsDataStream() &&
1836 !anOutPort->ChangeInPorts( j )->IsDataStream() &&
1837 !anOutPort->ChangeInPorts( j )->IsExternConnected() ) {
1838 cdebug << ThreadNo()
1839 << " InNodeThreads::SetWaitingStates OutPort "
1840 << Name() << "/" << anOutPort->ChangeInPorts( j )->NodeName() << "( "
1841 << anOutPort->PortName() << " " << anOutPort->PortStatus() << " ) --> InPort "
1842 << anOutPort->ChangeInPorts( j )->NodeName() << "( "
1843 << anOutPort->ChangeInPorts( j )->PortName() << " "
1844 << anOutPort->ChangeInPorts( j )->PortStatus() << " )" << endl;
1845 if ( strcmp( anOutPort->ChangeInPorts( j )->GetOutPort()->NodeName() , Name() ) ) {
1846 // After EndLoopNode or GOTONode the Input Ports of LoopNode or LabelNode have their values from
1847 // EndLoopNode or GOTONode. But if there is several nested loops we should re-establish.
1848 cdebug << ThreadNo()
1849 << " InNodeThreads::SetWaitingStates OutPort->ChangeInPorts( j )->OutPort()->NodeName "
1850 << anOutPort->ChangeInPorts( j )->GetOutPort()->NodeName() << " != "
1851 << Name() << " : Restored to " << anOutPort->NodeName() << "( "
1852 << anOutPort->PortName() << " )" << endl ;
1853 anOutPort->ChangeInPorts( j )->ChangeOutPort( anOutPort ) ;
1855 GraphExecutor::InNode * aNode = (GraphExecutor::InNode * ) _OutNode->Graph()->GetChangeGraphNode( anOutPort->ChangeInPorts( j )->NodeName() )->GetInNode() ;
1856 if ( aNode != EndNode ) {
1857 aNode->SetWaitingStates( EndNode ) ;
1864 int GraphExecutor::InNode::Successed_SuccessAction() {
1865 cdebug << ThreadNo() << " --> Successed_SuccessAction " << Name() << endl;
1867 int linkednodesnumber = LinkedNodesSize() ;
1868 GraphExecutor::InNode *firstzeroNode = NULL ;
1869 GraphExecutor::InNode *firsttoNode = NULL ;
1870 GraphExecutor::InNode *toNode ;
1873 list<GraphExecutor::InNode *> SomeDataNodes ;
1877 if ( IsMacroNode() ) {
1878 cdebug << ThreadNo() << " Successed_SuccessAction " << Name() << " LinkedNodes->SomeDataReady already done"
1883 if ( IsGOTONode() ||
1884 ( IsEndLoopNode() && GetNodeInLoop()->GetOutPort()->BoolValue() ) ) {
1885 cdebug << ThreadNo() << " Successed_SuccessAction " << Name()
1886 << " SetWaitingStates " << endl ;
1887 const GraphBase::OutPort * aGateOutPort ;
1888 if ( IsGOTONode() ) {
1889 aGateOutPort = GetNodeOutGate() ;
1892 aGateOutPort = GetNodeOutLoop() ;
1894 if ( aGateOutPort->InPortsSize() != 1 ) {
1895 cdebug << ThreadNo() << " Successed_SuccessAction aGateOutPort->InPortsSize "
1896 << aGateOutPort->InPortsSize() << " != 1 ERROR " << Name() << endl ;
1898 GraphExecutor::InNode * aLabelNode = NULL ;
1899 for ( i = 0 ; i < aGateOutPort->InPortsSize() ; i++ ) {
1900 const GraphBase::InPort * anInPort = aGateOutPort->InPorts( i ) ;
1901 aLabelNode = (GraphExecutor::InNode *) _OutNode->Graph()->GetChangeGraphNode( anInPort->NodeName() )->GetInNode() ;
1902 cdebug << ThreadNo() << " Successed_SuccessAction " << Name() << " will Loop to HeadNode "
1903 << aLabelNode->Name() << " from port " << anInPort->PortName() << endl ;
1904 aLabelNode->SetWaitingStates( this ) ;
1905 // JR 07.01.2005 Debug : Open the Gate of the coupledNode closed by SetWaitingStates
1906 GraphBase::OutPort * anOutPort = aLabelNode->GetChangeNodeInGate()->GetOutPort() ;
1908 CORBA::Any * anAny = new CORBA::Any() ;
1909 *anAny <<= (long ) 1 ;
1910 anOutPort->Value( anAny ) ;
1911 aLabelNode->GetChangeNodeInGate()->State( SUPERV::ReadyState ) ;
1913 for ( j = 0 ; j < aLabelNode->GetNodeInPortsSize() ; j++ ) {
1914 const GraphBase::InPort * anInPort = aLabelNode->GetNodeInPort( j ) ;
1915 if ( anInPort->GetOutPort() ) {
1916 cdebug << aLabelNode->Name() << "(" << anInPort->PortName() << ") value : "
1917 << anInPort->GetOutPort()->NodeName() << "(" << anInPort->GetOutPort()->PortName() << ")"
1921 for ( j = 0 ; j < GetNodeOutPortsSize() ; j++ ) {
1922 GraphBase::OutPort * aBusParamOutPort = GetChangeNodeOutPort( j ) ;
1923 if ( !aBusParamOutPort->IsGate() ) {
1924 GraphBase::InPort * aBusParamChangeInPort = NULL ;
1925 if ( aBusParamOutPort->IsLoop() ) {
1926 // For EndLoop do not copy EndLoop(DoLoop) in Loop(InLoop)
1927 // aBusParamChangeInPort = aLabelNode->GetChangeNodeInLoop() ;
1930 aBusParamChangeInPort = aLabelNode->GetChangeInPort( aBusParamOutPort->PortName() ) ;
1932 if ( aBusParamChangeInPort ) {
1933 aBusParamChangeInPort->ChangeOutPort( aBusParamOutPort ) ;
1934 cdebug << ThreadNo() << " Successed_SuccessAction " << Name() << " ChangeOutPort to HeadNode "
1935 << aLabelNode->Name() << "(" << aBusParamChangeInPort->PortName() << ") from port "
1936 << aBusParamOutPort->PortName() << endl ;
1942 if ( aLabelNode && !aLabelNode->IsLockedDataWait() ) {
1943 res = aLabelNode->SendSomeDataReady( Name() ) ;
1945 if ( firsttoNode == NULL &&
1946 aLabelNode->ThreadNo() == pthread_self() ) {
1947 firsttoNode = aLabelNode ;
1948 cdebug << ThreadNo() << " Successed_SuccessAction firsttoNode "
1949 << aLabelNode->Name() << endl ;
1951 else if ( firstzeroNode == NULL &&
1952 aLabelNode->ThreadNo() == 0 ) {
1953 firstzeroNode = aLabelNode ;
1956 SomeDataNodes.push_back( aLabelNode ) ;
1957 cdebug << ThreadNo() << " Successed_SuccessAction " << Name() << " push "
1958 << aLabelNode->Name() << " " << SomeDataNodes.size()
1963 for ( j = 0 ; j < aLabelNode->GetNodeInPortsSize() ; j++ ) {
1964 const GraphBase::InPort * anInPort = aLabelNode->GetNodeInPort( j ) ;
1965 if ( anInPort->GetOutPort() ) {
1966 cdebug << aLabelNode->Name() << "(" << anInPort->PortName() << ") value : "
1967 << anInPort->GetOutPort()->NodeName() << "(" << anInPort->GetOutPort()->PortName() << ")"
1971 const GraphBase::InPort * aGateInPort = aLabelNode->GetNodeInGate() ;
1972 if ( aGateInPort ) {
1973 if ( aGateInPort->GetOutPort() ) {
1974 aGateInPort->GetOutPort()->Value( aGateOutPort->Value() ) ;
1976 if ( !aLabelNode->IsLockedDataWait() ) {
1977 res = aLabelNode->SendSomeDataReady( Name() ) ;
1979 if ( firsttoNode == NULL &&
1980 aLabelNode->ThreadNo() == pthread_self() ) {
1981 firsttoNode = aLabelNode ;
1982 cdebug << ThreadNo() << " Successed_SuccessAction firsttoNode "
1983 << aLabelNode->Name() << endl ;
1985 else if ( firstzeroNode == NULL &&
1986 aLabelNode->ThreadNo() == 0 ) {
1987 firstzeroNode = aLabelNode ;
1990 SomeDataNodes.push_back( aLabelNode ) ;
1991 cdebug << ThreadNo() << " Successed_SuccessAction " << Name() << " push "
1992 << aLabelNode->Name() << " " << SomeDataNodes.size()
1999 cdebug << ThreadNo() << " ERROR in Successed_SuccessAction of " << Name()
2000 << " NO port " << aGateOutPort->PortName() << " in "
2001 << aLabelNode->Name() << endl;
2007 cdebug << ThreadNo() << " Successed_SuccessAction of " << Name()
2008 << " with " << LinkedNodesSize() << " linked nodes :" ;
2009 for ( i = 0 ; i < LinkedNodesSize() ; i++ ) {
2010 if ( LinkedNodes( i )->IsDataFlowNode() ) {
2011 linkednodesnumber -= 1 ;
2013 cdebug << " " << LinkedNodes( i )->Name() ;
2016 for ( i = 0 ; i < LinkedNodesSize() ; i++ ) {
2017 bool IgnoreForEndLoop = false ;
2018 GraphBase::ComputingNode * aComputingNode ;
2019 aComputingNode = (GraphBase::ComputingNode * ) LinkedNodes( i ) ;
2020 toNode = (GraphExecutor::InNode *) aComputingNode->GetInNode() ;
2021 cdebug << ThreadNo() << " Successed_SuccessAction of " << Name()
2022 << " [" << i << "] " << LinkedNodes( i )->Name() << " toNode " << toNode << " IgnoreForEndLoop "
2023 << IgnoreForEndLoop ;
2025 cdebug << " " << toNode->Kind() << endl ;
2027 if ( toNode && !toNode->IsDataFlowNode() ) {
2028 if ( IsComputingNode() && toNode->IsInLineNode() ) {
2029 GraphBase::InPort * toGateInPort = toNode->GetChangeNodeInGate() ;
2030 toGateInPort->State( SUPERV::ReadyState ) ;
2031 GraphBase::OutPort * GateOutPort = toGateInPort->GetOutPort() ;
2032 if ( GateOutPort ) {
2033 GateOutPort->PortStatus( DataConnected );
2034 GateOutPort->State( SUPERV::ReadyState ) ;
2035 GateOutPort->Done( true ) ;
2039 if ( toNode && IsLoopNode() ) {
2040 GraphBase::OutPort * fromLoopOutPort = GetChangeNodeOutLoop() ;
2041 if ( !fromLoopOutPort->BoolValue() ) { // Ne pas faire la boucle
2042 if ( strcmp( toNode->Name() , CoupledNode()->Name() ) ) {
2043 IgnoreForEndLoop = true ;
2045 else { // toNode is the EndLoopNode
2046 GraphBase::InPort * toLoopInPort ;
2047 toLoopInPort = toNode->GetChangeNodeInLoop() ;
2048 if ( toLoopInPort->State() != SUPERV::ReadyState ) {
2049 toLoopInPort->State( SUPERV::ReadyState ) ;
2054 else if ( toNode && IsSwitchNode() ) {
2056 else if ( toNode && toNode->IsInLineNode() ) {
2058 for ( j = 0 ; j < toNode->GetNodeInPortsSize() ; j++ ) {
2059 toNode->GetChangeNodeInPort( j )->InitialOutPort() ;
2062 if ( toNode && !IgnoreForEndLoop ) {
2063 if ( toNode && toNode->IsLoopNode() ) {
2064 GraphBase::InPort * toLoopInPort = toNode->GetChangeNodeInLoop() ;
2065 toLoopInPort->State( SUPERV::ReadyState ) ;
2066 GraphBase::OutPort * LoopOutPort = toLoopInPort->GetOutPort() ;
2067 LoopOutPort->PortStatus( DataConnected );
2068 LoopOutPort->State( SUPERV::ReadyState ) ;
2069 LoopOutPort->Done( true ) ;
2070 CORBA::Any * anAny = new CORBA::Any() ; // InitLoop
2071 *anAny <<= (long ) 1 ;
2072 LoopOutPort->Value( anAny ) ;
2074 for ( j = 0 ; j < toNode->GetNodeInPortsSize() ; j++ ) {
2075 toNode->GetChangeNodeInPort( j )->InitialOutPort() ;
2078 cdebug << ThreadNo() << " Successed_SuccessAction " << toNode->Name() << "->SendSomeDataReady( "
2079 << Name() << " )" << endl ;
2080 res = toNode->SendSomeDataReady( Name() ) ;
2082 if ( firsttoNode == NULL &&
2083 toNode->ThreadNo() == pthread_self() ) {
2084 firsttoNode = toNode ;
2085 cdebug << ThreadNo() << " Successed_SuccessAction firsttoNode "
2086 << toNode->Name() << endl ;
2088 else if ( firstzeroNode == NULL &&
2089 toNode->ThreadNo() == 0 ) {
2090 firstzeroNode = toNode ;
2093 SomeDataNodes.push_back( toNode ) ;
2094 cdebug << ThreadNo() << " Successed_SuccessAction " << Name() << " push "
2095 << toNode->Name() << " " << SomeDataNodes.size() << endl ;
2102 if ( firsttoNode == NULL && firstzeroNode ) {
2103 firsttoNode = firstzeroNode ;
2104 cdebug << ThreadNo()
2105 << " Successed_SuccessAction firsttoNode = firstzeroNode "
2108 else if ( firsttoNode && firstzeroNode ) {
2109 SomeDataNodes.push_back( firstzeroNode ) ;
2110 cdebug << ThreadNo() << " Successed_SuccessAction " << Name() << " push firstzeroNode "
2111 << firstzeroNode->Name() << " " << SomeDataNodes.size() << endl ;
2114 cdebug << ThreadNo() << " Successed_SuccessAction " << Name() << " firsttoNode " << firsttoNode
2115 << " firstzeroNode " << firstzeroNode << endl ;
2118 while ( SomeDataNodes.size() ) {
2119 GraphExecutor::InNode *aNode = SomeDataNodes.front() ;
2120 SomeDataNodes.pop_front() ;
2121 // cdebug << pthread_self() << "/" << ThreadNo()
2122 // << " Successed_SuccessAction pop "
2123 // << SomeDataNodes.size() << " " << aNode->Name() << endl ;
2124 if ( aNode->State() == GraphExecutor::DataReadyState ) {
2125 aNode->CreateNewThreadIf( true ) ;
2126 aNode->UnLockDataWait() ;
2127 res = aNode->DataUndef_AllDataReadyAction() ;
2130 // cdebug << pthread_self() << "/" << ThreadNo() << " ERROR "
2131 // << aNode->Name() << " "
2132 // << Automaton()->StateName( aNode->State() ) << endl ;
2136 if ( firsttoNode ) {
2137 // cdebug << pthread_self() << "/" << ThreadNo()
2138 // << " Successed_SuccessAction start firsttoNode "
2139 // << SomeDataNodes.size() << " " << firsttoNode->Name() << endl ;
2140 firsttoNode->CreateNewThreadIf( false ) ;
2141 firsttoNode->RewindStack( RewindStack() ) ;
2142 if ( firsttoNode->State() == GraphExecutor::SuccessedState ) {
2143 // cdebug << pthread_self() << "/" << ThreadNo() << " " << Name()
2144 // << " : " << firsttoNode->Name() << " "
2145 // << Automaton()->StateName( firsttoNode->State() )
2146 // << " --> DataWaitingState for Thread "
2147 // << firsttoNode->ThreadNo() << endl ;
2148 firsttoNode->State( GraphExecutor::DataWaitingState ) ;
2150 // pthread_t OldT = firsttoNode->ThreadNo() ;
2151 firsttoNode->ThreadNo( pthread_self() ) ;
2152 // On continue avec le meme thread
2153 // cdebug << pthread_self() << "/" << ThreadNo() << " firsttoNode "
2154 // << firsttoNode->Name() << "Thread(" << OldT << "-->"
2155 // << firsttoNode->ThreadNo() << ")" << endl ;
2157 // cdebug << ThreadNo() << " Successed_SuccessAction " << Name()
2158 // << " for " << firsttoNode->Name()
2159 // << " !firsttoNode->CreateNewThreadIf() "
2160 // << !firsttoNode->CreateNewThreadIf()
2161 // << " " << Automaton()->StateName( firsttoNode->State() ) ;
2162 if ( firsttoNode->State() == GraphExecutor::DataReadyState ) {
2164 firsttoNode->UnLockDataWait() ;
2165 res = firsttoNode->DataUndef_AllDataReadyAction() ;
2168 cdebug << " ERROR " << endl ;
2172 // cdebug << ThreadNo() << " Successed_SuccessAction " << Name()
2173 // << " NO DataReady ==> ThreadNo( 0 ) firsttoNode == NULL LINKEDnodesnumber " << linkednodesnumber << endl ;
2177 // if ( linkednodesnumber == 0 && firsttoNode == NULL ) {
2178 // cdebug << ThreadNo() << " Successed_SuccessAction " << Name() << " LinkedNodesSize " << LinkedNodesSize()
2179 // << " firsttoNode == NULL LINKEDnodesnumber " << linkednodesnumber << " CHECK" << endl ;
2180 // _OutNode->CheckAllDone() ;
2183 // cdebug << pthread_self() << "/" << ThreadNo()
2184 // << " <-- Successed_SuccessAction " << Name() << " linkednodesnumber "
2185 // << linkednodesnumber << endl;
2189 bool GraphExecutor::InNode::SendSomeDataReady( char * FromNodeName ) {
2190 bool RetVal = false ;
2191 if ( IsDataFlowNode() ) {
2192 cdebug << ThreadNo() << "InNode::SendSomeDataReady ----> " << Name()
2193 << " send Result to graph " << Name() << endl;
2196 // cdebug << pthread_self() << "/" << ThreadNo() << " ----> " << FromNodeName
2197 // << " send SomeDataReady to " << Name() << " "
2198 // << Automaton()->StateName( State() )
2199 // << " CreateNewThreadIf() " << CreateNewThreadIf()
2200 // << " LockedDataWait " << IsLockedDataWait() << endl;
2202 //cout << pthread_self() << "/" << ThreadNo() << " ----> " << FromNodeName
2203 << " send SomeDataReady to " << Name() << " "
2204 << Automaton()->StateName( State() )
2205 << " CreateNewThreadIf() " << CreateNewThreadIf()
2206 << " LockedDataWait " << IsLockedDataWait() << endl;
2208 if ( State() == GraphExecutor::SuccessedState ||
2209 State() == GraphExecutor::SuspendedSuccessedState ||
2210 State() == GraphExecutor::SuspendedSuccessedToReStartState ) {
2211 // cdebug << ThreadNo() << " " << FromNodeName
2212 // << " : " << Name() << " " << Automaton()->StateName( State() )
2213 // << " --> DataWaitingState for Thread "
2214 // << ThreadNo() << " " << endl ;
2215 State( GraphExecutor::DataWaitingState ) ;
2217 // We begin that LoopNode if SendSomeDataReady does not come from the corresponding EndLoopNode
2218 if ( IsLoopNode() && strcmp( LoopNode()->CoupledNodeName() , FromNodeName ) ) {
2219 cdebug << ThreadNo() << "InNode::SendSomeDataReady " << Name() << " Set _InitLoop from "
2220 << FromNodeName << endl ;
2224 DataFromNode( FromNodeName ) ;
2225 RetVal = !SendEvent( GraphExecutor::SomeDataReadyEvent );
2233 int GraphExecutor::InNode::Errored_ErrorAction() {
2234 cdebug << ThreadNo() << " Errored_ErrorAction " << Name()
2235 << " will pthread_exit" << endl;
2240 int GraphExecutor::InNode::Successed_SuspendAction() {
2241 cdebug << ThreadNo() << " Successed_SuspendAction -->Suspend " << Name()
2242 << " Threads " << _OutNode->Threads() << " SuspendedThreads "
2243 << _OutNode->SuspendedThreads() << endl;
2244 _OutNode->PushEvent( this , GraphExecutor::SuspendedSuccessedEvent ,
2245 GraphExecutor::SuspendedSuccessedState ) ;
2247 GraphExecutor::InNode * aReStartNode = SuspendAction() ;
2248 cdebug << ThreadNo() << " Successed_SuspendAction Resumed " << Name() ;
2249 if ( aReStartNode ) {
2250 _aReStartNode = NULL ;
2251 cdebug << " for " << aReStartNode->Name() << endl;
2252 aReStartNode->SendEvent( _aReStartEvent ) ;
2256 SendEvent( GraphExecutor::ResumeEvent ) ;
2261 int GraphExecutor::InNode::Errored_SuspendAction() {
2262 cdebug << ThreadNo() << " Errored_SuspendAction -->Suspend " << Name()
2263 << " Threads " << _OutNode->Threads() << " SuspendedThreads "
2264 << _OutNode->SuspendedThreads() << endl;
2265 _OutNode->PushEvent( this , GraphExecutor::SuspendedErroredEvent ,
2266 GraphExecutor::SuspendedErroredState ) ;
2268 GraphExecutor::InNode * aReStartNode = SuspendAction() ;
2269 cdebug << ThreadNo() << " Errored_SuspendAction Resumed " << Name()
2271 if ( aReStartNode ) {
2272 _aReStartNode = NULL ;
2273 aReStartNode->SendEvent( _aReStartEvent ) ;
2276 SendEvent( GraphExecutor::ResumeEvent ) ;
2281 int GraphExecutor::InNode::SuspendedSuccessed_ResumeAction() {
2282 cdebug << ThreadNo() << " SuspendedSuccessed_ResumeAction " << Name() << endl;
2284 _OutNode->PushEvent( this , GraphExecutor::ResumedSuccessedEvent ,
2285 GraphExecutor::ResumedSuccessedState ) ;
2286 SendEvent( ResumedSuccessedEvent ) ;
2290 int GraphExecutor::InNode::SuspendedErrored_ResumeAction() {
2291 cdebug << ThreadNo() << " SuspendedErrored_ResumeAction " << Name() << endl;
2293 _OutNode->PushEvent( this , GraphExecutor::ResumedErroredEvent ,
2294 GraphExecutor::ResumedErroredState ) ;
2295 SendEvent( ResumedErroredEvent ) ;
2299 int GraphExecutor::InNode::Successed_KillAction() {
2301 _OutNode->PushEvent( this , GraphExecutor::KilledEvent ,
2302 GraphExecutor::KilledSuccessedState ) ;
2303 cdebug << ThreadNo() << " Successed_KillAction " << Name() << endl;
2307 int GraphExecutor::InNode::Errored_KillAction() {
2309 _OutNode->PushEvent( this , GraphExecutor::KilledEvent ,
2310 GraphExecutor::KilledErroredState ) ;
2311 cdebug << ThreadNo() << " Errored_KillAction " << Name() << endl;
2315 int GraphExecutor::InNode::Successed_StopAction() {
2317 _OutNode->PushEvent( this , GraphExecutor::StoppedEvent ,
2318 GraphExecutor::StoppedSuccessedState ) ;
2319 cdebug << ThreadNo() << " Successed_StopAction " << Name() << endl;
2323 int GraphExecutor::InNode::Errored_StopAction() {
2325 _OutNode->PushEvent( this , GraphExecutor::StoppedEvent ,
2326 GraphExecutor::StoppedErroredState ) ;
2327 cdebug << ThreadNo() << " Errored_StopAction " << Name() << endl;
2331 int GraphExecutor::InNode::SuspendedSuccessed_ReStartAction() {
2332 cdebug << ThreadNo() << " SuspendedSuccessed_ReStartAction " << Name() << endl;
2333 _OutNode->PushEvent( this , GraphExecutor::ReStartedEvent ,
2334 GraphExecutor::ReStartedState ) ;
2336 for ( i = 0 ; i < GetNodeInPortsSize() ; i++ ) {
2337 GetChangeNodeInPort( i )->State( SUPERV::ReadyState ) ;
2339 SendEvent( ExecuteEvent ) ;
2340 cdebug << ThreadNo() << " SuspendedSuccessed_ReStartAction " << Name() << endl;
2344 int GraphExecutor::InNode::SuspendedErrored_ReStartAction() {
2345 cdebug << ThreadNo() << " SuspendedErrored_ReStartAction " << Name() << endl;
2346 _OutNode->PushEvent( this , GraphExecutor::ReStartedEvent ,
2347 GraphExecutor::ReStartedState ) ;
2349 for ( i = 0 ; i < GetNodeInPortsSize() ; i++ ) {
2350 GetChangeNodeInPort( i )->State( SUPERV::ReadyState ) ;
2352 SendEvent( ExecuteEvent ) ;
2353 cdebug << ThreadNo() << " SuspendedErrored_ReStartAction " << Name() << endl;
2357 int GraphExecutor::InNode::SuspendedSuccessed_ReStartAndSuspendAction() {
2358 cdebug << ThreadNo() << " SuspendedSuccessed_ReStartAndSuspendAction " << Name()
2360 _OutNode->PushEvent( this , GraphExecutor::ReStartedAndSuspendEvent ,
2361 GraphExecutor::ReStartedState ) ;
2362 State( GraphExecutor::DataWaitingState ) ;
2364 cdebug << "InNode::Suspend() Node " << Name() << endl ;
2367 else if ( SendEvent( GraphExecutor::SomeDataReadyEvent ) ) {
2368 cdebug << "InNode::SendEvent( SomeDataReadyEvent ) Node "
2372 cdebug << ThreadNo() << " SuspendedSuccessed_ReStartAndSuspendAction " << Name()
2377 int GraphExecutor::InNode::SuspendedErrored_ReStartAndSuspendAction() {
2378 cdebug << ThreadNo() << " SuspendedErrored_ReStartAndSuspendAction " << Name()
2380 _OutNode->PushEvent( this , GraphExecutor::ReStartedAndSuspendEvent ,
2381 GraphExecutor::ReStartedState ) ;
2382 State( GraphExecutor::DataWaitingState ) ;
2384 cdebug << "InNode::Suspend() Node " << Name() << endl ;
2387 else if ( SendEvent( GraphExecutor::SomeDataReadyEvent ) ) {
2388 cdebug << "InNode::SendEvent( SomeDataReadyEvent ) Node "
2392 cdebug << ThreadNo() << " SuspendedErrored_ReStartAndSuspendAction " << Name()
2397 void GraphExecutor::InNode::InParametersSet( bool & Err ,
2399 ServicesAnyData * InParametersList ) {
2401 cdebug << ThreadNo() << " InParametersSet " << Name() << endl ;
2402 for ( i = 0 ; i < nInParams ; i++ ) {
2403 ServicesAnyData D = InParametersList[i];
2404 GraphBase::InPort * anInPort = GetChangeNodeInPort(i) ;
2405 GraphBase::OutPort * theOutPort = anInPort->GetOutPort() ;
2406 if ( anInPort->IsGate() && theOutPort == NULL ) {
2407 cdebug << ThreadNo() << " ArgIn" << i << " " << D.Name << " "
2408 << anInPort->GetServicesParameter().Parametertype
2409 << " is inactive. " << anInPort->Kind() << endl ;
2411 else if ( anInPort->State() == SUPERV::ReadyState ) {
2412 if ( anInPort->IsGate() ) {
2413 CORBA::Any * anAny = new CORBA::Any() ;
2414 *anAny <<= (long ) 0 ;
2415 theOutPort->Value( anAny ) ;
2417 if ( !anInPort->IsDataStream() &&
2418 !anInPort->IsDataConnected() ) {
2419 anInPort->State( SUPERV::WaitingState ) ;
2421 D.Name = CORBA::string_dup( anInPort->GetServicesParameter().Parametername ) ;
2422 cdebug << ThreadNo() << " ArgIn" << i << " " << anInPort->Kind()
2423 << " " << anInPort->State() ;
2424 cdebug << " " << D.Name << " " << anInPort->GetServicesParameter().Parametertype << " : " ;
2425 D.Value = *theOutPort->Value() ; // CORBA::Any
2426 string _Type = CORBA::string_dup( anInPort->GetServicesParameter().Parametertype ) ;
2427 const char * Type = _Type.c_str() ;
2428 switch ( D.Value.type()->kind() ) { // { string , long , double , objref }
2429 case CORBA::tk_string:
2432 cdebug << t << " (string)" ;
2433 if ( !strcmp( Type , "string" ) ) {
2435 else if ( !strcmp( Type , "boolean" ) ) {
2438 sscanf( t , "%ld" , &d ) ;
2440 D.Value <<= (CORBA::Any::from_boolean ) b ;
2441 // theOutPort->Value( D.Value ) ;
2443 else if ( !strcmp( Type , "char" ) ) {
2446 sscanf( t , "%ld" , &d ) ;
2448 D.Value <<= (CORBA::Any::from_char ) c ;
2449 cdebug << "string '" << t << "' --> " << d << " --> char " << c ;
2450 // theOutPort->Value( D.Value ) ;
2452 else if ( !strcmp( Type , "short" ) ) {
2455 sscanf( t , "%ld" , &d ) ;
2458 cdebug << "string '" << t << "' --> " << d << " --> short " << s ;
2459 // theOutPort->Value( D.Value ) ;
2461 else if ( !strcmp( Type , "int" ) || !strcmp( Type , "long" ) ) {
2463 sscanf( t , "%ld" , &l ) ;
2465 cdebug << "string '" << t << " --> long " << l ;
2466 // theOutPort->Value( D.Value ) ;
2468 else if ( !strcmp( Type , "float" ) ) {
2470 sscanf( t , "%lf" , &d ) ;
2473 cdebug << "string '" << t << "' --> " << setw(25) << setprecision(18) << d << " --> float " << " = "
2474 << setw(25) << setprecision(18) << f ;
2475 // theOutPort->Value( D.Value ) ;
2477 else if ( !strcmp( Type , "double" ) ) {
2479 sscanf( t , "%lf" , &d ) ;
2481 cdebug << "string '" << t << " --> double " << setw(25) << setprecision(18) << d ;
2482 // theOutPort->Value( D.Value ) ;
2484 // else if ( !strcmp( Type , "objref" ) ) {
2486 CORBA::Object_ptr ObjRef ;
2488 ObjRef = StringToObject( t ) ;
2489 D.Value <<= ObjRef ;
2492 D.Value <<= CORBA::Object::_nil() ;
2494 // theOutPort->Value( D.Value ) ;
2497 // cdebug << " (other ERROR)" << endl ;
2499 cdebug << " --> call_kind " << D.Value.type()->kind() << endl ;
2501 case CORBA::tk_long:
2504 cdebug << l << " (long)" << endl ;
2505 if ( !strcmp( Type , "string" ) ) {
2507 sprintf( t , "%ld" , l ) ;
2509 // theOutPort->Value( D.Value ) ;
2511 else if ( !strcmp( Type , "boolean" ) ) {
2514 D.Value <<= (CORBA::Any::from_boolean ) b ;
2515 // theOutPort->Value( D.Value ) ;
2517 else if ( !strcmp( Type , "char" ) ) {
2519 c = (unsigned char ) l ;
2520 D.Value <<= (CORBA::Any::from_char ) c ;
2521 // theOutPort->Value( D.Value ) ;
2523 else if ( !strcmp( Type , "short" ) ) {
2527 // theOutPort->Value( D.Value ) ;
2529 else if ( !strcmp( Type , "int" ) || !strcmp( Type , "long" ) ) {
2531 else if ( !strcmp( Type , "float" ) ) {
2535 // theOutPort->Value( D.Value ) ;
2537 else if ( !strcmp( Type , "double" ) ) {
2541 // theOutPort->Value( D.Value ) ;
2543 // else if ( !strcmp( Type , "objref" ) ) {
2545 D.Value <<= CORBA::Object::_nil() ;
2546 // theOutPort->Value( D.Value ) ;
2549 // cdebug << " (other ERROR)" << endl ;
2551 cdebug << " --> call_kind " << D.Value.type()->kind() << endl ;
2553 case CORBA::tk_double:
2556 cdebug << d << " (double)" << endl ;
2557 if ( !strcmp( Type , "string" ) ) {
2559 sprintf( t , "%lf" , d ) ;
2561 // theOutPort->Value( D.Value ) ;
2563 else if ( !strcmp( Type , "boolean" ) ) {
2566 D.Value <<= (CORBA::Any::from_boolean ) b ;
2567 // theOutPort->Value( D.Value ) ;
2569 else if ( !strcmp( Type , "char" ) ) {
2571 c = (unsigned char ) d ;
2572 D.Value <<= (CORBA::Any::from_char ) c ;
2573 // theOutPort->Value( D.Value ) ;
2575 else if ( !strcmp( Type , "short" ) ) {
2579 // theOutPort->Value( D.Value ) ;
2581 else if ( !strcmp( Type , "int" ) || !strcmp( Type , "long" ) ) {
2585 // theOutPort->Value( D.Value ) ;
2587 else if ( !strcmp( Type , "float" ) ) {
2591 // theOutPort->Value( D.Value ) ;
2593 else if ( !strcmp( Type , "double" ) ) {
2595 // else if ( !strcmp( Type , "objref" ) ) {
2597 D.Value <<= CORBA::Object::_nil() ;
2598 // theOutPort->Value( D.Value ) ;
2601 // cdebug << " (other ERROR)" << endl ;
2603 cdebug << " --> call_kind " << D.Value.type()->kind() << endl ;
2605 case CORBA::tk_objref:
2606 if ( !strcmp( Type , "string" ) ) {
2607 CORBA::Object_ptr ObjRef ;
2610 D.Value >>= ObjRef ;
2611 retstr = ObjectToString( ObjRef ) ;
2612 D.Value <<= retstr ;
2613 // theOutPort->Value( D.Value ) ;
2619 cdebug << "ToString( object ) Catched ERROR" << endl ;
2622 else if ( !strcmp( Type , "boolean" ) ) {
2624 D.Value <<= (CORBA::Any::from_boolean ) b ;
2625 // theOutPort->Value( D.Value ) ;
2627 else if ( !strcmp( Type , "char" ) ) {
2628 unsigned char c = 0 ;
2629 D.Value <<= (CORBA::Any::from_char ) c ;
2630 // theOutPort->Value( D.Value ) ;
2632 else if ( !strcmp( Type , "short" ) ) {
2635 // theOutPort->Value( D.Value ) ;
2637 else if ( !strcmp( Type , "int" ) || !strcmp( Type , "long" ) ) {
2640 // theOutPort->Value( D.Value ) ;
2642 else if ( !strcmp( Type , "float" ) ) {
2645 // theOutPort->Value( D.Value ) ;
2647 else if ( !strcmp( Type , "double" ) ) {
2650 // theOutPort->Value( D.Value ) ;
2652 // else if ( !strcmp( Type , "objref" ) ) {
2654 CORBA::Object_ptr obj ;
2658 retstr = ObjectToString( obj ) ;
2659 cdebug << retstr << endl ;
2665 cdebug << "ToString( object ) Catched ERROR" << endl ;
2669 // cdebug << " (other ERROR)" << endl ;
2671 cdebug << " --> call_kind " << D.Value.type()->kind() << endl ;
2674 cdebug << " (other ERROR) " << D.Value.type()->kind() << endl ;
2678 cdebug << ThreadNo() << " In" << i << " : wrong state ERROR State "
2679 << anInPort->State() << " NameState "
2680 << Automaton()->StateName( anInPort->State() ) << " PortName "
2681 << anInPort->PortName() << " Parametername "
2682 << anInPort->GetServicesParameter().Parametername << endl ;
2685 InParametersList[i] = D ;
2689 void GraphExecutor::InNode::InOutParametersSet( int nOutParams ,
2690 ServicesAnyData * OutParametersList ) {
2692 for ( i = 0 ; i < nOutParams ; i++ ) {
2693 ServicesAnyData D = OutParametersList[i] ;
2695 D.Name = GetChangeNodeOutPort(i)->GetServicesParameter().Parametername;
2696 string _Type = CORBA::string_dup(GetChangeNodeOutPort(i)->GetServicesParameter().Parametertype) ;
2697 const char * Type = _Type.c_str() ;
2698 bool OutDone = GetChangeNodeOutPort(i)->Done() ;
2699 cdebug << ThreadNo() << " ArgOut" << i << " " << D.Name << " Done("
2700 << OutDone << ") " << Type << " : " << endl ;
2701 if ( !strcmp( Type , "string" ) ) {
2702 D.Value <<= (char *) NULL ;
2704 else if ( !strcmp( Type , "boolean" ) ) {
2706 D.Value <<= (CORBA::Any::from_boolean ) b ;
2708 else if ( !strcmp( Type , "char" ) ) {
2709 unsigned char c = 0 ;
2710 D.Value <<= (CORBA::Any::from_char ) c ;
2712 else if ( !strcmp( Type , "short" ) ) {
2716 else if ( !strcmp( Type , "int" ) || !strcmp( Type , "long" ) ) {
2717 D.Value <<= (long ) 0 ;
2719 else if ( !strcmp( Type , "float" ) ) {
2723 else if ( !strcmp( Type , "double" ) ) {
2728 D.Value <<= CORBA::Object::_nil() ;
2731 switch (D.Value.type()->kind()) { // { string , long , double , objref }
2732 case CORBA::tk_string:
2735 cdebug << ThreadNo() << " " << t << "(string)" << endl ;
2737 case CORBA::tk_boolean:
2739 D.Value >>= (CORBA::Any::to_boolean ) b;
2740 cdebug << ThreadNo() << " " << b << "(boolean)" << endl ;
2742 case CORBA::tk_char:
2744 D.Value >>= (CORBA::Any::to_char ) c;
2745 cdebug << ThreadNo() << " " << c << "(char)" << endl ;
2747 case CORBA::tk_short:
2750 cdebug << ThreadNo() << " " << s << "(short)" << endl ;
2752 case CORBA::tk_long:
2755 cdebug << ThreadNo() << " " << l << "(long)" << endl ;
2757 case CORBA::tk_float:
2760 cdebug << ThreadNo() << " " << f << "(float)" << endl ;
2762 case CORBA::tk_double:
2765 cdebug << ThreadNo() << " " << d << "(double)" << endl ;
2767 case CORBA::tk_objref:
2769 CORBA::Object_ptr obj ;
2772 retstr = ObjectToString( obj ) ;
2773 cdebug << ThreadNo() << retstr << endl ;
2776 cdebug << "ToString( object ) Catched ERROR" << endl ;
2780 cdebug << ThreadNo() << " " << "(other ERROR)" << endl ;
2783 OutParametersList[i] = D ;
2787 bool GraphExecutor::InNode::OutParametersSet( bool Err ,
2788 SUPERV::GraphState NewState ,
2790 ServicesAnyData * OutParametersList ) {
2791 bool RetVal = true ;
2793 GraphBase::OutPort * aGateOutPort = NULL ;
2794 bool OrSwitch = false ;
2795 cdebug << "OutParametersSet " << Name() << " nOutParams " << nOutParams << " NewState " << NewState << endl ;
2796 // cout << "OutParametersSet " << Name() << " nOutParams " << nOutParams << " NewState " << NewState << endl ;
2797 if ( nOutParams && !IsMacroNode() ) {
2798 GraphBase::OutPort * anOutPort ;
2799 for ( i = 0 ; i < nOutParams ; i++ ) {
2800 anOutPort = GetChangeNodeOutPort(i) ;
2802 anOutPort->State( NewState ) ;
2803 anOutPort->Done( true ) ;
2806 cdebug << ThreadNo() << " " << "Out" << i << " " << Name() << " "
2807 << anOutPort->PortName() << " " << anOutPort->Kind() ;
2808 ServicesAnyData D = OutParametersList[i] ;
2809 switch (D.Value.type()->kind()) { // { string , long , double , objref }
2810 case CORBA::tk_string: {
2813 cdebug << ThreadNo() << " " << t << "(string)" << endl ;
2816 case CORBA::tk_boolean: {
2818 D.Value >>= (CORBA::Any::to_boolean ) b;
2819 long l = (long ) b ;
2821 cdebug << ThreadNo() << " " << b << "(boolean)" << endl ;
2824 case CORBA::tk_char: {
2826 D.Value >>= (CORBA::Any::to_char ) c;
2827 long l = (long ) c ;
2829 cdebug << ThreadNo() << " " << c << "(char)" << endl ;
2832 case CORBA::tk_short: {
2835 long l = (long ) s ;
2837 cdebug << ThreadNo() << " " << s << "(short)" << endl ;
2840 case CORBA::tk_long: {
2843 cdebug << ThreadNo() << " " << l << "(long)" << endl ;
2846 case CORBA::tk_float: {
2849 double d = (double ) f ;
2851 cdebug << ThreadNo() << " " << f << "(float)" << endl ;
2854 case CORBA::tk_double: {
2857 cdebug << ThreadNo() << " " << d << "(double)" << endl ;
2860 case CORBA::tk_objref: {
2862 CORBA::Object_ptr obj ;
2865 retstr = ObjectToString( obj ) ;
2866 cdebug << ThreadNo() << retstr << endl ;
2869 cdebug << "ToString( object ) Catched ERROR" << endl ;
2874 cdebug << ThreadNo() << " " << "(other ERROR)" << endl ;
2877 OutParametersList[i] = D ;
2878 if ( !anOutPort->IsDataStream() ) {
2879 if ( anOutPort->IsGate() ) {
2880 aGateOutPort = anOutPort ;
2881 cdebug << " Gate " ;
2883 OutParametersList[i].Value <<= l;
2884 anOutPort->Value( OutParametersList[i].Value );
2886 else if ( anOutPort->IsLoop() ) {
2887 cdebug << " Loop " ;
2888 anOutPort->Value( OutParametersList[i].Value );
2889 // InLoop Port of EndLoopNode is ready :
2890 anOutPort->ChangeInPorts(0)->State( SUPERV::ReadyState ) ;
2892 else if ( anOutPort->IsSwitch() ) {
2893 cdebug << " Switch " ;
2894 anOutPort->Value( OutParametersList[i].Value );
2895 if ( anOutPort->InPortsSize() && anOutPort->ChangeInPorts( 0 )->IsGate() ) {
2896 if ( OrSwitch && anOutPort->BoolValue() ) {
2897 cdebug << "GraphExecutor::InNodeThreads::OutParameters more than one switch is true WARNING"
2901 OrSwitch = OrSwitch | anOutPort->BoolValue() ;
2904 cdebug << "OrSwitch " << OrSwitch ;
2907 cdebug << " Param " ;
2908 anOutPort->Value( OutParametersList[i].Value );
2910 anOutPort->State( NewState ) ;
2911 anOutPort->Done( true ) ;
2914 for ( j = 0 ; j < anOutPort->InPortsSize() ; j++ ) {
2915 bool fromGOTO = false ;
2916 const char * ToNodeName = anOutPort->ChangeInPorts( j )->NodeName() ;
2917 if ( !strcmp( ToNodeName , _OutNode->Graph()->Name() ) && _OutNode->Graph()->GraphMacroLevel() != 0 ) {
2918 cdebug << "OutParametersSet ToNodeName " << _OutNode->Graph()->Name() << " CoupledNode "
2919 << _OutNode->Graph()->CoupledNodeName() << _OutNode->Graph()->CoupledNode()
2921 cdebug << " GraphExecutor " << _OutNode->Graph()->CoupledNode()->GraphEditor()->Executor() << endl ;
2922 _OutNode->Graph()->CoupledNode()->GraphEditor()->Executor()->OutputOfAny( _OutNode->Graph()->CoupledNodeName() ,
2923 anOutPort->ChangeInPorts( j )->PortName() ,
2924 *anOutPort->Value() ) ;
2927 GraphBase::ComputingNode * ToNode = _OutNode->Graph()->GetChangeGraphNode( ToNodeName ) ;
2929 // cout << "OutParametersSet ToNodeName " << ToNodeName << endl ;
2930 cdebug << "OutParametersSet ToNodeName " << ToNodeName << " " << ToNode->Name() << endl ;
2931 GraphBase::OutPort * aGOTOPort = ToNode->GetChangeNodeInGate()->GetOutPort() ;
2933 fromGOTO = aGOTOPort->IsGOTO() ;
2935 if ( anOutPort->ChangeInPorts( j )->IsEndSwitch() || fromGOTO ) {
2936 cdebug << anOutPort->ChangeInPorts( j )->NodeName() << "("
2937 << anOutPort->ChangeInPorts( j )->PortName() << ","
2938 << anOutPort->ChangeInPorts( j )->Kind() << ") WILL BE changed from "
2939 << anOutPort->ChangeInPorts( j )->GetOutPort()->NodeName()
2941 << anOutPort->ChangeInPorts( j )->GetOutPort()->PortName()
2942 << ") to " << anOutPort->NodeName() << "("
2943 << anOutPort->PortName() << ")" << endl ;
2944 anOutPort->ChangeInPorts( j )->ChangeOutPort( anOutPort ) ;
2947 cdebug << anOutPort->ChangeInPorts( j )->NodeName() << "("
2948 << anOutPort->ChangeInPorts( j )->PortName() << ","
2949 << anOutPort->ChangeInPorts( j )->Kind() << ") NOT changed from "
2950 << anOutPort->ChangeInPorts( j )->GetOutPort()->NodeName()
2952 << anOutPort->ChangeInPorts( j )->GetOutPort()->PortName()
2953 << ") to " << anOutPort->NodeName() << "("
2954 << anOutPort->PortName() << ")" << endl ;
2960 switch (anOutPort->Value()->type()->kind()) {
2961 case CORBA::tk_string:
2963 (*anOutPort->Value()) >>= t;
2964 cdebug << ThreadNo() << " Out" << i << " : " << t << "(string)" << endl ;
2966 case CORBA::tk_boolean:
2968 (*anOutPort->Value()) >>= (CORBA::Any::to_boolean ) b;
2969 cdebug << ThreadNo() << " Out" << i << " : " << b << "(boolean)" << endl ;
2971 case CORBA::tk_char:
2973 (*anOutPort->Value()) >>= (CORBA::Any::to_char ) c;
2974 cdebug << ThreadNo() << " Out" << i << " : " << c << "(char)" << endl ;
2976 case CORBA::tk_short:
2978 (*anOutPort->Value()) >>= s;
2979 cdebug << ThreadNo() << " Out" << i << " : " << s << "(short)" << endl ;
2981 case CORBA::tk_long:
2983 (*anOutPort->Value()) >>= l;
2984 cdebug << ThreadNo() << " Out" << i << " : " << l << "(long)" << endl ;
2986 case CORBA::tk_float:
2988 (*anOutPort->Value()) >>= f;
2989 cdebug << ThreadNo() << " Out" << i << " : " << f << "(float)" << endl ;
2991 case CORBA::tk_double:
2993 (*anOutPort->Value()) >>= d;
2994 cdebug << ThreadNo() << " Out" << i << " : " << d << "(double)" << endl ;
2996 case CORBA::tk_objref:
2997 CORBA::Object_ptr obj ;
3000 (*anOutPort->Value()) >>= obj ;
3001 retstr = ObjectToString( obj );
3002 cdebug << ThreadNo() << " Out" << i << " : " << "ToString( object ) "
3006 cdebug << ThreadNo() << " Out" << i << " : " << "ToString( object ) "
3007 << "Catched ERROR" << endl ;
3011 cdebug << ThreadNo() << " Out" << i << " : " << "(other ERROR)" << endl ;
3017 if ( aGateOutPort && IsSwitchNode() ) {
3019 // cdebug << ThreadNo() << " " << "Out0 " << Name() << " Close of "
3020 // << aGateOutPort->PortName() << " " << aGateOutPort->Kind() ;
3022 OutParametersList[0].Value <<= l ;
3023 aGateOutPort->Value( OutParametersList[0].Value ) ;
3026 // cdebug << ThreadNo() << " " << "Out0 " << Name() << " Open of "
3027 // << aGateOutPort->PortName() << " " << aGateOutPort->Kind() ;
3029 OutParametersList[0].Value <<= l ;
3030 aGateOutPort->Value( OutParametersList[0].Value ) ;
3032 for ( i = 0 ; i < GetNodeOutPortsSize() ; i++ ) {
3033 GraphBase::InPort * anInPort ;
3034 anInPort = CoupledNode()->GetChangeInPort( GetNodeOutPort( i )->PortName() ) ;
3036 anInPort->ChangeOutPort( GetChangeNodeOutPort( i ) ) ;