00001 // -*- C++ -*- 00019 #ifndef RTC_IMPL_RTOBJECTSTATEMACHINE_H 00020 #define RTC_IMPL_RTOBJECTSTATEMACHINE_H 00021 00022 #include <stdlib.h> 00023 #include <rtm/SystemLogger.h> 00024 #include <coil/NonCopyable.h> 00025 #include <coil/TimeMeasure.h> 00026 #include <rtm/idl/RTCSkel.h> 00027 #include <rtm/StateMachine.h> 00028 #include <assert.h> 00029 #include <iostream> 00030 00031 #define NUM_OF_LIFECYCLESTATE 4 00032 00033 #ifdef WIN32 00034 #pragma warning( disable : 4290 ) 00035 #endif 00036 namespace RTC 00037 { 00038 class RTObject_impl; 00039 } 00040 namespace RTC_impl 00041 { 00042 typedef RTC::ExecutionContextHandle_t Ecid; 00043 typedef RTC::LifeCycleState ExecContextState; 00044 typedef RTC_Utils::StateHolder<ExecContextState> ExecContextStates; 00045 00046 class RTObjectStateMachine 00047 : private coil::NonCopyable 00048 { 00049 public: 00050 RTObjectStateMachine(RTC::ExecutionContextHandle_t id, 00051 RTC::LightweightRTObject_ptr comp); 00052 virtual ~RTObjectStateMachine(void); 00053 // RTObjectStateMachine(const RTObjectStateMachine& rtobjsm); 00054 // RTObjectStateMachine& operator=(const RTObjectStateMachine& rtobjsm); 00055 // void swap(RTObjectStateMachine& rtobjsm) throw(); 00056 00057 // functions for stored RTObject reference 00058 RTC::LightweightRTObject_ptr getRTObject(); 00059 bool isEquivalent(RTC::LightweightRTObject_ptr comp); 00060 00061 RTC::ExecutionContextHandle_t getExecutionContextHandle(); 00062 00063 // RTC::ComponentAction operations 00064 void onStartup(void); 00065 void onShutdown(void); 00066 void onActivated(const ExecContextStates& st); 00067 void onDeactivated(const ExecContextStates& st); 00068 void onAborting(const ExecContextStates& st); 00069 void onError(const ExecContextStates& st); 00070 void onReset(const ExecContextStates& st); 00071 00072 // RTC::DataflowComponentAction 00073 void onExecute(const ExecContextStates& st); 00074 void onStateUpdate(const ExecContextStates& st); 00075 void onRateChanged(void); 00076 00077 // FsmParticipantAction 00078 void onAction(const ExecContextStates& st); 00079 00080 // MultiModeComponentAction 00081 void onModeChanged(const ExecContextStates& st); 00082 00083 // Getting state of the context 00084 ExecContextState getState(void); 00085 ExecContextStates getStates(void); 00086 bool isCurrentState(ExecContextState state); 00087 bool isNextState(ExecContextState state); 00088 void goTo(ExecContextState state); 00089 00090 // Workers 00091 void workerPreDo(void); 00092 void workerDo(void); 00093 void workerPostDo(void); 00094 00095 protected: 00096 void setComponentAction(const RTC::LightweightRTObject_ptr comp); 00097 void setDataFlowComponentAction(const RTC::LightweightRTObject_ptr comp); 00098 void setFsmParticipantAction(const RTC::LightweightRTObject_ptr comp); 00099 void setMultiModeComponentAction(const RTC::LightweightRTObject_ptr comp); 00100 00101 private: // member variables 00102 RTC::Logger rtclog; 00103 // ExecutionContext id 00104 RTC::ExecutionContextHandle_t m_id; 00105 // Associated RTObject reference 00106 RTC::LightweightRTObject_var m_rtobj; 00107 // State machine 00108 RTC_Utils::StateMachine<ExecContextState, 00109 RTObjectStateMachine> m_sm; 00110 bool m_ca; 00111 bool m_dfc; 00112 bool m_fsm; 00113 bool m_mode; 00114 RTC::ComponentAction_var m_caVar; 00115 RTC::DataFlowComponentAction_var m_dfcVar; 00116 RTC::FsmParticipantAction_var m_fsmVar; 00117 RTC::MultiModeComponentAction_var m_modeVar; 00118 RTC::RTObject_impl* m_rtobjPtr; 00119 bool m_measure; 00120 00121 // char dara[1000]; 00122 // Component action invoker 00123 coil::TimeMeasure m_svtMeasure; 00124 coil::TimeMeasure m_refMeasure; 00125 }; 00126 }; // namespace RTC 00127 00128 #ifdef WIN32 00129 #pragma warning( default : 4290 ) 00130 #endif 00131 00132 #endif // RTC_RTOBJECTSTATEMACHINE_H