You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@qpid.apache.org by gs...@apache.org on 2007/01/18 20:22:41 UTC

svn commit: r497542 - in /incubator/qpid/branches/qpid.0-9/cpp: lib/broker/BrokerAdapter.cpp lib/common/framing/AMQMethodBody.h lib/common/framing/FramingContent.cpp lib/common/framing/FramingContent.h tests/FramingTest.cpp

Author: gsim
Date: Thu Jan 18 11:22:40 2007
New Revision: 497542

URL: http://svn.apache.org/viewvc?view=rev&rev=497542
Log:
Initial implementation of AMQP content data type.


Modified:
    incubator/qpid/branches/qpid.0-9/cpp/lib/broker/BrokerAdapter.cpp
    incubator/qpid/branches/qpid.0-9/cpp/lib/common/framing/AMQMethodBody.h
    incubator/qpid/branches/qpid.0-9/cpp/lib/common/framing/FramingContent.cpp
    incubator/qpid/branches/qpid.0-9/cpp/lib/common/framing/FramingContent.h
    incubator/qpid/branches/qpid.0-9/cpp/tests/FramingTest.cpp

Modified: incubator/qpid/branches/qpid.0-9/cpp/lib/broker/BrokerAdapter.cpp
URL: http://svn.apache.org/viewvc/incubator/qpid/branches/qpid.0-9/cpp/lib/broker/BrokerAdapter.cpp?view=diff&rev=497542&r1=497541&r2=497542
==============================================================================
--- incubator/qpid/branches/qpid.0-9/cpp/lib/broker/BrokerAdapter.cpp (original)
+++ incubator/qpid/branches/qpid.0-9/cpp/lib/broker/BrokerAdapter.cpp Thu Jan 18 11:22:40 2007
@@ -491,13 +491,14 @@
 void
 BrokerAdapter::ServerOps::ChannelHandlerImpl::ping( const MethodContext& )
 {
-    assert(0);                // FIXME aconway 2007-01-04: 0-9 feature
+    connection.client->getChannel().ok(channel.getId());
+    connection.client->getChannel().pong(channel.getId());
 }
 
 void
 BrokerAdapter::ServerOps::ChannelHandlerImpl::pong( const MethodContext& )
 {
-    assert(0);                // FIXME aconway 2007-01-04: 0-9 feature
+    connection.client->getChannel().ok(channel.getId());
 }
 
 void

Modified: incubator/qpid/branches/qpid.0-9/cpp/lib/common/framing/AMQMethodBody.h
URL: http://svn.apache.org/viewvc/incubator/qpid/branches/qpid.0-9/cpp/lib/common/framing/AMQMethodBody.h?view=diff&rev=497542&r1=497541&r2=497542
==============================================================================
--- incubator/qpid/branches/qpid.0-9/cpp/lib/common/framing/AMQMethodBody.h (original)
+++ incubator/qpid/branches/qpid.0-9/cpp/lib/common/framing/AMQMethodBody.h Thu Jan 18 11:22:40 2007
@@ -26,6 +26,7 @@
 #include <AMQBody.h>
 #include <Buffer.h>
 #include <AMQP_ServerOperations.h>
