OpenRTM-aist  2.1.0
RTObjectStateMachine.h
Go to the documentation of this file.
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,
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);
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);
69  RTC::ReturnCode_t onRateChanged();
70 
71  // FsmParticipantAction
72  void onAction(const ExecContextStates& st);
73 
74  // MultiModeComponentAction
76 
77  // Getting state of the context
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
State machine template class.
RT component logger class.
Logger class.
Definition: SystemLogger.h:101
RT-Component class.
Definition: RTObject.h:93
State machine class.
Definition: StateMachine.h:267
Definition: RTObjectStateMachine.h:43
void onAction(const ExecContextStates &st)
RTC::ReturnCode_t onRateChanged()
ExecContextStates getStates()
void onExecute(const ExecContextStates &st)
void onDeactivated(const ExecContextStates &st)
RTObjectStateMachine(RTC::ExecutionContextHandle_t id, RTC::LightweightRTObject_ptr comp)
RTObjectStateMachine(RTObjectStateMachine const &)=delete
RTC::LightweightRTObject_ptr getRTObject()
ExecContextState getState()
void setFsmParticipantAction(RTC::LightweightRTObject_ptr comp)
void goTo(ExecContextState state)
void onModeChanged(const ExecContextStates &st)
bool isEquivalent(RTC::LightweightRTObject_ptr comp)
void onAborting(const ExecContextStates &st)
void onStateUpdate(const ExecContextStates &st)
void setMultiModeComponentAction(RTC::LightweightRTObject_ptr comp)
void setDataFlowComponentAction(RTC::LightweightRTObject_ptr comp)
void setComponentAction(RTC::LightweightRTObject_ptr comp)
RTC::ExecutionContextHandle_t getExecutionContextHandle()
void onError(const ExecContextStates &st)
void onActivated(const ExecContextStates &st)
void onReset(const ExecContextStates &st)
RTObjectStateMachine & operator=(RTObjectStateMachine const &)=delete
bool isNextState(ExecContextState state)
bool isCurrentState(ExecContextState state)
Definition: ExecutionContextProfile.h:29
RTC::LightweightRTObject_var LightweightRTObject_var
Definition: ExecutionContextWorker.h:38
RTC::LightweightRTObject_ptr LightweightRTObject_ptr
Definition: ExecutionContextWorker.h:37
RTC::ExecutionContextHandle_t Ecid
Definition: RTObjectStateMachine.h:38
RTC::LifeCycleState ExecContextState
Definition: RTObjectStateMachine.h:39
RT-Component.
State holder class.
Definition: StateMachine.h:58