1 // SUPERV GraphExecutor : contains classes that permit execution of graphs and particularly the execution automaton
3 // Copyright (C) 2003 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
6 // This library is free software; you can redistribute it and/or
7 // modify it under the terms of the GNU Lesser General Public
8 // License as published by the Free Software Foundation; either
9 // version 2.1 of the License.
11 // This library is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 // Lesser General Public License for more details.
16 // You should have received a copy of the GNU Lesser General Public
17 // License along with this library; if not, write to the Free Software
18 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20 // See http://www.opencascade.org/SALOME/ or email : webmaster.salome@opencascade.org
24 // File : DataFlowBase_InNodeThreads.cxx
25 // Author : Jean Rahuel, CEA
40 #include <SALOMEconfig.h>
41 #include CORBA_CLIENT_HEADER(SALOME_Component)
42 //#include "SALOME_NamingService.hxx"
43 #include "SALOME_LifeCycleCORBA.hxx"
45 //#include "DataFlowExecutor_InNode.hxx"
47 #include "DataFlowExecutor_OutNode.hxx"
49 //static char *containerName = "FactoryServer" ;
51 int GraphExecutor::InNode::SendEvent(
52 const GraphExecutor::NodeEvent anEvent ) {
54 _CurrentEvent = (GraphExecutor::NodeEvent ) anEvent ;
55 cdebug << pthread_self() << "/" << ThreadNo() << " -->SendEvent Node " << Name()
57 << Automaton()->ControlStateName( ControlState() )
58 << " Event : " << Automaton()->EventName( anEvent )
59 << " State : " << Automaton()->StateName( State() ) << " _RewindStack " << _RewindStack << endl;
62 _NextState = Automaton()->NextState( _OldState , anEvent ) ;
63 if ( _NextState == _OldState ) {
64 cdebug << pthread_self() << "/" << ThreadNo()
65 << " GraphExecutor::InNodeThreads::SendEvent SameStates "
66 << _OldState << endl ;
67 _NextAction = GraphExecutor::VoidAction ;
70 _NextAction = Automaton()->NextAction( _NextState , anEvent ) ;
73 // State( _NextState ) ;
74 // if ( _OldState == SUPERV::SuccessedExecutingState ||
75 // _OldState == SUPERV::ErroredExecutingState ) {
79 cdebug << pthread_self() << "/" << ThreadNo() << " SendedEvent Node "
80 << Name() << endl << " ControlState : "
81 << Automaton()->ControlStateName( ControlState() ) << endl
82 << " OldState : " << Automaton()->StateName( _OldState ) << endl
83 << " Event : " << Automaton()->EventName( anEvent ) << endl
84 << " NextState : " << Automaton()->StateName( _NextState ) << endl
85 << " Action : " << Automaton()->ActionName( _NextAction ) << endl
86 << " CreateNewThread " << CreateNewThread() << endl
87 << " _RewindStack " << _RewindStack << endl ;
90 cout << pthread_self() << "/" << ThreadNo() << " SendedEvent Node " << Name()
91 << endl << " ControlState : "
92 << Automaton()->ControlStateName( ControlState() ) << endl
93 << " OldState : " << Automaton()->StateName( _OldState ) << endl
94 << " Event : " << Automaton()->EventName( anEvent ) << endl
95 << " NextState : " << Automaton()->StateName( _NextState ) << endl
96 << " Action : " << Automaton()->ActionName( _NextAction ) << endl
97 << " CreateNewThread " << CreateNewThread() << endl ;
100 int sts = executeAction() ;
102 cdebug << pthread_self() << "/" << ThreadNo() << " <--- SendEvent Node " << Name()
103 << " Event : " << Automaton()->EventName( anEvent )
104 << " State : " << Automaton()->StateName( State() )
111 // ReadyAction - RunningAction - DoneAction - SuspendedAction :
112 // for StateWait( ReadyW - RunningW - DoneW - SuspendedW )
113 void GraphExecutor::InNode::ReadyAction() {
114 if ( pthread_mutex_lock( &_MutexWait ) ) {
115 perror("Ready pthread_mutex_lock ") ;
118 cdebug << pthread_self() << "/" << ThreadNo()
119 << "ReadyAction pthread_cond_broadcast _ReadyWait "
121 if ( pthread_cond_broadcast( &_ReadyWait ) ) {
122 perror("Ready pthread_cond_broadcast ") ;
124 if ( pthread_mutex_unlock( &_MutexWait ) ) {
125 perror("Ready pthread_mutex_unlock ") ;
130 void GraphExecutor::InNode::RunningAction() {
131 if ( pthread_mutex_lock( &_MutexWait ) ) {
132 perror("Running pthread_mutex_lock ") ;
135 cdebug << pthread_self() << "/" << ThreadNo()
136 << "RunningAction pthread_cond_broadcast _RunningWait "
138 if ( pthread_cond_broadcast( &_RunningWait ) ) {
139 perror("Running pthread_cond_broadcast ") ;
141 if ( pthread_mutex_unlock( &_MutexWait ) ) {
142 perror("Running pthread_mutex_unlock ") ;
147 void GraphExecutor::InNode::DoneAction() {
148 if ( pthread_mutex_lock( &_MutexWait ) ) {
149 perror("Done pthread_mutex_lock ") ;
152 cdebug << pthread_self() << "/" << ThreadNo()
153 << "DoneAction pthread_cond_broadcast _DoneWait "
155 if ( pthread_cond_broadcast( &_DoneWait ) ) {
156 perror("Done pthread_cond_broadcast ") ;
158 if ( pthread_mutex_unlock( &_MutexWait ) ) {
159 perror("Done pthread_mutex_unlock ") ;
164 void GraphExecutor::InNode::SuspendedAction() {
165 if ( pthread_mutex_lock( &_MutexWait ) ) {
166 perror("Suspended pthread_mutex_lock ") ;
169 cdebug << pthread_self() << "/" << ThreadNo()
170 << "SuspendedAction pthread_cond_broadcast _SuspendedWait "
172 if ( pthread_cond_broadcast( &_SuspendedWait ) ) {
173 perror("Suspended pthread_cond_broadcast ") ;
175 if ( pthread_mutex_unlock( &_MutexWait ) ) {
176 perror("Suspended pthread_mutex_unlock ") ;
181 // SuspendAction <--> { ResumeAction - ReStartAction }
182 GraphExecutor::InNode * GraphExecutor::InNode::SuspendAction() {
184 if ( pthread_mutex_lock( &_MutexWait ) ) {
185 perror("Suspend pthread_mutex_lock ") ;
188 if ( !_SuspendSync ) {
189 cdebug << pthread_self() << "/" << ThreadNo() << " pthread_cond " << Name()
190 << " SuspendAction pthread_cond_wait _SuspendWait "
191 << Automaton()->StateName( State() ) << endl ;
192 _SuspendSync = true ;
193 _OutNode->SuspendThread() ;
194 if ( pthread_cond_wait( &_SuspendWait , &_MutexWait ) ) {
195 perror("SuspendAction pthread_cond_wait ") ;
197 _OutNode->ResumeThread() ;
198 cdebug << pthread_self() << "/" << ThreadNo() << " pthread_cond " << Name()
199 << " SuspendAction pthread_cond_waited"
200 << Automaton()->StateName( State() ) << endl ;
203 cdebug << pthread_self() << "/" << ThreadNo() << " pthread_cond " << Name()
204 << " NO SuspendAction pthread_cond_wait"
205 << Automaton()->StateName( State() ) << endl ;
207 SendEvent( _aResumeEvent ) ;
208 _SuspendSync = false ;
209 if ( pthread_mutex_unlock( &_MutexWait ) ) {
210 perror("SuspendAction pthread_mutex_unlock ") ;
214 if ( ControlState() == SUPERV::ToSuspendStartState ) {
215 ControlState( SUPERV::VoidState ) ;
218 if ( pthread_mutex_lock( &_MutexWait ) ) {
219 perror("SuspendAction pthread_mutex_lock ") ;
223 cdebug << pthread_self() << "/" << ThreadNo() << " pthread_cond " << Name()
224 << " SuspendAction pthread_cond_signal _ResumeWait" << endl ;
225 if ( pthread_cond_signal( &_ResumeWait ) ) {
226 perror("SuspendAction pthread_cond_signal _ResumeWait ") ;
228 cdebug << pthread_self() << "/" << ThreadNo() << " pthread_cond " << Name()
229 << " SuspendAction pthread_cond_signaled _ResumeWait " << endl ;
232 cdebug << pthread_self() << "/" << ThreadNo() << " pthread_cond " << Name()
233 << " NO SuspendAction pthread_cond_signal _ResumeWait" << endl ;
236 if ( pthread_mutex_unlock( &_MutexWait ) ) {
237 perror("SuspendAction pthread_mutex_unlock ") ;
240 if ( _aReStartNode ) {
241 cdebug << Name() << " " << Automaton()->StateName( State() )
242 << "aReStartNode : " << _aReStartNode->Name() << " "
243 << Automaton()->StateName( _aReStartNode->State() ) << endl ;
244 _aReStartNode->SendEvent( _aResumeEvent ) ;
247 cdebug << "NO aReStartNode"
248 << Automaton()->StateName( State() ) << endl ;
250 return _aReStartNode ;
253 bool GraphExecutor::InNode::ResumeAction( GraphExecutor::NodeEvent aResumeEvent ) {
255 if ( pthread_mutex_lock( &_MutexWait ) ) {
256 perror("ResumeAction pthread_mutex_lock ") ;
259 _aResumeEvent = aResumeEvent ;
260 if ( _SuspendSync ) {
261 cdebug << pthread_self() << "/" << ThreadNo() << " pthread_cond " << Name()
262 << " ResumeAction pthread_cond_signal" << endl ;
263 if ( pthread_cond_signal( &_SuspendWait ) ) {
264 perror("ResumeAction pthread_cond_signal ") ;
266 cdebug << pthread_self() << "/" << ThreadNo() << " pthread_cond " << Name()
267 << " ResumeAction pthread_cond_signaled _SuspendWait " << endl ;
271 cdebug << pthread_self() << "/" << ThreadNo() << " pthread_cond " << Name()
272 << " NO ResumeAction pthread_cond_signal" << endl ;
273 if ( pthread_self() == ThreadNo() ) {
274 RetVal = false ; // Ne pas s'attendre soi-meme !...
277 _SuspendSync = true ;
278 RetVal = true ; // Il faut tout de meme attendre ci-apres ...
281 if ( pthread_mutex_unlock( &_MutexWait ) ) {
282 perror("ResumeAction pthread_mutex_unlock ") ;
287 if ( pthread_mutex_lock( &_MutexWait ) ) {
288 perror("ResumeAction pthread_mutex_lock ") ;
291 if ( !_ResumeSync ) {
292 cdebug << pthread_self() << "/" << ThreadNo() << " pthread_cond "
293 << Name() << " ResumeAction pthread_cond_wait _ResumeWait "
294 << Automaton()->StateName( State() ) << endl ;
296 if ( pthread_cond_wait( &_ResumeWait , &_MutexWait ) ) {
297 perror("ResumeAction pthread_cond_wait ") ;
299 cdebug << pthread_self() << "/" << ThreadNo() << " pthread_cond "
300 << Name() << " ResumeAction pthread_cond_waited _ResumeWait"
301 << Automaton()->StateName( State() ) << endl ;
305 cdebug << pthread_self() << "/" << ThreadNo() << " pthread_cond "
306 << Name() << " NO ResumeAction pthread_cond_wait _ResumeWait"
307 << Automaton()->StateName( State() ) << endl ;
310 _ResumeSync = false ;
311 if ( pthread_mutex_unlock( &_MutexWait ) ) {
312 perror("ResumeAction pthread_mutex_unlock ") ;
316 cdebug << pthread_self() << "/" << ThreadNo()
317 << "GraphExecutor::InNodeThreads::ResumeAction RetVal " << RetVal << endl ;
321 bool GraphExecutor::InNode::ReStartAction( GraphExecutor::InNode * aReStartNode ,
322 GraphExecutor::NodeEvent anEvent ) {
323 GraphExecutor::InNode * oldReStartNode = _aReStartNode ;
324 _aReStartNode = aReStartNode ;
325 _aReStartEvent = anEvent ;
326 cdebug << pthread_self() << " GraphExecutor::InNodeThreads::ReStartAction from "
327 << Name() << " " << Automaton()->StateName( State() ) << " to "
328 << aReStartNode->ThreadNo() << " " << aReStartNode->Name() << " "
329 << Automaton()->StateName( aReStartNode->State() ) ;
330 if ( oldReStartNode ) {
331 cdebug << " oldReStartNode " << oldReStartNode->Name() << endl ;
336 return ResumeAction( GraphExecutor::ToReStartEvent ) ;
339 void GraphExecutor::InNode::KilledAction() {
340 if ( pthread_mutex_lock( &_MutexWait ) ) {
341 perror("Killed pthread_mutex_lock ") ;
345 cdebug << "pthread_cond " << Name() << " Killed pthread_cond_wait"
348 if ( pthread_cond_wait( &_KillWait , &_MutexWait ) ) {
349 perror("Killed pthread_cond_wait ") ;
351 cdebug << "pthread_cond " << Name() << " Killed pthread_cond_waited"
355 cdebug << "pthread_cond " << Name() << " NO Killed pthread_cond_wait"
359 if ( pthread_mutex_unlock( &_MutexWait ) ) {
360 perror("Killed pthread_mutex_unlock ") ;
365 void GraphExecutor::InNode::KillAction() {
366 if ( pthread_mutex_lock( &_MutexWait ) ) {
367 perror("Kill pthread_mutex_lock ") ;
371 cdebug << "pthread_cond " << Name() << " Kill pthread_cond_signal"
373 // if ( pthread_cond_broadcast( &_KillWait ) ) {
374 if ( pthread_cond_signal( &_KillWait ) ) {
375 perror("Kill pthread_cond_broadcast ") ;
377 cdebug << "pthread_cond " << Name() << " Kill pthread_cond_signaled"
381 cdebug << "pthread_cond " << Name() << " NO Kill pthread_cond_signal"
385 if ( pthread_mutex_unlock( &_MutexWait ) ) {
386 perror("Kill pthread_mutex_unlock ") ;
391 void GraphExecutor::InNode::StoppedAction() {
392 if ( pthread_mutex_lock( &_MutexWait ) ) {
393 perror("Stopped pthread_mutex_lock ") ;
396 if ( pthread_cond_wait( &_StopWait , &_MutexWait ) ) {
397 perror("Stopped pthread_cond_wait ") ;
399 if ( pthread_mutex_unlock( &_MutexWait ) ) {
400 perror("Stopped pthread_mutex_unlock ") ;
405 void GraphExecutor::InNode::StopAction() {
406 if ( pthread_mutex_lock( &_MutexWait ) ) {
407 perror("Stop pthread_mutex_lock ") ;
410 if ( pthread_cond_broadcast( &_StopWait ) ) {
411 perror("Stop pthread_cond_broadcast ") ;
413 if ( pthread_mutex_unlock( &_MutexWait ) ) {
414 perror("Stop pthread_mutex_unlock ") ;
419 int GraphExecutor::InNode::executeAction() {
420 if ( !CreateNewThread() && _RewindStack > 101 ) {
421 CreateNewThread( true ) ;
424 if ( CreateNewThread() ) {
425 CreateNewThread( false ) ;
426 if ( ThreadNo() == 0 ) {
428 cdebug << pthread_self() << "/" << ThreadNo()
429 << " executeAction start Thread _RewindStack " << _RewindStack << " "
430 << Automaton()->ActionName( _NextAction ) << "(" << Name() << ")"
433 int pthread_sts = 1 ;
434 // _OutNode->PushEvent( NULL , GraphExecutor::NewThreadEvent ,
435 // SUPERV::ExecutingState ) ;
436 while ( (pthread_sts = pthread_create(&T, NULL, run_function, this )) ) {
437 char * msg = "Cannot pthread_create " ;
439 cdebug << ThreadNo() << " " << msg << " --> sleep(5)" << endl ;
440 cdebug << ThreadNo() << " PTHREAD_THREADS_MAX : "
441 << PTHREAD_THREADS_MAX << " pthread_create status : " ;
442 if ( pthread_sts == EAGAIN ) {
443 cdebug << "EAGAIN(" << pthread_sts << ")" << endl ;
444 cdebug << "It seems to me that with gdb we are limited to 256 threads because of defunct" << endl ;
447 cdebug << pthread_sts << endl ;
451 pthread_exit( msg ) ;
453 cdebug << pthread_self() << "/" << ThreadNo()
454 << "executeAction has created thread " << T << endl ;
457 cdebug << pthread_self() << "/" << ThreadNo()
458 << " executeAction restart Thread _RewindStack " << _RewindStack << " "
459 << Automaton()->StateName( State() ) << " "
460 << Automaton()->ActionName( _NextAction ) << "(" << Name()
461 << ") ReStartAction ==>" << endl;
462 State( SUPERV::SuspendedSuccessedState ) ;
463 if ( !ReStartAction( this , GraphExecutor::ReStartEvent ) ) {
464 cdebug << pthread_self() << "/" << ThreadNo()
465 << " executeAction STATE & CALLED "
466 << Automaton()->ActionName( _NextAction ) << "(" << Name()
467 << ") ERROR-DEBUG " << endl;
470 cdebug << pthread_self() << "/" << ThreadNo() << " executeAction NO CALL "
471 << Automaton()->ActionName( _NextAction ) << "(" << Name()
477 if ( _CurrentEvent == ExecuteEvent ) {
480 cdebug << pthread_self() << "/" << ThreadNo() << " executeAction call "
481 << Automaton()->ActionName( _NextAction ) << "(" << Name() << ") _RewindStack " << _RewindStack
483 return ExecuteAction() ;
488 void GraphExecutor::InNode::coutbegin() {
489 cdebug << ThreadNo() << " " << pthread_self() << " run_function begin"
490 << " " << Name() << " " << Automaton()->StateName( State() ) << endl ;
492 void GraphExecutor::InNode::coutexit() {
493 cdebug << pthread_self() << "/" << ThreadNo() << " run_function pthread_exit _RewindStack " << _RewindStack
494 << " " << Name() << " " << Automaton()->StateName( State() ) << endl ;
496 void * run_function(void *p) {
497 GraphExecutor::InNode *aNode = (GraphExecutor::InNode *) p;
499 aNode->NewThread( pthread_self() ) ;
500 if ( pthread_setcanceltype( PTHREAD_CANCEL_ASYNCHRONOUS , NULL ) ) {
501 perror("pthread_setcanceltype ") ;
504 if ( pthread_setcancelstate( PTHREAD_CANCEL_ENABLE , NULL ) ) {
505 perror("pthread_setcancelstate ") ;
508 aNode->ExecuteAction() ;
509 char * msg = new char[40] ;
510 sprintf( msg , "%d" , (int ) aNode->ThreadNo() ) ;
511 strcat( msg , " thread exit" ) ;
513 aNode->ExitThread() ;
516 pthread_exit( (void * ) smsg.c_str() ) ;
520 int GraphExecutor::InNode::ExecuteAction() {
522 GraphExecutor::StateEventAction nextaction = _NextAction ;
523 const char * nextactionname = Automaton()->ActionName( nextaction ) ;
524 const char * statename = Automaton()->StateName( State() ) ;
525 const char * nextstatename = Automaton()->StateName( _NextState ) ;
526 cdebug << pthread_self() << "/" << ThreadNo() << " --> ExecuteAction "
527 << nextactionname << " " << statename << " NextState "
528 << nextstatename << endl ;
529 State( _NextState ) ;
530 switch ( nextaction ) {
531 case GraphExecutor::ErrorAction : {
532 sts = ErrorAction() ;
535 case GraphExecutor::VoidAction : {
539 case GraphExecutor::DataWaiting_SomeDataReadyAction : {
540 sts = DataWaiting_SomeDataReadyAction() ;
543 case GraphExecutor::DataUndef_NotAllDataReadyAction : {
544 sts = DataUndef_NotAllDataReadyAction() ;
547 case GraphExecutor::DataUndef_AllDataReadyAction : {
548 sts = DataUndef_AllDataReadyAction() ;
551 case GraphExecutor::DataReady_SuspendAction : {
552 sts = DataReady_SuspendAction() ;
555 case GraphExecutor::SuspendedReady_ResumeAction : {
556 sts = SuspendedReady_ResumeAction() ;
559 case GraphExecutor::DataReady_KillAction : {
560 sts = DataReady_KillAction() ;
563 case GraphExecutor::DataReady_StopAction : {
564 sts = DataReady_StopAction() ;
567 case GraphExecutor::DataReady_ExecuteAction : {
568 sts = DataReady_ExecuteAction() ;
571 case GraphExecutor::Executing_SuspendAction : {
572 sts = Executing_SuspendAction() ;
575 case GraphExecutor::SuspendedExecuting_ResumeAction : {
576 sts = SuspendedExecuting_ResumeAction() ;
579 case GraphExecutor::Executing_KillAction : {
580 sts = Executing_KillAction() ;
583 case GraphExecutor::Executing_StopAction : {
584 sts = Executing_StopAction() ;
587 case GraphExecutor::Executing_SuccessAction : {
588 sts = Executing_SuccessAction() ;
591 case GraphExecutor::Executing_ErrorAction : {
592 sts = Executing_ErrorAction() ;
595 case GraphExecutor::Successed_SuccessAction : {
596 sts = Successed_SuccessAction() ;
599 case GraphExecutor::Errored_ErrorAction : {
600 sts = Errored_ErrorAction() ;
603 case GraphExecutor::Successed_SuspendAction : {
604 sts = Successed_SuspendAction() ;
607 case GraphExecutor::Errored_SuspendAction : {
608 sts = Errored_SuspendAction() ;
611 case GraphExecutor::SuspendedSuccessed_ResumeAction : {
612 sts = SuspendedSuccessed_ResumeAction() ;
615 case GraphExecutor::SuspendedErrored_ResumeAction : {
616 sts = SuspendedErrored_ResumeAction() ;
619 case GraphExecutor::Successed_KillAction : {
620 sts = Successed_KillAction() ;
623 case GraphExecutor::Errored_KillAction : {
624 sts = Errored_KillAction() ;
627 case GraphExecutor::Successed_StopAction : {
628 sts = Successed_StopAction() ;
631 case GraphExecutor::Errored_StopAction : {
632 sts = Errored_StopAction() ;
635 case GraphExecutor::SuspendedSuccessed_ReStartAction : {
636 sts = SuspendedSuccessed_ReStartAction() ;
639 case GraphExecutor::SuspendedErrored_ReStartAction : {
640 sts = SuspendedErrored_ReStartAction() ;
643 case GraphExecutor::SuspendedSuccessed_ReStartAndSuspendAction : {
644 sts = SuspendedSuccessed_ReStartAndSuspendAction() ;
647 case GraphExecutor::SuspendedErrored_ReStartAndSuspendAction : {
648 sts = SuspendedErrored_ReStartAndSuspendAction() ;
652 cdebug << pthread_self() << "/" << ThreadNo()
653 << " GraphExecutor::InNodeThreads::SendEvent Error Undefined Action : "
654 << _NextAction << endl ;
658 cdebug << pthread_self() << "/" << ThreadNo() << "<-- ExecuteAction "
659 << Automaton()->ActionName( nextaction ) << endl ;
663 int GraphExecutor::InNode::ErrorAction() {
664 cdebug << pthread_self() << "/" << ThreadNo() << " Automaton ErrorAction Node "
669 int GraphExecutor::InNode::VoidAction() {
670 cdebug << pthread_self() << "/" << ThreadNo() << " VoidAction " << Name() << endl;
675 int GraphExecutor::InNode::DataWaiting_SomeDataReadyAction() {
676 cdebug << pthread_self() << "/" << ThreadNo()
677 << " --> DataWaiting_SomeDataReadyAction from " << DataFromNode()
678 << " to " << Name() << endl;
682 bool LoopFinished = false ;
683 bool LoopBeginning = false ;
684 bool SwitchFinished = false ;
686 if ( IsEndLoopNode() && !GetChangeNodeInLoop()->GetOutPort()->BoolValue() ) {
687 LoopFinished = true ; // End of Loop
689 if ( IsLoopNode() && GetChangeNodeInLoop()->GetOutPort()->BoolValue() ) {
690 LoopBeginning = true ; // Beginning of Loop
692 if ( IsEndSwitchNode() && !GetChangeNodeInGate()->GetOutPort()->BoolValue() ) {
693 SwitchFinished = true ;
695 for ( k = 0 ; k < (unsigned int ) GetNodeInPortsSize() ; k++ ) {
696 GraphBase::InPort * anInPort = GetChangeNodeInPort(k) ;
697 GraphBase::OutPort * anOutPort = anInPort->GetOutPort() ;
698 if ( anInPort->IsGate() && anOutPort == NULL ) {
700 anInPort->State( SUPERV::ReadyState ) ;
701 cdebug << pthread_self() << "/" << ThreadNo() << " " << Name() << " "
702 << anInPort->PortName() << " ControlPort inactive." << endl ;
704 else if ( strcmp( DataFromNode() , anOutPort->NodeName() ) ) {
705 if ( anInPort->State() == SUPERV::ReadyState ) {
707 cdebug << pthread_self() << "/" << ThreadNo() << " " << Name() << " "
708 << anInPort->PortName() << " Was Done from "
709 << anOutPort->NodeName() << " " << anOutPort->PortName()
712 if ( GraphBase::Base::_prof_debug ) {
713 anOutPort->StringValue( *GraphBase::Base::_fdebug ) ;
718 else if ( IsLoopNode() && anInPort->IsDataConnected() ) {
719 anInPort->State( SUPERV::ReadyState ) ;
721 cdebug << pthread_self() << "/" << ThreadNo() << " " << Name() << " "
722 << anInPort->PortName() << " Was Done from "
723 << anOutPort->NodeName() << " " << anOutPort->PortName()
724 << " LoopBeginning " << LoopBeginning ;
726 if ( GraphBase::Base::_prof_debug ) {
727 anOutPort->StringValue( *GraphBase::Base::_fdebug ) ;
732 else if ( LoopFinished ) {
733 anInPort->State( SUPERV::ReadyState ) ;
735 cdebug << pthread_self() << "/" << ThreadNo() << " " << Name() << " "
736 << anInPort->PortName() << " Was Done from "
737 << anOutPort->NodeName() << " " << anOutPort->PortName()
740 if ( GraphBase::Base::_prof_debug ) {
741 anOutPort->StringValue( *GraphBase::Base::_fdebug ) ;
746 else if ( anInPort->IsGate() && SwitchFinished ) {
747 anInPort->State( SUPERV::ReadyState ) ;
749 cdebug << pthread_self() << "/" << ThreadNo() << " " << Name() << " "
750 << anInPort->PortName() << " Was Done from "
751 << anOutPort->NodeName() << " " << anOutPort->PortName()
752 << " SwitchFinished" ;
754 if ( GraphBase::Base::_prof_debug ) {
755 anOutPort->StringValue( *GraphBase::Base::_fdebug ) ;
761 cdebug << pthread_self() << "/" << ThreadNo() << " " << Name() << " "
762 << anInPort->PortName() << " Was NOT Done from "
763 << anOutPort->NodeName() << " " << anOutPort->PortName() << " "
764 << " " << Automaton()->StateName( State() ) << " DataConnected "
765 << anInPort->IsDataConnected() << " LoopBeginning "
766 << LoopBeginning << endl ;
769 else if ( anInPort->IsGate() ) {
770 const CORBA::Any * theValue = anOutPort->Value() ;
772 (*theValue) >>= GateOpened ;
773 if ( GateOpened != 0 ) {
775 anInPort->State( SUPERV::ReadyState ) ;
776 cdebug << pthread_self() << "/" << ThreadNo() << " " << Name() << " "
777 << anInPort->PortName() << " Gate is Opened from "
778 << anOutPort->NodeName() << " " << anOutPort->PortName()
781 if ( GraphBase::Base::_prof_debug ) {
782 anOutPort->StringValue( *GraphBase::Base::_fdebug ) ;
787 else if ( LoopFinished ) {
788 anInPort->State( SUPERV::ReadyState ) ;
789 cdebug << pthread_self() << "/" << ThreadNo() << " " << Name() << " "
790 << anInPort->PortName() << " GATE IS CLOSED from "
791 << anOutPort->NodeName() << " " << anOutPort->PortName()
794 if ( GraphBase::Base::_prof_debug ) {
795 anOutPort->StringValue( *GraphBase::Base::_fdebug ) ;
801 cdebug << pthread_self() << "/" << ThreadNo() << " " << Name() << " "
802 << anInPort->PortName() << " GATE IS CLOSED from "
803 << anOutPort->NodeName() << " " << anOutPort->PortName()
806 if ( GraphBase::Base::_prof_debug ) {
807 anOutPort->StringValue( *GraphBase::Base::_fdebug ) ;
815 anInPort->State( SUPERV::ReadyState ) ;
816 cdebug << pthread_self() << "/" << ThreadNo() << " " << Name() << " "
817 << anInPort->PortName() << " is Done from "
818 << anOutPort->NodeName() << " " << anOutPort->PortName() << " " ;
820 if ( GraphBase::Base::_prof_debug ) {
821 anOutPort->StringValue( *GraphBase::Base::_fdebug ) ;
828 if ( InReady == GetNodeInPortsSize() ) { // All Flags != 0 :
829 res = SendEvent( GraphExecutor::AllDataReadyEvent ); // ==> Ready to execute
831 else { // At least one Flag == 0 :
832 res = SendEvent( GraphExecutor::NotAllDataReadyEvent );
835 cdebug << pthread_self() << "/" << ThreadNo()
836 << " <-- DataWaiting_SomeDataReadyAction " << Name() << endl;
841 int GraphExecutor::InNode::DataUndef_NotAllDataReadyAction() {
842 CreateNewThreadIf( false ) ;
843 cdebug << pthread_self() << " for " << ThreadNo()
844 << " DataUndef_NotAllDataReadyAction " << Name() << endl;
848 int GraphExecutor::InNode::DataUndef_AllDataReadyAction() {
849 cdebug << pthread_self() << "/" << ThreadNo()
850 << " --> DataUndef_AllDataReadyAction " << Name()
851 << " CreateNewThreadIf " << CreateNewThreadIf() << " IsLockedDataWait "
852 << IsLockedDataWait() ;
853 // if ( !CreateNewThreadIf() && IsLockedDataWait() ) {
854 if ( IsLockedDataWait() ) {
855 cdebug << " WOULD DEAD-LOCK" << endl ;
856 return 0 ; // ==> DataUndef_AllDataReadyAction() after UnLockDataWait()
859 CreateNewThread( CreateNewThreadIf() ) ;
860 if ( !CreateNewThread() ) {
861 cdebug << "Thread " << ThreadNo() << "-->" << pthread_self() << endl ;
862 ThreadNo( pthread_self() ) ;
864 _OutNode->PushEvent( this , GraphExecutor::AllDataReadyEvent ,
865 SUPERV::DataReadyState ) ;
867 SUPERV::ControlState aControl = ControlState() ;
868 switch ( aControl ) {
869 case SUPERV::VoidState : {
870 SendEvent( GraphExecutor::ExecuteEvent ) ;
873 case SUPERV::ToSuspendState : {
874 SendEvent( GraphExecutor::SuspendEvent ) ;
877 case SUPERV::ToSuspendStartState : {
878 SendEvent( GraphExecutor::SuspendEvent ) ;
881 case SUPERV::ToSuspendDoneState : {
882 SendEvent( GraphExecutor::ExecuteEvent ) ;
885 case SUPERV::ToKillState : {
886 SendEvent( GraphExecutor::KillEvent ) ;
889 case SUPERV::ToKillDoneState : {
890 SendEvent( GraphExecutor::ExecuteEvent ) ;
893 case SUPERV::ToStopState : {
894 SendEvent( GraphExecutor::StopEvent ) ;
899 << " GraphExecutor::InNodeThreads::DataUndef_AllDataReadyAction Error Undefined Control : "
900 << aControl << endl ;
904 cdebug << pthread_self() << "/" << ThreadNo()
905 << " <-- DataUndef_AllDataReadyAction " << Name() << endl;
909 int GraphExecutor::InNode::DataReady_SuspendAction() {
910 cdebug << pthread_self() << "/" << ThreadNo()
911 << "DataReady_SuspendAction --> Suspend " << Name()
912 << " Threads " << _OutNode->Threads() << " SuspendedThreads "
913 << _OutNode->SuspendedThreads() << endl;
914 _OutNode->PushEvent( this , GraphExecutor::SuspendedReadyEvent ,
915 SUPERV::SuspendedReadyState ) ;
916 GraphExecutor::InNode * aReStartNode = SuspendAction() ;
917 cdebug << pthread_self() << "/" << ThreadNo()
918 << "DataReady_SuspendAction Resumed " << Name() << endl;
919 if ( aReStartNode ) {
920 _aReStartNode = NULL ;
921 aReStartNode->SendEvent( _aReStartEvent ) ;
924 SendEvent( GraphExecutor::ExecuteEvent ) ;
929 int GraphExecutor::InNode::SuspendedReady_ResumeAction() {
930 cdebug << pthread_self() << "/" << ThreadNo() << "SuspendedReady_ResumeAction "
933 _OutNode->PushEvent( this , GraphExecutor::ResumedReadyEvent ,
934 SUPERV::ResumedReadyState ) ;
938 int GraphExecutor::InNode::DataReady_KillAction() {
939 _OutNode->PushEvent( this , GraphExecutor::KilledReadyEvent ,
940 SUPERV::KilledReadyState ) ;
942 cdebug << pthread_self() << "/" << ThreadNo() << "DataReady_KillAction " << Name()
943 << " will pthread_exit()" << endl;
947 int GraphExecutor::InNode::DataReady_StopAction() {
948 _OutNode->PushEvent( this , GraphExecutor::StoppedReadyEvent ,
949 SUPERV::StoppedReadyState ) ;
951 cdebug << pthread_self() << "/" << ThreadNo() << "DataReady_StopAction " << Name()
952 << " will pthread_exit()" << endl;
958 int GraphExecutor::InNode::DataReady_ExecuteAction() {
961 cdebug << pthread_self() << "/" << ThreadNo() << " --> DataReady_ExecuteAction "
963 _OutNode->PushEvent( this , GraphExecutor::ExecuteEvent ,
964 SUPERV::ExecutingState ) ;
967 SUPERV::GraphState PortState = SUPERV::ReadyState ;
968 SUPERV::AutomatonState NewState = SUPERV::DataUndefState ;
969 GraphExecutor::NodeEvent NewEvent = GraphExecutor::UndefinedEvent ;
973 int nInParams = GetNodeInPortsSize() ;
974 ServicesAnyData * InParametersList = new ServicesAnyData[nInParams];
975 InParametersSet( Err , nInParams , InParametersList ) ;
977 Engines::Container_var myContainer ;
978 Engines::Component_var myObjComponent ;
979 // if ( strlen( ComponentName() ) == 0 ) {
980 if ( !IsFactoryNode() ) {
981 cdebug << ThreadNo() << "No Component : NO StartComponent & No Ping"
983 if ( IsComputingNode() ) {
984 ObjInterface( true ) ;
985 CORBA::Object_ptr obj ;
986 InParametersList[0].Value >>= obj ;
987 CORBA::Object_var objvar = CORBA::Object_var( obj ) ;
988 myObjComponent = Engines::Component::_narrow( objvar ) ;
993 else if ( CORBA::is_nil( Component() ) ) {
994 Err = !_OutNode->StartComponent( ThreadNo() , Computer() ,
995 my_strdup( ComponentName() ) ,
996 myContainer , myObjComponent ) ;
997 // if ( !Err && nInParams > 1 &&
998 // strcmp( ComponentName() , InterfaceName() ) &&
999 // InParametersList[ 1 ].Value.type()->kind() ==
1000 // CORBA::tk_objref ) {
1003 ObjInterface( false ) ;
1005 SetContainer( myContainer ) ;
1006 SetComponent( myObjComponent ) ;
1009 myContainer = Container() ;
1010 myObjComponent = Component() ;
1011 cdebug << ThreadNo() << "Component known : NO StartComponent & Ping"
1013 myObjComponent->ping() ;
1016 int nOutParams = GetNodeOutPortsSize() ;
1017 ServicesAnyData * OutParametersList = new ServicesAnyData[nOutParams];
1018 InOutParametersSet( nOutParams , OutParametersList ) ;
1020 // if ( strlen( ComponentName() ) ) {
1021 if ( Err || ControlState() == SUPERV::ToKillState ||
1022 ControlState() == SUPERV::ToKillDoneState ||
1023 ControlState() == SUPERV::ToStopState ) {
1024 cdebug << ThreadNo() << "StartComponent Error or ToKillState" << endl ;
1029 cdebug << ThreadNo() << " Run( '" << ServiceName() << "'" ;
1030 for ( i = 0 ; i < (int ) ServiceInParameter().length() ; i++ ) {
1031 cdebug << " , " << InParametersList[ i ].Name << "[kind"
1032 << InParametersList[ i ].Value.type()->kind() << "]" ;
1034 for ( i = 0 ; i < (int ) ServiceOutParameter().length() ; i++ ) {
1035 cdebug << " , " << OutParametersList[ i ].Name << "[kind"
1036 << OutParametersList[ i ].Value.type()->kind() << "]" ;
1038 cdebug << ")" << endl ;
1040 if ( IsOneOfInLineNodes() ) {
1041 bool StsPyDynInvoke = true ;
1042 _OutNode->PyThreadLock() ;
1045 if ( IsInLineNode() && (*InLineNode()->PythonFunction()).length() &&
1046 strlen( InLineNode()->PyFuncName() ) ) {
1047 cdebug << ThreadNo() << " !ObjInterface " << Name() << " PyFuncName '"
1048 << InLineNode()->PyFuncName()
1049 << "' IsInLineNode PyDynInvoke" << endl ;
1050 StsPyDynInvoke = PyDynInvoke( InLineNode()->PyRunMethod() ,
1051 InLineNode()->PyFuncName() ,
1052 &InParametersList[0] , ServiceInParameter().length() ,
1053 &OutParametersList[0] , ServiceOutParameter().length() ) ;
1055 else if ( IsLoopNode() ) {
1056 if ( GetNodeInLoop()->GetOutPort()->BoolValue() ) { // InLoop Port
1057 cdebug << ThreadNo() << " !ObjInterface " << Name()
1058 << " IsLoopNode PyDynInvoke '" << InLineNode()->PyFuncName()
1060 StsPyDynInvoke = PyDynInvoke( InLineNode()->PyRunMethod() ,
1061 InLineNode()->PyFuncName() ,
1062 &InParametersList[1] , ServiceInParameter().length() ,
1063 &OutParametersList[1] , ServiceOutParameter().length() ) ;
1066 cdebug << ThreadNo() << " !ObjInterface " << Name()
1067 << " IsLoopNode PyDynInvoke '" << LoopNode()->PyNextName()
1069 StsPyDynInvoke = PyDynInvoke( LoopNode()->PyNextMethod() ,
1070 LoopNode()->PyNextName() ,
1071 &InParametersList[1] , ServiceInParameter().length() ,
1072 &OutParametersList[1] , ServiceOutParameter().length() ) ;
1074 if ( StsPyDynInvoke ) {
1075 cdebug << ThreadNo() << " !ObjInterface " << Name()
1076 << " IsLoopNode PyDynInvoke '" << LoopNode()->PyMoreName()
1077 << "' Copy of " << ServiceInParameter().length()
1078 << " OutParameters" << endl ;
1080 for ( i = 1 ; i <= (int ) ServiceInParameter().length() ; i++ ) {
1081 InParametersList[i].Value = OutParametersList[i].Value ;
1082 InParametersList[i].Name = OutParametersList[i].Name ;
1084 switch ( InParametersList[i].Value.type()->kind() ) {
1085 case CORBA::tk_string :
1087 InParametersList[i].Value >>= t ;
1088 cdebug << "ArgOut->In" << i << " : "
1089 << InParametersList[i].Name.c_str()
1090 << " Value(string) " << t << endl ;
1092 case CORBA::tk_double :
1094 InParametersList[i].Value >>= d;
1095 cdebug << "ArgOut->In" << i << " : "
1096 << InParametersList[i].Name.c_str()
1097 << " Value(double) " << d << endl ;
1099 case CORBA::tk_long :
1101 InParametersList[i].Value >>= l;
1102 cdebug << "ArgOut->In" << i << " : "
1103 << InParametersList[i].Name.c_str()
1104 << " Value(long) " << l << endl ;
1106 case CORBA::tk_objref :
1107 CORBA::Object_ptr obj ;
1110 InParametersList[i].Value >>= obj ;
1111 retstr = ObjectToString( obj );
1112 cdebug << "ArgOut->In" << i << " : "
1113 << InParametersList[i].Name.c_str()
1114 << " Value(object reference) " << retstr << endl ;
1117 cdebug << "ArgOut->In" << i << " : "
1118 << InParametersList[i].Name.c_str()
1119 << " Value(object reference) Catched ERROR" << endl ;
1123 cdebug << "ArgOut->In" << i << " : "
1124 << InParametersList[i].Name.c_str()
1125 << " Value(other) ERROR" << endl ;
1129 StsPyDynInvoke = PyDynInvoke( LoopNode()->PyMoreMethod() ,
1130 LoopNode()->PyMoreName() ,
1131 &InParametersList[1] , ServiceInParameter().length() ,
1132 &OutParametersList[0] , ServiceOutParameter().length()+1 ) ;
1136 cdebug << ThreadNo() << " InLineNode " << Name() << " "
1137 << InLineNode()->PyFuncName() << "/" << LoopNode()->PyNextName()
1138 << " Python Dynamic Call Error"
1142 else if ( IsSwitchNode() ) {
1143 cdebug << ThreadNo() << " !ObjInterface " << Name() << " PyFuncName '"
1144 << InLineNode()->PyFuncName()
1145 << "' IsSwitchNode PyDynInvoke" << endl ;
1146 StsPyDynInvoke = PyDynInvoke( InLineNode()->PyRunMethod() ,
1147 InLineNode()->PyFuncName() ,
1148 &InParametersList[0] , ServiceInParameter().length() ,
1149 &OutParametersList[0] , ServiceOutParameter().length() ) ;
1151 else if ( IsGOTONode() && (*GOTONode()->PythonFunction()).length() &&
1152 strlen( InLineNode()->PyFuncName() ) ) {
1153 cdebug << ThreadNo() << " !ObjInterface " << Name() << " PyFuncName '"
1154 << InLineNode()->PyFuncName()
1155 << "' IsGOTONode PyDynInvoke" << endl ;
1156 StsPyDynInvoke = PyDynInvoke( InLineNode()->PyRunMethod() ,
1157 InLineNode()->PyFuncName() ,
1158 &InParametersList[0] , ServiceInParameter().length() ,
1159 &OutParametersList[0] , ServiceOutParameter().length() ) ;
1161 else if ( IsEndSwitchNode() && (*InLineNode()->PythonFunction()).length() &&
1162 strlen( InLineNode()->PyFuncName() ) ) {
1163 cdebug << ThreadNo() << " !ObjInterface " << Name() << " PyFuncName '"
1164 << InLineNode()->PyFuncName()
1165 << "' IsSwitchNode PyDynInvoke" << endl ;
1166 StsPyDynInvoke = PyDynInvoke( InLineNode()->PyRunMethod() ,
1167 InLineNode()->PyFuncName() ,
1168 &InParametersList[0] , ServiceInParameter().length() ,
1169 &OutParametersList[0] , ServiceOutParameter().length() ) ;
1171 else if ( (*InLineNode()->PythonFunction()).length() == 0 ||
1172 strlen( InLineNode()->PyFuncName() ) == 0 ) {
1173 cdebug << ThreadNo() << " !ObjInterface " << Name()
1174 << " Copy of " << ServiceInParameter().length()
1175 << " OutParameters" << endl ;
1179 if ( IsEndLoopNode() ) {
1181 argin0 = 1 ; // after DoLoop
1183 for ( i = 0 ; i < (int ) ServiceInParameter().length() ; i++ ) {
1184 OutParametersList[argout0 + i].Value = InParametersList[argin0 + i].Value ;
1186 switch ( InParametersList[argin0 + i].Value.type()->kind() ) {
1187 case CORBA::tk_string :
1188 cdebug << "ArgOut->In" << argin0 + i << " : "
1189 << InParametersList[argin0 + i].Name.c_str()
1190 << " Value(string) "
1191 << OutParametersList[argin0 + i].Name.c_str() << endl ;
1193 case CORBA::tk_double :
1194 cdebug << "ArgOut->In" << argin0 + i << " : "
1195 << InParametersList[argin0 + i].Name.c_str()
1196 << " Value(double) "
1197 << OutParametersList[argin0 + i].Name.c_str() << endl ;
1199 case CORBA::tk_long :
1200 cdebug << "ArgOut->In" << argin0 + i << " : "
1201 << InParametersList[argin0 + i].Name.c_str()
1203 << OutParametersList[ i ].Name.c_str() << endl ;
1205 case CORBA::tk_objref :
1206 cdebug << "ArgOut->In" << argin0 + i << " : "
1207 << InParametersList[argin0 + i].Name.c_str()
1208 << " Value(object reference) "
1209 << OutParametersList[argin0 + i].Name.c_str() << endl ;
1212 cdebug << "ArgOut->In" << argin0 + i << " : "
1213 << InParametersList[argin0 + i].Name.c_str()
1214 << " Value(other) ERROR "
1215 << OutParametersList[argin0 + i].Name.c_str() << endl ;
1220 if ( !StsPyDynInvoke ) {
1222 cdebug << ThreadNo() << " InLineNode " << Name()
1223 << " Python Dynamic Call Error"
1229 cdebug << ThreadNo() << " InLineNode " << Name()
1230 << " Python Dynamic Call Exception catched ERROR"
1234 _OutNode->PyThreadUnLock() ;
1239 DynInvoke( myObjComponent, "Names" ,
1240 _OutNode->Name() , Name() ) ;
1243 cdebug << "DynInvoke Names catched ERROR" << endl ;
1245 cdebug << ServiceInParameter().length() << " input parameters and "
1246 << ServiceOutParameter().length() << " output parameters" << endl ;
1247 if ( IsComputingNode() ) {
1248 cdebug << ThreadNo() << " !ObjInterface " << Name()
1249 << " IsComputingNode DynInvoke" << endl ;
1250 DynInvoke( myObjComponent,
1252 &InParametersList[1] , ServiceInParameter().length()-1 ,
1253 &OutParametersList[0] , ServiceOutParameter().length() ) ;
1255 else if ( IsFactoryNode() ) {
1256 cdebug << ThreadNo() << " !ObjInterface " << Name()
1257 << " IsFactoryNode DynInvoke" << endl ;
1258 DynInvoke( myObjComponent,
1260 &InParametersList[0] , ServiceInParameter().length() ,
1261 &OutParametersList[0] , ServiceOutParameter().length() ) ;
1266 cdebug << ThreadNo() << " !ObjInterface " << Name()
1267 << " Node(Component) Dynamic Call Exception catched ERROR"
1279 if ( ControlState() == SUPERV::ToKillState ||
1280 ControlState() == SUPERV::ToKillDoneState ||
1281 ControlState() == SUPERV::ToStopState ) {
1282 PortState = SUPERV::ErrorState ;
1283 NewState = SUPERV::KilledState ;
1284 NewEvent = GraphExecutor::KillEvent ;
1287 PortState = SUPERV::ErrorState ;
1288 NewState = SUPERV::ErroredState ;
1289 NewEvent = GraphExecutor::ErrorEvent ;
1293 PortState = SUPERV::ReadyState ;
1294 NewState = SUPERV::DataReadyState ;
1295 NewEvent = GraphExecutor::SuccessEvent ;
1298 bool ErrOut = OutParametersSet( Err , PortState , nOutParams , OutParametersList ) ;
1300 NewEvent = GraphExecutor::ErrorEvent ;
1302 delete [] InParametersList ;
1303 delete [] OutParametersList ;
1305 SendEvent( NewEvent );
1307 cdebug << ThreadNo() << " <-- DataReady_ExecuteAction " << Name() << endl;
1311 int GraphExecutor::InNode::Executing_SuspendAction() {
1312 _OutNode->PushEvent( this , GraphExecutor::SuspendedExecutingEvent ,
1313 SUPERV::SuspendedExecutingState ) ;
1314 cdebug << ThreadNo() << " Executing_SuspendAction " << Name() << endl;
1318 int GraphExecutor::InNode::SuspendedExecuting_ResumeAction() {
1319 cdebug << ThreadNo() << " SuspendedExecuting_ResumeAction " << Name() << endl;
1320 SUPERV::AutomatonState next_state ;
1321 next_state = Automaton()->NextState( State() , GraphExecutor::ExecutingEvent ) ;
1322 _OutNode->NewThread() ; // Only for Threads count
1323 _OutNode->PushEvent( this , GraphExecutor::ResumedExecutingEvent ,
1325 State( next_state ) ;
1329 int GraphExecutor::InNode::Executing_KillAction() {
1330 cdebug << ThreadNo() << " Executing_KillAction " << Name() << endl;
1332 if ( pthread_self() == ThreadNo() ) {
1333 cdebug << "Executing_KillAction would pthread_canceled itself" << endl ;
1335 _OutNode->PushEvent( this , GraphExecutor::KilledExecutingEvent ,
1336 SUPERV::KilledExecutingState ) ;
1339 else if ( pthread_cancel( ThreadNo() ) ) {
1340 perror("Executing_KillAction pthread_cancel error") ;
1343 cdebug << "Executing_KillAction : ThreadId " << ThreadNo()
1344 << " pthread_canceled" << endl ;
1346 _OutNode->ExitThread() ;
1347 _OutNode->PushEvent( this , GraphExecutor::KilledExecutingEvent ,
1348 SUPERV::KilledExecutingState ) ;
1353 int GraphExecutor::InNode::Executing_StopAction() {
1354 cdebug << ThreadNo() << " Executing_StopAction " << Name() << endl;
1356 if ( pthread_cancel( ThreadNo() ) ) {
1357 perror("Executing_KillAction pthread_cancel error") ;
1360 cdebug << "Executing_KillAction : ThreadId " << ThreadNo()
1361 << " pthread_canceled" << endl ;
1363 _OutNode->ExitThread() ;
1364 _OutNode->PushEvent( this , GraphExecutor::StoppedExecutingEvent ,
1365 SUPERV::StoppedExecutingState ) ;
1370 int GraphExecutor::InNode::Executing_SuccessAction() {
1371 cdebug << ThreadNo() << " --> Executing_SuccessAction " << Name() << endl;
1372 _OutNode->PushEvent( this , GraphExecutor::SuccessedExecutingEvent ,
1373 SUPERV::SuccessedState ) ;
1375 SUPERV::ControlState aControl = ControlState() ;
1376 switch ( aControl ) {
1377 case SUPERV::VoidState : {
1378 SendEvent( SuccessEvent ) ;
1381 case SUPERV::ToSuspendState : {
1382 SendEvent( SuccessEvent ) ;
1385 case SUPERV::ToSuspendDoneState : {
1386 SendEvent( GraphExecutor::SuspendEvent ) ;
1389 case SUPERV::ToKillState : {
1390 SendEvent( GraphExecutor::KillEvent ) ;
1393 case SUPERV::ToKillDoneState : {
1394 SendEvent( GraphExecutor::KillEvent ) ;
1397 case SUPERV::ToStopState : {
1398 SendEvent( GraphExecutor::StopEvent ) ;
1402 cdebug << ThreadNo()
1403 << " GraphExecutor::InNodeThreads::Executing_SuccessAction Error Undefined Control : "
1404 << aControl << endl ;
1408 cdebug << ThreadNo() << " <-- Executing_SuccessAction " << Name() << endl;
1412 int GraphExecutor::InNode::Executing_ErrorAction() {
1413 cdebug << ThreadNo() << " --> Executing_ErrorAction " << Name() << endl;
1414 _OutNode->PushEvent( this , GraphExecutor::ErroredExecutingEvent ,
1415 SUPERV::ErroredState ) ;
1418 SUPERV::ControlState aControl = ControlState() ;
1419 switch ( aControl ) {
1420 case SUPERV::VoidState : {
1421 SendEvent( ErrorEvent ) ;
1424 case SUPERV::ToSuspendState : {
1425 SendEvent( ErrorEvent ) ;
1428 case SUPERV::ToSuspendDoneState : {
1429 SendEvent( GraphExecutor::SuspendEvent ) ;
1432 case SUPERV::ToKillState : {
1433 SendEvent( GraphExecutor::KillEvent ) ;
1436 case SUPERV::ToKillDoneState : {
1437 SendEvent( GraphExecutor::KillEvent ) ;
1440 case SUPERV::ToStopState : {
1441 SendEvent( GraphExecutor::StopEvent ) ;
1445 cdebug << ThreadNo()
1446 << " GraphExecutor::InNodeThreads::Executing_ErrorAction Error Undefined Control : "
1447 << aControl << endl ;
1451 cdebug << ThreadNo() << " <-- Executing_ErrorAction " << Name() << endl;
1455 // Set SUPERV::WaitingState to all InPorts
1456 void GraphExecutor::InNode::SetWaitingStates(GraphExecutor::InNode * EndNode ) {
1459 bool docdebug = false ;
1460 State( SUPERV::DataWaitingState ) ;
1461 for ( i = 0 ; i < GetNodeInPortsSize() ; i++ ) {
1462 GraphBase::InPort * anInPort = GetChangeNodeInPort( i ) ;
1463 if ( anInPort->IsGate() ) { // Loop : Open the doors
1464 GraphBase::OutPort * anOutPort = anInPort->GetOutPort() ;
1466 CORBA::Any * anAny = new CORBA::Any() ;
1467 *anAny <<= (long ) 1 ;
1468 anOutPort->Value( anAny ) ;
1469 anInPort->State( SUPERV::ReadyState ) ;
1472 else if ( anInPort->State() != SUPERV::WaitingState ) {
1474 cdebug << ThreadNo()
1475 << " --> GraphExecutor::InNodeThreads::SetWaitingStates " << Name() << endl;
1478 anInPort->State( SUPERV::WaitingState ) ;
1481 for ( i = 0 ; i < GetNodeOutPortsSize() ; i++ ) {
1482 for ( j = 0 ; j < GetChangeNodeOutPort( i )->InPortsSize() ; j++ ) {
1483 GraphBase::OutPort * anOutPort = GetChangeNodeOutPort( i ) ;
1484 // if ( !( IsGOTONode() && i == 0 ) && !( IsEndLoopNode() && i <= 1 ) ) {
1485 if ( !( IsGOTONode() && anOutPort->IsGate() ) &&
1486 !( IsEndLoopNode() && ( anOutPort->IsGate() || anOutPort->IsLoop() ) ) ) {
1487 GraphExecutor::InNode * aNode = (GraphExecutor::InNode * ) _OutNode->GetChangeGraphNode( anOutPort->ChangeInPorts( j )->NodeName() )->GetInNode() ;
1488 if ( aNode != EndNode ) {
1489 aNode->SetWaitingStates( EndNode ) ;
1496 int GraphExecutor::InNode::Successed_SuccessAction() {
1497 cdebug << ThreadNo() << " --> Successed_SuccessAction " << Name() << endl;
1499 int linkednodesnumber = LinkedNodesSize() ;
1500 GraphExecutor::InNode *firstzeroNode = NULL ;
1501 GraphExecutor::InNode *firsttoNode = NULL ;
1502 GraphExecutor::InNode *toNode ;
1505 list<GraphExecutor::InNode *> SomeDataNodes ;
1509 if ( IsGOTONode() ||
1510 ( IsEndLoopNode() && GetNodeInLoop()->GetOutPort()->BoolValue() ) ) {
1511 const GraphBase::OutPort * aGateOutPort ;
1512 if ( IsGOTONode() ) {
1513 aGateOutPort = GetNodeOutGate() ;
1516 aGateOutPort = GetNodeOutLoop() ;
1518 for ( i = 0 ; i < aGateOutPort->InPortsSize() ; i++ ) {
1519 const GraphBase::InPort * anInPort = aGateOutPort->InPorts( i ) ;
1520 GraphExecutor::InNode * aLabelNode = (GraphExecutor::InNode *) _OutNode->GetChangeGraphNode( anInPort->NodeName() )->GetInNode() ;
1521 cdebug << ThreadNo() << " Successed_SuccessAction " << Name() << " will Loop to HeadNode "
1522 << aLabelNode->Name() << " from port " << anInPort->PortName() << endl ;
1523 aLabelNode->SetWaitingStates( this ) ;
1524 for ( j = 0 ; j < aLabelNode->GetNodeInPortsSize() ; j++ ) {
1525 const GraphBase::InPort * anInPort = aLabelNode->GetNodeInPort( j ) ;
1526 if ( anInPort->GetOutPort() ) {
1527 cdebug << aLabelNode->Name() << "(" << anInPort->PortName() << ") value : "
1528 << anInPort->GetOutPort()->NodeName() << "(" << anInPort->GetOutPort()->PortName() << ")"
1532 for ( j = 0 ; j < GetNodeOutPortsSize() ; j++ ) {
1533 GraphBase::OutPort * aBusParamOutPort = GetChangeNodeOutPort( j ) ;
1534 if ( !aBusParamOutPort->IsGate() ) {
1535 GraphBase::InPort * aBusParamChangeInPort = NULL ;
1536 if ( aBusParamOutPort->IsLoop() ) {
1537 aBusParamChangeInPort = aLabelNode->GetChangeNodeInLoop() ;
1540 aBusParamChangeInPort = aLabelNode->GetChangeInPort( aBusParamOutPort->PortName() ) ;
1542 if ( aBusParamChangeInPort ) {
1543 aBusParamChangeInPort->ChangeOutPort( aBusParamOutPort ) ;
1544 cdebug << ThreadNo() << " Successed_SuccessAction " << Name() << " ChangeOutPort to HeadNode "
1545 << aLabelNode->Name() << "(" << aBusParamChangeInPort->PortName() << ") from port "
1546 << aBusParamOutPort->PortName() << endl ;
1547 if ( !aLabelNode->IsLockedDataWait() ) {
1548 res = aLabelNode->SendSomeDataReady( Name() ) ;
1550 if ( firsttoNode == NULL &&
1551 aLabelNode->ThreadNo() == pthread_self() ) {
1552 firsttoNode = aLabelNode ;
1553 cdebug << ThreadNo() << " Successed_SuccessAction firsttoNode "
1554 << aLabelNode->Name() << endl ;
1556 else if ( firstzeroNode == NULL &&
1557 aLabelNode->ThreadNo() == 0 ) {
1558 firstzeroNode = aLabelNode ;
1561 SomeDataNodes.push_back( aLabelNode ) ;
1562 cdebug << ThreadNo() << " Successed_SuccessAction push "
1563 << SomeDataNodes.size() << " " << aLabelNode->Name()
1569 cdebug << ThreadNo()
1570 << " Successed_SuccessAction Loop to HeadNode "
1571 << aLabelNode->Name() << " with datas from " << Name() << "("
1572 << aBusParamOutPort->PortName() << ") to port "
1573 << aBusParamChangeInPort->PortName() << endl;
1577 cdebug << ThreadNo() << " ERROR in Successed_SuccessAction of " << Name()
1578 << " NO port " << aBusParamOutPort->PortName() << " in "
1579 << aLabelNode->Name() << endl;
1583 for ( j = 0 ; j < aLabelNode->GetNodeInPortsSize() ; j++ ) {
1584 const GraphBase::InPort * anInPort = aLabelNode->GetNodeInPort( j ) ;
1585 if ( anInPort->GetOutPort() ) {
1586 cdebug << aLabelNode->Name() << "(" << anInPort->PortName() << ") value : "
1587 << anInPort->GetOutPort()->NodeName() << "(" << anInPort->GetOutPort()->PortName() << ")"
1591 // const GraphBase::OutPort * aGateOutPort = GetNodeOutPort( 0 ) ; // DoLoop or OutGate
1592 const GraphBase::InPort * aGateInPort = aLabelNode->GetNodeInGate() ;
1593 if ( aGateInPort ) {
1594 if ( aGateInPort->GetOutPort() ) {
1595 aGateInPort->GetOutPort()->Value( aGateOutPort->Value() ) ;
1597 if ( !aLabelNode->IsLockedDataWait() ) {
1598 res = aLabelNode->SendSomeDataReady( Name() ) ;
1600 if ( firsttoNode == NULL &&
1601 aLabelNode->ThreadNo() == pthread_self() ) {
1602 firsttoNode = aLabelNode ;
1603 cdebug << ThreadNo() << " Successed_SuccessAction firsttoNode "
1604 << aLabelNode->Name() << endl ;
1606 else if ( firstzeroNode == NULL &&
1607 aLabelNode->ThreadNo() == 0 ) {
1608 firstzeroNode = aLabelNode ;
1611 SomeDataNodes.push_back( aLabelNode ) ;
1612 cdebug << ThreadNo() << " Successed_SuccessAction push "
1613 << SomeDataNodes.size() << " " << aLabelNode->Name()
1620 cdebug << ThreadNo() << " ERROR in Successed_SuccessAction of " << Name()
1621 << " NO port " << aGateOutPort->PortName() << " in "
1622 << aLabelNode->Name() << endl;
1628 cdebug << ThreadNo() << " Successed_SuccessAction of " << Name()
1629 << " with " << LinkedNodesSize() << " linked nodes :" ;
1630 for ( i = 0 ; i < LinkedNodesSize() ; i++ ) {
1631 if ( LinkedNodes( i )->IsDataFlowNode() ) {
1632 linkednodesnumber -= 1 ;
1634 cdebug << " " << LinkedNodes( i )->Name() ;
1637 // SUPERV::ControlState aControl = ControlState() ;
1638 for ( i = 0 ; i < LinkedNodesSize() ; i++ ) {
1639 bool IgnoreForEndLoop = false ;
1640 toNode = (GraphExecutor::InNode *) LinkedNodes( i )->GetInNode() ;
1641 cdebug << ThreadNo() << " Successed_SuccessAction of " << Name()
1642 << " [" << i << "] " << LinkedNodes( i )->Name() << endl ;
1643 if ( toNode && !toNode->IsDataFlowNode() ) {
1644 if ( IsComputingNode() && toNode->IsInLineNode() ) {
1645 GraphBase::InPort * toGateInPort = toNode->GetChangeNodeInGate() ;
1646 toGateInPort->State( SUPERV::ReadyState ) ;
1647 GraphBase::OutPort * GateOutPort = toGateInPort->GetOutPort() ;
1648 if ( GateOutPort ) {
1649 GateOutPort->PortStatus( DataConnected );
1650 GateOutPort->State( SUPERV::ReadyState ) ;
1651 GateOutPort->Done( true ) ;
1655 if ( toNode && IsLoopNode() ) {
1656 GraphBase::OutPort * fromLoopOutPort = GetChangeNodeOutLoop() ;
1657 if ( !fromLoopOutPort->BoolValue() ) { // Ne pas faire la boucle
1658 if ( strcmp( toNode->Name() , CoupledNode()->Name() ) ) {
1659 IgnoreForEndLoop = true ;
1661 else { // toNode is the EndLoopNode
1662 GraphBase::InPort * toLoopInPort ;
1663 // toLoopInPort = toNode->GetChangeNodeInPort(1) ;
1664 toLoopInPort = toNode->GetChangeNodeInLoop() ;
1665 if ( toLoopInPort->State() != SUPERV::ReadyState ) {
1666 toLoopInPort->State( SUPERV::ReadyState ) ;
1671 else if ( toNode && IsSwitchNode() ) {
1673 else if ( toNode && toNode->IsInLineNode() ) {
1675 for ( j = 0 ; j < toNode->GetNodeInPortsSize() ; j++ ) {
1676 toNode->GetChangeNodeInPort( j )->InitialOutPort() ;
1679 if ( toNode && !IgnoreForEndLoop ) {
1680 if ( toNode && toNode->IsLoopNode() ) {
1681 // GraphBase::InPort * toLoopInPort = toNode->GetChangeNodeInPort(1) ;
1682 GraphBase::InPort * toLoopInPort = toNode->GetChangeNodeInLoop() ;
1683 toLoopInPort->State( SUPERV::ReadyState ) ;
1684 GraphBase::OutPort * LoopOutPort = toLoopInPort->GetOutPort() ;
1685 LoopOutPort->PortStatus( DataConnected );
1686 LoopOutPort->State( SUPERV::ReadyState ) ;
1687 LoopOutPort->Done( true ) ;
1688 CORBA::Any * anAny = new CORBA::Any() ;
1689 *anAny <<= (long ) 1 ;
1690 LoopOutPort->Value( anAny ) ;
1692 for ( j = 0 ; j < toNode->GetNodeInPortsSize() ; j++ ) {
1693 toNode->GetChangeNodeInPort( j )->InitialOutPort() ;
1696 res = toNode->SendSomeDataReady( Name() ) ;
1698 if ( firsttoNode == NULL &&
1699 toNode->ThreadNo() == pthread_self() ) {
1700 firsttoNode = toNode ;
1701 cdebug << ThreadNo() << " Successed_SuccessAction firsttoNode "
1702 << toNode->Name() << endl ;
1704 else if ( firstzeroNode == NULL &&
1705 toNode->ThreadNo() == 0 ) {
1706 firstzeroNode = toNode ;
1709 SomeDataNodes.push_back( toNode ) ;
1710 cdebug << ThreadNo() << " Successed_SuccessAction push "
1711 << SomeDataNodes.size() << " " << toNode->Name() << endl ;
1718 if ( firsttoNode == NULL && firstzeroNode ) {
1719 firsttoNode = firstzeroNode ;
1720 cdebug << ThreadNo()
1721 << " Successed_SuccessAction firsttoNode = firstzeroNode "
1724 else if ( firsttoNode && firstzeroNode ) {
1725 SomeDataNodes.push_back( firstzeroNode ) ;
1726 cdebug << ThreadNo() << " Successed_SuccessAction push firstzeroNode "
1727 << SomeDataNodes.size() << " " << firstzeroNode->Name() << endl ;
1730 while ( SomeDataNodes.size() ) {
1731 GraphExecutor::InNode *aNode = SomeDataNodes.front() ;
1732 SomeDataNodes.pop_front() ;
1733 cdebug << pthread_self() << "/" << ThreadNo()
1734 << " Successed_SuccessAction pop "
1735 << SomeDataNodes.size() << " " << aNode->Name() << endl ;
1736 if ( aNode->State() == SUPERV::DataReadyState ) {
1737 aNode->CreateNewThreadIf( true ) ;
1738 aNode->UnLockDataWait() ;
1739 res = aNode->DataUndef_AllDataReadyAction() ;
1742 cdebug << pthread_self() << "/" << ThreadNo() << " ERROR "
1743 << aNode->Name() << " "
1744 << Automaton()->StateName( aNode->State() ) << endl ;
1748 if ( firsttoNode ) {
1749 // firsttoNode = SomeDataNodes.front() ;
1750 // SomeDataNodes.pop_front() ;
1751 cdebug << pthread_self() << "/" << ThreadNo()
1752 << " Successed_SuccessAction pop firsttoNode "
1753 << SomeDataNodes.size() << " " << firsttoNode->Name() << endl ;
1754 firsttoNode->CreateNewThreadIf( false ) ;
1755 firsttoNode->RewindStack( RewindStack() ) ;
1756 if ( firsttoNode->State() == SUPERV::SuccessedState ) {
1757 cdebug << pthread_self() << "/" << ThreadNo() << " " << Name()
1758 << " : " << firsttoNode->Name() << " "
1759 << Automaton()->StateName( firsttoNode->State() )
1760 << " --> DataWaitingState for Thread "
1761 << firsttoNode->ThreadNo() << endl ;
1762 firsttoNode->State( SUPERV::DataWaitingState ) ;
1764 pthread_t OldT = firsttoNode->ThreadNo() ;
1765 firsttoNode->ThreadNo( pthread_self() ) ;
1766 // On continue avec le meme thread
1767 cdebug << pthread_self() << "/" << ThreadNo() << " firsttoNode "
1768 << firsttoNode->Name() << "Thread(" << OldT << "-->"
1769 << firsttoNode->ThreadNo() << ")" << endl ;
1771 cdebug << ThreadNo() << " Successed_SuccessAction " << Name()
1772 << " for " << firsttoNode->Name()
1773 << " !firsttoNode->CreateNewThreadIf() "
1774 << !firsttoNode->CreateNewThreadIf()
1775 << " " << Automaton()->StateName( firsttoNode->State() ) ;
1776 if ( firsttoNode->State() == SUPERV::DataReadyState ) {
1778 firsttoNode->UnLockDataWait() ;
1779 res = firsttoNode->DataUndef_AllDataReadyAction() ;
1782 cdebug << " ERROR " << endl ;
1786 cdebug << ThreadNo() << " Successed_SuccessAction " << Name()
1787 << " NO DataReady ==> ThreadNo( 0 )" << endl ;
1791 if ( linkednodesnumber == 0 ) {
1792 _OutNode->CheckAllDone() ;
1795 cdebug << pthread_self() << "/" << ThreadNo()
1796 << " <-- Successed_SuccessAction " << Name() << " linkednodesnumber "
1797 << linkednodesnumber << endl;
1801 bool GraphExecutor::InNode::SendSomeDataReady( char * FromNodeName ) {
1802 bool RetVal = false ;
1803 if ( IsDataFlowNode() ) {
1804 cdebug << ThreadNo() << " ----> " << Name()
1805 << " send Result to graph " << Name() << endl;
1808 cdebug << pthread_self() << "/" << ThreadNo() << " ----> " << FromNodeName
1809 << " send SomeDataReady to " << Name() << " "
1810 << Automaton()->StateName( State() )
1811 << " CreateNewThreadIf() " << CreateNewThreadIf()
1812 << " LockedDataWait " << IsLockedDataWait() << endl;
1814 cout << pthread_self() << "/" << ThreadNo() << " ----> " << FromNodeName
1815 << " send SomeDataReady to " << Name() << " "
1816 << Automaton()->StateName( State() )
1817 << " CreateNewThreadIf() " << CreateNewThreadIf()
1818 << " LockedDataWait " << IsLockedDataWait() << endl;
1820 if ( State() == SUPERV::SuccessedState ||
1821 State() == SUPERV::SuspendedSuccessedState ||
1822 State() == SUPERV::SuspendedSuccessedToReStartState ) {
1823 cdebug << ThreadNo() << " " << FromNodeName
1824 << " : " << Name() << " " << Automaton()->StateName( State() )
1825 << " --> DataWaitingState for Thread "
1826 << ThreadNo() << " " << endl ;
1827 State( SUPERV::DataWaitingState ) ;
1830 DataFromNode( FromNodeName ) ;
1831 RetVal = !SendEvent( GraphExecutor::SomeDataReadyEvent );
1839 int GraphExecutor::InNode::Errored_ErrorAction() {
1840 cdebug << ThreadNo() << " Errored_ErrorAction " << Name()
1841 << " will pthread_exit" << endl;
1846 int GraphExecutor::InNode::Successed_SuspendAction() {
1847 cdebug << ThreadNo() << " Successed_SuspendAction -->Suspend " << Name()
1848 << " Threads " << _OutNode->Threads() << " SuspendedThreads "
1849 << _OutNode->SuspendedThreads() << endl;
1850 _OutNode->PushEvent( this , GraphExecutor::SuspendedSuccessedEvent ,
1851 SUPERV::SuspendedSuccessedState ) ;
1853 GraphExecutor::InNode * aReStartNode = SuspendAction() ;
1854 cdebug << ThreadNo() << " Successed_SuspendAction Resumed " << Name() ;
1855 if ( aReStartNode ) {
1856 _aReStartNode = NULL ;
1857 cdebug << " for " << aReStartNode->Name() << endl;
1858 aReStartNode->SendEvent( _aReStartEvent ) ;
1862 SendEvent( GraphExecutor::ResumeEvent ) ;
1867 int GraphExecutor::InNode::Errored_SuspendAction() {
1868 cdebug << ThreadNo() << " Errored_SuspendAction -->Suspend " << Name()
1869 << " Threads " << _OutNode->Threads() << " SuspendedThreads "
1870 << _OutNode->SuspendedThreads() << endl;
1871 _OutNode->PushEvent( this , GraphExecutor::SuspendedErroredEvent ,
1872 SUPERV::SuspendedErroredState ) ;
1874 GraphExecutor::InNode * aReStartNode = SuspendAction() ;
1875 cdebug << ThreadNo() << " Errored_SuspendAction Resumed " << Name()
1877 if ( aReStartNode ) {
1878 _aReStartNode = NULL ;
1879 aReStartNode->SendEvent( _aReStartEvent ) ;
1882 SendEvent( GraphExecutor::ResumeEvent ) ;
1887 int GraphExecutor::InNode::SuspendedSuccessed_ResumeAction() {
1888 cdebug << ThreadNo() << " SuspendedSuccessed_ResumeAction " << Name() << endl;
1890 _OutNode->PushEvent( this , GraphExecutor::ResumedSuccessedEvent ,
1891 SUPERV::ResumedSuccessedState ) ;
1892 SendEvent( ResumedSuccessedEvent ) ;
1896 int GraphExecutor::InNode::SuspendedErrored_ResumeAction() {
1897 cdebug << ThreadNo() << " SuspendedErrored_ResumeAction " << Name() << endl;
1899 _OutNode->PushEvent( this , GraphExecutor::ResumedErroredEvent ,
1900 SUPERV::ResumedErroredState ) ;
1901 SendEvent( ResumedErroredEvent ) ;
1905 int GraphExecutor::InNode::Successed_KillAction() {
1907 _OutNode->PushEvent( this , GraphExecutor::KilledEvent ,
1908 SUPERV::KilledSuccessedState ) ;
1909 cdebug << ThreadNo() << " Successed_KillAction " << Name() << endl;
1913 int GraphExecutor::InNode::Errored_KillAction() {
1915 _OutNode->PushEvent( this , GraphExecutor::KilledEvent ,
1916 SUPERV::KilledErroredState ) ;
1917 cdebug << ThreadNo() << " Errored_KillAction " << Name() << endl;
1921 int GraphExecutor::InNode::Successed_StopAction() {
1923 _OutNode->PushEvent( this , GraphExecutor::StoppedEvent ,
1924 SUPERV::StoppedSuccessedState ) ;
1925 cdebug << ThreadNo() << " Successed_StopAction " << Name() << endl;
1929 int GraphExecutor::InNode::Errored_StopAction() {
1931 _OutNode->PushEvent( this , GraphExecutor::StoppedEvent ,
1932 SUPERV::StoppedErroredState ) ;
1933 cdebug << ThreadNo() << " Errored_StopAction " << Name() << endl;
1937 int GraphExecutor::InNode::SuspendedSuccessed_ReStartAction() {
1938 cdebug << ThreadNo() << " SuspendedSuccessed_ReStartAction " << Name() << endl;
1939 _OutNode->PushEvent( this , GraphExecutor::ReStartedEvent ,
1940 SUPERV::ReStartedState ) ;
1942 for ( i = 0 ; i < GetNodeInPortsSize() ; i++ ) {
1943 GetChangeNodeInPort( i )->State( SUPERV::ReadyState ) ;
1945 SendEvent( ExecuteEvent ) ;
1946 cdebug << ThreadNo() << " SuspendedSuccessed_ReStartAction " << Name() << endl;
1950 int GraphExecutor::InNode::SuspendedErrored_ReStartAction() {
1951 cdebug << ThreadNo() << " SuspendedErrored_ReStartAction " << Name() << endl;
1952 _OutNode->PushEvent( this , GraphExecutor::ReStartedEvent ,
1953 SUPERV::ReStartedState ) ;
1955 for ( i = 0 ; i < GetNodeInPortsSize() ; i++ ) {
1956 GetChangeNodeInPort( i )->State( SUPERV::ReadyState ) ;
1958 SendEvent( ExecuteEvent ) ;
1959 cdebug << ThreadNo() << " SuspendedErrored_ReStartAction " << Name() << endl;
1963 int GraphExecutor::InNode::SuspendedSuccessed_ReStartAndSuspendAction() {
1964 cdebug << ThreadNo() << " SuspendedSuccessed_ReStartAndSuspendAction " << Name()
1966 _OutNode->PushEvent( this , GraphExecutor::ReStartedAndSuspendEvent ,
1967 SUPERV::ReStartedState ) ;
1968 State( SUPERV::DataWaitingState ) ;
1970 cdebug << "InNode::Suspend() Node " << Name() << endl ;
1973 else if ( SendEvent( GraphExecutor::SomeDataReadyEvent ) ) {
1974 cdebug << "InNode::SendEvent( SomeDataReadyEvent ) Node "
1978 cdebug << ThreadNo() << " SuspendedSuccessed_ReStartAndSuspendAction " << Name()
1983 int GraphExecutor::InNode::SuspendedErrored_ReStartAndSuspendAction() {
1984 cdebug << ThreadNo() << " SuspendedErrored_ReStartAndSuspendAction " << Name()
1986 _OutNode->PushEvent( this , GraphExecutor::ReStartedAndSuspendEvent ,
1987 SUPERV::ReStartedState ) ;
1988 State( SUPERV::DataWaitingState ) ;
1990 cdebug << "InNode::Suspend() Node " << Name() << endl ;
1993 else if ( SendEvent( GraphExecutor::SomeDataReadyEvent ) ) {
1994 cdebug << "InNode::SendEvent( SomeDataReadyEvent ) Node "
1998 cdebug << ThreadNo() << " SuspendedErrored_ReStartAndSuspendAction " << Name()
2003 void GraphExecutor::InNode::InParametersSet(
2006 ServicesAnyData * InParametersList ) {
2008 for ( i = 0 ; i < nInParams ; i++ ) {
2009 ServicesAnyData D = InParametersList[i];
2010 GraphBase::InPort * anInPort = GetChangeNodeInPort(i) ;
2011 GraphBase::OutPort * theOutPort = anInPort->GetOutPort() ;
2012 if ( anInPort->IsGate() && theOutPort == NULL ) {
2013 cdebug << ThreadNo() << " ArgIn" << i << " " << D.Name << " "
2014 << anInPort->GetServicesParameter().Parametertype
2015 << " is inactive. " << anInPort->Kind() << endl ;
2017 else if ( anInPort->State() == SUPERV::ReadyState ) {
2018 if ( anInPort->IsGate() ) {
2019 CORBA::Any * anAny = new CORBA::Any() ;
2020 *anAny <<= (long ) 0 ;
2021 theOutPort->Value( anAny ) ;
2023 anInPort->State( SUPERV::WaitingState ) ;
2024 D.Name = CORBA::string_dup( anInPort->GetServicesParameter().Parametername ) ;
2025 cdebug << ThreadNo() << " ArgIn" << i << " " << anInPort->Kind() ;
2026 cdebug << " " << D.Name << " " << anInPort->GetServicesParameter().Parametertype << " : " ;
2027 D.Value = *theOutPort->Value() ; // CORBA::Any
2028 string _Type = CORBA::string_dup( anInPort->GetServicesParameter().Parametertype ) ;
2029 const char * Type = _Type.c_str() ;
2030 switch ( D.Value.type()->kind() ) { // { string , long , double , objref }
2031 case CORBA::tk_string:
2034 cdebug << t << " (string)" ;
2035 if ( !strcmp( Type , "string" ) ) {
2037 else if ( !strcmp( Type , "boolean" ) ) {
2040 sscanf( t , "%ld" , &d ) ;
2042 D.Value <<= (CORBA::Any::from_boolean ) b ;
2043 // theOutPort->Value( D.Value ) ;
2045 else if ( !strcmp( Type , "char" ) ) {
2048 sscanf( t , "%ld" , &d ) ;
2050 D.Value <<= (CORBA::Any::from_char ) c ;
2051 cdebug << "string '" << t << "' --> " << d << " --> char " << c ;
2052 // theOutPort->Value( D.Value ) ;
2054 else if ( !strcmp( Type , "short" ) ) {
2057 sscanf( t , "%ld" , &d ) ;
2060 cdebug << "string '" << t << "' --> " << d << " --> short " << s ;
2061 // theOutPort->Value( D.Value ) ;
2063 else if ( !strcmp( Type , "int" ) || !strcmp( Type , "long" ) ) {
2065 sscanf( t , "%ld" , &l ) ;
2067 cdebug << "string '" << t << " --> long " << l ;
2068 // theOutPort->Value( D.Value ) ;
2070 else if ( !strcmp( Type , "float" ) ) {
2072 sscanf( t , "%lf" , &d ) ;
2075 cdebug << "string '" << t << "' --> " << setw(25) << setprecision(18) << d << " --> float " << " = "
2076 << setw(25) << setprecision(18) << f ;
2077 // theOutPort->Value( D.Value ) ;
2079 else if ( !strcmp( Type , "double" ) ) {
2081 sscanf( t , "%lf" , &d ) ;
2083 cdebug << "string '" << t << " --> double " << setw(25) << setprecision(18) << d ;
2084 // theOutPort->Value( D.Value ) ;
2086 // else if ( !strcmp( Type , "objref" ) ) {
2088 CORBA::Object_ptr ObjRef ;
2090 ObjRef = StringToObject( t ) ;
2091 D.Value <<= ObjRef ;
2094 D.Value <<= CORBA::Object::_nil() ;
2096 // theOutPort->Value( D.Value ) ;
2099 // cdebug << " (other ERROR)" << endl ;
2101 cdebug << " --> call_kind " << D.Value.type()->kind() << endl ;
2103 case CORBA::tk_long:
2106 cdebug << l << " (long)" << endl ;
2107 if ( !strcmp( Type , "string" ) ) {
2109 sprintf( t , "%ld" , l ) ;
2111 // theOutPort->Value( D.Value ) ;
2113 else if ( !strcmp( Type , "boolean" ) ) {
2116 D.Value <<= (CORBA::Any::from_boolean ) b ;
2117 // theOutPort->Value( D.Value ) ;
2119 else if ( !strcmp( Type , "char" ) ) {
2121 c = (unsigned char ) l ;
2122 D.Value <<= (CORBA::Any::from_char ) c ;
2123 // theOutPort->Value( D.Value ) ;
2125 else if ( !strcmp( Type , "short" ) ) {
2129 // theOutPort->Value( D.Value ) ;
2131 else if ( !strcmp( Type , "int" ) || !strcmp( Type , "long" ) ) {
2133 else if ( !strcmp( Type , "float" ) ) {
2137 // theOutPort->Value( D.Value ) ;
2139 else if ( !strcmp( Type , "double" ) ) {
2143 // theOutPort->Value( D.Value ) ;
2145 // else if ( !strcmp( Type , "objref" ) ) {
2147 D.Value <<= CORBA::Object::_nil() ;
2148 // theOutPort->Value( D.Value ) ;
2151 // cdebug << " (other ERROR)" << endl ;
2153 cdebug << " --> call_kind " << D.Value.type()->kind() << endl ;
2155 case CORBA::tk_double:
2158 cdebug << d << " (double)" << endl ;
2159 if ( !strcmp( Type , "string" ) ) {
2161 sprintf( t , "%lf" , d ) ;
2163 // theOutPort->Value( D.Value ) ;
2165 else if ( !strcmp( Type , "boolean" ) ) {
2168 D.Value <<= (CORBA::Any::from_boolean ) b ;
2169 // theOutPort->Value( D.Value ) ;
2171 else if ( !strcmp( Type , "char" ) ) {
2173 c = (unsigned char ) d ;
2174 D.Value <<= (CORBA::Any::from_char ) c ;
2175 // theOutPort->Value( D.Value ) ;
2177 else if ( !strcmp( Type , "short" ) ) {
2181 // theOutPort->Value( D.Value ) ;
2183 else if ( !strcmp( Type , "int" ) || !strcmp( Type , "long" ) ) {
2187 // theOutPort->Value( D.Value ) ;
2189 else if ( !strcmp( Type , "float" ) ) {
2193 // theOutPort->Value( D.Value ) ;
2195 else if ( !strcmp( Type , "double" ) ) {
2197 // else if ( !strcmp( Type , "objref" ) ) {
2199 D.Value <<= CORBA::Object::_nil() ;
2200 // theOutPort->Value( D.Value ) ;
2203 // cdebug << " (other ERROR)" << endl ;
2205 cdebug << " --> call_kind " << D.Value.type()->kind() << endl ;
2207 case CORBA::tk_objref:
2208 if ( !strcmp( Type , "string" ) ) {
2209 CORBA::Object_ptr ObjRef ;
2212 D.Value >>= ObjRef ;
2213 retstr = ObjectToString( ObjRef ) ;
2214 D.Value <<= retstr ;
2215 // theOutPort->Value( D.Value ) ;
2221 cdebug << "ToString( object ) Catched ERROR" << endl ;
2224 else if ( !strcmp( Type , "boolean" ) ) {
2226 D.Value <<= (CORBA::Any::from_boolean ) b ;
2227 // theOutPort->Value( D.Value ) ;
2229 else if ( !strcmp( Type , "char" ) ) {
2230 unsigned char c = 0 ;
2231 D.Value <<= (CORBA::Any::from_char ) c ;
2232 // theOutPort->Value( D.Value ) ;
2234 else if ( !strcmp( Type , "short" ) ) {
2237 // theOutPort->Value( D.Value ) ;
2239 else if ( !strcmp( Type , "int" ) || !strcmp( Type , "long" ) ) {
2242 // theOutPort->Value( D.Value ) ;
2244 else if ( !strcmp( Type , "float" ) ) {
2247 // theOutPort->Value( D.Value ) ;
2249 else if ( !strcmp( Type , "double" ) ) {
2252 // theOutPort->Value( D.Value ) ;
2254 // else if ( !strcmp( Type , "objref" ) ) {
2256 CORBA::Object_ptr obj ;
2260 retstr = ObjectToString( obj ) ;
2261 cdebug << retstr << endl ;
2267 cdebug << "ToString( object ) Catched ERROR" << endl ;
2271 // cdebug << " (other ERROR)" << endl ;
2273 cdebug << " --> call_kind " << D.Value.type()->kind() << endl ;
2276 cdebug << " (other ERROR) " << D.Value.type()->kind() << endl ;
2280 cdebug << ThreadNo() << " In" << i << " : wrong state ERROR State "
2281 << anInPort->State() << " NameState "
2282 << Automaton()->StateName( anInPort->State() ) << " PortName "
2283 << anInPort->PortName() << " Parametername "
2284 << anInPort->GetServicesParameter().Parametername << endl ;
2287 InParametersList[i] = D ;
2291 void GraphExecutor::InNode::InOutParametersSet(
2293 ServicesAnyData * OutParametersList ) {
2295 for ( i = 0 ; i < nOutParams ; i++ ) {
2296 ServicesAnyData D = OutParametersList[i] ;
2298 D.Name = GetChangeNodeOutPort(i)->GetServicesParameter().Parametername;
2299 string _Type = CORBA::string_dup(GetChangeNodeOutPort(i)->GetServicesParameter().Parametertype) ;
2300 const char * Type = _Type.c_str() ;
2301 bool OutDone = GetChangeNodeOutPort(i)->Done() ;
2302 cdebug << ThreadNo() << " ArgOut" << i << " " << D.Name << " Done("
2303 << OutDone << ") " << Type << " : " << endl ;
2304 if ( !strcmp( Type , "string" ) ) {
2305 D.Value <<= (char *) NULL ;
2307 else if ( !strcmp( Type , "boolean" ) ) {
2309 D.Value <<= (CORBA::Any::from_boolean ) b ;
2311 else if ( !strcmp( Type , "char" ) ) {
2312 unsigned char c = 0 ;
2313 D.Value <<= (CORBA::Any::from_char ) c ;
2315 else if ( !strcmp( Type , "short" ) ) {
2319 else if ( !strcmp( Type , "int" ) || !strcmp( Type , "long" ) ) {
2320 D.Value <<= (long ) 0 ;
2322 else if ( !strcmp( Type , "float" ) ) {
2326 else if ( !strcmp( Type , "double" ) ) {
2331 D.Value <<= CORBA::Object::_nil() ;
2334 switch (D.Value.type()->kind()) { // { string , long , double , objref }
2335 case CORBA::tk_string:
2338 cdebug << ThreadNo() << " " << t << "(string)" << endl ;
2340 case CORBA::tk_boolean:
2342 D.Value >>= (CORBA::Any::to_boolean ) b;
2343 cdebug << ThreadNo() << " " << b << "(boolean)" << endl ;
2345 case CORBA::tk_char:
2347 D.Value >>= (CORBA::Any::to_char ) c;
2348 cdebug << ThreadNo() << " " << c << "(char)" << endl ;
2350 case CORBA::tk_short:
2353 cdebug << ThreadNo() << " " << s << "(short)" << endl ;
2355 case CORBA::tk_long:
2358 cdebug << ThreadNo() << " " << l << "(long)" << endl ;
2360 case CORBA::tk_float:
2363 cdebug << ThreadNo() << " " << f << "(float)" << endl ;
2365 case CORBA::tk_double:
2368 cdebug << ThreadNo() << " " << d << "(double)" << endl ;
2370 case CORBA::tk_objref:
2372 CORBA::Object_ptr obj ;
2375 retstr = ObjectToString( obj ) ;
2376 cdebug << ThreadNo() << retstr << endl ;
2379 cdebug << "ToString( object ) Catched ERROR" << endl ;
2383 cdebug << ThreadNo() << " " << "(other ERROR)" << endl ;
2386 OutParametersList[i] = D ;
2390 bool GraphExecutor::InNode::OutParametersSet(
2392 SUPERV::GraphState NewState ,
2394 ServicesAnyData * OutParametersList ) {
2395 bool RetVal = true ;
2397 GraphBase::OutPort * aGateOutPort = NULL ;
2398 bool OrSwitch = false ;
2400 GraphBase::OutPort * anOutPort ;
2401 for ( i = 0 ; i < nOutParams ; i++ ) {
2402 anOutPort = GetChangeNodeOutPort(i) ;
2404 anOutPort->State( NewState ) ;
2405 anOutPort->Done( true ) ;
2408 cdebug << ThreadNo() << " " << "Out" << i << " " << Name() << " "
2409 << anOutPort->PortName() << " " << anOutPort->Kind() ;
2410 ServicesAnyData D = OutParametersList[i] ;
2411 switch (D.Value.type()->kind()) { // { string , long , double , objref }
2412 case CORBA::tk_string: {
2415 cdebug << ThreadNo() << " " << t << "(string)" << endl ;
2418 case CORBA::tk_boolean: {
2420 D.Value >>= (CORBA::Any::to_boolean ) b;
2421 long l = (long ) b ;
2423 cdebug << ThreadNo() << " " << b << "(boolean)" << endl ;
2426 case CORBA::tk_char: {
2428 D.Value >>= (CORBA::Any::to_char ) c;
2429 long l = (long ) c ;
2431 cdebug << ThreadNo() << " " << c << "(char)" << endl ;
2434 case CORBA::tk_short: {
2437 long l = (long ) s ;
2439 cdebug << ThreadNo() << " " << s << "(short)" << endl ;
2442 case CORBA::tk_long: {
2445 cdebug << ThreadNo() << " " << l << "(long)" << endl ;
2448 case CORBA::tk_float: {
2451 double d = (double ) f ;
2453 cdebug << ThreadNo() << " " << f << "(float)" << endl ;
2456 case CORBA::tk_double: {
2459 cdebug << ThreadNo() << " " << d << "(double)" << endl ;
2462 case CORBA::tk_objref: {
2464 CORBA::Object_ptr obj ;
2467 retstr = ObjectToString( obj ) ;
2468 cdebug << ThreadNo() << retstr << endl ;
2471 cdebug << "ToString( object ) Catched ERROR" << endl ;
2476 cdebug << ThreadNo() << " " << "(other ERROR)" << endl ;
2479 OutParametersList[i] = D ;
2480 if ( anOutPort->IsGate() ) {
2481 aGateOutPort = anOutPort ;
2482 cdebug << " Gate " ;
2484 OutParametersList[i].Value <<= l;
2485 anOutPort->Value( OutParametersList[i].Value );
2487 else if ( anOutPort->IsLoop() ) {
2488 cdebug << " Loop " ;
2489 anOutPort->Value( OutParametersList[i].Value );
2490 // InLoop Port of EndLoopNode is ready :
2491 anOutPort->ChangeInPorts(0)->State( SUPERV::ReadyState ) ;
2493 else if ( anOutPort->IsSwitch() ) {
2494 cdebug << " Switch " ;
2495 anOutPort->Value( OutParametersList[i].Value );
2496 if ( anOutPort->InPortsSize() && anOutPort->ChangeInPorts( 0 )->IsGate() ) {
2497 if ( OrSwitch && anOutPort->BoolValue() ) {
2498 cdebug << "GraphExecutor::InNodeThreads::OutParameters more than one switch is true WARNING"
2502 OrSwitch = OrSwitch | anOutPort->BoolValue() ;
2505 cdebug << "OrSwitch " << OrSwitch ;
2508 cdebug << " Param " ;
2509 anOutPort->Value( OutParametersList[i].Value );
2511 anOutPort->State( NewState ) ;
2512 anOutPort->Done( true ) ;
2514 for ( j = 0 ; j < anOutPort->InPortsSize() ; j++ ) {
2515 bool fromGOTO = false ;
2516 GraphBase::OutPort * aGOTOPort = _OutNode->GetChangeGraphNode( anOutPort->ChangeInPorts( j )->NodeName() )->GetChangeNodeInGate()->GetOutPort() ;
2518 fromGOTO = aGOTOPort->IsGOTO() ;
2520 if ( anOutPort->ChangeInPorts( j )->IsEndSwitch() || fromGOTO ) {
2521 cdebug << anOutPort->ChangeInPorts( j )->NodeName() << "("
2522 << anOutPort->ChangeInPorts( j )->PortName() << ","
2523 << anOutPort->ChangeInPorts( j )->Kind() << ") WILL BE changed from "
2524 << anOutPort->ChangeInPorts( j )->GetOutPort()->NodeName()
2526 << anOutPort->ChangeInPorts( j )->GetOutPort()->PortName()
2527 << ") to " << anOutPort->NodeName() << "("
2528 << anOutPort->PortName() << ")" << endl ;
2529 anOutPort->ChangeInPorts( j )->ChangeOutPort( anOutPort ) ;
2532 cdebug << anOutPort->ChangeInPorts( j )->NodeName() << "("
2533 << anOutPort->ChangeInPorts( j )->PortName() << ","
2534 << anOutPort->ChangeInPorts( j )->Kind() << ") NOT changed from "
2535 << anOutPort->ChangeInPorts( j )->GetOutPort()->NodeName()
2537 << anOutPort->ChangeInPorts( j )->GetOutPort()->PortName()
2538 << ") to " << anOutPort->NodeName() << "("
2539 << anOutPort->PortName() << ")" << endl ;
2543 switch (anOutPort->Value()->type()->kind()) {
2544 case CORBA::tk_string:
2546 (*anOutPort->Value()) >>= t;
2547 cdebug << ThreadNo() << " Out" << i << " : " << t << "(string)" << endl ;
2549 case CORBA::tk_boolean:
2551 (*anOutPort->Value()) >>= (CORBA::Any::to_boolean ) b;
2552 cdebug << ThreadNo() << " Out" << i << " : " << b << "(boolean)" << endl ;
2554 case CORBA::tk_char:
2556 (*anOutPort->Value()) >>= (CORBA::Any::to_char ) c;
2557 cdebug << ThreadNo() << " Out" << i << " : " << c << "(char)" << endl ;
2559 case CORBA::tk_short:
2561 (*anOutPort->Value()) >>= s;
2562 cdebug << ThreadNo() << " Out" << i << " : " << s << "(short)" << endl ;
2564 case CORBA::tk_long:
2566 (*anOutPort->Value()) >>= l;
2567 cdebug << ThreadNo() << " Out" << i << " : " << l << "(long)" << endl ;
2569 case CORBA::tk_float:
2571 (*anOutPort->Value()) >>= f;
2572 cdebug << ThreadNo() << " Out" << i << " : " << f << "(float)" << endl ;
2574 case CORBA::tk_double:
2576 (*anOutPort->Value()) >>= d;
2577 cdebug << ThreadNo() << " Out" << i << " : " << d << "(double)" << endl ;
2579 case CORBA::tk_objref:
2580 CORBA::Object_ptr obj ;
2583 (*anOutPort->Value()) >>= obj ;
2584 retstr = ObjectToString( obj );
2585 cdebug << ThreadNo() << " Out" << i << " : " << "ToString( object ) "
2589 cdebug << ThreadNo() << " Out" << i << " : " << "ToString( object ) "
2590 << "Catched ERROR" << endl ;
2594 cdebug << ThreadNo() << " Out" << i << " : " << "(other ERROR)" << endl ;
2600 if ( aGateOutPort && IsSwitchNode() ) {
2602 // cdebug << ThreadNo() << " " << "Out0 " << Name() << " Close of "
2603 // << aGateOutPort->PortName() << " " << aGateOutPort->Kind() ;
2605 OutParametersList[0].Value <<= l ;
2606 aGateOutPort->Value( OutParametersList[0].Value ) ;
2609 // cdebug << ThreadNo() << " " << "Out0 " << Name() << " Open of "
2610 // << aGateOutPort->PortName() << " " << aGateOutPort->Kind() ;
2612 OutParametersList[0].Value <<= l ;
2613 aGateOutPort->Value( OutParametersList[0].Value ) ;
2615 for ( i = 0 ; i < GetNodeOutPortsSize() ; i++ ) {
2616 GraphBase::InPort * anInPort ;
2617 anInPort = CoupledNode()->GetChangeInPort( GetNodeOutPort( i )->PortName() ) ;
2619 anInPort->ChangeOutPort( GetChangeNodeOutPort( i ) ) ;