Author: aconway
Date: Fri Jan 12 10:24:13 2007
New Revision: 495679

URL: http://svn.apache.org/viewvc?view=rev&rev=495679
Log:
Use amqp 0-9 request/response framing in broker and client.
Updated: framing, client, broker, generated code.

The new request/response data (request-id etc.) is not yet being used,
we are simply running the old Basic protocol over request/response frames.

Modified:
    incubator/qpid/branches/qpid.0-9/cpp/lib/broker/SessionHandlerImpl.cpp
    incubator/qpid/branches/qpid.0-9/cpp/lib/client/ClientChannel.cpp
    incubator/qpid/branches/qpid.0-9/cpp/lib/common/framing/AMQFrame.cpp
    incubator/qpid/branches/qpid.0-9/cpp/lib/common/framing/AMQFrame.h
    incubator/qpid/branches/qpid.0-9/cpp/lib/common/framing/AMQMethodBody.cpp
    incubator/qpid/branches/qpid.0-9/cpp/lib/common/framing/AMQMethodBody.h
    incubator/qpid/branches/qpid.0-9/cpp/lib/common/framing/AMQRequestBody.cpp
    incubator/qpid/branches/qpid.0-9/cpp/lib/common/framing/AMQRequestBody.h
    incubator/qpid/branches/qpid.0-9/cpp/lib/common/framing/AMQResponseBody.cpp
    incubator/qpid/branches/qpid.0-9/cpp/lib/common/framing/AMQResponseBody.h
    incubator/qpid/branches/qpid.0-9/cpp/lib/common/framing/BodyHandler.cpp
    incubator/qpid/branches/qpid.0-9/cpp/lib/common/framing/amqp_types.h
    incubator/qpid/branches/qpid.0-9/cpp/tests/FramingTest.cpp
    
incubator/qpid/branches/qpid.0-9/gentools/src/org/apache/qpid/gentools/AmqpMethod.java
    
incubator/qpid/branches/qpid.0-9/gentools/src/org/apache/qpid/gentools/CppGenerator.java
    
incubator/qpid/branches/qpid.0-9/gentools/templ.cpp/AMQP_MethodVersionMap.h.tmpl
    incubator/qpid/branches/qpid.0-9/gentools/templ.cpp/MethodBodyClass.h.tmpl

