From 01e3826d26fd0efecd1663835143da15ebaa828d Mon Sep 17 00:00:00 2001 From: Alan Conway Date: Tue, 18 Sep 2007 15:20:29 +0000 Subject: * src/qpid/broker/SessionHandler.cpp: - Make SessionHandler an InOutHandler. - SessionHandler::out sets channel ID on frames. * src/qpid/framing/Handler.h: Fixed InOutHandler template. git-svn-id: https://svn.apache.org/repos/asf/incubator/qpid/trunk/qpid@576947 13f79535-47bb-0310-9956-ffa450edef68 --- cpp/src/qpid/broker/SessionHandler.cpp | 45 ++++++++++++++++--------------- cpp/src/qpid/broker/SessionHandler.h | 46 ++++++++++++++++--------------- cpp/src/qpid/framing/Handler.h | 49 +++++++++++++++++++--------------- 3 files changed, 75 insertions(+), 65 deletions(-) (limited to 'cpp') diff --git a/cpp/src/qpid/broker/SessionHandler.cpp b/cpp/src/qpid/broker/SessionHandler.cpp index c6ba73e43a..e46f11d98c 100644 --- a/cpp/src/qpid/broker/SessionHandler.cpp +++ b/cpp/src/qpid/broker/SessionHandler.cpp @@ -40,11 +40,7 @@ framing::AMQP_ClientProxy& SessionHandler::getProxy() { } SessionHandler::SessionHandler(Connection& c, ChannelId ch) - : connection(c), channel(ch), ignoring(false) -{ - in = this; - out = &c.getOutput(); -} + : InOutHandler(0, &c.getOutput()), connection(c), channel(ch), ignoring(false), channelHandler(*this) {} SessionHandler::~SessionHandler() {} @@ -53,7 +49,7 @@ ClassId classId(AMQMethodBody* m) { return m ? m->amqpMethodId() : 0; } MethodId methodId(AMQMethodBody* m) { return m ? m->amqpClassId() : 0; } } // namespace -void SessionHandler::handle(AMQFrame& f) { +void SessionHandler::handleIn(AMQFrame& f) { // Note on channel states: a channel is open if session != 0. A // channel that is closed (session == 0) can be in the "ignoring" // state. This is a temporary state after we have sent a channel @@ -62,7 +58,7 @@ void SessionHandler::handle(AMQFrame& f) { // AMQMethodBody* m=f.getMethod(); try { - if (m && m->invoke(static_cast(this))) + if (m && m->invoke(&channelHandler)) return; else if (session) session->in(f); @@ -82,6 +78,11 @@ void SessionHandler::handle(AMQFrame& f) { } } +void SessionHandler::handleOut(AMQFrame& f) { + f.setChannel(getChannel()); + out.next->handle(f); +} + void SessionHandler::assertOpen(const char* method) { if (!session) throw ChannelErrorException( @@ -99,21 +100,21 @@ void SessionHandler::assertClosed(const char* method) { << getChannel())); } -void SessionHandler::open(const string& /*outOfBand*/){ - assertClosed("open"); - session.reset(new Session(*this, 0)); - getProxy().getChannel().openOk(); +void SessionHandler::ChannelMethods::open(const string& /*outOfBand*/){ + parent.assertClosed("open"); + parent.session.reset(new Session(parent, 0)); + parent.getProxy().getChannel().openOk(); } // FIXME aconway 2007-08-31: flow is no longer in the spec. -void SessionHandler::flow(bool active){ - session->flow(active); - getProxy().getChannel().flowOk(active); +void SessionHandler::ChannelMethods::flow(bool active){ + parent.session->flow(active); + parent.getProxy().getChannel().flowOk(active); } -void SessionHandler::flowOk(bool /*active*/){} +void SessionHandler::ChannelMethods::flowOk(bool /*active*/){} -void SessionHandler::close(uint16_t replyCode, +void SessionHandler::ChannelMethods::close(uint16_t replyCode, const string& replyText, uint16_t classId, uint16_t methodId) { @@ -123,21 +124,21 @@ void SessionHandler::close(uint16_t replyCode, < #include namespace qpid { @@ -31,6 +32,7 @@ namespace framing { template struct Handler { typedef T HandledType; + typedef void handleFptr(T); Handler(Handler* next_=0) : next(next_) {} virtual ~Handler() {} @@ -74,37 +76,40 @@ struct Handler { }; /** Adapt a member function of X as a Handler. - * MemFun will copy x. - * MemFun will only take a reference to x. + * Only holds a reference to its target, not a copy. */ - template - class MemFun : public Handler { + template + class MemFunRef : public Handler { public: - MemFun(X x, Handler* next=0) : Handler(next), object(x) {} - void handle(T t) { object.*M(t); } + MemFunRef(X& x, Handler* next=0) : Handler(next), target(x) {} + void handle(T t) { (target.*F)(t); } + + /** Allow calling with -> syntax, compatible with Chains */ + MemFunRef* operator->() { return this; } + private: - X object; + X& target; }; - /** Support for implementing an in-out handler pair as a single class. - * Public interface is Handler::Chains pair, but implementation - * overrides handleIn, handleOut functions in a single class. + /** Interface for a handler that implements a + * pair of in/out handle operations. + * @see InOutHandler */ - class InOutHandler { + class InOutHandlerInterface { public: - virtual ~InOutHandler() {} - - InOutHandler() : - in(*this, &InOutHandler::handleIn), - out(*this, &InOutHandler::handleOut) {} - - MemFun in; - MemFun out; - - protected: + virtual ~InOutHandlerInterface() {} virtual void handleIn(T) = 0; virtual void handleOut(T) = 0; - private: + }; + + /** Support for implementing an in-out handler pair as a single class. + * Public interface is Handler::Chains pair, but implementation + * overrides handleIn, handleOut functions in a single class. + */ + struct InOutHandler : protected InOutHandlerInterface { + InOutHandler(Handler* nextIn=0, Handler* nextOut=0) : in(*this, nextIn), out(*this, nextOut) {} + MemFunRef in; + MemFunRef out; }; }; -- cgit v1.2.1