From 0efcf2c5c91f4927ccc00ad1cf391c2f964cc2e1 Mon Sep 17 00:00:00 2001 From: Alan Conway Date: Wed, 27 Jun 2007 21:19:14 +0000 Subject: * 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 --- cpp/src/qpid/framing/Handler.h | 70 ++++++++---------------------------------- 1 file changed, 12 insertions(+), 58 deletions(-) (limited to 'cpp/src/qpid/framing/Handler.h') 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 #include 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 struct Handler { - typedef T Type; - typedef shared_ptr Ptr; + typedef T ParamType; + typedef shared_ptr 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 struct HandlerFactory { - virtual ~HandlerFactory() {} - typedef typename Handler::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 -struct HandlerFactoryImpl : public HandlerFactory { - shared_ptr > 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 -struct HandlerFactoryChain : public std::vector* > { - typedef typename Handler::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*>::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(); - } -}; }} -- cgit v1.2.1