engine_enabled
engine_enabled<Base>
is a helper class that uses CRTP to aid in setting up you classes for easy use of the engine
class. It also provides configurations and member function bindings to remove common boiler plate.
If the base class satisisfies the details::HasInitialise<F>
concept (has a void initialise() noexcept
) method, this method will be called on engine start.
If the base class satisisfies the details::HasMain<F>
concept (has a void main() noexcept
) method, this method will be called on a loop of cadence kMainCadence.
The base class can configure its bindings by overiding the members zab::details::configs
which is a parent of engine_enabled<Base>
.
-
struct zab::details::configs
Since we cannot enforce std::is_base_of<engine_enabled<Base>, Base> due to circular depandancy we instead have a common ancestor to both Base and engine_enabled (configs -> engine_enabled -> Base).
An object could still satisfy std::is_base_of<configs, Base> by directly inheriting from configs instead of engine_enabled. But if they purposely do this then they can expect things to break :)
Subclassed by zab::engine_enabled< observable< Args… > >, zab::engine_enabled< Base >
Public Static Attributes
-
static constexpr auto kMainCadence = order::seconds(30)
-
static constexpr auto kDefaultThread = thread_t::any_thread()
-
static constexpr auto kInitialiseThread = thread_t::any_thread()
-
static constexpr auto kMainThread = thread_t::any_thread()
-
static constexpr auto kMainCadence = order::seconds(30)
zab::engine_enabled
The engine_enabled<Base>
provides easy access to Asynchronous Primitives and use of the proxy
primitive.
-
template<typename Base>
class zab::engine_enabled : public zab::details::configs This class describes an engine enabled wrapper for class.
- Template Parameters
Base – The class to wrap.
Public Functions
-
engine_enabled() = default
Default constructed.
-
~engine_enabled() = default
Default destroyed.
-
template<typename F = Base>
inline bool register_engine(engine &_engine) noexcept Register this class with an
engine
If the class statisfies
details::HasInitialise<F>
theninitialise()
will be called on engine start.If the class satisfies
details::HasMain<F>
thenmain()
will be called on a loop of cadencekMainCadence
. The Base class can overwrite the value ofkMainCadence
.If the class satisfies
details::HasAPI<F>
then theAPI
returned byAPIInterface()
will registered against theengine
s interface. If the does not provide akSlotToUse
then one is dynamically selected and the class must provide aSlot(size_t)
function will report the slot provided.Usuage of
YieldCode()
,HitAPI()
,Respond()
orFail()
results in undefined behaviour if an engine has not been registered.- Parameters
_engine – The engine to register against.
- Template Parameters
F – The
Base
class.- Returns
true if successful, 0 otherwise.
Protected Types
-
using async_member = async_function<Promise> (Base::*)(Parameters...)
-
template<typename Promise, typename ...Parameters>
using async_member_c = async_function<Promise> (Base::*)(Parameters...) const
-
template<typename Promise, typename Return, typename ...Parameters>
using simple_member = simple_future<Return, Promise> (Base::*)(Parameters...)
-
template<typename Promise, typename Return, typename ...Parameters>
using simple_member_c = simple_future<Return, Promise> (Base::*)(Parameters...) const
-
template<typename Promise, typename Return, typename ...Parameters>
using reusable_member = reusable_future<Return, Promise> (Base::*)(Parameters...)
-
template<typename Promise, typename Return, typename ...Parameters>
using reusable_member_c = reusable_future<Return, Promise> (Base::*)(Parameters...) const
Protected Functions
- template<typename Functor> requires (std::is_nothrow_invocable_v< Functor >) inline void code_block(Functor &&_cb
Defer some code to be executed at a later time.
- Parameters
_cb – [in] The code to execute later.
_ordering – [in] The ordering to apply.
_thread – [in] The thread to use.
-
template<typename Promise, typename ...Args, typename ...Parameters>
inline async_function proxy(async_member<Promise, Parameters...> _func, thread_t _required_thread, Args... _args) noexcept
-
template<typename Promise, typename ...Args, typename ...Parameters>
inline async_function proxy(async_member_c<Promise, Parameters...> _func, thread_t _required_thread, Args... _args) const noexcept
-
template<typename Promise, typename ...Args, typename Return, typename ...Parameters>
inline simple_future<Return, Promise> proxy(simple_member<Promise, Return, Parameters...> _func, thread_t _required_thread, Args... _args) noexcept
-
template<typename Promise, typename ...Args, typename Return, typename ...Parameters>
inline simple_future<Return> proxy(simple_member_c<Promise, Return, Parameters...> _func, thread_t _required_thread, Args... _args) const noexcept
-
template<typename Promise, typename ...Args, typename Return, typename ...Parameters>
inline reusable_future<Return> proxy(reusable_member<Promise, Return, Parameters...> _func, thread_t _required_thread, Args... _args) noexcept
-
template<typename Promise, typename ...Args, typename Return, typename ...Parameters>
inline reusable_future<Return> proxy(reusable_member_c<Promise, Return, Parameters...> _func, thread_t _required_thread, Args... _args) noexcept
Protected Static Functions
-
static inline constexpr order_t order(int64_t _order) noexcept
Create an order_t.
- Parameters
_order – [in] The order to apply.
- Returns
The order_t.
-
static inline constexpr order_t next() noexcept
Create an order_t that specifies to be executed next.
- Returns
The order_t.
-
static inline constexpr thread_t thread(std::uint16_t _thread) noexcept
Create a thread_t targeting a spercific thread.
- Parameters
_thread – [in] The thread to target.
- Returns
The thread_t.
Friends
-
inline friend void swap(engine_enabled &_first, engine_enabled &_second) noexcept