diff options
| author | Ted Ross <tross@apache.org> | 2010-03-31 21:13:12 +0000 |
|---|---|---|
| committer | Ted Ross <tross@apache.org> | 2010-03-31 21:13:12 +0000 |
| commit | 2e29faa768283390452b7d432db28d43cd4a27aa (patch) | |
| tree | 521e9711b340a330408245ba699b35d12b36ce9c /cpp/managementgen | |
| parent | 5e50981ac8a35db09723ad19f5994703d00e10d9 (diff) | |
| download | qpid-python-2e29faa768283390452b7d432db28d43cd4a27aa.tar.gz | |
Merged the changes from the qmf-devel0.7a branch back to the trunk.
This is a checkpoint along the QMFv2 development path.
This update introduces portions of QMFv2 into the code:
- The C++ agent (qpid/agent) uses QMFv2 for data and method transfer
o The APIs no longer use qpid::framing::*
o Consequently, boost is no longer referenced from the API headers.
o Agents and Objects are now referenced by strings, not numbers.
o Schema transfer still uses the QMFv1 format.
- The broker-resident agent can use QMFv1 or QMFv2 based on the command line options.
It defaults to QMFv1 for compatibility.
- The pure-python QMF console (qmf.console) can concurrently interact with both
QMFv1 and QMFv2 agents.
git-svn-id: https://svn.apache.org/repos/asf/qpid/trunk/qpid@929716 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'cpp/managementgen')
| -rwxr-xr-x | cpp/managementgen/qmf-gen | 2 | ||||
| -rwxr-xr-x | cpp/managementgen/qmfgen/generate.py | 41 | ||||
| -rw-r--r-- | cpp/managementgen/qmfgen/management-types.xml | 28 | ||||
| -rwxr-xr-x | cpp/managementgen/qmfgen/schema.py | 314 | ||||
| -rw-r--r-- | cpp/managementgen/qmfgen/templates/Args.h | 4 | ||||
| -rw-r--r-- | cpp/managementgen/qmfgen/templates/Class.cpp | 158 | ||||
| -rw-r--r-- | cpp/managementgen/qmfgen/templates/Class.h | 30 | ||||
| -rw-r--r-- | cpp/managementgen/qmfgen/templates/Event.cpp | 34 | ||||
| -rw-r--r-- | cpp/managementgen/qmfgen/templates/Event.h | 9 |
9 files changed, 552 insertions, 68 deletions
diff --git a/cpp/managementgen/qmf-gen b/cpp/managementgen/qmf-gen index ebc07137ae..667aa1ba2d 100755 --- a/cpp/managementgen/qmf-gen +++ b/cpp/managementgen/qmf-gen @@ -62,8 +62,10 @@ if len(args) == 0: vargs = {} if opts.brokerplugin: vargs["agentHeaderDir"] = "management" + vargs["genQmfV1"] = True else: vargs["agentHeaderDir"] = "agent" + vargs["genQmfV1"] = None for schemafile in args: package = SchemaPackage(typefile, schemafile, opts) diff --git a/cpp/managementgen/qmfgen/generate.py b/cpp/managementgen/qmfgen/generate.py index 4052b8c853..8a00b69761 100755 --- a/cpp/managementgen/qmfgen/generate.py +++ b/cpp/managementgen/qmfgen/generate.py @@ -38,39 +38,43 @@ class Template: self.filename = filename self.handler = handler self.handler.initExpansion () - self.writing = True + self.writing = 0 # 0 => write output lines; >0 => recursive depth of conditional regions def expandLine (self, line, stream, object): cursor = 0 while 1: sub = line.find ("/*MGEN:", cursor) if sub == -1: - if self.writing: + if self.writing == 0: stream.write (line[cursor:len (line)]) return subend = line.find("*/", sub) - if self.writing: + if self.writing == 0: stream.write (line[cursor:sub]) cursor = subend + 2 tag = line[sub:subend] if tag[7:10] == "IF(": - close = tag.find(")") - if close == -1: - raise ValueError ("Missing ')' on condition") - cond = tag[10:close] - dotPos = cond.find (".") - if dotPos == -1: - raise ValueError ("Invalid condition tag: %s" % cond) - tagObject = cond[0:dotPos] - tagName = cond[dotPos + 1 : len(cond)] - if not self.handler.testCondition(object, tagObject, tagName): - self.writing = False + if self.writing == 0: + close = tag.find(")") + if close == -1: + raise ValueError ("Missing ')' on condition") + cond = tag[10:close] + dotPos = cond.find (".") + if dotPos == -1: + raise ValueError ("Invalid condition tag: %s" % cond) + tagObject = cond[0:dotPos] + tagName = cond[dotPos + 1 : len(cond)] + if not self.handler.testCondition(object, tagObject, tagName): + self.writing += 1 + else: + self.writing += 1 elif tag[7:12] == "ENDIF": - self.writing = True + if self.writing > 0: + self.writing -= 1 else: equalPos = tag.find ("=") @@ -80,12 +84,12 @@ class Template: raise ValueError ("Invalid tag: %s" % tag) tagObject = tag[7:dotPos] tagName = tag[dotPos + 1:len (tag)] - if self.writing: + if self.writing == 0: self.handler.substHandler (object, stream, tagObject, tagName) else: tagKey = tag[7:equalPos] tagVal = tag[equalPos + 1:len (tag)] - if self.writing: + if self.writing == 0: self.handler.setVariable (tagKey, tagVal) def expand (self, object): @@ -297,6 +301,9 @@ class Generator: self.packagelist.append(path) self.packagePath = self.normalize(self.dest + path) + def testGenQMFv1 (self, variables): + return variables["genQmfV1"] + def genDisclaimer (self, stream, variables): prefix = variables["commentPrefix"] stream.write (prefix + " This source file was created by a code generator.\n") diff --git a/cpp/managementgen/qmfgen/management-types.xml b/cpp/managementgen/qmfgen/management-types.xml index 6dbabc90ff..857f8af212 100644 --- a/cpp/managementgen/qmfgen/management-types.xml +++ b/cpp/managementgen/qmfgen/management-types.xml @@ -19,7 +19,14 @@ under the License. --> -<type name="objId" base="REF" cpp="::qpid::management::ObjectId" encode="#.encode(@)" decode="#.decode(@)" stream="#.getV2Key()" size="16" accessor="direct" init="::qpid::management::ObjectId()" byRef="y"/> +<!-- "unmap": cast to convert from Variant to native type constructor, + "map": cast to convert from native type to Variant constructor parameter +--> + +<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"/> <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"/> @@ -29,14 +36,25 @@ <type name="int32" base="S32" cpp="int32_t" encode="@.putInt32(#)" decode="# = @.getInt32()" stream="#" size="4" accessor="direct" init="0"/> <type name="int64" base="S64" cpp="int64_t" encode="@.putInt64(#)" decode="# = @.getInt64()" stream="#" size="8" accessor="direct" init="0"/> <type name="bool" base="BOOL" cpp="uint8_t" encode="@.putOctet(#?1:0)" decode="# = @.getOctet()==1" stream="#" size="1" accessor="direct" init="0"/> -<type name="sstr" base="SSTR" cpp="std::string" encode="@.putShortString(#)" decode="@.getShortString(#)" stream="#" size="(1 + #.length())" accessor="direct" init='""' byRef="y"/> -<type name="lstr" base="LSTR" cpp="std::string" encode="@.putMediumString(#)" decode="@.getMediumString(#)" stream="#" size="(2 + #.length())" accessor="direct" init='""' byRef="y"/> +<type name="sstr" base="SSTR" cpp="std::string" encode="@.putShortString(#)" decode="@.getShortString(#)" stream="#" size="(1 + #.length())" accessor="direct" init='""' byRef="y" unmap="(#).getString()"/> +<type name="lstr" base="LSTR" cpp="std::string" encode="@.putMediumString(#)" decode="@.getMediumString(#)" stream="#" size="(2 + #.length())" accessor="direct" init='""' byRef="y" unmap="(#).getString()"/> <type name="absTime" base="ABSTIME" cpp="int64_t" encode="@.putLongLong(#)" decode="# = @.getLongLong()" stream="#" size="8" accessor="direct" init="0"/> <type name="deltaTime" base="DELTATIME" cpp="uint64_t" encode="@.putLongLong(#)" decode="# = @.getLongLong()" stream="#" size="8" accessor="direct" init="0"/> <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::framing::Uuid" encode="#.encode(@)" decode="#.decode(@)" stream="#" size="16" accessor="direct" init="::qpid::framing::Uuid()" byRef="y"/> -<type name="map" base="FTABLE" cpp="::qpid::framing::FieldTable" encode="#.encode(@)" decode="#.decode(@)" stream="#" size="#.encodedSize()" accessor="direct" init="::qpid::framing::FieldTable()" byRef="y"/> +<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())" /> +<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*/"/> +<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*/"/> <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/cpp/managementgen/qmfgen/schema.py b/cpp/managementgen/qmfgen/schema.py index d80567687e..c1bb507d84 100755 --- a/cpp/managementgen/qmfgen/schema.py +++ b/cpp/managementgen/qmfgen/schema.py @@ -19,12 +19,18 @@ from xml.dom.minidom import parse, parseString, Node from cStringIO import StringIO -import md5 +#import md5 +try: + import hashlib + _md5Obj = hashlib.md5 +except ImportError: + import md5 + _md5Obj = md5.new class Hash: """ Manage the hash of an XML sub-tree """ def __init__(self, node): - self.md5Sum = md5.new() + self.md5Sum = _md5Obj() self._compute(node) def addSubHash(self, hash): @@ -64,6 +70,8 @@ class SchemaType: self.init = "0" self.perThread = False self.byRef = False + self.unmap = "#" + self.map = "#" attrs = node.attributes for idx in range (attrs.length): @@ -109,6 +117,12 @@ class SchemaType: raise ValueError ("Expected 'y' in byRef attribute") self.byRef = True + elif key == 'unmap': + self.unmap = val + + elif key == 'map': + self.map = val + else: raise ValueError ("Unknown attribute in type '%s'" % key) @@ -211,6 +225,17 @@ class SchemaType: def genRead (self, stream, varName, indent=" "): stream.write(indent + self.decode.replace("@", "buf").replace("#", varName) + ";\n") + def genUnmap (self, stream, varName, indent=" ", key=None, mapName="_map", + _optional=False): + if key is None: + key = varName + stream.write(indent + "if ((_i = " + mapName + ".find(\"" + key + "\")) != " + mapName + ".end()) {\n") + stream.write(indent + " " + varName + " = " + + self.unmap.replace("#", "_i->second") + ";\n") + if _optional: + stream.write(indent + " _found = true;\n") + stream.write(indent + "}\n") + def genWrite (self, stream, varName, indent=" "): if self.style != "mma": stream.write (indent + self.encode.replace ("@", "buf").replace ("#", varName) + ";\n") @@ -230,6 +255,31 @@ class SchemaType: .replace ("#", varName + "Count ? " + varName + "Total / " + varName + "Count : 0") + ";\n") + def genMap (self, stream, varName, indent=" ", key=None, mapName="_map"): + if key is None: + key = varName + if self.style != "mma": + var_cast = self.map.replace("#", varName) + stream.write(indent + mapName + "[\"" + key + "\"] = ::qpid::types::Variant(" + var_cast + ");\n") + if self.style == "wm": + var_cast_hi = self.map.replace("#", varName + "High") + var_cast_lo = self.map.replace("#", varName + "Low") + stream.write(indent + mapName + "[\"" + key + "High\"] = " + + "::qpid::types::Variant(" + var_cast_hi + ");\n") + stream.write(indent + mapName + "[\"" + key + "Low\"] = " + + "::qpid::types::Variant(" + var_cast_lo + ");\n") + if self.style == "mma": + var_cast = self.map.replace("#", varName + "Count") + stream.write(indent + mapName + "[\"" + key + "Count\"] = " + "::qpid::types::Variant(" + var_cast + ");\n") + var_cast = self.map.replace("#", varName + "Min") + stream.write(indent + mapName + "[\"" + key + "Min\"] = " + + "(" + varName + "Count ? ::qpid::types::Variant(" + var_cast + ") : ::qpid::types::Variant(0));\n") + var_cast = self.map.replace("#", varName + "Max") + stream.write(indent + mapName + "[\"" + key + "Max\"] = " + "::qpid::types::Variant(" + var_cast + ");\n") + + var_cast = self.map.replace("#", "(" + varName + "Total / " + varName + "Count)") + stream.write(indent + mapName + "[\"" + key + "Avg\"] = " + + "(" + varName + "Count ? ::qpid::types::Variant(" + var_cast + ") : ::qpid::types::Variant(0));\n") def getReadCode (self, varName, bufName): result = self.decode.replace ("@", bufName).replace ("#", varName) @@ -392,6 +442,29 @@ class SchemaProperty: stream.write (" ft.setString (DESC, \"" + self.desc + "\");\n") stream.write (" buf.put (ft);\n\n") + + def genSchemaMap(self, stream): + stream.write (" {\n") + stream.write (" ::qpid::types::Variant::Map _value;\n") + stream.write (" _value[TYPE] = TYPE_" + self.type.type.base +";\n") + stream.write (" _value[ACCESS] = ACCESS_" + self.access + ";\n") + stream.write (" _value[IS_INDEX] = " + str (self.isIndex) + ";\n") + stream.write (" _value[IS_OPTIONAL] = " + str (self.isOptional) + ";\n") + if self.unit != None: + stream.write (" _value[UNIT] = \"" + self.unit + "\";\n") + if self.min != None: + stream.write (" _value[MIN] = " + self.min + ";\n") + if self.max != None: + stream.write (" _value[MAX] = " + self.max + ";\n") + if self.maxLen != None: + stream.write (" _value[MAXLEN] = " + self.maxLen + ";\n") + if self.desc != None: + stream.write (" _value[DESC] = \"" + self.desc + "\";\n") + stream.write (" _props[\"" + self.name + "\"] = _value;\n") + stream.write (" }\n\n") + + + def genSize (self, stream): indent = " " if self.isOptional: @@ -419,6 +492,43 @@ class SchemaProperty: if self.isOptional: stream.write(" }\n") + def genUnmap (self, stream): + indent = " " + if self.isOptional: + stream.write(" _found = false;\n") + self.type.type.genUnmap (stream, self.name, indent, _optional=self.isOptional) + if self.isOptional: + stream.write(" if (_found) {\n") + stream.write(" presenceMask[presenceByte_%s] |= presenceMask_%s;\n" % + (self.name, self.name)) + stream.write(" }\n") + + def genMap (self, stream): + indent = " " + if self.isOptional: + stream.write(" if (presenceMask[presenceByte_%s] & presenceMask_%s) {\n" % (self.name, self.name)) + indent = " " + self.type.type.genMap (stream, self.name, indent) + if self.isOptional: + stream.write(" }\n") + + + def __repr__(self): + m = {} + m["name"] = self.name + m["type"] = self.type + m["ref"] = self.ref + m["access"] = self.access + m["isIndex"] = self.isIndex + m["isParentRef"] = self.isParentRef + m["isGeneralRef"] = self.isGeneralRef + m["isOptional"] = self.isOptional + m["unit"] = self.unit + m["min"] = self.min + m["max"] = self.max + m["maxLen"] = self.maxLen + m["desc"] = self.desc + return str(m) #===================================================================================== # @@ -492,6 +602,17 @@ class SchemaStatistic: stream.write (" ft.setString (DESC, \"" + desc + "\");\n") stream.write (" buf.put (ft);\n\n") + def genSchemaTextMap(self, stream, name, desc): + stream.write (" {\n") + stream.write (" ::qpid::types::Variant::Map _value;\n") + stream.write (" _value[TYPE] = TYPE_" + self.type.type.base +";\n") + if self.unit != None: + stream.write (" _value[UNIT] = \"" + self.unit + "\";\n") + if desc != None: + stream.write (" _value[DESC] = \"" + desc + "\";\n") + stream.write (" _stats[\"" + self.name + "\"] = _value;\n") + stream.write (" }\n\n") + def genSchema (self, stream): if self.type.type.style != "mma": self.genSchemaText (stream, self.name, self.desc) @@ -518,6 +639,32 @@ class SchemaStatistic: self.genSchemaText (stream, self.name + "Max", descMax) self.genSchemaText (stream, self.name + "Average", descAverage) + def genSchemaMap (self, stream): + if self.type.type.style != "mma": + self.genSchemaTextMap (stream, self.name, self.desc) + if self.type.type.style == "wm": + descHigh = self.desc + descLow = self.desc + if self.desc != None: + descHigh = descHigh + " (High)" + descLow = descLow + " (Low)" + self.genSchemaTextMap (stream, self.name + "High", descHigh) + self.genSchemaTextMap (stream, self.name + "Low", descLow) + if self.type.type.style == "mma": + descCount = self.desc + descMin = self.desc + descMax = self.desc + descAverage = self.desc + if self.desc != None: + descCount = descCount + " (Samples)" + descMin = descMin + " (Min)" + descMax = descMax + " (Max)" + descAverage = descAverage + " (Average)" + self.genSchemaTextMap (stream, self.name + "Samples", descCount) + self.genSchemaTextMap (stream, self.name + "Min", descMin) + self.genSchemaTextMap (stream, self.name + "Max", descMax) + self.genSchemaTextMap (stream, self.name + "Average", descAverage) + def genAssign (self, stream): if self.assign != None: if self.type.type.perThread: @@ -533,6 +680,12 @@ class SchemaStatistic: else: self.type.type.genWrite (stream, self.name) + def genMap (self, stream): + if self.type.type.perThread: + self.type.type.genMap(stream, "totals." + self.name, key=self.name) + else: + self.type.type.genMap(stream, self.name) + def genInitialize (self, stream, prefix="", indent=" "): val = self.type.type.init if self.type.type.style != "mma": @@ -648,6 +801,30 @@ class SchemaArg: stream.write (" ft.setString (DESC, \"" + self.desc + "\");\n") stream.write (" buf.put (ft);\n\n") + def genSchemaMap (self, stream, event=False): + stream.write (" {\n") + stream.write (" ::qpid::types::Variant::Map _avalue;\n") + stream.write (" _avalue[TYPE] = TYPE_" + self.type.type.base +";\n") + if (not event): + stream.write (" _avalue[DIR] = \"" + self.dir + "\";\n") + if self.unit != None: + stream.write (" _avalue[UNIT] = \"" + self.unit + "\";\n") + if not event: + if self.min != None: + stream.write (" _avalue[MIN] = " + self.min + ";\n") + if self.max != None: + stream.write (" _avalue[MAX] = " + self.max + ";\n") + if self.maxLen != None: + stream.write (" _avalue[MAXLEN] = " + self.maxLen + ";\n") + if self.default != None: + stream.write (" _avalue[DEFAULT] = \"" + self.default + "\";\n") + if self.desc != None: + stream.write (" _avalue[DESC] = \"" + self.desc + "\";\n") + stream.write (" _args[\"" + self.name + "\"] = _avalue;\n") + stream.write (" }\n") + + + def genFormalParam (self, stream, variables): stream.write ("%s _%s" % (self.type.type.asArg, self.name)) @@ -727,6 +904,24 @@ class SchemaMethod: for arg in self.args: arg.genSchema (stream) + def genSchemaMap (self, stream, variables): + stream.write (" {\n") + stream.write (" ::qpid::types::Variant::Map _value;\n") + stream.write (" ::qpid::types::Variant::Map _args;\n") + stream.write (" _value[ARGCOUNT] = " + str(len(self.args)) + ";\n") + if self.desc != None: + stream.write (" _value[DESC] = \"" + self.desc + "\";\n") + + for arg in self.args: + arg.genSchemaMap (stream) + + stream.write (" if (!_args.empty())\n") + stream.write (" _value[ARGS] = _args;\n") + + + stream.write (" _methods[\"" + self.name + "\"] = _value;\n") + stream.write (" }\n\n") + #===================================================================================== # #===================================================================================== @@ -849,10 +1044,20 @@ class SchemaEvent: for arg in self.args: stream.write(" " + arg.type.type.encode.replace("@", "buf").replace("#", arg.name) + ";\n") + def genArgMap(self, stream, variables): + for arg in self.args: + arg.type.type.genMap(stream, arg.name, " ", mapName="map") + #stream.write(" " + arg.type.type.encode.replace("@", "buf").replace("#", arg.name) + ";\n") + + def genArgSchema(self, stream, variables): for arg in self.args: arg.genSchema(stream, True) + def genArgSchemaMap(self, stream, variables): + for arg in self.args: + arg.genSchemaMap(stream, True) + def genSchemaMD5(self, stream, variables): sum = self.hash.getDigest() for idx in range (len (sum)): @@ -1023,12 +1228,36 @@ class SchemaClass: inArgCount = inArgCount + 1 if methodCount == 0: - stream.write ("string&, Buffer&, Buffer& outBuf") + stream.write ("string&, const string&, string& outStr") + else: + if inArgCount == 0: + stream.write ("string& methodName, const string&, string& outStr") + else: + stream.write ("string& methodName, const string& inStr, string& outStr") + + + def genDoMapMethodArgs (self, stream, variables): + methodCount = 0 + inArgCount = 0 + for method in self.methods: + methodCount = methodCount + 1 + for arg in method.args: + if arg.getDir () == "I" or arg.getDir () == "IO": + inArgCount = inArgCount + 1 + + if methodCount == 0: + stream.write ("string&," + + " const ::qpid::types::Variant::Map&," + + " ::qpid::types::Variant::Map& outMap") else: if inArgCount == 0: - stream.write ("string& methodName, Buffer&, Buffer& outBuf") + stream.write ("string& methodName," + + " const ::qpid::types::Variant::Map&," + + " ::qpid::types::Variant::Map& outMap") else: - stream.write ("string& methodName, Buffer& inBuf, Buffer& outBuf") + stream.write ("string& methodName," + + " const ::qpid::types::Variant::Map& inMap," + + " ::qpid::types::Variant::Map& outMap") def genHiLoStatResets (self, stream, variables): for inst in self.statistics: @@ -1109,8 +1338,22 @@ class SchemaClass: stream.write ("%d" % len (self.methods)) def genMethodHandlers (self, stream, variables): + inArgs = False + for method in self.methods: + for arg in method.args: + if arg.getDir () == "I" or arg.getDir () == "IO": + inArgs = True; + break + + if inArgs: + 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") + for method in self.methods: stream.write ("\n if (methodName == \"" + method.getName () + "\") {\n") + stream.write (" _matched = true;\n") if method.getArgCount () == 0: stream.write (" ::qpid::management::ArgsNone ioArgs;\n") else: @@ -1131,7 +1374,43 @@ class SchemaClass: stream.write (" " +\ arg.type.type.getWriteCode ("ioArgs." +\ arg.dir.lower () + "_" +\ - arg.name, "outBuf") + ";\n") + arg.name, "outBuf") + ";\n") + stream.write(" }\n") + + if inArgs: + stream.write ("\n delete [] _tmpBuf;\n") + + + + def genMapMethodHandlers (self, stream, variables): + for method in self.methods: + stream.write ("\n if (methodName == \"" + method.getName () + "\") {\n") + if method.getArgCount () == 0: + stream.write (" ::qpid::management::ArgsNone ioArgs;\n") + else: + stream.write (" Args" + method.getFullName () + " ioArgs;\n") + stream.write (" ::qpid::types::Variant::Map::const_iterator _i;\n") + + # decode each input argument from the input map + for arg in method.args: + if arg.getDir () == "I" or arg.getDir () == "IO": + arg.type.type.genUnmap(stream, + "ioArgs." + arg.dir.lower () + "_" + arg.name, + " ", + arg.name, + "inMap") + + stream.write (" status = coreObject->ManagementMethod (METHOD_" +\ + method.getName().upper() + ", ioArgs, text);\n") + stream.write (" outMap[\"_status_code\"] = (uint32_t) status;\n") + stream.write (" outMap[\"_status_text\"] = ::qpid::management::Manageable::StatusText(status, text);\n") + for arg in method.args: + if arg.getDir () == "O" or arg.getDir () == "IO": + arg.type.type.genMap(stream, + "ioArgs." + arg.dir.lower () + "_" + arg.name, + " ", + arg.name, + "outMap") stream.write (" return;\n }\n") def genOpenNamespaces (self, stream, variables): @@ -1160,6 +1439,10 @@ class SchemaClass: for prop in self.properties: prop.genSchema (stream) + def genPropertySchemaMap (self, stream, variables): + for prop in self.properties: + prop.genSchemaMap(stream) + def genSetGeneralReferenceDeclaration (self, stream, variables): for prop in self.properties: if prop.isGeneralRef: @@ -1169,6 +1452,10 @@ class SchemaClass: for stat in self.statistics: stat.genSchema (stream) + def genStatisticSchemaMap (self, stream, variables): + for stat in self.statistics: + stat.genSchemaMap(stream) + def genMethodIdDeclarations (self, stream, variables): number = 1 for method in self.methods: @@ -1180,6 +1467,10 @@ class SchemaClass: for method in self.methods: method.genSchema (stream, variables) + def genMethodSchemaMap(self, stream, variables): + for method in self.methods: + method.genSchemaMap(stream, variables) + def genNameCap (self, stream, variables): stream.write (capitalize(self.name)) @@ -1241,6 +1532,17 @@ class SchemaClass: for stat in self.statistics: stat.genWrite (stream) + def genMapEncodeProperties(self, stream, variables): + for prop in self.properties: + prop.genMap (stream) + + def genMapEncodeStatistics (self, stream, variables): + for stat in self.statistics: + stat.genMap (stream) + + def genMapDecodeProperties (self, stream, variables): + for prop in self.properties: + prop.genUnmap (stream) class SchemaEventArgs: def __init__(self, package, node, typespec, fragments, options): diff --git a/cpp/managementgen/qmfgen/templates/Args.h b/cpp/managementgen/qmfgen/templates/Args.h index 074ccf9940..20681ab477 100644 --- a/cpp/managementgen/qmfgen/templates/Args.h +++ b/cpp/managementgen/qmfgen/templates/Args.h @@ -24,8 +24,8 @@ /*MGEN:Root.Disclaimer*/ #include "qpid/management/Args.h" -#include "qpid/framing/FieldTable.h" -#include "qpid/framing/Uuid.h" +//#include "qpid/framing/FieldTable.h" +//#include "qpid/framing/Uuid.h" #include <string> namespace qmf { diff --git a/cpp/managementgen/qmfgen/templates/Class.cpp b/cpp/managementgen/qmfgen/templates/Class.cpp index e6362758ba..ed4e17720f 100644 --- a/cpp/managementgen/qmfgen/templates/Class.cpp +++ b/cpp/managementgen/qmfgen/templates/Class.cpp @@ -21,15 +21,15 @@ /*MGEN:Root.Disclaimer*/ #include "qpid/log/Statement.h" +#include "qpid/management/Manageable.h" #include "qpid/framing/FieldTable.h" -#include "qpid/management/Manageable.h" +#include "qpid/framing/Buffer.h" #include "qpid//*MGEN:Class.AgentHeaderLocation*//ManagementAgent.h" #include "/*MGEN:Class.NameCap*/.h" /*MGEN:Class.MethodArgIncludes*/ #include <iostream> using namespace qmf::/*MGEN:Class.Namespace*/; -using namespace qpid::framing; using qpid::management::ManagementAgent; using qpid::management::Manageable; using qpid::management::ManagementObject; @@ -38,7 +38,7 @@ using std::string; string /*MGEN:Class.NameCap*/::packageName = string ("/*MGEN:Class.NamePackageLower*/"); string /*MGEN:Class.NameCap*/::className = string ("/*MGEN:Class.NameLower*/"); -uint8_t /*MGEN:Class.NameCap*/::md5Sum[16] = +uint8_t /*MGEN:Class.NameCap*/::md5Sum[MD5_LEN] = {/*MGEN:Class.SchemaMD5*/}; /*MGEN:Class.NameCap*/::/*MGEN:Class.NameCap*/ (ManagementAgent*, Manageable* _core/*MGEN:Class.ParentArg*//*MGEN:Class.ConstructorArgs*/) : @@ -90,9 +90,12 @@ void /*MGEN:Class.NameCap*/::registerSelf(ManagementAgent* agent) agent->registerClass(packageName, className, md5Sum, writeSchema); } -void /*MGEN:Class.NameCap*/::writeSchema (Buffer& buf) +void /*MGEN:Class.NameCap*/::writeSchema (std::string& schema) { - FieldTable ft; + const int _bufSize=65536; + char _msgChars[_bufSize]; + ::qpid::framing::Buffer buf(_msgChars, _bufSize); + ::qpid::framing::FieldTable ft; // Schema class header: buf.putOctet (CLASS_KIND_TABLE); @@ -109,10 +112,15 @@ void /*MGEN:Class.NameCap*/::writeSchema (Buffer& buf) /*MGEN:Class.StatisticSchema*/ // Methods /*MGEN:Class.MethodSchema*/ + { + uint32_t _len = buf.getPosition(); + buf.reset(); + buf.getRawData(schema, _len); + } } /*MGEN:IF(Class.ExistPerThreadStats)*/ -void /*MGEN:Class.NameCap*/::aggregatePerThreadStats(struct PerThreadStats* totals) +void /*MGEN:Class.NameCap*/::aggregatePerThreadStats(struct PerThreadStats* totals) const { /*MGEN:Class.InitializeTotalPerThreadStats*/ for (int idx = 0; idx < maxThreads; idx++) { @@ -124,6 +132,7 @@ void /*MGEN:Class.NameCap*/::aggregatePerThreadStats(struct PerThreadStats* tota } /*MGEN:ENDIF*/ +/*MGEN:IF(Root.GenQMFv1)*/ uint32_t /*MGEN:Class.NameCap*/::writePropertiesSize() const { uint32_t size = writeTimestampsSize(); @@ -134,32 +143,62 @@ uint32_t /*MGEN:Class.NameCap*/::writePropertiesSize() const return size; } -void /*MGEN:Class.NameCap*/::readProperties (Buffer& buf) +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::sys::Mutex::ScopedLock mutex(accessLock); - readTimestamps(buf); + + { + std::string _tbuf; + buf.getRawData(_tbuf, writeTimestampsSize()); + readTimestamps(_tbuf); + } + /*MGEN:IF(Class.ExistOptionals)*/ for (uint8_t idx = 0; idx < /*MGEN:Class.PresenceMaskBytes*/; idx++) presenceMask[idx] = buf.getOctet(); /*MGEN:ENDIF*/ /*MGEN:Class.ReadProperties*/ + + delete [] _tmpBuf; } -void /*MGEN:Class.NameCap*/::writeProperties (Buffer& buf) const +void /*MGEN:Class.NameCap*/::writeProperties (std::string& _sBuf) const { + const int _bufSize=65536; + char _msgChars[_bufSize]; + ::qpid::framing::Buffer buf(_msgChars, _bufSize); + ::qpid::sys::Mutex::ScopedLock mutex(accessLock); configChanged = false; - writeTimestamps (buf); + { + std::string _tbuf; + writeTimestamps(_tbuf); + buf.putRawData(_tbuf); + } + + /*MGEN:IF(Class.ExistOptionals)*/ for (uint8_t idx = 0; idx < /*MGEN:Class.PresenceMaskBytes*/; idx++) buf.putOctet(presenceMask[idx]); /*MGEN:ENDIF*/ /*MGEN:Class.WriteProperties*/ + + uint32_t _bufLen = buf.getPosition(); + buf.reset(); + + buf.getRawData(_sBuf, _bufLen); } -void /*MGEN:Class.NameCap*/::writeStatistics (Buffer& buf, bool skipHeaders) +void /*MGEN:Class.NameCap*/::writeStatistics (std::string& _sBuf, bool skipHeaders) { + const int _bufSize=65536; + char _msgChars[_bufSize]; + ::qpid::framing::Buffer buf(_msgChars, _bufSize); + ::qpid::sys::Mutex::ScopedLock mutex(accessLock); instChanged = false; /*MGEN:IF(Class.ExistPerThreadAssign)*/ @@ -175,8 +214,12 @@ void /*MGEN:Class.NameCap*/::writeStatistics (Buffer& buf, bool skipHeaders) aggregatePerThreadStats(&totals); /*MGEN:ENDIF*/ /*MGEN:Class.Assign*/ - if (!skipHeaders) - writeTimestamps (buf); + if (!skipHeaders) { + std::string _tbuf; + writeTimestamps (_tbuf); + buf.putRawData(_tbuf); + } + /*MGEN:Class.WriteStatistics*/ // Maintenance of hi-lo statistics @@ -189,6 +232,11 @@ void /*MGEN:Class.NameCap*/::writeStatistics (Buffer& buf, bool skipHeaders) } } /*MGEN:ENDIF*/ + + uint32_t _bufLen = buf.getPosition(); + buf.reset(); + + buf.getRawData(_sBuf, _bufLen); } void /*MGEN:Class.NameCap*/::doMethod (/*MGEN:Class.DoMethodArgs*/) @@ -196,11 +244,25 @@ void /*MGEN:Class.NameCap*/::doMethod (/*MGEN:Class.DoMethodArgs*/) Manageable::status_t status = Manageable::STATUS_UNKNOWN_METHOD; std::string text; + bool _matched = false; + + const int _bufSize=65536; + char _msgChars[_bufSize]; + ::qpid::framing::Buffer outBuf(_msgChars, _bufSize); + /*MGEN:Class.MethodHandlers*/ - outBuf.putLong(status); - outBuf.putShortString(Manageable::StatusText(status, text)); -} + if (!_matched) { + outBuf.putLong(status); + outBuf.putShortString(Manageable::StatusText(status, text)); + } + + uint32_t _bufLen = outBuf.getPosition(); + outBuf.reset(); + + outBuf.getRawData(outStr, _bufLen); +} +/*MGEN:ENDIF*/ std::string /*MGEN:Class.NameCap*/::getKey() const { std::stringstream key; @@ -209,3 +271,67 @@ std::string /*MGEN:Class.NameCap*/::getKey() const return key.str(); } + + +void /*MGEN:Class.NameCap*/::mapEncodeValues (::qpid::types::Variant::Map& _map, + bool includeProperties, + bool includeStatistics) +{ + using namespace ::qpid::types; + ::qpid::sys::Mutex::ScopedLock mutex(accessLock); + + if (includeProperties) { + configChanged = false; +/*MGEN:Class.MapEncodeProperties*/ + } + + if (includeStatistics) { + instChanged = false; +/*MGEN:IF(Class.ExistPerThreadAssign)*/ + for (int idx = 0; idx < maxThreads; idx++) { + struct PerThreadStats* threadStats = perThreadStatsArray[idx]; + if (threadStats != 0) { +/*MGEN:Class.PerThreadAssign*/ + } + } +/*MGEN:ENDIF*/ +/*MGEN:IF(Class.ExistPerThreadStats)*/ + struct PerThreadStats totals; + aggregatePerThreadStats(&totals); +/*MGEN:ENDIF*/ +/*MGEN:Class.Assign*/ + +/*MGEN:Class.MapEncodeStatistics*/ + + // Maintenance of hi-lo statistics +/*MGEN:Class.HiLoStatResets*/ +/*MGEN:IF(Class.ExistPerThreadResets)*/ + for (int idx = 0; idx < maxThreads; idx++) { + struct PerThreadStats* threadStats = perThreadStatsArray[idx]; + if (threadStats != 0) { +/*MGEN:Class.PerThreadHiLoStatResets*/ + } + } +/*MGEN:ENDIF*/ + } +} + +void /*MGEN:Class.NameCap*/::mapDecodeValues (const ::qpid::types::Variant::Map& _map) +{ + ::qpid::types::Variant::Map::const_iterator _i; + ::qpid::sys::Mutex::ScopedLock mutex(accessLock); +/*MGEN:IF(Class.ExistOptionals)*/ + bool _found; +/*MGEN:ENDIF*/ +/*MGEN:Class.MapDecodeProperties*/ +} + +void /*MGEN:Class.NameCap*/::doMethod (/*MGEN:Class.DoMapMethodArgs*/) +{ + Manageable::status_t status = Manageable::STATUS_UNKNOWN_METHOD; + std::string text; + +/*MGEN:Class.MapMethodHandlers*/ + outMap["_status_code"] = (uint32_t) status; + outMap["_status_text"] = Manageable::StatusText(status, text); +} diff --git a/cpp/managementgen/qmfgen/templates/Class.h b/cpp/managementgen/qmfgen/templates/Class.h index 8efacd650f..cdb31c4c9e 100644 --- a/cpp/managementgen/qmfgen/templates/Class.h +++ b/cpp/managementgen/qmfgen/templates/Class.h @@ -24,8 +24,6 @@ /*MGEN:Root.Disclaimer*/ #include "qpid/management/ManagementObject.h" -#include "qpid/framing/FieldTable.h" -#include "qpid/framing/Uuid.h" namespace qpid { namespace management { @@ -42,7 +40,7 @@ class /*MGEN:Class.NameCap*/ : public ::qpid::management::ManagementObject static std::string packageName; static std::string className; - static uint8_t md5Sum[16]; + static uint8_t md5Sum[MD5_LEN]; /*MGEN:IF(Class.ExistOptionals)*/ uint8_t presenceMask[/*MGEN:Class.PresenceMaskBytes*/]; /*MGEN:Class.PresenceMaskConstants*/ @@ -71,18 +69,28 @@ class /*MGEN:Class.NameCap*/ : public ::qpid::management::ManagementObject return threadStats; } - void aggregatePerThreadStats(struct PerThreadStats*); + void aggregatePerThreadStats(struct PerThreadStats*) const; /*MGEN:ENDIF*/ public: - static void writeSchema(::qpid::framing::Buffer& buf); + static void writeSchema(std::string& schema); + void mapEncodeValues(::qpid::types::Variant::Map& map, + bool includeProperties=true, + bool includeStatistics=true); + void mapDecodeValues(const ::qpid::types::Variant::Map& map); + void doMethod(std::string& methodName, + const ::qpid::types::Variant::Map& inMap, + ::qpid::types::Variant::Map& outMap); + std::string getKey() const; +/*MGEN:IF(Root.GenQMFv1)*/ uint32_t writePropertiesSize() const; - void readProperties(::qpid::framing::Buffer& buf); - void writeProperties(::qpid::framing::Buffer& buf) const; - void writeStatistics(::qpid::framing::Buffer& buf, bool skipHeaders = false); + void readProperties(const std::string& buf); + void writeProperties(std::string& buf) const; + void writeStatistics(std::string& buf, bool skipHeaders = false); void doMethod(std::string& methodName, - ::qpid::framing::Buffer& inBuf, - ::qpid::framing::Buffer& outBuf); - std::string getKey() const; + const std::string& inBuf, + std::string& outBuf); +/*MGEN:ENDIF*/ + writeSchemaCall_t getWriteSchemaCall() { return writeSchema; } /*MGEN:IF(Class.NoStatistics)*/ // Stub for getInstChanged. There are no statistics in this class. diff --git a/cpp/managementgen/qmfgen/templates/Event.cpp b/cpp/managementgen/qmfgen/templates/Event.cpp index a4fc28990d..d760fd9014 100644 --- a/cpp/managementgen/qmfgen/templates/Event.cpp +++ b/cpp/managementgen/qmfgen/templates/Event.cpp @@ -21,13 +21,13 @@ /*MGEN:Root.Disclaimer*/ #include "qpid/log/Statement.h" -#include "qpid/framing/FieldTable.h" #include "qpid/management/Manageable.h" +#include "qpid/framing/FieldTable.h" +#include "qpid/framing/Buffer.h" #include "qpid//*MGEN:Event.AgentHeaderLocation*//ManagementAgent.h" #include "Event/*MGEN:Event.NameCap*/.h" using namespace qmf::/*MGEN:Event.Namespace*/; -using namespace qpid::framing; using qpid::management::ManagementAgent; using qpid::management::Manageable; using qpid::management::ManagementObject; @@ -56,23 +56,45 @@ void Event/*MGEN:Event.NameCap*/::registerSelf(ManagementAgent* agent) agent->registerEvent(packageName, eventName, md5Sum, writeSchema); } -void Event/*MGEN:Event.NameCap*/::writeSchema (Buffer& buf) +void Event/*MGEN:Event.NameCap*/::writeSchema (std::string& schema) { - FieldTable ft; + const int _bufSize = 65536; + char _msgChars[_bufSize]; + ::qpid::framing::Buffer buf(_msgChars, _bufSize); + ::qpid::framing::FieldTable ft; // Schema class header: buf.putOctet (CLASS_KIND_EVENT); buf.putShortString (packageName); // Package Name buf.putShortString (eventName); // Event Name buf.putBin128 (md5Sum); // Schema Hash - buf.putOctet (0); // No Superclass buf.putShort (/*MGEN:Event.ArgCount*/); // Argument Count // Arguments /*MGEN:Event.ArgSchema*/ + { + uint32_t _len = buf.getPosition(); + buf.reset(); + buf.getRawData(schema, _len); + } } -void Event/*MGEN:Event.NameCap*/::encode(::qpid::framing::Buffer& buf) const +void Event/*MGEN:Event.NameCap*/::encode(std::string& _sBuf) const { + const int _bufSize=65536; + char _msgChars[_bufSize]; + ::qpid::framing::Buffer buf(_msgChars, _bufSize); + /*MGEN:Event.ArgEncodes*/ + + uint32_t _bufLen = buf.getPosition(); + buf.reset(); + + buf.getRawData(_sBuf, _bufLen); +} + +void Event/*MGEN:Event.NameCap*/::mapEncode(::qpid::types::Variant::Map& map) const +{ + using namespace ::qpid::types; +/*MGEN:Event.ArgMap*/ } diff --git a/cpp/managementgen/qmfgen/templates/Event.h b/cpp/managementgen/qmfgen/templates/Event.h index b5c2a211d1..4f912cf220 100644 --- a/cpp/managementgen/qmfgen/templates/Event.h +++ b/cpp/managementgen/qmfgen/templates/Event.h @@ -24,8 +24,6 @@ /*MGEN:Root.Disclaimer*/ #include "qpid/management/ManagementEvent.h" -#include "qpid/framing/FieldTable.h" -#include "qpid/framing/Uuid.h" namespace qmf { /*MGEN:Event.OpenNamespaces*/ @@ -33,10 +31,10 @@ namespace qmf { class Event/*MGEN:Event.NameCap*/ : public ::qpid::management::ManagementEvent { private: - static void writeSchema (::qpid::framing::Buffer& buf); + static void writeSchema (std::string& schema); static std::string packageName; static std::string eventName; - static uint8_t md5Sum[16]; + static uint8_t md5Sum[MD5_LEN]; /*MGEN:Event.ArgDeclarations*/ @@ -51,7 +49,8 @@ class Event/*MGEN:Event.NameCap*/ : public ::qpid::management::ManagementEvent std::string& getEventName() const { return eventName; } uint8_t* getMd5Sum() const { return md5Sum; } uint8_t getSeverity() const { return /*MGEN:Event.Severity*/; } - void encode(::qpid::framing::Buffer& buffer) const; + void encode(std::string& buffer) const; + void mapEncode(::qpid::types::Variant::Map& map) const; }; }/*MGEN:Event.CloseNamespaces*/ |