Modified: incubator/qpid/branches/qpid.0-9/cpp/lib/broker/SessionHandlerImpl.cpp
URL: 
http://svn.apache.org/viewvc/incubator/qpid/branches/qpid.0-9/cpp/lib/broker/SessionHandlerImpl.cpp?view=diff&rev=495679&r1=495678&r2=495679
==============================================================================
--- incubator/qpid/branches/qpid.0-9/cpp/lib/broker/SessionHandlerImpl.cpp 
(original)
+++ incubator/qpid/branches/qpid.0-9/cpp/lib/broker/SessionHandlerImpl.cpp Fri 
Jan 12 10:24:13 2007
@@ -95,7 +95,9 @@
 
     switch(body->type())
     {
-    case METHOD_BODY:
+      case REQUEST_BODY:
+      case RESPONSE_BODY:
+      case METHOD_BODY:
         method = dynamic_pointer_cast<AMQMethodBody, AMQBody>(body);
         try{
             method->invoke(*this, channel);

Modified: incubator/qpid/branches/qpid.0-9/cpp/lib/client/ClientChannel.cpp
URL: 
http://svn.apache.org/viewvc/incubator/qpid/branches/qpid.0-9/cpp/lib/client/ClientChannel.cpp?view=diff&rev=495679&r1=495678&r2=495679
==============================================================================
--- incubator/qpid/branches/qpid.0-9/cpp/lib/client/ClientChannel.cpp (original)
+++ incubator/qpid/branches/qpid.0-9/cpp/lib/client/ClientChannel.cpp Fri Jan 
12 10:24:13 2007
@@ -171,7 +171,7 @@
     for(consumer_iterator i = consumers.begin(); i != consumers.end(); i = 
consumers.begin()){
         Consumer* c = i->second;
         if((c->ackMode == LAZY_ACK || c->ackMode == AUTO_ACK) && 
c->lastDeliveryTag > 0){
-            out->send(new AMQFrame(version, id, new 
BasicAckBody(c->lastDeliveryTag, true)));
+            out->send(new AMQFrame(version, id, new BasicAckBody(version, 
c->lastDeliveryTag, true)));
         }
         consumers.erase(i);
         delete c;
@@ -377,8 +377,8 @@
             if(++(consumer->count) < prefetch) break;
             //else drop-through
         case AUTO_ACK:
-            out->send(new AMQFrame(version, id, new 
BasicAckBody(msg.getDeliveryTag(), multiple)));
-            consumer->lastDeliveryTag = 0;
+          out->send(new AMQFrame(version, id, new BasicAckBody(version, 
msg.getDeliveryTag(), multiple)));
+          consumer->lastDeliveryTag = 0;
         }
     }
 

Modified: incubator/qpid/branches/qpid.0-9/cpp/lib/common/framing/AMQFrame.cpp
URL: 
http://svn.apache.org/viewvc/incubator/qpid/branches/qpid.0-9/cpp/lib/common/framing/AMQFrame.cpp?view=diff&rev=495679&r1=495678&r2=495679
==============================================================================
--- incubator/qpid/branches/qpid.0-9/cpp/lib/common/framing/AMQFrame.cpp 
(original)
+++ incubator/qpid/branches/qpid.0-9/cpp/lib/common/framing/AMQFrame.cpp Fri 
Jan 12 10:24:13 2007
@@ -69,13 +69,13 @@
 {    
     if(buffer.available() < 7) return false;
     buffer.record();
-    u_int32_t bufSize = decodeHead(buffer);
-
-    if(buffer.available() < bufSize + 1){
+    u_int32_t frameSize = decodeHead(buffer);
+    
+    if(buffer.available() < frameSize + 1){
         buffer.restore();
         return false;
     }
-    decodeBody(buffer, bufSize);
+    decodeBody(buffer, frameSize);
     u_int8_t end = buffer.getOctet();
     if(end != 0xCE) THROW_QPID_ERROR(FRAMING_ERROR, "Frame end not found");
     return true;
@@ -87,13 +87,19 @@
     return buffer.getLong();
 }
 
-void AMQFrame::decodeBody(Buffer& buffer, uint32_t bufSize)
+void AMQFrame::decodeBody(Buffer& buffer, uint32_t size)
 {    
     switch(type)
     {
       case METHOD_BODY:
         body = AMQMethodBody::create(versionMap, version, buffer);
         break;
+      case REQUEST_BODY:
+        body = AMQRequestBody::create(versionMap, version, buffer);
+        break;
+      case RESPONSE_BODY:
+        body = AMQResponseBody::create(versionMap, version, buffer);
+        break;
       case HEADER_BODY: 
        body = AMQBody::shared_ptr(new AMQHeaderBody()); 
        break;
@@ -103,19 +109,13 @@
       case HEARTBEAT_BODY: 
        body = AMQBody::shared_ptr(new AMQHeartbeatBody()); 
        break;
-      case REQUEST_BODY:
-        body = AMQBody::shared_ptr(new AMQRequestBody(versionMap, version));
-        break;
-      case RESPONSE_BODY:
-        body = AMQBody::shared_ptr(new AMQResponseBody(versionMap, version));
-        break;
       default:
         assert(0);
        string msg("Unknown body type: ");
        msg += type;
        THROW_QPID_ERROR(FRAMING_ERROR, msg);
     }
-    body->decode(buffer, bufSize);
+    body->decode(buffer, size);
 }
 
 std::ostream& qpid::framing::operator<<(std::ostream& out, const AMQFrame& t)

Modified: incubator/qpid/branches/qpid.0-9/cpp/lib/common/framing/AMQFrame.h
URL: 
http://svn.apache.org/viewvc/incubator/qpid/branches/qpid.0-9/cpp/lib/common/framing/AMQFrame.h?view=diff&rev=495679&r1=495678&r2=495679
==============================================================================
--- incubator/qpid/branches/qpid.0-9/cpp/lib/common/framing/AMQFrame.h 
(original)
+++ incubator/qpid/branches/qpid.0-9/cpp/lib/common/framing/AMQFrame.h Fri Jan 
12 10:24:13 2007
@@ -39,13 +39,6 @@
        
 class AMQFrame : virtual public AMQDataBlock
 {
-    static AMQP_MethodVersionMap versionMap;
-    qpid::framing::ProtocolVersion version;
-            
-    u_int16_t channel;
-    u_int8_t type;
-    AMQBody::shared_ptr body;
-            
   public:
     AMQFrame(qpid::framing::ProtocolVersion& _version = 
highestProtocolVersion);
     AMQFrame(qpid::framing::ProtocolVersion& _version, u_int16_t channel, 
AMQBody* body);
@@ -59,6 +52,15 @@
 
     u_int32_t decodeHead(Buffer& buffer); 
     void decodeBody(Buffer& buffer, uint32_t size); 
+
+  private:
+        static AMQP_MethodVersionMap versionMap;
+    qpid::framing::ProtocolVersion version;
+            
+    u_int16_t channel;
+    u_int8_t type;
+    AMQBody::shared_ptr body;
+            
 
   friend std::ostream& operator<<(std::ostream& out, const AMQFrame& body);
 };

Modified: 
incubator/qpid/branches/qpid.0-9/cpp/lib/common/framing/AMQMethodBody.cpp
URL: 
http://svn.apache.org/viewvc/incubator/qpid/branches/qpid.0-9/cpp/lib/common/framing/AMQMethodBody.cpp?view=diff&rev=495679&r1=495678&r2=495679
==============================================================================
--- incubator/qpid/branches/qpid.0-9/cpp/lib/common/framing/AMQMethodBody.cpp 
(original)
+++ incubator/qpid/branches/qpid.0-9/cpp/lib/common/framing/AMQMethodBody.cpp 
Fri Jan 12 10:24:13 2007
@@ -25,14 +25,9 @@
 namespace qpid {
 namespace framing {
 
-void AMQMethodBody::encode(Buffer& buffer) const{
+void AMQMethodBody::encodeId(Buffer& buffer) const{
     buffer.putShort(amqpClassId());
     buffer.putShort(amqpMethodId());
-    encodeContent(buffer);
-}
-
-void AMQMethodBody::decode(Buffer& buffer, u_int32_t /*size*/){
-    decodeContent(buffer);
 }
 
 bool AMQMethodBody::match(AMQMethodBody* other) const{
@@ -43,17 +38,25 @@
     THROW_QPID_ERROR(PROTOCOL_ERROR, "Method not supported by AMQP Server.");
 }
 
-
-
 AMQMethodBody::shared_ptr AMQMethodBody::create(
     AMQP_MethodVersionMap& versionMap, ProtocolVersion version,
     Buffer& buffer)
 {
-    u_int16_t classId = buffer.getShort();
-    u_int16_t methodId = buffer.getShort();
+    MethodId id;
+    id.decode(buffer);
     return AMQMethodBody::shared_ptr(
         versionMap.createMethodBody(
-            classId, methodId, version.getMajor(), version.getMinor()));
+            id.classId, id.methodId, version.getMajor(), version.getMinor()));
 }
+
+void AMQMethodBody::MethodId::decode(Buffer& buffer) {
+    classId = buffer.getShort();
+    methodId = buffer.getShort();
+}
+
+void AMQMethodBody::decode(Buffer& buffer, u_int32_t /*size*/) {
+    decodeContent(buffer);
+}
+
 
 }} // namespace qpid::framing

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=495679&r1=495678&r2=495679
==============================================================================
--- 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 Fri 
Jan 12 10:24:13 2007
@@ -42,20 +42,28 @@
 
     ProtocolVersion version;    
     u_int8_t type() const { return METHOD_BODY; }
-    u_int32_t size() const { return 4 + bodySize(); }
     AMQMethodBody(u_int8_t major, u_int8_t minor) : version(major, minor) {}
     AMQMethodBody(ProtocolVersion version) : version(version) {}
     virtual ~AMQMethodBody() {}
+    void decode(Buffer&, u_int32_t);
 
     virtual u_int16_t amqpMethodId() const = 0;
     virtual u_int16_t amqpClassId() const = 0;
     virtual void invoke(AMQP_ServerOperations& target, u_int16_t channel);
+    bool match(AMQMethodBody* other) const;
+
+  protected:
+    static u_int32_t baseSize() { return 4; }
+
+    struct MethodId {
+        u_int16_t classId;
+        u_int16_t methodId;
+        void decode(Buffer& b);
+    };
+    
+    void encodeId(Buffer& buffer) const;
     virtual void encodeContent(Buffer& buffer) const = 0;
     virtual void decodeContent(Buffer& buffer) = 0;
-    virtual u_int32_t bodySize() const = 0;
-    void encode(Buffer& buffer) const;
-    void decode(Buffer& buffer, u_int32_t size);
-    bool match(AMQMethodBody* other) const;
 };
 
 }} // namespace qpid::framing

