From 0865408d7fa16f913391ed9391fb13268a74d8a1 Mon Sep 17 00:00:00 2001 From: Alan Conway Date: Thu, 5 Jul 2007 16:08:29 +0000 Subject: * src/qpid/cluster/SessionFrame.cpp, .h: Wrap AMQFrame with session UUID and direction. * src/qpid/cluster/Cluster.cpp, .h: Use SessionFrame. * src/qpid/framing/AMQFrame.h, .cpp: Added setBody(), inline getBody() * src/qpid/framing/Uuid.h, .cpp: Clean up constructors, inline. * src/qpid/framing/Buffer.h: Put/get byte*, size_T. * src/qpid/cluster/SessionManager.cpp, .h: - Maintain the session map. - Handle frames from cluster, dispatch to proper channels. - Implement HandlerUpdater for new channels and maintains git-svn-id: https://svn.apache.org/repos/asf/incubator/qpid/trunk/qpid@553543 13f79535-47bb-0310-9956-ffa450edef68 --- cpp/src/qpid/framing/AMQFrame.cpp | 4 ---- cpp/src/qpid/framing/AMQFrame.h | 7 +++++-- cpp/src/qpid/framing/Buffer.h | 2 ++ cpp/src/qpid/framing/Uuid.cpp | 8 +------- cpp/src/qpid/framing/Uuid.h | 26 +++++++++++++++++++++----- 5 files changed, 29 insertions(+), 18 deletions(-) (limited to 'cpp/src/qpid/framing') diff --git a/cpp/src/qpid/framing/AMQFrame.cpp b/cpp/src/qpid/framing/AMQFrame.cpp index a528913fd9..13f1d3cece 100644 --- a/cpp/src/qpid/framing/AMQFrame.cpp +++ b/cpp/src/qpid/framing/AMQFrame.cpp @@ -47,10 +47,6 @@ AMQFrame::AMQFrame(ProtocolVersion _version, uint16_t _channel, const AMQBody::s AMQFrame::~AMQFrame() {} -AMQBody::shared_ptr AMQFrame::getBody(){ - return body; -} - void AMQFrame::encode(Buffer& buffer) { buffer.putOctet(body->type()); diff --git a/cpp/src/qpid/framing/AMQFrame.h b/cpp/src/qpid/framing/AMQFrame.h index 1a7b203ad7..16c1427802 100644 --- a/cpp/src/qpid/framing/AMQFrame.h +++ b/cpp/src/qpid/framing/AMQFrame.h @@ -32,7 +32,8 @@ #include "AMQHeartbeatBody.h" #include "qpid/framing/AMQP_MethodVersionMap.h" #include "qpid/framing/AMQP_HighestVersion.h" -#include "Buffer.h" +#include "qpid/framing/Buffer.h" +#include "qpid/shared_ptr.h" namespace qpid { namespace framing { @@ -49,7 +50,9 @@ class AMQFrame : public AMQDataBlock virtual bool decode(Buffer& buffer); virtual uint32_t size() const; uint16_t getChannel() const { return channel; } - AMQBody::shared_ptr getBody(); + + shared_ptr getBody() { return body; } + void setBody(const shared_ptr& b) { body = b; } /** Convenience template to cast the body to an expected type */ template boost::shared_ptr castBody() { diff --git a/cpp/src/qpid/framing/Buffer.h b/cpp/src/qpid/framing/Buffer.h index d35935ad19..04acb65e91 100644 --- a/cpp/src/qpid/framing/Buffer.h +++ b/cpp/src/qpid/framing/Buffer.h @@ -81,6 +81,8 @@ public: void putRawData(const uint8_t* data, size_t size); void getRawData(uint8_t* data, size_t size); + template void put(const T& data) { data.encode(*this); } + template void get(T& data) { data.decode(*this); } }; }} // namespace qpid::framing diff --git a/cpp/src/qpid/framing/Uuid.cpp b/cpp/src/qpid/framing/Uuid.cpp index b1523f0d61..3a83430d56 100644 --- a/cpp/src/qpid/framing/Uuid.cpp +++ b/cpp/src/qpid/framing/Uuid.cpp @@ -21,20 +21,14 @@ #include "qpid/QpidError.h" #include "qpid/framing/Buffer.h" -#include - namespace qpid { namespace framing { using namespace std; -Uuid::Uuid() { uuid_generate(c_array()); } - -Uuid::Uuid(uint8_t* uu) { uuid_copy(c_array(),uu); } - static const size_t UNPARSED_SIZE=36; -void Uuid::encode(Buffer& buf) { +void Uuid::encode(Buffer& buf) const { buf.putRawData(data(), size()); } diff --git a/cpp/src/qpid/framing/Uuid.h b/cpp/src/qpid/framing/Uuid.h index a2f415b118..19ae79db6a 100644 --- a/cpp/src/qpid/framing/Uuid.h +++ b/cpp/src/qpid/framing/Uuid.h @@ -20,9 +20,12 @@ */ #include + #include #include +#include + namespace qpid { namespace framing { @@ -35,16 +38,29 @@ class Buffer; * boost::array so Uuid can be the key type in a map etc. */ struct Uuid : public boost::array { - /** Geneate universally unique identifier */ - Uuid(); + /** If unique is true, generate a unique ID else a null ID. */ + Uuid(bool unique=false) { if (unique) generate(); else clear(); } + + /** Copy from 16 bytes of data */ + Uuid(const uint8_t* data) { assign(data); } + + /** Copy from 16 bytes of data */ + void assign(const uint8_t* data) { uuid_copy(c_array(), data); } + + /** Set to a new unique identifier */ + void generate() { uuid_generate(c_array()); } - /** Initialize from 16 bytes of data */ - Uuid(uint8_t* data); + /** Set to all zeros */ + void clear() { uuid_clear(c_array()); } + + /** Test for null (all zeros) */ + bool isNull() const { return uuid_is_null(data()); } // Default op= and copy ctor are fine. // boost::array gives us ==, < etc. - void encode(framing::Buffer& buf); + void encode(framing::Buffer& buf) const; + void decode(framing::Buffer& buf); }; -- cgit v1.2.1