17 files changed
+451
-421
No files matched your search
@@ -0,0 +1,29 @@
|
||||
#pragma once
|
||||
#include <Mod/Base.hpp>
|
||||
#include <memory>
|
||||
#include <string>
|
||||
|
||||
namespace vl::mod {
|
||||
|
||||
class LoadedMod {
|
||||
public:
|
||||
LoadedMod(std::string name, std::string version,
|
||||
std::unique_ptr<Base> instance, void* handle)
|
||||
: name_(std::move(name)), version_(std::move(version)),
|
||||
instance_(std::move(instance)), handle_(handle) {}
|
||||
|
||||
Base& mod() { return *instance_; }
|
||||
const Base& mod() const { return *instance_; }
|
||||
|
||||
const std::string& name() const noexcept { return name_; }
|
||||
const std::string& version() const noexcept { return version_; }
|
||||
void* handle() const noexcept { return handle_; }
|
||||
|
||||
private:
|
||||
std::string name_;
|
||||
std::string version_;
|
||||
std::unique_ptr<Base> instance_;
|
||||
void* handle_{};
|
||||
};
|
||||
|
||||
} // namespace vl::log
|
||||
@@ -0,0 +1,32 @@
|
||||
#pragma once
|
||||
#include <Mod/Context.hpp>
|
||||
#include <Mods/Loaded.hpp>
|
||||
#include <Mods/Registry.hpp>
|
||||
#include <memory>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
namespace vl::mod {
|
||||
|
||||
// Handles dlopen/dlsym, discovers mod registrations, constructs mods (C2)
|
||||
class ModLoader {
|
||||
public:
|
||||
// Load a module (.so), discover CRTP-registered mod types, instantiate each with Context.
|
||||
// Returns the number of instances created from this module.
|
||||
std::size_t loadModule(const std::string& path, const Context& ctx);
|
||||
|
||||
// Start/stop all currently loaded instances.
|
||||
void startAll();
|
||||
void stopAll();
|
||||
|
||||
// Unload everything (calls stopAll first if not stopped).
|
||||
void unloadAll();
|
||||
|
||||
const std::vector<LoadedMod>& instances() const noexcept { return instances_; }
|
||||
|
||||
private:
|
||||
std::vector<void*> handles_;
|
||||
std::vector<LoadedMod> instances_;
|
||||
};
|
||||
|
||||
} // namespace vl::log
|
||||
@@ -0,0 +1,32 @@
|
||||
#pragma once
|
||||
#include <Mod/Registration.hpp>
|
||||
#include <functional>
|
||||
#include <memory>
|
||||
#include <string>
|
||||
#include <string_view>
|
||||
#include <vector>
|
||||
|
||||
namespace vl::mod {
|
||||
|
||||
class Registry {
|
||||
public:
|
||||
struct Entry {
|
||||
std::string typeName;
|
||||
std::string name; // from T::Name()
|
||||
std::string version; // from T::Version()
|
||||
std::function<std::unique_ptr<Base>(const Context&)> factory;
|
||||
};
|
||||
|
||||
// Read registration entries from a loaded module (ELF .so handle)
|
||||
// Returns number of entries found.
|
||||
static std::size_t addFromModule(void* soHandle);
|
||||
|
||||
// Enumerate all known entries from all modules loaded so far
|
||||
static const std::vector<Entry>& all();
|
||||
static std::vector<Entry>& mutableAll();
|
||||
|
||||
private:
|
||||
static std::vector<Entry>& storage_();
|
||||
};
|
||||
|
||||
} // namespace vl::log
|
||||
Reference in new issue
Block a user