diff options
author | Alan Conway <aconway@apache.org> | 2007-08-16 20:12:33 +0000 |
---|---|---|
committer | Alan Conway <aconway@apache.org> | 2007-08-16 20:12:33 +0000 |
commit | 49c7a491c98c26fe7d4f017a7ba655dfc029278c (patch) | |
tree | 304d51ba039a5391b4ebde08caab3da978b465fb /cpp/src/qpid/client/ChannelHandler.cpp | |
parent | dc13ca80ff893f74ab57fee6543de6543aa366bc (diff) | |
download | qpid-python-49c7a491c98c26fe7d4f017a7ba655dfc029278c.tar.gz |
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<FooBody> to FooBody* or FooBody&, and
converting stored shared_ptr<AMQBody> to AMQFrame and
share_ptr<AMQMethodBody> 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
Diffstat (limited to 'cpp/src/qpid/client/ChannelHandler.cpp')
-rw-r--r-- | cpp/src/qpid/client/ChannelHandler.cpp | 44 |
1 files changed, 22 insertions, 22 deletions
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<ChannelCloseBody>(body)) { - ChannelCloseBody::shared_ptr method(shared_polymorphic_cast<ChannelCloseBody>(body)); + ChannelCloseBody* closeBody= + dynamic_cast<ChannelCloseBody*>(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<AMQMethodBody>(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<AMQMethodBody>(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<int> 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<ChannelOpenOkBody>()) { setState(OPEN); } else { throw ConnectionException(504, "Channel not opened."); } break; - case CLOSING: + case CLOSING: if (method->isA<ChannelCloseOkBody>()) { 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!"); } } |