Go to the documentation of this file.
12 #ifndef RTCTK_COMPONENTFRAMEWORK_OPTIMISABLE_HPP
13 #define RTCTK_COMPONENTFRAMEWORK_OPTIMISABLE_HPP
40 : m_request(request), m_arg() {
41 m_arg = JsonPayload::parse(m_request.GetRequestPayload());
60 }
catch (std::exception
const& exception) {
63 "OptimiseContext::SendReply: Failed to send reply: " << exception.what());
67 "OptimiseContext::SendReply: Failed to send reply with unknown exception.");
78 m_request.SetException(
86 rad::cii::Request<std::string, std::string> m_request;
121 template <
typename Super>
123 static_assert(std::is_base_of_v<RtcComponent, Super>,
"'Optimisable' requires 'RtcComponent'");
158 using Super::InputStage::InputStage;
161 Super::InputStage::Start();
175 this->m_engine.PostEvent(std::make_unique<events::OptimiseDone>());
179 this->m_engine.PostEvent(std::make_unique<events::OptimiseError>(eptr));
184 this->m_no_disable_in_states.push_back(
"On:Operational:OptimiseBusy");
188 this->m_no_update_in_states.push_back(
"On:Operational:OptimiseBusy");
197 "GuardOptimisingAllowed",
198 [
this](events::Optimise
const& ev) ->
bool {
207 auto act_state = this->m_engine.GetState();
209 if (act_state.find(s) != std::string::npos) {
215 .GuardOptimisingAllowed(ctx.
GetArg())) {
229 "ActivityOptimising",
240 "ActionOptimisingDone",
241 [
this](events::OptimiseDone
const&) {
248 "ActionOptimisingFailed",
249 [
this](events::OptimiseError
const& ev) {
265 this->RegisterLayer({
"Optimisable", {}});
267 this->mm.AddState(
Composite,
"On:Operational:RegionOptimise",
"On:Operational");
268 this->mm.AddState(
Initial,
"On:Operational:OptimiseInitial",
"On:Operational:RegionOptimise");
269 this->mm.AddState(
Simple,
"On:Operational:OptimiseIdle",
"On:Operational:RegionOptimise");
270 this->mm.AddState(
Simple,
"On:Operational:OptimiseBusy",
"On:Operational:RegionOptimise",
"ActivityOptimising");
272 this->mm.AddTrans(
"On:Operational:OptimiseInitial" ,
"On:Operational:OptimiseIdle" );
273 this->mm.AddTrans(
"On:Operational:OptimiseIdle",
274 "On:Operational:OptimiseBusy",
275 events::Optimise::ID,
276 "GuardOptimisingAllowed");
277 this->mm.AddTrans(
"On:Operational:OptimiseBusy",
278 "On:Operational:OptimiseIdle",
279 events::OptimiseDone::ID,
281 "ActionOptimisingDone");
282 this->mm.AddTrans(
"On:Operational:OptimiseBusy",
283 "On:Operational:OptimiseIdle",
284 events::OptimiseError::ID,
286 "ActionOptimisingFailed");
OptimiseContext(rad::cii::Request< std::string, std::string > const &request)
Construct context with provided request.
Definition: optimisable.hpp:39
OptimiseContext(OptimiseContext &&) noexcept=default
@ Simple
Definition: model.hpp:23
Definition: rtcComponent.hpp:34
Provides macros and utilities for exception handling.
virtual void ActivityOptimising(StopToken st, JsonPayload const &arg)
Activity executed in its own thread that performs the requested optimization.
Definition: optimisable.hpp:140
static void Register(CommandReplier &replier, StateMachineEngine &engine)
Definition: optCmdsImpl.hpp:34
ModelBuilder(StateMachineEngine &engine)
Definition: optimisable.hpp:264
Definition: commandReplier.cpp:20
std::function< void(std::exception_ptr)> m_optimise_error_handler
Definition: optimisable.hpp:258
void RegisterGuardStatic(std::string const &id, std::function< bool(Event const &)> guard)
Register guard for statically known event type.
Definition: stateMachineEngine.hpp:112
Runnable< RtcComponent > Super
Definition: rtcSupervisor.hpp:33
const std::string STD_OK_REPLY
Definition: stdComponent.hpp:83
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
Definition: stateMachineEngine.hpp:31
virtual bool GuardOptimisingAllowed(JsonPayload const &arg)
Determines if optimising is possible at this time with the provided argument.
Definition: optimisable.hpp:151
Adapter object intended to be used in contexts without direct access to the output-stream object.
Definition: exceptions.hpp:157
void SendReply() noexcept
Sends hardcoded string reply.
Definition: optimisable.hpp:57
OutputStage(StateMachineEngine &engine, BizLogicIf &bl)
Definition: optimisable.hpp:169
log4cplus::Logger & GetLogger(const std::string &name="")
Get handle to a specific logger (used with logging macros)
Life cycle extension to make RtcComponent Optimisable.
Definition: optimisable.hpp:122
void SendErrorReply(std::exception_ptr eptr) noexcept
Send exceptional reply.
Definition: optimisable.hpp:76
Definition: optimisable.hpp:262
Defines the JSON payload type JsonPayload.
void RegisterRejectHandler(std::string const &id, RejectMethod reject)
Register reject handler.
Definition: stateMachineEngine.cpp:98
@ Initial
Definition: model.hpp:26
Definition: optimisable.hpp:167
Lifecycle of a basic 'RtcComponent'.
Definition: rtcComponent.hpp:44
std::list< std::string > m_no_optimise_in_states
Definition: optimisable.hpp:259
Business logic interface for Optimisable mixin.
Definition: optimisable.hpp:128
@ Composite
Definition: model.hpp:25
Holds context necessary for processing a optimise request to completion.
Definition: optimisable.hpp:31
std::function< void()> m_optimise_success_handler
Definition: optimisable.hpp:257
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
JsonPayload const & GetArg() const noexcept
Definition: optimisable.hpp:48
std::optional< detail::OptimiseContext > m_optimise_ctx
Definition: optimisable.hpp:256
Implementation of MAL commands for layer 'Optimisable'.