diff options
Diffstat (limited to 'cpp/src/qpid/cluster/Event.cpp')
-rw-r--r-- | cpp/src/qpid/cluster/Event.cpp | 23 |
1 files changed, 19 insertions, 4 deletions
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 <ostream> +#include <iterator> +#include <algorithm> 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<uint64_t>(connection.getConnectionPtr())); - iovec iov[] = { { header, b.getPosition() }, { data.get(), size } }; + iovec iov[] = { { header, OVERHEAD }, { const_cast<char*>(getData()), getSize() } }; cpg.mcast(name, iov, sizeof(iov)/sizeof(*iov)); } +Event::operator Buffer() const { + return Buffer(const_cast<char*>(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<char> oi(o,""); + std::copy(e.getData(), e.getData()+std::min(e.getSize(), size_t(16)), oi); + return o << "...]"; +} }} // namespace qpid::cluster |