diff options
| author | Ted Ross <tross@apache.org> | 2010-04-09 03:53:30 +0000 |
|---|---|---|
| committer | Ted Ross <tross@apache.org> | 2010-04-09 03:53:30 +0000 |
| commit | 5f4ccf5da76ae6ebfdd3252ed6f865e0a72fd745 (patch) | |
| tree | c9701ca9680b2effeb5591e346cda493313959ca /qpid/cpp | |
| parent | d300d4b595a37f25905313d99b86d7fdc94db0f8 (diff) | |
| download | qpid-python-5f4ccf5da76ae6ebfdd3252ed6f865e0a72fd745.tar.gz | |
QPID-2489 - Remove references to boost:: and qpid::framing:: from QMF-generated cpp files
Added a wrapper class for framing::Buffer in the qpid::management namespace. This wrapper class
has no reference to framing or boost and is now used in the generated C++ code to encode
QMFv1 content.
git-svn-id: https://svn.apache.org/repos/asf/qpid/trunk@932236 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'qpid/cpp')
| -rw-r--r-- | qpid/cpp/include/qpid/amqp_0_10/Codecs.h | 2 | ||||
| -rw-r--r-- | qpid/cpp/include/qpid/framing/Buffer.h | 1 | ||||
| -rw-r--r-- | qpid/cpp/include/qpid/management/Buffer.h | 106 | ||||
| -rw-r--r-- | qpid/cpp/managementgen/qmfgen/management-types.xml | 29 | ||||
| -rwxr-xr-x | qpid/cpp/managementgen/qmfgen/schema.py | 62 | ||||
| -rw-r--r-- | qpid/cpp/managementgen/qmfgen/templates/Args.h | 2 | ||||
| -rw-r--r-- | qpid/cpp/managementgen/qmfgen/templates/Class.cpp | 17 | ||||
| -rw-r--r-- | qpid/cpp/managementgen/qmfgen/templates/Event.cpp | 11 | ||||
| -rw-r--r-- | qpid/cpp/src/Makefile.am | 2 | ||||
| -rw-r--r-- | qpid/cpp/src/qpid/amqp_0_10/Codecs.cpp | 14 | ||||
| -rw-r--r-- | qpid/cpp/src/qpid/management/Buffer.cpp | 103 |
11 files changed, 290 insertions, 59 deletions
diff --git a/qpid/cpp/include/qpid/amqp_0_10/Codecs.h b/qpid/cpp/include/qpid/amqp_0_10/Codecs.h index 62370a0e5e..08275402fc 100644 --- a/qpid/cpp/include/qpid/amqp_0_10/Codecs.h +++ b/qpid/cpp/include/qpid/amqp_0_10/Codecs.h @@ -40,6 +40,7 @@ class QPID_COMMON_EXTERN MapCodec typedef qpid::types::Variant::Map ObjectType; static void encode(const ObjectType&, std::string&); static void decode(const std::string&, ObjectType&); + static size_t encodedSize(const ObjectType&); static const std::string contentType; private: }; @@ -54,6 +55,7 @@ class QPID_COMMON_EXTERN ListCodec typedef qpid::types::Variant::List ObjectType; static void encode(const ObjectType&, std::string&); static void decode(const std::string&, ObjectType&); + static size_t encodedSize(const ObjectType&); static const std::string contentType; private: }; diff --git a/qpid/cpp/include/qpid/framing/Buffer.h b/qpid/cpp/include/qpid/framing/Buffer.h index 50cc6fefe4..04583433c5 100644 --- a/qpid/cpp/include/qpid/framing/Buffer.h +++ b/qpid/cpp/include/qpid/framing/Buffer.h @@ -75,6 +75,7 @@ class Buffer QPID_COMMON_EXTERN uint32_t available() { return size - position; } QPID_COMMON_EXTERN uint32_t getSize() { return size; } QPID_COMMON_EXTERN uint32_t getPosition() { return position; } + QPID_COMMON_EXTERN void setPosition(uint32_t p) { position = p; } QPID_COMMON_EXTERN Iterator getIterator() { return Iterator(*this); } QPID_COMMON_EXTERN char* getPointer() { return data; } diff --git a/qpid/cpp/include/qpid/management/Buffer.h b/qpid/cpp/include/qpid/management/Buffer.h new file mode 100644 index 0000000000..81710171f5 --- /dev/null +++ b/qpid/cpp/include/qpid/management/Buffer.h @@ -0,0 +1,106 @@ +#ifndef _Management_Buffer_ +#define _Management_Buffer_ +/* + * 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/Exception.h" +#include "qpid/CommonImportExport.h" +#include "qpid/types/Variant.h" +#include <string> + +namespace qpid { +namespace framing { + class Buffer; +} + +namespace management { + +struct OutOfBounds : qpid::Exception { + OutOfBounds() : qpid::Exception(std::string("Out of Bounds")) {} +}; + + +/** + * This class is a wrapper around qpid::framing::Buffer that does not include any dependencies + * from boost or from qpid::framing. + */ +class Buffer +{ +public: + QPID_COMMON_EXTERN Buffer(char* data=0, uint32_t size=0); + QPID_COMMON_EXTERN ~Buffer(); + + QPID_COMMON_EXTERN void record(); + QPID_COMMON_EXTERN void restore(bool reRecord = false); + QPID_COMMON_EXTERN void reset(); + + QPID_COMMON_EXTERN uint32_t available(); + QPID_COMMON_EXTERN uint32_t getSize(); + QPID_COMMON_EXTERN uint32_t getPosition(); + QPID_COMMON_EXTERN char* getPointer(); + + QPID_COMMON_EXTERN void putOctet(uint8_t i); + QPID_COMMON_EXTERN void putShort(uint16_t i); + QPID_COMMON_EXTERN void putLong(uint32_t i); + QPID_COMMON_EXTERN void putLongLong(uint64_t i); + QPID_COMMON_EXTERN void putInt8(int8_t i); + QPID_COMMON_EXTERN void putInt16(int16_t i); + QPID_COMMON_EXTERN void putInt32(int32_t i); + QPID_COMMON_EXTERN void putInt64(int64_t i); + QPID_COMMON_EXTERN void putFloat(float f); + QPID_COMMON_EXTERN void putDouble(double f); + QPID_COMMON_EXTERN void putBin128(const uint8_t* b); + + QPID_COMMON_EXTERN uint8_t getOctet(); + QPID_COMMON_EXTERN uint16_t getShort(); + QPID_COMMON_EXTERN uint32_t getLong(); + QPID_COMMON_EXTERN uint64_t getLongLong(); + QPID_COMMON_EXTERN int8_t getInt8(); + QPID_COMMON_EXTERN int16_t getInt16(); + QPID_COMMON_EXTERN int32_t getInt32(); + QPID_COMMON_EXTERN int64_t getInt64(); + QPID_COMMON_EXTERN float getFloat(); + QPID_COMMON_EXTERN double getDouble(); + + QPID_COMMON_EXTERN void putShortString(const std::string& s); + QPID_COMMON_EXTERN void putMediumString(const std::string& s); + QPID_COMMON_EXTERN void putLongString(const std::string& s); + QPID_COMMON_EXTERN void getShortString(std::string& s); + QPID_COMMON_EXTERN void getMediumString(std::string& s); + QPID_COMMON_EXTERN void getLongString(std::string& s); + QPID_COMMON_EXTERN void getBin128(uint8_t* b); + + QPID_COMMON_EXTERN void putMap(const types::Variant::Map& map); + QPID_COMMON_EXTERN void putList(const types::Variant::List& list); + QPID_COMMON_EXTERN void getMap(types::Variant::Map& map); + QPID_COMMON_EXTERN void getList(types::Variant::List& list); + + QPID_COMMON_EXTERN void putRawData(const std::string& s); + QPID_COMMON_EXTERN void getRawData(std::string& s, uint32_t size); + + QPID_COMMON_EXTERN void putRawData(const uint8_t* data, size_t size); + QPID_COMMON_EXTERN void getRawData(uint8_t* data, size_t size); + +private: + framing::Buffer* impl; +}; + +}} // namespace qpid::management + +#endif diff --git a/qpid/cpp/managementgen/qmfgen/management-types.xml b/qpid/cpp/managementgen/qmfgen/management-types.xml index 857f8af212..61c91fed2d 100644 --- a/qpid/cpp/managementgen/qmfgen/management-types.xml +++ b/qpid/cpp/managementgen/qmfgen/management-types.xml @@ -24,9 +24,9 @@ --> <type name="objId" base="REF" cpp="::qpid::management::ObjectId" - encode="{std::string _s; #.encode(_s); @.putRawData(_s);}" - decode="{std::string _s; @.getRawData(_s, #.encodedSize()); #.decode(_s);}" -stream="#.getV2Key()" size="16" accessor="direct" init="::qpid::management::ObjectId()" byRef="y"/> + encode="{std::string _s; #.encode(_s); @.putRawData(_s);}" + decode="{std::string _s; @.getRawData(_s, #.encodedSize()); #.decode(_s);}" + stream="#.getV2Key()" size="16" accessor="direct" init="::qpid::management::ObjectId()" byRef="y"/> <type name="uint8" base="U8" cpp="uint8_t" encode="@.putOctet(#)" decode="# = @.getOctet()" stream="#" size="1" accessor="direct" init="0"/> <type name="uint16" base="U16" cpp="uint16_t" encode="@.putShort(#)" decode="# = @.getShort()" stream="#" size="2" accessor="direct" init="0"/> <type name="uint32" base="U32" cpp="uint32_t" encode="@.putLong(#)" decode="# = @.getLong()" stream="#" size="4" accessor="direct" init="0"/> @@ -43,18 +43,21 @@ stream="#.getV2Key()" size="16" accessor="direct" init="::qpid::management::Obje <type name="float" base="FLOAT" cpp="float" encode="@.putFloat(#)" decode="# = @.getFloat()" stream="#" size="4" accessor="direct" init="0."/> <type name="double" base="DOUBLE" cpp="double" encode="@.putDouble(#)" decode="# = @.getDouble()" stream="#" size="8" accessor="direct" init="0."/> <type name="uuid" base="UUID" cpp="::qpid::types::Uuid" - encode="{::qpid::framing::Uuid _u(#.data()); _u.encode(@); }" - decode="{::qpid::framing::Uuid _u; _u.decode(@); # = ::qpid::types::Uuid(_u.data());}" - stream="#" size="16" accessor="direct" init="::qpid::types::Uuid()" byRef="y" unmap="(#).asUuid().data()" map="::qpid::types::Uuid((#).data())" /> + encode="@.putRawData(#.data(), 16)" + decode="{ unsigned char d[16]; @.getRawData(d, 16); # = ::qpid::types::Uuid(d); }" + stream="#" size="16" accessor="direct" init="::qpid::types::Uuid()" byRef="y" + unmap="(#).asUuid().data()" + map="::qpid::types::Uuid((#).data())" /> <type name="map" base="FTABLE" cpp="::qpid::types::Variant::Map" - encode="{::qpid::framing::FieldTable _f = ManagementAgent::fromMap(#); _f.encode(@);}" - decode="{::qpid::framing::FieldTable _f; _f.decode(@); # = ManagementAgent::toMap(_f);}" - size="::qpid::framing::FieldTable(ManagementAgent::fromMap(#)).encodedSize()" -stream="#" accessor="direct" init="::qpid::types::Variant::Map()" byRef="y" unmap="::qpid::types::Variant::Map(); assert(false); /*TBD*/"/> + encode="@.putMap(#)" + decode="@.getMap(#)" + size="::qpid::amqp_0_10::MapCodec::encodedSize(#)" + stream="#" accessor="direct" init="::qpid::types::Variant::Map()" byRef="y" unmap="::qpid::types::Variant::Map(); assert(false); /*TBD*/"/> <type name="list" base="LIST" cpp="::qpid::types::Variant::List" - encode="{::qpid::framing::List _l = ManagementAgent::fromList(#); _l.encode(@);}" - decode="{::qpid::framing::List _l; _l.decode(@); # = ManagementAgent::toList(_l);}" -stream="#" size="#.encodedSize()" accessor="direct" init="::qpid::types::Variant::List()" byRef="y" unmap="::qpid::types::Variant::List(); assert(false); /*TBD*/"/> + encode="@.putList(#)" + decode="@.getList(#)" + size="::qpid::amqp_0_10::ListCodec::encodedSize(#)" + stream="#" accessor="direct" init="::qpid::types::Variant::List()" byRef="y" unmap="::qpid::types::Variant::List(); assert(false); /*TBD*/"/> <type name="hilo8" base="U8" cpp="uint8_t" encode="@.putOctet(#)" decode="# = @.getOctet()" style="wm" stream="#" size="1" accessor="counter" init="0"/> <type name="hilo16" base="U16" cpp="uint16_t" encode="@.putShort(#)" decode="# = @.getShort()" style="wm" stream="#" size="2" accessor="counter" init="0"/> diff --git a/qpid/cpp/managementgen/qmfgen/schema.py b/qpid/cpp/managementgen/qmfgen/schema.py index c1bb507d84..1206b0082d 100755 --- a/qpid/cpp/managementgen/qmfgen/schema.py +++ b/qpid/cpp/managementgen/qmfgen/schema.py @@ -425,22 +425,22 @@ class SchemaProperty: def genSchema (self, stream): stream.write (" ft.clear();\n") - stream.write (" ft.setString (NAME, \"" + self.name + "\");\n") - stream.write (" ft.setInt (TYPE, TYPE_" + self.type.type.base +");\n") - stream.write (" ft.setInt (ACCESS, ACCESS_" + self.access + ");\n") - stream.write (" ft.setInt (IS_INDEX, " + str (self.isIndex) + ");\n") - stream.write (" ft.setInt (IS_OPTIONAL, " + str (self.isOptional) + ");\n") + stream.write (" ft[NAME] = \"" + self.name + "\";\n") + stream.write (" ft[TYPE] = TYPE_" + self.type.type.base +";\n") + stream.write (" ft[ACCESS] = ACCESS_" + self.access + ";\n") + stream.write (" ft[IS_INDEX] = " + str (self.isIndex) + ";\n") + stream.write (" ft[IS_OPTIONAL] = " + str (self.isOptional) + ";\n") if self.unit != None: - stream.write (" ft.setString (UNIT, \"" + self.unit + "\");\n") + stream.write (" ft[UNIT] = \"" + self.unit + "\";\n") if self.min != None: - stream.write (" ft.setInt (MIN, " + self.min + ");\n") + stream.write (" ft[MIN] = " + self.min + ";\n") if self.max != None: - stream.write (" ft.setInt (MAX, " + self.max + ");\n") + stream.write (" ft[MAX] = " + self.max + ";\n") if self.maxLen != None: - stream.write (" ft.setInt (MAXLEN, " + self.maxLen + ");\n") + stream.write (" ft[MAXLEN] = " + self.maxLen + ";\n") if self.desc != None: - stream.write (" ft.setString (DESC, \"" + self.desc + "\");\n") - stream.write (" buf.put (ft);\n\n") + stream.write (" ft[DESC] = \"" + self.desc + "\";\n") + stream.write (" buf.putMap(ft);\n\n") def genSchemaMap(self, stream): @@ -594,13 +594,13 @@ class SchemaStatistic: def genSchemaText (self, stream, name, desc): stream.write (" ft.clear();\n") - stream.write (" ft.setString (NAME, \"" + name + "\");\n") - stream.write (" ft.setInt (TYPE, TYPE_" + self.type.type.base +");\n") + stream.write (" ft[NAME] = \"" + name + "\";\n") + stream.write (" ft[TYPE] = TYPE_" + self.type.type.base +";\n") if self.unit != None: - stream.write (" ft.setString (UNIT, \"" + self.unit + "\");\n") + stream.write (" ft[UNIT] = \"" + self.unit + "\";\n") if desc != None: - stream.write (" ft.setString (DESC, \"" + desc + "\");\n") - stream.write (" buf.put (ft);\n\n") + stream.write (" ft[DESC] = \"" + desc + "\";\n") + stream.write (" buf.putMap(ft);\n\n") def genSchemaTextMap(self, stream, name, desc): stream.write (" {\n") @@ -782,24 +782,24 @@ class SchemaArg: def genSchema (self, stream, event=False): stream.write (" ft.clear();\n") - stream.write (" ft.setString (NAME, \"" + self.name + "\");\n") - stream.write (" ft.setInt (TYPE, TYPE_" + self.type.type.base +");\n") + stream.write (" ft[NAME] = \"" + self.name + "\";\n") + stream.write (" ft[TYPE] = TYPE_" + self.type.type.base +";\n") if (not event): - stream.write (" ft.setString (DIR, \"" + self.dir + "\");\n") + stream.write (" ft[DIR] = \"" + self.dir + "\";\n") if self.unit != None: - stream.write (" ft.setString (UNIT, \"" + self.unit + "\");\n") + stream.write (" ft[UNIT] = \"" + self.unit + "\";\n") if not event: if self.min != None: - stream.write (" ft.setInt (MIN, " + self.min + ");\n") + stream.write (" ft[MIN] = " + self.min + ";\n") if self.max != None: - stream.write (" ft.setInt (MAX, " + self.max + ");\n") + stream.write (" ft[MAX] = " + self.max + ";\n") if self.maxLen != None: - stream.write (" ft.setInt (MAXLEN, " + self.maxLen + ");\n") + stream.write (" ft[MAXLEN] = " + self.maxLen + ";\n") if self.default != None: - stream.write (" ft.setString (DEFAULT, \"" + self.default + "\");\n") + stream.write (" ft[DEFAULT] = \"" + self.default + "\";\n") if self.desc != None: - stream.write (" ft.setString (DESC, \"" + self.desc + "\");\n") - stream.write (" buf.put (ft);\n\n") + stream.write (" ft[DESC] = \"" + self.desc + "\";\n") + stream.write (" buf.putMap(ft);\n\n") def genSchemaMap (self, stream, event=False): stream.write (" {\n") @@ -896,11 +896,11 @@ class SchemaMethod: def genSchema (self, stream, variables): stream.write (" ft.clear();\n") - stream.write (" ft.setString (NAME, \"" + self.name + "\");\n") - stream.write (" ft.setInt (ARGCOUNT, " + str (len (self.args)) + ");\n") + stream.write (" ft[NAME] = \"" + self.name + "\";\n") + stream.write (" ft[ARGCOUNT] = " + str (len (self.args)) + ";\n") if self.desc != None: - stream.write (" ft.setString (DESC, \"" + self.desc + "\");\n") - stream.write (" buf.put (ft);\n\n") + stream.write (" ft[DESC] = \"" + self.desc + "\";\n") + stream.write (" buf.putMap(ft);\n\n") for arg in self.args: arg.genSchema (stream) @@ -1349,7 +1349,7 @@ class SchemaClass: stream.write("\n") stream.write(" char *_tmpBuf = new char[inStr.length()];\n") stream.write(" memcpy(_tmpBuf, inStr.data(), inStr.length());\n") - stream.write(" ::qpid::framing::Buffer inBuf(_tmpBuf, inStr.length());\n") + stream.write(" ::qpid::management::Buffer inBuf(_tmpBuf, inStr.length());\n") for method in self.methods: stream.write ("\n if (methodName == \"" + method.getName () + "\") {\n") diff --git a/qpid/cpp/managementgen/qmfgen/templates/Args.h b/qpid/cpp/managementgen/qmfgen/templates/Args.h index 20681ab477..89a5bec9b9 100644 --- a/qpid/cpp/managementgen/qmfgen/templates/Args.h +++ b/qpid/cpp/managementgen/qmfgen/templates/Args.h @@ -24,8 +24,6 @@ /*MGEN:Root.Disclaimer*/ #include "qpid/management/Args.h" -//#include "qpid/framing/FieldTable.h" -//#include "qpid/framing/Uuid.h" #include <string> namespace qmf { diff --git a/qpid/cpp/managementgen/qmfgen/templates/Class.cpp b/qpid/cpp/managementgen/qmfgen/templates/Class.cpp index ed4e17720f..9a9af07b28 100644 --- a/qpid/cpp/managementgen/qmfgen/templates/Class.cpp +++ b/qpid/cpp/managementgen/qmfgen/templates/Class.cpp @@ -22,8 +22,9 @@ #include "qpid/log/Statement.h" #include "qpid/management/Manageable.h" -#include "qpid/framing/FieldTable.h" -#include "qpid/framing/Buffer.h" +#include "qpid/management/Buffer.h" +#include "qpid/types/Variant.h" +#include "qpid/amqp_0_10/Codecs.h" #include "qpid//*MGEN:Class.AgentHeaderLocation*//ManagementAgent.h" #include "/*MGEN:Class.NameCap*/.h" /*MGEN:Class.MethodArgIncludes*/ @@ -94,8 +95,8 @@ void /*MGEN:Class.NameCap*/::writeSchema (std::string& schema) { const int _bufSize=65536; char _msgChars[_bufSize]; - ::qpid::framing::Buffer buf(_msgChars, _bufSize); - ::qpid::framing::FieldTable ft; + ::qpid::management::Buffer buf(_msgChars, _bufSize); + ::qpid::types::Variant::Map ft; // Schema class header: buf.putOctet (CLASS_KIND_TABLE); @@ -147,7 +148,7 @@ void /*MGEN:Class.NameCap*/::readProperties (const std::string& _sBuf) { char *_tmpBuf = new char[_sBuf.length()]; memcpy(_tmpBuf, _sBuf.data(), _sBuf.length()); - ::qpid::framing::Buffer buf(_tmpBuf, _sBuf.length()); + ::qpid::management::Buffer buf(_tmpBuf, _sBuf.length()); ::qpid::sys::Mutex::ScopedLock mutex(accessLock); { @@ -169,7 +170,7 @@ void /*MGEN:Class.NameCap*/::writeProperties (std::string& _sBuf) const { const int _bufSize=65536; char _msgChars[_bufSize]; - ::qpid::framing::Buffer buf(_msgChars, _bufSize); + ::qpid::management::Buffer buf(_msgChars, _bufSize); ::qpid::sys::Mutex::ScopedLock mutex(accessLock); configChanged = false; @@ -197,7 +198,7 @@ void /*MGEN:Class.NameCap*/::writeStatistics (std::string& _sBuf, bool skipHeade { const int _bufSize=65536; char _msgChars[_bufSize]; - ::qpid::framing::Buffer buf(_msgChars, _bufSize); + ::qpid::management::Buffer buf(_msgChars, _bufSize); ::qpid::sys::Mutex::ScopedLock mutex(accessLock); instChanged = false; @@ -248,7 +249,7 @@ void /*MGEN:Class.NameCap*/::doMethod (/*MGEN:Class.DoMethodArgs*/) const int _bufSize=65536; char _msgChars[_bufSize]; - ::qpid::framing::Buffer outBuf(_msgChars, _bufSize); + ::qpid::management::Buffer outBuf(_msgChars, _bufSize); /*MGEN:Class.MethodHandlers*/ diff --git a/qpid/cpp/managementgen/qmfgen/templates/Event.cpp b/qpid/cpp/managementgen/qmfgen/templates/Event.cpp index d760fd9014..94de331611 100644 --- a/qpid/cpp/managementgen/qmfgen/templates/Event.cpp +++ b/qpid/cpp/managementgen/qmfgen/templates/Event.cpp @@ -22,8 +22,9 @@ #include "qpid/log/Statement.h" #include "qpid/management/Manageable.h" -#include "qpid/framing/FieldTable.h" -#include "qpid/framing/Buffer.h" +#include "qpid/management/Buffer.h" +#include "qpid/types/Variant.h" +#include "qpid/amqp_0_10/Codecs.h" #include "qpid//*MGEN:Event.AgentHeaderLocation*//ManagementAgent.h" #include "Event/*MGEN:Event.NameCap*/.h" @@ -60,8 +61,8 @@ void Event/*MGEN:Event.NameCap*/::writeSchema (std::string& schema) { const int _bufSize = 65536; char _msgChars[_bufSize]; - ::qpid::framing::Buffer buf(_msgChars, _bufSize); - ::qpid::framing::FieldTable ft; + ::qpid::management::Buffer buf(_msgChars, _bufSize); + ::qpid::types::Variant::Map ft; // Schema class header: buf.putOctet (CLASS_KIND_EVENT); @@ -83,7 +84,7 @@ void Event/*MGEN:Event.NameCap*/::encode(std::string& _sBuf) const { const int _bufSize=65536; char _msgChars[_bufSize]; - ::qpid::framing::Buffer buf(_msgChars, _bufSize); + ::qpid::management::Buffer buf(_msgChars, _bufSize); /*MGEN:Event.ArgEncodes*/ diff --git a/qpid/cpp/src/Makefile.am b/qpid/cpp/src/Makefile.am index e0b6b48cf2..427148dfbf 100644 --- a/qpid/cpp/src/Makefile.am +++ b/qpid/cpp/src/Makefile.am @@ -420,6 +420,7 @@ libqpidcommon_la_SOURCES += \ qpid/log/OstreamOutput.h \ qpid/log/Selector.cpp \ qpid/log/Statement.cpp \ + qpid/management/Buffer.cpp \ qpid/management/Manageable.cpp \ qpid/management/ManagementObject.cpp \ qpid/memory.h \ @@ -799,6 +800,7 @@ nobase_include_HEADERS += \ ../include/qpid/log/SinkOptions.h \ ../include/qpid/log/Statement.h \ ../include/qpid/management/Args.h \ + ../include/qpid/management/Buffer.h \ ../include/qpid/management/Manageable.h \ ../include/qpid/management/ManagementEvent.h \ ../include/qpid/management/ManagementObject.h \ diff --git a/qpid/cpp/src/qpid/amqp_0_10/Codecs.cpp b/qpid/cpp/src/qpid/amqp_0_10/Codecs.cpp index 6325f9f664..abe6b2c7da 100644 --- a/qpid/cpp/src/qpid/amqp_0_10/Codecs.cpp +++ b/qpid/cpp/src/qpid/amqp_0_10/Codecs.cpp @@ -301,6 +301,13 @@ void MapCodec::decode(const std::string& data, Variant::Map& value) _decode<FieldTable>(data, value, &toVariantMapEntry); } +size_t MapCodec::encodedSize(const Variant::Map& value) +{ + std::string encoded; + encode(value, encoded); + return encoded.size(); +} + void ListCodec::encode(const Variant::List& value, std::string& data) { _encode<List>(value, data, &toFieldValue); @@ -311,6 +318,13 @@ void ListCodec::decode(const std::string& data, Variant::List& value) _decode<List>(data, value, &toVariant); } +size_t ListCodec::encodedSize(const Variant::List& value) +{ + std::string encoded; + encode(value, encoded); + return encoded.size(); +} + void translate(const Variant::Map& from, FieldTable& to) { convert(from, to, &toFieldTableEntry); diff --git a/qpid/cpp/src/qpid/management/Buffer.cpp b/qpid/cpp/src/qpid/management/Buffer.cpp new file mode 100644 index 0000000000..17facd37bb --- /dev/null +++ b/qpid/cpp/src/qpid/management/Buffer.cpp @@ -0,0 +1,103 @@ +/* + * 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/Buffer.h" +#include "qpid/framing/Buffer.h" +#include "qpid/amqp_0_10/Codecs.h" + +using namespace std; +using namespace qpid::management; + +Buffer::Buffer(char* data, uint32_t size) : impl(new framing::Buffer(data, size)) {} +Buffer::~Buffer() { delete impl; } +void Buffer::record() { impl->record(); } +void Buffer::restore(bool reRecord) { impl->restore(reRecord); } +void Buffer::reset() { impl->reset(); } +uint32_t Buffer::available() { return impl->available(); } +uint32_t Buffer::getSize() { return impl->getSize(); } +uint32_t Buffer::getPosition() { return impl->getPosition(); } +char* Buffer::getPointer() { return impl->getPointer(); } +void Buffer::putOctet(uint8_t i) { impl->putOctet(i); } +void Buffer::putShort(uint16_t i) { impl->putShort(i); } +void Buffer::putLong(uint32_t i) { impl->putLong(i); } +void Buffer::putLongLong(uint64_t i) { impl->putLongLong(i); } +void Buffer::putInt8(int8_t i) { impl->putInt8(i); } +void Buffer::putInt16(int16_t i) { impl->putInt16(i); } +void Buffer::putInt32(int32_t i) { impl->putInt32(i); } +void Buffer::putInt64(int64_t i) { impl->putInt64(i); } +void Buffer::putFloat(float i) { impl->putFloat(i); } +void Buffer::putDouble(double i) { impl->putDouble(i); } +void Buffer::putBin128(const uint8_t* i) { impl->putBin128(i); } +uint8_t Buffer::getOctet() { return impl->getOctet(); } +uint16_t Buffer::getShort() { return impl->getShort(); } +uint32_t Buffer::getLong() { return impl->getLong(); } +uint64_t Buffer::getLongLong() { return impl->getLongLong(); } +int8_t Buffer:: getInt8() { return impl-> getInt8(); } +int16_t Buffer::getInt16() { return impl->getInt16(); } +int32_t Buffer::getInt32() { return impl->getInt32(); } +int64_t Buffer::getInt64() { return impl->getInt64(); } +float Buffer::getFloat() { return impl->getFloat(); } +double Buffer::getDouble() { return impl->getDouble(); } +void Buffer::putShortString(const string& i) { impl->putShortString(i); } +void Buffer::putMediumString(const string& i) { impl->putMediumString(i); } +void Buffer::putLongString(const string& i) { impl->putLongString(i); } +void Buffer::getShortString(string& i) { impl->getShortString(i); } +void Buffer::getMediumString(string& i) { impl->getMediumString(i); } +void Buffer::getLongString(string& i) { impl->getLongString(i); } +void Buffer::getBin128(uint8_t* i) { impl->getBin128(i); } +void Buffer::putRawData(const string& i) { impl->putRawData(i); } +void Buffer::getRawData(string& s, uint32_t size) { impl->getRawData(s, size); } +void Buffer::putRawData(const uint8_t* data, size_t size) { impl->putRawData(data, size); } +void Buffer::getRawData(uint8_t* data, size_t size) { impl->getRawData(data, size); } + +void Buffer::putMap(const types::Variant::Map& i) +{ + string encoded; + amqp_0_10::MapCodec::encode(i, encoded); + impl->putRawData(encoded); +} + +void Buffer::putList(const types::Variant::List& i) +{ + string encoded; + amqp_0_10::ListCodec::encode(i, encoded); + impl->putRawData(encoded); +} + +void Buffer::getMap(types::Variant::Map& map) +{ + string encoded; + uint32_t saved = impl->getPosition(); + uint32_t length = impl->getLong(); + impl->setPosition(saved); + impl->getRawData(encoded, length + sizeof(uint32_t)); + amqp_0_10::MapCodec::decode(encoded, map); +} + +void Buffer::getList(types::Variant::List& list) +{ + string encoded; + uint32_t saved = impl->getPosition(); + uint32_t length = impl->getLong(); + impl->setPosition(saved); + impl->getRawData(encoded, length + sizeof(uint32_t)); + amqp_0_10::ListCodec::decode(encoded, list); +} + |
