1 // SUPERV GraphExecutor : contains classes that permit execution of graphs and particularly the execution automaton
3 // Copyright (C) 2003 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
6 // This library is free software; you can redistribute it and/or
7 // modify it under the terms of the GNU Lesser General Public
8 // License as published by the Free Software Foundation; either
9 // version 2.1 of the License.
11 // This library is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 // Lesser General Public License for more details.
16 // You should have received a copy of the GNU Lesser General Public
17 // License along with this library; if not, write to the Free Software
18 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20 // See http://www.opencascade.org/SALOME/ or email : webmaster.salome@opencascade.org
24 // File : DataFlowBase_InNodeThreads.cxx
25 // Author : Jean Rahuel, CEA
42 #if defined __GNUC_2__
43 // _CS_gbo_040604 include explicite pour l'utilisation de
44 // std::transform dans UpperCase
45 #include <cctype> // for toupper
46 #include <algorithm> // for transform
53 #include <SALOMEconfig.h>
54 #include CORBA_CLIENT_HEADER(SALOME_Component)
55 #include "SALOME_LifeCycleCORBA.hxx"
57 #include "DataFlowExecutor_DataFlow.hxx"
58 #include "DataFlowEditor_DataFlow.hxx" // GraphEditor package must be built BEFORE
61 static void UpperCase(std::string& rstr)
63 #if defined __GNUC_2__
64 // _CS_gbo_040604 towupper n'existe pas. Utilisation de toupper. Par
65 // ailleurs, include explicite de cctype et algorithm pour toupper
66 // et transform respectivement.
67 std::transform(rstr.begin(), rstr.end(), rstr.begin(),toupper);
69 std::transform(rstr.begin(), rstr.end(), rstr.begin(),towupper);
74 int GraphExecutor::InNode::SendEvent( const GraphExecutor::NodeEvent anEvent ) {
76 _CurrentEvent = (GraphExecutor::NodeEvent ) anEvent ;
77 cdebug_in << pthread_self() << "/" << ThreadNo() << " -->SendEvent Node " << Name()
79 << Automaton()->ControlStateName( ControlState() )
80 << " Event : " << Automaton()->EventName( anEvent )
81 << " State : " << Automaton()->StateName( State() ) << " _RewindStack " << _RewindStack << endl;
84 _NextState = Automaton()->NextState( _OldState , anEvent ) ;
85 if ( _NextState == _OldState ) {
86 cdebug << pthread_self() << "/" << ThreadNo()
87 << " GraphExecutor::InNodeThreads::SendEvent SameStates "
88 << _OldState << endl ;
89 _NextAction = GraphExecutor::VoidAction ;
92 _NextAction = Automaton()->NextAction( _NextState , anEvent ) ;
95 // State( _NextState ) ;
96 // if ( _OldState == GraphExecutor::SuccessedExecutingState ||
97 // _OldState == GraphExecutor::ErroredExecutingState ) {
101 cdebug << pthread_self() << "/" << ThreadNo() << " SendedEvent Node "
102 << Name() << endl << " ControlState : "
103 << Automaton()->ControlStateName( ControlState() ) << endl
104 << " OldState : " << Automaton()->StateName( _OldState ) << endl
105 << " Event : " << Automaton()->EventName( anEvent ) << endl
106 << " NextState : " << Automaton()->StateName( _NextState ) << endl
107 << " Action : " << Automaton()->ActionName( _NextAction ) << endl
108 << " CreateNewThread " << CreateNewThread() << endl
109 << " _RewindStack " << _RewindStack << endl ;
111 int sts = executeAction() ;
113 // cdebug_out << pthread_self() << "/" << ThreadNo() << " <--- SendEvent Node " << Name()
114 // << " Event : " << Automaton()->EventName( anEvent )
115 // << " State : " << Automaton()->StateName( State() )
122 // ReadyAction - RunningAction - DoneAction - SuspendedAction :
123 // for StateWait( ReadyW - RunningW - DoneW - SuspendedW )
124 void GraphExecutor::InNode::ReadyAction() {
125 if ( pthread_mutex_lock( &_MutexWait ) ) {
126 perror("Ready pthread_mutex_lock ") ;
129 cdebug << pthread_self() << "/" << ThreadNo()
130 << "ReadyAction pthread_cond_broadcast _ReadyWait "
132 if ( pthread_cond_broadcast( &_ReadyWait ) ) {
133 perror("Ready pthread_cond_broadcast ") ;
135 if ( pthread_mutex_unlock( &_MutexWait ) ) {
136 perror("Ready pthread_mutex_unlock ") ;
141 void GraphExecutor::InNode::RunningAction() {
142 if ( pthread_mutex_lock( &_MutexWait ) ) {
143 perror("Running pthread_mutex_lock ") ;
146 cdebug << pthread_self() << "/" << ThreadNo()
147 << "RunningAction pthread_cond_broadcast _RunningWait "
149 // That activate the pthread_cond_wait for RunninWait
150 if ( pthread_cond_broadcast( &_RunningWait ) ) {
151 perror("Running pthread_cond_broadcast ") ;
153 if ( pthread_mutex_unlock( &_MutexWait ) ) {
154 perror("Running pthread_mutex_unlock ") ;
159 void GraphExecutor::InNode::DoneAction() {
160 if ( pthread_mutex_lock( &_MutexWait ) ) {
161 perror("Done pthread_mutex_lock ") ;
164 cdebug << pthread_self() << "/" << ThreadNo()
165 << "DoneAction pthread_cond_broadcast _DoneWait "
167 if ( pthread_cond_broadcast( &_DoneWait ) ) {
168 perror("Done pthread_cond_broadcast ") ;
170 if ( pthread_mutex_unlock( &_MutexWait ) ) {
171 perror("Done pthread_mutex_unlock ") ;
176 void GraphExecutor::InNode::SuspendedAction() {
177 if ( pthread_mutex_lock( &_MutexWait ) ) {
178 perror("Suspended pthread_mutex_lock ") ;
181 cdebug << pthread_self() << "/" << ThreadNo()
182 << "SuspendedAction pthread_cond_broadcast _SuspendedWait "
184 if ( pthread_cond_broadcast( &_SuspendedWait ) ) {
185 perror("Suspended pthread_cond_broadcast ") ;
187 if ( pthread_mutex_unlock( &_MutexWait ) ) {
188 perror("Suspended pthread_mutex_unlock ") ;
193 // SuspendAction <--> { ResumeAction - ReStartAction }
194 GraphExecutor::InNode * GraphExecutor::InNode::SuspendAction() {
196 if ( pthread_mutex_lock( &_MutexWait ) ) {
197 perror("Suspend pthread_mutex_lock ") ;
200 if ( !_SuspendSync ) {
201 cdebug << pthread_self() << "/" << ThreadNo() << " pthread_cond " << Name()
202 << " SuspendAction pthread_cond_wait _SuspendWait "
203 << Automaton()->StateName( State() ) << endl ;
204 _SuspendSync = true ;
205 _OutNode->SuspendThread() ;
206 if ( pthread_cond_wait( &_SuspendWait , &_MutexWait ) ) {
207 perror("SuspendAction pthread_cond_wait ") ;
209 _OutNode->ResumeThread() ;
210 cdebug << pthread_self() << "/" << ThreadNo() << " pthread_cond " << Name()
211 << " SuspendAction pthread_cond_waited"
212 << Automaton()->StateName( State() ) << endl ;
215 cdebug << pthread_self() << "/" << ThreadNo() << " pthread_cond " << Name()
216 << " NO SuspendAction pthread_cond_wait"
217 << Automaton()->StateName( State() ) << endl ;
219 // SendEvent( _aResumeEvent ) ; ===> Mutex with myself !
220 _SuspendSync = false ;
221 if ( ControlState() == SUPERV::ToSuspendStartState ||
222 ControlState() == SUPERV::ToSuspendState ) {
223 ControlState( SUPERV::VoidState ) ;
225 if ( pthread_mutex_unlock( &_MutexWait ) ) {
226 perror("SuspendAction pthread_mutex_unlock ") ;
230 SendEvent( _aResumeEvent ) ;
231 // if ( ControlState() == SUPERV::ToSuspendStartState ) {
232 // ControlState( SUPERV::VoidState ) ;
235 if ( pthread_mutex_lock( &_MutexWait ) ) {
236 perror("SuspendAction pthread_mutex_lock ") ;
240 cdebug << pthread_self() << "/" << ThreadNo() << " pthread_cond " << Name()
241 << " SuspendAction pthread_cond_signal _ResumeWait" << endl ;
242 if ( pthread_cond_signal( &_ResumeWait ) ) {
243 perror("SuspendAction pthread_cond_signal _ResumeWait ") ;
245 cdebug << pthread_self() << "/" << ThreadNo() << " pthread_cond " << Name()
246 << " SuspendAction pthread_cond_signaled _ResumeWait " << endl ;
249 cdebug << pthread_self() << "/" << ThreadNo() << " pthread_cond " << Name()
250 << " NO SuspendAction pthread_cond_signal _ResumeWait" << endl ;
253 if ( pthread_mutex_unlock( &_MutexWait ) ) {
254 perror("SuspendAction pthread_mutex_unlock ") ;
257 if ( _aReStartNode ) {
258 cdebug << Name() << " " << Automaton()->StateName( State() )
259 << "aReStartNode : " << _aReStartNode->Name() << " "
260 << Automaton()->StateName( _aReStartNode->State() ) << endl ;
261 _aReStartNode->SendEvent( _aResumeEvent ) ;
264 cdebug << "NO aReStartNode"
265 << Automaton()->StateName( State() ) << endl ;
267 return _aReStartNode ;
270 bool GraphExecutor::InNode::ResumeAction( GraphExecutor::NodeEvent aResumeEvent ) {
272 if ( pthread_mutex_lock( &_MutexWait ) ) {
273 perror("ResumeAction pthread_mutex_lock ") ;
276 _aResumeEvent = aResumeEvent ;
277 if ( _SuspendSync ) {
278 cdebug << pthread_self() << "/" << ThreadNo() << " pthread_cond " << Name()
279 << " ResumeAction pthread_cond_signal" << endl ;
280 if ( pthread_cond_signal( &_SuspendWait ) ) {
281 perror("ResumeAction pthread_cond_signal ") ;
283 cdebug << pthread_self() << "/" << ThreadNo() << " pthread_cond " << Name()
284 << " ResumeAction pthread_cond_signaled _SuspendWait " << endl ;
288 cdebug << pthread_self() << "/" << ThreadNo() << " pthread_cond " << Name()
289 << " NO ResumeAction pthread_cond_signal" << endl ;
290 if ( pthread_self() == ThreadNo() ) {
291 RetVal = false ; /*/ Ne pas s'attendre soi-meme !...*/
294 _SuspendSync = true ;
295 RetVal = true ; // Il faut tout de meme attendre ci-apres ...
298 if ( pthread_mutex_unlock( &_MutexWait ) ) {
299 perror("ResumeAction pthread_mutex_unlock ") ;
304 if ( pthread_mutex_lock( &_MutexWait ) ) {
305 perror("ResumeAction pthread_mutex_lock ") ;
308 if ( !_ResumeSync ) {
309 cdebug << pthread_self() << "/" << ThreadNo() << " pthread_cond "
310 << Name() << " ResumeAction pthread_cond_wait _ResumeWait "
311 << Automaton()->StateName( State() ) << endl ;
313 if ( pthread_cond_wait( &_ResumeWait , &_MutexWait ) ) {
314 perror("ResumeAction pthread_cond_wait ") ;
316 cdebug << pthread_self() << "/" << ThreadNo() << " pthread_cond "
317 << Name() << " ResumeAction pthread_cond_waited _ResumeWait"
318 << Automaton()->StateName( State() ) << endl ;
322 cdebug << pthread_self() << "/" << ThreadNo() << " pthread_cond "
323 << Name() << " NO ResumeAction pthread_cond_wait _ResumeWait"
324 << Automaton()->StateName( State() ) << endl ;
327 _ResumeSync = false ;
328 if ( pthread_mutex_unlock( &_MutexWait ) ) {
329 perror("ResumeAction pthread_mutex_unlock ") ;
333 cdebug << pthread_self() << "/" << ThreadNo()
334 << "GraphExecutor::InNodeThreads::ResumeAction RetVal " << RetVal << endl ;
338 bool GraphExecutor::InNode::ReStartAction( GraphExecutor::InNode * aReStartNode ,
339 GraphExecutor::NodeEvent anEvent ) {
340 GraphExecutor::InNode * oldReStartNode = _aReStartNode ;
341 _aReStartNode = aReStartNode ;
342 _aReStartEvent = anEvent ;
343 cdebug << pthread_self() << " GraphExecutor::InNodeThreads::ReStartAction from "
344 << Name() << " " << Automaton()->StateName( State() ) << " to "
345 << aReStartNode->ThreadNo() << " " << aReStartNode->Name() << " "
346 << Automaton()->StateName( aReStartNode->State() ) ;
347 if ( oldReStartNode ) {
348 cdebug << " oldReStartNode " << oldReStartNode->Name() << endl ;
353 return ResumeAction( GraphExecutor::ToReStartEvent ) ;
356 void GraphExecutor::InNode::KilledAction() {
357 if ( pthread_mutex_lock( &_MutexWait ) ) {
358 perror("Killed pthread_mutex_lock ") ;
362 cdebug << "pthread_cond " << Name() << " Killed pthread_cond_wait"
365 if ( pthread_cond_wait( &_KillWait , &_MutexWait ) ) {
366 perror("Killed pthread_cond_wait ") ;
368 cdebug << "pthread_cond " << Name() << " Killed pthread_cond_waited"
372 cdebug << "pthread_cond " << Name() << " NO Killed pthread_cond_wait"
376 if ( pthread_mutex_unlock( &_MutexWait ) ) {
377 perror("Killed pthread_mutex_unlock ") ;
382 void GraphExecutor::InNode::KillAction() {
383 if ( pthread_mutex_lock( &_MutexWait ) ) {
384 perror("Kill pthread_mutex_lock ") ;
388 cdebug << "pthread_cond " << Name() << " Kill pthread_cond_signal"
390 // if ( pthread_cond_broadcast( &_KillWait ) ) {
391 if ( pthread_cond_signal( &_KillWait ) ) {
392 perror("Kill pthread_cond_broadcast ") ;
394 cdebug << "pthread_cond " << Name() << " Kill pthread_cond_signaled"
398 cdebug << "pthread_cond " << Name() << " NO Kill pthread_cond_signal"
402 if ( pthread_mutex_unlock( &_MutexWait ) ) {
403 perror("Kill pthread_mutex_unlock ") ;
408 void GraphExecutor::InNode::StoppedAction() {
409 if ( pthread_mutex_lock( &_MutexWait ) ) {
410 perror("Stopped pthread_mutex_lock ") ;
413 if ( pthread_cond_wait( &_StopWait , &_MutexWait ) ) {
414 perror("Stopped pthread_cond_wait ") ;
416 if ( pthread_mutex_unlock( &_MutexWait ) ) {
417 perror("Stopped pthread_mutex_unlock ") ;
422 void GraphExecutor::InNode::StopAction() {
423 if ( pthread_mutex_lock( &_MutexWait ) ) {
424 perror("Stop pthread_mutex_lock ") ;
427 if ( pthread_cond_broadcast( &_StopWait ) ) {
428 perror("Stop pthread_cond_broadcast ") ;
430 if ( pthread_mutex_unlock( &_MutexWait ) ) {
431 perror("Stop pthread_mutex_unlock ") ;
436 void GraphExecutor::InNode::ThreadStartedAction() {
437 if ( pthread_mutex_lock( &_MutexWait ) ) {
438 perror("ThreadStarted pthread_mutex_lock ") ;
441 if ( !_ThreadStartedSync ) {
442 cdebug << pthread_self() << "/" << ThreadNo()
443 << "pthread_cond " << Name() << " ThreadStarted pthread_cond_wait"
445 _ThreadStartedSync = true ;
446 if ( pthread_cond_wait( &_ThreadStartedWait , &_MutexWait ) ) {
447 perror("ThreadStarted pthread_cond_wait ") ;
449 cdebug << pthread_self() << "/" << ThreadNo()
450 << "pthread_cond " << Name() << " ThreadStarted pthread_cond_waited"
454 cdebug << pthread_self() << "/" << ThreadNo()
455 << "pthread_cond " << Name() << " NO ThreadStarted pthread_cond_wait"
458 _ThreadStartedSync = false ;
459 if ( pthread_cond_signal( &_ThreadStartedWait ) ) {
460 perror("ThreadStart pthread_cond_signal ") ;
463 cdebug << pthread_self() << "/" << ThreadNo()
464 << "pthread_cond " << Name() << " NO ThreadStarted pthread_cond_signaled"
467 if ( pthread_mutex_unlock( &_MutexWait ) ) {
468 perror("ThreadStarted pthread_mutex_unlock ") ;
473 void GraphExecutor::InNode::ThreadStartAction() {
474 if ( pthread_mutex_lock( &_MutexWait ) ) {
475 perror("ThreadStart pthread_mutex_lock ") ;
478 if ( _ThreadStartedSync ) {
479 cdebug << pthread_self() << "/" << ThreadNo()
480 << "pthread_cond " << Name() << " ThreadStart pthread_cond_signal"
482 _ThreadStartedSync = false ;
483 if ( pthread_cond_signal( &_ThreadStartedWait ) ) {
484 perror("ThreadStart pthread_cond_broadcast ") ;
486 cdebug << pthread_self() << "/" << ThreadNo()
487 << "pthread_cond " << Name() << " ThreadStart pthread_cond_signaled"
491 cdebug << pthread_self() << "/" << ThreadNo()
492 << "pthread_cond " << Name() << " NO ThreadStart pthread_cond_signal"
494 _ThreadStartedSync = true ;
496 if ( pthread_cond_wait( &_ThreadStartedWait , &_MutexWait ) ) {
497 perror("ThreadStarted pthread_cond_wait ") ;
500 cdebug << pthread_self() << "/" << ThreadNo()
501 << "pthread_cond " << Name() << " NO ThreadStart pthread_cond_waited"
504 if ( pthread_mutex_unlock( &_MutexWait ) ) {
505 perror("ThreadStart pthread_mutex_unlock ") ;
510 int GraphExecutor::InNode::executeAction() {
511 int oldRewindStack = ( _RewindStack > MAXSTACKTHREADSIZE ) ;
512 if ( !CreateNewThread() && oldRewindStack ) {
513 cdebug << pthread_self() << "/" << ThreadNo()
514 << " executeAction start Thread _RewindStack " << _RewindStack << " > "
515 << MAXSTACKTHREADSIZE << " CreateNewThread "
516 << CreateNewThread() << " " << Automaton()->ActionName( _NextAction ) << "(" << Name() << ")"
518 CreateNewThread( true ) ;
519 _OutNode->IncrCreatedThreads() ;
522 if ( CreateNewThread() ) {
523 CreateNewThread( false ) ;
524 if ( ThreadNo() == 0 ) {
526 cdebug << pthread_self() << "/" << ThreadNo()
527 << " executeAction start Thread _RewindStack " << _RewindStack << " "
528 << Automaton()->ActionName( _NextAction ) << "(" << Name() << ")"
531 int pthread_sts = 1 ;
532 // _OutNode->PushEvent( NULL , GraphExecutor::NewThreadEvent ,
533 // GraphExecutor::ExecutingState ) ;
534 while ( (pthread_sts = pthread_create(&T, NULL, run_function, this )) ) {
535 char * msg = "Cannot pthread_create " ;
537 cdebug << ThreadNo() << " " << msg << " --> sleep(5)" << endl ;
538 cdebug << ThreadNo() << " PTHREAD_THREADS_MAX : "
539 << PTHREAD_THREADS_MAX << " pthread_create status : " ;
540 if ( pthread_sts == EAGAIN ) {
541 cdebug << "EAGAIN(" << pthread_sts << ")" << endl ;
542 cdebug << _OutNode->CreatedThreads() << " was created (and exited)" << endl ;
543 cdebug << "It seems to me that with gdb we are limited to 256 threads" << endl ;
546 cdebug << pthread_sts << endl ;
550 pthread_exit( msg ) ;
552 cdebug << pthread_self() << "/" << ThreadNo()
553 << "executeAction has created thread " << T << endl ;
554 ThreadStartedAction() ;
555 cdebug << pthread_self() << "/" << ThreadNo()
556 << "executeAction the thread " << T << " has called NewThread and will call ExecuteAction for node "
560 cdebug << pthread_self() << "/" << ThreadNo()
561 << " executeAction restart Thread _RewindStack " << _RewindStack << " "
562 << Automaton()->StateName( State() ) << " "
563 << Automaton()->ActionName( _NextAction ) << "(" << Name()
564 << ") ReStartAction ==>" << endl;
565 State( GraphExecutor::SuspendedSuccessedState ) ;
566 if ( !ReStartAction( this , GraphExecutor::ReStartEvent ) ) {
567 cdebug << pthread_self() << "/" << ThreadNo()
568 << " executeAction STATE & CALLED "
569 << Automaton()->ActionName( _NextAction ) << "(" << Name()
570 << ") ERROR-DEBUG " << endl;
573 cdebug << pthread_self() << "/" << ThreadNo() << " executeAction NO CALL "
574 << Automaton()->ActionName( _NextAction ) << "(" << Name()
580 if ( _CurrentEvent == ExecuteEvent ) {
583 cdebug << pthread_self() << "/" << ThreadNo() << " executeAction call "
584 << Automaton()->ActionName( _NextAction ) << "(" << Name() << ") _RewindStack " << _RewindStack
586 return ExecuteAction() ;
591 void GraphExecutor::InNode::coutbegin() {
592 cdebug << pthread_self() << "/" << ThreadNo() << " run_function begin"
593 << " " << Name() << " " << Automaton()->StateName( State() ) << endl ;
595 void GraphExecutor::InNode::coutexit() {
596 cdebug << pthread_self() << "/" << ThreadNo() << " run_function pthread_exit _RewindStack " << _RewindStack
597 << " " << Name() << " " << Automaton()->StateName( State() ) << endl ;
599 void * run_function(void *p) {
600 GraphExecutor::InNode *aNode = (GraphExecutor::InNode *) p;
602 aNode->NewThread( pthread_self() ) ;
603 if ( pthread_setcanceltype( PTHREAD_CANCEL_ASYNCHRONOUS , NULL ) ) {
604 perror("pthread_setcanceltype ") ;
607 if ( pthread_setcancelstate( PTHREAD_CANCEL_ENABLE , NULL ) ) {
608 perror("pthread_setcancelstate ") ;
611 aNode->ThreadStartAction() ;
612 // cout << "run_function " << aNode->Name() << "->ExecuteAction() Coupled : " << aNode->CoupledNode()
614 aNode->ExecuteAction() ;
615 char * msg = new char[40] ;
616 sprintf( msg , "%d" , (int ) aNode->ThreadNo() ) ;
617 strcat( msg , " thread exit" ) ;
619 aNode->ExitThread() ;
622 pthread_exit( (void * ) smsg.c_str() ) ;
626 int GraphExecutor::InNode::ExecuteAction() {
629 const char * nextactionname = Automaton()->ActionName( _NextAction ) ;
630 const char * statename = Automaton()->StateName( State() ) ;
631 const char * nextstatename = Automaton()->StateName( _NextState ) ;
632 cdebug_in << pthread_self() << "/" << ThreadNo() << " --> ExecuteAction "
633 << nextactionname << " " << statename << " NextState "
634 << nextstatename << endl ;
636 State( _NextState ) ;
637 switch ( _NextAction ) {
638 case GraphExecutor::ErrorAction : {
639 sts = ErrorAction() ;
642 case GraphExecutor::VoidAction : {
646 case GraphExecutor::DataWaiting_SomeDataReadyAction : {
647 sts = DataWaiting_SomeDataReadyAction() ;
650 case GraphExecutor::DataUndef_NotAllDataReadyAction : {
651 sts = DataUndef_NotAllDataReadyAction() ;
654 case GraphExecutor::DataUndef_AllDataReadyAction : {
655 sts = DataUndef_AllDataReadyAction() ;
658 case GraphExecutor::DataReady_SuspendAction : {
659 sts = DataReady_SuspendAction() ;
662 case GraphExecutor::SuspendedReady_ResumeAction : {
663 sts = SuspendedReady_ResumeAction() ;
666 case GraphExecutor::DataReady_KillAction : {
667 sts = DataReady_KillAction() ;
670 case GraphExecutor::DataReady_StopAction : {
671 sts = DataReady_StopAction() ;
674 case GraphExecutor::DataReady_ExecuteAction : {
675 sts = DataReady_ExecuteAction() ;
678 case GraphExecutor::Executing_SuspendAction : {
679 sts = Executing_SuspendAction() ;
682 case GraphExecutor::SuspendedExecuting_ResumeAction : {
683 sts = SuspendedExecuting_ResumeAction() ;
686 case GraphExecutor::Executing_KillAction : {
687 sts = Executing_KillAction() ;
690 case GraphExecutor::Executing_StopAction : {
691 sts = Executing_StopAction() ;
694 case GraphExecutor::Executing_SuccessAction : {
695 sts = Executing_SuccessAction() ;
698 case GraphExecutor::Executing_ErrorAction : {
699 sts = Executing_ErrorAction() ;
702 case GraphExecutor::Successed_SuccessAction : {
703 sts = Successed_SuccessAction() ;
706 case GraphExecutor::Errored_ErrorAction : {
707 sts = Errored_ErrorAction() ;
710 case GraphExecutor::Successed_SuspendAction : {
711 sts = Successed_SuspendAction() ;
714 case GraphExecutor::Errored_SuspendAction : {
715 sts = Errored_SuspendAction() ;
718 case GraphExecutor::SuspendedSuccessed_ResumeAction : {
719 sts = SuspendedSuccessed_ResumeAction() ;
722 case GraphExecutor::SuspendedErrored_ResumeAction : {
723 sts = SuspendedErrored_ResumeAction() ;
726 case GraphExecutor::Successed_KillAction : {
727 sts = Successed_KillAction() ;
730 case GraphExecutor::Errored_KillAction : {
731 sts = Errored_KillAction() ;
734 case GraphExecutor::Successed_StopAction : {
735 sts = Successed_StopAction() ;
738 case GraphExecutor::Errored_StopAction : {
739 sts = Errored_StopAction() ;
742 case GraphExecutor::SuspendedSuccessed_ReStartAction : {
743 sts = SuspendedSuccessed_ReStartAction() ;
746 case GraphExecutor::SuspendedErrored_ReStartAction : {
747 sts = SuspendedErrored_ReStartAction() ;
750 case GraphExecutor::SuspendedSuccessed_ReStartAndSuspendAction : {
751 sts = SuspendedSuccessed_ReStartAndSuspendAction() ;
754 case GraphExecutor::SuspendedErrored_ReStartAndSuspendAction : {
755 sts = SuspendedErrored_ReStartAndSuspendAction() ;
759 cdebug << pthread_self() << "/" << ThreadNo()
760 << " GraphExecutor::InNodeThreads::SendEvent Error Undefined Action : "
761 << _NextAction << endl ;
765 // cdebug_out << pthread_self() << "/" << ThreadNo() << "<-- ExecuteAction "
766 // << nextactionname << endl ;
770 int GraphExecutor::InNode::ErrorAction() {
771 cdebug << pthread_self() << "/" << ThreadNo() << " Automaton ErrorAction Node "
776 int GraphExecutor::InNode::VoidAction() {
777 cdebug << pthread_self() << "/" << ThreadNo() << " VoidAction " << Name() << endl;
782 int GraphExecutor::InNode::DataWaiting_SomeDataReadyAction() {
783 cdebug << pthread_self() << "/" << ThreadNo()
784 << " --> DataWaiting_SomeDataReadyAction from " << DataFromNode()
785 << " to " << Name() << endl;
789 bool LoopBeginning = false ;
790 bool LoopFinished = false ;
791 bool SwitchFinished = false ;
793 if ( IsLoopNode() ) {
794 GraphBase::OutPort * anOutLoopPort = GetChangeNodeInLoop()->GetOutPort() ; // DoLoop Port
795 if ( anOutLoopPort && anOutLoopPort->BoolValue() ) {
796 LoopBeginning = true ; // Beginning of Loop
799 if ( IsEndLoopNode() ) {
800 GraphBase::OutPort * anOutLoopPort = GetChangeNodeInLoop()->GetOutPort() ; // DoLoop Port
801 if ( anOutLoopPort && !anOutLoopPort->BoolValue() ) {
802 LoopFinished = true ; // End of Loop
805 if ( IsEndSwitchNode() && strcmp( GOTONode()->CoupledNode()->Name() , DataFromNode() ) ) {
806 GraphBase::OutPort * anOutGateSwitchPort = GetChangeNodeInGate()->GetOutPort() ; // Default Port
807 //JR 09.02.2005 : SomeDataReady is not from the SwitchNode
808 if ( anOutGateSwitchPort && !anOutGateSwitchPort->BoolValue() ) {
809 //JR 09.02.2005 : the OutPort of the SwitchNode connected to the default port is closed ===>
810 // Here after we consider that that DefaultPort is Ready (even if it's value is false)
811 SwitchFinished = true ; // End of Switch
814 #define SomeDataReadyTrace 0
815 #if SomeDataReadyTrace
816 cdebug << pthread_self() << "/" << ThreadNo() << " " << Name() << " LoopFinished " << LoopFinished
817 << " LoopBeginning " << LoopBeginning << " SwitchFinished " << SwitchFinished << endl ;
819 for ( k = 0 ; k < (unsigned int ) GetNodeInPortsSize() ; k++ ) {
820 GraphBase::InPort * anInPort = GetChangeNodeInPort(k) ;
821 GraphBase::OutPort * anOutPort = anInPort->GetOutPort() ;
822 cdebug << pthread_self() << "/" << ThreadNo() << " " << Name() << " InPort " << anInPort->PortName() << " " << anInPort->PortState() << " " << anInPort->PortStatus() << endl ;
823 if ( anInPort->IsGate() && anOutPort == NULL ) {
825 anInPort->PortState( SUPERV::ReadyState ) ;
826 #if SomeDataReadyTrace
827 cdebug << pthread_self() << "/" << ThreadNo() << " " << Name() << " "
828 << anInPort->PortName() << " ControlPort inactive." << endl ;
831 // That InPort get its value from an other node : the node of anOutPort linked to that anInPort is
832 // different from the sender of SomeDataReady (DataFromNode)
833 else if ( strcmp( DataFromNode() , anOutPort->NodeName() ) ) {
834 if ( anInPort->PortState() == SUPERV::ReadyState ) {
836 #if SomeDataReadyTrace
837 cdebug << pthread_self() << "/" << ThreadNo() << " " << Name() << " "
838 << anInPort->PortName() << " Was Done from Node "
839 << anOutPort->NodeName() << "( " << anOutPort->PortName()
842 if ( GraphBase::Base::_prof_debug ) {
843 anOutPort->StringValue( *GraphBase::Base::_fdebug ) ;
849 else if ( IsLoopNode() && anInPort->IsDataConnected() ) {
850 anInPort->PortState( SUPERV::ReadyState ) ;
852 #if SomeDataReadyTrace
853 cdebug << pthread_self() << "/" << ThreadNo() << " " << Name() << " "
854 << anInPort->PortName() << " Was Done from Node "
855 << anOutPort->NodeName() << "( " << anOutPort->PortName()
856 << ") LoopBeginning " << LoopBeginning ;
858 if ( GraphBase::Base::_prof_debug ) {
859 anOutPort->StringValue( *GraphBase::Base::_fdebug ) ;
865 else if ( LoopFinished ) {
866 anInPort->PortState( SUPERV::ReadyState ) ;
868 #if SomeDataReadyTrace
869 cdebug << pthread_self() << "/" << ThreadNo() << " " << Name() << " "
870 << anInPort->PortName() << " Was Done from Node "
871 << anOutPort->NodeName() << "( " << anOutPort->PortName()
872 << ") LoopFinished" ;
874 if ( GraphBase::Base::_prof_debug ) {
875 anOutPort->StringValue( *GraphBase::Base::_fdebug ) ;
881 else if ( anInPort->IsGate() && SwitchFinished ) {
882 anInPort->PortState( SUPERV::ReadyState ) ;
884 #if SomeDataReadyTrace
885 cdebug << pthread_self() << "/" << ThreadNo() << " " << Name() << " "
886 << anInPort->PortName() << " Was Done from Node "
887 << anOutPort->NodeName() << "( " << anOutPort->PortName()
888 << ") SwitchFinished" ;
890 if ( GraphBase::Base::_prof_debug ) {
891 anOutPort->StringValue( *GraphBase::Base::_fdebug ) ;
897 else if ( anInPort->IsGate() &&
898 _OutNode->Graph()->GetGraphNode( anOutPort->NodeName() )->IsGOTONode() ) {
899 // GateOutPort of GOTONodes are always opened
900 anInPort->PortState( SUPERV::ReadyState ) ;
902 //JR 21.02.2005 Debug Memory leak : CORBA::Any * anAny = new CORBA::Any() ;
903 CORBA::Any anAny = CORBA::Any() ;
904 //JR 21.02.2005 Debug Memory leak : *anAny <<= (long ) 1 ;
905 anAny <<= (long ) 1 ;
906 _OutNode->Graph()->GetGraphNode( anOutPort->NodeName() )->GetChangeNodeOutGate()->Value( anAny ) ;
907 #if SomeDataReadyTrace
908 cdebug << pthread_self() << "/" << ThreadNo() << " " << Name() << " "
909 << anInPort->PortName() << " Was Done from Node "
910 << anOutPort->NodeName() << "( " << anOutPort->PortName()
913 if ( GraphBase::Base::_prof_debug ) {
914 anOutPort->StringValue( *GraphBase::Base::_fdebug ) ;
921 #if SomeDataReadyTrace
922 cdebug << pthread_self() << "/" << ThreadNo() << " " << Name() << " "
923 << anInPort->PortName() << " Was NOT Done from Node "
924 << anOutPort->NodeName() << "( " << anOutPort->PortName() << ") "
925 << " " << Automaton()->StateName( State() ) << " DataConnected "
926 << anInPort->IsDataConnected() << " LoopBeginning "
927 << LoopBeginning << endl ;
931 // That InPort get its value from the sending node (DataFromNode)
932 else if ( anInPort->IsGate() ) {
933 const CORBA::Any * theValue = anOutPort->Value() ;
935 (*theValue) >>= GateOpened ;
936 if ( GateOpened != 0 ) {
938 anInPort->PortState( SUPERV::ReadyState ) ;
939 #if SomeDataReadyTrace
940 cdebug << pthread_self() << "/" << ThreadNo() << " " << Name() << " "
941 << anInPort->PortName() << " Gate is Opened from Node "
942 << anOutPort->NodeName() << "( " << anOutPort->PortName()
945 if ( GraphBase::Base::_prof_debug ) {
946 anOutPort->StringValue( *GraphBase::Base::_fdebug ) ;
952 else if ( LoopFinished ) {
953 anInPort->PortState( SUPERV::ReadyState ) ;
954 #if SomeDataReadyTrace
955 cdebug << pthread_self() << "/" << ThreadNo() << " " << Name() << " "
956 << anInPort->PortName() << " GATE IS CLOSED from Node "
957 << anOutPort->NodeName() << "( " << anOutPort->PortName()
958 << ") LoopFinished" ;
960 if ( GraphBase::Base::_prof_debug ) {
961 anOutPort->StringValue( *GraphBase::Base::_fdebug ) ;
968 #if SomeDataReadyTrace
969 cdebug << pthread_self() << "/" << ThreadNo() << " " << Name() << " "
970 << anInPort->PortName() << " GATE IS CLOSED from Node "
971 << anOutPort->NodeName() << "( " << anOutPort->PortName()
974 if ( GraphBase::Base::_prof_debug ) {
975 anOutPort->StringValue( *GraphBase::Base::_fdebug ) ;
982 else if ( anOutPort->PortDone() ) {
984 anInPort->PortState( SUPERV::ReadyState ) ;
985 #if SomeDataReadyTrace
986 cdebug << pthread_self() << "/" << ThreadNo() << " " << Name() << " InPort "
987 << anInPort->PortName() << " " << anInPort->PortStatus() << " "
988 << Automaton()->StateName( anInPort->PortState() ) << " is Done from Node "
989 << anOutPort->NodeName() << "( " << anOutPort->PortName() << ") "
990 << anOutPort->PortStatus() << " " ;
992 if ( GraphBase::Base::_prof_debug ) {
993 anOutPort->StringValue( *GraphBase::Base::_fdebug ) ;
998 // MacroNode : give immediately the value to the corresponding graph
999 if ( IsMacroNode() ) {
1000 cout << "SomeDataReadyAction " << GraphMacroNode() << " " << GraphMacroNode()->Name()
1001 << " coupled to " << GraphMacroNode()->CoupledNode() << endl ;
1002 GraphExecutor::DataFlow * aMacroGraph = GraphMacroNode()->CoupledNode()->GraphEditor()->Executor() ;
1003 cdebug << "SomeDataReadyAction MacroNode " << aMacroGraph->Graph()->Name() << " --> InputOfAny "
1004 << InReady << "/" << GetNodeInPortsSize() << " InPorts are Ready" << endl ;
1005 // GraphMacroNode()->MacroObject()->InputOfAny( anInPort->PortName() , *anOutPort->Value() ) ;
1006 aMacroGraph->InputOfAny( anInPort->PortName() , *anOutPort->Value() ) ;
1010 #if SomeDataReadyTrace
1011 cdebug << pthread_self() << "/" << ThreadNo() << " Node " << Name() << "( "
1012 << anInPort->PortName() << ") " << anInPort->PortStatus()
1013 << " is NOT Done from Node "
1014 << anOutPort->NodeName() << "( " << anOutPort->PortName() << ") "
1015 << anOutPort->PortStatus() << " " << endl ;
1020 if ( InReady == GetNodeInPortsSize() ) { // All Flags != 0 :
1021 res = SendEvent( GraphExecutor::AllDataReadyEvent ); // ==> Ready to execute
1023 else { // At least one Flag == 0 :
1024 res = SendEvent( GraphExecutor::NotAllDataReadyEvent );
1027 cdebug << pthread_self() << "/" << ThreadNo()
1028 << " <-- DataWaiting_SomeDataReadyAction " << Name() << endl;
1033 int GraphExecutor::InNode::DataUndef_NotAllDataReadyAction() {
1034 CreateNewThreadIf( false ) ;
1035 // cdebug << pthread_self() << " for " << ThreadNo()
1036 // << " DataUndef_NotAllDataReadyAction " << Name() << endl;
1040 int GraphExecutor::InNode::DataUndef_AllDataReadyAction() {
1041 // cdebug << pthread_self() << "/" << ThreadNo()
1042 // << " --> DataUndef_AllDataReadyAction " << Name()
1043 // << " CreateNewThreadIf " << CreateNewThreadIf() << " IsLockedDataWait "
1044 // << IsLockedDataWait() ;
1045 if ( IsLockedDataWait() ) {
1046 cdebug << "DataUndef_AllDataReadyAction() " << Name() << "WOULD DEAD-LOCK" << endl ;
1047 return 0 ; // ==> DataUndef_AllDataReadyAction() after UnLockDataWait()
1049 cdebug << "InNode::DataUndef_AllDataReadyAction CreateNewThread( CreateNewThreadIf() ) "
1050 << CreateNewThreadIf() << endl ;
1051 CreateNewThread( CreateNewThreadIf() ) ;
1052 if ( !CreateNewThread() ) {
1053 // cdebug << "Thread " << ThreadNo() << "-->" << pthread_self() << endl ;
1054 ThreadNo( pthread_self() ) ;
1057 _OutNode->IncrCreatedThreads() ;
1059 _OutNode->PushEvent( this , GraphExecutor::AllDataReadyEvent ,
1060 GraphExecutor::DataReadyState ) ;
1062 SUPERV::ControlState aControl = ControlState() ;
1063 switch ( aControl ) {
1064 case SUPERV::VoidState : {
1065 SendEvent( GraphExecutor::ExecuteEvent ) ;
1068 case SUPERV::ToSuspendState : {
1069 SendEvent( GraphExecutor::SuspendEvent ) ;
1072 case SUPERV::ToSuspendStartState : {
1073 SendEvent( GraphExecutor::SuspendEvent ) ;
1076 case SUPERV::ToSuspendDoneState : {
1077 SendEvent( GraphExecutor::ExecuteEvent ) ;
1080 case SUPERV::ToKillState : {
1081 SendEvent( GraphExecutor::KillEvent ) ;
1084 case SUPERV::ToKillDoneState : {
1085 SendEvent( GraphExecutor::ExecuteEvent ) ;
1088 case SUPERV::ToStopState : {
1089 SendEvent( GraphExecutor::StopEvent ) ;
1093 cdebug << ThreadNo()
1094 << " GraphExecutor::InNodeThreads::DataUndef_AllDataReadyAction Error Undefined Control : "
1095 << aControl << endl ;
1099 // cdebug << pthread_self() << "/" << ThreadNo()
1100 // << " <-- DataUndef_AllDataReadyAction " << Name() << endl;
1104 int GraphExecutor::InNode::DataReady_SuspendAction() {
1105 cdebug << pthread_self() << "/" << ThreadNo()
1106 << "DataReady_SuspendAction --> Suspend " << Name()
1107 << " Threads " << _OutNode->Threads() << " SuspendedThreads "
1108 << _OutNode->SuspendedThreads() << endl;
1109 _OutNode->PushEvent( this , GraphExecutor::SuspendedReadyEvent ,
1110 GraphExecutor::SuspendedReadyState ) ;
1111 GraphExecutor::InNode * aReStartNode = SuspendAction() ;
1112 cdebug << pthread_self() << "/" << ThreadNo()
1113 << "DataReady_SuspendAction Resumed " << Name() << endl;
1114 if ( aReStartNode ) {
1115 _aReStartNode = NULL ;
1116 aReStartNode->SendEvent( _aReStartEvent ) ;
1119 SendEvent( GraphExecutor::ExecuteEvent ) ;
1124 int GraphExecutor::InNode::SuspendedReady_ResumeAction() {
1125 cdebug << pthread_self() << "/" << ThreadNo() << "SuspendedReady_ResumeAction "
1128 _OutNode->PushEvent( this , GraphExecutor::ResumedReadyEvent ,
1129 GraphExecutor::ResumedReadyState ) ;
1133 int GraphExecutor::InNode::DataReady_KillAction() {
1134 _OutNode->PushEvent( this , GraphExecutor::KilledReadyEvent ,
1135 GraphExecutor::KilledReadyState ) ;
1137 cdebug << pthread_self() << "/" << ThreadNo() << "DataReady_KillAction " << Name()
1138 << " will pthread_exit()" << endl;
1142 int GraphExecutor::InNode::DataReady_StopAction() {
1143 _OutNode->PushEvent( this , GraphExecutor::StoppedReadyEvent ,
1144 GraphExecutor::StoppedReadyState ) ;
1146 cdebug << pthread_self() << "/" << ThreadNo() << "DataReady_StopAction " << Name()
1147 << " will pthread_exit()" << endl;
1153 int GraphExecutor::InNode::DataReady_ExecuteAction() {
1155 // cdebug << pthread_self() << "/" << ThreadNo() << " --> DataReady_ExecuteAction "
1156 // << Name() << endl;
1157 _OutNode->PushEvent( this , GraphExecutor::ExecuteEvent ,
1158 GraphExecutor::ExecutingState ) ;
1164 SUPERV::GraphState PortState = SUPERV::ReadyState ;
1165 GraphExecutor::AutomatonState NewState = GraphExecutor::DataUndefState ;
1166 GraphExecutor::NodeEvent NewEvent = GraphExecutor::UndefinedEvent ;
1169 ServicesAnyData * InParametersList ;
1171 ServicesAnyData * OutParametersList ;
1173 nInParams = GetNodeInPortsSize() ;
1174 InParametersList = new ServicesAnyData[nInParams];
1175 InParametersSet( Err , nInParams , InParametersList ) ;
1177 nOutParams = GetNodeOutPortsSize() ;
1178 OutParametersList = new ServicesAnyData[nOutParams];
1179 InOutParametersSet( nOutParams , OutParametersList ) ;
1181 if ( !IsMacroNode() ) {
1183 Engines::Container_var myContainer ;
1184 Engines::Component_var myObjComponent ;
1185 if ( !IsFactoryNode() ) {
1186 // cdebug << ThreadNo() << "No Component : NO StartComponent & No Ping" << endl ;
1187 if ( IsComputingNode() ) {
1188 ObjInterface( true ) ;
1189 CORBA::Object_ptr obj ;
1190 InParametersList[0].Value >>= obj ;
1191 CORBA::Object_var objvar = CORBA::Object_var( obj ) ;
1192 myObjComponent = Engines::Component::_narrow( objvar ) ;
1197 else if ( CORBA::is_nil( Component() ) ) {
1198 // ostringstream astr ;
1199 // astr << "Graph " << _OutNode->Graph()->Name() << " Node " << Name()
1200 // << " : load of component " << ComponentName() << " in container "
1202 // _OutNode->Graph()->ObjImpl()->sendMessage( NOTIF_STEP, astr.str().c_str() ) ;
1203 Err = !_OutNode->Graph()->StartComponent( ThreadNo() , Computer() ,
1204 //JR 17.02.2005 Memory Leak my_strdup( ComponentName() ) ,
1206 myContainer , myObjComponent ) ;
1207 ObjInterface( false ) ;
1208 SetContainer( myContainer ) ;
1209 SetComponent( myObjComponent ) ;
1212 myContainer = Container() ;
1213 myObjComponent = Component() ;
1214 // cdebug << ThreadNo() << "Component known : NO StartComponent & Ping"
1217 myObjComponent->ping() ;
1220 cdebug << "ping() catched" << endl ;
1225 if ( Err || ControlState() == SUPERV::ToKillState ||
1226 ControlState() == SUPERV::ToKillDoneState ||
1227 ControlState() == SUPERV::ToStopState ) {
1228 cdebug << ThreadNo() << "StartComponent Error or ToKillState" << endl ;
1229 // MESSAGE(pthread_self() << "Executor::InNode::DataReady_ExecuteAction of " << Name()
1230 // << " ControlState " << Automaton()->ControlStateName( ControlState() )
1231 // << " BEFORE execution ThreadNo " << ThreadNo() ) ;
1235 if ( ControlState() == SUPERV::ToSuspendState ) {
1236 cdebug << ThreadNo() << "ToSuspendState before running." << endl ;
1237 MESSAGE(ThreadNo() << "ToSuspendState before running.") ;
1240 // ostringstream astr ;
1241 // astr << "Graph " << _OutNode->Graph()->Name() << " Run of Node " << Name() ;
1242 // _OutNode->Graph()->ObjImpl()->sendMessage( NOTIF_STEP, astr.str().c_str() ) ;
1245 cdebug << ThreadNo() << " Run( '" << ServiceName() << "'" ;
1246 for ( i = 0 ; i < (int ) ServiceInParameter().length() ; i++ ) {
1247 cdebug << " , " << InParametersList[ i ].Name << "[kind"
1248 << InParametersList[ i ].Value.type()->kind() << "]" ;
1250 for ( i = 0 ; i < (int ) ServiceOutParameter().length() ; i++ ) {
1251 cdebug << " , " << OutParametersList[ i ].Name << "[kind"
1252 << OutParametersList[ i ].Value.type()->kind() << "]" ;
1254 if ( IsOneOfInLineNodes() ) {
1255 cdebug << " , PyFuncName '" << InLineNode()->PyFuncName() << "' PyRunMethod "
1256 << InLineNode()->PyRunMethod() << " length "
1257 << (*InLineNode()->PythonFunction()).length() ;
1259 cdebug << ")" << endl ;
1262 if ( IsOneOfInLineNodes() ) {
1263 bool StsPyDynInvoke = true;
1264 _OutNode->PyThreadLock() ;
1267 // if ( IsInLineNode() && (*InLineNode()->PythonFunction()).length() &&
1268 bool ItIsaLoop = false ;
1269 bool CopyInOut = false ;
1270 if ( IsInLineNode() && /*InLineNode()->PyRunMethod() &&*/
1271 strlen( InLineNode()->PyFuncName() ) ) {
1272 cdebug << ThreadNo() << " !ObjInterface " << Name() << " PyFuncName '"
1273 << InLineNode()->PyFuncName()
1274 << "' IsInLineNode PyDynInvoke" << endl ;
1275 StsPyDynInvoke = PyDynInvoke( InLineNode()->PyRunMethod() ,
1276 InLineNode()->PyFuncName() ,
1277 &InParametersList[0] , ServiceInParameter().length() ,
1278 &OutParametersList[0] , ServiceOutParameter().length() ) ;
1279 if ( !StsPyDynInvoke ) {
1280 RemovePyDynInvoke( InLineNode()->PyFuncName() ) ;
1282 else if ( IsLoopNode() ) {
1284 bool CopyOutIn = false ;
1285 // Switch between Init() and Next()
1286 // if InLoop port is true and does not come from EndLoop ==> execute Init
1287 // if InLoop port is false or come from EndLoop ==> execute Next
1288 // GraphExecutor::InNode * anEndLoopNode = (GraphExecutor::InNode * ) CoupledNode()->GetInNode() ;
1289 // if ( GetNodeInLoop()->GetOutPort()->BoolValue() &&
1291 if ( strlen( InLineNode()->PyFuncName() ) ) { // InLoop Port = true ==> Init()
1292 // cdebug << ThreadNo() << " !ObjInterface " << Name()
1293 // << " IsLoopNode PyDynInvoke '" << InLineNode()->PyFuncName()
1294 // << "' InitLoop " << LoopNode()->PyRunMethod() << endl ;
1295 StsPyDynInvoke = PyDynInvoke( InLineNode()->PyRunMethod() ,
1296 InLineNode()->PyFuncName() ,
1297 &InParametersList[1] , ServiceInParameter().length() ,
1298 &OutParametersList[1] , ServiceOutParameter().length() ) ;
1299 if ( !StsPyDynInvoke ) {
1300 RemovePyDynInvoke( InLineNode()->PyFuncName() ) ;
1305 // cdebug << ThreadNo() << " !ObjInterface " << Name()
1306 // << " IsLoopNode NO PyDynInvoke Void PyFuncName InitLoop" << endl ;
1308 // cdebug << ThreadNo() << " !ObjInterface " << Name()
1309 // << " IsLoopNode _InitLoop Reset after Init() Python Function" << endl ;
1312 else if ( LoopNode()->PyNextMethod() &&
1313 strlen( LoopNode()->PyNextName() ) ){ // InLoop Port = false ==> Next()
1314 // cdebug << ThreadNo() << " !ObjInterface " << Name()
1315 // << " IsLoopNode PyDynInvoke '" << LoopNode()->PyNextName()
1316 // << "' " << LoopNode()->PyNextMethod() << endl ;
1317 StsPyDynInvoke = PyDynInvoke( LoopNode()->PyNextMethod() ,
1318 LoopNode()->PyNextName() ,
1319 &InParametersList[1] , ServiceInParameter().length() ,
1320 &OutParametersList[1] , ServiceOutParameter().length() ) ;
1321 if ( !StsPyDynInvoke ) {
1322 RemovePyDynInvoke( LoopNode()->PyNextName() ) ;
1327 // cdebug << ThreadNo() << " !ObjInterface " << Name()
1328 // << " IsLoopNode NO PyDynInvoke Void PyFuncName NextLoop" << endl ;
1330 if ( StsPyDynInvoke ) {
1332 // cdebug << ThreadNo() << " !ObjInterface " << Name()
1333 // << " IsLoopNode PyDynInvoke '" << LoopNode()->PyMoreName()
1334 // << "' Copy of " << ServiceInParameter().length()
1335 // << " OutParameters" << endl ;
1337 // Start at 1 : Do not copy InLoop ( InLoop == true <==> Init ; InLoop == false <==> Next )
1338 for ( i = 1 ; i <= (int ) ServiceInParameter().length() ; i++ ) {
1339 InParametersList[i].Value = OutParametersList[i].Value ;
1340 InParametersList[i].Name = OutParametersList[i].Name ;
1342 switch ( InParametersList[i].Value.type()->kind() ) {
1343 case CORBA::tk_string :
1345 InParametersList[i].Value >>= t ;
1346 cdebug << "ArgOut->In" << i << " : "
1347 << InParametersList[i].Name.c_str()
1348 << " Value(string) " << t << endl ;
1350 case CORBA::tk_boolean:
1352 InParametersList[i].Value >>= (CORBA::Any::to_boolean ) b;
1353 cdebug << "ArgOut->In" << i << " : "
1354 << InParametersList[i].Name.c_str()
1355 << " Value(boolean) " << b << endl ;
1357 case CORBA::tk_char:
1359 InParametersList[i].Value >>= (CORBA::Any::to_char ) c;
1360 cdebug << "ArgOut->In" << i << " : "
1361 << InParametersList[i].Name.c_str()
1362 << " Value(char) " << c << endl ;
1364 case CORBA::tk_short:
1366 InParametersList[i].Value >>= s;
1367 cdebug << "ArgOut->In" << i << " : "
1368 << InParametersList[i].Name.c_str()
1369 << " Value(short) " << s << endl ;
1371 case CORBA::tk_long :
1373 InParametersList[i].Value >>= l;
1374 cdebug << "ArgOut->In" << i << " : "
1375 << InParametersList[i].Name.c_str()
1376 << " Value(long) " << l << endl ;
1378 case CORBA::tk_float :
1380 InParametersList[i].Value >>= f;
1381 cdebug << "ArgOut->In" << i << " : "
1382 << InParametersList[i].Name.c_str()
1383 << " Value(float) " << f << endl ;
1385 case CORBA::tk_double :
1387 InParametersList[i].Value >>= d;
1388 cdebug << "ArgOut->In" << i << " : "
1389 << InParametersList[i].Name.c_str()
1390 << " Value(double) " << d << endl ;
1392 case CORBA::tk_objref :
1393 CORBA::Object_ptr obj ;
1396 InParametersList[i].Value >>= obj ;
1397 retstr = ObjectToString( obj );
1398 cdebug << "ArgOut->In" << i << " : "
1399 << InParametersList[i].Name.c_str()
1400 << " Value(object reference) " << retstr << endl ;
1403 cdebug << "ArgOut->In" << i << " : "
1404 << InParametersList[i].Name.c_str()
1405 << " Value(object reference) Catched ERROR" << endl ;
1409 cdebug << "ArgOut->In" << i << " : "
1410 << InParametersList[i].Name.c_str()
1411 << " Value(other) ERROR" << endl ;
1416 if ( LoopNode()->PyMoreMethod() && strlen( LoopNode()->PyMoreName() ) ) {
1417 // cdebug << ThreadNo() << " !ObjInterface " << Name()
1418 // << " IsLoopNode PyDynInvoke '" << LoopNode()->PyMoreName()
1419 // << "' " << LoopNode()->PyMoreMethod() << endl ;
1420 StsPyDynInvoke = PyDynInvoke( LoopNode()->PyMoreMethod() ,
1421 LoopNode()->PyMoreName() ,
1422 &InParametersList[1] , ServiceInParameter().length() ,
1423 &OutParametersList[0] , ServiceOutParameter().length()+1 ) ;
1424 if ( !StsPyDynInvoke ) {
1425 RemovePyDynInvoke( LoopNode()->PyMoreName() ) ;
1429 // cdebug << ThreadNo() << " !ObjInterface " << Name()
1430 // << " IsLoopNode PyDynInvoke '" << LoopNode()->PyMoreName()
1431 // << "' No MoreMethod" << endl ;
1437 cdebug << ThreadNo() << " InLineNode " << Name() << " "
1438 << InLineNode()->PyFuncName() << "/" << LoopNode()->PyNextName()
1439 << " Python Dynamic Call Error"
1443 else if ( IsSwitchNode() && /*InLineNode()->PyRunMethod() &&*/
1444 strlen( InLineNode()->PyFuncName() ) ) {
1445 // cdebug << ThreadNo() << " !ObjInterface " << Name() << " PyFuncName '"
1446 // << InLineNode()->PyFuncName()
1447 // << "' IsSwitchNode PyDynInvoke" << endl ;
1448 StsPyDynInvoke = PyDynInvoke( InLineNode()->PyRunMethod() ,
1449 InLineNode()->PyFuncName() ,
1450 &InParametersList[0] , ServiceInParameter().length() ,
1451 &OutParametersList[0] , ServiceOutParameter().length() ) ;
1452 if ( !StsPyDynInvoke ) {
1453 RemovePyDynInvoke( InLineNode()->PyFuncName() ) ;
1456 // else if ( IsGOTONode() && (*GOTONode()->PythonFunction()).length() &&
1457 else if ( IsGOTONode() && /*InLineNode()->PyRunMethod() &&*/
1458 strlen( InLineNode()->PyFuncName() ) ) {
1459 // cdebug << ThreadNo() << " !ObjInterface " << Name() << " PyFuncName '"
1460 // << InLineNode()->PyFuncName()
1461 // << "' IsGOTONode PyDynInvoke" << endl ;
1462 StsPyDynInvoke = PyDynInvoke( InLineNode()->PyRunMethod() ,
1463 InLineNode()->PyFuncName() ,
1464 &InParametersList[0] , ServiceInParameter().length() ,
1465 &OutParametersList[0] , ServiceOutParameter().length() ) ;
1466 if ( !StsPyDynInvoke ) {
1467 RemovePyDynInvoke( GOTONode()->PyFuncName() ) ;
1470 // else if ( IsEndSwitchNode() && (*InLineNode()->PythonFunction()).length() &&
1471 else if ( ( IsEndSwitchNode() ) &&
1472 InLineNode()->PyRunMethod() && strlen( InLineNode()->PyFuncName() ) ) {
1473 // cdebug << ThreadNo() << " !ObjInterface " << Name() << " PyFuncName '"
1474 // << InLineNode()->PyFuncName()
1475 // << "' IsSwitchNode PyDynInvoke" << endl ;
1476 StsPyDynInvoke = PyDynInvoke( InLineNode()->PyRunMethod() ,
1477 InLineNode()->PyFuncName() ,
1478 &InParametersList[0] , ServiceInParameter().length() ,
1479 &OutParametersList[0] , ServiceOutParameter().length() ) ;
1480 if ( !StsPyDynInvoke ) {
1481 RemovePyDynInvoke( InLineNode()->PyFuncName() ) ;
1484 else if ( ( IsEndLoopNode() ) &&
1485 InLineNode()->PyRunMethod() && strlen( InLineNode()->PyFuncName() ) ) {
1486 cdebug << ThreadNo() << " !ObjInterface " << Name() << " PyFuncName '"
1487 << InLineNode()->PyFuncName()
1488 << "' IsSwitchNode PyDynInvoke" << endl ;
1489 StsPyDynInvoke = PyDynInvoke( InLineNode()->PyRunMethod() ,
1490 InLineNode()->PyFuncName() ,
1491 &InParametersList[0] , ServiceInParameter().length() + 1 ,
1492 &OutParametersList[0] , ServiceOutParameter().length() + 1 ) ;
1493 if ( !StsPyDynInvoke ) {
1494 RemovePyDynInvoke( InLineNode()->PyFuncName() ) ;
1498 // else if ( (*InLineNode()->PythonFunction()).length() == 0 ||
1499 if ( (!ItIsaLoop && ( InLineNode()->PyRunMethod() == NULL ||
1500 strlen( InLineNode()->PyFuncName() ) == 0 ) ) || CopyInOut ) {
1501 // This is a void Python Function : without code (No PyFuncName)
1502 // cdebug << ThreadNo() << " !ObjInterface " << Name()
1503 // << " Copy of " << ServiceInParameter().length()
1504 // << " OutParameters" << endl ;
1508 if ( IsLoopNode() || IsEndLoopNode() ) {
1510 argin0 = 1 ; // after DoLoop
1511 if ( IsLoopNode() ) { // More() is void
1512 // OutParametersList[0].Value = InParametersList[0].Value ; // DoLoop
1513 // cdebug << Name() << " Not Beginning of loop and non void EndLoop : DoLoop = EndLoop(DoLoop)"
1515 GraphExecutor::InNode * anEndLoopNode = (GraphExecutor::InNode * ) CoupledNode()->GetInNode() ;
1516 OutParametersList[0].Value = *anEndLoopNode->GetNodeOutLoop()->Value() ; // DoLoop = EndLoop(DoLoop)
1519 for ( i = 0 ; i < (int ) ServiceInParameter().length() ; i++ ) {
1520 OutParametersList[argout0 + i].Value = InParametersList[argin0 + i].Value ;
1522 switch ( InParametersList[argin0 + i].Value.type()->kind() ) {
1523 case CORBA::tk_string :
1524 cdebug << "ArgOut->In" << argin0 + i << " : "
1525 << InParametersList[argin0 + i].Name.c_str()
1526 << " Value(string) "
1527 << OutParametersList[argout0 + i].Name.c_str() << endl ;
1529 case CORBA::tk_boolean:
1530 cdebug << "ArgOut->In" << argin0 + i << " : "
1531 << InParametersList[argin0 + i].Name.c_str()
1532 << " Value(boolean) "
1533 << OutParametersList[argout0 + i].Name.c_str() << endl ;
1535 case CORBA::tk_char:
1536 cdebug << "ArgOut->In" << argin0 + i << " : "
1537 << InParametersList[argin0 + i].Name.c_str()
1539 << OutParametersList[argout0 + i].Name.c_str() << endl ;
1541 case CORBA::tk_short:
1542 cdebug << "ArgOut->In" << argin0 + i << " : "
1543 << InParametersList[argin0 + i].Name.c_str()
1545 << OutParametersList[argout0 + i].Name.c_str() << endl ;
1547 case CORBA::tk_long :
1548 cdebug << "ArgOut->In" << argin0 + i << " : "
1549 << InParametersList[argin0 + i].Name.c_str()
1551 << OutParametersList[argout0 + i ].Name.c_str() << endl ;
1553 case CORBA::tk_double :
1554 cdebug << "ArgOut->In" << argin0 + i << " : "
1555 << InParametersList[argin0 + i].Name.c_str()
1556 << " Value(double) "
1557 << OutParametersList[argout0 + i].Name.c_str() << endl ;
1559 case CORBA::tk_objref :
1560 cdebug << "ArgOut->In" << argin0 + i << " : "
1561 << InParametersList[argin0 + i].Name.c_str()
1562 << " Value(object reference) "
1563 << OutParametersList[argout0 + i].Name.c_str() << endl ;
1566 cdebug << "ArgOut->In" << argin0 + i << " : "
1567 << InParametersList[argin0 + i].Name.c_str()
1568 << " Value(other) ERROR "
1569 << OutParametersList[argout0 + i].Name.c_str() << endl ;
1574 if ( !StsPyDynInvoke ) {
1576 cdebug << ThreadNo() << " InLineNode " << Name()
1577 << " Python Dynamic Call Error"
1583 cdebug << ThreadNo() << " InLineNode " << Name()
1584 << " Python Dynamic Call Exception catched ERROR"
1588 _OutNode->PyThreadUnLock() ;
1593 cdebug << "DynInvoke -> Names " << _OutNode->Graph()->Name() << " " << Name() << endl ;
1594 DynInvoke( myObjComponent, "Names" ,
1595 _OutNode->Graph()->Name() , Name() ) ;
1598 cdebug << "DynInvoke Names catched ERROR" << endl ;
1600 // for DataStreamNodes : call of SetProperties ===> environment variables in the component/container
1601 if ( ComputingNode()->HasDataStream() ) {
1603 cdebug << "DynInvoke -> SetProperties " << _OutNode->Graph()->Name() << " " << Name() << endl ;
1604 Engines::FieldsDict_var dict = new Engines::FieldsDict;
1606 dict[ 0 ].key = CORBA::string_dup( "CAL_MACHINE");
1607 // myContainer->getHostName() ne renvoit pas le nom complet (avec domaine).
1608 // dict[ 0 ].value <<= myContainer->getHostName() ;
1609 char FullyQualifiedDomainName[256]="";
1610 gethostname(FullyQualifiedDomainName,255);
1611 dict[ 0 ].value <<= FullyQualifiedDomainName ;
1612 dict[ 1 ].key = CORBA::string_dup( "CAL_REPERTOIRE");
1613 dict[ 1 ].value <<= "/tmp" ;
1614 dict[ 2 ].key = CORBA::string_dup( "CAL_COUPLAGE");
1615 stringstream ofst1 ;
1616 ofst1 << ComputingNode()->SubStreamGraph() ;
1617 string cpl = string( "/tmp/" ) + string( _OutNode->Graph()->Name() ) + string( "_" ) +
1618 ofst1.str() + string( ".cpl" );
1619 dict[ 2 ].value <<= cpl.c_str() ;
1620 dict[ 3 ].key = CORBA::string_dup( "SALOME_INSTANCE_NAME");
1621 string uname = Name();
1623 dict[ 3 ].value <<= uname.c_str() ;
1625 myObjComponent->setProperties( dict ) ;
1628 cdebug << "DynInvoke setProperties catched ERROR" << endl ;
1632 if ( !Err && IsComputingNode() ) {
1633 cdebug << ThreadNo() << " !ObjInterface " << Name()
1634 << " IsComputingNode DynInvoke" << endl ;
1635 cdebug << ServiceInParameter().length()-1 << " input parameters and "
1636 << ServiceOutParameter().length() << " output parameters" << endl ;
1637 IsLoading( false ) ;
1638 DynInvoke( myObjComponent,
1640 &InParametersList[1] , ServiceInParameter().length()-1 ,
1641 &OutParametersList[0] , ServiceOutParameter().length() ) ;
1643 else if ( !Err && IsFactoryNode() ) {
1644 cdebug << ThreadNo() << " !ObjInterface " << Name()
1645 << " IsFactoryNode DynInvoke" << endl ;
1646 cdebug << ServiceInParameter().length() << " input parameters and "
1647 << ServiceOutParameter().length() << " output parameters" << endl ;
1648 IsLoading( false ) ;
1649 DynInvoke( myObjComponent,
1651 &InParametersList[0] , ServiceInParameter().length() ,
1652 &OutParametersList[0] , ServiceOutParameter().length() ) ;
1654 // cdebug << ThreadNo() << " Component::CpuUsed " << Name() << " "
1655 // << myObjComponent->CpuUsed_impl() << endl ;
1659 cdebug << ThreadNo() << " !ObjInterface " << Name()
1660 << " Node(Component) Dynamic Call Exception catched ERROR"
1662 //Reset of _ThreadId in the Container ...
1664 myObjComponent->Kill_impl() ;
1674 // ostringstream astr ;
1675 // astr << "Graph " << _OutNode->Graph()->Name() << " Node " << Name() << " is done : "
1676 // << Automaton()->StateName( State() ) ;
1677 // _OutNode->Graph()->ObjImpl()->sendMessage( NOTIF_STEP, astr.str().c_str() ) ;
1681 // if exception or something else - IsLoading( false ) may not NOT has been called
1685 if ( ControlState() == SUPERV::ToKillState ||
1686 ControlState() == SUPERV::ToKillDoneState ||
1687 ControlState() == SUPERV::ToStopState ) {
1688 PortState = SUPERV::ErrorState ;
1689 NewState = GraphExecutor::KilledState ;
1690 NewEvent = GraphExecutor::KillEvent ;
1693 PortState = SUPERV::ErrorState ;
1694 NewState = GraphExecutor::ErroredState ;
1695 NewEvent = GraphExecutor::ErrorEvent ;
1699 PortState = SUPERV::ReadyState ;
1700 NewState = GraphExecutor::DataReadyState ;
1701 NewEvent = GraphExecutor::SuccessEvent ;
1704 if ( !IsMacroNode() ) {
1705 bool ErrOut = OutParametersSet( Err , PortState , nOutParams , OutParametersList ) ;
1707 NewEvent = GraphExecutor::ErrorEvent ;
1709 delete [] InParametersList ;
1710 delete [] OutParametersList ;
1713 if ( !IsMacroNode() ) {
1714 SendEvent( NewEvent ) ;
1717 GraphExecutor::DataFlow * aMacroGraph = GraphMacroNode()->CoupledNode()->GraphEditor()->Executor() ;
1718 cdebug << ThreadNo() << " DataReady_ExecuteAction " << aMacroGraph << " "
1719 << aMacroGraph->Graph()->Name() << " ->DoneWait()"
1720 << " State " << aMacroGraph->State() << endl;
1721 aMacroGraph->DoneWait() ;
1722 cdebug << ThreadNo() << " DataReady_ExecuteAction " << Name() << " State " << aMacroGraph->State() << endl;
1723 if ( aMacroGraph->State() == SUPERV::DoneState ) {
1724 PortState = SUPERV::ReadyState ;
1725 NewState = GraphExecutor::DataReadyState ;
1726 NewEvent = GraphExecutor::SuccessEvent ;
1730 if ( ControlState() == SUPERV::ToKillState ||
1731 ControlState() == SUPERV::ToKillDoneState ||
1732 ControlState() == SUPERV::ToStopState ) {
1733 PortState = SUPERV::ErrorState ;
1734 NewState = GraphExecutor::KilledState ;
1735 NewEvent = GraphExecutor::KillEvent ;
1738 PortState = SUPERV::ErrorState ;
1739 NewState = GraphExecutor::ErroredState ;
1740 NewEvent = GraphExecutor::ErrorEvent ;
1743 bool ErrOut = OutParametersSet( Err , PortState , nOutParams , OutParametersList ) ;
1745 NewEvent = GraphExecutor::ErrorEvent ;
1747 delete [] InParametersList ;
1748 delete [] OutParametersList ;
1749 SendEvent( NewEvent ) ;
1752 // cdebug << ThreadNo() << " <-- DataReady_ExecuteAction " << Name() << endl;
1756 int GraphExecutor::InNode::Executing_SuspendAction() {
1757 _OutNode->PushEvent( this , GraphExecutor::SuspendedExecutingEvent ,
1758 GraphExecutor::SuspendedExecutingState ) ;
1759 cdebug << ThreadNo() << " Executing_SuspendAction " << Name() << endl;
1763 int GraphExecutor::InNode::SuspendedExecuting_ResumeAction() {
1764 cdebug << ThreadNo() << " SuspendedExecuting_ResumeAction " << Name() << endl;
1765 GraphExecutor::AutomatonState next_state ;
1766 next_state = Automaton()->NextState( State() , GraphExecutor::ExecutingEvent ) ;
1767 _OutNode->NewThread() ; // Only for Threads count
1768 _OutNode->PushEvent( this , GraphExecutor::ResumedExecutingEvent ,
1770 State( next_state ) ;
1774 int GraphExecutor::InNode::Executing_KillAction() {
1775 cdebug << ThreadNo() << " Executing_KillAction " << Name() << " Thread " << ThreadNo()<< endl;
1777 if ( pthread_self() == ThreadNo() ) {
1778 cdebug << "Executing_KillAction would pthread_canceled itself" << endl ;
1780 _OutNode->PushEvent( this , GraphExecutor::KilledExecutingEvent ,
1781 GraphExecutor::KilledExecutingState ) ;
1784 else if ( pthread_cancel( ThreadNo() ) ) {
1785 perror("Executing_KillAction pthread_cancel error") ;
1788 cdebug << pthread_self() << " Executing_KillAction : ThreadId " << ThreadNo()
1789 << " pthread_canceled" << endl ;
1791 _OutNode->ExitThread( ThreadNo() ) ;
1792 _OutNode->PushEvent( this , GraphExecutor::KilledExecutingEvent ,
1793 GraphExecutor::KilledExecutingState ) ;
1798 int GraphExecutor::InNode::Executing_StopAction() {
1799 cdebug << ThreadNo() << " Executing_StopAction " << Name() << " Thread " << ThreadNo() << endl;
1801 if ( pthread_cancel( ThreadNo() ) ) {
1802 perror("Executing_KillAction pthread_cancel error") ;
1805 cdebug << pthread_self() << " Executing_KillAction : ThreadId " << ThreadNo()
1806 << " pthread_canceled" << endl ;
1808 _OutNode->ExitThread( ThreadNo() ) ;
1809 _OutNode->PushEvent( this , GraphExecutor::StoppedExecutingEvent ,
1810 GraphExecutor::StoppedExecutingState ) ;
1815 int GraphExecutor::InNode::Executing_SuccessAction() {
1816 // cdebug << ThreadNo() << " --> Executing_SuccessAction " << Name() << endl;
1817 _OutNode->PushEvent( this , GraphExecutor::SuccessedExecutingEvent ,
1818 GraphExecutor::SuccessedState ) ;
1819 // MESSAGE(pthread_self() << "Executor::InNode::Executing_SuccessAction of " << Name()
1820 // << " ControlState " << Automaton()->ControlStateName( ControlState() )
1821 // << " AFTER execution ThreadNo " << ThreadNo() ) ;
1822 SUPERV::ControlState aControl = ControlState() ;
1823 switch ( aControl ) {
1824 case SUPERV::VoidState : {
1825 SendEvent( SuccessEvent ) ;
1828 case SUPERV::ToSuspendState : {
1829 SendEvent( SuccessEvent ) ;
1832 case SUPERV::ToSuspendDoneState : {
1833 SendEvent( GraphExecutor::SuspendEvent ) ;
1836 case SUPERV::ToKillState : {
1837 SendEvent( GraphExecutor::KillEvent ) ;
1840 case SUPERV::ToKillDoneState : {
1841 SendEvent( GraphExecutor::KillEvent ) ;
1844 case SUPERV::ToStopState : {
1845 SendEvent( GraphExecutor::StopEvent ) ;
1849 cdebug << ThreadNo()
1850 << " GraphExecutor::InNodeThreads::Executing_SuccessAction Error Undefined Control : "
1851 << aControl << endl ;
1855 // cdebug << ThreadNo() << " <-- Executing_SuccessAction " << Name() << endl;
1859 int GraphExecutor::InNode::Executing_ErrorAction() {
1860 cdebug << ThreadNo() << " --> Executing_ErrorAction " << Name() << endl;
1861 _OutNode->PushEvent( this , GraphExecutor::ErroredExecutingEvent ,
1862 GraphExecutor::ErroredState ) ;
1864 SUPERV::ControlState aControl = ControlState() ;
1865 switch ( aControl ) {
1866 case SUPERV::VoidState : {
1867 SendEvent( ErrorEvent ) ;
1870 case SUPERV::ToSuspendState : {
1871 SendEvent( ErrorEvent ) ;
1874 case SUPERV::ToSuspendDoneState : {
1875 SendEvent( GraphExecutor::SuspendEvent ) ;
1878 case SUPERV::ToKillState : {
1879 SendEvent( GraphExecutor::KillEvent ) ;
1882 case SUPERV::ToKillDoneState : {
1883 SendEvent( GraphExecutor::KillEvent ) ;
1886 case SUPERV::ToStopState : {
1887 SendEvent( GraphExecutor::StopEvent ) ;
1891 cdebug << ThreadNo()
1892 << " GraphExecutor::InNodeThreads::Executing_ErrorAction Error Undefined Control : "
1893 << aControl << endl ;
1897 cdebug << ThreadNo() << " <-- Executing_ErrorAction " << Name() << endl;
1901 // Set SUPERV::WaitingState to all InPorts
1902 void GraphExecutor::InNode::SetWaitingStates(GraphExecutor::InNode * EndNode ) {
1905 bool docdebug = false ;
1906 State( GraphExecutor::DataWaitingState ) ;
1907 // cdebug << "SetWaitingStates " << Name() << " " << Automaton()->StateName( State() ) << endl ;
1908 for ( i = 0 ; i < GetNodeInPortsSize() ; i++ ) {
1909 GraphBase::InPort * anInPort = GetChangeNodeInPort( i ) ;
1910 // cdebug << "SetWaitingStates InPort " << Name() << "( " << anInPort->PortName() << " ) "
1911 // << anInPort->PortStatus() << " " << anInPort->State() << endl ;
1912 // JR Debug 07.01.2005 : Close the Gates instead of open !!!
1913 if ( anInPort->IsGate() ) { // Loop : Close the doors
1914 GraphBase::OutPort * anOutPort = anInPort->GetOutPort() ;
1916 //JR 21.02.2005 Debug Memory leak : CORBA::Any * anAny = new CORBA::Any() ;
1917 CORBA::Any anAny = CORBA::Any() ;
1918 // *anAny <<= (long ) 1 ;
1919 //JR 21.02.2005 Debug Memory leak : *anAny <<= (long ) 0 ;
1920 anAny <<= (long ) 0 ;
1921 anOutPort->Value( anAny ) ;
1922 anInPort->PortState( SUPERV::WaitingState ) ;
1926 else if ( anInPort->PortState() != SUPERV::WaitingState &&
1927 !anInPort->IsDataConnected() ) {
1929 // cdebug << ThreadNo()
1930 // << " --> GraphExecutor::InNodeThreads::SetWaitingStates " << Name() << endl;
1933 if ( !anInPort->IsDataStream() ) {
1934 anInPort->PortState( SUPERV::WaitingState ) ;
1937 // cdebug << " --> " << Name() << "( " << anInPort->PortName() << " ) "
1938 // << anInPort->PortStatus() << " " << anInPort->State() << endl ;
1940 for ( i = 0 ; i < GetNodeOutPortsSize() ; i++ ) {
1941 GraphBase::OutPort * anOutPort = GetChangeNodeOutPort( i ) ;
1942 //JR 07.03.2005 Debug : Reset of Done flag in OutPorts !... :
1943 if ( !anOutPort->IsDataStream() ) {
1944 anOutPort->PortDone( false ) ;
1946 for ( j = 0 ; j < anOutPort->InPortsSize() ; j++ ) {
1947 if ( !( IsGOTONode() && anOutPort->IsGate() ) &&
1948 !( IsEndLoopNode() && ( anOutPort->IsGate() || anOutPort->IsLoop() ) ) &&
1949 !anOutPort->IsDataStream() &&
1950 !anOutPort->ChangeInPorts( j )->IsDataStream() &&
1951 !anOutPort->ChangeInPorts( j )->IsExternConnected() ) {
1952 // cdebug << ThreadNo()
1953 // << " InNodeThreads::SetWaitingStates OutPort "
1954 // << Name() << "/" << anOutPort->ChangeInPorts( j )->NodeName() << "( "
1955 // << anOutPort->PortName() << " " << anOutPort->PortStatus() << " ) --> InPort "
1956 // << anOutPort->ChangeInPorts( j )->NodeName() << "( "
1957 // << anOutPort->ChangeInPorts( j )->PortName() << " "
1958 // << anOutPort->ChangeInPorts( j )->PortStatus() << " )" << endl;
1959 GraphBase::ComputingNode * aToNode ;
1960 aToNode = _OutNode->Graph()->GetChangeGraphNode( anOutPort->ChangeInPorts( j )->NodeName() ) ;
1961 // JR 12.01.2005 : the OutPort linked to the InPort of a EndSwitchNode was changed so final
1962 // values of InPorts of EndSwitchNode may be wrong
1963 if ( !aToNode->IsEndSwitchNode() &&
1964 strcmp( anOutPort->ChangeInPorts( j )->GetOutPort()->NodeName() , Name() ) ) {
1965 // After EndLoopNode or GOTONode the Input Ports of LoopNode or LabelNode have their values from
1966 // EndLoopNode or GOTONode. But if there is several nested loops we should re-establish.
1967 // cdebug << ThreadNo()
1968 // << " InNodeThreads::SetWaitingStates Node " << Name() << " "
1969 // << anOutPort->ChangeInPorts( j )->GetOutPort()->NodeName() << "( "
1970 // << anOutPort->ChangeInPorts( j )->GetOutPort()->PortName() << " ) != "
1971 // << Name() << " : Restored to " << anOutPort->NodeName() << "( "
1972 // << anOutPort->PortName() << " )" << endl ;
1973 anOutPort->ChangeInPorts( j )->ChangeOutPort( anOutPort ) ;
1975 GraphExecutor::InNode * aNode = (GraphExecutor::InNode * ) aToNode->GetInNode() ;
1976 if ( aNode != EndNode ) {
1977 aNode->SetWaitingStates( EndNode ) ;
1984 int GraphExecutor::InNode::Successed_SuccessAction() {
1985 cdebug << ThreadNo() << " --> Successed_SuccessAction " << Name() << endl;
1987 int linkednodesnumber = LinkedNodesSize() ;
1988 GraphExecutor::InNode *firstzeroNode = NULL ;
1989 GraphExecutor::InNode *firsttoNode = NULL ;
1990 GraphExecutor::InNode *toNode ;
1993 list<GraphExecutor::InNode *> SomeDataNodes ;
1997 if ( IsMacroNode() ) {
1998 cdebug << pthread_self() << "/" << ThreadNo() << " Successed_SuccessAction " << Name() << " LinkedNodes->SomeDataReady already done"
2003 //JR 09.02.2005 : That complicated part of the code manages LOOPS and GOTO
2004 if ( IsGOTONode() ||
2005 ( IsEndLoopNode() && GetNodeInLoop()->GetOutPort()->BoolValue() ) ) {
2006 // cdebug << pthread_self() << "/" << ThreadNo() << " Successed_SuccessAction " << Name()
2007 // << " SetWaitingStates " << endl ;
2008 const GraphBase::OutPort * aGateOutPort ;
2009 if ( IsGOTONode() ) {
2010 aGateOutPort = GetNodeOutGate() ;
2013 aGateOutPort = GetNodeOutLoop() ;
2015 if ( aGateOutPort->InPortsSize() != 1 ) {
2016 cdebug << pthread_self() << "/" << ThreadNo() << " Successed_SuccessAction aGateOutPort->InPortsSize "
2017 << aGateOutPort->InPortsSize() << " != 1 ERROR " << Name() << endl ;
2019 GraphExecutor::InNode * aLabelNode = NULL ;
2020 for ( i = 0 ; i < aGateOutPort->InPortsSize() ; i++ ) {
2021 const GraphBase::InPort * anInPort = aGateOutPort->InPorts( i ) ;
2022 aLabelNode = (GraphExecutor::InNode *) _OutNode->Graph()->GetChangeGraphNode( anInPort->NodeName() )->GetInNode() ;
2023 // cdebug << pthread_self() << "/" << ThreadNo() << " Successed_SuccessAction " << Name() << " will Loop to HeadNode "
2024 // << aLabelNode->Name() << " from port " << anInPort->PortName() << endl ;
2025 aLabelNode->SetWaitingStates( this ) ;
2026 // JR 07.01.2005 Debug : Open the Gate of the coupledNode closed by SetWaitingStates
2027 GraphBase::OutPort * anOutPort = aLabelNode->GetChangeNodeInGate()->GetOutPort() ;
2029 //JR 21.02.2005 Debug Memory leak : CORBA::Any * anAny = new CORBA::Any() ;
2030 CORBA::Any anAny = CORBA::Any() ;
2031 //JR 21.02.2005 Debug Memory leak : *anAny <<= (long ) 1 ;
2032 anAny <<= (long ) 1 ;
2033 anOutPort->Value( anAny ) ;
2034 aLabelNode->GetChangeNodeInGate()->PortState( SUPERV::ReadyState ) ;
2037 for ( j = 0 ; j < aLabelNode->GetNodeInPortsSize() ; j++ ) {
2038 const GraphBase::InPort * anInPort = aLabelNode->GetNodeInPort( j ) ;
2039 if ( anInPort->GetOutPort() ) {
2040 // cdebug << aLabelNode->Name() << "(" << anInPort->PortName() << ") value : "
2041 // << anInPort->GetOutPort()->NodeName() << "(" << anInPort->GetOutPort()->PortName() << ")"
2045 for ( j = 0 ; j < GetNodeOutPortsSize() ; j++ ) {
2046 GraphBase::OutPort * aBusParamOutPort = GetChangeNodeOutPort( j ) ;
2047 if ( !aBusParamOutPort->IsGate() ) {
2048 GraphBase::InPort * aBusParamChangeInPort = NULL ;
2049 if ( aBusParamOutPort->IsLoop() ) {
2050 // For EndLoop do not copy EndLoop(DoLoop) in Loop(InLoop)
2051 // aBusParamChangeInPort = aLabelNode->GetChangeNodeInLoop() ;
2054 aBusParamChangeInPort = aLabelNode->GetChangeInPort( aBusParamOutPort->PortName() ) ;
2056 if ( aBusParamChangeInPort ) {
2057 aBusParamChangeInPort->ChangeOutPort( aBusParamOutPort ) ;
2058 cdebug << pthread_self() << "/" << ThreadNo() << " Successed_SuccessAction " << Name() << " ChangeOutPort to HeadNode "
2059 << aLabelNode->Name() << "(" << aBusParamChangeInPort->PortName() << ") from port "
2060 << aBusParamOutPort->PortName() << endl ;
2066 if ( aLabelNode && !aLabelNode->IsLockedDataWait() ) {
2067 res = aLabelNode->SendSomeDataReady( Name() ) ;
2069 if ( firsttoNode == NULL &&
2070 aLabelNode->ThreadNo() == pthread_self() ) {
2071 firsttoNode = aLabelNode ;
2072 // cdebug << pthread_self() << "/" << ThreadNo() << " Successed_SuccessAction firsttoNode "
2073 // << aLabelNode->Name() << endl ;
2075 else if ( firstzeroNode == NULL &&
2076 aLabelNode->ThreadNo() == 0 ) {
2077 firstzeroNode = aLabelNode ;
2080 SomeDataNodes.push_back( aLabelNode ) ;
2081 // cdebug << pthread_self() << "/" << ThreadNo() << " Successed_SuccessAction " << Name() << " push "
2082 // << aLabelNode->Name() << " " << SomeDataNodes.size()
2087 // for ( j = 0 ; j < aLabelNode->GetNodeInPortsSize() ; j++ ) {
2088 // const GraphBase::InPort * anInPort = aLabelNode->GetNodeInPort( j ) ;
2089 // if ( anInPort->GetOutPort() ) {
2090 // cdebug << aLabelNode->Name() << "(" << anInPort->PortName() << ") value : "
2091 // << anInPort->GetOutPort()->NodeName() << "(" << anInPort->GetOutPort()->PortName() << ")"
2095 const GraphBase::InPort * aGateInPort = aLabelNode->GetNodeInGate() ;
2096 if ( aGateInPort ) {
2097 if ( aGateInPort->GetOutPort() ) {
2098 //JR 21.02.2005 Debug Memory leak : aGateInPort->GetOutPort()->Value( aGateOutPort->Value() ) ;
2099 aGateInPort->GetOutPort()->Value( *aGateOutPort->Value() ) ;
2101 if ( !aLabelNode->IsLockedDataWait() ) {
2102 res = aLabelNode->SendSomeDataReady( Name() ) ;
2104 if ( firsttoNode == NULL &&
2105 aLabelNode->ThreadNo() == pthread_self() ) {
2106 firsttoNode = aLabelNode ;
2107 // cdebug << pthread_self() << "/" << ThreadNo() << " Successed_SuccessAction firsttoNode "
2108 // << aLabelNode->Name() << endl ;
2110 else if ( firstzeroNode == NULL &&
2111 aLabelNode->ThreadNo() == 0 ) {
2112 firstzeroNode = aLabelNode ;
2115 SomeDataNodes.push_back( aLabelNode ) ;
2116 // cdebug << pthread_self() << "/" << ThreadNo() << " Successed_SuccessAction " << Name() << " push "
2117 // << aLabelNode->Name() << " " << SomeDataNodes.size()
2124 cdebug << pthread_self() << "/" << ThreadNo() << " ERROR in Successed_SuccessAction of " << Name()
2125 << " NO port " << aGateOutPort->PortName() << " in "
2126 << aLabelNode->Name() << endl;
2131 // JR 09.02.2005 : this is not a EndLoop or a GOTO :
2133 cdebug << ThreadNo() << " Successed_SuccessAction of " << Name()
2134 << " with " << LinkedNodesSize() << " linked nodes :" ;
2135 for ( i = 0 ; i < LinkedNodesSize() ; i++ ) {
2136 if ( LinkedNodes( i )->IsDataFlowNode() ) {
2137 linkednodesnumber -= 1 ;
2139 cdebug << " " << LinkedNodes( i )->Name() ;
2142 for ( i = 0 ; i < LinkedNodesSize() ; i++ ) {
2143 // If this is a LoopNode and if DoLoopPort == false, we go directly to the EndOfLoopNode and
2144 // we do not activate Nodes within the loop
2145 bool IgnoreForEndLoop = false ;
2146 // If this is a SwitchNode and if DefaultOutPort == true, we may activate Nodes within Switch
2147 // or we may activate directly the EnSwitch
2148 // BUT the NotSwitchBranch(es) are NOT activated :
2149 bool IgnoreForDefaultSwitch = false ;
2150 GraphBase::ComputingNode * aComputingNode ;
2151 aComputingNode = (GraphBase::ComputingNode * ) LinkedNodes( i ) ;
2152 toNode = (GraphExecutor::InNode *) aComputingNode->GetInNode() ;
2153 cdebug << pthread_self() << "/" << ThreadNo() << " Successed_SuccessAction of " << Name()
2154 << " [" << i << "] " << LinkedNodes( i )->Name() << " toNode " << toNode
2155 << " IgnoreForEndLoop " << IgnoreForEndLoop ;
2157 cdebug << " " << toNode->Kind() << endl ;
2159 if ( toNode && !toNode->IsDataFlowNode() ) {
2160 if ( IsComputingNode() && toNode->IsInLineNode() ) {
2161 GraphBase::InPort * toGateInPort = toNode->GetChangeNodeInGate() ;
2162 toGateInPort->PortState( SUPERV::ReadyState ) ;
2163 GraphBase::OutPort * GateOutPort = toGateInPort->GetOutPort() ;
2164 if ( GateOutPort ) {
2165 GateOutPort->PortStatus( DataConnected );
2166 GateOutPort->PortState( SUPERV::ReadyState ) ;
2167 GateOutPort->PortDone( true ) ;
2171 if ( toNode && IsLoopNode() ) {
2172 GraphBase::OutPort * fromLoopOutPort = GetChangeNodeOutLoop() ;
2173 if ( !fromLoopOutPort->BoolValue() ) { // Ne pas faire la boucle
2174 if ( strcmp( toNode->Name() , CoupledNode()->Name() ) ) {
2175 IgnoreForEndLoop = true ;
2177 else { // toNode is the EndLoopNode
2178 GraphBase::InPort * toLoopInPort ;
2179 toLoopInPort = toNode->GetChangeNodeInLoop() ;
2180 if ( toLoopInPort->PortState() != SUPERV::ReadyState ) {
2181 toLoopInPort->PortState( SUPERV::ReadyState ) ;
2186 else if ( toNode && IsSwitchNode() ) {
2187 const GraphBase::OutPort * anOutGatePort = GetNodeOutGate() ;
2188 if ( anOutGatePort->BoolValue() && anOutGatePort->InPortsSize() ) { // DefaultPort is activated
2189 IgnoreForDefaultSwitch = true ;
2192 else if ( toNode && toNode->IsInLineNode() ) {
2194 for ( j = 0 ; j < toNode->GetNodeInPortsSize() ; j++ ) {
2195 toNode->GetChangeNodeInPort( j )->InitialOutPort() ;
2198 if ( toNode && !IgnoreForEndLoop ) {
2199 if ( toNode && toNode->IsLoopNode() ) {
2200 GraphBase::InPort * toLoopInPort = toNode->GetChangeNodeInLoop() ;
2201 toLoopInPort->PortState( SUPERV::ReadyState ) ;
2202 GraphBase::OutPort * LoopOutPort = toLoopInPort->GetOutPort() ;
2203 LoopOutPort->PortStatus( DataConnected );
2204 LoopOutPort->PortState( SUPERV::ReadyState ) ;
2205 LoopOutPort->PortDone( true ) ;
2206 //JR 21.02.2005 Debug Memory leak : CORBA::Any * anAny = new CORBA::Any() ; // InitLoop
2207 CORBA::Any anAny = CORBA::Any() ; // InitLoop
2208 //JR 21.02.2005 Debug Memory leak : *anAny <<= (long ) 1 ;
2209 anAny <<= (long ) 1 ;
2210 LoopOutPort->Value( anAny ) ;
2213 for ( j = 0 ; j < toNode->GetNodeInPortsSize() ; j++ ) {
2214 toNode->GetChangeNodeInPort( j )->InitialOutPort() ;
2217 // If the DefaultPort of that SwitchNode is connected to the DefaultPort od the EndSwitchNode
2218 // the NotSwitchBranch(es) are NOT activated :
2219 // If the DefaultPort of that SwitchNode is connected to SwitchBranch(es)
2220 // the NotSwitchBranch(es) are NOT activated :
2221 bool activatetoNode = true ;
2222 if ( IgnoreForDefaultSwitch ) {
2223 cdebug << pthread_self() << "/" << ThreadNo() << " Successed_SuccessAction search "
2224 << toNode->Name() << " among linked nodes to DefaultPort of " << Name() << endl ;
2225 activatetoNode = false ;
2226 const GraphBase::OutPort * anOutGatePort = GetNodeOutGate() ;
2227 const GraphBase::InPort * anInPort = NULL ;
2229 for ( j = 0 ; j < anOutGatePort->InPortsSize() ; j++ ) {
2230 anInPort = anOutGatePort->InPorts( j ) ;
2231 const GraphBase::ComputingNode * aNode ;
2232 aNode = _OutNode->Graph()->GetGraphNode( anInPort->NodeName() ) ;
2234 cdebug << pthread_self() << "/" << ThreadNo() << " Successed_SuccessAction try "
2235 << aNode << " " << aNode->Name() << " == " << toNode << " " << toNode->Name()
2238 if ( aNode && (const GraphBase::ComputingNode * ) toNode->ComputingNode() == aNode ) {
2239 // toNode is connected to the DefaultPort of that SwitchNode :
2240 activatetoNode = true ;
2244 // if ( activatetoNode ) {
2245 // cdebug << pthread_self() << "/" << ThreadNo() << " Successed_SuccessAction found "
2246 // << toNode->Name() << " among linked nodes to DefaultPort of " << Name()
2250 // cdebug << pthread_self() << "/" << ThreadNo()
2251 // << " Successed_SuccessAction does NOT found "
2252 // << toNode->Name() << " among linked nodes to DefaultPort of " << Name()
2256 if ( activatetoNode ) {
2257 // cdebug << pthread_self() << "/" << ThreadNo() << " Successed_SuccessAction "
2258 // << toNode->Name() << "->SendSomeDataReady( " << Name() << " )" << endl ;
2259 res = toNode->SendSomeDataReady( Name() ) ;
2261 if ( firsttoNode == NULL &&
2262 toNode->ThreadNo() == pthread_self() ) {
2263 firsttoNode = toNode ;
2264 // cdebug << pthread_self() << "/" << ThreadNo()
2265 // << " Successed_SuccessAction firsttoNode " << toNode->Name() << endl ;
2267 else if ( firstzeroNode == NULL &&
2268 toNode->ThreadNo() == 0 ) {
2269 firstzeroNode = toNode ;
2272 SomeDataNodes.push_back( toNode ) ;
2273 // cdebug << pthread_self() << "/" << ThreadNo() << " Successed_SuccessAction "
2274 // << Name() << " push "
2275 // << toNode->Name() << " " << SomeDataNodes.size() << endl ;
2283 //JR 10.02.2005 : Debug at the end of execution of a SwitchNode :
2284 // Here after we may start execution of only one SwitchBranch or of the Default
2285 // But with activation of only one SwitchBranch we may activate several nodes of that SwitchBranch and
2286 // we may activate several nodes of NotSwitchBranch ( a NotSwitchBranch is a Branch of the Switch
2287 // where GatePorts of Nodes are not connected ; that Branches are always executed for each of SwitchBranch
2288 // BUT are not executed when Default is activated).
2289 // So the bug is that all input ports of the corresponding EndSwitchNode must have the status NOTDONE !
2290 // (Only if Default OutPort is closed and Default InPort is closed)
2291 if ( IsSwitchNode() ) {
2292 GraphBase::InLineNode * anEndSwitchNode = GOTONode()->CoupledNode() ;
2293 if ( !GetNodeOutGate()->BoolValue() && anEndSwitchNode->GetNodeInGate()->GetOutPort() &&
2294 !anEndSwitchNode->GetNodeInGate()->GetOutPort()->BoolValue() ) {
2295 cdebug << pthread_self() << "/" << ThreadNo() << " Successed_SuccessAction " << anEndSwitchNode->Name()
2296 << " reset of InPort()->OutPort()->Done flag in EndSwitch" << endl ;
2298 for ( i = 0 ; i < anEndSwitchNode->GetNodeInPortsSize() ; i++ ) {
2299 GraphBase::OutPort * anOutPort = anEndSwitchNode->GetChangeNodeInPort( i )->GetOutPort() ;
2300 //JR 08.03.2005 Debug : update of state only if not a StreamPort
2301 if ( anOutPort && strcmp( anOutPort->NodeName() , Name() ) &&
2302 !anOutPort->IsDataStream() ) {
2303 cdebug << pthread_self() << "/" << ThreadNo() << " Successed_SuccessAction "
2304 << anEndSwitchNode->Name() << " InPort "
2305 << anEndSwitchNode->GetChangeNodeInPort( i )->PortName() << " NOTDONE from "
2306 << anOutPort->NodeName() << " " << anOutPort->PortName() << endl ;
2307 anEndSwitchNode->GetChangeNodeInPort( i )->PortState( SUPERV::WaitingState ) ;
2308 anEndSwitchNode->GetChangeNodeInPort( i )->GetOutPort()->PortDone( false ) ;
2311 cdebug << pthread_self() << "/" << ThreadNo() << " Successed_SuccessAction "
2312 << anEndSwitchNode->Name() << " InPort "
2313 << anEndSwitchNode->GetChangeNodeInPort( i )->PortName() << " NOT Changed : directly from "
2314 << anOutPort->NodeName() << " " << anOutPort->PortName() << endl ;
2319 cdebug << pthread_self() << "/" << ThreadNo() << " Successed_SuccessAction " << Name()
2320 << " " << Kind() << " OutGate->Value " << GetNodeOutGate()->BoolValue()
2321 << " NO reset of InPort()->OutPort()->Done flag in EndSwitch" << endl ;
2325 // firsttoNode : node that has the same ThreadNo() as the current node and that have to be activated
2326 // firstzeroNode : node that has a null ThreadNo() and that have to be activated
2327 if ( firsttoNode == NULL && firstzeroNode ) {
2328 firsttoNode = firstzeroNode ;
2329 // cdebug << pthread_self() << "/" << ThreadNo()
2330 // << " Successed_SuccessAction firsttoNode = firstzeroNode " << firsttoNode->Name()
2333 else if ( firsttoNode && firstzeroNode ) {
2334 SomeDataNodes.push_back( firstzeroNode ) ;
2335 // cdebug << pthread_self() << "/" << ThreadNo() << " Successed_SuccessAction " << Name() << " push firstzeroNode "
2336 // << firstzeroNode->Name() << " " << SomeDataNodes.size() << endl ;
2337 firstzeroNode = NULL ;
2340 // cdebug << pthread_self() << "/" << ThreadNo() << " Successed_SuccessAction " << Name() << " firsttoNode " << firsttoNode
2341 // << " firstzeroNode " << firstzeroNode << endl ;
2344 while ( SomeDataNodes.size() ) {
2345 GraphExecutor::InNode *aNode = SomeDataNodes.front() ;
2346 SomeDataNodes.pop_front() ;
2347 // cdebug << pthread_self() << "/" << ThreadNo()
2348 // << " Successed_SuccessAction pop size "
2349 // << SomeDataNodes.size() << " " << aNode->Name() << endl ;
2350 if ( aNode->State() == GraphExecutor::DataReadyState ) {
2351 // cdebug << pthread_self() << "/" << ThreadNo() << " Successed_SuccessAction pop CreateNewThreadIf( true )"
2353 aNode->CreateNewThreadIf( true ) ;
2354 _OutNode->IncrCreatedThreads() ;
2355 aNode->UnLockDataWait() ;
2356 res = aNode->DataUndef_AllDataReadyAction() ;
2359 // cdebug << pthread_self() << "/" << ThreadNo() << " ERROR "
2360 // << aNode->Name() << " "
2361 // << Automaton()->StateName( aNode->State() ) << endl ;
2365 if ( firsttoNode ) {
2366 // cdebug << pthread_self() << "/" << ThreadNo()
2367 // << " Successed_SuccessAction start firsttoNode "
2368 // << SomeDataNodes.size() << " " << firsttoNode->Name() << endl ;
2369 firsttoNode->CreateNewThreadIf( false ) ;
2370 firsttoNode->RewindStack( RewindStack() ) ;
2371 if ( firsttoNode->State() == GraphExecutor::SuccessedState ) {
2372 // cdebug << pthread_self() << "/" << ThreadNo() << " " << Name()
2373 // << " : " << firsttoNode->Name() << " "
2374 // << Automaton()->StateName( firsttoNode->State() )
2375 // << " --> DataWaitingState for Thread "
2376 // << firsttoNode->ThreadNo() << endl ;
2377 firsttoNode->State( GraphExecutor::DataWaitingState ) ;
2379 // pthread_t OldT = firsttoNode->ThreadNo() ;
2380 firsttoNode->ThreadNo( pthread_self() ) ;
2381 // On continue avec le meme thread
2382 // cdebug << pthread_self() << "/" << ThreadNo() << " firsttoNode "
2383 // << firsttoNode->Name() << "Thread(" << OldT << "-->"
2384 // << firsttoNode->ThreadNo() << ")" << endl ;
2386 // cdebug << ThreadNo() << " Successed_SuccessAction " << Name()
2387 // << " for " << firsttoNode->Name()
2388 // << " !firsttoNode->CreateNewThreadIf() "
2389 // << !firsttoNode->CreateNewThreadIf()
2390 // << " " << Automaton()->StateName( firsttoNode->State() ) ;
2391 if ( firsttoNode->State() == GraphExecutor::DataReadyState ) {
2393 firsttoNode->UnLockDataWait() ;
2394 res = firsttoNode->DataUndef_AllDataReadyAction() ;
2397 cdebug << " ERROR " << endl ;
2401 // cdebug << ThreadNo() << " Successed_SuccessAction " << Name()
2402 // << " NO DataReady ==> ThreadNo( 0 ) firsttoNode == NULL LINKEDnodesnumber " << linkednodesnumber << endl ;
2406 // if ( linkednodesnumber == 0 && firsttoNode == NULL ) {
2407 // cdebug << ThreadNo() << " Successed_SuccessAction " << Name() << " LinkedNodesSize " << LinkedNodesSize()
2408 // << " firsttoNode == NULL LINKEDnodesnumber " << linkednodesnumber << " CHECK" << endl ;
2409 // _OutNode->CheckAllDone() ;
2412 // cdebug << pthread_self() << "/" << ThreadNo()
2413 // << " <-- Successed_SuccessAction " << Name() << " linkednodesnumber "
2414 // << linkednodesnumber << endl;
2418 bool GraphExecutor::InNode::SendSomeDataReady( char * FromNodeName ) {
2419 bool RetVal = false ;
2420 if ( IsDataFlowNode() ) {
2421 // cdebug << ThreadNo() << "InNode::SendSomeDataReady ----> " << Name()
2422 // << " send Result to graph " << Name() << endl;
2425 // cdebug << pthread_self() << "/" << ThreadNo() << " ----> " << FromNodeName
2426 // << " send SomeDataReady to " << Name() << " "
2427 // << Automaton()->StateName( State() )
2428 // << " CreateNewThreadIf() " << CreateNewThreadIf()
2429 // << " LockedDataWait " << IsLockedDataWait() << endl;
2431 //cout << pthread_self() << "/" << ThreadNo() << " ----> " << FromNodeName
2432 << " send SomeDataReady to " << Name() << " "
2433 << Automaton()->StateName( State() )
2434 << " CreateNewThreadIf() " << CreateNewThreadIf()
2435 << " LockedDataWait " << IsLockedDataWait() << endl;
2437 if ( State() == GraphExecutor::SuccessedState ||
2438 State() == GraphExecutor::SuspendedSuccessedState ||
2439 State() == GraphExecutor::SuspendedSuccessedToReStartState ) {
2440 // cdebug << ThreadNo() << " " << FromNodeName
2441 // << " : " << Name() << " " << Automaton()->StateName( State() )
2442 // << " --> DataWaitingState for Thread "
2443 // << ThreadNo() << " " << endl ;
2444 State( GraphExecutor::DataWaitingState ) ;
2446 // We begin that LoopNode if SendSomeDataReady does not come from the corresponding EndLoopNode
2447 if ( IsLoopNode() && strcmp( LoopNode()->CoupledNodeName() , FromNodeName ) ) {
2448 cdebug << ThreadNo() << "InNode::SendSomeDataReady " << Name() << " Set _InitLoop from "
2449 << FromNodeName << endl ;
2453 DataFromNode( FromNodeName ) ;
2454 RetVal = !SendEvent( GraphExecutor::SomeDataReadyEvent );
2462 int GraphExecutor::InNode::Errored_ErrorAction() {
2463 cdebug << ThreadNo() << " Errored_ErrorAction " << Name()
2464 << " will pthread_exit" << endl;
2469 int GraphExecutor::InNode::Successed_SuspendAction() {
2470 cdebug << ThreadNo() << " Successed_SuspendAction -->Suspend " << Name()
2471 << " Threads " << _OutNode->Threads() << " SuspendedThreads "
2472 << _OutNode->SuspendedThreads() << endl;
2473 _OutNode->PushEvent( this , GraphExecutor::SuspendedSuccessedEvent ,
2474 GraphExecutor::SuspendedSuccessedState ) ;
2476 GraphExecutor::InNode * aReStartNode = SuspendAction() ;
2477 cdebug << ThreadNo() << " Successed_SuspendAction Resumed " << Name() ;
2478 if ( aReStartNode ) {
2479 _aReStartNode = NULL ;
2480 cdebug << " for " << aReStartNode->Name() << endl;
2481 aReStartNode->SendEvent( _aReStartEvent ) ;
2485 SendEvent( GraphExecutor::ResumeEvent ) ;
2490 int GraphExecutor::InNode::Errored_SuspendAction() {
2491 cdebug << ThreadNo() << " Errored_SuspendAction -->Suspend " << Name()
2492 << " Threads " << _OutNode->Threads() << " SuspendedThreads "
2493 << _OutNode->SuspendedThreads() << endl;
2494 _OutNode->PushEvent( this , GraphExecutor::SuspendedErroredEvent ,
2495 GraphExecutor::SuspendedErroredState ) ;
2497 GraphExecutor::InNode * aReStartNode = SuspendAction() ;
2498 cdebug << ThreadNo() << " Errored_SuspendAction Resumed " << Name()
2500 if ( aReStartNode ) {
2501 _aReStartNode = NULL ;
2502 aReStartNode->SendEvent( _aReStartEvent ) ;
2505 SendEvent( GraphExecutor::ResumeEvent ) ;
2510 int GraphExecutor::InNode::SuspendedSuccessed_ResumeAction() {
2511 cdebug << ThreadNo() << " SuspendedSuccessed_ResumeAction " << Name() << endl;
2513 _OutNode->PushEvent( this , GraphExecutor::ResumedSuccessedEvent ,
2514 GraphExecutor::ResumedSuccessedState ) ;
2515 SendEvent( ResumedSuccessedEvent ) ;
2519 int GraphExecutor::InNode::SuspendedErrored_ResumeAction() {
2520 cdebug << ThreadNo() << " SuspendedErrored_ResumeAction " << Name() << endl;
2522 _OutNode->PushEvent( this , GraphExecutor::ResumedErroredEvent ,
2523 GraphExecutor::ResumedErroredState ) ;
2524 SendEvent( ResumedErroredEvent ) ;
2528 int GraphExecutor::InNode::Successed_KillAction() {
2530 _OutNode->PushEvent( this , GraphExecutor::KilledEvent ,
2531 GraphExecutor::KilledSuccessedState ) ;
2532 cdebug << ThreadNo() << " Successed_KillAction " << Name() << endl;
2536 int GraphExecutor::InNode::Errored_KillAction() {
2538 _OutNode->PushEvent( this , GraphExecutor::KilledEvent ,
2539 GraphExecutor::KilledErroredState ) ;
2540 cdebug << ThreadNo() << " Errored_KillAction " << Name() << endl;
2544 int GraphExecutor::InNode::Successed_StopAction() {
2546 _OutNode->PushEvent( this , GraphExecutor::StoppedEvent ,
2547 GraphExecutor::StoppedSuccessedState ) ;
2548 cdebug << ThreadNo() << " Successed_StopAction " << Name() << endl;
2552 int GraphExecutor::InNode::Errored_StopAction() {
2554 _OutNode->PushEvent( this , GraphExecutor::StoppedEvent ,
2555 GraphExecutor::StoppedErroredState ) ;
2556 cdebug << ThreadNo() << " Errored_StopAction " << Name() << endl;
2560 int GraphExecutor::InNode::SuspendedSuccessed_ReStartAction() {
2561 cdebug << ThreadNo() << " SuspendedSuccessed_ReStartAction " << Name() << endl;
2562 _OutNode->PushEvent( this , GraphExecutor::ReStartedEvent ,
2563 GraphExecutor::ReStartedState ) ;
2565 for ( i = 0 ; i < GetNodeInPortsSize() ; i++ ) {
2566 GetChangeNodeInPort( i )->PortState( SUPERV::ReadyState ) ;
2568 SendEvent( ExecuteEvent ) ;
2569 cdebug << ThreadNo() << " SuspendedSuccessed_ReStartAction " << Name() << endl;
2573 int GraphExecutor::InNode::SuspendedErrored_ReStartAction() {
2574 cdebug << ThreadNo() << " SuspendedErrored_ReStartAction " << Name() << endl;
2575 _OutNode->PushEvent( this , GraphExecutor::ReStartedEvent ,
2576 GraphExecutor::ReStartedState ) ;
2578 for ( i = 0 ; i < GetNodeInPortsSize() ; i++ ) {
2579 GetChangeNodeInPort( i )->PortState( SUPERV::ReadyState ) ;
2581 SendEvent( ExecuteEvent ) ;
2582 cdebug << ThreadNo() << " SuspendedErrored_ReStartAction " << Name() << endl;
2586 int GraphExecutor::InNode::SuspendedSuccessed_ReStartAndSuspendAction() {
2587 cdebug << ThreadNo() << " SuspendedSuccessed_ReStartAndSuspendAction " << Name()
2589 _OutNode->PushEvent( this , GraphExecutor::ReStartedAndSuspendEvent ,
2590 GraphExecutor::ReStartedState ) ;
2591 State( GraphExecutor::DataWaitingState ) ;
2593 cdebug << "InNode::Suspend() Node " << Name() << endl ;
2596 else if ( SendEvent( GraphExecutor::SomeDataReadyEvent ) ) {
2597 cdebug << "InNode::SendEvent( SomeDataReadyEvent ) Node "
2601 cdebug << ThreadNo() << " SuspendedSuccessed_ReStartAndSuspendAction " << Name()
2606 int GraphExecutor::InNode::SuspendedErrored_ReStartAndSuspendAction() {
2607 cdebug << ThreadNo() << " SuspendedErrored_ReStartAndSuspendAction " << Name()
2609 _OutNode->PushEvent( this , GraphExecutor::ReStartedAndSuspendEvent ,
2610 GraphExecutor::ReStartedState ) ;
2611 State( GraphExecutor::DataWaitingState ) ;
2613 cdebug << "InNode::Suspend() Node " << Name() << endl ;
2616 else if ( SendEvent( GraphExecutor::SomeDataReadyEvent ) ) {
2617 cdebug << "InNode::SendEvent( SomeDataReadyEvent ) Node "
2621 cdebug << ThreadNo() << " SuspendedErrored_ReStartAndSuspendAction " << Name()
2626 void GraphExecutor::InNode::InParametersSet( bool & Err ,
2628 ServicesAnyData * InParametersList ) {
2630 cdebug << pthread_self() << "/" << ThreadNo() << " InParametersSet " << Name() << endl ;
2631 for ( i = 0 ; i < nInParams ; i++ ) {
2632 ServicesAnyData D = InParametersList[i];
2633 GraphBase::InPort * anInPort = GetChangeNodeInPort(i) ;
2634 GraphBase::OutPort * theOutPort = anInPort->GetOutPort() ;
2635 if ( anInPort->IsGate() && theOutPort == NULL ) {
2636 cdebug << ThreadNo() << " ArgIn" << i << " " << D.Name << " "
2637 << anInPort->GetServicesParameter().Parametertype
2638 << " is inactive. " << anInPort->Kind() << endl ;
2640 else if ( anInPort->PortState() == SUPERV::ReadyState ) {
2641 if ( anInPort->IsGate() ) {
2642 //JR 21.02.2005 Debug Memory leak : CORBA::Any * anAny = new CORBA::Any() ;
2643 CORBA::Any anAny = CORBA::Any() ;
2644 //JR 21.02.2005 Debug Memory leak : *anAny <<= (long ) 0 ;
2645 anAny <<= (long ) 0 ;
2646 theOutPort->Value( anAny ) ;
2649 if ( !anInPort->IsDataStream() &&
2650 !anInPort->IsDataConnected() ) {
2651 anInPort->PortState( SUPERV::WaitingState ) ;
2653 //JR 18.02.2005 Debug Memory leak : delete does not destroy that string ...
2654 // D.Name = CORBA::string_dup( anInPort->GetServicesParameter().Parametername ) ;
2655 D.Name = anInPort->PortName() ;
2656 cdebug << ThreadNo() << " ArgIn" << i << " " << anInPort->Kind()
2657 << " " << anInPort->PortState() ;
2658 cdebug << " " << D.Name << " " << anInPort->GetServicesParameter().Parametertype << " : " << endl ;
2659 D.Value = *theOutPort->Value() ; // CORBA::Any
2660 //JR 18.02.2005 Debug Memory leak : string _Type = CORBA::string_dup( anInPort->GetServicesParameter().Parametertype ) ;
2661 // const char * Type = _Type.c_str() ;
2662 const char * Type = anInPort->GetServicesParameter().Parametertype ;
2663 switch ( D.Value.type()->kind() ) { // { string , long , double , objref }
2664 case CORBA::tk_string:
2667 cdebug << t << " (string)" ;
2668 if ( !strcmp( Type , "string" ) ) {
2670 else if ( !strcmp( Type , "boolean" ) ) {
2673 sscanf( t , "%ld" , &d ) ;
2675 D.Value <<= (CORBA::Any::from_boolean ) b ;
2676 // theOutPort->Value( D.Value ) ;
2678 else if ( !strcmp( Type , "char" ) ) {
2681 sscanf( t , "%ld" , &d ) ;
2683 D.Value <<= (CORBA::Any::from_char ) c ;
2684 cdebug << "string '" << t << "' --> " << d << " --> char " << c ;
2685 // theOutPort->Value( D.Value ) ;
2687 else if ( !strcmp( Type , "short" ) ) {
2690 sscanf( t , "%ld" , &d ) ;
2693 cdebug << "string '" << t << "' --> " << d << " --> short " << s ;
2694 // theOutPort->Value( D.Value ) ;
2696 else if ( !strcmp( Type , "int" ) || !strcmp( Type , "long" ) ) {
2698 sscanf( t , "%ld" , &l ) ;
2700 cdebug << "string '" << t << " --> long " << l ;
2701 // theOutPort->Value( D.Value ) ;
2703 else if ( !strcmp( Type , "float" ) ) {
2705 sscanf( t , "%lf" , &d ) ;
2708 cdebug << "string '" << t << "' --> " << setw(25) << setprecision(18) << d << " --> float " << " = "
2709 << setw(25) << setprecision(18) << f ;
2710 // theOutPort->Value( D.Value ) ;
2712 else if ( !strcmp( Type , "double" ) ) {
2714 sscanf( t , "%lf" , &d ) ;
2716 cdebug << "string '" << t << " --> double " << setw(25) << setprecision(18) << d ;
2717 // theOutPort->Value( D.Value ) ;
2719 // else if ( !strcmp( Type , "objref" ) ) {
2721 CORBA::Object_ptr ObjRef ;
2723 ObjRef = StringToObject( t ) ;
2724 D.Value <<= ObjRef ;
2727 D.Value <<= CORBA::Object::_nil() ;
2729 // theOutPort->Value( D.Value ) ;
2732 // cdebug << " (other ERROR)" << endl ;
2734 cdebug << " --> call_kind " << D.Value.type()->kind() << endl ;
2736 case CORBA::tk_long:
2739 cdebug << l << " (long)" << endl ;
2740 if ( !strcmp( Type , "string" ) ) {
2742 sprintf( t , "%ld" , l ) ;
2744 // theOutPort->Value( D.Value ) ;
2746 else if ( !strcmp( Type , "boolean" ) ) {
2749 D.Value <<= (CORBA::Any::from_boolean ) b ;
2750 // theOutPort->Value( D.Value ) ;
2752 else if ( !strcmp( Type , "char" ) ) {
2754 c = (unsigned char ) l ;
2755 D.Value <<= (CORBA::Any::from_char ) c ;
2756 // theOutPort->Value( D.Value ) ;
2758 else if ( !strcmp( Type , "short" ) ) {
2762 // theOutPort->Value( D.Value ) ;
2764 else if ( !strcmp( Type , "int" ) || !strcmp( Type , "long" ) ) {
2766 else if ( !strcmp( Type , "float" ) ) {
2770 // theOutPort->Value( D.Value ) ;
2772 else if ( !strcmp( Type , "double" ) ) {
2776 // theOutPort->Value( D.Value ) ;
2778 // else if ( !strcmp( Type , "objref" ) ) {
2780 D.Value <<= CORBA::Object::_nil() ;
2781 // theOutPort->Value( D.Value ) ;
2784 // cdebug << " (other ERROR)" << endl ;
2786 cdebug << " --> call_kind " << D.Value.type()->kind() << endl ;
2788 case CORBA::tk_double:
2791 cdebug << d << " (double)" << endl ;
2792 if ( !strcmp( Type , "string" ) ) {
2794 sprintf( t , "%lf" , d ) ;
2796 // theOutPort->Value( D.Value ) ;
2798 else if ( !strcmp( Type , "boolean" ) ) {
2801 D.Value <<= (CORBA::Any::from_boolean ) b ;
2802 // theOutPort->Value( D.Value ) ;
2804 else if ( !strcmp( Type , "char" ) ) {
2806 c = (unsigned char ) d ;
2807 D.Value <<= (CORBA::Any::from_char ) c ;
2808 // theOutPort->Value( D.Value ) ;
2810 else if ( !strcmp( Type , "short" ) ) {
2814 // theOutPort->Value( D.Value ) ;
2816 else if ( !strcmp( Type , "int" ) || !strcmp( Type , "long" ) ) {
2820 // theOutPort->Value( D.Value ) ;
2822 else if ( !strcmp( Type , "float" ) ) {
2826 // theOutPort->Value( D.Value ) ;
2828 else if ( !strcmp( Type , "double" ) ) {
2830 // else if ( !strcmp( Type , "objref" ) ) {
2832 D.Value <<= CORBA::Object::_nil() ;
2833 // theOutPort->Value( D.Value ) ;
2836 // cdebug << " (other ERROR)" << endl ;
2838 cdebug << " --> call_kind " << D.Value.type()->kind() << endl ;
2840 case CORBA::tk_objref:
2841 if ( !strcmp( Type , "string" ) ) {
2842 CORBA::Object_ptr ObjRef ;
2845 D.Value >>= ObjRef ;
2846 retstr = ObjectToString( ObjRef ) ;
2847 D.Value <<= retstr ;
2848 // theOutPort->Value( D.Value ) ;
2854 cdebug << "ToString( object ) Catched ERROR" << endl ;
2857 else if ( !strcmp( Type , "boolean" ) ) {
2859 D.Value <<= (CORBA::Any::from_boolean ) b ;
2860 // theOutPort->Value( D.Value ) ;
2862 else if ( !strcmp( Type , "char" ) ) {
2863 unsigned char c = 0 ;
2864 D.Value <<= (CORBA::Any::from_char ) c ;
2865 // theOutPort->Value( D.Value ) ;
2867 else if ( !strcmp( Type , "short" ) ) {
2870 // theOutPort->Value( D.Value ) ;
2872 else if ( !strcmp( Type , "int" ) || !strcmp( Type , "long" ) ) {
2875 // theOutPort->Value( D.Value ) ;
2877 else if ( !strcmp( Type , "float" ) ) {
2880 // theOutPort->Value( D.Value ) ;
2882 else if ( !strcmp( Type , "double" ) ) {
2885 // theOutPort->Value( D.Value ) ;
2887 // else if ( !strcmp( Type , "objref" ) ) {
2889 CORBA::Object_ptr obj ;
2893 retstr = ObjectToString( obj ) ;
2894 cdebug << retstr << endl ;
2900 cdebug << "ToString( object ) Catched ERROR" << endl ;
2904 // cdebug << " (other ERROR)" << endl ;
2906 cdebug << " --> call_kind " << D.Value.type()->kind() << endl ;
2909 cdebug << " (other ERROR) " << D.Value.type()->kind() << endl ;
2913 cdebug << ThreadNo() << " In" << i << " : wrong state ERROR State "
2914 << anInPort->PortState() << " NameState "
2915 << Automaton()->StateName( anInPort->PortState() ) << " PortName "
2916 << anInPort->PortName() << " Parametername "
2917 << anInPort->GetServicesParameter().Parametername << endl ;
2920 InParametersList[i] = D ;
2924 void GraphExecutor::InNode::InOutParametersSet( int nOutParams ,
2925 ServicesAnyData * OutParametersList ) {
2926 cdebug << pthread_self() << "/" << ThreadNo() << " InOutParametersSet " << Name() << endl ;
2928 for ( i = 0 ; i < nOutParams ; i++ ) {
2929 ServicesAnyData D = OutParametersList[i] ;
2931 //JR 18.02.2005 Debug Memory leak : delete does not destroy that string ...
2932 // D.Name = CORBA::string_dup(GetChangeNodeOutPort(i)->GetServicesParameter().Parametername);
2933 D.Name = GetChangeNodeOutPort(i)->PortName() ;
2934 //JR 18.02.2005 Debug Memory leak : string _Type = CORBA::string_dup(GetChangeNodeOutPort(i)->GetServicesParameter().Parametertype) ;
2935 const char * Type = GetChangeNodeOutPort(i)->GetServicesParameter().Parametertype ;
2936 bool OutDone = GetChangeNodeOutPort(i)->PortDone() ;
2937 cdebug << ThreadNo() << " ArgOut" << i << " " << D.Name << " PortDone( " << OutDone << " ) Type : "
2939 if ( !strcmp( Type , "string" ) ) {
2940 D.Value <<= (char *) NULL ;
2942 else if ( !strcmp( Type , "boolean" ) ) {
2944 D.Value <<= (CORBA::Any::from_boolean ) b ;
2946 else if ( !strcmp( Type , "char" ) ) {
2947 unsigned char c = 0 ;
2948 D.Value <<= (CORBA::Any::from_char ) c ;
2950 else if ( !strcmp( Type , "short" ) ) {
2954 else if ( !strcmp( Type , "int" ) || !strcmp( Type , "long" ) ) {
2955 D.Value <<= (long ) 0 ;
2957 else if ( !strcmp( Type , "float" ) ) {
2961 else if ( !strcmp( Type , "double" ) ) {
2966 D.Value <<= CORBA::Object::_nil() ;
2969 switch (D.Value.type()->kind()) { // { string , long , double , objref }
2970 case CORBA::tk_string:
2973 cdebug << ThreadNo() << " " << t << "(string)" << endl ;
2975 case CORBA::tk_boolean:
2977 D.Value >>= (CORBA::Any::to_boolean ) b;
2978 cdebug << ThreadNo() << " " << b << "(boolean)" << endl ;
2980 case CORBA::tk_char:
2982 D.Value >>= (CORBA::Any::to_char ) c;
2983 cdebug << ThreadNo() << " " << c << "(char)" << endl ;
2985 case CORBA::tk_short:
2988 cdebug << ThreadNo() << " " << s << "(short)" << endl ;
2990 case CORBA::tk_long:
2993 cdebug << ThreadNo() << " " << l << "(long)" << endl ;
2995 case CORBA::tk_float:
2998 cdebug << ThreadNo() << " " << f << "(float)" << endl ;
3000 case CORBA::tk_double:
3003 cdebug << ThreadNo() << " " << d << "(double)" << endl ;
3005 case CORBA::tk_objref:
3007 CORBA::Object_ptr obj ;
3010 retstr = ObjectToString( obj ) ;
3011 cdebug << ThreadNo() << retstr << endl ;
3014 cdebug << "ToString( object ) Catched ERROR" << endl ;
3018 cdebug << ThreadNo() << " " << "(other ERROR)" << endl ;
3021 OutParametersList[i] = D ;
3025 bool GraphExecutor::InNode::OutParametersSet( bool Err ,
3026 SUPERV::GraphState PortState ,
3028 ServicesAnyData * OutParametersList ) {
3029 bool RetVal = true ;
3031 GraphBase::OutPort * aGateOutPort = NULL ;
3032 bool OrSwitch = false ;
3033 bool DefaultSwitch = false ;
3034 cdebug_in << "OutParametersSet " << Name() << " nOutParams " << nOutParams << " NewPortState "
3035 << PortState << endl ;
3036 // cout << "OutParametersSet " << Name() << " nOutParams " << nOutParams << " NewPortState " << PortState << endl ;
3037 if ( nOutParams && !IsMacroNode() ) {
3038 GraphBase::OutPort * anOutPort ;
3039 for ( i = 0 ; i < nOutParams ; i++ ) {
3040 anOutPort = GetChangeNodeOutPort(i) ;
3042 anOutPort->PortState( PortState ) ;
3043 anOutPort->PortDone( true ) ;
3046 cdebug << ThreadNo() << "OutParametersSet " << "Out" << i << " " << Name() << " "
3047 << anOutPort->PortName() << " " << anOutPort->Kind() ;
3048 ServicesAnyData D = OutParametersList[i] ;
3049 switch (D.Value.type()->kind()) { // { string , long , double , objref }
3050 case CORBA::tk_string: {
3053 cdebug << ThreadNo() << " " << t << "(string)" << endl ;
3056 case CORBA::tk_boolean: {
3058 D.Value >>= (CORBA::Any::to_boolean ) b;
3059 long l = (long ) b ;
3061 cdebug << ThreadNo() << " " << b << "(boolean)" << endl ;
3064 case CORBA::tk_char: {
3066 D.Value >>= (CORBA::Any::to_char ) c;
3067 long l = (long ) c ;
3069 cdebug << ThreadNo() << " " << c << "(char)" << endl ;
3072 case CORBA::tk_short: {
3075 long l = (long ) s ;
3077 cdebug << ThreadNo() << " " << s << "(short)" << endl ;
3080 case CORBA::tk_long: {
3083 cdebug << ThreadNo() << " " << l << "(long)" << endl ;
3086 case CORBA::tk_float: {
3089 double d = (double ) f ;
3091 cdebug << ThreadNo() << " " << f << "(float)" << endl ;
3094 case CORBA::tk_double: {
3097 cdebug << ThreadNo() << " " << d << "(double)" << endl ;
3100 case CORBA::tk_objref: {
3102 CORBA::Object_ptr obj ;
3105 retstr = ObjectToString( obj ) ;
3106 cdebug << ThreadNo() << retstr << endl ;
3109 cdebug << "ToString( object ) Catched ERROR" << endl ;
3114 cdebug << ThreadNo() << " " << "(other ERROR)" << endl ;
3117 OutParametersList[i] = D ;
3118 if ( !anOutPort->IsDataStream() ) {
3119 if ( anOutPort->IsGate() ) {
3120 aGateOutPort = anOutPort ;
3121 cdebug << " Gate " ;
3123 OutParametersList[i].Value <<= l;
3124 anOutPort->Value( OutParametersList[i].Value );
3126 else if ( anOutPort->IsLoop() ) {
3127 cdebug << " Loop " ;
3128 anOutPort->Value( OutParametersList[i].Value );
3129 // InLoop Port of EndLoopNode is ready :
3130 anOutPort->ChangeInPorts(0)->PortState( SUPERV::ReadyState ) ;
3132 else if ( anOutPort->IsSwitch() ) {
3133 cdebug << " Switch " ;
3134 anOutPort->Value( OutParametersList[i].Value );
3135 if ( anOutPort->InPortsSize() && anOutPort->ChangeInPorts( 0 )->IsGate() ) {
3136 //JR 09.02.2005 : OrSwitch is the OR of all SwitchBranches :
3137 //It controls that there is only one SwitchBranch activated
3138 //If it's final value is false ==> activation of the Default to GOTO to EndSwitchNode
3139 //DefaultSwitch is true if a SwitchPort is linked to the DefaultPort of the EndSwitchNode
3140 if ( OrSwitch && anOutPort->BoolValue() ) {
3141 cdebug << "GraphExecutor::InNodeThreads::OutParameters more than one switch is true ERROR"
3145 else if ( anOutPort->BoolValue() ) {
3146 //JR 09.02.2005 Debug : case of a SwitchPort linked to the DefaultPort of the EndSwitchNode :
3147 if ( !strcmp( anOutPort->ChangeInPorts( 0 )->NodeName() , GOTONode()->CoupledNodeName() ) ) {
3148 DefaultSwitch = anOutPort->BoolValue() ;
3151 OrSwitch = OrSwitch | anOutPort->BoolValue() ;
3153 cdebug << "InNodeThreads::OutParameters OrSwitch " << OrSwitch << "DefaultSwitch "
3154 << DefaultSwitch << endl ;
3159 cdebug << " Param " ;
3160 anOutPort->Value( OutParametersList[i].Value );
3162 anOutPort->PortState( PortState ) ;
3163 anOutPort->PortDone( true ) ;
3165 cdebug << "OutParametersSet OrSwitch " << OrSwitch << "DefaultSwitch "
3166 << DefaultSwitch << endl ;
3168 for ( j = 0 ; j < anOutPort->InPortsSize() ; j++ ) {
3169 cdebug << ThreadNo() << "OutParametersSet " << "Out" << i << " " << Name() << " "
3170 << anOutPort->PortName() << " " << anOutPort->Kind() << " --> "
3171 << anOutPort->ChangeInPorts( j )->NodeName() << "( "
3172 << anOutPort->ChangeInPorts( j )->PortName() << anOutPort->ChangeInPorts( j )->Kind()
3174 bool fromGOTO = false ;
3175 const char * ToNodeName = anOutPort->ChangeInPorts( j )->NodeName() ;
3176 if ( !strcmp( ToNodeName , _OutNode->Graph()->Name() ) && _OutNode->Graph()->GraphMacroLevel() != 0 ) {
3177 cdebug << "OutParametersSet ToNodeName " << _OutNode->Graph()->Name() << " CoupledNode "
3178 << _OutNode->Graph()->CoupledNodeName() << _OutNode->Graph()->CoupledNode()
3180 cdebug << " GraphExecutor " << _OutNode->Graph()->CoupledNode()->GraphEditor()->Executor() << endl ;
3181 _OutNode->Graph()->CoupledNode()->GraphEditor()->Executor()->OutputOfAny( _OutNode->Graph()->CoupledNodeName() ,
3182 anOutPort->ChangeInPorts( j )->PortName() ,
3183 *anOutPort->Value() ) ;
3186 GraphBase::ComputingNode * ToNode = _OutNode->Graph()->GetChangeGraphNode( ToNodeName ) ;
3188 // cout << "OutParametersSet ToNodeName " << ToNodeName << endl ;
3189 // cdebug << "OutParametersSet ToNodeName " << ToNodeName << " " << ToNode->Name() << endl ;
3190 GraphBase::OutPort * aGOTOPort = ToNode->GetChangeNodeInGate()->GetOutPort() ;
3192 fromGOTO = aGOTOPort->IsGOTO() ;
3194 if ( anOutPort->ChangeInPorts( j )->IsEndSwitch() || fromGOTO ) {
3195 cdebug << anOutPort->ChangeInPorts( j )->NodeName() << "("
3196 << anOutPort->ChangeInPorts( j )->PortName() << ","
3197 << anOutPort->ChangeInPorts( j )->Kind() << ") CHANGED from "
3198 << anOutPort->ChangeInPorts( j )->GetOutPort()->NodeName()
3200 << anOutPort->ChangeInPorts( j )->GetOutPort()->PortName()
3201 << " to " << anOutPort->ChangeInPorts( j )->GetOutPort()->Kind()
3202 << ") : Done " << anOutPort->PortDone() << " State "
3203 << Automaton()->StateName( anOutPort->ChangeInPorts( j )->PortState() ) << endl ;
3204 anOutPort->ChangeInPorts( j )->ChangeOutPort( anOutPort ) ;
3207 cdebug << anOutPort->ChangeInPorts( j )->NodeName() << "("
3208 << anOutPort->ChangeInPorts( j )->PortName() << ","
3209 << anOutPort->ChangeInPorts( j )->Kind() << ") NOT changed from "
3210 << anOutPort->ChangeInPorts( j )->GetOutPort()->NodeName()
3212 << anOutPort->ChangeInPorts( j )->GetOutPort()->PortName()
3213 << " " << anOutPort->ChangeInPorts( j )->GetOutPort()->Kind()
3220 switch (anOutPort->Value()->type()->kind()) {
3221 case CORBA::tk_string:
3223 (*anOutPort->Value()) >>= t;
3224 cdebug << ThreadNo() << " Out" << i << " : " << t << "(string)" << endl ;
3226 case CORBA::tk_boolean:
3228 (*anOutPort->Value()) >>= (CORBA::Any::to_boolean ) b;
3229 cdebug << ThreadNo() << " Out" << i << " : " << b << "(boolean)" << endl ;
3231 case CORBA::tk_char:
3233 (*anOutPort->Value()) >>= (CORBA::Any::to_char ) c;
3234 cdebug << ThreadNo() << " Out" << i << " : " << c << "(char)" << endl ;
3236 case CORBA::tk_short:
3238 (*anOutPort->Value()) >>= s;
3239 cdebug << ThreadNo() << " Out" << i << " : " << s << "(short)" << endl ;
3241 case CORBA::tk_long:
3243 (*anOutPort->Value()) >>= l;
3244 cdebug << ThreadNo() << " Out" << i << " : " << l << "(long)" << endl ;
3246 case CORBA::tk_float:
3248 (*anOutPort->Value()) >>= f;
3249 cdebug << ThreadNo() << " Out" << i << " : " << f << "(float)" << endl ;
3251 case CORBA::tk_double:
3253 (*anOutPort->Value()) >>= d;
3254 cdebug << ThreadNo() << " Out" << i << " : " << d << "(double)" << endl ;
3256 case CORBA::tk_objref:
3257 CORBA::Object_ptr obj ;
3260 (*anOutPort->Value()) >>= obj ;
3261 retstr = ObjectToString( obj );
3262 cdebug << ThreadNo() << " Out" << i << " : " << "ToString( object ) "
3266 cdebug << ThreadNo() << " Out" << i << " : " << "ToString( object ) "
3267 << "Catched ERROR" << endl ;
3271 cdebug << ThreadNo() << " Out" << i << " : " << "(other ERROR)" << endl ;
3277 if ( aGateOutPort && IsSwitchNode() ) {
3278 //JR 09.02.2005 : OrSwitch is the OR of all SwitchBranches :
3279 //It controls that there is only one SwitchBranch activated
3280 //If it's final value is false ==> activation of the Default to GOTO to EndSwitchNode
3281 //DefaultSwitch is true if a SwitchPort (SwitchBranch) is linked to the DefaultPort of the EndSwitchNode
3282 if ( !OrSwitch && !DefaultSwitch ) {
3283 if ( aGateOutPort->InPortsSize() && aGateOutPort->ChangeInPorts( 0 ) ) {
3284 cdebug << ThreadNo() << " " << "Out0 " << Name() << " Open of "
3285 << aGateOutPort->PortName() << " " << aGateOutPort->Kind() << " WITH DefaultPort" << endl ;
3287 OutParametersList[0].Value <<= l ;
3288 aGateOutPort->Value( OutParametersList[0].Value ) ;
3291 cdebug << ThreadNo() << " " << "Out0 " << Name() << " "
3292 << aGateOutPort->PortName() << " " << aGateOutPort->Kind() << " NOT CONNECTED ERROR" << endl ;
3297 cdebug << ThreadNo() << " " << "Out0 " << Name() << " Close of "
3298 << aGateOutPort->PortName() << " " << aGateOutPort->Kind() << " NO DefaultPort"
3299 << " OrSwitch " << OrSwitch << " DefaultSwitch " << DefaultSwitch << endl ;
3301 OutParametersList[0].Value <<= l ;
3302 aGateOutPort->Value( OutParametersList[0].Value ) ;
3304 if ( !OrSwitch || DefaultSwitch ) { // DefaultPort or DefaultSwitch
3306 for ( i = 0 ; i < GetNodeOutPortsSize() ; i++ ) {
3307 GraphBase::InPort * anInPort ;
3308 anInPort = CoupledNode()->GetChangeInPort( GetNodeOutPort( i )->PortName() ) ;
3309 //JR 16.02.2005 Debug : Change InPorts of EndSwitchNode that have the same name as an OutPort of
3310 // the SwitchNode even if it is the DefaultPort : GraphSwitchCheckDefault1.xml
3311 // if ( anInPort && !anInPort->IsGate() ) {
3312 if ( anInPort && anInPort->GetOutPort() ) {
3313 cdebug << "OutParametersSet " << Name() << " " << anInPort->NodeName() << "( "
3314 << anInPort->PortName() << " ) linked from " << anInPort->GetOutPort()->NodeName()
3315 << "( " << anInPort->GetOutPort()->PortName() << " ) CHANGED TO linked from "
3316 << GetChangeNodeOutPort( i )->NodeName() << "( "
3317 << GetChangeNodeOutPort( i )->PortName() << " )" << endl ;
3318 anInPort->ChangeOutPort( GetChangeNodeOutPort( i ) ) ;
3324 cdebug_out << "OutParametersSet " << Name() << " nOutParams " << nOutParams << " NewPortState "
3325 << PortState << " RetVal " << RetVal << endl ;