diff options
author | Alan Conway <aconway@apache.org> | 2008-07-08 22:58:37 +0000 |
---|---|---|
committer | Alan Conway <aconway@apache.org> | 2008-07-08 22:58:37 +0000 |
commit | 8c3baf496f9424249e2a666d79f0e3b38ba8d8fc (patch) | |
tree | 5fd950f023cacb47cf3cc9dc11aed91c94f380f8 /cpp/src/qpid/Plugin.cpp | |
parent | 391608a73f18a1797ab0c358f0a94364dc888eb2 (diff) | |
download | qpid-python-8c3baf496f9424249e2a666d79f0e3b38ba8d8fc.tar.gz |
HandlerChain: plug-in handler chain extension points. Replaces Handler<T>::Chain.
Updated Sessoin & Connection handler chains and Cluster.
git-svn-id: https://svn.apache.org/repos/asf/incubator/qpid/trunk/qpid@675017 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'cpp/src/qpid/Plugin.cpp')
-rw-r--r-- | cpp/src/qpid/Plugin.cpp | 21 |
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 |