Go to the documentation of this file.
12 #ifndef RTCTK_COMPONENTFRAMEWORK_MEASURABLE_HPP
13 #define RTCTK_COMPONENTFRAMEWORK_MEASURABLE_HPP
43 : m_request(request), m_arg() {
44 m_arg = JsonPayload::parse(m_request.GetRequestPayload());
59 m_result = result.dump();
69 m_request.SetReplyValue(m_result);
70 }
catch (std::exception
const& exception) {
73 "MeasureContext::SendReply: Failed to send reply: " << exception.what());
77 "MeasureContext::SendReply: Failed to send reply with unknown exception.");
86 m_request.SetException(
91 "MeasureContext::SendErrorReply: Failed to send reply: " << exception.what());
95 "MeasureContext::SendErrorReply: Failed to send reply with unknown exception.");
100 rad::cii::Request<std::string, std::string> m_request;
108 std::string m_result;
145 template <
typename Super>
147 static_assert(std::is_base_of_v<RtcComponent, Super>,
"'Measurable' requires 'RtcComponent'");
187 using Super::InputStage::InputStage;
190 Super::InputStage::Start();
204 this->m_engine.PostEvent(std::make_unique<events::MeasureDone>());
208 this->m_engine.PostEvent(std::make_unique<events::MeasureError>(eptr));
213 this->m_no_disable_in_states.push_back(
"On:Operational:MeasureBusy");
217 this->m_no_update_in_states.push_back(
"On:Operational:MeasureBusy");
226 "GuardMeasuringAllowed", [
this](events::Measure
const& ev) {
235 auto act_state = this->m_engine.GetState();
237 if (act_state.find(s) != std::string::npos) {
243 .GuardMeasuringAllowed(ctx.
GetArg())) {
259 .ActivityMeasuring(std::move(stop_token),
m_measure_ctx->GetArg());
274 "ActionMeasuringFailed", [
this](events::MeasureError
const& ev) {
292 this->RegisterLayer({
"Measurable", {}});
294 this->mm.AddState(
Composite,
"On:Operational:RegionMeasure",
"On:Operational");
295 this->mm.AddState(
Initial,
"On:Operational:MeasureInitial",
"On:Operational:RegionMeasure");
296 this->mm.AddState(
Simple,
"On:Operational:MeasureIdle",
"On:Operational:RegionMeasure");
297 this->mm.AddState(
Simple,
"On:Operational:MeasureBusy",
"On:Operational:RegionMeasure",
"ActivityMeasuring");
299 this->mm.AddTrans(
"On:Operational:MeasureInitial" ,
"On:Operational:MeasureIdle" );
300 this->mm.AddTrans(
"On:Operational:MeasureIdle",
301 "On:Operational:MeasureBusy",
303 "GuardMeasuringAllowed");
304 this->mm.AddTrans(
"On:Operational:MeasureBusy",
305 "On:Operational:MeasureIdle",
306 events::MeasureDone::ID,
308 "ActionMeasuringDone");
309 this->mm.AddTrans(
"On:Operational:MeasureBusy",
310 "On:Operational:MeasureIdle",
311 events::MeasureError::ID,
313 "ActionMeasuringFailed");
@ Simple
Definition: model.hpp:23
Definition: rtcComponent.hpp:34
ModelBuilder(StateMachineEngine &engine)
Definition: measurable.hpp:291
Provides macros and utilities for exception handling.
Life cycle extension to make RtcComponent Measurable.
Definition: measurable.hpp:146
void SendReply() noexcept
Send reply using result set with SetResult().
Definition: measurable.hpp:67
OutputStage(StateMachineEngine &engine, BizLogicIf &bl)
Definition: measurable.hpp:198
Definition: commandReplier.cpp:20
void RegisterGuardStatic(std::string const &id, std::function< bool(Event const &)> guard)
Register guard for statically known event type.
Definition: stateMachineEngine.hpp:112
Business logic interface for Measurable mixin.
Definition: measurable.hpp:152
Runnable< RtcComponent > Super
Definition: rtcSupervisor.hpp:33
The RtctkException class is the base class for all Rtctk exceptions.
Definition: exceptions.hpp:207
Definition: measurable.hpp:196
std::function< void(std::exception_ptr)> m_measure_error_handler
Definition: measurable.hpp:285
rad::StopToken StopToken
Definition: stopToken.hpp:19
void RegisterActionStatic(std::string const &id, std::function< void(Event const &)> action)
Register action for statically known event type.
Definition: stateMachineEngine.hpp:79
Implementation of MAL commands for layer 'Measurable'.
Definition: stateMachineEngine.hpp:31
Adapter object intended to be used in contexts without direct access to the output-stream object.
Definition: exceptions.hpp:157
MeasureContext(rad::cii::Request< std::string, std::string > const &request)
Construct context with provided request.
Definition: measurable.hpp:42
void RegisterAction(std::string const &id, ActionMethod action)
Register action.
Definition: stateMachineEngine.cpp:65
log4cplus::Logger & GetLogger(const std::string &name="")
Get handle to a specific logger (used with logging macros)
static void Register(CommandReplier &replier, StateMachineEngine &engine)
Definition: measCmdsImpl.hpp:34
virtual JsonPayload ActivityMeasuring(StopToken stop_token, JsonPayload const &arg)
Activity executed in its own thread that peforms the requested measurement specified by JSON argument...
Definition: measurable.hpp:166
JsonPayload const & GetArg() const noexcept
Definition: measurable.hpp:48
MeasureContext(MeasureContext &&) noexcept=default
void SetResult(JsonPayload const &result)
Sets serialized reply from JSON payload, but does not send it.
Definition: measurable.hpp:58
Defines the JSON payload type JsonPayload.
void RegisterRejectHandler(std::string const &id, RejectMethod reject)
Register reject handler.
Definition: stateMachineEngine.cpp:98
std::list< std::string > m_no_measure_in_states
Definition: measurable.hpp:286
void SendErrorReply(std::exception_ptr eptr) noexcept
If reply is pending, set exception to the provided value.
Definition: measurable.hpp:84
@ Initial
Definition: model.hpp:26
Definition: measurable.hpp:289
virtual bool GuardMeasuringAllowed(JsonPayload const &arg)
Determines if measurement is possible at this time with the provided argument.
Definition: measurable.hpp:180
Lifecycle of a basic 'RtcComponent'.
Definition: rtcComponent.hpp:44
Holds context necessary for processing a measure request to completion.
Definition: measurable.hpp:34
std::function< void()> m_measure_success_handler
Definition: measurable.hpp:284
@ Composite
Definition: model.hpp:25
void RegisterActivity(std::string const &id, ActivityMethod activity, SuccessMethod on_success, FailureMethod on_failure)
Register activity.
Definition: stateMachineEngine.cpp:90
nlohmann::json JsonPayload
Type requirements:
Definition: jsonPayload.hpp:24
std::optional< detail::MeasureContext > m_measure_ctx
Context storage used for each accepted Measure request.
Definition: measurable.hpp:283