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 if ( pthread_cond_broadcast( &_RunningWait ) ) {
161 perror("Running pthread_cond_broadcast ") ;
163 if ( pthread_mutex_unlock( &_MutexWait ) ) {
164 perror("Running pthread_mutex_unlock ") ;
169 void GraphExecutor::InNode::DoneAction() {
170 if ( pthread_mutex_lock( &_MutexWait ) ) {
171 perror("Done pthread_mutex_lock ") ;
174 cdebug << pthread_self() << "/" << ThreadNo()
175 << "DoneAction pthread_cond_broadcast _DoneWait "
177 if ( pthread_cond_broadcast( &_DoneWait ) ) {
178 perror("Done pthread_cond_broadcast ") ;
180 if ( pthread_mutex_unlock( &_MutexWait ) ) {
181 perror("Done pthread_mutex_unlock ") ;
186 void GraphExecutor::InNode::SuspendedAction() {
187 if ( pthread_mutex_lock( &_MutexWait ) ) {
188 perror("Suspended pthread_mutex_lock ") ;
191 cdebug << pthread_self() << "/" << ThreadNo()
192 << "SuspendedAction pthread_cond_broadcast _SuspendedWait "
194 if ( pthread_cond_broadcast( &_SuspendedWait ) ) {
195 perror("Suspended pthread_cond_broadcast ") ;
197 if ( pthread_mutex_unlock( &_MutexWait ) ) {
198 perror("Suspended pthread_mutex_unlock ") ;
203 // SuspendAction <--> { ResumeAction - ReStartAction }
204 GraphExecutor::InNode * GraphExecutor::InNode::SuspendAction() {
206 if ( pthread_mutex_lock( &_MutexWait ) ) {
207 perror("Suspend pthread_mutex_lock ") ;
210 if ( !_SuspendSync ) {
211 cdebug << pthread_self() << "/" << ThreadNo() << " pthread_cond " << Name()
212 << " SuspendAction pthread_cond_wait _SuspendWait "
213 << Automaton()->StateName( State() ) << endl ;
214 _SuspendSync = true ;
215 _OutNode->SuspendThread() ;
216 if ( pthread_cond_wait( &_SuspendWait , &_MutexWait ) ) {
217 perror("SuspendAction pthread_cond_wait ") ;
219 _OutNode->ResumeThread() ;
220 cdebug << pthread_self() << "/" << ThreadNo() << " pthread_cond " << Name()
221 << " SuspendAction pthread_cond_waited"
222 << Automaton()->StateName( State() ) << endl ;
225 cdebug << pthread_self() << "/" << ThreadNo() << " pthread_cond " << Name()
226 << " NO SuspendAction pthread_cond_wait"
227 << Automaton()->StateName( State() ) << endl ;
229 // SendEvent( _aResumeEvent ) ; ===> Mutex with myself !
230 _SuspendSync = false ;
231 if ( ControlState() == SUPERV::ToSuspendStartState ||
232 ControlState() == SUPERV::ToSuspendState ) {
233 ControlState( SUPERV::VoidState ) ;
235 if ( pthread_mutex_unlock( &_MutexWait ) ) {
236 perror("SuspendAction pthread_mutex_unlock ") ;
240 SendEvent( _aResumeEvent ) ;
241 // if ( ControlState() == SUPERV::ToSuspendStartState ) {
242 // ControlState( SUPERV::VoidState ) ;
245 if ( pthread_mutex_lock( &_MutexWait ) ) {
246 perror("SuspendAction pthread_mutex_lock ") ;
250 cdebug << pthread_self() << "/" << ThreadNo() << " pthread_cond " << Name()
251 << " SuspendAction pthread_cond_signal _ResumeWait" << endl ;
252 if ( pthread_cond_signal( &_ResumeWait ) ) {
253 perror("SuspendAction pthread_cond_signal _ResumeWait ") ;
255 cdebug << pthread_self() << "/" << ThreadNo() << " pthread_cond " << Name()
256 << " SuspendAction pthread_cond_signaled _ResumeWait " << endl ;
259 cdebug << pthread_self() << "/" << ThreadNo() << " pthread_cond " << Name()
260 << " NO SuspendAction pthread_cond_signal _ResumeWait" << endl ;
263 if ( pthread_mutex_unlock( &_MutexWait ) ) {
264 perror("SuspendAction pthread_mutex_unlock ") ;
267 if ( _aReStartNode ) {
268 cdebug << Name() << " " << Automaton()->StateName( State() )
269 << "aReStartNode : " << _aReStartNode->Name() << " "
270 << Automaton()->StateName( _aReStartNode->State() ) << endl ;
271 _aReStartNode->SendEvent( _aResumeEvent ) ;
274 cdebug << "NO aReStartNode"
275 << Automaton()->StateName( State() ) << endl ;
277 return _aReStartNode ;
280 bool GraphExecutor::InNode::ResumeAction( GraphExecutor::NodeEvent aResumeEvent ) {
282 if ( pthread_mutex_lock( &_MutexWait ) ) {
283 perror("ResumeAction pthread_mutex_lock ") ;
286 _aResumeEvent = aResumeEvent ;
287 if ( _SuspendSync ) {
288 cdebug << pthread_self() << "/" << ThreadNo() << " pthread_cond " << Name()
289 << " ResumeAction pthread_cond_signal" << endl ;
290 if ( pthread_cond_signal( &_SuspendWait ) ) {
291 perror("ResumeAction pthread_cond_signal ") ;
293 cdebug << pthread_self() << "/" << ThreadNo() << " pthread_cond " << Name()
294 << " ResumeAction pthread_cond_signaled _SuspendWait " << endl ;
298 cdebug << pthread_self() << "/" << ThreadNo() << " pthread_cond " << Name()
299 << " NO ResumeAction pthread_cond_signal" << endl ;
300 if ( pthread_self() == ThreadNo() ) {
301 RetVal = false ; /*/ Ne pas s'attendre soi-meme !...*/
304 _SuspendSync = true ;
305 RetVal = true ; // Il faut tout de meme attendre ci-apres ...
308 if ( pthread_mutex_unlock( &_MutexWait ) ) {
309 perror("ResumeAction pthread_mutex_unlock ") ;
314 if ( pthread_mutex_lock( &_MutexWait ) ) {
315 perror("ResumeAction pthread_mutex_lock ") ;
318 if ( !_ResumeSync ) {
319 cdebug << pthread_self() << "/" << ThreadNo() << " pthread_cond "
320 << Name() << " ResumeAction pthread_cond_wait _ResumeWait "
321 << Automaton()->StateName( State() ) << endl ;
323 if ( pthread_cond_wait( &_ResumeWait , &_MutexWait ) ) {
324 perror("ResumeAction pthread_cond_wait ") ;
326 cdebug << pthread_self() << "/" << ThreadNo() << " pthread_cond "
327 << Name() << " ResumeAction pthread_cond_waited _ResumeWait"
328 << Automaton()->StateName( State() ) << endl ;
332 cdebug << pthread_self() << "/" << ThreadNo() << " pthread_cond "
333 << Name() << " NO ResumeAction pthread_cond_wait _ResumeWait"
334 << Automaton()->StateName( State() ) << endl ;
337 _ResumeSync = false ;
338 if ( pthread_mutex_unlock( &_MutexWait ) ) {
339 perror("ResumeAction pthread_mutex_unlock ") ;
343 cdebug << pthread_self() << "/" << ThreadNo()
344 << "GraphExecutor::InNodeThreads::ResumeAction RetVal " << RetVal << endl ;
348 bool GraphExecutor::InNode::ReStartAction( GraphExecutor::InNode * aReStartNode ,
349 GraphExecutor::NodeEvent anEvent ) {
350 GraphExecutor::InNode * oldReStartNode = _aReStartNode ;
351 _aReStartNode = aReStartNode ;
352 _aReStartEvent = anEvent ;
353 cdebug << pthread_self() << " GraphExecutor::InNodeThreads::ReStartAction from "
354 << Name() << " " << Automaton()->StateName( State() ) << " to "
355 << aReStartNode->ThreadNo() << " " << aReStartNode->Name() << " "
356 << Automaton()->StateName( aReStartNode->State() ) ;
357 if ( oldReStartNode ) {
358 cdebug << " oldReStartNode " << oldReStartNode->Name() << endl ;
363 return ResumeAction( GraphExecutor::ToReStartEvent ) ;
366 void GraphExecutor::InNode::KilledAction() {
367 if ( pthread_mutex_lock( &_MutexWait ) ) {
368 perror("Killed pthread_mutex_lock ") ;
372 cdebug << "pthread_cond " << Name() << " Killed pthread_cond_wait"
375 if ( pthread_cond_wait( &_KillWait , &_MutexWait ) ) {
376 perror("Killed pthread_cond_wait ") ;
378 cdebug << "pthread_cond " << Name() << " Killed pthread_cond_waited"
382 cdebug << "pthread_cond " << Name() << " NO Killed pthread_cond_wait"
386 if ( pthread_mutex_unlock( &_MutexWait ) ) {
387 perror("Killed pthread_mutex_unlock ") ;
392 void GraphExecutor::InNode::KillAction() {
393 if ( pthread_mutex_lock( &_MutexWait ) ) {
394 perror("Kill pthread_mutex_lock ") ;
398 cdebug << "pthread_cond " << Name() << " Kill pthread_cond_signal"
400 // if ( pthread_cond_broadcast( &_KillWait ) ) {
401 if ( pthread_cond_signal( &_KillWait ) ) {
402 perror("Kill pthread_cond_broadcast ") ;
404 cdebug << "pthread_cond " << Name() << " Kill pthread_cond_signaled"
408 cdebug << "pthread_cond " << Name() << " NO Kill pthread_cond_signal"
412 if ( pthread_mutex_unlock( &_MutexWait ) ) {
413 perror("Kill pthread_mutex_unlock ") ;
418 void GraphExecutor::InNode::StoppedAction() {
419 if ( pthread_mutex_lock( &_MutexWait ) ) {
420 perror("Stopped pthread_mutex_lock ") ;
423 if ( pthread_cond_wait( &_StopWait , &_MutexWait ) ) {
424 perror("Stopped pthread_cond_wait ") ;
426 if ( pthread_mutex_unlock( &_MutexWait ) ) {
427 perror("Stopped pthread_mutex_unlock ") ;
432 void GraphExecutor::InNode::StopAction() {
433 if ( pthread_mutex_lock( &_MutexWait ) ) {
434 perror("Stop pthread_mutex_lock ") ;
437 if ( pthread_cond_broadcast( &_StopWait ) ) {
438 perror("Stop pthread_cond_broadcast ") ;
440 if ( pthread_mutex_unlock( &_MutexWait ) ) {
441 perror("Stop pthread_mutex_unlock ") ;
446 void GraphExecutor::InNode::ThreadStartedAction() {
447 if ( pthread_mutex_lock( &_MutexWait ) ) {
448 perror("ThreadStarted pthread_mutex_lock ") ;
451 if ( !_ThreadStartedSync ) {
452 cdebug << "pthread_cond " << Name() << " ThreadStarted pthread_cond_wait"
454 _ThreadStartedSync = true ;
455 if ( pthread_cond_wait( &_ThreadStartedWait , &_MutexWait ) ) {
456 perror("ThreadStarted pthread_cond_wait ") ;
458 cdebug << "pthread_cond " << Name() << " ThreadStarted pthread_cond_waited"
462 cdebug << "pthread_cond " << Name() << " NO ThreadStarted pthread_cond_wait"
465 _ThreadStartedSync = false ;
466 if ( pthread_cond_signal( &_ThreadStartedWait ) ) {
467 perror("ThreadStart pthread_cond_signal ") ;
470 cdebug << "pthread_cond " << Name() << " NO ThreadStarted pthread_cond_signaled"
473 if ( pthread_mutex_unlock( &_MutexWait ) ) {
474 perror("ThreadStarted pthread_mutex_unlock ") ;
479 void GraphExecutor::InNode::ThreadStartAction() {
480 if ( pthread_mutex_lock( &_MutexWait ) ) {
481 perror("ThreadStart pthread_mutex_lock ") ;
484 if ( _ThreadStartedSync ) {
485 cdebug << "pthread_cond " << Name() << " ThreadStart pthread_cond_signal"
487 _ThreadStartedSync = false ;
488 if ( pthread_cond_signal( &_ThreadStartedWait ) ) {
489 perror("ThreadStart pthread_cond_broadcast ") ;
491 cdebug << "pthread_cond " << Name() << " ThreadStart pthread_cond_signaled"
495 cdebug << "pthread_cond " << Name() << " NO ThreadStart pthread_cond_signal"
497 _ThreadStartedSync = true ;
499 if ( pthread_cond_wait( &_ThreadStartedWait , &_MutexWait ) ) {
500 perror("ThreadStarted pthread_cond_wait ") ;
503 cdebug << "pthread_cond " << Name() << " NO ThreadStart pthread_cond_waited"
506 if ( pthread_mutex_unlock( &_MutexWait ) ) {
507 perror("ThreadStart pthread_mutex_unlock ") ;
512 int GraphExecutor::InNode::executeAction() {
513 int oldRewindStack = ( _RewindStack > MAXSTACKTHREADSIZE ) ;
514 if ( !CreateNewThread() && oldRewindStack ) {
515 cdebug << pthread_self() << "/" << ThreadNo()
516 << " executeAction start Thread _RewindStack " << _RewindStack << " > "
517 << MAXSTACKTHREADSIZE << " CreateNewThread "
518 << CreateNewThread() << " " << Automaton()->ActionName( _NextAction ) << "(" << Name() << ")"
520 CreateNewThread( true ) ;
523 if ( CreateNewThread() ) {
524 CreateNewThread( false ) ;
525 if ( ThreadNo() == 0 ) {
527 cdebug << pthread_self() << "/" << ThreadNo()
528 << " executeAction start Thread _RewindStack " << _RewindStack << " "
529 << Automaton()->ActionName( _NextAction ) << "(" << Name() << ")"
532 int pthread_sts = 1 ;
533 // _OutNode->PushEvent( NULL , GraphExecutor::NewThreadEvent ,
534 // GraphExecutor::ExecutingState ) ;
535 while ( (pthread_sts = pthread_create(&T, NULL, run_function, this )) ) {
536 char * msg = "Cannot pthread_create " ;
538 cdebug << ThreadNo() << " " << msg << " --> sleep(5)" << endl ;
539 cdebug << ThreadNo() << " PTHREAD_THREADS_MAX : "
540 << PTHREAD_THREADS_MAX << " pthread_create status : " ;
541 if ( pthread_sts == EAGAIN ) {
542 cdebug << "EAGAIN(" << pthread_sts << ")" << endl ;
543 cdebug << "It seems to me that with gdb we are limited to 256 threads because of defunct" << endl ;
546 cdebug << pthread_sts << endl ;
550 pthread_exit( msg ) ;
552 cdebug << pthread_self() << "/" << ThreadNo()
553 << "executeAction has created thread " << T << endl ;
554 ThreadStartedAction() ;
555 cdebug << pthread_self() << "/" << ThreadNo()
556 << "executeAction the thread " << T << " has called NewThread and will call ExecuteAction for node "
560 cdebug << pthread_self() << "/" << ThreadNo()
561 << " executeAction restart Thread _RewindStack " << _RewindStack << " "
562 << Automaton()->StateName( State() ) << " "
563 << Automaton()->ActionName( _NextAction ) << "(" << Name()
564 << ") ReStartAction ==>" << endl;
565 State( GraphExecutor::SuspendedSuccessedState ) ;
566 if ( !ReStartAction( this , GraphExecutor::ReStartEvent ) ) {
567 cdebug << pthread_self() << "/" << ThreadNo()
568 << " executeAction STATE & CALLED "
569 << Automaton()->ActionName( _NextAction ) << "(" << Name()
570 << ") ERROR-DEBUG " << endl;
573 cdebug << pthread_self() << "/" << ThreadNo() << " executeAction NO CALL "
574 << Automaton()->ActionName( _NextAction ) << "(" << Name()
580 if ( _CurrentEvent == ExecuteEvent ) {
583 cdebug << pthread_self() << "/" << ThreadNo() << " executeAction call "
584 << Automaton()->ActionName( _NextAction ) << "(" << Name() << ") _RewindStack " << _RewindStack
586 return ExecuteAction() ;
591 void GraphExecutor::InNode::coutbegin() {
592 cdebug << ThreadNo() << " " << pthread_self() << " run_function begin"
593 << " " << Name() << " " << Automaton()->StateName( State() ) << endl ;
595 void GraphExecutor::InNode::coutexit() {
596 cdebug << pthread_self() << "/" << ThreadNo() << " run_function pthread_exit _RewindStack " << _RewindStack
597 << " " << Name() << " " << Automaton()->StateName( State() ) << endl ;
599 void * run_function(void *p) {
600 GraphExecutor::InNode *aNode = (GraphExecutor::InNode *) p;
602 aNode->NewThread( pthread_self() ) ;
603 if ( pthread_setcanceltype( PTHREAD_CANCEL_ASYNCHRONOUS , NULL ) ) {
604 perror("pthread_setcanceltype ") ;
607 if ( pthread_setcancelstate( PTHREAD_CANCEL_ENABLE , NULL ) ) {
608 perror("pthread_setcancelstate ") ;
611 aNode->ThreadStartAction() ;
612 // cout << "run_function " << aNode->Name() << "->ExecuteAction() Coupled : " << aNode->CoupledNode()
614 aNode->ExecuteAction() ;
615 char * msg = new char[40] ;
616 sprintf( msg , "%d" , (int ) aNode->ThreadNo() ) ;
617 strcat( msg , " thread exit" ) ;
619 aNode->ExitThread() ;
622 pthread_exit( (void * ) smsg.c_str() ) ;
626 int GraphExecutor::InNode::ExecuteAction() {
629 // const char * nextactionname = Automaton()->ActionName( _NextAction ) ;
630 // const char * statename = Automaton()->StateName( State() ) ;
631 // const char * nextstatename = Automaton()->StateName( _NextState ) ;
632 // cdebug << 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() << " " << anInPort->State() << " " << anInPort->PortStatus() << 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 cout << "SomeDataReadyAction " << GraphMacroNode() << " " << GraphMacroNode()->Name()
940 << " coupled to " << GraphMacroNode()->CoupledNode() << endl ;
941 GraphExecutor::DataFlow * aMacroGraph = GraphMacroNode()->CoupledNode()->GraphEditor()->Executor() ;
942 cdebug << "SomeDataReadyAction MacroNode " << aMacroGraph->Graph()->Name() << " --> InputOfAny "
943 << InReady << "/" << GetNodeInPortsSize() << " InPorts are Ready" << endl ;
944 // GraphMacroNode()->MacroObject()->InputOfAny( anInPort->PortName() , *anOutPort->Value() ) ;
945 aMacroGraph->InputOfAny( anInPort->PortName() , *anOutPort->Value() ) ;
949 cdebug << pthread_self() << "/" << ThreadNo() << " " << Name() << " "
950 << anInPort->PortName() << " " << anInPort->PortStatus() << " is NOT Done from "
951 << anOutPort->NodeName() << " " << anOutPort->PortName() << " " << anOutPort->PortStatus() << " " ;
955 if ( InReady == GetNodeInPortsSize() ) { // All Flags != 0 :
956 res = SendEvent( GraphExecutor::AllDataReadyEvent ); // ==> Ready to execute
958 else { // At least one Flag == 0 :
959 res = SendEvent( GraphExecutor::NotAllDataReadyEvent );
962 cdebug << pthread_self() << "/" << ThreadNo()
963 << " <-- DataWaiting_SomeDataReadyAction " << Name() << endl;
968 int GraphExecutor::InNode::DataUndef_NotAllDataReadyAction() {
969 CreateNewThreadIf( false ) ;
970 // cdebug << pthread_self() << " for " << ThreadNo()
971 // << " DataUndef_NotAllDataReadyAction " << Name() << endl;
975 int GraphExecutor::InNode::DataUndef_AllDataReadyAction() {
976 // cdebug << pthread_self() << "/" << ThreadNo()
977 // << " --> DataUndef_AllDataReadyAction " << Name()
978 // << " CreateNewThreadIf " << CreateNewThreadIf() << " IsLockedDataWait "
979 // << IsLockedDataWait() ;
980 if ( IsLockedDataWait() ) {
981 cdebug << "DataUndef_AllDataReadyAction() WOULD DEAD-LOCK" << endl ;
982 return 0 ; // ==> DataUndef_AllDataReadyAction() after UnLockDataWait()
985 CreateNewThread( CreateNewThreadIf() ) ;
986 if ( !CreateNewThread() ) {
987 // cdebug << "Thread " << ThreadNo() << "-->" << pthread_self() << endl ;
988 ThreadNo( pthread_self() ) ;
990 _OutNode->PushEvent( this , GraphExecutor::AllDataReadyEvent ,
991 GraphExecutor::DataReadyState ) ;
993 SUPERV::ControlState aControl = ControlState() ;
994 switch ( aControl ) {
995 case SUPERV::VoidState : {
996 SendEvent( GraphExecutor::ExecuteEvent ) ;
999 case SUPERV::ToSuspendState : {
1000 SendEvent( GraphExecutor::SuspendEvent ) ;
1003 case SUPERV::ToSuspendStartState : {
1004 SendEvent( GraphExecutor::SuspendEvent ) ;
1007 case SUPERV::ToSuspendDoneState : {
1008 SendEvent( GraphExecutor::ExecuteEvent ) ;
1011 case SUPERV::ToKillState : {
1012 SendEvent( GraphExecutor::KillEvent ) ;
1015 case SUPERV::ToKillDoneState : {
1016 SendEvent( GraphExecutor::ExecuteEvent ) ;
1019 case SUPERV::ToStopState : {
1020 SendEvent( GraphExecutor::StopEvent ) ;
1024 cdebug << ThreadNo()
1025 << " GraphExecutor::InNodeThreads::DataUndef_AllDataReadyAction Error Undefined Control : "
1026 << aControl << endl ;
1030 // cdebug << pthread_self() << "/" << ThreadNo()
1031 // << " <-- DataUndef_AllDataReadyAction " << Name() << endl;
1035 int GraphExecutor::InNode::DataReady_SuspendAction() {
1036 cdebug << pthread_self() << "/" << ThreadNo()
1037 << "DataReady_SuspendAction --> Suspend " << Name()
1038 << " Threads " << _OutNode->Threads() << " SuspendedThreads "
1039 << _OutNode->SuspendedThreads() << endl;
1040 _OutNode->PushEvent( this , GraphExecutor::SuspendedReadyEvent ,
1041 GraphExecutor::SuspendedReadyState ) ;
1042 GraphExecutor::InNode * aReStartNode = SuspendAction() ;
1043 cdebug << pthread_self() << "/" << ThreadNo()
1044 << "DataReady_SuspendAction Resumed " << Name() << endl;
1045 if ( aReStartNode ) {
1046 _aReStartNode = NULL ;
1047 aReStartNode->SendEvent( _aReStartEvent ) ;
1050 SendEvent( GraphExecutor::ExecuteEvent ) ;
1055 int GraphExecutor::InNode::SuspendedReady_ResumeAction() {
1056 cdebug << pthread_self() << "/" << ThreadNo() << "SuspendedReady_ResumeAction "
1059 _OutNode->PushEvent( this , GraphExecutor::ResumedReadyEvent ,
1060 GraphExecutor::ResumedReadyState ) ;
1064 int GraphExecutor::InNode::DataReady_KillAction() {
1065 _OutNode->PushEvent( this , GraphExecutor::KilledReadyEvent ,
1066 GraphExecutor::KilledReadyState ) ;
1068 cdebug << pthread_self() << "/" << ThreadNo() << "DataReady_KillAction " << Name()
1069 << " will pthread_exit()" << endl;
1073 int GraphExecutor::InNode::DataReady_StopAction() {
1074 _OutNode->PushEvent( this , GraphExecutor::StoppedReadyEvent ,
1075 GraphExecutor::StoppedReadyState ) ;
1077 cdebug << pthread_self() << "/" << ThreadNo() << "DataReady_StopAction " << Name()
1078 << " will pthread_exit()" << endl;
1084 int GraphExecutor::InNode::DataReady_ExecuteAction() {
1087 // cdebug << pthread_self() << "/" << ThreadNo() << " --> DataReady_ExecuteAction "
1088 // << Name() << endl;
1089 _OutNode->PushEvent( this , GraphExecutor::ExecuteEvent ,
1090 GraphExecutor::ExecutingState ) ;
1096 SUPERV::GraphState PortState = SUPERV::ReadyState ;
1097 GraphExecutor::AutomatonState NewState = GraphExecutor::DataUndefState ;
1098 GraphExecutor::NodeEvent NewEvent = GraphExecutor::UndefinedEvent ;
1101 ServicesAnyData * InParametersList ;
1103 ServicesAnyData * OutParametersList ;
1105 nInParams = GetNodeInPortsSize() ;
1106 InParametersList = new ServicesAnyData[nInParams];
1107 InParametersSet( Err , nInParams , InParametersList ) ;
1109 nOutParams = GetNodeOutPortsSize() ;
1110 OutParametersList = new ServicesAnyData[nOutParams];
1111 InOutParametersSet( nOutParams , OutParametersList ) ;
1113 if ( !IsMacroNode() ) {
1115 Engines::Container_var myContainer ;
1116 Engines::Component_var myObjComponent ;
1117 if ( !IsFactoryNode() ) {
1118 // cdebug << ThreadNo() << "No Component : NO StartComponent & No Ping" << endl ;
1119 if ( IsComputingNode() ) {
1120 ObjInterface( true ) ;
1121 CORBA::Object_ptr obj ;
1122 InParametersList[0].Value >>= obj ;
1123 CORBA::Object_var objvar = CORBA::Object_var( obj ) ;
1124 myObjComponent = Engines::Component::_narrow( objvar ) ;
1129 else if ( CORBA::is_nil( Component() ) ) {
1130 // ostringstream astr ;
1131 // astr << "Graph " << _OutNode->Graph()->Name() << " Node " << Name()
1132 // << " : load of component " << ComponentName() << " in container "
1134 // _OutNode->Graph()->ObjImpl()->sendMessage( NOTIF_STEP, astr.str().c_str() ) ;
1135 Err = !_OutNode->Graph()->StartComponent( ThreadNo() , Computer() ,
1136 my_strdup( ComponentName() ) ,
1137 myContainer , myObjComponent ) ;
1138 ObjInterface( false ) ;
1139 SetContainer( myContainer ) ;
1140 SetComponent( myObjComponent ) ;
1143 myContainer = Container() ;
1144 myObjComponent = Component() ;
1145 // cdebug << ThreadNo() << "Component known : NO StartComponent & Ping"
1148 myObjComponent->ping() ;
1151 cdebug << "ping() catched" << endl ;
1156 if ( Err || ControlState() == SUPERV::ToKillState ||
1157 ControlState() == SUPERV::ToKillDoneState ||
1158 ControlState() == SUPERV::ToStopState ) {
1159 cdebug << ThreadNo() << "StartComponent Error or ToKillState" << endl ;
1160 MESSAGE(pthread_self() << "Executor::InNode::DataReady_ExecuteAction of " << Name()
1161 << " ControlState " << Automaton()->ControlStateName( ControlState() )
1162 << " BEFORE execution ThreadNo " << ThreadNo() ) ;
1163 IsLoading( false ) ;
1167 if ( ControlState() == SUPERV::ToSuspendState ) {
1168 cdebug << ThreadNo() << "ToSuspendState before running." << endl ;
1169 MESSAGE(ThreadNo() << "ToSuspendState before running.") ;
1172 // ostringstream astr ;
1173 // astr << "Graph " << _OutNode->Graph()->Name() << " Run of Node " << Name() ;
1174 // _OutNode->Graph()->ObjImpl()->sendMessage( NOTIF_STEP, astr.str().c_str() ) ;
1175 cdebug << ThreadNo() << " Run( '" << ServiceName() << "'" ;
1176 for ( i = 0 ; i < (int ) ServiceInParameter().length() ; i++ ) {
1177 cdebug << " , " << InParametersList[ i ].Name << "[kind"
1178 << InParametersList[ i ].Value.type()->kind() << "]" ;
1180 for ( i = 0 ; i < (int ) ServiceOutParameter().length() ; i++ ) {
1181 cdebug << " , " << OutParametersList[ i ].Name << "[kind"
1182 << OutParametersList[ i ].Value.type()->kind() << "]" ;
1184 if ( IsOneOfInLineNodes() ) {
1185 cdebug << " , PyFuncName '" << InLineNode()->PyFuncName() << "' PyRunMethod "
1186 << InLineNode()->PyRunMethod() << " length " << (*InLineNode()->PythonFunction()).length() ;
1188 cdebug << ")" << endl ;
1190 if ( IsOneOfInLineNodes() ) {
1191 bool StsPyDynInvoke = true;
1192 _OutNode->PyThreadLock() ;
1195 // if ( IsInLineNode() && (*InLineNode()->PythonFunction()).length() &&
1196 bool CopyInOut = false ;
1197 if ( IsInLineNode() && /*InLineNode()->PyRunMethod() &&*/
1198 strlen( InLineNode()->PyFuncName() ) ) {
1199 // cdebug << ThreadNo() << " !ObjInterface " << Name() << " PyFuncName '"
1200 // << InLineNode()->PyFuncName()
1201 // << "' IsInLineNode PyDynInvoke" << endl ;
1202 StsPyDynInvoke = PyDynInvoke( InLineNode()->PyRunMethod() ,
1203 InLineNode()->PyFuncName() ,
1204 &InParametersList[0] , ServiceInParameter().length() ,
1205 &OutParametersList[0] , ServiceOutParameter().length() ) ;
1207 else if ( IsLoopNode() ) {
1208 bool CopyOutIn = false ;
1209 if ( GetNodeInLoop()->GetOutPort()->BoolValue() && /*InLineNode()->PyRunMethod() &&*/
1210 strlen( InLineNode()->PyFuncName() ) ) { // InLoop Port
1211 // cdebug << ThreadNo() << " !ObjInterface " << Name()
1212 // << " IsLoopNode PyDynInvoke '" << InLineNode()->PyFuncName()
1214 StsPyDynInvoke = PyDynInvoke( InLineNode()->PyRunMethod() ,
1215 InLineNode()->PyFuncName() ,
1216 &InParametersList[1] , ServiceInParameter().length() ,
1217 &OutParametersList[1] , ServiceOutParameter().length() ) ;
1220 else if ( LoopNode()->PyNextMethod() &&
1221 strlen( LoopNode()->PyNextName() ) ){
1222 // cdebug << ThreadNo() << " !ObjInterface " << Name()
1223 // << " IsLoopNode PyDynInvoke '" << LoopNode()->PyNextName()
1225 StsPyDynInvoke = PyDynInvoke( LoopNode()->PyNextMethod() ,
1226 LoopNode()->PyNextName() ,
1227 &InParametersList[1] , ServiceInParameter().length() ,
1228 &OutParametersList[1] , ServiceOutParameter().length() ) ;
1231 if ( StsPyDynInvoke && CopyOutIn ) {
1232 // cdebug << ThreadNo() << " !ObjInterface " << Name()
1233 // << " IsLoopNode PyDynInvoke '" << LoopNode()->PyMoreName()
1234 // << "' Copy of " << ServiceInParameter().length()
1235 // << " OutParameters" << endl ;
1237 for ( i = 1 ; i <= (int ) ServiceInParameter().length() ; i++ ) {
1238 InParametersList[i].Value = OutParametersList[i].Value ;
1239 InParametersList[i].Name = OutParametersList[i].Name ;
1241 switch ( InParametersList[i].Value.type()->kind() ) {
1242 case CORBA::tk_string :
1244 InParametersList[i].Value >>= t ;
1245 cdebug << "ArgOut->In" << i << " : "
1246 << InParametersList[i].Name.c_str()
1247 << " Value(string) " << t << endl ;
1249 case CORBA::tk_double :
1251 InParametersList[i].Value >>= d;
1252 cdebug << "ArgOut->In" << i << " : "
1253 << InParametersList[i].Name.c_str()
1254 << " Value(double) " << d << endl ;
1256 case CORBA::tk_long :
1258 InParametersList[i].Value >>= l;
1259 cdebug << "ArgOut->In" << i << " : "
1260 << InParametersList[i].Name.c_str()
1261 << " Value(long) " << l << endl ;
1263 case CORBA::tk_objref :
1264 CORBA::Object_ptr obj ;
1267 InParametersList[i].Value >>= obj ;
1268 retstr = ObjectToString( obj );
1269 cdebug << "ArgOut->In" << i << " : "
1270 << InParametersList[i].Name.c_str()
1271 << " Value(object reference) " << retstr << endl ;
1274 cdebug << "ArgOut->In" << i << " : "
1275 << InParametersList[i].Name.c_str()
1276 << " Value(object reference) Catched ERROR" << endl ;
1280 cdebug << "ArgOut->In" << i << " : "
1281 << InParametersList[i].Name.c_str()
1282 << " Value(other) ERROR" << endl ;
1286 if ( LoopNode()->PyMoreMethod() && strlen( LoopNode()->PyMoreName() ) ) {
1287 StsPyDynInvoke = PyDynInvoke( LoopNode()->PyMoreMethod() ,
1288 LoopNode()->PyMoreName() ,
1289 &InParametersList[1] , ServiceInParameter().length() ,
1290 &OutParametersList[0] , ServiceOutParameter().length()+1 ) ;
1296 else if ( !StsPyDynInvoke ) {
1298 cdebug << ThreadNo() << " InLineNode " << Name() << " "
1299 << InLineNode()->PyFuncName() << "/" << LoopNode()->PyNextName()
1300 << " Python Dynamic Call Error"
1304 else if ( IsSwitchNode() && /*InLineNode()->PyRunMethod() &&*/
1305 strlen( InLineNode()->PyFuncName() ) ) {
1306 // cdebug << ThreadNo() << " !ObjInterface " << Name() << " PyFuncName '"
1307 // << InLineNode()->PyFuncName()
1308 // << "' IsSwitchNode PyDynInvoke" << endl ;
1309 StsPyDynInvoke = PyDynInvoke( InLineNode()->PyRunMethod() ,
1310 InLineNode()->PyFuncName() ,
1311 &InParametersList[0] , ServiceInParameter().length() ,
1312 &OutParametersList[0] , ServiceOutParameter().length() ) ;
1314 // else if ( IsGOTONode() && (*GOTONode()->PythonFunction()).length() &&
1315 else if ( IsGOTONode() && /*InLineNode()->PyRunMethod() &&*/
1316 strlen( InLineNode()->PyFuncName() ) ) {
1317 // cdebug << ThreadNo() << " !ObjInterface " << Name() << " PyFuncName '"
1318 // << InLineNode()->PyFuncName()
1319 // << "' IsGOTONode PyDynInvoke" << endl ;
1320 StsPyDynInvoke = PyDynInvoke( InLineNode()->PyRunMethod() ,
1321 InLineNode()->PyFuncName() ,
1322 &InParametersList[0] , ServiceInParameter().length() ,
1323 &OutParametersList[0] , ServiceOutParameter().length() ) ;
1325 // else if ( IsEndSwitchNode() && (*InLineNode()->PythonFunction()).length() &&
1326 else if ( ( IsEndSwitchNode() ) &&
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() ,
1334 &OutParametersList[0] , ServiceOutParameter().length() ) ;
1336 else if ( ( IsEndLoopNode() ) &&
1337 InLineNode()->PyRunMethod() && strlen( InLineNode()->PyFuncName() ) ) {
1338 // cdebug << ThreadNo() << " !ObjInterface " << Name() << " PyFuncName '"
1339 // << InLineNode()->PyFuncName()
1340 // << "' IsSwitchNode PyDynInvoke" << endl ;
1341 StsPyDynInvoke = PyDynInvoke( InLineNode()->PyRunMethod() ,
1342 InLineNode()->PyFuncName() ,
1343 &InParametersList[0] , ServiceInParameter().length() + 1 ,
1344 &OutParametersList[0] , ServiceOutParameter().length() + 1 ) ;
1346 // else if ( (*InLineNode()->PythonFunction()).length() == 0 ||
1347 if ( InLineNode()->PyRunMethod() == NULL ||
1348 strlen( InLineNode()->PyFuncName() ) == 0 || CopyInOut ) {
1349 // cdebug << ThreadNo() << " !ObjInterface " << Name()
1350 // << " Copy of " << ServiceInParameter().length()
1351 // << " OutParameters" << endl ;
1355 if ( IsLoopNode() || IsEndLoopNode() ) {
1357 argin0 = 1 ; // after DoLoop
1358 if ( IsLoopNode() ) {
1359 OutParametersList[0].Value = InParametersList[0].Value ; // DoLoop
1362 for ( i = 0 ; i < (int ) ServiceInParameter().length() ; i++ ) {
1363 OutParametersList[argout0 + i].Value = InParametersList[argin0 + i].Value ;
1365 switch ( InParametersList[argin0 + i].Value.type()->kind() ) {
1366 case CORBA::tk_string :
1367 cdebug << "ArgOut->In" << argin0 + i << " : "
1368 << InParametersList[argin0 + i].Name.c_str()
1369 << " Value(string) "
1370 << OutParametersList[argout0 + i].Name.c_str() << endl ;
1372 case CORBA::tk_double :
1373 cdebug << "ArgOut->In" << argin0 + i << " : "
1374 << InParametersList[argin0 + i].Name.c_str()
1375 << " Value(double) "
1376 << OutParametersList[argout0 + i].Name.c_str() << endl ;
1378 case CORBA::tk_long :
1379 cdebug << "ArgOut->In" << argin0 + i << " : "
1380 << InParametersList[argin0 + i].Name.c_str()
1382 << OutParametersList[argout0 + i ].Name.c_str() << endl ;
1384 case CORBA::tk_objref :
1385 cdebug << "ArgOut->In" << argin0 + i << " : "
1386 << InParametersList[argin0 + i].Name.c_str()
1387 << " Value(object reference) "
1388 << OutParametersList[argout0 + i].Name.c_str() << endl ;
1391 cdebug << "ArgOut->In" << argin0 + i << " : "
1392 << InParametersList[argin0 + i].Name.c_str()
1393 << " Value(other) ERROR "
1394 << OutParametersList[argout0 + i].Name.c_str() << endl ;
1399 if ( !StsPyDynInvoke ) {
1401 cdebug << ThreadNo() << " InLineNode " << Name()
1402 << " Python Dynamic Call Error"
1408 cdebug << ThreadNo() << " InLineNode " << Name()
1409 << " Python Dynamic Call Exception catched ERROR"
1413 _OutNode->PyThreadUnLock() ;
1418 cdebug << "DynInvoke -> Names " << _OutNode->Graph()->Name() << " " << Name() << endl ;
1419 DynInvoke( myObjComponent, "Names" ,
1420 _OutNode->Graph()->Name() , Name() ) ;
1423 cdebug << "DynInvoke Names catched ERROR" << endl ;
1425 // for DataStreamNodes : call of SetProperties ===> environment variables in the component/container
1426 if ( ComputingNode()->HasDataStream() ) {
1428 cdebug << "DynInvoke -> SetProperties " << _OutNode->Graph()->Name() << " " << Name() << endl ;
1429 Engines::FieldsDict_var dict = new Engines::FieldsDict;
1431 dict[ 0 ].key = CORBA::string_dup( "CAL_MACHINE");
1432 // myContainer->getHostName() ne renvoit pas le nom complet (avec domaine).
1433 // dict[ 0 ].value <<= myContainer->getHostName() ;
1434 char FullyQualifiedDomainName[256]="";
1435 gethostname(FullyQualifiedDomainName,255);
1436 dict[ 0 ].value <<= FullyQualifiedDomainName ;
1437 dict[ 1 ].key = CORBA::string_dup( "CAL_REPERTOIRE");
1438 dict[ 1 ].value <<= "/tmp" ;
1439 dict[ 2 ].key = CORBA::string_dup( "CAL_COUPLAGE");
1440 stringstream ofst1 ;
1441 ofst1 << ComputingNode()->SubStreamGraph() ;
1442 string cpl = string( "/tmp/" ) + string( _OutNode->Graph()->Name() ) + string( "_" ) +
1443 ofst1.str() + string( ".cpl" );
1444 dict[ 2 ].value <<= cpl.c_str() ;
1445 dict[ 3 ].key = CORBA::string_dup( "SALOME_INSTANCE_NAME");
1446 string uname = Name();
1448 dict[ 3 ].value <<= uname.c_str() ;
1450 myObjComponent->setProperties( dict ) ;
1453 cdebug << "DynInvoke setProperties catched ERROR" << endl ;
1457 if ( !Err && IsComputingNode() ) {
1458 cdebug << ThreadNo() << " !ObjInterface " << Name()
1459 << " IsComputingNode DynInvoke" << endl ;
1460 cdebug << ServiceInParameter().length()-1 << " input parameters and "
1461 << ServiceOutParameter().length() << " output parameters" << endl ;
1462 IsLoading( false ) ;
1463 DynInvoke( myObjComponent,
1465 &InParametersList[1] , ServiceInParameter().length()-1 ,
1466 &OutParametersList[0] , ServiceOutParameter().length() ) ;
1468 else if ( !Err &&IsFactoryNode() ) {
1469 cdebug << ThreadNo() << " !ObjInterface " << Name()
1470 << " IsFactoryNode DynInvoke" << endl ;
1471 cdebug << ServiceInParameter().length() << " input parameters and "
1472 << ServiceOutParameter().length() << " output parameters" << endl ;
1473 IsLoading( false ) ;
1474 DynInvoke( myObjComponent,
1476 &InParametersList[0] , ServiceInParameter().length() ,
1477 &OutParametersList[0] , ServiceOutParameter().length() ) ;
1479 // cdebug << ThreadNo() << " Component::CpuUsed " << Name() << " "
1480 // << myObjComponent->CpuUsed_impl() << endl ;
1484 cdebug << ThreadNo() << " !ObjInterface " << Name()
1485 << " Node(Component) Dynamic Call Exception catched ERROR"
1496 // ostringstream astr ;
1497 // astr << "Graph " << _OutNode->Graph()->Name() << " Node " << Name() << " is done : "
1498 // << Automaton()->StateName( State() ) ;
1499 // _OutNode->Graph()->ObjImpl()->sendMessage( NOTIF_STEP, astr.str().c_str() ) ;
1501 if ( ControlState() == SUPERV::ToKillState ||
1502 ControlState() == SUPERV::ToKillDoneState ||
1503 ControlState() == SUPERV::ToStopState ) {
1504 PortState = SUPERV::ErrorState ;
1505 NewState = GraphExecutor::KilledState ;
1506 NewEvent = GraphExecutor::KillEvent ;
1509 PortState = SUPERV::ErrorState ;
1510 NewState = GraphExecutor::ErroredState ;
1511 NewEvent = GraphExecutor::ErrorEvent ;
1515 PortState = SUPERV::ReadyState ;
1516 NewState = GraphExecutor::DataReadyState ;
1517 NewEvent = GraphExecutor::SuccessEvent ;
1520 if ( !IsMacroNode() ) {
1521 bool ErrOut = OutParametersSet( Err , PortState , nOutParams , OutParametersList ) ;
1523 NewEvent = GraphExecutor::ErrorEvent ;
1525 delete [] InParametersList ;
1526 delete [] OutParametersList ;
1529 if ( !IsMacroNode() ) {
1530 SendEvent( NewEvent ) ;
1533 GraphExecutor::DataFlow * aMacroGraph = GraphMacroNode()->CoupledNode()->GraphEditor()->Executor() ;
1534 cdebug << ThreadNo() << " DataReady_ExecuteAction " << aMacroGraph << " "
1535 << aMacroGraph->Graph()->Name() << " ->DoneWait()"
1536 << " State " << aMacroGraph->State() << endl;
1537 aMacroGraph->DoneWait() ;
1538 cdebug << ThreadNo() << " DataReady_ExecuteAction " << Name() << " State " << aMacroGraph->State() << endl;
1539 if ( aMacroGraph->State() == SUPERV::DoneState ) {
1540 PortState = SUPERV::ReadyState ;
1541 NewState = GraphExecutor::DataReadyState ;
1542 NewEvent = GraphExecutor::SuccessEvent ;
1546 if ( ControlState() == SUPERV::ToKillState ||
1547 ControlState() == SUPERV::ToKillDoneState ||
1548 ControlState() == SUPERV::ToStopState ) {
1549 PortState = SUPERV::ErrorState ;
1550 NewState = GraphExecutor::KilledState ;
1551 NewEvent = GraphExecutor::KillEvent ;
1554 PortState = SUPERV::ErrorState ;
1555 NewState = GraphExecutor::ErroredState ;
1556 NewEvent = GraphExecutor::ErrorEvent ;
1559 bool ErrOut = OutParametersSet( Err , PortState , nOutParams , OutParametersList ) ;
1561 NewEvent = GraphExecutor::ErrorEvent ;
1563 delete [] InParametersList ;
1564 delete [] OutParametersList ;
1565 SendEvent( NewEvent ) ;
1568 // cdebug << ThreadNo() << " <-- DataReady_ExecuteAction " << Name() << endl;
1572 int GraphExecutor::InNode::Executing_SuspendAction() {
1573 _OutNode->PushEvent( this , GraphExecutor::SuspendedExecutingEvent ,
1574 GraphExecutor::SuspendedExecutingState ) ;
1575 cdebug << ThreadNo() << " Executing_SuspendAction " << Name() << endl;
1579 int GraphExecutor::InNode::SuspendedExecuting_ResumeAction() {
1580 cdebug << ThreadNo() << " SuspendedExecuting_ResumeAction " << Name() << endl;
1581 GraphExecutor::AutomatonState next_state ;
1582 next_state = Automaton()->NextState( State() , GraphExecutor::ExecutingEvent ) ;
1583 _OutNode->NewThread() ; // Only for Threads count
1584 _OutNode->PushEvent( this , GraphExecutor::ResumedExecutingEvent ,
1586 State( next_state ) ;
1590 int GraphExecutor::InNode::Executing_KillAction() {
1591 cdebug << ThreadNo() << " Executing_KillAction " << Name() << " Thread " << ThreadNo()<< endl;
1593 if ( pthread_self() == ThreadNo() ) {
1594 cdebug << "Executing_KillAction would pthread_canceled itself" << endl ;
1596 _OutNode->PushEvent( this , GraphExecutor::KilledExecutingEvent ,
1597 GraphExecutor::KilledExecutingState ) ;
1600 else if ( pthread_cancel( ThreadNo() ) ) {
1601 perror("Executing_KillAction pthread_cancel error") ;
1604 cdebug << pthread_self() << " Executing_KillAction : ThreadId " << ThreadNo()
1605 << " pthread_canceled" << endl ;
1607 _OutNode->ExitThread( ThreadNo() ) ;
1608 _OutNode->PushEvent( this , GraphExecutor::KilledExecutingEvent ,
1609 GraphExecutor::KilledExecutingState ) ;
1614 int GraphExecutor::InNode::Executing_StopAction() {
1615 cdebug << ThreadNo() << " Executing_StopAction " << Name() << " Thread " << ThreadNo() << endl;
1617 if ( pthread_cancel( ThreadNo() ) ) {
1618 perror("Executing_KillAction pthread_cancel error") ;
1621 cdebug << pthread_self() << " Executing_KillAction : ThreadId " << ThreadNo()
1622 << " pthread_canceled" << endl ;
1624 _OutNode->ExitThread( ThreadNo() ) ;
1625 _OutNode->PushEvent( this , GraphExecutor::StoppedExecutingEvent ,
1626 GraphExecutor::StoppedExecutingState ) ;
1631 int GraphExecutor::InNode::Executing_SuccessAction() {
1632 // cdebug << ThreadNo() << " --> Executing_SuccessAction " << Name() << endl;
1633 _OutNode->PushEvent( this , GraphExecutor::SuccessedExecutingEvent ,
1634 GraphExecutor::SuccessedState ) ;
1635 MESSAGE(pthread_self() << "Executor::InNode::Executing_SuccessAction of " << Name()
1636 << " ControlState " << Automaton()->ControlStateName( ControlState() )
1637 << " AFTER execution ThreadNo " << ThreadNo() ) ;
1638 SUPERV::ControlState aControl = ControlState() ;
1639 switch ( aControl ) {
1640 case SUPERV::VoidState : {
1641 SendEvent( SuccessEvent ) ;
1644 case SUPERV::ToSuspendState : {
1645 SendEvent( SuccessEvent ) ;
1648 case SUPERV::ToSuspendDoneState : {
1649 SendEvent( GraphExecutor::SuspendEvent ) ;
1652 case SUPERV::ToKillState : {
1653 SendEvent( GraphExecutor::KillEvent ) ;
1656 case SUPERV::ToKillDoneState : {
1657 SendEvent( GraphExecutor::KillEvent ) ;
1660 case SUPERV::ToStopState : {
1661 SendEvent( GraphExecutor::StopEvent ) ;
1665 cdebug << ThreadNo()
1666 << " GraphExecutor::InNodeThreads::Executing_SuccessAction Error Undefined Control : "
1667 << aControl << endl ;
1671 // cdebug << ThreadNo() << " <-- Executing_SuccessAction " << Name() << endl;
1675 int GraphExecutor::InNode::Executing_ErrorAction() {
1676 cdebug << ThreadNo() << " --> Executing_ErrorAction " << Name() << endl;
1677 _OutNode->PushEvent( this , GraphExecutor::ErroredExecutingEvent ,
1678 GraphExecutor::ErroredState ) ;
1680 SUPERV::ControlState aControl = ControlState() ;
1681 switch ( aControl ) {
1682 case SUPERV::VoidState : {
1683 SendEvent( ErrorEvent ) ;
1686 case SUPERV::ToSuspendState : {
1687 SendEvent( ErrorEvent ) ;
1690 case SUPERV::ToSuspendDoneState : {
1691 SendEvent( GraphExecutor::SuspendEvent ) ;
1694 case SUPERV::ToKillState : {
1695 SendEvent( GraphExecutor::KillEvent ) ;
1698 case SUPERV::ToKillDoneState : {
1699 SendEvent( GraphExecutor::KillEvent ) ;
1702 case SUPERV::ToStopState : {
1703 SendEvent( GraphExecutor::StopEvent ) ;
1707 cdebug << ThreadNo()
1708 << " GraphExecutor::InNodeThreads::Executing_ErrorAction Error Undefined Control : "
1709 << aControl << endl ;
1713 cdebug << ThreadNo() << " <-- Executing_ErrorAction " << Name() << endl;
1717 // Set SUPERV::WaitingState to all InPorts
1718 void GraphExecutor::InNode::SetWaitingStates(GraphExecutor::InNode * EndNode ) {
1721 bool docdebug = false ;
1722 State( GraphExecutor::DataWaitingState ) ;
1723 for ( i = 0 ; i < GetNodeInPortsSize() ; i++ ) {
1724 GraphBase::InPort * anInPort = GetChangeNodeInPort( i ) ;
1725 if ( anInPort->IsGate() ) { // Loop : Open the doors
1726 GraphBase::OutPort * anOutPort = anInPort->GetOutPort() ;
1728 CORBA::Any * anAny = new CORBA::Any() ;
1729 *anAny <<= (long ) 1 ;
1730 anOutPort->Value( anAny ) ;
1731 anInPort->State( SUPERV::ReadyState ) ;
1734 else if ( anInPort->State() != SUPERV::WaitingState ) {
1736 cdebug << ThreadNo()
1737 << " --> GraphExecutor::InNodeThreads::SetWaitingStates " << Name() << endl;
1740 if ( !anInPort->IsDataStream() ) {
1741 anInPort->State( SUPERV::WaitingState ) ;
1745 for ( i = 0 ; i < GetNodeOutPortsSize() ; i++ ) {
1746 GraphBase::OutPort * anOutPort = GetChangeNodeOutPort( i ) ;
1747 for ( j = 0 ; j < anOutPort->InPortsSize() ; j++ ) {
1748 if ( !( IsGOTONode() && anOutPort->IsGate() ) &&
1749 !( IsEndLoopNode() && ( anOutPort->IsGate() ||
1750 anOutPort->IsLoop() ) ) &&
1751 !anOutPort->IsDataStream() &&
1752 !anOutPort->ChangeInPorts( j )->IsDataStream() &&
1753 !anOutPort->ChangeInPorts( j )->IsExternConnected() ) {
1754 cdebug << ThreadNo()
1755 << " InNodeThreads::SetWaitingStates OutPort "
1756 << Name() << "/" << anOutPort->ChangeInPorts( j )->NodeName() << "( "
1757 << anOutPort->PortName() << " " << anOutPort->PortStatus() << " ) --> InPort "
1758 << anOutPort->ChangeInPorts( j )->NodeName() << "( "
1759 << anOutPort->ChangeInPorts( j )->PortName() << " "
1760 << anOutPort->ChangeInPorts( j )->PortStatus() << " )" << endl;
1761 if ( strcmp( anOutPort->ChangeInPorts( j )->GetOutPort()->NodeName() , Name() ) ) {
1762 // After EndLoopNode or GOTONode the Input Ports of LoopNode or LabelNode have their values from
1763 // EndLoopNode or GOTONode. But if there is several nested loops we should re-establish.
1764 cdebug << ThreadNo()
1765 << " InNodeThreads::SetWaitingStates OutPort->ChangeInPorts( j )->OutPort()->NodeName "
1766 << anOutPort->ChangeInPorts( j )->GetOutPort()->NodeName() << " != "
1767 << Name() << " : Restored to " << anOutPort->NodeName() << "( "
1768 << anOutPort->PortName() << " )" << endl ;
1769 anOutPort->ChangeInPorts( j )->ChangeOutPort( anOutPort ) ;
1771 GraphExecutor::InNode * aNode = (GraphExecutor::InNode * ) _OutNode->Graph()->GetChangeGraphNode( anOutPort->ChangeInPorts( j )->NodeName() )->GetInNode() ;
1772 if ( aNode != EndNode ) {
1773 aNode->SetWaitingStates( EndNode ) ;
1780 int GraphExecutor::InNode::Successed_SuccessAction() {
1781 cdebug << ThreadNo() << " --> Successed_SuccessAction " << Name() << endl;
1783 int linkednodesnumber = LinkedNodesSize() ;
1784 GraphExecutor::InNode *firstzeroNode = NULL ;
1785 GraphExecutor::InNode *firsttoNode = NULL ;
1786 GraphExecutor::InNode *toNode ;
1789 list<GraphExecutor::InNode *> SomeDataNodes ;
1793 if ( IsMacroNode() ) {
1794 cdebug << ThreadNo() << " Successed_SuccessAction " << Name() << " LinkedNodes->SomeDataReady already done"
1799 if ( IsGOTONode() ||
1800 ( IsEndLoopNode() && GetNodeInLoop()->GetOutPort()->BoolValue() ) ) {
1801 cdebug << ThreadNo() << " Successed_SuccessAction " << Name()
1802 << " SetWaitingStates " << endl ;
1803 const GraphBase::OutPort * aGateOutPort ;
1804 if ( IsGOTONode() ) {
1805 aGateOutPort = GetNodeOutGate() ;
1808 aGateOutPort = GetNodeOutLoop() ;
1810 for ( i = 0 ; i < aGateOutPort->InPortsSize() ; i++ ) {
1811 const GraphBase::InPort * anInPort = aGateOutPort->InPorts( i ) ;
1812 GraphExecutor::InNode * aLabelNode = (GraphExecutor::InNode *) _OutNode->Graph()->GetChangeGraphNode( anInPort->NodeName() )->GetInNode() ;
1813 cdebug << ThreadNo() << " Successed_SuccessAction " << Name() << " will Loop to HeadNode "
1814 << aLabelNode->Name() << " from port " << anInPort->PortName() << endl ;
1815 aLabelNode->SetWaitingStates( this ) ;
1816 for ( j = 0 ; j < aLabelNode->GetNodeInPortsSize() ; j++ ) {
1817 const GraphBase::InPort * anInPort = aLabelNode->GetNodeInPort( j ) ;
1818 if ( anInPort->GetOutPort() ) {
1819 cdebug << aLabelNode->Name() << "(" << anInPort->PortName() << ") value : "
1820 << anInPort->GetOutPort()->NodeName() << "(" << anInPort->GetOutPort()->PortName() << ")"
1824 for ( j = 0 ; j < GetNodeOutPortsSize() ; j++ ) {
1825 GraphBase::OutPort * aBusParamOutPort = GetChangeNodeOutPort( j ) ;
1826 if ( !aBusParamOutPort->IsGate() ) {
1827 GraphBase::InPort * aBusParamChangeInPort = NULL ;
1828 if ( aBusParamOutPort->IsLoop() ) {
1829 aBusParamChangeInPort = aLabelNode->GetChangeNodeInLoop() ;
1832 aBusParamChangeInPort = aLabelNode->GetChangeInPort( aBusParamOutPort->PortName() ) ;
1834 if ( aBusParamChangeInPort ) {
1835 aBusParamChangeInPort->ChangeOutPort( aBusParamOutPort ) ;
1836 cdebug << ThreadNo() << " Successed_SuccessAction " << Name() << " ChangeOutPort to HeadNode "
1837 << aLabelNode->Name() << "(" << aBusParamChangeInPort->PortName() << ") from port "
1838 << aBusParamOutPort->PortName() << endl ;
1839 if ( !aLabelNode->IsLockedDataWait() ) {
1840 res = aLabelNode->SendSomeDataReady( Name() ) ;
1842 if ( firsttoNode == NULL &&
1843 aLabelNode->ThreadNo() == pthread_self() ) {
1844 firsttoNode = aLabelNode ;
1845 cdebug << ThreadNo() << " Successed_SuccessAction firsttoNode "
1846 << aLabelNode->Name() << endl ;
1848 else if ( firstzeroNode == NULL &&
1849 aLabelNode->ThreadNo() == 0 ) {
1850 firstzeroNode = aLabelNode ;
1853 SomeDataNodes.push_back( aLabelNode ) ;
1854 cdebug << ThreadNo() << " Successed_SuccessAction " << Name() << " push "
1855 << aLabelNode->Name() << " " << SomeDataNodes.size()
1861 cdebug << ThreadNo()
1862 << " Successed_SuccessAction Loop to HeadNode "
1863 << aLabelNode->Name() << " with datas from " << Name() << "("
1864 << aBusParamOutPort->PortName() << ") to port "
1865 << aBusParamChangeInPort->PortName() << endl;
1869 cdebug << ThreadNo() << " ERROR in Successed_SuccessAction of " << Name()
1870 << " NO port " << aBusParamOutPort->PortName() << " in "
1871 << aLabelNode->Name() << endl;
1875 for ( j = 0 ; j < aLabelNode->GetNodeInPortsSize() ; j++ ) {
1876 const GraphBase::InPort * anInPort = aLabelNode->GetNodeInPort( j ) ;
1877 if ( anInPort->GetOutPort() ) {
1878 cdebug << aLabelNode->Name() << "(" << anInPort->PortName() << ") value : "
1879 << anInPort->GetOutPort()->NodeName() << "(" << anInPort->GetOutPort()->PortName() << ")"
1883 const GraphBase::InPort * aGateInPort = aLabelNode->GetNodeInGate() ;
1884 if ( aGateInPort ) {
1885 if ( aGateInPort->GetOutPort() ) {
1886 aGateInPort->GetOutPort()->Value( aGateOutPort->Value() ) ;
1888 if ( !aLabelNode->IsLockedDataWait() ) {
1889 res = aLabelNode->SendSomeDataReady( Name() ) ;
1891 if ( firsttoNode == NULL &&
1892 aLabelNode->ThreadNo() == pthread_self() ) {
1893 firsttoNode = aLabelNode ;
1894 cdebug << ThreadNo() << " Successed_SuccessAction firsttoNode "
1895 << aLabelNode->Name() << endl ;
1897 else if ( firstzeroNode == NULL &&
1898 aLabelNode->ThreadNo() == 0 ) {
1899 firstzeroNode = aLabelNode ;
1902 SomeDataNodes.push_back( aLabelNode ) ;
1903 cdebug << ThreadNo() << " Successed_SuccessAction " << Name() << " push "
1904 << aLabelNode->Name() << " " << SomeDataNodes.size()
1911 cdebug << ThreadNo() << " ERROR in Successed_SuccessAction of " << Name()
1912 << " NO port " << aGateOutPort->PortName() << " in "
1913 << aLabelNode->Name() << endl;
1919 cdebug << ThreadNo() << " Successed_SuccessAction of " << Name()
1920 << " with " << LinkedNodesSize() << " linked nodes :" ;
1921 for ( i = 0 ; i < LinkedNodesSize() ; i++ ) {
1922 if ( LinkedNodes( i )->IsDataFlowNode() ) {
1923 linkednodesnumber -= 1 ;
1925 cdebug << " " << LinkedNodes( i )->Name() ;
1928 for ( i = 0 ; i < LinkedNodesSize() ; i++ ) {
1929 bool IgnoreForEndLoop = false ;
1930 GraphBase::ComputingNode * aComputingNode ;
1931 aComputingNode = (GraphBase::ComputingNode * ) LinkedNodes( i ) ;
1932 toNode = (GraphExecutor::InNode *) aComputingNode->GetInNode() ;
1933 cdebug << ThreadNo() << " Successed_SuccessAction of " << Name()
1934 << " [" << i << "] " << LinkedNodes( i )->Name() << " toNode " << toNode << " IgnoreForEndLoop "
1935 << IgnoreForEndLoop ;
1937 cdebug << " " << toNode->Kind() << endl ;
1939 if ( toNode && !toNode->IsDataFlowNode() ) {
1940 if ( IsComputingNode() && toNode->IsInLineNode() ) {
1941 GraphBase::InPort * toGateInPort = toNode->GetChangeNodeInGate() ;
1942 toGateInPort->State( SUPERV::ReadyState ) ;
1943 GraphBase::OutPort * GateOutPort = toGateInPort->GetOutPort() ;
1944 if ( GateOutPort ) {
1945 GateOutPort->PortStatus( DataConnected );
1946 GateOutPort->State( SUPERV::ReadyState ) ;
1947 GateOutPort->Done( true ) ;
1951 if ( toNode && IsLoopNode() ) {
1952 GraphBase::OutPort * fromLoopOutPort = GetChangeNodeOutLoop() ;
1953 if ( !fromLoopOutPort->BoolValue() ) { // Ne pas faire la boucle
1954 if ( strcmp( toNode->Name() , CoupledNode()->Name() ) ) {
1955 IgnoreForEndLoop = true ;
1957 else { // toNode is the EndLoopNode
1958 GraphBase::InPort * toLoopInPort ;
1959 toLoopInPort = toNode->GetChangeNodeInLoop() ;
1960 if ( toLoopInPort->State() != SUPERV::ReadyState ) {
1961 toLoopInPort->State( SUPERV::ReadyState ) ;
1966 else if ( toNode && IsSwitchNode() ) {
1968 else if ( toNode && toNode->IsInLineNode() ) {
1970 for ( j = 0 ; j < toNode->GetNodeInPortsSize() ; j++ ) {
1971 toNode->GetChangeNodeInPort( j )->InitialOutPort() ;
1974 if ( toNode && !IgnoreForEndLoop ) {
1975 if ( toNode && toNode->IsLoopNode() ) {
1976 GraphBase::InPort * toLoopInPort = toNode->GetChangeNodeInLoop() ;
1977 toLoopInPort->State( SUPERV::ReadyState ) ;
1978 GraphBase::OutPort * LoopOutPort = toLoopInPort->GetOutPort() ;
1979 LoopOutPort->PortStatus( DataConnected );
1980 LoopOutPort->State( SUPERV::ReadyState ) ;
1981 LoopOutPort->Done( true ) ;
1982 CORBA::Any * anAny = new CORBA::Any() ;
1983 *anAny <<= (long ) 1 ;
1984 LoopOutPort->Value( anAny ) ;
1986 for ( j = 0 ; j < toNode->GetNodeInPortsSize() ; j++ ) {
1987 toNode->GetChangeNodeInPort( j )->InitialOutPort() ;
1990 cdebug << ThreadNo() << " Successed_SuccessAction " << toNode->Name() << "->SendSomeDataReady( "
1991 << Name() << " )" << endl ;
1992 res = toNode->SendSomeDataReady( Name() ) ;
1994 if ( firsttoNode == NULL &&
1995 toNode->ThreadNo() == pthread_self() ) {
1996 firsttoNode = toNode ;
1997 cdebug << ThreadNo() << " Successed_SuccessAction firsttoNode "
1998 << toNode->Name() << endl ;
2000 else if ( firstzeroNode == NULL &&
2001 toNode->ThreadNo() == 0 ) {
2002 firstzeroNode = toNode ;
2005 SomeDataNodes.push_back( toNode ) ;
2006 cdebug << ThreadNo() << " Successed_SuccessAction " << Name() << " push "
2007 << toNode->Name() << " " << SomeDataNodes.size() << endl ;
2014 if ( firsttoNode == NULL && firstzeroNode ) {
2015 firsttoNode = firstzeroNode ;
2016 cdebug << ThreadNo()
2017 << " Successed_SuccessAction firsttoNode = firstzeroNode "
2020 else if ( firsttoNode && firstzeroNode ) {
2021 SomeDataNodes.push_back( firstzeroNode ) ;
2022 cdebug << ThreadNo() << " Successed_SuccessAction " << Name() << " push firstzeroNode "
2023 << firstzeroNode->Name() << " " << SomeDataNodes.size() << endl ;
2026 cdebug << ThreadNo() << " Successed_SuccessAction " << Name() << " firsttoNode " << firsttoNode
2027 << " firstzeroNode " << firstzeroNode << endl ;
2030 while ( SomeDataNodes.size() ) {
2031 GraphExecutor::InNode *aNode = SomeDataNodes.front() ;
2032 SomeDataNodes.pop_front() ;
2033 // cdebug << pthread_self() << "/" << ThreadNo()
2034 // << " Successed_SuccessAction pop "
2035 // << SomeDataNodes.size() << " " << aNode->Name() << endl ;
2036 if ( aNode->State() == GraphExecutor::DataReadyState ) {
2037 aNode->CreateNewThreadIf( true ) ;
2038 aNode->UnLockDataWait() ;
2039 res = aNode->DataUndef_AllDataReadyAction() ;
2042 // cdebug << pthread_self() << "/" << ThreadNo() << " ERROR "
2043 // << aNode->Name() << " "
2044 // << Automaton()->StateName( aNode->State() ) << endl ;
2048 if ( firsttoNode ) {
2049 // cdebug << pthread_self() << "/" << ThreadNo()
2050 // << " Successed_SuccessAction start firsttoNode "
2051 // << SomeDataNodes.size() << " " << firsttoNode->Name() << endl ;
2052 firsttoNode->CreateNewThreadIf( false ) ;
2053 firsttoNode->RewindStack( RewindStack() ) ;
2054 if ( firsttoNode->State() == GraphExecutor::SuccessedState ) {
2055 // cdebug << pthread_self() << "/" << ThreadNo() << " " << Name()
2056 // << " : " << firsttoNode->Name() << " "
2057 // << Automaton()->StateName( firsttoNode->State() )
2058 // << " --> DataWaitingState for Thread "
2059 // << firsttoNode->ThreadNo() << endl ;
2060 firsttoNode->State( GraphExecutor::DataWaitingState ) ;
2062 // pthread_t OldT = firsttoNode->ThreadNo() ;
2063 firsttoNode->ThreadNo( pthread_self() ) ;
2064 // On continue avec le meme thread
2065 // cdebug << pthread_self() << "/" << ThreadNo() << " firsttoNode "
2066 // << firsttoNode->Name() << "Thread(" << OldT << "-->"
2067 // << firsttoNode->ThreadNo() << ")" << endl ;
2069 // cdebug << ThreadNo() << " Successed_SuccessAction " << Name()
2070 // << " for " << firsttoNode->Name()
2071 // << " !firsttoNode->CreateNewThreadIf() "
2072 // << !firsttoNode->CreateNewThreadIf()
2073 // << " " << Automaton()->StateName( firsttoNode->State() ) ;
2074 if ( firsttoNode->State() == GraphExecutor::DataReadyState ) {
2076 firsttoNode->UnLockDataWait() ;
2077 res = firsttoNode->DataUndef_AllDataReadyAction() ;
2080 cdebug << " ERROR " << endl ;
2084 // cdebug << ThreadNo() << " Successed_SuccessAction " << Name()
2085 // << " NO DataReady ==> ThreadNo( 0 ) firsttoNode == NULL LINKEDnodesnumber " << linkednodesnumber << endl ;
2089 // if ( linkednodesnumber == 0 && firsttoNode == NULL ) {
2090 // cdebug << ThreadNo() << " Successed_SuccessAction " << Name() << " LinkedNodesSize " << LinkedNodesSize()
2091 // << " firsttoNode == NULL LINKEDnodesnumber " << linkednodesnumber << " CHECK" << endl ;
2092 // _OutNode->CheckAllDone() ;
2095 // cdebug << pthread_self() << "/" << ThreadNo()
2096 // << " <-- Successed_SuccessAction " << Name() << " linkednodesnumber "
2097 // << linkednodesnumber << endl;
2101 bool GraphExecutor::InNode::SendSomeDataReady( char * FromNodeName ) {
2102 bool RetVal = false ;
2103 if ( IsDataFlowNode() ) {
2104 cdebug << ThreadNo() << " ----> " << Name()
2105 << " send Result to graph " << Name() << endl;
2108 // cdebug << pthread_self() << "/" << ThreadNo() << " ----> " << FromNodeName
2109 // << " send SomeDataReady to " << Name() << " "
2110 // << Automaton()->StateName( State() )
2111 // << " CreateNewThreadIf() " << CreateNewThreadIf()
2112 // << " LockedDataWait " << IsLockedDataWait() << endl;
2114 //cout << pthread_self() << "/" << ThreadNo() << " ----> " << FromNodeName
2115 << " send SomeDataReady to " << Name() << " "
2116 << Automaton()->StateName( State() )
2117 << " CreateNewThreadIf() " << CreateNewThreadIf()
2118 << " LockedDataWait " << IsLockedDataWait() << endl;
2120 if ( State() == GraphExecutor::SuccessedState ||
2121 State() == GraphExecutor::SuspendedSuccessedState ||
2122 State() == GraphExecutor::SuspendedSuccessedToReStartState ) {
2123 // cdebug << ThreadNo() << " " << FromNodeName
2124 // << " : " << Name() << " " << Automaton()->StateName( State() )
2125 // << " --> DataWaitingState for Thread "
2126 // << ThreadNo() << " " << endl ;
2127 State( GraphExecutor::DataWaitingState ) ;
2130 DataFromNode( FromNodeName ) ;
2131 RetVal = !SendEvent( GraphExecutor::SomeDataReadyEvent );
2139 int GraphExecutor::InNode::Errored_ErrorAction() {
2140 cdebug << ThreadNo() << " Errored_ErrorAction " << Name()
2141 << " will pthread_exit" << endl;
2146 int GraphExecutor::InNode::Successed_SuspendAction() {
2147 cdebug << ThreadNo() << " Successed_SuspendAction -->Suspend " << Name()
2148 << " Threads " << _OutNode->Threads() << " SuspendedThreads "
2149 << _OutNode->SuspendedThreads() << endl;
2150 _OutNode->PushEvent( this , GraphExecutor::SuspendedSuccessedEvent ,
2151 GraphExecutor::SuspendedSuccessedState ) ;
2153 GraphExecutor::InNode * aReStartNode = SuspendAction() ;
2154 cdebug << ThreadNo() << " Successed_SuspendAction Resumed " << Name() ;
2155 if ( aReStartNode ) {
2156 _aReStartNode = NULL ;
2157 cdebug << " for " << aReStartNode->Name() << endl;
2158 aReStartNode->SendEvent( _aReStartEvent ) ;
2162 SendEvent( GraphExecutor::ResumeEvent ) ;
2167 int GraphExecutor::InNode::Errored_SuspendAction() {
2168 cdebug << ThreadNo() << " Errored_SuspendAction -->Suspend " << Name()
2169 << " Threads " << _OutNode->Threads() << " SuspendedThreads "
2170 << _OutNode->SuspendedThreads() << endl;
2171 _OutNode->PushEvent( this , GraphExecutor::SuspendedErroredEvent ,
2172 GraphExecutor::SuspendedErroredState ) ;
2174 GraphExecutor::InNode * aReStartNode = SuspendAction() ;
2175 cdebug << ThreadNo() << " Errored_SuspendAction Resumed " << Name()
2177 if ( aReStartNode ) {
2178 _aReStartNode = NULL ;
2179 aReStartNode->SendEvent( _aReStartEvent ) ;
2182 SendEvent( GraphExecutor::ResumeEvent ) ;
2187 int GraphExecutor::InNode::SuspendedSuccessed_ResumeAction() {
2188 cdebug << ThreadNo() << " SuspendedSuccessed_ResumeAction " << Name() << endl;
2190 _OutNode->PushEvent( this , GraphExecutor::ResumedSuccessedEvent ,
2191 GraphExecutor::ResumedSuccessedState ) ;
2192 SendEvent( ResumedSuccessedEvent ) ;
2196 int GraphExecutor::InNode::SuspendedErrored_ResumeAction() {
2197 cdebug << ThreadNo() << " SuspendedErrored_ResumeAction " << Name() << endl;
2199 _OutNode->PushEvent( this , GraphExecutor::ResumedErroredEvent ,
2200 GraphExecutor::ResumedErroredState ) ;
2201 SendEvent( ResumedErroredEvent ) ;
2205 int GraphExecutor::InNode::Successed_KillAction() {
2207 _OutNode->PushEvent( this , GraphExecutor::KilledEvent ,
2208 GraphExecutor::KilledSuccessedState ) ;
2209 cdebug << ThreadNo() << " Successed_KillAction " << Name() << endl;
2213 int GraphExecutor::InNode::Errored_KillAction() {
2215 _OutNode->PushEvent( this , GraphExecutor::KilledEvent ,
2216 GraphExecutor::KilledErroredState ) ;
2217 cdebug << ThreadNo() << " Errored_KillAction " << Name() << endl;
2221 int GraphExecutor::InNode::Successed_StopAction() {
2223 _OutNode->PushEvent( this , GraphExecutor::StoppedEvent ,
2224 GraphExecutor::StoppedSuccessedState ) ;
2225 cdebug << ThreadNo() << " Successed_StopAction " << Name() << endl;
2229 int GraphExecutor::InNode::Errored_StopAction() {
2231 _OutNode->PushEvent( this , GraphExecutor::StoppedEvent ,
2232 GraphExecutor::StoppedErroredState ) ;
2233 cdebug << ThreadNo() << " Errored_StopAction " << Name() << endl;
2237 int GraphExecutor::InNode::SuspendedSuccessed_ReStartAction() {
2238 cdebug << ThreadNo() << " SuspendedSuccessed_ReStartAction " << Name() << endl;
2239 _OutNode->PushEvent( this , GraphExecutor::ReStartedEvent ,
2240 GraphExecutor::ReStartedState ) ;
2242 for ( i = 0 ; i < GetNodeInPortsSize() ; i++ ) {
2243 GetChangeNodeInPort( i )->State( SUPERV::ReadyState ) ;
2245 SendEvent( ExecuteEvent ) ;
2246 cdebug << ThreadNo() << " SuspendedSuccessed_ReStartAction " << Name() << endl;
2250 int GraphExecutor::InNode::SuspendedErrored_ReStartAction() {
2251 cdebug << ThreadNo() << " SuspendedErrored_ReStartAction " << Name() << endl;
2252 _OutNode->PushEvent( this , GraphExecutor::ReStartedEvent ,
2253 GraphExecutor::ReStartedState ) ;
2255 for ( i = 0 ; i < GetNodeInPortsSize() ; i++ ) {
2256 GetChangeNodeInPort( i )->State( SUPERV::ReadyState ) ;
2258 SendEvent( ExecuteEvent ) ;
2259 cdebug << ThreadNo() << " SuspendedErrored_ReStartAction " << Name() << endl;
2263 int GraphExecutor::InNode::SuspendedSuccessed_ReStartAndSuspendAction() {
2264 cdebug << ThreadNo() << " SuspendedSuccessed_ReStartAndSuspendAction " << Name()
2266 _OutNode->PushEvent( this , GraphExecutor::ReStartedAndSuspendEvent ,
2267 GraphExecutor::ReStartedState ) ;
2268 State( GraphExecutor::DataWaitingState ) ;
2270 cdebug << "InNode::Suspend() Node " << Name() << endl ;
2273 else if ( SendEvent( GraphExecutor::SomeDataReadyEvent ) ) {
2274 cdebug << "InNode::SendEvent( SomeDataReadyEvent ) Node "
2278 cdebug << ThreadNo() << " SuspendedSuccessed_ReStartAndSuspendAction " << Name()
2283 int GraphExecutor::InNode::SuspendedErrored_ReStartAndSuspendAction() {
2284 cdebug << ThreadNo() << " SuspendedErrored_ReStartAndSuspendAction " << Name()
2286 _OutNode->PushEvent( this , GraphExecutor::ReStartedAndSuspendEvent ,
2287 GraphExecutor::ReStartedState ) ;
2288 State( GraphExecutor::DataWaitingState ) ;
2290 cdebug << "InNode::Suspend() Node " << Name() << endl ;
2293 else if ( SendEvent( GraphExecutor::SomeDataReadyEvent ) ) {
2294 cdebug << "InNode::SendEvent( SomeDataReadyEvent ) Node "
2298 cdebug << ThreadNo() << " SuspendedErrored_ReStartAndSuspendAction " << Name()
2303 void GraphExecutor::InNode::InParametersSet( bool & Err ,
2305 ServicesAnyData * InParametersList ) {
2307 cdebug << ThreadNo() << " InParametersSet " << Name() << endl ;
2308 for ( i = 0 ; i < nInParams ; i++ ) {
2309 ServicesAnyData D = InParametersList[i];
2310 GraphBase::InPort * anInPort = GetChangeNodeInPort(i) ;
2311 GraphBase::OutPort * theOutPort = anInPort->GetOutPort() ;
2312 if ( anInPort->IsGate() && theOutPort == NULL ) {
2313 cdebug << ThreadNo() << " ArgIn" << i << " " << D.Name << " "
2314 << anInPort->GetServicesParameter().Parametertype
2315 << " is inactive. " << anInPort->Kind() << endl ;
2317 else if ( anInPort->State() == SUPERV::ReadyState ) {
2318 if ( anInPort->IsGate() ) {
2319 CORBA::Any * anAny = new CORBA::Any() ;
2320 *anAny <<= (long ) 0 ;
2321 theOutPort->Value( anAny ) ;
2323 if ( !anInPort->IsDataStream() ) {
2324 anInPort->State( SUPERV::WaitingState ) ;
2326 D.Name = CORBA::string_dup( anInPort->GetServicesParameter().Parametername ) ;
2327 cdebug << ThreadNo() << " ArgIn" << i << " " << anInPort->Kind()
2328 << " " << anInPort->State() ;
2329 cdebug << " " << D.Name << " " << anInPort->GetServicesParameter().Parametertype << " : " ;
2330 D.Value = *theOutPort->Value() ; // CORBA::Any
2331 string _Type = CORBA::string_dup( anInPort->GetServicesParameter().Parametertype ) ;
2332 const char * Type = _Type.c_str() ;
2333 switch ( D.Value.type()->kind() ) { // { string , long , double , objref }
2334 case CORBA::tk_string:
2337 cdebug << t << " (string)" ;
2338 if ( !strcmp( Type , "string" ) ) {
2340 else if ( !strcmp( Type , "boolean" ) ) {
2343 sscanf( t , "%ld" , &d ) ;
2345 D.Value <<= (CORBA::Any::from_boolean ) b ;
2346 // theOutPort->Value( D.Value ) ;
2348 else if ( !strcmp( Type , "char" ) ) {
2351 sscanf( t , "%ld" , &d ) ;
2353 D.Value <<= (CORBA::Any::from_char ) c ;
2354 cdebug << "string '" << t << "' --> " << d << " --> char " << c ;
2355 // theOutPort->Value( D.Value ) ;
2357 else if ( !strcmp( Type , "short" ) ) {
2360 sscanf( t , "%ld" , &d ) ;
2363 cdebug << "string '" << t << "' --> " << d << " --> short " << s ;
2364 // theOutPort->Value( D.Value ) ;
2366 else if ( !strcmp( Type , "int" ) || !strcmp( Type , "long" ) ) {
2368 sscanf( t , "%ld" , &l ) ;
2370 cdebug << "string '" << t << " --> long " << l ;
2371 // theOutPort->Value( D.Value ) ;
2373 else if ( !strcmp( Type , "float" ) ) {
2375 sscanf( t , "%lf" , &d ) ;
2378 cdebug << "string '" << t << "' --> " << setw(25) << setprecision(18) << d << " --> float " << " = "
2379 << setw(25) << setprecision(18) << f ;
2380 // theOutPort->Value( D.Value ) ;
2382 else if ( !strcmp( Type , "double" ) ) {
2384 sscanf( t , "%lf" , &d ) ;
2386 cdebug << "string '" << t << " --> double " << setw(25) << setprecision(18) << d ;
2387 // theOutPort->Value( D.Value ) ;
2389 // else if ( !strcmp( Type , "objref" ) ) {
2391 CORBA::Object_ptr ObjRef ;
2393 ObjRef = StringToObject( t ) ;
2394 D.Value <<= ObjRef ;
2397 D.Value <<= CORBA::Object::_nil() ;
2399 // theOutPort->Value( D.Value ) ;
2402 // cdebug << " (other ERROR)" << endl ;
2404 cdebug << " --> call_kind " << D.Value.type()->kind() << endl ;
2406 case CORBA::tk_long:
2409 cdebug << l << " (long)" << endl ;
2410 if ( !strcmp( Type , "string" ) ) {
2412 sprintf( t , "%ld" , l ) ;
2414 // theOutPort->Value( D.Value ) ;
2416 else if ( !strcmp( Type , "boolean" ) ) {
2419 D.Value <<= (CORBA::Any::from_boolean ) b ;
2420 // theOutPort->Value( D.Value ) ;
2422 else if ( !strcmp( Type , "char" ) ) {
2424 c = (unsigned char ) l ;
2425 D.Value <<= (CORBA::Any::from_char ) c ;
2426 // theOutPort->Value( D.Value ) ;
2428 else if ( !strcmp( Type , "short" ) ) {
2432 // theOutPort->Value( D.Value ) ;
2434 else if ( !strcmp( Type , "int" ) || !strcmp( Type , "long" ) ) {
2436 else if ( !strcmp( Type , "float" ) ) {
2440 // theOutPort->Value( D.Value ) ;
2442 else if ( !strcmp( Type , "double" ) ) {
2446 // theOutPort->Value( D.Value ) ;
2448 // else if ( !strcmp( Type , "objref" ) ) {
2450 D.Value <<= CORBA::Object::_nil() ;
2451 // theOutPort->Value( D.Value ) ;
2454 // cdebug << " (other ERROR)" << endl ;
2456 cdebug << " --> call_kind " << D.Value.type()->kind() << endl ;
2458 case CORBA::tk_double:
2461 cdebug << d << " (double)" << endl ;
2462 if ( !strcmp( Type , "string" ) ) {
2464 sprintf( t , "%lf" , d ) ;
2466 // theOutPort->Value( D.Value ) ;
2468 else if ( !strcmp( Type , "boolean" ) ) {
2471 D.Value <<= (CORBA::Any::from_boolean ) b ;
2472 // theOutPort->Value( D.Value ) ;
2474 else if ( !strcmp( Type , "char" ) ) {
2476 c = (unsigned char ) d ;
2477 D.Value <<= (CORBA::Any::from_char ) c ;
2478 // theOutPort->Value( D.Value ) ;
2480 else if ( !strcmp( Type , "short" ) ) {
2484 // theOutPort->Value( D.Value ) ;
2486 else if ( !strcmp( Type , "int" ) || !strcmp( Type , "long" ) ) {
2490 // theOutPort->Value( D.Value ) ;
2492 else if ( !strcmp( Type , "float" ) ) {
2496 // theOutPort->Value( D.Value ) ;
2498 else if ( !strcmp( Type , "double" ) ) {
2500 // else if ( !strcmp( Type , "objref" ) ) {
2502 D.Value <<= CORBA::Object::_nil() ;
2503 // theOutPort->Value( D.Value ) ;
2506 // cdebug << " (other ERROR)" << endl ;
2508 cdebug << " --> call_kind " << D.Value.type()->kind() << endl ;
2510 case CORBA::tk_objref:
2511 if ( !strcmp( Type , "string" ) ) {
2512 CORBA::Object_ptr ObjRef ;
2515 D.Value >>= ObjRef ;
2516 retstr = ObjectToString( ObjRef ) ;
2517 D.Value <<= retstr ;
2518 // theOutPort->Value( D.Value ) ;
2524 cdebug << "ToString( object ) Catched ERROR" << endl ;
2527 else if ( !strcmp( Type , "boolean" ) ) {
2529 D.Value <<= (CORBA::Any::from_boolean ) b ;
2530 // theOutPort->Value( D.Value ) ;
2532 else if ( !strcmp( Type , "char" ) ) {
2533 unsigned char c = 0 ;
2534 D.Value <<= (CORBA::Any::from_char ) c ;
2535 // theOutPort->Value( D.Value ) ;
2537 else if ( !strcmp( Type , "short" ) ) {
2540 // theOutPort->Value( D.Value ) ;
2542 else if ( !strcmp( Type , "int" ) || !strcmp( Type , "long" ) ) {
2545 // theOutPort->Value( D.Value ) ;
2547 else if ( !strcmp( Type , "float" ) ) {
2550 // theOutPort->Value( D.Value ) ;
2552 else if ( !strcmp( Type , "double" ) ) {
2555 // theOutPort->Value( D.Value ) ;
2557 // else if ( !strcmp( Type , "objref" ) ) {
2559 CORBA::Object_ptr obj ;
2563 retstr = ObjectToString( obj ) ;
2564 cdebug << retstr << endl ;
2570 cdebug << "ToString( object ) Catched ERROR" << endl ;
2574 // cdebug << " (other ERROR)" << endl ;
2576 cdebug << " --> call_kind " << D.Value.type()->kind() << endl ;
2579 cdebug << " (other ERROR) " << D.Value.type()->kind() << endl ;
2583 cdebug << ThreadNo() << " In" << i << " : wrong state ERROR State "
2584 << anInPort->State() << " NameState "
2585 << Automaton()->StateName( anInPort->State() ) << " PortName "
2586 << anInPort->PortName() << " Parametername "
2587 << anInPort->GetServicesParameter().Parametername << endl ;
2590 InParametersList[i] = D ;
2594 void GraphExecutor::InNode::InOutParametersSet( int nOutParams ,
2595 ServicesAnyData * OutParametersList ) {
2597 for ( i = 0 ; i < nOutParams ; i++ ) {
2598 ServicesAnyData D = OutParametersList[i] ;
2600 D.Name = GetChangeNodeOutPort(i)->GetServicesParameter().Parametername;
2601 string _Type = CORBA::string_dup(GetChangeNodeOutPort(i)->GetServicesParameter().Parametertype) ;
2602 const char * Type = _Type.c_str() ;
2603 bool OutDone = GetChangeNodeOutPort(i)->Done() ;
2604 cdebug << ThreadNo() << " ArgOut" << i << " " << D.Name << " Done("
2605 << OutDone << ") " << Type << " : " << endl ;
2606 if ( !strcmp( Type , "string" ) ) {
2607 D.Value <<= (char *) NULL ;
2609 else if ( !strcmp( Type , "boolean" ) ) {
2611 D.Value <<= (CORBA::Any::from_boolean ) b ;
2613 else if ( !strcmp( Type , "char" ) ) {
2614 unsigned char c = 0 ;
2615 D.Value <<= (CORBA::Any::from_char ) c ;
2617 else if ( !strcmp( Type , "short" ) ) {
2621 else if ( !strcmp( Type , "int" ) || !strcmp( Type , "long" ) ) {
2622 D.Value <<= (long ) 0 ;
2624 else if ( !strcmp( Type , "float" ) ) {
2628 else if ( !strcmp( Type , "double" ) ) {
2633 D.Value <<= CORBA::Object::_nil() ;
2636 switch (D.Value.type()->kind()) { // { string , long , double , objref }
2637 case CORBA::tk_string:
2640 cdebug << ThreadNo() << " " << t << "(string)" << endl ;
2642 case CORBA::tk_boolean:
2644 D.Value >>= (CORBA::Any::to_boolean ) b;
2645 cdebug << ThreadNo() << " " << b << "(boolean)" << endl ;
2647 case CORBA::tk_char:
2649 D.Value >>= (CORBA::Any::to_char ) c;
2650 cdebug << ThreadNo() << " " << c << "(char)" << endl ;
2652 case CORBA::tk_short:
2655 cdebug << ThreadNo() << " " << s << "(short)" << endl ;
2657 case CORBA::tk_long:
2660 cdebug << ThreadNo() << " " << l << "(long)" << endl ;
2662 case CORBA::tk_float:
2665 cdebug << ThreadNo() << " " << f << "(float)" << endl ;
2667 case CORBA::tk_double:
2670 cdebug << ThreadNo() << " " << d << "(double)" << endl ;
2672 case CORBA::tk_objref:
2674 CORBA::Object_ptr obj ;
2677 retstr = ObjectToString( obj ) ;
2678 cdebug << ThreadNo() << retstr << endl ;
2681 cdebug << "ToString( object ) Catched ERROR" << endl ;
2685 cdebug << ThreadNo() << " " << "(other ERROR)" << endl ;
2688 OutParametersList[i] = D ;
2692 bool GraphExecutor::InNode::OutParametersSet( bool Err ,
2693 SUPERV::GraphState NewState ,
2695 ServicesAnyData * OutParametersList ) {
2696 bool RetVal = true ;
2698 GraphBase::OutPort * aGateOutPort = NULL ;
2699 bool OrSwitch = false ;
2700 cdebug << "OutParametersSet " << Name() << " nOutParams " << nOutParams << " NewState " << NewState << endl ;
2701 // cout << "OutParametersSet " << Name() << " nOutParams " << nOutParams << " NewState " << NewState << endl ;
2702 if ( nOutParams && !IsMacroNode() ) {
2703 GraphBase::OutPort * anOutPort ;
2704 for ( i = 0 ; i < nOutParams ; i++ ) {
2705 anOutPort = GetChangeNodeOutPort(i) ;
2707 anOutPort->State( NewState ) ;
2708 anOutPort->Done( true ) ;
2711 cdebug << ThreadNo() << " " << "Out" << i << " " << Name() << " "
2712 << anOutPort->PortName() << " " << anOutPort->Kind() ;
2713 ServicesAnyData D = OutParametersList[i] ;
2714 switch (D.Value.type()->kind()) { // { string , long , double , objref }
2715 case CORBA::tk_string: {
2718 cdebug << ThreadNo() << " " << t << "(string)" << endl ;
2721 case CORBA::tk_boolean: {
2723 D.Value >>= (CORBA::Any::to_boolean ) b;
2724 long l = (long ) b ;
2726 cdebug << ThreadNo() << " " << b << "(boolean)" << endl ;
2729 case CORBA::tk_char: {
2731 D.Value >>= (CORBA::Any::to_char ) c;
2732 long l = (long ) c ;
2734 cdebug << ThreadNo() << " " << c << "(char)" << endl ;
2737 case CORBA::tk_short: {
2740 long l = (long ) s ;
2742 cdebug << ThreadNo() << " " << s << "(short)" << endl ;
2745 case CORBA::tk_long: {
2748 cdebug << ThreadNo() << " " << l << "(long)" << endl ;
2751 case CORBA::tk_float: {
2754 double d = (double ) f ;
2756 cdebug << ThreadNo() << " " << f << "(float)" << endl ;
2759 case CORBA::tk_double: {
2762 cdebug << ThreadNo() << " " << d << "(double)" << endl ;
2765 case CORBA::tk_objref: {
2767 CORBA::Object_ptr obj ;
2770 retstr = ObjectToString( obj ) ;
2771 cdebug << ThreadNo() << retstr << endl ;
2774 cdebug << "ToString( object ) Catched ERROR" << endl ;
2779 cdebug << ThreadNo() << " " << "(other ERROR)" << endl ;
2782 OutParametersList[i] = D ;
2783 if ( !anOutPort->IsDataStream() ) {
2784 if ( anOutPort->IsGate() ) {
2785 aGateOutPort = anOutPort ;
2786 cdebug << " Gate " ;
2788 OutParametersList[i].Value <<= l;
2789 anOutPort->Value( OutParametersList[i].Value );
2791 else if ( anOutPort->IsLoop() ) {
2792 cdebug << " Loop " ;
2793 anOutPort->Value( OutParametersList[i].Value );
2794 // InLoop Port of EndLoopNode is ready :
2795 anOutPort->ChangeInPorts(0)->State( SUPERV::ReadyState ) ;
2797 else if ( anOutPort->IsSwitch() ) {
2798 cdebug << " Switch " ;
2799 anOutPort->Value( OutParametersList[i].Value );
2800 if ( anOutPort->InPortsSize() && anOutPort->ChangeInPorts( 0 )->IsGate() ) {
2801 if ( OrSwitch && anOutPort->BoolValue() ) {
2802 cdebug << "GraphExecutor::InNodeThreads::OutParameters more than one switch is true WARNING"
2806 OrSwitch = OrSwitch | anOutPort->BoolValue() ;
2809 cdebug << "OrSwitch " << OrSwitch ;
2812 cdebug << " Param " ;
2813 anOutPort->Value( OutParametersList[i].Value );
2815 anOutPort->State( NewState ) ;
2816 anOutPort->Done( true ) ;
2819 for ( j = 0 ; j < anOutPort->InPortsSize() ; j++ ) {
2820 bool fromGOTO = false ;
2821 const char * ToNodeName = anOutPort->ChangeInPorts( j )->NodeName() ;
2822 if ( !strcmp( ToNodeName , _OutNode->Graph()->Name() ) && _OutNode->Graph()->GraphMacroLevel() != 0 ) {
2823 cdebug << "OutParametersSet ToNodeName " << _OutNode->Graph()->Name() << " CoupledNode "
2824 << _OutNode->Graph()->CoupledNodeName() << _OutNode->Graph()->CoupledNode()
2826 cdebug << " GraphExecutor " << _OutNode->Graph()->CoupledNode()->GraphEditor()->Executor() << endl ;
2827 _OutNode->Graph()->CoupledNode()->GraphEditor()->Executor()->OutputOfAny( _OutNode->Graph()->CoupledNodeName() ,
2828 anOutPort->ChangeInPorts( j )->PortName() ,
2829 *anOutPort->Value() ) ;
2832 GraphBase::ComputingNode * ToNode = _OutNode->Graph()->GetChangeGraphNode( ToNodeName ) ;
2834 // cout << "OutParametersSet ToNodeName " << ToNodeName << endl ;
2835 cdebug << "OutParametersSet ToNodeName " << ToNodeName << " " << ToNode->Name() << endl ;
2836 GraphBase::OutPort * aGOTOPort = ToNode->GetChangeNodeInGate()->GetOutPort() ;
2838 fromGOTO = aGOTOPort->IsGOTO() ;
2840 if ( anOutPort->ChangeInPorts( j )->IsEndSwitch() || fromGOTO ) {
2841 cdebug << anOutPort->ChangeInPorts( j )->NodeName() << "("
2842 << anOutPort->ChangeInPorts( j )->PortName() << ","
2843 << anOutPort->ChangeInPorts( j )->Kind() << ") WILL BE changed from "
2844 << anOutPort->ChangeInPorts( j )->GetOutPort()->NodeName()
2846 << anOutPort->ChangeInPorts( j )->GetOutPort()->PortName()
2847 << ") to " << anOutPort->NodeName() << "("
2848 << anOutPort->PortName() << ")" << endl ;
2849 anOutPort->ChangeInPorts( j )->ChangeOutPort( anOutPort ) ;
2852 cdebug << anOutPort->ChangeInPorts( j )->NodeName() << "("
2853 << anOutPort->ChangeInPorts( j )->PortName() << ","
2854 << anOutPort->ChangeInPorts( j )->Kind() << ") NOT changed from "
2855 << anOutPort->ChangeInPorts( j )->GetOutPort()->NodeName()
2857 << anOutPort->ChangeInPorts( j )->GetOutPort()->PortName()
2858 << ") to " << anOutPort->NodeName() << "("
2859 << anOutPort->PortName() << ")" << endl ;
2865 switch (anOutPort->Value()->type()->kind()) {
2866 case CORBA::tk_string:
2868 (*anOutPort->Value()) >>= t;
2869 cdebug << ThreadNo() << " Out" << i << " : " << t << "(string)" << endl ;
2871 case CORBA::tk_boolean:
2873 (*anOutPort->Value()) >>= (CORBA::Any::to_boolean ) b;
2874 cdebug << ThreadNo() << " Out" << i << " : " << b << "(boolean)" << endl ;
2876 case CORBA::tk_char:
2878 (*anOutPort->Value()) >>= (CORBA::Any::to_char ) c;
2879 cdebug << ThreadNo() << " Out" << i << " : " << c << "(char)" << endl ;
2881 case CORBA::tk_short:
2883 (*anOutPort->Value()) >>= s;
2884 cdebug << ThreadNo() << " Out" << i << " : " << s << "(short)" << endl ;
2886 case CORBA::tk_long:
2888 (*anOutPort->Value()) >>= l;
2889 cdebug << ThreadNo() << " Out" << i << " : " << l << "(long)" << endl ;
2891 case CORBA::tk_float:
2893 (*anOutPort->Value()) >>= f;
2894 cdebug << ThreadNo() << " Out" << i << " : " << f << "(float)" << endl ;
2896 case CORBA::tk_double:
2898 (*anOutPort->Value()) >>= d;
2899 cdebug << ThreadNo() << " Out" << i << " : " << d << "(double)" << endl ;
2901 case CORBA::tk_objref:
2902 CORBA::Object_ptr obj ;
2905 (*anOutPort->Value()) >>= obj ;
2906 retstr = ObjectToString( obj );
2907 cdebug << ThreadNo() << " Out" << i << " : " << "ToString( object ) "
2911 cdebug << ThreadNo() << " Out" << i << " : " << "ToString( object ) "
2912 << "Catched ERROR" << endl ;
2916 cdebug << ThreadNo() << " Out" << i << " : " << "(other ERROR)" << endl ;
2922 if ( aGateOutPort && IsSwitchNode() ) {
2924 // cdebug << ThreadNo() << " " << "Out0 " << Name() << " Close of "
2925 // << aGateOutPort->PortName() << " " << aGateOutPort->Kind() ;
2927 OutParametersList[0].Value <<= l ;
2928 aGateOutPort->Value( OutParametersList[0].Value ) ;
2931 // cdebug << ThreadNo() << " " << "Out0 " << Name() << " Open of "
2932 // << aGateOutPort->PortName() << " " << aGateOutPort->Kind() ;
2934 OutParametersList[0].Value <<= l ;
2935 aGateOutPort->Value( OutParametersList[0].Value ) ;
2937 for ( i = 0 ; i < GetNodeOutPortsSize() ; i++ ) {
2938 GraphBase::InPort * anInPort ;
2939 anInPort = CoupledNode()->GetChangeInPort( GetNodeOutPort( i )->PortName() ) ;
2941 anInPort->ChangeOutPort( GetChangeNodeOutPort( i ) ) ;