From 3a7f44a61ce4cada2bfce431e405652744368ab3 Mon Sep 17 00:00:00 2001 From: Ted Ross Date: Thu, 4 Feb 2010 17:25:19 +0000 Subject: Added encode/decode/encodedSize methods for management objects. Made methods on generated code public. git-svn-id: https://svn.apache.org/repos/asf/qpid/trunk@906573 13f79535-47bb-0310-9956-ffa450edef68 --- .../cpp/include/qpid/management/ManagementObject.h | 17 +++++-- qpid/cpp/managementgen/qmfgen/management-types.xml | 58 +++++++++++----------- qpid/cpp/managementgen/qmfgen/schema.py | 17 +++++++ qpid/cpp/managementgen/qmfgen/templates/Class.cpp | 12 ++++- qpid/cpp/managementgen/qmfgen/templates/Class.h | 9 ++-- qpid/cpp/src/qpid/management/ManagementObject.cpp | 15 +++++- 6 files changed, 86 insertions(+), 42 deletions(-) (limited to 'qpid/cpp') diff --git a/qpid/cpp/include/qpid/management/ManagementObject.h b/qpid/cpp/include/qpid/management/ManagementObject.h index c4921269ba..6475ff5406 100644 --- a/qpid/cpp/include/qpid/management/ManagementObject.h +++ b/qpid/cpp/include/qpid/management/ManagementObject.h @@ -62,7 +62,8 @@ public: QPID_COMMON_EXTERN ObjectId(const std::string&); QPID_COMMON_EXTERN bool operator==(const ObjectId &other) const; QPID_COMMON_EXTERN bool operator<(const ObjectId &other) const; - QPID_COMMON_EXTERN void encode(framing::Buffer& buffer); + QPID_COMMON_EXTERN uint32_t encodedSize() const { return 16; }; + QPID_COMMON_EXTERN void encode(framing::Buffer& buffer) const; QPID_COMMON_EXTERN void decode(framing::Buffer& buffer); QPID_COMMON_EXTERN void setV2Key(const std::string& key) { v2Key = key; } QPID_COMMON_EXTERN const std::string& getV2Key() const { return v2Key; } @@ -119,19 +120,20 @@ protected: uint64_t destroyTime; uint64_t updateTime; ObjectId objectId; - bool configChanged; + mutable bool configChanged; bool instChanged; bool deleted; Manageable* coreObject; - sys::Mutex accessLock; + mutable sys::Mutex accessLock; uint32_t flags; static int nextThreadIndex; bool forcePublish; QPID_COMMON_EXTERN int getThreadIndex(); - QPID_COMMON_EXTERN void writeTimestamps(qpid::framing::Buffer& buf); + QPID_COMMON_EXTERN void writeTimestamps(qpid::framing::Buffer& buf) const; QPID_COMMON_EXTERN void readTimestamps(qpid::framing::Buffer& buf); + QPID_COMMON_EXTERN uint32_t writeTimestampsSize() const; public: QPID_COMMON_EXTERN static int maxThreads; @@ -146,7 +148,8 @@ protected: virtual writeSchemaCall_t getWriteSchemaCall() = 0; virtual void readProperties(qpid::framing::Buffer& buf) = 0; - virtual void writeProperties(qpid::framing::Buffer& buf) = 0; + virtual uint32_t writePropertiesSize() const = 0; + virtual void writeProperties(qpid::framing::Buffer& buf) const = 0; virtual void writeStatistics(qpid::framing::Buffer& buf, bool skipHeaders = false) = 0; virtual void doMethod(std::string& methodName, @@ -182,6 +185,10 @@ protected: return other.getClassName() == getClassName() && other.getPackageName() == getPackageName(); } + + QPID_COMMON_EXTERN void encode(qpid::framing::Buffer& buf) const { writeProperties(buf); } + QPID_COMMON_EXTERN void decode(qpid::framing::Buffer& buf) { readProperties(buf); } + QPID_COMMON_EXTERN uint32_t encodedSize() const { return writePropertiesSize(); } }; typedef std::map ManagementObjectMap; diff --git a/qpid/cpp/managementgen/qmfgen/management-types.xml b/qpid/cpp/managementgen/qmfgen/management-types.xml index f3894cc962..6dbabc90ff 100644 --- a/qpid/cpp/managementgen/qmfgen/management-types.xml +++ b/qpid/cpp/managementgen/qmfgen/management-types.xml @@ -19,38 +19,38 @@ under the License. --> - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + - - - - + + + + - - - - + + + + - - - + + + diff --git a/qpid/cpp/managementgen/qmfgen/schema.py b/qpid/cpp/managementgen/qmfgen/schema.py index 51466c7860..b3d0f751d2 100755 --- a/qpid/cpp/managementgen/qmfgen/schema.py +++ b/qpid/cpp/managementgen/qmfgen/schema.py @@ -59,6 +59,7 @@ class SchemaType: self.decode = None self.style = "normal" self.stream = "#" + self.size = "1" self.accessor = None self.init = "0" self.perThread = False @@ -89,6 +90,9 @@ class SchemaType: elif key == 'stream': self.stream = val + elif key == 'size': + self.size = val + elif key == 'accessor': self.accessor = val @@ -388,6 +392,15 @@ class SchemaProperty: stream.write (" ft.setString (DESC, \"" + self.desc + "\");\n") stream.write (" buf.put (ft);\n\n") + def genSize (self, stream): + indent = " " + if self.isOptional: + stream.write(" if (presenceMask[presenceByte_%s] & presenceMask_%s) {\n" % (self.name, self.name)) + indent = " " + stream.write("%ssize += %s; // %s\n" % (indent, self.type.type.size.replace("#", self.name), self.name)) + if self.isOptional: + stream.write(" }\n") + def genRead (self, stream): indent = " " if self.isOptional: @@ -1211,6 +1224,10 @@ class SchemaClass: if inst.type.type.perThread: inst.genAssign (stream) + def genSizeProperties (self, stream, variables): + for prop in self.properties: + prop.genSize (stream) + def genReadProperties (self, stream, variables): for prop in self.properties: prop.genRead (stream) diff --git a/qpid/cpp/managementgen/qmfgen/templates/Class.cpp b/qpid/cpp/managementgen/qmfgen/templates/Class.cpp index 8312f35c64..e6362758ba 100644 --- a/qpid/cpp/managementgen/qmfgen/templates/Class.cpp +++ b/qpid/cpp/managementgen/qmfgen/templates/Class.cpp @@ -124,6 +124,16 @@ void /*MGEN:Class.NameCap*/::aggregatePerThreadStats(struct PerThreadStats* tota } /*MGEN:ENDIF*/ +uint32_t /*MGEN:Class.NameCap*/::writePropertiesSize() const +{ + uint32_t size = writeTimestampsSize(); +/*MGEN:IF(Class.ExistOptionals)*/ + size += /*MGEN:Class.PresenceMaskBytes*/; +/*MGEN:ENDIF*/ +/*MGEN:Class.SizeProperties*/ + return size; +} + void /*MGEN:Class.NameCap*/::readProperties (Buffer& buf) { ::qpid::sys::Mutex::ScopedLock mutex(accessLock); @@ -135,7 +145,7 @@ void /*MGEN:Class.NameCap*/::readProperties (Buffer& buf) /*MGEN:Class.ReadProperties*/ } -void /*MGEN:Class.NameCap*/::writeProperties (Buffer& buf) +void /*MGEN:Class.NameCap*/::writeProperties (Buffer& buf) const { ::qpid::sys::Mutex::ScopedLock mutex(accessLock); configChanged = false; diff --git a/qpid/cpp/managementgen/qmfgen/templates/Class.h b/qpid/cpp/managementgen/qmfgen/templates/Class.h index 298f339381..8efacd650f 100644 --- a/qpid/cpp/managementgen/qmfgen/templates/Class.h +++ b/qpid/cpp/managementgen/qmfgen/templates/Class.h @@ -73,12 +73,12 @@ class /*MGEN:Class.NameCap*/ : public ::qpid::management::ManagementObject void aggregatePerThreadStats(struct PerThreadStats*); /*MGEN:ENDIF*/ - // Private Methods + public: static void writeSchema(::qpid::framing::Buffer& buf); + uint32_t writePropertiesSize() const; void readProperties(::qpid::framing::Buffer& buf); - void writeProperties(::qpid::framing::Buffer& buf); - void writeStatistics(::qpid::framing::Buffer& buf, - bool skipHeaders = false); + void writeProperties(::qpid::framing::Buffer& buf) const; + void writeStatistics(::qpid::framing::Buffer& buf, bool skipHeaders = false); void doMethod(std::string& methodName, ::qpid::framing::Buffer& inBuf, ::qpid::framing::Buffer& outBuf); @@ -89,7 +89,6 @@ class /*MGEN:Class.NameCap*/ : public ::qpid::management::ManagementObject bool getInstChanged() { return false; } bool hasInst() { return false; } /*MGEN:ENDIF*/ - public: /*MGEN:Class.NameCap*/(::qpid::management::ManagementAgent* agent, ::qpid::management::Manageable* coreObject/*MGEN:Class.ParentArg*//*MGEN:Class.ConstructorArgs*/); diff --git a/qpid/cpp/src/qpid/management/ManagementObject.cpp b/qpid/cpp/src/qpid/management/ManagementObject.cpp index 6cbe386517..4ac6613419 100644 --- a/qpid/cpp/src/qpid/management/ManagementObject.cpp +++ b/qpid/cpp/src/qpid/management/ManagementObject.cpp @@ -121,7 +121,7 @@ bool ObjectId::operator<(const ObjectId &other) const return (first < otherFirst) || ((first == otherFirst) && (second < other.second)); } -void ObjectId::encode(framing::Buffer& buffer) +void ObjectId::encode(framing::Buffer& buffer) const { if (agent == 0) buffer.putLongLong(first); @@ -158,7 +158,7 @@ std::ostream& operator<<(std::ostream& out, const ObjectId& i) int ManagementObject::maxThreads = 1; int ManagementObject::nextThreadIndex = 0; -void ManagementObject::writeTimestamps (framing::Buffer& buf) +void ManagementObject::writeTimestamps (framing::Buffer& buf) const { buf.putShortString (getPackageName ()); buf.putShortString (getClassName ()); @@ -184,6 +184,17 @@ void ManagementObject::readTimestamps (framing::Buffer& buf) unusedObjectId.decode(buf); } +uint32_t ManagementObject::writeTimestampsSize() const +{ + return 1 + getPackageName().length() + // str8 + 1 + getClassName().length() + // str8 + 16 + // bin128 + 8 + // uint64 + 8 + // uint64 + 8 + // uint64 + objectId.encodedSize(); // objectId +} + void ManagementObject::setReference(ObjectId) {} int ManagementObject::getThreadIndex() { -- cgit v1.2.1