Program Listing for File supervisor_fsm.hpp
↰ Return to documentation for file (cosm/fsm/supervisor_fsm.hpp
)
#pragma once
/*******************************************************************************
* Includes
******************************************************************************/
#include <utility>
#include <variant>
#include "rcppsw/patterns/fsm/simple_fsm.hpp"
#include "cosm/cosm.hpp"
#include "cosm/ta/taskable.hpp"
#include "cosm/subsystem/subsystem_fwd.hpp"
/*******************************************************************************
* Namespaces
******************************************************************************/
namespace cosm::ta {
class base_executive;
} /* namespace ta */
namespace cosm::fsm {
/*******************************************************************************
* Class Definitions
******************************************************************************/
class supervisor_fsm final : public rpfsm::simple_fsm,
public rer::client<supervisor_fsm> {
using supervisee_variant_type =
std::variant<ta::taskable*, ta::base_executive*>;
public:
explicit supervisor_fsm(csubsystem::base_saa_subsystem* saa);
supervisor_fsm& operator=(const supervisor_fsm&) = delete;
supervisor_fsm(const supervisor_fsm&) = delete;
bool state_is_stopped(void) const {
return current_state() == states::ekST_STOP;
}
void event_malfunction(void);
void event_repair(void);
void event_stop(void);
template <typename T>
void supervisee_update(T* h) {
m_supervisee = supervisee_variant_type(h);
}
void run(void) {
inject_event(rpfsm::event_signal::ekRUN, rpfsm::event_type::ekNORMAL);
}
private:
enum states {
ekST_START,
ekST_NORMAL,
ekST_MALFUNCTION,
ekST_STOP,
ekST_MAX_STATES
};
/* supervisor states */
RCPPSW_FSM_STATE_DECLARE_ND(supervisor_fsm, start);
RCPPSW_FSM_STATE_DECLARE_ND(supervisor_fsm, normal);
RCPPSW_FSM_STATE_DECLARE_ND(supervisor_fsm, malfunction);
RCPPSW_FSM_ENTRY_DECLARE_ND(supervisor_fsm, entry_stop);
RCPPSW_FSM_STATE_DECLARE_ND(supervisor_fsm, stop);
RCPPSW_FSM_DEFINE_STATE_MAP_ACCESSOR(state_map_ex, index) override {
return &mc_state_map[index];
}
RCPPSW_FSM_DECLARE_STATE_MAP(state_map_ex,
mc_state_map,
states::ekST_MAX_STATES);
/* clang-format off */
csubsystem::base_saa_subsystem* m_saa;
supervisee_variant_type m_supervisee{};
/* clang-format on */
};
} /* namespace cosm::fsm */