diff options
| author | Alan Conway <aconway@apache.org> | 2007-08-29 23:27:40 +0000 |
|---|---|---|
| committer | Alan Conway <aconway@apache.org> | 2007-08-29 23:27:40 +0000 |
| commit | e183227707d150b1f42e750df0e90cd7dac8744e (patch) | |
| tree | a9156083c1890852c2d4013d4a856f9f28762946 /cpp/src/qpid/framing/Handler.h | |
| parent | 7422e57391a89bc2493cba18ca2ef0a84fec7baa (diff) | |
| download | qpid-python-e183227707d150b1f42e750df0e90cd7dac8744e.tar.gz | |
* src/qpid/broker/Session.h, .cpp: Session holds all state of a session including
handlers created for that session. Session is not directly associated with a channel.
* src/qpid/broker/SessionAdapter.h, .cpp: SessionAdapter is bound to a channel
managed by the Connection. It can be attached to and detatched from a Session.
* src/qpid/broker/Connection.cpp, .h: Use SessionAdapter.
* src/qpid/framing/Handler.h: Removed use of shared_ptr. Handlers belong
either to a Session or a Connection and are destroyed with it.
* src/qpid/framing/InputHandler.h, OutputHandler.h: Both now inherit from
FrameHandler and can be used as FrameHandlers. Intermediate step to removing
them entirely.
* src/qpid/broker/ConnectionAdapter.h:
* src/qpid/client/ConnectionHandler.h:
* src/qpid/framing/ChannelAdapter.cpp, .h:
Minor changes required by Handler changes.
git-svn-id: https://svn.apache.org/repos/asf/incubator/qpid/trunk/qpid@570982 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'cpp/src/qpid/framing/Handler.h')
| -rw-r--r-- | cpp/src/qpid/framing/Handler.h | 91 |
1 files changed, 74 insertions, 17 deletions
diff --git a/cpp/src/qpid/framing/Handler.h b/cpp/src/qpid/framing/Handler.h index 2f09911325..be49570f9b 100644 --- a/cpp/src/qpid/framing/Handler.h +++ b/cpp/src/qpid/framing/Handler.h @@ -27,33 +27,90 @@ namespace qpid { namespace framing { -/** 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 ParamType; - typedef shared_ptr<Handler> Chain; +/** Generic handler that can be linked into chains. */ +template <class T> +struct Handler { + typedef T HandledType; + + Handler(Handler<T>* next_=0) : next(next_) {} + virtual ~Handler() {} + virtual void handle(T) = 0; + + /** Allow functor syntax for calling handle */ + void operator()(T t) { handle(t); } + - /** Handler chains for incoming and outgoing traffic. */ + /** Pointer to next handler in a linked list. */ + Handler<T>* next; + + /** A Chain is a handler that forwards to a modifiable + * linked list of handlers. + */ + struct Chain : public Handler<T> { + Chain(Handler<T>* first) : Handler(first) {} + void operator=(Handler<T>* h) { next = h; } + void handle(T t) { (*next)(t); } + // TODO aconway 2007-08-29: chain modifier ops here. + }; + + /** In/out pair of handler chains. */ struct Chains { - Chains() {} - Chains(Chain i, Chain o) : in(i), out(o) {} - Chains(Handler* i, Handler* o) : in(i), out(o) {} + Chains(Handler<T>* in_=0, Handler<T>* out_=0) : in(in_), out(out_) {} + void reset(Handler<T>* in_=0, Handler<T>* out_=0) { in = in_; out = out_; } Chain in; Chain out; }; - Handler() {} - Handler(Chain next_) : next(next_) {} - virtual ~Handler() {} + /** Adapt any void(T) functor as a Handler. + * Functor<F>(f) will copy f. + * Functor<F&>(f) will only take a reference to x. + */ + template <class F> class Functor : public Handler<T> { + public: + Functor(F f, Handler<T>* next=0) : Handler<T>(next), functor(f) {} + void handle(T t) { functor(t); } + private: + F functor; + }; - virtual void handle(T) = 0; + /** Adapt a member function of X as a Handler. + * MemFun<X, X::f> will copy x. + * MemFun<X&, X::f> will only take a reference to x. + */ + template <class X, void(*M)(T)> + class MemFun : public Handler<T> { + public: + MemFun(X x, Handler<T>* next=0) : Handler(next), object(x) {} + void handle(T t) { object.*M(t); } + private: + X object; + }; + + /** Support for implementing an in-out handler pair as a single class. + * Public interface is Handler<T>::Chains pair, but implementation + * overrides handleIn, handleOut functions in a single class. + */ + class InOutHandler { + public: + virtual ~InOutHandler() {} + + InOutHandler() : + in(*this, &InOutHandler::handleIn), + out(*this, &InOutHandler::handleOut) {} + + MemFun<InOutHandler, &InOutHandler::handleIn> in; + MemFun<InOutHandler, &InOutHandler::handleOut> out; + + protected: + virtual void handleIn(T) = 0; + virtual void handleOut(T) = 0; + private: + }; - /** Next handler. Public so chains can be modified by altering next. */ - Chain next; }; -}} +}} #endif /*!QPID_FRAMING_HANDLER_H*/ +// |
