Author: tross
Date: Wed Oct  8 08:49:27 2008
New Revision: 702913

URL: http://svn.apache.org/viewvc?rev=702913&view=rev
Log:
Added serialize/deserialize for ObjectId

Added:
    incubator/qpid/trunk/qpid/cpp/src/tests/ManagementTest.cpp
Modified:
    incubator/qpid/trunk/qpid/cpp/src/qpid/management/ManagementObject.cpp
    incubator/qpid/trunk/qpid/cpp/src/qpid/management/ManagementObject.h
    incubator/qpid/trunk/qpid/cpp/src/tests/Makefile.am

Modified: incubator/qpid/trunk/qpid/cpp/src/qpid/management/ManagementObject.cpp
URL: 
http://svn.apache.org/viewvc/incubator/qpid/trunk/qpid/cpp/src/qpid/management/ManagementObject.cpp?rev=702913&r1=702912&r2=702913&view=diff
==============================================================================
--- incubator/qpid/trunk/qpid/cpp/src/qpid/management/ManagementObject.cpp 
(original)
+++ incubator/qpid/trunk/qpid/cpp/src/qpid/management/ManagementObject.cpp Wed 
Oct  8 08:49:27 2008
@@ -55,6 +55,41 @@
     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 @@
 
 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;
 }
 

Modified: incubator/qpid/trunk/qpid/cpp/src/qpid/management/ManagementObject.h
URL: 
http://svn.apache.org/viewvc/incubator/qpid/trunk/qpid/cpp/src/qpid/management/ManagementObject.h?rev=702913&r1=702912&r2=702913&view=diff
==============================================================================
--- incubator/qpid/trunk/qpid/cpp/src/qpid/management/ManagementObject.h 
(original)
+++ incubator/qpid/trunk/qpid/cpp/src/qpid/management/ManagementObject.h Wed 
Oct  8 08:49:27 2008
@@ -42,6 +42,7 @@
 public:
     AgentAttachment() : first(0) {}
     void setBanks(uint32_t broker, uint32_t bank);
+    uint64_t getFirst() const { return first; }
 };
 
 
@@ -55,6 +56,7 @@
     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);

Modified: incubator/qpid/trunk/qpid/cpp/src/tests/Makefile.am
URL: 
http://svn.apache.org/viewvc/incubator/qpid/trunk/qpid/cpp/src/tests/Makefile.am?rev=702913&r1=702912&r2=702913&view=diff
==============================================================================
--- incubator/qpid/trunk/qpid/cpp/src/tests/Makefile.am (original)
+++ incubator/qpid/trunk/qpid/cpp/src/tests/Makefile.am Wed Oct  8 08:49:27 2008
@@ -64,7 +64,8 @@
        TxPublishTest.cpp \
        MessageBuilderTest.cpp \
        ConnectionOptions.h \
-       ForkedBroker.h
+       ForkedBroker.h \
+       ManagementTest.cpp
 
 if HAVE_XML
 unit_test_SOURCES+= XmlClientSessionTest.cpp

Added: incubator/qpid/trunk/qpid/cpp/src/tests/ManagementTest.cpp
URL: 
http://svn.apache.org/viewvc/incubator/qpid/trunk/qpid/cpp/src/tests/ManagementTest.cpp?rev=702913&view=auto
==============================================================================
--- incubator/qpid/trunk/qpid/cpp/src/tests/ManagementTest.cpp (added)
+++ incubator/qpid/trunk/qpid/cpp/src/tests/ManagementTest.cpp Wed Oct  8 
08:49:27 2008
@@ -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()
+
+


Reply via email to