summaryrefslogtreecommitdiff
path: root/cpp/src/qpid/framing/Handler.h
diff options
context:
space:
mode:
authorAlan Conway <aconway@apache.org>2007-06-27 21:19:14 +0000
committerAlan Conway <aconway@apache.org>2007-06-27 21:19:14 +0000
commit0efcf2c5c91f4927ccc00ad1cf391c2f964cc2e1 (patch)
treea9318ac4787cf588dd1329c2e557d8f870be20cc /cpp/src/qpid/framing/Handler.h
parent548abd065f91bc1f238ac98c24edf410edf10356 (diff)
downloadqpid-python-0efcf2c5c91f4927ccc00ad1cf391c2f964cc2e1.tar.gz
* src/qpid/framing/ChannelAdapter.cpp: Use handler chains
for in and outbound frames. * src/qpid/framing/InputHandler.h, OutputHandler.h, FrameHandler.h: All handlers pass AMQFrame& and have consistent memory management. Terminal OutputHandlers used to take ownership and delete frame, now they make a shallow copy instead. * src/qpid/framing/Handler.h, FrameHandler.h: Simplified. * src/qpid/client/ClientConnection.cpp: * src/qpid/broker/Connection.cpp: * src/qpid/broker/BrokerChannel.cpp: Update for ChannelAdapter changes. git-svn-id: https://svn.apache.org/repos/asf/incubator/qpid/trunk/qpid@551336 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'cpp/src/qpid/framing/Handler.h')
-rw-r--r--cpp/src/qpid/framing/Handler.h70
1 files changed, 12 insertions, 58 deletions
diff --git a/cpp/src/qpid/framing/Handler.h b/cpp/src/qpid/framing/Handler.h
index 05a02a30b1..56e150a66d 100644
--- a/cpp/src/qpid/framing/Handler.h
+++ b/cpp/src/qpid/framing/Handler.h
@@ -22,75 +22,29 @@
*
*/
#include "qpid/shared_ptr.h"
-#include <vector>
#include <assert.h>
namespace qpid {
namespace framing {
-/** Handler for objects of type T. */
+/** Interface for handler for values of type T.
+ * Handlers can be linked into chains via the next pointer.
+ */
template <class T> struct Handler {
- typedef T Type;
- typedef shared_ptr<Handler> Ptr;
+ typedef T ParamType;
+ typedef shared_ptr<Handler> Chain;
+
+ /** Handler chains for incoming and outgoing traffic. */
+ struct Chains {
+ Chain in;
+ Chain out;
+ };
virtual ~Handler() {}
virtual void handle(T) = 0;
- virtual void link(Ptr next_) { next=next_; }
- protected:
- void nextHandler(T data) { if (next) next->handle(data); }
- private:
- Ptr next;
-};
-
-
-/** Factory interface that takes a context of type C */
-template <class T, class C> struct HandlerFactory {
- virtual ~HandlerFactory() {}
- typedef typename Handler<T>::Ptr Ptr;
-
- /** Create a handler */
- virtual Ptr create(C context) = 0;
-
- /** Create a handler and link it to next */
- Ptr create(C context, Ptr next) {
- Ptr h=create(context);
- h->link(next);
- }
-};
-
-/** Factory implementation template */
-template <class FH, class C>
-struct HandlerFactoryImpl : public HandlerFactory<typename FH::Type, C> {
- shared_ptr<Handler<typename FH::Type> > create(C context) {
- return typename FH::Ptr(new FH(context));
- }
+ Chain next;
};
-/** A factory chain is a vector of handler factories used to create
- * handler chains. The chain does not own the factories.
- */
-template <class T, class C>
-struct HandlerFactoryChain : public std::vector<HandlerFactory<T,C>* > {
- typedef typename Handler<T>::Ptr Ptr;
-
- /** Create a handler chain, return the first handler.
- *@param context - passed to each factory.
- */
- Ptr create(C context) {
- return this->create(context, this->begin());
- }
-
- private:
- typedef typename std::vector<HandlerFactory<T,C>*>::iterator iterator;
- Ptr create(C context, iterator i) {
- if (i != this->end()) {
- Ptr h=(*i)->create(context);
- h->link(create(context, i+1));
- return h;
- }
- return Ptr();
- }
-};
}}