Author: aconway
Date: Wed Jun 27 15:40:49 2007
New Revision: 551363

URL: http://svn.apache.org/viewvc?view=rev&rev=551363
Log:
        * src/qpid/broker/Plugin.h: Base class for plug-in objects.
        Plugins can contribute configuration options and can call
        extension point functions on the broker.
        
        * src/qpid/broker/ChannelInitializer.h: Interface for plug-in
        objects that want to modify newly created channels, e.g. to
        modify the handler chains.
        
        * src/qpid/broker/Broker.h: Added extension point for plug-ins to
        contribute ChannelInitializer objects.

Added:
    incubator/qpid/trunk/qpid/cpp/src/qpid/broker/ChannelInitializer.h   (with 
props)
    incubator/qpid/trunk/qpid/cpp/src/qpid/broker/Plugin.cpp   (with props)
    incubator/qpid/trunk/qpid/cpp/src/qpid/broker/Plugin.h   (with props)
Modified:
    incubator/qpid/trunk/qpid/cpp/src/Makefile.am
    incubator/qpid/trunk/qpid/cpp/src/qpid/broker/Broker.h

Modified: incubator/qpid/trunk/qpid/cpp/src/Makefile.am
URL: 
http://svn.apache.org/viewvc/incubator/qpid/trunk/qpid/cpp/src/Makefile.am?view=diff&rev=551363&r1=551362&r2=551363
==============================================================================
--- incubator/qpid/trunk/qpid/cpp/src/Makefile.am (original)
+++ incubator/qpid/trunk/qpid/cpp/src/Makefile.am Wed Jun 27 15:40:49 2007
@@ -217,7 +217,10 @@
   qpid/broker/TopicExchange.cpp \
   qpid/broker/TxAck.cpp \
   qpid/broker/TxBuffer.cpp \
-  qpid/broker/TxPublish.cpp
+  qpid/broker/TxPublish.cpp \
+  qpid/broker/Plugin.h \
+  qpid/broker/Plugin.cpp \
+  qpid/broker/ChannelInitializer.h
 
 libqpidclient_la_LIBADD = libqpidcommon.la
 libqpidclient_la_SOURCES =                     \

Modified: incubator/qpid/trunk/qpid/cpp/src/qpid/broker/Broker.h
URL: 
http://svn.apache.org/viewvc/incubator/qpid/trunk/qpid/cpp/src/qpid/broker/Broker.h?view=diff&rev=551363&r1=551362&r2=551363
==============================================================================
--- incubator/qpid/trunk/qpid/cpp/src/qpid/broker/Broker.h (original)
+++ incubator/qpid/trunk/qpid/cpp/src/qpid/broker/Broker.h Wed Jun 27 15:40:49 
2007
@@ -40,6 +40,8 @@
 
 namespace qpid { 
 namespace broker {
+class ChannelInitializer;
+
 /**
  * A broker instance. 
  */
@@ -85,6 +87,9 @@
      */
     virtual void run();
 
+    /** Plug-in a channel initializer. */
+    void plugin(const qpid::shared_ptr<ChannelInitializer>&);
+    
     /** Shut down the broker */
     virtual void shutdown();
 

Added: incubator/qpid/trunk/qpid/cpp/src/qpid/broker/ChannelInitializer.h
URL: 
http://svn.apache.org/viewvc/incubator/qpid/trunk/qpid/cpp/src/qpid/broker/ChannelInitializer.h?view=auto&rev=551363
==============================================================================
--- incubator/qpid/trunk/qpid/cpp/src/qpid/broker/ChannelInitializer.h (added)
+++ incubator/qpid/trunk/qpid/cpp/src/qpid/broker/ChannelInitializer.h Wed Jun 
27 15:40:49 2007
@@ -0,0 +1,43 @@
+#ifndef QPID_BROKER_CHANNELINITIALIZER_H
+#define QPID_BROKER_CHANNELINITIALIZER_H
+
+/*
+ *
+ * Copyright (c) 2006 The Apache Software Foundation
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *    http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+#include <boost/noncopyable.hpp>
+
+namespace qpid {
+namespace broker {
+
+/**
+ * A ChannelInitializer is called each time a new Channel is created.
+ */
+class ChannelInitializer : boost::noncopyable
+{
+  public:
+    virtual ~ChannelInitializer() {}
+
+    /** Called for each new channel */
+    virtual initialize(Channe&) = 0;
+};
+
+}} // namespace qpid::broker
+
+
+
+#endif  /*!QPID_BROKER_CHANNELINITIALIZER_H*/

Propchange: incubator/qpid/trunk/qpid/cpp/src/qpid/broker/ChannelInitializer.h
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: incubator/qpid/trunk/qpid/cpp/src/qpid/broker/ChannelInitializer.h
------------------------------------------------------------------------------
    svn:keywords = Rev Date

