From 028745dbc3c47bd6561310678f82f15bd45678d9 Mon Sep 17 00:00:00 2001 From: Alan Conway Date: Sat, 6 Sep 2008 14:10:08 +0000 Subject: RefCountedBuffer improvements, centralize cluster encoding/decoding in Event. git-svn-id: https://svn.apache.org/repos/asf/incubator/qpid/trunk/qpid@692654 13f79535-47bb-0310-9956-ffa450edef68 --- cpp/src/qpid/cluster/Event.cpp | 23 +++++++++++++++++++---- 1 file changed, 19 insertions(+), 4 deletions(-) (limited to 'cpp/src/qpid/cluster/Event.cpp') diff --git a/cpp/src/qpid/cluster/Event.cpp b/cpp/src/qpid/cluster/Event.cpp index 66f3cf261b..4dfb7ab400 100644 --- a/cpp/src/qpid/cluster/Event.cpp +++ b/cpp/src/qpid/cluster/Event.cpp @@ -22,13 +22,16 @@ #include "Event.h" #include "Cpg.h" #include "qpid/framing/Buffer.h" +#include +#include +#include namespace qpid { namespace cluster { using framing::Buffer; -const size_t Event::OVERHEAD = 1 /*type*/ + 8 /*64-bit pointr*/; +const size_t Event::OVERHEAD = sizeof(uint8_t) + sizeof(uint64_t); Event::Event(EventType t, const ConnectionId c, const size_t s) : type(t), connection(c), size(s), data(RefCountedBuffer::create(s)) {} @@ -43,15 +46,27 @@ Event Event::delivered(const MemberId& m, void* d, size_t s) { return e; } -void Event::mcast(const Cpg::Name& name, Cpg& cpg) { +void Event::mcast (const Cpg::Name& name, Cpg& cpg) const { char header[OVERHEAD]; - Buffer b; + Buffer b(header, OVERHEAD); b.putOctet(type); b.putLongLong(reinterpret_cast(connection.getConnectionPtr())); - iovec iov[] = { { header, b.getPosition() }, { data.get(), size } }; + iovec iov[] = { { header, OVERHEAD }, { const_cast(getData()), getSize() } }; cpg.mcast(name, iov, sizeof(iov)/sizeof(*iov)); } +Event::operator Buffer() const { + return Buffer(const_cast(getData()), getSize()); +} +static const char* EVENT_TYPE_NAMES[] = { "data", "control" }; +std::ostream& operator << (std::ostream& o, const Event& e) { + o << "[event: " << e.getConnection() + << " " << EVENT_TYPE_NAMES[e.getType()] + << " " << e.getSize() << " bytes: "; + std::ostream_iterator oi(o,""); + std::copy(e.getData(), e.getData()+std::min(e.getSize(), size_t(16)), oi); + return o << "...]"; +} }} // namespace qpid::cluster -- cgit v1.2.1