+#include <MethodContext.h>
 
 namespace qpid {
 namespace framing {

Modified: incubator/qpid/branches/qpid.0-9/cpp/lib/common/framing/FramingContent.cpp
URL: http://svn.apache.org/viewvc/incubator/qpid/branches/qpid.0-9/cpp/lib/common/framing/FramingContent.cpp?view=diff&rev=497542&r1=497541&r2=497542
==============================================================================
--- incubator/qpid/branches/qpid.0-9/cpp/lib/common/framing/FramingContent.cpp (original)
+++ incubator/qpid/branches/qpid.0-9/cpp/lib/common/framing/FramingContent.cpp Thu Jan 18 11:22:40 2007
@@ -22,26 +22,57 @@
 
 #include "Buffer.h"
 #include "FramingContent.h"
+#include <QpidError.h>
+#include <sstream>
 
 namespace qpid {
 namespace framing {
 
+Content::Content() : discriminator(0) {}
+
+Content::Content(u_int8_t _discriminator, const string& _value): discriminator(_discriminator), value(_value) {
+    validate();
+}
+
+void Content::validate() {
+    //validation:
+    if (discriminator == REFERENCE) {
+        if(value.empty()) {
+            //cannot have empty reference
+            THROW_QPID_ERROR(FRAMING_ERROR, "Reference cannot be empty");
+        }
+    }else if (discriminator != INLINE) {
+        //invalid discriminator
+        std::stringstream out;
+        out << "Invalid discriminator: " << discriminator;
+	THROW_QPID_ERROR(FRAMING_ERROR, out.str());
+    }
+}
+
 Content::~Content() {}
   
-void Content::encode(Buffer&) const {
-    assert(0);                // FIXME aconway 2007-01-04: 0-9 feature
+void Content::encode(Buffer& buffer) const {
+    buffer.putOctet(discriminator);
+    buffer.putLongString(value);
 }
 
-void Content::decode(Buffer&) {
-    assert(0);                // FIXME aconway 2007-01-04: 0-9 feature
+void Content::decode(Buffer& buffer) {
+    discriminator = buffer.getOctet();
+    buffer.getLongString(value);
+    validate();
 }
 
 size_t Content::size() const {
-    assert(0);                // FIXME aconway 2007-01-04: 0-9 feature
+    return 1 + 4 + value.size();
 }
 
-std::ostream& operator<<(std::ostream&, const Content&) {
-    assert(0);                // FIXME aconway 2007-01-04: 0-9 feature
+std::ostream& operator<<(std::ostream& out, const Content& content) {
+    if (content.discriminator == REFERENCE) {
+        out << "{REF:" << content.value << "}";
+    } else if (content.discriminator == INLINE) {
+        out << "{INLINE:" << content.value.size() << " bytes}";
+    }
+    return out;
 }
 
 }} // namespace framing::qpid

Modified: incubator/qpid/branches/qpid.0-9/cpp/lib/common/framing/FramingContent.h
URL: http://svn.apache.org/viewvc/incubator/qpid/branches/qpid.0-9/cpp/lib/common/framing/FramingContent.h?view=diff&rev=497542&r1=497541&r2=497542
==============================================================================
--- incubator/qpid/branches/qpid.0-9/cpp/lib/common/framing/FramingContent.h (original)
+++ incubator/qpid/branches/qpid.0-9/cpp/lib/common/framing/FramingContent.h Thu Jan 18 11:22:40 2007
@@ -6,19 +6,32 @@
 namespace qpid {
 namespace framing {
 
-/*
- * TODO: New Content class required for AMQP 0-9. This is a stub only.
+enum discriminator_types { INLINE = 0, REFERENCE = 1 };
+
+/**
+ * A representation of the AMQP 'content' data type (used for message
+ * bodies) which can hold inline data or a reference.
  */
 class Content
 {
-  public:
+    u_int8_t discriminator;
+    string value;
+
+    void validate();
+
+ public:
+    Content();
+    Content(u_int8_t _discriminator, const string& _value);
     ~Content();
   
     void encode(Buffer& buffer) const;
     void decode(Buffer& buffer);
     size_t size() const;
+    bool isInline() { return discriminator == INLINE; }
+    bool isReference() { return discriminator == REFERENCE; }
+    const string& getValue() { return value; }
 
-  friend std::ostream& operator<<(std::ostream&, const Content&);
+    friend std::ostream& operator<<(std::ostream&, const Content&);
 };    
 
 }} // namespace qpid::framing

Modified: incubator/qpid/branches/qpid.0-9/cpp/tests/FramingTest.cpp
URL: http://svn.apache.org/viewvc/incubator/qpid/branches/qpid.0-9/cpp/tests/FramingTest.cpp?view=diff&rev=497542&r1=497541&r2=497542
==============================================================================
--- incubator/qpid/branches/qpid.0-9/cpp/tests/FramingTest.cpp (original)
+++ incubator/qpid/branches/qpid.0-9/cpp/tests/FramingTest.cpp Thu Jan 18 11:22:40 2007
@@ -55,6 +55,8 @@
     CPPUNIT_TEST(testResponseBodyFrame);
     CPPUNIT_TEST(testRequester);
     CPPUNIT_TEST(testResponder);
+    CPPUNIT_TEST(testInlineContent);
+    CPPUNIT_TEST(testContentReference);
     CPPUNIT_TEST_SUITE_END();
 
   private:
@@ -173,6 +175,28 @@
         ChannelOkBody* decoded =
             dynamic_cast<ChannelOkBody*>(out.getBody().get());
         CPPUNIT_ASSERT(decoded);
+    }
+
+    void testInlineContent() {        
+        Content content(INLINE, "MyData");
+        CPPUNIT_ASSERT(content.isInline());
+        content.encode(buffer);
+        buffer.flip();
+        Content recovered;
+        recovered.decode(buffer);
+        CPPUNIT_ASSERT(recovered.isInline());
+        CPPUNIT_ASSERT_EQUAL(content.getValue(), recovered.getValue());
+    }
+
+    void testContentReference() {        
+        Content content(REFERENCE, "MyRef");
+        CPPUNIT_ASSERT(content.isReference());
+        content.encode(buffer);
+        buffer.flip();
+        Content recovered;
+        recovered.decode(buffer);
+        CPPUNIT_ASSERT(recovered.isReference());
+        CPPUNIT_ASSERT_EQUAL(content.getValue(), recovered.getValue());
     }
 
     void testRequester() {