OpenRTM-aist  2.0.2
RTObjectStateMachine.h
[詳解]
1 // -*- C++ -*-
19 #ifndef RTC_IMPL_RTOBJECTSTATEMACHINE_H
20 #define RTC_IMPL_RTOBJECTSTATEMACHINE_H
21 
22 #include <cstdlib>
23 #include <rtm/SystemLogger.h>
24 #include <coil/TimeMeasure.h>
25 #include <rtm/idl/RTCSkel.h>
26 #include <rtm/StateMachine.h>
27 #include <cassert>
28 #include <iostream>
29 #include <atomic>
30 
31 #define NUM_OF_LIFECYCLESTATE 4
32 namespace RTC
33 {
34  class RTObject_impl;
35 } // namespace RTC
36 namespace RTC_impl
37 {
38  using Ecid = RTC::ExecutionContextHandle_t;
39  using ExecContextState = RTC::LifeCycleState;
41 
43  {
44  public:
45  RTObjectStateMachine(RTC::ExecutionContextHandle_t id,
48  virtual ~RTObjectStateMachine();
50 
51  // functions for stored RTObject reference
54 
55  RTC::ExecutionContextHandle_t getExecutionContextHandle();
56 
57  // RTC::ComponentAction operations
58  void onStartup();
59  void onShutdown();
60  void onActivated(const ExecContextStates& st);
61  void onDeactivated(const ExecContextStates& st);
62  void onAborting(const ExecContextStates& st);
63  void onError(const ExecContextStates& st);
64  void onReset(const ExecContextStates& st);
65 
66  // RTC::DataflowComponentAction
67  void onExecute(const ExecContextStates& st);
68  void onStateUpdate(const ExecContextStates& st);
69  RTC::ReturnCode_t onRateChanged();
70 
71  // FsmParticipantAction
72  void onAction(const ExecContextStates& st);
73 
74  // MultiModeComponentAction
75  void onModeChanged(const ExecContextStates& st);
76 
77  // Getting state of the context
80  bool isCurrentState(ExecContextState state);
81  bool isNextState(ExecContextState state);
82  void goTo(ExecContextState state);
83 
84  // Workers
85  void workerPreDo();
86  void workerDo();
87  void workerPostDo();
88 
89  bool activate();
90  bool deactivate();
91  bool reset();
92 
93  protected:
98  void updateState();
99 
100  private: // member variables
101  RTC::Logger rtclog;
102  // ExecutionContext id
103  RTC::ExecutionContextHandle_t m_id;
104  // Associated RTObject reference
106  // State machine
108  RTObjectStateMachine> m_sm;
109  bool m_ca;
110  bool m_dfc;
111  bool m_fsm;
112  bool m_mode;
113  RTC::ComponentAction_var m_caVar;
114  RTC::DataFlowComponentAction_var m_dfcVar;
115  RTC::FsmParticipantAction_var m_fsmVar;
116  RTC::MultiModeComponentAction_var m_modeVar;
117  RTC::RTObject_impl* m_rtobjPtr;
118  bool m_measure;
119  // Component action invoker
120  coil::TimeMeasure m_svtMeasure;
121  coil::TimeMeasure m_refMeasure;
122  std::atomic<bool> m_activation;
123  std::atomic<bool> m_deactivation;
124  std::atomic<bool> m_reset;
125  };
126 } // namespace RTC_impl
127 
128 #endif // RTC_RTOBJECTSTATEMACHINE_H
RTC_impl::RTObjectStateMachine::setFsmParticipantAction
void setFsmParticipantAction(RTC::LightweightRTObject_ptr comp)
RTC_impl::RTObjectStateMachine::isNextState
bool isNextState(ExecContextState state)
RTC_impl::RTObjectStateMachine::getExecutionContextHandle
RTC::ExecutionContextHandle_t getExecutionContextHandle()
RTC_impl::RTObjectStateMachine::onReset
void onReset(const ExecContextStates &st)
RTC_impl::RTObjectStateMachine::deactivate
bool deactivate()
RTC_impl::RTObjectStateMachine::onActivated
void onActivated(const ExecContextStates &st)
RTC_impl
Definition: ExecutionContextProfile.h:28
RTC_impl::RTObjectStateMachine::workerPostDo
void workerPostDo()
RTC_impl::RTObjectStateMachine::setDataFlowComponentAction
void setDataFlowComponentAction(RTC::LightweightRTObject_ptr comp)
RTC::RTObject_impl
RTコンポーネントクラス
Definition: RTObject.h:90
RTC_impl::RTObjectStateMachine::onStateUpdate
void onStateUpdate(const ExecContextStates &st)
RTC_impl::RTObjectStateMachine::getStates
ExecContextStates getStates()
RTC_impl::RTObjectStateMachine::onError
void onError(const ExecContextStates &st)
RTC_impl::RTObjectStateMachine::onAction
void onAction(const ExecContextStates &st)
RTC_impl::RTObjectStateMachine::reset
bool reset()
RTC_impl::Ecid
RTC::ExecutionContextHandle_t Ecid
Definition: RTObjectStateMachine.h:38
RTC_impl::LightweightRTObject_var
RTC::LightweightRTObject_var LightweightRTObject_var
Definition: ExecutionContextWorker.h:38
RTC_Utils::StateHolder< ExecContextState >
RTC_impl::RTObjectStateMachine::setComponentAction
void setComponentAction(RTC::LightweightRTObject_ptr comp)
RTC_impl::RTObjectStateMachine::operator=
RTObjectStateMachine & operator=(RTObjectStateMachine const &)=delete
RTC_impl::ExecContextState
RTC::LifeCycleState ExecContextState
Definition: RTObjectStateMachine.h:39
RTC_impl::RTObjectStateMachine::workerPreDo
void workerPreDo()
RTC::Logger
Logger クラス
Definition: SystemLogger.h:99
RTC_impl::RTObjectStateMachine::~RTObjectStateMachine
virtual ~RTObjectStateMachine()
RTC_impl::RTObjectStateMachine::getRTObject
RTC::LightweightRTObject_ptr getRTObject()
RTC_impl::RTObjectStateMachine::onStartup
void onStartup()
RTC_impl::RTObjectStateMachine::RTObjectStateMachine
RTObjectStateMachine(RTC::ExecutionContextHandle_t id, RTC::LightweightRTObject_ptr comp)
RTC_impl::RTObjectStateMachine::onDeactivated
void onDeactivated(const ExecContextStates &st)
RTC_impl::RTObjectStateMachine::setMultiModeComponentAction
void setMultiModeComponentAction(RTC::LightweightRTObject_ptr comp)
RTC_impl::RTObjectStateMachine::goTo
void goTo(ExecContextState state)
RTC_impl::RTObjectStateMachine::onShutdown
void onShutdown()
RTC_impl::RTObjectStateMachine::workerDo
void workerDo()
RTC_impl::RTObjectStateMachine::isEquivalent
bool isEquivalent(RTC::LightweightRTObject_ptr comp)
RTC_impl::RTObjectStateMachine::onModeChanged
void onModeChanged(const ExecContextStates &st)
RTC_impl::RTObjectStateMachine
Definition: RTObjectStateMachine.h:42
RTC_impl::RTObjectStateMachine::onRateChanged
RTC::ReturnCode_t onRateChanged()
RTC
RTコンポーネント
RTC_impl::RTObjectStateMachine::onExecute
void onExecute(const ExecContextStates &st)
RTC_impl::RTObjectStateMachine::getState
ExecContextState getState()
RTC_impl::RTObjectStateMachine::isCurrentState
bool isCurrentState(ExecContextState state)
RTC_impl::RTObjectStateMachine::onAborting
void onAborting(const ExecContextStates &st)
StateMachine.h
State machine template class
RTC_impl::LightweightRTObject_ptr
RTC::LightweightRTObject_ptr LightweightRTObject_ptr
Definition: ExecutionContextWorker.h:37
RTC_impl::RTObjectStateMachine::activate
bool activate()
SystemLogger.h
RT component logger class
RTC_Utils::StateMachine
状態マシンクラス
Definition: StateMachine.h:266
RTC_impl::RTObjectStateMachine::updateState
void updateState()