Author: aconway
Date: Fri Feb 29 15:18:51 2008
New Revision: 632490

URL: http://svn.apache.org/viewvc?rev=632490&view=rev
Log:

 - Added Buffer::Iterator so amqp_0_10::Codec can use a Buffer
 - AMQBody wrappers for amqp_0_10::Command and Control
 - Extended AMQBody for CommandBody and ControlBody.

Added:
    incubator/qpid/trunk/qpid/cpp/src/qpid/framing/AMQCommandControlBody.h   
(with props)
Modified:
    incubator/qpid/trunk/qpid/cpp/src/Makefile.am
    incubator/qpid/trunk/qpid/cpp/src/qpid/amqp_0_10/helpers.h
    incubator/qpid/trunk/qpid/cpp/src/qpid/framing/AMQBody.h
    incubator/qpid/trunk/qpid/cpp/src/qpid/framing/Buffer.h

Modified: incubator/qpid/trunk/qpid/cpp/src/Makefile.am
URL: 
http://svn.apache.org/viewvc/incubator/qpid/trunk/qpid/cpp/src/Makefile.am?rev=632490&r1=632489&r2=632490&view=diff
==============================================================================
--- incubator/qpid/trunk/qpid/cpp/src/Makefile.am (original)
+++ incubator/qpid/trunk/qpid/cpp/src/Makefile.am Fri Feb 29 15:18:51 2008
@@ -375,6 +375,7 @@
   qpid/client/SubscriptionManager.h \
   qpid/client/TypedResult.h \
   qpid/framing/AMQBody.h \
+  qpid/framing/AMQCommandControlBody.h \
   qpid/framing/AMQContentBody.h \
   qpid/framing/AMQDataBlock.h \
   qpid/framing/AMQFrame.h \

Modified: incubator/qpid/trunk/qpid/cpp/src/qpid/amqp_0_10/helpers.h
URL: 
http://svn.apache.org/viewvc/incubator/qpid/trunk/qpid/cpp/src/qpid/amqp_0_10/helpers.h?rev=632490&r1=632489&r2=632490&view=diff
==============================================================================
--- incubator/qpid/trunk/qpid/cpp/src/qpid/amqp_0_10/helpers.h (original)
+++ incubator/qpid/trunk/qpid/cpp/src/qpid/amqp_0_10/helpers.h Fri Feb 29 
15:18:51 2008
@@ -21,6 +21,7 @@
  * under the License.
  *
  */
+#include "qpid/amqp_0_10/built_in_types.h"
 #include <string>
 
 namespace qpid {
@@ -33,22 +34,36 @@
 const char* getStructName(uint8_t classCode, uint8_t code);
 
 struct Command {
+    static const int SEGMENT_TYPE=COMMAND;
     virtual ~Command();
     struct Visitor;
     virtual void accept(Visitor&) const = 0;
 };
 
 struct Control {
+    static const int SEGMENT_TYPE=CONTROL;
     virtual ~Control();
     struct Visitor;
     virtual void accept(Visitor&) const = 0;
 };
 
+// Struct 
 struct Struct {
     virtual ~Struct();
     struct Visitor;
     virtual void accept(Visitor&) const = 0;
 };
+
+template <class SizeType, bool Coded, uint8_t Code, uint8_t Pack>
+struct SerializableStruct : public Struct {
+    static const uint8_t SIZE=sizeof(SizeType);
+    static const bool CODED=Coded;
+    static const uint8_t CODE=Code;
+    static const uint8_t PACK;
+    // TODO aconway 2008-02-29: handle common encoding/decoding/size
+    // for structs. Support for packing.
+};
+
 
 /** Base class for generated enum domains.
  * Enums map to classes for type safety and to provide separate namespaces

Modified: incubator/qpid/trunk/qpid/cpp/src/qpid/framing/AMQBody.h
URL: 
http://svn.apache.org/viewvc/incubator/qpid/trunk/qpid/cpp/src/qpid/framing/AMQBody.h?rev=632490&r1=632489&r2=632490&view=diff
==============================================================================
--- incubator/qpid/trunk/qpid/cpp/src/qpid/framing/AMQBody.h (original)
+++ incubator/qpid/trunk/qpid/cpp/src/qpid/framing/AMQBody.h Fri Feb 29 
15:18:51 2008
@@ -22,6 +22,7 @@
  *
  */
 #include "qpid/framing/amqp_types.h"
+#include "qpid/amqp_0_10/helpers.h"
 
 #include <ostream>
 
@@ -60,6 +61,12 @@
     virtual AMQMethodBody* getMethod() { return 0; }
     virtual const AMQMethodBody* getMethod() const { return 0; }
 
+    virtual amqp_0_10::Command* getCommand() { return 0; }
+    virtual const amqp_0_10::Command* getCommand() const { return 0; }
+
+    virtual amqp_0_10::Control* getControl() { return 0; }
+    virtual const amqp_0_10::Control* getControl() const { return 0; }
+
     /** Match if same type and same class/method ID for methods */
     static bool match(const AMQBody& , const AMQBody& );
 };
@@ -70,7 +77,9 @@
     METHOD_BODY = 1,
     HEADER_BODY = 2,
     CONTENT_BODY = 3,
