From 4244f76041b4d901a7fe2140ffaa25edfb8f3dd4 Mon Sep 17 00:00:00 2001 From: "Timur A. Fatkhullin" Date: Tue, 20 May 2025 23:32:25 +0300 Subject: [PATCH] ... --- cxx/mount.h | 84 +++++++++++++++++++++++++++++++++++++++++++---- cxx/mount_state.h | 6 ++++ 2 files changed, 83 insertions(+), 7 deletions(-) diff --git a/cxx/mount.h b/cxx/mount.h index 9e3b68f..5e0b30b 100644 --- a/cxx/mount.h +++ b/cxx/mount.h @@ -252,26 +252,96 @@ public: class MccMountState { - public: - MccMountState(MccMount& mount) : _mount(mount) {} + static constexpr std::string_view emptyIdentString{"EMPTY-STRING-MOUNT-STATE-IDENTIFICATOR"}; - virtual ~MccMountState() = default; + public: + MccMountState(MccMount& mount, traits::mcc_input_char_range auto const& ident) + : _mount(mount), _ident({ident.begin(), ident.end()}) + { + _mount.logTrace("Create MccMountState instance: {}", (void*)this); + + if (!_ident.size()) { + _mount.logWarn("An empty input mount state identificator! Use of default value!"); + _ident = emptyIdentString; + } + } + + + MccMountState(MccMount& mount, const char* ident) : MccMountState(mount, std::string_view(ident)) {} + + MccMountState(MccMountState&&) = default; // movable + MccMountState& operator=(MccMountState&&) = default; + + MccMountState(const MccMountState&) = delete; // non-copyable + MccMountState& operator=(const MccMountState&) = delete; + + + virtual ~MccMountState() + { + _mount.logTrace("Delete MccMountState instance: {}", (void)this); + }; + + + std::string_view ident() const + { + return _ident; + } void enter(this std::derived_from auto&& self) { - std::forward(self).enter(); + std::forward(self).enterImpl(); } - void exit(std::derived_from auto next_state) - requires std::movable + void stop(this std::derived_from auto&& self) { - _mount.setMountState(std::move(next_state)); + std::forward(self).stopImpl(); + } + + void exit(this std::derived_from auto&& self, std::derived_from auto next_state) + { + std::forward(self).exitImpl(std::move(next_state)); } protected: MccMount& _mount; + std::string_view _ident; + + void enterImpl() + { + _mount.logWarn("call no-op MccMountState::enterImpl()"); + } + + void stopImpl() + { + _mount.logWarn("call no-op MccMountState::stopImpl()"); + } + + + void exitImpl(std::derived_from auto next_state) + { + _mount.setMountState(std::move(next_state)); + } }; + // default IDLE state + class MccMountStateIDLE : public MccMountState + { + public: + MccMountStateIDLE(MccMount& mount) : MccMountState(mount, "DEFAULT IDLE STATE") {} + + private: + void enterImpl() + { + this->_mount.logInfo("Enter to defalut IDLE state"); + } + + void stopImpl() + { + this->_mount.logWarn("Ignore stop for default IDLE state!"); + } + }; + + /* Constructors and destructor */ MccMount(traits::mcc_input_char_range auto const& logger_mark = "[MOUNT]", diff --git a/cxx/mount_state.h b/cxx/mount_state.h index 4efebd5..0083862 100644 --- a/cxx/mount_state.h +++ b/cxx/mount_state.h @@ -188,4 +188,10 @@ protected: std::function _stopFunc; }; + +template CONFIG_TYPE = MccMountConfig> +class MccMountStateSlew1 : public MccMount::MccMountState +{ +}; + } // namespace mcc