1 // SUPERV GraphExecutor : contains classes that permit execution of graphs and particularly the execution automaton
3 // Copyright (C) 2003 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
6 // This library is free software; you can redistribute it and/or
7 // modify it under the terms of the GNU Lesser General Public
8 // License as published by the Free Software Foundation; either
9 // version 2.1 of the License.
11 // This library is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 // Lesser General Public License for more details.
16 // You should have received a copy of the GNU Lesser General Public
17 // License along with this library; if not, write to the Free Software
18 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20 // See http://www.opencascade.org/SALOME/ or email : webmaster.salome@opencascade.org
24 // File : DataFlowBase_InNodeThreads.cxx
25 // Author : Jean Rahuel, CEA
42 #if defined __GNUC_2__
43 // _CS_gbo_040604 include explicite pour l'utilisation de
44 // std::transform dans UpperCase
45 #include <cctype> // for toupper
46 #include <algorithm> // for transform
53 #include <SALOMEconfig.h>
54 #include CORBA_CLIENT_HEADER(SALOME_Component)
55 #include "SALOME_LifeCycleCORBA.hxx"
57 #include "DataFlowExecutor_DataFlow.hxx"
58 #include "DataFlowEditor_DataFlow.hxx" // GraphEditor package must be built BEFORE
61 static void UpperCase(std::string& rstr)
63 #if defined __GNUC_2__
64 // _CS_gbo_040604 towupper n'existe pas. Utilisation de toupper. Par
65 // ailleurs, include explicite de cctype et algorithm pour toupper
66 // et transform respectivement.
67 std::transform(rstr.begin(), rstr.end(), rstr.begin(),toupper);
69 std::transform(rstr.begin(), rstr.end(), rstr.begin(),towupper);
74 int GraphExecutor::InNode::SendEvent( const GraphExecutor::NodeEvent anEvent ) {
76 _CurrentEvent = (GraphExecutor::NodeEvent ) anEvent ;
77 cdebug << pthread_self() << "/" << ThreadNo() << " -->SendEvent Node " << Name()
79 << Automaton()->ControlStateName( ControlState() )
80 << " Event : " << Automaton()->EventName( anEvent )
81 << " State : " << Automaton()->StateName( State() ) << " _RewindStack " << _RewindStack << endl;
84 _NextState = Automaton()->NextState( _OldState , anEvent ) ;
85 if ( _NextState == _OldState ) {
86 cdebug << pthread_self() << "/" << ThreadNo()
87 << " GraphExecutor::InNodeThreads::SendEvent SameStates "
88 << _OldState << endl ;
89 _NextAction = GraphExecutor::VoidAction ;
92 _NextAction = Automaton()->NextAction( _NextState , anEvent ) ;
95 // State( _NextState ) ;
96 // if ( _OldState == GraphExecutor::SuccessedExecutingState ||
97 // _OldState == GraphExecutor::ErroredExecutingState ) {
101 cdebug << pthread_self() << "/" << ThreadNo() << " SendedEvent Node "
102 << Name() << endl << " ControlState : "
103 << Automaton()->ControlStateName( ControlState() ) << endl
104 << " OldState : " << Automaton()->StateName( _OldState ) << endl
105 << " Event : " << Automaton()->EventName( anEvent ) << endl
106 << " NextState : " << Automaton()->StateName( _NextState ) << endl
107 << " Action : " << Automaton()->ActionName( _NextAction ) << endl
108 << " CreateNewThread " << CreateNewThread() << endl
109 << " _RewindStack " << _RewindStack << endl ;
112 //cout << pthread_self() << "/" << ThreadNo() << " SendedEvent Node " << Name()
113 << endl << " ControlState : "
114 << Automaton()->ControlStateName( ControlState() ) << endl
115 << " OldState : " << Automaton()->StateName( _OldState ) << endl
116 << " Event : " << Automaton()->EventName( anEvent ) << endl
117 << " NextState : " << Automaton()->StateName( _NextState ) << endl
118 << " Action : " << Automaton()->ActionName( _NextAction ) << endl
119 << " CreateNewThread " << CreateNewThread() << endl ;
122 int sts = executeAction() ;
124 cdebug << pthread_self() << "/" << ThreadNo() << " <--- SendEvent Node " << Name()
125 << " Event : " << Automaton()->EventName( anEvent )
126 << " State : " << Automaton()->StateName( State() )
133 // ReadyAction - RunningAction - DoneAction - SuspendedAction :
134 // for StateWait( ReadyW - RunningW - DoneW - SuspendedW )
135 void GraphExecutor::InNode::ReadyAction() {
136 if ( pthread_mutex_lock( &_MutexWait ) ) {
137 perror("Ready pthread_mutex_lock ") ;
140 cdebug << pthread_self() << "/" << ThreadNo()
141 << "ReadyAction pthread_cond_broadcast _ReadyWait "
143 if ( pthread_cond_broadcast( &_ReadyWait ) ) {
144 perror("Ready pthread_cond_broadcast ") ;
146 if ( pthread_mutex_unlock( &_MutexWait ) ) {
147 perror("Ready pthread_mutex_unlock ") ;
152 void GraphExecutor::InNode::RunningAction() {
153 if ( pthread_mutex_lock( &_MutexWait ) ) {
154 perror("Running pthread_mutex_lock ") ;
157 cdebug << pthread_self() << "/" << ThreadNo()
158 << "RunningAction pthread_cond_broadcast _RunningWait "
160 // That activate the pthread_cond_wait for RunninWait
161 if ( pthread_cond_broadcast( &_RunningWait ) ) {
162 perror("Running pthread_cond_broadcast ") ;
164 if ( pthread_mutex_unlock( &_MutexWait ) ) {
165 perror("Running pthread_mutex_unlock ") ;
170 void GraphExecutor::InNode::DoneAction() {
171 if ( pthread_mutex_lock( &_MutexWait ) ) {
172 perror("Done pthread_mutex_lock ") ;
175 cdebug << pthread_self() << "/" << ThreadNo()
176 << "DoneAction pthread_cond_broadcast _DoneWait "
178 if ( pthread_cond_broadcast( &_DoneWait ) ) {
179 perror("Done pthread_cond_broadcast ") ;
181 if ( pthread_mutex_unlock( &_MutexWait ) ) {
182 perror("Done pthread_mutex_unlock ") ;
187 void GraphExecutor::InNode::SuspendedAction() {
188 if ( pthread_mutex_lock( &_MutexWait ) ) {
189 perror("Suspended pthread_mutex_lock ") ;
192 cdebug << pthread_self() << "/" << ThreadNo()
193 << "SuspendedAction pthread_cond_broadcast _SuspendedWait "
195 if ( pthread_cond_broadcast( &_SuspendedWait ) ) {
196 perror("Suspended pthread_cond_broadcast ") ;
198 if ( pthread_mutex_unlock( &_MutexWait ) ) {
199 perror("Suspended pthread_mutex_unlock ") ;
204 // SuspendAction <--> { ResumeAction - ReStartAction }
205 GraphExecutor::InNode * GraphExecutor::InNode::SuspendAction() {
207 if ( pthread_mutex_lock( &_MutexWait ) ) {
208 perror("Suspend pthread_mutex_lock ") ;
211 if ( !_SuspendSync ) {
212 cdebug << pthread_self() << "/" << ThreadNo() << " pthread_cond " << Name()
213 << " SuspendAction pthread_cond_wait _SuspendWait "
214 << Automaton()->StateName( State() ) << endl ;
215 _SuspendSync = true ;
216 _OutNode->SuspendThread() ;
217 if ( pthread_cond_wait( &_SuspendWait , &_MutexWait ) ) {
218 perror("SuspendAction pthread_cond_wait ") ;
220 _OutNode->ResumeThread() ;
221 cdebug << pthread_self() << "/" << ThreadNo() << " pthread_cond " << Name()
222 << " SuspendAction pthread_cond_waited"
223 << Automaton()->StateName( State() ) << endl ;
226 cdebug << pthread_self() << "/" << ThreadNo() << " pthread_cond " << Name()
227 << " NO SuspendAction pthread_cond_wait"
228 << Automaton()->StateName( State() ) << endl ;
230 // SendEvent( _aResumeEvent ) ; ===> Mutex with myself !
231 _SuspendSync = false ;
232 if ( ControlState() == SUPERV::ToSuspendStartState ||
233 ControlState() == SUPERV::ToSuspendState ) {
234 ControlState( SUPERV::VoidState ) ;
236 if ( pthread_mutex_unlock( &_MutexWait ) ) {
237 perror("SuspendAction pthread_mutex_unlock ") ;
241 SendEvent( _aResumeEvent ) ;
242 // if ( ControlState() == SUPERV::ToSuspendStartState ) {
243 // ControlState( SUPERV::VoidState ) ;
246 if ( pthread_mutex_lock( &_MutexWait ) ) {
247 perror("SuspendAction pthread_mutex_lock ") ;
251 cdebug << pthread_self() << "/" << ThreadNo() << " pthread_cond " << Name()
252 << " SuspendAction pthread_cond_signal _ResumeWait" << endl ;
253 if ( pthread_cond_signal( &_ResumeWait ) ) {
254 perror("SuspendAction pthread_cond_signal _ResumeWait ") ;
256 cdebug << pthread_self() << "/" << ThreadNo() << " pthread_cond " << Name()
257 << " SuspendAction pthread_cond_signaled _ResumeWait " << endl ;
260 cdebug << pthread_self() << "/" << ThreadNo() << " pthread_cond " << Name()
261 << " NO SuspendAction pthread_cond_signal _ResumeWait" << endl ;
264 if ( pthread_mutex_unlock( &_MutexWait ) ) {
265 perror("SuspendAction pthread_mutex_unlock ") ;
268 if ( _aReStartNode ) {
269 cdebug << Name() << " " << Automaton()->StateName( State() )
270 << "aReStartNode : " << _aReStartNode->Name() << " "
271 << Automaton()->StateName( _aReStartNode->State() ) << endl ;
272 _aReStartNode->SendEvent( _aResumeEvent ) ;
275 cdebug << "NO aReStartNode"
276 << Automaton()->StateName( State() ) << endl ;
278 return _aReStartNode ;
281 bool GraphExecutor::InNode::ResumeAction( GraphExecutor::NodeEvent aResumeEvent ) {
283 if ( pthread_mutex_lock( &_MutexWait ) ) {
284 perror("ResumeAction pthread_mutex_lock ") ;
287 _aResumeEvent = aResumeEvent ;
288 if ( _SuspendSync ) {
289 cdebug << pthread_self() << "/" << ThreadNo() << " pthread_cond " << Name()
290 << " ResumeAction pthread_cond_signal" << endl ;
291 if ( pthread_cond_signal( &_SuspendWait ) ) {
292 perror("ResumeAction pthread_cond_signal ") ;
294 cdebug << pthread_self() << "/" << ThreadNo() << " pthread_cond " << Name()
295 << " ResumeAction pthread_cond_signaled _SuspendWait " << endl ;
299 cdebug << pthread_self() << "/" << ThreadNo() << " pthread_cond " << Name()
300 << " NO ResumeAction pthread_cond_signal" << endl ;
301 if ( pthread_self() == ThreadNo() ) {
302 RetVal = false ; /*/ Ne pas s'attendre soi-meme !...*/
305 _SuspendSync = true ;
306 RetVal = true ; // Il faut tout de meme attendre ci-apres ...
309 if ( pthread_mutex_unlock( &_MutexWait ) ) {
310 perror("ResumeAction pthread_mutex_unlock ") ;
315 if ( pthread_mutex_lock( &_MutexWait ) ) {
316 perror("ResumeAction pthread_mutex_lock ") ;
319 if ( !_ResumeSync ) {
320 cdebug << pthread_self() << "/" << ThreadNo() << " pthread_cond "
321 << Name() << " ResumeAction pthread_cond_wait _ResumeWait "
322 << Automaton()->StateName( State() ) << endl ;
324 if ( pthread_cond_wait( &_ResumeWait , &_MutexWait ) ) {
325 perror("ResumeAction pthread_cond_wait ") ;
327 cdebug << pthread_self() << "/" << ThreadNo() << " pthread_cond "
328 << Name() << " ResumeAction pthread_cond_waited _ResumeWait"
329 << Automaton()->StateName( State() ) << endl ;
333 cdebug << pthread_self() << "/" << ThreadNo() << " pthread_cond "
334 << Name() << " NO ResumeAction pthread_cond_wait _ResumeWait"
335 << Automaton()->StateName( State() ) << endl ;
338 _ResumeSync = false ;
339 if ( pthread_mutex_unlock( &_MutexWait ) ) {
340 perror("ResumeAction pthread_mutex_unlock ") ;
344 cdebug << pthread_self() << "/" << ThreadNo()
345 << "GraphExecutor::InNodeThreads::ResumeAction RetVal " << RetVal << endl ;
349 bool GraphExecutor::InNode::ReStartAction( GraphExecutor::InNode * aReStartNode ,
350 GraphExecutor::NodeEvent anEvent ) {
351 GraphExecutor::InNode * oldReStartNode = _aReStartNode ;
352 _aReStartNode = aReStartNode ;
353 _aReStartEvent = anEvent ;
354 cdebug << pthread_self() << " GraphExecutor::InNodeThreads::ReStartAction from "
355 << Name() << " " << Automaton()->StateName( State() ) << " to "
356 << aReStartNode->ThreadNo() << " " << aReStartNode->Name() << " "
357 << Automaton()->StateName( aReStartNode->State() ) ;
358 if ( oldReStartNode ) {
359 cdebug << " oldReStartNode " << oldReStartNode->Name() << endl ;
364 return ResumeAction( GraphExecutor::ToReStartEvent ) ;
367 void GraphExecutor::InNode::KilledAction() {
368 if ( pthread_mutex_lock( &_MutexWait ) ) {
369 perror("Killed pthread_mutex_lock ") ;
373 cdebug << "pthread_cond " << Name() << " Killed pthread_cond_wait"
376 if ( pthread_cond_wait( &_KillWait , &_MutexWait ) ) {
377 perror("Killed pthread_cond_wait ") ;
379 cdebug << "pthread_cond " << Name() << " Killed pthread_cond_waited"
383 cdebug << "pthread_cond " << Name() << " NO Killed pthread_cond_wait"
387 if ( pthread_mutex_unlock( &_MutexWait ) ) {
388 perror("Killed pthread_mutex_unlock ") ;
393 void GraphExecutor::InNode::KillAction() {
394 if ( pthread_mutex_lock( &_MutexWait ) ) {
395 perror("Kill pthread_mutex_lock ") ;
399 cdebug << "pthread_cond " << Name() << " Kill pthread_cond_signal"
401 // if ( pthread_cond_broadcast( &_KillWait ) ) {
402 if ( pthread_cond_signal( &_KillWait ) ) {
403 perror("Kill pthread_cond_broadcast ") ;
405 cdebug << "pthread_cond " << Name() << " Kill pthread_cond_signaled"
409 cdebug << "pthread_cond " << Name() << " NO Kill pthread_cond_signal"
413 if ( pthread_mutex_unlock( &_MutexWait ) ) {
414 perror("Kill pthread_mutex_unlock ") ;
419 void GraphExecutor::InNode::StoppedAction() {
420 if ( pthread_mutex_lock( &_MutexWait ) ) {
421 perror("Stopped pthread_mutex_lock ") ;
424 if ( pthread_cond_wait( &_StopWait , &_MutexWait ) ) {
425 perror("Stopped pthread_cond_wait ") ;
427 if ( pthread_mutex_unlock( &_MutexWait ) ) {
428 perror("Stopped pthread_mutex_unlock ") ;
433 void GraphExecutor::InNode::StopAction() {
434 if ( pthread_mutex_lock( &_MutexWait ) ) {
435 perror("Stop pthread_mutex_lock ") ;
438 if ( pthread_cond_broadcast( &_StopWait ) ) {
439 perror("Stop pthread_cond_broadcast ") ;
441 if ( pthread_mutex_unlock( &_MutexWait ) ) {
442 perror("Stop pthread_mutex_unlock ") ;
447 void GraphExecutor::InNode::ThreadStartedAction() {
448 if ( pthread_mutex_lock( &_MutexWait ) ) {
449 perror("ThreadStarted pthread_mutex_lock ") ;
452 if ( !_ThreadStartedSync ) {
453 cdebug << "pthread_cond " << Name() << " ThreadStarted pthread_cond_wait"
455 _ThreadStartedSync = true ;
456 if ( pthread_cond_wait( &_ThreadStartedWait , &_MutexWait ) ) {
457 perror("ThreadStarted pthread_cond_wait ") ;
459 cdebug << "pthread_cond " << Name() << " ThreadStarted pthread_cond_waited"
463 cdebug << "pthread_cond " << Name() << " NO ThreadStarted pthread_cond_wait"
466 _ThreadStartedSync = false ;
467 if ( pthread_cond_signal( &_ThreadStartedWait ) ) {
468 perror("ThreadStart pthread_cond_signal ") ;
471 cdebug << "pthread_cond " << Name() << " NO ThreadStarted pthread_cond_signaled"
474 if ( pthread_mutex_unlock( &_MutexWait ) ) {
475 perror("ThreadStarted pthread_mutex_unlock ") ;
480 void GraphExecutor::InNode::ThreadStartAction() {
481 if ( pthread_mutex_lock( &_MutexWait ) ) {
482 perror("ThreadStart pthread_mutex_lock ") ;
485 if ( _ThreadStartedSync ) {
486 cdebug << "pthread_cond " << Name() << " ThreadStart pthread_cond_signal"
488 _ThreadStartedSync = false ;
489 if ( pthread_cond_signal( &_ThreadStartedWait ) ) {
490 perror("ThreadStart pthread_cond_broadcast ") ;
492 cdebug << "pthread_cond " << Name() << " ThreadStart pthread_cond_signaled"
496 cdebug << "pthread_cond " << Name() << " NO ThreadStart pthread_cond_signal"
498 _ThreadStartedSync = true ;
500 if ( pthread_cond_wait( &_ThreadStartedWait , &_MutexWait ) ) {
501 perror("ThreadStarted pthread_cond_wait ") ;
504 cdebug << "pthread_cond " << Name() << " NO ThreadStart pthread_cond_waited"
507 if ( pthread_mutex_unlock( &_MutexWait ) ) {
508 perror("ThreadStart pthread_mutex_unlock ") ;
513 int GraphExecutor::InNode::executeAction() {
514 int oldRewindStack = ( _RewindStack > MAXSTACKTHREADSIZE ) ;
515 if ( !CreateNewThread() && oldRewindStack ) {
516 cdebug << pthread_self() << "/" << ThreadNo()
517 << " executeAction start Thread _RewindStack " << _RewindStack << " > "
518 << MAXSTACKTHREADSIZE << " CreateNewThread "
519 << CreateNewThread() << " " << Automaton()->ActionName( _NextAction ) << "(" << Name() << ")"
521 CreateNewThread( true ) ;
524 if ( CreateNewThread() ) {
525 CreateNewThread( false ) ;
526 if ( ThreadNo() == 0 ) {
528 cdebug << pthread_self() << "/" << ThreadNo()
529 << " executeAction start Thread _RewindStack " << _RewindStack << " "
530 << Automaton()->ActionName( _NextAction ) << "(" << Name() << ")"
533 int pthread_sts = 1 ;
534 // _OutNode->PushEvent( NULL , GraphExecutor::NewThreadEvent ,
535 // GraphExecutor::ExecutingState ) ;
536 while ( (pthread_sts = pthread_create(&T, NULL, run_function, this )) ) {
537 char * msg = "Cannot pthread_create " ;
539 cdebug << ThreadNo() << " " << msg << " --> sleep(5)" << endl ;
540 cdebug << ThreadNo() << " PTHREAD_THREADS_MAX : "
541 << PTHREAD_THREADS_MAX << " pthread_create status : " ;
542 if ( pthread_sts == EAGAIN ) {
543 cdebug << "EAGAIN(" << pthread_sts << ")" << endl ;
544 cdebug << "It seems to me that with gdb we are limited to 256 threads because of defunct" << endl ;
547 cdebug << pthread_sts << endl ;
551 pthread_exit( msg ) ;
553 cdebug << pthread_self() << "/" << ThreadNo()
554 << "executeAction has created thread " << T << endl ;
555 ThreadStartedAction() ;
556 cdebug << pthread_self() << "/" << ThreadNo()
557 << "executeAction the thread " << T << " has called NewThread and will call ExecuteAction for node "
561 cdebug << pthread_self() << "/" << ThreadNo()
562 << " executeAction restart Thread _RewindStack " << _RewindStack << " "
563 << Automaton()->StateName( State() ) << " "
564 << Automaton()->ActionName( _NextAction ) << "(" << Name()
565 << ") ReStartAction ==>" << endl;
566 State( GraphExecutor::SuspendedSuccessedState ) ;
567 if ( !ReStartAction( this , GraphExecutor::ReStartEvent ) ) {
568 cdebug << pthread_self() << "/" << ThreadNo()
569 << " executeAction STATE & CALLED "
570 << Automaton()->ActionName( _NextAction ) << "(" << Name()
571 << ") ERROR-DEBUG " << endl;
574 cdebug << pthread_self() << "/" << ThreadNo() << " executeAction NO CALL "
575 << Automaton()->ActionName( _NextAction ) << "(" << Name()
581 if ( _CurrentEvent == ExecuteEvent ) {
584 cdebug << pthread_self() << "/" << ThreadNo() << " executeAction call "
585 << Automaton()->ActionName( _NextAction ) << "(" << Name() << ") _RewindStack " << _RewindStack
587 return ExecuteAction() ;
592 void GraphExecutor::InNode::coutbegin() {
593 cdebug << ThreadNo() << " " << pthread_self() << " run_function begin"
594 << " " << Name() << " " << Automaton()->StateName( State() ) << endl ;
596 void GraphExecutor::InNode::coutexit() {
597 cdebug << pthread_self() << "/" << ThreadNo() << " run_function pthread_exit _RewindStack " << _RewindStack
598 << " " << Name() << " " << Automaton()->StateName( State() ) << endl ;
600 void * run_function(void *p) {
601 GraphExecutor::InNode *aNode = (GraphExecutor::InNode *) p;
603 aNode->NewThread( pthread_self() ) ;
604 if ( pthread_setcanceltype( PTHREAD_CANCEL_ASYNCHRONOUS , NULL ) ) {
605 perror("pthread_setcanceltype ") ;
608 if ( pthread_setcancelstate( PTHREAD_CANCEL_ENABLE , NULL ) ) {
609 perror("pthread_setcancelstate ") ;
612 aNode->ThreadStartAction() ;
613 // cout << "run_function " << aNode->Name() << "->ExecuteAction() Coupled : " << aNode->CoupledNode()
615 aNode->ExecuteAction() ;
616 char * msg = new char[40] ;
617 sprintf( msg , "%d" , (int ) aNode->ThreadNo() ) ;
618 strcat( msg , " thread exit" ) ;
620 aNode->ExitThread() ;
623 pthread_exit( (void * ) smsg.c_str() ) ;
627 int GraphExecutor::InNode::ExecuteAction() {
630 // const char * nextactionname = Automaton()->ActionName( _NextAction ) ;
631 // const char * statename = Automaton()->StateName( State() ) ;
632 // const char * nextstatename = Automaton()->StateName( _NextState ) ;
633 // cdebug << pthread_self() << "/" << ThreadNo() << " --> ExecuteAction "
634 // << nextactionname << " " << statename << " NextState "
635 // << nextstatename << endl ;
637 State( _NextState ) ;
638 switch ( _NextAction ) {
639 case GraphExecutor::ErrorAction : {
640 sts = ErrorAction() ;
643 case GraphExecutor::VoidAction : {
647 case GraphExecutor::DataWaiting_SomeDataReadyAction : {
648 sts = DataWaiting_SomeDataReadyAction() ;
651 case GraphExecutor::DataUndef_NotAllDataReadyAction : {
652 sts = DataUndef_NotAllDataReadyAction() ;
655 case GraphExecutor::DataUndef_AllDataReadyAction : {
656 sts = DataUndef_AllDataReadyAction() ;
659 case GraphExecutor::DataReady_SuspendAction : {
660 sts = DataReady_SuspendAction() ;
663 case GraphExecutor::SuspendedReady_ResumeAction : {
664 sts = SuspendedReady_ResumeAction() ;
667 case GraphExecutor::DataReady_KillAction : {
668 sts = DataReady_KillAction() ;
671 case GraphExecutor::DataReady_StopAction : {
672 sts = DataReady_StopAction() ;
675 case GraphExecutor::DataReady_ExecuteAction : {
676 sts = DataReady_ExecuteAction() ;
679 case GraphExecutor::Executing_SuspendAction : {
680 sts = Executing_SuspendAction() ;
683 case GraphExecutor::SuspendedExecuting_ResumeAction : {
684 sts = SuspendedExecuting_ResumeAction() ;
687 case GraphExecutor::Executing_KillAction : {
688 sts = Executing_KillAction() ;
691 case GraphExecutor::Executing_StopAction : {
692 sts = Executing_StopAction() ;
695 case GraphExecutor::Executing_SuccessAction : {
696 sts = Executing_SuccessAction() ;
699 case GraphExecutor::Executing_ErrorAction : {
700 sts = Executing_ErrorAction() ;
703 case GraphExecutor::Successed_SuccessAction : {
704 sts = Successed_SuccessAction() ;
707 case GraphExecutor::Errored_ErrorAction : {
708 sts = Errored_ErrorAction() ;
711 case GraphExecutor::Successed_SuspendAction : {
712 sts = Successed_SuspendAction() ;
715 case GraphExecutor::Errored_SuspendAction : {
716 sts = Errored_SuspendAction() ;
719 case GraphExecutor::SuspendedSuccessed_ResumeAction : {
720 sts = SuspendedSuccessed_ResumeAction() ;
723 case GraphExecutor::SuspendedErrored_ResumeAction : {
724 sts = SuspendedErrored_ResumeAction() ;
727 case GraphExecutor::Successed_KillAction : {
728 sts = Successed_KillAction() ;
731 case GraphExecutor::Errored_KillAction : {
732 sts = Errored_KillAction() ;
735 case GraphExecutor::Successed_StopAction : {
736 sts = Successed_StopAction() ;
739 case GraphExecutor::Errored_StopAction : {
740 sts = Errored_StopAction() ;
743 case GraphExecutor::SuspendedSuccessed_ReStartAction : {
744 sts = SuspendedSuccessed_ReStartAction() ;
747 case GraphExecutor::SuspendedErrored_ReStartAction : {
748 sts = SuspendedErrored_ReStartAction() ;
751 case GraphExecutor::SuspendedSuccessed_ReStartAndSuspendAction : {
752 sts = SuspendedSuccessed_ReStartAndSuspendAction() ;
755 case GraphExecutor::SuspendedErrored_ReStartAndSuspendAction : {
756 sts = SuspendedErrored_ReStartAndSuspendAction() ;
760 cdebug << pthread_self() << "/" << ThreadNo()
761 << " GraphExecutor::InNodeThreads::SendEvent Error Undefined Action : "
762 << _NextAction << endl ;
766 // cdebug << pthread_self() << "/" << ThreadNo() << "<-- ExecuteAction "
767 // << Automaton()->ActionName( nextaction ) << endl ;
771 int GraphExecutor::InNode::ErrorAction() {
772 cdebug << pthread_self() << "/" << ThreadNo() << " Automaton ErrorAction Node "
777 int GraphExecutor::InNode::VoidAction() {
778 cdebug << pthread_self() << "/" << ThreadNo() << " VoidAction " << Name() << endl;
783 int GraphExecutor::InNode::DataWaiting_SomeDataReadyAction() {
784 cdebug << pthread_self() << "/" << ThreadNo()
785 << " --> DataWaiting_SomeDataReadyAction from " << DataFromNode()
786 << " to " << Name() << endl;
790 bool LoopBeginning = false ;
791 bool LoopFinished = false ;
792 bool SwitchFinished = false ;
794 if ( IsLoopNode() && GetChangeNodeInLoop()->GetOutPort()->BoolValue() ) {
795 LoopBeginning = true ; // Beginning of Loop
797 if ( IsEndLoopNode() && !GetChangeNodeInLoop()->GetOutPort()->BoolValue() ) {
798 LoopFinished = true ; // End of Loop
800 if ( IsEndSwitchNode() && !GetChangeNodeInGate()->GetOutPort()->BoolValue() ) {
801 SwitchFinished = true ; // End of Switch
803 cdebug << pthread_self() << "/" << ThreadNo() << " " << Name() << " LoopFinished " << LoopFinished
804 << " LoopBeginning " << LoopBeginning << " SwitchFinished " << SwitchFinished << endl ;
805 for ( k = 0 ; k < (unsigned int ) GetNodeInPortsSize() ; k++ ) {
806 GraphBase::InPort * anInPort = GetChangeNodeInPort(k) ;
807 GraphBase::OutPort * anOutPort = anInPort->GetOutPort() ;
808 cdebug << pthread_self() << "/" << ThreadNo() << " " << Name() << " InPort " << anInPort->PortName() << " " << anInPort->State() << " " << anInPort->PortStatus() << endl ;
809 if ( anInPort->IsGate() && anOutPort == NULL ) {
811 anInPort->State( SUPERV::ReadyState ) ;
812 cdebug << pthread_self() << "/" << ThreadNo() << " " << Name() << " "
813 << anInPort->PortName() << " ControlPort inactive." << endl ;
815 // That InPort get its value from an other node
816 else if ( strcmp( DataFromNode() , anOutPort->NodeName() ) ) {
817 if ( anInPort->State() == SUPERV::ReadyState ) {
819 cdebug << pthread_self() << "/" << ThreadNo() << " " << Name() << " "
820 << anInPort->PortName() << " Was Done from Node "
821 << anOutPort->NodeName() << "( " << anOutPort->PortName()
824 if ( GraphBase::Base::_prof_debug ) {
825 anOutPort->StringValue( *GraphBase::Base::_fdebug ) ;
830 else if ( IsLoopNode() && anInPort->IsDataConnected() ) {
831 anInPort->State( SUPERV::ReadyState ) ;
833 cdebug << pthread_self() << "/" << ThreadNo() << " " << Name() << " "
834 << anInPort->PortName() << " Was Done from Node "
835 << anOutPort->NodeName() << "( " << anOutPort->PortName()
836 << ") LoopBeginning " << LoopBeginning ;
838 if ( GraphBase::Base::_prof_debug ) {
839 anOutPort->StringValue( *GraphBase::Base::_fdebug ) ;
844 else if ( LoopFinished ) {
845 anInPort->State( SUPERV::ReadyState ) ;
847 cdebug << pthread_self() << "/" << ThreadNo() << " " << Name() << " "
848 << anInPort->PortName() << " Was Done from Node "
849 << anOutPort->NodeName() << "( " << anOutPort->PortName()
850 << ") LoopFinished" ;
852 if ( GraphBase::Base::_prof_debug ) {
853 anOutPort->StringValue( *GraphBase::Base::_fdebug ) ;
858 else if ( anInPort->IsGate() && SwitchFinished ) {
859 anInPort->State( SUPERV::ReadyState ) ;
861 cdebug << pthread_self() << "/" << ThreadNo() << " " << Name() << " "
862 << anInPort->PortName() << " Was Done from Node "
863 << anOutPort->NodeName() << "( " << anOutPort->PortName()
864 << ") SwitchFinished" ;
866 if ( GraphBase::Base::_prof_debug ) {
867 anOutPort->StringValue( *GraphBase::Base::_fdebug ) ;
873 cdebug << pthread_self() << "/" << ThreadNo() << " " << Name() << " "
874 << anInPort->PortName() << " Was NOT Done from Node "
875 << anOutPort->NodeName() << "( " << anOutPort->PortName() << ") "
876 << " " << Automaton()->StateName( State() ) << " DataConnected "
877 << anInPort->IsDataConnected() << " LoopBeginning "
878 << LoopBeginning << endl ;
881 // That InPort get its value from the sending node
882 else if ( anInPort->IsGate() ) {
883 const CORBA::Any * theValue = anOutPort->Value() ;
885 (*theValue) >>= GateOpened ;
886 if ( GateOpened != 0 ) {
888 anInPort->State( SUPERV::ReadyState ) ;
889 cdebug << pthread_self() << "/" << ThreadNo() << " " << Name() << " "
890 << anInPort->PortName() << " Gate is Opened from Node "
891 << anOutPort->NodeName() << "( " << anOutPort->PortName()
894 if ( GraphBase::Base::_prof_debug ) {
895 anOutPort->StringValue( *GraphBase::Base::_fdebug ) ;
900 else if ( LoopFinished ) {
901 anInPort->State( SUPERV::ReadyState ) ;
902 cdebug << pthread_self() << "/" << ThreadNo() << " " << Name() << " "
903 << anInPort->PortName() << " GATE IS CLOSED from Node "
904 << anOutPort->NodeName() << "( " << anOutPort->PortName()
905 << ") LoopFinished" ;
907 if ( GraphBase::Base::_prof_debug ) {
908 anOutPort->StringValue( *GraphBase::Base::_fdebug ) ;
914 cdebug << pthread_self() << "/" << ThreadNo() << " " << Name() << " "
915 << anInPort->PortName() << " GATE IS CLOSED from Node "
916 << anOutPort->NodeName() << "( " << anOutPort->PortName()
919 if ( GraphBase::Base::_prof_debug ) {
920 anOutPort->StringValue( *GraphBase::Base::_fdebug ) ;
926 else if ( anOutPort->Done() ) {
928 anInPort->State( SUPERV::ReadyState ) ;
929 cdebug << pthread_self() << "/" << ThreadNo() << " " << Name() << " "
930 << anInPort->PortName() << " " << anInPort->PortStatus() << " is Done from Node "
931 << anOutPort->NodeName() << "( " << anOutPort->PortName() << ") "
932 << anOutPort->PortStatus() << " " ;
934 if ( GraphBase::Base::_prof_debug ) {
935 anOutPort->StringValue( *GraphBase::Base::_fdebug ) ;
939 // MacroNode : give immediately the value to the corresponding graph
940 if ( IsMacroNode() ) {
941 cout << "SomeDataReadyAction " << GraphMacroNode() << " " << GraphMacroNode()->Name()
942 << " coupled to " << GraphMacroNode()->CoupledNode() << endl ;
943 GraphExecutor::DataFlow * aMacroGraph = GraphMacroNode()->CoupledNode()->GraphEditor()->Executor() ;
944 cdebug << "SomeDataReadyAction MacroNode " << aMacroGraph->Graph()->Name() << " --> InputOfAny "
945 << InReady << "/" << GetNodeInPortsSize() << " InPorts are Ready" << endl ;
946 // GraphMacroNode()->MacroObject()->InputOfAny( anInPort->PortName() , *anOutPort->Value() ) ;
947 aMacroGraph->InputOfAny( anInPort->PortName() , *anOutPort->Value() ) ;
951 cdebug << pthread_self() << "/" << ThreadNo() << " Node " << Name() << "( "
952 << anInPort->PortName() << ") " << anInPort->PortStatus()
953 << " is NOT Done from Node "
954 << anOutPort->NodeName() << "( " << anOutPort->PortName() << ") "
955 << anOutPort->PortStatus() << " " ;
959 if ( InReady == GetNodeInPortsSize() ) { // All Flags != 0 :
960 res = SendEvent( GraphExecutor::AllDataReadyEvent ); // ==> Ready to execute
962 else { // At least one Flag == 0 :
963 res = SendEvent( GraphExecutor::NotAllDataReadyEvent );
966 cdebug << pthread_self() << "/" << ThreadNo()
967 << " <-- DataWaiting_SomeDataReadyAction " << Name() << endl;
972 int GraphExecutor::InNode::DataUndef_NotAllDataReadyAction() {
973 CreateNewThreadIf( false ) ;
974 // cdebug << pthread_self() << " for " << ThreadNo()
975 // << " DataUndef_NotAllDataReadyAction " << Name() << endl;
979 int GraphExecutor::InNode::DataUndef_AllDataReadyAction() {
980 // cdebug << pthread_self() << "/" << ThreadNo()
981 // << " --> DataUndef_AllDataReadyAction " << Name()
982 // << " CreateNewThreadIf " << CreateNewThreadIf() << " IsLockedDataWait "
983 // << IsLockedDataWait() ;
984 if ( IsLockedDataWait() ) {
985 cdebug << "DataUndef_AllDataReadyAction() WOULD DEAD-LOCK" << endl ;
986 return 0 ; // ==> DataUndef_AllDataReadyAction() after UnLockDataWait()
989 CreateNewThread( CreateNewThreadIf() ) ;
990 if ( !CreateNewThread() ) {
991 // cdebug << "Thread " << ThreadNo() << "-->" << pthread_self() << endl ;
992 ThreadNo( pthread_self() ) ;
994 _OutNode->PushEvent( this , GraphExecutor::AllDataReadyEvent ,
995 GraphExecutor::DataReadyState ) ;
997 SUPERV::ControlState aControl = ControlState() ;
998 switch ( aControl ) {
999 case SUPERV::VoidState : {
1000 SendEvent( GraphExecutor::ExecuteEvent ) ;
1003 case SUPERV::ToSuspendState : {
1004 SendEvent( GraphExecutor::SuspendEvent ) ;
1007 case SUPERV::ToSuspendStartState : {
1008 SendEvent( GraphExecutor::SuspendEvent ) ;
1011 case SUPERV::ToSuspendDoneState : {
1012 SendEvent( GraphExecutor::ExecuteEvent ) ;
1015 case SUPERV::ToKillState : {
1016 SendEvent( GraphExecutor::KillEvent ) ;
1019 case SUPERV::ToKillDoneState : {
1020 SendEvent( GraphExecutor::ExecuteEvent ) ;
1023 case SUPERV::ToStopState : {
1024 SendEvent( GraphExecutor::StopEvent ) ;
1028 cdebug << ThreadNo()
1029 << " GraphExecutor::InNodeThreads::DataUndef_AllDataReadyAction Error Undefined Control : "
1030 << aControl << endl ;
1034 // cdebug << pthread_self() << "/" << ThreadNo()
1035 // << " <-- DataUndef_AllDataReadyAction " << Name() << endl;
1039 int GraphExecutor::InNode::DataReady_SuspendAction() {
1040 cdebug << pthread_self() << "/" << ThreadNo()
1041 << "DataReady_SuspendAction --> Suspend " << Name()
1042 << " Threads " << _OutNode->Threads() << " SuspendedThreads "
1043 << _OutNode->SuspendedThreads() << endl;
1044 _OutNode->PushEvent( this , GraphExecutor::SuspendedReadyEvent ,
1045 GraphExecutor::SuspendedReadyState ) ;
1046 GraphExecutor::InNode * aReStartNode = SuspendAction() ;
1047 cdebug << pthread_self() << "/" << ThreadNo()
1048 << "DataReady_SuspendAction Resumed " << Name() << endl;
1049 if ( aReStartNode ) {
1050 _aReStartNode = NULL ;
1051 aReStartNode->SendEvent( _aReStartEvent ) ;
1054 SendEvent( GraphExecutor::ExecuteEvent ) ;
1059 int GraphExecutor::InNode::SuspendedReady_ResumeAction() {
1060 cdebug << pthread_self() << "/" << ThreadNo() << "SuspendedReady_ResumeAction "
1063 _OutNode->PushEvent( this , GraphExecutor::ResumedReadyEvent ,
1064 GraphExecutor::ResumedReadyState ) ;
1068 int GraphExecutor::InNode::DataReady_KillAction() {
1069 _OutNode->PushEvent( this , GraphExecutor::KilledReadyEvent ,
1070 GraphExecutor::KilledReadyState ) ;
1072 cdebug << pthread_self() << "/" << ThreadNo() << "DataReady_KillAction " << Name()
1073 << " will pthread_exit()" << endl;
1077 int GraphExecutor::InNode::DataReady_StopAction() {
1078 _OutNode->PushEvent( this , GraphExecutor::StoppedReadyEvent ,
1079 GraphExecutor::StoppedReadyState ) ;
1081 cdebug << pthread_self() << "/" << ThreadNo() << "DataReady_StopAction " << Name()
1082 << " will pthread_exit()" << endl;
1088 int GraphExecutor::InNode::DataReady_ExecuteAction() {
1091 // cdebug << pthread_self() << "/" << ThreadNo() << " --> DataReady_ExecuteAction "
1092 // << Name() << endl;
1093 _OutNode->PushEvent( this , GraphExecutor::ExecuteEvent ,
1094 GraphExecutor::ExecutingState ) ;
1100 SUPERV::GraphState PortState = SUPERV::ReadyState ;
1101 GraphExecutor::AutomatonState NewState = GraphExecutor::DataUndefState ;
1102 GraphExecutor::NodeEvent NewEvent = GraphExecutor::UndefinedEvent ;
1105 ServicesAnyData * InParametersList ;
1107 ServicesAnyData * OutParametersList ;
1109 nInParams = GetNodeInPortsSize() ;
1110 InParametersList = new ServicesAnyData[nInParams];
1111 InParametersSet( Err , nInParams , InParametersList ) ;
1113 nOutParams = GetNodeOutPortsSize() ;
1114 OutParametersList = new ServicesAnyData[nOutParams];
1115 InOutParametersSet( nOutParams , OutParametersList ) ;
1117 if ( !IsMacroNode() ) {
1119 Engines::Container_var myContainer ;
1120 Engines::Component_var myObjComponent ;
1121 if ( !IsFactoryNode() ) {
1122 // cdebug << ThreadNo() << "No Component : NO StartComponent & No Ping" << endl ;
1123 if ( IsComputingNode() ) {
1124 ObjInterface( true ) ;
1125 CORBA::Object_ptr obj ;
1126 InParametersList[0].Value >>= obj ;
1127 CORBA::Object_var objvar = CORBA::Object_var( obj ) ;
1128 myObjComponent = Engines::Component::_narrow( objvar ) ;
1133 else if ( CORBA::is_nil( Component() ) ) {
1134 // ostringstream astr ;
1135 // astr << "Graph " << _OutNode->Graph()->Name() << " Node " << Name()
1136 // << " : load of component " << ComponentName() << " in container "
1138 // _OutNode->Graph()->ObjImpl()->sendMessage( NOTIF_STEP, astr.str().c_str() ) ;
1139 Err = !_OutNode->Graph()->StartComponent( ThreadNo() , Computer() ,
1140 my_strdup( ComponentName() ) ,
1141 myContainer , myObjComponent ) ;
1142 ObjInterface( false ) ;
1143 SetContainer( myContainer ) ;
1144 SetComponent( myObjComponent ) ;
1147 myContainer = Container() ;
1148 myObjComponent = Component() ;
1149 // cdebug << ThreadNo() << "Component known : NO StartComponent & Ping"
1152 myObjComponent->ping() ;
1155 cdebug << "ping() catched" << endl ;
1160 if ( Err || ControlState() == SUPERV::ToKillState ||
1161 ControlState() == SUPERV::ToKillDoneState ||
1162 ControlState() == SUPERV::ToStopState ) {
1163 cdebug << ThreadNo() << "StartComponent Error or ToKillState" << endl ;
1164 MESSAGE(pthread_self() << "Executor::InNode::DataReady_ExecuteAction of " << Name()
1165 << " ControlState " << Automaton()->ControlStateName( ControlState() )
1166 << " BEFORE execution ThreadNo " << ThreadNo() ) ;
1170 if ( ControlState() == SUPERV::ToSuspendState ) {
1171 cdebug << ThreadNo() << "ToSuspendState before running." << endl ;
1172 MESSAGE(ThreadNo() << "ToSuspendState before running.") ;
1175 // ostringstream astr ;
1176 // astr << "Graph " << _OutNode->Graph()->Name() << " Run of Node " << Name() ;
1177 // _OutNode->Graph()->ObjImpl()->sendMessage( NOTIF_STEP, astr.str().c_str() ) ;
1178 cdebug << ThreadNo() << " Run( '" << ServiceName() << "'" ;
1179 for ( i = 0 ; i < (int ) ServiceInParameter().length() ; i++ ) {
1180 cdebug << " , " << InParametersList[ i ].Name << "[kind"
1181 << InParametersList[ i ].Value.type()->kind() << "]" ;
1183 for ( i = 0 ; i < (int ) ServiceOutParameter().length() ; i++ ) {
1184 cdebug << " , " << OutParametersList[ i ].Name << "[kind"
1185 << OutParametersList[ i ].Value.type()->kind() << "]" ;
1187 if ( IsOneOfInLineNodes() ) {
1188 cdebug << " , PyFuncName '" << InLineNode()->PyFuncName() << "' PyRunMethod "
1189 << InLineNode()->PyRunMethod() << " length "
1190 << (*InLineNode()->PythonFunction()).length() ;
1192 cdebug << ")" << endl ;
1194 if ( IsOneOfInLineNodes() ) {
1195 bool StsPyDynInvoke = true;
1196 _OutNode->PyThreadLock() ;
1199 // if ( IsInLineNode() && (*InLineNode()->PythonFunction()).length() &&
1200 bool ItIsaLoop = false ;
1201 bool CopyInOut = false ;
1202 if ( IsInLineNode() && /*InLineNode()->PyRunMethod() &&*/
1203 strlen( InLineNode()->PyFuncName() ) ) {
1204 cdebug << ThreadNo() << " !ObjInterface " << Name() << " PyFuncName '"
1205 << InLineNode()->PyFuncName()
1206 << "' IsInLineNode PyDynInvoke" << endl ;
1207 StsPyDynInvoke = PyDynInvoke( InLineNode()->PyRunMethod() ,
1208 InLineNode()->PyFuncName() ,
1209 &InParametersList[0] , ServiceInParameter().length() ,
1210 &OutParametersList[0] , ServiceOutParameter().length() ) ;
1211 if ( !StsPyDynInvoke ) {
1212 RemovePyDynInvoke( InLineNode()->PyFuncName() ) ;
1214 else if ( IsLoopNode() ) {
1216 bool CopyOutIn = false ;
1217 // Switch between Init() and Next()
1218 // if InLoop port is true and does not come from EndLoop ==> execute Init
1219 // if InLoop port is false or come from EndLoop ==> execute Next
1220 // GraphExecutor::InNode * anEndLoopNode = (GraphExecutor::InNode * ) CoupledNode()->GetInNode() ;
1221 // if ( GetNodeInLoop()->GetOutPort()->BoolValue() &&
1223 if ( strlen( InLineNode()->PyFuncName() ) ) { // InLoop Port = true ==> Init()
1224 cdebug << ThreadNo() << " !ObjInterface " << Name()
1225 << " IsLoopNode PyDynInvoke '" << InLineNode()->PyFuncName()
1226 << "' InitLoop " << LoopNode()->PyRunMethod() << endl ;
1227 StsPyDynInvoke = PyDynInvoke( InLineNode()->PyRunMethod() ,
1228 InLineNode()->PyFuncName() ,
1229 &InParametersList[1] , ServiceInParameter().length() ,
1230 &OutParametersList[1] , ServiceOutParameter().length() ) ;
1231 if ( !StsPyDynInvoke ) {
1232 RemovePyDynInvoke( InLineNode()->PyFuncName() ) ;
1237 cdebug << ThreadNo() << " !ObjInterface " << Name()
1238 << " IsLoopNode NO PyDynInvoke Void PyFuncName InitLoop" << endl ;
1240 cdebug << ThreadNo() << " !ObjInterface " << Name()
1241 << " IsLoopNode _InitLoop Reset after Init() Python Function" << endl ;
1244 else if ( LoopNode()->PyNextMethod() &&
1245 strlen( LoopNode()->PyNextName() ) ){ // InLoop Port = false ==> Next()
1246 cdebug << ThreadNo() << " !ObjInterface " << Name()
1247 << " IsLoopNode PyDynInvoke '" << LoopNode()->PyNextName()
1248 << "' " << LoopNode()->PyNextMethod() << endl ;
1249 StsPyDynInvoke = PyDynInvoke( LoopNode()->PyNextMethod() ,
1250 LoopNode()->PyNextName() ,
1251 &InParametersList[1] , ServiceInParameter().length() ,
1252 &OutParametersList[1] , ServiceOutParameter().length() ) ;
1253 if ( !StsPyDynInvoke ) {
1254 RemovePyDynInvoke( LoopNode()->PyNextName() ) ;
1259 cdebug << ThreadNo() << " !ObjInterface " << Name()
1260 << " IsLoopNode NO PyDynInvoke Void PyFuncName NextLoop" << endl ;
1262 if ( StsPyDynInvoke ) {
1264 cdebug << ThreadNo() << " !ObjInterface " << Name()
1265 << " IsLoopNode PyDynInvoke '" << LoopNode()->PyMoreName()
1266 << "' Copy of " << ServiceInParameter().length()
1267 << " OutParameters" << endl ;
1269 // Start at 1 : Do not copy InLoop ( InLoop == true <==> Init ; InLoop == false <==> Next )
1270 for ( i = 1 ; i <= (int ) ServiceInParameter().length() ; i++ ) {
1271 InParametersList[i].Value = OutParametersList[i].Value ;
1272 InParametersList[i].Name = OutParametersList[i].Name ;
1274 switch ( InParametersList[i].Value.type()->kind() ) {
1275 case CORBA::tk_string :
1277 InParametersList[i].Value >>= t ;
1278 cdebug << "ArgOut->In" << i << " : "
1279 << InParametersList[i].Name.c_str()
1280 << " Value(string) " << t << endl ;
1282 case CORBA::tk_double :
1284 InParametersList[i].Value >>= d;
1285 cdebug << "ArgOut->In" << i << " : "
1286 << InParametersList[i].Name.c_str()
1287 << " Value(double) " << d << endl ;
1289 case CORBA::tk_long :
1291 InParametersList[i].Value >>= l;
1292 cdebug << "ArgOut->In" << i << " : "
1293 << InParametersList[i].Name.c_str()
1294 << " Value(long) " << l << endl ;
1296 case CORBA::tk_objref :
1297 CORBA::Object_ptr obj ;
1300 InParametersList[i].Value >>= obj ;
1301 retstr = ObjectToString( obj );
1302 cdebug << "ArgOut->In" << i << " : "
1303 << InParametersList[i].Name.c_str()
1304 << " Value(object reference) " << retstr << endl ;
1307 cdebug << "ArgOut->In" << i << " : "
1308 << InParametersList[i].Name.c_str()
1309 << " Value(object reference) Catched ERROR" << endl ;
1313 cdebug << "ArgOut->In" << i << " : "
1314 << InParametersList[i].Name.c_str()
1315 << " Value(other) ERROR" << endl ;
1320 if ( LoopNode()->PyMoreMethod() && strlen( LoopNode()->PyMoreName() ) ) {
1321 cdebug << ThreadNo() << " !ObjInterface " << Name()
1322 << " IsLoopNode PyDynInvoke '" << LoopNode()->PyMoreName()
1323 << "' " << LoopNode()->PyMoreMethod() << endl ;
1324 StsPyDynInvoke = PyDynInvoke( LoopNode()->PyMoreMethod() ,
1325 LoopNode()->PyMoreName() ,
1326 &InParametersList[1] , ServiceInParameter().length() ,
1327 &OutParametersList[0] , ServiceOutParameter().length()+1 ) ;
1328 if ( !StsPyDynInvoke ) {
1329 RemovePyDynInvoke( LoopNode()->PyMoreName() ) ;
1333 cdebug << ThreadNo() << " !ObjInterface " << Name()
1334 << " IsLoopNode PyDynInvoke '" << LoopNode()->PyMoreName()
1335 << "' No MoreMethod" << endl ;
1341 cdebug << ThreadNo() << " InLineNode " << Name() << " "
1342 << InLineNode()->PyFuncName() << "/" << LoopNode()->PyNextName()
1343 << " Python Dynamic Call Error"
1347 else if ( IsSwitchNode() && /*InLineNode()->PyRunMethod() &&*/
1348 strlen( InLineNode()->PyFuncName() ) ) {
1349 // cdebug << ThreadNo() << " !ObjInterface " << Name() << " PyFuncName '"
1350 // << InLineNode()->PyFuncName()
1351 // << "' IsSwitchNode PyDynInvoke" << endl ;
1352 StsPyDynInvoke = PyDynInvoke( InLineNode()->PyRunMethod() ,
1353 InLineNode()->PyFuncName() ,
1354 &InParametersList[0] , ServiceInParameter().length() ,
1355 &OutParametersList[0] , ServiceOutParameter().length() ) ;
1356 if ( !StsPyDynInvoke ) {
1357 RemovePyDynInvoke( InLineNode()->PyFuncName() ) ;
1360 // else if ( IsGOTONode() && (*GOTONode()->PythonFunction()).length() &&
1361 else if ( IsGOTONode() && /*InLineNode()->PyRunMethod() &&*/
1362 strlen( InLineNode()->PyFuncName() ) ) {
1363 // cdebug << ThreadNo() << " !ObjInterface " << Name() << " PyFuncName '"
1364 // << InLineNode()->PyFuncName()
1365 // << "' IsGOTONode PyDynInvoke" << endl ;
1366 StsPyDynInvoke = PyDynInvoke( InLineNode()->PyRunMethod() ,
1367 InLineNode()->PyFuncName() ,
1368 &InParametersList[0] , ServiceInParameter().length() ,
1369 &OutParametersList[0] , ServiceOutParameter().length() ) ;
1370 if ( !StsPyDynInvoke ) {
1371 RemovePyDynInvoke( GOTONode()->PyFuncName() ) ;
1374 // else if ( IsEndSwitchNode() && (*InLineNode()->PythonFunction()).length() &&
1375 else if ( ( IsEndSwitchNode() ) &&
1376 InLineNode()->PyRunMethod() && strlen( InLineNode()->PyFuncName() ) ) {
1377 // cdebug << ThreadNo() << " !ObjInterface " << Name() << " PyFuncName '"
1378 // << InLineNode()->PyFuncName()
1379 // << "' IsSwitchNode PyDynInvoke" << endl ;
1380 StsPyDynInvoke = PyDynInvoke( InLineNode()->PyRunMethod() ,
1381 InLineNode()->PyFuncName() ,
1382 &InParametersList[0] , ServiceInParameter().length() ,
1383 &OutParametersList[0] , ServiceOutParameter().length() ) ;
1384 if ( !StsPyDynInvoke ) {
1385 RemovePyDynInvoke( InLineNode()->PyFuncName() ) ;
1388 else if ( ( IsEndLoopNode() ) &&
1389 InLineNode()->PyRunMethod() && strlen( InLineNode()->PyFuncName() ) ) {
1390 cdebug << ThreadNo() << " !ObjInterface " << Name() << " PyFuncName '"
1391 << InLineNode()->PyFuncName()
1392 << "' IsSwitchNode PyDynInvoke" << endl ;
1393 StsPyDynInvoke = PyDynInvoke( InLineNode()->PyRunMethod() ,
1394 InLineNode()->PyFuncName() ,
1395 &InParametersList[0] , ServiceInParameter().length() + 1 ,
1396 &OutParametersList[0] , ServiceOutParameter().length() + 1 ) ;
1397 if ( !StsPyDynInvoke ) {
1398 RemovePyDynInvoke( InLineNode()->PyFuncName() ) ;
1402 // else if ( (*InLineNode()->PythonFunction()).length() == 0 ||
1403 if ( (!ItIsaLoop && ( InLineNode()->PyRunMethod() == NULL ||
1404 strlen( InLineNode()->PyFuncName() ) == 0 ) ) || CopyInOut ) {
1405 // This is a void Python Function : without code (No PyFuncName)
1406 // cdebug << ThreadNo() << " !ObjInterface " << Name()
1407 // << " Copy of " << ServiceInParameter().length()
1408 // << " OutParameters" << endl ;
1412 if ( IsLoopNode() || IsEndLoopNode() ) {
1414 argin0 = 1 ; // after DoLoop
1415 if ( IsLoopNode() ) { // More() is void
1416 // OutParametersList[0].Value = InParametersList[0].Value ; // DoLoop
1417 cdebug << Name() << " Not Beginning of loop and non void EndLoop : DoLoop = EndLoop(DoLoop)"
1419 GraphExecutor::InNode * anEndLoopNode = (GraphExecutor::InNode * ) CoupledNode()->GetInNode() ;
1420 OutParametersList[0].Value = *anEndLoopNode->GetNodeOutLoop()->Value() ; // DoLoop = EndLoop(DoLoop)
1423 for ( i = 0 ; i < (int ) ServiceInParameter().length() ; i++ ) {
1424 OutParametersList[argout0 + i].Value = InParametersList[argin0 + i].Value ;
1426 switch ( InParametersList[argin0 + i].Value.type()->kind() ) {
1427 case CORBA::tk_string :
1428 cdebug << "ArgOut->In" << argin0 + i << " : "
1429 << InParametersList[argin0 + i].Name.c_str()
1430 << " Value(string) "
1431 << OutParametersList[argout0 + i].Name.c_str() << endl ;
1433 case CORBA::tk_double :
1434 cdebug << "ArgOut->In" << argin0 + i << " : "
1435 << InParametersList[argin0 + i].Name.c_str()
1436 << " Value(double) "
1437 << OutParametersList[argout0 + i].Name.c_str() << endl ;
1439 case CORBA::tk_long :
1440 cdebug << "ArgOut->In" << argin0 + i << " : "
1441 << InParametersList[argin0 + i].Name.c_str()
1443 << OutParametersList[argout0 + i ].Name.c_str() << endl ;
1445 case CORBA::tk_objref :
1446 cdebug << "ArgOut->In" << argin0 + i << " : "
1447 << InParametersList[argin0 + i].Name.c_str()
1448 << " Value(object reference) "
1449 << OutParametersList[argout0 + i].Name.c_str() << endl ;
1452 cdebug << "ArgOut->In" << argin0 + i << " : "
1453 << InParametersList[argin0 + i].Name.c_str()
1454 << " Value(other) ERROR "
1455 << OutParametersList[argout0 + i].Name.c_str() << endl ;
1460 if ( !StsPyDynInvoke ) {
1462 cdebug << ThreadNo() << " InLineNode " << Name()
1463 << " Python Dynamic Call Error"
1469 cdebug << ThreadNo() << " InLineNode " << Name()
1470 << " Python Dynamic Call Exception catched ERROR"
1474 _OutNode->PyThreadUnLock() ;
1479 cdebug << "DynInvoke -> Names " << _OutNode->Graph()->Name() << " " << Name() << endl ;
1480 DynInvoke( myObjComponent, "Names" ,
1481 _OutNode->Graph()->Name() , Name() ) ;
1484 cdebug << "DynInvoke Names catched ERROR" << endl ;
1486 // for DataStreamNodes : call of SetProperties ===> environment variables in the component/container
1487 if ( ComputingNode()->HasDataStream() ) {
1489 cdebug << "DynInvoke -> SetProperties " << _OutNode->Graph()->Name() << " " << Name() << endl ;
1490 Engines::FieldsDict_var dict = new Engines::FieldsDict;
1492 dict[ 0 ].key = CORBA::string_dup( "CAL_MACHINE");
1493 // myContainer->getHostName() ne renvoit pas le nom complet (avec domaine).
1494 // dict[ 0 ].value <<= myContainer->getHostName() ;
1495 char FullyQualifiedDomainName[256]="";
1496 gethostname(FullyQualifiedDomainName,255);
1497 dict[ 0 ].value <<= FullyQualifiedDomainName ;
1498 dict[ 1 ].key = CORBA::string_dup( "CAL_REPERTOIRE");
1499 dict[ 1 ].value <<= "/tmp" ;
1500 dict[ 2 ].key = CORBA::string_dup( "CAL_COUPLAGE");
1501 stringstream ofst1 ;
1502 ofst1 << ComputingNode()->SubStreamGraph() ;
1503 string cpl = string( "/tmp/" ) + string( _OutNode->Graph()->Name() ) + string( "_" ) +
1504 ofst1.str() + string( ".cpl" );
1505 dict[ 2 ].value <<= cpl.c_str() ;
1506 dict[ 3 ].key = CORBA::string_dup( "SALOME_INSTANCE_NAME");
1507 string uname = Name();
1509 dict[ 3 ].value <<= uname.c_str() ;
1511 myObjComponent->setProperties( dict ) ;
1514 cdebug << "DynInvoke setProperties catched ERROR" << endl ;
1518 if ( !Err && IsComputingNode() ) {
1519 cdebug << ThreadNo() << " !ObjInterface " << Name()
1520 << " IsComputingNode DynInvoke" << endl ;
1521 cdebug << ServiceInParameter().length()-1 << " input parameters and "
1522 << ServiceOutParameter().length() << " output parameters" << endl ;
1523 IsLoading( false ) ;
1524 DynInvoke( myObjComponent,
1526 &InParametersList[1] , ServiceInParameter().length()-1 ,
1527 &OutParametersList[0] , ServiceOutParameter().length() ) ;
1529 else if ( !Err && IsFactoryNode() ) {
1530 cdebug << ThreadNo() << " !ObjInterface " << Name()
1531 << " IsFactoryNode DynInvoke" << endl ;
1532 cdebug << ServiceInParameter().length() << " input parameters and "
1533 << ServiceOutParameter().length() << " output parameters" << endl ;
1534 IsLoading( false ) ;
1535 DynInvoke( myObjComponent,
1537 &InParametersList[0] , ServiceInParameter().length() ,
1538 &OutParametersList[0] , ServiceOutParameter().length() ) ;
1540 // cdebug << ThreadNo() << " Component::CpuUsed " << Name() << " "
1541 // << myObjComponent->CpuUsed_impl() << endl ;
1545 cdebug << ThreadNo() << " !ObjInterface " << Name()
1546 << " Node(Component) Dynamic Call Exception catched ERROR"
1548 //Reset of _ThreadId in the Container ...
1550 myObjComponent->Kill_impl() ;
1560 // ostringstream astr ;
1561 // astr << "Graph " << _OutNode->Graph()->Name() << " Node " << Name() << " is done : "
1562 // << Automaton()->StateName( State() ) ;
1563 // _OutNode->Graph()->ObjImpl()->sendMessage( NOTIF_STEP, astr.str().c_str() ) ;
1567 // if exception or something else - IsLoading( false ) may not NOT has been called
1571 if ( ControlState() == SUPERV::ToKillState ||
1572 ControlState() == SUPERV::ToKillDoneState ||
1573 ControlState() == SUPERV::ToStopState ) {
1574 PortState = SUPERV::ErrorState ;
1575 NewState = GraphExecutor::KilledState ;
1576 NewEvent = GraphExecutor::KillEvent ;
1579 PortState = SUPERV::ErrorState ;
1580 NewState = GraphExecutor::ErroredState ;
1581 NewEvent = GraphExecutor::ErrorEvent ;
1585 PortState = SUPERV::ReadyState ;
1586 NewState = GraphExecutor::DataReadyState ;
1587 NewEvent = GraphExecutor::SuccessEvent ;
1590 if ( !IsMacroNode() ) {
1591 bool ErrOut = OutParametersSet( Err , PortState , nOutParams , OutParametersList ) ;
1593 NewEvent = GraphExecutor::ErrorEvent ;
1595 delete [] InParametersList ;
1596 delete [] OutParametersList ;
1599 if ( !IsMacroNode() ) {
1600 SendEvent( NewEvent ) ;
1603 GraphExecutor::DataFlow * aMacroGraph = GraphMacroNode()->CoupledNode()->GraphEditor()->Executor() ;
1604 cdebug << ThreadNo() << " DataReady_ExecuteAction " << aMacroGraph << " "
1605 << aMacroGraph->Graph()->Name() << " ->DoneWait()"
1606 << " State " << aMacroGraph->State() << endl;
1607 aMacroGraph->DoneWait() ;
1608 cdebug << ThreadNo() << " DataReady_ExecuteAction " << Name() << " State " << aMacroGraph->State() << endl;
1609 if ( aMacroGraph->State() == SUPERV::DoneState ) {
1610 PortState = SUPERV::ReadyState ;
1611 NewState = GraphExecutor::DataReadyState ;
1612 NewEvent = GraphExecutor::SuccessEvent ;
1616 if ( ControlState() == SUPERV::ToKillState ||
1617 ControlState() == SUPERV::ToKillDoneState ||
1618 ControlState() == SUPERV::ToStopState ) {
1619 PortState = SUPERV::ErrorState ;
1620 NewState = GraphExecutor::KilledState ;
1621 NewEvent = GraphExecutor::KillEvent ;
1624 PortState = SUPERV::ErrorState ;
1625 NewState = GraphExecutor::ErroredState ;
1626 NewEvent = GraphExecutor::ErrorEvent ;
1629 bool ErrOut = OutParametersSet( Err , PortState , nOutParams , OutParametersList ) ;
1631 NewEvent = GraphExecutor::ErrorEvent ;
1633 delete [] InParametersList ;
1634 delete [] OutParametersList ;
1635 SendEvent( NewEvent ) ;
1638 // cdebug << ThreadNo() << " <-- DataReady_ExecuteAction " << Name() << endl;
1642 int GraphExecutor::InNode::Executing_SuspendAction() {
1643 _OutNode->PushEvent( this , GraphExecutor::SuspendedExecutingEvent ,
1644 GraphExecutor::SuspendedExecutingState ) ;
1645 cdebug << ThreadNo() << " Executing_SuspendAction " << Name() << endl;
1649 int GraphExecutor::InNode::SuspendedExecuting_ResumeAction() {
1650 cdebug << ThreadNo() << " SuspendedExecuting_ResumeAction " << Name() << endl;
1651 GraphExecutor::AutomatonState next_state ;
1652 next_state = Automaton()->NextState( State() , GraphExecutor::ExecutingEvent ) ;
1653 _OutNode->NewThread() ; // Only for Threads count
1654 _OutNode->PushEvent( this , GraphExecutor::ResumedExecutingEvent ,
1656 State( next_state ) ;
1660 int GraphExecutor::InNode::Executing_KillAction() {
1661 cdebug << ThreadNo() << " Executing_KillAction " << Name() << " Thread " << ThreadNo()<< endl;
1663 if ( pthread_self() == ThreadNo() ) {
1664 cdebug << "Executing_KillAction would pthread_canceled itself" << endl ;
1666 _OutNode->PushEvent( this , GraphExecutor::KilledExecutingEvent ,
1667 GraphExecutor::KilledExecutingState ) ;
1670 else if ( pthread_cancel( ThreadNo() ) ) {
1671 perror("Executing_KillAction pthread_cancel error") ;
1674 cdebug << pthread_self() << " Executing_KillAction : ThreadId " << ThreadNo()
1675 << " pthread_canceled" << endl ;
1677 _OutNode->ExitThread( ThreadNo() ) ;
1678 _OutNode->PushEvent( this , GraphExecutor::KilledExecutingEvent ,
1679 GraphExecutor::KilledExecutingState ) ;
1684 int GraphExecutor::InNode::Executing_StopAction() {
1685 cdebug << ThreadNo() << " Executing_StopAction " << Name() << " Thread " << ThreadNo() << endl;
1687 if ( pthread_cancel( ThreadNo() ) ) {
1688 perror("Executing_KillAction pthread_cancel error") ;
1691 cdebug << pthread_self() << " Executing_KillAction : ThreadId " << ThreadNo()
1692 << " pthread_canceled" << endl ;
1694 _OutNode->ExitThread( ThreadNo() ) ;
1695 _OutNode->PushEvent( this , GraphExecutor::StoppedExecutingEvent ,
1696 GraphExecutor::StoppedExecutingState ) ;
1701 int GraphExecutor::InNode::Executing_SuccessAction() {
1702 // cdebug << ThreadNo() << " --> Executing_SuccessAction " << Name() << endl;
1703 _OutNode->PushEvent( this , GraphExecutor::SuccessedExecutingEvent ,
1704 GraphExecutor::SuccessedState ) ;
1705 MESSAGE(pthread_self() << "Executor::InNode::Executing_SuccessAction of " << Name()
1706 << " ControlState " << Automaton()->ControlStateName( ControlState() )
1707 << " AFTER execution ThreadNo " << ThreadNo() ) ;
1708 SUPERV::ControlState aControl = ControlState() ;
1709 switch ( aControl ) {
1710 case SUPERV::VoidState : {
1711 SendEvent( SuccessEvent ) ;
1714 case SUPERV::ToSuspendState : {
1715 SendEvent( SuccessEvent ) ;
1718 case SUPERV::ToSuspendDoneState : {
1719 SendEvent( GraphExecutor::SuspendEvent ) ;
1722 case SUPERV::ToKillState : {
1723 SendEvent( GraphExecutor::KillEvent ) ;
1726 case SUPERV::ToKillDoneState : {
1727 SendEvent( GraphExecutor::KillEvent ) ;
1730 case SUPERV::ToStopState : {
1731 SendEvent( GraphExecutor::StopEvent ) ;
1735 cdebug << ThreadNo()
1736 << " GraphExecutor::InNodeThreads::Executing_SuccessAction Error Undefined Control : "
1737 << aControl << endl ;
1741 // cdebug << ThreadNo() << " <-- Executing_SuccessAction " << Name() << endl;
1745 int GraphExecutor::InNode::Executing_ErrorAction() {
1746 cdebug << ThreadNo() << " --> Executing_ErrorAction " << Name() << endl;
1747 _OutNode->PushEvent( this , GraphExecutor::ErroredExecutingEvent ,
1748 GraphExecutor::ErroredState ) ;
1750 SUPERV::ControlState aControl = ControlState() ;
1751 switch ( aControl ) {
1752 case SUPERV::VoidState : {
1753 SendEvent( ErrorEvent ) ;
1756 case SUPERV::ToSuspendState : {
1757 SendEvent( ErrorEvent ) ;
1760 case SUPERV::ToSuspendDoneState : {
1761 SendEvent( GraphExecutor::SuspendEvent ) ;
1764 case SUPERV::ToKillState : {
1765 SendEvent( GraphExecutor::KillEvent ) ;
1768 case SUPERV::ToKillDoneState : {
1769 SendEvent( GraphExecutor::KillEvent ) ;
1772 case SUPERV::ToStopState : {
1773 SendEvent( GraphExecutor::StopEvent ) ;
1777 cdebug << ThreadNo()
1778 << " GraphExecutor::InNodeThreads::Executing_ErrorAction Error Undefined Control : "
1779 << aControl << endl ;
1783 cdebug << ThreadNo() << " <-- Executing_ErrorAction " << Name() << endl;
1787 // Set SUPERV::WaitingState to all InPorts
1788 void GraphExecutor::InNode::SetWaitingStates(GraphExecutor::InNode * EndNode ) {
1791 bool docdebug = false ;
1792 State( GraphExecutor::DataWaitingState ) ;
1793 for ( i = 0 ; i < GetNodeInPortsSize() ; i++ ) {
1794 GraphBase::InPort * anInPort = GetChangeNodeInPort( i ) ;
1795 if ( anInPort->IsGate() ) { // Loop : Open the doors
1796 GraphBase::OutPort * anOutPort = anInPort->GetOutPort() ;
1798 CORBA::Any * anAny = new CORBA::Any() ;
1799 *anAny <<= (long ) 1 ;
1800 anOutPort->Value( anAny ) ;
1801 anInPort->State( SUPERV::ReadyState ) ;
1804 else if ( anInPort->State() != SUPERV::WaitingState ) {
1806 cdebug << ThreadNo()
1807 << " --> GraphExecutor::InNodeThreads::SetWaitingStates " << Name() << endl;
1810 if ( !anInPort->IsDataStream() ) {
1811 anInPort->State( SUPERV::WaitingState ) ;
1815 for ( i = 0 ; i < GetNodeOutPortsSize() ; i++ ) {
1816 GraphBase::OutPort * anOutPort = GetChangeNodeOutPort( i ) ;
1817 for ( j = 0 ; j < anOutPort->InPortsSize() ; j++ ) {
1818 if ( !( IsGOTONode() && anOutPort->IsGate() ) &&
1819 !( IsEndLoopNode() && ( anOutPort->IsGate() ||
1820 anOutPort->IsLoop() ) ) &&
1821 !anOutPort->IsDataStream() &&
1822 !anOutPort->ChangeInPorts( j )->IsDataStream() &&
1823 !anOutPort->ChangeInPorts( j )->IsExternConnected() ) {
1824 cdebug << ThreadNo()
1825 << " InNodeThreads::SetWaitingStates OutPort "
1826 << Name() << "/" << anOutPort->ChangeInPorts( j )->NodeName() << "( "
1827 << anOutPort->PortName() << " " << anOutPort->PortStatus() << " ) --> InPort "
1828 << anOutPort->ChangeInPorts( j )->NodeName() << "( "
1829 << anOutPort->ChangeInPorts( j )->PortName() << " "
1830 << anOutPort->ChangeInPorts( j )->PortStatus() << " )" << endl;
1831 if ( strcmp( anOutPort->ChangeInPorts( j )->GetOutPort()->NodeName() , Name() ) ) {
1832 // After EndLoopNode or GOTONode the Input Ports of LoopNode or LabelNode have their values from
1833 // EndLoopNode or GOTONode. But if there is several nested loops we should re-establish.
1834 cdebug << ThreadNo()
1835 << " InNodeThreads::SetWaitingStates OutPort->ChangeInPorts( j )->OutPort()->NodeName "
1836 << anOutPort->ChangeInPorts( j )->GetOutPort()->NodeName() << " != "
1837 << Name() << " : Restored to " << anOutPort->NodeName() << "( "
1838 << anOutPort->PortName() << " )" << endl ;
1839 anOutPort->ChangeInPorts( j )->ChangeOutPort( anOutPort ) ;
1841 GraphExecutor::InNode * aNode = (GraphExecutor::InNode * ) _OutNode->Graph()->GetChangeGraphNode( anOutPort->ChangeInPorts( j )->NodeName() )->GetInNode() ;
1842 if ( aNode != EndNode ) {
1843 aNode->SetWaitingStates( EndNode ) ;
1850 int GraphExecutor::InNode::Successed_SuccessAction() {
1851 cdebug << ThreadNo() << " --> Successed_SuccessAction " << Name() << endl;
1853 int linkednodesnumber = LinkedNodesSize() ;
1854 GraphExecutor::InNode *firstzeroNode = NULL ;
1855 GraphExecutor::InNode *firsttoNode = NULL ;
1856 GraphExecutor::InNode *toNode ;
1859 list<GraphExecutor::InNode *> SomeDataNodes ;
1863 if ( IsMacroNode() ) {
1864 cdebug << ThreadNo() << " Successed_SuccessAction " << Name() << " LinkedNodes->SomeDataReady already done"
1869 if ( IsGOTONode() ||
1870 ( IsEndLoopNode() && GetNodeInLoop()->GetOutPort()->BoolValue() ) ) {
1871 cdebug << ThreadNo() << " Successed_SuccessAction " << Name()
1872 << " SetWaitingStates " << endl ;
1873 const GraphBase::OutPort * aGateOutPort ;
1874 if ( IsGOTONode() ) {
1875 aGateOutPort = GetNodeOutGate() ;
1878 aGateOutPort = GetNodeOutLoop() ;
1880 if ( aGateOutPort->InPortsSize() != 1 ) {
1881 cdebug << ThreadNo() << " Successed_SuccessAction aGateOutPort->InPortsSize "
1882 << aGateOutPort->InPortsSize() << " != 1 ERROR " << Name() << endl ;
1884 GraphExecutor::InNode * aLabelNode = NULL ;
1885 for ( i = 0 ; i < aGateOutPort->InPortsSize() ; i++ ) {
1886 const GraphBase::InPort * anInPort = aGateOutPort->InPorts( i ) ;
1887 aLabelNode = (GraphExecutor::InNode *) _OutNode->Graph()->GetChangeGraphNode( anInPort->NodeName() )->GetInNode() ;
1888 cdebug << ThreadNo() << " Successed_SuccessAction " << Name() << " will Loop to HeadNode "
1889 << aLabelNode->Name() << " from port " << anInPort->PortName() << endl ;
1890 aLabelNode->SetWaitingStates( this ) ;
1891 for ( j = 0 ; j < aLabelNode->GetNodeInPortsSize() ; j++ ) {
1892 const GraphBase::InPort * anInPort = aLabelNode->GetNodeInPort( j ) ;
1893 if ( anInPort->GetOutPort() ) {
1894 cdebug << aLabelNode->Name() << "(" << anInPort->PortName() << ") value : "
1895 << anInPort->GetOutPort()->NodeName() << "(" << anInPort->GetOutPort()->PortName() << ")"
1899 for ( j = 0 ; j < GetNodeOutPortsSize() ; j++ ) {
1900 GraphBase::OutPort * aBusParamOutPort = GetChangeNodeOutPort( j ) ;
1901 if ( !aBusParamOutPort->IsGate() ) {
1902 GraphBase::InPort * aBusParamChangeInPort = NULL ;
1903 if ( aBusParamOutPort->IsLoop() ) {
1904 // For EndLoop do not copy EndLoop(DoLoop) in Loop(InLoop)
1905 // aBusParamChangeInPort = aLabelNode->GetChangeNodeInLoop() ;
1908 aBusParamChangeInPort = aLabelNode->GetChangeInPort( aBusParamOutPort->PortName() ) ;
1910 if ( aBusParamChangeInPort ) {
1911 aBusParamChangeInPort->ChangeOutPort( aBusParamOutPort ) ;
1912 cdebug << ThreadNo() << " Successed_SuccessAction " << Name() << " ChangeOutPort to HeadNode "
1913 << aLabelNode->Name() << "(" << aBusParamChangeInPort->PortName() << ") from port "
1914 << aBusParamOutPort->PortName() << endl ;
1920 if ( aLabelNode && !aLabelNode->IsLockedDataWait() ) {
1921 res = aLabelNode->SendSomeDataReady( Name() ) ;
1923 if ( firsttoNode == NULL &&
1924 aLabelNode->ThreadNo() == pthread_self() ) {
1925 firsttoNode = aLabelNode ;
1926 cdebug << ThreadNo() << " Successed_SuccessAction firsttoNode "
1927 << aLabelNode->Name() << endl ;
1929 else if ( firstzeroNode == NULL &&
1930 aLabelNode->ThreadNo() == 0 ) {
1931 firstzeroNode = aLabelNode ;
1934 SomeDataNodes.push_back( aLabelNode ) ;
1935 cdebug << ThreadNo() << " Successed_SuccessAction " << Name() << " push "
1936 << aLabelNode->Name() << " " << SomeDataNodes.size()
1941 for ( j = 0 ; j < aLabelNode->GetNodeInPortsSize() ; j++ ) {
1942 const GraphBase::InPort * anInPort = aLabelNode->GetNodeInPort( j ) ;
1943 if ( anInPort->GetOutPort() ) {
1944 cdebug << aLabelNode->Name() << "(" << anInPort->PortName() << ") value : "
1945 << anInPort->GetOutPort()->NodeName() << "(" << anInPort->GetOutPort()->PortName() << ")"
1949 const GraphBase::InPort * aGateInPort = aLabelNode->GetNodeInGate() ;
1950 if ( aGateInPort ) {
1951 if ( aGateInPort->GetOutPort() ) {
1952 aGateInPort->GetOutPort()->Value( aGateOutPort->Value() ) ;
1954 if ( !aLabelNode->IsLockedDataWait() ) {
1955 res = aLabelNode->SendSomeDataReady( Name() ) ;
1957 if ( firsttoNode == NULL &&
1958 aLabelNode->ThreadNo() == pthread_self() ) {
1959 firsttoNode = aLabelNode ;
1960 cdebug << ThreadNo() << " Successed_SuccessAction firsttoNode "
1961 << aLabelNode->Name() << endl ;
1963 else if ( firstzeroNode == NULL &&
1964 aLabelNode->ThreadNo() == 0 ) {
1965 firstzeroNode = aLabelNode ;
1968 SomeDataNodes.push_back( aLabelNode ) ;
1969 cdebug << ThreadNo() << " Successed_SuccessAction " << Name() << " push "
1970 << aLabelNode->Name() << " " << SomeDataNodes.size()
1977 cdebug << ThreadNo() << " ERROR in Successed_SuccessAction of " << Name()
1978 << " NO port " << aGateOutPort->PortName() << " in "
1979 << aLabelNode->Name() << endl;
1985 cdebug << ThreadNo() << " Successed_SuccessAction of " << Name()
1986 << " with " << LinkedNodesSize() << " linked nodes :" ;
1987 for ( i = 0 ; i < LinkedNodesSize() ; i++ ) {
1988 if ( LinkedNodes( i )->IsDataFlowNode() ) {
1989 linkednodesnumber -= 1 ;
1991 cdebug << " " << LinkedNodes( i )->Name() ;
1994 for ( i = 0 ; i < LinkedNodesSize() ; i++ ) {
1995 bool IgnoreForEndLoop = false ;
1996 GraphBase::ComputingNode * aComputingNode ;
1997 aComputingNode = (GraphBase::ComputingNode * ) LinkedNodes( i ) ;
1998 toNode = (GraphExecutor::InNode *) aComputingNode->GetInNode() ;
1999 cdebug << ThreadNo() << " Successed_SuccessAction of " << Name()
2000 << " [" << i << "] " << LinkedNodes( i )->Name() << " toNode " << toNode << " IgnoreForEndLoop "
2001 << IgnoreForEndLoop ;
2003 cdebug << " " << toNode->Kind() << endl ;
2005 if ( toNode && !toNode->IsDataFlowNode() ) {
2006 if ( IsComputingNode() && toNode->IsInLineNode() ) {
2007 GraphBase::InPort * toGateInPort = toNode->GetChangeNodeInGate() ;
2008 toGateInPort->State( SUPERV::ReadyState ) ;
2009 GraphBase::OutPort * GateOutPort = toGateInPort->GetOutPort() ;
2010 if ( GateOutPort ) {
2011 GateOutPort->PortStatus( DataConnected );
2012 GateOutPort->State( SUPERV::ReadyState ) ;
2013 GateOutPort->Done( true ) ;
2017 if ( toNode && IsLoopNode() ) {
2018 GraphBase::OutPort * fromLoopOutPort = GetChangeNodeOutLoop() ;
2019 if ( !fromLoopOutPort->BoolValue() ) { // Ne pas faire la boucle
2020 if ( strcmp( toNode->Name() , CoupledNode()->Name() ) ) {
2021 IgnoreForEndLoop = true ;
2023 else { // toNode is the EndLoopNode
2024 GraphBase::InPort * toLoopInPort ;
2025 toLoopInPort = toNode->GetChangeNodeInLoop() ;
2026 if ( toLoopInPort->State() != SUPERV::ReadyState ) {
2027 toLoopInPort->State( SUPERV::ReadyState ) ;
2032 else if ( toNode && IsSwitchNode() ) {
2034 else if ( toNode && toNode->IsInLineNode() ) {
2036 for ( j = 0 ; j < toNode->GetNodeInPortsSize() ; j++ ) {
2037 toNode->GetChangeNodeInPort( j )->InitialOutPort() ;
2040 if ( toNode && !IgnoreForEndLoop ) {
2041 if ( toNode && toNode->IsLoopNode() ) {
2042 GraphBase::InPort * toLoopInPort = toNode->GetChangeNodeInLoop() ;
2043 toLoopInPort->State( SUPERV::ReadyState ) ;
2044 GraphBase::OutPort * LoopOutPort = toLoopInPort->GetOutPort() ;
2045 LoopOutPort->PortStatus( DataConnected );
2046 LoopOutPort->State( SUPERV::ReadyState ) ;
2047 LoopOutPort->Done( true ) ;
2048 CORBA::Any * anAny = new CORBA::Any() ; // InitLoop
2049 *anAny <<= (long ) 1 ;
2050 LoopOutPort->Value( anAny ) ;
2052 for ( j = 0 ; j < toNode->GetNodeInPortsSize() ; j++ ) {
2053 toNode->GetChangeNodeInPort( j )->InitialOutPort() ;
2056 cdebug << ThreadNo() << " Successed_SuccessAction " << toNode->Name() << "->SendSomeDataReady( "
2057 << Name() << " )" << endl ;
2058 res = toNode->SendSomeDataReady( Name() ) ;
2060 if ( firsttoNode == NULL &&
2061 toNode->ThreadNo() == pthread_self() ) {
2062 firsttoNode = toNode ;
2063 cdebug << ThreadNo() << " Successed_SuccessAction firsttoNode "
2064 << toNode->Name() << endl ;
2066 else if ( firstzeroNode == NULL &&
2067 toNode->ThreadNo() == 0 ) {
2068 firstzeroNode = toNode ;
2071 SomeDataNodes.push_back( toNode ) ;
2072 cdebug << ThreadNo() << " Successed_SuccessAction " << Name() << " push "
2073 << toNode->Name() << " " << SomeDataNodes.size() << endl ;
2080 if ( firsttoNode == NULL && firstzeroNode ) {
2081 firsttoNode = firstzeroNode ;
2082 cdebug << ThreadNo()
2083 << " Successed_SuccessAction firsttoNode = firstzeroNode "
2086 else if ( firsttoNode && firstzeroNode ) {
2087 SomeDataNodes.push_back( firstzeroNode ) ;
2088 cdebug << ThreadNo() << " Successed_SuccessAction " << Name() << " push firstzeroNode "
2089 << firstzeroNode->Name() << " " << SomeDataNodes.size() << endl ;
2092 cdebug << ThreadNo() << " Successed_SuccessAction " << Name() << " firsttoNode " << firsttoNode
2093 << " firstzeroNode " << firstzeroNode << endl ;
2096 while ( SomeDataNodes.size() ) {
2097 GraphExecutor::InNode *aNode = SomeDataNodes.front() ;
2098 SomeDataNodes.pop_front() ;
2099 // cdebug << pthread_self() << "/" << ThreadNo()
2100 // << " Successed_SuccessAction pop "
2101 // << SomeDataNodes.size() << " " << aNode->Name() << endl ;
2102 if ( aNode->State() == GraphExecutor::DataReadyState ) {
2103 aNode->CreateNewThreadIf( true ) ;
2104 aNode->UnLockDataWait() ;
2105 res = aNode->DataUndef_AllDataReadyAction() ;
2108 // cdebug << pthread_self() << "/" << ThreadNo() << " ERROR "
2109 // << aNode->Name() << " "
2110 // << Automaton()->StateName( aNode->State() ) << endl ;
2114 if ( firsttoNode ) {
2115 // cdebug << pthread_self() << "/" << ThreadNo()
2116 // << " Successed_SuccessAction start firsttoNode "
2117 // << SomeDataNodes.size() << " " << firsttoNode->Name() << endl ;
2118 firsttoNode->CreateNewThreadIf( false ) ;
2119 firsttoNode->RewindStack( RewindStack() ) ;
2120 if ( firsttoNode->State() == GraphExecutor::SuccessedState ) {
2121 // cdebug << pthread_self() << "/" << ThreadNo() << " " << Name()
2122 // << " : " << firsttoNode->Name() << " "
2123 // << Automaton()->StateName( firsttoNode->State() )
2124 // << " --> DataWaitingState for Thread "
2125 // << firsttoNode->ThreadNo() << endl ;
2126 firsttoNode->State( GraphExecutor::DataWaitingState ) ;
2128 // pthread_t OldT = firsttoNode->ThreadNo() ;
2129 firsttoNode->ThreadNo( pthread_self() ) ;
2130 // On continue avec le meme thread
2131 // cdebug << pthread_self() << "/" << ThreadNo() << " firsttoNode "
2132 // << firsttoNode->Name() << "Thread(" << OldT << "-->"
2133 // << firsttoNode->ThreadNo() << ")" << endl ;
2135 // cdebug << ThreadNo() << " Successed_SuccessAction " << Name()
2136 // << " for " << firsttoNode->Name()
2137 // << " !firsttoNode->CreateNewThreadIf() "
2138 // << !firsttoNode->CreateNewThreadIf()
2139 // << " " << Automaton()->StateName( firsttoNode->State() ) ;
2140 if ( firsttoNode->State() == GraphExecutor::DataReadyState ) {
2142 firsttoNode->UnLockDataWait() ;
2143 res = firsttoNode->DataUndef_AllDataReadyAction() ;
2146 cdebug << " ERROR " << endl ;
2150 // cdebug << ThreadNo() << " Successed_SuccessAction " << Name()
2151 // << " NO DataReady ==> ThreadNo( 0 ) firsttoNode == NULL LINKEDnodesnumber " << linkednodesnumber << endl ;
2155 // if ( linkednodesnumber == 0 && firsttoNode == NULL ) {
2156 // cdebug << ThreadNo() << " Successed_SuccessAction " << Name() << " LinkedNodesSize " << LinkedNodesSize()
2157 // << " firsttoNode == NULL LINKEDnodesnumber " << linkednodesnumber << " CHECK" << endl ;
2158 // _OutNode->CheckAllDone() ;
2161 // cdebug << pthread_self() << "/" << ThreadNo()
2162 // << " <-- Successed_SuccessAction " << Name() << " linkednodesnumber "
2163 // << linkednodesnumber << endl;
2167 bool GraphExecutor::InNode::SendSomeDataReady( char * FromNodeName ) {
2168 bool RetVal = false ;
2169 if ( IsDataFlowNode() ) {
2170 cdebug << ThreadNo() << "InNode::SendSomeDataReady ----> " << Name()
2171 << " send Result to graph " << Name() << endl;
2174 // cdebug << pthread_self() << "/" << ThreadNo() << " ----> " << FromNodeName
2175 // << " send SomeDataReady to " << Name() << " "
2176 // << Automaton()->StateName( State() )
2177 // << " CreateNewThreadIf() " << CreateNewThreadIf()
2178 // << " LockedDataWait " << IsLockedDataWait() << endl;
2180 //cout << pthread_self() << "/" << ThreadNo() << " ----> " << FromNodeName
2181 << " send SomeDataReady to " << Name() << " "
2182 << Automaton()->StateName( State() )
2183 << " CreateNewThreadIf() " << CreateNewThreadIf()
2184 << " LockedDataWait " << IsLockedDataWait() << endl;
2186 if ( State() == GraphExecutor::SuccessedState ||
2187 State() == GraphExecutor::SuspendedSuccessedState ||
2188 State() == GraphExecutor::SuspendedSuccessedToReStartState ) {
2189 // cdebug << ThreadNo() << " " << FromNodeName
2190 // << " : " << Name() << " " << Automaton()->StateName( State() )
2191 // << " --> DataWaitingState for Thread "
2192 // << ThreadNo() << " " << endl ;
2193 State( GraphExecutor::DataWaitingState ) ;
2195 // We begin that LoopNode if SendSomeDataReady does not come from the corresponding EndLoopNode
2196 if ( IsLoopNode() && strcmp( LoopNode()->CoupledNodeName() , FromNodeName ) ) {
2197 cdebug << ThreadNo() << "InNode::SendSomeDataReady " << Name() << " Set _InitLoop from "
2198 << FromNodeName << endl ;
2202 DataFromNode( FromNodeName ) ;
2203 RetVal = !SendEvent( GraphExecutor::SomeDataReadyEvent );
2211 int GraphExecutor::InNode::Errored_ErrorAction() {
2212 cdebug << ThreadNo() << " Errored_ErrorAction " << Name()
2213 << " will pthread_exit" << endl;
2218 int GraphExecutor::InNode::Successed_SuspendAction() {
2219 cdebug << ThreadNo() << " Successed_SuspendAction -->Suspend " << Name()
2220 << " Threads " << _OutNode->Threads() << " SuspendedThreads "
2221 << _OutNode->SuspendedThreads() << endl;
2222 _OutNode->PushEvent( this , GraphExecutor::SuspendedSuccessedEvent ,
2223 GraphExecutor::SuspendedSuccessedState ) ;
2225 GraphExecutor::InNode * aReStartNode = SuspendAction() ;
2226 cdebug << ThreadNo() << " Successed_SuspendAction Resumed " << Name() ;
2227 if ( aReStartNode ) {
2228 _aReStartNode = NULL ;
2229 cdebug << " for " << aReStartNode->Name() << endl;
2230 aReStartNode->SendEvent( _aReStartEvent ) ;
2234 SendEvent( GraphExecutor::ResumeEvent ) ;
2239 int GraphExecutor::InNode::Errored_SuspendAction() {
2240 cdebug << ThreadNo() << " Errored_SuspendAction -->Suspend " << Name()
2241 << " Threads " << _OutNode->Threads() << " SuspendedThreads "
2242 << _OutNode->SuspendedThreads() << endl;
2243 _OutNode->PushEvent( this , GraphExecutor::SuspendedErroredEvent ,
2244 GraphExecutor::SuspendedErroredState ) ;
2246 GraphExecutor::InNode * aReStartNode = SuspendAction() ;
2247 cdebug << ThreadNo() << " Errored_SuspendAction Resumed " << Name()
2249 if ( aReStartNode ) {
2250 _aReStartNode = NULL ;
2251 aReStartNode->SendEvent( _aReStartEvent ) ;
2254 SendEvent( GraphExecutor::ResumeEvent ) ;
2259 int GraphExecutor::InNode::SuspendedSuccessed_ResumeAction() {
2260 cdebug << ThreadNo() << " SuspendedSuccessed_ResumeAction " << Name() << endl;
2262 _OutNode->PushEvent( this , GraphExecutor::ResumedSuccessedEvent ,
2263 GraphExecutor::ResumedSuccessedState ) ;
2264 SendEvent( ResumedSuccessedEvent ) ;
2268 int GraphExecutor::InNode::SuspendedErrored_ResumeAction() {
2269 cdebug << ThreadNo() << " SuspendedErrored_ResumeAction " << Name() << endl;
2271 _OutNode->PushEvent( this , GraphExecutor::ResumedErroredEvent ,
2272 GraphExecutor::ResumedErroredState ) ;
2273 SendEvent( ResumedErroredEvent ) ;
2277 int GraphExecutor::InNode::Successed_KillAction() {
2279 _OutNode->PushEvent( this , GraphExecutor::KilledEvent ,
2280 GraphExecutor::KilledSuccessedState ) ;
2281 cdebug << ThreadNo() << " Successed_KillAction " << Name() << endl;
2285 int GraphExecutor::InNode::Errored_KillAction() {
2287 _OutNode->PushEvent( this , GraphExecutor::KilledEvent ,
2288 GraphExecutor::KilledErroredState ) ;
2289 cdebug << ThreadNo() << " Errored_KillAction " << Name() << endl;
2293 int GraphExecutor::InNode::Successed_StopAction() {
2295 _OutNode->PushEvent( this , GraphExecutor::StoppedEvent ,
2296 GraphExecutor::StoppedSuccessedState ) ;
2297 cdebug << ThreadNo() << " Successed_StopAction " << Name() << endl;
2301 int GraphExecutor::InNode::Errored_StopAction() {
2303 _OutNode->PushEvent( this , GraphExecutor::StoppedEvent ,
2304 GraphExecutor::StoppedErroredState ) ;
2305 cdebug << ThreadNo() << " Errored_StopAction " << Name() << endl;
2309 int GraphExecutor::InNode::SuspendedSuccessed_ReStartAction() {
2310 cdebug << ThreadNo() << " SuspendedSuccessed_ReStartAction " << Name() << endl;
2311 _OutNode->PushEvent( this , GraphExecutor::ReStartedEvent ,
2312 GraphExecutor::ReStartedState ) ;
2314 for ( i = 0 ; i < GetNodeInPortsSize() ; i++ ) {
2315 GetChangeNodeInPort( i )->State( SUPERV::ReadyState ) ;
2317 SendEvent( ExecuteEvent ) ;
2318 cdebug << ThreadNo() << " SuspendedSuccessed_ReStartAction " << Name() << endl;
2322 int GraphExecutor::InNode::SuspendedErrored_ReStartAction() {
2323 cdebug << ThreadNo() << " SuspendedErrored_ReStartAction " << Name() << endl;
2324 _OutNode->PushEvent( this , GraphExecutor::ReStartedEvent ,
2325 GraphExecutor::ReStartedState ) ;
2327 for ( i = 0 ; i < GetNodeInPortsSize() ; i++ ) {
2328 GetChangeNodeInPort( i )->State( SUPERV::ReadyState ) ;
2330 SendEvent( ExecuteEvent ) ;
2331 cdebug << ThreadNo() << " SuspendedErrored_ReStartAction " << Name() << endl;
2335 int GraphExecutor::InNode::SuspendedSuccessed_ReStartAndSuspendAction() {
2336 cdebug << ThreadNo() << " SuspendedSuccessed_ReStartAndSuspendAction " << Name()
2338 _OutNode->PushEvent( this , GraphExecutor::ReStartedAndSuspendEvent ,
2339 GraphExecutor::ReStartedState ) ;
2340 State( GraphExecutor::DataWaitingState ) ;
2342 cdebug << "InNode::Suspend() Node " << Name() << endl ;
2345 else if ( SendEvent( GraphExecutor::SomeDataReadyEvent ) ) {
2346 cdebug << "InNode::SendEvent( SomeDataReadyEvent ) Node "
2350 cdebug << ThreadNo() << " SuspendedSuccessed_ReStartAndSuspendAction " << Name()
2355 int GraphExecutor::InNode::SuspendedErrored_ReStartAndSuspendAction() {
2356 cdebug << ThreadNo() << " SuspendedErrored_ReStartAndSuspendAction " << Name()
2358 _OutNode->PushEvent( this , GraphExecutor::ReStartedAndSuspendEvent ,
2359 GraphExecutor::ReStartedState ) ;
2360 State( GraphExecutor::DataWaitingState ) ;
2362 cdebug << "InNode::Suspend() Node " << Name() << endl ;
2365 else if ( SendEvent( GraphExecutor::SomeDataReadyEvent ) ) {
2366 cdebug << "InNode::SendEvent( SomeDataReadyEvent ) Node "
2370 cdebug << ThreadNo() << " SuspendedErrored_ReStartAndSuspendAction " << Name()
2375 void GraphExecutor::InNode::InParametersSet( bool & Err ,
2377 ServicesAnyData * InParametersList ) {
2379 cdebug << ThreadNo() << " InParametersSet " << Name() << endl ;
2380 for ( i = 0 ; i < nInParams ; i++ ) {
2381 ServicesAnyData D = InParametersList[i];
2382 GraphBase::InPort * anInPort = GetChangeNodeInPort(i) ;
2383 GraphBase::OutPort * theOutPort = anInPort->GetOutPort() ;
2384 if ( anInPort->IsGate() && theOutPort == NULL ) {
2385 cdebug << ThreadNo() << " ArgIn" << i << " " << D.Name << " "
2386 << anInPort->GetServicesParameter().Parametertype
2387 << " is inactive. " << anInPort->Kind() << endl ;
2389 else if ( anInPort->State() == SUPERV::ReadyState ) {
2390 if ( anInPort->IsGate() ) {
2391 CORBA::Any * anAny = new CORBA::Any() ;
2392 *anAny <<= (long ) 0 ;
2393 theOutPort->Value( anAny ) ;
2395 if ( !anInPort->IsDataStream() ) {
2396 anInPort->State( SUPERV::WaitingState ) ;
2398 D.Name = CORBA::string_dup( anInPort->GetServicesParameter().Parametername ) ;
2399 cdebug << ThreadNo() << " ArgIn" << i << " " << anInPort->Kind()
2400 << " " << anInPort->State() ;
2401 cdebug << " " << D.Name << " " << anInPort->GetServicesParameter().Parametertype << " : " ;
2402 D.Value = *theOutPort->Value() ; // CORBA::Any
2403 string _Type = CORBA::string_dup( anInPort->GetServicesParameter().Parametertype ) ;
2404 const char * Type = _Type.c_str() ;
2405 switch ( D.Value.type()->kind() ) { // { string , long , double , objref }
2406 case CORBA::tk_string:
2409 cdebug << t << " (string)" ;
2410 if ( !strcmp( Type , "string" ) ) {
2412 else if ( !strcmp( Type , "boolean" ) ) {
2415 sscanf( t , "%ld" , &d ) ;
2417 D.Value <<= (CORBA::Any::from_boolean ) b ;
2418 // theOutPort->Value( D.Value ) ;
2420 else if ( !strcmp( Type , "char" ) ) {
2423 sscanf( t , "%ld" , &d ) ;
2425 D.Value <<= (CORBA::Any::from_char ) c ;
2426 cdebug << "string '" << t << "' --> " << d << " --> char " << c ;
2427 // theOutPort->Value( D.Value ) ;
2429 else if ( !strcmp( Type , "short" ) ) {
2432 sscanf( t , "%ld" , &d ) ;
2435 cdebug << "string '" << t << "' --> " << d << " --> short " << s ;
2436 // theOutPort->Value( D.Value ) ;
2438 else if ( !strcmp( Type , "int" ) || !strcmp( Type , "long" ) ) {
2440 sscanf( t , "%ld" , &l ) ;
2442 cdebug << "string '" << t << " --> long " << l ;
2443 // theOutPort->Value( D.Value ) ;
2445 else if ( !strcmp( Type , "float" ) ) {
2447 sscanf( t , "%lf" , &d ) ;
2450 cdebug << "string '" << t << "' --> " << setw(25) << setprecision(18) << d << " --> float " << " = "
2451 << setw(25) << setprecision(18) << f ;
2452 // theOutPort->Value( D.Value ) ;
2454 else if ( !strcmp( Type , "double" ) ) {
2456 sscanf( t , "%lf" , &d ) ;
2458 cdebug << "string '" << t << " --> double " << setw(25) << setprecision(18) << d ;
2459 // theOutPort->Value( D.Value ) ;
2461 // else if ( !strcmp( Type , "objref" ) ) {
2463 CORBA::Object_ptr ObjRef ;
2465 ObjRef = StringToObject( t ) ;
2466 D.Value <<= ObjRef ;
2469 D.Value <<= CORBA::Object::_nil() ;
2471 // theOutPort->Value( D.Value ) ;
2474 // cdebug << " (other ERROR)" << endl ;
2476 cdebug << " --> call_kind " << D.Value.type()->kind() << endl ;
2478 case CORBA::tk_long:
2481 cdebug << l << " (long)" << endl ;
2482 if ( !strcmp( Type , "string" ) ) {
2484 sprintf( t , "%ld" , l ) ;
2486 // theOutPort->Value( D.Value ) ;
2488 else if ( !strcmp( Type , "boolean" ) ) {
2491 D.Value <<= (CORBA::Any::from_boolean ) b ;
2492 // theOutPort->Value( D.Value ) ;
2494 else if ( !strcmp( Type , "char" ) ) {
2496 c = (unsigned char ) l ;
2497 D.Value <<= (CORBA::Any::from_char ) c ;
2498 // theOutPort->Value( D.Value ) ;
2500 else if ( !strcmp( Type , "short" ) ) {
2504 // theOutPort->Value( D.Value ) ;
2506 else if ( !strcmp( Type , "int" ) || !strcmp( Type , "long" ) ) {
2508 else if ( !strcmp( Type , "float" ) ) {
2512 // theOutPort->Value( D.Value ) ;
2514 else if ( !strcmp( Type , "double" ) ) {
2518 // theOutPort->Value( D.Value ) ;
2520 // else if ( !strcmp( Type , "objref" ) ) {
2522 D.Value <<= CORBA::Object::_nil() ;
2523 // theOutPort->Value( D.Value ) ;
2526 // cdebug << " (other ERROR)" << endl ;
2528 cdebug << " --> call_kind " << D.Value.type()->kind() << endl ;
2530 case CORBA::tk_double:
2533 cdebug << d << " (double)" << endl ;
2534 if ( !strcmp( Type , "string" ) ) {
2536 sprintf( t , "%lf" , d ) ;
2538 // theOutPort->Value( D.Value ) ;
2540 else if ( !strcmp( Type , "boolean" ) ) {
2543 D.Value <<= (CORBA::Any::from_boolean ) b ;
2544 // theOutPort->Value( D.Value ) ;
2546 else if ( !strcmp( Type , "char" ) ) {
2548 c = (unsigned char ) d ;
2549 D.Value <<= (CORBA::Any::from_char ) c ;
2550 // theOutPort->Value( D.Value ) ;
2552 else if ( !strcmp( Type , "short" ) ) {
2556 // theOutPort->Value( D.Value ) ;
2558 else if ( !strcmp( Type , "int" ) || !strcmp( Type , "long" ) ) {
2562 // theOutPort->Value( D.Value ) ;
2564 else if ( !strcmp( Type , "float" ) ) {
2568 // theOutPort->Value( D.Value ) ;
2570 else if ( !strcmp( Type , "double" ) ) {
2572 // else if ( !strcmp( Type , "objref" ) ) {
2574 D.Value <<= CORBA::Object::_nil() ;
2575 // theOutPort->Value( D.Value ) ;
2578 // cdebug << " (other ERROR)" << endl ;
2580 cdebug << " --> call_kind " << D.Value.type()->kind() << endl ;
2582 case CORBA::tk_objref:
2583 if ( !strcmp( Type , "string" ) ) {
2584 CORBA::Object_ptr ObjRef ;
2587 D.Value >>= ObjRef ;
2588 retstr = ObjectToString( ObjRef ) ;
2589 D.Value <<= retstr ;
2590 // theOutPort->Value( D.Value ) ;
2596 cdebug << "ToString( object ) Catched ERROR" << endl ;
2599 else if ( !strcmp( Type , "boolean" ) ) {
2601 D.Value <<= (CORBA::Any::from_boolean ) b ;
2602 // theOutPort->Value( D.Value ) ;
2604 else if ( !strcmp( Type , "char" ) ) {
2605 unsigned char c = 0 ;
2606 D.Value <<= (CORBA::Any::from_char ) c ;
2607 // theOutPort->Value( D.Value ) ;
2609 else if ( !strcmp( Type , "short" ) ) {
2612 // theOutPort->Value( D.Value ) ;
2614 else if ( !strcmp( Type , "int" ) || !strcmp( Type , "long" ) ) {
2617 // theOutPort->Value( D.Value ) ;
2619 else if ( !strcmp( Type , "float" ) ) {
2622 // theOutPort->Value( D.Value ) ;
2624 else if ( !strcmp( Type , "double" ) ) {
2627 // theOutPort->Value( D.Value ) ;
2629 // else if ( !strcmp( Type , "objref" ) ) {
2631 CORBA::Object_ptr obj ;
2635 retstr = ObjectToString( obj ) ;
2636 cdebug << retstr << endl ;
2642 cdebug << "ToString( object ) Catched ERROR" << endl ;
2646 // cdebug << " (other ERROR)" << endl ;
2648 cdebug << " --> call_kind " << D.Value.type()->kind() << endl ;
2651 cdebug << " (other ERROR) " << D.Value.type()->kind() << endl ;
2655 cdebug << ThreadNo() << " In" << i << " : wrong state ERROR State "
2656 << anInPort->State() << " NameState "
2657 << Automaton()->StateName( anInPort->State() ) << " PortName "
2658 << anInPort->PortName() << " Parametername "
2659 << anInPort->GetServicesParameter().Parametername << endl ;
2662 InParametersList[i] = D ;
2666 void GraphExecutor::InNode::InOutParametersSet( int nOutParams ,
2667 ServicesAnyData * OutParametersList ) {
2669 for ( i = 0 ; i < nOutParams ; i++ ) {
2670 ServicesAnyData D = OutParametersList[i] ;
2672 D.Name = GetChangeNodeOutPort(i)->GetServicesParameter().Parametername;
2673 string _Type = CORBA::string_dup(GetChangeNodeOutPort(i)->GetServicesParameter().Parametertype) ;
2674 const char * Type = _Type.c_str() ;
2675 bool OutDone = GetChangeNodeOutPort(i)->Done() ;
2676 cdebug << ThreadNo() << " ArgOut" << i << " " << D.Name << " Done("
2677 << OutDone << ") " << Type << " : " << endl ;
2678 if ( !strcmp( Type , "string" ) ) {
2679 D.Value <<= (char *) NULL ;
2681 else if ( !strcmp( Type , "boolean" ) ) {
2683 D.Value <<= (CORBA::Any::from_boolean ) b ;
2685 else if ( !strcmp( Type , "char" ) ) {
2686 unsigned char c = 0 ;
2687 D.Value <<= (CORBA::Any::from_char ) c ;
2689 else if ( !strcmp( Type , "short" ) ) {
2693 else if ( !strcmp( Type , "int" ) || !strcmp( Type , "long" ) ) {
2694 D.Value <<= (long ) 0 ;
2696 else if ( !strcmp( Type , "float" ) ) {
2700 else if ( !strcmp( Type , "double" ) ) {
2705 D.Value <<= CORBA::Object::_nil() ;
2708 switch (D.Value.type()->kind()) { // { string , long , double , objref }
2709 case CORBA::tk_string:
2712 cdebug << ThreadNo() << " " << t << "(string)" << endl ;
2714 case CORBA::tk_boolean:
2716 D.Value >>= (CORBA::Any::to_boolean ) b;
2717 cdebug << ThreadNo() << " " << b << "(boolean)" << endl ;
2719 case CORBA::tk_char:
2721 D.Value >>= (CORBA::Any::to_char ) c;
2722 cdebug << ThreadNo() << " " << c << "(char)" << endl ;
2724 case CORBA::tk_short:
2727 cdebug << ThreadNo() << " " << s << "(short)" << endl ;
2729 case CORBA::tk_long:
2732 cdebug << ThreadNo() << " " << l << "(long)" << endl ;
2734 case CORBA::tk_float:
2737 cdebug << ThreadNo() << " " << f << "(float)" << endl ;
2739 case CORBA::tk_double:
2742 cdebug << ThreadNo() << " " << d << "(double)" << endl ;
2744 case CORBA::tk_objref:
2746 CORBA::Object_ptr obj ;
2749 retstr = ObjectToString( obj ) ;
2750 cdebug << ThreadNo() << retstr << endl ;
2753 cdebug << "ToString( object ) Catched ERROR" << endl ;
2757 cdebug << ThreadNo() << " " << "(other ERROR)" << endl ;
2760 OutParametersList[i] = D ;
2764 bool GraphExecutor::InNode::OutParametersSet( bool Err ,
2765 SUPERV::GraphState NewState ,
2767 ServicesAnyData * OutParametersList ) {
2768 bool RetVal = true ;
2770 GraphBase::OutPort * aGateOutPort = NULL ;
2771 bool OrSwitch = false ;
2772 cdebug << "OutParametersSet " << Name() << " nOutParams " << nOutParams << " NewState " << NewState << endl ;
2773 // cout << "OutParametersSet " << Name() << " nOutParams " << nOutParams << " NewState " << NewState << endl ;
2774 if ( nOutParams && !IsMacroNode() ) {
2775 GraphBase::OutPort * anOutPort ;
2776 for ( i = 0 ; i < nOutParams ; i++ ) {
2777 anOutPort = GetChangeNodeOutPort(i) ;
2779 anOutPort->State( NewState ) ;
2780 anOutPort->Done( true ) ;
2783 cdebug << ThreadNo() << " " << "Out" << i << " " << Name() << " "
2784 << anOutPort->PortName() << " " << anOutPort->Kind() ;
2785 ServicesAnyData D = OutParametersList[i] ;
2786 switch (D.Value.type()->kind()) { // { string , long , double , objref }
2787 case CORBA::tk_string: {
2790 cdebug << ThreadNo() << " " << t << "(string)" << endl ;
2793 case CORBA::tk_boolean: {
2795 D.Value >>= (CORBA::Any::to_boolean ) b;
2796 long l = (long ) b ;
2798 cdebug << ThreadNo() << " " << b << "(boolean)" << endl ;
2801 case CORBA::tk_char: {
2803 D.Value >>= (CORBA::Any::to_char ) c;
2804 long l = (long ) c ;
2806 cdebug << ThreadNo() << " " << c << "(char)" << endl ;
2809 case CORBA::tk_short: {
2812 long l = (long ) s ;
2814 cdebug << ThreadNo() << " " << s << "(short)" << endl ;
2817 case CORBA::tk_long: {
2820 cdebug << ThreadNo() << " " << l << "(long)" << endl ;
2823 case CORBA::tk_float: {
2826 double d = (double ) f ;
2828 cdebug << ThreadNo() << " " << f << "(float)" << endl ;
2831 case CORBA::tk_double: {
2834 cdebug << ThreadNo() << " " << d << "(double)" << endl ;
2837 case CORBA::tk_objref: {
2839 CORBA::Object_ptr obj ;
2842 retstr = ObjectToString( obj ) ;
2843 cdebug << ThreadNo() << retstr << endl ;
2846 cdebug << "ToString( object ) Catched ERROR" << endl ;
2851 cdebug << ThreadNo() << " " << "(other ERROR)" << endl ;
2854 OutParametersList[i] = D ;
2855 if ( !anOutPort->IsDataStream() ) {
2856 if ( anOutPort->IsGate() ) {
2857 aGateOutPort = anOutPort ;
2858 cdebug << " Gate " ;
2860 OutParametersList[i].Value <<= l;
2861 anOutPort->Value( OutParametersList[i].Value );
2863 else if ( anOutPort->IsLoop() ) {
2864 cdebug << " Loop " ;
2865 anOutPort->Value( OutParametersList[i].Value );
2866 // InLoop Port of EndLoopNode is ready :
2867 anOutPort->ChangeInPorts(0)->State( SUPERV::ReadyState ) ;
2869 else if ( anOutPort->IsSwitch() ) {
2870 cdebug << " Switch " ;
2871 anOutPort->Value( OutParametersList[i].Value );
2872 if ( anOutPort->InPortsSize() && anOutPort->ChangeInPorts( 0 )->IsGate() ) {
2873 if ( OrSwitch && anOutPort->BoolValue() ) {
2874 cdebug << "GraphExecutor::InNodeThreads::OutParameters more than one switch is true WARNING"
2878 OrSwitch = OrSwitch | anOutPort->BoolValue() ;
2881 cdebug << "OrSwitch " << OrSwitch ;
2884 cdebug << " Param " ;
2885 anOutPort->Value( OutParametersList[i].Value );
2887 anOutPort->State( NewState ) ;
2888 anOutPort->Done( true ) ;
2891 for ( j = 0 ; j < anOutPort->InPortsSize() ; j++ ) {
2892 bool fromGOTO = false ;
2893 const char * ToNodeName = anOutPort->ChangeInPorts( j )->NodeName() ;
2894 if ( !strcmp( ToNodeName , _OutNode->Graph()->Name() ) && _OutNode->Graph()->GraphMacroLevel() != 0 ) {
2895 cdebug << "OutParametersSet ToNodeName " << _OutNode->Graph()->Name() << " CoupledNode "
2896 << _OutNode->Graph()->CoupledNodeName() << _OutNode->Graph()->CoupledNode()
2898 cdebug << " GraphExecutor " << _OutNode->Graph()->CoupledNode()->GraphEditor()->Executor() << endl ;
2899 _OutNode->Graph()->CoupledNode()->GraphEditor()->Executor()->OutputOfAny( _OutNode->Graph()->CoupledNodeName() ,
2900 anOutPort->ChangeInPorts( j )->PortName() ,
2901 *anOutPort->Value() ) ;
2904 GraphBase::ComputingNode * ToNode = _OutNode->Graph()->GetChangeGraphNode( ToNodeName ) ;
2906 // cout << "OutParametersSet ToNodeName " << ToNodeName << endl ;
2907 cdebug << "OutParametersSet ToNodeName " << ToNodeName << " " << ToNode->Name() << endl ;
2908 GraphBase::OutPort * aGOTOPort = ToNode->GetChangeNodeInGate()->GetOutPort() ;
2910 fromGOTO = aGOTOPort->IsGOTO() ;
2912 if ( anOutPort->ChangeInPorts( j )->IsEndSwitch() || fromGOTO ) {
2913 cdebug << anOutPort->ChangeInPorts( j )->NodeName() << "("
2914 << anOutPort->ChangeInPorts( j )->PortName() << ","
2915 << anOutPort->ChangeInPorts( j )->Kind() << ") WILL BE changed from "
2916 << anOutPort->ChangeInPorts( j )->GetOutPort()->NodeName()
2918 << anOutPort->ChangeInPorts( j )->GetOutPort()->PortName()
2919 << ") to " << anOutPort->NodeName() << "("
2920 << anOutPort->PortName() << ")" << endl ;
2921 anOutPort->ChangeInPorts( j )->ChangeOutPort( anOutPort ) ;
2924 cdebug << anOutPort->ChangeInPorts( j )->NodeName() << "("
2925 << anOutPort->ChangeInPorts( j )->PortName() << ","
2926 << anOutPort->ChangeInPorts( j )->Kind() << ") NOT changed from "
2927 << anOutPort->ChangeInPorts( j )->GetOutPort()->NodeName()
2929 << anOutPort->ChangeInPorts( j )->GetOutPort()->PortName()
2930 << ") to " << anOutPort->NodeName() << "("
2931 << anOutPort->PortName() << ")" << endl ;
2937 switch (anOutPort->Value()->type()->kind()) {
2938 case CORBA::tk_string:
2940 (*anOutPort->Value()) >>= t;
2941 cdebug << ThreadNo() << " Out" << i << " : " << t << "(string)" << endl ;
2943 case CORBA::tk_boolean:
2945 (*anOutPort->Value()) >>= (CORBA::Any::to_boolean ) b;
2946 cdebug << ThreadNo() << " Out" << i << " : " << b << "(boolean)" << endl ;
2948 case CORBA::tk_char:
2950 (*anOutPort->Value()) >>= (CORBA::Any::to_char ) c;
2951 cdebug << ThreadNo() << " Out" << i << " : " << c << "(char)" << endl ;
2953 case CORBA::tk_short:
2955 (*anOutPort->Value()) >>= s;
2956 cdebug << ThreadNo() << " Out" << i << " : " << s << "(short)" << endl ;
2958 case CORBA::tk_long:
2960 (*anOutPort->Value()) >>= l;
2961 cdebug << ThreadNo() << " Out" << i << " : " << l << "(long)" << endl ;
2963 case CORBA::tk_float:
2965 (*anOutPort->Value()) >>= f;
2966 cdebug << ThreadNo() << " Out" << i << " : " << f << "(float)" << endl ;
2968 case CORBA::tk_double:
2970 (*anOutPort->Value()) >>= d;
2971 cdebug << ThreadNo() << " Out" << i << " : " << d << "(double)" << endl ;
2973 case CORBA::tk_objref:
2974 CORBA::Object_ptr obj ;
2977 (*anOutPort->Value()) >>= obj ;
2978 retstr = ObjectToString( obj );
2979 cdebug << ThreadNo() << " Out" << i << " : " << "ToString( object ) "
2983 cdebug << ThreadNo() << " Out" << i << " : " << "ToString( object ) "
2984 << "Catched ERROR" << endl ;
2988 cdebug << ThreadNo() << " Out" << i << " : " << "(other ERROR)" << endl ;
2994 if ( aGateOutPort && IsSwitchNode() ) {
2996 // cdebug << ThreadNo() << " " << "Out0 " << Name() << " Close of "
2997 // << aGateOutPort->PortName() << " " << aGateOutPort->Kind() ;
2999 OutParametersList[0].Value <<= l ;
3000 aGateOutPort->Value( OutParametersList[0].Value ) ;
3003 // cdebug << ThreadNo() << " " << "Out0 " << Name() << " Open of "
3004 // << aGateOutPort->PortName() << " " << aGateOutPort->Kind() ;
3006 OutParametersList[0].Value <<= l ;
3007 aGateOutPort->Value( OutParametersList[0].Value ) ;
3009 for ( i = 0 ; i < GetNodeOutPortsSize() ; i++ ) {
3010 GraphBase::InPort * anInPort ;
3011 anInPort = CoupledNode()->GetChangeInPort( GetNodeOutPort( i )->PortName() ) ;
3013 anInPort->ChangeOutPort( GetChangeNodeOutPort( i ) ) ;