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( 1 )->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 ;
1005 if ( IsInLineNode() && (*InLineNode()->PythonFunction()).length() &&
1006 strlen( InLineNode()->PyFuncName() ) ) {
1007 cdebug << ThreadNo() << " !ObjInterface " << Name() << " PyFuncName '"
1008 << InLineNode()->PyFuncName()
1009 << "' IsInLineNode PyDynInvoke" << endl ;
1010 StsPyDynInvoke = PyDynInvoke( InLineNode()->PyRunMethod() ,
1011 InLineNode()->PyFuncName() ,
1012 &aListOfInParameters[1] , ServiceInParameter().length() ,
1013 &aListOfOutParameters[1] , ServiceOutParameter().length() ) ;
1015 else if ( IsLoopNode() ) {
1016 if ( GetNodeInPort( 1 )->GetOutPort()->BoolValue() ) { // InLoop Port
1017 cdebug << ThreadNo() << " !ObjInterface " << Name()
1018 << " IsLoopNode PyDynInvoke '" << InLineNode()->PyFuncName()
1020 StsPyDynInvoke = PyDynInvoke( InLineNode()->PyRunMethod() ,
1021 InLineNode()->PyFuncName() ,
1022 &aListOfInParameters[2] , ServiceInParameter().length() ,
1023 &aListOfOutParameters[2] , ServiceOutParameter().length() ) ;
1026 cdebug << ThreadNo() << " !ObjInterface " << Name()
1027 << " IsLoopNode PyDynInvoke '" << LoopNode()->PyNextName()
1029 StsPyDynInvoke = PyDynInvoke( LoopNode()->PyNextMethod() ,
1030 LoopNode()->PyNextName() ,
1031 &aListOfInParameters[2] , ServiceInParameter().length() ,
1032 &aListOfOutParameters[2] , ServiceOutParameter().length() ) ;
1034 if ( StsPyDynInvoke ) {
1035 cdebug << ThreadNo() << " !ObjInterface " << Name()
1036 << " IsLoopNode PyDynInvoke '" << LoopNode()->PyMoreName()
1037 << "' Copy of " << ServiceInParameter().length()
1038 << " OutParameters" << endl ;
1040 for ( i = 0 ; i < ServiceInParameter().length() ; i++ ) {
1041 aListOfInParameters[2 + i].Value = aListOfOutParameters[2+ i].Value ;
1042 aListOfInParameters[2 + i].Name = aListOfOutParameters[2+ i].Name ;
1043 switch ( aListOfInParameters[2 + i].Value.type()->kind() ) {
1044 case CORBA::tk_string :
1045 cdebug << "Arg" << i << " : "
1046 << aListOfInParameters[2 + i].Name.c_str()
1047 << " Value(string) " << endl ;
1049 case CORBA::tk_double :
1050 cdebug << "Arg" << i << " : "
1051 << aListOfInParameters[2 + i].Name.c_str()
1052 << " Value(double) " << endl ;
1054 case CORBA::tk_long :
1055 cdebug << "Arg" << i << " : "
1056 << aListOfInParameters[2 + i].Name.c_str()
1057 << " Value(long) " << endl ;
1059 case CORBA::tk_objref :
1060 cdebug << "Arg" << i << " : "
1061 << aListOfInParameters[2 + i].Name.c_str()
1062 << " Value(object reference) " << endl ;
1065 cdebug << "Arg" << i << " : "
1066 << aListOfInParameters[2 + i].Name.c_str()
1067 << " Value(other) ERROR" << endl ;
1070 StsPyDynInvoke = PyDynInvoke( LoopNode()->PyMoreMethod() ,
1071 LoopNode()->PyMoreName() ,
1072 &aListOfInParameters[2] , ServiceInParameter().length() ,
1073 &aListOfOutParameters[1] , ServiceOutParameter().length()+1 ) ;
1077 cdebug << ThreadNo() << " InLineNode " << Name() << " "
1078 << InLineNode()->PyFuncName() << "/" << LoopNode()->PyNextName()
1079 << " Python Dynamic Call Error"
1083 else if ( IsSwitchNode() ) {
1084 cdebug << ThreadNo() << " !ObjInterface " << Name() << " PyFuncName '"
1085 << InLineNode()->PyFuncName()
1086 << "' IsSwitchNode PyDynInvoke" << endl ;
1087 StsPyDynInvoke = PyDynInvoke( InLineNode()->PyRunMethod() ,
1088 InLineNode()->PyFuncName() ,
1089 &aListOfInParameters[1] , ServiceInParameter().length() ,
1090 &aListOfOutParameters[1] , ServiceOutParameter().length() ) ;
1092 else if ( IsGOTONode() && (*GOTONode()->PythonFunction()).length() &&
1093 strlen( InLineNode()->PyFuncName() ) ) {
1094 cdebug << ThreadNo() << " !ObjInterface " << Name() << " PyFuncName '"
1095 << InLineNode()->PyFuncName()
1096 << "' IsGOTONode PyDynInvoke" << endl ;
1097 StsPyDynInvoke = PyDynInvoke( InLineNode()->PyRunMethod() ,
1098 InLineNode()->PyFuncName() ,
1099 &aListOfInParameters[1] , ServiceInParameter().length() ,
1100 &aListOfOutParameters[1] , ServiceOutParameter().length() ) ;
1102 else if ( IsEndSwitchNode() && (*InLineNode()->PythonFunction()).length() &&
1103 strlen( InLineNode()->PyFuncName() ) ) {
1104 cdebug << ThreadNo() << " !ObjInterface " << Name() << " PyFuncName '"
1105 << InLineNode()->PyFuncName()
1106 << "' IsSwitchNode PyDynInvoke" << endl ;
1107 StsPyDynInvoke = PyDynInvoke( InLineNode()->PyRunMethod() ,
1108 InLineNode()->PyFuncName() ,
1109 &aListOfInParameters[1] , ServiceInParameter().length() ,
1110 &aListOfOutParameters[1] , ServiceOutParameter().length() ) ;
1112 else if ( (*InLineNode()->PythonFunction()).length() == 0 ||
1113 strlen( InLineNode()->PyFuncName() ) == 0 ) {
1114 cdebug << ThreadNo() << " !ObjInterface " << Name()
1115 << " Copy of " << ServiceInParameter().length()
1116 << " OutParameters" << endl ;
1119 if ( IsEndLoopNode() ) {
1122 for ( i = 0 ; i < ServiceInParameter().length() ; i++ ) {
1123 aListOfOutParameters[argind0 + i].Value = aListOfInParameters[argind0 + i].Value ;
1124 // aListOfOutParameters[argind0 + i].Name = aListOfInParameters[argind0 + i].Name ;
1125 switch ( aListOfInParameters[argind0 + i].Value.type()->kind() ) {
1126 case CORBA::tk_string :
1127 cdebug << "Arg" << i << " : "
1128 << aListOfInParameters[argind0 + i].Name.c_str()
1129 << " Value(string) "
1130 << aListOfOutParameters[argind0 + i].Name.c_str() << endl ;
1132 case CORBA::tk_double :
1133 cdebug << "Arg" << i << " : "
1134 << aListOfInParameters[argind0 + i].Name.c_str()
1135 << " Value(double) "
1136 << aListOfOutParameters[argind0 + i].Name.c_str() << endl ;
1138 case CORBA::tk_long :
1139 cdebug << "Arg" << i << " : "
1140 << aListOfInParameters[argind0 + i].Name.c_str()
1142 << aListOfOutParameters[argind0 + i].Name.c_str() << endl ;
1144 case CORBA::tk_objref :
1145 cdebug << "Arg" << i << " : "
1146 << aListOfInParameters[argind0 + i].Name.c_str()
1147 << " Value(object reference) "
1148 << aListOfOutParameters[argind0 + i].Name.c_str() << endl ;
1151 cdebug << "Arg" << i << " : "
1152 << aListOfInParameters[argind0 + i].Name.c_str()
1153 << " Value(other) ERROR "
1154 << aListOfOutParameters[argind0 + i].Name.c_str() << endl ;
1158 if ( !StsPyDynInvoke ) {
1160 cdebug << ThreadNo() << " InLineNode " << Name()
1161 << " Python Dynamic Call Error"
1167 cdebug << ThreadNo() << " InLineNode " << Name()
1168 << " Python Dynamic Call Exception catched ERROR"
1172 // else if ( !ObjInterface() ) {
1173 else if ( IsFactoryNode() ) {
1176 DynInvoke( myObjComponent, "Names" ,
1177 _OutNode->Name() , Name() ) ;
1180 cdebug << "DynInvoke Names catched ERROR" << endl ;
1182 cdebug << ServiceInParameter().length() << " input parameters and "
1183 << ServiceOutParameter().length() << " output parameters" << endl ;
1184 if ( IsComputingNode() ) {
1185 cdebug << ThreadNo() << " !ObjInterface " << Name()
1186 << " IsComputingNode DynInvoke" << endl ;
1187 DynInvoke( myObjComponent,
1189 &aListOfInParameters[1] , ServiceInParameter().length() ,
1190 &aListOfOutParameters[1] , ServiceOutParameter().length() ) ;
1192 else if ( IsFactoryNode() ) {
1193 cdebug << ThreadNo() << " !ObjInterface " << Name()
1194 << " IsFactoryNode DynInvoke" << endl ;
1195 DynInvoke( myObjComponent,
1197 &aListOfInParameters[1] , ServiceInParameter().length() ,
1198 &aListOfOutParameters[1] , ServiceOutParameter().length() ) ;
1203 cdebug << ThreadNo() << " !ObjInterface " << Name()
1204 << " Node(Component) Dynamic Call Exception catched ERROR"
1211 DynInvoke( myObjComponent, "Names" ,
1212 _OutNode->Name() , Name() ) ;
1216 cdebug << ThreadNo() << " ObjInterface " << Name() << " DynInvoke"
1218 DynInvoke( myObjComponent ,
1220 &aListOfInParameters[2] , ServiceInParameter().length()-1 ,
1221 &aListOfOutParameters[1] , ServiceOutParameter().length() ) ;
1225 cdebug << ThreadNo() << " ObjInterface " << Name()
1226 << " Node(Interface) Dynamic Call Exception catched ERROR"
1238 if ( ControlState() == SUPERV::ToKillState ||
1239 ControlState() == SUPERV::ToKillDoneState ||
1240 ControlState() == SUPERV::ToStopState ) {
1241 PortState = SUPERV::ErrorState ;
1242 NewState = SUPERV::KilledState ;
1243 NewEvent = GraphExecutor::KillEvent ;
1246 PortState = SUPERV::ErrorState ;
1247 NewState = SUPERV::ErroredState ;
1248 NewEvent = GraphExecutor::ErrorEvent ;
1252 PortState = SUPERV::ReadyState ;
1253 NewState = SUPERV::DataReadyState ;
1254 NewEvent = GraphExecutor::SuccessEvent ;
1257 bool ErrOut = OutParameters( Err , PortState , nOutParams , aListOfOutParameters ) ;
1259 NewEvent = GraphExecutor::ErrorEvent ;
1261 delete [] aListOfInParameters ;
1262 delete [] aListOfOutParameters ;
1264 SendEvent( NewEvent );
1266 cdebug << ThreadNo() << " <-- DataReady_ExecuteAction " << Name() << endl;
1270 int GraphExecutor::InNode::Executing_SuspendAction() {
1271 _OutNode->PushEvent( this , GraphExecutor::SuspendedExecutingEvent ,
1272 SUPERV::SuspendedExecutingState ) ;
1273 cdebug << ThreadNo() << " Executing_SuspendAction " << Name() << endl;
1277 int GraphExecutor::InNode::SuspendedExecuting_ResumeAction() {
1278 cdebug << ThreadNo() << " SuspendedExecuting_ResumeAction " << Name() << endl;
1279 SUPERV::AutomatonState next_state ;
1280 next_state = Automaton()->NextState( State() , GraphExecutor::ExecutingEvent ) ;
1281 _OutNode->NewThread() ; // Only for Threads count
1282 _OutNode->PushEvent( this , GraphExecutor::ResumedExecutingEvent ,
1284 State( next_state ) ;
1288 int GraphExecutor::InNode::Executing_KillAction() {
1289 cdebug << ThreadNo() << " Executing_KillAction " << Name() << endl;
1291 if ( pthread_self() == ThreadNo() ) {
1292 cdebug << "Executing_KillAction would pthread_canceled itself" << endl ;
1294 _OutNode->PushEvent( this , GraphExecutor::KilledExecutingEvent ,
1295 SUPERV::KilledExecutingState ) ;
1298 else if ( pthread_cancel( ThreadNo() ) ) {
1299 perror("Executing_KillAction pthread_cancel error") ;
1302 cdebug << "Executing_KillAction : ThreadId " << ThreadNo()
1303 << " pthread_canceled" << endl ;
1305 _OutNode->ExitThread() ;
1306 _OutNode->PushEvent( this , GraphExecutor::KilledExecutingEvent ,
1307 SUPERV::KilledExecutingState ) ;
1312 int GraphExecutor::InNode::Executing_StopAction() {
1313 cdebug << ThreadNo() << " Executing_StopAction " << Name() << endl;
1315 if ( pthread_cancel( ThreadNo() ) ) {
1316 perror("Executing_KillAction pthread_cancel error") ;
1319 cdebug << "Executing_KillAction : ThreadId " << ThreadNo()
1320 << " pthread_canceled" << endl ;
1322 _OutNode->ExitThread() ;
1323 _OutNode->PushEvent( this , GraphExecutor::StoppedExecutingEvent ,
1324 SUPERV::StoppedExecutingState ) ;
1329 int GraphExecutor::InNode::Executing_SuccessAction() {
1330 cdebug << ThreadNo() << " --> Executing_SuccessAction " << Name() << endl;
1331 _OutNode->PushEvent( this , GraphExecutor::SuccessedExecutingEvent ,
1332 SUPERV::SuccessedState ) ;
1334 SUPERV::ControlState aControl = ControlState() ;
1335 switch ( aControl ) {
1336 case SUPERV::VoidState : {
1337 SendEvent( SuccessEvent ) ;
1340 case SUPERV::ToSuspendState : {
1341 SendEvent( SuccessEvent ) ;
1344 case SUPERV::ToSuspendDoneState : {
1345 SendEvent( GraphExecutor::SuspendEvent ) ;
1348 case SUPERV::ToKillState : {
1349 SendEvent( GraphExecutor::KillEvent ) ;
1352 case SUPERV::ToKillDoneState : {
1353 SendEvent( GraphExecutor::KillEvent ) ;
1356 case SUPERV::ToStopState : {
1357 SendEvent( GraphExecutor::StopEvent ) ;
1361 cdebug << ThreadNo()
1362 << " GraphExecutor::InNodeThreads::Executing_SuccessAction Error Undefined Control : "
1363 << aControl << endl ;
1367 cdebug << ThreadNo() << " <-- Executing_SuccessAction " << Name() << endl;
1371 int GraphExecutor::InNode::Executing_ErrorAction() {
1372 cdebug << ThreadNo() << " --> Executing_ErrorAction " << Name() << endl;
1373 _OutNode->PushEvent( this , GraphExecutor::ErroredExecutingEvent ,
1374 SUPERV::ErroredState ) ;
1377 SUPERV::ControlState aControl = ControlState() ;
1378 switch ( aControl ) {
1379 case SUPERV::VoidState : {
1380 SendEvent( ErrorEvent ) ;
1383 case SUPERV::ToSuspendState : {
1384 SendEvent( ErrorEvent ) ;
1387 case SUPERV::ToSuspendDoneState : {
1388 SendEvent( GraphExecutor::SuspendEvent ) ;
1391 case SUPERV::ToKillState : {
1392 SendEvent( GraphExecutor::KillEvent ) ;
1395 case SUPERV::ToKillDoneState : {
1396 SendEvent( GraphExecutor::KillEvent ) ;
1399 case SUPERV::ToStopState : {
1400 SendEvent( GraphExecutor::StopEvent ) ;
1404 cdebug << ThreadNo()
1405 << " GraphExecutor::InNodeThreads::Executing_ErrorAction Error Undefined Control : "
1406 << aControl << endl ;
1410 cdebug << ThreadNo() << " <-- Executing_ErrorAction " << Name() << endl;
1414 // Set SUPERV::WaitingState to all InPorts
1415 void GraphExecutor::InNode::SetWaitingStates(GraphExecutor::InNode * EndNode ) {
1418 bool docdebug = false ;
1419 State( SUPERV::DataWaitingState ) ;
1420 for ( i = 0 ; i < GetNodeInPortsSize() ; i++ ) {
1421 GraphBase::InPort * anInPort = GetChangeNodeInPort( i ) ;
1422 if ( anInPort->IsGate() ) { // Loop : Open the doors
1423 GraphBase::OutPort * anOutPort = anInPort->GetOutPort() ;
1425 CORBA::Any * anAny = new CORBA::Any() ;
1426 *anAny <<= (long ) 1 ;
1427 anOutPort->Value( anAny ) ;
1428 anInPort->State( SUPERV::ReadyState ) ;
1431 else if ( anInPort->State() != SUPERV::WaitingState ) {
1433 cdebug << ThreadNo()
1434 << " --> GraphExecutor::InNodeThreads::SetWaitingStates "
1438 anInPort->State( SUPERV::WaitingState ) ;
1441 for ( i = 0 ; i < GetNodeOutPortsSize() ; i++ ) {
1442 if ( !( IsGOTONode() && i == 0 ) && !( IsEndLoopNode() && i <= 1 ) ) {
1443 for ( j = 0 ; j < GetChangeNodeOutPort( i )->InPortsSize() ; j++ ) {
1444 GraphExecutor::InNode * aNode = (GraphExecutor::InNode * ) _OutNode->GetChangeGraphNode( GetChangeNodeOutPort( i )->ChangeInPorts( j )->NodeName() )->GetInNode() ;
1445 if ( aNode != EndNode ) {
1446 aNode->SetWaitingStates( EndNode ) ;
1453 int GraphExecutor::InNode::Successed_SuccessAction() {
1454 cdebug << ThreadNo() << " --> Successed_SuccessAction " << Name() << endl;
1456 int linkednodesnumber = LinkedNodesSize() ;
1457 GraphExecutor::InNode *firstzeroNode = NULL ;
1458 GraphExecutor::InNode *firsttoNode = NULL ;
1459 GraphExecutor::InNode *toNode ;
1462 list<GraphExecutor::InNode *> SomeDataNodes ;
1466 if ( IsGOTONode() ||
1467 ( IsEndLoopNode() && GetNodeInPort(1)->GetOutPort()->BoolValue() ) ) {
1469 if ( IsGOTONode() ) {
1474 CORBA::Any * anAny = new CORBA::Any() ;
1475 *anAny <<= (long ) 0 ;
1476 GetChangeNodeOutPort(1)->Value( anAny ) ; // Loop(InLoop) = false
1478 const GraphBase::OutPort * GateOutPort = GetNodeOutPort(index) ;
1479 for ( i = 0 ; i < GateOutPort->InPortsSize() ; i++ ) {
1480 const GraphBase::InPort * anInPort = GateOutPort->InPorts( i ) ;
1481 GraphExecutor::InNode * aLabelNode = (GraphExecutor::InNode *) _OutNode->GetChangeGraphNode( anInPort->NodeName() )->GetInNode() ;
1482 aLabelNode->SetWaitingStates( this ) ;
1483 for ( j = 1 ; j < GetNodeOutPortsSize() ; j++ ) {
1484 GraphBase::OutPort * aBusParamOutPort = GetChangeNodeOutPort( j ) ;
1485 GraphBase::InPort * aBusParamChangeInPort = NULL ;
1486 if ( aBusParamOutPort->IsLoop() ) {
1487 aBusParamChangeInPort = aLabelNode->GetChangeInPort( "InitLoop" ) ;
1490 aBusParamChangeInPort = aLabelNode->GetChangeInPort( aBusParamOutPort->PortName() ) ;
1492 // const GraphBase::InPort * aBusParamInPort = aBusParamChangeInPort ;
1493 // if ( aBusParamInPort ) {
1494 // GraphBase::OutPort * anOutPort = aBusParamInPort->GetOutPort() ;
1495 // anOutPort->Value( aBusParamOutPort->Value() ) ;
1496 // GraphExecutor::InNode * aFromLabelNode = (GraphExecutor::InNode *) _OutNode->GetChangeGraphNode( anOutPort->NodeName() )->GetInNode() ;
1497 // if ( aFromLabelNode && !aLabelNode->IsLockedDataWait() ) {
1498 // res = aLabelNode->SendSomeDataReady( aFromLabelNode->Name() , EndTest ) ;
1499 if ( aBusParamChangeInPort ) {
1500 aBusParamChangeInPort->ChangeOutPort( aBusParamOutPort ) ;
1501 if ( !aLabelNode->IsLockedDataWait() ) {
1502 res = aLabelNode->SendSomeDataReady( Name() ) ;
1504 if ( firsttoNode == NULL &&
1505 aLabelNode->ThreadNo() == pthread_self() ) {
1506 firsttoNode = aLabelNode ;
1507 cdebug << ThreadNo() << " Successed_SuccessAction firsttoNode "
1508 << aLabelNode->Name() << endl ;
1510 else if ( firstzeroNode == NULL &&
1511 aLabelNode->ThreadNo() == 0 ) {
1512 firstzeroNode = aLabelNode ;
1515 SomeDataNodes.push_back( aLabelNode ) ;
1516 cdebug << ThreadNo() << " Successed_SuccessAction push "
1517 << SomeDataNodes.size() << " " << aLabelNode->Name()
1523 cdebug << ThreadNo()
1524 << " Successed_SuccessAction Loop to HeadNode "
1525 << aLabelNode->Name() << " with datas from "
1526 << aBusParamOutPort->PortName() << " to port "
1527 << aBusParamChangeInPort->PortName() << endl;
1528 // aBusParamChangeInPort->State( SUPERV::ReadyState ) ;
1532 cdebug << ThreadNo() << " ERROR in Successed_SuccessAction of " << Name()
1533 << " NO port " << aBusParamOutPort->PortName() << " in "
1534 << aLabelNode->Name() << endl;
1537 const GraphBase::OutPort * aGateOutPort = GetNodeOutPort( index ) ;
1538 const GraphBase::InPort * aGateInPort = aLabelNode->GetNodeInPort( index ) ;
1539 if ( aGateInPort ) {
1540 aGateInPort->GetOutPort()->Value( aGateOutPort->Value() ) ;
1541 if ( !aLabelNode->IsLockedDataWait() ) {
1542 res = aLabelNode->SendSomeDataReady( Name() ) ;
1544 if ( firsttoNode == NULL &&
1545 aLabelNode->ThreadNo() == pthread_self() ) {
1546 firsttoNode = aLabelNode ;
1547 cdebug << ThreadNo() << " Successed_SuccessAction firsttoNode "
1548 << aLabelNode->Name() << endl ;
1550 else if ( firstzeroNode == NULL &&
1551 aLabelNode->ThreadNo() == 0 ) {
1552 firstzeroNode = aLabelNode ;
1555 SomeDataNodes.push_back( aLabelNode ) ;
1556 cdebug << ThreadNo() << " Successed_SuccessAction push "
1557 << SomeDataNodes.size() << " " << aLabelNode->Name()
1564 cdebug << ThreadNo() << " ERROR in Successed_SuccessAction of " << Name()
1565 << " NO port " << aGateOutPort->PortName() << " in "
1566 << aLabelNode->Name() << endl;
1572 cdebug << ThreadNo() << " Successed_SuccessAction of " << Name()
1573 << " with " << LinkedNodesSize() << " linked nodes :" ;
1574 for ( i = 0 ; i < LinkedNodesSize() ; i++ ) {
1575 if ( LinkedNodes( i )->IsDataFlowNode() ) {
1576 linkednodesnumber -= 1 ;
1578 cdebug << " " << LinkedNodes( i )->Name() ;
1581 SUPERV::ControlState aControl = ControlState() ;
1582 for ( i = 0 ; i < LinkedNodesSize() ; i++ ) {
1583 bool IgnoreForEndLoop = false ;
1584 toNode = (GraphExecutor::InNode *) LinkedNodes( i )->GetInNode() ;
1585 cdebug << ThreadNo() << " Successed_SuccessAction of " << Name()
1586 << " [" << i << "] " << LinkedNodes( i )->Name() << endl ;
1587 if ( toNode && !toNode->IsDataFlowNode() ) {
1588 GraphBase::InPort * toGateInPort = toNode->GetChangeNodeInPort(0) ;
1589 if ( IsComputingNode() && toNode->IsInLineNode() ) {
1590 toGateInPort->State( SUPERV::ReadyState ) ;
1591 GraphBase::OutPort * GateOutPort = toGateInPort->GetOutPort() ;
1592 if ( GateOutPort ) {
1593 GateOutPort->PortStatus( DataConnected );
1594 GateOutPort->State( SUPERV::ReadyState ) ;
1595 GateOutPort->Done( true ) ;
1599 if ( toNode && IsLoopNode() ) {
1600 GraphBase::OutPort * fromLoopOutPort = GetChangeNodeOutPort(1) ;
1601 if ( !fromLoopOutPort->BoolValue() ) {
1602 if ( strcmp( toNode->Name() , CoupledNode()->Name() ) ) {
1603 IgnoreForEndLoop = true ; // toNode is the EndLoopNode
1606 GraphBase::InPort * toLoopInPort ;
1607 toLoopInPort = toNode->GetChangeNodeInPort(1) ;
1608 if ( toLoopInPort->State() != SUPERV::ReadyState ) {
1609 toLoopInPort->State( SUPERV::ReadyState ) ;
1614 else if ( toNode && IsSwitchNode() ) {
1616 else if ( toNode && toNode->IsInLineNode() ) {
1618 for ( j = 0 ; j < toNode->GetNodeInPortsSize() ; j++ ) {
1619 toNode->GetChangeNodeInPort( j )->InitialOutPort() ;
1622 if ( toNode && !IgnoreForEndLoop ) {
1623 if ( toNode && toNode->IsLoopNode() ) {
1624 GraphBase::InPort * toLoopInPort = toNode->GetChangeNodeInPort(1) ;
1625 toLoopInPort->State( SUPERV::ReadyState ) ;
1626 GraphBase::OutPort * LoopOutPort = toLoopInPort->GetOutPort() ;
1627 LoopOutPort->PortStatus( DataConnected );
1628 LoopOutPort->State( SUPERV::ReadyState ) ;
1629 LoopOutPort->Done( true ) ;
1630 CORBA::Any * anAny = new CORBA::Any() ;
1631 *anAny <<= (long ) 1 ;
1632 LoopOutPort->Value( anAny ) ;
1634 for ( j = 0 ; j < toNode->GetNodeInPortsSize() ; j++ ) {
1635 toNode->GetChangeNodeInPort( j )->InitialOutPort() ;
1638 res = toNode->SendSomeDataReady( Name() ) ;
1640 if ( firsttoNode == NULL &&
1641 toNode->ThreadNo() == pthread_self() ) {
1642 firsttoNode = toNode ;
1643 cdebug << ThreadNo() << " Successed_SuccessAction firsttoNode "
1644 << toNode->Name() << endl ;
1646 else if ( firstzeroNode == NULL &&
1647 toNode->ThreadNo() == 0 ) {
1648 firstzeroNode = toNode ;
1651 SomeDataNodes.push_back( toNode ) ;
1652 cdebug << ThreadNo() << " Successed_SuccessAction push "
1653 << SomeDataNodes.size() << " " << toNode->Name() << endl ;
1660 if ( firsttoNode == NULL && firstzeroNode ) {
1661 firsttoNode = firstzeroNode ;
1662 cdebug << ThreadNo()
1663 << " Successed_SuccessAction firsttoNode = firstzeroNode "
1666 else if ( firsttoNode && firstzeroNode ) {
1667 SomeDataNodes.push_back( firstzeroNode ) ;
1668 cdebug << ThreadNo() << " Successed_SuccessAction push firstzeroNode "
1669 << SomeDataNodes.size() << " " << firstzeroNode->Name() << endl ;
1672 while ( SomeDataNodes.size() ) {
1673 GraphExecutor::InNode *aNode = SomeDataNodes.front() ;
1674 SomeDataNodes.pop_front() ;
1675 cdebug << pthread_self() << "/" << ThreadNo()
1676 << " Successed_SuccessAction pop "
1677 << SomeDataNodes.size() << " " << aNode->Name() << endl ;
1678 if ( aNode->State() == SUPERV::DataReadyState ) {
1679 aNode->CreateNewThreadIf( true ) ;
1680 aNode->UnLockDataWait() ;
1681 res = aNode->DataUndef_AllDataReadyAction() ;
1684 cdebug << pthread_self() << "/" << ThreadNo() << " ERROR "
1685 << aNode->Name() << " "
1686 << Automaton()->StateName( aNode->State() ) << endl ;
1690 if ( firsttoNode ) {
1691 // firsttoNode = SomeDataNodes.front() ;
1692 // SomeDataNodes.pop_front() ;
1693 cdebug << pthread_self() << "/" << ThreadNo()
1694 << " Successed_SuccessAction pop firsttoNode "
1695 << SomeDataNodes.size() << " " << firsttoNode->Name() << endl ;
1696 firsttoNode->CreateNewThreadIf( false ) ;
1697 if ( firsttoNode->State() == SUPERV::SuccessedState ) {
1698 cdebug << pthread_self() << "/" << ThreadNo() << " " << Name()
1699 << " : " << firsttoNode->Name() << " "
1700 << Automaton()->StateName( firsttoNode->State() )
1701 << " --> DataWaitingState for Thread "
1702 << firsttoNode->ThreadNo() << endl ;
1703 firsttoNode->State( SUPERV::DataWaitingState ) ;
1705 pthread_t OldT = firsttoNode->ThreadNo() ;
1706 firsttoNode->ThreadNo( pthread_self() ) ;
1707 // On continue avec le meme thread
1708 cdebug << pthread_self() << "/" << ThreadNo() << " firsttoNode "
1709 << firsttoNode->Name() << "Thread(" << OldT << "-->"
1710 << firsttoNode->ThreadNo() << ")" << endl ;
1712 cdebug << ThreadNo() << " Successed_SuccessAction " << Name()
1713 << " for " << firsttoNode->Name()
1714 << " !firsttoNode->CreateNewThreadIf() "
1715 << !firsttoNode->CreateNewThreadIf()
1716 << " " << Automaton()->StateName( firsttoNode->State() ) ;
1717 if ( firsttoNode->State() == SUPERV::DataReadyState ) {
1719 firsttoNode->UnLockDataWait() ;
1720 res = firsttoNode->DataUndef_AllDataReadyAction() ;
1723 cdebug << " ERROR " << endl ;
1727 cdebug << ThreadNo() << " Successed_SuccessAction " << Name()
1728 << " NO DataReady ==> ThreadNo( 0 )" << endl ;
1732 if ( linkednodesnumber == 0 ) {
1733 _OutNode->CheckAllDone() ;
1736 cdebug << pthread_self() << "/" << ThreadNo()
1737 << " <-- Successed_SuccessAction " << Name() << " linkednodesnumber "
1738 << linkednodesnumber << endl;
1742 bool GraphExecutor::InNode::SendSomeDataReady( char * FromNodeName ) {
1743 bool RetVal = false ;
1744 if ( IsDataFlowNode() ) {
1745 cdebug << ThreadNo() << " ----> " << Name()
1746 << " send Result to graph " << Name() << endl;
1749 cdebug << pthread_self() << "/" << ThreadNo() << " ----> " << FromNodeName
1750 << " send SomeDataReady to " << Name() << " "
1751 << Automaton()->StateName( State() )
1752 << " CreateNewThreadIf() " << CreateNewThreadIf()
1753 << " LockedDataWait " << IsLockedDataWait() << endl;
1755 cout << pthread_self() << "/" << ThreadNo() << " ----> " << FromNodeName
1756 << " send SomeDataReady to " << Name() << " "
1757 << Automaton()->StateName( State() )
1758 << " CreateNewThreadIf() " << CreateNewThreadIf()
1759 << " LockedDataWait " << IsLockedDataWait() << endl;
1761 if ( State() == SUPERV::SuccessedState ||
1762 State() == SUPERV::SuspendedSuccessedState ||
1763 State() == SUPERV::SuspendedSuccessedToReStartState ) {
1764 cdebug << ThreadNo() << " " << FromNodeName
1765 << " : " << Name() << " " << Automaton()->StateName( State() )
1766 << " --> DataWaitingState for Thread "
1767 << ThreadNo() << " " << endl ;
1768 State( SUPERV::DataWaitingState ) ;
1771 DataFromNode( FromNodeName ) ;
1772 RetVal = !SendEvent( GraphExecutor::SomeDataReadyEvent );
1780 int GraphExecutor::InNode::Errored_ErrorAction() {
1781 cdebug << ThreadNo() << " Errored_ErrorAction " << Name()
1782 << " will pthread_exit" << endl;
1787 int GraphExecutor::InNode::Successed_SuspendAction() {
1788 cdebug << ThreadNo() << " Successed_SuspendAction -->Suspend " << Name()
1789 << " Threads " << _OutNode->Threads() << " SuspendedThreads "
1790 << _OutNode->SuspendedThreads() << endl;
1791 _OutNode->PushEvent( this , GraphExecutor::SuspendedSuccessedEvent ,
1792 SUPERV::SuspendedSuccessedState ) ;
1794 GraphExecutor::InNode * aReStartNode = SuspendAction() ;
1795 cdebug << ThreadNo() << " Successed_SuspendAction Resumed " << Name() ;
1796 if ( aReStartNode ) {
1797 _aReStartNode = NULL ;
1798 cdebug << " for " << aReStartNode->Name() << endl;
1799 aReStartNode->SendEvent( _aReStartEvent ) ;
1803 SendEvent( GraphExecutor::ResumeEvent ) ;
1808 int GraphExecutor::InNode::Errored_SuspendAction() {
1809 cdebug << ThreadNo() << " Errored_SuspendAction -->Suspend " << Name()
1810 << " Threads " << _OutNode->Threads() << " SuspendedThreads "
1811 << _OutNode->SuspendedThreads() << endl;
1812 _OutNode->PushEvent( this , GraphExecutor::SuspendedErroredEvent ,
1813 SUPERV::SuspendedErroredState ) ;
1815 GraphExecutor::InNode * aReStartNode = SuspendAction() ;
1816 cdebug << ThreadNo() << " Errored_SuspendAction Resumed " << Name()
1818 if ( aReStartNode ) {
1819 _aReStartNode = NULL ;
1820 aReStartNode->SendEvent( _aReStartEvent ) ;
1823 SendEvent( GraphExecutor::ResumeEvent ) ;
1828 int GraphExecutor::InNode::SuspendedSuccessed_ResumeAction() {
1829 cdebug << ThreadNo() << " SuspendedSuccessed_ResumeAction " << Name() << endl;
1831 _OutNode->PushEvent( this , GraphExecutor::ResumedSuccessedEvent ,
1832 SUPERV::ResumedSuccessedState ) ;
1833 SendEvent( ResumedSuccessedEvent ) ;
1837 int GraphExecutor::InNode::SuspendedErrored_ResumeAction() {
1838 cdebug << ThreadNo() << " SuspendedErrored_ResumeAction " << Name() << endl;
1840 _OutNode->PushEvent( this , GraphExecutor::ResumedErroredEvent ,
1841 SUPERV::ResumedErroredState ) ;
1842 SendEvent( ResumedErroredEvent ) ;
1846 int GraphExecutor::InNode::Successed_KillAction() {
1848 _OutNode->PushEvent( this , GraphExecutor::KilledEvent ,
1849 SUPERV::KilledSuccessedState ) ;
1850 cdebug << ThreadNo() << " Successed_KillAction " << Name() << endl;
1854 int GraphExecutor::InNode::Errored_KillAction() {
1856 _OutNode->PushEvent( this , GraphExecutor::KilledEvent ,
1857 SUPERV::KilledErroredState ) ;
1858 cdebug << ThreadNo() << " Errored_KillAction " << Name() << endl;
1862 int GraphExecutor::InNode::Successed_StopAction() {
1864 _OutNode->PushEvent( this , GraphExecutor::StoppedEvent ,
1865 SUPERV::StoppedSuccessedState ) ;
1866 cdebug << ThreadNo() << " Successed_StopAction " << Name() << endl;
1870 int GraphExecutor::InNode::Errored_StopAction() {
1872 _OutNode->PushEvent( this , GraphExecutor::StoppedEvent ,
1873 SUPERV::StoppedErroredState ) ;
1874 cdebug << ThreadNo() << " Errored_StopAction " << Name() << endl;
1878 int GraphExecutor::InNode::SuspendedSuccessed_ReStartAction() {
1879 cdebug << ThreadNo() << " SuspendedSuccessed_ReStartAction " << Name() << endl;
1880 _OutNode->PushEvent( this , GraphExecutor::ReStartedEvent ,
1881 SUPERV::ReStartedState ) ;
1883 for ( i = 0 ; i < GetNodeInPortsSize() ; i++ ) {
1884 GetChangeNodeInPort( i )->State( SUPERV::ReadyState ) ;
1886 SendEvent( ExecuteEvent ) ;
1887 cdebug << ThreadNo() << " SuspendedSuccessed_ReStartAction " << Name() << endl;
1891 int GraphExecutor::InNode::SuspendedErrored_ReStartAction() {
1892 cdebug << ThreadNo() << " SuspendedErrored_ReStartAction " << Name() << endl;
1893 _OutNode->PushEvent( this , GraphExecutor::ReStartedEvent ,
1894 SUPERV::ReStartedState ) ;
1896 for ( i = 0 ; i < GetNodeInPortsSize() ; i++ ) {
1897 GetChangeNodeInPort( i )->State( SUPERV::ReadyState ) ;
1899 SendEvent( ExecuteEvent ) ;
1900 cdebug << ThreadNo() << " SuspendedErrored_ReStartAction " << Name() << endl;
1904 int GraphExecutor::InNode::SuspendedSuccessed_ReStartAndSuspendAction() {
1905 cdebug << ThreadNo() << " SuspendedSuccessed_ReStartAndSuspendAction " << Name()
1907 _OutNode->PushEvent( this , GraphExecutor::ReStartedAndSuspendEvent ,
1908 SUPERV::ReStartedState ) ;
1909 State( SUPERV::DataWaitingState ) ;
1911 cdebug << "InNode::Suspend() Node " << Name() << endl ;
1914 else if ( SendEvent( GraphExecutor::SomeDataReadyEvent ) ) {
1915 cdebug << "InNode::SendEvent( SomeDataReadyEvent ) Node "
1919 cdebug << ThreadNo() << " SuspendedSuccessed_ReStartAndSuspendAction " << Name()
1924 int GraphExecutor::InNode::SuspendedErrored_ReStartAndSuspendAction() {
1925 cdebug << ThreadNo() << " SuspendedErrored_ReStartAndSuspendAction " << Name()
1927 _OutNode->PushEvent( this , GraphExecutor::ReStartedAndSuspendEvent ,
1928 SUPERV::ReStartedState ) ;
1929 State( SUPERV::DataWaitingState ) ;
1931 cdebug << "InNode::Suspend() Node " << Name() << endl ;
1934 else if ( SendEvent( GraphExecutor::SomeDataReadyEvent ) ) {
1935 cdebug << "InNode::SendEvent( SomeDataReadyEvent ) Node "
1939 cdebug << ThreadNo() << " SuspendedErrored_ReStartAndSuspendAction " << Name()
1944 void GraphExecutor::InNode::InParametersSet(
1947 ServicesAnyData * aListOfInParameters ) {
1949 for ( i = 0 ; i < nInParams ; i++ ) {
1950 ServicesAnyData D = aListOfInParameters[i];
1951 GraphBase::InPort * anInPort = GetChangeNodeInPort(i) ;
1952 GraphBase::OutPort * theOutPort = anInPort->GetOutPort() ;
1953 if ( anInPort->IsGate() && theOutPort == NULL ) {
1954 cdebug << ThreadNo() << " ArgIn" << i << " " << D.Name << " "
1955 << anInPort->GetServicesParameter().Parametertype
1956 << " is inactive. " << anInPort->Kind() << endl ;
1958 // else if ( theOutPort->State() == SUPERV::ReadyState ) {
1959 else if ( anInPort->State() == SUPERV::ReadyState ) {
1960 if ( anInPort->IsGate() ) {
1961 CORBA::Any * anAny = new CORBA::Any() ;
1962 *anAny <<= (long ) 0 ;
1963 theOutPort->Value( anAny ) ;
1965 anInPort->State( SUPERV::WaitingState ) ;
1966 // const CORBA::Any * theValue = theOutPort->Value() ;
1967 D.Name = CORBA::string_dup( anInPort->GetServicesParameter().Parametername ) ;
1968 // D.Value = *theValue ; // CORBA::Any
1969 D.Value = *theOutPort->Value() ; // CORBA::Any
1970 cdebug << ThreadNo() << " ArgIn" << i << " " << anInPort->Kind() ;
1971 cdebug << D.Name << " " << anInPort->GetServicesParameter().Parametertype
1973 string _Type = CORBA::string_dup( anInPort->GetServicesParameter().Parametertype ) ;
1974 const char * Type = _Type.c_str() ;
1975 switch (D.Value.type()->kind()) {
1976 case CORBA::tk_string:
1979 cdebug << t << " (string)" << endl ;
1980 if ( !strcmp( Type , "string" ) ) {
1982 else if ( !strcmp( Type , "double" ) ) {
1984 sscanf( t , "%lf" , &d ) ;
1986 theOutPort->Value( D.Value ) ;
1988 else if ( !strcmp( Type , "long" ) || !strcmp( Type , "bool" ) ) {
1990 sscanf( t , "%ld" , &l ) ;
1992 theOutPort->Value( D.Value ) ;
1994 else if ( !strcmp( Type , "objref" ) ) {
1995 CORBA::Object_ptr ObjRef ;
1996 ObjRef = StringToObject( t ) ;
1997 D.Value <<= ObjRef ;
1998 theOutPort->Value( D.Value ) ;
2003 case CORBA::tk_double:
2006 cdebug << d << " (double)" << endl ;
2007 if ( !strcmp( Type , "string" ) ) {
2009 sprintf( t , "lf" , d ) ;
2011 theOutPort->Value( D.Value ) ;
2013 else if ( !strcmp( Type , "double" ) ) {
2015 else if ( !strcmp( Type , "long" ) || !strcmp( Type , "bool" ) ) {
2019 theOutPort->Value( D.Value ) ;
2021 else if ( !strcmp( Type , "objref" ) ) {
2026 case CORBA::tk_long:
2029 cdebug << l << " (long)" << endl ;
2030 if ( !strcmp( Type , "string" ) ) {
2032 sprintf( t , "lf" , l ) ;
2034 theOutPort->Value( D.Value ) ;
2036 else if ( !strcmp( Type , "double" ) ) {
2040 theOutPort->Value( D.Value ) ;
2042 else if ( !strcmp( Type , "long" ) || !strcmp( Type , "bool" ) ) {
2044 else if ( !strcmp( Type , "objref" ) ) {
2049 case CORBA::tk_objref:
2050 CORBA::Object_ptr obj ;
2054 // retstr = _Orb->object_to_string(obj );
2055 retstr = ObjectToString( obj ) ;
2056 cdebug << retstr << endl ;
2062 cdebug << "ToString( object ) Catched ERROR" << endl ;
2066 cdebug << " (other ERROR)" << endl ;
2070 cdebug << ThreadNo() << " In" << i << " : wrong state ERROR State "
2071 << anInPort->State() << " NameState "
2072 << Automaton()->StateName( anInPort->State() ) << " PortName "
2073 << anInPort->PortName() << " Parametername "
2074 << anInPort->GetServicesParameter().Parametername << endl ;
2077 aListOfInParameters[i] = D ;
2081 void GraphExecutor::InNode::InOutParameters(
2083 ServicesAnyData * aListOfOutParameters ) {
2085 for ( i = 0 ; i < nOutParams ; i++ ) {
2086 ServicesAnyData D = aListOfOutParameters[i] ;
2088 D.Name = GetChangeNodeOutPort(i)->GetServicesParameter().Parametername;
2089 string _Type = CORBA::string_dup(GetChangeNodeOutPort(i)->GetServicesParameter().Parametertype) ;
2090 const char * Type = _Type.c_str() ;
2091 bool OutDone = GetChangeNodeOutPort(i)->Done() ;
2092 // cdebug << ThreadNo() << " ArgOut" << i << " " << D.Name << " Done("
2093 // << OutDone << ") " << Type << " : " << endl ;
2094 if ( !strcmp( Type , "string" ) ) {
2095 D.Value <<= (char *) NULL ;
2097 else if ( !strcmp( Type , "double" ) ) {
2100 else if ( !strcmp( Type , "long" ) || !strcmp( Type , "bool" ) ) {
2101 D.Value <<= (long ) 0 ;
2104 D.Value.replace(CORBA::_tc_Object, NULL);
2106 // GetChangeNodeOutPort(i)->Value( D.Value ) ;
2108 switch (D.Value.type()->kind()) {
2109 case CORBA::tk_string:
2112 cdebug << ThreadNo() << " " << t << "(string)" << endl ;
2114 case CORBA::tk_double:
2117 cdebug << ThreadNo() << " " << d << "(double)" << endl ;
2119 case CORBA::tk_long:
2122 cdebug << ThreadNo() << " " << l << "(long)" << endl ;
2124 case CORBA::tk_objref:
2125 cdebug << ThreadNo() << " " << "(object)" << endl ;
2128 cdebug << ThreadNo() << " " << "(other ERROR)" << endl ;
2131 aListOfOutParameters[i] = D ;
2135 bool GraphExecutor::InNode::OutParameters(
2137 SUPERV::GraphState NewState ,
2139 ServicesAnyData * aListOfOutParameters ) {
2140 bool RetVal = true ;
2142 GraphBase::OutPort * aGateOutPort = NULL ;
2143 bool OrSwitch = false ;
2144 GraphBase::OutPort * anOutPort = GetChangeNodeOutPort(0) ;
2145 for ( i = 0 ; i < nOutParams ; i++ ) {
2146 anOutPort = GetChangeNodeOutPort(i) ;
2148 anOutPort->State( NewState ) ;
2149 anOutPort->Done( true ) ;
2152 cdebug << ThreadNo() << " " << "Out" << i << " " << Name() << " "
2153 << anOutPort->PortName() << " " << anOutPort->Kind() ;
2154 if ( anOutPort->IsGate() ) {
2155 aGateOutPort = anOutPort ;
2156 cdebug << " Gate " ;
2158 aListOfOutParameters[i].Value <<= l;
2159 anOutPort->Value( aListOfOutParameters[i].Value );
2161 else if ( anOutPort->IsLoop() ) {
2162 cdebug << " Loop " ;
2163 anOutPort->Value( aListOfOutParameters[i].Value );
2164 // InLoop Port of EndLoopNode is ready :
2165 anOutPort->ChangeInPorts(0)->State( SUPERV::ReadyState ) ;
2167 else if ( anOutPort->IsSwitch() ) {
2168 cdebug << " Switch " ;
2169 anOutPort->Value( aListOfOutParameters[i].Value );
2170 if ( anOutPort->InPortsSize() && anOutPort->ChangeInPorts( 0 )->IsGate() ) {
2171 if ( OrSwitch && anOutPort->BoolValue() ) {
2172 cdebug << "GraphExecutor::InNodeThreads::OutParameters more than one switch is true WARNING"
2177 OrSwitch = OrSwitch | anOutPort->BoolValue() ;
2180 cdebug << "OrSwitch " << OrSwitch ;
2183 cdebug << " Param " ;
2184 anOutPort->Value( aListOfOutParameters[i].Value );
2186 // else if ( anOutPort->IsBus() ) {
2187 // cdebug << " Bus " ;
2188 // anOutPort->Value( GetNodeInPort( anOutPort->PortIndex() )->GetOutPort()->Value() );
2190 anOutPort->State( NewState ) ;
2191 anOutPort->Done( true ) ;
2193 for ( j = 0 ; j < anOutPort->InPortsSize() ; j++ ) {
2194 bool fromGOTO = false ;
2195 GraphBase::OutPort * aGOTOPort = _OutNode->GetChangeGraphNode( anOutPort->ChangeInPorts( j )->NodeName() )->GetChangeNodeInPort( 0 )->GetOutPort() ;
2197 fromGOTO = aGOTOPort->IsGOTO() ;
2199 if ( anOutPort->ChangeInPorts( j )->IsEndSwitch() || fromGOTO ) {
2200 cdebug << anOutPort->ChangeInPorts( j )->NodeName() << "("
2201 << anOutPort->ChangeInPorts( j )->PortName() << ","
2202 << anOutPort->ChangeInPorts( j )->Kind() << ") WILL BE changed from "
2203 << anOutPort->ChangeInPorts( j )->GetOutPort()->NodeName()
2205 << anOutPort->ChangeInPorts( j )->GetOutPort()->PortName()
2206 << ") to " << anOutPort->NodeName() << "("
2207 << anOutPort->PortName() << ")" << endl ;
2208 anOutPort->ChangeInPorts( j )->ChangeOutPort( anOutPort ) ;
2211 cdebug << anOutPort->ChangeInPorts( j )->NodeName() << "("
2212 << anOutPort->ChangeInPorts( j )->PortName() << ","
2213 << anOutPort->ChangeInPorts( j )->Kind() << ") NOT changed from "
2214 << anOutPort->ChangeInPorts( j )->GetOutPort()->NodeName()
2216 << anOutPort->ChangeInPorts( j )->GetOutPort()->PortName()
2217 << ") to " << anOutPort->NodeName() << "("
2218 << anOutPort->PortName() << ")" << endl ;
2222 switch (anOutPort->Value()->type()->kind()) {
2223 case CORBA::tk_string:
2225 (*anOutPort->Value()) >>= t;
2226 cdebug << ThreadNo() << " Out" << i << " : " << t << "(string)" << endl ;
2228 case CORBA::tk_double:
2230 (*anOutPort->Value()) >>= d;
2231 cdebug << ThreadNo() << " Out" << i << " : " << d << "(double)" << endl ;
2233 case CORBA::tk_long:
2235 (*anOutPort->Value()) >>= l;
2236 cdebug << ThreadNo() << " Out" << i << " : " << l << "(long)" << endl ;
2238 case CORBA::tk_objref:
2239 CORBA::Object_ptr obj ;
2242 (*anOutPort->Value()) >>= obj ;
2243 retstr = _Orb->object_to_string(obj );
2244 cdebug << ThreadNo() << " Out" << i << " : " << "ToString( object ) "
2248 cdebug << ThreadNo() << " Out" << i << " : " << "ToString( object ) "
2249 << "Catched ERROR" << endl ;
2253 cdebug << ThreadNo() << " Out" << i << " : " << "(other ERROR)" << endl ;
2259 if ( aGateOutPort && IsSwitchNode() ) {
2261 cdebug << ThreadNo() << " " << "Out0 " << Name() << " Close of "
2262 << aGateOutPort->PortName() << " " << aGateOutPort->Kind() ;
2264 aListOfOutParameters[0].Value <<= l ;
2265 aGateOutPort->Value( aListOfOutParameters[0].Value ) ;
2268 cdebug << ThreadNo() << " " << "Out0 " << Name() << " Open of "
2269 << aGateOutPort->PortName() << " " << aGateOutPort->Kind() ;
2271 aListOfOutParameters[0].Value <<= l ;
2272 aGateOutPort->Value( aListOfOutParameters[0].Value ) ;
2274 for ( i = 0 ; i < GetNodeOutPortsSize() ; i++ ) {
2275 GraphBase::InPort * anInPort ;
2276 anInPort = CoupledNode()->GetChangeInPort( GetNodeOutPort( i )->PortName() ) ;
2278 anInPort->ChangeOutPort( GetChangeNodeOutPort( i ) ) ;