Modified: 
incubator/qpid/branches/qpid.0-9/cpp/lib/common/framing/AMQRequestBody.cpp
URL: 
http://svn.apache.org/viewvc/incubator/qpid/branches/qpid.0-9/cpp/lib/common/framing/AMQRequestBody.cpp?view=diff&rev=495679&r1=495678&r2=495679
==============================================================================
--- incubator/qpid/branches/qpid.0-9/cpp/lib/common/framing/AMQRequestBody.cpp 
(original)
+++ incubator/qpid/branches/qpid.0-9/cpp/lib/common/framing/AMQRequestBody.cpp 
Fri Jan 12 10:24:13 2007
@@ -22,37 +22,37 @@
 namespace qpid {
 namespace framing {
 
-AMQRequestBody::AMQRequestBody(AMQP_MethodVersionMap& vm, ProtocolVersion v)
-    : versionMap(vm), version(v) {}
-
-AMQRequestBody::AMQRequestBody(
-    AMQP_MethodVersionMap& vm, ProtocolVersion v,
-    u_int64_t reqId, u_int64_t respMark,
-    AMQMethodBody::shared_ptr m
-) : versionMap(vm), version(v), 
-    requestId(reqId), responseMark(respMark), method(m)
-{}
-    
-
-void
-AMQRequestBody::encode(Buffer& buffer) const {
-    assert(method.get());
+void AMQRequestBody::Data::encode(Buffer& buffer) const {
     buffer.putLongLong(requestId);
     buffer.putLongLong(responseMark);
-    method->encode(buffer);
 }
-
-void
-AMQRequestBody::decode(Buffer& buffer, u_int32_t /*size*/) {
+    
+void AMQRequestBody::Data::decode(Buffer& buffer) {
     requestId = buffer.getLongLong();
     responseMark = buffer.getLongLong();
-    method = AMQMethodBody::create(versionMap, version, buffer);
 }
 
-void
-AMQRequestBody::print(std::ostream& out) const
+void AMQRequestBody::encode(Buffer& buffer) const {
+    data.encode(buffer);
+    encodeId(buffer);
+    encodeContent(buffer);
+}
+
+AMQRequestBody::shared_ptr    
+AMQRequestBody::create(
+    AMQP_MethodVersionMap& versionMap, ProtocolVersion version,
+    Buffer& buffer)
 {
-    out << "request(" << size() << " bytes) " << *method;
+    MethodId id;
+    Data data;
+    data.decode(buffer);
+    id.decode(buffer);
+    AMQRequestBody* body = dynamic_cast<AMQRequestBody*>(
+        versionMap.createMethodBody(
+            id.classId, id.methodId, version.getMajor(), version.getMinor()));
+    assert(body);
+    body->data = data;
+    return AMQRequestBody::shared_ptr(body);
 }
 
 }} // namespace qpid::framing

Modified: 
incubator/qpid/branches/qpid.0-9/cpp/lib/common/framing/AMQRequestBody.h
URL: 
http://svn.apache.org/viewvc/incubator/qpid/branches/qpid.0-9/cpp/lib/common/framing/AMQRequestBody.h?view=diff&rev=495679&r1=495678&r2=495679
==============================================================================
--- incubator/qpid/branches/qpid.0-9/cpp/lib/common/framing/AMQRequestBody.h 
(original)
+++ incubator/qpid/branches/qpid.0-9/cpp/lib/common/framing/AMQRequestBody.h 
Fri Jan 12 10:24:13 2007
@@ -24,40 +24,44 @@
 namespace qpid {
 namespace framing {
 
-class AMQP_MethodVersionMap;
-
 /**
- * Body of an AMQP Request frame.
+ * Body of a request method frame.
  */
-class AMQRequestBody : public AMQBody
+class AMQRequestBody : public AMQMethodBody
 {
-  public:
+ public:
     typedef boost::shared_ptr<AMQRequestBody> shared_ptr;
-
-    AMQRequestBody(AMQP_MethodVersionMap&, ProtocolVersion);
-    AMQRequestBody(
-        AMQP_MethodVersionMap&, ProtocolVersion,
-        u_int64_t requestId, u_int64_t responseMark,
-        AMQMethodBody::shared_ptr method);
-
-    const AMQMethodBody& getMethodBody() const { return *method; }
-    AMQMethodBody& getMethodBody()  { return *method; }
-    u_int64_t getRequestId() { return requestId; }
-    u_int64_t getResponseMark() { return responseMark; }
     
-    u_int32_t size() const  { return 16 + method->size(); }
+    static shared_ptr create(
+        AMQP_MethodVersionMap& versionMap, ProtocolVersion version,
+        Buffer& buffer);
+
+    AMQRequestBody(ProtocolVersion v, RequestId id=0, ResponseId mark=0)
+        : AMQMethodBody(v), data(id, mark) {}
+
     u_int8_t type() const { return REQUEST_BODY; }
-    
     void encode(Buffer& buffer) const;
-    void decode(Buffer& buffer, u_int32_t size);
-    void print(std::ostream& out) const;
 
+    RequestId  getRequestId() const { return data.requestId; }
+    void setRequestId(RequestId id) { data.requestId=id; }
+    ResponseId getResponseMark() const { return data.responseMark; }
+    void setResponseMark(ResponseId mark) { data.responseMark=mark; }
+
+  protected:
+    static const u_int32_t baseSize() { return AMQMethodBody::baseSize()+16; }
+    
   private:
-    AMQP_MethodVersionMap& versionMap;
-    ProtocolVersion version;
-    u_int64_t requestId;
-    u_int64_t responseMark;
-    AMQMethodBody::shared_ptr method;
+    struct Data {
+        Data(RequestId id=0, ResponseId mark=0)
+            : requestId(id), responseMark(mark) {}
+        void encode(Buffer&) const;
+        void decode(Buffer&);
+
+        RequestId requestId;
+        ResponseId responseMark;
+    };
+
+    Data data;
 };
 
 }} // namespace qpid::framing

Modified: 
incubator/qpid/branches/qpid.0-9/cpp/lib/common/framing/AMQResponseBody.cpp
URL: 
http://svn.apache.org/viewvc/incubator/qpid/branches/qpid.0-9/cpp/lib/common/framing/AMQResponseBody.cpp?view=diff&rev=495679&r1=495678&r2=495679
==============================================================================
--- incubator/qpid/branches/qpid.0-9/cpp/lib/common/framing/AMQResponseBody.cpp 
(original)
+++ incubator/qpid/branches/qpid.0-9/cpp/lib/common/framing/AMQResponseBody.cpp 
Fri Jan 12 10:24:13 2007
@@ -22,38 +22,39 @@
 namespace qpid {
 namespace framing {
 
-AMQResponseBody::AMQResponseBody(AMQP_MethodVersionMap& vm, ProtocolVersion v)
-    : versionMap(vm), version(v) {}
-
-AMQResponseBody::AMQResponseBody(
-    AMQP_MethodVersionMap& vm, ProtocolVersion v,
-    u_int64_t respId, u_int64_t reqId, u_int32_t batch,
-    AMQMethodBody::shared_ptr m
-) : versionMap(vm), version(v), 
-    responseId(respId), requestId(reqId), batchOffset(batch), method(m)
-{}
-
-void
-AMQResponseBody::encode(Buffer& buffer) const {
-    assert(method.get());
+void AMQResponseBody::Data::encode(Buffer& buffer) const {
     buffer.putLongLong(responseId);
     buffer.putLongLong(requestId);
     buffer.putLong(batchOffset);
-    method->encode(buffer);
 }
 
-void
-AMQResponseBody::decode(Buffer& buffer, u_int32_t /*size*/) {
+void AMQResponseBody::Data::decode(Buffer& buffer) {
     responseId = buffer.getLongLong();
     requestId = buffer.getLongLong();
     batchOffset = buffer.getLong();
-    method = AMQMethodBody::create(versionMap, version, buffer);
 }
 
-void
-AMQResponseBody::print(std::ostream& out) const
+void AMQResponseBody::encode(Buffer& buffer) const {
+    data.encode(buffer);
+    encodeId(buffer);
+    encodeContent(buffer);
+}
+
+AMQResponseBody::shared_ptr AMQResponseBody::create(
+    AMQP_MethodVersionMap& versionMap, ProtocolVersion version,
+    Buffer& buffer)
 {
-    out << "response(" << size() << " bytes) " << *method;
+    MethodId id;
+    Data data;
+    data.decode(buffer);
+    id.decode(buffer);
+    AMQResponseBody* body = dynamic_cast<AMQResponseBody*>(
+        versionMap.createMethodBody(
+        id.classId, id.methodId, version.getMajor(), version.getMinor()));
+    assert(body);
+    body->data = data;
+    return AMQResponseBody::shared_ptr(body);
 }
+
 
 }} // namespace qpid::framing

Modified: 
incubator/qpid/branches/qpid.0-9/cpp/lib/common/framing/AMQResponseBody.h
URL: 
http://svn.apache.org/viewvc/incubator/qpid/branches/qpid.0-9/cpp/lib/common/framing/AMQResponseBody.h?view=diff&rev=495679&r1=495678&r2=495679
==============================================================================
--- incubator/qpid/branches/qpid.0-9/cpp/lib/common/framing/AMQResponseBody.h 
(original)
+++ incubator/qpid/branches/qpid.0-9/cpp/lib/common/framing/AMQResponseBody.h 
Fri Jan 12 10:24:13 2007
@@ -27,40 +27,44 @@
 class AMQP_MethodVersionMap;
 
 /**
- * Body of an AMQP Response frame.
+ * Body of a response method frame.
  */
-class AMQResponseBody : public AMQBody
+class AMQResponseBody : public AMQMethodBody
 {
 
   public:
     typedef boost::shared_ptr<AMQResponseBody> shared_ptr;
+    
+    static shared_ptr create(
+        AMQP_MethodVersionMap& versionMap, ProtocolVersion version,
+        Buffer& buffer);
 
-    AMQResponseBody(AMQP_MethodVersionMap&, ProtocolVersion);
     AMQResponseBody(
-        AMQP_MethodVersionMap&, ProtocolVersion,
-        u_int64_t responseId, u_int64_t requestId, u_int32_t batchOffset,
-        AMQMethodBody::shared_ptr method);
-
-    const AMQMethodBody& getMethodBody() const { return *method; }
-    AMQMethodBody& getMethodBody()  { return *method; }
-    u_int64_t getResponseId() { return responseId; }
-    u_int64_t getRequestId() { return requestId; }
-    u_int32_t getBatchOffset() { return batchOffset; }
-    
-    u_int32_t size() const  { return 20 + method->size(); }
+        ProtocolVersion v, ResponseId id=0, RequestId req=0, BatchOffset off=0)
+        : AMQMethodBody(v), data(id, req, off) {}
+
     u_int8_t type() const { return RESPONSE_BODY; }
-    
     void encode(Buffer& buffer) const;
-    void decode(Buffer& buffer, u_int32_t size);
-    void print(std::ostream& out) const;
 
+    ResponseId getResponseId() { return data.responseId; }
+    RequestId getRequestId() { return data.requestId; }
+    BatchOffset getBatchOffset() { return data.batchOffset; }
+
+  protected:
+    static const u_int32_t baseSize() { return AMQMethodBody::baseSize()+20; }
   private:
-    AMQP_MethodVersionMap& versionMap;
-    ProtocolVersion version;
-    u_int64_t responseId;
-    u_int64_t requestId;
-    u_int32_t batchOffset;
-    AMQMethodBody::shared_ptr method;
+    struct Data {
+        Data(ResponseId id=0, RequestId req=0, BatchOffset off=0)
+            : responseId(id), requestId(req), batchOffset(off) {}
+        void encode(Buffer&) const;
+        void decode(Buffer&);
+
+        u_int64_t responseId;
+        u_int64_t requestId;
+        u_int32_t batchOffset;
+    };
+
+    Data data;
 };
 
 }} // namespace qpid::framing

Modified: 
incubator/qpid/branches/qpid.0-9/cpp/lib/common/framing/BodyHandler.cpp
URL: 
http://svn.apache.org/viewvc/incubator/qpid/branches/qpid.0-9/cpp/lib/common/framing/BodyHandler.cpp?view=diff&rev=495679&r1=495678&r2=495679
==============================================================================
--- incubator/qpid/branches/qpid.0-9/cpp/lib/common/framing/BodyHandler.cpp 
(original)
+++ incubator/qpid/branches/qpid.0-9/cpp/lib/common/framing/BodyHandler.cpp Fri 
Jan 12 10:24:13 2007
@@ -30,24 +30,25 @@
 
     switch(body->type())
     {
-
-    case METHOD_BODY:
+      case METHOD_BODY:
+      case REQUEST_BODY:
+      case RESPONSE_BODY:
        handleMethod(dynamic_pointer_cast<AMQMethodBody, AMQBody>(body));
        break;
  
-   case HEADER_BODY:
+      case HEADER_BODY:
        handleHeader(dynamic_pointer_cast<AMQHeaderBody, AMQBody>(body));
        break;
 
-    case CONTENT_BODY:
+      case CONTENT_BODY:
        handleContent(dynamic_pointer_cast<AMQContentBody, AMQBody>(body));
        break;
 
-    case HEARTBEAT_BODY:
+      case HEARTBEAT_BODY:
        handleHeartbeat(dynamic_pointer_cast<AMQHeartbeatBody, AMQBody>(body));
        break;
 
-    default:
+      default:
        throw UnknownBodyType(body->type());
     }
 

Modified: incubator/qpid/branches/qpid.0-9/cpp/lib/common/framing/amqp_types.h
URL: 
http://svn.apache.org/viewvc/incubator/qpid/branches/qpid.0-9/cpp/lib/common/framing/amqp_types.h?view=diff&rev=495679&r1=495678&r2=495679
==============================================================================
--- incubator/qpid/branches/qpid.0-9/cpp/lib/common/framing/amqp_types.h 
(original)
+++ incubator/qpid/branches/qpid.0-9/cpp/lib/common/framing/amqp_types.h Fri 
Jan 12 10:24:13 2007
@@ -32,11 +32,14 @@
 #include "stdint.h"
 #endif
 
-
 namespace qpid {
 namespace framing {
 
 using std::string;
+
+typedef u_int64_t RequestId;
+typedef u_int64_t ResponseId;
+typedef u_int32_t BatchOffset;
 
 }} // namespace qpid::framing
 #endif

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=495679&r1=495678&r2=495679
==============================================================================
--- incubator/qpid/branches/qpid.0-9/cpp/tests/FramingTest.cpp (original)
+++ incubator/qpid/branches/qpid.0-9/cpp/tests/FramingTest.cpp Fri Jan 12 
10:24:13 2007
@@ -39,7 +39,7 @@
     out << x;
     return out.str();
 }
