46 lines
1.1 KiB
C++
46 lines
1.1 KiB
C++
#pragma once
|
|
#include <Mod/Base.hpp>
|
|
#include <Mod/Registration.hpp>
|
|
#include <Mod/Context.hpp>
|
|
#include <memory>
|
|
#include <type_traits>
|
|
#include <typeinfo>
|
|
namespace vl::mod {
|
|
|
|
#if defined(__ELF__)
|
|
#define VL_MOD_SECTION __attribute__((section("vlmods"), used))
|
|
#else
|
|
#define VL_MOD_SECTION __attribute__((used))
|
|
#endif
|
|
|
|
// ---- Contract Concepts ----
|
|
|
|
|
|
template <class T>
|
|
class Mod : public Base {
|
|
private:
|
|
static std::unique_ptr<Base> _vl_factory(const Context& ctx) {
|
|
return std::make_unique<T>(ctx);
|
|
}
|
|
|
|
static inline const Registration _vl_reg VL_MOD_SECTION {
|
|
kModRegMagic,
|
|
&_vl_factory,
|
|
typeid(T).name(),
|
|
T::Name().data(),
|
|
T::Version().data()
|
|
};
|
|
|
|
public:
|
|
Mod(const Context& ctx) : m_ctx(ctx){};
|
|
virtual void onStart() = 0;
|
|
virtual void onStop() = 0;
|
|
virtual ~Mod() = default;
|
|
virtual constexpr std::string_view Name() = 0;
|
|
virtual constexpr std::string_view Version() = 0;
|
|
Context m_ctx;
|
|
// T provides: T(const Context&), onStart(), onStop()
|
|
};
|
|
|
|
} // namespace vl::log
|