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 "StreamGraph_Impl.hxx"
59 //#include "DataFlowExecutor_OutNode.hxx"
60 #include "DataFlowExecutor_DataFlow.hxx"
63 static void UpperCase(std::string& rstr)
65 #if defined __GNUC_2__
66 // _CS_gbo_040604 towupper n'existe pas. Utilisation de toupper. Par
67 // ailleurs, include explicite de cctype et algorithm pour toupper
68 // et transform respectivement.
69 std::transform(rstr.begin(), rstr.end(), rstr.begin(),toupper);
71 std::transform(rstr.begin(), rstr.end(), rstr.begin(),towupper);
76 int GraphExecutor::InNode::SendEvent( const GraphExecutor::NodeEvent anEvent ) {
78 _CurrentEvent = (GraphExecutor::NodeEvent ) anEvent ;
79 cdebug << pthread_self() << "/" << ThreadNo() << " -->SendEvent Node " << Name()
81 << Automaton()->ControlStateName( ControlState() )
82 << " Event : " << Automaton()->EventName( anEvent )
83 << " State : " << Automaton()->StateName( State() ) << " _RewindStack " << _RewindStack << endl;
86 _NextState = Automaton()->NextState( _OldState , anEvent ) ;
87 if ( _NextState == _OldState ) {
88 cdebug << pthread_self() << "/" << ThreadNo()
89 << " GraphExecutor::InNodeThreads::SendEvent SameStates "
90 << _OldState << endl ;
91 _NextAction = GraphExecutor::VoidAction ;
94 _NextAction = Automaton()->NextAction( _NextState , anEvent ) ;
97 // State( _NextState ) ;
98 // if ( _OldState == GraphExecutor::SuccessedExecutingState ||
99 // _OldState == GraphExecutor::ErroredExecutingState ) {
103 cdebug << pthread_self() << "/" << ThreadNo() << " SendedEvent Node "
104 << Name() << endl << " ControlState : "
105 << Automaton()->ControlStateName( ControlState() ) << endl
106 << " OldState : " << Automaton()->StateName( _OldState ) << endl
107 << " Event : " << Automaton()->EventName( anEvent ) << endl
108 << " NextState : " << Automaton()->StateName( _NextState ) << endl
109 << " Action : " << Automaton()->ActionName( _NextAction ) << endl
110 << " CreateNewThread " << CreateNewThread() << endl
111 << " _RewindStack " << _RewindStack << endl ;
114 //cout << pthread_self() << "/" << ThreadNo() << " SendedEvent Node " << Name()
115 << endl << " ControlState : "
116 << Automaton()->ControlStateName( ControlState() ) << endl
117 << " OldState : " << Automaton()->StateName( _OldState ) << endl
118 << " Event : " << Automaton()->EventName( anEvent ) << endl
119 << " NextState : " << Automaton()->StateName( _NextState ) << endl
120 << " Action : " << Automaton()->ActionName( _NextAction ) << endl
121 << " CreateNewThread " << CreateNewThread() << endl ;
124 int sts = executeAction() ;
126 cdebug << pthread_self() << "/" << ThreadNo() << " <--- SendEvent Node " << Name()
127 << " Event : " << Automaton()->EventName( anEvent )
128 << " State : " << Automaton()->StateName( State() )
135 // ReadyAction - RunningAction - DoneAction - SuspendedAction :
136 // for StateWait( ReadyW - RunningW - DoneW - SuspendedW )
137 void GraphExecutor::InNode::ReadyAction() {
138 if ( pthread_mutex_lock( &_MutexWait ) ) {
139 perror("Ready pthread_mutex_lock ") ;
142 cdebug << pthread_self() << "/" << ThreadNo()
143 << "ReadyAction pthread_cond_broadcast _ReadyWait "
145 if ( pthread_cond_broadcast( &_ReadyWait ) ) {
146 perror("Ready pthread_cond_broadcast ") ;
148 if ( pthread_mutex_unlock( &_MutexWait ) ) {
149 perror("Ready pthread_mutex_unlock ") ;
154 void GraphExecutor::InNode::RunningAction() {
155 if ( pthread_mutex_lock( &_MutexWait ) ) {
156 perror("Running pthread_mutex_lock ") ;
159 cdebug << pthread_self() << "/" << ThreadNo()
160 << "RunningAction pthread_cond_broadcast _RunningWait "
162 if ( pthread_cond_broadcast( &_RunningWait ) ) {
163 perror("Running pthread_cond_broadcast ") ;
165 if ( pthread_mutex_unlock( &_MutexWait ) ) {
166 perror("Running pthread_mutex_unlock ") ;
171 void GraphExecutor::InNode::DoneAction() {
172 if ( pthread_mutex_lock( &_MutexWait ) ) {
173 perror("Done pthread_mutex_lock ") ;
176 cdebug << pthread_self() << "/" << ThreadNo()
177 << "DoneAction pthread_cond_broadcast _DoneWait "
179 if ( pthread_cond_broadcast( &_DoneWait ) ) {
180 perror("Done pthread_cond_broadcast ") ;
182 if ( pthread_mutex_unlock( &_MutexWait ) ) {
183 perror("Done pthread_mutex_unlock ") ;
188 void GraphExecutor::InNode::SuspendedAction() {
189 if ( pthread_mutex_lock( &_MutexWait ) ) {
190 perror("Suspended pthread_mutex_lock ") ;
193 cdebug << pthread_self() << "/" << ThreadNo()
194 << "SuspendedAction pthread_cond_broadcast _SuspendedWait "
196 if ( pthread_cond_broadcast( &_SuspendedWait ) ) {
197 perror("Suspended pthread_cond_broadcast ") ;
199 if ( pthread_mutex_unlock( &_MutexWait ) ) {
200 perror("Suspended pthread_mutex_unlock ") ;
205 // SuspendAction <--> { ResumeAction - ReStartAction }
206 GraphExecutor::InNode * GraphExecutor::InNode::SuspendAction() {
208 if ( pthread_mutex_lock( &_MutexWait ) ) {
209 perror("Suspend pthread_mutex_lock ") ;
212 if ( !_SuspendSync ) {
213 cdebug << pthread_self() << "/" << ThreadNo() << " pthread_cond " << Name()
214 << " SuspendAction pthread_cond_wait _SuspendWait "
215 << Automaton()->StateName( State() ) << endl ;
216 _SuspendSync = true ;
217 _OutNode->SuspendThread() ;
218 if ( pthread_cond_wait( &_SuspendWait , &_MutexWait ) ) {
219 perror("SuspendAction pthread_cond_wait ") ;
221 _OutNode->ResumeThread() ;
222 cdebug << pthread_self() << "/" << ThreadNo() << " pthread_cond " << Name()
223 << " SuspendAction pthread_cond_waited"
224 << Automaton()->StateName( State() ) << endl ;
227 cdebug << pthread_self() << "/" << ThreadNo() << " pthread_cond " << Name()
228 << " NO SuspendAction pthread_cond_wait"
229 << Automaton()->StateName( State() ) << endl ;
231 // SendEvent( _aResumeEvent ) ; ===> Mutex with myself !
232 _SuspendSync = false ;
233 if ( ControlState() == SUPERV::ToSuspendStartState ||
234 ControlState() == SUPERV::ToSuspendState ) {
235 ControlState( SUPERV::VoidState ) ;
237 if ( pthread_mutex_unlock( &_MutexWait ) ) {
238 perror("SuspendAction pthread_mutex_unlock ") ;
242 SendEvent( _aResumeEvent ) ;
243 // if ( ControlState() == SUPERV::ToSuspendStartState ) {
244 // ControlState( SUPERV::VoidState ) ;
247 if ( pthread_mutex_lock( &_MutexWait ) ) {
248 perror("SuspendAction pthread_mutex_lock ") ;
252 cdebug << pthread_self() << "/" << ThreadNo() << " pthread_cond " << Name()
253 << " SuspendAction pthread_cond_signal _ResumeWait" << endl ;
254 if ( pthread_cond_signal( &_ResumeWait ) ) {
255 perror("SuspendAction pthread_cond_signal _ResumeWait ") ;
257 cdebug << pthread_self() << "/" << ThreadNo() << " pthread_cond " << Name()
258 << " SuspendAction pthread_cond_signaled _ResumeWait " << endl ;
261 cdebug << pthread_self() << "/" << ThreadNo() << " pthread_cond " << Name()
262 << " NO SuspendAction pthread_cond_signal _ResumeWait" << endl ;
265 if ( pthread_mutex_unlock( &_MutexWait ) ) {
266 perror("SuspendAction pthread_mutex_unlock ") ;
269 if ( _aReStartNode ) {
270 cdebug << Name() << " " << Automaton()->StateName( State() )
271 << "aReStartNode : " << _aReStartNode->Name() << " "
272 << Automaton()->StateName( _aReStartNode->State() ) << endl ;
273 _aReStartNode->SendEvent( _aResumeEvent ) ;
276 cdebug << "NO aReStartNode"
277 << Automaton()->StateName( State() ) << endl ;
279 return _aReStartNode ;
282 bool GraphExecutor::InNode::ResumeAction( GraphExecutor::NodeEvent aResumeEvent ) {
284 if ( pthread_mutex_lock( &_MutexWait ) ) {
285 perror("ResumeAction pthread_mutex_lock ") ;
288 _aResumeEvent = aResumeEvent ;
289 if ( _SuspendSync ) {
290 cdebug << pthread_self() << "/" << ThreadNo() << " pthread_cond " << Name()
291 << " ResumeAction pthread_cond_signal" << endl ;
292 if ( pthread_cond_signal( &_SuspendWait ) ) {
293 perror("ResumeAction pthread_cond_signal ") ;
295 cdebug << pthread_self() << "/" << ThreadNo() << " pthread_cond " << Name()
296 << " ResumeAction pthread_cond_signaled _SuspendWait " << endl ;
300 cdebug << pthread_self() << "/" << ThreadNo() << " pthread_cond " << Name()
301 << " NO ResumeAction pthread_cond_signal" << endl ;
302 if ( pthread_self() == ThreadNo() ) {
303 RetVal = false ; /*/ Ne pas s'attendre soi-meme !...*/
306 _SuspendSync = true ;
307 RetVal = true ; // Il faut tout de meme attendre ci-apres ...
310 if ( pthread_mutex_unlock( &_MutexWait ) ) {
311 perror("ResumeAction pthread_mutex_unlock ") ;
316 if ( pthread_mutex_lock( &_MutexWait ) ) {
317 perror("ResumeAction pthread_mutex_lock ") ;
320 if ( !_ResumeSync ) {
321 cdebug << pthread_self() << "/" << ThreadNo() << " pthread_cond "
322 << Name() << " ResumeAction pthread_cond_wait _ResumeWait "
323 << Automaton()->StateName( State() ) << endl ;
325 if ( pthread_cond_wait( &_ResumeWait , &_MutexWait ) ) {
326 perror("ResumeAction pthread_cond_wait ") ;
328 cdebug << pthread_self() << "/" << ThreadNo() << " pthread_cond "
329 << Name() << " ResumeAction pthread_cond_waited _ResumeWait"
330 << Automaton()->StateName( State() ) << endl ;
334 cdebug << pthread_self() << "/" << ThreadNo() << " pthread_cond "
335 << Name() << " NO ResumeAction pthread_cond_wait _ResumeWait"
336 << Automaton()->StateName( State() ) << endl ;
339 _ResumeSync = false ;
340 if ( pthread_mutex_unlock( &_MutexWait ) ) {
341 perror("ResumeAction pthread_mutex_unlock ") ;
345 cdebug << pthread_self() << "/" << ThreadNo()
346 << "GraphExecutor::InNodeThreads::ResumeAction RetVal " << RetVal << endl ;
350 bool GraphExecutor::InNode::ReStartAction( GraphExecutor::InNode * aReStartNode ,
351 GraphExecutor::NodeEvent anEvent ) {
352 GraphExecutor::InNode * oldReStartNode = _aReStartNode ;
353 _aReStartNode = aReStartNode ;
354 _aReStartEvent = anEvent ;
355 cdebug << pthread_self() << " GraphExecutor::InNodeThreads::ReStartAction from "
356 << Name() << " " << Automaton()->StateName( State() ) << " to "
357 << aReStartNode->ThreadNo() << " " << aReStartNode->Name() << " "
358 << Automaton()->StateName( aReStartNode->State() ) ;
359 if ( oldReStartNode ) {
360 cdebug << " oldReStartNode " << oldReStartNode->Name() << endl ;
365 return ResumeAction( GraphExecutor::ToReStartEvent ) ;
368 void GraphExecutor::InNode::KilledAction() {
369 if ( pthread_mutex_lock( &_MutexWait ) ) {
370 perror("Killed pthread_mutex_lock ") ;
374 cdebug << "pthread_cond " << Name() << " Killed pthread_cond_wait"
377 if ( pthread_cond_wait( &_KillWait , &_MutexWait ) ) {
378 perror("Killed pthread_cond_wait ") ;
380 cdebug << "pthread_cond " << Name() << " Killed pthread_cond_waited"
384 cdebug << "pthread_cond " << Name() << " NO Killed pthread_cond_wait"
388 if ( pthread_mutex_unlock( &_MutexWait ) ) {
389 perror("Killed pthread_mutex_unlock ") ;
394 void GraphExecutor::InNode::KillAction() {
395 if ( pthread_mutex_lock( &_MutexWait ) ) {
396 perror("Kill pthread_mutex_lock ") ;
400 cdebug << "pthread_cond " << Name() << " Kill pthread_cond_signal"
402 // if ( pthread_cond_broadcast( &_KillWait ) ) {
403 if ( pthread_cond_signal( &_KillWait ) ) {
404 perror("Kill pthread_cond_broadcast ") ;
406 cdebug << "pthread_cond " << Name() << " Kill pthread_cond_signaled"
410 cdebug << "pthread_cond " << Name() << " NO Kill pthread_cond_signal"
414 if ( pthread_mutex_unlock( &_MutexWait ) ) {
415 perror("Kill pthread_mutex_unlock ") ;
420 void GraphExecutor::InNode::StoppedAction() {
421 if ( pthread_mutex_lock( &_MutexWait ) ) {
422 perror("Stopped pthread_mutex_lock ") ;
425 if ( pthread_cond_wait( &_StopWait , &_MutexWait ) ) {
426 perror("Stopped pthread_cond_wait ") ;
428 if ( pthread_mutex_unlock( &_MutexWait ) ) {
429 perror("Stopped pthread_mutex_unlock ") ;
434 void GraphExecutor::InNode::StopAction() {
435 if ( pthread_mutex_lock( &_MutexWait ) ) {
436 perror("Stop pthread_mutex_lock ") ;
439 if ( pthread_cond_broadcast( &_StopWait ) ) {
440 perror("Stop pthread_cond_broadcast ") ;
442 if ( pthread_mutex_unlock( &_MutexWait ) ) {
443 perror("Stop pthread_mutex_unlock ") ;
448 void GraphExecutor::InNode::ThreadStartedAction() {
449 if ( pthread_mutex_lock( &_MutexWait ) ) {
450 perror("ThreadStarted pthread_mutex_lock ") ;
453 if ( !_ThreadStartedSync ) {
454 cdebug << "pthread_cond " << Name() << " ThreadStarted pthread_cond_wait"
456 _ThreadStartedSync = true ;
457 if ( pthread_cond_wait( &_ThreadStartedWait , &_MutexWait ) ) {
458 perror("ThreadStarted pthread_cond_wait ") ;
460 cdebug << "pthread_cond " << Name() << " ThreadStarted pthread_cond_waited"
464 cdebug << "pthread_cond " << Name() << " NO ThreadStarted pthread_cond_wait"
467 _ThreadStartedSync = false ;
468 if ( pthread_cond_signal( &_ThreadStartedWait ) ) {
469 perror("ThreadStart pthread_cond_signal ") ;
472 cdebug << "pthread_cond " << Name() << " NO ThreadStarted pthread_cond_signaled"
475 if ( pthread_mutex_unlock( &_MutexWait ) ) {
476 perror("ThreadStarted pthread_mutex_unlock ") ;
481 void GraphExecutor::InNode::ThreadStartAction() {
482 if ( pthread_mutex_lock( &_MutexWait ) ) {
483 perror("ThreadStart pthread_mutex_lock ") ;
486 if ( _ThreadStartedSync ) {
487 cdebug << "pthread_cond " << Name() << " ThreadStart pthread_cond_signal"
489 _ThreadStartedSync = false ;
490 if ( pthread_cond_signal( &_ThreadStartedWait ) ) {
491 perror("ThreadStart pthread_cond_broadcast ") ;
493 cdebug << "pthread_cond " << Name() << " ThreadStart pthread_cond_signaled"
497 cdebug << "pthread_cond " << Name() << " NO ThreadStart pthread_cond_signal"
499 _ThreadStartedSync = true ;
501 if ( pthread_cond_wait( &_ThreadStartedWait , &_MutexWait ) ) {
502 perror("ThreadStarted pthread_cond_wait ") ;
505 cdebug << "pthread_cond " << Name() << " NO ThreadStart pthread_cond_waited"
508 if ( pthread_mutex_unlock( &_MutexWait ) ) {
509 perror("ThreadStart pthread_mutex_unlock ") ;
514 int GraphExecutor::InNode::executeAction() {
515 int oldRewindStack = ( _RewindStack > MAXSTACKTHREADSIZE ) ;
516 if ( !CreateNewThread() && oldRewindStack ) {
517 cdebug << pthread_self() << "/" << ThreadNo()
518 << " executeAction start Thread _RewindStack " << _RewindStack << " > "
519 << MAXSTACKTHREADSIZE << " CreateNewThread "
520 << CreateNewThread() << " " << Automaton()->ActionName( _NextAction ) << "(" << Name() << ")"
522 CreateNewThread( true ) ;
525 if ( CreateNewThread() ) {
526 CreateNewThread( false ) ;
527 if ( ThreadNo() == 0 ) {
529 cdebug << pthread_self() << "/" << ThreadNo()
530 << " executeAction start Thread _RewindStack " << _RewindStack << " "
531 << Automaton()->ActionName( _NextAction ) << "(" << Name() << ")"
534 int pthread_sts = 1 ;
535 // _OutNode->PushEvent( NULL , GraphExecutor::NewThreadEvent ,
536 // GraphExecutor::ExecutingState ) ;
537 while ( (pthread_sts = pthread_create(&T, NULL, run_function, this )) ) {
538 char * msg = "Cannot pthread_create " ;
540 cdebug << ThreadNo() << " " << msg << " --> sleep(5)" << endl ;
541 cdebug << ThreadNo() << " PTHREAD_THREADS_MAX : "
542 << PTHREAD_THREADS_MAX << " pthread_create status : " ;
543 if ( pthread_sts == EAGAIN ) {
544 cdebug << "EAGAIN(" << pthread_sts << ")" << endl ;
545 cdebug << "It seems to me that with gdb we are limited to 256 threads because of defunct" << endl ;
548 cdebug << pthread_sts << endl ;
552 pthread_exit( msg ) ;
554 cdebug << pthread_self() << "/" << ThreadNo()
555 << "executeAction has created thread " << T << endl ;
556 ThreadStartedAction() ;
557 cdebug << pthread_self() << "/" << ThreadNo()
558 << "executeAction the thread " << T << " has called NewThread and will call ExecuteAction for node "
562 cdebug << pthread_self() << "/" << ThreadNo()
563 << " executeAction restart Thread _RewindStack " << _RewindStack << " "
564 << Automaton()->StateName( State() ) << " "
565 << Automaton()->ActionName( _NextAction ) << "(" << Name()
566 << ") ReStartAction ==>" << endl;
567 State( GraphExecutor::SuspendedSuccessedState ) ;
568 if ( !ReStartAction( this , GraphExecutor::ReStartEvent ) ) {
569 cdebug << pthread_self() << "/" << ThreadNo()
570 << " executeAction STATE & CALLED "
571 << Automaton()->ActionName( _NextAction ) << "(" << Name()
572 << ") ERROR-DEBUG " << endl;
575 cdebug << pthread_self() << "/" << ThreadNo() << " executeAction NO CALL "
576 << Automaton()->ActionName( _NextAction ) << "(" << Name()
582 if ( _CurrentEvent == ExecuteEvent ) {
585 cdebug << pthread_self() << "/" << ThreadNo() << " executeAction call "
586 << Automaton()->ActionName( _NextAction ) << "(" << Name() << ") _RewindStack " << _RewindStack
588 return ExecuteAction() ;
593 void GraphExecutor::InNode::coutbegin() {
594 cdebug << ThreadNo() << " " << pthread_self() << " run_function begin"
595 << " " << Name() << " " << Automaton()->StateName( State() ) << endl ;
597 void GraphExecutor::InNode::coutexit() {
598 cdebug << pthread_self() << "/" << ThreadNo() << " run_function pthread_exit _RewindStack " << _RewindStack
599 << " " << Name() << " " << Automaton()->StateName( State() ) << endl ;
601 void * run_function(void *p) {
602 GraphExecutor::InNode *aNode = (GraphExecutor::InNode *) p;
604 aNode->NewThread( pthread_self() ) ;
605 if ( pthread_setcanceltype( PTHREAD_CANCEL_ASYNCHRONOUS , NULL ) ) {
606 perror("pthread_setcanceltype ") ;
609 if ( pthread_setcancelstate( PTHREAD_CANCEL_ENABLE , NULL ) ) {
610 perror("pthread_setcancelstate ") ;
613 aNode->ThreadStartAction() ;
614 aNode->ExecuteAction() ;
615 char * msg = new char[40] ;
616 sprintf( msg , "%d" , (int ) aNode->ThreadNo() ) ;
617 strcat( msg , " thread exit" ) ;
619 aNode->ExitThread() ;
622 pthread_exit( (void * ) smsg.c_str() ) ;
626 int GraphExecutor::InNode::ExecuteAction() {
629 // const char * nextactionname = Automaton()->ActionName( _NextAction ) ;
630 // const char * statename = Automaton()->StateName( State() ) ;
631 // const char * nextstatename = Automaton()->StateName( _NextState ) ;
632 // cdebug << pthread_self() << "/" << ThreadNo() << " --> ExecuteAction "
633 // << nextactionname << " " << statename << " NextState "
634 // << nextstatename << endl ;
636 State( _NextState ) ;
637 switch ( _NextAction ) {
638 case GraphExecutor::ErrorAction : {
639 sts = ErrorAction() ;
642 case GraphExecutor::VoidAction : {
646 case GraphExecutor::DataWaiting_SomeDataReadyAction : {
647 sts = DataWaiting_SomeDataReadyAction() ;
650 case GraphExecutor::DataUndef_NotAllDataReadyAction : {
651 sts = DataUndef_NotAllDataReadyAction() ;
654 case GraphExecutor::DataUndef_AllDataReadyAction : {
655 sts = DataUndef_AllDataReadyAction() ;
658 case GraphExecutor::DataReady_SuspendAction : {
659 sts = DataReady_SuspendAction() ;
662 case GraphExecutor::SuspendedReady_ResumeAction : {
663 sts = SuspendedReady_ResumeAction() ;
666 case GraphExecutor::DataReady_KillAction : {
667 sts = DataReady_KillAction() ;
670 case GraphExecutor::DataReady_StopAction : {
671 sts = DataReady_StopAction() ;
674 case GraphExecutor::DataReady_ExecuteAction : {
675 sts = DataReady_ExecuteAction() ;
678 case GraphExecutor::Executing_SuspendAction : {
679 sts = Executing_SuspendAction() ;
682 case GraphExecutor::SuspendedExecuting_ResumeAction : {
683 sts = SuspendedExecuting_ResumeAction() ;
686 case GraphExecutor::Executing_KillAction : {
687 sts = Executing_KillAction() ;
690 case GraphExecutor::Executing_StopAction : {
691 sts = Executing_StopAction() ;
694 case GraphExecutor::Executing_SuccessAction : {
695 sts = Executing_SuccessAction() ;
698 case GraphExecutor::Executing_ErrorAction : {
699 sts = Executing_ErrorAction() ;
702 case GraphExecutor::Successed_SuccessAction : {
703 sts = Successed_SuccessAction() ;
706 case GraphExecutor::Errored_ErrorAction : {
707 sts = Errored_ErrorAction() ;
710 case GraphExecutor::Successed_SuspendAction : {
711 sts = Successed_SuspendAction() ;
714 case GraphExecutor::Errored_SuspendAction : {
715 sts = Errored_SuspendAction() ;
718 case GraphExecutor::SuspendedSuccessed_ResumeAction : {
719 sts = SuspendedSuccessed_ResumeAction() ;
722 case GraphExecutor::SuspendedErrored_ResumeAction : {
723 sts = SuspendedErrored_ResumeAction() ;
726 case GraphExecutor::Successed_KillAction : {
727 sts = Successed_KillAction() ;
730 case GraphExecutor::Errored_KillAction : {
731 sts = Errored_KillAction() ;
734 case GraphExecutor::Successed_StopAction : {
735 sts = Successed_StopAction() ;
738 case GraphExecutor::Errored_StopAction : {
739 sts = Errored_StopAction() ;
742 case GraphExecutor::SuspendedSuccessed_ReStartAction : {
743 sts = SuspendedSuccessed_ReStartAction() ;
746 case GraphExecutor::SuspendedErrored_ReStartAction : {
747 sts = SuspendedErrored_ReStartAction() ;
750 case GraphExecutor::SuspendedSuccessed_ReStartAndSuspendAction : {
751 sts = SuspendedSuccessed_ReStartAndSuspendAction() ;
754 case GraphExecutor::SuspendedErrored_ReStartAndSuspendAction : {
755 sts = SuspendedErrored_ReStartAndSuspendAction() ;
759 cdebug << pthread_self() << "/" << ThreadNo()
760 << " GraphExecutor::InNodeThreads::SendEvent Error Undefined Action : "
761 << _NextAction << endl ;
765 // cdebug << pthread_self() << "/" << ThreadNo() << "<-- ExecuteAction "
766 // << Automaton()->ActionName( nextaction ) << endl ;
770 int GraphExecutor::InNode::ErrorAction() {
771 cdebug << pthread_self() << "/" << ThreadNo() << " Automaton ErrorAction Node "
776 int GraphExecutor::InNode::VoidAction() {
777 cdebug << pthread_self() << "/" << ThreadNo() << " VoidAction " << Name() << endl;
782 int GraphExecutor::InNode::DataWaiting_SomeDataReadyAction() {
783 cdebug << pthread_self() << "/" << ThreadNo()
784 << " --> DataWaiting_SomeDataReadyAction from " << DataFromNode()
785 << " to " << Name() << endl;
789 bool LoopFinished = false ;
790 bool LoopBeginning = false ;
791 bool SwitchFinished = false ;
793 if ( IsEndLoopNode() && !GetChangeNodeInLoop()->GetOutPort()->BoolValue() ) {
794 LoopFinished = true ; // End of Loop
796 if ( IsLoopNode() && GetChangeNodeInLoop()->GetOutPort()->BoolValue() ) {
797 LoopBeginning = true ; // Beginning of Loop
799 if ( IsEndSwitchNode() && !GetChangeNodeInGate()->GetOutPort()->BoolValue() ) {
800 SwitchFinished = true ; // End of Switch
802 cdebug << pthread_self() << "/" << ThreadNo() << " " << Name() << " LoopFinished " << LoopFinished
803 << " LoopBeginning " << LoopBeginning << " SwitchFinished " << SwitchFinished << endl ;
804 for ( k = 0 ; k < (unsigned int ) GetNodeInPortsSize() ; k++ ) {
805 GraphBase::InPort * anInPort = GetChangeNodeInPort(k) ;
806 GraphBase::OutPort * anOutPort = anInPort->GetOutPort() ;
807 cdebug << pthread_self() << "/" << ThreadNo() << " " << Name() << " InPort " << anInPort->PortName() << endl ;
808 if ( anInPort->IsGate() && anOutPort == NULL ) {
810 anInPort->State( SUPERV::ReadyState ) ;
811 cdebug << pthread_self() << "/" << ThreadNo() << " " << Name() << " "
812 << anInPort->PortName() << " ControlPort inactive." << endl ;
814 // That InPort get its value from an other node
815 else if ( strcmp( DataFromNode() , anOutPort->NodeName() ) ) {
816 if ( anInPort->State() == SUPERV::ReadyState ) {
818 cdebug << pthread_self() << "/" << ThreadNo() << " " << Name() << " "
819 << anInPort->PortName() << " Was Done from "
820 << anOutPort->NodeName() << " " << anOutPort->PortName()
823 if ( GraphBase::Base::_prof_debug ) {
824 anOutPort->StringValue( *GraphBase::Base::_fdebug ) ;
829 else if ( IsLoopNode() && anInPort->IsDataConnected() ) {
830 anInPort->State( SUPERV::ReadyState ) ;
832 cdebug << pthread_self() << "/" << ThreadNo() << " " << Name() << " "
833 << anInPort->PortName() << " Was Done from "
834 << anOutPort->NodeName() << " " << anOutPort->PortName()
835 << " LoopBeginning " << LoopBeginning ;
837 if ( GraphBase::Base::_prof_debug ) {
838 anOutPort->StringValue( *GraphBase::Base::_fdebug ) ;
843 else if ( LoopFinished ) {
844 anInPort->State( SUPERV::ReadyState ) ;
846 cdebug << pthread_self() << "/" << ThreadNo() << " " << Name() << " "
847 << anInPort->PortName() << " Was Done from "
848 << anOutPort->NodeName() << " " << anOutPort->PortName()
851 if ( GraphBase::Base::_prof_debug ) {
852 anOutPort->StringValue( *GraphBase::Base::_fdebug ) ;
857 else if ( anInPort->IsGate() && SwitchFinished ) {
858 anInPort->State( SUPERV::ReadyState ) ;
860 cdebug << pthread_self() << "/" << ThreadNo() << " " << Name() << " "
861 << anInPort->PortName() << " Was Done from "
862 << anOutPort->NodeName() << " " << anOutPort->PortName()
863 << " SwitchFinished" ;
865 if ( GraphBase::Base::_prof_debug ) {
866 anOutPort->StringValue( *GraphBase::Base::_fdebug ) ;
872 cdebug << pthread_self() << "/" << ThreadNo() << " " << Name() << " "
873 << anInPort->PortName() << " Was NOT Done from "
874 << anOutPort->NodeName() << " " << anOutPort->PortName() << " "
875 << " " << Automaton()->StateName( State() ) << " DataConnected "
876 << anInPort->IsDataConnected() << " LoopBeginning "
877 << LoopBeginning << endl ;
880 // That InPort get its value from the sending node
881 else if ( anInPort->IsGate() ) {
882 const CORBA::Any * theValue = anOutPort->Value() ;
884 (*theValue) >>= GateOpened ;
885 if ( GateOpened != 0 ) {
887 anInPort->State( SUPERV::ReadyState ) ;
888 cdebug << pthread_self() << "/" << ThreadNo() << " " << Name() << " "
889 << anInPort->PortName() << " Gate is Opened from "
890 << anOutPort->NodeName() << " " << anOutPort->PortName()
893 if ( GraphBase::Base::_prof_debug ) {
894 anOutPort->StringValue( *GraphBase::Base::_fdebug ) ;
899 else if ( LoopFinished ) {
900 anInPort->State( SUPERV::ReadyState ) ;
901 cdebug << pthread_self() << "/" << ThreadNo() << " " << Name() << " "
902 << anInPort->PortName() << " GATE IS CLOSED from "
903 << anOutPort->NodeName() << " " << anOutPort->PortName()
906 if ( GraphBase::Base::_prof_debug ) {
907 anOutPort->StringValue( *GraphBase::Base::_fdebug ) ;
913 cdebug << pthread_self() << "/" << ThreadNo() << " " << Name() << " "
914 << anInPort->PortName() << " GATE IS CLOSED from "
915 << anOutPort->NodeName() << " " << anOutPort->PortName()
918 if ( GraphBase::Base::_prof_debug ) {
919 anOutPort->StringValue( *GraphBase::Base::_fdebug ) ;
925 else if ( anOutPort->Done() ) {
927 anInPort->State( SUPERV::ReadyState ) ;
928 cdebug << pthread_self() << "/" << ThreadNo() << " " << Name() << " "
929 << anInPort->PortName() << " " << anInPort->PortStatus() << " is Done from "
930 << anOutPort->NodeName() << " " << anOutPort->PortName() << " " << anOutPort->PortStatus() << " " ;
932 if ( GraphBase::Base::_prof_debug ) {
933 anOutPort->StringValue( *GraphBase::Base::_fdebug ) ;
937 // MacroNode : give immediately the value to the corresponding graph
938 if ( IsMacroNode() ) {
939 GraphExecutor::DataFlow * aMacroGraph = GraphMacroNode()->CoupledNode()->GraphExecutor() ;
940 cdebug << "SomeDataReadyAction MacroNode " << aMacroGraph->Graph()->Name() << " --> InputOfAny "
941 << InReady << "/" << GetNodeInPortsSize() << " InPorts are Ready" << endl ;
942 // GraphMacroNode()->MacroObject()->InputOfAny( anInPort->PortName() , *anOutPort->Value() ) ;
943 aMacroGraph->InputOfAny( anInPort->PortName() , *anOutPort->Value() ) ;
947 cdebug << pthread_self() << "/" << ThreadNo() << " " << Name() << " "
948 << anInPort->PortName() << " " << anInPort->PortStatus() << " is NOT Done from "
949 << anOutPort->NodeName() << " " << anOutPort->PortName() << " " << anOutPort->PortStatus() << " " ;
953 if ( InReady == GetNodeInPortsSize() ) { // All Flags != 0 :
954 res = SendEvent( GraphExecutor::AllDataReadyEvent ); // ==> Ready to execute
956 else { // At least one Flag == 0 :
957 res = SendEvent( GraphExecutor::NotAllDataReadyEvent );
960 cdebug << pthread_self() << "/" << ThreadNo()
961 << " <-- DataWaiting_SomeDataReadyAction " << Name() << endl;
966 int GraphExecutor::InNode::DataUndef_NotAllDataReadyAction() {
967 CreateNewThreadIf( false ) ;
968 // cdebug << pthread_self() << " for " << ThreadNo()
969 // << " DataUndef_NotAllDataReadyAction " << Name() << endl;
973 int GraphExecutor::InNode::DataUndef_AllDataReadyAction() {
974 // cdebug << pthread_self() << "/" << ThreadNo()
975 // << " --> DataUndef_AllDataReadyAction " << Name()
976 // << " CreateNewThreadIf " << CreateNewThreadIf() << " IsLockedDataWait "
977 // << IsLockedDataWait() ;
978 if ( IsLockedDataWait() ) {
979 cdebug << "DataUndef_AllDataReadyAction() WOULD DEAD-LOCK" << endl ;
980 return 0 ; // ==> DataUndef_AllDataReadyAction() after UnLockDataWait()
983 CreateNewThread( CreateNewThreadIf() ) ;
984 if ( !CreateNewThread() ) {
985 // cdebug << "Thread " << ThreadNo() << "-->" << pthread_self() << endl ;
986 ThreadNo( pthread_self() ) ;
988 _OutNode->PushEvent( this , GraphExecutor::AllDataReadyEvent ,
989 GraphExecutor::DataReadyState ) ;
991 SUPERV::ControlState aControl = ControlState() ;
992 switch ( aControl ) {
993 case SUPERV::VoidState : {
994 SendEvent( GraphExecutor::ExecuteEvent ) ;
997 case SUPERV::ToSuspendState : {
998 SendEvent( GraphExecutor::SuspendEvent ) ;
1001 case SUPERV::ToSuspendStartState : {
1002 SendEvent( GraphExecutor::SuspendEvent ) ;
1005 case SUPERV::ToSuspendDoneState : {
1006 SendEvent( GraphExecutor::ExecuteEvent ) ;
1009 case SUPERV::ToKillState : {
1010 SendEvent( GraphExecutor::KillEvent ) ;
1013 case SUPERV::ToKillDoneState : {
1014 SendEvent( GraphExecutor::ExecuteEvent ) ;
1017 case SUPERV::ToStopState : {
1018 SendEvent( GraphExecutor::StopEvent ) ;
1022 cdebug << ThreadNo()
1023 << " GraphExecutor::InNodeThreads::DataUndef_AllDataReadyAction Error Undefined Control : "
1024 << aControl << endl ;
1028 // cdebug << pthread_self() << "/" << ThreadNo()
1029 // << " <-- DataUndef_AllDataReadyAction " << Name() << endl;
1033 int GraphExecutor::InNode::DataReady_SuspendAction() {
1034 cdebug << pthread_self() << "/" << ThreadNo()
1035 << "DataReady_SuspendAction --> Suspend " << Name()
1036 << " Threads " << _OutNode->Threads() << " SuspendedThreads "
1037 << _OutNode->SuspendedThreads() << endl;
1038 _OutNode->PushEvent( this , GraphExecutor::SuspendedReadyEvent ,
1039 GraphExecutor::SuspendedReadyState ) ;
1040 GraphExecutor::InNode * aReStartNode = SuspendAction() ;
1041 cdebug << pthread_self() << "/" << ThreadNo()
1042 << "DataReady_SuspendAction Resumed " << Name() << endl;
1043 if ( aReStartNode ) {
1044 _aReStartNode = NULL ;
1045 aReStartNode->SendEvent( _aReStartEvent ) ;
1048 SendEvent( GraphExecutor::ExecuteEvent ) ;
1053 int GraphExecutor::InNode::SuspendedReady_ResumeAction() {
1054 cdebug << pthread_self() << "/" << ThreadNo() << "SuspendedReady_ResumeAction "
1057 _OutNode->PushEvent( this , GraphExecutor::ResumedReadyEvent ,
1058 GraphExecutor::ResumedReadyState ) ;
1062 int GraphExecutor::InNode::DataReady_KillAction() {
1063 _OutNode->PushEvent( this , GraphExecutor::KilledReadyEvent ,
1064 GraphExecutor::KilledReadyState ) ;
1066 cdebug << pthread_self() << "/" << ThreadNo() << "DataReady_KillAction " << Name()
1067 << " will pthread_exit()" << endl;
1071 int GraphExecutor::InNode::DataReady_StopAction() {
1072 _OutNode->PushEvent( this , GraphExecutor::StoppedReadyEvent ,
1073 GraphExecutor::StoppedReadyState ) ;
1075 cdebug << pthread_self() << "/" << ThreadNo() << "DataReady_StopAction " << Name()
1076 << " will pthread_exit()" << endl;
1082 int GraphExecutor::InNode::DataReady_ExecuteAction() {
1085 // cdebug << pthread_self() << "/" << ThreadNo() << " --> DataReady_ExecuteAction "
1086 // << Name() << endl;
1087 _OutNode->PushEvent( this , GraphExecutor::ExecuteEvent ,
1088 GraphExecutor::ExecutingState ) ;
1094 SUPERV::GraphState PortState = SUPERV::ReadyState ;
1095 GraphExecutor::AutomatonState NewState = GraphExecutor::DataUndefState ;
1096 GraphExecutor::NodeEvent NewEvent = GraphExecutor::UndefinedEvent ;
1099 ServicesAnyData * InParametersList ;
1101 ServicesAnyData * OutParametersList ;
1103 nInParams = GetNodeInPortsSize() ;
1104 InParametersList = new ServicesAnyData[nInParams];
1105 InParametersSet( Err , nInParams , InParametersList ) ;
1107 nOutParams = GetNodeOutPortsSize() ;
1108 OutParametersList = new ServicesAnyData[nOutParams];
1109 InOutParametersSet( nOutParams , OutParametersList ) ;
1111 if ( !IsMacroNode() ) {
1113 Engines::Container_var myContainer ;
1114 Engines::Component_var myObjComponent ;
1115 if ( !IsFactoryNode() ) {
1116 // cdebug << ThreadNo() << "No Component : NO StartComponent & No Ping" << endl ;
1117 if ( IsComputingNode() ) {
1118 ObjInterface( true ) ;
1119 CORBA::Object_ptr obj ;
1120 InParametersList[0].Value >>= obj ;
1121 CORBA::Object_var objvar = CORBA::Object_var( obj ) ;
1122 myObjComponent = Engines::Component::_narrow( objvar ) ;
1127 else if ( CORBA::is_nil( Component() ) ) {
1128 // ostringstream astr ;
1129 // astr << "Graph " << _OutNode->Graph()->Name() << " Node " << Name()
1130 // << " : load of component " << ComponentName() << " in container "
1132 // _OutNode->Graph()->ObjImpl()->sendMessage( NOTIF_STEP, astr.str().c_str() ) ;
1133 Err = !_OutNode->Graph()->StartComponent( ThreadNo() , Computer() ,
1134 my_strdup( ComponentName() ) ,
1135 myContainer , myObjComponent ) ;
1136 ObjInterface( false ) ;
1137 SetContainer( myContainer ) ;
1138 SetComponent( myObjComponent ) ;
1141 myContainer = Container() ;
1142 myObjComponent = Component() ;
1143 // cdebug << ThreadNo() << "Component known : NO StartComponent & Ping"
1146 myObjComponent->ping() ;
1149 cdebug << "ping() catched" << endl ;
1154 if ( Err || ControlState() == SUPERV::ToKillState ||
1155 ControlState() == SUPERV::ToKillDoneState ||
1156 ControlState() == SUPERV::ToStopState ) {
1157 cdebug << ThreadNo() << "StartComponent Error or ToKillState" << endl ;
1162 // ostringstream astr ;
1163 // astr << "Graph " << _OutNode->Graph()->Name() << " Run of Node " << Name() ;
1164 // _OutNode->Graph()->ObjImpl()->sendMessage( NOTIF_STEP, astr.str().c_str() ) ;
1165 cdebug << ThreadNo() << " Run( '" << ServiceName() << "'" ;
1166 for ( i = 0 ; i < (int ) ServiceInParameter().length() ; i++ ) {
1167 cdebug << " , " << InParametersList[ i ].Name << "[kind"
1168 << InParametersList[ i ].Value.type()->kind() << "]" ;
1170 for ( i = 0 ; i < (int ) ServiceOutParameter().length() ; i++ ) {
1171 cdebug << " , " << OutParametersList[ i ].Name << "[kind"
1172 << OutParametersList[ i ].Value.type()->kind() << "]" ;
1174 if ( IsOneOfInLineNodes() ) {
1175 cdebug << " , PyFuncName '" << InLineNode()->PyFuncName() << "' PyRunMethod "
1176 << InLineNode()->PyRunMethod() << " length " << (*InLineNode()->PythonFunction()).length() ;
1178 cdebug << ")" << endl ;
1180 if ( IsOneOfInLineNodes() ) {
1181 bool StsPyDynInvoke = true;
1182 _OutNode->PyThreadLock() ;
1185 // if ( IsInLineNode() && (*InLineNode()->PythonFunction()).length() &&
1186 bool CopyInOut = false ;
1187 if ( IsInLineNode() && /*InLineNode()->PyRunMethod() &&*/
1188 strlen( InLineNode()->PyFuncName() ) ) {
1189 // cdebug << ThreadNo() << " !ObjInterface " << Name() << " PyFuncName '"
1190 // << InLineNode()->PyFuncName()
1191 // << "' IsInLineNode PyDynInvoke" << endl ;
1192 StsPyDynInvoke = PyDynInvoke( InLineNode()->PyRunMethod() ,
1193 InLineNode()->PyFuncName() ,
1194 &InParametersList[0] , ServiceInParameter().length() ,
1195 &OutParametersList[0] , ServiceOutParameter().length() ) ;
1197 else if ( IsLoopNode() ) {
1198 bool CopyOutIn = false ;
1199 if ( GetNodeInLoop()->GetOutPort()->BoolValue() && /*InLineNode()->PyRunMethod() &&*/
1200 strlen( InLineNode()->PyFuncName() ) ) { // InLoop Port
1201 // cdebug << ThreadNo() << " !ObjInterface " << Name()
1202 // << " IsLoopNode PyDynInvoke '" << InLineNode()->PyFuncName()
1204 StsPyDynInvoke = PyDynInvoke( InLineNode()->PyRunMethod() ,
1205 InLineNode()->PyFuncName() ,
1206 &InParametersList[1] , ServiceInParameter().length() ,
1207 &OutParametersList[1] , ServiceOutParameter().length() ) ;
1210 else if ( LoopNode()->PyNextMethod() &&
1211 strlen( LoopNode()->PyNextName() ) ){
1212 // cdebug << ThreadNo() << " !ObjInterface " << Name()
1213 // << " IsLoopNode PyDynInvoke '" << LoopNode()->PyNextName()
1215 StsPyDynInvoke = PyDynInvoke( LoopNode()->PyNextMethod() ,
1216 LoopNode()->PyNextName() ,
1217 &InParametersList[1] , ServiceInParameter().length() ,
1218 &OutParametersList[1] , ServiceOutParameter().length() ) ;
1221 if ( StsPyDynInvoke && CopyOutIn ) {
1222 // cdebug << ThreadNo() << " !ObjInterface " << Name()
1223 // << " IsLoopNode PyDynInvoke '" << LoopNode()->PyMoreName()
1224 // << "' Copy of " << ServiceInParameter().length()
1225 // << " OutParameters" << endl ;
1227 for ( i = 1 ; i <= (int ) ServiceInParameter().length() ; i++ ) {
1228 InParametersList[i].Value = OutParametersList[i].Value ;
1229 InParametersList[i].Name = OutParametersList[i].Name ;
1231 switch ( InParametersList[i].Value.type()->kind() ) {
1232 case CORBA::tk_string :
1234 InParametersList[i].Value >>= t ;
1235 cdebug << "ArgOut->In" << i << " : "
1236 << InParametersList[i].Name.c_str()
1237 << " Value(string) " << t << endl ;
1239 case CORBA::tk_double :
1241 InParametersList[i].Value >>= d;
1242 cdebug << "ArgOut->In" << i << " : "
1243 << InParametersList[i].Name.c_str()
1244 << " Value(double) " << d << endl ;
1246 case CORBA::tk_long :
1248 InParametersList[i].Value >>= l;
1249 cdebug << "ArgOut->In" << i << " : "
1250 << InParametersList[i].Name.c_str()
1251 << " Value(long) " << l << endl ;
1253 case CORBA::tk_objref :
1254 CORBA::Object_ptr obj ;
1257 InParametersList[i].Value >>= obj ;
1258 retstr = ObjectToString( obj );
1259 cdebug << "ArgOut->In" << i << " : "
1260 << InParametersList[i].Name.c_str()
1261 << " Value(object reference) " << retstr << endl ;
1264 cdebug << "ArgOut->In" << i << " : "
1265 << InParametersList[i].Name.c_str()
1266 << " Value(object reference) Catched ERROR" << endl ;
1270 cdebug << "ArgOut->In" << i << " : "
1271 << InParametersList[i].Name.c_str()
1272 << " Value(other) ERROR" << endl ;
1276 if ( LoopNode()->PyMoreMethod() && strlen( LoopNode()->PyMoreName() ) ) {
1277 StsPyDynInvoke = PyDynInvoke( LoopNode()->PyMoreMethod() ,
1278 LoopNode()->PyMoreName() ,
1279 &InParametersList[1] , ServiceInParameter().length() ,
1280 &OutParametersList[0] , ServiceOutParameter().length()+1 ) ;
1286 else if ( !StsPyDynInvoke ) {
1288 cdebug << ThreadNo() << " InLineNode " << Name() << " "
1289 << InLineNode()->PyFuncName() << "/" << LoopNode()->PyNextName()
1290 << " Python Dynamic Call Error"
1294 else if ( IsSwitchNode() && /*InLineNode()->PyRunMethod() &&*/
1295 strlen( InLineNode()->PyFuncName() ) ) {
1296 // cdebug << ThreadNo() << " !ObjInterface " << Name() << " PyFuncName '"
1297 // << InLineNode()->PyFuncName()
1298 // << "' IsSwitchNode PyDynInvoke" << endl ;
1299 StsPyDynInvoke = PyDynInvoke( InLineNode()->PyRunMethod() ,
1300 InLineNode()->PyFuncName() ,
1301 &InParametersList[0] , ServiceInParameter().length() ,
1302 &OutParametersList[0] , ServiceOutParameter().length() ) ;
1304 // else if ( IsGOTONode() && (*GOTONode()->PythonFunction()).length() &&
1305 else if ( IsGOTONode() && /*InLineNode()->PyRunMethod() &&*/
1306 strlen( InLineNode()->PyFuncName() ) ) {
1307 // cdebug << ThreadNo() << " !ObjInterface " << Name() << " PyFuncName '"
1308 // << InLineNode()->PyFuncName()
1309 // << "' IsGOTONode PyDynInvoke" << endl ;
1310 StsPyDynInvoke = PyDynInvoke( InLineNode()->PyRunMethod() ,
1311 InLineNode()->PyFuncName() ,
1312 &InParametersList[0] , ServiceInParameter().length() ,
1313 &OutParametersList[0] , ServiceOutParameter().length() ) ;
1315 // else if ( IsEndSwitchNode() && (*InLineNode()->PythonFunction()).length() &&
1316 else if ( ( IsEndSwitchNode() ) &&
1317 InLineNode()->PyRunMethod() && strlen( InLineNode()->PyFuncName() ) ) {
1318 // cdebug << ThreadNo() << " !ObjInterface " << Name() << " PyFuncName '"
1319 // << InLineNode()->PyFuncName()
1320 // << "' IsSwitchNode PyDynInvoke" << endl ;
1321 StsPyDynInvoke = PyDynInvoke( InLineNode()->PyRunMethod() ,
1322 InLineNode()->PyFuncName() ,
1323 &InParametersList[0] , ServiceInParameter().length() ,
1324 &OutParametersList[0] , ServiceOutParameter().length() ) ;
1326 else if ( ( IsEndLoopNode() ) &&
1327 InLineNode()->PyRunMethod() && strlen( InLineNode()->PyFuncName() ) ) {
1328 // cdebug << ThreadNo() << " !ObjInterface " << Name() << " PyFuncName '"
1329 // << InLineNode()->PyFuncName()
1330 // << "' IsSwitchNode PyDynInvoke" << endl ;
1331 StsPyDynInvoke = PyDynInvoke( InLineNode()->PyRunMethod() ,
1332 InLineNode()->PyFuncName() ,
1333 &InParametersList[0] , ServiceInParameter().length() + 1 ,
1334 &OutParametersList[0] , ServiceOutParameter().length() + 1 ) ;
1336 // else if ( (*InLineNode()->PythonFunction()).length() == 0 ||
1337 if ( InLineNode()->PyRunMethod() == NULL ||
1338 strlen( InLineNode()->PyFuncName() ) == 0 || CopyInOut ) {
1339 // cdebug << ThreadNo() << " !ObjInterface " << Name()
1340 // << " Copy of " << ServiceInParameter().length()
1341 // << " OutParameters" << endl ;
1345 if ( IsLoopNode() || IsEndLoopNode() ) {
1347 argin0 = 1 ; // after DoLoop
1348 if ( IsLoopNode() ) {
1349 OutParametersList[0].Value = InParametersList[0].Value ; // DoLoop
1352 for ( i = 0 ; i < (int ) ServiceInParameter().length() ; i++ ) {
1353 OutParametersList[argout0 + i].Value = InParametersList[argin0 + i].Value ;
1355 switch ( InParametersList[argin0 + i].Value.type()->kind() ) {
1356 case CORBA::tk_string :
1357 cdebug << "ArgOut->In" << argin0 + i << " : "
1358 << InParametersList[argin0 + i].Name.c_str()
1359 << " Value(string) "
1360 << OutParametersList[argout0 + i].Name.c_str() << endl ;
1362 case CORBA::tk_double :
1363 cdebug << "ArgOut->In" << argin0 + i << " : "
1364 << InParametersList[argin0 + i].Name.c_str()
1365 << " Value(double) "
1366 << OutParametersList[argout0 + i].Name.c_str() << endl ;
1368 case CORBA::tk_long :
1369 cdebug << "ArgOut->In" << argin0 + i << " : "
1370 << InParametersList[argin0 + i].Name.c_str()
1372 << OutParametersList[argout0 + i ].Name.c_str() << endl ;
1374 case CORBA::tk_objref :
1375 cdebug << "ArgOut->In" << argin0 + i << " : "
1376 << InParametersList[argin0 + i].Name.c_str()
1377 << " Value(object reference) "
1378 << OutParametersList[argout0 + i].Name.c_str() << endl ;
1381 cdebug << "ArgOut->In" << argin0 + i << " : "
1382 << InParametersList[argin0 + i].Name.c_str()
1383 << " Value(other) ERROR "
1384 << OutParametersList[argout0 + i].Name.c_str() << endl ;
1389 if ( !StsPyDynInvoke ) {
1391 cdebug << ThreadNo() << " InLineNode " << Name()
1392 << " Python Dynamic Call Error"
1398 cdebug << ThreadNo() << " InLineNode " << Name()
1399 << " Python Dynamic Call Exception catched ERROR"
1403 _OutNode->PyThreadUnLock() ;
1408 cdebug << "DynInvoke -> Names " << _OutNode->Graph()->Name() << " " << Name() << endl ;
1409 DynInvoke( myObjComponent, "Names" ,
1410 _OutNode->Graph()->Name() , Name() ) ;
1413 cdebug << "DynInvoke Names catched ERROR" << endl ;
1415 // for DataStreamNodes : call of SetProperties ===> environment variables in the component/container
1416 if ( ComputingNode()->HasDataStream() ) {
1418 cdebug << "DynInvoke -> SetProperties " << _OutNode->Graph()->Name() << " " << Name() << endl ;
1419 Engines::FieldsDict_var dict = new Engines::FieldsDict;
1421 dict[ 0 ].key = CORBA::string_dup( "CAL_MACHINE");
1422 // myContainer->getHostName() ne renvoit pas le nom complet (avec domaine).
1423 // dict[ 0 ].value <<= myContainer->getHostName() ;
1424 char FullyQualifiedDomainName[256]="";
1425 gethostname(FullyQualifiedDomainName,255);
1426 dict[ 0 ].value <<= FullyQualifiedDomainName ;
1427 dict[ 1 ].key = CORBA::string_dup( "CAL_REPERTOIRE");
1428 dict[ 1 ].value <<= "/tmp" ;
1429 dict[ 2 ].key = CORBA::string_dup( "CAL_COUPLAGE");
1430 stringstream ofst1 ;
1431 ofst1 << ComputingNode()->SubStreamGraph() ;
1432 string cpl = string( "/tmp/" ) + string( _OutNode->Graph()->Name() ) + string( "_" ) +
1433 ofst1.str() + string( ".cpl" );
1434 dict[ 2 ].value <<= cpl.c_str() ;
1435 dict[ 3 ].key = CORBA::string_dup( "SALOME_INSTANCE_NAME");
1436 string uname = Name();
1438 dict[ 3 ].value <<= uname.c_str() ;
1440 myObjComponent->setProperties( dict ) ;
1443 cdebug << "DynInvoke setProperties catched ERROR" << endl ;
1447 if ( !Err && IsComputingNode() ) {
1448 cdebug << ThreadNo() << " !ObjInterface " << Name()
1449 << " IsComputingNode DynInvoke" << endl ;
1450 cdebug << ServiceInParameter().length()-1 << " input parameters and "
1451 << ServiceOutParameter().length() << " output parameters" << endl ;
1452 DynInvoke( myObjComponent,
1454 &InParametersList[1] , ServiceInParameter().length()-1 ,
1455 &OutParametersList[0] , ServiceOutParameter().length() ) ;
1457 else if ( !Err &&IsFactoryNode() ) {
1458 cdebug << ThreadNo() << " !ObjInterface " << Name()
1459 << " IsFactoryNode DynInvoke" << endl ;
1460 cdebug << ServiceInParameter().length() << " input parameters and "
1461 << ServiceOutParameter().length() << " output parameters" << endl ;
1462 DynInvoke( myObjComponent,
1464 &InParametersList[0] , ServiceInParameter().length() ,
1465 &OutParametersList[0] , ServiceOutParameter().length() ) ;
1467 // cdebug << ThreadNo() << " Component::CpuUsed " << Name() << " "
1468 // << myObjComponent->CpuUsed_impl() << endl ;
1472 cdebug << ThreadNo() << " !ObjInterface " << Name()
1473 << " Node(Component) Dynamic Call Exception catched ERROR"
1484 // ostringstream astr ;
1485 // astr << "Graph " << _OutNode->Graph()->Name() << " Node " << Name() << " is done : "
1486 // << Automaton()->StateName( State() ) ;
1487 // _OutNode->Graph()->ObjImpl()->sendMessage( NOTIF_STEP, astr.str().c_str() ) ;
1489 if ( ControlState() == SUPERV::ToKillState ||
1490 ControlState() == SUPERV::ToKillDoneState ||
1491 ControlState() == SUPERV::ToStopState ) {
1492 PortState = SUPERV::ErrorState ;
1493 NewState = GraphExecutor::KilledState ;
1494 NewEvent = GraphExecutor::KillEvent ;
1497 PortState = SUPERV::ErrorState ;
1498 NewState = GraphExecutor::ErroredState ;
1499 NewEvent = GraphExecutor::ErrorEvent ;
1503 PortState = SUPERV::ReadyState ;
1504 NewState = GraphExecutor::DataReadyState ;
1505 NewEvent = GraphExecutor::SuccessEvent ;
1508 if ( !IsMacroNode() ) {
1509 bool ErrOut = OutParametersSet( Err , PortState , nOutParams , OutParametersList ) ;
1511 NewEvent = GraphExecutor::ErrorEvent ;
1513 delete [] InParametersList ;
1514 delete [] OutParametersList ;
1517 if ( !IsMacroNode() ) {
1518 SendEvent( NewEvent ) ;
1521 GraphExecutor::DataFlow * aMacroGraph = GraphMacroNode()->CoupledNode()->GraphExecutor() ;
1522 cdebug << ThreadNo() << " DataReady_ExecuteAction " << aMacroGraph->Graph()->Name() << " ->DoneWait()"
1523 << " State " << aMacroGraph->State() << endl;
1524 aMacroGraph->DoneWait() ;
1525 cdebug << ThreadNo() << " DataReady_ExecuteAction " << Name() << " State " << aMacroGraph->State() << endl;
1526 if ( aMacroGraph->State() == SUPERV::DoneState ) {
1527 PortState = SUPERV::ReadyState ;
1528 NewState = GraphExecutor::DataReadyState ;
1529 NewEvent = GraphExecutor::SuccessEvent ;
1533 if ( ControlState() == SUPERV::ToKillState ||
1534 ControlState() == SUPERV::ToKillDoneState ||
1535 ControlState() == SUPERV::ToStopState ) {
1536 PortState = SUPERV::ErrorState ;
1537 NewState = GraphExecutor::KilledState ;
1538 NewEvent = GraphExecutor::KillEvent ;
1541 PortState = SUPERV::ErrorState ;
1542 NewState = GraphExecutor::ErroredState ;
1543 NewEvent = GraphExecutor::ErrorEvent ;
1546 bool ErrOut = OutParametersSet( Err , PortState , nOutParams , OutParametersList ) ;
1548 NewEvent = GraphExecutor::ErrorEvent ;
1550 delete [] InParametersList ;
1551 delete [] OutParametersList ;
1552 SendEvent( NewEvent ) ;
1555 // cdebug << ThreadNo() << " <-- DataReady_ExecuteAction " << Name() << endl;
1559 int GraphExecutor::InNode::Executing_SuspendAction() {
1560 _OutNode->PushEvent( this , GraphExecutor::SuspendedExecutingEvent ,
1561 GraphExecutor::SuspendedExecutingState ) ;
1562 cdebug << ThreadNo() << " Executing_SuspendAction " << Name() << endl;
1566 int GraphExecutor::InNode::SuspendedExecuting_ResumeAction() {
1567 cdebug << ThreadNo() << " SuspendedExecuting_ResumeAction " << Name() << endl;
1568 GraphExecutor::AutomatonState next_state ;
1569 next_state = Automaton()->NextState( State() , GraphExecutor::ExecutingEvent ) ;
1570 _OutNode->NewThread() ; // Only for Threads count
1571 _OutNode->PushEvent( this , GraphExecutor::ResumedExecutingEvent ,
1573 State( next_state ) ;
1577 int GraphExecutor::InNode::Executing_KillAction() {
1578 cdebug << ThreadNo() << " Executing_KillAction " << Name() << endl;
1580 if ( pthread_self() == ThreadNo() ) {
1581 cdebug << "Executing_KillAction would pthread_canceled itself" << endl ;
1583 _OutNode->PushEvent( this , GraphExecutor::KilledExecutingEvent ,
1584 GraphExecutor::KilledExecutingState ) ;
1587 else if ( pthread_cancel( ThreadNo() ) ) {
1588 perror("Executing_KillAction pthread_cancel error") ;
1591 cdebug << "Executing_KillAction : ThreadId " << ThreadNo()
1592 << " pthread_canceled" << endl ;
1594 _OutNode->ExitThread() ;
1595 _OutNode->PushEvent( this , GraphExecutor::KilledExecutingEvent ,
1596 GraphExecutor::KilledExecutingState ) ;
1601 int GraphExecutor::InNode::Executing_StopAction() {
1602 cdebug << ThreadNo() << " Executing_StopAction " << Name() << endl;
1604 if ( pthread_cancel( ThreadNo() ) ) {
1605 perror("Executing_KillAction pthread_cancel error") ;
1608 cdebug << "Executing_KillAction : ThreadId " << ThreadNo()
1609 << " pthread_canceled" << endl ;
1611 _OutNode->ExitThread() ;
1612 _OutNode->PushEvent( this , GraphExecutor::StoppedExecutingEvent ,
1613 GraphExecutor::StoppedExecutingState ) ;
1618 int GraphExecutor::InNode::Executing_SuccessAction() {
1619 // cdebug << ThreadNo() << " --> Executing_SuccessAction " << Name() << endl;
1620 _OutNode->PushEvent( this , GraphExecutor::SuccessedExecutingEvent ,
1621 GraphExecutor::SuccessedState ) ;
1622 SUPERV::ControlState aControl = ControlState() ;
1623 switch ( aControl ) {
1624 case SUPERV::VoidState : {
1625 SendEvent( SuccessEvent ) ;
1628 case SUPERV::ToSuspendState : {
1629 SendEvent( SuccessEvent ) ;
1632 case SUPERV::ToSuspendDoneState : {
1633 SendEvent( GraphExecutor::SuspendEvent ) ;
1636 case SUPERV::ToKillState : {
1637 SendEvent( GraphExecutor::KillEvent ) ;
1640 case SUPERV::ToKillDoneState : {
1641 SendEvent( GraphExecutor::KillEvent ) ;
1644 case SUPERV::ToStopState : {
1645 SendEvent( GraphExecutor::StopEvent ) ;
1649 cdebug << ThreadNo()
1650 << " GraphExecutor::InNodeThreads::Executing_SuccessAction Error Undefined Control : "
1651 << aControl << endl ;
1655 // cdebug << ThreadNo() << " <-- Executing_SuccessAction " << Name() << endl;
1659 int GraphExecutor::InNode::Executing_ErrorAction() {
1660 cdebug << ThreadNo() << " --> Executing_ErrorAction " << Name() << endl;
1661 _OutNode->PushEvent( this , GraphExecutor::ErroredExecutingEvent ,
1662 GraphExecutor::ErroredState ) ;
1664 SUPERV::ControlState aControl = ControlState() ;
1665 switch ( aControl ) {
1666 case SUPERV::VoidState : {
1667 SendEvent( ErrorEvent ) ;
1670 case SUPERV::ToSuspendState : {
1671 SendEvent( ErrorEvent ) ;
1674 case SUPERV::ToSuspendDoneState : {
1675 SendEvent( GraphExecutor::SuspendEvent ) ;
1678 case SUPERV::ToKillState : {
1679 SendEvent( GraphExecutor::KillEvent ) ;
1682 case SUPERV::ToKillDoneState : {
1683 SendEvent( GraphExecutor::KillEvent ) ;
1686 case SUPERV::ToStopState : {
1687 SendEvent( GraphExecutor::StopEvent ) ;
1691 cdebug << ThreadNo()
1692 << " GraphExecutor::InNodeThreads::Executing_ErrorAction Error Undefined Control : "
1693 << aControl << endl ;
1697 cdebug << ThreadNo() << " <-- Executing_ErrorAction " << Name() << endl;
1701 // Set SUPERV::WaitingState to all InPorts
1702 void GraphExecutor::InNode::SetWaitingStates(GraphExecutor::InNode * EndNode ) {
1705 bool docdebug = false ;
1706 State( GraphExecutor::DataWaitingState ) ;
1707 for ( i = 0 ; i < GetNodeInPortsSize() ; i++ ) {
1708 GraphBase::InPort * anInPort = GetChangeNodeInPort( i ) ;
1709 if ( anInPort->IsGate() ) { // Loop : Open the doors
1710 GraphBase::OutPort * anOutPort = anInPort->GetOutPort() ;
1712 CORBA::Any * anAny = new CORBA::Any() ;
1713 *anAny <<= (long ) 1 ;
1714 anOutPort->Value( anAny ) ;
1715 anInPort->State( SUPERV::ReadyState ) ;
1718 else if ( anInPort->State() != SUPERV::WaitingState ) {
1720 cdebug << ThreadNo()
1721 << " --> GraphExecutor::InNodeThreads::SetWaitingStates " << Name() << endl;
1724 if ( !anInPort->IsDataStream() ) {
1725 anInPort->State( SUPERV::WaitingState ) ;
1729 for ( i = 0 ; i < GetNodeOutPortsSize() ; i++ ) {
1730 GraphBase::OutPort * anOutPort = GetChangeNodeOutPort( i ) ;
1731 for ( j = 0 ; j < anOutPort->InPortsSize() ; j++ ) {
1732 if ( !( IsGOTONode() && anOutPort->IsGate() ) &&
1733 !( IsEndLoopNode() && ( anOutPort->IsGate() ||
1734 anOutPort->IsLoop() ) ) &&
1735 !anOutPort->IsDataStream() &&
1736 !anOutPort->ChangeInPorts( j )->IsDataStream() &&
1737 !anOutPort->ChangeInPorts( j )->IsExternConnected() ) {
1738 cdebug << ThreadNo()
1739 << " GraphExecutor::InNodeThreads::SetWaitingStates "
1740 << Name() << "( " << anOutPort->PortName() << " " << anOutPort->PortStatus() << " ) --> InPort "
1741 << anOutPort->ChangeInPorts( j )->PortName() << " "
1742 << anOutPort->ChangeInPorts( j )->PortStatus() << " from Node "
1743 << anOutPort->ChangeInPorts( j )->NodeName() << endl;
1744 GraphExecutor::InNode * aNode = (GraphExecutor::InNode * ) _OutNode->Graph()->GetChangeGraphNode( anOutPort->ChangeInPorts( j )->NodeName() )->GetInNode() ;
1745 if ( aNode != EndNode ) {
1746 aNode->SetWaitingStates( EndNode ) ;
1753 int GraphExecutor::InNode::Successed_SuccessAction() {
1754 cdebug << ThreadNo() << " --> Successed_SuccessAction " << Name() << endl;
1756 int linkednodesnumber = LinkedNodesSize() ;
1757 GraphExecutor::InNode *firstzeroNode = NULL ;
1758 GraphExecutor::InNode *firsttoNode = NULL ;
1759 GraphExecutor::InNode *toNode ;
1762 list<GraphExecutor::InNode *> SomeDataNodes ;
1766 if ( IsMacroNode() ) {
1767 cdebug << ThreadNo() << " Successed_SuccessAction " << Name() << " LinkedNodes->SomeDataReady already done"
1772 if ( IsGOTONode() ||
1773 ( IsEndLoopNode() && GetNodeInLoop()->GetOutPort()->BoolValue() ) ) {
1774 cdebug << ThreadNo() << " Successed_SuccessAction " << Name()
1775 << " SetWaitingStates " << endl ;
1776 const GraphBase::OutPort * aGateOutPort ;
1777 if ( IsGOTONode() ) {
1778 aGateOutPort = GetNodeOutGate() ;
1781 aGateOutPort = GetNodeOutLoop() ;
1783 for ( i = 0 ; i < aGateOutPort->InPortsSize() ; i++ ) {
1784 const GraphBase::InPort * anInPort = aGateOutPort->InPorts( i ) ;
1785 GraphExecutor::InNode * aLabelNode = (GraphExecutor::InNode *) _OutNode->Graph()->GetChangeGraphNode( anInPort->NodeName() )->GetInNode() ;
1786 cdebug << ThreadNo() << " Successed_SuccessAction " << Name() << " will Loop to HeadNode "
1787 << aLabelNode->Name() << " from port " << anInPort->PortName() << endl ;
1788 aLabelNode->SetWaitingStates( this ) ;
1789 for ( j = 0 ; j < aLabelNode->GetNodeInPortsSize() ; j++ ) {
1790 const GraphBase::InPort * anInPort = aLabelNode->GetNodeInPort( j ) ;
1791 if ( anInPort->GetOutPort() ) {
1792 cdebug << aLabelNode->Name() << "(" << anInPort->PortName() << ") value : "
1793 << anInPort->GetOutPort()->NodeName() << "(" << anInPort->GetOutPort()->PortName() << ")"
1797 for ( j = 0 ; j < GetNodeOutPortsSize() ; j++ ) {
1798 GraphBase::OutPort * aBusParamOutPort = GetChangeNodeOutPort( j ) ;
1799 if ( !aBusParamOutPort->IsGate() ) {
1800 GraphBase::InPort * aBusParamChangeInPort = NULL ;
1801 if ( aBusParamOutPort->IsLoop() ) {
1802 aBusParamChangeInPort = aLabelNode->GetChangeNodeInLoop() ;
1805 aBusParamChangeInPort = aLabelNode->GetChangeInPort( aBusParamOutPort->PortName() ) ;
1807 if ( aBusParamChangeInPort ) {
1808 aBusParamChangeInPort->ChangeOutPort( aBusParamOutPort ) ;
1809 cdebug << ThreadNo() << " Successed_SuccessAction " << Name() << " ChangeOutPort to HeadNode "
1810 << aLabelNode->Name() << "(" << aBusParamChangeInPort->PortName() << ") from port "
1811 << aBusParamOutPort->PortName() << endl ;
1812 if ( !aLabelNode->IsLockedDataWait() ) {
1813 res = aLabelNode->SendSomeDataReady( Name() ) ;
1815 if ( firsttoNode == NULL &&
1816 aLabelNode->ThreadNo() == pthread_self() ) {
1817 firsttoNode = aLabelNode ;
1818 cdebug << ThreadNo() << " Successed_SuccessAction firsttoNode "
1819 << aLabelNode->Name() << endl ;
1821 else if ( firstzeroNode == NULL &&
1822 aLabelNode->ThreadNo() == 0 ) {
1823 firstzeroNode = aLabelNode ;
1826 SomeDataNodes.push_back( aLabelNode ) ;
1827 cdebug << ThreadNo() << " Successed_SuccessAction " << Name() << " push "
1828 << aLabelNode->Name() << " " << SomeDataNodes.size()
1834 cdebug << ThreadNo()
1835 << " Successed_SuccessAction Loop to HeadNode "
1836 << aLabelNode->Name() << " with datas from " << Name() << "("
1837 << aBusParamOutPort->PortName() << ") to port "
1838 << aBusParamChangeInPort->PortName() << endl;
1842 cdebug << ThreadNo() << " ERROR in Successed_SuccessAction of " << Name()
1843 << " NO port " << aBusParamOutPort->PortName() << " in "
1844 << aLabelNode->Name() << endl;
1848 for ( j = 0 ; j < aLabelNode->GetNodeInPortsSize() ; j++ ) {
1849 const GraphBase::InPort * anInPort = aLabelNode->GetNodeInPort( j ) ;
1850 if ( anInPort->GetOutPort() ) {
1851 cdebug << aLabelNode->Name() << "(" << anInPort->PortName() << ") value : "
1852 << anInPort->GetOutPort()->NodeName() << "(" << anInPort->GetOutPort()->PortName() << ")"
1856 const GraphBase::InPort * aGateInPort = aLabelNode->GetNodeInGate() ;
1857 if ( aGateInPort ) {
1858 if ( aGateInPort->GetOutPort() ) {
1859 aGateInPort->GetOutPort()->Value( aGateOutPort->Value() ) ;
1861 if ( !aLabelNode->IsLockedDataWait() ) {
1862 res = aLabelNode->SendSomeDataReady( Name() ) ;
1864 if ( firsttoNode == NULL &&
1865 aLabelNode->ThreadNo() == pthread_self() ) {
1866 firsttoNode = aLabelNode ;
1867 cdebug << ThreadNo() << " Successed_SuccessAction firsttoNode "
1868 << aLabelNode->Name() << endl ;
1870 else if ( firstzeroNode == NULL &&
1871 aLabelNode->ThreadNo() == 0 ) {
1872 firstzeroNode = aLabelNode ;
1875 SomeDataNodes.push_back( aLabelNode ) ;
1876 cdebug << ThreadNo() << " Successed_SuccessAction " << Name() << " push "
1877 << aLabelNode->Name() << " " << SomeDataNodes.size()
1884 cdebug << ThreadNo() << " ERROR in Successed_SuccessAction of " << Name()
1885 << " NO port " << aGateOutPort->PortName() << " in "
1886 << aLabelNode->Name() << endl;
1892 cdebug << ThreadNo() << " Successed_SuccessAction of " << Name()
1893 << " with " << LinkedNodesSize() << " linked nodes :" ;
1894 for ( i = 0 ; i < LinkedNodesSize() ; i++ ) {
1895 if ( LinkedNodes( i )->IsDataFlowNode() ) {
1896 linkednodesnumber -= 1 ;
1898 cdebug << " " << LinkedNodes( i )->Name() ;
1901 for ( i = 0 ; i < LinkedNodesSize() ; i++ ) {
1902 bool IgnoreForEndLoop = false ;
1903 GraphBase::ComputingNode * aComputingNode ;
1904 aComputingNode = (GraphBase::ComputingNode * ) LinkedNodes( i ) ;
1905 toNode = (GraphExecutor::InNode *) aComputingNode->GetInNode() ;
1906 cdebug << ThreadNo() << " Successed_SuccessAction of " << Name()
1907 << " [" << i << "] " << LinkedNodes( i )->Name() << " toNode " << toNode << " IgnoreForEndLoop "
1908 << IgnoreForEndLoop ;
1910 cdebug << " " << toNode->Kind() << endl ;
1912 if ( toNode && !toNode->IsDataFlowNode() ) {
1913 if ( IsComputingNode() && toNode->IsInLineNode() ) {
1914 GraphBase::InPort * toGateInPort = toNode->GetChangeNodeInGate() ;
1915 toGateInPort->State( SUPERV::ReadyState ) ;
1916 GraphBase::OutPort * GateOutPort = toGateInPort->GetOutPort() ;
1917 if ( GateOutPort ) {
1918 GateOutPort->PortStatus( DataConnected );
1919 GateOutPort->State( SUPERV::ReadyState ) ;
1920 GateOutPort->Done( true ) ;
1924 if ( toNode && IsLoopNode() ) {
1925 GraphBase::OutPort * fromLoopOutPort = GetChangeNodeOutLoop() ;
1926 if ( !fromLoopOutPort->BoolValue() ) { // Ne pas faire la boucle
1927 if ( strcmp( toNode->Name() , CoupledNode()->Name() ) ) {
1928 IgnoreForEndLoop = true ;
1930 else { // toNode is the EndLoopNode
1931 GraphBase::InPort * toLoopInPort ;
1932 toLoopInPort = toNode->GetChangeNodeInLoop() ;
1933 if ( toLoopInPort->State() != SUPERV::ReadyState ) {
1934 toLoopInPort->State( SUPERV::ReadyState ) ;
1939 else if ( toNode && IsSwitchNode() ) {
1941 else if ( toNode && toNode->IsInLineNode() ) {
1943 for ( j = 0 ; j < toNode->GetNodeInPortsSize() ; j++ ) {
1944 toNode->GetChangeNodeInPort( j )->InitialOutPort() ;
1947 if ( toNode && !IgnoreForEndLoop ) {
1948 if ( toNode && toNode->IsLoopNode() ) {
1949 GraphBase::InPort * toLoopInPort = toNode->GetChangeNodeInLoop() ;
1950 toLoopInPort->State( SUPERV::ReadyState ) ;
1951 GraphBase::OutPort * LoopOutPort = toLoopInPort->GetOutPort() ;
1952 LoopOutPort->PortStatus( DataConnected );
1953 LoopOutPort->State( SUPERV::ReadyState ) ;
1954 LoopOutPort->Done( true ) ;
1955 CORBA::Any * anAny = new CORBA::Any() ;
1956 *anAny <<= (long ) 1 ;
1957 LoopOutPort->Value( anAny ) ;
1959 for ( j = 0 ; j < toNode->GetNodeInPortsSize() ; j++ ) {
1960 toNode->GetChangeNodeInPort( j )->InitialOutPort() ;
1963 cdebug << ThreadNo() << " Successed_SuccessAction " << toNode->Name() << "->SendSomeDataReady( "
1964 << Name() << " )" << endl ;
1965 res = toNode->SendSomeDataReady( Name() ) ;
1967 if ( firsttoNode == NULL &&
1968 toNode->ThreadNo() == pthread_self() ) {
1969 firsttoNode = toNode ;
1970 cdebug << ThreadNo() << " Successed_SuccessAction firsttoNode "
1971 << toNode->Name() << endl ;
1973 else if ( firstzeroNode == NULL &&
1974 toNode->ThreadNo() == 0 ) {
1975 firstzeroNode = toNode ;
1978 SomeDataNodes.push_back( toNode ) ;
1979 cdebug << ThreadNo() << " Successed_SuccessAction " << Name() << " push "
1980 << toNode->Name() << " " << SomeDataNodes.size() << endl ;
1987 if ( firsttoNode == NULL && firstzeroNode ) {
1988 firsttoNode = firstzeroNode ;
1989 cdebug << ThreadNo()
1990 << " Successed_SuccessAction firsttoNode = firstzeroNode "
1993 else if ( firsttoNode && firstzeroNode ) {
1994 SomeDataNodes.push_back( firstzeroNode ) ;
1995 cdebug << ThreadNo() << " Successed_SuccessAction " << Name() << " push firstzeroNode "
1996 << firstzeroNode->Name() << " " << SomeDataNodes.size() << endl ;
1999 cdebug << ThreadNo() << " Successed_SuccessAction " << Name() << " firsttoNode " << firsttoNode
2000 << " firstzeroNode " << firstzeroNode << endl ;
2003 while ( SomeDataNodes.size() ) {
2004 GraphExecutor::InNode *aNode = SomeDataNodes.front() ;
2005 SomeDataNodes.pop_front() ;
2006 // cdebug << pthread_self() << "/" << ThreadNo()
2007 // << " Successed_SuccessAction pop "
2008 // << SomeDataNodes.size() << " " << aNode->Name() << endl ;
2009 if ( aNode->State() == GraphExecutor::DataReadyState ) {
2010 aNode->CreateNewThreadIf( true ) ;
2011 aNode->UnLockDataWait() ;
2012 res = aNode->DataUndef_AllDataReadyAction() ;
2015 // cdebug << pthread_self() << "/" << ThreadNo() << " ERROR "
2016 // << aNode->Name() << " "
2017 // << Automaton()->StateName( aNode->State() ) << endl ;
2021 if ( firsttoNode ) {
2022 // cdebug << pthread_self() << "/" << ThreadNo()
2023 // << " Successed_SuccessAction start firsttoNode "
2024 // << SomeDataNodes.size() << " " << firsttoNode->Name() << endl ;
2025 firsttoNode->CreateNewThreadIf( false ) ;
2026 firsttoNode->RewindStack( RewindStack() ) ;
2027 if ( firsttoNode->State() == GraphExecutor::SuccessedState ) {
2028 // cdebug << pthread_self() << "/" << ThreadNo() << " " << Name()
2029 // << " : " << firsttoNode->Name() << " "
2030 // << Automaton()->StateName( firsttoNode->State() )
2031 // << " --> DataWaitingState for Thread "
2032 // << firsttoNode->ThreadNo() << endl ;
2033 firsttoNode->State( GraphExecutor::DataWaitingState ) ;
2035 // pthread_t OldT = firsttoNode->ThreadNo() ;
2036 firsttoNode->ThreadNo( pthread_self() ) ;
2037 // On continue avec le meme thread
2038 // cdebug << pthread_self() << "/" << ThreadNo() << " firsttoNode "
2039 // << firsttoNode->Name() << "Thread(" << OldT << "-->"
2040 // << firsttoNode->ThreadNo() << ")" << endl ;
2042 // cdebug << ThreadNo() << " Successed_SuccessAction " << Name()
2043 // << " for " << firsttoNode->Name()
2044 // << " !firsttoNode->CreateNewThreadIf() "
2045 // << !firsttoNode->CreateNewThreadIf()
2046 // << " " << Automaton()->StateName( firsttoNode->State() ) ;
2047 if ( firsttoNode->State() == GraphExecutor::DataReadyState ) {
2049 firsttoNode->UnLockDataWait() ;
2050 res = firsttoNode->DataUndef_AllDataReadyAction() ;
2053 cdebug << " ERROR " << endl ;
2057 // cdebug << ThreadNo() << " Successed_SuccessAction " << Name()
2058 // << " NO DataReady ==> ThreadNo( 0 ) firsttoNode == NULL LINKEDnodesnumber " << linkednodesnumber << endl ;
2062 // if ( linkednodesnumber == 0 && firsttoNode == NULL ) {
2063 // cdebug << ThreadNo() << " Successed_SuccessAction " << Name() << " LinkedNodesSize " << LinkedNodesSize()
2064 // << " firsttoNode == NULL LINKEDnodesnumber " << linkednodesnumber << " CHECK" << endl ;
2065 // _OutNode->CheckAllDone() ;
2068 // cdebug << pthread_self() << "/" << ThreadNo()
2069 // << " <-- Successed_SuccessAction " << Name() << " linkednodesnumber "
2070 // << linkednodesnumber << endl;
2074 bool GraphExecutor::InNode::SendSomeDataReady( char * FromNodeName ) {
2075 bool RetVal = false ;
2076 if ( IsDataFlowNode() ) {
2077 cdebug << ThreadNo() << " ----> " << Name()
2078 << " send Result to graph " << Name() << endl;
2081 // cdebug << pthread_self() << "/" << ThreadNo() << " ----> " << FromNodeName
2082 // << " send SomeDataReady to " << Name() << " "
2083 // << Automaton()->StateName( State() )
2084 // << " CreateNewThreadIf() " << CreateNewThreadIf()
2085 // << " LockedDataWait " << IsLockedDataWait() << endl;
2087 //cout << pthread_self() << "/" << ThreadNo() << " ----> " << FromNodeName
2088 << " send SomeDataReady to " << Name() << " "
2089 << Automaton()->StateName( State() )
2090 << " CreateNewThreadIf() " << CreateNewThreadIf()
2091 << " LockedDataWait " << IsLockedDataWait() << endl;
2093 if ( State() == GraphExecutor::SuccessedState ||
2094 State() == GraphExecutor::SuspendedSuccessedState ||
2095 State() == GraphExecutor::SuspendedSuccessedToReStartState ) {
2096 // cdebug << ThreadNo() << " " << FromNodeName
2097 // << " : " << Name() << " " << Automaton()->StateName( State() )
2098 // << " --> DataWaitingState for Thread "
2099 // << ThreadNo() << " " << endl ;
2100 State( GraphExecutor::DataWaitingState ) ;
2103 DataFromNode( FromNodeName ) ;
2104 RetVal = !SendEvent( GraphExecutor::SomeDataReadyEvent );
2112 int GraphExecutor::InNode::Errored_ErrorAction() {
2113 cdebug << ThreadNo() << " Errored_ErrorAction " << Name()
2114 << " will pthread_exit" << endl;
2119 int GraphExecutor::InNode::Successed_SuspendAction() {
2120 cdebug << ThreadNo() << " Successed_SuspendAction -->Suspend " << Name()
2121 << " Threads " << _OutNode->Threads() << " SuspendedThreads "
2122 << _OutNode->SuspendedThreads() << endl;
2123 _OutNode->PushEvent( this , GraphExecutor::SuspendedSuccessedEvent ,
2124 GraphExecutor::SuspendedSuccessedState ) ;
2126 GraphExecutor::InNode * aReStartNode = SuspendAction() ;
2127 cdebug << ThreadNo() << " Successed_SuspendAction Resumed " << Name() ;
2128 if ( aReStartNode ) {
2129 _aReStartNode = NULL ;
2130 cdebug << " for " << aReStartNode->Name() << endl;
2131 aReStartNode->SendEvent( _aReStartEvent ) ;
2135 SendEvent( GraphExecutor::ResumeEvent ) ;
2140 int GraphExecutor::InNode::Errored_SuspendAction() {
2141 cdebug << ThreadNo() << " Errored_SuspendAction -->Suspend " << Name()
2142 << " Threads " << _OutNode->Threads() << " SuspendedThreads "
2143 << _OutNode->SuspendedThreads() << endl;
2144 _OutNode->PushEvent( this , GraphExecutor::SuspendedErroredEvent ,
2145 GraphExecutor::SuspendedErroredState ) ;
2147 GraphExecutor::InNode * aReStartNode = SuspendAction() ;
2148 cdebug << ThreadNo() << " Errored_SuspendAction Resumed " << Name()
2150 if ( aReStartNode ) {
2151 _aReStartNode = NULL ;
2152 aReStartNode->SendEvent( _aReStartEvent ) ;
2155 SendEvent( GraphExecutor::ResumeEvent ) ;
2160 int GraphExecutor::InNode::SuspendedSuccessed_ResumeAction() {
2161 cdebug << ThreadNo() << " SuspendedSuccessed_ResumeAction " << Name() << endl;
2163 _OutNode->PushEvent( this , GraphExecutor::ResumedSuccessedEvent ,
2164 GraphExecutor::ResumedSuccessedState ) ;
2165 SendEvent( ResumedSuccessedEvent ) ;
2169 int GraphExecutor::InNode::SuspendedErrored_ResumeAction() {
2170 cdebug << ThreadNo() << " SuspendedErrored_ResumeAction " << Name() << endl;
2172 _OutNode->PushEvent( this , GraphExecutor::ResumedErroredEvent ,
2173 GraphExecutor::ResumedErroredState ) ;
2174 SendEvent( ResumedErroredEvent ) ;
2178 int GraphExecutor::InNode::Successed_KillAction() {
2180 _OutNode->PushEvent( this , GraphExecutor::KilledEvent ,
2181 GraphExecutor::KilledSuccessedState ) ;
2182 cdebug << ThreadNo() << " Successed_KillAction " << Name() << endl;
2186 int GraphExecutor::InNode::Errored_KillAction() {
2188 _OutNode->PushEvent( this , GraphExecutor::KilledEvent ,
2189 GraphExecutor::KilledErroredState ) ;
2190 cdebug << ThreadNo() << " Errored_KillAction " << Name() << endl;
2194 int GraphExecutor::InNode::Successed_StopAction() {
2196 _OutNode->PushEvent( this , GraphExecutor::StoppedEvent ,
2197 GraphExecutor::StoppedSuccessedState ) ;
2198 cdebug << ThreadNo() << " Successed_StopAction " << Name() << endl;
2202 int GraphExecutor::InNode::Errored_StopAction() {
2204 _OutNode->PushEvent( this , GraphExecutor::StoppedEvent ,
2205 GraphExecutor::StoppedErroredState ) ;
2206 cdebug << ThreadNo() << " Errored_StopAction " << Name() << endl;
2210 int GraphExecutor::InNode::SuspendedSuccessed_ReStartAction() {
2211 cdebug << ThreadNo() << " SuspendedSuccessed_ReStartAction " << Name() << endl;
2212 _OutNode->PushEvent( this , GraphExecutor::ReStartedEvent ,
2213 GraphExecutor::ReStartedState ) ;
2215 for ( i = 0 ; i < GetNodeInPortsSize() ; i++ ) {
2216 GetChangeNodeInPort( i )->State( SUPERV::ReadyState ) ;
2218 SendEvent( ExecuteEvent ) ;
2219 cdebug << ThreadNo() << " SuspendedSuccessed_ReStartAction " << Name() << endl;
2223 int GraphExecutor::InNode::SuspendedErrored_ReStartAction() {
2224 cdebug << ThreadNo() << " SuspendedErrored_ReStartAction " << Name() << endl;
2225 _OutNode->PushEvent( this , GraphExecutor::ReStartedEvent ,
2226 GraphExecutor::ReStartedState ) ;
2228 for ( i = 0 ; i < GetNodeInPortsSize() ; i++ ) {
2229 GetChangeNodeInPort( i )->State( SUPERV::ReadyState ) ;
2231 SendEvent( ExecuteEvent ) ;
2232 cdebug << ThreadNo() << " SuspendedErrored_ReStartAction " << Name() << endl;
2236 int GraphExecutor::InNode::SuspendedSuccessed_ReStartAndSuspendAction() {
2237 cdebug << ThreadNo() << " SuspendedSuccessed_ReStartAndSuspendAction " << Name()
2239 _OutNode->PushEvent( this , GraphExecutor::ReStartedAndSuspendEvent ,
2240 GraphExecutor::ReStartedState ) ;
2241 State( GraphExecutor::DataWaitingState ) ;
2243 cdebug << "InNode::Suspend() Node " << Name() << endl ;
2246 else if ( SendEvent( GraphExecutor::SomeDataReadyEvent ) ) {
2247 cdebug << "InNode::SendEvent( SomeDataReadyEvent ) Node "
2251 cdebug << ThreadNo() << " SuspendedSuccessed_ReStartAndSuspendAction " << Name()
2256 int GraphExecutor::InNode::SuspendedErrored_ReStartAndSuspendAction() {
2257 cdebug << ThreadNo() << " SuspendedErrored_ReStartAndSuspendAction " << Name()
2259 _OutNode->PushEvent( this , GraphExecutor::ReStartedAndSuspendEvent ,
2260 GraphExecutor::ReStartedState ) ;
2261 State( GraphExecutor::DataWaitingState ) ;
2263 cdebug << "InNode::Suspend() Node " << Name() << endl ;
2266 else if ( SendEvent( GraphExecutor::SomeDataReadyEvent ) ) {
2267 cdebug << "InNode::SendEvent( SomeDataReadyEvent ) Node "
2271 cdebug << ThreadNo() << " SuspendedErrored_ReStartAndSuspendAction " << Name()
2276 void GraphExecutor::InNode::InParametersSet( bool & Err ,
2278 ServicesAnyData * InParametersList ) {
2280 for ( i = 0 ; i < nInParams ; i++ ) {
2281 ServicesAnyData D = InParametersList[i];
2282 GraphBase::InPort * anInPort = GetChangeNodeInPort(i) ;
2283 GraphBase::OutPort * theOutPort = anInPort->GetOutPort() ;
2284 if ( anInPort->IsGate() && theOutPort == NULL ) {
2285 cdebug << ThreadNo() << " ArgIn" << i << " " << D.Name << " "
2286 << anInPort->GetServicesParameter().Parametertype
2287 << " is inactive. " << anInPort->Kind() << endl ;
2289 else if ( anInPort->State() == SUPERV::ReadyState ) {
2290 if ( anInPort->IsGate() ) {
2291 CORBA::Any * anAny = new CORBA::Any() ;
2292 *anAny <<= (long ) 0 ;
2293 theOutPort->Value( anAny ) ;
2295 if ( !anInPort->IsDataStream() ) {
2296 anInPort->State( SUPERV::WaitingState ) ;
2298 D.Name = CORBA::string_dup( anInPort->GetServicesParameter().Parametername ) ;
2299 cdebug << ThreadNo() << " ArgIn" << i << " " << anInPort->Kind() ;
2300 cdebug << " " << D.Name << " " << anInPort->GetServicesParameter().Parametertype << " : " ;
2301 D.Value = *theOutPort->Value() ; // CORBA::Any
2302 string _Type = CORBA::string_dup( anInPort->GetServicesParameter().Parametertype ) ;
2303 const char * Type = _Type.c_str() ;
2304 switch ( D.Value.type()->kind() ) { // { string , long , double , objref }
2305 case CORBA::tk_string:
2308 cdebug << t << " (string)" ;
2309 if ( !strcmp( Type , "string" ) ) {
2311 else if ( !strcmp( Type , "boolean" ) ) {
2314 sscanf( t , "%ld" , &d ) ;
2316 D.Value <<= (CORBA::Any::from_boolean ) b ;
2317 // theOutPort->Value( D.Value ) ;
2319 else if ( !strcmp( Type , "char" ) ) {
2322 sscanf( t , "%ld" , &d ) ;
2324 D.Value <<= (CORBA::Any::from_char ) c ;
2325 cdebug << "string '" << t << "' --> " << d << " --> char " << c ;
2326 // theOutPort->Value( D.Value ) ;
2328 else if ( !strcmp( Type , "short" ) ) {
2331 sscanf( t , "%ld" , &d ) ;
2334 cdebug << "string '" << t << "' --> " << d << " --> short " << s ;
2335 // theOutPort->Value( D.Value ) ;
2337 else if ( !strcmp( Type , "int" ) || !strcmp( Type , "long" ) ) {
2339 sscanf( t , "%ld" , &l ) ;
2341 cdebug << "string '" << t << " --> long " << l ;
2342 // theOutPort->Value( D.Value ) ;
2344 else if ( !strcmp( Type , "float" ) ) {
2346 sscanf( t , "%lf" , &d ) ;
2349 cdebug << "string '" << t << "' --> " << setw(25) << setprecision(18) << d << " --> float " << " = "
2350 << setw(25) << setprecision(18) << f ;
2351 // theOutPort->Value( D.Value ) ;
2353 else if ( !strcmp( Type , "double" ) ) {
2355 sscanf( t , "%lf" , &d ) ;
2357 cdebug << "string '" << t << " --> double " << setw(25) << setprecision(18) << d ;
2358 // theOutPort->Value( D.Value ) ;
2360 // else if ( !strcmp( Type , "objref" ) ) {
2362 CORBA::Object_ptr ObjRef ;
2364 ObjRef = StringToObject( t ) ;
2365 D.Value <<= ObjRef ;
2368 D.Value <<= CORBA::Object::_nil() ;
2370 // theOutPort->Value( D.Value ) ;
2373 // cdebug << " (other ERROR)" << endl ;
2375 cdebug << " --> call_kind " << D.Value.type()->kind() << endl ;
2377 case CORBA::tk_long:
2380 cdebug << l << " (long)" << endl ;
2381 if ( !strcmp( Type , "string" ) ) {
2383 sprintf( t , "%ld" , l ) ;
2385 // theOutPort->Value( D.Value ) ;
2387 else if ( !strcmp( Type , "boolean" ) ) {
2390 D.Value <<= (CORBA::Any::from_boolean ) b ;
2391 // theOutPort->Value( D.Value ) ;
2393 else if ( !strcmp( Type , "char" ) ) {
2395 c = (unsigned char ) l ;
2396 D.Value <<= (CORBA::Any::from_char ) c ;
2397 // theOutPort->Value( D.Value ) ;
2399 else if ( !strcmp( Type , "short" ) ) {
2403 // theOutPort->Value( D.Value ) ;
2405 else if ( !strcmp( Type , "int" ) || !strcmp( Type , "long" ) ) {
2407 else if ( !strcmp( Type , "float" ) ) {
2411 // theOutPort->Value( D.Value ) ;
2413 else if ( !strcmp( Type , "double" ) ) {
2417 // theOutPort->Value( D.Value ) ;
2419 // else if ( !strcmp( Type , "objref" ) ) {
2421 D.Value <<= CORBA::Object::_nil() ;
2422 // theOutPort->Value( D.Value ) ;
2425 // cdebug << " (other ERROR)" << endl ;
2427 cdebug << " --> call_kind " << D.Value.type()->kind() << endl ;
2429 case CORBA::tk_double:
2432 cdebug << d << " (double)" << endl ;
2433 if ( !strcmp( Type , "string" ) ) {
2435 sprintf( t , "%lf" , d ) ;
2437 // theOutPort->Value( D.Value ) ;
2439 else if ( !strcmp( Type , "boolean" ) ) {
2442 D.Value <<= (CORBA::Any::from_boolean ) b ;
2443 // theOutPort->Value( D.Value ) ;
2445 else if ( !strcmp( Type , "char" ) ) {
2447 c = (unsigned char ) d ;
2448 D.Value <<= (CORBA::Any::from_char ) c ;
2449 // theOutPort->Value( D.Value ) ;
2451 else if ( !strcmp( Type , "short" ) ) {
2455 // theOutPort->Value( D.Value ) ;
2457 else if ( !strcmp( Type , "int" ) || !strcmp( Type , "long" ) ) {
2461 // theOutPort->Value( D.Value ) ;
2463 else if ( !strcmp( Type , "float" ) ) {
2467 // theOutPort->Value( D.Value ) ;
2469 else if ( !strcmp( Type , "double" ) ) {
2471 // else if ( !strcmp( Type , "objref" ) ) {
2473 D.Value <<= CORBA::Object::_nil() ;
2474 // theOutPort->Value( D.Value ) ;
2477 // cdebug << " (other ERROR)" << endl ;
2479 cdebug << " --> call_kind " << D.Value.type()->kind() << endl ;
2481 case CORBA::tk_objref:
2482 if ( !strcmp( Type , "string" ) ) {
2483 CORBA::Object_ptr ObjRef ;
2486 D.Value >>= ObjRef ;
2487 retstr = ObjectToString( ObjRef ) ;
2488 D.Value <<= retstr ;
2489 // theOutPort->Value( D.Value ) ;
2495 cdebug << "ToString( object ) Catched ERROR" << endl ;
2498 else if ( !strcmp( Type , "boolean" ) ) {
2500 D.Value <<= (CORBA::Any::from_boolean ) b ;
2501 // theOutPort->Value( D.Value ) ;
2503 else if ( !strcmp( Type , "char" ) ) {
2504 unsigned char c = 0 ;
2505 D.Value <<= (CORBA::Any::from_char ) c ;
2506 // theOutPort->Value( D.Value ) ;
2508 else if ( !strcmp( Type , "short" ) ) {
2511 // theOutPort->Value( D.Value ) ;
2513 else if ( !strcmp( Type , "int" ) || !strcmp( Type , "long" ) ) {
2516 // theOutPort->Value( D.Value ) ;
2518 else if ( !strcmp( Type , "float" ) ) {
2521 // theOutPort->Value( D.Value ) ;
2523 else if ( !strcmp( Type , "double" ) ) {
2526 // theOutPort->Value( D.Value ) ;
2528 // else if ( !strcmp( Type , "objref" ) ) {
2530 CORBA::Object_ptr obj ;
2534 retstr = ObjectToString( obj ) ;
2535 cdebug << retstr << endl ;
2541 cdebug << "ToString( object ) Catched ERROR" << endl ;
2545 // cdebug << " (other ERROR)" << endl ;
2547 cdebug << " --> call_kind " << D.Value.type()->kind() << endl ;
2550 cdebug << " (other ERROR) " << D.Value.type()->kind() << endl ;
2554 cdebug << ThreadNo() << " In" << i << " : wrong state ERROR State "
2555 << anInPort->State() << " NameState "
2556 << Automaton()->StateName( anInPort->State() ) << " PortName "
2557 << anInPort->PortName() << " Parametername "
2558 << anInPort->GetServicesParameter().Parametername << endl ;
2561 InParametersList[i] = D ;
2565 void GraphExecutor::InNode::InOutParametersSet( int nOutParams ,
2566 ServicesAnyData * OutParametersList ) {
2568 for ( i = 0 ; i < nOutParams ; i++ ) {
2569 ServicesAnyData D = OutParametersList[i] ;
2571 D.Name = GetChangeNodeOutPort(i)->GetServicesParameter().Parametername;
2572 string _Type = CORBA::string_dup(GetChangeNodeOutPort(i)->GetServicesParameter().Parametertype) ;
2573 const char * Type = _Type.c_str() ;
2574 bool OutDone = GetChangeNodeOutPort(i)->Done() ;
2575 cdebug << ThreadNo() << " ArgOut" << i << " " << D.Name << " Done("
2576 << OutDone << ") " << Type << " : " << endl ;
2577 if ( !strcmp( Type , "string" ) ) {
2578 D.Value <<= (char *) NULL ;
2580 else if ( !strcmp( Type , "boolean" ) ) {
2582 D.Value <<= (CORBA::Any::from_boolean ) b ;
2584 else if ( !strcmp( Type , "char" ) ) {
2585 unsigned char c = 0 ;
2586 D.Value <<= (CORBA::Any::from_char ) c ;
2588 else if ( !strcmp( Type , "short" ) ) {
2592 else if ( !strcmp( Type , "int" ) || !strcmp( Type , "long" ) ) {
2593 D.Value <<= (long ) 0 ;
2595 else if ( !strcmp( Type , "float" ) ) {
2599 else if ( !strcmp( Type , "double" ) ) {
2604 D.Value <<= CORBA::Object::_nil() ;
2607 switch (D.Value.type()->kind()) { // { string , long , double , objref }
2608 case CORBA::tk_string:
2611 cdebug << ThreadNo() << " " << t << "(string)" << endl ;
2613 case CORBA::tk_boolean:
2615 D.Value >>= (CORBA::Any::to_boolean ) b;
2616 cdebug << ThreadNo() << " " << b << "(boolean)" << endl ;
2618 case CORBA::tk_char:
2620 D.Value >>= (CORBA::Any::to_char ) c;
2621 cdebug << ThreadNo() << " " << c << "(char)" << endl ;
2623 case CORBA::tk_short:
2626 cdebug << ThreadNo() << " " << s << "(short)" << endl ;
2628 case CORBA::tk_long:
2631 cdebug << ThreadNo() << " " << l << "(long)" << endl ;
2633 case CORBA::tk_float:
2636 cdebug << ThreadNo() << " " << f << "(float)" << endl ;
2638 case CORBA::tk_double:
2641 cdebug << ThreadNo() << " " << d << "(double)" << endl ;
2643 case CORBA::tk_objref:
2645 CORBA::Object_ptr obj ;
2648 retstr = ObjectToString( obj ) ;
2649 cdebug << ThreadNo() << retstr << endl ;
2652 cdebug << "ToString( object ) Catched ERROR" << endl ;
2656 cdebug << ThreadNo() << " " << "(other ERROR)" << endl ;
2659 OutParametersList[i] = D ;
2663 bool GraphExecutor::InNode::OutParametersSet( bool Err ,
2664 SUPERV::GraphState NewState ,
2666 ServicesAnyData * OutParametersList ) {
2667 bool RetVal = true ;
2669 GraphBase::OutPort * aGateOutPort = NULL ;
2670 bool OrSwitch = false ;
2671 cdebug << "OutParametersSet " << Name() << " nOutParams " << nOutParams << " NewState " << NewState << endl ;
2672 // cout << "OutParametersSet " << Name() << " nOutParams " << nOutParams << " NewState " << NewState << endl ;
2673 if ( nOutParams && !IsMacroNode() ) {
2674 GraphBase::OutPort * anOutPort ;
2675 for ( i = 0 ; i < nOutParams ; i++ ) {
2676 anOutPort = GetChangeNodeOutPort(i) ;
2678 anOutPort->State( NewState ) ;
2679 anOutPort->Done( true ) ;
2682 cdebug << ThreadNo() << " " << "Out" << i << " " << Name() << " "
2683 << anOutPort->PortName() << " " << anOutPort->Kind() ;
2684 ServicesAnyData D = OutParametersList[i] ;
2685 switch (D.Value.type()->kind()) { // { string , long , double , objref }
2686 case CORBA::tk_string: {
2689 cdebug << ThreadNo() << " " << t << "(string)" << endl ;
2692 case CORBA::tk_boolean: {
2694 D.Value >>= (CORBA::Any::to_boolean ) b;
2695 long l = (long ) b ;
2697 cdebug << ThreadNo() << " " << b << "(boolean)" << endl ;
2700 case CORBA::tk_char: {
2702 D.Value >>= (CORBA::Any::to_char ) c;
2703 long l = (long ) c ;
2705 cdebug << ThreadNo() << " " << c << "(char)" << endl ;
2708 case CORBA::tk_short: {
2711 long l = (long ) s ;
2713 cdebug << ThreadNo() << " " << s << "(short)" << endl ;
2716 case CORBA::tk_long: {
2719 cdebug << ThreadNo() << " " << l << "(long)" << endl ;
2722 case CORBA::tk_float: {
2725 double d = (double ) f ;
2727 cdebug << ThreadNo() << " " << f << "(float)" << endl ;
2730 case CORBA::tk_double: {
2733 cdebug << ThreadNo() << " " << d << "(double)" << endl ;
2736 case CORBA::tk_objref: {
2738 CORBA::Object_ptr obj ;
2741 retstr = ObjectToString( obj ) ;
2742 cdebug << ThreadNo() << retstr << endl ;
2745 cdebug << "ToString( object ) Catched ERROR" << endl ;
2750 cdebug << ThreadNo() << " " << "(other ERROR)" << endl ;
2753 OutParametersList[i] = D ;
2754 if ( !anOutPort->IsDataStream() ) {
2755 if ( anOutPort->IsGate() ) {
2756 aGateOutPort = anOutPort ;
2757 cdebug << " Gate " ;
2759 OutParametersList[i].Value <<= l;
2760 anOutPort->Value( OutParametersList[i].Value );
2762 else if ( anOutPort->IsLoop() ) {
2763 cdebug << " Loop " ;
2764 anOutPort->Value( OutParametersList[i].Value );
2765 // InLoop Port of EndLoopNode is ready :
2766 anOutPort->ChangeInPorts(0)->State( SUPERV::ReadyState ) ;
2768 else if ( anOutPort->IsSwitch() ) {
2769 cdebug << " Switch " ;
2770 anOutPort->Value( OutParametersList[i].Value );
2771 if ( anOutPort->InPortsSize() && anOutPort->ChangeInPorts( 0 )->IsGate() ) {
2772 if ( OrSwitch && anOutPort->BoolValue() ) {
2773 cdebug << "GraphExecutor::InNodeThreads::OutParameters more than one switch is true WARNING"
2777 OrSwitch = OrSwitch | anOutPort->BoolValue() ;
2780 cdebug << "OrSwitch " << OrSwitch ;
2783 cdebug << " Param " ;
2784 anOutPort->Value( OutParametersList[i].Value );
2786 anOutPort->State( NewState ) ;
2787 anOutPort->Done( true ) ;
2790 for ( j = 0 ; j < anOutPort->InPortsSize() ; j++ ) {
2791 bool fromGOTO = false ;
2792 const char * ToNodeName = anOutPort->ChangeInPorts( j )->NodeName() ;
2793 if ( !strcmp( ToNodeName , _OutNode->Graph()->Name() ) && _OutNode->Graph()->GraphMacroLevel() != 0 ) {
2794 cdebug << "OutParametersSet ToNodeName " << _OutNode->Graph()->CoupledNode()
2795 << " GraphExecutor " << _OutNode->Graph()->CoupledNode()->GraphExecutor() << endl ;
2796 _OutNode->Graph()->CoupledNode()->GraphExecutor()->OutputOfAny( _OutNode->Graph()->CoupledNodeName() ,
2797 anOutPort->ChangeInPorts( j )->PortName() ,
2798 *anOutPort->Value() ) ;
2801 GraphBase::ComputingNode * ToNode = _OutNode->Graph()->GetChangeGraphNode( ToNodeName ) ;
2803 // cout << "OutParametersSet ToNodeName " << ToNodeName << endl ;
2804 cdebug << "OutParametersSet ToNodeName " << ToNodeName << " " << ToNode->Name() << endl ;
2805 GraphBase::OutPort * aGOTOPort = ToNode->GetChangeNodeInGate()->GetOutPort() ;
2807 fromGOTO = aGOTOPort->IsGOTO() ;
2809 if ( anOutPort->ChangeInPorts( j )->IsEndSwitch() || fromGOTO ) {
2810 cdebug << anOutPort->ChangeInPorts( j )->NodeName() << "("
2811 << anOutPort->ChangeInPorts( j )->PortName() << ","
2812 << anOutPort->ChangeInPorts( j )->Kind() << ") WILL BE changed from "
2813 << anOutPort->ChangeInPorts( j )->GetOutPort()->NodeName()
2815 << anOutPort->ChangeInPorts( j )->GetOutPort()->PortName()
2816 << ") to " << anOutPort->NodeName() << "("
2817 << anOutPort->PortName() << ")" << endl ;
2818 anOutPort->ChangeInPorts( j )->ChangeOutPort( anOutPort ) ;
2821 cdebug << anOutPort->ChangeInPorts( j )->NodeName() << "("
2822 << anOutPort->ChangeInPorts( j )->PortName() << ","
2823 << anOutPort->ChangeInPorts( j )->Kind() << ") NOT changed from "
2824 << anOutPort->ChangeInPorts( j )->GetOutPort()->NodeName()
2826 << anOutPort->ChangeInPorts( j )->GetOutPort()->PortName()
2827 << ") to " << anOutPort->NodeName() << "("
2828 << anOutPort->PortName() << ")" << endl ;
2834 switch (anOutPort->Value()->type()->kind()) {
2835 case CORBA::tk_string:
2837 (*anOutPort->Value()) >>= t;
2838 cdebug << ThreadNo() << " Out" << i << " : " << t << "(string)" << endl ;
2840 case CORBA::tk_boolean:
2842 (*anOutPort->Value()) >>= (CORBA::Any::to_boolean ) b;
2843 cdebug << ThreadNo() << " Out" << i << " : " << b << "(boolean)" << endl ;
2845 case CORBA::tk_char:
2847 (*anOutPort->Value()) >>= (CORBA::Any::to_char ) c;
2848 cdebug << ThreadNo() << " Out" << i << " : " << c << "(char)" << endl ;
2850 case CORBA::tk_short:
2852 (*anOutPort->Value()) >>= s;
2853 cdebug << ThreadNo() << " Out" << i << " : " << s << "(short)" << endl ;
2855 case CORBA::tk_long:
2857 (*anOutPort->Value()) >>= l;
2858 cdebug << ThreadNo() << " Out" << i << " : " << l << "(long)" << endl ;
2860 case CORBA::tk_float:
2862 (*anOutPort->Value()) >>= f;
2863 cdebug << ThreadNo() << " Out" << i << " : " << f << "(float)" << endl ;
2865 case CORBA::tk_double:
2867 (*anOutPort->Value()) >>= d;
2868 cdebug << ThreadNo() << " Out" << i << " : " << d << "(double)" << endl ;
2870 case CORBA::tk_objref:
2871 CORBA::Object_ptr obj ;
2874 (*anOutPort->Value()) >>= obj ;
2875 retstr = ObjectToString( obj );
2876 cdebug << ThreadNo() << " Out" << i << " : " << "ToString( object ) "
2880 cdebug << ThreadNo() << " Out" << i << " : " << "ToString( object ) "
2881 << "Catched ERROR" << endl ;
2885 cdebug << ThreadNo() << " Out" << i << " : " << "(other ERROR)" << endl ;
2891 if ( aGateOutPort && IsSwitchNode() ) {
2893 // cdebug << ThreadNo() << " " << "Out0 " << Name() << " Close of "
2894 // << aGateOutPort->PortName() << " " << aGateOutPort->Kind() ;
2896 OutParametersList[0].Value <<= l ;
2897 aGateOutPort->Value( OutParametersList[0].Value ) ;
2900 // cdebug << ThreadNo() << " " << "Out0 " << Name() << " Open of "
2901 // << aGateOutPort->PortName() << " " << aGateOutPort->Kind() ;
2903 OutParametersList[0].Value <<= l ;
2904 aGateOutPort->Value( OutParametersList[0].Value ) ;
2906 for ( i = 0 ; i < GetNodeOutPortsSize() ; i++ ) {
2907 GraphBase::InPort * anInPort ;
2908 anInPort = CoupledNode()->GetChangeInPort( GetNodeOutPort( i )->PortName() ) ;
2910 anInPort->ChangeOutPort( GetChangeNodeOutPort( i ) ) ;