-    
+
 class FramingTest : public CppUnit::TestCase  
 {
     CPPUNIT_TEST_SUITE(FramingTest);
@@ -147,38 +147,29 @@
     }
 
     void testRequestBodyFrame() {
-        AMQMethodBody::shared_ptr method(new ChannelOkBody(version));
-        AMQRequestBody::shared_ptr request(
-            new AMQRequestBody(versionMap, version, 111, 222, method));
+        std::string testing("testing");
+        AMQBody::shared_ptr request(new ChannelOpenBody(version, testing));
         AMQFrame in(version, 999, request);
         in.encode(buffer);
         buffer.flip();
         AMQFrame out;
         out.decode(buffer);
-        request = boost::dynamic_pointer_cast<AMQRequestBody>(out.getBody());
-        CPPUNIT_ASSERT(request);
-        CPPUNIT_ASSERT_EQUAL(111ULL, request->getRequestId());
-        CPPUNIT_ASSERT_EQUAL(222ULL, request->getResponseMark());
-        AMQMethodBody& body = request->getMethodBody();
-        CPPUNIT_ASSERT(dynamic_cast<ChannelOkBody*>(&body));
+        ChannelOpenBody* decoded =
+            dynamic_cast<ChannelOpenBody*>(out.getBody().get());
+        CPPUNIT_ASSERT(decoded);
+        CPPUNIT_ASSERT_EQUAL(testing, decoded->getOutOfBand());
     }
     
     void testResponseBodyFrame() {
-        AMQMethodBody::shared_ptr method(new ChannelOkBody(version));
-        AMQResponseBody::shared_ptr response(
-            new AMQResponseBody(versionMap, version, 111, 222, 333, method));
+        AMQBody::shared_ptr response(new ChannelOkBody(version));
         AMQFrame in(version, 999, response);
         in.encode(buffer);
         buffer.flip();
         AMQFrame out;
         out.decode(buffer);
-        response = boost::dynamic_pointer_cast<AMQResponseBody>(out.getBody());
-        CPPUNIT_ASSERT(response);
-        CPPUNIT_ASSERT_EQUAL(111ULL, response->getResponseId());
-        CPPUNIT_ASSERT_EQUAL(222ULL, response->getRequestId());
-        CPPUNIT_ASSERT_EQUAL(333U, response->getBatchOffset());
-        AMQMethodBody& body = response->getMethodBody();
-        CPPUNIT_ASSERT(dynamic_cast<ChannelOkBody*>(&body));
+        ChannelOkBody* decoded =
+            dynamic_cast<ChannelOkBody*>(out.getBody().get());
+        CPPUNIT_ASSERT(decoded);
     }
 };
 

