summaryrefslogtreecommitdiff
path: root/cpp/src
diff options
context:
space:
mode:
Diffstat (limited to 'cpp/src')
-rw-r--r--cpp/src/qpid/management/ManagementObject.cpp49
-rw-r--r--cpp/src/qpid/management/ManagementObject.h2
-rw-r--r--cpp/src/tests/Makefile.am3
-rw-r--r--cpp/src/tests/ManagementTest.cpp74
4 files changed, 122 insertions, 6 deletions
diff --git a/cpp/src/qpid/management/ManagementObject.cpp b/cpp/src/qpid/management/ManagementObject.cpp
index ce65ae3279..b31fff83ae 100644
--- a/cpp/src/qpid/management/ManagementObject.cpp
+++ b/cpp/src/qpid/management/ManagementObject.cpp
@@ -55,6 +55,41 @@ ObjectId::ObjectId(AgentAttachment* _agent, uint8_t flags, uint16_t seq, uint64_
second = object;
}
+ObjectId::ObjectId(std::istream& in) : agent(0)
+{
+#define FIELDS 5
+ string text;
+ char* cText;
+ char* field[FIELDS];
+ bool atFieldStart = true;
+ int idx = 0;
+
+ in >> text;
+ cText = const_cast<char*>(text.c_str());
+ 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 != FIELDS)
+ throw Exception("Invalid ObjectId format");
+
+ first = (atoll(field[0]) << 60) +
+ (atoll(field[1]) << 48) +
+ (atoll(field[2]) << 28) +
+ atoll(field[3]);
+ second = atoll(field[4]);
+}
+
bool ObjectId::operator==(const ObjectId &other) const
{
uint64_t otherFirst = agent == 0 ? other.first : other.first & 0xffff000000000000LL;
@@ -89,11 +124,15 @@ namespace management {
std::ostream& operator<<(std::ostream& out, const ObjectId& i)
{
- out << "[" << ((i.first & 0xF000000000000000LL) >> 60) <<
- "-" << ((i.first & 0x0FFF000000000000LL) >> 48) <<
- "-" << ((i.first & 0x0000FFFFF0000000LL) >> 32) <<
- "-" << (i.first & 0x000000000FFFFFFFLL) <<
- "-" << i.second << "]";
+ uint64_t virtFirst = i.first;
+ if (i.agent)
+ virtFirst |= i.agent->getFirst();
+
+ out << ((virtFirst & 0xF000000000000000LL) >> 60) <<
+ "-" << ((virtFirst & 0x0FFF000000000000LL) >> 48) <<
+ "-" << ((virtFirst & 0x0000FFFFF0000000LL) >> 28) <<
+ "-" << (virtFirst & 0x000000000FFFFFFFLL) <<
+ "-" << i.second;
return out;
}
diff --git a/cpp/src/qpid/management/ManagementObject.h b/cpp/src/qpid/management/ManagementObject.h
index 3778d66b7e..df05ca15d3 100644
--- a/cpp/src/qpid/management/ManagementObject.h
+++ b/cpp/src/qpid/management/ManagementObject.h
@@ -42,6 +42,7 @@ private:
public:
AgentAttachment() : first(0) {}
void setBanks(uint32_t broker, uint32_t bank);
+ uint64_t getFirst() const { return first; }
};
@@ -55,6 +56,7 @@ public:
ObjectId(framing::Buffer& buf) : agent(0) { decode(buf); }
ObjectId(uint8_t flags, uint16_t seq, uint32_t broker, uint32_t bank, uint64_t object);
ObjectId(AgentAttachment* _agent, uint8_t flags, uint16_t seq, uint64_t object);
+ ObjectId(std::istream&);
bool operator==(const ObjectId &other) const;
bool operator<(const ObjectId &other) const;
void encode(framing::Buffer& buffer);
diff --git a/cpp/src/tests/Makefile.am b/cpp/src/tests/Makefile.am
index b1f5eaeb3f..191b784180 100644
--- a/cpp/src/tests/Makefile.am
+++ b/cpp/src/tests/Makefile.am
@@ -64,7 +64,8 @@ unit_test_SOURCES= unit_test.cpp unit_test.h \
TxPublishTest.cpp \
MessageBuilderTest.cpp \
ConnectionOptions.h \
- ForkedBroker.h
+ ForkedBroker.h \
+ ManagementTest.cpp
if HAVE_XML
unit_test_SOURCES+= XmlClientSessionTest.cpp
diff --git a/cpp/src/tests/ManagementTest.cpp b/cpp/src/tests/ManagementTest.cpp
new file mode 100644
index 0000000000..5ec3453b7c
--- /dev/null
+++ b/cpp/src/tests/ManagementTest.cpp
@@ -0,0 +1,74 @@
+/*
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ *
+ */
+
+#include "qpid/management/ManagementObject.h"
+#include "qpid/framing/Buffer.h"
+#include "unit_test.h"
+
+QPID_AUTO_TEST_SUITE(ManagementTestSuite)
+
+using namespace qpid::framing;
+using namespace qpid::management;
+
+QPID_AUTO_TEST_CASE(testObjectIdSerialize) {
+ std::string text("0-10-4-2500-80000000000");
+ std::stringstream input(text);
+
+ ObjectId oid(input);
+
+ std::stringstream output;
+ output << oid;
+
+ BOOST_CHECK_EQUAL(text, output.str());
+}
+
+QPID_AUTO_TEST_CASE(testObjectIdEncode) {
+ char buffer[100];
+ Buffer msgBuf(buffer, 100);
+ msgBuf.putLongLong(0x1002000030000004LL);
+ msgBuf.putLongLong(0x0000000000000005LL);
+ msgBuf.reset();
+
+ ObjectId oid(msgBuf);
+
+ std::stringstream out1;
+ out1 << oid;
+
+ BOOST_CHECK_EQUAL(out1.str(), "1-2-3-4-5");
+}
+
+QPID_AUTO_TEST_CASE(testObjectIdAttach) {
+ AgentAttachment agent;
+ ObjectId oid(&agent, 10, 20, 50);
+
+ std::stringstream out1;
+ out1 << oid;
+ BOOST_CHECK_EQUAL(out1.str(), "10-20-0-0-50");
+
+ agent.setBanks(30, 40);
+ std::stringstream out2;
+ out2 << oid;
+ BOOST_CHECK_EQUAL(out2.str(), "10-20-30-40-50");
+}
+
+QPID_AUTO_TEST_SUITE_END()
+
+