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.salome-platform.org/ or email : webmaster.salome@opencascade.com
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);
73 #define SendEventTrace 1
74 int GraphExecutor::InNode::SendEvent( const GraphExecutor::NodeEvent anEvent ) {
76 _CurrentEvent = (GraphExecutor::NodeEvent ) anEvent ;
78 cdebug_in << pthread_self() << "/" << ThreadNo() << " SendEvent Graph " << _OutNode->Name()
79 << " Node " << Name() << " Event : " << Automaton()->EventName( anEvent )
80 << " State : " << Automaton()->StateName( State() ) << " _RewindStack " << _RewindStack
81 << " ControlState : " << Automaton()->ControlStateName( ControlState() )
86 _NextState = Automaton()->NextState( _OldState , anEvent ) ;
87 if ( _NextState == _OldState ) {
88 cdebug << pthread_self() << "/" << ThreadNo() << " " << Name()
89 << " GraphExecutor::InNodeThreads::SendEvent SameStates ERROR _OldState/_NextState "
90 << _OldState << " Event " << Automaton()->EventName( anEvent ) << endl ;
91 _NextAction = GraphExecutor::VoidAction ;
95 _NextAction = Automaton()->NextAction( _NextState , anEvent ) ;
98 cdebug << pthread_self() << "/" << ThreadNo() << "NextState( " << _OldState << " , "
99 << Automaton()->EventName( anEvent ) << " ) --> _NextState = " << _NextState
100 << " NextAction( " << _NextState << " , " << Automaton()->EventName( anEvent )
101 << " ) --> _NextAction = "
102 << Automaton()->ActionName( _NextAction ) << endl ;
105 // State( _NextState ) ;
106 // if ( _OldState == GraphExecutor::SuccessedExecutingState ||
107 // _OldState == GraphExecutor::ErroredExecutingState ) {
112 cdebug << pthread_self() << "/" << ThreadNo() << " SendedEvent Node "
113 << Name() << endl << " ControlState : "
114 << Automaton()->ControlStateName( ControlState() ) << endl
115 << " OldState : " << Automaton()->StateName( _OldState ) << endl
116 << " Event : " << Automaton()->EventName( anEvent ) << endl
117 << " NextState : " << Automaton()->StateName( _NextState ) << endl
118 << " Action : " << Automaton()->ActionName( _NextAction ) << endl
119 << " CreateNewThread " << CreateNewThread() << endl
120 << " _RewindStack " << _RewindStack << endl ;
124 #if ExitWhenNodeAborted
125 if ( _OutNode->IsNodeAborted() ) {
127 cdebug << pthread_self() << "/" << ThreadNo() << " SendedEvent Node " << Name()
128 << " will exit : a node was aborted ..." << endl ;
130 State( _NextState ) ;
134 sts = executeAction() ;
137 sts = executeAction() ;
141 cdebug_out << pthread_self() << "/" << ThreadNo() << " <--- SendEvent Node " << Name()
142 << " Event : " << Automaton()->EventName( anEvent )
143 << " State : " << Automaton()->StateName( State() )
151 #define ActionsTrace 1
152 // ReadyAction - RunningAction - DoneAction - SuspendedAction :
153 // for StateWait( ReadyW - RunningW - DoneW - SuspendedW )
154 void GraphExecutor::InNode::ReadyAction() {
155 if ( pthread_mutex_lock( &_MutexWait ) ) {
156 perror("Ready pthread_mutex_lock ") ;
160 cdebug << pthread_self() << "/" << ThreadNo()
161 << "ReadyAction pthread_cond_broadcast _ReadyWait "
164 if ( pthread_cond_broadcast( &_ReadyWait ) ) {
165 perror("Ready pthread_cond_broadcast ") ;
167 if ( pthread_mutex_unlock( &_MutexWait ) ) {
168 perror("Ready pthread_mutex_unlock ") ;
173 void GraphExecutor::InNode::RunningAction() {
174 if ( pthread_mutex_lock( &_MutexWait ) ) {
175 perror("Running pthread_mutex_lock ") ;
179 cdebug << pthread_self() << "/" << ThreadNo()
180 << "RunningAction pthread_cond_broadcast _RunningWait "
183 // That activate the pthread_cond_wait for RunninWait
184 if ( pthread_cond_broadcast( &_RunningWait ) ) {
185 perror("Running pthread_cond_broadcast ") ;
187 if ( pthread_mutex_unlock( &_MutexWait ) ) {
188 perror("Running pthread_mutex_unlock ") ;
193 void GraphExecutor::InNode::DoneAction() {
194 if ( pthread_mutex_lock( &_MutexWait ) ) {
195 perror("Done pthread_mutex_lock ") ;
199 cdebug << pthread_self() << "/" << ThreadNo()
200 << "DoneAction pthread_cond_broadcast _DoneWait "
203 if ( pthread_cond_broadcast( &_DoneWait ) ) {
204 perror("Done pthread_cond_broadcast ") ;
206 if ( pthread_mutex_unlock( &_MutexWait ) ) {
207 perror("Done pthread_mutex_unlock ") ;
212 void GraphExecutor::InNode::SuspendedAction() {
213 if ( pthread_mutex_lock( &_MutexWait ) ) {
214 perror("Suspended pthread_mutex_lock ") ;
218 cdebug << pthread_self() << "/" << ThreadNo()
219 << "SuspendedAction pthread_cond_broadcast _SuspendedWait "
222 if ( pthread_cond_broadcast( &_SuspendedWait ) ) {
223 perror("Suspended pthread_cond_broadcast ") ;
225 if ( pthread_mutex_unlock( &_MutexWait ) ) {
226 perror("Suspended pthread_mutex_unlock ") ;
231 // SuspendAction <--> { ResumeAction - ReStartAction }
232 GraphExecutor::InNode * GraphExecutor::InNode::SuspendAction() {
234 if ( pthread_mutex_lock( &_MutexWait ) ) {
235 perror("Suspend pthread_mutex_lock ") ;
238 if ( !_SuspendSync ) {
239 cdebug << pthread_self() << "/" << ThreadNo() << " pthread_cond " << Name()
240 << " SuspendAction pthread_cond_wait _SuspendWait "
241 << Automaton()->StateName( State() ) << endl ;
242 _SuspendSync = true ;
243 _OutNode->SuspendThread() ;
244 if ( pthread_cond_wait( &_SuspendWait , &_MutexWait ) ) {
245 perror("SuspendAction pthread_cond_wait ") ;
247 _OutNode->ResumeThread() ;
249 cdebug << pthread_self() << "/" << ThreadNo() << " pthread_cond " << Name()
250 << " SuspendAction pthread_cond_waited"
251 << Automaton()->StateName( State() ) << endl ;
256 cdebug << pthread_self() << "/" << ThreadNo() << " pthread_cond " << Name()
257 << " NO SuspendAction pthread_cond_wait"
258 << Automaton()->StateName( State() ) << endl ;
261 // SendEvent( _aResumeEvent ) ; ===> Mutex with myself !
262 _SuspendSync = false ;
263 if ( ControlState() == SUPERV::ToSuspendStartState ||
264 ControlState() == SUPERV::ToSuspendState ) {
265 ControlState( SUPERV::VoidState ) ;
267 if ( pthread_mutex_unlock( &_MutexWait ) ) {
268 perror("SuspendAction pthread_mutex_unlock ") ;
272 SendEvent( _aResumeEvent ) ;
273 // if ( ControlState() == SUPERV::ToSuspendStartState ) {
274 // ControlState( SUPERV::VoidState ) ;
277 if ( pthread_mutex_lock( &_MutexWait ) ) {
278 perror("SuspendAction pthread_mutex_lock ") ;
283 cdebug << pthread_self() << "/" << ThreadNo() << " pthread_cond " << Name()
284 << " SuspendAction pthread_cond_signal _ResumeWait" << endl ;
286 if ( pthread_cond_signal( &_ResumeWait ) ) {
287 perror("SuspendAction pthread_cond_signal _ResumeWait ") ;
290 cdebug << pthread_self() << "/" << ThreadNo() << " pthread_cond " << Name()
291 << " SuspendAction pthread_cond_signaled _ResumeWait " << endl ;
296 cdebug << pthread_self() << "/" << ThreadNo() << " pthread_cond " << Name()
297 << " NO SuspendAction pthread_cond_signal _ResumeWait" << endl ;
301 if ( pthread_mutex_unlock( &_MutexWait ) ) {
302 perror("SuspendAction pthread_mutex_unlock ") ;
305 if ( _aReStartNode ) {
306 cdebug << Name() << " " << Automaton()->StateName( State() )
307 << "aReStartNode : " << _aReStartNode->Name() << " "
308 << Automaton()->StateName( _aReStartNode->State() ) << endl ;
309 _aReStartNode->SendEvent( _aResumeEvent ) ;
312 cdebug << "NO aReStartNode"
313 << Automaton()->StateName( State() ) << endl ;
315 return _aReStartNode ;
318 bool GraphExecutor::InNode::ResumeAction( GraphExecutor::NodeEvent aResumeEvent ) {
320 if ( pthread_mutex_lock( &_MutexWait ) ) {
321 perror("ResumeAction pthread_mutex_lock ") ;
324 _aResumeEvent = aResumeEvent ;
325 if ( _SuspendSync ) {
327 cdebug << pthread_self() << "/" << ThreadNo() << " pthread_cond " << Name()
328 << " ResumeAction pthread_cond_signal" << endl ;
330 if ( pthread_cond_signal( &_SuspendWait ) ) {
331 perror("ResumeAction pthread_cond_signal ") ;
334 cdebug << pthread_self() << "/" << ThreadNo() << " pthread_cond " << Name()
335 << " ResumeAction pthread_cond_signaled _SuspendWait " << endl ;
341 cdebug << pthread_self() << "/" << ThreadNo() << " pthread_cond " << Name()
342 << " NO ResumeAction pthread_cond_signal" << endl ;
344 if ( pthread_self() == ThreadNo() ) {
345 RetVal = false ; /*/ Ne pas s'attendre soi-meme !...*/
348 _SuspendSync = true ;
349 RetVal = true ; // Il faut tout de meme attendre ci-apres ...
352 if ( pthread_mutex_unlock( &_MutexWait ) ) {
353 perror("ResumeAction pthread_mutex_unlock ") ;
358 if ( pthread_mutex_lock( &_MutexWait ) ) {
359 perror("ResumeAction pthread_mutex_lock ") ;
362 if ( !_ResumeSync ) {
364 cdebug << pthread_self() << "/" << ThreadNo() << " pthread_cond "
365 << Name() << " ResumeAction pthread_cond_wait _ResumeWait "
366 << Automaton()->StateName( State() ) << endl ;
369 if ( pthread_cond_wait( &_ResumeWait , &_MutexWait ) ) {
370 perror("ResumeAction pthread_cond_wait ") ;
373 cdebug << pthread_self() << "/" << ThreadNo() << " pthread_cond "
374 << Name() << " ResumeAction pthread_cond_waited _ResumeWait"
375 << Automaton()->StateName( State() ) << endl ;
381 cdebug << pthread_self() << "/" << ThreadNo() << " pthread_cond "
382 << Name() << " NO ResumeAction pthread_cond_wait _ResumeWait"
383 << Automaton()->StateName( State() ) << endl ;
387 _ResumeSync = false ;
388 if ( pthread_mutex_unlock( &_MutexWait ) ) {
389 perror("ResumeAction pthread_mutex_unlock ") ;
394 cdebug << pthread_self() << "/" << ThreadNo()
395 << "GraphExecutor::InNodeThreads::ResumeAction RetVal " << RetVal << endl ;
400 bool GraphExecutor::InNode::ReStartAction( GraphExecutor::InNode * aReStartNode ,
401 GraphExecutor::NodeEvent anEvent ) {
402 GraphExecutor::InNode * oldReStartNode = _aReStartNode ;
403 _aReStartNode = aReStartNode ;
404 _aReStartEvent = anEvent ;
405 cdebug << pthread_self() << "/" << ThreadNo()
406 << " GraphExecutor::InNodeThreads::ReStartAction from "
407 << Name() << " " << Automaton()->StateName( State() ) << " to "
408 << aReStartNode->ThreadNo() << " " << aReStartNode->Name() << " "
409 << Automaton()->StateName( aReStartNode->State() ) ;
410 if ( oldReStartNode ) {
411 cdebug << " oldReStartNode " << oldReStartNode->Name() << endl ;
416 return ResumeAction( GraphExecutor::ToReStartEvent ) ;
419 void GraphExecutor::InNode::KilledAction() {
420 if ( pthread_mutex_lock( &_MutexWait ) ) {
421 perror("Killed pthread_mutex_lock ") ;
425 cdebug << "pthread_cond " << Name() << " Killed pthread_cond_wait"
428 if ( pthread_cond_wait( &_KillWait , &_MutexWait ) ) {
429 perror("Killed pthread_cond_wait ") ;
431 cdebug << "pthread_cond " << Name() << " Killed pthread_cond_waited"
435 cdebug << "pthread_cond " << Name() << " NO Killed pthread_cond_wait"
439 if ( pthread_mutex_unlock( &_MutexWait ) ) {
440 perror("Killed pthread_mutex_unlock ") ;
445 void GraphExecutor::InNode::KillAction() {
446 if ( pthread_mutex_lock( &_MutexWait ) ) {
447 perror("Kill pthread_mutex_lock ") ;
451 cdebug << "pthread_cond " << Name() << " Kill pthread_cond_signal"
453 // if ( pthread_cond_broadcast( &_KillWait ) ) {
454 if ( pthread_cond_signal( &_KillWait ) ) {
455 perror("Kill pthread_cond_broadcast ") ;
457 cdebug << "pthread_cond " << Name() << " Kill pthread_cond_signaled"
461 cdebug << "pthread_cond " << Name() << " NO Kill pthread_cond_signal"
465 if ( pthread_mutex_unlock( &_MutexWait ) ) {
466 perror("Kill pthread_mutex_unlock ") ;
471 void GraphExecutor::InNode::StoppedAction() {
472 if ( pthread_mutex_lock( &_MutexWait ) ) {
473 perror("Stopped pthread_mutex_lock ") ;
476 if ( pthread_cond_wait( &_StopWait , &_MutexWait ) ) {
477 perror("Stopped pthread_cond_wait ") ;
479 if ( pthread_mutex_unlock( &_MutexWait ) ) {
480 perror("Stopped pthread_mutex_unlock ") ;
485 void GraphExecutor::InNode::StopAction() {
486 if ( pthread_mutex_lock( &_MutexWait ) ) {
487 perror("Stop pthread_mutex_lock ") ;
490 if ( pthread_cond_broadcast( &_StopWait ) ) {
491 perror("Stop pthread_cond_broadcast ") ;
493 if ( pthread_mutex_unlock( &_MutexWait ) ) {
494 perror("Stop pthread_mutex_unlock ") ;
499 void GraphExecutor::InNode::ThreadStartedAction() {
500 if ( pthread_mutex_lock( &_MutexWait ) ) {
501 perror("ThreadStarted pthread_mutex_lock ") ;
504 if ( !_ThreadStartedSync ) {
506 cdebug << pthread_self() << "/" << ThreadNo()
507 << "pthread_cond " << Name() << " ThreadStarted pthread_cond_wait"
510 _ThreadStartedSync = true ;
511 if ( pthread_cond_wait( &_ThreadStartedWait , &_MutexWait ) ) {
512 perror("ThreadStarted pthread_cond_wait ") ;
515 cdebug << pthread_self() << "/" << ThreadNo()
516 << "pthread_cond " << Name() << " ThreadStarted pthread_cond_waited"
522 cdebug << pthread_self() << "/" << ThreadNo()
523 << "pthread_cond " << Name() << " NO ThreadStarted pthread_cond_wait"
527 _ThreadStartedSync = false ;
528 if ( pthread_cond_signal( &_ThreadStartedWait ) ) {
529 perror("ThreadStart pthread_cond_signal ") ;
533 cdebug << pthread_self() << "/" << ThreadNo()
534 << "pthread_cond " << Name() << " NO ThreadStarted pthread_cond_signaled"
538 if ( pthread_mutex_unlock( &_MutexWait ) ) {
539 perror("ThreadStarted pthread_mutex_unlock ") ;
544 void GraphExecutor::InNode::ThreadStartAction() {
545 if ( pthread_mutex_lock( &_MutexWait ) ) {
546 perror("ThreadStart pthread_mutex_lock ") ;
549 if ( _ThreadStartedSync ) {
551 cdebug << pthread_self() << "/" << ThreadNo()
552 << "pthread_cond " << Name() << " ThreadStart pthread_cond_signal"
555 _ThreadStartedSync = false ;
556 if ( pthread_cond_signal( &_ThreadStartedWait ) ) {
557 perror("ThreadStart pthread_cond_broadcast ") ;
560 cdebug << pthread_self() << "/" << ThreadNo()
561 << "pthread_cond " << Name() << " ThreadStart pthread_cond_signaled"
567 cdebug << pthread_self() << "/" << ThreadNo()
568 << "pthread_cond " << Name() << " NO ThreadStart pthread_cond_signal"
571 _ThreadStartedSync = true ;
573 if ( pthread_cond_wait( &_ThreadStartedWait , &_MutexWait ) ) {
574 perror("ThreadStarted pthread_cond_wait ") ;
578 cdebug << pthread_self() << "/" << ThreadNo()
579 << "pthread_cond " << Name() << " NO ThreadStart pthread_cond_waited"
583 if ( pthread_mutex_unlock( &_MutexWait ) ) {
584 perror("ThreadStart pthread_mutex_unlock ") ;
589 int GraphExecutor::InNode::executeAction() {
591 int oldRewindStack = ( _RewindStack > MAXSTACKTHREADSIZE ) ;
592 if ( !CreateNewThread() && oldRewindStack ) {
594 cdebug << pthread_self() << "/" << ThreadNo()
595 << " executeAction start Thread _RewindStack " << _RewindStack << " > "
596 << MAXSTACKTHREADSIZE << " CreateNewThread "
597 << CreateNewThread() << " " << Automaton()->ActionName( _NextAction ) << "("
598 << Name() << ")" << endl;
600 CreateNewThread( true ) ;
601 _OutNode->IncrCreatedThreads() ;
604 if ( CreateNewThread() ) {
605 CreateNewThread( false ) ;
606 //JR 15.04.2005 Debug PAL8624 RetroConception :
607 // if ( ThreadNo() == 0 ) {
610 cdebug << pthread_self() << "/" << ThreadNo()
611 << " executeAction start Thread _RewindStack " << _RewindStack << " "
612 << Automaton()->ActionName( _NextAction ) << "(" << Name() << ")"
616 int pthread_sts = 1 ;
617 // _OutNode->PushEvent( NULL , GraphExecutor::NewThreadEvent ,
618 // GraphExecutor::ExecutingState ) ;
619 while ( (pthread_sts = pthread_create(&T, NULL, run_function, this )) ) {
620 char * msg = "Cannot pthread_create " ;
622 cdebug << ThreadNo() << " " << msg << " --> sleep(5)" << endl ;
623 cdebug << ThreadNo() << " PTHREAD_THREADS_MAX : "
624 << PTHREAD_THREADS_MAX << " pthread_create status : " ;
625 if ( pthread_sts == EAGAIN ) {
626 cdebug << "EAGAIN(" << pthread_sts << ")" << endl ;
627 cdebug << _OutNode->CreatedThreads() << " was created (and exited)" << endl ;
628 cdebug << "It seems to me that with gdb we are limited to 256 threads" << endl ;
631 cdebug << pthread_sts << endl ;
635 pthread_exit( msg ) ;
638 cdebug << pthread_self() << "/" << ThreadNo() << " " << Name()
639 << " executeAction has created thread " << T << endl ;
641 ThreadStartedAction() ;
643 cdebug << pthread_self() << "/" << ThreadNo() << " " << Name()
644 << "executeAction the thread " << T << " has called NewThread and will call ExecuteAction for node "
648 //JR 15.04.2005 Debug PAL8624 RetroConception :
652 cdebug << pthread_self() << "/" << ThreadNo()
653 << " executeAction restart Thread _RewindStack " << _RewindStack << " "
654 << Automaton()->StateName( State() ) << " "
655 << Automaton()->ActionName( _NextAction ) << "(" << Name()
656 << ") ReStartAction ==>" << endl;
658 State( GraphExecutor::SuspendedSuccessedState ) ;
659 if ( !ReStartAction( this , GraphExecutor::ReStartEvent ) ) {
660 cdebug << pthread_self() << "/" << ThreadNo()
661 << " executeAction STATE & CALLED "
662 << Automaton()->ActionName( _NextAction ) << "(" << Name()
663 << ") ERROR-DEBUG " << endl;
667 cdebug << pthread_self() << "/" << ThreadNo() << " executeAction NO CALL "
668 << Automaton()->ActionName( _NextAction ) << "(" << Name()
676 if ( _CurrentEvent == ExecuteEvent ) {
680 cdebug << pthread_self() << "/" << ThreadNo() << " executeAction call "
681 << Automaton()->ActionName( _NextAction ) << "(" << Name() << ") _RewindStack " << _RewindStack
684 return ExecuteAction() ;
689 void GraphExecutor::InNode::coutbegin() {
691 cdebug << pthread_self() << "/" << ThreadNo() << " run_function begin"
692 << " " << Name() << " " << Automaton()->StateName( State() ) << endl ;
695 void GraphExecutor::InNode::coutexit() {
697 cdebug << pthread_self() << "/" << ThreadNo() << " run_function pthread_exit _RewindStack " << _RewindStack
698 << " " << Name() << " " << Automaton()->StateName( State() ) << endl ;
701 void * run_function(void *p) {
702 GraphExecutor::InNode *aNode = (GraphExecutor::InNode *) p;
704 aNode->NewThread( pthread_self() ) ;
705 if ( pthread_setcanceltype( PTHREAD_CANCEL_ASYNCHRONOUS , NULL ) ) {
706 perror("pthread_setcanceltype ") ;
709 if ( pthread_setcancelstate( PTHREAD_CANCEL_ENABLE , NULL ) ) {
710 perror("pthread_setcancelstate ") ;
713 aNode->ThreadStartAction() ;
714 // cout << "run_function " << aNode->Name() << "->ExecuteAction() Coupled : " << aNode->CoupledNode()
716 aNode->ExecuteAction() ;
717 char * msg = new char[40] ;
718 sprintf( msg , "%d" , (int ) aNode->ThreadNo() ) ;
719 strcat( msg , " thread exit" ) ;
721 aNode->ExitThread() ;
724 pthread_exit( (void * ) smsg.c_str() ) ;
728 int GraphExecutor::InNode::ExecuteAction() {
732 const char * nextactionname = Automaton()->ActionName( _NextAction ) ;
733 const char * statename = Automaton()->StateName( State() ) ;
734 const char * nextstatename = Automaton()->StateName( _NextState ) ;
735 cdebug_in << pthread_self() << "/" << ThreadNo() << " " << Name() << " --> ExecuteAction "
736 << nextactionname << " " << statename << " NextState "
737 << nextstatename << endl ;
740 State( _NextState ) ;
741 switch ( _NextAction ) {
742 case GraphExecutor::ErrorAction : {
743 sts = ErrorAction() ;
746 case GraphExecutor::VoidAction : {
750 case GraphExecutor::DataWaiting_SomeDataReadyAction : {
751 sts = DataWaiting_SomeDataReadyAction() ;
754 case GraphExecutor::DataUndef_NotAllDataReadyAction : {
755 sts = DataUndef_NotAllDataReadyAction() ;
758 case GraphExecutor::DataUndef_AllDataReadyAction : {
759 sts = DataUndef_AllDataReadyAction() ;
762 case GraphExecutor::DataReady_SuspendAction : {
763 sts = DataReady_SuspendAction() ;
766 case GraphExecutor::SuspendedReady_ResumeAction : {
767 sts = SuspendedReady_ResumeAction() ;
770 case GraphExecutor::DataReady_KillAction : {
771 sts = DataReady_KillAction() ;
774 case GraphExecutor::DataReady_StopAction : {
775 sts = DataReady_StopAction() ;
778 case GraphExecutor::DataReady_ExecuteAction : {
779 sts = DataReady_ExecuteAction() ;
782 case GraphExecutor::Executing_SuspendAction : {
783 sts = Executing_SuspendAction() ;
786 case GraphExecutor::SuspendedExecuting_ResumeAction : {
787 sts = SuspendedExecuting_ResumeAction() ;
790 case GraphExecutor::Executing_KillAction : {
791 sts = Executing_KillAction() ;
794 case GraphExecutor::Executing_StopAction : {
795 sts = Executing_StopAction() ;
798 case GraphExecutor::Executing_SuccessAction : {
799 sts = Executing_SuccessAction() ;
802 case GraphExecutor::Errored_ExecutingAction : {
803 sts = Errored_ExecutingAction() ;
806 case GraphExecutor::Successed_SuccessAction : {
807 sts = Successed_SuccessAction() ;
810 case GraphExecutor::Errored_ErrorAction : {
811 sts = Errored_ErrorAction() ;
814 case GraphExecutor::Successed_SuspendAction : {
815 sts = Successed_SuspendAction() ;
818 case GraphExecutor::Errored_SuspendAction : {
819 sts = Errored_SuspendAction() ;
822 case GraphExecutor::SuspendedSuccessed_ResumeAction : {
823 sts = SuspendedSuccessed_ResumeAction() ;
826 case GraphExecutor::SuspendedErrored_ResumeAction : {
827 sts = SuspendedErrored_ResumeAction() ;
830 case GraphExecutor::Successed_KillAction : {
831 sts = Successed_KillAction() ;
834 case GraphExecutor::Errored_KillAction : {
835 sts = Errored_KillAction() ;
838 case GraphExecutor::Successed_StopAction : {
839 sts = Successed_StopAction() ;
842 case GraphExecutor::Errored_StopAction : {
843 sts = Errored_StopAction() ;
846 case GraphExecutor::SuspendedSuccessed_ReStartAction : {
847 sts = SuspendedSuccessed_ReStartAction() ;
850 case GraphExecutor::SuspendedErrored_ReStartAction : {
851 sts = SuspendedErrored_ReStartAction() ;
854 case GraphExecutor::SuspendedSuccessed_ReStartAndSuspendAction : {
855 sts = SuspendedSuccessed_ReStartAndSuspendAction() ;
858 case GraphExecutor::SuspendedErrored_ReStartAndSuspendAction : {
859 sts = SuspendedErrored_ReStartAndSuspendAction() ;
863 cdebug << pthread_self() << "/" << ThreadNo()
864 << " GraphExecutor::InNodeThreads::SendEvent Error Undefined Action : "
865 << _NextAction << endl ;
870 cdebug_out << pthread_self() << "/" << ThreadNo() << "<-- ExecuteAction "
871 << nextactionname << endl ;
876 int GraphExecutor::InNode::ErrorAction() {
877 cdebug << pthread_self() << "/" << ThreadNo() << " Automaton ErrorAction Node "
882 int GraphExecutor::InNode::VoidAction() {
883 cdebug << pthread_self() << "/" << ThreadNo() << " VoidAction " << Name() << endl;
887 #define SomeDataReadyActionTrace 1
888 int GraphExecutor::InNode::DataWaiting_SomeDataReadyAction() {
889 #if SomeDataReadyActionTrace
890 cdebug_in << pthread_self() << "/" << ThreadNo() << " " << Name()
891 << " DataWaiting_SomeDataReadyAction from " << DataFromNode() << endl;
896 bool LoopBeginning = false ;
897 bool LoopFinished = false ;
898 bool SwitchFinished = false ;
899 bool SwitchDefault = false ;
900 bool DoAllDataReadyIf = true ;
902 if ( IsLoopNode() ) {
903 GraphBase::OutPort * anOutLoopPort = GetChangeNodeInLoop()->GetOutPort() ; // DoLoop Port
904 if ( anOutLoopPort && anOutLoopPort->BoolValue() ) {
905 LoopBeginning = true ; // Beginning of Loop
908 else if ( IsEndLoopNode() ) {
909 GraphBase::OutPort * anOutLoopPort = GetChangeNodeInLoop()->GetOutPort() ; // DoLoop Port
910 if ( anOutLoopPort && !anOutLoopPort->BoolValue() ) {
911 LoopFinished = true ; // End of Loop
914 else if ( IsEndSwitchNode() ) {
915 if ( strcmp( GOTONode()->CoupledNode()->Name() , DataFromNode() ) ) {
916 GraphBase::OutPort * anOutGateSwitchPort = GetChangeNodeInGate()->GetOutPort() ; // Default Port
917 //JR 09.02.2005 : SomeDataReady is NOT from the SwitchNode
918 if ( anOutGateSwitchPort && !anOutGateSwitchPort->BoolValue() ) {
919 //JR 09.02.2005 : the OutPort of the SwitchNode connected to the default port is closed ===>
920 // Here after we consider that that DefaultPort is Ready (even if it's value is false) in
921 // order to have the good count of InPorts Ready in the EndSwitchNode
922 // SwitchFinished = true ; // End of Switch
924 // But we do that only if the InDefaultPort of the EndSwitchNode is not connected or
925 // is connected from the OutDefaultPort of the corresponding SwitchNode
926 if ( !strcmp( GOTONode()->CoupledNode()->Name() , anOutGateSwitchPort->NodeName() ) ) {
927 SwitchFinished = true ; // End of Switch
932 //JR 20.04.2005 : SomeDataReady is FROM the SwitchNode to that EndSwitchNode
934 //JR 16.02.2005 Debug : Change InPorts of EndSwitchNode that have the same name as an OutPort of
935 // the SwitchNode even if it is the DefaultPort : GraphSwitchCheckDefault1.xml
936 GraphBase::OutPort * anOutGateSwitchPort = GetChangeNodeInGate()->GetOutPort() ; // Default P
937 //JR 20.04.2005 : SomeDataReady is from the SwitchNode and Default is activated :
938 if ( anOutGateSwitchPort ) {
939 if ( anOutGateSwitchPort->BoolValue() ) {
940 SwitchDefault = true ;
942 //JR 20.04.2005 : SomeDataReady is from the SwitchNode and Default is NOT activated :
943 // a SwitchBranch should be activated
945 DoAllDataReadyIf = false ;
947 #if SomeDataReadyActionTrace
948 cdebug << pthread_self() << "/" << ThreadNo() << " " << Name()
949 << " activated from CoupledNode " << GOTONode()->CoupledNode()->Name() << " "
950 << anOutGateSwitchPort->NodeName() << "( " << anOutGateSwitchPort->PortName()
951 << " ) to InDefault " ;
953 if ( GraphBase::Base::_prof_debug ) {
954 anOutGateSwitchPort->StringValue( *GraphBase::Base::_fdebug ) ;
960 //JR 28.06.2005 : SomeDataReady is from the SwitchNode and the InDefault is not connected :
961 // a SwitchBranch should be activated
963 DoAllDataReadyIf = false ;
968 #if SomeDataReadyActionTrace
969 cdebug << pthread_self() << "/" << ThreadNo() << " " << Name() << " LoopFinished " << LoopFinished
970 << " LoopBeginning " << LoopBeginning << " SwitchFinished " << SwitchFinished
971 << " SwitchDefault " << SwitchDefault << " DoAllDataReadyIf " << DoAllDataReadyIf << endl ;
973 for ( k = 0 ; k < (unsigned int ) GetNodeInPortsSize() ; k++ ) {
974 GraphBase::InPort * anInPort = GetChangeNodeInPort(k) ;
975 GraphBase::OutPort * anOutPort ;
976 if ( SwitchDefault && !anInPort->IsDataStream() ) {
977 //Get or Set the field OutPort of that InPort of the EndSwitchNode to the corresponding OutPort
979 anOutPort = anInPort->GetOutPort() ;
981 #if SomeDataReadyActionTrace
982 cdebug << pthread_self() << "/" << ThreadNo() << " " << Name() << " InPort "
983 << anInPort->PortName() << " already setted to OutPort " << anOutPort->NodeName()
984 << "( " << anOutPort->PortName() << " )" << endl ;
988 anOutPort = CoupledNode()->GetChangeOutPort( anInPort->PortName() ) ;
990 #if SomeDataReadyActionTrace
991 cdebug << pthread_self() << "/" << ThreadNo() << " " << Name() << " InPort "
992 << anInPort->PortName() << " change of OutPort from "
993 << anInPort->GetOutPort()->NodeName() << "( " << anInPort->GetOutPort()->PortName()
994 << " ) to " << anOutPort->NodeName() << "( " << anOutPort->PortName() << " )"
999 cdebug << pthread_self() << "/" << ThreadNo() << " " << Name() << " InPort "
1000 << anInPort->PortName() << " have NO OutPort ERROR " << endl ;
1003 anInPort->ChangeOutPort( anOutPort ) ;
1007 anOutPort = anInPort->GetOutPort() ;
1009 #if SomeDataReadyActionTrace
1010 cdebug << pthread_self() << "/" << ThreadNo() << " " << Name() << " InPort "
1011 << anInPort->PortName() << " " << anInPort->PortState() << " "
1012 << anInPort->PortStatus() << " " << anInPort->Kind() ;
1014 cdebug << " from OutPort " << anOutPort->NodeName() << "( " << anOutPort->PortName()
1018 cdebug << " without OutPort " ;
1022 if ( anInPort->IsGate() && anOutPort == NULL ) {
1024 anInPort->PortState( SUPERV::ReadyState ) ;
1025 #if SomeDataReadyActionTrace
1026 cdebug << pthread_self() << "/" << ThreadNo() << " " << Name() << " "
1027 << anInPort->PortName() << " ControlPort inactive." << endl ;
1031 // That InPort get its value from an other node : the node of anOutPort linked to that anInPort is
1032 // different from the sender of SomeDataReady (DataFromNode) :
1033 else if ( strcmp( DataFromNode() , anOutPort->NodeName() ) ) {
1034 if ( anInPort->PortState() == SUPERV::ReadyState ) {
1036 #if SomeDataReadyActionTrace
1037 cdebug << pthread_self() << "/" << ThreadNo() << " " << Name() << " "
1038 << anInPort->PortName() << " " << anInPort->PortState() << " Was Done from Node "
1039 << anOutPort->NodeName() << "( " << anOutPort->PortName() << " , "
1040 << anOutPort->PortState() << " ) PortDone " << anOutPort->PortDone() << " " ;
1042 if ( GraphBase::Base::_prof_debug ) {
1043 anOutPort->StringValue( *GraphBase::Base::_fdebug ) ;
1049 else if ( IsLoopNode() && anInPort->IsDataConnected() ) {
1050 anInPort->PortState( SUPERV::ReadyState ) ;
1052 #if SomeDataReadyActionTrace
1053 cdebug << pthread_self() << "/" << ThreadNo() << " " << Name() << " "
1054 << anInPort->PortName() << " Was Done from Node "
1055 << anOutPort->NodeName() << "( " << anOutPort->PortName()
1056 << ") LoopBeginning " << LoopBeginning << " " ;
1058 if ( GraphBase::Base::_prof_debug ) {
1059 anOutPort->StringValue( *GraphBase::Base::_fdebug ) ;
1065 else if ( LoopFinished ) {
1066 anInPort->PortState( SUPERV::ReadyState ) ;
1068 #if SomeDataReadyActionTrace
1069 cdebug << pthread_self() << "/" << ThreadNo() << " " << Name() << " "
1070 << anInPort->PortName() << " Was Done from Node "
1071 << anOutPort->NodeName() << "( " << anOutPort->PortName()
1072 << ") LoopFinished " << LoopFinished << " " ;
1074 if ( GraphBase::Base::_prof_debug ) {
1075 anOutPort->StringValue( *GraphBase::Base::_fdebug ) ;
1081 else if ( anInPort->IsGate() && SwitchFinished ) {
1082 anInPort->PortState( SUPERV::ReadyState ) ;
1084 #if SomeDataReadyActionTrace
1085 cdebug << pthread_self() << "/" << ThreadNo() << " " << Name() << " "
1086 << anInPort->PortName() << " Was Done from Node "
1087 << anOutPort->NodeName() << "( " << anOutPort->PortName()
1088 << ") SwitchFinished " << SwitchFinished << " " ;
1090 if ( GraphBase::Base::_prof_debug ) {
1091 anOutPort->StringValue( *GraphBase::Base::_fdebug ) ;
1097 else if ( anInPort->IsGate() &&
1098 _OutNode->Graph()->GetGraphNode( anOutPort->NodeName() )->IsGOTONode() ) {
1099 // GateOutPort of GOTONodes are always opened
1100 anInPort->PortState( SUPERV::ReadyState ) ;
1102 //JR 21.02.2005 Debug Memory leak : CORBA::Any * anAny = new CORBA::Any() ;
1103 CORBA::Any anAny = CORBA::Any() ;
1104 //JR 21.02.2005 Debug Memory leak : *anAny <<= (long ) 1 ;
1105 anAny <<= (long ) 1 ;
1106 _OutNode->Graph()->GetGraphNode( anOutPort->NodeName() )->GetChangeNodeOutGate()->SetValue( anAny ) ;
1107 #if SomeDataReadyActionTrace
1108 cdebug << pthread_self() << "/" << ThreadNo() << " " << Name() << " "
1109 << anInPort->PortName() << " Was Done from Node "
1110 << anOutPort->NodeName() << "( " << anOutPort->PortName()
1113 if ( GraphBase::Base::_prof_debug ) {
1114 anOutPort->StringValue( *GraphBase::Base::_fdebug ) ;
1121 #if SomeDataReadyActionTrace
1122 cdebug << pthread_self() << "/" << ThreadNo() << " " << Name() << " "
1123 << " " << Automaton()->StateName( State() ) << " LoopBeginning "
1124 << LoopBeginning << " " << anInPort->PortName() << " DataConnected "
1125 << anInPort->IsDataConnected() << " Was NOT Done from Node "
1126 << anOutPort->NodeName() << "( " << anOutPort->PortName() << " , "
1127 << anOutPort->PortState() << " , PortDone " << anOutPort->PortDone() << ") "
1133 // That InPort get its value from the sending node (DataFromNode)
1134 else if ( anInPort->IsGate() ) {
1135 //JR 30.03.2005 const CORBA::Any * theValue = anOutPort->Value() ;
1136 const CORBA::Any theValue = anOutPort->Value() ;
1138 //JR 30.03.2005 (*theValue) >>= GateOpened ;
1139 theValue >>= GateOpened ;
1140 if ( GateOpened != 0 ) {
1142 anInPort->PortState( SUPERV::ReadyState ) ;
1143 #if SomeDataReadyActionTrace
1144 cdebug << pthread_self() << "/" << ThreadNo() << " " << Name() << " "
1145 << anInPort->PortName() << " Gate is Opened from Node "
1146 << anOutPort->NodeName() << "( " << anOutPort->PortName()
1149 if ( GraphBase::Base::_prof_debug ) {
1150 anOutPort->StringValue( *GraphBase::Base::_fdebug ) ;
1156 else if ( LoopFinished ) {
1157 anInPort->PortState( SUPERV::ReadyState ) ;
1158 #if SomeDataReadyActionTrace
1159 cdebug << pthread_self() << "/" << ThreadNo() << " " << Name() << " "
1160 << anInPort->PortName() << " GATE IS CLOSED from Node "
1161 << anOutPort->NodeName() << "( " << anOutPort->PortName()
1162 << ") LoopFinished" ;
1164 if ( GraphBase::Base::_prof_debug ) {
1165 anOutPort->StringValue( *GraphBase::Base::_fdebug ) ;
1172 #if SomeDataReadyActionTrace
1173 cdebug << pthread_self() << "/" << ThreadNo() << " " << Name() << " "
1174 << anInPort->PortName() << " GATE IS CLOSED from Node "
1175 << anOutPort->NodeName() << "( " << anOutPort->PortName()
1178 if ( GraphBase::Base::_prof_debug ) {
1179 anOutPort->StringValue( *GraphBase::Base::_fdebug ) ;
1186 else if ( anOutPort->PortDone() ) {
1187 #if SomeDataReadyActionTrace
1188 cdebug << pthread_self() << "/" << ThreadNo() << " " << Name() << " InPort "
1189 << anInPort->PortName() << " " << anInPort->PortStatus() << " "
1190 << Automaton()->StateName( anInPort->PortState() ) << " is Done from Node "
1191 << anOutPort->NodeName() << "( " << anOutPort->PortName() << ") "
1192 << anOutPort->PortStatus() << " --> ReadyState " ;
1194 if ( GraphBase::Base::_prof_debug ) {
1195 anOutPort->StringValue( *GraphBase::Base::_fdebug ) ;
1201 anInPort->PortState( SUPERV::ReadyState ) ;
1202 // MacroNode : give immediately the value to the corresponding graph
1203 if ( IsMacroNode() ) {
1204 GraphExecutor::DataFlow * aMacroGraph = GraphMacroNode()->CoupledNode()->GraphEditor()->Executor() ;
1205 cdebug << "SomeDataReadyAction MacroNode " << aMacroGraph->Name() << " --> InputOfAny "
1206 << InReady << "/" << GetNodeInPortsSize() << " InPorts are Ready ( "
1207 << anInPort->PortName() << " ) ===> InputOfAny" << endl ;
1208 // GraphMacroNode()->MacroObject()->InputOfAny( anInPort->PortName() , *anOutPort->Value() ) ;
1209 //JR 30.03.2005 aMacroGraph->InputOfAny( anInPort->PortName() , *anOutPort->Value() ) ;
1210 aMacroGraph->InputOfAny( anInPort->PortName() , anOutPort->Value() ) ;
1214 #if SomeDataReadyActionTrace
1215 cdebug << pthread_self() << "/" << ThreadNo() << " Node " << Name() << "( "
1216 << anInPort->PortName() << ") " << anInPort->PortStatus()
1217 << " is NOT Done from Node "
1218 << anOutPort->NodeName() << "( " << anOutPort->PortName() << ") "
1219 << anOutPort->PortStatus() << " " << anOutPort->PortDone() << endl ;
1224 if ( InReady == GetNodeInPortsSize() && DoAllDataReadyIf ) { // All Flags != 0 :
1225 //JR 15.04.2005 Debug PAL8624 RetroConception :
1226 // res = SendEvent( GraphExecutor::AllDataReadyEvent ); // ==> Ready to execute
1227 #if SomeDataReadyActionTrace
1228 cdebug << pthread_self() << "/" << ThreadNo() << " Node " << Name() << " HasAllDataReady"
1231 HasAllDataReady( true ) ; // ==> Ready to execute
1234 else { // At least one Flag == 0 :
1235 HasAllDataReady( false ) ;
1236 res = SendEvent( GraphExecutor::NotAllDataReadyEvent );
1239 #if SomeDataReadyActionTrace
1240 cdebug_out << pthread_self() << "/" << ThreadNo() << Name()
1241 << " DataWaiting_SomeDataReadyAction " << endl;
1247 #define NotAllDataReadyActionTrace 1
1248 int GraphExecutor::InNode::DataUndef_NotAllDataReadyAction() {
1249 //JR 15.04.2005 Debug PAL8624 RetroConception :
1250 // CreateNewThreadIf( false ) ;
1251 #if NotAllDataReadyActionTrace
1252 cdebug << pthread_self() << " for " << ThreadNo()
1253 << " DataUndef_NotAllDataReadyAction " << Name() << endl;
1258 #define AllDataReadyActionTrace 1
1259 int GraphExecutor::InNode::DataUndef_AllDataReadyAction() {
1260 #if AllDataReadyActionTrace
1261 cdebug << pthread_self() << "/" << ThreadNo()
1262 << " --> DataUndef_AllDataReadyAction " << Name() << endl ;
1263 // << " CreateNewThreadIf " << CreateNewThreadIf() << " IsLockedDataWait "
1264 // << IsLockedDataWait() ;
1266 //JR 15.04.2005 Debug PAL8624 RetroConception :
1267 if ( !CreateNewThread() ) {
1268 #if AllDataReadyActionTrace
1269 cdebug << "Thread " << ThreadNo() << " --> " << pthread_self() << endl ;
1271 ThreadNo( pthread_self() ) ;
1274 _OutNode->IncrCreatedThreads() ;
1276 _OutNode->PushEvent( this , GraphExecutor::AllDataReadyEvent ,
1277 GraphExecutor::DataReadyState ) ;
1279 SUPERV::ControlState aControl = ControlState() ;
1280 switch ( aControl ) {
1281 case SUPERV::VoidState : {
1282 SendEvent( GraphExecutor::ExecuteEvent ) ;
1285 case SUPERV::ToSuspendState : {
1286 SendEvent( GraphExecutor::SuspendEvent ) ;
1289 case SUPERV::ToSuspendStartState : {
1290 SendEvent( GraphExecutor::SuspendEvent ) ;
1293 case SUPERV::ToSuspendDoneState : {
1294 SendEvent( GraphExecutor::ExecuteEvent ) ;
1297 case SUPERV::ToKillState : {
1298 SendEvent( GraphExecutor::KillEvent ) ;
1301 case SUPERV::ToKillDoneState : {
1302 SendEvent( GraphExecutor::ExecuteEvent ) ;
1305 case SUPERV::ToStopState : {
1306 SendEvent( GraphExecutor::StopEvent ) ;
1310 cdebug << ThreadNo()
1311 << " GraphExecutor::InNodeThreads::DataUndef_AllDataReadyAction Error Undefined Control : "
1312 << aControl << endl ;
1316 #if AllDataReadyActionTrace
1317 cdebug << pthread_self() << "/" << ThreadNo()
1318 << " <-- DataUndef_AllDataReadyAction " << Name() << endl;
1323 int GraphExecutor::InNode::DataReady_SuspendAction() {
1324 cdebug << pthread_self() << "/" << ThreadNo()
1325 << "DataReady_SuspendAction --> Suspend " << Name()
1326 << " Threads " << _OutNode->Threads() << " SuspendedThreads "
1327 << _OutNode->SuspendedThreads() << endl;
1328 _OutNode->PushEvent( this , GraphExecutor::SuspendedReadyEvent ,
1329 GraphExecutor::SuspendedReadyState ) ;
1330 GraphExecutor::InNode * aReStartNode = SuspendAction() ;
1331 cdebug << pthread_self() << "/" << ThreadNo()
1332 << "DataReady_SuspendAction Resumed " << Name() << endl;
1333 if ( aReStartNode ) {
1334 _aReStartNode = NULL ;
1335 aReStartNode->SendEvent( _aReStartEvent ) ;
1338 SendEvent( GraphExecutor::ExecuteEvent ) ;
1343 int GraphExecutor::InNode::SuspendedReady_ResumeAction() {
1344 cdebug << pthread_self() << "/" << ThreadNo() << "SuspendedReady_ResumeAction "
1347 _OutNode->PushEvent( this , GraphExecutor::ResumedReadyEvent ,
1348 GraphExecutor::ResumedReadyState ) ;
1352 int GraphExecutor::InNode::DataReady_KillAction() {
1353 _OutNode->PushEvent( this , GraphExecutor::KilledReadyEvent ,
1354 GraphExecutor::KilledReadyState ) ;
1356 cdebug << pthread_self() << "/" << ThreadNo() << "DataReady_KillAction " << Name()
1357 << " will pthread_exit()" << endl;
1361 int GraphExecutor::InNode::DataReady_StopAction() {
1362 _OutNode->PushEvent( this , GraphExecutor::StoppedReadyEvent ,
1363 GraphExecutor::StoppedReadyState ) ;
1365 cdebug << pthread_self() << "/" << ThreadNo() << "DataReady_StopAction " << Name()
1366 << " will pthread_exit()" << endl;
1372 #define TraceDataReady_ExecuteAction 1
1373 int GraphExecutor::InNode::DataReady_ExecuteAction() {
1375 #if TraceDataReady_ExecuteAction
1376 cdebug_in << pthread_self() << "/" << ThreadNo() << " DataReady_ExecuteAction "
1379 _OutNode->PushEvent( this , GraphExecutor::ExecuteEvent ,
1380 GraphExecutor::ExecutingState ) ;
1386 Engines::Container_var myContainer ;
1387 Engines::Component_var myObjComponent ;
1389 SUPERV::GraphState PortState = SUPERV::ReadyState ;
1390 GraphExecutor::AutomatonState NewState = GraphExecutor::DataUndefState ;
1391 GraphExecutor::NodeEvent NewEvent = GraphExecutor::UndefinedEvent ;
1394 ServicesAnyData * InParametersList = NULL ;
1396 ServicesAnyData * OutParametersList = NULL ;
1398 nInParams = GetNodeInPortsSize() ;
1399 #if TraceDataReady_ExecuteAction
1400 char * aName = Name() ;
1401 cdebug << pthread_self() << "/" << ThreadNo() << " " << aName
1402 << " nInParams " << nInParams << " InParametersList "
1403 << (void * ) InParametersList << endl ;
1405 InParametersList = new ServicesAnyData[nInParams];
1406 InParametersSet( Err , nInParams , InParametersList ) ;
1408 nOutParams = GetNodeOutPortsSize() ;
1409 OutParametersList = new ServicesAnyData[nOutParams];
1410 InOutParametersSet( nOutParams , OutParametersList ) ;
1413 if ( !Err && IsComputingNode() ) {
1414 cdebug << ThreadNo() << " DataReady_ExecuteAction " << Name() << " "
1415 << " after creation of InParametersList : nInParams " << nInParams
1418 for ( i = 0 ; i < nInParams-1 ; i++ ) { // Without Gates
1419 cdebug << "InParametersList[" << i << "] : "
1420 << InParametersList[i].Name << " "
1421 << AnyValue( InParametersList[i].Value ) << endl ;
1423 CORBA::Object * obj ;
1424 InParametersList[0].Value >>= obj ;
1425 Engines::Component_var theObjComponent ;
1426 theObjComponent = Engines::Component::_narrow( obj ) ;
1427 DynInvoke( theObjComponent , "ping" ,
1428 NULL , 0 , NULL , 0 ) ;
1429 cdebug << ThreadNo() << " DataReady_ExecuteAction " << Name() << " ping done "
1431 cdebug << ThreadNo() << " DataReady_ExecuteAction " << Name() << " "
1432 << " after creation of OutParametersList :" << endl;
1433 for ( i = 0 ; i < nOutParams-1 ; i++ ) { // Without Gates
1434 cdebug << "OutParametersList[" << i << "] : "
1435 << OutParametersList[i].Name << " "
1436 << AnyValue( OutParametersList[i].Value ) << endl ;
1441 if ( !IsMacroNode() ) {
1443 if ( !IsFactoryNode() ) {
1444 #if TraceDataReady_ExecuteAction
1445 cdebug << ThreadNo() << "No Component : NO StartComponent & No Ping" << endl ;
1447 if ( IsComputingNode() ) {
1448 ObjInterface( true ) ;
1449 //JR 05.08.2005 DEBUG : that code runs with SALOME_3 (OMNIOrb4) ...
1450 #if OMNIORB_VERSION >= 4
1451 CORBA::Object * obj ;
1452 InParametersList[0].Value >>= obj ;
1453 myObjComponent = Engines::Component::_narrow( obj ) ;
1454 //JR 05.08.2005 DEBUG : the folowing code runs with OMNIOrb3 but gives
1455 // unpredictable results with SALOME_3 (OMNIOrb4) ...
1457 CORBA::Object_ptr obj ;
1458 InParametersList[0].Value >>= obj ;
1459 CORBA::Object_var objvar = CORBA::Object_var( obj ) ;
1460 myObjComponent = Engines::Component::_duplicate( Engines::Component::_narrow( objvar ) ) ;
1466 else if ( CORBA::is_nil( Component() ) ) {
1467 Err = !_OutNode->Graph()->StartComponent( ThreadNo() , Computer() ,
1468 //JR 17.02.2005 Memory Leak my_strdup( ComponentName() ) ,
1470 myContainer , myObjComponent ) ;
1471 ObjInterface( false ) ;
1472 SetContainer( myContainer ) ;
1473 SetComponent( myObjComponent ) ;
1476 myContainer = Container() ;
1477 myObjComponent = Component() ;
1478 #if TraceDataReady_ExecuteAction
1479 cdebug << ThreadNo() << "Component known : NO StartComponent & Ping"
1482 myObjComponent->ping() ;
1485 cdebug << "ping() ERROR catched" << endl ;
1491 if ( Err || ControlState() == SUPERV::ToKillState ||
1492 ControlState() == SUPERV::ToKillDoneState ||
1493 ControlState() == SUPERV::ToStopState ) {
1494 #if TraceDataReady_ExecuteAction
1495 cdebug << ThreadNo() << "StartComponent Error or ToKillState" << endl ;
1500 if ( ControlState() == SUPERV::ToSuspendState ) {
1501 #if TraceDataReady_ExecuteAction
1502 cdebug << ThreadNo() << "ToSuspendState before running." << endl ;
1503 MESSAGE(ThreadNo() << "ToSuspendState before running.") ;
1506 #if TraceDataReady_ExecuteAction
1508 cdebug << ThreadNo() << " Run( '" << ServiceName() << "'" ;
1509 for ( i = 0 ; i < (int ) ServiceInParameter().length() ; i++ ) {
1510 cdebug << " , " << InParametersList[ i ].Name << "[kind"
1511 << InParametersList[ i ].Value.type()->kind() << "]" ;
1513 for ( i = 0 ; i < (int ) ServiceOutParameter().length() ; i++ ) {
1514 cdebug << " , " << OutParametersList[ i ].Name << "[kind"
1515 << OutParametersList[ i ].Value.type()->kind() << "]" ;
1517 if ( IsOneOfInLineNodes() ) {
1518 cdebug << " , PyFuncName '" << InLineNode()->PyFuncName() << "' PyRunMethod "
1519 << InLineNode()->PyRunMethod() << " length "
1520 << (*InLineNode()->PythonFunction()).length()
1521 << " InParametersList " << InParametersList
1522 << " OutParametersList " << OutParametersList ;
1524 cdebug << ")" << endl ;
1527 if ( IsOneOfInLineNodes() ) {
1528 Err = DataReady_ExecuteActionInLineNodes( InParametersList ,
1529 OutParametersList ) ;
1534 if ( IsComputingNode() ) {
1535 cdebug << ThreadNo() << " DataReady_ExecuteAction " << Name()
1536 << " myObjComponent " << myObjComponent << " "
1537 << ObjectToString( myObjComponent ) << endl ;
1538 cdebug << ThreadNo() << " DataReady_ExecuteAction " << Name() << " "
1539 << " before DynInvoke nInParams " << nInParams
1542 CORBA::Object * obj ;
1543 InParametersList[0].Value >>= obj ;
1544 Engines::Component_var theObjComponent ;
1545 theObjComponent = Engines::Component::_narrow( obj ) ;
1546 DynInvoke( theObjComponent , "ping" ,
1547 NULL , 0 , NULL , 0 ) ;
1548 for ( i = 0 ; i < nInParams-1 ; i++ ) { // Without Gates
1549 cdebug << "InParametersList[" << i << "] : "
1550 << InParametersList[i].Name << " "
1551 << AnyValue( InParametersList[i].Value ) << endl ;
1556 #if TraceDataReady_ExecuteAction
1557 cdebug << "DynInvoke -> Names " << _OutNode->Name() << " " << Name() << endl ;
1559 DynInvoke( myObjComponent, "Names" ,
1560 _OutNode->Name() , Name() ) ;
1563 string anErrorMessage = string( "Dynamic CORBA call to Names for node " ) +
1564 string( Name() ) + " catched." ;
1565 _OutNode->Graph()->SetMessages( anErrorMessage ) ;
1566 cdebug << "DynInvoke Names catched ERROR" << endl ;
1568 // for DataStreamNodes : call of SetProperties ===> environment variables in the component/container
1569 if ( ComputingNode()->HasDataStream() ) {
1571 #if TraceDataReady_ExecuteAction
1572 cdebug << "DynInvoke -> SetProperties " << _OutNode->Name() << " " << Name() << endl ;
1574 Engines::FieldsDict_var dict = new Engines::FieldsDict;
1576 dict[ 0 ].key = CORBA::string_dup( "CAL_MACHINE");
1577 // myContainer->getHostName() ne renvoit pas le nom complet (avec domaine).
1578 // dict[ 0 ].value <<= myContainer->getHostName() ;
1579 char FullyQualifiedDomainName[256]="";
1580 gethostname(FullyQualifiedDomainName,255);
1581 dict[ 0 ].value <<= FullyQualifiedDomainName ;
1582 dict[ 1 ].key = CORBA::string_dup( "CAL_REPERTOIRE");
1583 dict[ 1 ].value <<= "/tmp" ;
1584 dict[ 2 ].key = CORBA::string_dup( "CAL_COUPLAGE");
1585 stringstream ofst1 ;
1586 ofst1 << ComputingNode()->SubStreamGraph() ;
1587 string cpl = string( "/tmp/" ) + string( _OutNode->Name() ) + string( "_" ) +
1588 ofst1.str() + string( ".cpl" );
1589 dict[ 2 ].value <<= cpl.c_str() ;
1590 dict[ 3 ].key = CORBA::string_dup( "SALOME_INSTANCE_NAME");
1591 string uname = Name();
1593 dict[ 3 ].value <<= uname.c_str() ;
1595 myObjComponent->setProperties( dict ) ;
1598 string anErrorMessage = string( "Dynamic CORBA call to setProperties for node " ) +
1599 string( Name() ) + " catched." ;
1600 _OutNode->Graph()->SetMessages( anErrorMessage ) ;
1601 cdebug << "DynInvoke setProperties catched ERROR" << endl ;
1607 if ( !Err && IsComputingNode() ) {
1608 #if TraceDataReady_ExecuteAction
1609 cdebug << ThreadNo() << " !ObjInterface " << Name()
1610 << " IsComputingNode DynInvoke" << endl ;
1611 cdebug << ServiceInParameter().length()-1 << " input parameters and "
1612 << ServiceOutParameter().length() << " output parameters" << endl ;
1614 IsLoading( false ) ;
1615 DynInvoke( myObjComponent,
1617 &InParametersList[1] , ServiceInParameter().length()-1 ,
1618 &OutParametersList[0] , ServiceOutParameter().length() ) ;
1620 { cdebug << ThreadNo() << " DataReady_ExecuteAction " << Name()
1621 << " myObjComponent " << myObjComponent << " "
1622 << ObjectToString( myObjComponent ) << endl ;
1623 cdebug << ThreadNo() << " DataReady_ExecuteAction " << Name() << " "
1624 << " after DynInvoke nInParams " << nInParams
1626 CORBA::Object * obj ;
1627 InParametersList[0].Value >>= obj ;
1628 Engines::Component_var theObjComponent ;
1629 theObjComponent = Engines::Component::_narrow( obj ) ;
1630 DynInvoke( theObjComponent , "ping" ,
1631 NULL , 0 , NULL , 0 ) ;
1632 for ( i = 0 ; i < nInParams-1 ; i++ ) { // Without Gates
1633 cdebug << "InParametersList[" << i << "] : "
1634 << InParametersList[i].Name << " "
1635 << AnyValue( InParametersList[i].Value ) << endl ;
1640 else if ( !Err && IsFactoryNode() ) {
1641 #if TraceDataReady_ExecuteAction
1642 cdebug << pthread_self() << "/" << ThreadNo() << " !ObjInterface " << Name()
1643 << " IsFactoryNode DynInvoke" << endl ;
1644 cdebug << ServiceInParameter().length() << " input parameters and "
1645 << ServiceOutParameter().length() << " output parameters" << endl ;
1647 IsLoading( false ) ;
1648 DynInvoke( myObjComponent,
1650 &InParametersList[0] , ServiceInParameter().length() ,
1651 &OutParametersList[0] , ServiceOutParameter().length() ) ;
1653 // cdebug << ThreadNo() << " Component::CpuUsed " << Name() << " "
1654 // << myObjComponent->CpuUsed_impl() << endl ;
1658 string anErrorMessage = string( "Dynamic CORBA call for node " ) +
1659 string( Name() ) + " catched." ;
1660 _OutNode->Graph()->SetMessages( anErrorMessage ) ;
1661 cdebug << pthread_self() << "/" << ThreadNo() << " !ObjInterface " << Name()
1662 << " Node(Component) Dynamic Call Exception catched ERROR"
1664 //Reset of _ThreadId in the Container ...
1666 // myObjComponent->Kill_impl() ;
1677 // if exception or something else - IsLoading( false ) may not NOT has been called
1681 if ( ControlState() == SUPERV::ToKillState ||
1682 ControlState() == SUPERV::ToKillDoneState ||
1683 ControlState() == SUPERV::ToStopState ) {
1684 PortState = SUPERV::ErrorState ;
1685 NewState = GraphExecutor::KilledState ;
1686 NewEvent = GraphExecutor::KillEvent ;
1689 PortState = SUPERV::ErrorState ;
1690 NewState = GraphExecutor::ErroredState ;
1691 NewEvent = GraphExecutor::ErrorEvent ;
1695 PortState = SUPERV::ReadyState ;
1696 NewState = GraphExecutor::DataReadyState ;
1697 NewEvent = GraphExecutor::SuccessEvent ;
1700 if ( !IsMacroNode() ) {
1702 bool ErrOut = OutParametersSet( Err , PortState , nOutParams , OutParametersList ) ;
1704 NewEvent = GraphExecutor::ErrorEvent ;
1707 if ( !Err && IsComputingNode() ) {
1708 cdebug << ThreadNo() << " DataReady_ExecuteAction " << Name()
1709 << " myObjComponent " << myObjComponent << " "
1710 << ObjectToString( myObjComponent ) << endl ;
1711 cdebug << ThreadNo() << " DataReady_ExecuteAction " << Name() << " "
1712 << " delete [] InParametersList nInParams " << nInParams
1715 CORBA::Object * obj ;
1716 InParametersList[0].Value >>= obj ;
1717 Engines::Component_var theObjComponent ;
1718 theObjComponent = Engines::Component::_narrow( obj ) ;
1719 DynInvoke( theObjComponent , "ping" ,
1720 NULL , 0 , NULL , 0 ) ;
1721 for ( i = 0 ; i < nInParams-1 ; i++ ) { // Without Gates
1722 cdebug << "InParametersList[" << i << "] : "
1723 << InParametersList[i].Name << " "
1724 << AnyValue( InParametersList[i].Value ) << endl ;
1729 delete [] InParametersList ;
1732 cdebug << ThreadNo() << " DataReady_ExecuteAction " << Name()
1733 << " catch ERROR of delete [] InParametersList" << endl ;
1735 #if TraceDataReady_ExecuteAction
1736 cdebug << ThreadNo() << " DataReady_ExecuteAction " << Name() << " "
1737 << " delete [] OutParametersList :" << endl;
1739 for ( i = 0 ; i < nOutParams-1 ; i++ ) { // Without Gates
1740 cdebug << "OutParametersList[" << i << "] : "
1741 << OutParametersList[i].Name << " "
1742 << AnyValue( OutParametersList[i].Value ) << endl ;
1746 delete [] OutParametersList ;
1749 cdebug << ThreadNo() << " DataReady_ExecuteAction " << Name()
1750 << " catch ERROR of delete [] OutParametersList" << endl ;
1752 SendEvent( NewEvent ) ;
1755 GraphExecutor::DataFlow * aMacroGraph = GraphMacroNode()->CoupledNode()->GraphEditor()->Executor() ;
1756 #if TraceDataReady_ExecuteAction
1758 for ( i = 0 ; i < GraphMacroNode()->GetNodeOutPortsSize() ; i++ ) {
1759 cdebug << "Out" << i << " " << GraphMacroNode()->GetNodeOutPort( i )->PortName() << " "
1760 << GraphMacroNode()->GetChangeNodeOutPort( i )->PortState() << " Done="
1761 << GraphMacroNode()->GetChangeNodeOutPort( i )->PortDone() << " " ;
1762 if ( GraphBase::Base::_prof_debug ) {
1763 GraphMacroNode()->GetNodeOutPort( i )->StringValue( *GraphBase::Base::_fdebug ) ;
1765 if ( GraphMacroNode()->GetChangeNodeOutPort( i )->IsGate() ) {
1766 cdebug << " BoolValue " << GraphMacroNode()->GetChangeNodeOutPort( i )->BoolValue() ;
1770 cdebug << ThreadNo() << " DataReady_ExecuteAction " << aMacroGraph << " "
1771 << aMacroGraph->Name() << " ->DoneWait()"
1772 << " State " << aMacroGraph->State() << endl;
1774 aMacroGraph->DoneWait() ;
1775 #if TraceDataReady_ExecuteAction
1776 cdebug << ThreadNo() << " DataReady_ExecuteAction " << Name() << " State "
1777 << aMacroGraph->State() << endl;
1780 //JR 29.09.2005 Debug for CEA (examples/GraphMacroNodes1) :
1781 // Set of value of the OutGate of the corresponding MacroNode was missing
1782 CORBA::Any anAny = CORBA::Any() ;
1783 anAny <<= (long ) 1 ;
1784 GraphMacroNode()->GraphEditor()->Executor()->OutputOfAny( Name() , "Gate" , anAny ) ;
1785 #if TraceDataReady_ExecuteAction
1786 cdebug << "DataReady_ExecuteAction OutputOfAny( " << Name() << " , Gate , 1 )" << endl ;
1788 for ( i = 0 ; i < GraphMacroNode()->GetNodeOutPortsSize() ; i++ ) {
1789 cdebug << "Out" << i << " " << GraphMacroNode()->GetNodeOutPort( i )->PortName() << " "
1790 << GraphMacroNode()->GetChangeNodeOutPort( i )->PortState() << " Done="
1791 << GraphMacroNode()->GetChangeNodeOutPort( i )->PortDone() << " " ;
1792 if ( GraphBase::Base::_prof_debug ) {
1793 GraphMacroNode()->GetNodeOutPort( i )->StringValue( *GraphBase::Base::_fdebug ) ;
1795 if ( GraphMacroNode()->GetChangeNodeOutPort( i )->IsGate() ) {
1796 cdebug << " BoolValue " << GraphMacroNode()->GetChangeNodeOutPort( i )->BoolValue() ;
1800 cdebug << ThreadNo() << " DataReady_ExecuteAction " << Name() << " State " << aMacroGraph->State() << endl;
1802 if ( aMacroGraph->State() == SUPERV::DoneState ) {
1803 PortState = SUPERV::ReadyState ;
1804 NewState = GraphExecutor::DataReadyState ;
1805 NewEvent = GraphExecutor::SuccessEvent ;
1809 if ( ControlState() == SUPERV::ToKillState ||
1810 ControlState() == SUPERV::ToKillDoneState ||
1811 ControlState() == SUPERV::ToStopState ) {
1812 PortState = SUPERV::ErrorState ;
1813 NewState = GraphExecutor::KilledState ;
1814 NewEvent = GraphExecutor::KillEvent ;
1817 PortState = SUPERV::ErrorState ;
1818 NewState = GraphExecutor::ErroredState ;
1819 NewEvent = GraphExecutor::ErrorEvent ;
1822 bool ErrOut = OutParametersSet( Err , PortState , nOutParams , OutParametersList ) ;
1824 NewEvent = GraphExecutor::ErrorEvent ;
1826 delete [] InParametersList ;
1827 delete [] OutParametersList ;
1828 SendEvent( NewEvent ) ;
1831 #if TraceDataReady_ExecuteAction
1832 cdebug_out << ThreadNo() << " DataReady_ExecuteAction " << Name() << endl;
1837 int GraphExecutor::InNode::DataReady_ExecuteActionInLineNodes( ServicesAnyData * InParametersList ,
1838 ServicesAnyData * OutParametersList ) {
1840 #if TraceDataReady_ExecuteAction
1841 cdebug_in << pthread_self() << "/" << ThreadNo()
1842 << " DataReady_ExecuteActionInLineNodes " << Name()
1843 << " InParametersList " << InParametersList
1844 << " OutParametersList " << OutParametersList << endl;
1847 bool StsPyDynInvoke = true ;
1848 _OutNode->PyThreadLock() ;
1851 bool ItIsaLoop = false ;
1852 bool CopyInOut = false ;
1853 if ( IsInLineNode() &&
1854 strlen( InLineNode()->PyFuncName() ) ) {
1855 #if TraceDataReady_ExecuteAction
1856 cdebug << ThreadNo() << " !ObjInterface " << Name() << " PyFuncName '"
1857 << InLineNode()->PyFuncName()
1858 << "' IsInLineNode PyDynInvoke" << endl ;
1860 StsPyDynInvoke = PyDynInvoke( InLineNode()->PyRunMethod() ,
1861 InLineNode()->PyFuncName() ,
1862 InParametersList , ServiceInParameter().length() ,
1863 OutParametersList , ServiceOutParameter().length() ) ;
1864 if ( !StsPyDynInvoke ) {
1865 RemovePyDynInvoke( InLineNode()->PyFuncName() ) ;
1868 else if ( IsLoopNode() ) {
1870 Err = DataReady_ExecuteActionLoopNodes( InParametersList ,
1874 else if ( IsSwitchNode() && /*InLineNode()->PyRunMethod() &&*/
1875 strlen( InLineNode()->PyFuncName() ) ) {
1876 #if TraceDataReady_ExecuteAction
1877 cdebug << ThreadNo() << " !ObjInterface " << Name() << " PyFuncName '"
1878 << InLineNode()->PyFuncName()
1879 << "' IsSwitchNode PyDynInvoke" << endl ;
1881 StsPyDynInvoke = PyDynInvoke( InLineNode()->PyRunMethod() ,
1882 InLineNode()->PyFuncName() ,
1883 InParametersList , ServiceInParameter().length() ,
1884 OutParametersList , ServiceOutParameter().length() ) ;
1886 if ( !StsPyDynInvoke ) {
1887 string anErrorMessage = string( "Dynamic Python call for node " ) +
1888 string( Name() ) + " function " +
1889 InLineNode()->PyFuncName() + " error." ;
1890 _OutNode->Graph()->SetMessages( anErrorMessage ) ;
1891 RemovePyDynInvoke( InLineNode()->PyFuncName() ) ;
1894 else if ( IsGOTONode() && /*InLineNode()->PyRunMethod() &&*/
1895 strlen( InLineNode()->PyFuncName() ) ) {
1896 #if TraceDataReady_ExecuteAction
1897 cdebug << ThreadNo() << " !ObjInterface " << Name() << " PyFuncName '"
1898 << InLineNode()->PyFuncName()
1899 << "' IsGOTONode PyDynInvoke" << endl ;
1902 StsPyDynInvoke = PyDynInvoke( InLineNode()->PyRunMethod() ,
1903 InLineNode()->PyFuncName() ,
1904 InParametersList , ServiceInParameter().length() ,
1905 OutParametersList , ServiceOutParameter().length() ) ;
1907 if ( !StsPyDynInvoke ) {
1908 string anErrorMessage = string( "Dynamic Python call for node " ) +
1909 string( Name() ) + " function " +
1910 InLineNode()->PyFuncName() + " error." ;
1911 _OutNode->Graph()->SetMessages( anErrorMessage ) ;
1912 RemovePyDynInvoke( GOTONode()->PyFuncName() ) ;
1915 else if ( ( IsEndSwitchNode() ) &&
1916 InLineNode()->PyRunMethod() && strlen( InLineNode()->PyFuncName() ) ) {
1917 #if TraceDataReady_ExecuteAction
1918 cdebug << ThreadNo() << " !ObjInterface " << Name() << " PyFuncName '"
1919 << InLineNode()->PyFuncName()
1920 << "' IsSwitchNode PyDynInvoke" << endl ;
1923 StsPyDynInvoke = PyDynInvoke( InLineNode()->PyRunMethod() ,
1924 InLineNode()->PyFuncName() ,
1925 InParametersList , ServiceInParameter().length() ,
1926 OutParametersList , ServiceOutParameter().length() ) ;
1928 if ( !StsPyDynInvoke ) {
1929 string anErrorMessage = string( "Dynamic Python call for node " ) +
1930 string( Name() ) + " function " +
1931 InLineNode()->PyFuncName() + " error." ;
1932 _OutNode->Graph()->SetMessages( anErrorMessage ) ;
1933 RemovePyDynInvoke( InLineNode()->PyFuncName() ) ;
1936 else if ( IsEndLoopNode() &&
1937 InLineNode()->PyRunMethod() && strlen( InLineNode()->PyFuncName() ) ) {
1938 #if TraceDataReady_ExecuteAction
1939 cdebug << ThreadNo() << " !ObjInterface " << Name() << " PyFuncName '"
1940 << InLineNode()->PyFuncName()
1941 << "' IsSwitchNode PyDynInvoke" << endl ;
1944 StsPyDynInvoke = PyDynInvoke( InLineNode()->PyRunMethod() ,
1945 InLineNode()->PyFuncName() ,
1946 InParametersList , ServiceInParameter().length() + 1 ,
1947 OutParametersList , ServiceOutParameter().length() + 1 ) ;
1949 if ( !StsPyDynInvoke ) {
1950 string anErrorMessage = string( "Dynamic Python call for node " ) +
1951 string( Name() ) + " function " +
1952 InLineNode()->PyFuncName() + " error." ;
1953 _OutNode->Graph()->SetMessages( anErrorMessage ) ;
1954 RemovePyDynInvoke( InLineNode()->PyFuncName() ) ;
1958 if ( (!ItIsaLoop && ( InLineNode()->PyRunMethod() == NULL ||
1959 strlen( InLineNode()->PyFuncName() ) == 0 ) ) || CopyInOut ) {
1960 // This is a void Python Function : without code (No PyFuncName)
1961 #if TraceDataReady_ExecuteAction
1962 cdebug << ThreadNo() << " !ObjInterface " << Name()
1963 << " Copy of " << ServiceInParameter().length()
1964 << " OutParameters" << endl ;
1969 if ( IsLoopNode() || IsEndLoopNode() ) {
1971 argin0 = 1 ; // after DoLoop
1972 if ( IsLoopNode() ) { // More() is void
1973 #if TraceDataReady_ExecuteAction
1974 cdebug << Name() << " Not Beginning of loop and non void EndLoop : DoLoop = EndLoop(DoLoop)"
1977 GraphExecutor::InNode * anEndLoopNode = (GraphExecutor::InNode * ) CoupledNode()->GetInNode() ;
1978 OutParametersList[0].Value = anEndLoopNode->GetNodeOutLoop()->Value() ; // DoLoop = EndLoop(DoLoop)
1981 //PAL8072 ==> PAL8512
1982 //JR 24.03.2005 : Debug : void InLine Python function : check of the number of Input Ports
1983 // equals the number of Output Ports was missing
1984 if ( ServiceInParameter().length() != ServiceOutParameter().length() ) {
1985 string anErrorMessage = string( "Inconsistent number of In<->Out parameters for the vois Python function of the node " ) +
1987 _OutNode->Graph()->SetMessages( anErrorMessage ) ;
1988 StsPyDynInvoke = false ;
1991 for ( i = 0 ; i < (int ) ServiceInParameter().length() ; i++ ) {
1992 OutParametersList[argout0 + i].Value = InParametersList[argin0 + i].Value ;
1994 #if TraceDataReady_ExecuteAction
1995 cdebug << "ArgOut->In" << InParametersList[argin0 + i].Name.c_str()
1996 << " " << AnyValue( InParametersList[argin0 + i].Value )
2002 if ( !StsPyDynInvoke ) {
2004 string anErrorMessage = string( "Dynamic Python call for node " ) +
2005 string( Name() ) + " error." ;
2006 _OutNode->Graph()->SetMessages( anErrorMessage ) ;
2007 cdebug << ThreadNo() << " InLineNode " << Name()
2008 << " Python Dynamic Call Error"
2014 string anErrorMessage = string( "Dynamic Python call for node " ) +
2015 string( Name() ) + " catched." ;
2016 _OutNode->Graph()->SetMessages( anErrorMessage ) ;
2017 cdebug << ThreadNo() << " InLineNode " << Name()
2018 << " Python Dynamic Call Exception catched ERROR"
2022 _OutNode->PyThreadUnLock() ;
2023 #if TraceDataReady_ExecuteAction
2024 cdebug_out << pthread_self() << "/" << ThreadNo()
2025 << " DataReady_ExecuteActionInLineNodes " << Name() << endl;
2030 int GraphExecutor::InNode::DataReady_ExecuteActionLoopNodes( ServicesAnyData * InParametersList ,
2031 ServicesAnyData * OutParametersList ,
2032 bool & CopyInOut ) {
2034 #if TraceDataReady_ExecuteAction
2035 cdebug_in << pthread_self() << "/" << ThreadNo()
2036 << " DataReady_ExecuteActionLoopNodes " << Name()
2037 << " InParametersList " << InParametersList
2038 << " OutParametersList " << OutParametersList << endl;
2041 bool StsPyDynInvoke = true ;
2042 bool CopyOutIn = false ;
2043 // Switch between Init() and Next()
2044 // if InLoop port is true and does not come from EndLoop ==> execute Init
2045 // if InLoop port is false or come from EndLoop ==> execute Next
2047 if ( strlen( InLineNode()->PyFuncName() ) ) { // InLoop Port = true ==> Init()
2048 #if TraceDataReady_ExecuteAction
2049 cdebug << ThreadNo() << " !ObjInterface " << Name()
2050 << " IsLoopNode PyDynInvoke '" << InLineNode()->PyFuncName()
2051 << "' InitLoop " << LoopNode()->PyRunMethod() << endl ;
2053 StsPyDynInvoke = PyDynInvoke( InLineNode()->PyRunMethod() ,
2054 InLineNode()->PyFuncName() ,
2055 &InParametersList[1] , ServiceInParameter().length() ,
2056 &OutParametersList[1] , ServiceOutParameter().length() ) ;
2057 if ( !StsPyDynInvoke ) {
2058 string anErrorMessage = string( "Dynamic Python call for node " ) +
2059 string( Name() ) + " function " +
2060 InLineNode()->PyFuncName() + " error." ;
2061 _OutNode->Graph()->SetMessages( anErrorMessage ) ;
2062 RemovePyDynInvoke( InLineNode()->PyFuncName() ) ;
2067 #if TraceDataReady_ExecuteAction
2068 cdebug << ThreadNo() << " !ObjInterface " << Name()
2069 << " IsLoopNode NO PyDynInvoke Void PyFuncName InitLoop" << endl ;
2072 #if TraceDataReady_ExecuteAction
2073 cdebug << ThreadNo() << " !ObjInterface " << Name()
2074 << " IsLoopNode _InitLoop Reset after Init() Python Function" << endl ;
2078 else if ( LoopNode()->PyNextMethod() &&
2079 strlen( LoopNode()->PyNextName() ) ){ // InLoop Port = false ==> Next()
2080 #if TraceDataReady_ExecuteAction
2081 cdebug << ThreadNo() << " !ObjInterface " << Name()
2082 << " IsLoopNode PyDynInvoke '" << LoopNode()->PyNextName()
2083 << "' " << LoopNode()->PyNextMethod() << endl ;
2085 StsPyDynInvoke = PyDynInvoke( LoopNode()->PyNextMethod() ,
2086 LoopNode()->PyNextName() ,
2087 &InParametersList[1] , ServiceInParameter().length() ,
2088 &OutParametersList[1] , ServiceOutParameter().length() ) ;
2089 if ( !StsPyDynInvoke ) {
2090 string anErrorMessage = string( "Dynamic Python call for node " ) +
2091 string( Name() ) + " function " +
2092 LoopNode()->PyNextName() + " error." ;
2093 _OutNode->Graph()->SetMessages( anErrorMessage ) ;
2094 RemovePyDynInvoke( LoopNode()->PyNextName() ) ;
2099 #if TraceDataReady_ExecuteAction
2100 cdebug << ThreadNo() << " !ObjInterface " << Name()
2101 << " IsLoopNode NO PyDynInvoke Void PyFuncName NextLoop" << endl ;
2104 if ( StsPyDynInvoke ) {
2106 #if TraceDataReady_ExecuteAction
2107 cdebug << ThreadNo() << " !ObjInterface " << Name()
2108 << " IsLoopNode PyDynInvoke '" << LoopNode()->PyMoreName()
2109 << "' Copy of " << ServiceInParameter().length()
2110 << " OutParameters" << endl ;
2113 // Start at 1 : Do not copy InLoop ( InLoop == true <==> Init ; InLoop == false <==> Next )
2114 for ( i = 1 ; i <= (int ) ServiceInParameter().length() ; i++ ) {
2115 InParametersList[i].Value = OutParametersList[i].Value ;
2116 InParametersList[i].Name = OutParametersList[i].Name ;
2117 #if TraceDataReady_ExecuteAction
2118 cdebug << "ArgOut->In" << InParametersList[ i].Name.c_str()
2119 << " " << AnyValue( InParametersList[ i].Value )
2124 if ( LoopNode()->PyMoreMethod() && strlen( LoopNode()->PyMoreName() ) ) {
2125 #if TraceDataReady_ExecuteAction
2126 cdebug << ThreadNo() << " !ObjInterface " << Name()
2127 << " IsLoopNode PyDynInvoke '" << LoopNode()->PyMoreName()
2128 << "' " << LoopNode()->PyMoreMethod() << endl ;
2130 StsPyDynInvoke = PyDynInvoke( LoopNode()->PyMoreMethod() ,
2131 LoopNode()->PyMoreName() ,
2132 &InParametersList[1] , ServiceInParameter().length() ,
2133 &OutParametersList[0] , ServiceOutParameter().length()+1 ) ;
2134 if ( !StsPyDynInvoke ) {
2135 string anErrorMessage = string( "Dynamic Python call for node " ) +
2136 string( Name() ) + " function " +
2137 LoopNode()->PyMoreName() + " error." ;
2138 _OutNode->Graph()->SetMessages( anErrorMessage ) ;
2139 RemovePyDynInvoke( LoopNode()->PyMoreName() ) ;
2143 #if TraceDataReady_ExecuteAction
2144 cdebug << ThreadNo() << " !ObjInterface " << Name()
2145 << " IsLoopNode PyDynInvoke '" << LoopNode()->PyMoreName()
2146 << "' No MoreMethod" << endl ;
2153 cdebug << ThreadNo() << " InLineNode " << Name() << " "
2154 << InLineNode()->PyFuncName() << "/" << LoopNode()->PyNextName()
2155 << " Python Dynamic Call Error"
2158 #if TraceDataReady_ExecuteAction
2159 cdebug_out << pthread_self() << "/" << ThreadNo()
2160 << " DataReady_ExecuteActionLoopNodes " << Name() << endl;
2165 int GraphExecutor::InNode::Executing_SuspendAction() {
2166 _OutNode->PushEvent( this , GraphExecutor::SuspendedExecutingEvent ,
2167 GraphExecutor::SuspendedExecutingState ) ;
2168 cdebug << ThreadNo() << " Executing_SuspendAction " << Name() << endl;
2172 int GraphExecutor::InNode::SuspendedExecuting_ResumeAction() {
2173 cdebug << ThreadNo() << " SuspendedExecuting_ResumeAction " << Name() << endl;
2174 GraphExecutor::AutomatonState next_state ;
2175 next_state = Automaton()->NextState( State() , GraphExecutor::ExecutingEvent ) ;
2176 _OutNode->NewThread() ; // Only for Threads count
2177 _OutNode->PushEvent( this , GraphExecutor::ResumedExecutingEvent ,
2179 State( next_state ) ;
2183 int GraphExecutor::InNode::Executing_KillAction() {
2184 cdebug << ThreadNo() << " Executing_KillAction " << Name() << " Thread " << ThreadNo()<< endl;
2186 if ( pthread_self() == ThreadNo() ) {
2187 cdebug << "Executing_KillAction would pthread_canceled itself" << endl ;
2189 _OutNode->PushEvent( this , GraphExecutor::KilledExecutingEvent ,
2190 GraphExecutor::KilledExecutingState ) ;
2193 else if ( pthread_cancel( ThreadNo() ) ) {
2194 perror("Executing_KillAction pthread_cancel error") ;
2197 cdebug << pthread_self() << " Executing_KillAction : ThreadId " << ThreadNo()
2198 << " pthread_canceled" << endl ;
2200 _OutNode->ExitThread( ThreadNo() ) ;
2201 _OutNode->PushEvent( this , GraphExecutor::KilledExecutingEvent ,
2202 GraphExecutor::KilledExecutingState ) ;
2207 int GraphExecutor::InNode::Executing_StopAction() {
2208 cdebug << ThreadNo() << " Executing_StopAction " << Name() << " Thread " << ThreadNo() << endl;
2210 if ( pthread_cancel( ThreadNo() ) ) {
2211 perror("Executing_KillAction pthread_cancel error") ;
2214 cdebug << pthread_self() << " Executing_KillAction : ThreadId " << ThreadNo()
2215 << " pthread_canceled" << endl ;
2217 _OutNode->ExitThread( ThreadNo() ) ;
2218 _OutNode->PushEvent( this , GraphExecutor::StoppedExecutingEvent ,
2219 GraphExecutor::StoppedExecutingState ) ;
2224 int GraphExecutor::InNode::Executing_SuccessAction() {
2225 // cdebug << ThreadNo() << " --> Executing_SuccessAction " << Name() << endl;
2226 _OutNode->PushEvent( this , GraphExecutor::SuccessedExecutingEvent ,
2227 GraphExecutor::SuccessedState ) ;
2228 // MESSAGE(pthread_self() << "Executor::InNode::Executing_SuccessAction of " << Name()
2229 // << " ControlState " << Automaton()->ControlStateName( ControlState() )
2230 // << " AFTER execution ThreadNo " << ThreadNo() ) ;
2231 SUPERV::ControlState aControl = ControlState() ;
2232 switch ( aControl ) {
2233 case SUPERV::VoidState : {
2234 SendEvent( SuccessEvent ) ;
2237 case SUPERV::ToSuspendState : {
2238 SendEvent( SuccessEvent ) ;
2241 case SUPERV::ToSuspendDoneState : {
2242 SendEvent( GraphExecutor::SuspendEvent ) ;
2245 case SUPERV::ToKillState : {
2246 SendEvent( GraphExecutor::KillEvent ) ;
2249 case SUPERV::ToKillDoneState : {
2250 SendEvent( GraphExecutor::KillEvent ) ;
2253 case SUPERV::ToStopState : {
2254 SendEvent( GraphExecutor::StopEvent ) ;
2258 cdebug << ThreadNo()
2259 << " GraphExecutor::InNodeThreads::Executing_SuccessAction Error Undefined Control : "
2260 << aControl << endl ;
2264 // cdebug << ThreadNo() << " <-- Executing_SuccessAction " << Name() << endl;
2268 int GraphExecutor::InNode::Errored_ExecutingAction() {
2269 cdebug << ThreadNo() << " --> Errored_ExecutingAction " << Name() << endl;
2270 _OutNode->PushEvent( this , GraphExecutor::ErroredExecutingEvent ,
2271 GraphExecutor::ErroredState ) ;
2273 _OutNode->NodeAborted( Name() ) ;
2275 SUPERV::ControlState aControl = ControlState() ;
2276 switch ( aControl ) {
2277 case SUPERV::VoidState : {
2278 SendEvent( ErrorEvent ) ;
2281 case SUPERV::ToSuspendState : {
2282 SendEvent( ErrorEvent ) ;
2285 case SUPERV::ToSuspendDoneState : {
2286 SendEvent( GraphExecutor::SuspendEvent ) ;
2289 case SUPERV::ToKillState : {
2290 SendEvent( GraphExecutor::KillEvent ) ;
2293 case SUPERV::ToKillDoneState : {
2294 SendEvent( GraphExecutor::KillEvent ) ;
2297 case SUPERV::ToStopState : {
2298 SendEvent( GraphExecutor::StopEvent ) ;
2302 cdebug << ThreadNo()
2303 << " GraphExecutor::InNodeThreads::Errored_ExecutingAction Error Undefined Control : "
2304 << aControl << endl ;
2308 cdebug << ThreadNo() << " <-- Errored_ExecutingAction " << Name() << endl;
2312 #define SetWaitingStatesTrace 0
2313 // Set SUPERV::WaitingState to all InPorts
2314 void GraphExecutor::InNode::SetWaitingStates(GraphExecutor::InNode * EndNode ) {
2317 bool docdebug = false ;
2318 State( GraphExecutor::DataWaitingState ) ;
2319 #if SetWaitingStatesTrace
2320 cdebug << "SetWaitingStates " << Name() << " " << Automaton()->StateName( State() ) << endl ;
2322 for ( i = 0 ; i < GetNodeInPortsSize() ; i++ ) {
2323 GraphBase::InPort * anInPort = GetChangeNodeInPort( i ) ;
2324 #if SetWaitingStatesTrace
2325 cdebug << "SetWaitingStates InPort " << Name() << "( " << anInPort->PortName() << " ) "
2326 << anInPort->PortStatus() << " " << anInPort->PortState() << endl ;
2329 // JR Debug 07.01.2005 : Close the Gates instead of open !!!
2330 if ( anInPort->IsGate() ) { // Loop : Close the doors
2331 GraphBase::OutPort * anOutPort = anInPort->GetOutPort() ;
2333 //JR 21.02.2005 Debug Memory leak : CORBA::Any * anAny = new CORBA::Any() ;
2334 CORBA::Any anAny = CORBA::Any() ;
2335 // *anAny <<= (long ) 1 ;
2336 //JR 21.02.2005 Debug Memory leak : *anAny <<= (long ) 0 ;
2337 anAny <<= (long ) 0 ;
2338 anOutPort->SetValue( anAny ) ;
2339 anInPort->PortState( SUPERV::WaitingState ) ;
2343 else if ( anInPort->PortState() != SUPERV::WaitingState &&
2344 !anInPort->IsDataConnected() ) {
2346 #if SetWaitingStatesTrace
2347 cdebug << ThreadNo()
2348 << " --> GraphExecutor::InNodeThreads::SetWaitingStates " << Name() << endl;
2352 if ( !anInPort->IsDataStream() ) {
2353 anInPort->PortState( SUPERV::WaitingState ) ;
2356 #if SetWaitingStatesTrace
2357 cdebug << " --> InPort " << Name() << "( " << anInPort->PortName() << " ) "
2358 << anInPort->PortStatus() << " " << anInPort->PortState() << endl ;
2361 for ( i = 0 ; i < GetNodeOutPortsSize() ; i++ ) {
2362 GraphBase::OutPort * anOutPort = GetChangeNodeOutPort( i ) ;
2364 //JR 07.03.2005 Debug : Reset of Done flag in OutPorts !... :
2365 if ( !anOutPort->IsDataStream() ) {
2366 anOutPort->PortDone( false ) ;
2367 anOutPort->PortState( SUPERV::WaitingState ) ;
2369 for ( j = 0 ; j < anOutPort->InPortsSize() ; j++ ) {
2370 if ( !( IsGOTONode() && anOutPort->IsGate() ) &&
2371 !( IsEndLoopNode() && ( anOutPort->IsGate() || anOutPort->IsLoop() ) ) &&
2372 !anOutPort->IsDataStream() &&
2373 !anOutPort->ChangeInPorts( j )->IsDataStream() &&
2374 !anOutPort->ChangeInPorts( j )->IsExternConnected() ) {
2375 #if SetWaitingStatesTrace
2376 cdebug << ThreadNo()
2377 << " InNodeThreads::SetWaitingStates OutPort "
2378 << Name() << "/" << anOutPort->ChangeInPorts( j )->NodeName() << "( "
2379 << anOutPort->PortName() << " " << anOutPort->PortStatus() << " ) --> InPort "
2380 << anOutPort->ChangeInPorts( j )->NodeName() << "( "
2381 << anOutPort->ChangeInPorts( j )->PortName() << " "
2382 << anOutPort->ChangeInPorts( j )->PortStatus() << " )" << endl;
2384 GraphBase::ComputingNode * aToNode ;
2385 aToNode = _OutNode->Graph()->GetChangeGraphNode( anOutPort->ChangeInPorts( j )->NodeName() ) ;
2386 // JR 12.01.2005 Debug : the OutPort linked to the InPort of a EndSwitchNode was changed so final
2387 // values of InPorts of EndSwitchNode may be wrong
2388 // (depending of order of linkednodes)
2389 if ( !aToNode->IsEndSwitchNode() &&
2390 strcmp( anOutPort->ChangeInPorts( j )->GetOutPort()->NodeName() , Name() ) ) {
2391 // After EndLoopNode or GOTONode the Input Ports of LoopNode or LabelNode have their values from
2392 // EndLoopNode or GOTONode. But if there is several nested loops we should re-establish.
2393 #if SetWaitingStatesTrace
2394 cdebug << ThreadNo()
2395 << " InNodeThreads::SetWaitingStates Node " << Name() << " "
2396 << anOutPort->ChangeInPorts( j )->GetOutPort()->NodeName() << "( "
2397 << anOutPort->ChangeInPorts( j )->GetOutPort()->PortName() << " ) != "
2398 << Name() << " : Restored to " << anOutPort->NodeName() << "( "
2399 << anOutPort->PortName() << " )" << endl ;
2401 anOutPort->ChangeInPorts( j )->ChangeOutPort( anOutPort ) ;
2404 //JR 21.04.2005 Debug : the OutPort field of InPorts of EndSwitchNodes must be an OutPort
2405 // of a SwitchBranch or of a NOTSwitchBranch if a link exist
2406 // (if not there is no change)
2407 else if ( !IsSwitchNode() && aToNode->IsEndSwitchNode() &&
2408 strcmp( anOutPort->ChangeInPorts( j )->GetOutPort()->NodeName() , Name() ) ) {
2409 #if SetWaitingStatesTrace
2410 cdebug << ThreadNo()
2411 << " InNodeThreads::SetWaitingStates Node " << Name() << " "
2412 << anOutPort->ChangeInPorts( j )->GetOutPort()->NodeName() << "( "
2413 << anOutPort->ChangeInPorts( j )->GetOutPort()->PortName() << " ) != "
2414 << Name() << " : Restored to " << anOutPort->NodeName() << "( "
2415 << anOutPort->PortName() << " )" << endl ;
2417 anOutPort->ChangeInPorts( j )->ChangeOutPort( anOutPort ) ;
2419 GraphExecutor::InNode * aNode = (GraphExecutor::InNode * ) aToNode->GetInNode() ;
2420 if ( aNode != EndNode ) {
2421 aNode->SetWaitingStates( EndNode ) ;
2425 #if SetWaitingStatesTrace
2426 cdebug << " --> OutPort " << Name() << "( " << anOutPort->PortName() << " ) "
2427 << anOutPort->PortStatus() << " " << anOutPort->PortState() << endl ;
2432 #define SuccessActionTrace 1
2434 int GraphExecutor::InNode::Successed_SuccessAction() {
2435 #if SuccessActionTrace
2436 cdebug_in << pthread_self() << "/" << ThreadNo() << " Successed_SuccessAction " << Name()
2441 //JR 15.04.2005 Debug RetroConception :
2442 //The behavior of firstzeroNode and firsttoNode is not reliable and must be removed
2443 //The real problem is :
2444 // 1. send "SomeDataReady" event to linked nodes of the current node
2445 // 2. DO NOT send "AllDataReady" event even if all data are ready in SomeDataReady Action
2446 // but register only that all data are ready :
2447 // MAJOR ENHANCEMENT OF GRAPHEXECUTOR
2448 // 3. activate AllDataReady Action for each node (except the first one ) which have all
2449 // its data ready with a creation of a new thread
2450 // 3. activate AllDataReady Action for the first node which have all its data
2451 // ready in the current thread
2452 //The difficult problem (that I had in the past) was to clearly identify the above behavior ==>
2453 // firstzeroNode, firsttoNode, createnewthreadif, loackdatawait, "would dead lock" etc...
2454 // because if SomeDataReady Action see that all data were ready, it called immediately
2455 // AllDataReady Action ==> bugs difficult to understand and to reproduce
2456 //And the MAJOR DEBUG is (since the first "maquette") : we may have concurrent executions
2457 // of "SomeDataReady" in several threads and there WAS NO MUTEX to protect that
2458 // concurrent actions on the same node
2459 // int linkednodesnumber = LinkedNodesSize() ;
2460 // GraphExecutor::InNode *firstzeroNode = NULL ;
2461 GraphExecutor::InNode *firsttoNode = NULL ;
2462 GraphExecutor::InNode *toNode ;
2465 list<GraphExecutor::InNode *> SomeDataNodes ;
2469 if ( IsMacroNode() ) {
2470 #if SuccessActionTrace
2471 cdebug << pthread_self() << "/" << ThreadNo() << " Successed_SuccessAction " << Name() << " LinkedNodes->SomeDataReady already done for that MacroNode"
2477 //JR 09.02.2005 : That complicated part of the code manages LOOPS and GOTO
2478 if ( IsGOTONode() ||
2479 ( IsEndLoopNode() && GetNodeInLoop()->GetOutPort()->BoolValue() ) ) {
2480 #if SuccessActionTrace
2481 cdebug << pthread_self() << "/" << ThreadNo() << " Successed_SuccessAction " << Name()
2482 << " SetWaitingStates " << endl ;
2484 const GraphBase::OutPort * aGateOutPort ;
2485 if ( IsGOTONode() ) {
2486 aGateOutPort = GetNodeOutGate() ;
2489 aGateOutPort = GetNodeOutLoop() ;
2491 if ( aGateOutPort->InPortsSize() != 1 ) {
2492 cdebug << pthread_self() << "/" << ThreadNo() << " Successed_SuccessAction aGateOutPort->InPortsSize "
2493 << aGateOutPort->InPortsSize() << " != 1 ERROR " << Name() << endl ;
2495 GraphExecutor::InNode * aLabelNode = NULL ;
2496 for ( i = 0 ; i < aGateOutPort->InPortsSize() ; i++ ) {
2497 const GraphBase::InPort * anInPort = aGateOutPort->InPorts( i ) ;
2498 aLabelNode = (GraphExecutor::InNode *) _OutNode->Graph()->GetChangeGraphNode( anInPort->NodeName() )->GetInNode() ;
2499 #if SuccessActionTrace
2500 cdebug << pthread_self() << "/" << ThreadNo() << " Successed_SuccessAction " << Name() << " will Loop to HeadNode "
2501 << aLabelNode->Name() << " from port " << anInPort->PortName() << endl ;
2503 State( GraphExecutor::DataWaitingState ) ;
2504 aLabelNode->SetWaitingStates( this ) ;
2505 // JR 07.01.2005 Debug : Open the Gate of the coupledNode closed by SetWaitingStates
2506 GraphBase::OutPort * anOutPort = aLabelNode->GetChangeNodeInGate()->GetOutPort() ;
2508 //JR 21.02.2005 Debug Memory leak : CORBA::Any * anAny = new CORBA::Any() ;
2509 CORBA::Any anAny = CORBA::Any() ;
2510 //JR 21.02.2005 Debug Memory leak : *anAny <<= (long ) 1 ;
2511 anAny <<= (long ) 1 ;
2512 anOutPort->SetValue( anAny ) ;
2513 aLabelNode->GetChangeNodeInGate()->PortState( SUPERV::ReadyState ) ;
2516 for ( j = 0 ; j < aLabelNode->GetNodeInPortsSize() ; j++ ) {
2517 const GraphBase::InPort * anInPort = aLabelNode->GetNodeInPort( j ) ;
2518 if ( anInPort->GetOutPort() ) {
2519 #if SuccessActionTrace
2520 cdebug << aLabelNode->Name() << "(" << anInPort->PortName() << ") value : "
2521 << anInPort->GetOutPort()->NodeName() << "(" << anInPort->GetOutPort()->PortName() << ")"
2526 //PAL8176 ==> PAL8516
2527 //JR 24.03.2005 Debug : the number of OutPorts of a GOTONode and of InPorts of its linked
2528 // InLine node must be the same
2529 if ( GetNodeOutPortsSize() != aLabelNode-> GetNodeInPortsSize() ) {
2530 cdebug << pthread_self() << "/" << ThreadNo()
2531 << " Successed_SuccessAction # number of ports " << GetNodeOutPortsSize()
2532 << " != " << aLabelNode-> GetNodeInPortsSize() << endl ;
2533 SendEvent( GraphExecutor::ErrorEvent ) ;
2537 for ( j = 0 ; j < GetNodeOutPortsSize() ; j++ ) {
2538 GraphBase::OutPort * aBusParamOutPort = GetChangeNodeOutPort( j ) ;
2539 if ( !aBusParamOutPort->IsGate() ) {
2540 GraphBase::InPort * aBusParamChangeInPort = NULL ;
2541 if ( aBusParamOutPort->IsLoop() ) {
2542 // For EndLoop do not copy EndLoop(DoLoop) in Loop(InLoop)
2543 // aBusParamChangeInPort = aLabelNode->GetChangeNodeInLoop() ;
2546 aBusParamChangeInPort = aLabelNode->GetChangeInPort( aBusParamOutPort->PortName() ) ;
2548 if ( aBusParamChangeInPort ) {
2549 aBusParamChangeInPort->ChangeOutPort( aBusParamOutPort ) ;
2550 #if SuccessActionTrace
2551 cdebug << pthread_self() << "/" << ThreadNo() << " Successed_SuccessAction " << Name() << " ChangeOutPort to HeadNode "
2552 << aLabelNode->Name() << "(" << aBusParamChangeInPort->PortName() << ") from port "
2553 << aBusParamOutPort->PortName() << endl ;
2556 else if ( IsGOTONode() ) {
2557 //PAL8176 ==> PAL8516
2558 //JR 24.03.2005 Debug : the names of OutPorts of a GOTONode and of InPorts of its linked
2559 // InLine node must be the same
2560 cdebug << pthread_self() << "/" << ThreadNo()
2561 << " Successed_SuccessAction # names of ports "
2562 << aBusParamOutPort->PortName() << endl ;
2563 SendEvent( GraphExecutor::ErrorEvent ) ;
2571 //JR 15.04.2005 Debug PAL8624 RetroConception :
2572 // THERE IS ONLY ONE NODE COUPLED TO A GOTONODE OR AN ENDLOOPNODE BUT Mutex/Lock for consistency
2574 const GraphBase::InPort * aGateInPort = aLabelNode->GetNodeInGate() ;
2575 if ( aGateInPort ) {
2576 if ( aGateInPort->GetOutPort() ) {
2577 //JR 21.02.2005 Debug Memory leak : aGateInPort->GetOutPort()->Value( aGateOutPort->Value() ) ;
2578 //JR 30.03.2005 aGateInPort->GetOutPort()->Value( *aGateOutPort->Value() ) ;
2579 aGateInPort->GetOutPort()->SetValue( aGateOutPort->Value() ) ;
2581 //JR 15.04.2005 Debug PAL8624 RetroConception :
2582 if ( !aLabelNode->SendSomeDataReady( Name() ) ) {
2583 cdebug << pthread_self() << "/" << ThreadNo() << " Successed_SuccessAction "
2584 << Name() << " SendSomeDataReady to " << aLabelNode->Name() << " ERROR"
2587 SendEvent( GraphExecutor::ErrorEvent ) ;
2590 if ( aLabelNode->HasAllDataReady() ) {
2591 aLabelNode->ThreadNo( pthread_self() ) ;
2592 aLabelNode->CreateNewThread( false ) ;
2593 aLabelNode->RewindStack( RewindStack() ) ;
2594 aLabelNode->HasAllDataReady( false ) ;
2595 res = aLabelNode->SendEvent( GraphExecutor::AllDataReadyEvent ); // ==> Ready to execute
2599 cdebug << pthread_self() << "/" << ThreadNo() << " ERROR in Successed_SuccessAction of " << Name()
2600 << " NO port " << aGateOutPort->PortName() << " in "
2601 << aLabelNode->Name() << endl;
2607 //==================================================
2608 // JR 09.02.2005 : this is not a EndLoop or a GOTO :
2609 //==================================================
2610 else { // Not a EndLoop or a GOTO
2611 #if SuccessActionTrace
2612 cdebug << ThreadNo() << " Successed_SuccessAction of " << Name()
2613 << " with " << LinkedNodesSize() << " linked nodes :" ;
2614 for ( i = 0 ; i < LinkedNodesSize() ; i++ ) {
2615 cdebug << " " << LinkedNodes( i )->Name() ;
2619 //JR 15.04.2005 Debug PAL8624 RetroConception :
2620 // If this is a LoopNode and if DoLoopPort == false, we go directly to the EndOfLoopNode and
2621 // we do not activate Nodes within the loop
2622 bool IgnoreForEndLoop = false ;
2623 // If this is a SwitchNode and if DefaultOutPort == true, we do not activate Nodes within Switch
2624 // We activate directly the EnSwitch
2625 // BUT the NotSwitchBranch(es) are NOT activated :
2626 bool IgnoreForDefaultSwitch = false ;
2627 if ( IsLoopNode() ) {
2628 GraphBase::OutPort * fromLoopOutPort = GetChangeNodeOutLoop() ;
2629 if ( !fromLoopOutPort->BoolValue() ) { // Ne pas faire la boucle
2630 IgnoreForEndLoop = true ;
2633 else if ( IsSwitchNode() ) {
2634 const GraphBase::OutPort * anOutGatePort = GetNodeOutGate() ;
2635 if ( anOutGatePort->BoolValue() && anOutGatePort->InPortsSize() ) { // DefaultPort is activated
2636 // The DefaultOutPort of that SwitchNode is true and is connected
2637 IgnoreForDefaultSwitch = true ;
2641 //Loop of LinkedNodes for SendSomeDataReady :
2642 for ( i = 0 ; i < LinkedNodesSize() ; i++ ) {
2643 GraphBase::ComputingNode * aComputingNode ;
2644 aComputingNode = (GraphBase::ComputingNode * ) LinkedNodes( i ) ;
2645 toNode = (GraphExecutor::InNode *) aComputingNode->GetInNode() ;
2646 #if SuccessActionTrace
2647 cdebug << pthread_self() << "/" << ThreadNo() << " Successed_SuccessAction of " << Name()
2648 << " [" << i << "] " << LinkedNodes( i )->Name() << " toNode " << toNode
2649 << " IgnoreForEndLoop " << IgnoreForEndLoop ;
2651 cdebug << " " << toNode->Kind() << endl ;
2654 //JR 15.04.2005 Debug PAL8624 RetroConception :
2656 //JR 18.05.2005 : we must lock because of concurrent SendEvent if NotAllDataReady :
2657 toNode->LockDataReady() ;
2658 if ( IsComputingNode() && toNode->IsInLineNode() ) {
2659 GraphBase::InPort * toGateInPort = toNode->GetChangeNodeInGate() ;
2660 toGateInPort->PortState( SUPERV::ReadyState ) ;
2661 GraphBase::OutPort * GateOutPort = toGateInPort->GetOutPort() ;
2662 if ( GateOutPort ) {
2663 GateOutPort->PortStatus( DataConnected );
2664 GateOutPort->PortState( SUPERV::ReadyState ) ;
2665 GateOutPort->PortDone( true ) ;
2669 //JR 15.04.2005 Debug PAL8624 RetroConception :
2670 if ( IsLoopNode() ) {
2671 if ( IgnoreForEndLoop && !strcmp( toNode->Name() , CoupledNode()->Name() ) ) {
2672 GraphBase::InPort * toLoopInPort ;
2673 toLoopInPort = toNode->GetChangeNodeInLoop() ;
2674 if ( toLoopInPort->PortState() != SUPERV::ReadyState ) {
2675 toLoopInPort->PortState( SUPERV::ReadyState ) ;
2679 //JR 15.04.2005 Debug PAL8624 RetroConception :
2680 else if ( toNode->IsInLineNode() ) {
2682 for ( j = 0 ; j < toNode->GetNodeInPortsSize() ; j++ ) {
2683 toNode->GetChangeNodeInPort( j )->InitialOutPort() ;
2687 bool activatetoNode = true ;
2688 //We have to execute the loop :
2689 if ( !IgnoreForEndLoop ) {
2690 //The loop is not finished :
2691 if ( toNode->IsLoopNode() ) {
2692 //We enter in a new loop :
2693 GraphBase::InPort * toLoopInPort = toNode->GetChangeNodeInLoop() ;
2694 toLoopInPort->PortState( SUPERV::ReadyState ) ;
2695 GraphBase::OutPort * LoopOutPort = toLoopInPort->GetOutPort() ;
2696 LoopOutPort->PortStatus( DataConnected );
2697 LoopOutPort->PortState( SUPERV::ReadyState ) ;
2698 LoopOutPort->PortDone( true ) ;
2699 //JR 21.02.2005 Debug Memory leak : CORBA::Any * anAny = new CORBA::Any() ; // InitLoop
2700 CORBA::Any anAny = CORBA::Any() ; // InitLoop
2701 //JR 21.02.2005 Debug Memory leak : *anAny <<= (long ) 1 ;
2702 anAny <<= (long ) 1 ;
2703 LoopOutPort->SetValue( anAny ) ;
2705 for ( j = 0 ; j < toNode->GetNodeInPortsSize() ; j++ ) {
2706 toNode->GetChangeNodeInPort( j )->InitialOutPort() ;
2710 //The loop is finished :
2711 else if ( IsLoopNode() ) {
2712 if ( toNode->IsEndLoopNode() ) {
2713 //Not the corresponding EndLoopNode :
2714 if ( strcmp( toNode->Name() , CoupledNode()->Name() ) ) {
2715 #if SuccessActionTrace
2716 cdebug << pthread_self() << "/" << ThreadNo()
2717 << " Successed_SuccessAction NO activate EndLoopNode " << toNode->Name()
2720 activatetoNode = false ;
2723 //Not a EndLoopNode :
2725 #if SuccessActionTrace
2726 cdebug << pthread_self() << "/" << ThreadNo()
2727 << " Successed_SuccessAction NO activate node " << toNode->Name() << endl ;
2729 activatetoNode = false ;
2733 // If the DefaultPort of that SwitchNode is connected to the DefaultPort of the EndSwitchNode
2734 // the NotSwitchBranch(es) are NOT activated :
2735 if ( IgnoreForDefaultSwitch ) {
2736 //We have to activate Default to EndSwitchNode
2737 #if SuccessActionTrace
2738 cdebug << pthread_self() << "/" << ThreadNo() << " Successed_SuccessAction search "
2739 << toNode->Name() << " among linked nodes to DefaultPort of " << Name()
2740 << "IgnoreForDefaultSwitch" << IgnoreForDefaultSwitch << endl ;
2742 activatetoNode = false ;
2743 const GraphBase::OutPort * anOutGatePort = GetNodeOutGate() ;
2744 const GraphBase::InPort * anInPort = NULL ;
2746 for ( j = 0 ; j < anOutGatePort->InPortsSize() ; j++ ) {
2747 anInPort = anOutGatePort->InPorts( j ) ;
2748 const GraphBase::ComputingNode * aNode ;
2749 aNode = _OutNode->Graph()->GetGraphNode( anInPort->NodeName() ) ;
2751 #if SuccessActionTrace
2752 cdebug << pthread_self() << "/" << ThreadNo() << " Successed_SuccessAction try "
2753 << aNode << " " << aNode->Name() << " == " << toNode << " " << toNode->Name()
2757 if ( aNode && (const GraphBase::ComputingNode * ) toNode->ComputingNode() == aNode ) {
2758 // toNode is connected to the DefaultPort of that SwitchNode :
2759 #if SuccessActionTrace
2760 cdebug << pthread_self() << "/" << ThreadNo()
2761 << " Successed_SuccessAction activate node " << aNode->Name() << endl ;
2763 activatetoNode = true ;
2767 #if SuccessActionTrace
2768 cdebug << pthread_self() << "/" << ThreadNo()
2769 << " Successed_SuccessAction NO activate node " << aNode->Name() << endl ;
2774 //JR 19.04.2005 Debug : Do not activate the EndSwitchNode if DefaultGate is close.
2775 //JR 20.04.2005 : it is false : an outport of the SwitchNode may be connected to an
2776 // input port of the EndSwitchNode
2777 if ( activatetoNode ) {
2778 #if SuccessActionTrace
2779 cdebug << pthread_self() << "/" << ThreadNo() << " Successed_SuccessAction "
2780 << toNode->Name() << "->SendSomeDataReady( " << Name() << " )" << endl ;
2782 if ( !toNode->SendSomeDataReady( Name() ) ) {
2783 cdebug << pthread_self() << "/" << ThreadNo() << " Successed_SuccessAction "
2784 << Name() << " SendSomeDataReady to " << toNode->Name() << " ERROR"
2787 toNode->UnLockDataReady() ;
2788 SendEvent( GraphExecutor::ErrorEvent ) ;
2792 toNode->UnLockDataReady() ;
2794 } //End of Loop of LinkedNodes for SendSomeDataReady
2796 //JR 10.02.2005 : Debug at the end of execution of a SwitchNode :
2797 // Here after we may start execution of only one SwitchBranch or of the Default
2798 // But with activation of only one SwitchBranch we may activate several nodes of that SwitchBranch and
2799 // we may activate several nodes of NotSwitchBranch ( a NotSwitchBranch is a Branch of the Switch
2800 // where GatePorts of Nodes are not connected ; that Branches are always executed for each of SwitchBranch
2801 // BUT are not executed when Default is activated).
2802 if ( IsSwitchNode() ) {
2803 GraphBase::InLineNode * anEndSwitchNode = GOTONode()->CoupledNode() ;
2804 //The InPorts of the EndSwitchNode may be connected from that SwitchNode
2805 //So at first, if we activate a SwitchBranch, we have to establish the correct OutPort in the InPorts
2806 // of the EndSwitchNode (for the SwitchBranch and the NOTSwitchBranch[es] :
2808 // So the bug is that all input ports of the corresponding EndSwitchNode must have the status NOTDONE !
2809 // (Only if Default OutPort is closed and Default InPort is closed) :
2810 if ( !GetNodeOutGate()->BoolValue() && anEndSwitchNode->GetNodeInGate()->GetOutPort() &&
2811 !anEndSwitchNode->GetNodeInGate()->GetOutPort()->BoolValue() ) {
2812 #if SuccessActionTrace
2813 cdebug << pthread_self() << "/" << ThreadNo() << " Successed_SuccessAction " << anEndSwitchNode->Name()
2814 << " reset of InPort()->OutPort()->Done flag in EndSwitch" << endl ;
2817 for ( i = 0 ; i < anEndSwitchNode->GetNodeInPortsSize() ; i++ ) {
2818 GraphBase::OutPort * anOutPort = anEndSwitchNode->GetChangeNodeInPort( i )->GetOutPort() ;
2820 //JR 08.03.2005 Debug : update of state only if not a StreamPort
2821 if ( anOutPort && strcmp( anOutPort->NodeName() , Name() ) &&
2822 !anOutPort->IsDataStream() ) {
2823 #if SuccessActionTrace
2824 cdebug << pthread_self() << "/" << ThreadNo() << " Successed_SuccessAction "
2825 << anEndSwitchNode->Name() << " InPort "
2826 << anEndSwitchNode->GetChangeNodeInPort( i )->PortName() << " NOTDONE from "
2827 << anOutPort->NodeName() << " " << anOutPort->PortName() << endl ;
2829 anEndSwitchNode->GetChangeNodeInPort( i )->PortState( SUPERV::WaitingState ) ;
2830 anEndSwitchNode->GetChangeNodeInPort( i )->GetOutPort()->PortDone( false ) ;
2833 #if SuccessActionTrace
2834 cdebug << pthread_self() << "/" << ThreadNo() << " Successed_SuccessAction "
2835 << anEndSwitchNode->Name() << " InPort "
2836 << anEndSwitchNode->GetChangeNodeInPort( i )->PortName() << " NOT Changed : directly from "
2837 << anOutPort->NodeName() << " " << anOutPort->PortName() << endl ;
2843 #if SuccessActionTrace
2844 cdebug << pthread_self() << "/" << ThreadNo() << " Successed_SuccessAction " << Name()
2845 << " " << Kind() << " OutGate->Value " << GetNodeOutGate()->BoolValue()
2846 << " NO reset of InPort()->OutPort()->Done flag in EndSwitch" << endl ;
2851 //JR 15.04.2005 Debug PAL8624 RetroConception :
2852 //Make the list of nodes to activate :
2853 for ( i = 0 ; i < LinkedNodesSize() ; i++ ) {
2854 GraphBase::ComputingNode * aComputingNode ;
2855 aComputingNode = (GraphBase::ComputingNode * ) LinkedNodes( i ) ;
2856 toNode = (GraphExecutor::InNode *) aComputingNode->GetInNode() ;
2857 if ( toNode ) { // Only Not DataFlowNode :
2858 toNode->LockDataReady() ; // Only ONE Node may send AllDataReadyEvent to an other node
2859 if ( toNode->HasAllDataReady() ) {
2860 SomeDataNodes.push_back( toNode ) ;
2861 toNode->HasAllDataReady( false ) ;
2862 #if SuccessActionTrace
2863 cdebug << pthread_self() << "/" << ThreadNo() << " Successed_SuccessAction "
2864 << Name() << " push "
2865 << toNode->Name() << " " << SomeDataNodes.size() << endl ;
2868 toNode->UnLockDataReady() ;
2872 // firsttoNode : node that has the same ThreadNo() as the current node and that have to be activated
2873 //JR 15.04.2005 Debug PAL8624 RetroConception :
2874 //Activation of nodes that have AllDataReady in a new thread except one :
2875 while ( SomeDataNodes.size() > 1 ) {
2876 GraphExecutor::InNode *aNode = SomeDataNodes.front() ;
2877 SomeDataNodes.pop_front() ;
2878 #if SuccessActionTrace
2879 cdebug << pthread_self() << "/" << ThreadNo()
2880 << " Successed_SuccessAction pop size "
2881 << SomeDataNodes.size() << " " << aNode->Name() << endl ;
2882 cdebug << pthread_self() << "/" << ThreadNo() << " " << aNode->Name()
2883 << " Successed_SuccessAction poped and will start in a new thread" << endl ;
2885 aNode->CreateNewThread( true ) ;
2886 _OutNode->IncrCreatedThreads() ;
2887 //JR 15.04.2005 Debug PAL8624 RetroConception :
2888 res = aNode->SendEvent( GraphExecutor::AllDataReadyEvent ); // ==> Ready to execute
2891 //Activation of the last node that have AllDataReady in the same thread :
2892 if ( SomeDataNodes.size() ) {
2893 firsttoNode = SomeDataNodes.front() ;
2894 SomeDataNodes.pop_front() ;
2896 if ( firsttoNode ) {
2897 #if SuccessActionTrace
2898 cdebug << pthread_self() << "/" << ThreadNo()
2899 << " Successed_SuccessAction start firsttoNode "
2900 << SomeDataNodes.size() << " " << firsttoNode->Name() << endl ;
2902 // firsttoNode->CreateNewThreadIf( false ) ;
2903 firsttoNode->CreateNewThread( false ) ;
2904 firsttoNode->RewindStack( RewindStack() ) ;
2905 if ( firsttoNode->State() == GraphExecutor::SuccessedState ) {
2906 #if SuccessActionTrace
2907 cdebug << pthread_self() << "/" << ThreadNo() << " " << Name()
2908 << " : " << firsttoNode->Name() << " "
2909 << Automaton()->StateName( firsttoNode->State() )
2910 << " --> DataWaitingState for Thread "
2911 << firsttoNode->ThreadNo() << endl ;
2913 firsttoNode->State( GraphExecutor::DataWaitingState ) ;
2915 firsttoNode->ThreadNo( pthread_self() ) ;
2916 // On continue avec le meme thread
2918 #if SuccessActionTrace
2919 cdebug << pthread_self() << "/" << ThreadNo() << " Successed_SuccessAction " << Name()
2920 << " for firsttoNode " << firsttoNode->Name()
2921 << " " << Automaton()->StateName( firsttoNode->State() ) << endl ;
2923 //JR 15.04.2005 Debug PAL8624 RetroConception :
2924 //No creation of thread and with LockDataReady, an other node in an other thread cannot be
2925 // waiting for that lock ( if it was the case we could not find AllDataReady for firsttoNode
2926 res = firsttoNode->SendEvent( GraphExecutor::AllDataReadyEvent ); // ==> Ready to execute
2929 #if SuccessActionTrace
2930 cdebug << ThreadNo() << " Successed_SuccessAction " << Name()
2931 << " NO DataReady ==> ThreadNo( 0 ) firsttoNode == NULL" << endl ;
2936 #if SuccessActionTrace
2937 cdebug_out << pthread_self() << "/" << ThreadNo()
2938 << " Successed_SuccessAction " << Name() << endl;
2943 #define SendSomeDataReadyTrace 1
2944 bool GraphExecutor::InNode::SendSomeDataReady( char * FromNodeName ) {
2945 bool RetVal = false ;
2946 if ( IsDataFlowNode() ) {
2947 #if SendSomeDataReadyTrace
2948 cdebug_in << ThreadNo() << "InNode::SendSomeDataReady " << FromNodeName
2949 << " send Result to graph " << Name() << endl;
2953 #if SendSomeDataReadyTrace
2954 cdebug_in << pthread_self() << "/" << ThreadNo() << FromNodeName
2955 << " GraphExecutor::InNode::SendSomeDataReady to " << Name() << " State "
2956 << Automaton()->StateName( State() ) << endl;
2958 if ( State() == GraphExecutor::SuccessedState ||
2959 State() == GraphExecutor::SuspendedSuccessedState ||
2960 State() == GraphExecutor::SuspendedSuccessedToReStartState ) {
2961 #if SendSomeDataReadyTrace
2962 cdebug << ThreadNo() << " " << FromNodeName
2963 << " : " << Name() << " " << Automaton()->StateName( State() )
2964 << " --> DataWaitingState for Thread "
2965 << ThreadNo() << " " << endl ;
2967 State( GraphExecutor::DataWaitingState ) ;
2969 // We begin that LoopNode if SendSomeDataReady does not come from the corresponding EndLoopNode
2970 if ( IsLoopNode() && strcmp( LoopNode()->CoupledNodeName() , FromNodeName ) ) {
2971 #if SendSomeDataReadyTrace
2972 cdebug << ThreadNo() << "InNode::SendSomeDataReady " << Name() << " Set _InitLoop from "
2973 << FromNodeName << endl ;
2977 #if SendSomeDataReadyTrace
2978 cdebug << "SendEvent( SomeDataReadyEvent )" << endl ;
2980 //JR 15.04.2005 Debug PAL8624 RetroConception :
2981 DataFromNode( FromNodeName ) ;
2982 // RetVal = !SendEvent( GraphExecutor::SomeDataReadyEvent );
2983 RetVal = SendEvent( GraphExecutor::SomeDataReadyEvent );
2984 //JR 15.04.2005 Debug PAL8624 RetroConception :
2986 #if SendSomeDataReadyTrace
2987 cdebug_out << pthread_self() << "/" << ThreadNo() << FromNodeName
2988 << " GraphExecutor::InNode::SendSomeDataReady to " << Name() << " State "
2989 << Automaton()->StateName( State() ) << " " << RetVal << endl;
2994 int GraphExecutor::InNode::Errored_ErrorAction() {
2995 cdebug << ThreadNo() << " Errored_ErrorAction " << Name()
2996 << " will pthread_exit" << endl;
2998 _OutNode->NodeAborted( Name() ) ;
3004 int GraphExecutor::InNode::Successed_SuspendAction() {
3005 cdebug << ThreadNo() << " Successed_SuspendAction -->Suspend " << Name()
3006 << " Threads " << _OutNode->Threads() << " SuspendedThreads "
3007 << _OutNode->SuspendedThreads() << endl;
3008 _OutNode->PushEvent( this , GraphExecutor::SuspendedSuccessedEvent ,
3009 GraphExecutor::SuspendedSuccessedState ) ;
3011 GraphExecutor::InNode * aReStartNode = SuspendAction() ;
3012 cdebug << ThreadNo() << " Successed_SuspendAction Resumed " << Name() ;
3013 if ( aReStartNode ) {
3014 _aReStartNode = NULL ;
3015 cdebug << " for " << aReStartNode->Name() << endl;
3016 aReStartNode->SendEvent( _aReStartEvent ) ;
3020 SendEvent( GraphExecutor::ResumeEvent ) ;
3025 int GraphExecutor::InNode::Errored_SuspendAction() {
3026 cdebug << ThreadNo() << " Errored_SuspendAction -->Suspend " << Name()
3027 << " Threads " << _OutNode->Threads() << " SuspendedThreads "
3028 << _OutNode->SuspendedThreads() << endl;
3029 _OutNode->PushEvent( this , GraphExecutor::SuspendedErroredEvent ,
3030 GraphExecutor::SuspendedErroredState ) ;
3032 _OutNode->NodeAborted( Name() ) ;
3035 GraphExecutor::InNode * aReStartNode = SuspendAction() ;
3036 cdebug << ThreadNo() << " Errored_SuspendAction Resumed " << Name()
3038 if ( aReStartNode ) {
3039 _aReStartNode = NULL ;
3040 aReStartNode->SendEvent( _aReStartEvent ) ;
3043 SendEvent( GraphExecutor::ResumeEvent ) ;
3048 int GraphExecutor::InNode::SuspendedSuccessed_ResumeAction() {
3049 cdebug << ThreadNo() << " SuspendedSuccessed_ResumeAction " << Name() << endl;
3051 _OutNode->PushEvent( this , GraphExecutor::ResumedSuccessedEvent ,
3052 GraphExecutor::ResumedSuccessedState ) ;
3053 SendEvent( ResumedSuccessedEvent ) ;
3057 int GraphExecutor::InNode::SuspendedErrored_ResumeAction() {
3058 cdebug << ThreadNo() << " SuspendedErrored_ResumeAction " << Name() << endl;
3060 _OutNode->PushEvent( this , GraphExecutor::ResumedErroredEvent ,
3061 GraphExecutor::ResumedErroredState ) ;
3063 _OutNode->NodeAborted( Name() ) ;
3065 SendEvent( ResumedErroredEvent ) ;
3069 int GraphExecutor::InNode::Successed_KillAction() {
3071 _OutNode->PushEvent( this , GraphExecutor::KilledEvent ,
3072 GraphExecutor::KilledSuccessedState ) ;
3073 cdebug << ThreadNo() << " Successed_KillAction " << Name() << endl;
3077 int GraphExecutor::InNode::Errored_KillAction() {
3079 _OutNode->PushEvent( this , GraphExecutor::KilledEvent ,
3080 GraphExecutor::KilledErroredState ) ;
3082 _OutNode->NodeAborted( Name() ) ;
3084 cdebug << ThreadNo() << " Errored_KillAction " << Name() << endl;
3088 int GraphExecutor::InNode::Successed_StopAction() {
3090 _OutNode->PushEvent( this , GraphExecutor::StoppedEvent ,
3091 GraphExecutor::StoppedSuccessedState ) ;
3092 cdebug << ThreadNo() << " Successed_StopAction " << Name() << endl;
3096 int GraphExecutor::InNode::Errored_StopAction() {
3098 _OutNode->PushEvent( this , GraphExecutor::StoppedEvent ,
3099 GraphExecutor::StoppedErroredState ) ;
3101 _OutNode->NodeAborted( Name() ) ;
3103 cdebug << ThreadNo() << " Errored_StopAction " << Name() << endl;
3107 int GraphExecutor::InNode::SuspendedSuccessed_ReStartAction() {
3108 cdebug << ThreadNo() << " SuspendedSuccessed_ReStartAction " << Name() << endl;
3109 _OutNode->PushEvent( this , GraphExecutor::ReStartedEvent ,
3110 GraphExecutor::ReStartedState ) ;
3112 for ( i = 0 ; i < GetNodeInPortsSize() ; i++ ) {
3113 GetChangeNodeInPort( i )->PortState( SUPERV::ReadyState ) ;
3115 SendEvent( ExecuteEvent ) ;
3116 cdebug << ThreadNo() << " SuspendedSuccessed_ReStartAction " << Name() << endl;
3120 int GraphExecutor::InNode::SuspendedErrored_ReStartAction() {
3121 cdebug << ThreadNo() << " SuspendedErrored_ReStartAction " << Name() << endl;
3122 _OutNode->PushEvent( this , GraphExecutor::ReStartedEvent ,
3123 GraphExecutor::ReStartedState ) ;
3125 for ( i = 0 ; i < GetNodeInPortsSize() ; i++ ) {
3126 GetChangeNodeInPort( i )->PortState( SUPERV::ReadyState ) ;
3128 SendEvent( ExecuteEvent ) ;
3129 cdebug << ThreadNo() << " SuspendedErrored_ReStartAction " << Name() << endl;
3133 int GraphExecutor::InNode::SuspendedSuccessed_ReStartAndSuspendAction() {
3134 cdebug << ThreadNo() << " SuspendedSuccessed_ReStartAndSuspendAction " << Name()
3136 _OutNode->PushEvent( this , GraphExecutor::ReStartedAndSuspendEvent ,
3137 GraphExecutor::ReStartedState ) ;
3138 State( GraphExecutor::DataWaitingState ) ;
3140 cdebug << "InNode::Suspend() Node " << Name() << endl ;
3143 else if ( SendEvent( GraphExecutor::SomeDataReadyEvent ) ) {
3144 cdebug << "InNode::SendEvent( SomeDataReadyEvent ) Node "
3148 cdebug << ThreadNo() << " SuspendedSuccessed_ReStartAndSuspendAction " << Name()
3153 int GraphExecutor::InNode::SuspendedErrored_ReStartAndSuspendAction() {
3154 cdebug << ThreadNo() << " SuspendedErrored_ReStartAndSuspendAction " << Name()
3156 _OutNode->PushEvent( this , GraphExecutor::ReStartedAndSuspendEvent ,
3157 GraphExecutor::ReStartedState ) ;
3158 State( GraphExecutor::DataWaitingState ) ;
3160 cdebug << "InNode::Suspend() Node " << Name() << endl ;
3163 else if ( SendEvent( GraphExecutor::SomeDataReadyEvent ) ) {
3164 cdebug << "InNode::SendEvent( SomeDataReadyEvent ) Node "
3168 cdebug << ThreadNo() << " SuspendedErrored_ReStartAndSuspendAction " << Name()
3173 #define InParametersSetTrace 1
3174 void GraphExecutor::InNode::InParametersSet( bool & Err ,
3176 ServicesAnyData * InParametersList ) {
3178 #if InParametersSetTrace
3179 cdebug << pthread_self() << "/" << ThreadNo() << " InParametersSet " << Name() << endl ;
3181 for ( i = 0 ; i < nInParams ; i++ ) {
3182 ServicesAnyData D = InParametersList[i];
3183 GraphBase::InPort * anInPort = GetChangeNodeInPort(i) ;
3184 GraphBase::OutPort * theOutPort = anInPort->GetOutPort() ;
3185 if ( anInPort->IsGate() && theOutPort == NULL ) {
3186 #if InParametersSetTrace
3187 cdebug << ThreadNo() << " ArgIn" << i << " " << D.Name << " "
3188 << anInPort->GetServicesParameter().Parametertype
3189 << " is inactive. " << anInPort->Kind() << endl ;
3192 else if ( anInPort->PortState() == SUPERV::ReadyState ) {
3193 if ( anInPort->IsGate() ) {
3194 //JR 21.02.2005 Debug Memory leak : CORBA::Any * anAny = new CORBA::Any() ;
3195 CORBA::Any anAny = CORBA::Any() ;
3196 //JR 21.02.2005 Debug Memory leak : *anAny <<= (long ) 0 ;
3197 anAny <<= (long ) 0 ;
3198 theOutPort->SetValue( anAny ) ;
3201 if ( !anInPort->IsDataStream() &&
3202 !anInPort->IsDataConnected() ) {
3203 anInPort->PortState( SUPERV::WaitingState ) ;
3205 //JR 18.02.2005 Debug Memory leak : delete does not destroy that string ...
3206 // D.Name = CORBA::string_dup( anInPort->GetServicesParameter().Parametername ) ;
3207 D.Name = anInPort->PortName() ;
3208 //JR 30.03.2005 const CORBA::Any * AnyPtr = theOutPort->Value() ;
3209 const CORBA::Any AnyRef = theOutPort->Value() ;
3210 #if InParametersSetTrace
3211 cdebug << ThreadNo() << " ArgIn" << i << " " << anInPort->Kind() << " "
3212 << anInPort->PortState() << " " << D.Name << " "
3213 << anInPort->GetServicesParameter().Parametertype << endl ;
3215 //JR 30.03.2005 D.Value = * AnyPtr ; // CORBA::Any
3216 D.Value = AnyRef ; // CORBA::Any
3217 //JR 18.02.2005 Debug Memory leak : string _Type = CORBA::string_dup( anInPort->GetServicesParameter().Parametertype ) ;
3218 // const char * Type = _Type.c_str() ;
3219 const char * Type = anInPort->GetServicesParameter().Parametertype ;
3220 switch ( D.Value.type()->kind() ) { // { string , long , double , objref }
3221 case CORBA::tk_string:
3224 #if InParametersSetTrace
3225 cdebug << t << " (string)" ;
3227 if ( !strcmp( Type , "string" ) ) {
3229 else if ( !strcmp( Type , "boolean" ) ) {
3232 sscanf( t , "%ld" , &d ) ;
3234 D.Value <<= (CORBA::Any::from_boolean ) b ;
3235 // theOutPort->Value( D.Value ) ;
3237 else if ( !strcmp( Type , "char" ) ) {
3240 sscanf( t , "%ld" , &d ) ;
3242 D.Value <<= (CORBA::Any::from_char ) c ;
3243 #if InParametersSetTrace
3244 cdebug << "string '" << t << "' --> " << d << " --> char " << c ;
3246 // theOutPort->Value( D.Value ) ;
3248 else if ( !strcmp( Type , "short" ) ) {
3251 sscanf( t , "%ld" , &d ) ;
3254 #if InParametersSetTrace
3255 cdebug << "string '" << t << "' --> " << d << " --> short " << s ;
3257 // theOutPort->Value( D.Value ) ;
3259 else if ( !strcmp( Type , "int" ) || !strcmp( Type , "long" ) ) {
3261 sscanf( t , "%ld" , &l ) ;
3263 #if InParametersSetTrace
3264 cdebug << "string '" << t << " --> long " << l ;
3266 // theOutPort->Value( D.Value ) ;
3268 else if ( !strcmp( Type , "float" ) ) {
3270 sscanf( t , "%lf" , &d ) ;
3272 #ifdef REDHAT // mkr : debug for PAL12255
3275 D.Value.replace(CORBA::TypeCode::PR_float_tc(), (void*)(&f));
3277 #if InParametersSetTrace
3278 cdebug << "string '" << t << "' --> " << setw(25) << setprecision(18) << d << " --> float " << " = "
3279 << setw(25) << setprecision(18) << f ;
3281 // theOutPort->Value( D.Value ) ;
3283 else if ( !strcmp( Type , "double" ) ) {
3285 sscanf( t , "%lf" , &d ) ;
3286 #ifdef REDHAT // mkr : debug for PAL12255
3289 D.Value.replace(CORBA::TypeCode::PR_double_tc(), (void*)(&d));
3291 #if InParametersSetTrace
3292 cdebug << "string '" << t << " --> double " << setw(25) << setprecision(18) << d ;
3294 // theOutPort->Value( D.Value ) ;
3296 // else if ( !strcmp( Type , "objref" ) ) {
3298 CORBA::Object_ptr ObjRef ;
3300 ObjRef = StringToObject( t ) ;
3301 D.Value <<= ObjRef ;
3304 D.Value <<= CORBA::Object::_nil() ;
3306 // theOutPort->Value( D.Value ) ;
3309 // cdebug << " (other ERROR)" << endl ;
3311 #if InParametersSetTrace
3312 cdebug << " --> call_kind " << D.Value.type()->kind() << endl ;
3315 case CORBA::tk_long:
3316 #if InParametersSetTrace
3317 cdebug << ThreadNo() << " " << Name() << " ArgIn" << i << " " << D.Name << " "
3318 << anInPort->GetServicesParameter().Parametertype << " " << anInPort->Kind()
3320 theOutPort->StringValue( *GraphBase::Base::_fdebug ) ;
3325 #if InParametersSetTrace
3326 cdebug << l << " (long)" << endl ;
3328 if ( !strcmp( Type , "string" ) ) {
3330 sprintf( t , "%ld" , l ) ;
3332 // theOutPort->Value( D.Value ) ;
3334 else if ( !strcmp( Type , "boolean" ) ) {
3337 D.Value <<= (CORBA::Any::from_boolean ) b ;
3338 // theOutPort->Value( D.Value ) ;
3340 else if ( !strcmp( Type , "char" ) ) {
3342 c = (unsigned char ) l ;
3343 D.Value <<= (CORBA::Any::from_char ) c ;
3344 // theOutPort->Value( D.Value ) ;
3346 else if ( !strcmp( Type , "short" ) ) {
3350 // theOutPort->Value( D.Value ) ;
3352 else if ( !strcmp( Type , "int" ) || !strcmp( Type , "long" ) ) {
3354 else if ( !strcmp( Type , "float" ) ) {
3357 #ifdef REDHAT // mkr : debug for PAL12255
3360 D.Value.replace(CORBA::TypeCode::PR_float_tc(), (void*)(&f));
3362 // theOutPort->Value( D.Value ) ;
3364 else if ( !strcmp( Type , "double" ) ) {
3367 #ifdef REDHAT // mkr : debug for PAL12255
3370 D.Value.replace(CORBA::TypeCode::PR_double_tc(), (void*)(&d));
3372 // theOutPort->Value( D.Value ) ;
3374 // else if ( !strcmp( Type , "objref" ) ) {
3376 D.Value <<= CORBA::Object::_nil() ;
3377 // theOutPort->Value( D.Value ) ;
3380 // cdebug << " (other ERROR)" << endl ;
3382 #if InParametersSetTrace
3383 cdebug << " --> call_kind " << D.Value.type()->kind() << endl ;
3386 case CORBA::tk_double:
3389 #if InParametersSetTrace
3390 cdebug << d << " (double)" << endl ;
3392 if ( !strcmp( Type , "string" ) ) {
3394 sprintf( t , "%lf" , d ) ;
3396 // theOutPort->Value( D.Value ) ;
3398 else if ( !strcmp( Type , "boolean" ) ) {
3401 D.Value <<= (CORBA::Any::from_boolean ) b ;
3402 // theOutPort->Value( D.Value ) ;
3404 else if ( !strcmp( Type , "char" ) ) {
3406 c = (unsigned char ) d ;
3407 D.Value <<= (CORBA::Any::from_char ) c ;
3408 // theOutPort->Value( D.Value ) ;
3410 else if ( !strcmp( Type , "short" ) ) {
3414 // theOutPort->Value( D.Value ) ;
3416 else if ( !strcmp( Type , "int" ) || !strcmp( Type , "long" ) ) {
3420 // theOutPort->Value( D.Value ) ;
3422 else if ( !strcmp( Type , "float" ) ) {
3425 #ifdef REDHAT // mkr : debug for PAL12255
3428 D.Value.replace(CORBA::TypeCode::PR_float_tc(), (void*)(&f));
3430 // theOutPort->Value( D.Value ) ;
3432 else if ( !strcmp( Type , "double" ) ) {
3434 // else if ( !strcmp( Type , "objref" ) ) {
3436 D.Value <<= CORBA::Object::_nil() ;
3437 // theOutPort->Value( D.Value ) ;
3440 // cdebug << " (other ERROR)" << endl ;
3442 #if InParametersSetTrace
3443 cdebug << " --> call_kind " << D.Value.type()->kind() << endl ;
3446 case CORBA::tk_objref:
3447 if ( !strcmp( Type , "string" ) ) {
3448 CORBA::Object_ptr ObjRef ;
3451 #if OMNIORB_VERSION >= 4
3452 D.Value >>= (CORBA::Any::to_object ) ObjRef ;
3454 D.Value >>= ObjRef ;
3456 retstr = ObjectToString( ObjRef ) ;
3457 D.Value <<= retstr ;
3458 // theOutPort->Value( D.Value ) ;
3464 cdebug << "ToString( object ) Catched ERROR" << endl ;
3467 else if ( !strcmp( Type , "boolean" ) ) {
3469 D.Value <<= (CORBA::Any::from_boolean ) b ;
3470 // theOutPort->Value( D.Value ) ;
3472 else if ( !strcmp( Type , "char" ) ) {
3473 unsigned char c = 0 ;
3474 D.Value <<= (CORBA::Any::from_char ) c ;
3475 // theOutPort->Value( D.Value ) ;
3477 else if ( !strcmp( Type , "short" ) ) {
3480 // theOutPort->Value( D.Value ) ;
3482 else if ( !strcmp( Type , "int" ) || !strcmp( Type , "long" ) ) {
3485 // theOutPort->Value( D.Value ) ;
3487 else if ( !strcmp( Type , "float" ) ) {
3489 #ifdef REDHAT // mkr : debug for PAL12255
3492 D.Value.replace(CORBA::TypeCode::PR_float_tc(), (void*)(&f));
3494 // theOutPort->Value( D.Value ) ;
3496 else if ( !strcmp( Type , "double" ) ) {
3498 #ifdef REDHAT // mkr : debug for PAL12255
3501 D.Value.replace(CORBA::TypeCode::PR_double_tc(), (void*)(&d));
3503 // theOutPort->Value( D.Value ) ;
3505 // else if ( !strcmp( Type , "objref" ) ) {
3507 CORBA::Object_ptr obj ;
3510 #if OMNIORB_VERSION >= 4
3511 D.Value >>= (CORBA::Any::to_object ) obj ;
3515 retstr = ObjectToString( obj ) ;
3516 #if InParametersSetTrace
3517 cdebug << retstr << endl ;
3524 cdebug << "ToString( object ) Catched ERROR" << endl ;
3528 // cdebug << " (other ERROR)" << endl ;
3530 #if InParametersSetTrace
3531 cdebug << " --> call_kind " << D.Value.type()->kind() << endl ;
3535 cdebug << " (other ERROR) " << D.Value.type()->kind() << endl ;
3539 cdebug << ThreadNo() << " In" << i << " : wrong state ERROR State "
3540 << anInPort->PortState() << " NameState "
3541 << Automaton()->StateName( anInPort->PortState() ) << " PortName "
3542 << anInPort->PortName() << " Parametername "
3543 << anInPort->GetServicesParameter().Parametername << endl ;
3546 InParametersList[i] = D ;
3550 void GraphExecutor::InNode::InOutParametersSet( int nOutParams ,
3551 ServicesAnyData * OutParametersList ) {
3552 #if InParametersSetTrace
3553 cdebug << pthread_self() << "/" << ThreadNo() << " InOutParametersSet " << Name() << endl ;
3556 for ( i = 0 ; i < nOutParams ; i++ ) {
3557 ServicesAnyData D = OutParametersList[i] ;
3559 //JR 18.02.2005 Debug Memory leak : delete does not destroy that string ...
3560 // D.Name = CORBA::string_dup(GetChangeNodeOutPort(i)->GetServicesParameter().Parametername);
3561 D.Name = GetChangeNodeOutPort(i)->PortName() ;
3562 //JR 18.02.2005 Debug Memory leak : string _Type = CORBA::string_dup(GetChangeNodeOutPort(i)->GetServicesParameter().Parametertype) ;
3563 const char * Type = GetChangeNodeOutPort(i)->GetServicesParameter().Parametertype ;
3564 #if InParametersSetTrace
3565 bool OutDone = GetChangeNodeOutPort(i)->PortDone() ;
3566 cdebug << ThreadNo() << " ArgOut" << i << " " << D.Name << " PortDone( " << OutDone << " ) Type : "
3569 if ( !strcmp( Type , "string" ) ) {
3570 // D.Value <<= (char *) NULL ;
3573 else if ( !strcmp( Type , "boolean" ) ) {
3575 D.Value <<= (CORBA::Any::from_boolean ) b ;
3577 else if ( !strcmp( Type , "char" ) ) {
3578 unsigned char c = 0 ;
3579 D.Value <<= (CORBA::Any::from_char ) c ;
3581 else if ( !strcmp( Type , "short" ) ) {
3585 else if ( !strcmp( Type , "int" ) || !strcmp( Type , "long" ) ) {
3586 D.Value <<= (long ) 0 ;
3588 else if ( !strcmp( Type , "float" ) ) {
3590 #ifdef REDHAT // mkr : debug for PAL12255
3593 D.Value.replace(CORBA::TypeCode::PR_float_tc(), (void*)(&f));
3596 else if ( !strcmp( Type , "double" ) ) {
3598 #ifdef REDHAT // mkr : debug for PAL12255
3601 D.Value.replace(CORBA::TypeCode::PR_double_tc(), (void*)(&d));
3605 D.Value <<= CORBA::Object::_nil() ;
3607 #if InParametersSetTrace
3608 switch (D.Value.type()->kind()) { // { string , long , double , objref }
3609 case CORBA::tk_string:
3612 cdebug << ThreadNo() << " " << t << "(string)" << endl ;
3614 case CORBA::tk_boolean:
3616 D.Value >>= (CORBA::Any::to_boolean ) b;
3617 cdebug << ThreadNo() << " " << b << "(boolean)" << endl ;
3619 case CORBA::tk_char:
3621 D.Value >>= (CORBA::Any::to_char ) c;
3622 cdebug << ThreadNo() << " " << c << "(char)" << endl ;
3624 case CORBA::tk_short:
3627 cdebug << ThreadNo() << " " << s << "(short)" << endl ;
3629 case CORBA::tk_long:
3632 cdebug << ThreadNo() << " " << l << "(long)" << endl ;
3634 case CORBA::tk_float:
3637 cdebug << ThreadNo() << " " << f << "(float)" << endl ;
3639 case CORBA::tk_double:
3642 cdebug << ThreadNo() << " " << d << "(double)" << endl ;
3644 case CORBA::tk_objref:
3646 CORBA::Object_ptr obj ;
3648 #if OMNIORB_VERSION >= 4
3649 D.Value >>= (CORBA::Any::to_object ) obj ;
3653 retstr = ObjectToString( obj ) ;
3654 cdebug << ThreadNo() << retstr << endl ;
3657 cdebug << "ToString( object ) Catched ERROR" << endl ;
3661 cdebug << ThreadNo() << " " << "(other ERROR)" << endl ;
3664 OutParametersList[i] = D ;
3668 #define OutParametersSetTrace 1
3669 bool GraphExecutor::InNode::OutParametersSet( bool Err ,
3670 SUPERV::GraphState PortState ,
3672 ServicesAnyData * OutParametersList ) {
3673 bool RetVal = true ;
3675 GraphBase::OutPort * aGateOutPort = NULL ;
3676 bool OrSwitch = false ;
3677 bool DefaultSwitch = false ;
3678 #if OutParametersSetTrace
3679 cdebug_in << "OutParametersSet " << Name() << " nOutParams " << nOutParams << " NewPortState "
3680 << PortState << endl ;
3682 // cout << "OutParametersSet " << Name() << " nOutParams " << nOutParams << " NewPortState " << PortState << endl ;
3683 if ( nOutParams && !IsMacroNode() ) {
3684 GraphBase::OutPort * anOutPort ;
3685 for ( i = 0 ; i < nOutParams ; i++ ) {
3686 anOutPort = GetChangeNodeOutPort(i) ;
3688 anOutPort->PortState( PortState ) ;
3689 anOutPort->PortDone( true ) ;
3692 #if OutParametersSetTrace
3693 cdebug << ThreadNo() << "OutParametersSet " << "Out" << i << " " << Name() << " "
3694 << anOutPort->PortName() << " " << anOutPort->Kind() ;
3696 ServicesAnyData D = OutParametersList[i] ;
3697 switch (D.Value.type()->kind()) { // { string , long , double , objref }
3698 case CORBA::tk_string: {
3701 #if OutParametersSetTrace
3702 cdebug << ThreadNo() << " " << t << "(string)" << endl ;
3706 case CORBA::tk_boolean: {
3708 D.Value >>= (CORBA::Any::to_boolean ) b;
3709 long l = (long ) b ;
3711 #if OutParametersSetTrace
3712 cdebug << ThreadNo() << " " << b << "(boolean)" << endl ;
3716 case CORBA::tk_char: {
3718 D.Value >>= (CORBA::Any::to_char ) c;
3719 long l = (long ) c ;
3721 #if OutParametersSetTrace
3722 cdebug << ThreadNo() << " " << c << "(char)" << endl ;
3726 case CORBA::tk_short: {
3729 long l = (long ) s ;
3731 #if OutParametersSetTrace
3732 cdebug << ThreadNo() << " " << s << "(short)" << endl ;
3736 case CORBA::tk_long: {
3739 #if OutParametersSetTrace
3740 cdebug << ThreadNo() << " " << l << "(long)" << endl ;
3744 case CORBA::tk_float: {
3747 double d = (double ) f ;
3748 #ifdef REDHAT // mkr : debug for PAL12255
3751 D.Value.replace(CORBA::TypeCode::PR_double_tc(), (void*)(&d));
3753 #if OutParametersSetTrace
3754 cdebug << ThreadNo() << " " << f << "(float)" << endl ;
3758 case CORBA::tk_double: {
3761 #if OutParametersSetTrace
3762 cdebug << ThreadNo() << " " << d << "(double)" << endl ;
3766 case CORBA::tk_objref: {
3768 CORBA::Object_ptr obj ;
3769 #if OMNIORB_VERSION >= 4
3770 D.Value >>= (CORBA::Any::to_object ) obj ;
3774 #if OutParametersSetTrace
3776 retstr = ObjectToString( obj ) ;
3777 cdebug << ThreadNo() << retstr << endl ;
3781 cdebug << "ToString( object ) Catched ERROR" << endl ;
3787 cdebug << ThreadNo() << " " << "(other ERROR)" << endl ;
3791 OutParametersList[i] = D ;
3792 if ( !anOutPort->IsDataStream() ) {
3793 if ( anOutPort->IsGate() ) {
3794 aGateOutPort = anOutPort ;
3795 #if OutParametersSetTrace
3796 cdebug << " Gate " ;
3799 OutParametersList[i].Value <<= l;
3800 anOutPort->SetValue( OutParametersList[i].Value );
3802 else if ( anOutPort->IsLoop() ) {
3803 #if OutParametersSetTrace
3804 cdebug << " Loop " ;
3806 anOutPort->SetValue( OutParametersList[i].Value );
3807 // InLoop Port of EndLoopNode is ready :
3808 anOutPort->ChangeInPorts(0)->PortState( SUPERV::ReadyState ) ;
3810 else if ( anOutPort->IsSwitch() ) {
3811 #if OutParametersSetTrace
3812 cdebug << " Switch " ;
3814 anOutPort->SetValue( OutParametersList[i].Value );
3815 if ( anOutPort->InPortsSize() && anOutPort->ChangeInPorts( 0 )->IsGate() ) {
3816 //We have a SwitchBranch or the DefaultBranch .
3817 //JR 09.02.2005 : OrSwitch is the OR of all SwitchBranches (SwitchParameters) :
3818 //It controls that there is only one SwitchBranch activated
3819 //If it's final value is false ==> activation of the Default to GOTO to EndSwitchNode
3820 //DefaultSwitch is true if a SwitchPort is linked to the DefaultPort of the EndSwitchNode
3821 if ( OrSwitch && anOutPort->BoolValue() ) {
3822 string anErrorMessage = string( "More than one SwitchBranch should be activated in SwitchNode " ) +
3823 string( Name() ) + string( "( " ) +
3824 string( anOutPort->PortName() ) + string( " )" ) ;
3825 _OutNode->Graph()->SetMessages( anErrorMessage ) ;
3826 cdebug << "Executor::InNodeThreads::OutParameters more than one SwitchBranch is true ERROR"
3830 else if ( anOutPort->BoolValue() ) {
3831 //JR 09.02.2005 Debug : case of a SwitchPort linked to the DefaultPort of the EndSwitchNode :
3832 if ( !strcmp( anOutPort->ChangeInPorts( 0 )->NodeName() , GOTONode()->CoupledNodeName() ) ) {
3833 DefaultSwitch = anOutPort->BoolValue() ;
3836 OrSwitch = OrSwitch | anOutPort->BoolValue() ;
3838 #if OutParametersSetTrace
3839 cdebug << "InNodeThreads::OutParameters OrSwitch " << OrSwitch << "DefaultSwitch "
3840 << DefaultSwitch << endl ;
3846 #if OutParametersSetTrace
3847 cdebug << " Param " ;
3849 anOutPort->SetValue( OutParametersList[i].Value );
3851 anOutPort->PortState( PortState ) ;
3852 anOutPort->PortDone( true ) ;
3854 #if OutParametersSetTrace
3855 cdebug << "OutParametersSet OrSwitch " << OrSwitch << "DefaultSwitch "
3856 << DefaultSwitch << endl ;
3859 for ( j = 0 ; j < anOutPort->InPortsSize() ; j++ ) {
3860 #if OutParametersSetTrace
3861 cdebug << ThreadNo() << "OutParametersSet " << "Out" << i << " " << Name() << " "
3862 << anOutPort->PortName() << " " << anOutPort->Kind() << " --> "
3863 << anOutPort->ChangeInPorts( j )->NodeName() << "( "
3864 << anOutPort->ChangeInPorts( j )->PortName() << anOutPort->ChangeInPorts( j )->Kind()
3867 bool fromGOTO = false ;
3868 const char * ToNodeName = anOutPort->ChangeInPorts( j )->NodeName() ;
3869 if ( !strcmp( ToNodeName , _OutNode->Name() ) &&
3870 _OutNode->Graph()->GraphMacroLevel() != 0 ) {
3871 #if OutParametersSetTrace
3872 cdebug << "OutParametersSet ToNodeName " << _OutNode->Name() << " CoupledNode "
3873 << _OutNode->Graph()->CoupledNodeName() << _OutNode->Graph()->CoupledNode()
3875 cdebug << "OutParametersSet GraphExecutor " << _OutNode->Graph()->CoupledNode()->GraphEditor()->Executor() << endl ;
3877 _OutNode->Graph()->CoupledNode()->GraphEditor()->Executor()->OutputOfAny( _OutNode->Graph()->CoupledNodeName() ,
3878 anOutPort->ChangeInPorts( j )->PortName() ,
3879 //JR 30.03.2005 *anOutPort->Value() ) ;
3880 anOutPort->Value() ) ;
3881 #if OutParametersSetTrace
3882 cdebug << "OutParametersSet OutputOfAny( "
3883 << _OutNode->Graph()->CoupledNodeName() << " , "
3884 << anOutPort->ChangeInPorts( j )->PortName() << " , value )" << endl ;
3889 GraphBase::ComputingNode * ToNode = _OutNode->Graph()->GetChangeGraphNode( ToNodeName ) ;
3891 // cout << "OutParametersSet ToNodeName " << ToNodeName << endl ;
3892 // cdebug << "OutParametersSet ToNodeName " << ToNodeName << " " << ToNode->Name() << endl ;
3893 GraphBase::OutPort * aGOTOPort = ToNode->GetChangeNodeInGate()->GetOutPort() ;
3895 fromGOTO = aGOTOPort->IsGOTO() ;
3897 if ( anOutPort->ChangeInPorts( j )->IsEndSwitch() || fromGOTO ) {
3898 #if OutParametersSetTrace
3899 cdebug << anOutPort->ChangeInPorts( j )->NodeName() << "("
3900 << anOutPort->ChangeInPorts( j )->PortName() << ","
3901 << anOutPort->ChangeInPorts( j )->Kind() << ") CHANGED from "
3902 << anOutPort->ChangeInPorts( j )->GetOutPort()->NodeName()
3904 << anOutPort->ChangeInPorts( j )->GetOutPort()->PortName()
3905 << " to " << anOutPort->ChangeInPorts( j )->GetOutPort()->Kind()
3906 << ") : Done " << anOutPort->PortDone() << " State "
3907 << Automaton()->StateName( anOutPort->ChangeInPorts( j )->PortState() ) << endl ;
3909 anOutPort->ChangeInPorts( j )->ChangeOutPort( anOutPort ) ;
3912 #if OutParametersSetTrace
3913 cdebug << anOutPort->ChangeInPorts( j )->NodeName() << "("
3914 << anOutPort->ChangeInPorts( j )->PortName() << ","
3915 << anOutPort->ChangeInPorts( j )->Kind() << ") NOT changed from "
3916 << anOutPort->ChangeInPorts( j )->GetOutPort()->NodeName()
3918 << anOutPort->ChangeInPorts( j )->GetOutPort()->PortName()
3919 << " " << anOutPort->ChangeInPorts( j )->GetOutPort()->Kind()
3926 #if OutParametersSetTrace
3927 switch ( anOutPort->Value().type()->kind() ) {
3928 case CORBA::tk_string:
3930 (anOutPort->Value()) >>= t;
3931 cdebug << ThreadNo() << " Out" << i << " : " << t << "(string)" << endl ;
3933 case CORBA::tk_boolean:
3935 (anOutPort->Value()) >>= (CORBA::Any::to_boolean ) b;
3936 cdebug << ThreadNo() << " Out" << i << " : " << b << "(boolean)" << endl ;
3938 case CORBA::tk_char:
3940 (anOutPort->Value()) >>= (CORBA::Any::to_char ) c;
3941 cdebug << ThreadNo() << " Out" << i << " : " << c << "(char)" << endl ;
3943 case CORBA::tk_short:
3945 (anOutPort->Value()) >>= s;
3946 cdebug << ThreadNo() << " Out" << i << " : " << s << "(short)" << endl ;
3948 case CORBA::tk_long:
3950 (anOutPort->Value()) >>= l;
3951 cdebug << ThreadNo() << " Out" << i << " : " << l << "(long)" << endl ;
3953 case CORBA::tk_float:
3955 (anOutPort->Value()) >>= f;
3956 cdebug << ThreadNo() << " Out" << i << " : " << f << "(float)" << endl ;
3958 case CORBA::tk_double:
3960 (anOutPort->Value()) >>= d;
3961 cdebug << ThreadNo() << " Out" << i << " : " << d << "(double)" << endl ;
3963 case CORBA::tk_objref:
3964 CORBA::Object_ptr obj ;
3967 //JR 02.08.2005 Debug SEGV anOutPort->Value() >>= obj ;
3969 anAny = anOutPort->Value() ;
3970 #if OMNIORB_VERSION >= 4
3971 anAny >>= (CORBA::Any::to_object ) obj ;
3975 retstr = ObjectToString( obj );
3976 cdebug << ThreadNo() << " Out" << i << " : " << "ToString( object ) "
3980 cdebug << ThreadNo() << " Out" << i << " : " << "ToString( object ) "
3981 << "Catched ERROR" << endl ;
3986 cdebug << ThreadNo() << " Out" << i << " : " << "(other ERROR)" << endl ;
3991 } // End of : for ( i = 0 ; i < nOutParams ; i++ ) {
3992 #if OutParametersSetTrace
3993 cdebug << ThreadNo() << "OutParametersSet End of loop with " << nOutParams
3994 << " OutParams. aGateOutPort " << (void *) aGateOutPort << " IsSwitchNode "
3995 << IsSwitchNode() << " OrSwitch " << OrSwitch << " DefaultSwitch " << DefaultSwitch
4000 if ( IsSwitchNode() && aGateOutPort ) {
4001 //JR 09.02.2005 : OrSwitch is the OR of all SwitchBranches :
4002 //It controls that there is only one SwitchBranch activated
4003 //If it's final value is false ==> activation of the Default in order to GOTO to EndSwitchNode
4004 //DefaultSwitch is true if a SwitchPort (SwitchBranch) is linked to the DefaultPort of the EndSwitchNode
4005 if ( !OrSwitch && !DefaultSwitch ) {
4006 if ( aGateOutPort->InPortsSize() && aGateOutPort->ChangeInPorts( 0 ) ) {
4007 //Dynamic activation of the Default OutPort :
4008 #if OutParametersSetTrace
4009 cdebug << ThreadNo() << " " << "OutGate " << Name() << " Open of "
4010 << aGateOutPort->PortName() << " " << aGateOutPort->Kind() << " WITH DefaultPort"
4014 OutParametersList[0].Value <<= l ;
4015 aGateOutPort->SetValue( OutParametersList[0].Value ) ;
4018 //The Default OutPort is not linked ==> error
4019 string anErrorMessage = string( "DefaultPort of SwitchNode " ) +
4020 string( Name() ) + " is not connected." ;
4021 _OutNode->Graph()->SetMessages( anErrorMessage ) ;
4022 #if OutParametersSetTrace
4023 cdebug << ThreadNo() << " " << "OutGate " << Name() << " "
4024 << aGateOutPort->PortName() << " " << aGateOutPort->Kind() << " NOT CONNECTED ERROR"
4030 //JR 07.04.2005 Debug : reset only if it is not a default switch (SwitchBranch or
4031 // SwitchParameter of SwitchNode connected to the DefaultInPort of
4034 else if ( !DefaultSwitch ) {
4035 #if OutParametersSetTrace
4036 cdebug << ThreadNo() << " " << "OutGate " << Name() << " Close of "
4037 << aGateOutPort->PortName() << " " << aGateOutPort->Kind() << " NO DefaultPort"
4038 << " OrSwitch " << OrSwitch << " DefaultSwitch " << DefaultSwitch << endl ;
4041 OutParametersList[0].Value <<= l ;
4042 aGateOutPort->SetValue( OutParametersList[0].Value ) ;
4045 // The OutPort field of InPorts of EndSwitchNode may be updated from each OutPort of that SwitchNode :
4046 GraphBase::EndOfSwitchNode * anEndSwitchNode = (GraphBase::EndOfSwitchNode * ) CoupledNode() ;
4049 //JR 16.02.2005 Debug : At first Change InPorts of EndSwitchNode that have the same name as an OutPort of
4050 // the SwitchNode even if it is the DefaultPort : GraphSwitchCheckDefault1.xml
4051 //STEP A : InPorts of EndSwitchNode that have the same name as an OutPort of the SwitchNode
4052 for ( i = 0 ; i < GetNodeOutPortsSize() ; i++ ) {
4053 GraphBase::OutPort * anOutPort = GetChangeNodeOutPort( i );
4054 GraphBase::InPort * anInPort = NULL ;
4055 anInPort = anEndSwitchNode->GetChangeInPort( anOutPort->PortName() ) ;
4057 #if OutParametersSetTrace
4058 cdebug << "OutParametersSet " << Name() << " " << anInPort->NodeName()
4059 << "( " << anInPort->PortName() << " , " << anInPort->Kind() << " ) with same name " ;
4060 if ( anInPort->GetOutPort() ) {
4061 cdebug << "linked from " << anInPort->GetOutPort()->NodeName()
4062 << "( " << anInPort->GetOutPort()->PortName() << " ) " ;
4065 cdebug << "NOT linked " ;
4067 cdebug << "CHANGED TO linked from " << anOutPort->NodeName() << "( "
4068 << anOutPort->PortName() << " )" << endl ;
4070 anInPort->ChangeOutPort( anOutPort ) ;
4073 //STEP B : InPorts of EndSwitchNode directly connected from an OutPort of the SwitchNode
4074 for ( i = 0 ; i < GetNodeOutPortsSize() ; i++ ) {
4075 GraphBase::OutPort * anOutPort = GetChangeNodeOutPort( i );
4076 GraphBase::InPort * anInPort ;
4078 for ( j = 0 ; j < anOutPort->InPortsSize() ; j++ ) {
4079 anInPort = anOutPort->ChangeInPorts( j ) ;
4080 //Update the OutPort field in the Inports directly connected of the EndSwitchNode :
4081 if ( !strcmp( anInPort->NodeName() , anEndSwitchNode->Name() ) ) {
4082 #if OutParametersSetTrace
4083 cdebug << "OutParametersSet " << Name() << " " << anInPort->NodeName()
4084 << "( " << anInPort->PortName() << " , " << anInPort->Kind()
4085 << " ) directly connected " ;
4086 if ( anInPort->GetOutPort() ) {
4087 cdebug << "linked from " << anInPort->GetOutPort()->NodeName()
4088 << "( " << anInPort->GetOutPort()->PortName() << " ) " ;
4091 cdebug << "NOT linked " ;
4093 cdebug << "CHANGED TO linked from " << anOutPort->NodeName() << "( "
4094 << anOutPort->PortName() << " )" << endl ;
4096 anInPort->ChangeOutPort( anOutPort ) ;
4100 //STEP C : If it is not the DefaultBranch, explore the SwitchBranch and all NOTSwitchBranch[es]
4101 //Change recursively InPorts of EndSwitchNode linked to that Branch (or that SwitchNode)
4103 for ( i = 0 ; i < LinkedNodesSize() ; i++ ) {
4104 GraphBase::ComputingNode * aNode = (GraphBase::ComputingNode * ) LinkedNodes( i ) ;
4105 if ( aNode != anEndSwitchNode && !aNode->IsGOTONode() &&
4106 !aNode->IsDataFlowNode() && !aNode->IsDataStreamNode() ) {
4107 const GraphBase::InPort * anInGate = aNode->GetNodeInGate() ;
4108 GraphExecutor::InNode * anInNode = (GraphExecutor::InNode * ) aNode->GetInNode() ;
4109 //STEP C1 : SwitchBranch :
4110 if ( anInGate->GetOutPort() ) {
4111 if ( anInGate->GetOutPort()->BoolValue() ) {
4112 #if OutParametersSetTrace
4113 cdebug << "OutParametersSet " << Name() << " SWITCHBranch " << aNode->Name() << endl ;
4116 for ( j = 0 ; j < aNode->GetNodeOutPortsSize() ; j++ ) {
4117 GraphBase::OutPort * anOutPort = aNode->GetChangeNodeOutPort( j );
4118 anInNode->SetOutPortsOfInportsOfEndSwitch( anOutPort , anEndSwitchNode->Name() ) ;
4122 //STEP C2 : NOTSwitchBranch :
4124 #if OutParametersSetTrace
4125 cdebug << "OutParametersSet " << Name() << " NOTSWITCHBranch " << aNode->Name() << endl ;
4128 for ( j = 0 ; j < aNode->GetNodeOutPortsSize() ; j++ ) {
4129 GraphBase::OutPort * anOutPort = aNode->GetChangeNodeOutPort( j );
4130 anInNode->SetOutPortsOfInportsOfEndSwitch( anOutPort , anEndSwitchNode->Name() ) ;
4139 #if OutParametersSetTrace
4140 cdebug_out << "OutParametersSet " << Name() << " nOutParams " << nOutParams << " NewPortState "
4141 << PortState << " RetVal " << RetVal << endl ;
4147 void GraphExecutor::InNode::SetOutPortsOfInportsOfEndSwitch( GraphBase::OutPort * anOutPort ,
4148 const char * anEndSwitchNodeName ) {
4149 #if OutParametersSetTrace
4150 cdebug_in << "SetOutPortsOfInportsOfEndSwitch " << Name() << " " << anOutPort->NodeName() << "( "
4151 << anOutPort->PortName() << " ) with " << anOutPort->InPortsSize() << " links." << endl ;
4153 GraphBase::InPort * anInPort ;
4155 for ( i = 0 ; i < anOutPort->InPortsSize() ; i++ ) {
4156 anInPort = anOutPort->ChangeInPorts( i ) ;
4157 if ( !anInPort->IsDataStream() ) {
4158 //Update the OutPort field in the Inports of the EndSwitchNode :
4159 if ( !strcmp( anInPort->NodeName() , anEndSwitchNodeName ) ) {
4160 #if OutParametersSetTrace
4161 cdebug << "SetOutPortsOfInportsOfEndSwitch " << Name() << " " << anInPort->NodeName()
4162 << "( " << anInPort->PortName() << " , " << anInPort->Kind() << " ) " ;
4163 if ( anInPort->GetOutPort() ) {
4164 cdebug << "linked from " << anInPort->GetOutPort()->NodeName()
4165 << "( " << anInPort->GetOutPort()->PortName() << " ) " ;
4168 cdebug << "NOT linked ERROR " ;
4170 cdebug << "CHANGED TO linked from "
4171 << anOutPort->NodeName() << "( "
4172 << anOutPort->PortName() << " )" << endl ;
4174 anInPort->ChangeOutPort( anOutPort ) ;
4177 #if OutParametersSetTrace
4178 cdebug << "SetOutPortsOfInportsOfEndSwitch " << Name() << " " << anInPort->NodeName()
4179 << "( " << anInPort->PortName() << " , " << anInPort->Kind() << " ) " << endl ;
4181 GraphBase::ComputingNode * aComputingNode ;
4182 aComputingNode = _OutNode->Graph()->GetChangeGraphNode( anInPort->NodeName() ) ;
4183 if ( aComputingNode && !aComputingNode->IsGOTONode() &&
4184 !( IsEndLoopNode() && GOTONode()->CoupledNode() == aComputingNode ) ) {
4185 GraphExecutor::InNode * aNode ;
4186 aNode = (GraphExecutor::InNode * ) aComputingNode->GetInNode() ;
4189 for ( j = 0 ; j < aNode->GetNodeOutPortsSize() ; j++ ) {
4190 GraphBase::OutPort * anOutPort = aNode->GetChangeNodeOutPort( j ) ;
4191 aNode->SetOutPortsOfInportsOfEndSwitch( anOutPort , anEndSwitchNodeName ) ;
4198 #if OutParametersSetTrace
4199 cdebug_out << "SetOutPortsOfInportsOfEndSwitch " << Name() << " OutPort " << anOutPort->PortName()