Modified: 
incubator/qpid/branches/qpid.0-9/gentools/src/org/apache/qpid/gentools/AmqpMethod.java
URL: 
http://svn.apache.org/viewvc/incubator/qpid/branches/qpid.0-9/gentools/src/org/apache/qpid/gentools/AmqpMethod.java?view=diff&rev=495679&r1=495678&r2=495679
==============================================================================
--- 
incubator/qpid/branches/qpid.0-9/gentools/src/org/apache/qpid/gentools/AmqpMethod.java
 (original)
+++ 
incubator/qpid/branches/qpid.0-9/gentools/src/org/apache/qpid/gentools/AmqpMethod.java
 Fri Jan 12 10:24:13 2007
@@ -31,6 +31,7 @@
        public AmqpVersionSet versionSet;
        public AmqpFieldMap fieldMap;
        public String name;
+        public boolean isRequest;
        public AmqpOrdinalVersionMap indexMap;
        public AmqpFlagMap clientMethodFlagMap; // Method called on client 
(<chassis name="server"> in XML)
        public AmqpFlagMap serverMethodFlagMap; // Method called on server 
(<chassis name="client"> in XML)
@@ -64,6 +65,7 @@
                }
                NodeList nList = methodNode.getChildNodes();
                int fieldCntr = 0;
