summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDan Goodliffe <dan@randomdan.homeip.net>2015-09-28 23:45:17 +0100
committerDan Goodliffe <dan@randomdan.homeip.net>2015-09-28 23:45:17 +0100
commit00e36ad1c77c478bf86abef5751a5d027c3486f3 (patch)
treeb53063a2bfb4f8f050553beaf0f4ce5ac7d77ce3
parentUse AdHoc plugins for CGI routers (diff)
downloadproject2-00e36ad1c77c478bf86abef5751a5d027c3486f3.tar.bz2
project2-00e36ad1c77c478bf86abef5751a5d027c3486f3.tar.xz
project2-00e36ad1c77c478bf86abef5751a5d027c3486f3.zip
Use AdHoc plugins for options
-rw-r--r--project2/basics/options/preload.cpp6
-rw-r--r--project2/basics/options/showHelp.cpp4
-rw-r--r--project2/common/options.cpp4
-rw-r--r--project2/common/options.h14
-rw-r--r--project2/common/optionsSource.cpp25
-rw-r--r--project2/common/variables/config.cpp4
6 files changed, 31 insertions, 26 deletions
diff --git a/project2/basics/options/preload.cpp b/project2/basics/options/preload.cpp
index 5cf42e8..4781abb 100644
--- a/project2/basics/options/preload.cpp
+++ b/project2/basics/options/preload.cpp
@@ -19,7 +19,7 @@ class Preload {
static void LoadLibrary(const VariableType & librarypath)
{
- const auto beforeOpts = InstanceSet<Options>::GetAll();
+ const auto beforeOpts = AdHoc::PluginManager::getDefault()->getAll<Options>();
void * handle = dlopen(librarypath, RTLD_GLOBAL | RTLD_NOW);
if (handle) {
@@ -32,10 +32,10 @@ class Preload {
}
libs[librarypath.as<std::string>()] = boost::shared_ptr<void>(handle, &dlclose);
- const auto afterOpts = InstanceSet<Options>::GetAll();
+ const auto afterOpts = AdHoc::PluginManager::getDefault()->getAll<Options>();
for (const auto & opt : afterOpts) {
if (std::find(beforeOpts.begin(), beforeOpts.end(), opt) == beforeOpts.end()) {
- opt->reset();
+ opt->implementation()->reset();
}
}
}
diff --git a/project2/basics/options/showHelp.cpp b/project2/basics/options/showHelp.cpp
index 86dbc6f..b7f481c 100644
--- a/project2/basics/options/showHelp.cpp
+++ b/project2/basics/options/showHelp.cpp
@@ -8,7 +8,9 @@ void ShowHelpComponent::onConfigLoad()
if (!showHelp)
return;
fprintf(stdout, "Help\n");
- InstanceSet<Options>::OnAll(boost::bind(&ShowHelpComponent::outputOptions, this, _1));
+ for (auto opts : AdHoc::PluginManager::getDefault()->getAll<Options>()) {
+ outputOptions(opts->implementation());
+ }
exit(1);
}
diff --git a/project2/common/options.cpp b/project2/common/options.cpp
index c1ed762..7819bd9 100644
--- a/project2/common/options.cpp
+++ b/project2/common/options.cpp
@@ -1,6 +1,6 @@
#include <pch.hpp>
#include "options.h"
-#include "instanceStore.impl.h"
+#include <plugins.impl.h>
class NamedOption : public Options::Option {
public:
@@ -169,5 +169,5 @@ Options::InstanceTarget::assign(const VariableType & value) const
assigner(value);
}
-INSTANTIATESTORE(std::string, Options);
+INSTANTIATEPLUGINOF(Options);
diff --git a/project2/common/options.h b/project2/common/options.h
index 0d90826..6e734bb 100644
--- a/project2/common/options.h
+++ b/project2/common/options.h
@@ -9,9 +9,9 @@
#include <boost/function.hpp>
#include <boost/utility/enable_if.hpp>
#include "variableType.h"
-#include "plugable.h"
+#include <plugins.h>
-class Options {
+class Options : public AdHoc::AbstractPluginImplementation {
public:
class Target;
@@ -99,22 +99,20 @@ class Options {
OptionList options;
};
-// Registration helpers
-// These work pluggable component style
-typedef PluginsSameBase<Options, std::string> OptionsSets;
-
#define DECLARE_OPTIONS(Type, Label) \
static void init_options_##Type() __attribute__ ((constructor(200))); \
static void init_options_##Type() { \
Options * o = new Options(Label); \
Type::InitOptions(*o); \
- OptionsSets::Add(#Type, o); } \
+ AdHoc::PluginManager::getDefault()->add<Options>(o, #Type, __FILE__, __LINE__); } \
void Type::InitOptions(Options & o) { o
#define END_OPTIONS(Type) \
;} \
static void kill_options_##Type() __attribute__ ((destructor(200))); \
- static void kill_options_##Type() { OptionsSets::Remove(#Type); }
+ static void kill_options_##Type() { \
+ AdHoc::PluginManager::getDefault()->remove<Options>(#Type); \
+ }
#define INITOPTIONS \
static void InitOptions(Options &)
diff --git a/project2/common/optionsSource.cpp b/project2/common/optionsSource.cpp
index 0e1d751..c74243d 100644
--- a/project2/common/optionsSource.cpp
+++ b/project2/common/optionsSource.cpp
@@ -5,17 +5,18 @@
class DefaultConfigConsumer : public ConfigConsumer {
public:
void operator()(const Glib::ustring & n, const Glib::ustring & p, const Glib::ustring & v, const Options::CurrentPlatform & cp) const {
- InstanceSet<Options>::OnAll(boost::bind(&Options::consume, _1, n, p, v, cp));
+ for (auto opts : AdHoc::PluginManager::getDefault()->getAll<Options>()) {
+ opts->implementation()->consume(n, p, v, cp);
+ }
}
const Options::Option * get(const Glib::ustring & n) const {
- const Options::Option * rtn = NULL;
- InstanceSet<Options>::OnAll([n,&rtn](const Options * os) {
- const Options::Option * o = os->find(n);
+ for (auto opts : AdHoc::PluginManager::getDefault()->getAll<Options>()) {
+ const Options::Option * o = opts->implementation()->find(n);
if (o) {
- rtn = o;
+ return o;
}
- });
- return rtn;
+ }
+ return nullptr;
}
};
@@ -27,7 +28,9 @@ 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()) {
- InstanceSet<Options>::OnAll(boost::bind(&Options::reset, _1));
+ for (auto opts : AdHoc::PluginManager::getDefault()->getAll<Options>()) {
+ opts->implementation()->reset();
+ }
DefaultConfigConsumer dcc;
std::set<boost::shared_ptr<OptionsSource>> loadedConfigs;
@@ -40,7 +43,7 @@ OptionsSource::loadSources(const Options::CurrentPlatform & platform)
}
}
Plugable::onAllComponents(boost::bind(&ComponentLoader::onConfigLoad, _1));
-
+
loadedTime = boost::posix_time::microsec_clock::universal_time();
Logger()->messagebf(LOG_DEBUG, "Loaded configuration at %s", loadedTime);
}
@@ -49,7 +52,9 @@ OptionsSource::loadSources(const Options::CurrentPlatform & platform)
void
OptionsSource::loadSource(const Options::CurrentPlatform & platform, OptionsSourcePtr opts)
{
- InstanceSet<Options>::OnAll(boost::bind(&Options::reset, _1));
+ for (auto opts : AdHoc::PluginManager::getDefault()->getAll<Options>()) {
+ opts->implementation()->reset();
+ }
DefaultConfigConsumer dcc;
opts->loadInto(dcc, platform);
diff --git a/project2/common/variables/config.cpp b/project2/common/variables/config.cpp
index 273b5aa..1696f43 100644
--- a/project2/common/variables/config.cpp
+++ b/project2/common/variables/config.cpp
@@ -72,12 +72,12 @@ class VariableConfigLoader : public VariableFactory::For<VariableConfig> {
opts(new Options("Variables - ModConfig options"))
{
(*opts)(new AppSettings());
- OptionsSets::Add(typeid(AppSettings).name(), opts);
+ AdHoc::PluginManager::getDefault()->add<Options>(opts, typeid(AppSettings).name(), __FILE__, __LINE__);
}
~VariableConfigLoader()
{
- OptionsSets::Remove(typeid(AppSettings).name());
+ AdHoc::PluginManager::getDefault()->remove<Options>(typeid(AppSettings).name());
}
const Options * options() const {