Go to the documentation of this file.
12 #ifndef RTCTK_COMPONENTFRAMEWORK_STDCOMPONENT_HPP
13 #define RTCTK_COMPONENTFRAMEWORK_STDCOMPONENT_HPP
16 #include <rtctk/componentFramework/events.rad.hpp>
26 #include <mal/Cii.hpp>
59 :
stdif::ExceptionErr(
"Request " + request_id +
" rejected in state " + state_id,
90 template <
typename... Options>
105 :
public optional_base<IStarting, RTCTK_IS_OPTION(UseStarting, Enabled)>
106 ,
public optional_base<IInitialising, RTCTK_IS_OPTION(UseInitialising, Enabled)>
107 ,
public optional_base<IEnabling, RTCTK_IS_OPTION(UseEnabling, Enabled)>
108 ,
public optional_base<IDisabling, RTCTK_IS_OPTION(UseDisabling, Enabled)> {
164 auto req = GetPayloadNothrow<events::Reset>(c);
165 if (req ==
nullptr) {
186 engine.
RegisterAction(
"ActionInitialisingFailed", [
this](
auto c) {
187 if(
auto eptr = GetPayloadNothrow<events::Error>(c); eptr) {
196 engine.
RegisterAction(
"ActionInitialisingStopped", [
this](
auto c) {
197 auto req = GetPayloadNothrow<events::Stop>(c);
198 if (req ==
nullptr) {
209 engine.
RegisterAction(
"ActionInitialisingRestarted", [
this](
auto c) {
210 auto req = GetPayloadNothrow<events::Init>(c);
211 if (req ==
nullptr) {
223 auto req = GetPayloadNothrow<events::Init>(c);
224 if (req ==
nullptr) {
246 if(
auto eptr = GetPayloadNothrow<events::Error>(c); eptr) {
256 auto req = GetPayloadNothrow<events::Enable>(c);
257 if (req ==
nullptr) {
279 if(
auto eptr = GetPayloadNothrow<events::Error>(c); eptr) {
289 auto req = GetPayloadNothrow<events::Disable>(c);
290 if (req ==
nullptr) {
300 auto req = GetPayloadNothrow<events::Exit>(c);
301 if (req ==
nullptr) {
312 auto req = GetPayloadNothrow<events::GetState>(c);
313 if (req ==
nullptr) {
323 auto req = GetPayloadNothrow<events::GetVersion>(c);
324 if (req ==
nullptr) {
328 req->SetReplyValue(VERSION);
334 auto req = GetPayloadNothrow<events::SetLogLevel>(c);
335 if (req ==
nullptr) {
339 std::string level = req->GetRequestPayload();
341 log4cplus::LogLevelManager llm;
342 logger.setLogLevel(llm.fromString(level));
344 "Log Level set to " << llm.toString(logger.getLogLevel()));
345 req->SetReplyValue(VERSION);
353 m_logic.ActivityStarting(stop_token);
360 m_logic.ActivityInitialising(stop_token);
367 m_logic.ActivityEnabling(stop_token);
374 m_logic.ActivityDisabling(stop_token);
413 mm.
AddTrans(
"On" ,
"Off" ,
"events.Exit",
"" ,
"ActionExit");
414 mm.
AddTrans(
"On" ,
"" ,
"events.GetState",
"" ,
"ActionGetState");
415 mm.
AddTrans(
"On" ,
"" ,
"events.GetVersion",
"" ,
"ActionGetVersion");
416 mm.
AddTrans(
"On" ,
"" ,
"events.SetLogLevel",
"" ,
"ActionSetLogLevel");
418 mm.
AddTrans(
"On.Initial" ,
"On.NotOperational");
421 mm.
AddState(
Simple,
"On.NotOperational.Starting",
"On.NotOperational",
"ActivityStarting" ,
"ActionStartingEntry");
423 mm.
AddTrans(
"On.NotOperational.Initial" ,
"On.NotOperational.Starting");
424 mm.
AddTrans(
"On.NotOperational.Starting" ,
"On.NotOperational.NotReady" ,
"events.Done",
"" ,
"ActionStartingDone");
426 mm.
AddTrans(
"On.NotOperational.Initial" ,
"On.NotOperational.NotReady" ,
"",
"" ,
"ActionStartingDone");
430 mm.
AddState(
Simple,
"On.NotOperational.Initialising",
"On.NotOperational",
"ActivityInitialising" ,
"ActionInitialisingEntry");
432 mm.
AddTrans(
"On.NotOperational.NotReady" ,
"On.NotOperational.Initialising" ,
"events.Init");
433 mm.
AddTrans(
"On.NotOperational.Initialising" ,
"On.NotOperational.Ready" ,
"events.Done",
"" ,
"ActionInitialisingDone");
434 mm.
AddTrans(
"On.NotOperational.Initialising" ,
"On.NotOperational.NotReady" ,
"events.Error",
"" ,
"ActionInitialisingFailed");
435 mm.
AddTrans(
"On.NotOperational.Initialising" ,
"On.NotOperational.NotReady" ,
"events.Stop",
"" ,
"ActionInitialisingStopped");
436 mm.
AddTrans(
"On.NotOperational.Initialising" ,
"On.NotOperational.Initialising" ,
"events.Init",
"" ,
"ActionInitialisingRestarted");
437 mm.
AddTrans(
"On.NotOperational.Ready" ,
"On.NotOperational.Initialising" ,
"events.Init");
439 mm.
AddTrans(
"On.NotOperational.NotReady" ,
"On.NotOperational.Ready" ,
"events.Init",
"" ,
"ActionInitialisingDone");
443 mm.
AddState(
Simple,
"On.NotOperational.Enabling",
"On.NotOperational",
"ActivityEnabling" ,
"ActionEnablingEntry");
445 mm.
AddTrans(
"On.NotOperational.Ready" ,
"On.NotOperational.Enabling" ,
"events.Enable");
446 mm.
AddTrans(
"On.NotOperational.Enabling" ,
"On.Operational" ,
"events.Done",
"" ,
"ActionEnablingDone");
447 mm.
AddTrans(
"On.NotOperational.Enabling" ,
"On.NotOperational.Ready" ,
"events.Error",
"" ,
"ActionEnablingFailed");
451 mm.
AddTrans(
"On.NotOperational.Ready" ,
"On.Operational" ,
"events.Enable",
"" ,
"ActionEnablingDone");
455 mm.
AddState(
Simple,
"On.NotOperational.Disabling",
"On.NotOperational",
"ActivityDisabling" ,
"ActionDisablingEntry");
456 mm.
AddTrans(
"On.Operational" ,
"On.NotOperational.Disabling" ,
"events.Disable");
457 mm.
AddTrans(
"On.NotOperational.Disabling" ,
"On.NotOperational.Ready" ,
"events.Done",
"" ,
"ActionDisablingDone");
458 mm.
AddTrans(
"On.NotOperational.Disabling" ,
"On.NotOperational.Ready" ,
"events.Error",
"" ,
"ActionDisablingFailed");
460 mm.
AddTrans(
"On.Operational" ,
"On.NotOperational.Ready" ,
"events.Disable",
"" ,
"ActionDisablingDone");
468 #endif // RTCTK_COMPONENTFRAMEWORK_STDCOMPONENT_HPP
A container that can hold any type of service.
RTCTK_ASSERT_OPTION_ED(UseDisabling)
@ Simple
Definition: model.hpp:23
Definition: stdComponent.hpp:52
Receive commands via MAL.
RTCTK_ASSERT_OPTION_ED(UseEnabling)
Provides macros and utilities for exception handling.
Wrapper around the SCXML State Machine Engine.
virtual ~OutputStage()=default
std::shared_ptr< rad::cii::Request< std::string, void > > m_tmp_request
Definition: stdComponent.hpp:384
Implementation of MAL commands for layer 'StdComponent'.
std::error_code Reset(ReaderType &reader)
helper function to reset the ipcq.reader to latest sample
Definition: readerHelpers.hpp:176
RTCTK_ASSERT_OPTION_ED(UseInitialising)
Various utilities for Life Cycle Extension.
void AddTrans(std::string const &source_id, std::string const &target_id, std::string const &event_id="", std::string const &guard_id="", std::string const &action_id="")
Adds a new transition.
Definition: modelManipulator.cpp:227
std::function< void(std::exception_ptr)> m_error_handler
Definition: stdComponent.hpp:386
ModelManipulator mm
Definition: modelBuilderBase.hpp:86
static constexpr int32_t ERROR_CODE
Definition: stdComponent.hpp:45
Definition: commandReplier.cpp:20
RTCTK_DEFINE_OPTION(UseStarting, Disabled)
static constexpr int32_t ERROR_CODE
Definition: stdComponent.hpp:70
const std::string STD_OK_REPLY
Definition: stdComponent.hpp:36
rad::StopToken StopToken
Definition: stopToken.hpp:19
Definition: stateMachineEngine.hpp:31
Basic life cycle for StdComponent.
Definition: stdComponent.hpp:91
std::conditional_t< Condition, T, empty_base< T > > optional_base
Definition: utils.hpp:90
Adapter object intended to be used in contexts without direct access to the output-stream object.
Definition: exceptions.hpp:157
std::function< void()> m_success_handler
Definition: stdComponent.hpp:385
RequestRejected(std::string const &request_id, std::string const &state_id)
Definition: stdComponent.hpp:58
Base class of the ModelBuilder.
Definition: modelBuilderBase.hpp:32
void RegisterAction(std::string const &id, ActionMethod action)
Register action.
Definition: stateMachineEngine.cpp:62
Business Logic Interfaces with methods to be implemented in layer 'StdComponent'.
Base class of the ModelBuilder.
log4cplus::Logger & GetLogger(const std::string &name="")
Get handle to a specific logger (used with logging macros)
#define RTCTK_IS_OPTION(Name, Value)
Definition: utils.hpp:32
StateMachineEngine & m_engine
Definition: stdComponent.hpp:382
std::string Str() const
Convenience function for constructing a std::string from the exception.
Definition: exceptions.hpp:175
OutputStage(StateMachineEngine &engine, BizLogicIf &bl)
Definition: stdComponent.hpp:132
RequestFailed(std::string const &message)
Definition: stdComponent.hpp:71
void RegisterRejectHandler(std::string const &id, RejectMethod reject)
Register reject handler.
Definition: stateMachineEngine.cpp:95
void AddState(StateType type, std::string const &id, std::string const &parent_id="", std::string const &activity_id="", std::string const &entry_action_id="", std::string const &exit_action_id="")
Adds a new state.
Definition: modelManipulator.cpp:29
void RegisterLayer(Layer layer)
Definition: modelBuilderBase.hpp:74
#define RTCTK_APPLY_OPTION_ED(Options, Name)
Definition: utils.hpp:25
Class that handles reception of commands using MAL.
Definition: commandReplier.hpp:26
@ Initial
Definition: model.hpp:26
Definition: stdComponent.hpp:108
Definition: stdComponent.hpp:389
RTCTK_ASSERT_OPTION_ED(UseStarting)
Definition: statePublisher.hpp:24
@ Final
Definition: model.hpp:27
Definition: stdComponent.hpp:65
Logging Support Library based on log4cplus.
RequestAborted()
Definition: stdComponent.hpp:46
int int32_t
Definition: mudpi.h:17
std::string GetState()
Queries the current state.
Definition: stateMachineEngine.cpp:126
Definition: stdComponent.hpp:43
ModelBuilder(StateMachineEngine &engine)
Definition: stdComponent.hpp:391
Definition: stdComponent.hpp:129
Definition: stdComponent.hpp:96
std::false_type Disabled
Definition: utils.hpp:47
BizLogicIf & m_logic
Definition: stdComponent.hpp:383
void PostEvent(rad::SharedEvent s)
Injects a new event into the state machine engine.
Definition: stateMachineEngine.cpp:121
@ Composite
Definition: model.hpp:25
static constexpr int32_t ERROR_CODE
Definition: stdComponent.hpp:57
void Stop()
Stops execution of the state machine event loop.
Definition: stateMachineEngine.cpp:152
void RegisterActivity(std::string const &id, ActivityMethod activity, SuccessMethod on_success, FailureMethod on_failure)
Register activity.
Definition: stateMachineEngine.cpp:87
std::true_type Enabled
Definition: utils.hpp:46
static void Register(CommandReplier &replier, StateMachineEngine &engine)
Definition: stdCmdsImpl.hpp:34