+               isRequest = false; // Assume not a request  unless we find a 
response node.
                for (int i=0; i<nList.getLength(); i++)
                {
                        Node child = nList.item(i);
@@ -102,6 +104,9 @@
                                String value = Utils.getNamedAttribute(child, 
Utils.ATTRIBUTE_VALUE);
                                if (value.compareTo("no-gen") == 0)
                                        return false;
+                       }
+                       else if (child.getNodeName().equals("response")) {
+                           isRequest = true;
                        }
                }
                processChassisFlags(serverChassisFlag, clientChassisFlag, 
version);

Modified: 
incubator/qpid/branches/qpid.0-9/gentools/src/org/apache/qpid/gentools/CppGenerator.java
URL: 
http://svn.apache.org/viewvc/incubator/qpid/branches/qpid.0-9/gentools/src/org/apache/qpid/gentools/CppGenerator.java?view=diff&rev=495679&r1=495678&r2=495679
==============================================================================
--- 
incubator/qpid/branches/qpid.0-9/gentools/src/org/apache/qpid/gentools/CppGenerator.java
 (original)
+++ 
incubator/qpid/branches/qpid.0-9/gentools/src/org/apache/qpid/gentools/CppGenerator.java
 Fri Jan 12 10:24:13 2007
@@ -340,24 +340,30 @@
             }
         if (token.compareTo("${FIELD}") == 0 && field != null)
             return field.name;
