summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDan Goodliffe <dan@randomdan.homeip.net>2015-10-24 18:34:13 +0100
committerDan Goodliffe <dan@randomdan.homeip.net>2015-10-24 18:34:13 +0100
commit75e114283262d1cbb62721488b29fbc753fdc9f4 (patch)
treeb093d62904f49ad7da33913a1c01806c8210d3ff
parentFix loading dynamically added option sources (diff)
downloadproject2-75e114283262d1cbb62721488b29fbc753fdc9f4.tar.bz2
project2-75e114283262d1cbb62721488b29fbc753fdc9f4.tar.xz
project2-75e114283262d1cbb62721488b29fbc753fdc9f4.zip
Support options sources and targets coming and going during options load
-rw-r--r--project2/common/optionsSource.cpp43
-rw-r--r--project2/common/optionsSource.h2
2 files changed, 33 insertions, 12 deletions
diff --git a/project2/common/optionsSource.cpp b/project2/common/optionsSource.cpp
index 0112ad4..2461c58 100644
--- a/project2/common/optionsSource.cpp
+++ b/project2/common/optionsSource.cpp
@@ -24,23 +24,44 @@ class DefaultConfigConsumer : public ConfigConsumer {
boost::posix_time::ptime OptionsSource::loadedTime = boost::posix_time::special_values::neg_infin;
void
+OptionsSource::resetOptions()
+{
+ auto options = 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>();
+ if (newOptions != options) {
+ options = newOptions;
+ break;
+ }
+ }
+ }
+ }
+}
+
+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()) {
- for (auto opts : AdHoc::PluginManager::getDefault()->getAll<Options>()) {
- opts->implementation()->reset();
- }
+ resetOptions();
DefaultConfigConsumer dcc;
- std::set<const OptionsSource *> loadedConfigs;
- while (loadedConfigs.size() != configs.size()) {
+ decltype(configs) loadedConfigs;
+ while (loadedConfigs != configs) {
for (const auto & c : configs) {
- if (loadedConfigs.find(c->implementation()) == loadedConfigs.end()) {
+ if (loadedConfigs.find(c) == loadedConfigs.end()) {
c->implementation()->loadInto(dcc, platform);
- loadedConfigs.insert(c->implementation());
- configs = AdHoc::PluginManager::getDefault()->getAll<OptionsSource>();
- break;
+ loadedConfigs.insert(c);
+ auto newConfigs = AdHoc::PluginManager::getDefault()->getAll<OptionsSource>();
+ if (newConfigs != configs) {
+ configs = newConfigs;
+ break;
+ }
}
}
}
@@ -54,9 +75,7 @@ OptionsSource::loadSources(const Options::CurrentPlatform & platform)
void
OptionsSource::loadSource(const Options::CurrentPlatform & platform, OptionsSourcePtr opts)
{
- for (auto opts : AdHoc::PluginManager::getDefault()->getAll<Options>()) {
- opts->implementation()->reset();
- }
+ resetOptions();
DefaultConfigConsumer dcc;
opts->loadInto(dcc, platform);
diff --git a/project2/common/optionsSource.h b/project2/common/optionsSource.h
index 32c43ed..a6b50e9 100644
--- a/project2/common/optionsSource.h
+++ b/project2/common/optionsSource.h
@@ -29,6 +29,8 @@ class OptionsSource : public AdHoc::AbstractPluginImplementation {
static void loadSource(const Options::CurrentPlatform & platform, OptionsSourcePtr opts);
private:
+ static void resetOptions();
+
static boost::posix_time::ptime loadedTime;
};