Added: incubator/qpid/trunk/qpid/cpp/src/qpid/broker/Plugin.cpp
URL: 
http://svn.apache.org/viewvc/incubator/qpid/trunk/qpid/cpp/src/qpid/broker/Plugin.cpp?view=auto&rev=551363
==============================================================================
--- incubator/qpid/trunk/qpid/cpp/src/qpid/broker/Plugin.cpp (added)
+++ incubator/qpid/trunk/qpid/cpp/src/qpid/broker/Plugin.cpp Wed Jun 27 
15:40:49 2007
@@ -0,0 +1,67 @@
+/*
+ *
+ * Copyright (c) 2006 The Apache Software Foundation
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *    http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+#include "Plugin.h"
+
+namespace qpid {
+namespace broker {
+
+std::vector<Plugin*> Plugin::plugins;
+
+Plugin::Plugin() {
+    // Register myself.
+    plugins.push_back(this);
+}
+
+Plugin::~Plugin() {}
+
+Options*  Plugin::getOptions() { return 0; }
+
+void  Plugin::start(Broker&) {}
+
+void  Plugin::finish(Broker&) {}
+
+const std::vector<Plugin*>& Plugin::getPlugins() { return plugins; }
+
+#ifdef USE_APR_PLATFORM
+
+#include "qpid/sys/apr/APRBase.h"
+#include "qpid/sys/apr/APRPool.h"
+#include <apr_dso.h>
+
+void Plugin::dlopen(const std::string& name) {
+    apr_dso_handle_t* handle;
+    CHECK_APR_SUCCESS(
+        apr_dso_load(&handle, name.c_str(), sys::APRPool::get()));
+}
+
+#else // Posix
+
+#include <dlfcn.h>
+
+void Plugin::dlopen(const std::string& name) {
+    dlerror();
+    dlopen(name.c_str(), RTLD_NOW);
+    const char* error = dlerror();
+    if (error) {
+        THROW_QPID_ERROR(INTERNAL_ERROR, error);
+    }
+}
+#endif // USE_APR_PLATFORM
+
+}} // namespace qpid::broker

Propchange: incubator/qpid/trunk/qpid/cpp/src/qpid/broker/Plugin.cpp
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: incubator/qpid/trunk/qpid/cpp/src/qpid/broker/Plugin.cpp
------------------------------------------------------------------------------
    svn:keywords = Rev Date

Added: incubator/qpid/trunk/qpid/cpp/src/qpid/broker/Plugin.h
URL: 
http://svn.apache.org/viewvc/incubator/qpid/trunk/qpid/cpp/src/qpid/broker/Plugin.h?view=auto&rev=551363
==============================================================================
--- incubator/qpid/trunk/qpid/cpp/src/qpid/broker/Plugin.h (added)
+++ incubator/qpid/trunk/qpid/cpp/src/qpid/broker/Plugin.h Wed Jun 27 15:40:49 
2007
@@ -0,0 +1,80 @@
+#ifndef QPID_BROKER_PLUGIN_H
+#define QPID_BROKER_PLUGIN_H
+
+/*
+ *
+ * Copyright (c) 2006 The Apache Software Foundation
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *    http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+#include "qpid/Options.h"
+#include "qpid/broker/Broker.h"
+#include <boost/noncopyable.hpp>
+#include <vector>
+
+namespace qpid {
+namespace broker {
+
+/**
+ * Inherit broker plug-ins from this class, override the virtual
+ * functions and create a global (or class static member) instance in
+ * a shared library. When the library is loaded your plug-in will be
+ * registered.
+ */
+class Plugin : boost::noncopyable
+{
+  public:
+    /** Constructor registers the plugin to appear in getPlugins().
+     * Note: Plugin subclasses should only be constructed during
+     * static initialization, i.e. they should only be declared
+     * as global or static member variables.
+     */
+    Plugin();
+    
+    virtual ~Plugin();
+
+    /**
+     * Override if your plugin has configuration options.
+     * They will be included in options parsing prior to broker
+     * creation setup.
+     [EMAIL PROTECTED] An options group or 0. Default returns 0.
+     */
+    virtual Options* getOptions();
+
+    /** Called immediately after broker creation to allow plug-ins
+     * to do whatever they do to the broker, e.g. add handler chain
+     * manipulators.
+     */
+    virtual void start(Broker& b);
+
+    /** Called just before broker shutdown. Default does nothing */
+    virtual void finish(Broker& b);
+
+    /** Get the list of registered plug-ins. */
+    static const std::vector<Plugin*>& getPlugins();
+
+    /** Load a shared library (that contains plugins presumably!) */
+    static void dlopen(const std::string& libname);
+    
+  private:
+    static std::vector<Plugin*> plugins;
+};
+    
+}} // namespace qpid::broker
+
+
+
+
+#endif  /*!QPID_BROKER_PLUGIN_H*/

Propchange: incubator/qpid/trunk/qpid/cpp/src/qpid/broker/Plugin.h
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: incubator/qpid/trunk/qpid/cpp/src/qpid/broker/Plugin.h
------------------------------------------------------------------------------
    svn:keywords = Rev Date


Reply via email to