1
0
mirror of synced 2024-11-15 03:27:40 +01:00
ImHex/lib/libimhex/include/hex/api/plugin_manager.hpp

81 lines
2.5 KiB
C++
Raw Normal View History

#pragma once
#include <hex.hpp>
2021-08-29 22:15:18 +02:00
#include <hex/helpers/fmt.hpp>
2022-01-13 14:33:30 +01:00
#include <hex/helpers/paths.hpp>
#include <string>
2021-08-21 00:51:50 +02:00
struct ImGuiContext;
namespace hex {
class Plugin {
public:
explicit Plugin(const fs::path &path);
Plugin(const Plugin &) = delete;
Plugin(Plugin &&other) noexcept;
~Plugin();
[[nodiscard]] bool initializePlugin() const;
[[nodiscard]] std::string getPluginName() const;
[[nodiscard]] std::string getPluginAuthor() const;
[[nodiscard]] std::string getPluginDescription() const;
[[nodiscard]] std::string getCompatibleVersion() const;
2021-08-21 00:51:50 +02:00
void setImGuiContext(ImGuiContext *ctx) const;
[[nodiscard]] bool isBuiltinPlugin() const;
[[nodiscard]] const fs::path &getPath() const;
[[nodiscard]] bool isLoaded() const;
private:
2022-02-01 22:09:44 +01:00
using InitializePluginFunc = void (*)();
using GetPluginNameFunc = const char *(*)();
using GetPluginAuthorFunc = const char *(*)();
using GetPluginDescriptionFunc = const char *(*)();
using GetCompatibleVersionFunc = const char *(*)();
2022-02-01 22:09:44 +01:00
using SetImGuiContextFunc = void (*)(ImGuiContext *);
using IsBuiltinPluginFunc = bool (*)();
void *m_handle = nullptr;
fs::path m_path;
mutable bool m_initialized = false;
2022-02-01 22:09:44 +01:00
InitializePluginFunc m_initializePluginFunction = nullptr;
GetPluginNameFunc m_getPluginNameFunction = nullptr;
GetPluginAuthorFunc m_getPluginAuthorFunction = nullptr;
GetPluginDescriptionFunc m_getPluginDescriptionFunction = nullptr;
GetCompatibleVersionFunc m_getCompatibleVersionFunction = nullptr;
2022-02-01 22:09:44 +01:00
SetImGuiContextFunc m_setImGuiContextFunction = nullptr;
IsBuiltinPluginFunc m_isBuiltinPluginFunction = nullptr;
template<typename T>
[[nodiscard]] auto getPluginFunction(const std::string &symbol) {
return reinterpret_cast<T>(this->getPluginFunction(symbol));
}
private:
[[nodiscard]] void *getPluginFunction(const std::string &symbol);
};
class PluginManager {
public:
PluginManager() = delete;
2022-01-13 14:33:30 +01:00
static bool load(const fs::path &pluginFolder);
static void unload();
static void reload();
static const auto &getPlugins() {
return PluginManager::s_plugins;
}
private:
static fs::path s_pluginFolder;
static std::vector<Plugin> s_plugins;
};
}