diff options
author | Dan Goodliffe <dan@randomdan.homeip.net> | 2015-10-25 00:41:46 +0100 |
---|---|---|
committer | Dan Goodliffe <dan@randomdan.homeip.net> | 2015-10-25 00:41:46 +0100 |
commit | 8ca8e67873ff0ff84b0bb3d279815f300f01ca7d (patch) | |
tree | c2167aa6f35eeeb617b97c825f50415c448c896f | |
parent | Support options sources and targets coming and going during options load (diff) | |
download | project2-8ca8e67873ff0ff84b0bb3d279815f300f01ca7d.tar.bz2 project2-8ca8e67873ff0ff84b0bb3d279815f300f01ca7d.tar.xz project2-8ca8e67873ff0ff84b0bb3d279815f300f01ca7d.zip |
Don't keep references to plugins that might get unloadedproject2-1.2.2.4
-rw-r--r-- | project2/common/optionsSource.cpp | 21 |
1 files changed, 16 insertions, 5 deletions
diff --git a/project2/common/optionsSource.cpp b/project2/common/optionsSource.cpp index 2461c58..d37a6c6 100644 --- a/project2/common/optionsSource.cpp +++ b/project2/common/optionsSource.cpp @@ -23,17 +23,28 @@ class DefaultConfigConsumer : public ConfigConsumer { boost::posix_time::ptime OptionsSource::loadedTime = boost::posix_time::special_values::neg_infin; +template <typename X> +std::set<X *> +raw(const std::set<boost::shared_ptr<X>> & xs) +{ + std::set<X *> y; + for (const auto & x : xs) { + y.insert(x.get()); + } + return y; +} + void OptionsSource::resetOptions() { - auto options = AdHoc::PluginManager::getDefault()->getAll<Options>(); + auto options = raw(AdHoc::PluginManager::getDefault()->getAll<Options>()); decltype(options) resetConfigs; while (options != resetConfigs) { for (auto opts : options) { if (resetConfigs.find(opts) == resetConfigs.end()) { opts->implementation()->reset(); resetConfigs.insert(opts); - auto newOptions = AdHoc::PluginManager::getDefault()->getAll<Options>(); + auto newOptions = raw(AdHoc::PluginManager::getDefault()->getAll<Options>()); if (newOptions != options) { options = newOptions; break; @@ -46,8 +57,8 @@ OptionsSource::resetOptions() void OptionsSource::loadSources(const Options::CurrentPlatform & platform) { - auto configs = AdHoc::PluginManager::getDefault()->getAll<OptionsSource>(); - if (std::find_if(configs.begin(), configs.end(), [](boost::shared_ptr<const AdHoc::PluginOf<OptionsSource>> c) { return c->implementation()->modifiedTime() > loadedTime; }) != configs.end()) { + auto configs = raw(AdHoc::PluginManager::getDefault()->getAll<OptionsSource>()); + if (std::find_if(configs.begin(), configs.end(), [](const AdHoc::PluginOf<OptionsSource> * c) { return c->implementation()->modifiedTime() > loadedTime; }) != configs.end()) { resetOptions(); DefaultConfigConsumer dcc; @@ -57,7 +68,7 @@ OptionsSource::loadSources(const Options::CurrentPlatform & platform) if (loadedConfigs.find(c) == loadedConfigs.end()) { c->implementation()->loadInto(dcc, platform); loadedConfigs.insert(c); - auto newConfigs = AdHoc::PluginManager::getDefault()->getAll<OptionsSource>(); + auto newConfigs = raw(AdHoc::PluginManager::getDefault()->getAll<OptionsSource>()); if (newConfigs != configs) { configs = newConfigs; break; |