-        if (token.compareTo(versionNamespaceStartToken) == 0 && version != 
null)
+        if (token.equals(versionNamespaceStartToken) && version != null)
             return "namespace " + version.namespace() + cr + "{";
-        if (token.compareTo(versionNamespaceEndToken) == 0 && version != null)
+        if (token.equals(versionNamespaceEndToken) && version != null)
             return "} // namespace " + version.namespace();
-        if (token.compareTo("${mb_constructor_with_initializers}") == 0)
+        if (token.equals("${mb_constructor_with_initializers}"))
             return generateConstructor(thisClass, method, version, 4, 4);
-        if (token.compareTo("${mb_server_operation_invoke}") == 0)
+        if (token.equals("${mb_server_operation_invoke}"))
             return generateServerOperationsInvoke(thisClass, method, version, 
4, 4);
-        if (token.compareTo("${mb_buffer_param}") == 0)
-            return method.fieldMap.size() > 0 ? " buffer" : "";
-        if (token.compareTo("${hv_latest_major}") == 0)
+        if (token.equals("${mb_buffer_param}"))
+            return method.fieldMap.size() > 0 ? " buffer" : "/*buffer*/";
+        if (token.equals("${hv_latest_major}"))
             return String.valueOf(globalVersionSet.last().getMajor());
-        if (token.compareTo("${hv_latest_minor}") == 0)
+        if (token.equals("${hv_latest_minor}"))
             return String.valueOf(globalVersionSet.last().getMinor());
+       if (token.equals("${mb_base_class}")) 
+           return baseClass(method);
             
         throw new AmqpTemplateException("Template token " + token + " 
unknown.");       
     }
-        
+
+    private String baseClass(AmqpMethod method) {
+       return method.isRequest ? "AMQRequestBody" : "AMQResponseBody";
+    }
+    
     @Override
         protected void processClassList(StringBuffer sb, int 
listMarkerStartIndex, int listMarkerEndIndex,
                                         AmqpModel model)
@@ -524,35 +530,20 @@
         String token = tline.substring(tokxStart).trim();
         sb.delete(listMarkerStartIndex, lend);
                 
-        if (token.compareTo("${mb_field_declaration}") == 0)
-            {
-                codeSnippet = generateFieldDeclarations(fieldMap, version, 4);
-            }
-        else if (token.compareTo("${mb_field_get_method}") == 0)
-            {
-                codeSnippet = generateFieldGetMethods(fieldMap, version, 4);
-            }
-        else if (token.compareTo("${mb_field_print}") == 0)
-            {
-                codeSnippet = generatePrintMethodContents(fieldMap, version, 
8);
-            }
-        else if (token.compareTo("${mb_body_size}") == 0)
-            {
-                codeSnippet = generateBodySizeMethodContents(fieldMap, 
version, 8);
-            }
-        else if (token.compareTo("${mb_encode}") == 0)
-            {
-                codeSnippet = generateEncodeMethodContents(fieldMap, version, 
8);
-            }
-        else if (token.compareTo("${mb_decode}") == 0)
-            {
-                codeSnippet = generateDecodeMethodContents(fieldMap, version, 
8);
-            }
-                
+        if (token.equals("${mb_field_declaration}") )
+           codeSnippet = generateFieldDeclarations(fieldMap, version, 4);
+        else if (token.equals("${mb_field_get_method}") )
+           codeSnippet = generateFieldGetMethods(fieldMap, version, 4);
+        else if (token.equals("${mb_field_print}") )
+           codeSnippet = generatePrintMethodContents(fieldMap, version, 8);
+        else if (token.equals("${mb_body_size}") )
+           codeSnippet = generateBodySizeMethodContents(fieldMap, version, 8);
+        else if (token.equals("${mb_encode}") )
+           codeSnippet = generateEncodeMethodContents(fieldMap, version, 8);
+        else if (token.equals("${mb_decode}") )
+           codeSnippet = generateDecodeMethodContents(fieldMap, version, 8);
         else // Oops!
