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
40 #include <SALOMEconfig.h>
41 #include CORBA_CLIENT_HEADER(SALOME_Component)
42 #include "SALOME_LifeCycleCORBA.hxx"
44 //#include "StreamGraph_Impl.hxx"
46 #include "DataFlowExecutor_OutNode.hxx"
49 static void UpperCase(std::string& rstr)
51 std::transform(rstr.begin(), rstr.end(), rstr.begin(), towupper);
55 int GraphExecutor::InNode::SendEvent( const GraphExecutor::NodeEvent anEvent ) {
57 _CurrentEvent = (GraphExecutor::NodeEvent ) anEvent ;
58 cdebug << pthread_self() << "/" << ThreadNo() << " -->SendEvent Node " << Name()
60 << Automaton()->ControlStateName( ControlState() )
61 << " Event : " << Automaton()->EventName( anEvent )
62 << " State : " << Automaton()->StateName( State() ) << " _RewindStack " << _RewindStack << endl;
65 _NextState = Automaton()->NextState( _OldState , anEvent ) ;
66 if ( _NextState == _OldState ) {
67 cdebug << pthread_self() << "/" << ThreadNo()
68 << " GraphExecutor::InNodeThreads::SendEvent SameStates "
69 << _OldState << endl ;
70 _NextAction = GraphExecutor::VoidAction ;
73 _NextAction = Automaton()->NextAction( _NextState , anEvent ) ;
76 // State( _NextState ) ;
77 // if ( _OldState == SUPERV::SuccessedExecutingState ||
78 // _OldState == SUPERV::ErroredExecutingState ) {
82 cdebug << pthread_self() << "/" << ThreadNo() << " SendedEvent Node "
83 << Name() << endl << " ControlState : "
84 << Automaton()->ControlStateName( ControlState() ) << endl
85 << " OldState : " << Automaton()->StateName( _OldState ) << endl
86 << " Event : " << Automaton()->EventName( anEvent ) << endl
87 << " NextState : " << Automaton()->StateName( _NextState ) << endl
88 << " Action : " << Automaton()->ActionName( _NextAction ) << endl
89 << " CreateNewThread " << CreateNewThread() << endl
90 << " _RewindStack " << _RewindStack << endl ;
93 cout << pthread_self() << "/" << ThreadNo() << " SendedEvent Node " << Name()
94 << endl << " ControlState : "
95 << Automaton()->ControlStateName( ControlState() ) << endl
96 << " OldState : " << Automaton()->StateName( _OldState ) << endl
97 << " Event : " << Automaton()->EventName( anEvent ) << endl
98 << " NextState : " << Automaton()->StateName( _NextState ) << endl
99 << " Action : " << Automaton()->ActionName( _NextAction ) << endl
100 << " CreateNewThread " << CreateNewThread() << endl ;
103 int sts = executeAction() ;
105 cdebug << pthread_self() << "/" << ThreadNo() << " <--- SendEvent Node " << Name()
106 << " Event : " << Automaton()->EventName( anEvent )
107 << " State : " << Automaton()->StateName( State() )
114 // ReadyAction - RunningAction - DoneAction - SuspendedAction :
115 // for StateWait( ReadyW - RunningW - DoneW - SuspendedW )
116 void GraphExecutor::InNode::ReadyAction() {
117 if ( pthread_mutex_lock( &_MutexWait ) ) {
118 perror("Ready pthread_mutex_lock ") ;
121 cdebug << pthread_self() << "/" << ThreadNo()
122 << "ReadyAction pthread_cond_broadcast _ReadyWait "
124 if ( pthread_cond_broadcast( &_ReadyWait ) ) {
125 perror("Ready pthread_cond_broadcast ") ;
127 if ( pthread_mutex_unlock( &_MutexWait ) ) {
128 perror("Ready pthread_mutex_unlock ") ;
133 void GraphExecutor::InNode::RunningAction() {
134 if ( pthread_mutex_lock( &_MutexWait ) ) {
135 perror("Running pthread_mutex_lock ") ;
138 cdebug << pthread_self() << "/" << ThreadNo()
139 << "RunningAction pthread_cond_broadcast _RunningWait "
141 if ( pthread_cond_broadcast( &_RunningWait ) ) {
142 perror("Running pthread_cond_broadcast ") ;
144 if ( pthread_mutex_unlock( &_MutexWait ) ) {
145 perror("Running pthread_mutex_unlock ") ;
150 void GraphExecutor::InNode::DoneAction() {
151 if ( pthread_mutex_lock( &_MutexWait ) ) {
152 perror("Done pthread_mutex_lock ") ;
155 cdebug << pthread_self() << "/" << ThreadNo()
156 << "DoneAction pthread_cond_broadcast _DoneWait "
158 if ( pthread_cond_broadcast( &_DoneWait ) ) {
159 perror("Done pthread_cond_broadcast ") ;
161 if ( pthread_mutex_unlock( &_MutexWait ) ) {
162 perror("Done pthread_mutex_unlock ") ;
167 void GraphExecutor::InNode::SuspendedAction() {
168 if ( pthread_mutex_lock( &_MutexWait ) ) {
169 perror("Suspended pthread_mutex_lock ") ;
172 cdebug << pthread_self() << "/" << ThreadNo()
173 << "SuspendedAction pthread_cond_broadcast _SuspendedWait "
175 if ( pthread_cond_broadcast( &_SuspendedWait ) ) {
176 perror("Suspended pthread_cond_broadcast ") ;
178 if ( pthread_mutex_unlock( &_MutexWait ) ) {
179 perror("Suspended pthread_mutex_unlock ") ;
184 // SuspendAction <--> { ResumeAction - ReStartAction }
185 GraphExecutor::InNode * GraphExecutor::InNode::SuspendAction() {
187 if ( pthread_mutex_lock( &_MutexWait ) ) {
188 perror("Suspend pthread_mutex_lock ") ;
191 if ( !_SuspendSync ) {
192 cdebug << pthread_self() << "/" << ThreadNo() << " pthread_cond " << Name()
193 << " SuspendAction pthread_cond_wait _SuspendWait "
194 << Automaton()->StateName( State() ) << endl ;
195 _SuspendSync = true ;
196 _OutNode->SuspendThread() ;
197 if ( pthread_cond_wait( &_SuspendWait , &_MutexWait ) ) {
198 perror("SuspendAction pthread_cond_wait ") ;
200 _OutNode->ResumeThread() ;
201 cdebug << pthread_self() << "/" << ThreadNo() << " pthread_cond " << Name()
202 << " SuspendAction pthread_cond_waited"
203 << Automaton()->StateName( State() ) << endl ;
206 cdebug << pthread_self() << "/" << ThreadNo() << " pthread_cond " << Name()
207 << " NO SuspendAction pthread_cond_wait"
208 << Automaton()->StateName( State() ) << endl ;
210 // SendEvent( _aResumeEvent ) ; ===> Mutex with myself !
211 _SuspendSync = false ;
212 if ( ControlState() == SUPERV::ToSuspendStartState ||
213 ControlState() == SUPERV::ToSuspendState ) {
214 ControlState( SUPERV::VoidState ) ;
216 if ( pthread_mutex_unlock( &_MutexWait ) ) {
217 perror("SuspendAction pthread_mutex_unlock ") ;
221 SendEvent( _aResumeEvent ) ;
222 // if ( ControlState() == SUPERV::ToSuspendStartState ) {
223 // ControlState( SUPERV::VoidState ) ;
226 if ( pthread_mutex_lock( &_MutexWait ) ) {
227 perror("SuspendAction pthread_mutex_lock ") ;
231 cdebug << pthread_self() << "/" << ThreadNo() << " pthread_cond " << Name()
232 << " SuspendAction pthread_cond_signal _ResumeWait" << endl ;
233 if ( pthread_cond_signal( &_ResumeWait ) ) {
234 perror("SuspendAction pthread_cond_signal _ResumeWait ") ;
236 cdebug << pthread_self() << "/" << ThreadNo() << " pthread_cond " << Name()
237 << " SuspendAction pthread_cond_signaled _ResumeWait " << endl ;
240 cdebug << pthread_self() << "/" << ThreadNo() << " pthread_cond " << Name()
241 << " NO SuspendAction pthread_cond_signal _ResumeWait" << endl ;
244 if ( pthread_mutex_unlock( &_MutexWait ) ) {
245 perror("SuspendAction pthread_mutex_unlock ") ;
248 if ( _aReStartNode ) {
249 cdebug << Name() << " " << Automaton()->StateName( State() )
250 << "aReStartNode : " << _aReStartNode->Name() << " "
251 << Automaton()->StateName( _aReStartNode->State() ) << endl ;
252 _aReStartNode->SendEvent( _aResumeEvent ) ;
255 cdebug << "NO aReStartNode"
256 << Automaton()->StateName( State() ) << endl ;
258 return _aReStartNode ;
261 bool GraphExecutor::InNode::ResumeAction( GraphExecutor::NodeEvent aResumeEvent ) {
263 if ( pthread_mutex_lock( &_MutexWait ) ) {
264 perror("ResumeAction pthread_mutex_lock ") ;
267 _aResumeEvent = aResumeEvent ;
268 if ( _SuspendSync ) {
269 cdebug << pthread_self() << "/" << ThreadNo() << " pthread_cond " << Name()
270 << " ResumeAction pthread_cond_signal" << endl ;
271 if ( pthread_cond_signal( &_SuspendWait ) ) {
272 perror("ResumeAction pthread_cond_signal ") ;
274 cdebug << pthread_self() << "/" << ThreadNo() << " pthread_cond " << Name()
275 << " ResumeAction pthread_cond_signaled _SuspendWait " << endl ;
279 cdebug << pthread_self() << "/" << ThreadNo() << " pthread_cond " << Name()
280 << " NO ResumeAction pthread_cond_signal" << endl ;
281 if ( pthread_self() == ThreadNo() ) {
282 RetVal = false ; /*/ Ne pas s'attendre soi-meme !...*/
285 _SuspendSync = true ;
286 RetVal = true ; // Il faut tout de meme attendre ci-apres ...
289 if ( pthread_mutex_unlock( &_MutexWait ) ) {
290 perror("ResumeAction pthread_mutex_unlock ") ;
295 if ( pthread_mutex_lock( &_MutexWait ) ) {
296 perror("ResumeAction pthread_mutex_lock ") ;
299 if ( !_ResumeSync ) {
300 cdebug << pthread_self() << "/" << ThreadNo() << " pthread_cond "
301 << Name() << " ResumeAction pthread_cond_wait _ResumeWait "
302 << Automaton()->StateName( State() ) << endl ;
304 if ( pthread_cond_wait( &_ResumeWait , &_MutexWait ) ) {
305 perror("ResumeAction pthread_cond_wait ") ;
307 cdebug << pthread_self() << "/" << ThreadNo() << " pthread_cond "
308 << Name() << " ResumeAction pthread_cond_waited _ResumeWait"
309 << Automaton()->StateName( State() ) << endl ;
313 cdebug << pthread_self() << "/" << ThreadNo() << " pthread_cond "
314 << Name() << " NO ResumeAction pthread_cond_wait _ResumeWait"
315 << Automaton()->StateName( State() ) << endl ;
318 _ResumeSync = false ;
319 if ( pthread_mutex_unlock( &_MutexWait ) ) {
320 perror("ResumeAction pthread_mutex_unlock ") ;
324 cdebug << pthread_self() << "/" << ThreadNo()
325 << "GraphExecutor::InNodeThreads::ResumeAction RetVal " << RetVal << endl ;
329 bool GraphExecutor::InNode::ReStartAction( GraphExecutor::InNode * aReStartNode ,
330 GraphExecutor::NodeEvent anEvent ) {
331 GraphExecutor::InNode * oldReStartNode = _aReStartNode ;
332 _aReStartNode = aReStartNode ;
333 _aReStartEvent = anEvent ;
334 cdebug << pthread_self() << " GraphExecutor::InNodeThreads::ReStartAction from "
335 << Name() << " " << Automaton()->StateName( State() ) << " to "
336 << aReStartNode->ThreadNo() << " " << aReStartNode->Name() << " "
337 << Automaton()->StateName( aReStartNode->State() ) ;
338 if ( oldReStartNode ) {
339 cdebug << " oldReStartNode " << oldReStartNode->Name() << endl ;
344 return ResumeAction( GraphExecutor::ToReStartEvent ) ;
347 void GraphExecutor::InNode::KilledAction() {
348 if ( pthread_mutex_lock( &_MutexWait ) ) {
349 perror("Killed pthread_mutex_lock ") ;
353 cdebug << "pthread_cond " << Name() << " Killed pthread_cond_wait"
356 if ( pthread_cond_wait( &_KillWait , &_MutexWait ) ) {
357 perror("Killed pthread_cond_wait ") ;
359 cdebug << "pthread_cond " << Name() << " Killed pthread_cond_waited"
363 cdebug << "pthread_cond " << Name() << " NO Killed pthread_cond_wait"
367 if ( pthread_mutex_unlock( &_MutexWait ) ) {
368 perror("Killed pthread_mutex_unlock ") ;
373 void GraphExecutor::InNode::KillAction() {
374 if ( pthread_mutex_lock( &_MutexWait ) ) {
375 perror("Kill pthread_mutex_lock ") ;
379 cdebug << "pthread_cond " << Name() << " Kill pthread_cond_signal"
381 // if ( pthread_cond_broadcast( &_KillWait ) ) {
382 if ( pthread_cond_signal( &_KillWait ) ) {
383 perror("Kill pthread_cond_broadcast ") ;
385 cdebug << "pthread_cond " << Name() << " Kill pthread_cond_signaled"
389 cdebug << "pthread_cond " << Name() << " NO Kill pthread_cond_signal"
393 if ( pthread_mutex_unlock( &_MutexWait ) ) {
394 perror("Kill pthread_mutex_unlock ") ;
399 void GraphExecutor::InNode::StoppedAction() {
400 if ( pthread_mutex_lock( &_MutexWait ) ) {
401 perror("Stopped pthread_mutex_lock ") ;
404 if ( pthread_cond_wait( &_StopWait , &_MutexWait ) ) {
405 perror("Stopped pthread_cond_wait ") ;
407 if ( pthread_mutex_unlock( &_MutexWait ) ) {
408 perror("Stopped pthread_mutex_unlock ") ;
413 void GraphExecutor::InNode::StopAction() {
414 if ( pthread_mutex_lock( &_MutexWait ) ) {
415 perror("Stop pthread_mutex_lock ") ;
418 if ( pthread_cond_broadcast( &_StopWait ) ) {
419 perror("Stop pthread_cond_broadcast ") ;
421 if ( pthread_mutex_unlock( &_MutexWait ) ) {
422 perror("Stop pthread_mutex_unlock ") ;
427 void GraphExecutor::InNode::ThreadStartedAction() {
428 if ( pthread_mutex_lock( &_MutexWait ) ) {
429 perror("ThreadStarted pthread_mutex_lock ") ;
432 if ( !_ThreadStartedSync ) {
433 cdebug << "pthread_cond " << Name() << " ThreadStarted pthread_cond_wait"
435 _ThreadStartedSync = true ;
436 if ( pthread_cond_wait( &_ThreadStartedWait , &_MutexWait ) ) {
437 perror("ThreadStarted pthread_cond_wait ") ;
439 cdebug << "pthread_cond " << Name() << " ThreadStarted pthread_cond_waited"
443 cdebug << "pthread_cond " << Name() << " NO ThreadStarted pthread_cond_wait"
446 _ThreadStartedSync = false ;
447 if ( pthread_cond_signal( &_ThreadStartedWait ) ) {
448 perror("ThreadStart pthread_cond_signal ") ;
451 cdebug << "pthread_cond " << Name() << " NO ThreadStarted pthread_cond_signaled"
454 if ( pthread_mutex_unlock( &_MutexWait ) ) {
455 perror("ThreadStarted pthread_mutex_unlock ") ;
460 void GraphExecutor::InNode::ThreadStartAction() {
461 if ( pthread_mutex_lock( &_MutexWait ) ) {
462 perror("ThreadStart pthread_mutex_lock ") ;
465 if ( _ThreadStartedSync ) {
466 cdebug << "pthread_cond " << Name() << " ThreadStart pthread_cond_signal"
468 _ThreadStartedSync = false ;
469 if ( pthread_cond_signal( &_ThreadStartedWait ) ) {
470 perror("ThreadStart pthread_cond_broadcast ") ;
472 cdebug << "pthread_cond " << Name() << " ThreadStart pthread_cond_signaled"
476 cdebug << "pthread_cond " << Name() << " NO ThreadStart pthread_cond_signal"
478 _ThreadStartedSync = true ;
480 if ( pthread_cond_wait( &_ThreadStartedWait , &_MutexWait ) ) {
481 perror("ThreadStarted pthread_cond_wait ") ;
484 cdebug << "pthread_cond " << Name() << " NO ThreadStart pthread_cond_waited"
487 if ( pthread_mutex_unlock( &_MutexWait ) ) {
488 perror("ThreadStart pthread_mutex_unlock ") ;
493 int GraphExecutor::InNode::executeAction() {
494 int oldRewindStack = ( _RewindStack > MAXSTACKTHREADSIZE ) ;
495 if ( !CreateNewThread() && oldRewindStack ) {
496 cdebug << pthread_self() << "/" << ThreadNo()
497 << " executeAction start Thread _RewindStack " << _RewindStack << " > "
498 << MAXSTACKTHREADSIZE << " CreateNewThread "
499 << CreateNewThread() << " " << Automaton()->ActionName( _NextAction ) << "(" << Name() << ")"
501 CreateNewThread( true ) ;
504 if ( CreateNewThread() ) {
505 CreateNewThread( false ) ;
506 if ( ThreadNo() == 0 ) {
508 cdebug << pthread_self() << "/" << ThreadNo()
509 << " executeAction start Thread _RewindStack " << _RewindStack << " "
510 << Automaton()->ActionName( _NextAction ) << "(" << Name() << ")"
513 int pthread_sts = 1 ;
514 // _OutNode->PushEvent( NULL , GraphExecutor::NewThreadEvent ,
515 // SUPERV::ExecutingState ) ;
516 while ( (pthread_sts = pthread_create(&T, NULL, run_function, this )) ) {
517 char * msg = "Cannot pthread_create " ;
519 cdebug << ThreadNo() << " " << msg << " --> sleep(5)" << endl ;
520 cdebug << ThreadNo() << " PTHREAD_THREADS_MAX : "
521 << PTHREAD_THREADS_MAX << " pthread_create status : " ;
522 if ( pthread_sts == EAGAIN ) {
523 cdebug << "EAGAIN(" << pthread_sts << ")" << endl ;
524 cdebug << "It seems to me that with gdb we are limited to 256 threads because of defunct" << endl ;
527 cdebug << pthread_sts << endl ;
531 pthread_exit( msg ) ;
533 cdebug << pthread_self() << "/" << ThreadNo()
534 << "executeAction has created thread " << T << endl ;
535 ThreadStartedAction() ;
536 cdebug << pthread_self() << "/" << ThreadNo()
537 << "executeAction the thread " << T << " has called NewThread and will call ExecuteAction for node "
541 cdebug << pthread_self() << "/" << ThreadNo()
542 << " executeAction restart Thread _RewindStack " << _RewindStack << " "
543 << Automaton()->StateName( State() ) << " "
544 << Automaton()->ActionName( _NextAction ) << "(" << Name()
545 << ") ReStartAction ==>" << endl;
546 State( SUPERV::SuspendedSuccessedState ) ;
547 if ( !ReStartAction( this , GraphExecutor::ReStartEvent ) ) {
548 cdebug << pthread_self() << "/" << ThreadNo()
549 << " executeAction STATE & CALLED "
550 << Automaton()->ActionName( _NextAction ) << "(" << Name()
551 << ") ERROR-DEBUG " << endl;
554 cdebug << pthread_self() << "/" << ThreadNo() << " executeAction NO CALL "
555 << Automaton()->ActionName( _NextAction ) << "(" << Name()
561 if ( _CurrentEvent == ExecuteEvent ) {
564 cdebug << pthread_self() << "/" << ThreadNo() << " executeAction call "
565 << Automaton()->ActionName( _NextAction ) << "(" << Name() << ") _RewindStack " << _RewindStack
567 return ExecuteAction() ;
572 void GraphExecutor::InNode::coutbegin() {
573 cdebug << ThreadNo() << " " << pthread_self() << " run_function begin"
574 << " " << Name() << " " << Automaton()->StateName( State() ) << endl ;
576 void GraphExecutor::InNode::coutexit() {
577 cdebug << pthread_self() << "/" << ThreadNo() << " run_function pthread_exit _RewindStack " << _RewindStack
578 << " " << Name() << " " << Automaton()->StateName( State() ) << endl ;
580 void * run_function(void *p) {
581 GraphExecutor::InNode *aNode = (GraphExecutor::InNode *) p;
583 aNode->NewThread( pthread_self() ) ;
584 if ( pthread_setcanceltype( PTHREAD_CANCEL_ASYNCHRONOUS , NULL ) ) {
585 perror("pthread_setcanceltype ") ;
588 if ( pthread_setcancelstate( PTHREAD_CANCEL_ENABLE , NULL ) ) {
589 perror("pthread_setcancelstate ") ;
592 aNode->ThreadStartAction() ;
593 aNode->ExecuteAction() ;
594 char * msg = new char[40] ;
595 sprintf( msg , "%d" , (int ) aNode->ThreadNo() ) ;
596 strcat( msg , " thread exit" ) ;
598 aNode->ExitThread() ;
601 pthread_exit( (void * ) smsg.c_str() ) ;
605 int GraphExecutor::InNode::ExecuteAction() {
608 // const char * nextactionname = Automaton()->ActionName( _NextAction ) ;
609 // const char * statename = Automaton()->StateName( State() ) ;
610 // const char * nextstatename = Automaton()->StateName( _NextState ) ;
611 // cdebug << pthread_self() << "/" << ThreadNo() << " --> ExecuteAction "
612 // << nextactionname << " " << statename << " NextState "
613 // << nextstatename << endl ;
615 State( _NextState ) ;
616 switch ( _NextAction ) {
617 case GraphExecutor::ErrorAction : {
618 sts = ErrorAction() ;
621 case GraphExecutor::VoidAction : {
625 case GraphExecutor::DataWaiting_SomeDataReadyAction : {
626 sts = DataWaiting_SomeDataReadyAction() ;
629 case GraphExecutor::DataUndef_NotAllDataReadyAction : {
630 sts = DataUndef_NotAllDataReadyAction() ;
633 case GraphExecutor::DataUndef_AllDataReadyAction : {
634 sts = DataUndef_AllDataReadyAction() ;
637 case GraphExecutor::DataReady_SuspendAction : {
638 sts = DataReady_SuspendAction() ;
641 case GraphExecutor::SuspendedReady_ResumeAction : {
642 sts = SuspendedReady_ResumeAction() ;
645 case GraphExecutor::DataReady_KillAction : {
646 sts = DataReady_KillAction() ;
649 case GraphExecutor::DataReady_StopAction : {
650 sts = DataReady_StopAction() ;
653 case GraphExecutor::DataReady_ExecuteAction : {
654 sts = DataReady_ExecuteAction() ;
657 case GraphExecutor::Executing_SuspendAction : {
658 sts = Executing_SuspendAction() ;
661 case GraphExecutor::SuspendedExecuting_ResumeAction : {
662 sts = SuspendedExecuting_ResumeAction() ;
665 case GraphExecutor::Executing_KillAction : {
666 sts = Executing_KillAction() ;
669 case GraphExecutor::Executing_StopAction : {
670 sts = Executing_StopAction() ;
673 case GraphExecutor::Executing_SuccessAction : {
674 sts = Executing_SuccessAction() ;
677 case GraphExecutor::Executing_ErrorAction : {
678 sts = Executing_ErrorAction() ;
681 case GraphExecutor::Successed_SuccessAction : {
682 sts = Successed_SuccessAction() ;
685 case GraphExecutor::Errored_ErrorAction : {
686 sts = Errored_ErrorAction() ;
689 case GraphExecutor::Successed_SuspendAction : {
690 sts = Successed_SuspendAction() ;
693 case GraphExecutor::Errored_SuspendAction : {
694 sts = Errored_SuspendAction() ;
697 case GraphExecutor::SuspendedSuccessed_ResumeAction : {
698 sts = SuspendedSuccessed_ResumeAction() ;
701 case GraphExecutor::SuspendedErrored_ResumeAction : {
702 sts = SuspendedErrored_ResumeAction() ;
705 case GraphExecutor::Successed_KillAction : {
706 sts = Successed_KillAction() ;
709 case GraphExecutor::Errored_KillAction : {
710 sts = Errored_KillAction() ;
713 case GraphExecutor::Successed_StopAction : {
714 sts = Successed_StopAction() ;
717 case GraphExecutor::Errored_StopAction : {
718 sts = Errored_StopAction() ;
721 case GraphExecutor::SuspendedSuccessed_ReStartAction : {
722 sts = SuspendedSuccessed_ReStartAction() ;
725 case GraphExecutor::SuspendedErrored_ReStartAction : {
726 sts = SuspendedErrored_ReStartAction() ;
729 case GraphExecutor::SuspendedSuccessed_ReStartAndSuspendAction : {
730 sts = SuspendedSuccessed_ReStartAndSuspendAction() ;
733 case GraphExecutor::SuspendedErrored_ReStartAndSuspendAction : {
734 sts = SuspendedErrored_ReStartAndSuspendAction() ;
738 cdebug << pthread_self() << "/" << ThreadNo()
739 << " GraphExecutor::InNodeThreads::SendEvent Error Undefined Action : "
740 << _NextAction << endl ;
744 // cdebug << pthread_self() << "/" << ThreadNo() << "<-- ExecuteAction "
745 // << Automaton()->ActionName( nextaction ) << endl ;
749 int GraphExecutor::InNode::ErrorAction() {
750 cdebug << pthread_self() << "/" << ThreadNo() << " Automaton ErrorAction Node "
755 int GraphExecutor::InNode::VoidAction() {
756 cdebug << pthread_self() << "/" << ThreadNo() << " VoidAction " << Name() << endl;
761 int GraphExecutor::InNode::DataWaiting_SomeDataReadyAction() {
762 cdebug << pthread_self() << "/" << ThreadNo()
763 << " --> DataWaiting_SomeDataReadyAction from " << DataFromNode()
764 << " to " << Name() << endl;
768 bool LoopFinished = false ;
769 bool LoopBeginning = false ;
770 bool SwitchFinished = false ;
772 if ( IsEndLoopNode() && !GetChangeNodeInLoop()->GetOutPort()->BoolValue() ) {
773 LoopFinished = true ; // End of Loop
775 if ( IsLoopNode() && GetChangeNodeInLoop()->GetOutPort()->BoolValue() ) {
776 LoopBeginning = true ; // Beginning of Loop
778 if ( IsEndSwitchNode() && !GetChangeNodeInGate()->GetOutPort()->BoolValue() ) {
779 SwitchFinished = true ; // End of Switch
781 cdebug << pthread_self() << "/" << ThreadNo() << " " << Name() << " LoopFinished " << LoopFinished
782 << " LoopBeginning " << LoopBeginning << " SwitchFinished " << SwitchFinished << endl ;
783 for ( k = 0 ; k < (unsigned int ) GetNodeInPortsSize() ; k++ ) {
784 GraphBase::InPort * anInPort = GetChangeNodeInPort(k) ;
785 GraphBase::OutPort * anOutPort = anInPort->GetOutPort() ;
786 cdebug << pthread_self() << "/" << ThreadNo() << " " << Name() << " InPort " << anInPort->PortName() << endl ;
787 if ( anInPort->IsGate() && anOutPort == NULL ) {
789 anInPort->State( SUPERV::ReadyState ) ;
790 cdebug << pthread_self() << "/" << ThreadNo() << " " << Name() << " "
791 << anInPort->PortName() << " ControlPort inactive." << endl ;
793 else if ( strcmp( DataFromNode() , anOutPort->NodeName() ) ) {
794 if ( anInPort->State() == SUPERV::ReadyState ) {
796 cdebug << pthread_self() << "/" << ThreadNo() << " " << Name() << " "
797 << anInPort->PortName() << " Was Done from "
798 << anOutPort->NodeName() << " " << anOutPort->PortName()
801 if ( GraphBase::Base::_prof_debug ) {
802 anOutPort->StringValue( *GraphBase::Base::_fdebug ) ;
807 else if ( IsLoopNode() && anInPort->IsDataConnected() ) {
808 anInPort->State( SUPERV::ReadyState ) ;
810 cdebug << pthread_self() << "/" << ThreadNo() << " " << Name() << " "
811 << anInPort->PortName() << " Was Done from "
812 << anOutPort->NodeName() << " " << anOutPort->PortName()
813 << " LoopBeginning " << LoopBeginning ;
815 if ( GraphBase::Base::_prof_debug ) {
816 anOutPort->StringValue( *GraphBase::Base::_fdebug ) ;
821 else if ( LoopFinished ) {
822 anInPort->State( SUPERV::ReadyState ) ;
824 cdebug << pthread_self() << "/" << ThreadNo() << " " << Name() << " "
825 << anInPort->PortName() << " Was Done from "
826 << anOutPort->NodeName() << " " << anOutPort->PortName()
829 if ( GraphBase::Base::_prof_debug ) {
830 anOutPort->StringValue( *GraphBase::Base::_fdebug ) ;
835 else if ( anInPort->IsGate() && SwitchFinished ) {
836 anInPort->State( SUPERV::ReadyState ) ;
838 cdebug << pthread_self() << "/" << ThreadNo() << " " << Name() << " "
839 << anInPort->PortName() << " Was Done from "
840 << anOutPort->NodeName() << " " << anOutPort->PortName()
841 << " SwitchFinished" ;
843 if ( GraphBase::Base::_prof_debug ) {
844 anOutPort->StringValue( *GraphBase::Base::_fdebug ) ;
850 cdebug << pthread_self() << "/" << ThreadNo() << " " << Name() << " "
851 << anInPort->PortName() << " Was NOT Done from "
852 << anOutPort->NodeName() << " " << anOutPort->PortName() << " "
853 << " " << Automaton()->StateName( State() ) << " DataConnected "
854 << anInPort->IsDataConnected() << " LoopBeginning "
855 << LoopBeginning << endl ;
858 else if ( anInPort->IsGate() ) {
859 const CORBA::Any * theValue = anOutPort->Value() ;
861 (*theValue) >>= GateOpened ;
862 if ( GateOpened != 0 ) {
864 anInPort->State( SUPERV::ReadyState ) ;
865 cdebug << pthread_self() << "/" << ThreadNo() << " " << Name() << " "
866 << anInPort->PortName() << " Gate is Opened from "
867 << anOutPort->NodeName() << " " << anOutPort->PortName()
870 if ( GraphBase::Base::_prof_debug ) {
871 anOutPort->StringValue( *GraphBase::Base::_fdebug ) ;
876 else if ( LoopFinished ) {
877 anInPort->State( SUPERV::ReadyState ) ;
878 cdebug << pthread_self() << "/" << ThreadNo() << " " << Name() << " "
879 << anInPort->PortName() << " GATE IS CLOSED from "
880 << anOutPort->NodeName() << " " << anOutPort->PortName()
883 if ( GraphBase::Base::_prof_debug ) {
884 anOutPort->StringValue( *GraphBase::Base::_fdebug ) ;
890 cdebug << pthread_self() << "/" << ThreadNo() << " " << Name() << " "
891 << anInPort->PortName() << " GATE IS CLOSED from "
892 << anOutPort->NodeName() << " " << anOutPort->PortName()
895 if ( GraphBase::Base::_prof_debug ) {
896 anOutPort->StringValue( *GraphBase::Base::_fdebug ) ;
904 anInPort->State( SUPERV::ReadyState ) ;
905 cdebug << pthread_self() << "/" << ThreadNo() << " " << Name() << " "
906 << anInPort->PortName() << " is Done from "
907 << anOutPort->NodeName() << " " << anOutPort->PortName() << " " ;
909 if ( GraphBase::Base::_prof_debug ) {
910 anOutPort->StringValue( *GraphBase::Base::_fdebug ) ;
917 if ( InReady == GetNodeInPortsSize() ) { // All Flags != 0 :
918 res = SendEvent( GraphExecutor::AllDataReadyEvent ); // ==> Ready to execute
920 else { // At least one Flag == 0 :
921 res = SendEvent( GraphExecutor::NotAllDataReadyEvent );
924 cdebug << pthread_self() << "/" << ThreadNo()
925 << " <-- DataWaiting_SomeDataReadyAction " << Name() << endl;
930 int GraphExecutor::InNode::DataUndef_NotAllDataReadyAction() {
931 CreateNewThreadIf( false ) ;
932 // cdebug << pthread_self() << " for " << ThreadNo()
933 // << " DataUndef_NotAllDataReadyAction " << Name() << endl;
937 int GraphExecutor::InNode::DataUndef_AllDataReadyAction() {
938 // cdebug << pthread_self() << "/" << ThreadNo()
939 // << " --> DataUndef_AllDataReadyAction " << Name()
940 // << " CreateNewThreadIf " << CreateNewThreadIf() << " IsLockedDataWait "
941 // << IsLockedDataWait() ;
942 if ( IsLockedDataWait() ) {
943 // cdebug << " WOULD DEAD-LOCK" << endl ;
944 return 0 ; // ==> DataUndef_AllDataReadyAction() after UnLockDataWait()
947 CreateNewThread( CreateNewThreadIf() ) ;
948 if ( !CreateNewThread() ) {
949 // cdebug << "Thread " << ThreadNo() << "-->" << pthread_self() << endl ;
950 ThreadNo( pthread_self() ) ;
952 _OutNode->PushEvent( this , GraphExecutor::AllDataReadyEvent ,
953 SUPERV::DataReadyState ) ;
955 SUPERV::ControlState aControl = ControlState() ;
956 switch ( aControl ) {
957 case SUPERV::VoidState : {
958 SendEvent( GraphExecutor::ExecuteEvent ) ;
961 case SUPERV::ToSuspendState : {
962 SendEvent( GraphExecutor::SuspendEvent ) ;
965 case SUPERV::ToSuspendStartState : {
966 SendEvent( GraphExecutor::SuspendEvent ) ;
969 case SUPERV::ToSuspendDoneState : {
970 SendEvent( GraphExecutor::ExecuteEvent ) ;
973 case SUPERV::ToKillState : {
974 SendEvent( GraphExecutor::KillEvent ) ;
977 case SUPERV::ToKillDoneState : {
978 SendEvent( GraphExecutor::ExecuteEvent ) ;
981 case SUPERV::ToStopState : {
982 SendEvent( GraphExecutor::StopEvent ) ;
987 << " GraphExecutor::InNodeThreads::DataUndef_AllDataReadyAction Error Undefined Control : "
988 << aControl << endl ;
992 // cdebug << pthread_self() << "/" << ThreadNo()
993 // << " <-- DataUndef_AllDataReadyAction " << Name() << endl;
997 int GraphExecutor::InNode::DataReady_SuspendAction() {
998 cdebug << pthread_self() << "/" << ThreadNo()
999 << "DataReady_SuspendAction --> Suspend " << Name()
1000 << " Threads " << _OutNode->Threads() << " SuspendedThreads "
1001 << _OutNode->SuspendedThreads() << endl;
1002 _OutNode->PushEvent( this , GraphExecutor::SuspendedReadyEvent ,
1003 SUPERV::SuspendedReadyState ) ;
1004 GraphExecutor::InNode * aReStartNode = SuspendAction() ;
1005 cdebug << pthread_self() << "/" << ThreadNo()
1006 << "DataReady_SuspendAction Resumed " << Name() << endl;
1007 if ( aReStartNode ) {
1008 _aReStartNode = NULL ;
1009 aReStartNode->SendEvent( _aReStartEvent ) ;
1012 SendEvent( GraphExecutor::ExecuteEvent ) ;
1017 int GraphExecutor::InNode::SuspendedReady_ResumeAction() {
1018 cdebug << pthread_self() << "/" << ThreadNo() << "SuspendedReady_ResumeAction "
1021 _OutNode->PushEvent( this , GraphExecutor::ResumedReadyEvent ,
1022 SUPERV::ResumedReadyState ) ;
1026 int GraphExecutor::InNode::DataReady_KillAction() {
1027 _OutNode->PushEvent( this , GraphExecutor::KilledReadyEvent ,
1028 SUPERV::KilledReadyState ) ;
1030 cdebug << pthread_self() << "/" << ThreadNo() << "DataReady_KillAction " << Name()
1031 << " will pthread_exit()" << endl;
1035 int GraphExecutor::InNode::DataReady_StopAction() {
1036 _OutNode->PushEvent( this , GraphExecutor::StoppedReadyEvent ,
1037 SUPERV::StoppedReadyState ) ;
1039 cdebug << pthread_self() << "/" << ThreadNo() << "DataReady_StopAction " << Name()
1040 << " will pthread_exit()" << endl;
1046 int GraphExecutor::InNode::DataReady_ExecuteAction() {
1049 // cdebug << pthread_self() << "/" << ThreadNo() << " --> DataReady_ExecuteAction "
1050 // << Name() << endl;
1051 _OutNode->PushEvent( this , GraphExecutor::ExecuteEvent ,
1052 SUPERV::ExecutingState ) ;
1055 SUPERV::GraphState PortState = SUPERV::ReadyState ;
1056 SUPERV::AutomatonState NewState = SUPERV::DataUndefState ;
1057 GraphExecutor::NodeEvent NewEvent = GraphExecutor::UndefinedEvent ;
1061 int nInParams = GetNodeInPortsSize() ;
1062 ServicesAnyData * InParametersList = new ServicesAnyData[nInParams];
1063 InParametersSet( Err , nInParams , InParametersList ) ;
1065 Engines::Container_var myContainer ;
1066 Engines::Component_var myObjComponent ;
1067 if ( !IsFactoryNode() ) {
1068 // cdebug << ThreadNo() << "No Component : NO StartComponent & No Ping" << endl ;
1069 if ( IsComputingNode() ) {
1070 ObjInterface( true ) ;
1071 CORBA::Object_ptr obj ;
1072 InParametersList[0].Value >>= obj ;
1073 CORBA::Object_var objvar = CORBA::Object_var( obj ) ;
1074 myObjComponent = Engines::Component::_narrow( objvar ) ;
1079 else if ( CORBA::is_nil( Component() ) ) {
1080 ostringstream astr ;
1081 astr << "Graph " << _OutNode->Graph()->Name() << " Node " << Name()
1082 << " : load of component " << ComponentName() << " in container "
1084 // _OutNode->Graph()->ObjImpl()->sendMessage( NOTIF_STEP, astr.str().c_str() ) ;
1085 Err = !_OutNode->Graph()->StartComponent( ThreadNo() , Computer() ,
1086 my_strdup( ComponentName() ) ,
1087 myContainer , myObjComponent ) ;
1088 ObjInterface( false ) ;
1089 SetContainer( myContainer ) ;
1090 SetComponent( myObjComponent ) ;
1093 myContainer = Container() ;
1094 myObjComponent = Component() ;
1095 // cdebug << ThreadNo() << "Component known : NO StartComponent & Ping"
1098 myObjComponent->ping() ;
1101 cdebug << "ping() catched" << endl ;
1106 int nOutParams = GetNodeOutPortsSize() ;
1107 ServicesAnyData * OutParametersList = new ServicesAnyData[nOutParams];
1108 InOutParametersSet( nOutParams , OutParametersList ) ;
1110 if ( Err || ControlState() == SUPERV::ToKillState ||
1111 ControlState() == SUPERV::ToKillDoneState ||
1112 ControlState() == SUPERV::ToStopState ) {
1113 cdebug << ThreadNo() << "StartComponent Error or ToKillState" << endl ;
1118 ostringstream astr ;
1119 astr << "Graph " << _OutNode->Graph()->Name() << " Run of Node " << Name() ;
1120 // _OutNode->Graph()->ObjImpl()->sendMessage( NOTIF_STEP, astr.str().c_str() ) ;
1121 cdebug << ThreadNo() << " Run( '" << ServiceName() << "'" ;
1122 for ( i = 0 ; i < (int ) ServiceInParameter().length() ; i++ ) {
1123 cdebug << " , " << InParametersList[ i ].Name << "[kind"
1124 << InParametersList[ i ].Value.type()->kind() << "]" ;
1126 for ( i = 0 ; i < (int ) ServiceOutParameter().length() ; i++ ) {
1127 cdebug << " , " << OutParametersList[ i ].Name << "[kind"
1128 << OutParametersList[ i ].Value.type()->kind() << "]" ;
1130 if ( IsOneOfInLineNodes() ) {
1131 cdebug << " , PyFuncName '" << InLineNode()->PyFuncName() << "' PyRunMethod "
1132 << InLineNode()->PyRunMethod() << " length " << (*InLineNode()->PythonFunction()).length() ;
1134 cdebug << ")" << endl ;
1136 if ( IsOneOfInLineNodes() ) {
1137 bool StsPyDynInvoke = true;
1138 _OutNode->PyThreadLock() ;
1141 // if ( IsInLineNode() && (*InLineNode()->PythonFunction()).length() &&
1142 bool CopyInOut = false ;
1143 if ( IsInLineNode() && /*InLineNode()->PyRunMethod() &&*/
1144 strlen( InLineNode()->PyFuncName() ) ) {
1145 // cdebug << ThreadNo() << " !ObjInterface " << Name() << " PyFuncName '"
1146 // << InLineNode()->PyFuncName()
1147 // << "' IsInLineNode PyDynInvoke" << endl ;
1148 StsPyDynInvoke = PyDynInvoke( InLineNode()->PyRunMethod() ,
1149 InLineNode()->PyFuncName() ,
1150 &InParametersList[0] , ServiceInParameter().length() ,
1151 &OutParametersList[0] , ServiceOutParameter().length() ) ;
1153 else if ( IsLoopNode() ) {
1154 bool CopyOutIn = false ;
1155 if ( GetNodeInLoop()->GetOutPort()->BoolValue() && /*InLineNode()->PyRunMethod() &&*/
1156 strlen( InLineNode()->PyFuncName() ) ) { // InLoop Port
1157 // cdebug << ThreadNo() << " !ObjInterface " << Name()
1158 // << " IsLoopNode PyDynInvoke '" << InLineNode()->PyFuncName()
1160 StsPyDynInvoke = PyDynInvoke( InLineNode()->PyRunMethod() ,
1161 InLineNode()->PyFuncName() ,
1162 &InParametersList[1] , ServiceInParameter().length() ,
1163 &OutParametersList[1] , ServiceOutParameter().length() ) ;
1166 else if ( LoopNode()->PyNextMethod() &&
1167 strlen( LoopNode()->PyNextName() ) ){
1168 // cdebug << ThreadNo() << " !ObjInterface " << Name()
1169 // << " IsLoopNode PyDynInvoke '" << LoopNode()->PyNextName()
1171 StsPyDynInvoke = PyDynInvoke( LoopNode()->PyNextMethod() ,
1172 LoopNode()->PyNextName() ,
1173 &InParametersList[1] , ServiceInParameter().length() ,
1174 &OutParametersList[1] , ServiceOutParameter().length() ) ;
1177 if ( StsPyDynInvoke && CopyOutIn ) {
1178 // cdebug << ThreadNo() << " !ObjInterface " << Name()
1179 // << " IsLoopNode PyDynInvoke '" << LoopNode()->PyMoreName()
1180 // << "' Copy of " << ServiceInParameter().length()
1181 // << " OutParameters" << endl ;
1183 for ( i = 1 ; i <= (int ) ServiceInParameter().length() ; i++ ) {
1184 InParametersList[i].Value = OutParametersList[i].Value ;
1185 InParametersList[i].Name = OutParametersList[i].Name ;
1187 switch ( InParametersList[i].Value.type()->kind() ) {
1188 case CORBA::tk_string :
1190 InParametersList[i].Value >>= t ;
1191 cdebug << "ArgOut->In" << i << " : "
1192 << InParametersList[i].Name.c_str()
1193 << " Value(string) " << t << endl ;
1195 case CORBA::tk_double :
1197 InParametersList[i].Value >>= d;
1198 cdebug << "ArgOut->In" << i << " : "
1199 << InParametersList[i].Name.c_str()
1200 << " Value(double) " << d << endl ;
1202 case CORBA::tk_long :
1204 InParametersList[i].Value >>= l;
1205 cdebug << "ArgOut->In" << i << " : "
1206 << InParametersList[i].Name.c_str()
1207 << " Value(long) " << l << endl ;
1209 case CORBA::tk_objref :
1210 CORBA::Object_ptr obj ;
1213 InParametersList[i].Value >>= obj ;
1214 retstr = ObjectToString( obj );
1215 cdebug << "ArgOut->In" << i << " : "
1216 << InParametersList[i].Name.c_str()
1217 << " Value(object reference) " << retstr << endl ;
1220 cdebug << "ArgOut->In" << i << " : "
1221 << InParametersList[i].Name.c_str()
1222 << " Value(object reference) Catched ERROR" << endl ;
1226 cdebug << "ArgOut->In" << i << " : "
1227 << InParametersList[i].Name.c_str()
1228 << " Value(other) ERROR" << endl ;
1232 if ( LoopNode()->PyMoreMethod() && strlen( LoopNode()->PyMoreName() ) ) {
1233 StsPyDynInvoke = PyDynInvoke( LoopNode()->PyMoreMethod() ,
1234 LoopNode()->PyMoreName() ,
1235 &InParametersList[1] , ServiceInParameter().length() ,
1236 &OutParametersList[0] , ServiceOutParameter().length()+1 ) ;
1242 else if ( !StsPyDynInvoke ) {
1244 cdebug << ThreadNo() << " InLineNode " << Name() << " "
1245 << InLineNode()->PyFuncName() << "/" << LoopNode()->PyNextName()
1246 << " Python Dynamic Call Error"
1250 else if ( IsSwitchNode() && /*InLineNode()->PyRunMethod() &&*/
1251 strlen( InLineNode()->PyFuncName() ) ) {
1252 // cdebug << ThreadNo() << " !ObjInterface " << Name() << " PyFuncName '"
1253 // << InLineNode()->PyFuncName()
1254 // << "' IsSwitchNode PyDynInvoke" << endl ;
1255 StsPyDynInvoke = PyDynInvoke( InLineNode()->PyRunMethod() ,
1256 InLineNode()->PyFuncName() ,
1257 &InParametersList[0] , ServiceInParameter().length() ,
1258 &OutParametersList[0] , ServiceOutParameter().length() ) ;
1260 // else if ( IsGOTONode() && (*GOTONode()->PythonFunction()).length() &&
1261 else if ( IsGOTONode() && /*InLineNode()->PyRunMethod() &&*/
1262 strlen( InLineNode()->PyFuncName() ) ) {
1263 // cdebug << ThreadNo() << " !ObjInterface " << Name() << " PyFuncName '"
1264 // << InLineNode()->PyFuncName()
1265 // << "' IsGOTONode PyDynInvoke" << endl ;
1266 StsPyDynInvoke = PyDynInvoke( InLineNode()->PyRunMethod() ,
1267 InLineNode()->PyFuncName() ,
1268 &InParametersList[0] , ServiceInParameter().length() ,
1269 &OutParametersList[0] , ServiceOutParameter().length() ) ;
1271 // else if ( IsEndSwitchNode() && (*InLineNode()->PythonFunction()).length() &&
1272 else if ( ( IsEndSwitchNode() ) &&
1273 InLineNode()->PyRunMethod() && strlen( InLineNode()->PyFuncName() ) ) {
1274 // cdebug << ThreadNo() << " !ObjInterface " << Name() << " PyFuncName '"
1275 // << InLineNode()->PyFuncName()
1276 // << "' IsSwitchNode PyDynInvoke" << endl ;
1277 StsPyDynInvoke = PyDynInvoke( InLineNode()->PyRunMethod() ,
1278 InLineNode()->PyFuncName() ,
1279 &InParametersList[0] , ServiceInParameter().length() ,
1280 &OutParametersList[0] , ServiceOutParameter().length() ) ;
1282 else if ( ( IsEndLoopNode() ) &&
1283 InLineNode()->PyRunMethod() && strlen( InLineNode()->PyFuncName() ) ) {
1284 // cdebug << ThreadNo() << " !ObjInterface " << Name() << " PyFuncName '"
1285 // << InLineNode()->PyFuncName()
1286 // << "' IsSwitchNode PyDynInvoke" << endl ;
1287 StsPyDynInvoke = PyDynInvoke( InLineNode()->PyRunMethod() ,
1288 InLineNode()->PyFuncName() ,
1289 &InParametersList[0] , ServiceInParameter().length() + 1 ,
1290 &OutParametersList[0] , ServiceOutParameter().length() + 1 ) ;
1292 // else if ( (*InLineNode()->PythonFunction()).length() == 0 ||
1293 if ( InLineNode()->PyRunMethod() == NULL ||
1294 strlen( InLineNode()->PyFuncName() ) == 0 || CopyInOut ) {
1295 // cdebug << ThreadNo() << " !ObjInterface " << Name()
1296 // << " Copy of " << ServiceInParameter().length()
1297 // << " OutParameters" << endl ;
1301 if ( IsLoopNode() || IsEndLoopNode() ) {
1303 argin0 = 1 ; // after DoLoop
1304 if ( IsLoopNode() ) {
1305 OutParametersList[0].Value = InParametersList[0].Value ; // DoLoop
1308 for ( i = 0 ; i < (int ) ServiceInParameter().length() ; i++ ) {
1309 OutParametersList[argout0 + i].Value = InParametersList[argin0 + i].Value ;
1311 switch ( InParametersList[argin0 + i].Value.type()->kind() ) {
1312 case CORBA::tk_string :
1313 cdebug << "ArgOut->In" << argin0 + i << " : "
1314 << InParametersList[argin0 + i].Name.c_str()
1315 << " Value(string) "
1316 << OutParametersList[argout0 + i].Name.c_str() << endl ;
1318 case CORBA::tk_double :
1319 cdebug << "ArgOut->In" << argin0 + i << " : "
1320 << InParametersList[argin0 + i].Name.c_str()
1321 << " Value(double) "
1322 << OutParametersList[argout0 + i].Name.c_str() << endl ;
1324 case CORBA::tk_long :
1325 cdebug << "ArgOut->In" << argin0 + i << " : "
1326 << InParametersList[argin0 + i].Name.c_str()
1328 << OutParametersList[argout0 + i ].Name.c_str() << endl ;
1330 case CORBA::tk_objref :
1331 cdebug << "ArgOut->In" << argin0 + i << " : "
1332 << InParametersList[argin0 + i].Name.c_str()
1333 << " Value(object reference) "
1334 << OutParametersList[argout0 + i].Name.c_str() << endl ;
1337 cdebug << "ArgOut->In" << argin0 + i << " : "
1338 << InParametersList[argin0 + i].Name.c_str()
1339 << " Value(other) ERROR "
1340 << OutParametersList[argout0 + i].Name.c_str() << endl ;
1345 if ( !StsPyDynInvoke ) {
1347 cdebug << ThreadNo() << " InLineNode " << Name()
1348 << " Python Dynamic Call Error"
1354 cdebug << ThreadNo() << " InLineNode " << Name()
1355 << " Python Dynamic Call Exception catched ERROR"
1359 _OutNode->PyThreadUnLock() ;
1364 cdebug << "DynInvoke -> Names " << _OutNode->Graph()->Name() << " " << Name() << endl ;
1365 DynInvoke( myObjComponent, "Names" ,
1366 _OutNode->Graph()->Name() , Name() ) ;
1369 cdebug << "DynInvoke Names catched ERROR" << endl ;
1371 // for DataStreamNodes : call of SetProperties ===> environment variables in the component/container
1372 if ( ComputingNode()->HasDataStream() ) {
1374 cdebug << "DynInvoke -> SetProperties " << _OutNode->Graph()->Name() << " " << Name() << endl ;
1375 Engines::FieldsDict_var dict = new Engines::FieldsDict;
1377 dict[ 0 ].key = CORBA::string_dup( "CAL_MACHINE");
1378 // myContainer->getHostName() ne renvoit pas le nom complet (avec domaine).
1379 // dict[ 0 ].value <<= myContainer->getHostName() ;
1380 char FullyQualifiedDomainName[256]="";
1381 gethostname(FullyQualifiedDomainName,255);
1382 dict[ 0 ].value <<= FullyQualifiedDomainName ;
1383 dict[ 1 ].key = CORBA::string_dup( "CAL_REPERTOIRE");
1384 dict[ 1 ].value <<= "/tmp" ;
1385 dict[ 2 ].key = CORBA::string_dup( "CAL_COUPLAGE");
1386 stringstream ofst1 ;
1387 ofst1 << ComputingNode()->SubStreamGraph() ;
1388 string cpl = string( "/tmp/" ) + string( _OutNode->Graph()->Name() ) + string( "_" ) +
1389 ofst1.str() + string( ".cpl" );
1390 dict[ 2 ].value <<= cpl.c_str() ;
1391 dict[ 3 ].key = CORBA::string_dup( "SALOME_INSTANCE_NAME");
1392 string uname = Name();
1394 dict[ 3 ].value <<= uname.c_str() ;
1396 myObjComponent->setProperties( dict ) ;
1399 cdebug << "DynInvoke setProperties catched ERROR" << endl ;
1403 if ( !Err && IsComputingNode() ) {
1404 cdebug << ThreadNo() << " !ObjInterface " << Name()
1405 << " IsComputingNode DynInvoke" << endl ;
1406 cdebug << ServiceInParameter().length()-1 << " input parameters and "
1407 << ServiceOutParameter().length() << " output parameters" << endl ;
1408 DynInvoke( myObjComponent,
1410 &InParametersList[1] , ServiceInParameter().length()-1 ,
1411 &OutParametersList[0] , ServiceOutParameter().length() ) ;
1413 else if ( !Err &&IsFactoryNode() ) {
1414 cdebug << ThreadNo() << " !ObjInterface " << Name()
1415 << " IsFactoryNode DynInvoke" << endl ;
1416 cdebug << ServiceInParameter().length() << " input parameters and "
1417 << ServiceOutParameter().length() << " output parameters" << endl ;
1418 DynInvoke( myObjComponent,
1420 &InParametersList[0] , ServiceInParameter().length() ,
1421 &OutParametersList[0] , ServiceOutParameter().length() ) ;
1423 // cdebug << ThreadNo() << " Component::CpuUsed " << Name() << " "
1424 // << myObjComponent->CpuUsed_impl() << endl ;
1428 cdebug << ThreadNo() << " !ObjInterface " << Name()
1429 << " Node(Component) Dynamic Call Exception catched ERROR"
1440 ostringstream astr ;
1441 astr << "Graph " << _OutNode->Graph()->Name() << " Node " << Name() << " is done : "
1442 << Automaton()->StateName( State() ) ;
1443 // _OutNode->Graph()->ObjImpl()->sendMessage( NOTIF_STEP, astr.str().c_str() ) ;
1445 if ( ControlState() == SUPERV::ToKillState ||
1446 ControlState() == SUPERV::ToKillDoneState ||
1447 ControlState() == SUPERV::ToStopState ) {
1448 PortState = SUPERV::ErrorState ;
1449 NewState = SUPERV::KilledState ;
1450 NewEvent = GraphExecutor::KillEvent ;
1453 PortState = SUPERV::ErrorState ;
1454 NewState = SUPERV::ErroredState ;
1455 NewEvent = GraphExecutor::ErrorEvent ;
1459 PortState = SUPERV::ReadyState ;
1460 NewState = SUPERV::DataReadyState ;
1461 NewEvent = GraphExecutor::SuccessEvent ;
1464 bool ErrOut = OutParametersSet( Err , PortState , nOutParams , OutParametersList ) ;
1467 NewEvent = GraphExecutor::ErrorEvent ;
1470 delete [] InParametersList ;
1471 delete [] OutParametersList ;
1474 SendEvent( NewEvent );
1476 // cdebug << ThreadNo() << " <-- DataReady_ExecuteAction " << Name() << endl;
1480 int GraphExecutor::InNode::Executing_SuspendAction() {
1481 _OutNode->PushEvent( this , GraphExecutor::SuspendedExecutingEvent ,
1482 SUPERV::SuspendedExecutingState ) ;
1483 cdebug << ThreadNo() << " Executing_SuspendAction " << Name() << endl;
1487 int GraphExecutor::InNode::SuspendedExecuting_ResumeAction() {
1488 cdebug << ThreadNo() << " SuspendedExecuting_ResumeAction " << Name() << endl;
1489 SUPERV::AutomatonState next_state ;
1490 next_state = Automaton()->NextState( State() , GraphExecutor::ExecutingEvent ) ;
1491 _OutNode->NewThread() ; // Only for Threads count
1492 _OutNode->PushEvent( this , GraphExecutor::ResumedExecutingEvent ,
1494 State( next_state ) ;
1498 int GraphExecutor::InNode::Executing_KillAction() {
1499 cdebug << ThreadNo() << " Executing_KillAction " << Name() << endl;
1501 if ( pthread_self() == ThreadNo() ) {
1502 cdebug << "Executing_KillAction would pthread_canceled itself" << endl ;
1504 _OutNode->PushEvent( this , GraphExecutor::KilledExecutingEvent ,
1505 SUPERV::KilledExecutingState ) ;
1508 else if ( pthread_cancel( ThreadNo() ) ) {
1509 perror("Executing_KillAction pthread_cancel error") ;
1512 cdebug << "Executing_KillAction : ThreadId " << ThreadNo()
1513 << " pthread_canceled" << endl ;
1515 _OutNode->ExitThread() ;
1516 _OutNode->PushEvent( this , GraphExecutor::KilledExecutingEvent ,
1517 SUPERV::KilledExecutingState ) ;
1522 int GraphExecutor::InNode::Executing_StopAction() {
1523 cdebug << ThreadNo() << " Executing_StopAction " << Name() << endl;
1525 if ( pthread_cancel( ThreadNo() ) ) {
1526 perror("Executing_KillAction pthread_cancel error") ;
1529 cdebug << "Executing_KillAction : ThreadId " << ThreadNo()
1530 << " pthread_canceled" << endl ;
1532 _OutNode->ExitThread() ;
1533 _OutNode->PushEvent( this , GraphExecutor::StoppedExecutingEvent ,
1534 SUPERV::StoppedExecutingState ) ;
1539 int GraphExecutor::InNode::Executing_SuccessAction() {
1540 // cdebug << ThreadNo() << " --> Executing_SuccessAction " << Name() << endl;
1541 _OutNode->PushEvent( this , GraphExecutor::SuccessedExecutingEvent ,
1542 SUPERV::SuccessedState ) ;
1543 SUPERV::ControlState aControl = ControlState() ;
1544 switch ( aControl ) {
1545 case SUPERV::VoidState : {
1546 SendEvent( SuccessEvent ) ;
1549 case SUPERV::ToSuspendState : {
1550 SendEvent( SuccessEvent ) ;
1553 case SUPERV::ToSuspendDoneState : {
1554 SendEvent( GraphExecutor::SuspendEvent ) ;
1557 case SUPERV::ToKillState : {
1558 SendEvent( GraphExecutor::KillEvent ) ;
1561 case SUPERV::ToKillDoneState : {
1562 SendEvent( GraphExecutor::KillEvent ) ;
1565 case SUPERV::ToStopState : {
1566 SendEvent( GraphExecutor::StopEvent ) ;
1570 cdebug << ThreadNo()
1571 << " GraphExecutor::InNodeThreads::Executing_SuccessAction Error Undefined Control : "
1572 << aControl << endl ;
1576 // cdebug << ThreadNo() << " <-- Executing_SuccessAction " << Name() << endl;
1580 int GraphExecutor::InNode::Executing_ErrorAction() {
1581 cdebug << ThreadNo() << " --> Executing_ErrorAction " << Name() << endl;
1582 _OutNode->PushEvent( this , GraphExecutor::ErroredExecutingEvent ,
1583 SUPERV::ErroredState ) ;
1585 SUPERV::ControlState aControl = ControlState() ;
1586 switch ( aControl ) {
1587 case SUPERV::VoidState : {
1588 SendEvent( ErrorEvent ) ;
1591 case SUPERV::ToSuspendState : {
1592 SendEvent( ErrorEvent ) ;
1595 case SUPERV::ToSuspendDoneState : {
1596 SendEvent( GraphExecutor::SuspendEvent ) ;
1599 case SUPERV::ToKillState : {
1600 SendEvent( GraphExecutor::KillEvent ) ;
1603 case SUPERV::ToKillDoneState : {
1604 SendEvent( GraphExecutor::KillEvent ) ;
1607 case SUPERV::ToStopState : {
1608 SendEvent( GraphExecutor::StopEvent ) ;
1612 cdebug << ThreadNo()
1613 << " GraphExecutor::InNodeThreads::Executing_ErrorAction Error Undefined Control : "
1614 << aControl << endl ;
1618 cdebug << ThreadNo() << " <-- Executing_ErrorAction " << Name() << endl;
1622 // Set SUPERV::WaitingState to all InPorts
1623 void GraphExecutor::InNode::SetWaitingStates(GraphExecutor::InNode * EndNode ) {
1626 bool docdebug = false ;
1627 State( SUPERV::DataWaitingState ) ;
1628 for ( i = 0 ; i < GetNodeInPortsSize() ; i++ ) {
1629 GraphBase::InPort * anInPort = GetChangeNodeInPort( i ) ;
1630 if ( anInPort->IsGate() ) { // Loop : Open the doors
1631 GraphBase::OutPort * anOutPort = anInPort->GetOutPort() ;
1633 CORBA::Any * anAny = new CORBA::Any() ;
1634 *anAny <<= (long ) 1 ;
1635 anOutPort->Value( anAny ) ;
1636 anInPort->State( SUPERV::ReadyState ) ;
1639 else if ( anInPort->State() != SUPERV::WaitingState ) {
1641 // cdebug << ThreadNo()
1642 // << " --> GraphExecutor::InNodeThreads::SetWaitingStates " << Name() << endl;
1645 if ( !anInPort->IsDataStream() ) {
1646 anInPort->State( SUPERV::WaitingState ) ;
1650 for ( i = 0 ; i < GetNodeOutPortsSize() ; i++ ) {
1651 GraphBase::OutPort * anOutPort = GetChangeNodeOutPort( i ) ;
1652 for ( j = 0 ; j < anOutPort->InPortsSize() ; j++ ) {
1653 if ( !( IsGOTONode() && anOutPort->IsGate() ) &&
1654 !( IsEndLoopNode() && ( anOutPort->IsGate() ||
1655 anOutPort->IsLoop() ) ) &&
1656 !anOutPort->IsDataStream() &&
1657 !anOutPort->ChangeInPorts( j )->IsDataStream() ) {
1658 // cdebug << ThreadNo()
1659 // << " GraphExecutor::InNodeThreads::SetWaitingStates "
1660 // << Name() << "( " << anOutPort->PortName() << " ) --> InPort "
1661 // << anOutPort->ChangeInPorts( j )->PortName() << " from Node "
1662 // << anOutPort->ChangeInPorts( j )->NodeName() << endl;
1663 GraphExecutor::InNode * aNode = (GraphExecutor::InNode * ) _OutNode->Graph()->GetChangeGraphNode( anOutPort->ChangeInPorts( j )->NodeName() )->GetInNode() ;
1664 if ( aNode != EndNode ) {
1665 aNode->SetWaitingStates( EndNode ) ;
1672 int GraphExecutor::InNode::Successed_SuccessAction() {
1673 // cdebug << ThreadNo() << " --> Successed_SuccessAction " << Name() << endl;
1675 int linkednodesnumber = LinkedNodesSize() ;
1676 GraphExecutor::InNode *firstzeroNode = NULL ;
1677 GraphExecutor::InNode *firsttoNode = NULL ;
1678 GraphExecutor::InNode *toNode ;
1681 list<GraphExecutor::InNode *> SomeDataNodes ;
1685 if ( IsGOTONode() ||
1686 ( IsEndLoopNode() && GetNodeInLoop()->GetOutPort()->BoolValue() ) ) {
1687 cdebug << ThreadNo() << " Successed_SuccessAction " << Name()
1688 << " SetWaitingStates " << endl ;
1689 const GraphBase::OutPort * aGateOutPort ;
1690 if ( IsGOTONode() ) {
1691 aGateOutPort = GetNodeOutGate() ;
1694 aGateOutPort = GetNodeOutLoop() ;
1696 for ( i = 0 ; i < aGateOutPort->InPortsSize() ; i++ ) {
1697 const GraphBase::InPort * anInPort = aGateOutPort->InPorts( i ) ;
1698 GraphExecutor::InNode * aLabelNode = (GraphExecutor::InNode *) _OutNode->Graph()->GetChangeGraphNode( anInPort->NodeName() )->GetInNode() ;
1699 // cdebug << ThreadNo() << " Successed_SuccessAction " << Name() << " will Loop to HeadNode "
1700 // << aLabelNode->Name() << " from port " << anInPort->PortName() << endl ;
1701 aLabelNode->SetWaitingStates( this ) ;
1702 for ( j = 0 ; j < aLabelNode->GetNodeInPortsSize() ; j++ ) {
1703 const GraphBase::InPort * anInPort = aLabelNode->GetNodeInPort( j ) ;
1704 if ( anInPort->GetOutPort() ) {
1705 // cdebug << aLabelNode->Name() << "(" << anInPort->PortName() << ") value : "
1706 // << anInPort->GetOutPort()->NodeName() << "(" << anInPort->GetOutPort()->PortName() << ")"
1710 for ( j = 0 ; j < GetNodeOutPortsSize() ; j++ ) {
1711 GraphBase::OutPort * aBusParamOutPort = GetChangeNodeOutPort( j ) ;
1712 if ( !aBusParamOutPort->IsGate() ) {
1713 GraphBase::InPort * aBusParamChangeInPort = NULL ;
1714 if ( aBusParamOutPort->IsLoop() ) {
1715 aBusParamChangeInPort = aLabelNode->GetChangeNodeInLoop() ;
1718 aBusParamChangeInPort = aLabelNode->GetChangeInPort( aBusParamOutPort->PortName() ) ;
1720 if ( aBusParamChangeInPort ) {
1721 aBusParamChangeInPort->ChangeOutPort( aBusParamOutPort ) ;
1722 // cdebug << ThreadNo() << " Successed_SuccessAction " << Name() << " ChangeOutPort to HeadNode "
1723 // << aLabelNode->Name() << "(" << aBusParamChangeInPort->PortName() << ") from port "
1724 // << aBusParamOutPort->PortName() << endl ;
1725 if ( !aLabelNode->IsLockedDataWait() ) {
1726 res = aLabelNode->SendSomeDataReady( Name() ) ;
1728 if ( firsttoNode == NULL &&
1729 aLabelNode->ThreadNo() == pthread_self() ) {
1730 firsttoNode = aLabelNode ;
1731 // cdebug << ThreadNo() << " Successed_SuccessAction firsttoNode "
1732 // << aLabelNode->Name() << endl ;
1734 else if ( firstzeroNode == NULL &&
1735 aLabelNode->ThreadNo() == 0 ) {
1736 firstzeroNode = aLabelNode ;
1739 SomeDataNodes.push_back( aLabelNode ) ;
1740 // cdebug << ThreadNo() << " Successed_SuccessAction " << Name() << " push "
1741 // << aLabelNode->Name() << " " << SomeDataNodes.size()
1747 // cdebug << ThreadNo()
1748 // << " Successed_SuccessAction Loop to HeadNode "
1749 // << aLabelNode->Name() << " with datas from " << Name() << "("
1750 // << aBusParamOutPort->PortName() << ") to port "
1751 // << aBusParamChangeInPort->PortName() << endl;
1755 // cdebug << ThreadNo() << " ERROR in Successed_SuccessAction of " << Name()
1756 // << " NO port " << aBusParamOutPort->PortName() << " in "
1757 // << aLabelNode->Name() << endl;
1761 for ( j = 0 ; j < aLabelNode->GetNodeInPortsSize() ; j++ ) {
1762 const GraphBase::InPort * anInPort = aLabelNode->GetNodeInPort( j ) ;
1763 if ( anInPort->GetOutPort() ) {
1764 // cdebug << aLabelNode->Name() << "(" << anInPort->PortName() << ") value : "
1765 // << anInPort->GetOutPort()->NodeName() << "(" << anInPort->GetOutPort()->PortName() << ")"
1769 const GraphBase::InPort * aGateInPort = aLabelNode->GetNodeInGate() ;
1770 if ( aGateInPort ) {
1771 if ( aGateInPort->GetOutPort() ) {
1772 aGateInPort->GetOutPort()->Value( aGateOutPort->Value() ) ;
1774 if ( !aLabelNode->IsLockedDataWait() ) {
1775 res = aLabelNode->SendSomeDataReady( Name() ) ;
1777 if ( firsttoNode == NULL &&
1778 aLabelNode->ThreadNo() == pthread_self() ) {
1779 firsttoNode = aLabelNode ;
1780 // cdebug << ThreadNo() << " Successed_SuccessAction firsttoNode "
1781 // << aLabelNode->Name() << endl ;
1783 else if ( firstzeroNode == NULL &&
1784 aLabelNode->ThreadNo() == 0 ) {
1785 firstzeroNode = aLabelNode ;
1788 SomeDataNodes.push_back( aLabelNode ) ;
1789 // cdebug << ThreadNo() << " Successed_SuccessAction " << Name() << " push "
1790 // << aLabelNode->Name() << " " << SomeDataNodes.size()
1797 cdebug << ThreadNo() << " ERROR in Successed_SuccessAction of " << Name()
1798 << " NO port " << aGateOutPort->PortName() << " in "
1799 << aLabelNode->Name() << endl;
1805 // cdebug << ThreadNo() << " Successed_SuccessAction of " << Name()
1806 // << " with " << LinkedNodesSize() << " linked nodes :" ;
1807 for ( i = 0 ; i < LinkedNodesSize() ; i++ ) {
1808 if ( LinkedNodes( i )->IsDataFlowNode() ) {
1809 linkednodesnumber -= 1 ;
1811 // cdebug << " " << LinkedNodes( i )->Name() ;
1814 for ( i = 0 ; i < LinkedNodesSize() ; i++ ) {
1815 bool IgnoreForEndLoop = false ;
1816 GraphBase::ComputingNode * aComputingNode ;
1817 aComputingNode = (GraphBase::ComputingNode * ) LinkedNodes( i ) ;
1818 toNode = (GraphExecutor::InNode *) aComputingNode->GetInNode() ;
1819 // cdebug << ThreadNo() << " Successed_SuccessAction of " << Name()
1820 // << " [" << i << "] " << LinkedNodes( i )->Name() << endl ;
1821 if ( toNode && !toNode->IsDataFlowNode() ) {
1822 if ( IsComputingNode() && toNode->IsInLineNode() ) {
1823 GraphBase::InPort * toGateInPort = toNode->GetChangeNodeInGate() ;
1824 toGateInPort->State( SUPERV::ReadyState ) ;
1825 GraphBase::OutPort * GateOutPort = toGateInPort->GetOutPort() ;
1826 if ( GateOutPort ) {
1827 GateOutPort->PortStatus( DataConnected );
1828 GateOutPort->State( SUPERV::ReadyState ) ;
1829 GateOutPort->Done( true ) ;
1833 if ( toNode && IsLoopNode() ) {
1834 GraphBase::OutPort * fromLoopOutPort = GetChangeNodeOutLoop() ;
1835 if ( !fromLoopOutPort->BoolValue() ) { // Ne pas faire la boucle
1836 if ( strcmp( toNode->Name() , CoupledNode()->Name() ) ) {
1837 IgnoreForEndLoop = true ;
1839 else { // toNode is the EndLoopNode
1840 GraphBase::InPort * toLoopInPort ;
1841 toLoopInPort = toNode->GetChangeNodeInLoop() ;
1842 if ( toLoopInPort->State() != SUPERV::ReadyState ) {
1843 toLoopInPort->State( SUPERV::ReadyState ) ;
1848 else if ( toNode && IsSwitchNode() ) {
1850 else if ( toNode && toNode->IsInLineNode() ) {
1852 for ( j = 0 ; j < toNode->GetNodeInPortsSize() ; j++ ) {
1853 toNode->GetChangeNodeInPort( j )->InitialOutPort() ;
1856 if ( toNode && !IgnoreForEndLoop ) {
1857 if ( toNode && toNode->IsLoopNode() ) {
1858 GraphBase::InPort * toLoopInPort = toNode->GetChangeNodeInLoop() ;
1859 toLoopInPort->State( SUPERV::ReadyState ) ;
1860 GraphBase::OutPort * LoopOutPort = toLoopInPort->GetOutPort() ;
1861 LoopOutPort->PortStatus( DataConnected );
1862 LoopOutPort->State( SUPERV::ReadyState ) ;
1863 LoopOutPort->Done( true ) ;
1864 CORBA::Any * anAny = new CORBA::Any() ;
1865 *anAny <<= (long ) 1 ;
1866 LoopOutPort->Value( anAny ) ;
1868 for ( j = 0 ; j < toNode->GetNodeInPortsSize() ; j++ ) {
1869 toNode->GetChangeNodeInPort( j )->InitialOutPort() ;
1872 res = toNode->SendSomeDataReady( Name() ) ;
1874 if ( firsttoNode == NULL &&
1875 toNode->ThreadNo() == pthread_self() ) {
1876 firsttoNode = toNode ;
1877 // cdebug << ThreadNo() << " Successed_SuccessAction firsttoNode "
1878 // << toNode->Name() << endl ;
1880 else if ( firstzeroNode == NULL &&
1881 toNode->ThreadNo() == 0 ) {
1882 firstzeroNode = toNode ;
1885 SomeDataNodes.push_back( toNode ) ;
1886 // cdebug << ThreadNo() << " Successed_SuccessAction " << Name() << " push "
1887 // << toNode->Name() << " " << SomeDataNodes.size() << endl ;
1894 if ( firsttoNode == NULL && firstzeroNode ) {
1895 firsttoNode = firstzeroNode ;
1896 // cdebug << ThreadNo()
1897 // << " Successed_SuccessAction firsttoNode = firstzeroNode "
1900 else if ( firsttoNode && firstzeroNode ) {
1901 SomeDataNodes.push_back( firstzeroNode ) ;
1902 // cdebug << ThreadNo() << " Successed_SuccessAction " << Name() << " push firstzeroNode "
1903 // << firstzeroNode->Name() << " " << SomeDataNodes.size() << endl ;
1906 while ( SomeDataNodes.size() ) {
1907 GraphExecutor::InNode *aNode = SomeDataNodes.front() ;
1908 SomeDataNodes.pop_front() ;
1909 // cdebug << pthread_self() << "/" << ThreadNo()
1910 // << " Successed_SuccessAction pop "
1911 // << SomeDataNodes.size() << " " << aNode->Name() << endl ;
1912 if ( aNode->State() == SUPERV::DataReadyState ) {
1913 aNode->CreateNewThreadIf( true ) ;
1914 aNode->UnLockDataWait() ;
1915 res = aNode->DataUndef_AllDataReadyAction() ;
1918 // cdebug << pthread_self() << "/" << ThreadNo() << " ERROR "
1919 // << aNode->Name() << " "
1920 // << Automaton()->StateName( aNode->State() ) << endl ;
1924 if ( firsttoNode ) {
1925 // cdebug << pthread_self() << "/" << ThreadNo()
1926 // << " Successed_SuccessAction start firsttoNode "
1927 // << SomeDataNodes.size() << " " << firsttoNode->Name() << endl ;
1928 firsttoNode->CreateNewThreadIf( false ) ;
1929 firsttoNode->RewindStack( RewindStack() ) ;
1930 if ( firsttoNode->State() == SUPERV::SuccessedState ) {
1931 // cdebug << pthread_self() << "/" << ThreadNo() << " " << Name()
1932 // << " : " << firsttoNode->Name() << " "
1933 // << Automaton()->StateName( firsttoNode->State() )
1934 // << " --> DataWaitingState for Thread "
1935 // << firsttoNode->ThreadNo() << endl ;
1936 firsttoNode->State( SUPERV::DataWaitingState ) ;
1938 // pthread_t OldT = firsttoNode->ThreadNo() ;
1939 firsttoNode->ThreadNo( pthread_self() ) ;
1940 // On continue avec le meme thread
1941 // cdebug << pthread_self() << "/" << ThreadNo() << " firsttoNode "
1942 // << firsttoNode->Name() << "Thread(" << OldT << "-->"
1943 // << firsttoNode->ThreadNo() << ")" << endl ;
1945 // cdebug << ThreadNo() << " Successed_SuccessAction " << Name()
1946 // << " for " << firsttoNode->Name()
1947 // << " !firsttoNode->CreateNewThreadIf() "
1948 // << !firsttoNode->CreateNewThreadIf()
1949 // << " " << Automaton()->StateName( firsttoNode->State() ) ;
1950 if ( firsttoNode->State() == SUPERV::DataReadyState ) {
1952 firsttoNode->UnLockDataWait() ;
1953 res = firsttoNode->DataUndef_AllDataReadyAction() ;
1956 cdebug << " ERROR " << endl ;
1960 // cdebug << ThreadNo() << " Successed_SuccessAction " << Name()
1961 // << " NO DataReady ==> ThreadNo( 0 ) firsttoNode == NULL LINKEDnodesnumber " << linkednodesnumber << endl ;
1965 // if ( linkednodesnumber == 0 && firsttoNode == NULL ) {
1966 // cdebug << ThreadNo() << " Successed_SuccessAction " << Name() << " LinkedNodesSize " << LinkedNodesSize()
1967 // << " firsttoNode == NULL LINKEDnodesnumber " << linkednodesnumber << " CHECK" << endl ;
1968 // _OutNode->CheckAllDone() ;
1971 // cdebug << pthread_self() << "/" << ThreadNo()
1972 // << " <-- Successed_SuccessAction " << Name() << " linkednodesnumber "
1973 // << linkednodesnumber << endl;
1977 bool GraphExecutor::InNode::SendSomeDataReady( char * FromNodeName ) {
1978 bool RetVal = false ;
1979 if ( IsDataFlowNode() ) {
1980 // cdebug << ThreadNo() << " ----> " << Name()
1981 // << " send Result to graph " << Name() << endl;
1984 // cdebug << pthread_self() << "/" << ThreadNo() << " ----> " << FromNodeName
1985 // << " send SomeDataReady to " << Name() << " "
1986 // << Automaton()->StateName( State() )
1987 // << " CreateNewThreadIf() " << CreateNewThreadIf()
1988 // << " LockedDataWait " << IsLockedDataWait() << endl;
1990 cout << pthread_self() << "/" << ThreadNo() << " ----> " << FromNodeName
1991 << " send SomeDataReady to " << Name() << " "
1992 << Automaton()->StateName( State() )
1993 << " CreateNewThreadIf() " << CreateNewThreadIf()
1994 << " LockedDataWait " << IsLockedDataWait() << endl;
1996 if ( State() == SUPERV::SuccessedState ||
1997 State() == SUPERV::SuspendedSuccessedState ||
1998 State() == SUPERV::SuspendedSuccessedToReStartState ) {
1999 // cdebug << ThreadNo() << " " << FromNodeName
2000 // << " : " << Name() << " " << Automaton()->StateName( State() )
2001 // << " --> DataWaitingState for Thread "
2002 // << ThreadNo() << " " << endl ;
2003 State( SUPERV::DataWaitingState ) ;
2006 DataFromNode( FromNodeName ) ;
2007 RetVal = !SendEvent( GraphExecutor::SomeDataReadyEvent );
2015 int GraphExecutor::InNode::Errored_ErrorAction() {
2016 cdebug << ThreadNo() << " Errored_ErrorAction " << Name()
2017 << " will pthread_exit" << endl;
2022 int GraphExecutor::InNode::Successed_SuspendAction() {
2023 cdebug << ThreadNo() << " Successed_SuspendAction -->Suspend " << Name()
2024 << " Threads " << _OutNode->Threads() << " SuspendedThreads "
2025 << _OutNode->SuspendedThreads() << endl;
2026 _OutNode->PushEvent( this , GraphExecutor::SuspendedSuccessedEvent ,
2027 SUPERV::SuspendedSuccessedState ) ;
2029 GraphExecutor::InNode * aReStartNode = SuspendAction() ;
2030 cdebug << ThreadNo() << " Successed_SuspendAction Resumed " << Name() ;
2031 if ( aReStartNode ) {
2032 _aReStartNode = NULL ;
2033 cdebug << " for " << aReStartNode->Name() << endl;
2034 aReStartNode->SendEvent( _aReStartEvent ) ;
2038 SendEvent( GraphExecutor::ResumeEvent ) ;
2043 int GraphExecutor::InNode::Errored_SuspendAction() {
2044 cdebug << ThreadNo() << " Errored_SuspendAction -->Suspend " << Name()
2045 << " Threads " << _OutNode->Threads() << " SuspendedThreads "
2046 << _OutNode->SuspendedThreads() << endl;
2047 _OutNode->PushEvent( this , GraphExecutor::SuspendedErroredEvent ,
2048 SUPERV::SuspendedErroredState ) ;
2050 GraphExecutor::InNode * aReStartNode = SuspendAction() ;
2051 cdebug << ThreadNo() << " Errored_SuspendAction Resumed " << Name()
2053 if ( aReStartNode ) {
2054 _aReStartNode = NULL ;
2055 aReStartNode->SendEvent( _aReStartEvent ) ;
2058 SendEvent( GraphExecutor::ResumeEvent ) ;
2063 int GraphExecutor::InNode::SuspendedSuccessed_ResumeAction() {
2064 cdebug << ThreadNo() << " SuspendedSuccessed_ResumeAction " << Name() << endl;
2066 _OutNode->PushEvent( this , GraphExecutor::ResumedSuccessedEvent ,
2067 SUPERV::ResumedSuccessedState ) ;
2068 SendEvent( ResumedSuccessedEvent ) ;
2072 int GraphExecutor::InNode::SuspendedErrored_ResumeAction() {
2073 cdebug << ThreadNo() << " SuspendedErrored_ResumeAction " << Name() << endl;
2075 _OutNode->PushEvent( this , GraphExecutor::ResumedErroredEvent ,
2076 SUPERV::ResumedErroredState ) ;
2077 SendEvent( ResumedErroredEvent ) ;
2081 int GraphExecutor::InNode::Successed_KillAction() {
2083 _OutNode->PushEvent( this , GraphExecutor::KilledEvent ,
2084 SUPERV::KilledSuccessedState ) ;
2085 cdebug << ThreadNo() << " Successed_KillAction " << Name() << endl;
2089 int GraphExecutor::InNode::Errored_KillAction() {
2091 _OutNode->PushEvent( this , GraphExecutor::KilledEvent ,
2092 SUPERV::KilledErroredState ) ;
2093 cdebug << ThreadNo() << " Errored_KillAction " << Name() << endl;
2097 int GraphExecutor::InNode::Successed_StopAction() {
2099 _OutNode->PushEvent( this , GraphExecutor::StoppedEvent ,
2100 SUPERV::StoppedSuccessedState ) ;
2101 cdebug << ThreadNo() << " Successed_StopAction " << Name() << endl;
2105 int GraphExecutor::InNode::Errored_StopAction() {
2107 _OutNode->PushEvent( this , GraphExecutor::StoppedEvent ,
2108 SUPERV::StoppedErroredState ) ;
2109 cdebug << ThreadNo() << " Errored_StopAction " << Name() << endl;
2113 int GraphExecutor::InNode::SuspendedSuccessed_ReStartAction() {
2114 cdebug << ThreadNo() << " SuspendedSuccessed_ReStartAction " << Name() << endl;
2115 _OutNode->PushEvent( this , GraphExecutor::ReStartedEvent ,
2116 SUPERV::ReStartedState ) ;
2118 for ( i = 0 ; i < GetNodeInPortsSize() ; i++ ) {
2119 GetChangeNodeInPort( i )->State( SUPERV::ReadyState ) ;
2121 SendEvent( ExecuteEvent ) ;
2122 cdebug << ThreadNo() << " SuspendedSuccessed_ReStartAction " << Name() << endl;
2126 int GraphExecutor::InNode::SuspendedErrored_ReStartAction() {
2127 cdebug << ThreadNo() << " SuspendedErrored_ReStartAction " << Name() << endl;
2128 _OutNode->PushEvent( this , GraphExecutor::ReStartedEvent ,
2129 SUPERV::ReStartedState ) ;
2131 for ( i = 0 ; i < GetNodeInPortsSize() ; i++ ) {
2132 GetChangeNodeInPort( i )->State( SUPERV::ReadyState ) ;
2134 SendEvent( ExecuteEvent ) ;
2135 cdebug << ThreadNo() << " SuspendedErrored_ReStartAction " << Name() << endl;
2139 int GraphExecutor::InNode::SuspendedSuccessed_ReStartAndSuspendAction() {
2140 cdebug << ThreadNo() << " SuspendedSuccessed_ReStartAndSuspendAction " << Name()
2142 _OutNode->PushEvent( this , GraphExecutor::ReStartedAndSuspendEvent ,
2143 SUPERV::ReStartedState ) ;
2144 State( SUPERV::DataWaitingState ) ;
2146 cdebug << "InNode::Suspend() Node " << Name() << endl ;
2149 else if ( SendEvent( GraphExecutor::SomeDataReadyEvent ) ) {
2150 cdebug << "InNode::SendEvent( SomeDataReadyEvent ) Node "
2154 cdebug << ThreadNo() << " SuspendedSuccessed_ReStartAndSuspendAction " << Name()
2159 int GraphExecutor::InNode::SuspendedErrored_ReStartAndSuspendAction() {
2160 cdebug << ThreadNo() << " SuspendedErrored_ReStartAndSuspendAction " << Name()
2162 _OutNode->PushEvent( this , GraphExecutor::ReStartedAndSuspendEvent ,
2163 SUPERV::ReStartedState ) ;
2164 State( SUPERV::DataWaitingState ) ;
2166 cdebug << "InNode::Suspend() Node " << Name() << endl ;
2169 else if ( SendEvent( GraphExecutor::SomeDataReadyEvent ) ) {
2170 cdebug << "InNode::SendEvent( SomeDataReadyEvent ) Node "
2174 cdebug << ThreadNo() << " SuspendedErrored_ReStartAndSuspendAction " << Name()
2179 void GraphExecutor::InNode::InParametersSet( bool & Err ,
2181 ServicesAnyData * InParametersList ) {
2183 for ( i = 0 ; i < nInParams ; i++ ) {
2184 ServicesAnyData D = InParametersList[i];
2185 GraphBase::InPort * anInPort = GetChangeNodeInPort(i) ;
2186 GraphBase::OutPort * theOutPort = anInPort->GetOutPort() ;
2187 if ( anInPort->IsGate() && theOutPort == NULL ) {
2188 cdebug << ThreadNo() << " ArgIn" << i << " " << D.Name << " "
2189 << anInPort->GetServicesParameter().Parametertype
2190 << " is inactive. " << anInPort->Kind() << endl ;
2192 else if ( anInPort->State() == SUPERV::ReadyState ) {
2193 if ( anInPort->IsGate() ) {
2194 CORBA::Any * anAny = new CORBA::Any() ;
2195 *anAny <<= (long ) 0 ;
2196 theOutPort->Value( anAny ) ;
2198 if ( !anInPort->IsDataStream() ) {
2199 anInPort->State( SUPERV::WaitingState ) ;
2201 D.Name = CORBA::string_dup( anInPort->GetServicesParameter().Parametername ) ;
2202 cdebug << ThreadNo() << " ArgIn" << i << " " << anInPort->Kind() ;
2203 cdebug << " " << D.Name << " " << anInPort->GetServicesParameter().Parametertype << " : " ;
2204 D.Value = *theOutPort->Value() ; // CORBA::Any
2205 string _Type = CORBA::string_dup( anInPort->GetServicesParameter().Parametertype ) ;
2206 const char * Type = _Type.c_str() ;
2207 switch ( D.Value.type()->kind() ) { // { string , long , double , objref }
2208 case CORBA::tk_string:
2211 cdebug << t << " (string)" ;
2212 if ( !strcmp( Type , "string" ) ) {
2214 else if ( !strcmp( Type , "boolean" ) ) {
2217 sscanf( t , "%ld" , &d ) ;
2219 D.Value <<= (CORBA::Any::from_boolean ) b ;
2220 // theOutPort->Value( D.Value ) ;
2222 else if ( !strcmp( Type , "char" ) ) {
2225 sscanf( t , "%ld" , &d ) ;
2227 D.Value <<= (CORBA::Any::from_char ) c ;
2228 cdebug << "string '" << t << "' --> " << d << " --> char " << c ;
2229 // theOutPort->Value( D.Value ) ;
2231 else if ( !strcmp( Type , "short" ) ) {
2234 sscanf( t , "%ld" , &d ) ;
2237 cdebug << "string '" << t << "' --> " << d << " --> short " << s ;
2238 // theOutPort->Value( D.Value ) ;
2240 else if ( !strcmp( Type , "int" ) || !strcmp( Type , "long" ) ) {
2242 sscanf( t , "%ld" , &l ) ;
2244 cdebug << "string '" << t << " --> long " << l ;
2245 // theOutPort->Value( D.Value ) ;
2247 else if ( !strcmp( Type , "float" ) ) {
2249 sscanf( t , "%lf" , &d ) ;
2252 cdebug << "string '" << t << "' --> " << setw(25) << setprecision(18) << d << " --> float " << " = "
2253 << setw(25) << setprecision(18) << f ;
2254 // theOutPort->Value( D.Value ) ;
2256 else if ( !strcmp( Type , "double" ) ) {
2258 sscanf( t , "%lf" , &d ) ;
2260 cdebug << "string '" << t << " --> double " << setw(25) << setprecision(18) << d ;
2261 // theOutPort->Value( D.Value ) ;
2263 // else if ( !strcmp( Type , "objref" ) ) {
2265 CORBA::Object_ptr ObjRef ;
2267 ObjRef = StringToObject( t ) ;
2268 D.Value <<= ObjRef ;
2271 D.Value <<= CORBA::Object::_nil() ;
2273 // theOutPort->Value( D.Value ) ;
2276 // cdebug << " (other ERROR)" << endl ;
2278 cdebug << " --> call_kind " << D.Value.type()->kind() << endl ;
2280 case CORBA::tk_long:
2283 cdebug << l << " (long)" << endl ;
2284 if ( !strcmp( Type , "string" ) ) {
2286 sprintf( t , "%ld" , l ) ;
2288 // theOutPort->Value( D.Value ) ;
2290 else if ( !strcmp( Type , "boolean" ) ) {
2293 D.Value <<= (CORBA::Any::from_boolean ) b ;
2294 // theOutPort->Value( D.Value ) ;
2296 else if ( !strcmp( Type , "char" ) ) {
2298 c = (unsigned char ) l ;
2299 D.Value <<= (CORBA::Any::from_char ) c ;
2300 // theOutPort->Value( D.Value ) ;
2302 else if ( !strcmp( Type , "short" ) ) {
2306 // theOutPort->Value( D.Value ) ;
2308 else if ( !strcmp( Type , "int" ) || !strcmp( Type , "long" ) ) {
2310 else if ( !strcmp( Type , "float" ) ) {
2314 // theOutPort->Value( D.Value ) ;
2316 else if ( !strcmp( Type , "double" ) ) {
2320 // theOutPort->Value( D.Value ) ;
2322 // else if ( !strcmp( Type , "objref" ) ) {
2324 D.Value <<= CORBA::Object::_nil() ;
2325 // theOutPort->Value( D.Value ) ;
2328 // cdebug << " (other ERROR)" << endl ;
2330 cdebug << " --> call_kind " << D.Value.type()->kind() << endl ;
2332 case CORBA::tk_double:
2335 cdebug << d << " (double)" << endl ;
2336 if ( !strcmp( Type , "string" ) ) {
2338 sprintf( t , "%lf" , d ) ;
2340 // theOutPort->Value( D.Value ) ;
2342 else if ( !strcmp( Type , "boolean" ) ) {
2345 D.Value <<= (CORBA::Any::from_boolean ) b ;
2346 // theOutPort->Value( D.Value ) ;
2348 else if ( !strcmp( Type , "char" ) ) {
2350 c = (unsigned char ) d ;
2351 D.Value <<= (CORBA::Any::from_char ) c ;
2352 // theOutPort->Value( D.Value ) ;
2354 else if ( !strcmp( Type , "short" ) ) {
2358 // theOutPort->Value( D.Value ) ;
2360 else if ( !strcmp( Type , "int" ) || !strcmp( Type , "long" ) ) {
2364 // theOutPort->Value( D.Value ) ;
2366 else if ( !strcmp( Type , "float" ) ) {
2370 // theOutPort->Value( D.Value ) ;
2372 else if ( !strcmp( Type , "double" ) ) {
2374 // else if ( !strcmp( Type , "objref" ) ) {
2376 D.Value <<= CORBA::Object::_nil() ;
2377 // theOutPort->Value( D.Value ) ;
2380 // cdebug << " (other ERROR)" << endl ;
2382 cdebug << " --> call_kind " << D.Value.type()->kind() << endl ;
2384 case CORBA::tk_objref:
2385 if ( !strcmp( Type , "string" ) ) {
2386 CORBA::Object_ptr ObjRef ;
2389 D.Value >>= ObjRef ;
2390 retstr = ObjectToString( ObjRef ) ;
2391 D.Value <<= retstr ;
2392 // theOutPort->Value( D.Value ) ;
2398 cdebug << "ToString( object ) Catched ERROR" << endl ;
2401 else if ( !strcmp( Type , "boolean" ) ) {
2403 D.Value <<= (CORBA::Any::from_boolean ) b ;
2404 // theOutPort->Value( D.Value ) ;
2406 else if ( !strcmp( Type , "char" ) ) {
2407 unsigned char c = 0 ;
2408 D.Value <<= (CORBA::Any::from_char ) c ;
2409 // theOutPort->Value( D.Value ) ;
2411 else if ( !strcmp( Type , "short" ) ) {
2414 // theOutPort->Value( D.Value ) ;
2416 else if ( !strcmp( Type , "int" ) || !strcmp( Type , "long" ) ) {
2419 // theOutPort->Value( D.Value ) ;
2421 else if ( !strcmp( Type , "float" ) ) {
2424 // theOutPort->Value( D.Value ) ;
2426 else if ( !strcmp( Type , "double" ) ) {
2429 // theOutPort->Value( D.Value ) ;
2431 // else if ( !strcmp( Type , "objref" ) ) {
2433 CORBA::Object_ptr obj ;
2437 retstr = ObjectToString( obj ) ;
2438 cdebug << retstr << endl ;
2444 cdebug << "ToString( object ) Catched ERROR" << endl ;
2448 // cdebug << " (other ERROR)" << endl ;
2450 cdebug << " --> call_kind " << D.Value.type()->kind() << endl ;
2453 cdebug << " (other ERROR) " << D.Value.type()->kind() << endl ;
2457 cdebug << ThreadNo() << " In" << i << " : wrong state ERROR State "
2458 << anInPort->State() << " NameState "
2459 << Automaton()->StateName( anInPort->State() ) << " PortName "
2460 << anInPort->PortName() << " Parametername "
2461 << anInPort->GetServicesParameter().Parametername << endl ;
2464 InParametersList[i] = D ;
2468 void GraphExecutor::InNode::InOutParametersSet( int nOutParams ,
2469 ServicesAnyData * OutParametersList ) {
2471 for ( i = 0 ; i < nOutParams ; i++ ) {
2472 ServicesAnyData D = OutParametersList[i] ;
2474 D.Name = GetChangeNodeOutPort(i)->GetServicesParameter().Parametername;
2475 string _Type = CORBA::string_dup(GetChangeNodeOutPort(i)->GetServicesParameter().Parametertype) ;
2476 const char * Type = _Type.c_str() ;
2477 bool OutDone = GetChangeNodeOutPort(i)->Done() ;
2478 cdebug << ThreadNo() << " ArgOut" << i << " " << D.Name << " Done("
2479 << OutDone << ") " << Type << " : " << endl ;
2480 if ( !strcmp( Type , "string" ) ) {
2481 D.Value <<= (char *) NULL ;
2483 else if ( !strcmp( Type , "boolean" ) ) {
2485 D.Value <<= (CORBA::Any::from_boolean ) b ;
2487 else if ( !strcmp( Type , "char" ) ) {
2488 unsigned char c = 0 ;
2489 D.Value <<= (CORBA::Any::from_char ) c ;
2491 else if ( !strcmp( Type , "short" ) ) {
2495 else if ( !strcmp( Type , "int" ) || !strcmp( Type , "long" ) ) {
2496 D.Value <<= (long ) 0 ;
2498 else if ( !strcmp( Type , "float" ) ) {
2502 else if ( !strcmp( Type , "double" ) ) {
2507 D.Value <<= CORBA::Object::_nil() ;
2510 switch (D.Value.type()->kind()) { // { string , long , double , objref }
2511 case CORBA::tk_string:
2514 cdebug << ThreadNo() << " " << t << "(string)" << endl ;
2516 case CORBA::tk_boolean:
2518 D.Value >>= (CORBA::Any::to_boolean ) b;
2519 cdebug << ThreadNo() << " " << b << "(boolean)" << endl ;
2521 case CORBA::tk_char:
2523 D.Value >>= (CORBA::Any::to_char ) c;
2524 cdebug << ThreadNo() << " " << c << "(char)" << endl ;
2526 case CORBA::tk_short:
2529 cdebug << ThreadNo() << " " << s << "(short)" << endl ;
2531 case CORBA::tk_long:
2534 cdebug << ThreadNo() << " " << l << "(long)" << endl ;
2536 case CORBA::tk_float:
2539 cdebug << ThreadNo() << " " << f << "(float)" << endl ;
2541 case CORBA::tk_double:
2544 cdebug << ThreadNo() << " " << d << "(double)" << endl ;
2546 case CORBA::tk_objref:
2548 CORBA::Object_ptr obj ;
2551 retstr = ObjectToString( obj ) ;
2552 cdebug << ThreadNo() << retstr << endl ;
2555 cdebug << "ToString( object ) Catched ERROR" << endl ;
2559 cdebug << ThreadNo() << " " << "(other ERROR)" << endl ;
2562 OutParametersList[i] = D ;
2566 bool GraphExecutor::InNode::OutParametersSet( bool Err ,
2567 SUPERV::GraphState NewState ,
2569 ServicesAnyData * OutParametersList ) {
2570 bool RetVal = true ;
2572 GraphBase::OutPort * aGateOutPort = NULL ;
2573 bool OrSwitch = false ;
2575 GraphBase::OutPort * anOutPort ;
2576 for ( i = 0 ; i < nOutParams ; i++ ) {
2577 anOutPort = GetChangeNodeOutPort(i) ;
2579 anOutPort->State( NewState ) ;
2580 anOutPort->Done( true ) ;
2583 cdebug << ThreadNo() << " " << "Out" << i << " " << Name() << " "
2584 << anOutPort->PortName() << " " << anOutPort->Kind() ;
2585 ServicesAnyData D = OutParametersList[i] ;
2586 switch (D.Value.type()->kind()) { // { string , long , double , objref }
2587 case CORBA::tk_string: {
2590 cdebug << ThreadNo() << " " << t << "(string)" << endl ;
2593 case CORBA::tk_boolean: {
2595 D.Value >>= (CORBA::Any::to_boolean ) b;
2596 long l = (long ) b ;
2598 cdebug << ThreadNo() << " " << b << "(boolean)" << endl ;
2601 case CORBA::tk_char: {
2603 D.Value >>= (CORBA::Any::to_char ) c;
2604 long l = (long ) c ;
2606 cdebug << ThreadNo() << " " << c << "(char)" << endl ;
2609 case CORBA::tk_short: {
2612 long l = (long ) s ;
2614 cdebug << ThreadNo() << " " << s << "(short)" << endl ;
2617 case CORBA::tk_long: {
2620 cdebug << ThreadNo() << " " << l << "(long)" << endl ;
2623 case CORBA::tk_float: {
2626 double d = (double ) f ;
2628 cdebug << ThreadNo() << " " << f << "(float)" << endl ;
2631 case CORBA::tk_double: {
2634 cdebug << ThreadNo() << " " << d << "(double)" << endl ;
2637 case CORBA::tk_objref: {
2639 CORBA::Object_ptr obj ;
2642 retstr = ObjectToString( obj ) ;
2643 cdebug << ThreadNo() << retstr << endl ;
2646 cdebug << "ToString( object ) Catched ERROR" << endl ;
2651 cdebug << ThreadNo() << " " << "(other ERROR)" << endl ;
2654 OutParametersList[i] = D ;
2655 if ( !anOutPort->IsDataStream() ) {
2656 if ( anOutPort->IsGate() ) {
2657 aGateOutPort = anOutPort ;
2658 cdebug << " Gate " ;
2660 OutParametersList[i].Value <<= l;
2661 anOutPort->Value( OutParametersList[i].Value );
2663 else if ( anOutPort->IsLoop() ) {
2664 cdebug << " Loop " ;
2665 anOutPort->Value( OutParametersList[i].Value );
2666 // InLoop Port of EndLoopNode is ready :
2667 anOutPort->ChangeInPorts(0)->State( SUPERV::ReadyState ) ;
2669 else if ( anOutPort->IsSwitch() ) {
2670 cdebug << " Switch " ;
2671 anOutPort->Value( OutParametersList[i].Value );
2672 if ( anOutPort->InPortsSize() && anOutPort->ChangeInPorts( 0 )->IsGate() ) {
2673 if ( OrSwitch && anOutPort->BoolValue() ) {
2674 cdebug << "GraphExecutor::InNodeThreads::OutParameters more than one switch is true WARNING"
2678 OrSwitch = OrSwitch | anOutPort->BoolValue() ;
2681 cdebug << "OrSwitch " << OrSwitch ;
2684 cdebug << " Param " ;
2685 anOutPort->Value( OutParametersList[i].Value );
2687 anOutPort->State( NewState ) ;
2688 anOutPort->Done( true ) ;
2691 for ( j = 0 ; j < anOutPort->InPortsSize() ; j++ ) {
2692 bool fromGOTO = false ;
2693 GraphBase::OutPort * aGOTOPort = _OutNode->Graph()->GetChangeGraphNode( anOutPort->ChangeInPorts( j )->NodeName() )->GetChangeNodeInGate()->GetOutPort() ;
2695 fromGOTO = aGOTOPort->IsGOTO() ;
2697 if ( anOutPort->ChangeInPorts( j )->IsEndSwitch() || fromGOTO ) {
2698 cdebug << anOutPort->ChangeInPorts( j )->NodeName() << "("
2699 << anOutPort->ChangeInPorts( j )->PortName() << ","
2700 << anOutPort->ChangeInPorts( j )->Kind() << ") WILL BE changed from "
2701 << anOutPort->ChangeInPorts( j )->GetOutPort()->NodeName()
2703 << anOutPort->ChangeInPorts( j )->GetOutPort()->PortName()
2704 << ") to " << anOutPort->NodeName() << "("
2705 << anOutPort->PortName() << ")" << endl ;
2706 anOutPort->ChangeInPorts( j )->ChangeOutPort( anOutPort ) ;
2709 cdebug << anOutPort->ChangeInPorts( j )->NodeName() << "("
2710 << anOutPort->ChangeInPorts( j )->PortName() << ","
2711 << anOutPort->ChangeInPorts( j )->Kind() << ") NOT changed from "
2712 << anOutPort->ChangeInPorts( j )->GetOutPort()->NodeName()
2714 << anOutPort->ChangeInPorts( j )->GetOutPort()->PortName()
2715 << ") to " << anOutPort->NodeName() << "("
2716 << anOutPort->PortName() << ")" << endl ;
2720 switch (anOutPort->Value()->type()->kind()) {
2721 case CORBA::tk_string:
2723 (*anOutPort->Value()) >>= t;
2724 cdebug << ThreadNo() << " Out" << i << " : " << t << "(string)" << endl ;
2726 case CORBA::tk_boolean:
2728 (*anOutPort->Value()) >>= (CORBA::Any::to_boolean ) b;
2729 cdebug << ThreadNo() << " Out" << i << " : " << b << "(boolean)" << endl ;
2731 case CORBA::tk_char:
2733 (*anOutPort->Value()) >>= (CORBA::Any::to_char ) c;
2734 cdebug << ThreadNo() << " Out" << i << " : " << c << "(char)" << endl ;
2736 case CORBA::tk_short:
2738 (*anOutPort->Value()) >>= s;
2739 cdebug << ThreadNo() << " Out" << i << " : " << s << "(short)" << endl ;
2741 case CORBA::tk_long:
2743 (*anOutPort->Value()) >>= l;
2744 cdebug << ThreadNo() << " Out" << i << " : " << l << "(long)" << endl ;
2746 case CORBA::tk_float:
2748 (*anOutPort->Value()) >>= f;
2749 cdebug << ThreadNo() << " Out" << i << " : " << f << "(float)" << endl ;
2751 case CORBA::tk_double:
2753 (*anOutPort->Value()) >>= d;
2754 cdebug << ThreadNo() << " Out" << i << " : " << d << "(double)" << endl ;
2756 case CORBA::tk_objref:
2757 CORBA::Object_ptr obj ;
2760 (*anOutPort->Value()) >>= obj ;
2761 retstr = ObjectToString( obj );
2762 cdebug << ThreadNo() << " Out" << i << " : " << "ToString( object ) "
2766 cdebug << ThreadNo() << " Out" << i << " : " << "ToString( object ) "
2767 << "Catched ERROR" << endl ;
2771 cdebug << ThreadNo() << " Out" << i << " : " << "(other ERROR)" << endl ;
2777 if ( aGateOutPort && IsSwitchNode() ) {
2779 // cdebug << ThreadNo() << " " << "Out0 " << Name() << " Close of "
2780 // << aGateOutPort->PortName() << " " << aGateOutPort->Kind() ;
2782 OutParametersList[0].Value <<= l ;
2783 aGateOutPort->Value( OutParametersList[0].Value ) ;
2786 // cdebug << ThreadNo() << " " << "Out0 " << Name() << " Open of "
2787 // << aGateOutPort->PortName() << " " << aGateOutPort->Kind() ;
2789 OutParametersList[0].Value <<= l ;
2790 aGateOutPort->Value( OutParametersList[0].Value ) ;
2792 for ( i = 0 ; i < GetNodeOutPortsSize() ; i++ ) {
2793 GraphBase::InPort * anInPort ;
2794 anInPort = CoupledNode()->GetChangeInPort( GetNodeOutPort( i )->PortName() ) ;
2796 anInPort->ChangeOutPort( GetChangeNodeOutPort( i ) ) ;