diff options
-rw-r--r-- | qpid/cpp/include/qpid/management/ManagementObject.h | 4 | ||||
-rw-r--r-- | qpid/cpp/src/qpid/management/ManagementObject.cpp | 46 | ||||
-rw-r--r-- | qpid/cpp/src/tests/ManagementTest.cpp | 8 |
3 files changed, 38 insertions, 20 deletions
diff --git a/qpid/cpp/include/qpid/management/ManagementObject.h b/qpid/cpp/include/qpid/management/ManagementObject.h index d8805e182e..50c396d2a9 100644 --- a/qpid/cpp/include/qpid/management/ManagementObject.h +++ b/qpid/cpp/include/qpid/management/ManagementObject.h @@ -53,7 +53,9 @@ class ObjectId { protected: const AgentAttachment* agent; uint64_t first; + uint64_t agentEpoch; std::string v2Key; + std::string agentName; void fromString(const std::string&); public: QPID_COMMON_EXTERN ObjectId() : agent(0), first(0) {} @@ -69,6 +71,8 @@ public: QPID_COMMON_EXTERN operator messaging::VariantMap() const; QPID_COMMON_EXTERN void setV2Key(const std::string& _key) { v2Key = _key; } QPID_COMMON_EXTERN void setV2Key(const ManagementObject& object); + QPID_COMMON_EXTERN void setAgentName(const std::string& _name) { agentName = _name; } + QPID_COMMON_EXTERN const std::string& getAgentName() const { return agentName; } QPID_COMMON_EXTERN const std::string& getV2Key() const { return v2Key; } friend QPID_COMMON_EXTERN std::ostream& operator<<(std::ostream&, const ObjectId&); }; diff --git a/qpid/cpp/src/qpid/management/ManagementObject.cpp b/qpid/cpp/src/qpid/management/ManagementObject.cpp index 00cd604802..9f9216824c 100644 --- a/qpid/cpp/src/qpid/management/ManagementObject.cpp +++ b/qpid/cpp/src/qpid/management/ManagementObject.cpp @@ -51,7 +51,7 @@ ObjectId::ObjectId(uint8_t flags, uint16_t seq, uint32_t broker, uint32_t bank, #endif ObjectId::ObjectId(uint8_t flags, uint16_t seq, uint32_t broker) - : agent(0) + : agent(0), agentEpoch(seq) { first = ((uint64_t) (flags & 0x0f)) << 60 | @@ -60,8 +60,9 @@ ObjectId::ObjectId(uint8_t flags, uint16_t seq, uint32_t broker) } ObjectId::ObjectId(AgentAttachment* _agent, uint8_t flags, uint16_t seq) - : agent(_agent) + : agent(_agent), agentEpoch(seq) { + first = ((uint64_t) (flags & 0x0f)) << 60 | ((uint64_t) (seq & 0x0fff)) << 48; @@ -82,43 +83,41 @@ ObjectId::ObjectId(const std::string& text) : agent(0) void ObjectId::fromString(const std::string& text) { -#define NUMERIC_FIELDS 4 +#define FIELDS 5 #if defined (_WIN32) && !defined (atoll) # define atoll(X) _atoi64(X) #endif std::string copy(text.c_str()); char* cText; - char* field[NUMERIC_FIELDS]; + char* field[FIELDS]; bool atFieldStart = true; int idx = 0; - char *cursor; cText = const_cast<char*>(copy.c_str()); - for (cursor = cText; *cursor; cursor++) { + for (char* cursor = cText; *cursor; cursor++) { if (atFieldStart) { + if (idx >= FIELDS) + throw Exception("Invalid ObjectId format"); field[idx++] = cursor; atFieldStart = false; } else { if (*cursor == '-') { *cursor = '\0'; atFieldStart = true; - if (idx == NUMERIC_FIELDS) { - cursor++; - break; - } } } } - if (idx != NUMERIC_FIELDS || !atFieldStart || !(*cursor)) + if (idx != FIELDS) throw Exception("Invalid ObjectId format"); first = (atoll(field[0]) << 60) + (atoll(field[1]) << 48) + - (atoll(field[2]) << 28) + - atoll(field[3]); - v2Key = std::string(cursor); + (atoll(field[2]) << 28); + + agentName = std::string(field[3]); + v2Key = std::string(field[4]); } @@ -168,18 +167,31 @@ void ObjectId::mapEncode(messaging::VariantMap& map) const map["_first"] = first; else map["_first"] = (first | agent->first); + map["_object_name"] = v2Key; + if (!agentName.empty()) + map["_agent_name"] = agentName; + if (agentEpoch) + map["_agent_epoch"] = agentEpoch; } void ObjectId::mapDecode(const messaging::VariantMap& map) { messaging::MapView::const_iterator i; + if ((i = map.find("_object_name")) != map.end()) + v2Key = i->second.asString(); + else + throw Exception("Required _object_name field missing."); + if ((i = map.find("_first")) != map.end()) first = i->second.asUint64(); - if ((i = map.find("_object_name")) != map.end()) - v2Key = i->second.asString(); + if ((i = map.find("_agent_name")) != map.end()) + agentName = i->second.asString(); + + if ((i = map.find("_agent_epoch")) != map.end()) + agentEpoch = i->second.asUint64(); } @@ -204,7 +216,7 @@ std::ostream& operator<<(std::ostream& out, const ObjectId& i) out << ((virtFirst & 0xF000000000000000LL) >> 60) << "-" << ((virtFirst & 0x0FFF000000000000LL) >> 48) << "-" << ((virtFirst & 0x0000FFFFF0000000LL) >> 28) << - "-" << (virtFirst & 0x000000000FFFFFFFLL) << + "-" << i.agentName << "-" << i.v2Key; return out; } diff --git a/qpid/cpp/src/tests/ManagementTest.cpp b/qpid/cpp/src/tests/ManagementTest.cpp index 3d079eff75..d0141f796f 100644 --- a/qpid/cpp/src/tests/ManagementTest.cpp +++ b/qpid/cpp/src/tests/ManagementTest.cpp @@ -60,28 +60,30 @@ QPID_AUTO_TEST_CASE(testObjectIdEncode) { ObjectId oid(1, 2, 3); oid.setV2Key("testkey"); + oid.setAgentName("myAgent"); std::stringstream out1; out1 << oid; - BOOST_CHECK_EQUAL(out1.str(), "1-2-3-0-testkey"); + BOOST_CHECK_EQUAL(out1.str(), "1-2-3-myAgent-testkey"); } QPID_AUTO_TEST_CASE(testObjectIdAttach) { AgentAttachment agent; ObjectId oid(&agent, 10, 20); oid.setV2Key("GabbaGabbaHey"); + oid.setAgentName("MrSmith"); std::stringstream out1; out1 << oid; - BOOST_CHECK_EQUAL(out1.str(), "10-20-0-0-GabbaGabbaHey"); + BOOST_CHECK_EQUAL(out1.str(), "10-20-0-MrSmith-GabbaGabbaHey"); agent.setBanks(30, 40); std::stringstream out2; out2 << oid; - BOOST_CHECK_EQUAL(out2.str(), "10-20-30-40-GabbaGabbaHey"); + BOOST_CHECK_EQUAL(out2.str(), "10-20-30-MrSmith-GabbaGabbaHey"); } QPID_AUTO_TEST_CASE(testConsoleObjectId) { |