diff options
Diffstat (limited to 'project2/common/environment.cpp')
-rw-r--r-- | project2/common/environment.cpp | 55 |
1 files changed, 0 insertions, 55 deletions
diff --git a/project2/common/environment.cpp b/project2/common/environment.cpp index 7765a06..0b9a1fe 100644 --- a/project2/common/environment.cpp +++ b/project2/common/environment.cpp @@ -11,14 +11,8 @@ #include <boost/bind.hpp> const Environment * Environment::currentEnv(NULL); -#include <boost/preprocessor/control/if.hpp> -#include <boost/preprocessor/facilities/expand.hpp> DECLARE_OPTIONS(Environment, "Project2 Common options") -("common.syslogLevel", Options::value(&slLevel, -1), - "Log to syslog with level <arg> (default OFF)")("s") -("common.consolelogLevel", Options::value(&clLevel, LOG_WARNING), - "Log to console with level <arg> (default WARNING)")("c") ("common.datasourceRoot", Options::value(&datasourceRoot, "datasources"), "The folder in which to find datasource definitions") ("common.namespace", Options::value(&scriptNamespace, "http://project2.randomdan.homeip.net"), @@ -33,59 +27,10 @@ time_t Environment::sessionTimeOut; std::string Environment::scriptNamespacePrefix; std::string Environment::scriptNamespace; std::string Environment::datasourceRoot; -int Environment::clLevel; -int Environment::slLevel; Environment::Environment() { currentEnv = this; - typedef std::map<std::string, boost::shared_ptr<OptionsSourceLoader> > ConfigParsersMap; - BOOST_FOREACH(const ConfigParsersMap::value_type & cp, *Plugable::objLoaders<OptionsSourceLoader>()) { - configs.push_back(cp.second->create()); - } -} - -typedef std::vector<const Options *> AllOptions; - -class DefaultConfigConsumer : public ConfigConsumer { - public: - void operator()(const Glib::ustring & n, const Glib::ustring & p, const Glib::ustring & v) const { - Plugable::onAll<Options>(boost::bind(&Options::consume, _1, n, p, v)); - } - const Options::Option * get(const Glib::ustring & n) const { - const Options::Option * rtn = NULL; - Plugable::onAll<Options>([n,&rtn](const Options * os) { - const Options::Option * o = os->find(n); - if (o) { - rtn = o; - } - }); - return rtn; - } -}; - -void -Environment::init() -{ - if (std::find_if(configs.begin(), configs.end(), boost::bind(&OptionsSource::needReload, _1)) != configs.end()) { - DefaultConfigConsumer dcc; - - Plugable::onAll<Options>(boost::bind(&Options::reset, _1)); - - BOOST_FOREACH(const ConfigsMap::value_type & c, configs) { - c->loadInto(dcc); - } - Plugable::onAllComponents(boost::bind(&ComponentLoader::onConfigLoad, _1)); - - Logger()->clear(); - if (clLevel >= 0) { - Logger()->addLogger(LogDriverLoader::createNew("console", clLevel, std::string())); - } - if (slLevel >= 0) { - Logger()->addLogger(LogDriverLoader::createNew("syslog", slLevel, getScriptName())); - } - Logger()->message(LOG_DEBUG, "Loaded configuration"); - } } Environment::~Environment() |