#define ToKillDoneState SUPERV::ToKillDoneState
#define ToStopState SUPERV::ToStopState
+#if 0
// States :
-#define UnKnownState SUPERV::UnKnownState
-#define DataUndefState SUPERV::DataUndefState
-#define DataWaitingState SUPERV::DataWaitingState
-#define DataReadyState SUPERV::DataReadyState
-#define SuspendedReadyState SUPERV::SuspendedReadyState
-#define SuspendedReadyToResumeState SUPERV::SuspendedReadyToResumeState
-#define ResumedReadyState SUPERV::ResumedReadyState
-#define KilledReadyState SUPERV::KilledReadyState
-#define StoppedReadyState SUPERV::StoppedReadyState
-#define ExecutingState SUPERV::ExecutingState
-#define SuspendedExecutingState SUPERV::SuspendedExecutingState
-#define ResumedExecutingState SUPERV::ResumedExecutingState
-#define KilledExecutingState SUPERV::KilledExecutingState
-#define StoppedExecutingState SUPERV::StoppedExecutingState
-#define SuccessedExecutingState SUPERV::SuccessedExecutingState
-#define ErroredExecutingState SUPERV::ErroredExecutingState
-#define SuspendedSuccessedState SUPERV::SuspendedSuccessedState
-#define SuspendedErroredState SUPERV::SuspendedErroredState
-#define SuspendedSuccessedToReStartState SUPERV::SuspendedSuccessedToReStartState
-#define SuspendedErroredToReStartState SUPERV::SuspendedErroredToReStartState
-#define ResumedSuccessedState SUPERV::ResumedSuccessedState
-#define ResumedErroredState SUPERV::ResumedErroredState
-#define KilledSuccessedState SUPERV::KilledSuccessedState
-#define KilledErroredState SUPERV::KilledErroredState
-#define StoppedSuccessedState SUPERV::StoppedSuccessedState
-#define StoppedErroredState SUPERV::StoppedErroredState
-#define SuccessedState SUPERV::SuccessedState
-#define ErroredState SUPERV::ErroredState
-#define SuspendedState SUPERV::SuspendedState
-#define KilledState SUPERV::KilledState
-#define StoppedState SUPERV::StoppedState
-#define ReRunnedState SUPERV::ReRunnedState
-#define ReStartedState SUPERV::ReStartedState
-#define NumberOfAutomatonStates SUPERV::NumberOfAutomatonStates
+#define UnKnownState GraphExecutor::UnKnownState
+#define DataUndefState GraphExecutor::DataUndefState
+#define DataWaitingState GraphExecutor::DataWaitingState
+#define DataReadyState GraphExecutor::DataReadyState
+#define SuspendedReadyState GraphExecutor::SuspendedReadyState
+#define SuspendedReadyToResumeState GraphExecutor::SuspendedReadyToResumeState
+#define ResumedReadyState GraphExecutor::ResumedReadyState
+#define KilledReadyState GraphExecutor::KilledReadyState
+#define StoppedReadyState GraphExecutor::StoppedReadyState
+#define ExecutingState GraphExecutor::ExecutingState
+#define SuspendedExecutingState GraphExecutor::SuspendedExecutingState
+#define ResumedExecutingState GraphExecutor::ResumedExecutingState
+#define KilledExecutingState GraphExecutor::KilledExecutingState
+#define StoppedExecutingState GraphExecutor::StoppedExecutingState
+#define SuccessedExecutingState GraphExecutor::SuccessedExecutingState
+#define ErroredExecutingState GraphExecutor::ErroredExecutingState
+#define SuspendedSuccessedState GraphExecutor::SuspendedSuccessedState
+#define SuspendedErroredState GraphExecutor::SuspendedErroredState
+#define SuspendedSuccessedToReStartState GraphExecutor::SuspendedSuccessedToReStartState
+#define SuspendedErroredToReStartState GraphExecutor::SuspendedErroredToReStartState
+#define ResumedSuccessedState GraphExecutor::ResumedSuccessedState
+#define ResumedErroredState GraphExecutor::ResumedErroredState
+#define KilledSuccessedState GraphExecutor::KilledSuccessedState
+#define KilledErroredState GraphExecutor::KilledErroredState
+#define StoppedSuccessedState GraphExecutor::StoppedSuccessedState
+#define StoppedErroredState GraphExecutor::StoppedErroredState
+#define SuccessedState GraphExecutor::SuccessedState
+#define ErroredState GraphExecutor::ErroredState
+#define SuspendedState GraphExecutor::SuspendedState
+#define KilledState GraphExecutor::KilledState
+#define StoppedState GraphExecutor::StoppedState
+#define ReStartedState GraphExecutor::ReStartedState
+#define LoadingState GraphExecutor::LoadingState
+#define NumberOfAutomatonStates GraphExecutor::NumberOfAutomatonStates
+#endif
// Events :
#define UndefinedEvent GraphExecutor::UndefinedEvent
#define NumberOfEvents GraphExecutor::NumberOfEvents
GraphExecutor::FiniteStateMachine::FiniteStateMachine() {
-// cdebug_in << "FiniteStateMachine::FiniteStateMachine" << endl;
+ MESSAGE( "FiniteStateMachine::FiniteStateMachine" ) ;
_ControlStateName[ VoidState ] = "VoidState" ;
_ControlStateName[ ToSuspendStartState ]= "ToSuspendStartState" ;
_StateName[ SuspendedState ] = "SuspendedState" ;
_StateName[ KilledState ] = "KilledState" ;
_StateName[ StoppedState ] = "StoppedState" ;
- _StateName[ ReRunnedState ] = "ReRunnedState" ;
_StateName[ ReStartedState ] = "ReStartedState" ;
+ _StateName[ LoadingState ] = "LoadingState" ;
_EventName[ UndefinedEvent ] = "UndefinedEvent" ;
_EventName[ NewThreadEvent ] = "NewThreadEvent" ;
_ActionName[ Executing_StopAction ] = "Executing_StopAction" ;
_ActionName[ Executing_SuccessAction ] = "Executing_SuccessAction" ;
- _ActionName[ Executing_ErrorAction ] = "Executing_ErrorAction" ;
+// _ActionName[ Executing_ErrorAction ] = "Executing_ErrorAction" ;
+ _ActionName[ Errored_ExecutingAction ] = "Errored_ExecutingAction" ;
_ActionName[ Successed_SuccessAction ] = "Successed_SuccessAction" ;
_ActionName[ Errored_ErrorAction ] = "Errored_ErrorAction" ;
_GraphStateName[ SUPERV::SuspendErroredState ] = "SuspendErroredState" ;
_GraphStateName[ SUPERV::KillState ] = "KillState" ;
_GraphStateName[ SUPERV::StopState ] = "StopState" ;
- _GraphStateName[ SUPERV::ReRunState ] = "ReRunState" ;
- _GraphStateName[ SUPERV::ReStartState ] = "ReStartState" ;
int i , j ;
// NewStates = _TransitionTable[ States ] [ Events ]
for ( i = 0 ; i < NumberOfAutomatonStates ; i++ ) {
for ( j = 0 ; j < NumberOfEvents ; j++ ) {
// id est = SameState and VoidAction
- _TransitionTable[ i ][ j ] = (SUPERV::AutomatonState ) i ;
+ _TransitionTable[ i ][ j ] = (GraphExecutor::AutomatonState ) i ;
_ActionTable[ i ][ j ] = GraphExecutor::ErrorAction ;
}
}
// SomeDataReadyEvent :
_TransitionTable[ DataWaitingState ][ SomeDataReadyEvent ] = DataUndefState ;
_ActionTable[ DataUndefState ][ SomeDataReadyEvent ] = DataWaiting_SomeDataReadyAction;
+ _TransitionTable[ DataReadyState ][ SomeDataReadyEvent ] = DataUndefState ;
+ _ActionTable[ DataUndefState ][ SomeDataReadyEvent ] = DataWaiting_SomeDataReadyAction;
// NotAllDataReadyEvent :
_TransitionTable[ DataUndefState ][ NotAllDataReadyEvent ] = DataWaitingState ;
_ActionTable[ DataWaitingState ][ NotAllDataReadyEvent ] = DataUndef_NotAllDataReadyAction;
// SuspendedExecutingState : NO ResumeEvent 13-03-2003
_TransitionTable[ SuspendedExecutingState ][ SuccessEvent ] = SuccessedExecutingState ;
_ActionTable[ SuccessedExecutingState ][ SuccessEvent ] = Executing_SuccessAction;
+//JR 24.03.2005 : Debug for PAL8176 : abort of GOTONode
+// ErrorEvent
+ _TransitionTable[ SuccessedState ][ ErrorEvent ] = ErroredExecutingState ;
+// _ActionTable[ ErroredExecutingState ][ ErrorEvent ] = Executing_ErrorAction;
+ _ActionTable[ ErroredExecutingState ][ ErrorEvent ] = Errored_ExecutingAction;
// ErrorEvent
_TransitionTable[ ExecutingState ][ ErrorEvent ] = ErroredExecutingState ;
- _ActionTable[ ErroredExecutingState ][ ErrorEvent ] = Executing_ErrorAction;
+// _ActionTable[ ErroredExecutingState ][ ErrorEvent ] = Executing_ErrorAction;
+ _ActionTable[ ErroredExecutingState ][ ErrorEvent ] = Errored_ExecutingAction;
// SuspendedExecutingState : NO ResumeEvent 13-03-2003
_TransitionTable[ SuspendedExecutingState ][ ErrorEvent ] = ErroredExecutingState ;
- _ActionTable[ ErroredExecutingState ][ ErrorEvent ] = Executing_ErrorAction;
+// _ActionTable[ ErroredExecutingState ][ ErrorEvent ] = Executing_ErrorAction;
+ _ActionTable[ ErroredExecutingState ][ ErrorEvent ] = Errored_ExecutingAction;
// DONE-CONTROL :
// SuccessedExecutingState - SuccessEvent
perror( msg ) ;
}
-// cdebug_out << "FiniteStateMachine::FiniteStateMachine _TransitionTable "
-// << endl;
+#if omniORB_4_0_5
+ _SuperVisionComponent = SUPERV::SuperG::_nil() ;
+#endif
+
+ pthread_mutex_init( &_MutexPythonWait , NULL ) ;
+ _MutexPythonLocked = false ;
+ _ExecNumber = 0 ;
+ _GraphExecutingNumber = 0 ;
+ _PyInitModule = false ;
+ _DbgFileNumber = 0 ;
+ MESSAGE( "FiniteStateMachine::FiniteStateMachine _TransitionTable " ) ;
}
void * start_function( void *p ) {
pthread_exit( PTHREAD_CANCELED ) ;
}
+int GraphExecutor::FiniteStateMachine::ExecNumber() {
+ PyLock() ;
+ _ExecNumber += 1 ;
+ int RetVal = _ExecNumber ;
+ _GraphExecutingNumber += 1 ;
+ PyUnLock() ;
+ return RetVal ;
+}
+
+void GraphExecutor::FiniteStateMachine::Executed() {
+ PyLock() ;
+ _GraphExecutingNumber -= 1 ;
+ if ( _GraphExecutingNumber == 0 ) {
+ map< string , PyObject * >::iterator aPyFunction ;
+ for ( aPyFunction = _MapOfPyFunctions.begin() ; aPyFunction != _MapOfPyFunctions.end() ; aPyFunction++ ) {
+ if ( !strcmp( aPyFunction->first.c_str() , "PyObjRef" ) ||
+ !strcmp( aPyFunction->first.c_str() , "PyObjIor" ) ) {
+ MESSAGE( "GraphExecutor::FiniteStateMachine::Executed " << aPyFunction->first << " keeped ..."
+ ) ;
+ }
+ else {
+ MESSAGE( "GraphExecutor::FiniteStateMachine::Executed " << aPyFunction->first << " erased ..."
+ ) ;
+ _MapOfPyFunctions.erase( aPyFunction->first ) ;
+ }
+ }
+ }
+ else {
+ MESSAGE( "GraphExecutor::FiniteStateMachine::Executed _GraphExecutingNumber "
+ << _GraphExecutingNumber << " != 0 ==> no erase" ) ;
+ }
+ PyUnLock() ;
+ return ;
+}
+
+void GraphExecutor::FiniteStateMachine::PyInitModule( bool aPyInitModule ) {
+ _PyInitModule = aPyInitModule ;
+}
+
+bool GraphExecutor::FiniteStateMachine::PyInitModule() {
+ bool InitedModule = _PyInitModule ;
+ _PyInitModule = true ;
+ return InitedModule ;
+}
+
+void GraphExecutor::FiniteStateMachine::PyLock() {
+// cout << pthread_self() << " GraphExecutor::FiniteStateMachine::PyLock " << &_MutexPythonWait << endl ;
+ if ( pthread_mutex_lock( &_MutexPythonWait ) ) {
+ perror( "GraphExecutor::FiniteStateMachine::PyLock" ) ;
+ exit( 0 ) ;
+ }
+ _MutexPythonLocked = true ;
+// cout << pthread_self() << " GraphExecutor::FiniteStateMachine::PyLocked " << &_MutexPythonWait << endl ;
+}
+
+void GraphExecutor::FiniteStateMachine::PyUnLock() {
+// cout << pthread_self() << " GraphExecutor::FiniteStateMachine::PyUnLock " << &_MutexPythonWait << endl ;
+ if ( pthread_mutex_unlock( &_MutexPythonWait ) ) {
+ perror( "GraphExecutor::FiniteStateMachine::PyUnLock" ) ;
+ exit( 0 ) ;
+ }
+ _MutexPythonLocked = false ;
+// cout << pthread_self() << " GraphExecutor::FiniteStateMachine::PyUnLocked " << &_MutexPythonWait << endl ;
+}
+
+void GraphExecutor::FiniteStateMachine::PyLockReset() {
+ if ( _MutexPythonLocked ) {
+ PyUnLock() ;
+ }
+}
+
+#define PyFunctionTrace 1
+PyObject * GraphExecutor::FiniteStateMachine::PyFunction( const char * aPyFuncName ) {
+
+ PyObject * RetVal = NULL ;
+ bool PyObjRefIor = !strcmp( aPyFuncName , "PyObjRef" ) || !strcmp( aPyFuncName , "PyObjIor" ) ;
+ PyObject * PyFunctionMapped = _MapOfPyFunctions[ aPyFuncName ] ;
+ if ( _GraphExecutingNumber > 1 && !PyObjRefIor ) {
+ RetVal = PyFunctionMapped ;
+#if PyFunctionTrace
+ MESSAGE( "GraphExecutor::FiniteStateMachine::PyFunction( '" << aPyFuncName << "' ) --> " ) ;
+ if ( RetVal ) {
+ MESSAGE( RetVal << " ob_refcnt " << RetVal->ob_refcnt ) ;
+ }
+ else {
+ MESSAGE( " NULL" ) ;
+ }
+#endif
+ }
+ else {
+ RetVal = PyFunctionMapped ;
+#if PyFunctionTrace
+ MESSAGE( "GraphExecutor::FiniteStateMachine::PyFunction( '" << aPyFuncName << "' ) --> " ) ;
+ if ( RetVal && PyObjRefIor ) {
+ MESSAGE( RetVal << " " << RetVal->ob_refcnt ) ;
+ }
+ else if ( RetVal ) {
+ MESSAGE( RetVal << " " << RetVal->ob_refcnt ) ;
+ }
+ else {
+ MESSAGE( " NULL" ) ;
+ }
+#endif
+ }
+
+ return RetVal ;
+}
+
+bool GraphExecutor::FiniteStateMachine::PyFunction( const char * aPyFuncName , PyObject * aPyFunction ) {
+
+ bool RetVal = false ;
+ if ( _MapOfPyFunctions[ aPyFuncName ] != NULL ) {
+#if PyFunctionTrace
+ PyObject * aPyFunc = _MapOfPyFunctions[ aPyFuncName ] ;
+ MESSAGE( "GraphExecutor::FiniteStateMachine::PyFunction( '" << aPyFuncName << "' , aPyFunction "
+ << aPyFunction << " ) ob_refcnt " << aPyFunction->ob_refcnt << " already mapped : "
+ << aPyFunc << " ob_refcnt " << aPyFunc->ob_refcnt ) ;
+#endif
+ }
+ else {
+ _MapOfPyFunctions[ aPyFuncName ] = aPyFunction ;
+#if PyFunctionTrace
+ MESSAGE( "GraphExecutor::FiniteStateMachine::PyFunction( '" << aPyFuncName << "' ) " << aPyFunction
+ << " ) ob_refcnt " << aPyFunction->ob_refcnt << " mapped" ) ;
+#endif
+ RetVal = true ;
+ }
+
+ return RetVal ;
+}
+
+bool GraphExecutor::FiniteStateMachine::ErasePyFunction( const char * aPyFuncName ) {
+
+#if PyFunctionTrace
+ MESSAGE( "GraphExecutor::FiniteStateMachine::ErasePyFunction( '" << aPyFuncName << "' )" ) ;
+#endif
+ if ( _MapOfPyFunctions[ aPyFuncName ] != NULL ) {
+ _MapOfPyFunctions.erase( aPyFuncName ) ;
+ return true ;
+ }
+ return false ;
+}
+
+/*
+GraphBase::Graph * GraphExecutor::FiniteStateMachine::MapGraph( const char * aGraphName ) {
+ GraphBase::Graph * aGraph = _MapOfGraphs[ aGraphName ] ;
+ //cout << "MapGraph " << aGraphName << " --> " << aGraph << endl ;
+ return aGraph ;
+}
+
+bool GraphExecutor::FiniteStateMachine::MapGraph( GraphBase::Graph * aGraph , const char * aGraphName ) {
+ if ( MapGraph( aGraphName ) ) {
+ return false ;
+ }
+ _MapOfGraphs[ aGraphName ] = aGraph ;
+ return true ;
+}
+
+void GraphExecutor::FiniteStateMachine::EraseGraph( const char * aGraphName ) {
+ _MapOfGraphs.erase( aGraphName ) ;
+}
+
+bool GraphExecutor::FiniteStateMachine::GraphName( const char * aGraphName ) {
+ return _MapOfGraphNames[ aGraphName ] ;
+}
+
+string GraphExecutor::FiniteStateMachine::GraphInstanceName( const char * aGraphName ) {
+ int GraphInstanceNumber = _MapOfGraphNames[ aGraphName ] ;
+ if ( GraphInstanceNumber ) {
+ _MapOfGraphNames[ aGraphName ] = GraphInstanceNumber + 1 ;
+ }
+ else {
+ GraphInstanceNumber = 0 ;
+ _MapOfGraphNames[ aGraphName ] = GraphInstanceNumber + 1 ;
+ }
+ string theGraphInstanceName = string( aGraphName ) ;
+ if ( GraphInstanceNumber ) {
+ theGraphInstanceName += "_" ;
+ ostringstream astr ;
+// astr << GraphInstanceNumber << ends ;
+ astr << GraphInstanceNumber ;
+ theGraphInstanceName += astr.str() ;
+ }
+ //cout << "GraphExecutor::FiniteStateMachine::GraphInstanceName( " << aGraphName << " ) --> "
+ // << theGraphInstanceName << endl ;
+ return theGraphInstanceName ;
+}
+*/
+
void GraphExecutor::FiniteStateMachine::JoinThread() {
if ( pthread_mutex_lock( &_MutexJoinWait ) ) {
- perror("Join pthread_mutex_lock ") ;
+ perror("FiniteStateMachine:JoinThread pthread_mutex_lock ") ;
exit( 0 ) ;
}
while ( _JoinThread ) {
while ( _ThreadList.size() == 0) {
-// MESSAGE( pthread_self() << " Join pthread_cond_wait" );
+// MESSAGE( pthread_self() << " FiniteStateMachine:Join pthread_cond_wait" );
if ( pthread_cond_wait( &_JoinWait , &_MutexJoinWait ) ) {
- perror("Join pthread_cond_wait ") ;
+ perror("FiniteStateMachine:JoinThread pthread_cond_wait ") ;
}
}
pthread_t _Thread = _ThreadList.front() ;
-// MESSAGE( pthread_self() << " Join pthread_cond_waited : " << _Thread )
- _ThreadList.pop_front() ;
-// MESSAGE( pthread_self() << " Join pthread_join : " << _Thread );
+// MESSAGE( pthread_self() << " FiniteStateMachine:JoinThread pthread_cond_waited : " << _Thread )
+// MESSAGE( pthread_self() << " FiniteStateMachine:JoinThread pthread_join : " << _Thread );
int joinsts = pthread_join( _Thread , NULL ) ;
-// MESSAGE( pthread_self() << " Join pthread_joined : " << _Thread );
if ( joinsts ) {
- perror("Join pthread_join ") ;
-// exit( 0 ) ;
+ perror("FiniteStateMachine:JoinThread pthread_join ") ;
+ MESSAGE( pthread_self() << " FiniteStateMachine:JoinThread pthread_join : " << _Thread
+ << " Error" );
+ exit( 0 ) ;
+ }
+ else {
+// MESSAGE( pthread_self() << " FiniteStateMachine:JoinThread pthread_joined : " << _Thread );
+ _ThreadList.pop_front() ;
}
}
if ( pthread_mutex_unlock( &_MutexJoinWait ) ) {
- perror("Join pthread_mutex_unlock ") ;
+ perror("FiniteStateMachine:JoinThread pthread_mutex_unlock ") ;
exit( 0 ) ;
}
}
}
}
+ostream & operator<< (ostream &f ,const GraphExecutor::AutomatonState & aState ) {
+ switch (aState) {
+ case GraphExecutor::UnKnownState :
+ f << "UnKnownState";
+ break;
+ case GraphExecutor::DataUndefState :
+ f << "DataUndefState";
+ break;
+ case GraphExecutor::DataWaitingState :
+ f << "DataWaitingState";
+ break;
+ case GraphExecutor::DataReadyState :
+ f << "DataReadyState";
+ break;
+ case GraphExecutor::SuspendedReadyState :
+ f << "SuspendedReadyState";
+ break;
+ case GraphExecutor::SuspendedReadyToResumeState :
+ f << "SuspendedReadyToResumeState";
+ break;
+ case GraphExecutor::ResumedReadyState :
+ f << "ResumedReadyState";
+ break;
+ case GraphExecutor::KilledReadyState :
+ f << "KilledReadyState";
+ break;
+ case GraphExecutor::StoppedReadyState :
+ f << "StoppedReadyState";
+ break;
+ case GraphExecutor::ExecutingState :
+ f << "ExecutingState";
+ break;
+ case GraphExecutor::SuspendedExecutingState :
+ f << "SuspendedExecutingState";
+ break;
+ case GraphExecutor::ResumedExecutingState :
+ f << "ResumedExecutingState";
+ break;
+ case GraphExecutor::KilledExecutingState :
+ f << "KilledExecutingState";
+ break;
+ case GraphExecutor::StoppedExecutingState :
+ f << "StoppedExecutingState";
+ break;
+ case GraphExecutor::SuccessedExecutingState :
+ f << "SuccessedExecutingState";
+ break;
+ case GraphExecutor::ErroredExecutingState :
+ f << "ErroredExecutingState";
+ break;
+ case GraphExecutor::SuspendedSuccessedState :
+ f << "SuspendedSuccessedState";
+ break;
+ case GraphExecutor::SuspendedErroredState :
+ f << "SuspendedErroredState";
+ break;
+ case GraphExecutor::ResumedSuccessedState :
+ f << "ResumedSuccessedState";
+ break;
+ case GraphExecutor::ResumedErroredState :
+ f << "ResumedErroredState";
+ break;
+ case GraphExecutor::KilledSuccessedState :
+ f << "KilledSuccessedState";
+ break;
+ case GraphExecutor::KilledErroredState :
+ f << "KilledErroredState";
+ break;
+ case GraphExecutor::StoppedSuccessedState :
+ f << "StoppedSuccessedState";
+ break;
+ case GraphExecutor::StoppedErroredState :
+ f << "StoppedErroredState";
+ break;
+ case GraphExecutor::SuccessedState :
+ f << "SuccessedState";
+ break;
+ case GraphExecutor::ErroredState :
+ f << "ErroredState";
+ break;
+ case GraphExecutor::SuspendedState :
+ f << "SuspendedState";
+ break;
+ case GraphExecutor::KilledState :
+ f << "KilledState";
+ break;
+ case GraphExecutor::StoppedState :
+ f << "StoppedState";
+ break;
+ case GraphExecutor::SuspendedSuccessedToReStartState :
+ f << "SuspendedSuccessedToReStartState";
+ break;
+ case GraphExecutor::SuspendedErroredToReStartState :
+ f << "SuspendedErroredToReStartState";
+ break;
+ case GraphExecutor::ReStartedState :
+ f << "ReStartedState";
+ break;
+ case GraphExecutor::LoadingState :
+ f << "LoadingState";
+ break;
+ default :
+ f << "GraphExecutor::AutomatonState_?";
+ break;
+ }
+
+ return f;
+}
+