Mercurial > irccd
changeset 148:1f61fc0566f2
Irccd: apply configuration after finding the plugin
author | David Demelier <markand@malikania.fr> |
---|---|
date | Fri, 20 May 2016 12:49:05 +0200 |
parents | d2ed121a6a99 |
children | 19df514cb61c |
files | lib/irccd/plugin.hpp lib/irccd/service-plugin.cpp |
diffstat | 2 files changed, 15 insertions(+), 8 deletions(-) [+] |
line wrap: on
line diff
--- a/lib/irccd/plugin.hpp Fri May 20 12:37:00 2016 +0200 +++ b/lib/irccd/plugin.hpp Fri May 20 12:49:05 2016 +0200 @@ -213,6 +213,16 @@ } /** + * Set the configuration. + * + * \param config the configuration + */ + inline void setConfig(PluginConfig config) noexcept + { + m_config = std::move(config); + } + + /** * Access the plugin formats. * * \return the format
--- a/lib/irccd/service-plugin.cpp Fri May 20 12:37:00 2016 +0200 +++ b/lib/irccd/service-plugin.cpp Fri May 20 12:49:05 2016 +0200 @@ -36,16 +36,14 @@ namespace { -std::shared_ptr<Plugin> find(std::unordered_map<std::string, PluginConfig> &configs, std::string name) +std::shared_ptr<Plugin> find(std::string name) { - PluginConfig config = configs[name]; - for (const auto &path : path::list(path::PathPlugins)) { std::string jspath = path + name + ".js"; std::string dynlibpath = path + name + DYNLIB_SUFFIX; if (fs::isReadable(jspath)) - return std::make_shared<JsPlugin>(std::move(name), std::move(jspath), std::move(config)); + return std::make_shared<JsPlugin>(std::move(name), std::move(jspath)); if (fs::isReadable(dynlibpath)) return std::make_shared<DynlibPlugin>(std::move(name), std::move(dynlibpath)); } @@ -60,9 +58,7 @@ std::shared_ptr<Plugin> plugin; if (std::regex_match(path, match, regex)) { - std::string extension = match[1]; - - if (extension == DYNLIB_SUFFIX) + if (match[1] == DYNLIB_SUFFIX) plugin = std::make_shared<DynlibPlugin>(name, path); else plugin = std::make_shared<JsPlugin>(name, path); @@ -162,10 +158,11 @@ std::shared_ptr<Plugin> plugin; if (path.empty()) - plugin = find(m_config, name); + plugin = find(name); else plugin = open(name, std::move(path)); + plugin->setConfig(m_config[name]); plugin->setFormats(m_formats[name]); plugin->onLoad(m_irccd); add(std::move(plugin));