...
This commit is contained in:
60
cxx/mount_state.h
Normal file
60
cxx/mount_state.h
Normal file
@@ -0,0 +1,60 @@
|
||||
#pragma once
|
||||
|
||||
#include "mount.h"
|
||||
|
||||
|
||||
namespace mcc::traits
|
||||
{
|
||||
|
||||
template <typename T, mcc::MccMountType MOUNT_TYPE>
|
||||
concept mcc_mount_c = std::derived_from<T, mcc::MccMount<MOUNT_TYPE>>;
|
||||
|
||||
} // namespace mcc::traits
|
||||
|
||||
namespace mcc
|
||||
{
|
||||
|
||||
class MccMountAbstractState
|
||||
{
|
||||
std::function<void()> _getMountStateFunc{[]() {}};
|
||||
|
||||
public:
|
||||
typedef std::error_code mount_state_error_t;
|
||||
|
||||
typedef std::function<void(const mount_state_error_t&)> enter_callback_t;
|
||||
typedef std::function<void(const mount_state_error_t&)> exit_callback_t;
|
||||
typedef std::function<void(const mount_state_error_t&)> error_callback_t;
|
||||
|
||||
// helper
|
||||
static constexpr auto mcc_noop_callback = [](const mount_state_error_t&) {};
|
||||
|
||||
template <MccMountType MOUNT_TYPE>
|
||||
MccMountAbstractState(traits::mcc_mount_c<MOUNT_TYPE> auto* mount_ptr,
|
||||
std::convertible_to<enter_callback_t> auto&& enter_callback,
|
||||
std::convertible_to<exit_callback_t> auto&& exit_callback,
|
||||
std::convertible_to<error_callback_t> auto&& error_callback)
|
||||
{
|
||||
_getMountStateFunc = [&mount_ptr, this]() { auto mstate = mount_ptr->getMountData(); };
|
||||
}
|
||||
|
||||
|
||||
virtual ~MccMountAbstractState() = default;
|
||||
|
||||
|
||||
std::string_view ident() const
|
||||
{
|
||||
return "MCC-ABSTRACT-MOUNT-STATE";
|
||||
}
|
||||
|
||||
|
||||
void enter() {}
|
||||
|
||||
void exit() {}
|
||||
|
||||
protected:
|
||||
enter_callback_t _enterCallback{[](const mount_state_error_t&) {}};
|
||||
exit_callback_t _exitCallback{[](const mount_state_error_t&) {}};
|
||||
error_callback_t _errorCallback{[](const mount_state_error_t&) {}};
|
||||
};
|
||||
|
||||
} // namespace mcc
|
||||
Reference in New Issue
Block a user