diff options
author | Roland Reichwein <mail@reichwein.it> | 2020-04-09 11:38:48 +0200 |
---|---|---|
committer | Roland Reichwein <mail@reichwein.it> | 2020-04-09 11:38:48 +0200 |
commit | 2f42619303627db401e469e2fd65123cd794a378 (patch) | |
tree | fb9944f9838b9d19be3e2ce39e6be6b71f9c469c /plugin.cpp | |
parent | f5e2c43abe9477fba6255c734faf2822e7f2f9c5 (diff) |
Load only configured plugins, add plugins
Diffstat (limited to 'plugin.cpp')
-rw-r--r-- | plugin.cpp | 35 |
1 files changed, 21 insertions, 14 deletions
@@ -20,24 +20,31 @@ void PluginLoader::load_plugins() for (const auto& dir: plugin_directories) { for (auto& path: fs::recursive_directory_iterator(dir)) { - if (path.is_regular_file()) { + if (path.is_regular_file() && path.path().extension() == ".so"s) { dll::fs::path lib_path{path.path()}; try { - boost::shared_ptr<webserver_plugin_interface> plugin = dll::import<webserver_plugin_interface>(lib_path, "webserver_plugin", dll::load_mode::append_decorations); - if (plugin) { - if (plugin->version() != webserver_plugin_interface::interface_version) - throw std::runtime_error("Bad interface version for "s + path.path().generic_string() + ": "s + std::to_string(plugin->version()) + " vs. "s + std::to_string(webserver_plugin_interface::interface_version)); - - if (m_plugins.contains(plugin->name())) - throw std::runtime_error("Plugin already exists: "s + plugin->name()); - - m_plugins.emplace(plugin->name(), plugin); - - std::cout << "Found plugin: " << plugin->name() << std::endl; - } else - std::cout << "Can't load plugin from " << path.path().generic_string() << std::endl; + boost::shared_ptr<webserver_plugin_interface> plugin = dll::import<webserver_plugin_interface>(lib_path, "webserver_plugin", dll::load_mode::append_decorations); + if (plugin) { + if (plugin->version() != webserver_plugin_interface::interface_version) + throw std::runtime_error("Bad interface version for "s + path.path().generic_string() + ": "s + std::to_string(plugin->version()) + " vs. "s + std::to_string(webserver_plugin_interface::interface_version)); + + std::string name{plugin->name()}; + if (m_plugins.contains(name)) + throw std::runtime_error("Plugin already exists: "s + name); + + std::cout << "Found plugin: " << name << " (" << path.path().string() << "), "; + if (m_config.PluginIsConfigured(name)) { + std::cout << "loading."; + m_plugins.emplace(plugin->name(), plugin); + } else { + std::cout << "ignored (not configured)."; + } + std::cout << std::endl; + + } else + std::cout << "Can't load plugin from " << path.path().generic_string() << std::endl; } catch (const std::exception& ex) { std::cout << "Can't load plugin from " << path.path().generic_string() << ": " << ex.what() << std::endl; } |