diff options
Diffstat (limited to 'cpp/src/qpid/client')
| -rw-r--r-- | cpp/src/qpid/client/SessionCore.cpp | 2 | ||||
| -rw-r--r-- | cpp/src/qpid/client/SessionCore.h | 4 | ||||
| -rw-r--r-- | cpp/src/qpid/client/SessionHandler.cpp (renamed from cpp/src/qpid/client/ChannelHandler.cpp) | 43 | ||||
| -rw-r--r-- | cpp/src/qpid/client/SessionHandler.h (renamed from cpp/src/qpid/client/ChannelHandler.h) | 14 |
4 files changed, 29 insertions, 34 deletions
diff --git a/cpp/src/qpid/client/SessionCore.cpp b/cpp/src/qpid/client/SessionCore.cpp index 3595479642..82b3e77b94 100644 --- a/cpp/src/qpid/client/SessionCore.cpp +++ b/cpp/src/qpid/client/SessionCore.cpp @@ -33,7 +33,7 @@ SessionCore::SessionCore(uint16_t _id, boost::shared_ptr<framing::FrameHandler> { l2.out = boost::bind(&FrameHandler::handle, out, _1); l2.in = boost::bind(&ExecutionHandler::handle, &l3, _1); - l3.out = boost::bind(&ChannelHandler::outgoing, &l2, _1); + l3.out = boost::bind(&SessionHandler::outgoing, &l2, _1); l2.onClose = boost::bind(&SessionCore::closed, this, _1, _2); } diff --git a/cpp/src/qpid/client/SessionCore.h b/cpp/src/qpid/client/SessionCore.h index 80fe13715f..5b15a607b3 100644 --- a/cpp/src/qpid/client/SessionCore.h +++ b/cpp/src/qpid/client/SessionCore.h @@ -28,7 +28,7 @@ #include "qpid/framing/FrameHandler.h" #include "qpid/framing/FrameSet.h" #include "qpid/framing/MethodContent.h" -#include "ChannelHandler.h" +#include "SessionHandler.h" #include "ExecutionHandler.h" namespace qpid { @@ -45,7 +45,7 @@ class SessionCore : public framing::FrameHandler }; ExecutionHandler l3; - ChannelHandler l2; + SessionHandler l2; const uint16_t id; bool sync; bool isClosed; diff --git a/cpp/src/qpid/client/ChannelHandler.cpp b/cpp/src/qpid/client/SessionHandler.cpp index 49e7285a47..3885ac437a 100644 --- a/cpp/src/qpid/client/ChannelHandler.cpp +++ b/cpp/src/qpid/client/SessionHandler.cpp @@ -19,7 +19,7 @@ * */ -#include "ChannelHandler.h" +#include "SessionHandler.h" #include "qpid/framing/amqp_framing.h" #include "qpid/framing/all_method_bodies.h" @@ -27,14 +27,14 @@ using namespace qpid::client; using namespace qpid::framing; using namespace boost; -ChannelHandler::ChannelHandler() : StateManager(CLOSED), id(0) {} +SessionHandler::SessionHandler() : StateManager(CLOSED), id(0) {} -void ChannelHandler::incoming(AMQFrame& frame) +void SessionHandler::incoming(AMQFrame& frame) { AMQBody* body = frame.getBody(); if (getState() == OPEN) { - ChannelCloseBody* closeBody= - dynamic_cast<ChannelCloseBody*>(body->getMethod()); + SessionClosedBody* closeBody= + dynamic_cast<SessionClosedBody*>(body->getMethod()); if (closeBody) { setState(CLOSED_BY_PEER); code = closeBody->getReplyCode(); @@ -46,12 +46,7 @@ void ChannelHandler::incoming(AMQFrame& frame) try { in(frame); }catch(ChannelException& e){ - AMQMethodBody* method=body->getMethod(); - if (method) - close(e.code, e.toString(), - method->amqpClassId(), method->amqpMethodId()); - else - close(e.code, e.toString(), 0, 0); + closed(e.code, e.toString()); } } } else { @@ -62,7 +57,7 @@ void ChannelHandler::incoming(AMQFrame& frame) } } -void ChannelHandler::outgoing(AMQFrame& frame) +void SessionHandler::outgoing(AMQFrame& frame) { if (getState() == OPEN) { frame.setChannel(id); @@ -74,12 +69,12 @@ void ChannelHandler::outgoing(AMQFrame& frame) } } -void ChannelHandler::open(uint16_t _id) +void SessionHandler::open(uint16_t _id) { id = _id; setState(OPENING); - AMQFrame f(id, ChannelOpenBody(version)); + AMQFrame f(id, SessionOpenBody(version)); out(f); std::set<int> states; @@ -91,37 +86,39 @@ void ChannelHandler::open(uint16_t _id) } } -void ChannelHandler::close(uint16_t code, const std::string& message, uint16_t classId, uint16_t methodId) +void SessionHandler::close() { setState(CLOSING); - AMQFrame f(id, ChannelCloseBody(version, code, message, classId, methodId)); + AMQFrame f(id, SessionCloseBody(version)); out(f); + waitFor(CLOSED); } -void ChannelHandler::close() +void SessionHandler::closed(uint16_t code, const std::string& msg) { - close(200, "OK", 0, 0); - waitFor(CLOSED); + setState(CLOSED); + AMQFrame f(id, SessionClosedBody(version, code, msg)); + out(f); } -void ChannelHandler::handleMethod(AMQMethodBody* method) +void SessionHandler::handleMethod(AMQMethodBody* method) { switch (getState()) { case OPENING: - if (method->isA<ChannelOpenOkBody>()) { + if (method->isA<SessionAttachedBody>()) { setState(OPEN); } else { throw ConnectionException(504, "Channel not opened."); } break; case CLOSING: - if (method->isA<ChannelCloseOkBody>()) { + if (method->isA<SessionClosedBody>()) { setState(CLOSED); } //else just ignore it break; case CLOSED: throw ConnectionException(504, "Channel is closed."); default: - throw Exception("Unexpected state encountered in ChannelHandler!"); + throw Exception("Unexpected state encountered in SessionHandler!"); } } diff --git a/cpp/src/qpid/client/ChannelHandler.h b/cpp/src/qpid/client/SessionHandler.h index 24c24e49c4..e71d527406 100644 --- a/cpp/src/qpid/client/ChannelHandler.h +++ b/cpp/src/qpid/client/SessionHandler.h @@ -18,8 +18,8 @@ * under the License. * */ -#ifndef _ChannelHandler_ -#define _ChannelHandler_ +#ifndef _SessionHandler_ +#define _SessionHandler_ #include "StateManager.h" #include "ChainableFrameHandler.h" @@ -28,7 +28,7 @@ namespace qpid { namespace client { -class ChannelHandler : private StateManager, public ChainableFrameHandler +class SessionHandler : private StateManager, public ChainableFrameHandler { enum STATES {OPENING, OPEN, CLOSING, CLOSED, CLOSED_BY_PEER}; framing::ProtocolVersion version; @@ -38,21 +38,19 @@ class ChannelHandler : private StateManager, public ChainableFrameHandler std::string text; void handleMethod(framing::AMQMethodBody* method); - - void close(uint16_t code, const std::string& message, uint16_t classId, uint16_t methodId); - + void closed(uint16_t code, const std::string& msg); public: typedef boost::function<void(uint16_t, const std::string&)> CloseListener; - ChannelHandler(); + SessionHandler(); void incoming(framing::AMQFrame& frame); void outgoing(framing::AMQFrame& frame); void open(uint16_t id); void close(); - + CloseListener onClose; }; |
