diff options
author | Alan Conway <aconway@apache.org> | 2008-02-29 23:18:51 +0000 |
---|---|---|
committer | Alan Conway <aconway@apache.org> | 2008-02-29 23:18:51 +0000 |
commit | 254e04814f2ad7887990cd9c3374c9e8a93d501a (patch) | |
tree | 4954c7c410ebefefdd7205d72d3e544ee1de34ab /qpid/cpp/src | |
parent | e7755b9ca2742f4f3ac934fadb7a5a7925a5ead6 (diff) | |
download | qpid-python-254e04814f2ad7887990cd9c3374c9e8a93d501a.tar.gz |
- 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.
git-svn-id: https://svn.apache.org/repos/asf/incubator/qpid/trunk@632490 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'qpid/cpp/src')
-rw-r--r-- | qpid/cpp/src/Makefile.am | 1 | ||||
-rw-r--r-- | qpid/cpp/src/qpid/amqp_0_10/helpers.h | 15 | ||||
-rw-r--r-- | qpid/cpp/src/qpid/framing/AMQBody.h | 11 | ||||
-rw-r--r-- | qpid/cpp/src/qpid/framing/AMQCommandControlBody.h | 70 | ||||
-rw-r--r-- | qpid/cpp/src/qpid/framing/Buffer.h | 26 |
5 files changed, 120 insertions, 3 deletions
diff --git a/qpid/cpp/src/Makefile.am b/qpid/cpp/src/Makefile.am index a3609667d7..48851085c6 100644 --- a/qpid/cpp/src/Makefile.am +++ b/qpid/cpp/src/Makefile.am @@ -375,6 +375,7 @@ nobase_include_HEADERS = \ 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 \ diff --git a/qpid/cpp/src/qpid/amqp_0_10/helpers.h b/qpid/cpp/src/qpid/amqp_0_10/helpers.h index fc9a3e16a4..b5150cd10f 100644 --- a/qpid/cpp/src/qpid/amqp_0_10/helpers.h +++ b/qpid/cpp/src/qpid/amqp_0_10/helpers.h @@ -21,6 +21,7 @@ n * "License"); you may not use this file except in compliance * under the License. * */ +#include "qpid/amqp_0_10/built_in_types.h" #include <string> namespace qpid { @@ -33,23 +34,37 @@ const char* getControlName(uint8_t classCode, uint8_t code); 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 * for clashing values. diff --git a/qpid/cpp/src/qpid/framing/AMQBody.h b/qpid/cpp/src/qpid/framing/AMQBody.h index f3bf65470c..73c462a427 100644 --- a/qpid/cpp/src/qpid/framing/AMQBody.h +++ b/qpid/cpp/src/qpid/framing/AMQBody.h @@ -22,6 +22,7 @@ * */ #include "qpid/framing/amqp_types.h" +#include "qpid/amqp_0_10/helpers.h" #include <ostream> @@ -60,6 +61,12 @@ class AMQBody 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 @@ enum BodyTypes { 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 diff --git a/qpid/cpp/src/qpid/framing/AMQCommandControlBody.h b/qpid/cpp/src/qpid/framing/AMQCommandControlBody.h new file mode 100644 index 0000000000..388fb48299 --- /dev/null +++ b/qpid/cpp/src/qpid/framing/AMQCommandControlBody.h @@ -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*/ diff --git a/qpid/cpp/src/qpid/framing/Buffer.h b/qpid/cpp/src/qpid/framing/Buffer.h index d0ca41f82b..9c0d403462 100644 --- a/qpid/cpp/src/qpid/framing/Buffer.h +++ b/qpid/cpp/src/qpid/framing/Buffer.h @@ -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 @@ class Buffer 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 @@ public: 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); |