diff --git a/server/lib/plugins/PluginsLoader/PluginsLoader.hpp b/server/lib/plugins/PluginsLoader/PluginsLoader.hpp index e99e34715389d6f505d7301a53074a2c35d3a443..405eae304496aa51b09570d8e22690a7b4ebeeb1 100644 --- a/server/lib/plugins/PluginsLoader/PluginsLoader.hpp +++ b/server/lib/plugins/PluginsLoader/PluginsLoader.hpp @@ -2,18 +2,25 @@ #define PLUGINS_LOADER_H #include "Container.hpp" +#include "IPluginWrapper.hpp" +#include "PyExceptionInfo.hpp" #include "spdlog/common.h" +#include #include #include +#include #include #include #include #include +#include #include #include #include template + requires std::derived_from, Wrapper> && + std::constructible_from class IPluginsLoader { public: virtual ~IPluginsLoader() = default; @@ -22,9 +29,12 @@ class IPluginsLoader { }; template + requires std::derived_from, Wrapper> && + std::constructible_from class PluginsLoader : public IPluginsLoader { public: - explicit PluginsLoader(std::filesystem::path &&plugins_dir) { + explicit PluginsLoader(std::filesystem::path &&plugins_dir) noexcept( + false) { try { boost::python::object sys = boost::python::import("sys"); sys.attr("path").attr("append")(plugins_dir.c_str()); @@ -34,7 +44,7 @@ class PluginsLoader : public IPluginsLoader { std::ranges::for_each( std::filesystem::directory_iterator(plugins_dir), - [](const std::filesystem::path &dir_entry) { + [this](const std::filesystem::path &dir_entry) { if (!std::filesystem::is_directory(dir_entry)) { return; } @@ -42,25 +52,33 @@ class PluginsLoader : public IPluginsLoader { auto loaded_module = boost::python::import(module_name.c_str()); auto plugin_container = Container::build(std::move(loaded_module)); - // std::visit( - // [this, module_name]( - // std::optional &&exception_info) { - // failed_plugins_[module_name] = exception_info; - // }, - // [this, module_name](Container &&container) { - // plugins_[module_name] = Wrapper(container); - // }, - // plugin_container); + std::visit( + [this](Container &&container, std::string &&module_name) { + plugins_[module_name] = Wrapper(std::move(container)); + }, + [this](std::optional &&exception_info, + std::string &&module_name) { + failed_plugins_[module_name] = + std::move(exception_info); + }, + std::move(plugin_container), + std::move(module_name)); }); } - // auto get(const std::string &plugin_name) - // -> std::optional override { - // } + auto get(const std::string &plugin_name) + -> std::optional override { + auto res = plugins_.find(plugin_name); + if (res == plugins_.end()) { + return std::nullopt; + } + return *res; + } private: - std::unordered_map plugins_; - std::unordered_map failed_plugins_; + std::unordered_map plugins_; + std::unordered_map> + failed_plugins_; }; #endif diff --git a/server/lib/plugins/wrappers/PluginWrapperInterface/IPluginWrapper.hpp b/server/lib/plugins/wrappers/PluginWrapperInterface/IPluginWrapper.hpp index 6af9c42b04bd957d43d5ccca6465c2b8df8c9d4d..89d31abdaa83761c9662115aae6f78acc5b5f9c8 100644 --- a/server/lib/plugins/wrappers/PluginWrapperInterface/IPluginWrapper.hpp +++ b/server/lib/plugins/wrappers/PluginWrapperInterface/IPluginWrapper.hpp @@ -18,7 +18,7 @@ class IPluginWrapper { virtual ~IPluginWrapper() = default; IPluginWrapper(const IPluginWrapper &) = delete; - IPluginWrapper(IPluginWrapper &&) = delete; + IPluginWrapper(IPluginWrapper &&) noexcept = default; auto operator=(const IPluginWrapper &) -> IPluginWrapper & = delete; auto operator=(IPluginWrapper &&) -> IPluginWrapper & = delete;