13#ifndef RTCTK_COMPONENTFRAMEWORK_RUNABLE_HPP
14#define RTCTK_COMPONENTFRAMEWORK_RUNABLE_HPP
22template <
typename Super>
30template <
typename Super>
32 static_assert(std::is_base_of_v<RtcComponent, Super>,
"'Runnable' requires 'RtcComponent'");
33 static_assert(not is_base_of_template_v<Loopaware, Super>,
"'Runnable' excludes 'Loopaware'");
45 using Super::InputStage::InputStage;
48 Super::InputStage::Start();
65 this->m_no_disable_in_states.push_back(
"On::Operational::Error");
66 this->m_no_disable_in_states.push_back(
"On::Operational::Recovering");
67 this->m_no_disable_in_states.push_back(
"On::Operational::GoingRunning");
68 this->m_no_disable_in_states.push_back(
"On::Operational::GoingIdle");
69 this->m_no_disable_in_states.push_back(
"On::Operational::Running");
73 this->m_no_update_in_states.push_back(
"On::Operational::GoingRunning");
74 this->m_no_update_in_states.push_back(
"On::Operational::GoingIdle");
75 this->m_no_update_in_states.push_back(
"On::Operational::Error");
76 this->m_no_update_in_states.push_back(
"On::Operational::Recovering");
81 this->m_tmp_request = GetPayloadNothrow<events::Run>(c);
85 if (this->m_tmp_request) {
87 this->m_tmp_request =
nullptr;
94 this->m_tmp_request = GetPayloadNothrow<events::Idle>(c);
98 if (this->m_tmp_request) {
100 this->m_tmp_request =
nullptr;
107 if (
auto eptr = GetPayloadNothrow<events::Error>(c); eptr) {
108 if (this->m_tmp_request) {
109 this->m_tmp_request->SetException(
111 this->m_tmp_request =
nullptr;
119 this->m_tmp_request = GetPayloadNothrow<events::Recover>(c);
123 if (this->m_tmp_request) {
125 this->m_tmp_request =
nullptr;
132 "ActivityGoingRunning",
134 static_cast<BizLogicIf&
>(this->m_logic).ActivityGoingRunning(stop_token);
136 this->m_success_handler,
137 this->m_error_handler);
142 static_cast<BizLogicIf&
>(this->m_logic).ActivityGoingIdle(stop_token);
144 this->m_success_handler,
145 this->m_error_handler);
150 static_cast<BizLogicIf&
>(this->m_logic).ActivityRunning(stop_token);
152 this->m_success_handler,
153 this->m_error_handler);
156 "ActivityRecovering",
158 static_cast<BizLogicIf&
>(this->m_logic).ActivityRecovering(stop_token);
160 this->m_success_handler,
161 this->m_error_handler);
169 this->mm.ModStateType(
"On::Operational",
Parallel);
171 const std::string parent_region =
"On::Operational:";
173 this->mm.AddState(
Composite, parent_region,
"On::Operational");
175 this->mm.AddState(
Initial,
"On::Operational::Initial", parent_region);
176 this->mm.AddState(
Simple,
"On::Operational::Idle", parent_region);
177 this->mm.AddState(
Simple,
"On::Operational::Error", parent_region ,
"" ,
"ActionErrorEntry");
178 this->mm.AddState(
Simple,
"On::Operational::Running", parent_region ,
"ActivityRunning");
179 this->mm.AddState(
Simple,
"On::Operational::Recovering", parent_region ,
"ActivityRecovering" ,
"ActionRecoveringEntry");
180 this->mm.AddState(
Simple,
"On::Operational::GoingRunning", parent_region ,
"ActivityGoingRunning" ,
"ActionGoingRunningEntry");
181 this->mm.AddState(
Simple,
"On::Operational::GoingIdle", parent_region ,
"ActivityGoingIdle" ,
"ActionGoingIdleEntry");
183 this->mm.AddTrans(
"On::Operational::Initial" ,
"On::Operational::Idle" );
184 this->mm.AddTrans(parent_region ,
"On::Operational::Error" ,
"events.Error");
186 this->mm.AddTrans(
"On::Operational::Error" ,
"On::Operational::Recovering" ,
"events.Recover");
187 this->mm.AddTrans(
"On::Operational::Recovering" ,
"On::Operational::Idle" ,
"events.Done",
"" ,
"ActionRecoveringDone");
189 this->mm.AddTrans(
"On::Operational::Idle" ,
"On::Operational::GoingRunning" ,
"events.Run");
190 this->mm.AddTrans(
"On::Operational::GoingRunning" ,
"On::Operational::Running" ,
"events.Done",
"" ,
"ActionGoingRunningDone");
192 this->mm.AddTrans(
"On::Operational::Running" ,
"On::Operational::GoingIdle" ,
"events.Idle");
193 this->mm.AddTrans(
"On::Operational::GoingIdle" ,
"On::Operational::Idle" ,
"events.Done",
"" ,
"ActionGoingIdleDone");
195 this->mm.AddTrans(
"On::Operational::Running" ,
"On::Operational::GoingIdle" ,
"events.Done");
static void Register(CommandReplier &replier, StateMachineEngine &engine)
Definition: rtcCmdsImpl.hpp:37
Adapter object intended to be used in contexts without direct access to the output-stream object.
Definition: exceptions.hpp:185
std::string Str() const
Convenience function for constructing a std::string from the exception.
Definition: exceptions.hpp:203
Thrown if the command was accepted but the task to run failed.
Definition: rtcComponent.hpp:53
Thrown if a command is not allowed in current state or guard.
Definition: rtcComponent.hpp:40
Definition: runnable.hpp:35
virtual void ActivityGoingRunning(StopToken st)
Definition: runnable.hpp:37
virtual void ActivityRunning(StopToken st)
Definition: runnable.hpp:39
virtual void ActivityRecovering(StopToken st)
Definition: runnable.hpp:40
virtual void ActivityGoingIdle(StopToken st)
Definition: runnable.hpp:38
Definition: runnable.hpp:54
OutputStage(StateMachineEngine &engine, BizLogicIf &bl)
Definition: runnable.hpp:56
Definition: stateMachineEngine.hpp:35
void RegisterRejectHandler(std::string const &id, RejectMethod reject)
Register reject handler.
Definition: stateMachineEngine.cpp:131
void RegisterActivity(std::string const &id, ActivityMethod activity, SuccessMethod on_success, FailureMethod on_failure)
Register activity.
Definition: stateMachineEngine.cpp:123
void RegisterAction(std::string const &id, ActionMethod action)
Register action.
Definition: stateMachineEngine.cpp:86
Definition: commandReplier.cpp:22
const std::string STD_OK_REPLY
Definition: stdComponent.hpp:86
rad::StopToken StopToken
Definition: stopToken.hpp:20
@ Simple
Definition: model.hpp:22
@ Composite
Definition: model.hpp:22
@ Parallel
Definition: model.hpp:22
@ Initial
Definition: model.hpp:22
Lifecycle of a basic 'RtcComponent'.
Definition: runnable.hpp:165
ModelBuilder(StateMachineEngine &engine)
Definition: runnable.hpp:167
Life cycle extension to make RtcComponent Runnable.
Definition: runnable.hpp:31