OpenRTM-aist 2.0.2
Loading...
Searching...
No Matches
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
32namespace RTC
33{
34 class RTObject_impl;
35} // namespace RTC
36namespace RTC_impl
37{
38 using Ecid = RTC::ExecutionContextHandle_t;
39 using ExecContextState = RTC::LifeCycleState;
41
43 {
44 public:
45 RTObjectStateMachine(RTC::ExecutionContextHandle_t id,
46 RTC::LightweightRTObject_ptr comp);
50
51 // functions for stored RTObject reference
52 RTC::LightweightRTObject_ptr getRTObject();
53 bool isEquivalent(RTC::LightweightRTObject_ptr comp);
54
55 RTC::ExecutionContextHandle_t getExecutionContextHandle();
56
57 // RTC::ComponentAction operations
58 void onStartup();
59 void onShutdown();
63 void onError(const ExecContextStates& st);
64 void onReset(const ExecContextStates& st);
65
66 // RTC::DataflowComponentAction
69 RTC::ReturnCode_t onRateChanged();
70
71 // FsmParticipantAction
72 void onAction(const ExecContextStates& st);
73
74 // MultiModeComponentAction
76
77 // Getting state of the context
83
84 // Workers
86 void workerDo();
88
89 bool activate();
90 bool deactivate();
91 bool reset();
92
93 protected:
94 void setComponentAction(RTC::LightweightRTObject_ptr comp);
95 void setDataFlowComponentAction(RTC::LightweightRTObject_ptr comp);
96 void setFsmParticipantAction(RTC::LightweightRTObject_ptr comp);
97 void setMultiModeComponentAction(RTC::LightweightRTObject_ptr comp);
99
100 private: // member variables
101 RTC::Logger rtclog;
102 // ExecutionContext id
103 RTC::ExecutionContextHandle_t m_id;
104 // Associated RTObject reference
105 RTC::LightweightRTObject_var m_rtobj;
106 // State machine
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()
RTObjectStateMachine & operator=(RTObjectStateMachine const &)=delete
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)
bool isNextState(ExecContextState state)
bool isCurrentState(ExecContextState state)
Definition ExecutionContextProfile.h:29
RTC::ExecutionContextHandle_t Ecid
Definition RTObjectStateMachine.h:38
RTC::LifeCycleState ExecContextState
Definition RTObjectStateMachine.h:39
RT-Component.