diff options
author | Alan Conway <aconway@apache.org> | 2009-01-16 17:25:18 +0000 |
---|---|---|
committer | Alan Conway <aconway@apache.org> | 2009-01-16 17:25:18 +0000 |
commit | 0541090a05e124e8af9e2b887f641ff0f985b2d5 (patch) | |
tree | 240571682f5210ff5dc5f297ccef74ef16343c1b /cpp/src/qpid/cluster/Event.cpp | |
parent | 9b0a13818d536d92c39ae15b8934d2bc33ce573d (diff) | |
download | qpid-python-0541090a05e124e8af9e2b887f641ff0f985b2d5.tar.gz |
Separate cluster::EventHeader to allow non-copy events.
git-svn-id: https://svn.apache.org/repos/asf/qpid/trunk/qpid@735059 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'cpp/src/qpid/cluster/Event.cpp')
-rw-r--r-- | cpp/src/qpid/cluster/Event.cpp | 36 |
1 files changed, 25 insertions, 11 deletions
diff --git a/cpp/src/qpid/cluster/Event.cpp b/cpp/src/qpid/cluster/Event.cpp index cfa8fe05f1..5fe2b4d5b0 100644 --- a/cpp/src/qpid/cluster/Event.cpp +++ b/cpp/src/qpid/cluster/Event.cpp @@ -32,28 +32,37 @@ namespace cluster { using framing::Buffer; -const size_t Event::HEADER_SIZE = +const size_t EventHeader::HEADER_SIZE = sizeof(uint8_t) + // type sizeof(uint64_t) + // connection pointer only, CPG provides member ID. sizeof(uint32_t); // payload size +EventHeader::EventHeader(EventType t, const ConnectionId& c, size_t s) + : type(t), connectionId(c), size(s) {} + Event::Event(EventType t, const ConnectionId& c, size_t s) - : type(t), connectionId(c), size(s), store(RefCountedBuffer::create(s+HEADER_SIZE)) { + : EventHeader(t,c,s), store(RefCountedBuffer::create(s+HEADER_SIZE)) +{ encodeHeader(); } -Event Event::decode(const MemberId& m, framing::Buffer& buf) { +void EventHeader::decode(const MemberId& m, framing::Buffer& buf) { if (buf.available() <= HEADER_SIZE) throw ClusterLeaveException("Not enough for multicast header"); - EventType type((EventType)buf.getOctet()); + type = (EventType)buf.getOctet(); if(type != DATA && type != CONTROL) throw ClusterLeaveException("Invalid multicast event type"); - ConnectionId connection(m, reinterpret_cast<Connection*>(buf.getLongLong())); - uint32_t size = buf.getLong(); - Event e(type, connection, size); - if (buf.available() < size) + connectionId = ConnectionId(m, reinterpret_cast<Connection*>(buf.getLongLong())); + size = buf.getLong(); +} + +Event Event::decodeCopy(const MemberId& m, framing::Buffer& buf) { + EventHeader h; + h.decode(m, buf); // Header + Event e(h.getType(), h.getConnectionId(), h.getSize()); + if (buf.available() < e.size) throw ClusterLeaveException("Not enough data for multicast event"); - memcpy(e.getData(), buf.getPointer() + buf.getPosition(), size); + memcpy(e.getData(), buf.getPointer() + buf.getPosition(), e.size); return e; } @@ -65,11 +74,16 @@ Event Event::control(const framing::AMQBody& body, const ConnectionId& cid) { return e; } -void Event::encodeHeader () { - Buffer b(getStore(), HEADER_SIZE); +void EventHeader::encode(Buffer& b) const { b.putOctet(type); b.putLongLong(reinterpret_cast<uint64_t>(connectionId.getPointer())); b.putLong(size); +} + +// Encode my header in my buffer. +void Event::encodeHeader () { + Buffer b(getStore(), HEADER_SIZE); + encode(b); assert(b.getPosition() == HEADER_SIZE); } |