-    HEARTBEAT_BODY = 8
+    HEARTBEAT_BODY = 8,
+    COMMAND_BODY = 100+amqp_0_10::COMMAND,
+    CONTROL_BODY = 100+amqp_0_10::CONTROL
 };
 
 }} // namespace qpid::framing

Added: incubator/qpid/trunk/qpid/cpp/src/qpid/framing/AMQCommandControlBody.h
URL: 
http://svn.apache.org/viewvc/incubator/qpid/trunk/qpid/cpp/src/qpid/framing/AMQCommandControlBody.h?rev=632490&view=auto
==============================================================================
--- incubator/qpid/trunk/qpid/cpp/src/qpid/framing/AMQCommandControlBody.h 
(added)
+++ incubator/qpid/trunk/qpid/cpp/src/qpid/framing/AMQCommandControlBody.h Fri 
Feb 29 15:18:51 2008
@@ -0,0 +1,70 @@
+#ifndef QPID_FRAMING_AMQCOMMANDCONTROLBODY_H
+#define QPID_FRAMING_AMQCOMMANDCONTROLBODY_H
+
+/*
+ *
+ * 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/amqp_0_10/helpers.h"
+#include "qpid/framing/AMQBody.h"
+
+namespace qpid {
+namespace framing {
+
+/**
+ * AMQBody wrapper for Command and Control.
+ * Temporary measure to fit with old code.
+ */
+template <class T> class AMQCommandControlBody : public AMQBody, public T
+{
+  public:
+    virtual uint8_t type() const { return 100+T::SEGMENT_TYPE; }
+
+    virtual void encode(Buffer& buffer) const {
+        Codec::encode(buffer.getIterator(), static_cast<const T&>(*this));
+    }
+    virtual void decode(Buffer& buffer, uint32_t=0) {
+        Codec::decode(buffer.getIterator(), static_cast<T&>(*this));
+    }
+    virtual uint32_t size() const {
+        Codec::size(buffer.getIterator(), static_cast<const T&>(*this));
+    }
+
+    virtual void print(std::ostream& out) const {
+        out << static_cast<const T&>(*this) << endl;
+    }
+    virtual void AMQBody::accept(AMQBodyConstVisitor&) const { assert(0); }
+};
+
+class CommandBody : public AMQCommandControlBody<amqp_0_10::Command> {
+    using Command::accept;      // Hide AMQBody::accept
+    virtual Command* getCommand() { return this; }
+    virtual const Command* getCommand() const { return this; }
+};
+
+class ControlBody : public AMQCommandControlBody<amqp_0_10::Control> {
+    using Control::accept;      // Hide AMQBody::accept
+    virtual Control* getControl() { return this; }
+    virtual const Control* getControl() const { return this; }
+};
+
+}} // namespace qpid::framing
+
+#endif  /*!QPID_FRAMING_AMQCOMMANDCONTROLBODY_H*/

Propchange: 
incubator/qpid/trunk/qpid/cpp/src/qpid/framing/AMQCommandControlBody.h
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: 
incubator/qpid/trunk/qpid/cpp/src/qpid/framing/AMQCommandControlBody.h
------------------------------------------------------------------------------
    svn:keywords = Rev Date

Modified: incubator/qpid/trunk/qpid/cpp/src/qpid/framing/Buffer.h
URL: 
http://svn.apache.org/viewvc/incubator/qpid/trunk/qpid/cpp/src/qpid/framing/Buffer.h?rev=632490&r1=632489&r2=632490&view=diff
==============================================================================
--- incubator/qpid/trunk/qpid/cpp/src/qpid/framing/Buffer.h (original)
+++ incubator/qpid/trunk/qpid/cpp/src/qpid/framing/Buffer.h Fri Feb 29 15:18:51 
2008
@@ -20,6 +20,7 @@
  */
 #include "amqp_types.h"
 #include "qpid/Exception.h"
+#include <boost/iterator/iterator_facade.hpp>
 
 #ifndef _Buffer_
 #define _Buffer_
@@ -41,8 +42,28 @@
 
     void checkAvailable(uint32_t count) { if (position + count > size) throw 
OutOfBounds(); }
 
-public:
-
+  public:
+    
+    /** Buffer input/output iterator.
+     * Supports using an amqp_0_10::Codec with a framing::Buffer.
+     */
+    class Iterator  : public boost::iterator_facade<
+      Iterator, char, boost::random_access_traversal_tag>
+    {
+      public:
+        Iterator(Buffer& b) : buffer(&b) {}
+
+      private:
+      friend class boost::iterator_core_access;
+        char& dereference() const { return buffer->data[buffer->position]; }
+        void increment() { ++buffer->position; }
+        bool equal(const Iterator& x) const { return buffer == x.buffer; }
+
+        Buffer* buffer;
+    };
+    
+  friend class Iterator;
+    
     Buffer(char* data=0, uint32_t size=0);
 
     void record();
@@ -52,6 +73,7 @@
     uint32_t available() { return size - position; }
     uint32_t getSize() { return size; }
     uint32_t getPosition() { return position; }
+    Iterator getIterator() { return Iterator(*this); }
         
     void putOctet(uint8_t i);
     void putShort(uint16_t i);


Reply via email to