1 // SUPERV GraphExecutor : contains classes that permit execution of graphs and particularly the execution automaton
3 // Copyright (C) 2003 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
6 // This library is free software; you can redistribute it and/or
7 // modify it under the terms of the GNU Lesser General Public
8 // License as published by the Free Software Foundation; either
9 // version 2.1 of the License.
11 // This library is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 // Lesser General Public License for more details.
16 // You should have received a copy of the GNU Lesser General Public
17 // License along with this library; if not, write to the Free Software
18 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20 // See http://www.opencascade.org/SALOME/ or email : webmaster.salome@opencascade.org
24 // File : DataFlowBase_InNodeThreads.cxx
25 // Author : Jean Rahuel, CEA
42 #if defined __GNUC_2__
43 // _CS_gbo_040604 include explicite pour l'utilisation de
44 // std::transform dans UpperCase
45 #include <cctype> // for toupper
46 #include <algorithm> // for transform
53 #include <SALOMEconfig.h>
54 #include CORBA_CLIENT_HEADER(SALOME_Component)
55 #include "SALOME_LifeCycleCORBA.hxx"
57 #include "DataFlowExecutor_DataFlow.hxx"
58 #include "DataFlowEditor_DataFlow.hxx" // GraphEditor package must be built BEFORE
61 static void UpperCase(std::string& rstr)
63 #if defined __GNUC_2__
64 // _CS_gbo_040604 towupper n'existe pas. Utilisation de toupper. Par
65 // ailleurs, include explicite de cctype et algorithm pour toupper
66 // et transform respectivement.
67 std::transform(rstr.begin(), rstr.end(), rstr.begin(),toupper);
69 std::transform(rstr.begin(), rstr.end(), rstr.begin(),towupper);
73 #define SendEventTrace 0
74 int GraphExecutor::InNode::SendEvent( const GraphExecutor::NodeEvent anEvent ) {
76 _CurrentEvent = (GraphExecutor::NodeEvent ) anEvent ;
78 cdebug_in << pthread_self() << "/" << ThreadNo() << " -->SendEvent Node " << Name()
80 << Automaton()->ControlStateName( ControlState() )
81 << " Event : " << Automaton()->EventName( anEvent )
82 << " State : " << Automaton()->StateName( State() ) << " _RewindStack " << _RewindStack << endl;
86 _NextState = Automaton()->NextState( _OldState , anEvent ) ;
87 if ( _NextState == _OldState ) {
88 cdebug << pthread_self() << "/" << ThreadNo()
89 << " GraphExecutor::InNodeThreads::SendEvent SameStates "
90 << _OldState << endl ;
91 _NextAction = GraphExecutor::VoidAction ;
94 _NextAction = Automaton()->NextAction( _NextState , anEvent ) ;
97 cdebug << pthread_self() << "/" << ThreadNo() << "NextState( " << _OldState << " , "
98 << Automaton()->EventName( anEvent ) << " ) --> _NextState = " << _NextState
99 << " NextAction( " << _NextState << " , " << Automaton()->EventName( anEvent )
100 << " ) --> _NextAction = "
101 << Automaton()->ActionName( _NextAction ) << endl ;
104 // State( _NextState ) ;
105 // if ( _OldState == GraphExecutor::SuccessedExecutingState ||
106 // _OldState == GraphExecutor::ErroredExecutingState ) {
111 cdebug << pthread_self() << "/" << ThreadNo() << " SendedEvent Node "
112 << Name() << endl << " ControlState : "
113 << Automaton()->ControlStateName( ControlState() ) << endl
114 << " OldState : " << Automaton()->StateName( _OldState ) << endl
115 << " Event : " << Automaton()->EventName( anEvent ) << endl
116 << " NextState : " << Automaton()->StateName( _NextState ) << endl
117 << " Action : " << Automaton()->ActionName( _NextAction ) << endl
118 << " CreateNewThread " << CreateNewThread() << endl
119 << " _RewindStack " << _RewindStack << endl ;
122 int sts = executeAction() ;
125 cdebug_out << pthread_self() << "/" << ThreadNo() << " <--- SendEvent Node " << Name()
126 << " Event : " << Automaton()->EventName( anEvent )
127 << " State : " << Automaton()->StateName( State() )
135 #define ActionsTrace 0
136 // ReadyAction - RunningAction - DoneAction - SuspendedAction :
137 // for StateWait( ReadyW - RunningW - DoneW - SuspendedW )
138 void GraphExecutor::InNode::ReadyAction() {
139 if ( pthread_mutex_lock( &_MutexWait ) ) {
140 perror("Ready pthread_mutex_lock ") ;
144 cdebug << pthread_self() << "/" << ThreadNo()
145 << "ReadyAction pthread_cond_broadcast _ReadyWait "
148 if ( pthread_cond_broadcast( &_ReadyWait ) ) {
149 perror("Ready pthread_cond_broadcast ") ;
151 if ( pthread_mutex_unlock( &_MutexWait ) ) {
152 perror("Ready pthread_mutex_unlock ") ;
157 void GraphExecutor::InNode::RunningAction() {
158 if ( pthread_mutex_lock( &_MutexWait ) ) {
159 perror("Running pthread_mutex_lock ") ;
163 cdebug << pthread_self() << "/" << ThreadNo()
164 << "RunningAction pthread_cond_broadcast _RunningWait "
167 // That activate the pthread_cond_wait for RunninWait
168 if ( pthread_cond_broadcast( &_RunningWait ) ) {
169 perror("Running pthread_cond_broadcast ") ;
171 if ( pthread_mutex_unlock( &_MutexWait ) ) {
172 perror("Running pthread_mutex_unlock ") ;
177 void GraphExecutor::InNode::DoneAction() {
178 if ( pthread_mutex_lock( &_MutexWait ) ) {
179 perror("Done pthread_mutex_lock ") ;
183 cdebug << pthread_self() << "/" << ThreadNo()
184 << "DoneAction pthread_cond_broadcast _DoneWait "
187 if ( pthread_cond_broadcast( &_DoneWait ) ) {
188 perror("Done pthread_cond_broadcast ") ;
190 if ( pthread_mutex_unlock( &_MutexWait ) ) {
191 perror("Done pthread_mutex_unlock ") ;
196 void GraphExecutor::InNode::SuspendedAction() {
197 if ( pthread_mutex_lock( &_MutexWait ) ) {
198 perror("Suspended pthread_mutex_lock ") ;
202 cdebug << pthread_self() << "/" << ThreadNo()
203 << "SuspendedAction pthread_cond_broadcast _SuspendedWait "
206 if ( pthread_cond_broadcast( &_SuspendedWait ) ) {
207 perror("Suspended pthread_cond_broadcast ") ;
209 if ( pthread_mutex_unlock( &_MutexWait ) ) {
210 perror("Suspended pthread_mutex_unlock ") ;
215 // SuspendAction <--> { ResumeAction - ReStartAction }
216 GraphExecutor::InNode * GraphExecutor::InNode::SuspendAction() {
218 if ( pthread_mutex_lock( &_MutexWait ) ) {
219 perror("Suspend pthread_mutex_lock ") ;
222 if ( !_SuspendSync ) {
223 cdebug << pthread_self() << "/" << ThreadNo() << " pthread_cond " << Name()
224 << " SuspendAction pthread_cond_wait _SuspendWait "
225 << Automaton()->StateName( State() ) << endl ;
226 _SuspendSync = true ;
227 _OutNode->SuspendThread() ;
228 if ( pthread_cond_wait( &_SuspendWait , &_MutexWait ) ) {
229 perror("SuspendAction pthread_cond_wait ") ;
231 _OutNode->ResumeThread() ;
233 cdebug << pthread_self() << "/" << ThreadNo() << " pthread_cond " << Name()
234 << " SuspendAction pthread_cond_waited"
235 << Automaton()->StateName( State() ) << endl ;
240 cdebug << pthread_self() << "/" << ThreadNo() << " pthread_cond " << Name()
241 << " NO SuspendAction pthread_cond_wait"
242 << Automaton()->StateName( State() ) << endl ;
245 // SendEvent( _aResumeEvent ) ; ===> Mutex with myself !
246 _SuspendSync = false ;
247 if ( ControlState() == SUPERV::ToSuspendStartState ||
248 ControlState() == SUPERV::ToSuspendState ) {
249 ControlState( SUPERV::VoidState ) ;
251 if ( pthread_mutex_unlock( &_MutexWait ) ) {
252 perror("SuspendAction pthread_mutex_unlock ") ;
256 SendEvent( _aResumeEvent ) ;
257 // if ( ControlState() == SUPERV::ToSuspendStartState ) {
258 // ControlState( SUPERV::VoidState ) ;
261 if ( pthread_mutex_lock( &_MutexWait ) ) {
262 perror("SuspendAction pthread_mutex_lock ") ;
267 cdebug << pthread_self() << "/" << ThreadNo() << " pthread_cond " << Name()
268 << " SuspendAction pthread_cond_signal _ResumeWait" << endl ;
270 if ( pthread_cond_signal( &_ResumeWait ) ) {
271 perror("SuspendAction pthread_cond_signal _ResumeWait ") ;
274 cdebug << pthread_self() << "/" << ThreadNo() << " pthread_cond " << Name()
275 << " SuspendAction pthread_cond_signaled _ResumeWait " << endl ;
280 cdebug << pthread_self() << "/" << ThreadNo() << " pthread_cond " << Name()
281 << " NO SuspendAction pthread_cond_signal _ResumeWait" << endl ;
285 if ( pthread_mutex_unlock( &_MutexWait ) ) {
286 perror("SuspendAction pthread_mutex_unlock ") ;
289 if ( _aReStartNode ) {
290 cdebug << Name() << " " << Automaton()->StateName( State() )
291 << "aReStartNode : " << _aReStartNode->Name() << " "
292 << Automaton()->StateName( _aReStartNode->State() ) << endl ;
293 _aReStartNode->SendEvent( _aResumeEvent ) ;
296 cdebug << "NO aReStartNode"
297 << Automaton()->StateName( State() ) << endl ;
299 return _aReStartNode ;
302 bool GraphExecutor::InNode::ResumeAction( GraphExecutor::NodeEvent aResumeEvent ) {
304 if ( pthread_mutex_lock( &_MutexWait ) ) {
305 perror("ResumeAction pthread_mutex_lock ") ;
308 _aResumeEvent = aResumeEvent ;
309 if ( _SuspendSync ) {
311 cdebug << pthread_self() << "/" << ThreadNo() << " pthread_cond " << Name()
312 << " ResumeAction pthread_cond_signal" << endl ;
314 if ( pthread_cond_signal( &_SuspendWait ) ) {
315 perror("ResumeAction pthread_cond_signal ") ;
318 cdebug << pthread_self() << "/" << ThreadNo() << " pthread_cond " << Name()
319 << " ResumeAction pthread_cond_signaled _SuspendWait " << endl ;
325 cdebug << pthread_self() << "/" << ThreadNo() << " pthread_cond " << Name()
326 << " NO ResumeAction pthread_cond_signal" << endl ;
328 if ( pthread_self() == ThreadNo() ) {
329 RetVal = false ; /*/ Ne pas s'attendre soi-meme !...*/
332 _SuspendSync = true ;
333 RetVal = true ; // Il faut tout de meme attendre ci-apres ...
336 if ( pthread_mutex_unlock( &_MutexWait ) ) {
337 perror("ResumeAction pthread_mutex_unlock ") ;
342 if ( pthread_mutex_lock( &_MutexWait ) ) {
343 perror("ResumeAction pthread_mutex_lock ") ;
346 if ( !_ResumeSync ) {
348 cdebug << pthread_self() << "/" << ThreadNo() << " pthread_cond "
349 << Name() << " ResumeAction pthread_cond_wait _ResumeWait "
350 << Automaton()->StateName( State() ) << endl ;
353 if ( pthread_cond_wait( &_ResumeWait , &_MutexWait ) ) {
354 perror("ResumeAction pthread_cond_wait ") ;
357 cdebug << pthread_self() << "/" << ThreadNo() << " pthread_cond "
358 << Name() << " ResumeAction pthread_cond_waited _ResumeWait"
359 << Automaton()->StateName( State() ) << endl ;
365 cdebug << pthread_self() << "/" << ThreadNo() << " pthread_cond "
366 << Name() << " NO ResumeAction pthread_cond_wait _ResumeWait"
367 << Automaton()->StateName( State() ) << endl ;
371 _ResumeSync = false ;
372 if ( pthread_mutex_unlock( &_MutexWait ) ) {
373 perror("ResumeAction pthread_mutex_unlock ") ;
378 cdebug << pthread_self() << "/" << ThreadNo()
379 << "GraphExecutor::InNodeThreads::ResumeAction RetVal " << RetVal << endl ;
384 bool GraphExecutor::InNode::ReStartAction( GraphExecutor::InNode * aReStartNode ,
385 GraphExecutor::NodeEvent anEvent ) {
386 GraphExecutor::InNode * oldReStartNode = _aReStartNode ;
387 _aReStartNode = aReStartNode ;
388 _aReStartEvent = anEvent ;
389 cdebug << pthread_self() << " GraphExecutor::InNodeThreads::ReStartAction from "
390 << Name() << " " << Automaton()->StateName( State() ) << " to "
391 << aReStartNode->ThreadNo() << " " << aReStartNode->Name() << " "
392 << Automaton()->StateName( aReStartNode->State() ) ;
393 if ( oldReStartNode ) {
394 cdebug << " oldReStartNode " << oldReStartNode->Name() << endl ;
399 return ResumeAction( GraphExecutor::ToReStartEvent ) ;
402 void GraphExecutor::InNode::KilledAction() {
403 if ( pthread_mutex_lock( &_MutexWait ) ) {
404 perror("Killed pthread_mutex_lock ") ;
408 cdebug << "pthread_cond " << Name() << " Killed pthread_cond_wait"
411 if ( pthread_cond_wait( &_KillWait , &_MutexWait ) ) {
412 perror("Killed pthread_cond_wait ") ;
414 cdebug << "pthread_cond " << Name() << " Killed pthread_cond_waited"
418 cdebug << "pthread_cond " << Name() << " NO Killed pthread_cond_wait"
422 if ( pthread_mutex_unlock( &_MutexWait ) ) {
423 perror("Killed pthread_mutex_unlock ") ;
428 void GraphExecutor::InNode::KillAction() {
429 if ( pthread_mutex_lock( &_MutexWait ) ) {
430 perror("Kill pthread_mutex_lock ") ;
434 cdebug << "pthread_cond " << Name() << " Kill pthread_cond_signal"
436 // if ( pthread_cond_broadcast( &_KillWait ) ) {
437 if ( pthread_cond_signal( &_KillWait ) ) {
438 perror("Kill pthread_cond_broadcast ") ;
440 cdebug << "pthread_cond " << Name() << " Kill pthread_cond_signaled"
444 cdebug << "pthread_cond " << Name() << " NO Kill pthread_cond_signal"
448 if ( pthread_mutex_unlock( &_MutexWait ) ) {
449 perror("Kill pthread_mutex_unlock ") ;
454 void GraphExecutor::InNode::StoppedAction() {
455 if ( pthread_mutex_lock( &_MutexWait ) ) {
456 perror("Stopped pthread_mutex_lock ") ;
459 if ( pthread_cond_wait( &_StopWait , &_MutexWait ) ) {
460 perror("Stopped pthread_cond_wait ") ;
462 if ( pthread_mutex_unlock( &_MutexWait ) ) {
463 perror("Stopped pthread_mutex_unlock ") ;
468 void GraphExecutor::InNode::StopAction() {
469 if ( pthread_mutex_lock( &_MutexWait ) ) {
470 perror("Stop pthread_mutex_lock ") ;
473 if ( pthread_cond_broadcast( &_StopWait ) ) {
474 perror("Stop pthread_cond_broadcast ") ;
476 if ( pthread_mutex_unlock( &_MutexWait ) ) {
477 perror("Stop pthread_mutex_unlock ") ;
482 void GraphExecutor::InNode::ThreadStartedAction() {
483 if ( pthread_mutex_lock( &_MutexWait ) ) {
484 perror("ThreadStarted pthread_mutex_lock ") ;
487 if ( !_ThreadStartedSync ) {
489 cdebug << pthread_self() << "/" << ThreadNo()
490 << "pthread_cond " << Name() << " ThreadStarted pthread_cond_wait"
493 _ThreadStartedSync = true ;
494 if ( pthread_cond_wait( &_ThreadStartedWait , &_MutexWait ) ) {
495 perror("ThreadStarted pthread_cond_wait ") ;
498 cdebug << pthread_self() << "/" << ThreadNo()
499 << "pthread_cond " << Name() << " ThreadStarted pthread_cond_waited"
505 cdebug << pthread_self() << "/" << ThreadNo()
506 << "pthread_cond " << Name() << " NO ThreadStarted pthread_cond_wait"
510 _ThreadStartedSync = false ;
511 if ( pthread_cond_signal( &_ThreadStartedWait ) ) {
512 perror("ThreadStart pthread_cond_signal ") ;
516 cdebug << pthread_self() << "/" << ThreadNo()
517 << "pthread_cond " << Name() << " NO ThreadStarted pthread_cond_signaled"
521 if ( pthread_mutex_unlock( &_MutexWait ) ) {
522 perror("ThreadStarted pthread_mutex_unlock ") ;
527 void GraphExecutor::InNode::ThreadStartAction() {
528 if ( pthread_mutex_lock( &_MutexWait ) ) {
529 perror("ThreadStart pthread_mutex_lock ") ;
532 if ( _ThreadStartedSync ) {
534 cdebug << pthread_self() << "/" << ThreadNo()
535 << "pthread_cond " << Name() << " ThreadStart pthread_cond_signal"
538 _ThreadStartedSync = false ;
539 if ( pthread_cond_signal( &_ThreadStartedWait ) ) {
540 perror("ThreadStart pthread_cond_broadcast ") ;
543 cdebug << pthread_self() << "/" << ThreadNo()
544 << "pthread_cond " << Name() << " ThreadStart pthread_cond_signaled"
550 cdebug << pthread_self() << "/" << ThreadNo()
551 << "pthread_cond " << Name() << " NO ThreadStart pthread_cond_signal"
554 _ThreadStartedSync = true ;
556 if ( pthread_cond_wait( &_ThreadStartedWait , &_MutexWait ) ) {
557 perror("ThreadStarted pthread_cond_wait ") ;
561 cdebug << pthread_self() << "/" << ThreadNo()
562 << "pthread_cond " << Name() << " NO ThreadStart pthread_cond_waited"
566 if ( pthread_mutex_unlock( &_MutexWait ) ) {
567 perror("ThreadStart pthread_mutex_unlock ") ;
572 int GraphExecutor::InNode::executeAction() {
573 int oldRewindStack = ( _RewindStack > MAXSTACKTHREADSIZE ) ;
574 if ( !CreateNewThread() && oldRewindStack ) {
576 cdebug << pthread_self() << "/" << ThreadNo()
577 << " executeAction start Thread _RewindStack " << _RewindStack << " > "
578 << MAXSTACKTHREADSIZE << " CreateNewThread "
579 << CreateNewThread() << " " << Automaton()->ActionName( _NextAction ) << "(" << Name() << ")"
582 CreateNewThread( true ) ;
583 _OutNode->IncrCreatedThreads() ;
586 if ( CreateNewThread() ) {
587 CreateNewThread( false ) ;
588 if ( ThreadNo() == 0 ) {
591 cdebug << pthread_self() << "/" << ThreadNo()
592 << " executeAction start Thread _RewindStack " << _RewindStack << " "
593 << Automaton()->ActionName( _NextAction ) << "(" << Name() << ")"
597 int pthread_sts = 1 ;
598 // _OutNode->PushEvent( NULL , GraphExecutor::NewThreadEvent ,
599 // GraphExecutor::ExecutingState ) ;
600 while ( (pthread_sts = pthread_create(&T, NULL, run_function, this )) ) {
601 char * msg = "Cannot pthread_create " ;
603 cdebug << ThreadNo() << " " << msg << " --> sleep(5)" << endl ;
604 cdebug << ThreadNo() << " PTHREAD_THREADS_MAX : "
605 << PTHREAD_THREADS_MAX << " pthread_create status : " ;
606 if ( pthread_sts == EAGAIN ) {
607 cdebug << "EAGAIN(" << pthread_sts << ")" << endl ;
608 cdebug << _OutNode->CreatedThreads() << " was created (and exited)" << endl ;
609 cdebug << "It seems to me that with gdb we are limited to 256 threads" << endl ;
612 cdebug << pthread_sts << endl ;
616 pthread_exit( msg ) ;
619 cdebug << pthread_self() << "/" << ThreadNo()
620 << "executeAction has created thread " << T << endl ;
622 ThreadStartedAction() ;
624 cdebug << pthread_self() << "/" << ThreadNo()
625 << "executeAction the thread " << T << " has called NewThread and will call ExecuteAction for node "
631 cdebug << pthread_self() << "/" << ThreadNo()
632 << " executeAction restart Thread _RewindStack " << _RewindStack << " "
633 << Automaton()->StateName( State() ) << " "
634 << Automaton()->ActionName( _NextAction ) << "(" << Name()
635 << ") ReStartAction ==>" << endl;
637 State( GraphExecutor::SuspendedSuccessedState ) ;
638 if ( !ReStartAction( this , GraphExecutor::ReStartEvent ) ) {
639 cdebug << pthread_self() << "/" << ThreadNo()
640 << " executeAction STATE & CALLED "
641 << Automaton()->ActionName( _NextAction ) << "(" << Name()
642 << ") ERROR-DEBUG " << endl;
646 cdebug << pthread_self() << "/" << ThreadNo() << " executeAction NO CALL "
647 << Automaton()->ActionName( _NextAction ) << "(" << Name()
654 if ( _CurrentEvent == ExecuteEvent ) {
658 cdebug << pthread_self() << "/" << ThreadNo() << " executeAction call "
659 << Automaton()->ActionName( _NextAction ) << "(" << Name() << ") _RewindStack " << _RewindStack
662 return ExecuteAction() ;
667 void GraphExecutor::InNode::coutbegin() {
669 cdebug << pthread_self() << "/" << ThreadNo() << " run_function begin"
670 << " " << Name() << " " << Automaton()->StateName( State() ) << endl ;
673 void GraphExecutor::InNode::coutexit() {
675 cdebug << pthread_self() << "/" << ThreadNo() << " run_function pthread_exit _RewindStack " << _RewindStack
676 << " " << Name() << " " << Automaton()->StateName( State() ) << endl ;
679 void * run_function(void *p) {
680 GraphExecutor::InNode *aNode = (GraphExecutor::InNode *) p;
682 aNode->NewThread( pthread_self() ) ;
683 if ( pthread_setcanceltype( PTHREAD_CANCEL_ASYNCHRONOUS , NULL ) ) {
684 perror("pthread_setcanceltype ") ;
687 if ( pthread_setcancelstate( PTHREAD_CANCEL_ENABLE , NULL ) ) {
688 perror("pthread_setcancelstate ") ;
691 aNode->ThreadStartAction() ;
692 // cout << "run_function " << aNode->Name() << "->ExecuteAction() Coupled : " << aNode->CoupledNode()
694 aNode->ExecuteAction() ;
695 char * msg = new char[40] ;
696 sprintf( msg , "%d" , (int ) aNode->ThreadNo() ) ;
697 strcat( msg , " thread exit" ) ;
699 aNode->ExitThread() ;
702 pthread_exit( (void * ) smsg.c_str() ) ;
706 int GraphExecutor::InNode::ExecuteAction() {
710 const char * nextactionname = Automaton()->ActionName( _NextAction ) ;
711 const char * statename = Automaton()->StateName( State() ) ;
712 const char * nextstatename = Automaton()->StateName( _NextState ) ;
713 cdebug_in << pthread_self() << "/" << ThreadNo() << " --> ExecuteAction "
714 << nextactionname << " " << statename << " NextState "
715 << nextstatename << endl ;
718 State( _NextState ) ;
719 switch ( _NextAction ) {
720 case GraphExecutor::ErrorAction : {
721 sts = ErrorAction() ;
724 case GraphExecutor::VoidAction : {
728 case GraphExecutor::DataWaiting_SomeDataReadyAction : {
729 sts = DataWaiting_SomeDataReadyAction() ;
732 case GraphExecutor::DataUndef_NotAllDataReadyAction : {
733 sts = DataUndef_NotAllDataReadyAction() ;
736 case GraphExecutor::DataUndef_AllDataReadyAction : {
737 sts = DataUndef_AllDataReadyAction() ;
740 case GraphExecutor::DataReady_SuspendAction : {
741 sts = DataReady_SuspendAction() ;
744 case GraphExecutor::SuspendedReady_ResumeAction : {
745 sts = SuspendedReady_ResumeAction() ;
748 case GraphExecutor::DataReady_KillAction : {
749 sts = DataReady_KillAction() ;
752 case GraphExecutor::DataReady_StopAction : {
753 sts = DataReady_StopAction() ;
756 case GraphExecutor::DataReady_ExecuteAction : {
757 sts = DataReady_ExecuteAction() ;
760 case GraphExecutor::Executing_SuspendAction : {
761 sts = Executing_SuspendAction() ;
764 case GraphExecutor::SuspendedExecuting_ResumeAction : {
765 sts = SuspendedExecuting_ResumeAction() ;
768 case GraphExecutor::Executing_KillAction : {
769 sts = Executing_KillAction() ;
772 case GraphExecutor::Executing_StopAction : {
773 sts = Executing_StopAction() ;
776 case GraphExecutor::Executing_SuccessAction : {
777 sts = Executing_SuccessAction() ;
780 case GraphExecutor::Executing_ErrorAction : {
781 sts = Executing_ErrorAction() ;
784 case GraphExecutor::Successed_SuccessAction : {
785 sts = Successed_SuccessAction() ;
788 case GraphExecutor::Errored_ErrorAction : {
789 sts = Errored_ErrorAction() ;
792 case GraphExecutor::Successed_SuspendAction : {
793 sts = Successed_SuspendAction() ;
796 case GraphExecutor::Errored_SuspendAction : {
797 sts = Errored_SuspendAction() ;
800 case GraphExecutor::SuspendedSuccessed_ResumeAction : {
801 sts = SuspendedSuccessed_ResumeAction() ;
804 case GraphExecutor::SuspendedErrored_ResumeAction : {
805 sts = SuspendedErrored_ResumeAction() ;
808 case GraphExecutor::Successed_KillAction : {
809 sts = Successed_KillAction() ;
812 case GraphExecutor::Errored_KillAction : {
813 sts = Errored_KillAction() ;
816 case GraphExecutor::Successed_StopAction : {
817 sts = Successed_StopAction() ;
820 case GraphExecutor::Errored_StopAction : {
821 sts = Errored_StopAction() ;
824 case GraphExecutor::SuspendedSuccessed_ReStartAction : {
825 sts = SuspendedSuccessed_ReStartAction() ;
828 case GraphExecutor::SuspendedErrored_ReStartAction : {
829 sts = SuspendedErrored_ReStartAction() ;
832 case GraphExecutor::SuspendedSuccessed_ReStartAndSuspendAction : {
833 sts = SuspendedSuccessed_ReStartAndSuspendAction() ;
836 case GraphExecutor::SuspendedErrored_ReStartAndSuspendAction : {
837 sts = SuspendedErrored_ReStartAndSuspendAction() ;
841 cdebug << pthread_self() << "/" << ThreadNo()
842 << " GraphExecutor::InNodeThreads::SendEvent Error Undefined Action : "
843 << _NextAction << endl ;
848 cdebug_out << pthread_self() << "/" << ThreadNo() << "<-- ExecuteAction "
849 << nextactionname << endl ;
854 int GraphExecutor::InNode::ErrorAction() {
855 cdebug << pthread_self() << "/" << ThreadNo() << " Automaton ErrorAction Node "
860 int GraphExecutor::InNode::VoidAction() {
861 cdebug << pthread_self() << "/" << ThreadNo() << " VoidAction " << Name() << endl;
865 #define SomeDataReadyTrace 0
866 int GraphExecutor::InNode::DataWaiting_SomeDataReadyAction() {
867 #if SomeDataReadyTrace
868 cdebug << pthread_self() << "/" << ThreadNo()
869 << " --> DataWaiting_SomeDataReadyAction from " << DataFromNode()
870 << " to " << Name() << endl;
875 bool LoopBeginning = false ;
876 bool LoopFinished = false ;
877 bool SwitchFinished = false ;
879 if ( IsLoopNode() ) {
880 GraphBase::OutPort * anOutLoopPort = GetChangeNodeInLoop()->GetOutPort() ; // DoLoop Port
881 if ( anOutLoopPort && anOutLoopPort->BoolValue() ) {
882 LoopBeginning = true ; // Beginning of Loop
885 if ( IsEndLoopNode() ) {
886 GraphBase::OutPort * anOutLoopPort = GetChangeNodeInLoop()->GetOutPort() ; // DoLoop Port
887 if ( anOutLoopPort && !anOutLoopPort->BoolValue() ) {
888 LoopFinished = true ; // End of Loop
891 if ( IsEndSwitchNode() && strcmp( GOTONode()->CoupledNode()->Name() , DataFromNode() ) ) {
892 GraphBase::OutPort * anOutGateSwitchPort = GetChangeNodeInGate()->GetOutPort() ; // Default Port
893 //JR 09.02.2005 : SomeDataReady is not from the SwitchNode
894 if ( anOutGateSwitchPort && !anOutGateSwitchPort->BoolValue() ) {
895 //JR 09.02.2005 : the OutPort of the SwitchNode connected to the default port is closed ===>
896 // Here after we consider that that DefaultPort is Ready (even if it's value is false)
897 SwitchFinished = true ; // End of Switch
900 #if SomeDataReadyTrace
901 cdebug << pthread_self() << "/" << ThreadNo() << " " << Name() << " LoopFinished " << LoopFinished
902 << " LoopBeginning " << LoopBeginning << " SwitchFinished " << SwitchFinished << endl ;
904 for ( k = 0 ; k < (unsigned int ) GetNodeInPortsSize() ; k++ ) {
905 GraphBase::InPort * anInPort = GetChangeNodeInPort(k) ;
906 GraphBase::OutPort * anOutPort = anInPort->GetOutPort() ;
907 #if SomeDataReadyTrace
908 cdebug << pthread_self() << "/" << ThreadNo() << " " << Name() << " InPort " << anInPort->PortName() << " " << anInPort->PortState() << " " << anInPort->PortStatus() ;
910 cdebug << " from OutPort " << anOutPort->NodeName() << "( " << anOutPort->PortName()
915 if ( anInPort->IsGate() && anOutPort == NULL ) {
917 anInPort->PortState( SUPERV::ReadyState ) ;
918 #if SomeDataReadyTrace
919 cdebug << pthread_self() << "/" << ThreadNo() << " " << Name() << " "
920 << anInPort->PortName() << " ControlPort inactive." << endl ;
923 // That InPort get its value from an other node : the node of anOutPort linked to that anInPort is
924 // different from the sender of SomeDataReady (DataFromNode)
925 else if ( strcmp( DataFromNode() , anOutPort->NodeName() ) ) {
926 if ( anInPort->PortState() == SUPERV::ReadyState ) {
928 #if SomeDataReadyTrace
929 cdebug << pthread_self() << "/" << ThreadNo() << " " << Name() << " "
930 << anInPort->PortName() << " Was Done from Node "
931 << anOutPort->NodeName() << "( " << anOutPort->PortName()
934 if ( GraphBase::Base::_prof_debug ) {
935 anOutPort->StringValue( *GraphBase::Base::_fdebug ) ;
941 else if ( IsLoopNode() && anInPort->IsDataConnected() ) {
942 anInPort->PortState( SUPERV::ReadyState ) ;
944 #if SomeDataReadyTrace
945 cdebug << pthread_self() << "/" << ThreadNo() << " " << Name() << " "
946 << anInPort->PortName() << " Was Done from Node "
947 << anOutPort->NodeName() << "( " << anOutPort->PortName()
948 << ") LoopBeginning " << LoopBeginning ;
950 if ( GraphBase::Base::_prof_debug ) {
951 anOutPort->StringValue( *GraphBase::Base::_fdebug ) ;
957 else if ( LoopFinished ) {
958 anInPort->PortState( SUPERV::ReadyState ) ;
960 #if SomeDataReadyTrace
961 cdebug << pthread_self() << "/" << ThreadNo() << " " << Name() << " "
962 << anInPort->PortName() << " Was Done from Node "
963 << anOutPort->NodeName() << "( " << anOutPort->PortName()
964 << ") LoopFinished" ;
966 if ( GraphBase::Base::_prof_debug ) {
967 anOutPort->StringValue( *GraphBase::Base::_fdebug ) ;
973 else if ( anInPort->IsGate() && SwitchFinished ) {
974 anInPort->PortState( SUPERV::ReadyState ) ;
976 #if SomeDataReadyTrace
977 cdebug << pthread_self() << "/" << ThreadNo() << " " << Name() << " "
978 << anInPort->PortName() << " Was Done from Node "
979 << anOutPort->NodeName() << "( " << anOutPort->PortName()
980 << ") SwitchFinished" ;
982 if ( GraphBase::Base::_prof_debug ) {
983 anOutPort->StringValue( *GraphBase::Base::_fdebug ) ;
989 else if ( anInPort->IsGate() &&
990 _OutNode->Graph()->GetGraphNode( anOutPort->NodeName() )->IsGOTONode() ) {
991 // GateOutPort of GOTONodes are always opened
992 anInPort->PortState( SUPERV::ReadyState ) ;
994 //JR 21.02.2005 Debug Memory leak : CORBA::Any * anAny = new CORBA::Any() ;
995 CORBA::Any anAny = CORBA::Any() ;
996 //JR 21.02.2005 Debug Memory leak : *anAny <<= (long ) 1 ;
997 anAny <<= (long ) 1 ;
998 _OutNode->Graph()->GetGraphNode( anOutPort->NodeName() )->GetChangeNodeOutGate()->Value( anAny ) ;
999 #if SomeDataReadyTrace
1000 cdebug << pthread_self() << "/" << ThreadNo() << " " << Name() << " "
1001 << anInPort->PortName() << " Was Done from Node "
1002 << anOutPort->NodeName() << "( " << anOutPort->PortName()
1005 if ( GraphBase::Base::_prof_debug ) {
1006 anOutPort->StringValue( *GraphBase::Base::_fdebug ) ;
1013 #if SomeDataReadyTrace
1014 cdebug << pthread_self() << "/" << ThreadNo() << " " << Name() << " "
1015 << anInPort->PortName() << " Was NOT Done from Node "
1016 << anOutPort->NodeName() << "( " << anOutPort->PortName() << ") "
1017 << " " << Automaton()->StateName( State() ) << " DataConnected "
1018 << anInPort->IsDataConnected() << " LoopBeginning "
1019 << LoopBeginning << endl ;
1023 // That InPort get its value from the sending node (DataFromNode)
1024 else if ( anInPort->IsGate() ) {
1025 //JR 30.03.2005 const CORBA::Any * theValue = anOutPort->Value() ;
1026 const CORBA::Any theValue = anOutPort->Value() ;
1028 //JR 30.03.2005 (*theValue) >>= GateOpened ;
1029 theValue >>= GateOpened ;
1030 if ( GateOpened != 0 ) {
1032 anInPort->PortState( SUPERV::ReadyState ) ;
1033 #if SomeDataReadyTrace
1034 cdebug << pthread_self() << "/" << ThreadNo() << " " << Name() << " "
1035 << anInPort->PortName() << " Gate is Opened from Node "
1036 << anOutPort->NodeName() << "( " << anOutPort->PortName()
1039 if ( GraphBase::Base::_prof_debug ) {
1040 anOutPort->StringValue( *GraphBase::Base::_fdebug ) ;
1046 else if ( LoopFinished ) {
1047 anInPort->PortState( SUPERV::ReadyState ) ;
1048 #if SomeDataReadyTrace
1049 cdebug << pthread_self() << "/" << ThreadNo() << " " << Name() << " "
1050 << anInPort->PortName() << " GATE IS CLOSED from Node "
1051 << anOutPort->NodeName() << "( " << anOutPort->PortName()
1052 << ") LoopFinished" ;
1054 if ( GraphBase::Base::_prof_debug ) {
1055 anOutPort->StringValue( *GraphBase::Base::_fdebug ) ;
1062 #if SomeDataReadyTrace
1063 cdebug << pthread_self() << "/" << ThreadNo() << " " << Name() << " "
1064 << anInPort->PortName() << " GATE IS CLOSED from Node "
1065 << anOutPort->NodeName() << "( " << anOutPort->PortName()
1068 if ( GraphBase::Base::_prof_debug ) {
1069 anOutPort->StringValue( *GraphBase::Base::_fdebug ) ;
1076 else if ( anOutPort->PortDone() ) {
1078 anInPort->PortState( SUPERV::ReadyState ) ;
1079 #if SomeDataReadyTrace
1080 cdebug << pthread_self() << "/" << ThreadNo() << " " << Name() << " InPort "
1081 << anInPort->PortName() << " " << anInPort->PortStatus() << " "
1082 << Automaton()->StateName( anInPort->PortState() ) << " is Done from Node "
1083 << anOutPort->NodeName() << "( " << anOutPort->PortName() << ") "
1084 << anOutPort->PortStatus() << " " ;
1086 if ( GraphBase::Base::_prof_debug ) {
1087 anOutPort->StringValue( *GraphBase::Base::_fdebug ) ;
1092 // MacroNode : give immediately the value to the corresponding graph
1093 if ( IsMacroNode() ) {
1094 cout << "SomeDataReadyAction " << GraphMacroNode() << " " << GraphMacroNode()->Name()
1095 << " coupled to " << GraphMacroNode()->CoupledNode() << endl ;
1096 GraphExecutor::DataFlow * aMacroGraph = GraphMacroNode()->CoupledNode()->GraphEditor()->Executor() ;
1097 cdebug << "SomeDataReadyAction MacroNode " << aMacroGraph->Graph()->Name() << " --> InputOfAny "
1098 << InReady << "/" << GetNodeInPortsSize() << " InPorts are Ready" << endl ;
1099 // GraphMacroNode()->MacroObject()->InputOfAny( anInPort->PortName() , *anOutPort->Value() ) ;
1100 //JR 30.03.2005 aMacroGraph->InputOfAny( anInPort->PortName() , *anOutPort->Value() ) ;
1101 aMacroGraph->InputOfAny( anInPort->PortName() , anOutPort->Value() ) ;
1105 #if SomeDataReadyTrace
1106 cdebug << pthread_self() << "/" << ThreadNo() << " Node " << Name() << "( "
1107 << anInPort->PortName() << ") " << anInPort->PortStatus()
1108 << " is NOT Done from Node "
1109 << anOutPort->NodeName() << "( " << anOutPort->PortName() << ") "
1110 << anOutPort->PortStatus() << " " << endl ;
1115 if ( InReady == GetNodeInPortsSize() ) { // All Flags != 0 :
1116 res = SendEvent( GraphExecutor::AllDataReadyEvent ); // ==> Ready to execute
1118 else { // At least one Flag == 0 :
1119 res = SendEvent( GraphExecutor::NotAllDataReadyEvent );
1122 #if SomeDataReadyTrace
1123 cdebug << pthread_self() << "/" << ThreadNo()
1124 << " <-- DataWaiting_SomeDataReadyAction " << Name() << endl;
1130 #define TraceDataReadyAction 0
1131 int GraphExecutor::InNode::DataUndef_NotAllDataReadyAction() {
1132 CreateNewThreadIf( false ) ;
1133 #if TraceDataReadyAction
1134 cdebug << pthread_self() << " for " << ThreadNo()
1135 << " DataUndef_NotAllDataReadyAction " << Name() << endl;
1140 int GraphExecutor::InNode::DataUndef_AllDataReadyAction() {
1141 #if TraceDataReadyAction
1142 cdebug << pthread_self() << "/" << ThreadNo()
1143 << " --> DataUndef_AllDataReadyAction " << Name()
1144 << " CreateNewThreadIf " << CreateNewThreadIf() << " IsLockedDataWait "
1145 << IsLockedDataWait() ;
1147 if ( IsLockedDataWait() ) {
1148 #if TraceDataReadyAction
1149 cdebug << "DataUndef_AllDataReadyAction() " << Name() << "WOULD DEAD-LOCK" << endl ;
1151 return 0 ; // ==> DataUndef_AllDataReadyAction() after UnLockDataWait()
1153 #if TraceDataReadyAction
1154 cdebug << "InNode::DataUndef_AllDataReadyAction CreateNewThread( CreateNewThreadIf() ) "
1155 << CreateNewThreadIf() << endl ;
1157 CreateNewThread( CreateNewThreadIf() ) ;
1158 if ( !CreateNewThread() ) {
1159 #if TraceDataReadyAction
1160 cdebug << "Thread " << ThreadNo() << "-->" << pthread_self() << endl ;
1162 ThreadNo( pthread_self() ) ;
1165 _OutNode->IncrCreatedThreads() ;
1167 _OutNode->PushEvent( this , GraphExecutor::AllDataReadyEvent ,
1168 GraphExecutor::DataReadyState ) ;
1170 SUPERV::ControlState aControl = ControlState() ;
1171 switch ( aControl ) {
1172 case SUPERV::VoidState : {
1173 SendEvent( GraphExecutor::ExecuteEvent ) ;
1176 case SUPERV::ToSuspendState : {
1177 SendEvent( GraphExecutor::SuspendEvent ) ;
1180 case SUPERV::ToSuspendStartState : {
1181 SendEvent( GraphExecutor::SuspendEvent ) ;
1184 case SUPERV::ToSuspendDoneState : {
1185 SendEvent( GraphExecutor::ExecuteEvent ) ;
1188 case SUPERV::ToKillState : {
1189 SendEvent( GraphExecutor::KillEvent ) ;
1192 case SUPERV::ToKillDoneState : {
1193 SendEvent( GraphExecutor::ExecuteEvent ) ;
1196 case SUPERV::ToStopState : {
1197 SendEvent( GraphExecutor::StopEvent ) ;
1201 cdebug << ThreadNo()
1202 << " GraphExecutor::InNodeThreads::DataUndef_AllDataReadyAction Error Undefined Control : "
1203 << aControl << endl ;
1207 #if TraceDataReadyAction
1208 cdebug << pthread_self() << "/" << ThreadNo()
1209 << " <-- DataUndef_AllDataReadyAction " << Name() << endl;
1214 int GraphExecutor::InNode::DataReady_SuspendAction() {
1215 cdebug << pthread_self() << "/" << ThreadNo()
1216 << "DataReady_SuspendAction --> Suspend " << Name()
1217 << " Threads " << _OutNode->Threads() << " SuspendedThreads "
1218 << _OutNode->SuspendedThreads() << endl;
1219 _OutNode->PushEvent( this , GraphExecutor::SuspendedReadyEvent ,
1220 GraphExecutor::SuspendedReadyState ) ;
1221 GraphExecutor::InNode * aReStartNode = SuspendAction() ;
1222 cdebug << pthread_self() << "/" << ThreadNo()
1223 << "DataReady_SuspendAction Resumed " << Name() << endl;
1224 if ( aReStartNode ) {
1225 _aReStartNode = NULL ;
1226 aReStartNode->SendEvent( _aReStartEvent ) ;
1229 SendEvent( GraphExecutor::ExecuteEvent ) ;
1234 int GraphExecutor::InNode::SuspendedReady_ResumeAction() {
1235 cdebug << pthread_self() << "/" << ThreadNo() << "SuspendedReady_ResumeAction "
1238 _OutNode->PushEvent( this , GraphExecutor::ResumedReadyEvent ,
1239 GraphExecutor::ResumedReadyState ) ;
1243 int GraphExecutor::InNode::DataReady_KillAction() {
1244 _OutNode->PushEvent( this , GraphExecutor::KilledReadyEvent ,
1245 GraphExecutor::KilledReadyState ) ;
1247 cdebug << pthread_self() << "/" << ThreadNo() << "DataReady_KillAction " << Name()
1248 << " will pthread_exit()" << endl;
1252 int GraphExecutor::InNode::DataReady_StopAction() {
1253 _OutNode->PushEvent( this , GraphExecutor::StoppedReadyEvent ,
1254 GraphExecutor::StoppedReadyState ) ;
1256 cdebug << pthread_self() << "/" << ThreadNo() << "DataReady_StopAction " << Name()
1257 << " will pthread_exit()" << endl;
1263 #define TraceDataReady_ExecuteAction 0
1264 int GraphExecutor::InNode::DataReady_ExecuteAction() {
1266 #if TraceDataReady_ExecuteAction
1267 cdebug << pthread_self() << "/" << ThreadNo() << " --> DataReady_ExecuteAction "
1270 _OutNode->PushEvent( this , GraphExecutor::ExecuteEvent ,
1271 GraphExecutor::ExecutingState ) ;
1277 SUPERV::GraphState PortState = SUPERV::ReadyState ;
1278 GraphExecutor::AutomatonState NewState = GraphExecutor::DataUndefState ;
1279 GraphExecutor::NodeEvent NewEvent = GraphExecutor::UndefinedEvent ;
1282 ServicesAnyData * InParametersList ;
1284 ServicesAnyData * OutParametersList ;
1286 nInParams = GetNodeInPortsSize() ;
1287 InParametersList = new ServicesAnyData[nInParams];
1288 InParametersSet( Err , nInParams , InParametersList ) ;
1290 nOutParams = GetNodeOutPortsSize() ;
1291 OutParametersList = new ServicesAnyData[nOutParams];
1292 InOutParametersSet( nOutParams , OutParametersList ) ;
1294 if ( !IsMacroNode() ) {
1296 Engines::Container_var myContainer ;
1297 Engines::Component_var myObjComponent ;
1298 if ( !IsFactoryNode() ) {
1299 #if TraceDataReady_ExecuteAction
1300 cdebug << ThreadNo() << "No Component : NO StartComponent & No Ping" << endl ;
1302 if ( IsComputingNode() ) {
1303 ObjInterface( true ) ;
1304 CORBA::Object_ptr obj ;
1305 InParametersList[0].Value >>= obj ;
1306 CORBA::Object_var objvar = CORBA::Object_var( obj ) ;
1307 myObjComponent = Engines::Component::_narrow( objvar ) ;
1312 else if ( CORBA::is_nil( Component() ) ) {
1313 // ostringstream astr ;
1314 // astr << "Graph " << _OutNode->Graph()->Name() << " Node " << Name()
1315 // << " : load of component " << ComponentName() << " in container "
1317 // _OutNode->Graph()->ObjImpl()->sendMessage( NOTIF_STEP, astr.str().c_str() ) ;
1318 Err = !_OutNode->Graph()->StartComponent( ThreadNo() , Computer() ,
1319 //JR 17.02.2005 Memory Leak my_strdup( ComponentName() ) ,
1321 myContainer , myObjComponent ) ;
1322 ObjInterface( false ) ;
1323 SetContainer( myContainer ) ;
1324 SetComponent( myObjComponent ) ;
1327 myContainer = Container() ;
1328 myObjComponent = Component() ;
1329 #if TraceDataReady_ExecuteAction
1330 cdebug << ThreadNo() << "Component known : NO StartComponent & Ping"
1334 myObjComponent->ping() ;
1337 cdebug << "ping() catched" << endl ;
1342 if ( Err || ControlState() == SUPERV::ToKillState ||
1343 ControlState() == SUPERV::ToKillDoneState ||
1344 ControlState() == SUPERV::ToStopState ) {
1345 #if TraceDataReady_ExecuteAction
1346 cdebug << ThreadNo() << "StartComponent Error or ToKillState" << endl ;
1347 // MESSAGE(pthread_self() << "Executor::InNode::DataReady_ExecuteAction of " << Name()
1348 // << " ControlState " << Automaton()->ControlStateName( ControlState() )
1349 // << " BEFORE execution ThreadNo " << ThreadNo() ) ;
1354 if ( ControlState() == SUPERV::ToSuspendState ) {
1355 #if TraceDataReady_ExecuteAction
1356 cdebug << ThreadNo() << "ToSuspendState before running." << endl ;
1357 MESSAGE(ThreadNo() << "ToSuspendState before running.") ;
1361 // ostringstream astr ;
1362 // astr << "Graph " << _OutNode->Graph()->Name() << " Run of Node " << Name() ;
1363 // _OutNode->Graph()->ObjImpl()->sendMessage( NOTIF_STEP, astr.str().c_str() ) ;
1364 #if TraceDataReady_ExecuteAction
1366 cdebug << ThreadNo() << " Run( '" << ServiceName() << "'" ;
1367 for ( i = 0 ; i < (int ) ServiceInParameter().length() ; i++ ) {
1368 cdebug << " , " << InParametersList[ i ].Name << "[kind"
1369 << InParametersList[ i ].Value.type()->kind() << "]" ;
1371 for ( i = 0 ; i < (int ) ServiceOutParameter().length() ; i++ ) {
1372 cdebug << " , " << OutParametersList[ i ].Name << "[kind"
1373 << OutParametersList[ i ].Value.type()->kind() << "]" ;
1375 if ( IsOneOfInLineNodes() ) {
1376 cdebug << " , PyFuncName '" << InLineNode()->PyFuncName() << "' PyRunMethod "
1377 << InLineNode()->PyRunMethod() << " length "
1378 << (*InLineNode()->PythonFunction()).length() ;
1380 cdebug << ")" << endl ;
1383 if ( IsOneOfInLineNodes() ) {
1384 bool StsPyDynInvoke = true;
1385 _OutNode->PyThreadLock() ;
1388 // if ( IsInLineNode() && (*InLineNode()->PythonFunction()).length() &&
1389 bool ItIsaLoop = false ;
1390 bool CopyInOut = false ;
1391 if ( IsInLineNode() && /*InLineNode()->PyRunMethod() &&*/
1392 strlen( InLineNode()->PyFuncName() ) ) {
1393 #if TraceDataReady_ExecuteAction
1394 cdebug << ThreadNo() << " !ObjInterface " << Name() << " PyFuncName '"
1395 << InLineNode()->PyFuncName()
1396 << "' IsInLineNode PyDynInvoke" << endl ;
1398 StsPyDynInvoke = PyDynInvoke( InLineNode()->PyRunMethod() ,
1399 InLineNode()->PyFuncName() ,
1400 &InParametersList[0] , ServiceInParameter().length() ,
1401 &OutParametersList[0] , ServiceOutParameter().length() ) ;
1402 if ( !StsPyDynInvoke ) {
1403 RemovePyDynInvoke( InLineNode()->PyFuncName() ) ;
1405 else if ( IsLoopNode() ) {
1407 bool CopyOutIn = false ;
1408 // Switch between Init() and Next()
1409 // if InLoop port is true and does not come from EndLoop ==> execute Init
1410 // if InLoop port is false or come from EndLoop ==> execute Next
1411 // GraphExecutor::InNode * anEndLoopNode = (GraphExecutor::InNode * ) CoupledNode()->GetInNode() ;
1412 // if ( GetNodeInLoop()->GetOutPort()->BoolValue() &&
1414 if ( strlen( InLineNode()->PyFuncName() ) ) { // InLoop Port = true ==> Init()
1415 #if TraceDataReady_ExecuteAction
1416 cdebug << ThreadNo() << " !ObjInterface " << Name()
1417 << " IsLoopNode PyDynInvoke '" << InLineNode()->PyFuncName()
1418 << "' InitLoop " << LoopNode()->PyRunMethod() << endl ;
1420 StsPyDynInvoke = PyDynInvoke( InLineNode()->PyRunMethod() ,
1421 InLineNode()->PyFuncName() ,
1422 &InParametersList[1] , ServiceInParameter().length() ,
1423 &OutParametersList[1] , ServiceOutParameter().length() ) ;
1424 if ( !StsPyDynInvoke ) {
1425 RemovePyDynInvoke( InLineNode()->PyFuncName() ) ;
1430 #if TraceDataReady_ExecuteAction
1431 cdebug << ThreadNo() << " !ObjInterface " << Name()
1432 << " IsLoopNode NO PyDynInvoke Void PyFuncName InitLoop" << endl ;
1435 #if TraceDataReady_ExecuteAction
1436 cdebug << ThreadNo() << " !ObjInterface " << Name()
1437 << " IsLoopNode _InitLoop Reset after Init() Python Function" << endl ;
1441 else if ( LoopNode()->PyNextMethod() &&
1442 strlen( LoopNode()->PyNextName() ) ){ // InLoop Port = false ==> Next()
1443 #if TraceDataReady_ExecuteAction
1444 cdebug << ThreadNo() << " !ObjInterface " << Name()
1445 << " IsLoopNode PyDynInvoke '" << LoopNode()->PyNextName()
1446 << "' " << LoopNode()->PyNextMethod() << endl ;
1448 StsPyDynInvoke = PyDynInvoke( LoopNode()->PyNextMethod() ,
1449 LoopNode()->PyNextName() ,
1450 &InParametersList[1] , ServiceInParameter().length() ,
1451 &OutParametersList[1] , ServiceOutParameter().length() ) ;
1452 if ( !StsPyDynInvoke ) {
1453 RemovePyDynInvoke( LoopNode()->PyNextName() ) ;
1458 #if TraceDataReady_ExecuteAction
1459 cdebug << ThreadNo() << " !ObjInterface " << Name()
1460 << " IsLoopNode NO PyDynInvoke Void PyFuncName NextLoop" << endl ;
1463 if ( StsPyDynInvoke ) {
1465 #if TraceDataReady_ExecuteAction
1466 cdebug << ThreadNo() << " !ObjInterface " << Name()
1467 << " IsLoopNode PyDynInvoke '" << LoopNode()->PyMoreName()
1468 << "' Copy of " << ServiceInParameter().length()
1469 << " OutParameters" << endl ;
1472 // Start at 1 : Do not copy InLoop ( InLoop == true <==> Init ; InLoop == false <==> Next )
1473 for ( i = 1 ; i <= (int ) ServiceInParameter().length() ; i++ ) {
1474 InParametersList[i].Value = OutParametersList[i].Value ;
1475 InParametersList[i].Name = OutParametersList[i].Name ;
1476 #if TraceDataReady_ExecuteAction
1477 switch ( InParametersList[i].Value.type()->kind() ) {
1478 case CORBA::tk_string :
1480 InParametersList[i].Value >>= t ;
1481 cdebug << "ArgOut->In" << i << " : "
1482 << InParametersList[i].Name.c_str()
1483 << " Value(string) " << t << endl ;
1485 case CORBA::tk_boolean:
1487 InParametersList[i].Value >>= (CORBA::Any::to_boolean ) b;
1488 cdebug << "ArgOut->In" << i << " : "
1489 << InParametersList[i].Name.c_str()
1490 << " Value(boolean) " << b << endl ;
1492 case CORBA::tk_char:
1494 InParametersList[i].Value >>= (CORBA::Any::to_char ) c;
1495 cdebug << "ArgOut->In" << i << " : "
1496 << InParametersList[i].Name.c_str()
1497 << " Value(char) " << c << endl ;
1499 case CORBA::tk_short:
1501 InParametersList[i].Value >>= s;
1502 cdebug << "ArgOut->In" << i << " : "
1503 << InParametersList[i].Name.c_str()
1504 << " Value(short) " << s << endl ;
1506 case CORBA::tk_long :
1508 InParametersList[i].Value >>= l;
1509 cdebug << "ArgOut->In" << i << " : "
1510 << InParametersList[i].Name.c_str()
1511 << " Value(long) " << l << endl ;
1513 case CORBA::tk_float :
1515 InParametersList[i].Value >>= f;
1516 cdebug << "ArgOut->In" << i << " : "
1517 << InParametersList[i].Name.c_str()
1518 << " Value(float) " << f << endl ;
1520 case CORBA::tk_double :
1522 InParametersList[i].Value >>= d;
1523 cdebug << "ArgOut->In" << i << " : "
1524 << InParametersList[i].Name.c_str()
1525 << " Value(double) " << d << endl ;
1527 case CORBA::tk_objref :
1528 CORBA::Object_ptr obj ;
1531 InParametersList[i].Value >>= obj ;
1532 retstr = ObjectToString( obj );
1533 cdebug << "ArgOut->In" << i << " : "
1534 << InParametersList[i].Name.c_str()
1535 << " Value(object reference) " << retstr << endl ;
1538 cdebug << "ArgOut->In" << i << " : "
1539 << InParametersList[i].Name.c_str()
1540 << " Value(object reference) Catched ERROR" << endl ;
1544 cdebug << "ArgOut->In" << i << " : "
1545 << InParametersList[i].Name.c_str()
1546 << " Value(other) ERROR" << endl ;
1551 if ( LoopNode()->PyMoreMethod() && strlen( LoopNode()->PyMoreName() ) ) {
1552 #if TraceDataReady_ExecuteAction
1553 cdebug << ThreadNo() << " !ObjInterface " << Name()
1554 << " IsLoopNode PyDynInvoke '" << LoopNode()->PyMoreName()
1555 << "' " << LoopNode()->PyMoreMethod() << endl ;
1557 StsPyDynInvoke = PyDynInvoke( LoopNode()->PyMoreMethod() ,
1558 LoopNode()->PyMoreName() ,
1559 &InParametersList[1] , ServiceInParameter().length() ,
1560 &OutParametersList[0] , ServiceOutParameter().length()+1 ) ;
1561 if ( !StsPyDynInvoke ) {
1562 RemovePyDynInvoke( LoopNode()->PyMoreName() ) ;
1566 #if TraceDataReady_ExecuteAction
1567 cdebug << ThreadNo() << " !ObjInterface " << Name()
1568 << " IsLoopNode PyDynInvoke '" << LoopNode()->PyMoreName()
1569 << "' No MoreMethod" << endl ;
1576 cdebug << ThreadNo() << " InLineNode " << Name() << " "
1577 << InLineNode()->PyFuncName() << "/" << LoopNode()->PyNextName()
1578 << " Python Dynamic Call Error"
1582 else if ( IsSwitchNode() && /*InLineNode()->PyRunMethod() &&*/
1583 strlen( InLineNode()->PyFuncName() ) ) {
1584 #if TraceDataReady_ExecuteAction
1585 cdebug << ThreadNo() << " !ObjInterface " << Name() << " PyFuncName '"
1586 << InLineNode()->PyFuncName()
1587 << "' IsSwitchNode PyDynInvoke" << endl ;
1589 StsPyDynInvoke = PyDynInvoke( InLineNode()->PyRunMethod() ,
1590 InLineNode()->PyFuncName() ,
1591 &InParametersList[0] , ServiceInParameter().length() ,
1592 &OutParametersList[0] , ServiceOutParameter().length() ) ;
1593 if ( !StsPyDynInvoke ) {
1594 RemovePyDynInvoke( InLineNode()->PyFuncName() ) ;
1597 // else if ( IsGOTONode() && (*GOTONode()->PythonFunction()).length() &&
1598 else if ( IsGOTONode() && /*InLineNode()->PyRunMethod() &&*/
1599 strlen( InLineNode()->PyFuncName() ) ) {
1600 #if TraceDataReady_ExecuteAction
1601 cdebug << ThreadNo() << " !ObjInterface " << Name() << " PyFuncName '"
1602 << InLineNode()->PyFuncName()
1603 << "' IsGOTONode PyDynInvoke" << endl ;
1605 StsPyDynInvoke = PyDynInvoke( InLineNode()->PyRunMethod() ,
1606 InLineNode()->PyFuncName() ,
1607 &InParametersList[0] , ServiceInParameter().length() ,
1608 &OutParametersList[0] , ServiceOutParameter().length() ) ;
1609 if ( !StsPyDynInvoke ) {
1610 RemovePyDynInvoke( GOTONode()->PyFuncName() ) ;
1613 // else if ( IsEndSwitchNode() && (*InLineNode()->PythonFunction()).length() &&
1614 else if ( ( IsEndSwitchNode() ) &&
1615 InLineNode()->PyRunMethod() && strlen( InLineNode()->PyFuncName() ) ) {
1616 #if TraceDataReady_ExecuteAction
1617 cdebug << ThreadNo() << " !ObjInterface " << Name() << " PyFuncName '"
1618 << InLineNode()->PyFuncName()
1619 << "' IsSwitchNode PyDynInvoke" << endl ;
1621 StsPyDynInvoke = PyDynInvoke( InLineNode()->PyRunMethod() ,
1622 InLineNode()->PyFuncName() ,
1623 &InParametersList[0] , ServiceInParameter().length() ,
1624 &OutParametersList[0] , ServiceOutParameter().length() ) ;
1625 if ( !StsPyDynInvoke ) {
1626 RemovePyDynInvoke( InLineNode()->PyFuncName() ) ;
1629 else if ( ( IsEndLoopNode() ) &&
1630 InLineNode()->PyRunMethod() && strlen( InLineNode()->PyFuncName() ) ) {
1631 #if TraceDataReady_ExecuteAction
1632 cdebug << ThreadNo() << " !ObjInterface " << Name() << " PyFuncName '"
1633 << InLineNode()->PyFuncName()
1634 << "' IsSwitchNode PyDynInvoke" << endl ;
1636 StsPyDynInvoke = PyDynInvoke( InLineNode()->PyRunMethod() ,
1637 InLineNode()->PyFuncName() ,
1638 &InParametersList[0] , ServiceInParameter().length() + 1 ,
1639 &OutParametersList[0] , ServiceOutParameter().length() + 1 ) ;
1640 if ( !StsPyDynInvoke ) {
1641 RemovePyDynInvoke( InLineNode()->PyFuncName() ) ;
1645 // else if ( (*InLineNode()->PythonFunction()).length() == 0 ||
1646 if ( (!ItIsaLoop && ( InLineNode()->PyRunMethod() == NULL ||
1647 strlen( InLineNode()->PyFuncName() ) == 0 ) ) || CopyInOut ) {
1648 // This is a void Python Function : without code (No PyFuncName)
1649 #if TraceDataReady_ExecuteAction
1650 cdebug << ThreadNo() << " !ObjInterface " << Name()
1651 << " Copy of " << ServiceInParameter().length()
1652 << " OutParameters" << endl ;
1657 if ( IsLoopNode() || IsEndLoopNode() ) {
1659 argin0 = 1 ; // after DoLoop
1660 if ( IsLoopNode() ) { // More() is void
1661 // OutParametersList[0].Value = InParametersList[0].Value ; // DoLoop
1662 #if TraceDataReady_ExecuteAction
1663 cdebug << Name() << " Not Beginning of loop and non void EndLoop : DoLoop = EndLoop(DoLoop)"
1666 GraphExecutor::InNode * anEndLoopNode = (GraphExecutor::InNode * ) CoupledNode()->GetInNode() ;
1667 //JR 30.03.2005 OutParametersList[0].Value = *anEndLoopNode->GetNodeOutLoop()->Value() ; // DoLoop = EndLoop(DoLoop)
1668 OutParametersList[0].Value = anEndLoopNode->GetNodeOutLoop()->Value() ; // DoLoop = EndLoop(DoLoop)
1671 //PAL8072 ==> PAL8512
1672 //JR 24.03.2005 : Debug : void InLine Python function : check of the number of Input Ports
1673 // equals the number of Output Ports was missing
1674 if ( ServiceInParameter().length() != ServiceOutParameter().length() ) {
1675 StsPyDynInvoke = false ;
1678 for ( i = 0 ; i < (int ) ServiceInParameter().length() ; i++ ) {
1679 OutParametersList[argout0 + i].Value = InParametersList[argin0 + i].Value ;
1680 #if TraceDataReady_ExecuteAction
1681 switch ( InParametersList[argin0 + i].Value.type()->kind() ) {
1682 case CORBA::tk_string :
1683 cdebug << "ArgOut->In" << argin0 + i << " : "
1684 << InParametersList[argin0 + i].Name.c_str()
1685 << " Value(string) "
1686 << OutParametersList[argout0 + i].Name.c_str() << endl ;
1688 case CORBA::tk_boolean:
1689 cdebug << "ArgOut->In" << argin0 + i << " : "
1690 << InParametersList[argin0 + i].Name.c_str()
1691 << " Value(boolean) "
1692 << OutParametersList[argout0 + i].Name.c_str() << endl ;
1694 case CORBA::tk_char:
1695 cdebug << "ArgOut->In" << argin0 + i << " : "
1696 << InParametersList[argin0 + i].Name.c_str()
1698 << OutParametersList[argout0 + i].Name.c_str() << endl ;
1700 case CORBA::tk_short:
1701 cdebug << "ArgOut->In" << argin0 + i << " : "
1702 << InParametersList[argin0 + i].Name.c_str()
1704 << OutParametersList[argout0 + i].Name.c_str() << endl ;
1706 case CORBA::tk_long :
1707 cdebug << "ArgOut->In" << argin0 + i << " : "
1708 << InParametersList[argin0 + i].Name.c_str()
1710 << OutParametersList[argout0 + i ].Name.c_str() << endl ;
1712 case CORBA::tk_double :
1713 cdebug << "ArgOut->In" << argin0 + i << " : "
1714 << InParametersList[argin0 + i].Name.c_str()
1715 << " Value(double) "
1716 << OutParametersList[argout0 + i].Name.c_str() << endl ;
1718 case CORBA::tk_objref :
1719 cdebug << "ArgOut->In" << argin0 + i << " : "
1720 << InParametersList[argin0 + i].Name.c_str()
1721 << " Value(object reference) "
1722 << OutParametersList[argout0 + i].Name.c_str() << endl ;
1725 cdebug << "ArgOut->In" << argin0 + i << " : "
1726 << InParametersList[argin0 + i].Name.c_str()
1727 << " Value(other) ERROR "
1728 << OutParametersList[argout0 + i].Name.c_str() << endl ;
1734 if ( !StsPyDynInvoke ) {
1736 cdebug << ThreadNo() << " InLineNode " << Name()
1737 << " Python Dynamic Call Error"
1743 cdebug << ThreadNo() << " InLineNode " << Name()
1744 << " Python Dynamic Call Exception catched ERROR"
1748 _OutNode->PyThreadUnLock() ;
1753 #if TraceDataReady_ExecuteAction
1754 cdebug << "DynInvoke -> Names " << _OutNode->Graph()->Name() << " " << Name() << endl ;
1756 DynInvoke( myObjComponent, "Names" ,
1757 _OutNode->Graph()->Name() , Name() ) ;
1760 cdebug << "DynInvoke Names catched ERROR" << endl ;
1762 // for DataStreamNodes : call of SetProperties ===> environment variables in the component/container
1763 if ( ComputingNode()->HasDataStream() ) {
1765 #if TraceDataReady_ExecuteAction
1766 cdebug << "DynInvoke -> SetProperties " << _OutNode->Graph()->Name() << " " << Name() << endl ;
1768 Engines::FieldsDict_var dict = new Engines::FieldsDict;
1770 dict[ 0 ].key = CORBA::string_dup( "CAL_MACHINE");
1771 // myContainer->getHostName() ne renvoit pas le nom complet (avec domaine).
1772 // dict[ 0 ].value <<= myContainer->getHostName() ;
1773 char FullyQualifiedDomainName[256]="";
1774 gethostname(FullyQualifiedDomainName,255);
1775 dict[ 0 ].value <<= FullyQualifiedDomainName ;
1776 dict[ 1 ].key = CORBA::string_dup( "CAL_REPERTOIRE");
1777 dict[ 1 ].value <<= "/tmp" ;
1778 dict[ 2 ].key = CORBA::string_dup( "CAL_COUPLAGE");
1779 stringstream ofst1 ;
1780 ofst1 << ComputingNode()->SubStreamGraph() ;
1781 string cpl = string( "/tmp/" ) + string( _OutNode->Graph()->Name() ) + string( "_" ) +
1782 ofst1.str() + string( ".cpl" );
1783 dict[ 2 ].value <<= cpl.c_str() ;
1784 dict[ 3 ].key = CORBA::string_dup( "SALOME_INSTANCE_NAME");
1785 string uname = Name();
1787 dict[ 3 ].value <<= uname.c_str() ;
1789 myObjComponent->setProperties( dict ) ;
1792 cdebug << "DynInvoke setProperties catched ERROR" << endl ;
1796 if ( !Err && IsComputingNode() ) {
1797 #if TraceDataReady_ExecuteAction
1798 cdebug << ThreadNo() << " !ObjInterface " << Name()
1799 << " IsComputingNode DynInvoke" << endl ;
1800 cdebug << ServiceInParameter().length()-1 << " input parameters and "
1801 << ServiceOutParameter().length() << " output parameters" << endl ;
1803 IsLoading( false ) ;
1804 DynInvoke( myObjComponent,
1806 &InParametersList[1] , ServiceInParameter().length()-1 ,
1807 &OutParametersList[0] , ServiceOutParameter().length() ) ;
1809 else if ( !Err && IsFactoryNode() ) {
1810 #if TraceDataReady_ExecuteAction
1811 cdebug << ThreadNo() << " !ObjInterface " << Name()
1812 << " IsFactoryNode DynInvoke" << endl ;
1813 cdebug << ServiceInParameter().length() << " input parameters and "
1814 << ServiceOutParameter().length() << " output parameters" << endl ;
1816 IsLoading( false ) ;
1817 DynInvoke( myObjComponent,
1819 &InParametersList[0] , ServiceInParameter().length() ,
1820 &OutParametersList[0] , ServiceOutParameter().length() ) ;
1822 // cdebug << ThreadNo() << " Component::CpuUsed " << Name() << " "
1823 // << myObjComponent->CpuUsed_impl() << endl ;
1827 cdebug << ThreadNo() << " !ObjInterface " << Name()
1828 << " Node(Component) Dynamic Call Exception catched ERROR"
1830 //Reset of _ThreadId in the Container ...
1832 myObjComponent->Kill_impl() ;
1842 // ostringstream astr ;
1843 // astr << "Graph " << _OutNode->Graph()->Name() << " Node " << Name() << " is done : "
1844 // << Automaton()->StateName( State() ) ;
1845 // _OutNode->Graph()->ObjImpl()->sendMessage( NOTIF_STEP, astr.str().c_str() ) ;
1849 // if exception or something else - IsLoading( false ) may not NOT has been called
1853 if ( ControlState() == SUPERV::ToKillState ||
1854 ControlState() == SUPERV::ToKillDoneState ||
1855 ControlState() == SUPERV::ToStopState ) {
1856 PortState = SUPERV::ErrorState ;
1857 NewState = GraphExecutor::KilledState ;
1858 NewEvent = GraphExecutor::KillEvent ;
1861 PortState = SUPERV::ErrorState ;
1862 NewState = GraphExecutor::ErroredState ;
1863 NewEvent = GraphExecutor::ErrorEvent ;
1867 PortState = SUPERV::ReadyState ;
1868 NewState = GraphExecutor::DataReadyState ;
1869 NewEvent = GraphExecutor::SuccessEvent ;
1872 if ( !IsMacroNode() ) {
1873 bool ErrOut = OutParametersSet( Err , PortState , nOutParams , OutParametersList ) ;
1875 NewEvent = GraphExecutor::ErrorEvent ;
1877 delete [] InParametersList ;
1878 delete [] OutParametersList ;
1881 if ( !IsMacroNode() ) {
1882 SendEvent( NewEvent ) ;
1885 GraphExecutor::DataFlow * aMacroGraph = GraphMacroNode()->CoupledNode()->GraphEditor()->Executor() ;
1886 #if TraceDataReady_ExecuteAction
1887 cdebug << ThreadNo() << " DataReady_ExecuteAction " << aMacroGraph << " "
1888 << aMacroGraph->Graph()->Name() << " ->DoneWait()"
1889 << " State " << aMacroGraph->State() << endl;
1891 aMacroGraph->DoneWait() ;
1892 #if TraceDataReady_ExecuteAction
1893 cdebug << ThreadNo() << " DataReady_ExecuteAction " << Name() << " State " << aMacroGraph->State() << endl;
1895 if ( aMacroGraph->State() == SUPERV::DoneState ) {
1896 PortState = SUPERV::ReadyState ;
1897 NewState = GraphExecutor::DataReadyState ;
1898 NewEvent = GraphExecutor::SuccessEvent ;
1902 if ( ControlState() == SUPERV::ToKillState ||
1903 ControlState() == SUPERV::ToKillDoneState ||
1904 ControlState() == SUPERV::ToStopState ) {
1905 PortState = SUPERV::ErrorState ;
1906 NewState = GraphExecutor::KilledState ;
1907 NewEvent = GraphExecutor::KillEvent ;
1910 PortState = SUPERV::ErrorState ;
1911 NewState = GraphExecutor::ErroredState ;
1912 NewEvent = GraphExecutor::ErrorEvent ;
1915 bool ErrOut = OutParametersSet( Err , PortState , nOutParams , OutParametersList ) ;
1917 NewEvent = GraphExecutor::ErrorEvent ;
1919 delete [] InParametersList ;
1920 delete [] OutParametersList ;
1921 SendEvent( NewEvent ) ;
1924 #if TraceDataReady_ExecuteAction
1925 cdebug << ThreadNo() << " <-- DataReady_ExecuteAction " << Name() << endl;
1930 int GraphExecutor::InNode::Executing_SuspendAction() {
1931 _OutNode->PushEvent( this , GraphExecutor::SuspendedExecutingEvent ,
1932 GraphExecutor::SuspendedExecutingState ) ;
1933 cdebug << ThreadNo() << " Executing_SuspendAction " << Name() << endl;
1937 int GraphExecutor::InNode::SuspendedExecuting_ResumeAction() {
1938 cdebug << ThreadNo() << " SuspendedExecuting_ResumeAction " << Name() << endl;
1939 GraphExecutor::AutomatonState next_state ;
1940 next_state = Automaton()->NextState( State() , GraphExecutor::ExecutingEvent ) ;
1941 _OutNode->NewThread() ; // Only for Threads count
1942 _OutNode->PushEvent( this , GraphExecutor::ResumedExecutingEvent ,
1944 State( next_state ) ;
1948 int GraphExecutor::InNode::Executing_KillAction() {
1949 cdebug << ThreadNo() << " Executing_KillAction " << Name() << " Thread " << ThreadNo()<< endl;
1951 if ( pthread_self() == ThreadNo() ) {
1952 cdebug << "Executing_KillAction would pthread_canceled itself" << endl ;
1954 _OutNode->PushEvent( this , GraphExecutor::KilledExecutingEvent ,
1955 GraphExecutor::KilledExecutingState ) ;
1958 else if ( pthread_cancel( ThreadNo() ) ) {
1959 perror("Executing_KillAction pthread_cancel error") ;
1962 cdebug << pthread_self() << " Executing_KillAction : ThreadId " << ThreadNo()
1963 << " pthread_canceled" << endl ;
1965 _OutNode->ExitThread( ThreadNo() ) ;
1966 _OutNode->PushEvent( this , GraphExecutor::KilledExecutingEvent ,
1967 GraphExecutor::KilledExecutingState ) ;
1972 int GraphExecutor::InNode::Executing_StopAction() {
1973 cdebug << ThreadNo() << " Executing_StopAction " << Name() << " Thread " << ThreadNo() << endl;
1975 if ( pthread_cancel( ThreadNo() ) ) {
1976 perror("Executing_KillAction pthread_cancel error") ;
1979 cdebug << pthread_self() << " Executing_KillAction : ThreadId " << ThreadNo()
1980 << " pthread_canceled" << endl ;
1982 _OutNode->ExitThread( ThreadNo() ) ;
1983 _OutNode->PushEvent( this , GraphExecutor::StoppedExecutingEvent ,
1984 GraphExecutor::StoppedExecutingState ) ;
1989 int GraphExecutor::InNode::Executing_SuccessAction() {
1990 // cdebug << ThreadNo() << " --> Executing_SuccessAction " << Name() << endl;
1991 _OutNode->PushEvent( this , GraphExecutor::SuccessedExecutingEvent ,
1992 GraphExecutor::SuccessedState ) ;
1993 // MESSAGE(pthread_self() << "Executor::InNode::Executing_SuccessAction of " << Name()
1994 // << " ControlState " << Automaton()->ControlStateName( ControlState() )
1995 // << " AFTER execution ThreadNo " << ThreadNo() ) ;
1996 SUPERV::ControlState aControl = ControlState() ;
1997 switch ( aControl ) {
1998 case SUPERV::VoidState : {
1999 SendEvent( SuccessEvent ) ;
2002 case SUPERV::ToSuspendState : {
2003 SendEvent( SuccessEvent ) ;
2006 case SUPERV::ToSuspendDoneState : {
2007 SendEvent( GraphExecutor::SuspendEvent ) ;
2010 case SUPERV::ToKillState : {
2011 SendEvent( GraphExecutor::KillEvent ) ;
2014 case SUPERV::ToKillDoneState : {
2015 SendEvent( GraphExecutor::KillEvent ) ;
2018 case SUPERV::ToStopState : {
2019 SendEvent( GraphExecutor::StopEvent ) ;
2023 cdebug << ThreadNo()
2024 << " GraphExecutor::InNodeThreads::Executing_SuccessAction Error Undefined Control : "
2025 << aControl << endl ;
2029 // cdebug << ThreadNo() << " <-- Executing_SuccessAction " << Name() << endl;
2033 int GraphExecutor::InNode::Executing_ErrorAction() {
2034 cdebug << ThreadNo() << " --> Executing_ErrorAction " << Name() << endl;
2035 _OutNode->PushEvent( this , GraphExecutor::ErroredExecutingEvent ,
2036 GraphExecutor::ErroredState ) ;
2038 SUPERV::ControlState aControl = ControlState() ;
2039 switch ( aControl ) {
2040 case SUPERV::VoidState : {
2041 SendEvent( ErrorEvent ) ;
2044 case SUPERV::ToSuspendState : {
2045 SendEvent( ErrorEvent ) ;
2048 case SUPERV::ToSuspendDoneState : {
2049 SendEvent( GraphExecutor::SuspendEvent ) ;
2052 case SUPERV::ToKillState : {
2053 SendEvent( GraphExecutor::KillEvent ) ;
2056 case SUPERV::ToKillDoneState : {
2057 SendEvent( GraphExecutor::KillEvent ) ;
2060 case SUPERV::ToStopState : {
2061 SendEvent( GraphExecutor::StopEvent ) ;
2065 cdebug << ThreadNo()
2066 << " GraphExecutor::InNodeThreads::Executing_ErrorAction Error Undefined Control : "
2067 << aControl << endl ;
2071 cdebug << ThreadNo() << " <-- Executing_ErrorAction " << Name() << endl;
2075 // Set SUPERV::WaitingState to all InPorts
2076 void GraphExecutor::InNode::SetWaitingStates(GraphExecutor::InNode * EndNode ) {
2079 bool docdebug = false ;
2080 State( GraphExecutor::DataWaitingState ) ;
2081 // cdebug << "SetWaitingStates " << Name() << " " << Automaton()->StateName( State() ) << endl ;
2082 for ( i = 0 ; i < GetNodeInPortsSize() ; i++ ) {
2083 GraphBase::InPort * anInPort = GetChangeNodeInPort( i ) ;
2084 // cdebug << "SetWaitingStates InPort " << Name() << "( " << anInPort->PortName() << " ) "
2085 // << anInPort->PortStatus() << " " << anInPort->State() << endl ;
2087 // JR Debug 07.01.2005 : Close the Gates instead of open !!!
2088 if ( anInPort->IsGate() ) { // Loop : Close the doors
2089 GraphBase::OutPort * anOutPort = anInPort->GetOutPort() ;
2091 //JR 21.02.2005 Debug Memory leak : CORBA::Any * anAny = new CORBA::Any() ;
2092 CORBA::Any anAny = CORBA::Any() ;
2093 // *anAny <<= (long ) 1 ;
2094 //JR 21.02.2005 Debug Memory leak : *anAny <<= (long ) 0 ;
2095 anAny <<= (long ) 0 ;
2096 anOutPort->Value( anAny ) ;
2097 anInPort->PortState( SUPERV::WaitingState ) ;
2101 else if ( anInPort->PortState() != SUPERV::WaitingState &&
2102 !anInPort->IsDataConnected() ) {
2104 // cdebug << ThreadNo()
2105 // << " --> GraphExecutor::InNodeThreads::SetWaitingStates " << Name() << endl;
2108 if ( !anInPort->IsDataStream() ) {
2109 anInPort->PortState( SUPERV::WaitingState ) ;
2112 // cdebug << " --> " << Name() << "( " << anInPort->PortName() << " ) "
2113 // << anInPort->PortStatus() << " " << anInPort->State() << endl ;
2115 for ( i = 0 ; i < GetNodeOutPortsSize() ; i++ ) {
2116 GraphBase::OutPort * anOutPort = GetChangeNodeOutPort( i ) ;
2118 //JR 07.03.2005 Debug : Reset of Done flag in OutPorts !... :
2119 if ( !anOutPort->IsDataStream() ) {
2120 anOutPort->PortDone( false ) ;
2122 for ( j = 0 ; j < anOutPort->InPortsSize() ; j++ ) {
2123 if ( !( IsGOTONode() && anOutPort->IsGate() ) &&
2124 !( IsEndLoopNode() && ( anOutPort->IsGate() || anOutPort->IsLoop() ) ) &&
2125 !anOutPort->IsDataStream() &&
2126 !anOutPort->ChangeInPorts( j )->IsDataStream() &&
2127 !anOutPort->ChangeInPorts( j )->IsExternConnected() ) {
2128 // cdebug << ThreadNo()
2129 // << " InNodeThreads::SetWaitingStates OutPort "
2130 // << Name() << "/" << anOutPort->ChangeInPorts( j )->NodeName() << "( "
2131 // << anOutPort->PortName() << " " << anOutPort->PortStatus() << " ) --> InPort "
2132 // << anOutPort->ChangeInPorts( j )->NodeName() << "( "
2133 // << anOutPort->ChangeInPorts( j )->PortName() << " "
2134 // << anOutPort->ChangeInPorts( j )->PortStatus() << " )" << endl;
2135 GraphBase::ComputingNode * aToNode ;
2136 aToNode = _OutNode->Graph()->GetChangeGraphNode( anOutPort->ChangeInPorts( j )->NodeName() ) ;
2137 // JR 12.01.2005 Debug : the OutPort linked to the InPort of a EndSwitchNode was changed so final
2138 // values of InPorts of EndSwitchNode may be wrong
2139 if ( !aToNode->IsEndSwitchNode() &&
2140 strcmp( anOutPort->ChangeInPorts( j )->GetOutPort()->NodeName() , Name() ) ) {
2141 // After EndLoopNode or GOTONode the Input Ports of LoopNode or LabelNode have their values from
2142 // EndLoopNode or GOTONode. But if there is several nested loops we should re-establish.
2143 // cdebug << ThreadNo()
2144 // << " InNodeThreads::SetWaitingStates Node " << Name() << " "
2145 // << anOutPort->ChangeInPorts( j )->GetOutPort()->NodeName() << "( "
2146 // << anOutPort->ChangeInPorts( j )->GetOutPort()->PortName() << " ) != "
2147 // << Name() << " : Restored to " << anOutPort->NodeName() << "( "
2148 // << anOutPort->PortName() << " )" << endl ;
2149 anOutPort->ChangeInPorts( j )->ChangeOutPort( anOutPort ) ;
2151 GraphExecutor::InNode * aNode = (GraphExecutor::InNode * ) aToNode->GetInNode() ;
2152 if ( aNode != EndNode ) {
2153 aNode->SetWaitingStates( EndNode ) ;
2160 #define SuccessActionTrace 0
2161 int GraphExecutor::InNode::Successed_SuccessAction() {
2162 cdebug << ThreadNo() << " --> Successed_SuccessAction " << Name() << endl;
2164 int linkednodesnumber = LinkedNodesSize() ;
2165 GraphExecutor::InNode *firstzeroNode = NULL ;
2166 GraphExecutor::InNode *firsttoNode = NULL ;
2167 GraphExecutor::InNode *toNode ;
2170 list<GraphExecutor::InNode *> SomeDataNodes ;
2174 if ( IsMacroNode() ) {
2175 #if SuccessActionTrace
2176 cdebug << pthread_self() << "/" << ThreadNo() << " Successed_SuccessAction " << Name() << " LinkedNodes->SomeDataReady already done"
2182 //JR 09.02.2005 : That complicated part of the code manages LOOPS and GOTO
2183 if ( IsGOTONode() ||
2184 ( IsEndLoopNode() && GetNodeInLoop()->GetOutPort()->BoolValue() ) ) {
2185 #if SuccessActionTrace
2186 cdebug << pthread_self() << "/" << ThreadNo() << " Successed_SuccessAction " << Name()
2187 << " SetWaitingStates " << endl ;
2189 const GraphBase::OutPort * aGateOutPort ;
2190 if ( IsGOTONode() ) {
2191 aGateOutPort = GetNodeOutGate() ;
2194 aGateOutPort = GetNodeOutLoop() ;
2196 if ( aGateOutPort->InPortsSize() != 1 ) {
2197 cdebug << pthread_self() << "/" << ThreadNo() << " Successed_SuccessAction aGateOutPort->InPortsSize "
2198 << aGateOutPort->InPortsSize() << " != 1 ERROR " << Name() << endl ;
2200 GraphExecutor::InNode * aLabelNode = NULL ;
2201 for ( i = 0 ; i < aGateOutPort->InPortsSize() ; i++ ) {
2202 const GraphBase::InPort * anInPort = aGateOutPort->InPorts( i ) ;
2203 aLabelNode = (GraphExecutor::InNode *) _OutNode->Graph()->GetChangeGraphNode( anInPort->NodeName() )->GetInNode() ;
2204 #if SuccessActionTrace
2205 cdebug << pthread_self() << "/" << ThreadNo() << " Successed_SuccessAction " << Name() << " will Loop to HeadNode "
2206 << aLabelNode->Name() << " from port " << anInPort->PortName() << endl ;
2207 aLabelNode->SetWaitingStates( this ) ;
2209 // JR 07.01.2005 Debug : Open the Gate of the coupledNode closed by SetWaitingStates
2210 GraphBase::OutPort * anOutPort = aLabelNode->GetChangeNodeInGate()->GetOutPort() ;
2212 //JR 21.02.2005 Debug Memory leak : CORBA::Any * anAny = new CORBA::Any() ;
2213 CORBA::Any anAny = CORBA::Any() ;
2214 //JR 21.02.2005 Debug Memory leak : *anAny <<= (long ) 1 ;
2215 anAny <<= (long ) 1 ;
2216 anOutPort->Value( anAny ) ;
2217 aLabelNode->GetChangeNodeInGate()->PortState( SUPERV::ReadyState ) ;
2220 for ( j = 0 ; j < aLabelNode->GetNodeInPortsSize() ; j++ ) {
2221 const GraphBase::InPort * anInPort = aLabelNode->GetNodeInPort( j ) ;
2222 if ( anInPort->GetOutPort() ) {
2223 #if SuccessActionTrace
2224 cdebug << aLabelNode->Name() << "(" << anInPort->PortName() << ") value : "
2225 << anInPort->GetOutPort()->NodeName() << "(" << anInPort->GetOutPort()->PortName() << ")"
2230 //PAL8176 ==> PAL8516
2231 //JR 24.03.2005 Debug : the number of OutPorts of a GOTONode and of InPorts of its linked
2232 // InLine node must be the same
2233 if ( GetNodeOutPortsSize() != aLabelNode-> GetNodeInPortsSize() ) {
2234 cdebug << pthread_self() << "/" << ThreadNo()
2235 << " Successed_SuccessAction # number of ports " << GetNodeOutPortsSize()
2236 << " != " << aLabelNode-> GetNodeInPortsSize() << endl ;
2237 SendEvent( GraphExecutor::ErrorEvent ) ;
2241 for ( j = 0 ; j < GetNodeOutPortsSize() ; j++ ) {
2242 GraphBase::OutPort * aBusParamOutPort = GetChangeNodeOutPort( j ) ;
2243 if ( !aBusParamOutPort->IsGate() ) {
2244 GraphBase::InPort * aBusParamChangeInPort = NULL ;
2245 if ( aBusParamOutPort->IsLoop() ) {
2246 // For EndLoop do not copy EndLoop(DoLoop) in Loop(InLoop)
2247 // aBusParamChangeInPort = aLabelNode->GetChangeNodeInLoop() ;
2250 aBusParamChangeInPort = aLabelNode->GetChangeInPort( aBusParamOutPort->PortName() ) ;
2252 if ( aBusParamChangeInPort ) {
2253 aBusParamChangeInPort->ChangeOutPort( aBusParamOutPort ) ;
2254 #if SuccessActionTrace
2255 cdebug << pthread_self() << "/" << ThreadNo() << " Successed_SuccessAction " << Name() << " ChangeOutPort to HeadNode "
2256 << aLabelNode->Name() << "(" << aBusParamChangeInPort->PortName() << ") from port "
2257 << aBusParamOutPort->PortName() << endl ;
2260 else if ( IsGOTONode() ) {
2261 //PAL8176 ==> PAL8516
2262 //JR 24.03.2005 Debug : the names of OutPorts of a GOTONode and of InPorts of its linked
2263 // InLine node must be the same
2264 cdebug << pthread_self() << "/" << ThreadNo()
2265 << " Successed_SuccessAction # names of ports "
2266 << aBusParamOutPort->PortName() << endl ;
2267 SendEvent( GraphExecutor::ErrorEvent ) ;
2275 if ( aLabelNode && !aLabelNode->IsLockedDataWait() ) {
2276 res = aLabelNode->SendSomeDataReady( Name() ) ;
2278 if ( firsttoNode == NULL &&
2279 aLabelNode->ThreadNo() == pthread_self() ) {
2280 firsttoNode = aLabelNode ;
2281 #if SuccessActionTrace
2282 cdebug << pthread_self() << "/" << ThreadNo() << " Successed_SuccessAction firsttoNode "
2283 << aLabelNode->Name() << endl ;
2286 else if ( firstzeroNode == NULL &&
2287 aLabelNode->ThreadNo() == 0 ) {
2288 firstzeroNode = aLabelNode ;
2291 SomeDataNodes.push_back( aLabelNode ) ;
2292 #if SuccessActionTrace
2293 cdebug << pthread_self() << "/" << ThreadNo() << " Successed_SuccessAction " << Name() << " push "
2294 << aLabelNode->Name() << " " << SomeDataNodes.size()
2300 // for ( j = 0 ; j < aLabelNode->GetNodeInPortsSize() ; j++ ) {
2301 // const GraphBase::InPort * anInPort = aLabelNode->GetNodeInPort( j ) ;
2302 // if ( anInPort->GetOutPort() ) {
2303 // cdebug << aLabelNode->Name() << "(" << anInPort->PortName() << ") value : "
2304 // << anInPort->GetOutPort()->NodeName() << "(" << anInPort->GetOutPort()->PortName() << ")"
2308 const GraphBase::InPort * aGateInPort = aLabelNode->GetNodeInGate() ;
2309 if ( aGateInPort ) {
2310 if ( aGateInPort->GetOutPort() ) {
2311 //JR 21.02.2005 Debug Memory leak : aGateInPort->GetOutPort()->Value( aGateOutPort->Value() ) ;
2312 //JR 30.03.2005 aGateInPort->GetOutPort()->Value( *aGateOutPort->Value() ) ;
2313 aGateInPort->GetOutPort()->Value( aGateOutPort->Value() ) ;
2315 if ( !aLabelNode->IsLockedDataWait() ) {
2316 res = aLabelNode->SendSomeDataReady( Name() ) ;
2318 if ( firsttoNode == NULL &&
2319 aLabelNode->ThreadNo() == pthread_self() ) {
2320 firsttoNode = aLabelNode ;
2321 #if SuccessActionTrace
2322 cdebug << pthread_self() << "/" << ThreadNo() << " Successed_SuccessAction firsttoNode "
2323 << aLabelNode->Name() << endl ;
2326 else if ( firstzeroNode == NULL &&
2327 aLabelNode->ThreadNo() == 0 ) {
2328 firstzeroNode = aLabelNode ;
2331 SomeDataNodes.push_back( aLabelNode ) ;
2332 #if SuccessActionTrace
2333 cdebug << pthread_self() << "/" << ThreadNo() << " Successed_SuccessAction " << Name() << " push "
2334 << aLabelNode->Name() << " " << SomeDataNodes.size()
2342 cdebug << pthread_self() << "/" << ThreadNo() << " ERROR in Successed_SuccessAction of " << Name()
2343 << " NO port " << aGateOutPort->PortName() << " in "
2344 << aLabelNode->Name() << endl;
2349 // JR 09.02.2005 : this is not a EndLoop or a GOTO :
2351 #if SuccessActionTrace
2352 cdebug << ThreadNo() << " Successed_SuccessAction of " << Name()
2353 << " with " << LinkedNodesSize() << " linked nodes :" ;
2355 for ( i = 0 ; i < LinkedNodesSize() ; i++ ) {
2356 if ( LinkedNodes( i )->IsDataFlowNode() ) {
2357 linkednodesnumber -= 1 ;
2359 #if SuccessActionTrace
2360 cdebug << " " << LinkedNodes( i )->Name() ;
2363 #if SuccessActionTrace
2366 for ( i = 0 ; i < LinkedNodesSize() ; i++ ) {
2367 // If this is a LoopNode and if DoLoopPort == false, we go directly to the EndOfLoopNode and
2368 // we do not activate Nodes within the loop
2369 bool IgnoreForEndLoop = false ;
2370 // If this is a SwitchNode and if DefaultOutPort == true, we may activate Nodes within Switch
2371 // or we may activate directly the EnSwitch
2372 // BUT the NotSwitchBranch(es) are NOT activated :
2373 bool IgnoreForDefaultSwitch = false ;
2374 GraphBase::ComputingNode * aComputingNode ;
2375 aComputingNode = (GraphBase::ComputingNode * ) LinkedNodes( i ) ;
2376 toNode = (GraphExecutor::InNode *) aComputingNode->GetInNode() ;
2377 #if SuccessActionTrace
2378 cdebug << pthread_self() << "/" << ThreadNo() << " Successed_SuccessAction of " << Name()
2379 << " [" << i << "] " << LinkedNodes( i )->Name() << " toNode " << toNode
2380 << " IgnoreForEndLoop " << IgnoreForEndLoop ;
2382 cdebug << " " << toNode->Kind() << endl ;
2385 if ( toNode && !toNode->IsDataFlowNode() ) {
2386 if ( IsComputingNode() && toNode->IsInLineNode() ) {
2387 GraphBase::InPort * toGateInPort = toNode->GetChangeNodeInGate() ;
2388 toGateInPort->PortState( SUPERV::ReadyState ) ;
2389 GraphBase::OutPort * GateOutPort = toGateInPort->GetOutPort() ;
2390 if ( GateOutPort ) {
2391 GateOutPort->PortStatus( DataConnected );
2392 GateOutPort->PortState( SUPERV::ReadyState ) ;
2393 GateOutPort->PortDone( true ) ;
2397 if ( toNode && IsLoopNode() ) {
2398 GraphBase::OutPort * fromLoopOutPort = GetChangeNodeOutLoop() ;
2399 if ( !fromLoopOutPort->BoolValue() ) { // Ne pas faire la boucle
2400 if ( strcmp( toNode->Name() , CoupledNode()->Name() ) ) {
2401 IgnoreForEndLoop = true ;
2403 else { // toNode is the EndLoopNode
2404 GraphBase::InPort * toLoopInPort ;
2405 toLoopInPort = toNode->GetChangeNodeInLoop() ;
2406 if ( toLoopInPort->PortState() != SUPERV::ReadyState ) {
2407 toLoopInPort->PortState( SUPERV::ReadyState ) ;
2412 else if ( toNode && IsSwitchNode() ) {
2413 const GraphBase::OutPort * anOutGatePort = GetNodeOutGate() ;
2414 if ( anOutGatePort->BoolValue() && anOutGatePort->InPortsSize() ) { // DefaultPort is activated
2415 IgnoreForDefaultSwitch = true ;
2418 else if ( toNode && toNode->IsInLineNode() ) {
2420 for ( j = 0 ; j < toNode->GetNodeInPortsSize() ; j++ ) {
2421 toNode->GetChangeNodeInPort( j )->InitialOutPort() ;
2424 if ( toNode && !IgnoreForEndLoop ) {
2425 if ( toNode && toNode->IsLoopNode() ) {
2426 GraphBase::InPort * toLoopInPort = toNode->GetChangeNodeInLoop() ;
2427 toLoopInPort->PortState( SUPERV::ReadyState ) ;
2428 GraphBase::OutPort * LoopOutPort = toLoopInPort->GetOutPort() ;
2429 LoopOutPort->PortStatus( DataConnected );
2430 LoopOutPort->PortState( SUPERV::ReadyState ) ;
2431 LoopOutPort->PortDone( true ) ;
2432 //JR 21.02.2005 Debug Memory leak : CORBA::Any * anAny = new CORBA::Any() ; // InitLoop
2433 CORBA::Any anAny = CORBA::Any() ; // InitLoop
2434 //JR 21.02.2005 Debug Memory leak : *anAny <<= (long ) 1 ;
2435 anAny <<= (long ) 1 ;
2436 LoopOutPort->Value( anAny ) ;
2439 for ( j = 0 ; j < toNode->GetNodeInPortsSize() ; j++ ) {
2440 toNode->GetChangeNodeInPort( j )->InitialOutPort() ;
2443 // If the DefaultPort of that SwitchNode is connected to the DefaultPort od the EndSwitchNode
2444 // the NotSwitchBranch(es) are NOT activated :
2445 // If the DefaultPort of that SwitchNode is connected to SwitchBranch(es)
2446 // the NotSwitchBranch(es) are NOT activated :
2447 bool activatetoNode = true ;
2448 if ( IgnoreForDefaultSwitch ) {
2449 #if SuccessActionTrace
2450 cdebug << pthread_self() << "/" << ThreadNo() << " Successed_SuccessAction search "
2451 << toNode->Name() << " among linked nodes to DefaultPort of " << Name() << endl ;
2453 activatetoNode = false ;
2454 const GraphBase::OutPort * anOutGatePort = GetNodeOutGate() ;
2455 const GraphBase::InPort * anInPort = NULL ;
2457 for ( j = 0 ; j < anOutGatePort->InPortsSize() ; j++ ) {
2458 anInPort = anOutGatePort->InPorts( j ) ;
2459 const GraphBase::ComputingNode * aNode ;
2460 aNode = _OutNode->Graph()->GetGraphNode( anInPort->NodeName() ) ;
2462 #if SuccessActionTrace
2463 cdebug << pthread_self() << "/" << ThreadNo() << " Successed_SuccessAction try "
2464 << aNode << " " << aNode->Name() << " == " << toNode << " " << toNode->Name()
2468 if ( aNode && (const GraphBase::ComputingNode * ) toNode->ComputingNode() == aNode ) {
2469 // toNode is connected to the DefaultPort of that SwitchNode :
2470 activatetoNode = true ;
2474 // if ( activatetoNode ) {
2475 // cdebug << pthread_self() << "/" << ThreadNo() << " Successed_SuccessAction found "
2476 // << toNode->Name() << " among linked nodes to DefaultPort of " << Name()
2480 // cdebug << pthread_self() << "/" << ThreadNo()
2481 // << " Successed_SuccessAction does NOT found "
2482 // << toNode->Name() << " among linked nodes to DefaultPort of " << Name()
2486 if ( activatetoNode ) {
2487 #if SuccessActionTrace
2488 cdebug << pthread_self() << "/" << ThreadNo() << " Successed_SuccessAction "
2489 << toNode->Name() << "->SendSomeDataReady( " << Name() << " )" << endl ;
2491 res = toNode->SendSomeDataReady( Name() ) ;
2493 if ( firsttoNode == NULL &&
2494 toNode->ThreadNo() == pthread_self() ) {
2495 firsttoNode = toNode ;
2496 #if SuccessActionTrace
2497 cdebug << pthread_self() << "/" << ThreadNo()
2498 << " Successed_SuccessAction firsttoNode " << toNode->Name() << endl ;
2501 else if ( firstzeroNode == NULL &&
2502 toNode->ThreadNo() == 0 ) {
2503 firstzeroNode = toNode ;
2506 SomeDataNodes.push_back( toNode ) ;
2507 #if SuccessActionTrace
2508 cdebug << pthread_self() << "/" << ThreadNo() << " Successed_SuccessAction "
2509 << Name() << " push "
2510 << toNode->Name() << " " << SomeDataNodes.size() << endl ;
2520 //JR 10.02.2005 : Debug at the end of execution of a SwitchNode :
2521 // Here after we may start execution of only one SwitchBranch or of the Default
2522 // But with activation of only one SwitchBranch we may activate several nodes of that SwitchBranch and
2523 // we may activate several nodes of NotSwitchBranch ( a NotSwitchBranch is a Branch of the Switch
2524 // where GatePorts of Nodes are not connected ; that Branches are always executed for each of SwitchBranch
2525 // BUT are not executed when Default is activated).
2526 // So the bug is that all input ports of the corresponding EndSwitchNode must have the status NOTDONE !
2527 // (Only if Default OutPort is closed and Default InPort is closed)
2528 if ( IsSwitchNode() ) {
2529 GraphBase::InLineNode * anEndSwitchNode = GOTONode()->CoupledNode() ;
2530 if ( !GetNodeOutGate()->BoolValue() && anEndSwitchNode->GetNodeInGate()->GetOutPort() &&
2531 !anEndSwitchNode->GetNodeInGate()->GetOutPort()->BoolValue() ) {
2532 #if SuccessActionTrace
2533 cdebug << pthread_self() << "/" << ThreadNo() << " Successed_SuccessAction " << anEndSwitchNode->Name()
2534 << " reset of InPort()->OutPort()->Done flag in EndSwitch" << endl ;
2537 for ( i = 0 ; i < anEndSwitchNode->GetNodeInPortsSize() ; i++ ) {
2538 GraphBase::OutPort * anOutPort = anEndSwitchNode->GetChangeNodeInPort( i )->GetOutPort() ;
2540 //JR 08.03.2005 Debug : update of state only if not a StreamPort
2541 if ( anOutPort && strcmp( anOutPort->NodeName() , Name() ) &&
2542 !anOutPort->IsDataStream() ) {
2543 #if SuccessActionTrace
2544 cdebug << pthread_self() << "/" << ThreadNo() << " Successed_SuccessAction "
2545 << anEndSwitchNode->Name() << " InPort "
2546 << anEndSwitchNode->GetChangeNodeInPort( i )->PortName() << " NOTDONE from "
2547 << anOutPort->NodeName() << " " << anOutPort->PortName() << endl ;
2549 anEndSwitchNode->GetChangeNodeInPort( i )->PortState( SUPERV::WaitingState ) ;
2550 anEndSwitchNode->GetChangeNodeInPort( i )->GetOutPort()->PortDone( false ) ;
2553 #if SuccessActionTrace
2554 cdebug << pthread_self() << "/" << ThreadNo() << " Successed_SuccessAction "
2555 << anEndSwitchNode->Name() << " InPort "
2556 << anEndSwitchNode->GetChangeNodeInPort( i )->PortName() << " NOT Changed : directly from "
2557 << anOutPort->NodeName() << " " << anOutPort->PortName() << endl ;
2563 #if SuccessActionTrace
2564 cdebug << pthread_self() << "/" << ThreadNo() << " Successed_SuccessAction " << Name()
2565 << " " << Kind() << " OutGate->Value " << GetNodeOutGate()->BoolValue()
2566 << " NO reset of InPort()->OutPort()->Done flag in EndSwitch" << endl ;
2571 // firsttoNode : node that has the same ThreadNo() as the current node and that have to be activated
2572 // firstzeroNode : node that has a null ThreadNo() and that have to be activated
2573 if ( firsttoNode == NULL && firstzeroNode ) {
2574 firsttoNode = firstzeroNode ;
2575 #if SuccessActionTrace
2576 cdebug << pthread_self() << "/" << ThreadNo()
2577 << " Successed_SuccessAction firsttoNode = firstzeroNode " << firsttoNode->Name()
2581 else if ( firsttoNode && firstzeroNode ) {
2582 SomeDataNodes.push_back( firstzeroNode ) ;
2583 #if SuccessActionTrace
2584 cdebug << pthread_self() << "/" << ThreadNo() << " Successed_SuccessAction " << Name() << " push firstzeroNode "
2585 << firstzeroNode->Name() << " " << SomeDataNodes.size() << endl ;
2587 firstzeroNode = NULL ;
2590 #if SuccessActionTrace
2591 cdebug << pthread_self() << "/" << ThreadNo() << " Successed_SuccessAction " << Name() << " firsttoNode " << firsttoNode
2592 << " firstzeroNode " << firstzeroNode << endl ;
2596 while ( SomeDataNodes.size() ) {
2597 GraphExecutor::InNode *aNode = SomeDataNodes.front() ;
2598 SomeDataNodes.pop_front() ;
2599 #if SuccessActionTrace
2600 cdebug << pthread_self() << "/" << ThreadNo()
2601 << " Successed_SuccessAction pop size "
2602 << SomeDataNodes.size() << " " << aNode->Name() << endl ;
2604 if ( aNode->State() == GraphExecutor::DataReadyState ) {
2605 #if SuccessActionTrace
2606 cdebug << pthread_self() << "/" << ThreadNo() << " Successed_SuccessAction pop CreateNewThreadIf( true )"
2609 aNode->CreateNewThreadIf( true ) ;
2610 _OutNode->IncrCreatedThreads() ;
2611 aNode->UnLockDataWait() ;
2612 res = aNode->DataUndef_AllDataReadyAction() ;
2615 #if SuccessActionTrace
2616 cdebug << pthread_self() << "/" << ThreadNo() << " ERROR "
2617 << aNode->Name() << " "
2618 << Automaton()->StateName( aNode->State() ) << endl ;
2623 if ( firsttoNode ) {
2624 #if SuccessActionTrace
2625 cdebug << pthread_self() << "/" << ThreadNo()
2626 << " Successed_SuccessAction start firsttoNode "
2627 << SomeDataNodes.size() << " " << firsttoNode->Name() << endl ;
2629 firsttoNode->CreateNewThreadIf( false ) ;
2630 firsttoNode->RewindStack( RewindStack() ) ;
2631 if ( firsttoNode->State() == GraphExecutor::SuccessedState ) {
2632 #if SuccessActionTrace
2633 cdebug << pthread_self() << "/" << ThreadNo() << " " << Name()
2634 << " : " << firsttoNode->Name() << " "
2635 << Automaton()->StateName( firsttoNode->State() )
2636 << " --> DataWaitingState for Thread "
2637 << firsttoNode->ThreadNo() << endl ;
2639 firsttoNode->State( GraphExecutor::DataWaitingState ) ;
2641 firsttoNode->ThreadNo( pthread_self() ) ;
2642 // On continue avec le meme thread
2644 #if SuccessActionTrace
2645 cdebug << ThreadNo() << " Successed_SuccessAction " << Name()
2646 << " for " << firsttoNode->Name()
2647 << " !firsttoNode->CreateNewThreadIf() "
2648 << !firsttoNode->CreateNewThreadIf()
2649 << " " << Automaton()->StateName( firsttoNode->State() ) ;
2650 if ( firsttoNode->State() == GraphExecutor::DataReadyState ) {
2653 cdebug << " ERROR " << endl ;
2656 if ( firsttoNode->State() == GraphExecutor::DataReadyState ) {
2657 firsttoNode->UnLockDataWait() ;
2658 res = firsttoNode->DataUndef_AllDataReadyAction() ;
2662 #if SuccessActionTrace
2663 cdebug << ThreadNo() << " Successed_SuccessAction " << Name()
2664 << " NO DataReady ==> ThreadNo( 0 ) firsttoNode == NULL LINKEDnodesnumber " << linkednodesnumber << endl ;
2669 // if ( linkednodesnumber == 0 && firsttoNode == NULL ) {
2670 // cdebug << ThreadNo() << " Successed_SuccessAction " << Name() << " LinkedNodesSize " << LinkedNodesSize()
2671 // << " firsttoNode == NULL LINKEDnodesnumber " << linkednodesnumber << " CHECK" << endl ;
2672 // _OutNode->CheckAllDone() ;
2675 #if SuccessActionTrace
2676 cdebug << pthread_self() << "/" << ThreadNo()
2677 << " <-- Successed_SuccessAction " << Name() << " linkednodesnumber "
2678 << linkednodesnumber << endl;
2683 #define SendSomeDataReadyTrace 0
2684 bool GraphExecutor::InNode::SendSomeDataReady( char * FromNodeName ) {
2685 bool RetVal = false ;
2686 if ( IsDataFlowNode() ) {
2687 #if SendSomeDataReadyTrace
2688 cdebug << ThreadNo() << "InNode::SendSomeDataReady ----> " << Name()
2689 << " send Result to graph " << Name() << endl;
2693 #if SendSomeDataReadyTrace
2694 cdebug << pthread_self() << "/" << ThreadNo() << " ----> " << FromNodeName
2695 << " send SomeDataReady to " << Name() << " "
2696 << Automaton()->StateName( State() )
2697 << " CreateNewThreadIf() " << CreateNewThreadIf()
2698 << " LockedDataWait " << IsLockedDataWait() << endl;
2701 //cout << pthread_self() << "/" << ThreadNo() << " ----> " << FromNodeName
2702 << " send SomeDataReady to " << Name() << " "
2703 << Automaton()->StateName( State() )
2704 << " CreateNewThreadIf() " << CreateNewThreadIf()
2705 << " LockedDataWait " << IsLockedDataWait() << endl;
2707 if ( State() == GraphExecutor::SuccessedState ||
2708 State() == GraphExecutor::SuspendedSuccessedState ||
2709 State() == GraphExecutor::SuspendedSuccessedToReStartState ) {
2710 #if SendSomeDataReadyTrace
2711 cdebug << ThreadNo() << " " << FromNodeName
2712 << " : " << Name() << " " << Automaton()->StateName( State() )
2713 << " --> DataWaitingState for Thread "
2714 << ThreadNo() << " " << endl ;
2716 State( GraphExecutor::DataWaitingState ) ;
2718 // We begin that LoopNode if SendSomeDataReady does not come from the corresponding EndLoopNode
2719 if ( IsLoopNode() && strcmp( LoopNode()->CoupledNodeName() , FromNodeName ) ) {
2720 cdebug << ThreadNo() << "InNode::SendSomeDataReady " << Name() << " Set _InitLoop from "
2721 << FromNodeName << endl ;
2725 DataFromNode( FromNodeName ) ;
2726 RetVal = !SendEvent( GraphExecutor::SomeDataReadyEvent );
2734 int GraphExecutor::InNode::Errored_ErrorAction() {
2735 cdebug << ThreadNo() << " Errored_ErrorAction " << Name()
2736 << " will pthread_exit" << endl;
2741 int GraphExecutor::InNode::Successed_SuspendAction() {
2742 cdebug << ThreadNo() << " Successed_SuspendAction -->Suspend " << Name()
2743 << " Threads " << _OutNode->Threads() << " SuspendedThreads "
2744 << _OutNode->SuspendedThreads() << endl;
2745 _OutNode->PushEvent( this , GraphExecutor::SuspendedSuccessedEvent ,
2746 GraphExecutor::SuspendedSuccessedState ) ;
2748 GraphExecutor::InNode * aReStartNode = SuspendAction() ;
2749 cdebug << ThreadNo() << " Successed_SuspendAction Resumed " << Name() ;
2750 if ( aReStartNode ) {
2751 _aReStartNode = NULL ;
2752 cdebug << " for " << aReStartNode->Name() << endl;
2753 aReStartNode->SendEvent( _aReStartEvent ) ;
2757 SendEvent( GraphExecutor::ResumeEvent ) ;
2762 int GraphExecutor::InNode::Errored_SuspendAction() {
2763 cdebug << ThreadNo() << " Errored_SuspendAction -->Suspend " << Name()
2764 << " Threads " << _OutNode->Threads() << " SuspendedThreads "
2765 << _OutNode->SuspendedThreads() << endl;
2766 _OutNode->PushEvent( this , GraphExecutor::SuspendedErroredEvent ,
2767 GraphExecutor::SuspendedErroredState ) ;
2769 GraphExecutor::InNode * aReStartNode = SuspendAction() ;
2770 cdebug << ThreadNo() << " Errored_SuspendAction Resumed " << Name()
2772 if ( aReStartNode ) {
2773 _aReStartNode = NULL ;
2774 aReStartNode->SendEvent( _aReStartEvent ) ;
2777 SendEvent( GraphExecutor::ResumeEvent ) ;
2782 int GraphExecutor::InNode::SuspendedSuccessed_ResumeAction() {
2783 cdebug << ThreadNo() << " SuspendedSuccessed_ResumeAction " << Name() << endl;
2785 _OutNode->PushEvent( this , GraphExecutor::ResumedSuccessedEvent ,
2786 GraphExecutor::ResumedSuccessedState ) ;
2787 SendEvent( ResumedSuccessedEvent ) ;
2791 int GraphExecutor::InNode::SuspendedErrored_ResumeAction() {
2792 cdebug << ThreadNo() << " SuspendedErrored_ResumeAction " << Name() << endl;
2794 _OutNode->PushEvent( this , GraphExecutor::ResumedErroredEvent ,
2795 GraphExecutor::ResumedErroredState ) ;
2796 SendEvent( ResumedErroredEvent ) ;
2800 int GraphExecutor::InNode::Successed_KillAction() {
2802 _OutNode->PushEvent( this , GraphExecutor::KilledEvent ,
2803 GraphExecutor::KilledSuccessedState ) ;
2804 cdebug << ThreadNo() << " Successed_KillAction " << Name() << endl;
2808 int GraphExecutor::InNode::Errored_KillAction() {
2810 _OutNode->PushEvent( this , GraphExecutor::KilledEvent ,
2811 GraphExecutor::KilledErroredState ) ;
2812 cdebug << ThreadNo() << " Errored_KillAction " << Name() << endl;
2816 int GraphExecutor::InNode::Successed_StopAction() {
2818 _OutNode->PushEvent( this , GraphExecutor::StoppedEvent ,
2819 GraphExecutor::StoppedSuccessedState ) ;
2820 cdebug << ThreadNo() << " Successed_StopAction " << Name() << endl;
2824 int GraphExecutor::InNode::Errored_StopAction() {
2826 _OutNode->PushEvent( this , GraphExecutor::StoppedEvent ,
2827 GraphExecutor::StoppedErroredState ) ;
2828 cdebug << ThreadNo() << " Errored_StopAction " << Name() << endl;
2832 int GraphExecutor::InNode::SuspendedSuccessed_ReStartAction() {
2833 cdebug << ThreadNo() << " SuspendedSuccessed_ReStartAction " << Name() << endl;
2834 _OutNode->PushEvent( this , GraphExecutor::ReStartedEvent ,
2835 GraphExecutor::ReStartedState ) ;
2837 for ( i = 0 ; i < GetNodeInPortsSize() ; i++ ) {
2838 GetChangeNodeInPort( i )->PortState( SUPERV::ReadyState ) ;
2840 SendEvent( ExecuteEvent ) ;
2841 cdebug << ThreadNo() << " SuspendedSuccessed_ReStartAction " << Name() << endl;
2845 int GraphExecutor::InNode::SuspendedErrored_ReStartAction() {
2846 cdebug << ThreadNo() << " SuspendedErrored_ReStartAction " << Name() << endl;
2847 _OutNode->PushEvent( this , GraphExecutor::ReStartedEvent ,
2848 GraphExecutor::ReStartedState ) ;
2850 for ( i = 0 ; i < GetNodeInPortsSize() ; i++ ) {
2851 GetChangeNodeInPort( i )->PortState( SUPERV::ReadyState ) ;
2853 SendEvent( ExecuteEvent ) ;
2854 cdebug << ThreadNo() << " SuspendedErrored_ReStartAction " << Name() << endl;
2858 int GraphExecutor::InNode::SuspendedSuccessed_ReStartAndSuspendAction() {
2859 cdebug << ThreadNo() << " SuspendedSuccessed_ReStartAndSuspendAction " << Name()
2861 _OutNode->PushEvent( this , GraphExecutor::ReStartedAndSuspendEvent ,
2862 GraphExecutor::ReStartedState ) ;
2863 State( GraphExecutor::DataWaitingState ) ;
2865 cdebug << "InNode::Suspend() Node " << Name() << endl ;
2868 else if ( SendEvent( GraphExecutor::SomeDataReadyEvent ) ) {
2869 cdebug << "InNode::SendEvent( SomeDataReadyEvent ) Node "
2873 cdebug << ThreadNo() << " SuspendedSuccessed_ReStartAndSuspendAction " << Name()
2878 int GraphExecutor::InNode::SuspendedErrored_ReStartAndSuspendAction() {
2879 cdebug << ThreadNo() << " SuspendedErrored_ReStartAndSuspendAction " << Name()
2881 _OutNode->PushEvent( this , GraphExecutor::ReStartedAndSuspendEvent ,
2882 GraphExecutor::ReStartedState ) ;
2883 State( GraphExecutor::DataWaitingState ) ;
2885 cdebug << "InNode::Suspend() Node " << Name() << endl ;
2888 else if ( SendEvent( GraphExecutor::SomeDataReadyEvent ) ) {
2889 cdebug << "InNode::SendEvent( SomeDataReadyEvent ) Node "
2893 cdebug << ThreadNo() << " SuspendedErrored_ReStartAndSuspendAction " << Name()
2898 #define InParametersSetTrace 0
2899 void GraphExecutor::InNode::InParametersSet( bool & Err ,
2901 ServicesAnyData * InParametersList ) {
2903 #if InParametersSetTrace
2904 cdebug << pthread_self() << "/" << ThreadNo() << " InParametersSet " << Name() << endl ;
2906 for ( i = 0 ; i < nInParams ; i++ ) {
2907 ServicesAnyData D = InParametersList[i];
2908 GraphBase::InPort * anInPort = GetChangeNodeInPort(i) ;
2909 GraphBase::OutPort * theOutPort = anInPort->GetOutPort() ;
2910 if ( anInPort->IsGate() && theOutPort == NULL ) {
2911 #if InParametersSetTrace
2912 cdebug << ThreadNo() << " ArgIn" << i << " " << D.Name << " "
2913 << anInPort->GetServicesParameter().Parametertype
2914 << " is inactive. " << anInPort->Kind() << endl ;
2917 else if ( anInPort->PortState() == SUPERV::ReadyState ) {
2918 if ( anInPort->IsGate() ) {
2919 //JR 21.02.2005 Debug Memory leak : CORBA::Any * anAny = new CORBA::Any() ;
2920 CORBA::Any anAny = CORBA::Any() ;
2921 //JR 21.02.2005 Debug Memory leak : *anAny <<= (long ) 0 ;
2922 anAny <<= (long ) 0 ;
2923 theOutPort->Value( anAny ) ;
2926 if ( !anInPort->IsDataStream() &&
2927 !anInPort->IsDataConnected() ) {
2928 anInPort->PortState( SUPERV::WaitingState ) ;
2930 //JR 18.02.2005 Debug Memory leak : delete does not destroy that string ...
2931 // D.Name = CORBA::string_dup( anInPort->GetServicesParameter().Parametername ) ;
2932 D.Name = anInPort->PortName() ;
2933 //JR 30.03.2005 const CORBA::Any * AnyPtr = theOutPort->Value() ;
2934 const CORBA::Any AnyRef = theOutPort->Value() ;
2935 #if InParametersSetTrace
2936 cdebug << ThreadNo() << " ArgIn" << i << " " << anInPort->Kind() << " "
2937 << anInPort->PortState() << " " << D.Name << " "
2938 << anInPort->GetServicesParameter().Parametertype << endl ;
2940 //JR 30.03.2005 D.Value = * AnyPtr ; // CORBA::Any
2941 D.Value = AnyRef ; // CORBA::Any
2942 //JR 18.02.2005 Debug Memory leak : string _Type = CORBA::string_dup( anInPort->GetServicesParameter().Parametertype ) ;
2943 // const char * Type = _Type.c_str() ;
2944 const char * Type = anInPort->GetServicesParameter().Parametertype ;
2945 switch ( D.Value.type()->kind() ) { // { string , long , double , objref }
2946 case CORBA::tk_string:
2949 #if InParametersSetTrace
2950 cdebug << t << " (string)" ;
2952 if ( !strcmp( Type , "string" ) ) {
2954 else if ( !strcmp( Type , "boolean" ) ) {
2957 sscanf( t , "%ld" , &d ) ;
2959 D.Value <<= (CORBA::Any::from_boolean ) b ;
2960 // theOutPort->Value( D.Value ) ;
2962 else if ( !strcmp( Type , "char" ) ) {
2965 sscanf( t , "%ld" , &d ) ;
2967 D.Value <<= (CORBA::Any::from_char ) c ;
2968 #if InParametersSetTrace
2969 cdebug << "string '" << t << "' --> " << d << " --> char " << c ;
2971 // theOutPort->Value( D.Value ) ;
2973 else if ( !strcmp( Type , "short" ) ) {
2976 sscanf( t , "%ld" , &d ) ;
2979 #if InParametersSetTrace
2980 cdebug << "string '" << t << "' --> " << d << " --> short " << s ;
2982 // theOutPort->Value( D.Value ) ;
2984 else if ( !strcmp( Type , "int" ) || !strcmp( Type , "long" ) ) {
2986 sscanf( t , "%ld" , &l ) ;
2988 #if InParametersSetTrace
2989 cdebug << "string '" << t << " --> long " << l ;
2991 // theOutPort->Value( D.Value ) ;
2993 else if ( !strcmp( Type , "float" ) ) {
2995 sscanf( t , "%lf" , &d ) ;
2998 #if InParametersSetTrace
2999 cdebug << "string '" << t << "' --> " << setw(25) << setprecision(18) << d << " --> float " << " = "
3000 << setw(25) << setprecision(18) << f ;
3002 // theOutPort->Value( D.Value ) ;
3004 else if ( !strcmp( Type , "double" ) ) {
3006 sscanf( t , "%lf" , &d ) ;
3008 #if InParametersSetTrace
3009 cdebug << "string '" << t << " --> double " << setw(25) << setprecision(18) << d ;
3011 // theOutPort->Value( D.Value ) ;
3013 // else if ( !strcmp( Type , "objref" ) ) {
3015 CORBA::Object_ptr ObjRef ;
3017 ObjRef = StringToObject( t ) ;
3018 D.Value <<= ObjRef ;
3021 D.Value <<= CORBA::Object::_nil() ;
3023 // theOutPort->Value( D.Value ) ;
3026 // cdebug << " (other ERROR)" << endl ;
3028 #if InParametersSetTrace
3029 cdebug << " --> call_kind " << D.Value.type()->kind() << endl ;
3032 case CORBA::tk_long:
3033 #if InParametersSetTrace
3034 cdebug << ThreadNo() << " " << Name() << " ArgIn" << i << " " << D.Name << " "
3035 << anInPort->GetServicesParameter().Parametertype << " " << anInPort->Kind()
3037 theOutPort->StringValue( *GraphBase::Base::_fdebug ) ;
3042 #if InParametersSetTrace
3043 cdebug << l << " (long)" << endl ;
3045 if ( !strcmp( Type , "string" ) ) {
3047 sprintf( t , "%ld" , l ) ;
3049 // theOutPort->Value( D.Value ) ;
3051 else if ( !strcmp( Type , "boolean" ) ) {
3054 D.Value <<= (CORBA::Any::from_boolean ) b ;
3055 // theOutPort->Value( D.Value ) ;
3057 else if ( !strcmp( Type , "char" ) ) {
3059 c = (unsigned char ) l ;
3060 D.Value <<= (CORBA::Any::from_char ) c ;
3061 // theOutPort->Value( D.Value ) ;
3063 else if ( !strcmp( Type , "short" ) ) {
3067 // theOutPort->Value( D.Value ) ;
3069 else if ( !strcmp( Type , "int" ) || !strcmp( Type , "long" ) ) {
3071 else if ( !strcmp( Type , "float" ) ) {
3075 // theOutPort->Value( D.Value ) ;
3077 else if ( !strcmp( Type , "double" ) ) {
3081 // theOutPort->Value( D.Value ) ;
3083 // else if ( !strcmp( Type , "objref" ) ) {
3085 D.Value <<= CORBA::Object::_nil() ;
3086 // theOutPort->Value( D.Value ) ;
3089 // cdebug << " (other ERROR)" << endl ;
3091 #if InParametersSetTrace
3092 cdebug << " --> call_kind " << D.Value.type()->kind() << endl ;
3095 case CORBA::tk_double:
3098 #if InParametersSetTrace
3099 cdebug << d << " (double)" << endl ;
3101 if ( !strcmp( Type , "string" ) ) {
3103 sprintf( t , "%lf" , d ) ;
3105 // theOutPort->Value( D.Value ) ;
3107 else if ( !strcmp( Type , "boolean" ) ) {
3110 D.Value <<= (CORBA::Any::from_boolean ) b ;
3111 // theOutPort->Value( D.Value ) ;
3113 else if ( !strcmp( Type , "char" ) ) {
3115 c = (unsigned char ) d ;
3116 D.Value <<= (CORBA::Any::from_char ) c ;
3117 // theOutPort->Value( D.Value ) ;
3119 else if ( !strcmp( Type , "short" ) ) {
3123 // theOutPort->Value( D.Value ) ;
3125 else if ( !strcmp( Type , "int" ) || !strcmp( Type , "long" ) ) {
3129 // theOutPort->Value( D.Value ) ;
3131 else if ( !strcmp( Type , "float" ) ) {
3135 // theOutPort->Value( D.Value ) ;
3137 else if ( !strcmp( Type , "double" ) ) {
3139 // else if ( !strcmp( Type , "objref" ) ) {
3141 D.Value <<= CORBA::Object::_nil() ;
3142 // theOutPort->Value( D.Value ) ;
3145 // cdebug << " (other ERROR)" << endl ;
3147 #if InParametersSetTrace
3148 cdebug << " --> call_kind " << D.Value.type()->kind() << endl ;
3151 case CORBA::tk_objref:
3152 if ( !strcmp( Type , "string" ) ) {
3153 CORBA::Object_ptr ObjRef ;
3156 D.Value >>= ObjRef ;
3157 retstr = ObjectToString( ObjRef ) ;
3158 D.Value <<= retstr ;
3159 // theOutPort->Value( D.Value ) ;
3165 cdebug << "ToString( object ) Catched ERROR" << endl ;
3168 else if ( !strcmp( Type , "boolean" ) ) {
3170 D.Value <<= (CORBA::Any::from_boolean ) b ;
3171 // theOutPort->Value( D.Value ) ;
3173 else if ( !strcmp( Type , "char" ) ) {
3174 unsigned char c = 0 ;
3175 D.Value <<= (CORBA::Any::from_char ) c ;
3176 // theOutPort->Value( D.Value ) ;
3178 else if ( !strcmp( Type , "short" ) ) {
3181 // theOutPort->Value( D.Value ) ;
3183 else if ( !strcmp( Type , "int" ) || !strcmp( Type , "long" ) ) {
3186 // theOutPort->Value( D.Value ) ;
3188 else if ( !strcmp( Type , "float" ) ) {
3191 // theOutPort->Value( D.Value ) ;
3193 else if ( !strcmp( Type , "double" ) ) {
3196 // theOutPort->Value( D.Value ) ;
3198 // else if ( !strcmp( Type , "objref" ) ) {
3200 CORBA::Object_ptr obj ;
3204 retstr = ObjectToString( obj ) ;
3205 #if InParametersSetTrace
3206 cdebug << retstr << endl ;
3213 cdebug << "ToString( object ) Catched ERROR" << endl ;
3217 // cdebug << " (other ERROR)" << endl ;
3219 #if InParametersSetTrace
3220 cdebug << " --> call_kind " << D.Value.type()->kind() << endl ;
3224 cdebug << " (other ERROR) " << D.Value.type()->kind() << endl ;
3228 cdebug << ThreadNo() << " In" << i << " : wrong state ERROR State "
3229 << anInPort->PortState() << " NameState "
3230 << Automaton()->StateName( anInPort->PortState() ) << " PortName "
3231 << anInPort->PortName() << " Parametername "
3232 << anInPort->GetServicesParameter().Parametername << endl ;
3235 InParametersList[i] = D ;
3239 void GraphExecutor::InNode::InOutParametersSet( int nOutParams ,
3240 ServicesAnyData * OutParametersList ) {
3241 #if InParametersSetTrace
3242 cdebug << pthread_self() << "/" << ThreadNo() << " InOutParametersSet " << Name() << endl ;
3245 for ( i = 0 ; i < nOutParams ; i++ ) {
3246 ServicesAnyData D = OutParametersList[i] ;
3248 //JR 18.02.2005 Debug Memory leak : delete does not destroy that string ...
3249 // D.Name = CORBA::string_dup(GetChangeNodeOutPort(i)->GetServicesParameter().Parametername);
3250 D.Name = GetChangeNodeOutPort(i)->PortName() ;
3251 //JR 18.02.2005 Debug Memory leak : string _Type = CORBA::string_dup(GetChangeNodeOutPort(i)->GetServicesParameter().Parametertype) ;
3252 const char * Type = GetChangeNodeOutPort(i)->GetServicesParameter().Parametertype ;
3253 #if InParametersSetTrace
3254 bool OutDone = GetChangeNodeOutPort(i)->PortDone() ;
3255 cdebug << ThreadNo() << " ArgOut" << i << " " << D.Name << " PortDone( " << OutDone << " ) Type : "
3258 if ( !strcmp( Type , "string" ) ) {
3260 D.Value <<= (char *) ch;
3262 else if ( !strcmp( Type , "boolean" ) ) {
3264 D.Value <<= (CORBA::Any::from_boolean ) b ;
3266 else if ( !strcmp( Type , "char" ) ) {
3267 unsigned char c = 0 ;
3268 D.Value <<= (CORBA::Any::from_char ) c ;
3270 else if ( !strcmp( Type , "short" ) ) {
3274 else if ( !strcmp( Type , "int" ) || !strcmp( Type , "long" ) ) {
3275 D.Value <<= (long ) 0 ;
3277 else if ( !strcmp( Type , "float" ) ) {
3281 else if ( !strcmp( Type , "double" ) ) {
3286 D.Value <<= CORBA::Object::_nil() ;
3288 #if InParametersSetTrace
3289 switch (D.Value.type()->kind()) { // { string , long , double , objref }
3290 case CORBA::tk_string:
3293 cdebug << ThreadNo() << " " << t << "(string)" << endl ;
3295 case CORBA::tk_boolean:
3297 D.Value >>= (CORBA::Any::to_boolean ) b;
3298 cdebug << ThreadNo() << " " << b << "(boolean)" << endl ;
3300 case CORBA::tk_char:
3302 D.Value >>= (CORBA::Any::to_char ) c;
3303 cdebug << ThreadNo() << " " << c << "(char)" << endl ;
3305 case CORBA::tk_short:
3308 cdebug << ThreadNo() << " " << s << "(short)" << endl ;
3310 case CORBA::tk_long:
3313 cdebug << ThreadNo() << " " << l << "(long)" << endl ;
3315 case CORBA::tk_float:
3318 cdebug << ThreadNo() << " " << f << "(float)" << endl ;
3320 case CORBA::tk_double:
3323 cdebug << ThreadNo() << " " << d << "(double)" << endl ;
3325 case CORBA::tk_objref:
3327 CORBA::Object_ptr obj ;
3330 retstr = ObjectToString( obj ) ;
3331 cdebug << ThreadNo() << retstr << endl ;
3334 cdebug << "ToString( object ) Catched ERROR" << endl ;
3338 cdebug << ThreadNo() << " " << "(other ERROR)" << endl ;
3341 OutParametersList[i] = D ;
3345 #define OutParametersSetTrace 0
3346 bool GraphExecutor::InNode::OutParametersSet( bool Err ,
3347 SUPERV::GraphState PortState ,
3349 ServicesAnyData * OutParametersList ) {
3350 bool RetVal = true ;
3352 GraphBase::OutPort * aGateOutPort = NULL ;
3353 bool OrSwitch = false ;
3354 bool DefaultSwitch = false ;
3355 #if OutParametersSetTrace
3356 cdebug_in << "OutParametersSet " << Name() << " nOutParams " << nOutParams << " NewPortState "
3357 << PortState << endl ;
3359 // cout << "OutParametersSet " << Name() << " nOutParams " << nOutParams << " NewPortState " << PortState << endl ;
3360 if ( nOutParams && !IsMacroNode() ) {
3361 GraphBase::OutPort * anOutPort ;
3362 for ( i = 0 ; i < nOutParams ; i++ ) {
3363 anOutPort = GetChangeNodeOutPort(i) ;
3365 anOutPort->PortState( PortState ) ;
3366 anOutPort->PortDone( true ) ;
3369 #if OutParametersSetTrace
3370 cdebug << ThreadNo() << "OutParametersSet " << "Out" << i << " " << Name() << " "
3371 << anOutPort->PortName() << " " << anOutPort->Kind() ;
3373 ServicesAnyData D = OutParametersList[i] ;
3374 switch (D.Value.type()->kind()) { // { string , long , double , objref }
3375 case CORBA::tk_string: {
3378 #if OutParametersSetTrace
3379 cdebug << ThreadNo() << " " << t << "(string)" << endl ;
3383 case CORBA::tk_boolean: {
3385 D.Value >>= (CORBA::Any::to_boolean ) b;
3386 long l = (long ) b ;
3388 #if OutParametersSetTrace
3389 cdebug << ThreadNo() << " " << b << "(boolean)" << endl ;
3393 case CORBA::tk_char: {
3395 D.Value >>= (CORBA::Any::to_char ) c;
3396 long l = (long ) c ;
3398 #if OutParametersSetTrace
3399 cdebug << ThreadNo() << " " << c << "(char)" << endl ;
3403 case CORBA::tk_short: {
3406 long l = (long ) s ;
3408 #if OutParametersSetTrace
3409 cdebug << ThreadNo() << " " << s << "(short)" << endl ;
3413 case CORBA::tk_long: {
3416 #if OutParametersSetTrace
3417 cdebug << ThreadNo() << " " << l << "(long)" << endl ;
3421 case CORBA::tk_float: {
3424 double d = (double ) f ;
3426 #if OutParametersSetTrace
3427 cdebug << ThreadNo() << " " << f << "(float)" << endl ;
3431 case CORBA::tk_double: {
3434 #if OutParametersSetTrace
3435 cdebug << ThreadNo() << " " << d << "(double)" << endl ;
3439 case CORBA::tk_objref: {
3441 CORBA::Object_ptr obj ;
3443 #if OutParametersSetTrace
3445 retstr = ObjectToString( obj ) ;
3446 cdebug << ThreadNo() << retstr << endl ;
3450 cdebug << "ToString( object ) Catched ERROR" << endl ;
3456 cdebug << ThreadNo() << " " << "(other ERROR)" << endl ;
3460 OutParametersList[i] = D ;
3461 if ( !anOutPort->IsDataStream() ) {
3462 if ( anOutPort->IsGate() ) {
3463 aGateOutPort = anOutPort ;
3464 #if OutParametersSetTrace
3465 cdebug << " Gate " ;
3468 OutParametersList[i].Value <<= l;
3469 anOutPort->Value( OutParametersList[i].Value );
3471 else if ( anOutPort->IsLoop() ) {
3472 #if OutParametersSetTrace
3473 cdebug << " Loop " ;
3475 anOutPort->Value( OutParametersList[i].Value );
3476 // InLoop Port of EndLoopNode is ready :
3477 anOutPort->ChangeInPorts(0)->PortState( SUPERV::ReadyState ) ;
3479 else if ( anOutPort->IsSwitch() ) {
3480 #if OutParametersSetTrace
3481 cdebug << " Switch " ;
3483 anOutPort->Value( OutParametersList[i].Value );
3484 if ( anOutPort->InPortsSize() && anOutPort->ChangeInPorts( 0 )->IsGate() ) {
3485 //JR 09.02.2005 : OrSwitch is the OR of all SwitchBranches :
3486 //It controls that there is only one SwitchBranch activated
3487 //If it's final value is false ==> activation of the Default to GOTO to EndSwitchNode
3488 //DefaultSwitch is true if a SwitchPort is linked to the DefaultPort of the EndSwitchNode
3489 if ( OrSwitch && anOutPort->BoolValue() ) {
3490 cdebug << "GraphExecutor::InNodeThreads::OutParameters more than one switch is true ERROR"
3494 else if ( anOutPort->BoolValue() ) {
3495 //JR 09.02.2005 Debug : case of a SwitchPort linked to the DefaultPort of the EndSwitchNode :
3496 if ( !strcmp( anOutPort->ChangeInPorts( 0 )->NodeName() , GOTONode()->CoupledNodeName() ) ) {
3497 DefaultSwitch = anOutPort->BoolValue() ;
3500 OrSwitch = OrSwitch | anOutPort->BoolValue() ;
3502 #if OutParametersSetTrace
3503 cdebug << "InNodeThreads::OutParameters OrSwitch " << OrSwitch << "DefaultSwitch "
3504 << DefaultSwitch << endl ;
3510 #if OutParametersSetTrace
3511 cdebug << " Param " ;
3513 anOutPort->Value( OutParametersList[i].Value );
3515 anOutPort->PortState( PortState ) ;
3516 anOutPort->PortDone( true ) ;
3518 #if OutParametersSetTrace
3519 cdebug << "OutParametersSet OrSwitch " << OrSwitch << "DefaultSwitch "
3520 << DefaultSwitch << endl ;
3523 for ( j = 0 ; j < anOutPort->InPortsSize() ; j++ ) {
3524 #if OutParametersSetTrace
3525 cdebug << ThreadNo() << "OutParametersSet " << "Out" << i << " " << Name() << " "
3526 << anOutPort->PortName() << " " << anOutPort->Kind() << " --> "
3527 << anOutPort->ChangeInPorts( j )->NodeName() << "( "
3528 << anOutPort->ChangeInPorts( j )->PortName() << anOutPort->ChangeInPorts( j )->Kind()
3531 bool fromGOTO = false ;
3532 const char * ToNodeName = anOutPort->ChangeInPorts( j )->NodeName() ;
3533 if ( !strcmp( ToNodeName , _OutNode->Graph()->Name() ) && _OutNode->Graph()->GraphMacroLevel() != 0 ) {
3534 #if OutParametersSetTrace
3535 cdebug << "OutParametersSet ToNodeName " << _OutNode->Graph()->Name() << " CoupledNode "
3536 << _OutNode->Graph()->CoupledNodeName() << _OutNode->Graph()->CoupledNode()
3538 cdebug << " GraphExecutor " << _OutNode->Graph()->CoupledNode()->GraphEditor()->Executor() << endl ;
3540 _OutNode->Graph()->CoupledNode()->GraphEditor()->Executor()->OutputOfAny( _OutNode->Graph()->CoupledNodeName() ,
3541 anOutPort->ChangeInPorts( j )->PortName() ,
3542 //JR 30.03.2005 *anOutPort->Value() ) ;
3543 anOutPort->Value() ) ;
3546 GraphBase::ComputingNode * ToNode = _OutNode->Graph()->GetChangeGraphNode( ToNodeName ) ;
3548 // cout << "OutParametersSet ToNodeName " << ToNodeName << endl ;
3549 // cdebug << "OutParametersSet ToNodeName " << ToNodeName << " " << ToNode->Name() << endl ;
3550 GraphBase::OutPort * aGOTOPort = ToNode->GetChangeNodeInGate()->GetOutPort() ;
3552 fromGOTO = aGOTOPort->IsGOTO() ;
3554 if ( anOutPort->ChangeInPorts( j )->IsEndSwitch() || fromGOTO ) {
3555 #if OutParametersSetTrace
3556 cdebug << anOutPort->ChangeInPorts( j )->NodeName() << "("
3557 << anOutPort->ChangeInPorts( j )->PortName() << ","
3558 << anOutPort->ChangeInPorts( j )->Kind() << ") CHANGED from "
3559 << anOutPort->ChangeInPorts( j )->GetOutPort()->NodeName()
3561 << anOutPort->ChangeInPorts( j )->GetOutPort()->PortName()
3562 << " to " << anOutPort->ChangeInPorts( j )->GetOutPort()->Kind()
3563 << ") : Done " << anOutPort->PortDone() << " State "
3564 << Automaton()->StateName( anOutPort->ChangeInPorts( j )->PortState() ) << endl ;
3566 anOutPort->ChangeInPorts( j )->ChangeOutPort( anOutPort ) ;
3569 #if OutParametersSetTrace
3570 cdebug << anOutPort->ChangeInPorts( j )->NodeName() << "("
3571 << anOutPort->ChangeInPorts( j )->PortName() << ","
3572 << anOutPort->ChangeInPorts( j )->Kind() << ") NOT changed from "
3573 << anOutPort->ChangeInPorts( j )->GetOutPort()->NodeName()
3575 << anOutPort->ChangeInPorts( j )->GetOutPort()->PortName()
3576 << " " << anOutPort->ChangeInPorts( j )->GetOutPort()->Kind()
3583 #if OutParametersSetTrace
3584 switch ( anOutPort->Value().type()->kind() ) {
3585 case CORBA::tk_string:
3587 anOutPort->Value() >>= t;
3588 cdebug << ThreadNo() << " Out" << i << " : " << t << "(string)" << endl ;
3590 case CORBA::tk_boolean:
3592 anOutPort->Value() >>= (CORBA::Any::to_boolean ) b;
3593 cdebug << ThreadNo() << " Out" << i << " : " << b << "(boolean)" << endl ;
3595 case CORBA::tk_char:
3597 anOutPort->Value() >>= (CORBA::Any::to_char ) c;
3598 cdebug << ThreadNo() << " Out" << i << " : " << c << "(char)" << endl ;
3600 case CORBA::tk_short:
3602 anOutPort->Value() >>= s;
3603 cdebug << ThreadNo() << " Out" << i << " : " << s << "(short)" << endl ;
3605 case CORBA::tk_long:
3607 anOutPort->Value() >>= l;
3608 cdebug << ThreadNo() << " Out" << i << " : " << l << "(long)" << endl ;
3610 case CORBA::tk_float:
3612 anOutPort->Value() >>= f;
3613 cdebug << ThreadNo() << " Out" << i << " : " << f << "(float)" << endl ;
3615 case CORBA::tk_double:
3617 anOutPort->Value() >>= d;
3618 cdebug << ThreadNo() << " Out" << i << " : " << d << "(double)" << endl ;
3620 case CORBA::tk_objref:
3621 CORBA::Object_ptr obj ;
3624 anOutPort->Value() >>= obj ;
3625 retstr = ObjectToString( obj );
3626 cdebug << ThreadNo() << " Out" << i << " : " << "ToString( object ) "
3630 cdebug << ThreadNo() << " Out" << i << " : " << "ToString( object ) "
3631 << "Catched ERROR" << endl ;
3636 cdebug << ThreadNo() << " Out" << i << " : " << "(other ERROR)" << endl ;
3642 if ( aGateOutPort && IsSwitchNode() ) {
3643 //JR 09.02.2005 : OrSwitch is the OR of all SwitchBranches :
3644 //It controls that there is only one SwitchBranch activated
3645 //If it's final value is false ==> activation of the Default to GOTO to EndSwitchNode
3646 //DefaultSwitch is true if a SwitchPort (SwitchBranch) is linked to the DefaultPort of the EndSwitchNode
3647 if ( !OrSwitch && !DefaultSwitch ) {
3648 if ( aGateOutPort->InPortsSize() && aGateOutPort->ChangeInPorts( 0 ) ) {
3649 #if OutParametersSetTrace
3650 cdebug << ThreadNo() << " " << "OutGate " << Name() << " Open of "
3651 << aGateOutPort->PortName() << " " << aGateOutPort->Kind() << " WITH DefaultPort" << endl ;
3654 OutParametersList[0].Value <<= l ;
3655 aGateOutPort->Value( OutParametersList[0].Value ) ;
3658 #if OutParametersSetTrace
3659 cdebug << ThreadNo() << " " << "OutGate " << Name() << " "
3660 << aGateOutPort->PortName() << " " << aGateOutPort->Kind() << " NOT CONNECTED ERROR" << endl ;
3665 //JR 07.04.2005 Debug : reset only if it is not a default switch (SwitchBranch or
3666 // SwitchParameter of SwitchNode connected to the InDefaultPort of
3669 else if ( !DefaultSwitch ) {
3670 #if OutParametersSetTrace
3671 cdebug << ThreadNo() << " " << "OutGate " << Name() << " Close of "
3672 << aGateOutPort->PortName() << " " << aGateOutPort->Kind() << " NO DefaultPort"
3673 << " OrSwitch " << OrSwitch << " DefaultSwitch " << DefaultSwitch << endl ;
3676 OutParametersList[0].Value <<= l ;
3677 aGateOutPort->Value( OutParametersList[0].Value ) ;
3679 if ( !OrSwitch || DefaultSwitch ) { // DefaultPort or DefaultSwitch
3681 for ( i = 0 ; i < GetNodeOutPortsSize() ; i++ ) {
3682 GraphBase::InPort * anInPort ;
3683 anInPort = CoupledNode()->GetChangeInPort( GetNodeOutPort( i )->PortName() ) ;
3685 //JR 16.02.2005 Debug : Change InPorts of EndSwitchNode that have the same name as an OutPort of
3686 // the SwitchNode even if it is the DefaultPort : GraphSwitchCheckDefault1.xml
3687 // if ( anInPort && !anInPort->IsGate() ) {
3688 if ( anInPort && anInPort->GetOutPort() ) {
3689 #if OutParametersSetTrace
3690 cdebug << "OutParametersSet " << Name() << " " << anInPort->NodeName() << "( "
3691 << anInPort->PortName() << " ) linked from " << anInPort->GetOutPort()->NodeName()
3692 << "( " << anInPort->GetOutPort()->PortName() << " ) CHANGED TO linked from "
3693 << GetChangeNodeOutPort( i )->NodeName() << "( "
3694 << GetChangeNodeOutPort( i )->PortName() << " )" << endl ;
3696 anInPort->ChangeOutPort( GetChangeNodeOutPort( i ) ) ;
3702 #if OutParametersSetTrace
3703 cdebug_out << "OutParametersSet " << Name() << " nOutParams " << nOutParams << " NewPortState "
3704 << PortState << " RetVal " << RetVal << endl ;