From 49c7a491c98c26fe7d4f017a7ba655dfc029278c Mon Sep 17 00:00:00 2001 From: Alan Conway Date: Thu, 16 Aug 2007 20:12:33 +0000 Subject: AMQBodies are no longer allocated on the heap and passed with shared_ptr. AMQFrame contains a boost::variant of AMQHeaderBody,AMQContentBody, AMQHeatbeatBody, and MethodHolder. A variant is basically a type-safe union, it can allocate any of the types in-place. MethodHolder contains a Blob, a less sophisticated kind of variant, which can contain any of the concrete method body types. Using variants for all the method types causes outrageous compile times and bloated library symbol names. Blob lacks some of the finer features of variant and needs help from generated code. For now both are hidden to the rest of the code base behind AMQFrame and MethodBody classes so if/when we decide to settle on just one "variant" type solution we can do so. This commit touches nearly 100 files, mostly converting method signatures with shared_ptr to FooBody* or FooBody&, and converting stored shared_ptr to AMQFrame and share_ptr to MethodHolder. There is one outstanding client memory leak, which I will fix in my next commit. git-svn-id: https://svn.apache.org/repos/asf/incubator/qpid/trunk/qpid@566822 13f79535-47bb-0310-9956-ffa450edef68 --- cpp/src/qpid/client/ChannelHandler.cpp | 44 +++++++++++++++++----------------- 1 file changed, 22 insertions(+), 22 deletions(-) (limited to 'cpp/src/qpid/client/ChannelHandler.cpp') diff --git a/cpp/src/qpid/client/ChannelHandler.cpp b/cpp/src/qpid/client/ChannelHandler.cpp index a6aea438f0..b3d720baf0 100644 --- a/cpp/src/qpid/client/ChannelHandler.cpp +++ b/cpp/src/qpid/client/ChannelHandler.cpp @@ -21,6 +21,7 @@ #include "ChannelHandler.h" #include "qpid/framing/amqp_framing.h" +#include "qpid/framing/all_method_bodies.h" using namespace qpid::client; using namespace qpid::framing; @@ -30,40 +31,39 @@ ChannelHandler::ChannelHandler() : StateManager(CLOSED), id(0) {} void ChannelHandler::incoming(AMQFrame& frame) { - AMQBody::shared_ptr body = frame.getBody(); + AMQBody* body = frame.getBody(); if (getState() == OPEN) { - if (isA(body)) { - ChannelCloseBody::shared_ptr method(shared_polymorphic_cast(body)); + ChannelCloseBody* closeBody= + dynamic_cast(body->getMethod()); + if (closeBody) { setState(CLOSED); if (onClose) { - onClose(method->getReplyCode(), method->getReplyText()); + onClose(closeBody->getReplyCode(), closeBody->getReplyText()); } } else { try { in(frame); }catch(ChannelException& e){ - if (body->type() == METHOD_BODY) { - AMQMethodBody::shared_ptr method(shared_polymorphic_cast(body)); - close(e.code, e.toString(), method->amqpClassId(), method->amqpMethodId()); - } else { + AMQMethodBody* method=body->getMethod(); + if (method) + close(e.code, e.toString(), + method->amqpClassId(), method->amqpMethodId()); + else close(e.code, e.toString(), 0, 0); - } } } } else { - if (body->type() == METHOD_BODY) { - handleMethod(shared_polymorphic_cast(body)); - } else { + if (body->getMethod()) + handleMethod(body->getMethod()); + else throw new ConnectionException(504, "Channel not open."); - } - } } void ChannelHandler::outgoing(AMQFrame& frame) { if (getState() == OPEN) { - frame.channel = id; + frame.setChannel(id); out(frame); } else { throw Exception("Channel not open"); @@ -75,7 +75,7 @@ void ChannelHandler::open(uint16_t _id) id = _id; setState(OPENING); - AMQFrame f(version, id, make_shared_ptr(new ChannelOpenBody(version))); + AMQFrame f(version, id, ChannelOpenBody(version)); out(f); std::set states; @@ -90,7 +90,7 @@ void ChannelHandler::open(uint16_t _id) void ChannelHandler::close(uint16_t code, const std::string& message, uint16_t classId, uint16_t methodId) { setState(CLOSING); - AMQFrame f(version, id, make_shared_ptr(new ChannelCloseBody(version, code, message, classId, methodId))); + AMQFrame f(version, id, ChannelCloseBody(version, code, message, classId, methodId)); out(f); } @@ -100,24 +100,24 @@ void ChannelHandler::close() waitFor(CLOSED); } -void ChannelHandler::handleMethod(AMQMethodBody::shared_ptr method) +void ChannelHandler::handleMethod(AMQMethodBody* method) { switch (getState()) { - case OPENING: + case OPENING: if (method->isA()) { setState(OPEN); } else { throw ConnectionException(504, "Channel not opened."); } break; - case CLOSING: + case CLOSING: if (method->isA()) { setState(CLOSED); } //else just ignore it break; - case CLOSED: + case CLOSED: throw ConnectionException(504, "Channel not opened."); - default: + default: throw Exception("Unexpected state encountered in ChannelHandler!"); } } -- cgit v1.2.1