diff options
Diffstat (limited to 'project2/common/environment.cpp')
-rw-r--r-- | project2/common/environment.cpp | 47 |
1 files changed, 26 insertions, 21 deletions
diff --git a/project2/common/environment.cpp b/project2/common/environment.cpp index 2047813..c0f84a2 100644 --- a/project2/common/environment.cpp +++ b/project2/common/environment.cpp @@ -10,11 +10,11 @@ #include <boost/bind.hpp> const Environment * Environment::currentEnv(NULL); -int Environment::clLevel(-1); -int Environment::slLevel(-1); Environment::Environment() : - commonOptions("Project2 Common options") + commonOptions("Project2 Common options"), + clLevel(-1), + slLevel(-1) { currentEnv = this; commonOptions @@ -31,6 +31,10 @@ Environment::Environment() : ("common.sessionTimeOut", Options::value(&sessionTimeOut, 3600), "The time after which idle sessions are forgotten") ; + typedef std::map<std::string, boost::shared_ptr<OptionsSourceLoader> > ConfigParsersMap; + BOOST_FOREACH(const ConfigParsersMap::value_type & cp, *LoaderBase::objLoaders<OptionsSourceLoader>()) { + configs.push_back(cp.second->create()); + } } typedef std::vector<const Options *> AllOptions; @@ -66,26 +70,27 @@ class DefaultConfigConsumer : public ConfigConsumer { void Environment::init() { - DefaultConfigConsumer dcc; - dcc.allOptions.push_back(&commonOptions); - dcc.allOptions.push_back(&engineOptions()); - LoaderBase::onAllComponents(boost::bind(optionsHelper, &dcc.allOptions, boost::bind(&ComponentLoader::options, _1))); + if (std::find_if(configs.begin(), configs.end(), boost::bind(&OptionsSource::needReload, _1)) != configs.end()) { + DefaultConfigConsumer dcc; + dcc.allOptions.push_back(&commonOptions); + dcc.allOptions.push_back(&engineOptions()); + LoaderBase::onAllComponents(boost::bind(optionsHelper, &dcc.allOptions, boost::bind(&ComponentLoader::options, _1))); - BOOST_FOREACH(const AllOptions::value_type & v, dcc.allOptions) { - v->reset(); - } - - typedef std::map<std::string, boost::shared_ptr<OptionsSourceLoader> > ConfigParsersMap; - BOOST_FOREACH(const ConfigParsersMap::value_type & cp, *LoaderBase::objLoaders<OptionsSourceLoader>()) { - cp.second->create()->loadInto(dcc); - } + BOOST_FOREACH(const AllOptions::value_type & v, dcc.allOptions) { + v->reset(); + } - Logger()->clear(); - if (clLevel >= 0) { - Logger()->addLogger(new ConsoleLogDriver(stderr, clLevel, false)); - } - if (slLevel >= 0) { - Logger()->addLogger(new SyslogLogDriver(getScriptName().c_str(), slLevel)); + BOOST_FOREACH(const ConfigsMap::value_type & c, configs) { + c->loadInto(dcc); + } + Logger()->clear(); + if (clLevel >= 0) { + Logger()->addLogger(new ConsoleLogDriver(stderr, clLevel, false)); + } + if (slLevel >= 0) { + Logger()->addLogger(new SyslogLogDriver(getScriptName().c_str(), slLevel)); + } + Logger()->message(LOG_DEBUG, "Loaded configuration"); } } |