12 #ifndef RTCTK_COMPONENTFRAMEWORK_LOOPAWARE_HPP
13 #define RTCTK_COMPONENTFRAMEWORK_LOOPAWARE_HPP
21 template <
typename Super>
29 template <
typename Super>
31 static_assert(std::is_base_of_v<RtcComponent, Super>,
"'Loopaware' requires 'RtcComponent'");
32 static_assert(not is_base_of_template_v<Runnable, Super>,
"'Loopaware' excludes 'Runnable'");
47 using Super::InputStage::InputStage;
50 Super::InputStage::Start();
70 this->m_no_disable_in_states.push_back(
"On:Operational:Error");
71 this->m_no_disable_in_states.push_back(
"On:Operational:Recovering");
72 this->m_no_disable_in_states.push_back(
"On:Operational:GoingRunning");
73 this->m_no_disable_in_states.push_back(
"On:Operational:GoingIdle");
74 this->m_no_disable_in_states.push_back(
"On:Operational:Opened");
75 this->m_no_disable_in_states.push_back(
"On:Operational:Closed");
76 this->m_no_disable_in_states.push_back(
"On:Operational:Opening");
77 this->m_no_disable_in_states.push_back(
"On:Operational:Closing");
81 this->m_no_update_in_states.push_back(
"On:Operational:Error");
82 this->m_no_update_in_states.push_back(
"On:Operational:Recovering");
83 this->m_no_update_in_states.push_back(
"On:Operational:GoingRunning");
84 this->m_no_update_in_states.push_back(
"On:Operational:GoingIdle");
85 this->m_no_update_in_states.push_back(
"On:Operational:Opening");
86 this->m_no_update_in_states.push_back(
"On:Operational:Closing");
91 this->m_tmp_request = GetPayloadNothrow<events::Run>(c);
95 if (this->m_tmp_request) {
97 this->m_tmp_request =
nullptr;
102 this->m_tmp_request = GetPayloadNothrow<events::Idle>(c);
106 if (this->m_tmp_request) {
108 this->m_tmp_request =
nullptr;
113 this->m_tmp_request = GetPayloadNothrow<events::Open>(c);
117 if (this->m_tmp_request) {
119 this->m_tmp_request =
nullptr;
124 this->m_tmp_request = GetPayloadNothrow<events::Close>(c);
128 if (this->m_tmp_request) {
130 this->m_tmp_request =
nullptr;
135 if(
auto eptr = GetPayloadNothrow<events::Error>(c); eptr) {
136 if (this->m_tmp_request) {
137 this->m_tmp_request->SetException(
139 this->m_tmp_request =
nullptr;
145 this->m_tmp_request = GetPayloadNothrow<events::Recover>(c);
149 if (this->m_tmp_request) {
151 this->m_tmp_request =
nullptr;
159 static_cast<BizLogicIf&
>(this->m_logic).ActivityGoingRunning(stop_token);
160 }, this->m_success_handler, this->m_error_handler);
164 static_cast<BizLogicIf&
>(this->m_logic).ActivityGoingIdle(stop_token);
165 }, this->m_success_handler, this->m_error_handler);
169 static_cast<BizLogicIf&
>(this->m_logic).ActivityOpening(stop_token);
170 }, this->m_success_handler, this->m_error_handler);
174 static_cast<BizLogicIf&
>(this->m_logic).ActivityClosing(stop_token);
175 }, this->m_success_handler, this->m_error_handler);
179 static_cast<BizLogicIf&
>(this->m_logic).ActivityOpened(stop_token);
180 }, {}, this->m_error_handler);
184 static_cast<BizLogicIf&
>(this->m_logic).ActivityClosed(stop_token);
185 }, {}, this->m_error_handler);
189 static_cast<BizLogicIf&
>(this->m_logic).ActivityRecovering(stop_token);
190 }, this->m_success_handler, this->m_error_handler);
197 this->RegisterLayer({
"Loopaware", {}});
199 const std::string parent_region =
"On:Operational:RegionMain";
201 this->mm.AddState(
Composite, parent_region,
"On:Operational");
203 this->mm.AddState(
Initial,
"On:Operational:Initial", parent_region);
204 this->mm.AddState(
Simple,
"On:Operational:Idle", parent_region);
205 this->mm.AddState(
Simple,
"On:Operational:Error", parent_region,
"" ,
"ActionErrorEntry");
206 this->mm.AddState(
Simple,
"On:Operational:Recovering", parent_region,
"ActivityRecovering" ,
"ActionRecoveringEntry");
207 this->mm.AddState(
Simple,
"On:Operational:GoingRunning", parent_region,
"ActivityGoingRunning" ,
"ActionGoingRunningEntry");
208 this->mm.AddState(
Simple,
"On:Operational:GoingIdle", parent_region,
"ActivityGoingIdle" ,
"ActionGoingIdleEntry");
209 this->mm.AddState(
Simple,
"On:Operational:Opened", parent_region,
"ActivityOpened");
210 this->mm.AddState(
Simple,
"On:Operational:Closed", parent_region,
"ActivityClosed");
211 this->mm.AddState(
Simple,
"On:Operational:Opening", parent_region,
"ActivityOpening" ,
"ActionOpeningEntry");
212 this->mm.AddState(
Simple,
"On:Operational:Closing", parent_region,
"ActivityClosing" ,
"ActionClosingEntry");
214 this->mm.AddTrans(
"On:Operational:Initial" ,
"On:Operational:Idle" );
215 this->mm.AddTrans(parent_region ,
"On:Operational:Error" ,
"events.Error");
217 this->mm.AddTrans(
"On:Operational:Error" ,
"On:Operational:Recovering" ,
"events.Recover");
218 this->mm.AddTrans(
"On:Operational:Recovering" ,
"On:Operational:Idle" ,
"events.Done",
"" ,
"ActionRecoveringDone");
220 this->mm.AddTrans(
"On:Operational:Idle" ,
"On:Operational:GoingRunning",
"events.Run");
221 this->mm.AddTrans(
"On:Operational:GoingRunning" ,
"On:Operational:Opened" ,
"events.Done",
"" ,
"ActionGoingRunningDone");
223 this->mm.AddTrans(
"On:Operational:Opened" ,
"On:Operational:GoingIdle" ,
"events.Idle");
224 this->mm.AddTrans(
"On:Operational:GoingIdle" ,
"On:Operational:Idle" ,
"events.Done",
"" ,
"ActionGoingIdleDone");
226 this->mm.AddTrans(
"On:Operational:Opened" ,
"On:Operational:Closing" ,
"events.Close");
227 this->mm.AddTrans(
"On:Operational:Closing" ,
"On:Operational:Closed" ,
"events.Done",
"" ,
"ActionClosingDone");
228 this->mm.AddTrans(
"On:Operational:Closed" ,
"On:Operational:Opening" ,
"events.Open");
229 this->mm.AddTrans(
"On:Operational:Opening" ,
"On:Operational:Opened" ,
"events.Done",
"" ,
"ActionOpeningDone");