summaryrefslogtreecommitdiff
path: root/project2/common/environment.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'project2/common/environment.cpp')
-rw-r--r--project2/common/environment.cpp73
1 files changed, 32 insertions, 41 deletions
diff --git a/project2/common/environment.cpp b/project2/common/environment.cpp
index 57665f0..7d24c5c 100644
--- a/project2/common/environment.cpp
+++ b/project2/common/environment.cpp
@@ -11,27 +11,34 @@
#include <boost/bind.hpp>
const Environment * Environment::currentEnv(NULL);
+#include <boost/preprocessor/control/if.hpp>
+#include <boost/preprocessor/facilities/expand.hpp>
-Environment::Environment() :
- commonOptions("Project2 Common options"),
- clLevel(-1),
- slLevel(-1)
+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"),
+ "The namespace to use for Project2 components and responses")
+("common.namespacePrefix", Options::value(&scriptNamespacePrefix, "project2"),
+ "The namespace prefix to use for the Project2 namespace")
+("common.sessionTimeOut", Options::value(&sessionTimeOut, 3600),
+ "The time after which idle sessions are forgotten")
+END_OPTIONS(Environment);
+
+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;
- commonOptions
- ("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"),
- "The namespace to use for Project2 components and responses")
- ("common.namespacePrefix", Options::value(&scriptNamespacePrefix, "project2"),
- "The namespace prefix to use for the Project2 namespace")
- ("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());
@@ -40,32 +47,21 @@ Environment::Environment() :
typedef std::vector<const Options *> AllOptions;
-static
-void
-optionsHelper(AllOptions * ao, const Options * options)
-{
- if (options) {
- ao->push_back(options);
- }
-}
-
class DefaultConfigConsumer : public ConfigConsumer {
public:
void operator()(const Glib::ustring & n, const Glib::ustring & p, const Glib::ustring & v) const {
- BOOST_FOREACH(const Options * o, allOptions) {
- o->consume(n, p, v);
- }
+ LoaderBase::onAll<Options>(boost::bind(&Options::consume, _1, n, p, v));
}
const Options::Option * get(const Glib::ustring & n) const {
- BOOST_FOREACH(const Options * os, allOptions) {
+ const Options::Option * rtn = NULL;
+ LoaderBase::onAll<Options>([n,&rtn](const Options * os) {
const Options::Option * o = os->find(n);
if (o) {
- return o;
+ rtn = o;
}
- }
- return NULL;
+ });
+ return rtn;
}
- AllOptions allOptions;
};
void
@@ -73,13 +69,8 @@ Environment::init()
{
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();
- }
+ LoaderBase::onAll<Options>(boost::bind(&Options::reset, _1));
BOOST_FOREACH(const ConfigsMap::value_type & c, configs) {
c->loadInto(dcc);