diff options
-rw-r--r-- | project2/cgi/testCgi.cpp | 10 | ||||
-rw-r--r-- | project2/common/optionsSource.cpp | 16 | ||||
-rw-r--r-- | project2/common/optionsSource.h | 8 | ||||
-rw-r--r-- | project2/console/p2consoleMain.cpp | 3 | ||||
-rw-r--r-- | project2/daemon/p2daemonMain.cpp | 4 | ||||
-rw-r--r-- | project2/files/optionsSource.cpp | 14 |
6 files changed, 30 insertions, 25 deletions
diff --git a/project2/cgi/testCgi.cpp b/project2/cgi/testCgi.cpp index 4ab13d1..b61a475 100644 --- a/project2/cgi/testCgi.cpp +++ b/project2/cgi/testCgi.cpp @@ -27,14 +27,14 @@ class TestInput : public cgicc::CgiInput, public CgiEnvInput { typedef std::map<std::string, StrPtr> OptStore; TestInput(int argc, char ** argv) { - OptionsSources::Add("_1", new FileOptions(".testCgi.settings")); - OptionsSources::Add("_2", new CommandLineArguments(argc, argv, - [](const char * url) { urls.push_back(url); })); + AdHoc::PluginManager::getDefault()->add<OptionsSource>(new FileOptions(".testCgi.settings"), "_1", __FILE__, __LINE__); + AdHoc::PluginManager::getDefault()->add<OptionsSource>( + new CommandLineArguments(argc, argv, [](const char * url) { urls.push_back(url); }), "_2", __FILE__, __LINE__); } ~TestInput() { - OptionsSources::Remove("_1"); - OptionsSources::Remove("_2"); + AdHoc::PluginManager::getDefault()->remove<OptionsSource>("_1"); + AdHoc::PluginManager::getDefault()->remove<OptionsSource>("_2"); } std::string getenv(const std::string & varName) const diff --git a/project2/common/optionsSource.cpp b/project2/common/optionsSource.cpp index c74243d..1739ed5 100644 --- a/project2/common/optionsSource.cpp +++ b/project2/common/optionsSource.cpp @@ -1,6 +1,6 @@ #include "optionsSource.h" #include "logger.h" -#include "instanceStore.impl.h" +#include <plugins.impl.h> class DefaultConfigConsumer : public ConfigConsumer { public: @@ -26,19 +26,19 @@ boost::posix_time::ptime OptionsSource::loadedTime = boost::posix_time::special_ void OptionsSource::loadSources(const Options::CurrentPlatform & platform) { - const auto & configs = InstanceSet<OptionsSource>::GetAll(); - if (std::find_if(configs.begin(), configs.end(), [](const OptionsSourcePtr & c) { return c->modifiedTime() > loadedTime; }) != configs.end()) { + const 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(); } DefaultConfigConsumer dcc; - std::set<boost::shared_ptr<OptionsSource>> loadedConfigs; + std::set<const OptionsSource *> loadedConfigs; while (loadedConfigs.size() != configs.size()) { for (const auto & c : configs) { - if (loadedConfigs.find(c) == loadedConfigs.end()) { - c->loadInto(dcc, platform); - loadedConfigs.insert(c); + if (loadedConfigs.find(c->implementation()) == loadedConfigs.end()) { + c->implementation()->loadInto(dcc, platform); + loadedConfigs.insert(c->implementation()); } } } @@ -64,5 +64,5 @@ OptionsSource::loadSource(const Options::CurrentPlatform & platform, OptionsSour Logger()->messagebf(LOG_DEBUG, "Loaded configuration at %s", loadedTime); } -INSTANTIATESTORE(std::string, OptionsSource); +INSTANTIATEPLUGINOF(OptionsSource); diff --git a/project2/common/optionsSource.h b/project2/common/optionsSource.h index 7f1deee..32c43ed 100644 --- a/project2/common/optionsSource.h +++ b/project2/common/optionsSource.h @@ -18,7 +18,7 @@ class OptionsSource; typedef boost::shared_ptr<OptionsSource> OptionsSourcePtr; /// Base class of things that load options -class OptionsSource { +class OptionsSource : public AdHoc::AbstractPluginImplementation { public: virtual ~OptionsSource() = default; @@ -32,12 +32,8 @@ class OptionsSource { static boost::posix_time::ptime loadedTime; }; -typedef PluginsSameBase<OptionsSource, std::string> OptionsSources; #define DECLARE_OPTIONSSOURCE(Id, Inst) \ - static void init_optionsSource() __attribute__ ((constructor(200))); \ - static void init_optionsSource() { OptionsSources::Add(Id, Inst); } \ - static void kill_optionsSource() __attribute__ ((destructor(200))); \ - static void kill_optionsSource() { OptionsSources::Remove(Id); } + NAMEDPLUGIN(Id, Inst, OptionsSource) #endif diff --git a/project2/console/p2consoleMain.cpp b/project2/console/p2consoleMain.cpp index 62f09b0..87a3293 100644 --- a/project2/console/p2consoleMain.cpp +++ b/project2/console/p2consoleMain.cpp @@ -6,7 +6,8 @@ int main(int argc, char ** argv) { - OptionsSources::Add("", new CommandLineArguments(argc, argv, &ConsoleApplicationEngine::appendScript)); + AdHoc::PluginManager::getDefault()->add<OptionsSource>( + new CommandLineArguments(argc, argv, &ConsoleApplicationEngine::appendScript), "", __FILE__, __LINE__); Plugable::onAllComponents(boost::bind(&ComponentLoader::onBegin, _1)); ConsoleApplicationEngine app; diff --git a/project2/daemon/p2daemonMain.cpp b/project2/daemon/p2daemonMain.cpp index 95de88e..0da41f3 100644 --- a/project2/daemon/p2daemonMain.cpp +++ b/project2/daemon/p2daemonMain.cpp @@ -45,8 +45,8 @@ int main(int argc, char ** argv) { Plugable::onAllComponents(boost::bind(&ComponentLoader::onBegin, _1)); - OptionsSources::Add("_2", new CommandLineArguments(argc, argv, - [](const char * a) { throw UnsupportedArguments(a); })); + AdHoc::PluginManager::getDefault()->add<OptionsSource>( + new CommandLineArguments(argc, argv, [](const char * a) { throw UnsupportedArguments(a); }), "_2", __FILE__, __LINE__); DaemonAppEngine dae(argc, argv); OptionsSource::loadSources([] { return DaemonAppEngine::reqPlatform;} ); diff --git a/project2/files/optionsSource.cpp b/project2/files/optionsSource.cpp index 8e98df0..2ce320c 100644 --- a/project2/files/optionsSource.cpp +++ b/project2/files/optionsSource.cpp @@ -38,19 +38,27 @@ FileOptions::modifiedTime() const FileOptions::ExtraFileOptions FileOptions::extraFileOptions; +class DefaultFileOptions : public FileOptions { + public: + DefaultFileOptions() : + FileOptions(".p2config") + { + } +}; + // Z... process last :) -DECLARE_OPTIONSSOURCE("Z_configfile", new FileOptions(".p2config")) +DECLARE_OPTIONSSOURCE("Z_configfile", DefaultFileOptions) DECLARE_OPTIONS(FileOptions, "File Options options") ("file.options.read", Options::functions( [](const VariableType & vt) { auto fo = new FileOptions(vt.as<std::string>()); extraFileOptions[vt] = boost::shared_ptr<FileOptions>(fo); - OptionsSources::Add(vt, fo); + AdHoc::PluginManager::getDefault()->add<OptionsSource>(fo, vt, __FILE__, __LINE__); }, []() { for (const auto & fo : extraFileOptions) { - OptionsSources::Remove(fo.first); + AdHoc::PluginManager::getDefault()->remove<OptionsSource>(fo.first); } extraFileOptions.clear(); }), |