-            {
-                throw new AmqpTemplateException("Template token " + token + " 
unknown.");
-            }
+           throw new AmqpTemplateException("Template token " + token + " 
unknown.");
         sb.insert(listMarkerStartIndex, codeSnippet);
     }
 
@@ -1214,7 +1205,7 @@
                             {
                                 
sb.append(generateBitArrayBodySizeMethodContents(bitFieldList, ordinal, 
indentSize));
                             }
-                        sb.append(indent + "size += " +
+                        sb.append(indent + "sz += " +
                                   typeMap.get(domainType).size.replaceAll("#", 
fieldDomainPair[FIELD_NAME]) +
                                   "; /* " + fieldDomainPair[FIELD_NAME] + ": " 
+
                                   domainType + " */" + cr);
@@ -1236,7 +1227,7 @@
         String comment = bitFieldList.size() == 1 ?
             bitFieldList.get(0) + ": bit" :
             "Combinded bits: " + bitFieldList;
-        sb.append(indent + "size += " +
+        sb.append(indent + "sz += " +
                   typeMap.get("bit").size.replaceAll("~", 
String.valueOf(numBytes)) +
                   "; /* " + comment + " */" + cr);
         bitFieldList.clear();           
@@ -1437,7 +1428,7 @@
                 sb.append(indent + thisClass.name + 
Utils.firstUpper(method.name) + "Body(ProtocolVersion& version," + cr);
                 sb.append(generateFieldList(method.fieldMap, version, true, 
false, 8));
                 sb.append(indent + tab + ") :" + cr);
-                sb.append(indent + tab + "AMQMethodBody(version)," + cr);
+                sb.append(indent + tab + baseClass(method) + "(version)," + 
cr);
                 sb.append(generateFieldList(method.fieldMap, version, false, 
true, 8));
                 sb.append(indent + "{ }" + cr);
             }

Modified: 
incubator/qpid/branches/qpid.0-9/gentools/templ.cpp/AMQP_MethodVersionMap.h.tmpl
URL: 
http://svn.apache.org/viewvc/incubator/qpid/branches/qpid.0-9/gentools/templ.cpp/AMQP_MethodVersionMap.h.tmpl?view=diff&rev=495679&r1=495678&r2=495679
==============================================================================
--- 
incubator/qpid/branches/qpid.0-9/gentools/templ.cpp/AMQP_MethodVersionMap.h.tmpl
 (original)
+++ 
incubator/qpid/branches/qpid.0-9/gentools/templ.cpp/AMQP_MethodVersionMap.h.tmpl
 Fri Jan 12 10:24:13 2007
@@ -39,7 +39,7 @@
 namespace framing
 {
 
-template <class T> AMQMethodBody* createMethodBodyFn(u_int8_t major, u_int8_t 
minor) { return new T(major, minor); }
+template <class T> AMQMethodBody* createMethodBodyFn(u_int8_t major, u_int8_t 
minor) { return new T(ProtocolVersion(major, minor)); }
 typedef AMQMethodBody* (*fnPtr)(u_int8_t, u_int8_t);
 
 class AMQP_MethodVersionMap: public std::map<u_int64_t, fnPtr>

Modified: 
incubator/qpid/branches/qpid.0-9/gentools/templ.cpp/MethodBodyClass.h.tmpl
URL: 
http://svn.apache.org/viewvc/incubator/qpid/branches/qpid.0-9/gentools/templ.cpp/MethodBodyClass.h.tmpl?view=diff&rev=495679&r1=495678&r2=495679
==============================================================================
--- incubator/qpid/branches/qpid.0-9/gentools/templ.cpp/MethodBodyClass.h.tmpl 
(original)
+++ incubator/qpid/branches/qpid.0-9/gentools/templ.cpp/MethodBodyClass.h.tmpl 
Fri Jan 12 10:24:13 2007
@@ -30,7 +30,7 @@
 #include <sstream>
 
 #include <amqp_types.h>
-#include <AMQMethodBody.h>
+#include <${mb_base_class}.h>
 #include <Buffer.h>
 #include <FieldTable.h>
 #include <FramingContent.h>
@@ -44,7 +44,7 @@
 {
 ${version_namespace_start}
  
-class ${CLASS}${METHOD}Body : public AMQMethodBody
+class ${CLASS}${METHOD}Body : public ${mb_base_class}
 {
        // Method field declarations
 
@@ -58,8 +58,7 @@
 
 ${mb_constructor_with_initializers}
 
-    inline ${CLASS}${METHOD}Body(u_int8_t major, u_int8_t minor): 
AMQMethodBody(major, minor) {}
-    inline ${CLASS}${METHOD}Body(ProtocolVersion& version): 
AMQMethodBody(version) {}
+    ${CLASS}${METHOD}Body(const ProtocolVersion& version): 
${mb_base_class}(version) {}
     virtual ~${CLASS}${METHOD}Body() {}
     
     // Attribute get methods
@@ -84,19 +83,19 @@
        return ${METHOD_ID_INIT};
     }
 
-    inline u_int32_t bodySize() const
+    u_int32_t size() const
     {
-               u_int32_t size = 0;        
+        u_int32_t sz = baseSize();
 %{FLIST} ${mb_body_size}
-        return size;
+        return sz;
     }
 
-    inline void encodeContent(Buffer&${mb_buffer_param}) const
+    void encodeContent(Buffer& ${mb_buffer_param}) const
     {
 %{FLIST} ${mb_encode}
     }
 
-    inline void decodeContent(Buffer&${mb_buffer_param})
+    inline void decodeContent(Buffer& ${mb_buffer_param})
     {
 %{FLIST} ${mb_decode}
     }       


Reply via email to