summaryrefslogtreecommitdiff
path: root/cpp/src/qpid/Plugin.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'cpp/src/qpid/Plugin.cpp')
-rw-r--r--cpp/src/qpid/Plugin.cpp21
1 files changed, 21 insertions, 0 deletions
diff --git a/cpp/src/qpid/Plugin.cpp b/cpp/src/qpid/Plugin.cpp
index 733d134334..b8206499ae 100644
--- a/cpp/src/qpid/Plugin.cpp
+++ b/cpp/src/qpid/Plugin.cpp
@@ -20,10 +20,13 @@
#include "Plugin.h"
#include "qpid/Options.h"
+#include <boost/bind.hpp>
+#include <algorithm>
namespace qpid {
namespace {
+
Plugin::Plugins& thePlugins() {
// This is a single threaded singleton implementation so
// it is important to be sure that the first use of this
@@ -31,8 +34,17 @@ Plugin::Plugins& thePlugins() {
static Plugin::Plugins plugins;
return plugins;
}
+
+void call(boost::function<void()> f) { f(); }
+
+} // namespace
+
+Plugin::Target::~Target() {
+ std::for_each(cleanup.begin(), cleanup.end(), &call);
}
+void Plugin::Target::addCleanup(const boost::function<void()>& f) { cleanup.push_back(f); }
+
Plugin::Plugin() {
// Register myself.
thePlugins().push_back(this);
@@ -44,6 +56,12 @@ Options* Plugin::getOptions() { return 0; }
const Plugin::Plugins& Plugin::getPlugins() { return thePlugins(); }
+namespace {
+template <class F> void each_plugin(const F& f) {
+ std::for_each(Plugin::getPlugins().begin(), Plugin::getPlugins().end(), f);
+}
+}
+
void Plugin::addOptions(Options& opts) {
for (Plugins::const_iterator i = getPlugins().begin(); i != getPlugins().end(); ++i) {
if ((*i)->getOptions())
@@ -51,4 +69,7 @@ void Plugin::addOptions(Options& opts) {
}
}
+void Plugin::earlyInitAll(Target& t) { each_plugin(boost::bind(&Plugin::earlyInitialize, _1, t)); }
+void Plugin::initAll(Target& t) { each_plugin(boost::bind(&Plugin::initialize, _1, t)); }
+
} // namespace qpid