2 //=============================================================================
3 // File : DataFlowBase_InNodeThreads.cxx
5 // Author : Jean Rahuel, CEA
8 //=============================================================================
19 #include <SALOMEconfig.h>
20 #include CORBA_CLIENT_HEADER(SALOME_Component)
21 #include "SALOME_NamingService.hxx"
22 #include "SALOME_LifeCycleCORBA.hxx"
24 //#include "DataFlowExecutor_InNode.hxx"
26 #include "DataFlowExecutor_OutNode.hxx"
28 static char *containerName = "FactoryServer" ;
30 int GraphExecutor::InNode::SendEvent(
31 const GraphExecutor::NodeEvent anEvent ) {
32 SUPERV::AutomatonState old_state ;
34 cdebug << pthread_self() << "/" << ThreadNo() << " -->SendEvent Node " << Name()
36 << Automaton()->ControlStateName( ControlState() )
37 << " Event : " << Automaton()->EventName( anEvent )
38 << " State : " << Automaton()->StateName( State() ) << endl;
41 _NextState = Automaton()->NextState( old_state , anEvent ) ;
42 if ( _NextState == old_state ) {
43 cdebug << pthread_self() << "/" << ThreadNo()
44 << " GraphExecutor::InNodeThreads::SendEvent SameStates "
45 << old_state << endl ;
46 _NextAction = GraphExecutor::VoidAction ;
49 _NextAction = Automaton()->NextAction( _NextState , anEvent ) ;
52 // State( _NextState ) ;
53 // if ( old_state == SUPERV::SuccessedExecutingState ||
54 // old_state == SUPERV::ErroredExecutingState ) {
58 cdebug << pthread_self() << "/" << ThreadNo() << " SendedEvent Node "
59 << Name() << endl << " ControlState : "
60 << Automaton()->ControlStateName( ControlState() ) << endl
61 << " OldState : " << Automaton()->StateName( old_state ) << endl
62 << " Event : " << Automaton()->EventName( anEvent ) << endl
63 << " NextState : " << Automaton()->StateName( _NextState ) << endl
64 << " Action : " << Automaton()->ActionName( _NextAction ) << endl
65 << " CreateNewThread " << CreateNewThread() << endl ;
68 cout << pthread_self() << "/" << ThreadNo() << " SendedEvent Node " << Name()
69 << endl << " ControlState : "
70 << Automaton()->ControlStateName( ControlState() ) << endl
71 << " OldState : " << Automaton()->StateName( old_state ) << endl
72 << " Event : " << Automaton()->EventName( anEvent ) << endl
73 << " NextState : " << Automaton()->StateName( _NextState ) << endl
74 << " Action : " << Automaton()->ActionName( _NextAction ) << endl
75 << " CreateNewThread " << CreateNewThread() << endl ;
78 int sts = executeAction() ;
80 cdebug << pthread_self() << "/" << ThreadNo() << " <- SendEvent Node " << Name()
81 << " Event : " << Automaton()->EventName( anEvent )
82 << " State : " << Automaton()->StateName( State() )
89 // ReadyAction - RunningAction - DoneAction - SuspendedAction :
90 // for StateWait( ReadyW - RunningW - DoneW - SuspendedW )
91 void GraphExecutor::InNode::ReadyAction() {
92 if ( pthread_mutex_lock( &_MutexWait ) ) {
93 perror("Ready pthread_mutex_lock ") ;
96 cdebug << pthread_self() << "/" << ThreadNo()
97 << "ReadyAction pthread_cond_broadcast _ReadyWait "
99 if ( pthread_cond_broadcast( &_ReadyWait ) ) {
100 perror("Ready pthread_cond_broadcast ") ;
102 if ( pthread_mutex_unlock( &_MutexWait ) ) {
103 perror("Ready pthread_mutex_unlock ") ;
108 void GraphExecutor::InNode::RunningAction() {
109 if ( pthread_mutex_lock( &_MutexWait ) ) {
110 perror("Running pthread_mutex_lock ") ;
113 cdebug << pthread_self() << "/" << ThreadNo()
114 << "RunningAction pthread_cond_broadcast _RunningWait "
116 if ( pthread_cond_broadcast( &_RunningWait ) ) {
117 perror("Running pthread_cond_broadcast ") ;
119 if ( pthread_mutex_unlock( &_MutexWait ) ) {
120 perror("Running pthread_mutex_unlock ") ;
125 void GraphExecutor::InNode::DoneAction() {
126 if ( pthread_mutex_lock( &_MutexWait ) ) {
127 perror("Done pthread_mutex_lock ") ;
130 cdebug << pthread_self() << "/" << ThreadNo()
131 << "DoneAction pthread_cond_broadcast _DoneWait "
133 if ( pthread_cond_broadcast( &_DoneWait ) ) {
134 perror("Done pthread_cond_broadcast ") ;
136 if ( pthread_mutex_unlock( &_MutexWait ) ) {
137 perror("Done pthread_mutex_unlock ") ;
142 void GraphExecutor::InNode::SuspendedAction() {
143 if ( pthread_mutex_lock( &_MutexWait ) ) {
144 perror("Suspended pthread_mutex_lock ") ;
147 cdebug << pthread_self() << "/" << ThreadNo()
148 << "SuspendedAction pthread_cond_broadcast _SuspendedWait "
150 if ( pthread_cond_broadcast( &_SuspendedWait ) ) {
151 perror("Suspended pthread_cond_broadcast ") ;
153 if ( pthread_mutex_unlock( &_MutexWait ) ) {
154 perror("Suspended pthread_mutex_unlock ") ;
159 // SuspendAction <--> { ResumeAction - ReStartAction }
160 GraphExecutor::InNode * GraphExecutor::InNode::SuspendAction() {
162 if ( pthread_mutex_lock( &_MutexWait ) ) {
163 perror("Suspend pthread_mutex_lock ") ;
166 if ( !_SuspendSync ) {
167 cdebug << pthread_self() << "/" << ThreadNo() << " pthread_cond " << Name()
168 << " SuspendAction pthread_cond_wait _SuspendWait "
169 << Automaton()->StateName( State() ) << endl ;
170 _SuspendSync = true ;
171 _OutNode->SuspendThread() ;
172 if ( pthread_cond_wait( &_SuspendWait , &_MutexWait ) ) {
173 perror("SuspendAction pthread_cond_wait ") ;
175 _OutNode->ResumeThread() ;
176 cdebug << pthread_self() << "/" << ThreadNo() << " pthread_cond " << Name()
177 << " SuspendAction pthread_cond_waited"
178 << Automaton()->StateName( State() ) << endl ;
181 cdebug << pthread_self() << "/" << ThreadNo() << " pthread_cond " << Name()
182 << " NO SuspendAction pthread_cond_wait"
183 << Automaton()->StateName( State() ) << endl ;
185 SendEvent( _aResumeEvent ) ;
186 _SuspendSync = false ;
187 if ( pthread_mutex_unlock( &_MutexWait ) ) {
188 perror("SuspendAction pthread_mutex_unlock ") ;
192 if ( ControlState() == SUPERV::ToSuspendStartState ) {
193 ControlState( SUPERV::VoidState ) ;
196 if ( pthread_mutex_lock( &_MutexWait ) ) {
197 perror("SuspendAction pthread_mutex_lock ") ;
201 cdebug << pthread_self() << "/" << ThreadNo() << " pthread_cond " << Name()
202 << " SuspendAction pthread_cond_signal _ResumeWait" << endl ;
203 if ( pthread_cond_signal( &_ResumeWait ) ) {
204 perror("SuspendAction pthread_cond_signal _ResumeWait ") ;
206 cdebug << pthread_self() << "/" << ThreadNo() << " pthread_cond " << Name()
207 << " SuspendAction pthread_cond_signaled _ResumeWait " << endl ;
210 cdebug << pthread_self() << "/" << ThreadNo() << " pthread_cond " << Name()
211 << " NO SuspendAction pthread_cond_signal _ResumeWait" << endl ;
214 if ( pthread_mutex_unlock( &_MutexWait ) ) {
215 perror("SuspendAction pthread_mutex_unlock ") ;
218 if ( _aReStartNode ) {
219 cdebug << Name() << " " << Automaton()->StateName( State() )
220 << "aReStartNode : " << _aReStartNode->Name() << " "
221 << Automaton()->StateName( _aReStartNode->State() ) << endl ;
222 _aReStartNode->SendEvent( _aResumeEvent ) ;
225 cdebug << "NO aReStartNode"
226 << Automaton()->StateName( State() ) << endl ;
228 return _aReStartNode ;
231 bool GraphExecutor::InNode::ResumeAction( GraphExecutor::NodeEvent aResumeEvent ) {
233 if ( pthread_mutex_lock( &_MutexWait ) ) {
234 perror("ResumeAction pthread_mutex_lock ") ;
237 _aResumeEvent = aResumeEvent ;
238 if ( _SuspendSync ) {
239 cdebug << pthread_self() << "/" << ThreadNo() << " pthread_cond " << Name()
240 << " ResumeAction pthread_cond_signal" << endl ;
241 if ( pthread_cond_signal( &_SuspendWait ) ) {
242 perror("ResumeAction pthread_cond_signal ") ;
244 cdebug << pthread_self() << "/" << ThreadNo() << " pthread_cond " << Name()
245 << " ResumeAction pthread_cond_signaled _SuspendWait " << endl ;
249 cdebug << pthread_self() << "/" << ThreadNo() << " pthread_cond " << Name()
250 << " NO ResumeAction pthread_cond_signal" << endl ;
251 if ( pthread_self() == ThreadNo() ) {
252 RetVal = false ; // Ne pas s'attendre soi-meme !...
255 _SuspendSync = true ;
256 RetVal = true ; // Il faut tout de meme attendre ci-apres ...
259 if ( pthread_mutex_unlock( &_MutexWait ) ) {
260 perror("ResumeAction pthread_mutex_unlock ") ;
265 if ( pthread_mutex_lock( &_MutexWait ) ) {
266 perror("ResumeAction pthread_mutex_lock ") ;
269 if ( !_ResumeSync ) {
270 cdebug << pthread_self() << "/" << ThreadNo() << " pthread_cond "
271 << Name() << " ResumeAction pthread_cond_wait _ResumeWait "
272 << Automaton()->StateName( State() ) << endl ;
274 if ( pthread_cond_wait( &_ResumeWait , &_MutexWait ) ) {
275 perror("ResumeAction pthread_cond_wait ") ;
277 cdebug << pthread_self() << "/" << ThreadNo() << " pthread_cond "
278 << Name() << " ResumeAction pthread_cond_waited _ResumeWait"
279 << Automaton()->StateName( State() ) << endl ;
283 cdebug << pthread_self() << "/" << ThreadNo() << " pthread_cond "
284 << Name() << " NO ResumeAction pthread_cond_wait _ResumeWait"
285 << Automaton()->StateName( State() ) << endl ;
288 _ResumeSync = false ;
289 if ( pthread_mutex_unlock( &_MutexWait ) ) {
290 perror("ResumeAction pthread_mutex_unlock ") ;
294 cdebug << pthread_self() << "/" << ThreadNo()
295 << "GraphExecutor::InNodeThreads::ResumeAction RetVal " << RetVal << endl ;
299 bool GraphExecutor::InNode::ReStartAction( GraphExecutor::InNode * aReStartNode ,
300 GraphExecutor::NodeEvent anEvent ) {
301 GraphExecutor::InNode * oldReStartNode = _aReStartNode ;
302 _aReStartNode = aReStartNode ;
303 _aReStartEvent = anEvent ;
304 cdebug << pthread_self() << " GraphExecutor::InNodeThreads::ReStartAction from "
305 << Name() << " " << Automaton()->StateName( State() ) << " to "
306 << aReStartNode->ThreadNo() << " " << aReStartNode->Name() << " "
307 << Automaton()->StateName( aReStartNode->State() ) ;
308 if ( oldReStartNode ) {
309 cdebug << " oldReStartNode " << oldReStartNode->Name() << endl ;
314 return ResumeAction( GraphExecutor::ToReStartEvent ) ;
317 void GraphExecutor::InNode::KilledAction() {
318 if ( pthread_mutex_lock( &_MutexWait ) ) {
319 perror("Killed pthread_mutex_lock ") ;
323 cdebug << "pthread_cond " << Name() << " Killed pthread_cond_wait"
326 if ( pthread_cond_wait( &_KillWait , &_MutexWait ) ) {
327 perror("Killed pthread_cond_wait ") ;
329 cdebug << "pthread_cond " << Name() << " Killed pthread_cond_waited"
333 cdebug << "pthread_cond " << Name() << " NO Killed pthread_cond_wait"
337 if ( pthread_mutex_unlock( &_MutexWait ) ) {
338 perror("Killed pthread_mutex_unlock ") ;
343 void GraphExecutor::InNode::KillAction() {
344 if ( pthread_mutex_lock( &_MutexWait ) ) {
345 perror("Kill pthread_mutex_lock ") ;
349 cdebug << "pthread_cond " << Name() << " Kill pthread_cond_signal"
351 // if ( pthread_cond_broadcast( &_KillWait ) ) {
352 if ( pthread_cond_signal( &_KillWait ) ) {
353 perror("Kill pthread_cond_broadcast ") ;
355 cdebug << "pthread_cond " << Name() << " Kill pthread_cond_signaled"
359 cdebug << "pthread_cond " << Name() << " NO Kill pthread_cond_signal"
363 if ( pthread_mutex_unlock( &_MutexWait ) ) {
364 perror("Kill pthread_mutex_unlock ") ;
369 void GraphExecutor::InNode::StoppedAction() {
370 if ( pthread_mutex_lock( &_MutexWait ) ) {
371 perror("Stopped pthread_mutex_lock ") ;
374 if ( pthread_cond_wait( &_StopWait , &_MutexWait ) ) {
375 perror("Stopped pthread_cond_wait ") ;
377 if ( pthread_mutex_unlock( &_MutexWait ) ) {
378 perror("Stopped pthread_mutex_unlock ") ;
383 void GraphExecutor::InNode::StopAction() {
384 if ( pthread_mutex_lock( &_MutexWait ) ) {
385 perror("Stop pthread_mutex_lock ") ;
388 if ( pthread_cond_broadcast( &_StopWait ) ) {
389 perror("Stop pthread_cond_broadcast ") ;
391 if ( pthread_mutex_unlock( &_MutexWait ) ) {
392 perror("Stop pthread_mutex_unlock ") ;
397 int GraphExecutor::InNode::executeAction() {
398 if ( CreateNewThread() ) {
399 CreateNewThread( false ) ;
400 if ( ThreadNo() == 0 ) {
401 cdebug << pthread_self() << "/" << ThreadNo()
402 << " executeAction start Thread "
403 << Automaton()->ActionName( _NextAction ) << "(" << Name() << ")"
406 int pthread_sts = 1 ;
407 // _OutNode->PushEvent( NULL , GraphExecutor::NewThreadEvent ,
408 // SUPERV::ExecutingState ) ;
409 while ( (pthread_sts = pthread_create(&T, NULL, run_function, this )) ) {
410 char * msg = "Cannot pthread_create " ;
412 cdebug << ThreadNo() << " " << msg << endl ;
413 cdebug << ThreadNo() << " PTHREAD_THREADS_MAX : "
414 << PTHREAD_THREADS_MAX << " " << pthread_sts << endl ;
416 pthread_exit( msg ) ;
418 cdebug << pthread_self() << "/" << ThreadNo()
419 << "executeAction has created thread " << T << endl ;
422 cdebug << pthread_self() << "/" << ThreadNo()
423 << " executeAction restart Thread "
424 << Automaton()->StateName( State() ) << " "
425 << Automaton()->ActionName( _NextAction ) << "(" << Name()
426 << ") ReStartAction ==>" << endl;
427 SUPERV::AutomatonState oldstate = State() ;
428 State( SUPERV::SuspendedSuccessedState ) ;
429 if ( !ReStartAction( this , GraphExecutor::ReStartEvent ) ) {
430 // State( oldstate ) ;
431 cdebug << pthread_self() << "/" << ThreadNo()
432 << " executeAction STATE & CALLED "
433 << Automaton()->ActionName( _NextAction ) << "(" << Name()
434 << ") ERROR-DEBUG " << endl;
435 // return ExecuteAction() ;
438 cdebug << pthread_self() << "/" << ThreadNo() << " executeAction NO CALL "
439 << Automaton()->ActionName( _NextAction ) << "(" << Name()
445 cdebug << pthread_self() << "/" << ThreadNo() << " executeAction call "
446 << Automaton()->ActionName( _NextAction ) << "(" << Name() << ")"
448 return ExecuteAction() ;
453 void GraphExecutor::InNode::coutbegin() {
454 cdebug << ThreadNo() << " " << pthread_self() << " run_function begin"
455 << " " << Name() << " " << Automaton()->StateName( State() )
458 void GraphExecutor::InNode::coutexit() {
459 cdebug << pthread_self() << "/" << ThreadNo() << " run_function pthread_exit"
460 << " " << Name() << " " << Automaton()->StateName( State() )
463 void * run_function(void *p) {
464 GraphExecutor::InNode *aNode = (GraphExecutor::InNode *) p;
466 aNode->NewThread( pthread_self() ) ;
467 if ( pthread_setcanceltype( PTHREAD_CANCEL_ASYNCHRONOUS , NULL ) ) {
468 perror("pthread_setcanceltype ") ;
471 if ( pthread_setcancelstate( PTHREAD_CANCEL_ENABLE , NULL ) ) {
472 perror("pthread_setcancelstate ") ;
475 aNode->ExecuteAction() ;
476 char * msg = new char[40] ;
477 sprintf( msg , "%d" , aNode->ThreadNo() ) ;
478 strcat( msg , " thread exit" ) ;
480 aNode->ExitThread() ;
482 pthread_exit( (void * ) smsg.c_str() ) ;
486 int GraphExecutor::InNode::ExecuteAction() {
488 GraphExecutor::StateEventAction nextaction = _NextAction ;
489 const char * nextactionname = Automaton()->ActionName( nextaction ) ;
490 const char * statename = Automaton()->StateName( State() ) ;
491 const char * nextstatename = Automaton()->StateName( _NextState ) ;
492 cdebug << pthread_self() << "/" << ThreadNo() << " --> ExecuteAction "
493 << nextactionname << " " << statename << " NextState "
494 << nextstatename << endl ;
495 State( _NextState ) ;
496 switch ( nextaction ) {
497 case GraphExecutor::ErrorAction : {
498 sts = ErrorAction() ;
501 case GraphExecutor::VoidAction : {
505 case GraphExecutor::DataWaiting_SomeDataReadyAction : {
506 sts = DataWaiting_SomeDataReadyAction() ;
509 case GraphExecutor::DataUndef_NotAllDataReadyAction : {
510 sts = DataUndef_NotAllDataReadyAction() ;
513 case GraphExecutor::DataUndef_AllDataReadyAction : {
514 sts = DataUndef_AllDataReadyAction() ;
517 case GraphExecutor::DataReady_SuspendAction : {
518 sts = DataReady_SuspendAction() ;
521 case GraphExecutor::SuspendedReady_ResumeAction : {
522 sts = SuspendedReady_ResumeAction() ;
525 case GraphExecutor::DataReady_KillAction : {
526 sts = DataReady_KillAction() ;
529 case GraphExecutor::DataReady_StopAction : {
530 sts = DataReady_StopAction() ;
533 case GraphExecutor::DataReady_ExecuteAction : {
534 sts = DataReady_ExecuteAction() ;
537 case GraphExecutor::Executing_SuspendAction : {
538 sts = Executing_SuspendAction() ;
541 case GraphExecutor::SuspendedExecuting_ResumeAction : {
542 sts = SuspendedExecuting_ResumeAction() ;
545 case GraphExecutor::Executing_KillAction : {
546 sts = Executing_KillAction() ;
549 case GraphExecutor::Executing_StopAction : {
550 sts = Executing_StopAction() ;
553 case GraphExecutor::Executing_SuccessAction : {
554 sts = Executing_SuccessAction() ;
557 case GraphExecutor::Executing_ErrorAction : {
558 sts = Executing_ErrorAction() ;
561 case GraphExecutor::Successed_SuccessAction : {
562 sts = Successed_SuccessAction() ;
565 case GraphExecutor::Errored_ErrorAction : {
566 sts = Errored_ErrorAction() ;
569 case GraphExecutor::Successed_SuspendAction : {
570 sts = Successed_SuspendAction() ;
573 case GraphExecutor::Errored_SuspendAction : {
574 sts = Errored_SuspendAction() ;
577 case GraphExecutor::SuspendedSuccessed_ResumeAction : {
578 sts = SuspendedSuccessed_ResumeAction() ;
581 case GraphExecutor::SuspendedErrored_ResumeAction : {
582 sts = SuspendedErrored_ResumeAction() ;
585 case GraphExecutor::Successed_KillAction : {
586 sts = Successed_KillAction() ;
589 case GraphExecutor::Errored_KillAction : {
590 sts = Errored_KillAction() ;
593 case GraphExecutor::Successed_StopAction : {
594 sts = Successed_StopAction() ;
597 case GraphExecutor::Errored_StopAction : {
598 sts = Errored_StopAction() ;
601 case GraphExecutor::SuspendedSuccessed_ReStartAction : {
602 sts = SuspendedSuccessed_ReStartAction() ;
605 case GraphExecutor::SuspendedErrored_ReStartAction : {
606 sts = SuspendedErrored_ReStartAction() ;
609 case GraphExecutor::SuspendedSuccessed_ReStartAndSuspendAction : {
610 sts = SuspendedSuccessed_ReStartAndSuspendAction() ;
613 case GraphExecutor::SuspendedErrored_ReStartAndSuspendAction : {
614 sts = SuspendedErrored_ReStartAndSuspendAction() ;
618 cdebug << pthread_self() << "/" << ThreadNo()
619 << " GraphExecutor::InNodeThreads::SendEvent Error Undefined Action : "
620 << _NextAction << endl ;
624 cdebug << pthread_self() << "/" << ThreadNo() << "<-- ExecuteAction "
625 << Automaton()->ActionName( nextaction ) << endl ;
629 int GraphExecutor::InNode::ErrorAction() {
630 cdebug << pthread_self() << "/" << ThreadNo() << " Automaton ErrorAction Node "
635 int GraphExecutor::InNode::VoidAction() {
636 cdebug << pthread_self() << "/" << ThreadNo() << " VoidAction " << Name() << endl;
641 int GraphExecutor::InNode::DataWaiting_SomeDataReadyAction() {
642 cdebug << pthread_self() << "/" << ThreadNo()
643 << " --> DataWaiting_SomeDataReadyAction from " << DataFromNode()
644 << " to " << Name() << endl;
648 bool LoopFinished = false ;
649 bool LoopBeginning = false ;
650 bool SwitchFinished = false ;
652 if ( IsEndLoopNode() && !GetChangeNodeInPort( 0 )->GetOutPort()->BoolValue() ) {
653 LoopFinished = true ; // End of Loop
655 if ( IsLoopNode() && GetChangeNodeInPort( 1 )->GetOutPort()->BoolValue() ) {
656 LoopBeginning = true ; // Beginning of Loop
658 if ( IsEndSwitchNode() && !GetChangeNodeInPort( 0 )->GetOutPort()->BoolValue() ) {
659 SwitchFinished = true ;
661 for ( k = 0 ; k < GetNodeInPortsSize() ; k++ ) {
662 GraphBase::InPort * anInPort = GetChangeNodeInPort(k) ;
663 GraphBase::OutPort * anOutPort = anInPort->GetOutPort() ;
664 if ( anInPort->IsGate() && anOutPort == NULL ) {
666 anInPort->State( SUPERV::ReadyState ) ;
667 cdebug << pthread_self() << "/" << ThreadNo() << " " << Name() << " "
668 << anInPort->PortName() << " ControlPort inactive." << endl ;
670 else if ( strcmp( DataFromNode() , anOutPort->NodeName() ) ) {
671 if ( anInPort->State() == SUPERV::ReadyState ) {
673 cdebug << pthread_self() << "/" << ThreadNo() << " " << Name() << " "
674 << anInPort->PortName() << " Was Done from "
675 << anOutPort->NodeName() << " " << anOutPort->PortName()
678 if ( GraphBase::Base::_prof_debug ) {
679 anOutPort->StringValue( *GraphBase::Base::_fdebug ) ;
684 // else if ( LoopBeginning && anInPort->IsDataConnected() ) {
685 else if ( IsLoopNode() && anInPort->IsDataConnected() ) {
686 anInPort->State( SUPERV::ReadyState ) ;
688 cdebug << pthread_self() << "/" << ThreadNo() << " " << Name() << " "
689 << anInPort->PortName() << " Was Done from "
690 << anOutPort->NodeName() << " " << anOutPort->PortName()
691 << " LoopBeginning " << LoopBeginning ;
693 if ( GraphBase::Base::_prof_debug ) {
694 anOutPort->StringValue( *GraphBase::Base::_fdebug ) ;
699 else if ( LoopFinished ) {
700 anInPort->State( SUPERV::ReadyState ) ;
702 cdebug << pthread_self() << "/" << ThreadNo() << " " << Name() << " "
703 << anInPort->PortName() << " Was Done from "
704 << anOutPort->NodeName() << " " << anOutPort->PortName()
707 if ( GraphBase::Base::_prof_debug ) {
708 anOutPort->StringValue( *GraphBase::Base::_fdebug ) ;
713 else if ( anInPort->IsGate() && SwitchFinished ) {
714 anInPort->State( SUPERV::ReadyState ) ;
716 cdebug << pthread_self() << "/" << ThreadNo() << " " << Name() << " "
717 << anInPort->PortName() << " Was Done from "
718 << anOutPort->NodeName() << " " << anOutPort->PortName()
719 << " SwitchFinished" ;
721 if ( GraphBase::Base::_prof_debug ) {
722 anOutPort->StringValue( *GraphBase::Base::_fdebug ) ;
728 cdebug << pthread_self() << "/" << ThreadNo() << " " << Name() << " "
729 << anInPort->PortName() << " Was NOT Done from "
730 << anOutPort->NodeName() << " " << anOutPort->PortName() << " "
731 << " " << Automaton()->StateName( State() ) << " DataConnected "
732 << anInPort->IsDataConnected() << " LoopBeginning "
733 << LoopBeginning << endl ;
736 else if ( anInPort->IsGate() ) {
737 const CORBA::Any * theValue = anOutPort->Value() ;
739 (*theValue) >>= GateOpened ;
740 if ( GateOpened != 0 ) {
742 anInPort->State( SUPERV::ReadyState ) ;
743 cdebug << pthread_self() << "/" << ThreadNo() << " " << Name() << " "
744 << anInPort->PortName() << " Gate is Opened from "
745 << anOutPort->NodeName() << " " << anOutPort->PortName()
748 if ( GraphBase::Base::_prof_debug ) {
749 anOutPort->StringValue( *GraphBase::Base::_fdebug ) ;
754 else if ( LoopFinished ) {
755 anInPort->State( SUPERV::ReadyState ) ;
756 cdebug << pthread_self() << "/" << ThreadNo() << " " << Name() << " "
757 << anInPort->PortName() << " GATE IS CLOSED from "
758 << anOutPort->NodeName() << " " << anOutPort->PortName()
761 if ( GraphBase::Base::_prof_debug ) {
762 anOutPort->StringValue( *GraphBase::Base::_fdebug ) ;
768 cdebug << pthread_self() << "/" << ThreadNo() << " " << Name() << " "
769 << anInPort->PortName() << " GATE IS CLOSED from "
770 << anOutPort->NodeName() << " " << anOutPort->PortName()
773 if ( GraphBase::Base::_prof_debug ) {
774 anOutPort->StringValue( *GraphBase::Base::_fdebug ) ;
782 anInPort->State( SUPERV::ReadyState ) ;
783 cdebug << pthread_self() << "/" << ThreadNo() << " " << Name() << " "
784 << anInPort->PortName() << " is Done from "
785 << anOutPort->NodeName() << " " << anOutPort->PortName() << " " ;
787 if ( GraphBase::Base::_prof_debug ) {
788 anOutPort->StringValue( *GraphBase::Base::_fdebug ) ;
795 if ( InReady == GetNodeInPortsSize() ) { // All Flags != 0 :
796 res = SendEvent( GraphExecutor::AllDataReadyEvent ); // ==> Ready to execute
798 else { // At least one Flag == 0 :
799 res = SendEvent( GraphExecutor::NotAllDataReadyEvent );
802 cdebug << pthread_self() << "/" << ThreadNo()
803 << " <-- DataWaiting_SomeDataReadyAction " << Name() << endl;
808 int GraphExecutor::InNode::DataUndef_NotAllDataReadyAction() {
809 CreateNewThreadIf( false ) ;
810 cdebug << pthread_self() << " for " << ThreadNo()
811 << " DataUndef_NotAllDataReadyAction " << Name() << endl;
815 int GraphExecutor::InNode::DataUndef_AllDataReadyAction() {
816 cdebug << pthread_self() << "/" << ThreadNo()
817 << " --> DataUndef_AllDataReadyAction " << Name()
818 << " CreateNewThreadIf " << CreateNewThreadIf() << " IsLockedDataWait "
819 << IsLockedDataWait() ;
820 // if ( !CreateNewThreadIf() && IsLockedDataWait() ) {
821 if ( IsLockedDataWait() ) {
822 cdebug << " WOULD DEAD-LOCK" << endl ;
823 return 0 ; // ==> DataUndef_AllDataReadyAction() after UnLockDataWait()
826 CreateNewThread( CreateNewThreadIf() ) ;
827 if ( !CreateNewThread() ) {
828 cdebug << "Thread " << ThreadNo() << "-->" << pthread_self() << endl ;
829 ThreadNo( pthread_self() ) ;
831 _OutNode->PushEvent( this , GraphExecutor::AllDataReadyEvent ,
832 SUPERV::DataReadyState ) ;
834 SUPERV::ControlState aControl = ControlState() ;
835 switch ( aControl ) {
836 case SUPERV::VoidState : {
837 SendEvent( GraphExecutor::ExecuteEvent ) ;
840 case SUPERV::ToSuspendState : {
841 SendEvent( GraphExecutor::SuspendEvent ) ;
844 case SUPERV::ToSuspendStartState : {
845 SendEvent( GraphExecutor::SuspendEvent ) ;
848 case SUPERV::ToSuspendDoneState : {
849 SendEvent( GraphExecutor::ExecuteEvent ) ;
852 case SUPERV::ToKillState : {
853 SendEvent( GraphExecutor::KillEvent ) ;
856 case SUPERV::ToKillDoneState : {
857 SendEvent( GraphExecutor::ExecuteEvent ) ;
860 case SUPERV::ToStopState : {
861 SendEvent( GraphExecutor::StopEvent ) ;
866 << " GraphExecutor::InNodeThreads::DataUndef_AllDataReadyAction Error Undefined Control : "
867 << aControl << endl ;
871 cdebug << pthread_self() << "/" << ThreadNo()
872 << " <-- DataUndef_AllDataReadyAction " << Name() << endl;
876 int GraphExecutor::InNode::DataReady_SuspendAction() {
877 cdebug << pthread_self() << "/" << ThreadNo()
878 << "DataReady_SuspendAction --> Suspend " << Name()
879 << " Threads " << _OutNode->Threads() << " SuspendedThreads "
880 << _OutNode->SuspendedThreads() << endl;
881 _OutNode->PushEvent( this , GraphExecutor::SuspendedReadyEvent ,
882 SUPERV::SuspendedReadyState ) ;
883 GraphExecutor::InNode * aReStartNode = SuspendAction() ;
884 cdebug << pthread_self() << "/" << ThreadNo()
885 << "DataReady_SuspendAction Resumed " << Name() << endl;
886 if ( aReStartNode ) {
887 _aReStartNode = NULL ;
888 aReStartNode->SendEvent( _aReStartEvent ) ;
891 SendEvent( GraphExecutor::ExecuteEvent ) ;
896 int GraphExecutor::InNode::SuspendedReady_ResumeAction() {
897 cdebug << pthread_self() << "/" << ThreadNo() << "SuspendedReady_ResumeAction "
900 _OutNode->PushEvent( this , GraphExecutor::ResumedReadyEvent ,
901 SUPERV::ResumedReadyState ) ;
905 int GraphExecutor::InNode::DataReady_KillAction() {
906 _OutNode->PushEvent( this , GraphExecutor::KilledReadyEvent ,
907 SUPERV::KilledReadyState ) ;
909 cdebug << pthread_self() << "/" << ThreadNo() << "DataReady_KillAction " << Name()
910 << " will pthread_exit()" << endl;
914 int GraphExecutor::InNode::DataReady_StopAction() {
915 _OutNode->PushEvent( this , GraphExecutor::StoppedReadyEvent ,
916 SUPERV::StoppedReadyState ) ;
918 cdebug << pthread_self() << "/" << ThreadNo() << "DataReady_StopAction " << Name()
919 << " will pthread_exit()" << endl;
925 int GraphExecutor::InNode::DataReady_ExecuteAction() {
928 cdebug << pthread_self() << "/" << ThreadNo() << " --> DataReady_ExecuteAction "
930 _OutNode->PushEvent( this , GraphExecutor::ExecuteEvent ,
931 SUPERV::ExecutingState ) ;
934 SUPERV::GraphState PortState = SUPERV::ReadyState ;
935 SUPERV::AutomatonState NewState = SUPERV::DataUndefState ;
936 GraphExecutor::NodeEvent NewEvent = GraphExecutor::UndefinedEvent ;
940 int nInParams = GetNodeInPortsSize() ;
941 ServicesAnyData * aListOfInParameters = new ServicesAnyData[nInParams];
942 InParametersSet( Err , nInParams , aListOfInParameters ) ;
944 Engines::Container_var myContainer ;
945 Engines::Component_var myObjComponent ;
946 // if ( strlen( ComponentName() ) == 0 ) {
947 if ( !IsFactoryNode() ) {
948 cdebug << ThreadNo() << "No Component : NO StartComponent & No Ping"
950 if ( IsComputingNode() ) {
951 ObjInterface( true ) ;
952 CORBA::Object_ptr obj ;
953 aListOfInParameters[1].Value >>= obj ;
954 CORBA::Object_var objvar = CORBA::Object_var( obj ) ;
955 myObjComponent = Engines::Component::_narrow( objvar ) ;
960 else if ( CORBA::is_nil( Component() ) ) {
961 Err = !_OutNode->StartComponent( ThreadNo() , Computer() ,
962 my_strdup( ComponentName() ) ,
963 myContainer , myObjComponent ) ;
964 // if ( !Err && nInParams > 1 &&
965 // strcmp( ComponentName() , InterfaceName() ) &&
966 // aListOfInParameters[ 1 ].Value.type()->kind() ==
967 // CORBA::tk_objref ) {
970 ObjInterface( false ) ;
972 SetContainer( myContainer ) ;
973 SetComponent( myObjComponent ) ;
976 myContainer = Container() ;
977 myObjComponent = Component() ;
978 cdebug << ThreadNo() << "Component known : NO StartComponent & Ping"
980 myObjComponent->ping() ;
983 int nOutParams = GetNodeOutPortsSize() ;
984 ServicesAnyData * aListOfOutParameters = new ServicesAnyData[nOutParams];
985 InOutParameters( nOutParams , aListOfOutParameters ) ;
987 // if ( strlen( ComponentName() ) ) {
988 if ( Err || ControlState() == SUPERV::ToKillState ||
989 ControlState() == SUPERV::ToKillDoneState ||
990 ControlState() == SUPERV::ToStopState ) {
991 cdebug << ThreadNo() << "StartComponent Error or ToKillState" << endl ;
996 cdebug << ThreadNo() << " Run( '" << ServiceName() << "'" ;
997 for ( i = 0 ; i < nInParams ; i++ ) {
998 cdebug << " , " << aListOfInParameters[ i ].Name ;
1000 cdebug << ")" << endl ;
1002 if ( IsOneOfInLineNodes() ) {
1003 bool StsPyDynInvoke = true ;
1004 _OutNode->PThreadLock() ;
1006 if ( IsInLineNode() && (*InLineNode()->PythonFunction()).length() &&
1007 strlen( InLineNode()->PyFuncName() ) ) {
1008 cdebug << ThreadNo() << " !ObjInterface " << Name() << " PyFuncName '"
1009 << InLineNode()->PyFuncName()
1010 << "' IsInLineNode PyDynInvoke" << endl ;
1011 StsPyDynInvoke = PyDynInvoke( InLineNode()->PyRunMethod() ,
1012 InLineNode()->PyFuncName() ,
1013 &aListOfInParameters[1] , ServiceInParameter().length() ,
1014 &aListOfOutParameters[1] , ServiceOutParameter().length() ) ;
1016 else if ( IsLoopNode() ) {
1017 if ( GetNodeInPort( 1 )->GetOutPort()->BoolValue() ) { // InLoop Port
1018 cdebug << ThreadNo() << " !ObjInterface " << Name()
1019 << " IsLoopNode PyDynInvoke '" << InLineNode()->PyFuncName()
1021 StsPyDynInvoke = PyDynInvoke( InLineNode()->PyRunMethod() ,
1022 InLineNode()->PyFuncName() ,
1023 &aListOfInParameters[2] , ServiceInParameter().length() ,
1024 &aListOfOutParameters[1] , ServiceOutParameter().length() ) ;
1027 cdebug << ThreadNo() << " !ObjInterface " << Name()
1028 << " IsLoopNode PyDynInvoke '" << LoopNode()->PyNextName()
1030 StsPyDynInvoke = PyDynInvoke( LoopNode()->PyNextMethod() ,
1031 LoopNode()->PyNextName() ,
1032 &aListOfInParameters[2] , ServiceInParameter().length() ,
1033 &aListOfOutParameters[1] , ServiceOutParameter().length() ) ;
1035 if ( StsPyDynInvoke ) {
1036 cdebug << ThreadNo() << " !ObjInterface " << Name()
1037 << " IsLoopNode PyDynInvoke '" << LoopNode()->PyMoreName()
1038 << "' Copy of " << ServiceInParameter().length()
1039 << " OutParameters" << endl ;
1041 for ( i = 0 ; i < ServiceInParameter().length() ; i++ ) {
1042 aListOfInParameters[2 + i].Value = aListOfOutParameters[1+ i].Value ;
1043 aListOfInParameters[2 + i].Name = aListOfOutParameters[1+ i].Name ;
1044 switch ( aListOfInParameters[2 + i].Value.type()->kind() ) {
1045 case CORBA::tk_string :
1046 cdebug << "Arg" << i << " : "
1047 << aListOfInParameters[2 + i].Name.c_str()
1048 << " Value(string) " << endl ;
1050 case CORBA::tk_double :
1051 cdebug << "Arg" << i << " : "
1052 << aListOfInParameters[2 + i].Name.c_str()
1053 << " Value(double) " << endl ;
1055 case CORBA::tk_long :
1056 cdebug << "Arg" << i << " : "
1057 << aListOfInParameters[2 + i].Name.c_str()
1058 << " Value(long) " << endl ;
1060 case CORBA::tk_objref :
1061 cdebug << "Arg" << i << " : "
1062 << aListOfInParameters[2 + i].Name.c_str()
1063 << " Value(object reference) " << endl ;
1066 cdebug << "Arg" << i << " : "
1067 << aListOfInParameters[2 + i].Name.c_str()
1068 << " Value(other) ERROR" << endl ;
1071 StsPyDynInvoke = PyDynInvoke( LoopNode()->PyMoreMethod() ,
1072 LoopNode()->PyMoreName() ,
1073 &aListOfInParameters[2] , ServiceInParameter().length() ,
1074 &aListOfOutParameters[0] , ServiceOutParameter().length()+1 ) ;
1078 cdebug << ThreadNo() << " InLineNode " << Name() << " "
1079 << InLineNode()->PyFuncName() << "/" << LoopNode()->PyNextName()
1080 << " Python Dynamic Call Error"
1084 else if ( IsSwitchNode() ) {
1085 cdebug << ThreadNo() << " !ObjInterface " << Name() << " PyFuncName '"
1086 << InLineNode()->PyFuncName()
1087 << "' IsSwitchNode PyDynInvoke" << endl ;
1088 StsPyDynInvoke = PyDynInvoke( InLineNode()->PyRunMethod() ,
1089 InLineNode()->PyFuncName() ,
1090 &aListOfInParameters[1] , ServiceInParameter().length() ,
1091 &aListOfOutParameters[1] , ServiceOutParameter().length() ) ;
1093 else if ( IsGOTONode() && (*GOTONode()->PythonFunction()).length() &&
1094 strlen( InLineNode()->PyFuncName() ) ) {
1095 cdebug << ThreadNo() << " !ObjInterface " << Name() << " PyFuncName '"
1096 << InLineNode()->PyFuncName()
1097 << "' IsGOTONode PyDynInvoke" << endl ;
1098 StsPyDynInvoke = PyDynInvoke( InLineNode()->PyRunMethod() ,
1099 InLineNode()->PyFuncName() ,
1100 &aListOfInParameters[1] , ServiceInParameter().length() ,
1101 &aListOfOutParameters[1] , ServiceOutParameter().length() ) ;
1103 else if ( IsEndSwitchNode() && (*InLineNode()->PythonFunction()).length() &&
1104 strlen( InLineNode()->PyFuncName() ) ) {
1105 cdebug << ThreadNo() << " !ObjInterface " << Name() << " PyFuncName '"
1106 << InLineNode()->PyFuncName()
1107 << "' IsSwitchNode PyDynInvoke" << endl ;
1108 StsPyDynInvoke = PyDynInvoke( InLineNode()->PyRunMethod() ,
1109 InLineNode()->PyFuncName() ,
1110 &aListOfInParameters[1] , ServiceInParameter().length() ,
1111 &aListOfOutParameters[0] , ServiceOutParameter().length() ) ;
1113 else if ( (*InLineNode()->PythonFunction()).length() == 0 ||
1114 strlen( InLineNode()->PyFuncName() ) == 0 ) {
1115 cdebug << ThreadNo() << " !ObjInterface " << Name()
1116 << " Copy of " << ServiceInParameter().length()
1117 << " OutParameters" << endl ;
1120 if ( IsEndSwitchNode() ) {
1123 else if ( IsEndLoopNode() || IsGOTONode() ) {
1126 for ( i = 0 ; i < ServiceInParameter().length() ; i++ ) {
1127 aListOfOutParameters[argind0 + i].Value = aListOfInParameters[ 1 + i].Value ;
1128 // aListOfOutParameters[argind0 + i].Name = aListOfInParameters[argind0 + i].Name ;
1129 switch ( aListOfInParameters[ 1 + i].Value.type()->kind() ) {
1130 case CORBA::tk_string :
1131 cdebug << "Arg" << i << " : "
1132 << aListOfInParameters[ 1 + i].Name.c_str()
1133 << " Value(string) "
1134 << aListOfOutParameters[argind0 + i].Name.c_str() << endl ;
1136 case CORBA::tk_double :
1137 cdebug << "Arg" << i << " : "
1138 << aListOfInParameters[ 1 + i].Name.c_str()
1139 << " Value(double) "
1140 << aListOfOutParameters[argind0 + i].Name.c_str() << endl ;
1142 case CORBA::tk_long :
1143 cdebug << "Arg" << i << " : "
1144 << aListOfInParameters[ 1 + i].Name.c_str()
1146 << aListOfOutParameters[argind0 + i].Name.c_str() << endl ;
1148 case CORBA::tk_objref :
1149 cdebug << "Arg" << i << " : "
1150 << aListOfInParameters[ 1 + i].Name.c_str()
1151 << " Value(object reference) "
1152 << aListOfOutParameters[argind0 + i].Name.c_str() << endl ;
1155 cdebug << "Arg" << i << " : "
1156 << aListOfInParameters[ 1 + i].Name.c_str()
1157 << " Value(other) ERROR "
1158 << aListOfOutParameters[argind0 + i].Name.c_str() << endl ;
1162 if ( !StsPyDynInvoke ) {
1164 cdebug << ThreadNo() << " InLineNode " << Name()
1165 << " Python Dynamic Call Error"
1171 cdebug << ThreadNo() << " InLineNode " << Name()
1172 << " Python Dynamic Call Exception catched ERROR"
1175 _OutNode->PThreadUnLock() ;
1177 // else if ( !ObjInterface() ) {
1178 else if ( IsFactoryNode() ) {
1181 DynInvoke( myObjComponent, "Names" ,
1182 _OutNode->Name() , Name() ) ;
1185 cdebug << "DynInvoke Names catched ERROR" << endl ;
1187 cdebug << ServiceInParameter().length() << " input parameters and "
1188 << ServiceOutParameter().length() << " output parameters" << endl ;
1189 if ( IsComputingNode() ) {
1190 cdebug << ThreadNo() << " !ObjInterface " << Name()
1191 << " IsComputingNode DynInvoke" << endl ;
1192 DynInvoke( myObjComponent,
1194 &aListOfInParameters[1] , ServiceInParameter().length() ,
1195 &aListOfOutParameters[1] , ServiceOutParameter().length() ) ;
1197 else if ( IsFactoryNode() ) {
1198 cdebug << ThreadNo() << " !ObjInterface " << Name()
1199 << " IsFactoryNode DynInvoke" << endl ;
1200 DynInvoke( myObjComponent,
1202 &aListOfInParameters[1] , ServiceInParameter().length() ,
1203 &aListOfOutParameters[1] , ServiceOutParameter().length() ) ;
1208 cdebug << ThreadNo() << " !ObjInterface " << Name()
1209 << " Node(Component) Dynamic Call Exception catched ERROR"
1216 DynInvoke( myObjComponent, "Names" ,
1217 _OutNode->Name() , Name() ) ;
1221 cdebug << ThreadNo() << " ObjInterface " << Name() << " DynInvoke"
1223 DynInvoke( myObjComponent ,
1225 &aListOfInParameters[2] , ServiceInParameter().length()-1 ,
1226 &aListOfOutParameters[1] , ServiceOutParameter().length() ) ;
1230 cdebug << ThreadNo() << " ObjInterface " << Name()
1231 << " Node(Interface) Dynamic Call Exception catched ERROR"
1243 if ( ControlState() == SUPERV::ToKillState ||
1244 ControlState() == SUPERV::ToKillDoneState ||
1245 ControlState() == SUPERV::ToStopState ) {
1246 PortState = SUPERV::ErrorState ;
1247 NewState = SUPERV::KilledState ;
1248 NewEvent = GraphExecutor::KillEvent ;
1251 PortState = SUPERV::ErrorState ;
1252 NewState = SUPERV::ErroredState ;
1253 NewEvent = GraphExecutor::ErrorEvent ;
1257 PortState = SUPERV::ReadyState ;
1258 NewState = SUPERV::DataReadyState ;
1259 NewEvent = GraphExecutor::SuccessEvent ;
1262 bool ErrOut = OutParameters( Err , PortState , nOutParams , aListOfOutParameters ) ;
1264 NewEvent = GraphExecutor::ErrorEvent ;
1266 delete [] aListOfInParameters ;
1267 delete [] aListOfOutParameters ;
1269 SendEvent( NewEvent );
1271 cdebug << ThreadNo() << " <-- DataReady_ExecuteAction " << Name() << endl;
1275 int GraphExecutor::InNode::Executing_SuspendAction() {
1276 _OutNode->PushEvent( this , GraphExecutor::SuspendedExecutingEvent ,
1277 SUPERV::SuspendedExecutingState ) ;
1278 cdebug << ThreadNo() << " Executing_SuspendAction " << Name() << endl;
1282 int GraphExecutor::InNode::SuspendedExecuting_ResumeAction() {
1283 cdebug << ThreadNo() << " SuspendedExecuting_ResumeAction " << Name() << endl;
1284 SUPERV::AutomatonState next_state ;
1285 next_state = Automaton()->NextState( State() , GraphExecutor::ExecutingEvent ) ;
1286 _OutNode->NewThread() ; // Only for Threads count
1287 _OutNode->PushEvent( this , GraphExecutor::ResumedExecutingEvent ,
1289 State( next_state ) ;
1293 int GraphExecutor::InNode::Executing_KillAction() {
1294 cdebug << ThreadNo() << " Executing_KillAction " << Name() << endl;
1296 if ( pthread_self() == ThreadNo() ) {
1297 cdebug << "Executing_KillAction would pthread_canceled itself" << endl ;
1299 _OutNode->PushEvent( this , GraphExecutor::KilledExecutingEvent ,
1300 SUPERV::KilledExecutingState ) ;
1303 else if ( pthread_cancel( ThreadNo() ) ) {
1304 perror("Executing_KillAction pthread_cancel error") ;
1307 cdebug << "Executing_KillAction : ThreadId " << ThreadNo()
1308 << " pthread_canceled" << endl ;
1310 _OutNode->ExitThread() ;
1311 _OutNode->PushEvent( this , GraphExecutor::KilledExecutingEvent ,
1312 SUPERV::KilledExecutingState ) ;
1317 int GraphExecutor::InNode::Executing_StopAction() {
1318 cdebug << ThreadNo() << " Executing_StopAction " << Name() << endl;
1320 if ( pthread_cancel( ThreadNo() ) ) {
1321 perror("Executing_KillAction pthread_cancel error") ;
1324 cdebug << "Executing_KillAction : ThreadId " << ThreadNo()
1325 << " pthread_canceled" << endl ;
1327 _OutNode->ExitThread() ;
1328 _OutNode->PushEvent( this , GraphExecutor::StoppedExecutingEvent ,
1329 SUPERV::StoppedExecutingState ) ;
1334 int GraphExecutor::InNode::Executing_SuccessAction() {
1335 cdebug << ThreadNo() << " --> Executing_SuccessAction " << Name() << endl;
1336 _OutNode->PushEvent( this , GraphExecutor::SuccessedExecutingEvent ,
1337 SUPERV::SuccessedState ) ;
1339 SUPERV::ControlState aControl = ControlState() ;
1340 switch ( aControl ) {
1341 case SUPERV::VoidState : {
1342 SendEvent( SuccessEvent ) ;
1345 case SUPERV::ToSuspendState : {
1346 SendEvent( SuccessEvent ) ;
1349 case SUPERV::ToSuspendDoneState : {
1350 SendEvent( GraphExecutor::SuspendEvent ) ;
1353 case SUPERV::ToKillState : {
1354 SendEvent( GraphExecutor::KillEvent ) ;
1357 case SUPERV::ToKillDoneState : {
1358 SendEvent( GraphExecutor::KillEvent ) ;
1361 case SUPERV::ToStopState : {
1362 SendEvent( GraphExecutor::StopEvent ) ;
1366 cdebug << ThreadNo()
1367 << " GraphExecutor::InNodeThreads::Executing_SuccessAction Error Undefined Control : "
1368 << aControl << endl ;
1372 cdebug << ThreadNo() << " <-- Executing_SuccessAction " << Name() << endl;
1376 int GraphExecutor::InNode::Executing_ErrorAction() {
1377 cdebug << ThreadNo() << " --> Executing_ErrorAction " << Name() << endl;
1378 _OutNode->PushEvent( this , GraphExecutor::ErroredExecutingEvent ,
1379 SUPERV::ErroredState ) ;
1382 SUPERV::ControlState aControl = ControlState() ;
1383 switch ( aControl ) {
1384 case SUPERV::VoidState : {
1385 SendEvent( ErrorEvent ) ;
1388 case SUPERV::ToSuspendState : {
1389 SendEvent( ErrorEvent ) ;
1392 case SUPERV::ToSuspendDoneState : {
1393 SendEvent( GraphExecutor::SuspendEvent ) ;
1396 case SUPERV::ToKillState : {
1397 SendEvent( GraphExecutor::KillEvent ) ;
1400 case SUPERV::ToKillDoneState : {
1401 SendEvent( GraphExecutor::KillEvent ) ;
1404 case SUPERV::ToStopState : {
1405 SendEvent( GraphExecutor::StopEvent ) ;
1409 cdebug << ThreadNo()
1410 << " GraphExecutor::InNodeThreads::Executing_ErrorAction Error Undefined Control : "
1411 << aControl << endl ;
1415 cdebug << ThreadNo() << " <-- Executing_ErrorAction " << Name() << endl;
1419 // Set SUPERV::WaitingState to all InPorts
1420 void GraphExecutor::InNode::SetWaitingStates(GraphExecutor::InNode * EndNode ) {
1423 bool docdebug = false ;
1424 State( SUPERV::DataWaitingState ) ;
1425 for ( i = 0 ; i < GetNodeInPortsSize() ; i++ ) {
1426 GraphBase::InPort * anInPort = GetChangeNodeInPort( i ) ;
1427 if ( anInPort->IsGate() ) { // Loop : Open the doors
1428 GraphBase::OutPort * anOutPort = anInPort->GetOutPort() ;
1430 CORBA::Any * anAny = new CORBA::Any() ;
1431 *anAny <<= (long ) 1 ;
1432 anOutPort->Value( anAny ) ;
1433 anInPort->State( SUPERV::ReadyState ) ;
1436 else if ( anInPort->State() != SUPERV::WaitingState ) {
1438 cdebug << ThreadNo()
1439 << " --> GraphExecutor::InNodeThreads::SetWaitingStates "
1443 anInPort->State( SUPERV::WaitingState ) ;
1446 for ( i = 0 ; i < GetNodeOutPortsSize() ; i++ ) {
1447 if ( !( IsGOTONode() && i == 0 ) && !( IsEndLoopNode() && i <= 1 ) ) {
1448 for ( j = 0 ; j < GetChangeNodeOutPort( i )->InPortsSize() ; j++ ) {
1449 GraphExecutor::InNode * aNode = (GraphExecutor::InNode * ) _OutNode->GetChangeGraphNode( GetChangeNodeOutPort( i )->ChangeInPorts( j )->NodeName() )->GetInNode() ;
1450 if ( aNode != EndNode ) {
1451 aNode->SetWaitingStates( EndNode ) ;
1458 int GraphExecutor::InNode::Successed_SuccessAction() {
1459 cdebug << ThreadNo() << " --> Successed_SuccessAction " << Name() << endl;
1461 int linkednodesnumber = LinkedNodesSize() ;
1462 GraphExecutor::InNode *firstzeroNode = NULL ;
1463 GraphExecutor::InNode *firsttoNode = NULL ;
1464 GraphExecutor::InNode *toNode ;
1467 list<GraphExecutor::InNode *> SomeDataNodes ;
1471 if ( IsGOTONode() ||
1472 ( IsEndLoopNode() && GetNodeInPort(0)->GetOutPort()->BoolValue() ) ) {
1474 // if ( IsGOTONode() ) {
1479 // CORBA::Any * anAny = new CORBA::Any() ;
1480 // *anAny <<= (long ) 0 ;
1481 // GetChangeNodeOutPort(1)->Value( anAny ) ; // Loop(InLoop) = false
1483 // const GraphBase::OutPort * GateOutPort = GetNodeOutPort(index) ;
1484 const GraphBase::OutPort * GateOutPort = GetNodeOutPort(0) ;
1485 for ( i = 0 ; i < GateOutPort->InPortsSize() ; i++ ) {
1486 const GraphBase::InPort * anInPort = GateOutPort->InPorts( i ) ;
1487 GraphExecutor::InNode * aLabelNode = (GraphExecutor::InNode *) _OutNode->GetChangeGraphNode( anInPort->NodeName() )->GetInNode() ;
1488 aLabelNode->SetWaitingStates( this ) ;
1489 for ( j = 1 ; j < GetNodeOutPortsSize() ; j++ ) {
1490 GraphBase::OutPort * aBusParamOutPort = GetChangeNodeOutPort( j ) ;
1491 GraphBase::InPort * aBusParamChangeInPort = NULL ;
1492 // if ( aBusParamOutPort->IsLoop() ) {
1493 // aBusParamChangeInPort = aLabelNode->GetChangeInPort( "InitLoop" ) ;
1496 aBusParamChangeInPort = aLabelNode->GetChangeInPort( aBusParamOutPort->PortName() ) ;
1498 if ( aBusParamChangeInPort ) {
1499 aBusParamChangeInPort->ChangeOutPort( aBusParamOutPort ) ;
1500 if ( !aLabelNode->IsLockedDataWait() ) {
1501 res = aLabelNode->SendSomeDataReady( Name() ) ;
1503 if ( firsttoNode == NULL &&
1504 aLabelNode->ThreadNo() == pthread_self() ) {
1505 firsttoNode = aLabelNode ;
1506 cdebug << ThreadNo() << " Successed_SuccessAction firsttoNode "
1507 << aLabelNode->Name() << endl ;
1509 else if ( firstzeroNode == NULL &&
1510 aLabelNode->ThreadNo() == 0 ) {
1511 firstzeroNode = aLabelNode ;
1514 SomeDataNodes.push_back( aLabelNode ) ;
1515 cdebug << ThreadNo() << " Successed_SuccessAction push "
1516 << SomeDataNodes.size() << " " << aLabelNode->Name()
1522 cdebug << ThreadNo()
1523 << " Successed_SuccessAction Loop to HeadNode "
1524 << aLabelNode->Name() << " with datas from "
1525 << aBusParamOutPort->PortName() << " to port "
1526 << aBusParamChangeInPort->PortName() << endl;
1530 cdebug << ThreadNo() << " ERROR in Successed_SuccessAction of " << Name()
1531 << " NO port " << aBusParamOutPort->PortName() << " in "
1532 << aLabelNode->Name() << endl;
1535 // const GraphBase::OutPort * aGateOutPort = GetNodeOutPort( index ) ;
1536 // const GraphBase::InPort * aGateInPort = aLabelNode->GetNodeInPort( index ) ;
1537 const GraphBase::OutPort * aGateOutPort = GetNodeOutPort( 0 ) ; // DoLoop or OutGate
1538 const GraphBase::InPort * aGateInPort = aLabelNode->GetNodeInPort( 0 ) ;
1539 if ( aGateInPort ) {
1540 if ( aGateInPort->GetOutPort() ) {
1541 aGateInPort->GetOutPort()->Value( aGateOutPort->Value() ) ;
1543 if ( !aLabelNode->IsLockedDataWait() ) {
1544 res = aLabelNode->SendSomeDataReady( Name() ) ;
1546 if ( firsttoNode == NULL &&
1547 aLabelNode->ThreadNo() == pthread_self() ) {
1548 firsttoNode = aLabelNode ;
1549 cdebug << ThreadNo() << " Successed_SuccessAction firsttoNode "
1550 << aLabelNode->Name() << endl ;
1552 else if ( firstzeroNode == NULL &&
1553 aLabelNode->ThreadNo() == 0 ) {
1554 firstzeroNode = aLabelNode ;
1557 SomeDataNodes.push_back( aLabelNode ) ;
1558 cdebug << ThreadNo() << " Successed_SuccessAction push "
1559 << SomeDataNodes.size() << " " << aLabelNode->Name()
1566 cdebug << ThreadNo() << " ERROR in Successed_SuccessAction of " << Name()
1567 << " NO port " << aGateOutPort->PortName() << " in "
1568 << aLabelNode->Name() << endl;
1574 cdebug << ThreadNo() << " Successed_SuccessAction of " << Name()
1575 << " with " << LinkedNodesSize() << " linked nodes :" ;
1576 for ( i = 0 ; i < LinkedNodesSize() ; i++ ) {
1577 if ( LinkedNodes( i )->IsDataFlowNode() ) {
1578 linkednodesnumber -= 1 ;
1580 cdebug << " " << LinkedNodes( i )->Name() ;
1583 SUPERV::ControlState aControl = ControlState() ;
1584 for ( i = 0 ; i < LinkedNodesSize() ; i++ ) {
1585 bool IgnoreForEndLoop = false ;
1586 toNode = (GraphExecutor::InNode *) LinkedNodes( i )->GetInNode() ;
1587 cdebug << ThreadNo() << " Successed_SuccessAction of " << Name()
1588 << " [" << i << "] " << LinkedNodes( i )->Name() << endl ;
1589 if ( toNode && !toNode->IsDataFlowNode() ) {
1590 GraphBase::InPort * toGateInPort = toNode->GetChangeNodeInPort(0) ;
1591 if ( IsComputingNode() && toNode->IsInLineNode() ) {
1592 toGateInPort->State( SUPERV::ReadyState ) ;
1593 GraphBase::OutPort * GateOutPort = toGateInPort->GetOutPort() ;
1594 if ( GateOutPort ) {
1595 GateOutPort->PortStatus( DataConnected );
1596 GateOutPort->State( SUPERV::ReadyState ) ;
1597 GateOutPort->Done( true ) ;
1601 if ( toNode && IsLoopNode() ) {
1602 GraphBase::OutPort * fromLoopOutPort = GetChangeNodeOutPort(0) ;
1603 if ( !fromLoopOutPort->BoolValue() ) {
1604 if ( strcmp( toNode->Name() , CoupledNode()->Name() ) ) {
1605 IgnoreForEndLoop = true ; // toNode is the EndLoopNode
1608 GraphBase::InPort * toLoopInPort ;
1609 toLoopInPort = toNode->GetChangeNodeInPort(1) ;
1610 if ( toLoopInPort->State() != SUPERV::ReadyState ) {
1611 toLoopInPort->State( SUPERV::ReadyState ) ;
1616 else if ( toNode && IsSwitchNode() ) {
1618 else if ( toNode && toNode->IsInLineNode() ) {
1620 for ( j = 0 ; j < toNode->GetNodeInPortsSize() ; j++ ) {
1621 toNode->GetChangeNodeInPort( j )->InitialOutPort() ;
1624 if ( toNode && !IgnoreForEndLoop ) {
1625 if ( toNode && toNode->IsLoopNode() ) {
1626 GraphBase::InPort * toLoopInPort = toNode->GetChangeNodeInPort(1) ;
1627 toLoopInPort->State( SUPERV::ReadyState ) ;
1628 GraphBase::OutPort * LoopOutPort = toLoopInPort->GetOutPort() ;
1629 LoopOutPort->PortStatus( DataConnected );
1630 LoopOutPort->State( SUPERV::ReadyState ) ;
1631 LoopOutPort->Done( true ) ;
1632 CORBA::Any * anAny = new CORBA::Any() ;
1633 *anAny <<= (long ) 1 ;
1634 LoopOutPort->Value( anAny ) ;
1636 for ( j = 0 ; j < toNode->GetNodeInPortsSize() ; j++ ) {
1637 toNode->GetChangeNodeInPort( j )->InitialOutPort() ;
1640 res = toNode->SendSomeDataReady( Name() ) ;
1642 if ( firsttoNode == NULL &&
1643 toNode->ThreadNo() == pthread_self() ) {
1644 firsttoNode = toNode ;
1645 cdebug << ThreadNo() << " Successed_SuccessAction firsttoNode "
1646 << toNode->Name() << endl ;
1648 else if ( firstzeroNode == NULL &&
1649 toNode->ThreadNo() == 0 ) {
1650 firstzeroNode = toNode ;
1653 SomeDataNodes.push_back( toNode ) ;
1654 cdebug << ThreadNo() << " Successed_SuccessAction push "
1655 << SomeDataNodes.size() << " " << toNode->Name() << endl ;
1662 if ( firsttoNode == NULL && firstzeroNode ) {
1663 firsttoNode = firstzeroNode ;
1664 cdebug << ThreadNo()
1665 << " Successed_SuccessAction firsttoNode = firstzeroNode "
1668 else if ( firsttoNode && firstzeroNode ) {
1669 SomeDataNodes.push_back( firstzeroNode ) ;
1670 cdebug << ThreadNo() << " Successed_SuccessAction push firstzeroNode "
1671 << SomeDataNodes.size() << " " << firstzeroNode->Name() << endl ;
1674 while ( SomeDataNodes.size() ) {
1675 GraphExecutor::InNode *aNode = SomeDataNodes.front() ;
1676 SomeDataNodes.pop_front() ;
1677 cdebug << pthread_self() << "/" << ThreadNo()
1678 << " Successed_SuccessAction pop "
1679 << SomeDataNodes.size() << " " << aNode->Name() << endl ;
1680 if ( aNode->State() == SUPERV::DataReadyState ) {
1681 aNode->CreateNewThreadIf( true ) ;
1682 aNode->UnLockDataWait() ;
1683 res = aNode->DataUndef_AllDataReadyAction() ;
1686 cdebug << pthread_self() << "/" << ThreadNo() << " ERROR "
1687 << aNode->Name() << " "
1688 << Automaton()->StateName( aNode->State() ) << endl ;
1692 if ( firsttoNode ) {
1693 // firsttoNode = SomeDataNodes.front() ;
1694 // SomeDataNodes.pop_front() ;
1695 cdebug << pthread_self() << "/" << ThreadNo()
1696 << " Successed_SuccessAction pop firsttoNode "
1697 << SomeDataNodes.size() << " " << firsttoNode->Name() << endl ;
1698 firsttoNode->CreateNewThreadIf( false ) ;
1699 if ( firsttoNode->State() == SUPERV::SuccessedState ) {
1700 cdebug << pthread_self() << "/" << ThreadNo() << " " << Name()
1701 << " : " << firsttoNode->Name() << " "
1702 << Automaton()->StateName( firsttoNode->State() )
1703 << " --> DataWaitingState for Thread "
1704 << firsttoNode->ThreadNo() << endl ;
1705 firsttoNode->State( SUPERV::DataWaitingState ) ;
1707 pthread_t OldT = firsttoNode->ThreadNo() ;
1708 firsttoNode->ThreadNo( pthread_self() ) ;
1709 // On continue avec le meme thread
1710 cdebug << pthread_self() << "/" << ThreadNo() << " firsttoNode "
1711 << firsttoNode->Name() << "Thread(" << OldT << "-->"
1712 << firsttoNode->ThreadNo() << ")" << endl ;
1714 cdebug << ThreadNo() << " Successed_SuccessAction " << Name()
1715 << " for " << firsttoNode->Name()
1716 << " !firsttoNode->CreateNewThreadIf() "
1717 << !firsttoNode->CreateNewThreadIf()
1718 << " " << Automaton()->StateName( firsttoNode->State() ) ;
1719 if ( firsttoNode->State() == SUPERV::DataReadyState ) {
1721 firsttoNode->UnLockDataWait() ;
1722 res = firsttoNode->DataUndef_AllDataReadyAction() ;
1725 cdebug << " ERROR " << endl ;
1729 cdebug << ThreadNo() << " Successed_SuccessAction " << Name()
1730 << " NO DataReady ==> ThreadNo( 0 )" << endl ;
1734 if ( linkednodesnumber == 0 ) {
1735 _OutNode->CheckAllDone() ;
1738 cdebug << pthread_self() << "/" << ThreadNo()
1739 << " <-- Successed_SuccessAction " << Name() << " linkednodesnumber "
1740 << linkednodesnumber << endl;
1744 bool GraphExecutor::InNode::SendSomeDataReady( char * FromNodeName ) {
1745 bool RetVal = false ;
1746 if ( IsDataFlowNode() ) {
1747 cdebug << ThreadNo() << " ----> " << Name()
1748 << " send Result to graph " << Name() << endl;
1751 cdebug << pthread_self() << "/" << ThreadNo() << " ----> " << FromNodeName
1752 << " send SomeDataReady to " << Name() << " "
1753 << Automaton()->StateName( State() )
1754 << " CreateNewThreadIf() " << CreateNewThreadIf()
1755 << " LockedDataWait " << IsLockedDataWait() << endl;
1757 cout << pthread_self() << "/" << ThreadNo() << " ----> " << FromNodeName
1758 << " send SomeDataReady to " << Name() << " "
1759 << Automaton()->StateName( State() )
1760 << " CreateNewThreadIf() " << CreateNewThreadIf()
1761 << " LockedDataWait " << IsLockedDataWait() << endl;
1763 if ( State() == SUPERV::SuccessedState ||
1764 State() == SUPERV::SuspendedSuccessedState ||
1765 State() == SUPERV::SuspendedSuccessedToReStartState ) {
1766 cdebug << ThreadNo() << " " << FromNodeName
1767 << " : " << Name() << " " << Automaton()->StateName( State() )
1768 << " --> DataWaitingState for Thread "
1769 << ThreadNo() << " " << endl ;
1770 State( SUPERV::DataWaitingState ) ;
1773 DataFromNode( FromNodeName ) ;
1774 RetVal = !SendEvent( GraphExecutor::SomeDataReadyEvent );
1782 int GraphExecutor::InNode::Errored_ErrorAction() {
1783 cdebug << ThreadNo() << " Errored_ErrorAction " << Name()
1784 << " will pthread_exit" << endl;
1789 int GraphExecutor::InNode::Successed_SuspendAction() {
1790 cdebug << ThreadNo() << " Successed_SuspendAction -->Suspend " << Name()
1791 << " Threads " << _OutNode->Threads() << " SuspendedThreads "
1792 << _OutNode->SuspendedThreads() << endl;
1793 _OutNode->PushEvent( this , GraphExecutor::SuspendedSuccessedEvent ,
1794 SUPERV::SuspendedSuccessedState ) ;
1796 GraphExecutor::InNode * aReStartNode = SuspendAction() ;
1797 cdebug << ThreadNo() << " Successed_SuspendAction Resumed " << Name() ;
1798 if ( aReStartNode ) {
1799 _aReStartNode = NULL ;
1800 cdebug << " for " << aReStartNode->Name() << endl;
1801 aReStartNode->SendEvent( _aReStartEvent ) ;
1805 SendEvent( GraphExecutor::ResumeEvent ) ;
1810 int GraphExecutor::InNode::Errored_SuspendAction() {
1811 cdebug << ThreadNo() << " Errored_SuspendAction -->Suspend " << Name()
1812 << " Threads " << _OutNode->Threads() << " SuspendedThreads "
1813 << _OutNode->SuspendedThreads() << endl;
1814 _OutNode->PushEvent( this , GraphExecutor::SuspendedErroredEvent ,
1815 SUPERV::SuspendedErroredState ) ;
1817 GraphExecutor::InNode * aReStartNode = SuspendAction() ;
1818 cdebug << ThreadNo() << " Errored_SuspendAction Resumed " << Name()
1820 if ( aReStartNode ) {
1821 _aReStartNode = NULL ;
1822 aReStartNode->SendEvent( _aReStartEvent ) ;
1825 SendEvent( GraphExecutor::ResumeEvent ) ;
1830 int GraphExecutor::InNode::SuspendedSuccessed_ResumeAction() {
1831 cdebug << ThreadNo() << " SuspendedSuccessed_ResumeAction " << Name() << endl;
1833 _OutNode->PushEvent( this , GraphExecutor::ResumedSuccessedEvent ,
1834 SUPERV::ResumedSuccessedState ) ;
1835 SendEvent( ResumedSuccessedEvent ) ;
1839 int GraphExecutor::InNode::SuspendedErrored_ResumeAction() {
1840 cdebug << ThreadNo() << " SuspendedErrored_ResumeAction " << Name() << endl;
1842 _OutNode->PushEvent( this , GraphExecutor::ResumedErroredEvent ,
1843 SUPERV::ResumedErroredState ) ;
1844 SendEvent( ResumedErroredEvent ) ;
1848 int GraphExecutor::InNode::Successed_KillAction() {
1850 _OutNode->PushEvent( this , GraphExecutor::KilledEvent ,
1851 SUPERV::KilledSuccessedState ) ;
1852 cdebug << ThreadNo() << " Successed_KillAction " << Name() << endl;
1856 int GraphExecutor::InNode::Errored_KillAction() {
1858 _OutNode->PushEvent( this , GraphExecutor::KilledEvent ,
1859 SUPERV::KilledErroredState ) ;
1860 cdebug << ThreadNo() << " Errored_KillAction " << Name() << endl;
1864 int GraphExecutor::InNode::Successed_StopAction() {
1866 _OutNode->PushEvent( this , GraphExecutor::StoppedEvent ,
1867 SUPERV::StoppedSuccessedState ) ;
1868 cdebug << ThreadNo() << " Successed_StopAction " << Name() << endl;
1872 int GraphExecutor::InNode::Errored_StopAction() {
1874 _OutNode->PushEvent( this , GraphExecutor::StoppedEvent ,
1875 SUPERV::StoppedErroredState ) ;
1876 cdebug << ThreadNo() << " Errored_StopAction " << Name() << endl;
1880 int GraphExecutor::InNode::SuspendedSuccessed_ReStartAction() {
1881 cdebug << ThreadNo() << " SuspendedSuccessed_ReStartAction " << Name() << endl;
1882 _OutNode->PushEvent( this , GraphExecutor::ReStartedEvent ,
1883 SUPERV::ReStartedState ) ;
1885 for ( i = 0 ; i < GetNodeInPortsSize() ; i++ ) {
1886 GetChangeNodeInPort( i )->State( SUPERV::ReadyState ) ;
1888 SendEvent( ExecuteEvent ) ;
1889 cdebug << ThreadNo() << " SuspendedSuccessed_ReStartAction " << Name() << endl;
1893 int GraphExecutor::InNode::SuspendedErrored_ReStartAction() {
1894 cdebug << ThreadNo() << " SuspendedErrored_ReStartAction " << Name() << endl;
1895 _OutNode->PushEvent( this , GraphExecutor::ReStartedEvent ,
1896 SUPERV::ReStartedState ) ;
1898 for ( i = 0 ; i < GetNodeInPortsSize() ; i++ ) {
1899 GetChangeNodeInPort( i )->State( SUPERV::ReadyState ) ;
1901 SendEvent( ExecuteEvent ) ;
1902 cdebug << ThreadNo() << " SuspendedErrored_ReStartAction " << Name() << endl;
1906 int GraphExecutor::InNode::SuspendedSuccessed_ReStartAndSuspendAction() {
1907 cdebug << ThreadNo() << " SuspendedSuccessed_ReStartAndSuspendAction " << Name()
1909 _OutNode->PushEvent( this , GraphExecutor::ReStartedAndSuspendEvent ,
1910 SUPERV::ReStartedState ) ;
1911 State( SUPERV::DataWaitingState ) ;
1913 cdebug << "InNode::Suspend() Node " << Name() << endl ;
1916 else if ( SendEvent( GraphExecutor::SomeDataReadyEvent ) ) {
1917 cdebug << "InNode::SendEvent( SomeDataReadyEvent ) Node "
1921 cdebug << ThreadNo() << " SuspendedSuccessed_ReStartAndSuspendAction " << Name()
1926 int GraphExecutor::InNode::SuspendedErrored_ReStartAndSuspendAction() {
1927 cdebug << ThreadNo() << " SuspendedErrored_ReStartAndSuspendAction " << Name()
1929 _OutNode->PushEvent( this , GraphExecutor::ReStartedAndSuspendEvent ,
1930 SUPERV::ReStartedState ) ;
1931 State( SUPERV::DataWaitingState ) ;
1933 cdebug << "InNode::Suspend() Node " << Name() << endl ;
1936 else if ( SendEvent( GraphExecutor::SomeDataReadyEvent ) ) {
1937 cdebug << "InNode::SendEvent( SomeDataReadyEvent ) Node "
1941 cdebug << ThreadNo() << " SuspendedErrored_ReStartAndSuspendAction " << Name()
1946 void GraphExecutor::InNode::InParametersSet(
1949 ServicesAnyData * aListOfInParameters ) {
1951 for ( i = 0 ; i < nInParams ; i++ ) {
1952 ServicesAnyData D = aListOfInParameters[i];
1953 GraphBase::InPort * anInPort = GetChangeNodeInPort(i) ;
1954 GraphBase::OutPort * theOutPort = anInPort->GetOutPort() ;
1955 if ( anInPort->IsGate() && theOutPort == NULL ) {
1956 cdebug << ThreadNo() << " ArgIn" << i << " " << D.Name << " "
1957 << anInPort->GetServicesParameter().Parametertype
1958 << " is inactive. " << anInPort->Kind() << endl ;
1960 // else if ( theOutPort->State() == SUPERV::ReadyState ) {
1961 else if ( anInPort->State() == SUPERV::ReadyState ) {
1962 if ( anInPort->IsGate() ) {
1963 CORBA::Any * anAny = new CORBA::Any() ;
1964 *anAny <<= (long ) 0 ;
1965 theOutPort->Value( anAny ) ;
1967 anInPort->State( SUPERV::WaitingState ) ;
1968 // const CORBA::Any * theValue = theOutPort->Value() ;
1969 D.Name = CORBA::string_dup( anInPort->GetServicesParameter().Parametername ) ;
1970 // D.Value = *theValue ; // CORBA::Any
1971 D.Value = *theOutPort->Value() ; // CORBA::Any
1972 cdebug << ThreadNo() << " ArgIn" << i << " " << anInPort->Kind() ;
1973 cdebug << D.Name << " " << anInPort->GetServicesParameter().Parametertype
1975 string _Type = CORBA::string_dup( anInPort->GetServicesParameter().Parametertype ) ;
1976 const char * Type = _Type.c_str() ;
1977 switch (D.Value.type()->kind()) {
1978 case CORBA::tk_string:
1981 cdebug << t << " (string)" << endl ;
1982 if ( !strcmp( Type , "string" ) ) {
1984 else if ( !strcmp( Type , "double" ) ) {
1986 sscanf( t , "%lf" , &d ) ;
1988 theOutPort->Value( D.Value ) ;
1990 else if ( !strcmp( Type , "long" ) || !strcmp( Type , "bool" ) ) {
1992 sscanf( t , "%ld" , &l ) ;
1994 theOutPort->Value( D.Value ) ;
1996 else if ( !strcmp( Type , "objref" ) ) {
1997 CORBA::Object_ptr ObjRef ;
1998 ObjRef = StringToObject( t ) ;
1999 D.Value <<= ObjRef ;
2000 theOutPort->Value( D.Value ) ;
2005 case CORBA::tk_double:
2008 cdebug << d << " (double)" << endl ;
2009 if ( !strcmp( Type , "string" ) ) {
2011 sprintf( t , "lf" , d ) ;
2013 theOutPort->Value( D.Value ) ;
2015 else if ( !strcmp( Type , "double" ) ) {
2017 else if ( !strcmp( Type , "long" ) || !strcmp( Type , "bool" ) ) {
2021 theOutPort->Value( D.Value ) ;
2023 else if ( !strcmp( Type , "objref" ) ) {
2028 case CORBA::tk_long:
2031 cdebug << l << " (long)" << endl ;
2032 if ( !strcmp( Type , "string" ) ) {
2034 sprintf( t , "lf" , l ) ;
2036 theOutPort->Value( D.Value ) ;
2038 else if ( !strcmp( Type , "double" ) ) {
2042 theOutPort->Value( D.Value ) ;
2044 else if ( !strcmp( Type , "long" ) || !strcmp( Type , "bool" ) ) {
2046 else if ( !strcmp( Type , "objref" ) ) {
2051 case CORBA::tk_objref:
2052 CORBA::Object_ptr obj ;
2056 // retstr = _Orb->object_to_string(obj );
2057 retstr = ObjectToString( obj ) ;
2058 cdebug << retstr << endl ;
2064 cdebug << "ToString( object ) Catched ERROR" << endl ;
2068 cdebug << " (other ERROR)" << endl ;
2072 cdebug << ThreadNo() << " In" << i << " : wrong state ERROR State "
2073 << anInPort->State() << " NameState "
2074 << Automaton()->StateName( anInPort->State() ) << " PortName "
2075 << anInPort->PortName() << " Parametername "
2076 << anInPort->GetServicesParameter().Parametername << endl ;
2079 aListOfInParameters[i] = D ;
2083 void GraphExecutor::InNode::InOutParameters(
2085 ServicesAnyData * aListOfOutParameters ) {
2087 for ( i = 0 ; i < nOutParams ; i++ ) {
2088 ServicesAnyData D = aListOfOutParameters[i] ;
2090 D.Name = GetChangeNodeOutPort(i)->GetServicesParameter().Parametername;
2091 string _Type = CORBA::string_dup(GetChangeNodeOutPort(i)->GetServicesParameter().Parametertype) ;
2092 const char * Type = _Type.c_str() ;
2093 bool OutDone = GetChangeNodeOutPort(i)->Done() ;
2094 cdebug << ThreadNo() << " ArgOut" << i << " " << D.Name << " Done("
2095 << OutDone << ") " << Type << " : " << endl ;
2096 if ( !strcmp( Type , "string" ) ) {
2097 D.Value <<= (char *) NULL ;
2099 else if ( !strcmp( Type , "double" ) ) {
2102 else if ( !strcmp( Type , "long" ) || !strcmp( Type , "bool" ) ) {
2103 D.Value <<= (long ) 0 ;
2106 // D.Value.replace(CORBA::_tc_Object, NULL);
2107 D.Value <<= CORBA::Object::_nil() ;
2109 // GetChangeNodeOutPort(i)->Value( D.Value ) ;
2111 switch (D.Value.type()->kind()) {
2112 case CORBA::tk_string:
2115 cdebug << ThreadNo() << " " << t << "(string)" << endl ;
2117 case CORBA::tk_double:
2120 cdebug << ThreadNo() << " " << d << "(double)" << endl ;
2122 case CORBA::tk_long:
2125 cdebug << ThreadNo() << " " << l << "(long)" << endl ;
2127 case CORBA::tk_objref:
2128 cdebug << ThreadNo() << " " << "(object)" << endl ;
2131 cdebug << ThreadNo() << " " << "(other ERROR)" << endl ;
2134 aListOfOutParameters[i] = D ;
2138 bool GraphExecutor::InNode::OutParameters(
2140 SUPERV::GraphState NewState ,
2142 ServicesAnyData * aListOfOutParameters ) {
2143 bool RetVal = true ;
2145 GraphBase::OutPort * aGateOutPort = NULL ;
2146 bool OrSwitch = false ;
2147 GraphBase::OutPort * anOutPort = GetChangeNodeOutPort(0) ;
2148 for ( i = 0 ; i < nOutParams ; i++ ) {
2149 anOutPort = GetChangeNodeOutPort(i) ;
2151 anOutPort->State( NewState ) ;
2152 anOutPort->Done( true ) ;
2155 cdebug << ThreadNo() << " " << "Out" << i << " " << Name() << " "
2156 << anOutPort->PortName() << " " << anOutPort->Kind() ;
2157 if ( anOutPort->IsGate() ) {
2158 aGateOutPort = anOutPort ;
2159 cdebug << " Gate " ;
2161 aListOfOutParameters[i].Value <<= l;
2162 anOutPort->Value( aListOfOutParameters[i].Value );
2164 else if ( anOutPort->IsLoop() ) {
2165 cdebug << " Loop " ;
2166 anOutPort->Value( aListOfOutParameters[i].Value );
2167 // InLoop Port of EndLoopNode is ready :
2168 anOutPort->ChangeInPorts(0)->State( SUPERV::ReadyState ) ;
2170 else if ( anOutPort->IsSwitch() ) {
2171 cdebug << " Switch " ;
2172 anOutPort->Value( aListOfOutParameters[i].Value );
2173 if ( anOutPort->InPortsSize() && anOutPort->ChangeInPorts( 0 )->IsGate() ) {
2174 if ( OrSwitch && anOutPort->BoolValue() ) {
2175 cdebug << "GraphExecutor::InNodeThreads::OutParameters more than one switch is true WARNING"
2180 OrSwitch = OrSwitch | anOutPort->BoolValue() ;
2183 cdebug << "OrSwitch " << OrSwitch ;
2186 cdebug << " Param " ;
2187 anOutPort->Value( aListOfOutParameters[i].Value );
2189 // else if ( anOutPort->IsBus() ) {
2190 // cdebug << " Bus " ;
2191 // anOutPort->Value( GetNodeInPort( anOutPort->PortIndex() )->GetOutPort()->Value() );
2193 anOutPort->State( NewState ) ;
2194 anOutPort->Done( true ) ;
2196 for ( j = 0 ; j < anOutPort->InPortsSize() ; j++ ) {
2197 bool fromGOTO = false ;
2198 GraphBase::OutPort * aGOTOPort = _OutNode->GetChangeGraphNode( anOutPort->ChangeInPorts( j )->NodeName() )->GetChangeNodeInPort( 0 )->GetOutPort() ;
2200 fromGOTO = aGOTOPort->IsGOTO() ;
2202 if ( anOutPort->ChangeInPorts( j )->IsEndSwitch() || fromGOTO ) {
2203 cdebug << anOutPort->ChangeInPorts( j )->NodeName() << "("
2204 << anOutPort->ChangeInPorts( j )->PortName() << ","
2205 << anOutPort->ChangeInPorts( j )->Kind() << ") WILL BE changed from "
2206 << anOutPort->ChangeInPorts( j )->GetOutPort()->NodeName()
2208 << anOutPort->ChangeInPorts( j )->GetOutPort()->PortName()
2209 << ") to " << anOutPort->NodeName() << "("
2210 << anOutPort->PortName() << ")" << endl ;
2211 anOutPort->ChangeInPorts( j )->ChangeOutPort( anOutPort ) ;
2214 cdebug << anOutPort->ChangeInPorts( j )->NodeName() << "("
2215 << anOutPort->ChangeInPorts( j )->PortName() << ","
2216 << anOutPort->ChangeInPorts( j )->Kind() << ") NOT changed from "
2217 << anOutPort->ChangeInPorts( j )->GetOutPort()->NodeName()
2219 << anOutPort->ChangeInPorts( j )->GetOutPort()->PortName()
2220 << ") to " << anOutPort->NodeName() << "("
2221 << anOutPort->PortName() << ")" << endl ;
2225 switch (anOutPort->Value()->type()->kind()) {
2226 case CORBA::tk_string:
2228 (*anOutPort->Value()) >>= t;
2229 cdebug << ThreadNo() << " Out" << i << " : " << t << "(string)" << endl ;
2231 case CORBA::tk_double:
2233 (*anOutPort->Value()) >>= d;
2234 cdebug << ThreadNo() << " Out" << i << " : " << d << "(double)" << endl ;
2236 case CORBA::tk_long:
2238 (*anOutPort->Value()) >>= l;
2239 cdebug << ThreadNo() << " Out" << i << " : " << l << "(long)" << endl ;
2241 case CORBA::tk_objref:
2242 CORBA::Object_ptr obj ;
2245 (*anOutPort->Value()) >>= obj ;
2246 retstr = _Orb->object_to_string(obj );
2247 cdebug << ThreadNo() << " Out" << i << " : " << "ToString( object ) "
2251 cdebug << ThreadNo() << " Out" << i << " : " << "ToString( object ) "
2252 << "Catched ERROR" << endl ;
2256 cdebug << ThreadNo() << " Out" << i << " : " << "(other ERROR)" << endl ;
2262 if ( aGateOutPort && IsSwitchNode() ) {
2264 cdebug << ThreadNo() << " " << "Out0 " << Name() << " Close of "
2265 << aGateOutPort->PortName() << " " << aGateOutPort->Kind() ;
2267 aListOfOutParameters[0].Value <<= l ;
2268 aGateOutPort->Value( aListOfOutParameters[0].Value ) ;
2271 cdebug << ThreadNo() << " " << "Out0 " << Name() << " Open of "
2272 << aGateOutPort->PortName() << " " << aGateOutPort->Kind() ;
2274 aListOfOutParameters[0].Value <<= l ;
2275 aGateOutPort->Value( aListOfOutParameters[0].Value ) ;
2277 for ( i = 0 ; i < GetNodeOutPortsSize() ; i++ ) {
2278 GraphBase::InPort * anInPort ;
2279 anInPort = CoupledNode()->GetChangeInPort( GetNodeOutPort( i )->PortName() ) ;
2281 anInPort->ChangeOutPort( GetChangeNodeOutPort( i ) ) ;