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>
38 LogInfo(std::string
const& level, std::string
const& logger=
"")
39 : m_logger(logger), m_level(level) {
47 void setLogger(std::string
const& logger)
override {
55 void setLevel(std::string
const& level)
override {
63 bool keyEquals(stdif::LogInfo
const& other)
const override {
67 std::unique_ptr<stdif::LogInfo>
clone()
const override {
68 return std::make_unique<LogInfo>(m_logger, m_level);
71 std::unique_ptr<stdif::LogInfo>
cloneKey()
const override {
72 return std::make_unique<LogInfo>(m_logger, m_level);
106 :
stdif::ExceptionErr(
"Request " + request_id +
" rejected in state " + state_id,
137 template <
typename... Options>
152 :
public optional_base<IStarting, RTCTK_IS_OPTION(UseStarting, Enabled)>
153 ,
public optional_base<IInitialising, RTCTK_IS_OPTION(UseInitialising, Enabled)>
154 ,
public optional_base<IEnabling, RTCTK_IS_OPTION(UseEnabling, Enabled)>
155 ,
public optional_base<IDisabling, RTCTK_IS_OPTION(UseDisabling, Enabled)> {
211 auto req = GetPayloadNothrow<events::Reset>(c);
212 if (req ==
nullptr) {
233 engine.
RegisterAction(
"ActionInitialisingFailed", [
this](
auto c) {
234 if(
auto eptr = GetPayloadNothrow<events::Error>(c); eptr) {
243 engine.
RegisterAction(
"ActionInitialisingStopped", [
this](
auto c) {
244 auto req = GetPayloadNothrow<events::Stop>(c);
245 if (req ==
nullptr) {
256 engine.
RegisterAction(
"ActionInitialisingRestarted", [
this](
auto c) {
257 auto req = GetPayloadNothrow<events::Init>(c);
258 if (req ==
nullptr) {
270 auto req = GetPayloadNothrow<events::Init>(c);
271 if (req ==
nullptr) {
293 if(
auto eptr = GetPayloadNothrow<events::Error>(c); eptr) {
303 auto req = GetPayloadNothrow<events::Enable>(c);
304 if (req ==
nullptr) {
326 if(
auto eptr = GetPayloadNothrow<events::Error>(c); eptr) {
336 auto req = GetPayloadNothrow<events::Disable>(c);
337 if (req ==
nullptr) {
347 auto req = GetPayloadNothrow<events::Exit>(c);
348 if (req ==
nullptr) {
359 auto req = GetPayloadNothrow<events::GetState>(c);
360 if (req ==
nullptr) {
370 auto req = GetPayloadNothrow<events::GetStatus>(c);
371 if (req ==
nullptr) {
381 auto req = GetPayloadNothrow<events::GetVersion>(c);
382 if (req ==
nullptr) {
386 req->SetReplyValue(VERSION);
392 auto req = GetPayloadNothrow<events::SetLogLevel>(c);
393 if (req ==
nullptr) {
397 auto loginfo = req->GetRequestPayload();
398 auto selected_logger = loginfo->getLogger();
399 auto& logger =
GetLogger(selected_logger);
400 log4cplus::LogLevelManager llm;
401 auto selected_ll = llm.fromString(loginfo->getLevel());
402 if(selected_ll == log4cplus::NOT_SET_LOG_LEVEL) {
405 logger.setLogLevel(selected_ll);
407 "Log Level of logger '" << loginfo->getLogger() <<
408 "' set to '" << llm.toString(logger.getLogLevel()) <<
"'");
418 m_logic.ActivityStarting(stop_token);
425 m_logic.ActivityInitialising(stop_token);
432 m_logic.ActivityEnabling(stop_token);
439 m_logic.ActivityDisabling(stop_token);
478 mm.
AddTrans(
"On" ,
"Off" ,
"events.Exit",
"" ,
"ActionExit");
479 mm.
AddTrans(
"On" ,
"" ,
"events.GetState",
"" ,
"ActionGetState");
480 mm.
AddTrans(
"On" ,
"" ,
"events.GetStatus",
"" ,
"ActionGetStatus");
481 mm.
AddTrans(
"On" ,
"" ,
"events.GetVersion",
"" ,
"ActionGetVersion");
482 mm.
AddTrans(
"On" ,
"" ,
"events.SetLogLevel",
"" ,
"ActionSetLogLevel");
484 mm.
AddTrans(
"On:Initial" ,
"On:NotOperational");
487 mm.
AddState(
Simple,
"On:NotOperational:Starting",
"On:NotOperational",
"ActivityStarting" ,
"ActionStartingEntry");
489 mm.
AddTrans(
"On:NotOperational:Initial" ,
"On:NotOperational:Starting");
490 mm.
AddTrans(
"On:NotOperational:Starting" ,
"On:NotOperational:NotReady" ,
"events.Done",
"" ,
"ActionStartingDone");
492 mm.
AddTrans(
"On:NotOperational:Initial" ,
"On:NotOperational:NotReady" ,
"",
"" ,
"ActionStartingDone");
496 mm.
AddState(
Simple,
"On:NotOperational:Initialising",
"On:NotOperational",
"ActivityInitialising" ,
"ActionInitialisingEntry");
498 mm.
AddTrans(
"On:NotOperational:NotReady" ,
"On:NotOperational:Initialising" ,
"events.Init");
499 mm.
AddTrans(
"On:NotOperational:Initialising" ,
"On:NotOperational:Ready" ,
"events.Done",
"" ,
"ActionInitialisingDone");
500 mm.
AddTrans(
"On:NotOperational:Initialising" ,
"On:NotOperational:NotReady" ,
"events.Error",
"" ,
"ActionInitialisingFailed");
501 mm.
AddTrans(
"On:NotOperational:Initialising" ,
"On:NotOperational:NotReady" ,
"events.Stop",
"" ,
"ActionInitialisingStopped");
502 mm.
AddTrans(
"On:NotOperational:Initialising" ,
"On:NotOperational:Initialising" ,
"events.Init",
"" ,
"ActionInitialisingRestarted");
503 mm.
AddTrans(
"On:NotOperational:Ready" ,
"On:NotOperational:Initialising" ,
"events.Init");
505 mm.
AddTrans(
"On:NotOperational:NotReady" ,
"On:NotOperational:Ready" ,
"events.Init",
"" ,
"ActionInitialisingDone");
509 mm.
AddState(
Simple,
"On:NotOperational:Enabling",
"On:NotOperational",
"ActivityEnabling" ,
"ActionEnablingEntry");
511 mm.
AddTrans(
"On:NotOperational:Ready" ,
"On:NotOperational:Enabling" ,
"events.Enable");
512 mm.
AddTrans(
"On:NotOperational:Enabling" ,
"On:Operational" ,
"events.Done",
"" ,
"ActionEnablingDone");
513 mm.
AddTrans(
"On:NotOperational:Enabling" ,
"On:NotOperational:Ready" ,
"events.Error",
"" ,
"ActionEnablingFailed");
517 mm.
AddTrans(
"On:NotOperational:Ready" ,
"On:Operational" ,
"events.Enable",
"" ,
"ActionEnablingDone");
521 mm.
AddState(
Simple,
"On:NotOperational:Disabling",
"On:NotOperational",
"ActivityDisabling" ,
"ActionDisablingEntry");
522 mm.
AddTrans(
"On:Operational" ,
"On:NotOperational:Disabling" ,
"events.Disable");
523 mm.
AddTrans(
"On:NotOperational:Disabling" ,
"On:NotOperational:Ready" ,
"events.Done",
"" ,
"ActionDisablingDone");
524 mm.
AddTrans(
"On:NotOperational:Disabling" ,
"On:NotOperational:Ready" ,
"events.Error",
"" ,
"ActionDisablingFailed");
526 mm.
AddTrans(
"On:Operational" ,
"On:NotOperational:Ready" ,
"events.Disable",
"" ,
"ActionDisablingDone");
534 #endif // RTCTK_COMPONENTFRAMEWORK_STDCOMPONENT_HPP
A container that can hold any type of service.
RTCTK_ASSERT_OPTION_ED(UseDisabling)
std::unique_ptr< stdif::LogInfo > clone() const override
Definition: stdComponent.hpp:67
Definition: stdComponent.hpp:90
@ Simple
Definition: model.hpp:23
Receive commands via MAL.
RTCTK_ASSERT_OPTION_ED(UseEnabling)
Provides macros and utilities for exception handling.
static constexpr int32_t ERROR_CODE
Definition: stdComponent.hpp:117
Wrapper around the SCXML State Machine Engine.
virtual ~OutputStage()=default
LogInfo(std::string const &level, std::string const &logger="")
Definition: stdComponent.hpp:38
std::shared_ptr< rad::cii::Request< std::string, void > > m_tmp_request
Definition: stdComponent.hpp:449
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:157
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:451
ModelManipulator mm
Definition: modelBuilderBase.hpp:86
StdIfRequestFailed(std::string const &message)
Definition: stdComponent.hpp:118
Definition: commandReplier.cpp:20
RTCTK_DEFINE_OPTION(UseStarting, Disabled)
Definition: stdComponent.hpp:99
bool keyEquals(stdif::LogInfo const &other) const override
Definition: stdComponent.hpp:63
const std::string STD_OK_REPLY
Definition: stdComponent.hpp:83
rad::StopToken StopToken
Definition: stopToken.hpp:19
Definition: stateMachineEngine.hpp:31
Basic life cycle for StdComponent.
Definition: stdComponent.hpp:138
std::unique_ptr< stdif::LogInfo > cloneKey() const override
Definition: stdComponent.hpp:71
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:450
Base class of the ModelBuilder.
Definition: modelBuilderBase.hpp:32
StdIfRequestRejected(std::string const &request_id, std::string const &state_id)
Definition: stdComponent.hpp:105
static constexpr int32_t ERROR_CODE
Definition: stdComponent.hpp:104
void RegisterAction(std::string const &id, ActionMethod action)
Register action.
Definition: stateMachineEngine.cpp:65
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:447
std::string getLevel() const override
Definition: stdComponent.hpp:51
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:179
void RegisterRejectHandler(std::string const &id, RejectMethod reject)
Register reject handler.
Definition: stateMachineEngine.cpp:98
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
static constexpr int32_t ERROR_CODE
Definition: stdComponent.hpp:92
#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:155
Definition: stdComponent.hpp:454
RTCTK_ASSERT_OPTION_ED(UseStarting)
Definition: statePublisher.hpp:24
@ Final
Definition: model.hpp:27
Definition: stdComponent.hpp:33
Logging Support Library based on log4cplus.
int int32_t
Definition: mudpi.h:17
std::string getLogger() const override
Definition: stdComponent.hpp:43
std::string GetState()
Queries the current state.
Definition: stateMachineEngine.cpp:129
ModelBuilder(StateMachineEngine &engine)
Definition: stdComponent.hpp:456
Definition: stdComponent.hpp:176
Definition: stdComponent.hpp:143
std::false_type Disabled
Definition: utils.hpp:47
BizLogicIf & m_logic
Definition: stdComponent.hpp:448
void PostEvent(rad::SharedEvent s)
Injects a new event into the state machine engine.
Definition: stateMachineEngine.cpp:124
Definition: stdComponent.hpp:112
@ Composite
Definition: model.hpp:25
bool hasKey() const override
Definition: stdComponent.hpp:59
void setLevel(std::string const &level) override
Definition: stdComponent.hpp:55
StdIfRequestAborted()
Definition: stdComponent.hpp:93
void setLogger(std::string const &logger) override
Definition: stdComponent.hpp:47
void Stop()
Stops execution of the state machine event loop.
Definition: stateMachineEngine.cpp:155
void RegisterActivity(std::string const &id, ActivityMethod activity, SuccessMethod on_success, FailureMethod on_failure)
Register activity.
Definition: stateMachineEngine.cpp:90
std::true_type Enabled
Definition: utils.hpp:46
static void Register(CommandReplier &replier, StateMachineEngine &engine)
Definition: stdCmdsImpl.hpp:34