diff options
Diffstat (limited to 'cpp/managementgen/qmfgen')
-rw-r--r-- | cpp/managementgen/qmfgen/__init__.py | 19 | ||||
-rwxr-xr-x | cpp/managementgen/qmfgen/generate.py | 369 | ||||
-rw-r--r-- | cpp/managementgen/qmfgen/management-types.xml | 56 | ||||
-rwxr-xr-x | cpp/managementgen/qmfgen/schema.py | 1339 | ||||
-rw-r--r-- | cpp/managementgen/qmfgen/templates/Args.h | 42 | ||||
-rw-r--r-- | cpp/managementgen/qmfgen/templates/Class.cpp | 181 | ||||
-rw-r--r-- | cpp/managementgen/qmfgen/templates/Class.h | 104 | ||||
-rw-r--r-- | cpp/managementgen/qmfgen/templates/Event.cpp | 77 | ||||
-rw-r--r-- | cpp/managementgen/qmfgen/templates/Event.h | 59 | ||||
-rw-r--r-- | cpp/managementgen/qmfgen/templates/Makefile.mk | 40 | ||||
-rw-r--r-- | cpp/managementgen/qmfgen/templates/Package.cpp | 32 | ||||
-rw-r--r-- | cpp/managementgen/qmfgen/templates/Package.h | 41 |
12 files changed, 2359 insertions, 0 deletions
diff --git a/cpp/managementgen/qmfgen/__init__.py b/cpp/managementgen/qmfgen/__init__.py new file mode 100644 index 0000000000..caef6cc58b --- /dev/null +++ b/cpp/managementgen/qmfgen/__init__.py @@ -0,0 +1,19 @@ +# +# 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. +# + diff --git a/cpp/managementgen/qmfgen/generate.py b/cpp/managementgen/qmfgen/generate.py new file mode 100755 index 0000000000..762af972e7 --- /dev/null +++ b/cpp/managementgen/qmfgen/generate.py @@ -0,0 +1,369 @@ +# +# 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. +# + +from xml.dom.minidom import parse, parseString, Node +from cStringIO import StringIO +from stat import * +from errno import * +import os +import os.path +import filecmp + +class Template: + """ + Expandable File Template - This class is instantiated each time a + template is to be expanded. It is instantiated with the "filename" + which is the full path to the template file and the "handler" which + is an object that is responsible for storing variables (setVariable), + checking conditions (testCondition), and expanding tags (substHandler). + """ + def __init__ (self, filename, handler): + self.filename = filename + self.handler = handler + self.handler.initExpansion () + self.writing = True + + def expandLine (self, line, stream, object): + cursor = 0 + while 1: + sub = line.find ("/*MGEN:", cursor) + if sub == -1: + if self.writing: + stream.write (line[cursor:len (line)]) + return + + subend = line.find("*/", sub) + if self.writing: + 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 + + elif tag[7:12] == "ENDIF": + self.writing = True + + else: + equalPos = tag.find ("=") + if equalPos == -1: + dotPos = tag.find (".") + if dotPos == -1: + raise ValueError ("Invalid tag: %s" % tag) + tagObject = tag[7:dotPos] + tagName = tag[dotPos + 1:len (tag)] + if self.writing: + self.handler.substHandler (object, stream, tagObject, tagName) + else: + tagKey = tag[7:equalPos] + tagVal = tag[equalPos + 1:len (tag)] + if self.writing: + self.handler.setVariable (tagKey, tagVal) + + def expand (self, object): + fd = open (self.filename) + stream = StringIO () + + for line in fd: + self.expandLine (line, stream, object) + fd.close () + + return stream + + +class Makefile: + """ Object representing a makefile fragment """ + def __init__ (self, filelists, templateFiles, packagelist): + self.filelists = filelists + self.templateFiles = templateFiles + self.packagelist = packagelist + + def genGenSources (self, stream, variables): + mdir = variables["mgenDir"] + sdir = variables["specDir"] + stream.write (mdir + "/qmf-gen \\\n") + stream.write (" " + mdir + "/qmfgen/generate.py \\\n") + stream.write (" " + mdir + "/qmfgen/schema.py \\\n") + stream.write (" " + mdir + "/qmfgen/management-types.xml \\\n") + stream.write (" " + sdir + "/management-schema.xml \\\n") + first = True + for template in self.templateFiles: + if first: + first = False + stream.write (" ") + else: + stream.write (" \\\n ") + stream.write (mdir + "/qmfgen/templates/" + template) + + def genGenCppFiles (self, stream, variables): + first = True + for file in self.filelists["cpp"]: + if first: + first = False + else: + stream.write (" \\\n ") + stream.write (file) + + def genGenHFiles (self, stream, variables): + first = True + for file in self.filelists["h"]: + if first: + first = False + else: + stream.write (" \\\n ") + stream.write (file) + + def genGeneratedFiles(self, stream, variables): + first = True + extensions = ("h", "cpp") + for ext in extensions: + for file in self.filelists[ext]: + if first: + first = False + else: + stream.write(" \\\n ") + if "genprefix" in variables: + prefix = variables["genprefix"] + if prefix != "": + stream.write(prefix + "/") + stream.write(file) + + def genHeaderInstalls (self, stream, variables): + for package in self.packagelist: + name = "_".join(package.split("/")) + stream.write(name + "dir = $(includedir)/qmf/" + package + "\n") + stream.write("dist_" + name + "_HEADERS = ") + first = True + for file in self.filelists["h"]: + if file.find("gen/qmf/" + package) == 0: + if first: + first = False + else: + stream.write (" \\\n ") + stream.write(file) + stream.write("\n\n") + + def testQpidBroker(self, variables): + if "qpidbroker" in variables: + return variables["qpidbroker"] + return False + + +class Generator: + """ + This class manages code generation using template files. It is instantiated + once for an entire code generation session. + """ + def createPath (self, path): + exists = True + try: + mode = os.stat (path)[ST_MODE] + except OSError, (err,text): + if err == ENOENT or err == ESRCH: + exists = False + else: + raise + if exists and not S_ISDIR (mode): + raise ValueError ("path is not directory: %s" % path) + if not exists: + pair = os.path.split (path) + if pair[0] != '': + self.createPath (pair[0]) + os.mkdir (path) + + def normalize (self, path): + newpath = os.path.normcase (os.path.normpath (path)) + self.createPath (newpath) + return newpath + "/" + + def __init__ (self, destDir, templateDir): + self.dest = self.normalize (destDir) + self.input = self.normalize (templateDir) + self.packagePath = self.dest + self.filelists = {} + self.filelists["h"] = [] + self.filelists["cpp"] = [] + self.filelists["mk"] = [] + self.packagelist = [] + self.templateFiles = [] + self.variables = {} + + def setPackage (self, packageName): + path = "/".join(packageName.split(".")) + self.packagelist.append(path) + self.packagePath = self.normalize(self.dest + path) + + def genDisclaimer (self, stream, variables): + prefix = variables["commentPrefix"] + stream.write (prefix + " This source file was created by a code generator.\n") + stream.write (prefix + " Please do not edit.") + + def fileExt (self, path): + dot = path.rfind (".") + if dot == -1: + return "" + return path[dot + 1:] + + def writeIfChanged (self, stream, target, force=False): + ext = self.fileExt (target) + self.filelists[ext].append (target) + tempFile = self.packagePath + "gen.tmp" + fd = open (tempFile, "w") + fd.write (stream.getvalue ()) + fd.close () + + try: + if not force and filecmp.cmp (target, tempFile): + os.remove (tempFile) + return + except: + pass + + try: + os.remove (target) + except: + pass + + os.rename (tempFile, target) + print "Generated:", target + + def targetPackageFile (self, schema, templateFile): + dot = templateFile.find(".") + if dot == -1: + raise ValueError ("Invalid template file name %s" % templateFile) + extension = templateFile[dot:len (templateFile)] + path = self.packagePath + "Package" + extension + return path + + def targetClassFile (self, _class, templateFile): + dot = templateFile.find(".") + if dot == -1: + raise ValueError ("Invalid template file name %s" % templateFile) + extension = templateFile[dot:len (templateFile)] + path = self.packagePath + _class.getNameCap () + extension + return path + + def targetEventFile (self, event, templateFile): + dot = templateFile.find(".") + if dot == -1: + raise ValueError ("Invalid template file name %s" % templateFile) + extension = templateFile[dot:len (templateFile)] + path = self.packagePath + "Event" + event.getNameCap () + extension + return path + + def targetMethodFile (self, method, templateFile): + """ Return the file name for a method file """ + dot = templateFile.rfind(".") + if dot == -1: + raise ValueError ("Invalid template file name %s" % templateFile) + extension = templateFile[dot:] + path = self.packagePath + "Args" + method.getFullName () + extension + return path + + def initExpansion (self): + self.variables = {} + + def substHandler (self, object, stream, tagObject, tag): + if tagObject == "Root": + obj = "self" + else: + obj = "object" # MUST be the same as the 2nd formal parameter + + call = obj + ".gen" + tag + "(stream, self.variables)" + eval (call) + + def testCondition (self, object, tagObject, tag): + if tagObject == "Root": + obj = "self" + else: + obj = "object" # MUST be the same as the 2nd formal parameter + + call = obj + ".test" + tag + "(self.variables)" + return eval (call) + + def setVariable (self, key, value): + self.variables[key] = value + + def makeClassFiles (self, templateFile, schema, force=False): + """ Generate an expanded template per schema class """ + classes = schema.getClasses () + template = Template (self.input + templateFile, self) + self.templateFiles.append (templateFile) + for _class in classes: + target = self.targetClassFile (_class, templateFile) + stream = template.expand (_class) + self.writeIfChanged (stream, target, force) + + def makeEventFiles (self, templateFile, schema, force=False): + """ Generate an expanded template per schema event """ + events = schema.getEvents() + template = Template (self.input + templateFile, self) + self.templateFiles.append (templateFile) + for event in events: + target = self.targetEventFile(event, templateFile) + stream = template.expand(event) + self.writeIfChanged(stream, target, force) + + def makeMethodFiles (self, templateFile, schema, force=False): + """ Generate an expanded template per method-with-arguments """ + classes = schema.getClasses () + template = Template (self.input + templateFile, self) + self.templateFiles.append (templateFile) + for _class in classes: + methods = _class.getMethods () + for method in methods: + if method.getArgCount () > 0: + target = self.targetMethodFile (method, templateFile) + stream = template.expand (method) + self.writeIfChanged (stream, target, force) + + def makePackageFile (self, templateFile, schema, force=False): + """ Generate a package-specific file """ + template = Template (self.input + templateFile, self) + self.templateFiles.append (templateFile) + target = self.targetPackageFile (schema, templateFile) + stream = template.expand (schema) + self.writeIfChanged (stream, target, force) + + def makeSingleFile (self, templateFile, target, force=False, vars=None): + """ Generate a single expanded template """ + makefile = Makefile (self.filelists, self.templateFiles, self.packagelist) + template = Template (self.input + templateFile, self) + if vars: + for arg in vars: + self.setVariable(arg, vars[arg]) + self.templateFiles.append (templateFile) + stream = template.expand (makefile) + self.writeIfChanged (stream, target, force) + + def getModulePath(): + return __file__ + + getModulePath = staticmethod(getModulePath) diff --git a/cpp/managementgen/qmfgen/management-types.xml b/cpp/managementgen/qmfgen/management-types.xml new file mode 100644 index 0000000000..626880afb3 --- /dev/null +++ b/cpp/managementgen/qmfgen/management-types.xml @@ -0,0 +1,56 @@ +<schema-types> + +<!-- + 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. +--> + +<type name="objId" base="REF" cpp="::qpid::management::ObjectId" encode="#.encode(@)" decode="#.decode(@)" accessor="direct" init="::qpid::management::ObjectId()" byRef="y"/> +<type name="uint8" base="U8" cpp="uint8_t" encode="@.putOctet(#)" decode="# = @.getOctet()" accessor="direct" init="0"/> +<type name="uint16" base="U16" cpp="uint16_t" encode="@.putShort(#)" decode="# = @.getShort()" accessor="direct" init="0"/> +<type name="uint32" base="U32" cpp="uint32_t" encode="@.putLong(#)" decode="# = @.getLong()" accessor="direct" init="0"/> +<type name="uint64" base="U64" cpp="uint64_t" encode="@.putLongLong(#)" decode="# = @.getLongLong()" accessor="direct" init="0"/> +<type name="int8" base="S8" cpp="int8_t" encode="@.putInt8(#)" decode="# = @.getInt8()" accessor="direct" init="0"/> +<type name="int16" base="S16" cpp="int16_t" encode="@.putInt16(#)" decode="# = @.getInt16()" accessor="direct" init="0"/> +<type name="int32" base="S32" cpp="int32_t" encode="@.putInt32(#)" decode="# = @.getInt32()" accessor="direct" init="0"/> +<type name="int64" base="S64" cpp="int64_t" encode="@.putInt64(#)" decode="# = @.getInt64()" accessor="direct" init="0"/> +<type name="bool" base="BOOL" cpp="uint8_t" encode="@.putOctet(#?1:0)" decode="# = @.getOctet()==1" accessor="direct" init="0"/> +<type name="sstr" base="SSTR" cpp="std::string" encode="@.putShortString(#)" decode="@.getShortString(#)" accessor="direct" init='""' byRef="y"/> +<type name="lstr" base="LSTR" cpp="std::string" encode="@.putMediumString(#)" decode="@.getMediumString(#)" accessor="direct" init='""' byRef="y"/> +<type name="absTime" base="ABSTIME" cpp="int64_t" encode="@.putLongLong(#)" decode="# = @.getLongLong()" accessor="direct" init="0"/> +<type name="deltaTime" base="DELTATIME" cpp="uint64_t" encode="@.putLongLong(#)" decode="# = @.getLongLong()" accessor="direct" init="0"/> +<type name="float" base="FLOAT" cpp="float" encode="@.putFloat(#)" decode="# = @.getFloat()" accessor="direct" init="0."/> +<type name="double" base="DOUBLE" cpp="double" encode="@.putDouble(#)" decode="# = @.getDouble()" accessor="direct" init="0."/> +<type name="uuid" base="UUID" cpp="::qpid::framing::Uuid" encode="#.encode(@)" decode="#.decode(@)" accessor="direct" init="::qpid::framing::Uuid()" byRef="y"/> +<type name="map" base="FTABLE" cpp="::qpid::framing::FieldTable" encode="#.encode(@)" decode="#.decode(@)" accessor="direct" init="::qpid::framing::FieldTable()" byRef="y"/> + +<type name="hilo8" base="U8" cpp="uint8_t" encode="@.putOctet(#)" decode="# = @.getOctet()" style="wm" accessor="counter" init="0"/> +<type name="hilo16" base="U16" cpp="uint16_t" encode="@.putShort(#)" decode="# = @.getShort()" style="wm" accessor="counter" init="0"/> +<type name="hilo32" base="U32" cpp="uint32_t" encode="@.putLong(#)" decode="# = @.getLong()" style="wm" accessor="counter" init="0"/> +<type name="hilo64" base="U64" cpp="uint64_t" encode="@.putLongLong(#)" decode="# = @.getLongLong()" style="wm" accessor="counter" init="0"/> + +<type name="count8" base="U8" cpp="uint8_t" encode="@.putOctet(#)" decode="# = @.getOctet()" accessor="counter" init="0" perThread="y"/> +<type name="count16" base="U16" cpp="uint16_t" encode="@.putShort(#)" decode="# = @.getShort()" accessor="counter" init="0" perThread="y"/> +<type name="count32" base="U32" cpp="uint32_t" encode="@.putLong(#)" decode="# = @.getLong()" accessor="counter" init="0" perThread="y"/> +<type name="count64" base="U64" cpp="uint64_t" encode="@.putLongLong(#)" decode="# = @.getLongLong()" accessor="counter" init="0" perThread="y"/> + +<!-- Min/Max/Average statistics --> +<type name="mma32" base="U32" cpp="uint32_t" encode="@.putLong(#)" decode="# = @.getLong()" style="mma" accessor="direct" init="0" perThread="y"/> +<type name="mma64" base="U64" cpp="uint64_t" encode="@.putLongLong(#)" decode="# = @.getLongLong()" style="mma" accessor="direct" init="0" perThread="y"/> +<type name="mmaTime" base="DELTATIME" cpp="uint64_t" encode="@.putLongLong(#)" decode="# = @.getLongLong()" style="mma" accessor="direct" init="0" perThread="y"/> + +</schema-types> diff --git a/cpp/managementgen/qmfgen/schema.py b/cpp/managementgen/qmfgen/schema.py new file mode 100755 index 0000000000..692a474992 --- /dev/null +++ b/cpp/managementgen/qmfgen/schema.py @@ -0,0 +1,1339 @@ +# +# 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. +# + +from xml.dom.minidom import parse, parseString, Node +from cStringIO import StringIO +import md5 + +class Hash: + """ Manage the hash of an XML sub-tree """ + def __init__(self, node): + self.md5Sum = md5.new() + self._compute(node) + + def addSubHash(self, hash): + """ Use this method to add the hash of a dependend-on XML fragment that is not in the sub-tree """ + self.md5Sum.update(hash.getDigest()) + + def getDigest(self): + return self.md5Sum.digest() + + def _compute(self, node): + attrs = node.attributes + self.md5Sum.update(node.nodeName) + + for idx in range(attrs.length): + self.md5Sum.update(attrs.item(idx).nodeName) + self.md5Sum.update(attrs.item(idx).nodeValue) + + for child in node.childNodes: + if child.nodeType == Node.ELEMENT_NODE: + self._compute(child) + + +#===================================================================================== +# +#===================================================================================== +class SchemaType: + def __init__ (self, node): + self.name = None + self.base = None + self.cpp = None + self.encode = None + self.decode = None + self.style = "normal" + self.accessor = None + self.init = "0" + self.perThread = False + self.byRef = False + + attrs = node.attributes + for idx in range (attrs.length): + key = attrs.item(idx).nodeName + val = attrs.item(idx).nodeValue + if key == 'name': + self.name = val + + elif key == 'base': + self.base = val + + elif key == 'cpp': + self.cpp = val + + elif key == 'encode': + self.encode = val + + elif key == 'decode': + self.decode = val + + elif key == 'style': + self.style = val + + elif key == 'accessor': + self.accessor = val + + elif key == 'init': + self.init = val + + elif key == 'perThread': + if val != 'y': + raise ValueError ("Expected 'y' in perThread attribute") + self.perThread = True + + elif key == 'byRef': + if val != 'y': + raise ValueError ("Expected 'y' in byRef attribute") + self.byRef = True + + else: + raise ValueError ("Unknown attribute in type '%s'" % key) + + if self.name == None or self.base == None or self.cpp == None or \ + self.encode == None or self.decode == None: + raise ValueError ("Missing required attribute(s) in type") + + if self.byRef: + self.asArg = "const " + self.cpp + "&" + else: + self.asArg = self.cpp + + def getName (self): + return self.name + + def genAccessor (self, stream, varName, changeFlag = None, optional = False): + if self.perThread: + prefix = "getThreadStats()->" + if self.style == "wm": + raise ValueError ("'wm' style types can't be per-thread") + else: + prefix = "" + if self.accessor == "direct": + stream.write (" inline void set_" + varName + " (" + self.asArg + " val) {\n"); + if not self.perThread: + stream.write (" ::qpid::sys::Mutex::ScopedLock mutex(accessLock);\n") + if self.style != "mma": + stream.write (" " + prefix + varName + " = val;\n") + if optional: + stream.write (" presenceMask[presenceByte_%s] |= presenceMask_%s;\n" % (varName, varName)) + if self.style == "wm": + stream.write (" if (" + varName + "Low > val)\n") + stream.write (" " + varName + "Low = val;\n") + stream.write (" if (" + varName + "High < val)\n") + stream.write (" " + varName + "High = val;\n") + if self.style == "mma": + stream.write (" " + prefix + varName + "Count++;\n") + stream.write (" " + prefix + varName + "Total += val;\n") + stream.write (" if (" + prefix + varName + "Min > val)\n") + stream.write (" " + prefix + varName + "Min = val;\n") + stream.write (" if (" + prefix + varName + "Max < val)\n") + stream.write (" " + prefix + varName + "Max = val;\n") + if changeFlag != None: + stream.write (" " + changeFlag + " = true;\n") + stream.write (" }\n") + if self.style != "mma": + stream.write (" inline " + self.asArg + " get_" + varName + "() {\n"); + if not self.perThread: + stream.write (" ::qpid::sys::Mutex::ScopedLock mutex(accessLock);\n") + stream.write (" return " + prefix + varName + ";\n") + stream.write (" }\n") + if optional: + stream.write (" inline void clr_" + varName + "() {\n") + stream.write (" presenceMask[presenceByte_%s] &= ~presenceMask_%s;\n" % (varName, varName)) + if changeFlag != None: + stream.write (" " + changeFlag + " = true;\n") + stream.write (" }\n") + stream.write (" inline bool isSet_" + varName + "() {\n") + stream.write (" return (presenceMask[presenceByte_%s] & presenceMask_%s) != 0;\n" % (varName, varName)) + stream.write (" }\n") + elif self.accessor == "counter": + stream.write (" inline void inc_" + varName + " (" + self.asArg + " by = 1) {\n"); + if not self.perThread: + stream.write (" ::qpid::sys::Mutex::ScopedLock mutex(accessLock);\n") + stream.write (" " + prefix + varName + " += by;\n") + if self.style == "wm": + stream.write (" if (" + varName + "High < " + varName + ")\n") + stream.write (" " + varName + "High = " + varName + ";\n") + if changeFlag != None: + stream.write (" " + changeFlag + " = true;\n") + stream.write (" }\n"); + stream.write (" inline void dec_" + varName + " (" + self.asArg + " by = 1) {\n"); + if not self.perThread: + stream.write (" ::qpid::sys::Mutex::ScopedLock mutex(accessLock);\n") + stream.write (" " + prefix + varName + " -= by;\n") + if self.style == "wm": + stream.write (" if (" + varName + "Low > " + varName + ")\n") + stream.write (" " + varName + "Low = " + varName + ";\n") + if changeFlag != None: + stream.write (" " + changeFlag + " = true;\n") + stream.write (" }\n"); + + def genHiLoStatResets (self, stream, varName): + if self.style == "wm": + stream.write (" " + varName + "High = " + varName + ";\n") + stream.write (" " + varName + "Low = " + varName + ";\n") + if self.style == "mma": + stream.write (" " + varName + "Count = 0;\n") + stream.write (" " + varName + "Total = 0;\n") + stream.write (" " + varName + "Min = std::numeric_limits<" + self.type.type.cpp + ">::max();\n") + stream.write (" " + varName + "Max = std::numeric_limits<" + self.type.type.cpp + ">::min();\n") + + def genPerThreadHiLoStatResets (self, stream, varName, cpptype): + if self.style == "mma": + stream.write (" threadStats->" + varName + "Count = 0;\n") + stream.write (" threadStats->" + varName + "Total = 0;\n") + stream.write (" threadStats->" + varName + "Min = std::numeric_limits<" + cpptype + ">::max();\n") + stream.write (" threadStats->" + varName + "Max = std::numeric_limits<" + cpptype + ">::min();\n") + + def genWrite (self, stream, varName, indent=" "): + if self.style != "mma": + stream.write (indent + self.encode.replace ("@", "buf").replace ("#", varName) + ";\n") + if self.style == "wm": + stream.write (indent + self.encode.replace ("@", "buf") \ + .replace ("#", varName + "High") + ";\n") + stream.write (indent + self.encode.replace ("@", "buf") \ + .replace ("#", varName + "Low") + ";\n") + if self.style == "mma": + stream.write (indent + self.encode.replace ("@", "buf") \ + .replace ("#", varName + "Count") + ";\n") + stream.write (indent + self.encode.replace ("@", "buf") \ + .replace ("#", varName + "Count ? " + varName + "Min : 0") + ";\n") + stream.write (indent + self.encode.replace ("@", "buf") \ + .replace ("#", varName + "Max") + ";\n") + stream.write (indent + self.encode.replace ("@", "buf") \ + .replace ("#", varName + "Count ? " + varName + "Total / " + + varName + "Count : 0") + ";\n") + + + def getReadCode (self, varName, bufName): + result = self.decode.replace ("@", bufName).replace ("#", varName) + return result + + def getWriteCode (self, varName, bufName): + result = self.encode.replace ("@", bufName).replace ("#", varName) + return result + +#===================================================================================== +# +#===================================================================================== +class TypeSpec: + def __init__ (self, file): + self.types = {} + dom = parse (file) + document = dom.documentElement + if document.tagName != 'schema-types': + raise ValueError ("Expected 'schema-types' in type file") + + for child in document.childNodes: + if child.nodeType == Node.ELEMENT_NODE: + if child.nodeName == 'type': + stype = SchemaType (child) + self.types[stype.getName ()] = stype + else: + raise ValueError ("Unknown type tag '%s'" % child.nodeName) + + def getType (self, name): + return self.types[name] + + +#===================================================================================== +# +#===================================================================================== +class Type: + def __init__ (self, name, typespec): + self.type = typespec.getType (name) + +#===================================================================================== +# +#===================================================================================== +class SchemaProperty: + def __init__ (self, node, typespec): + self.name = None + self.type = None + self.ref = None + self.access = "RO" + self.isIndex = 0 + self.isParentRef = 0 + self.isGeneralRef = 0 + self.isOptional = 0 + self.unit = None + self.min = None + self.max = None + self.maxLen = None + self.desc = None + + attrs = node.attributes + for idx in range (attrs.length): + key = attrs.item(idx).nodeName + val = attrs.item(idx).nodeValue + if key == 'name': + self.name = makeValidCppSymbol(val) + + elif key == 'type': + self.type = Type (val, typespec) + if self.type.type.accessor != 'direct': + raise ValueError ("Class properties must have a type with a direct accessor") + + elif key == 'references': + self.ref = val + + elif key == 'access': + self.access = val + + elif key == 'index': + if val != 'y': + raise ValueError ("Expected 'y' in index attribute") + self.isIndex = 1 + + elif key == 'parentRef': + if val != 'y': + raise ValueError ("Expected 'y' in parentRef attribute") + self.isParentRef = 1 + + elif key == 'isGeneralReference': + if val != 'y': + raise ValueError ("Expected 'y' in isGeneralReference attribute") + self.isGeneralRef = 1 + + elif key == 'optional': + if val != 'y': + raise ValueError ("Expected 'y' in optional attribute") + self.isOptional = 1 + + elif key == 'unit': + self.unit = val + + elif key == 'min': + self.min = val + + elif key == 'max': + self.max = val + + elif key == 'maxlen': + self.maxLen = val + + elif key == 'desc': + self.desc = val + + else: + raise ValueError ("Unknown attribute in property '%s'" % key) + + if self.access == "RC" and self.isOptional == 1: + raise ValueError ("Properties with ReadCreate access must not be optional (%s)" % self.name) + + if self.name == None: + raise ValueError ("Missing 'name' attribute in property") + if self.type == None: + raise ValueError ("Missing 'type' attribute in property") + + def getName (self): + return self.name + + def isConstructorArg (self): + if self.access == "RC" and self.isParentRef == 0: + return 1 + return 0 + + def genDeclaration (self, stream, prefix=" "): + stream.write (prefix + self.type.type.cpp + " " + self.name + ";\n") + + def genFormalParam (self, stream, variables): + stream.write (self.type.type.asArg + " _" + self.name) + + def genAccessor (self, stream): + self.type.type.genAccessor (stream, self.name, "configChanged", self.isOptional == 1) + + def genInitialize (self, stream, prefix="", indent=" "): + val = self.type.type.init + stream.write (indent + prefix + self.name + " = " + val + ";\n") + + def genSchema (self, stream): + stream.write (" ft = FieldTable ();\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") + if self.unit != None: + stream.write (" ft.setString (UNIT, \"" + self.unit + "\");\n") + if self.min != None: + stream.write (" ft.setInt (MIN, " + self.min + ");\n") + if self.max != None: + stream.write (" ft.setInt (MAX, " + self.max + ");\n") + if self.maxLen != None: + stream.write (" ft.setInt (MAXLEN, " + self.maxLen + ");\n") + if self.desc != None: + stream.write (" ft.setString (DESC, \"" + self.desc + "\");\n") + stream.write (" buf.put (ft);\n\n") + + def genWrite (self, stream): + indent = " " + if self.isOptional: + stream.write(" if (presenceMask[presenceByte_%s] & presenceMask_%s) {\n" % (self.name, self.name)) + indent = " " + self.type.type.genWrite (stream, self.name, indent) + if self.isOptional: + stream.write(" }\n") + + +#===================================================================================== +# +#===================================================================================== +class SchemaStatistic: + def __init__ (self, node, typespec): + self.name = None + self.type = None + self.unit = None + self.desc = None + self.assign = None + + attrs = node.attributes + for idx in range (attrs.length): + key = attrs.item(idx).nodeName + val = attrs.item(idx).nodeValue + if key == 'name': + self.name = makeValidCppSymbol(val) + + elif key == 'type': + self.type = Type (val, typespec) + + elif key == 'unit': + self.unit = val + + elif key == 'desc': + self.desc = val + + elif key == 'assign': + self.assign = val + + else: + raise ValueError ("Unknown attribute in statistic '%s'" % key) + + if self.name == None: + raise ValueError ("Missing 'name' attribute in statistic") + if self.type == None: + raise ValueError ("Missing 'type' attribute in statistic") + + def getName (self): + return self.name + + def genDeclaration (self, stream, prefix=" "): + if self.type.type.style != "mma": + stream.write (prefix + self.type.type.cpp + " " + self.name + ";\n") + if self.type.type.style == 'wm': + stream.write (prefix + self.type.type.cpp + " " + self.name + "High;\n") + stream.write (prefix + self.type.type.cpp + " " + self.name + "Low;\n") + if self.type.type.style == "mma": + stream.write (prefix + self.type.type.cpp + " " + self.name + "Count;\n") + stream.write (prefix + "uint64_t " + self.name + "Total;\n") + stream.write (prefix + self.type.type.cpp + " " + self.name + "Min;\n") + stream.write (prefix + self.type.type.cpp + " " + self.name + "Max;\n") + + def genAccessor (self, stream): + self.type.type.genAccessor (stream, self.name, "instChanged") + + def genHiLoStatResets (self, stream): + self.type.type.genHiLoStatResets (stream, self.name) + + def genPerThreadHiLoStatResets (self, stream): + self.type.type.genPerThreadHiLoStatResets (stream, self.name, self.type.type.cpp) + + def genSchemaText (self, stream, name, desc): + stream.write (" ft = FieldTable ();\n") + stream.write (" ft.setString (NAME, \"" + name + "\");\n") + stream.write (" ft.setInt (TYPE, TYPE_" + self.type.type.base +");\n") + if self.unit != None: + stream.write (" ft.setString (UNIT, \"" + self.unit + "\");\n") + if desc != None: + stream.write (" ft.setString (DESC, \"" + desc + "\");\n") + stream.write (" buf.put (ft);\n\n") + + def genSchema (self, stream): + if self.type.type.style != "mma": + self.genSchemaText (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.genSchemaText (stream, self.name + "High", descHigh) + self.genSchemaText (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.genSchemaText (stream, self.name + "Samples", descCount) + self.genSchemaText (stream, self.name + "Min", descMin) + self.genSchemaText (stream, self.name + "Max", descMax) + self.genSchemaText (stream, self.name + "Average", descAverage) + + def genAssign (self, stream): + if self.assign != None: + if self.type.type.perThread: + prefix = " threadStats->" + else: + prefix = "" + stream.write (" " + prefix + self.name + " = (" + self.type.type.cpp + + ") (" + self.assign + ");\n") + + def genWrite (self, stream): + if self.type.type.perThread: + self.type.type.genWrite (stream, "totals." + self.name) + else: + self.type.type.genWrite (stream, self.name) + + def genInitialize (self, stream, prefix="", indent=" "): + val = self.type.type.init + if self.type.type.style != "mma": + stream.write (indent + prefix + self.name + " = " + val + ";\n") + if self.type.type.style == "wm": + stream.write (indent + prefix + self.name + "High = " + val + ";\n") + stream.write (indent + prefix + self.name + "Low = " + val + ";\n") + if self.type.type.style == "mma": + stream.write (indent + prefix + self.name + "Count = 0;\n") + stream.write (indent + prefix + self.name + "Min = std::numeric_limits<" + self.type.type.cpp + ">::max();\n") + stream.write (indent + prefix + self.name + "Max = std::numeric_limits<" + self.type.type.cpp + ">::min();\n") + stream.write (indent + prefix + self.name + "Total = 0;\n") + + def genInitializeTotalPerThreadStats (self, stream): + if self.type.type.style == "mma": + stream.write (" totals->" + self.name + "Count = 0;\n") + stream.write (" totals->" + self.name + "Min = std::numeric_limits<" + self.type.type.cpp + ">::max();\n") + stream.write (" totals->" + self.name + "Max = std::numeric_limits<" + self.type.type.cpp + ">::min();\n") + stream.write (" totals->" + self.name + "Total = 0;\n") + else: + stream.write (" totals->" + self.name + " = 0;\n") + + def genAggregatePerThreadStats (self, stream): + if self.type.type.style == "mma": + stream.write (" totals->%sCount += threadStats->%sCount;\n" % (self.name, self.name)) + stream.write (" if (totals->%sMin > threadStats->%sMin)\n" % (self.name, self.name)) + stream.write (" totals->%sMin = threadStats->%sMin;\n" % (self.name, self.name)) + stream.write (" if (totals->%sMax < threadStats->%sMax)\n" % (self.name, self.name)) + stream.write (" totals->%sMax = threadStats->%sMax;\n" % (self.name, self.name)) + stream.write (" totals->%sTotal += threadStats->%sTotal;\n" % (self.name, self.name)) + else: + stream.write (" totals->%s += threadStats->%s;\n" % (self.name, self.name)) + +#===================================================================================== +# +#===================================================================================== +class SchemaArg: + def __init__ (self, node, typespec): + self.name = None + self.type = None + self.unit = None + self.dir = "I" + self.min = None + self.max = None + self.maxLen = None + self.desc = None + self.default = None + self.hash = Hash(node) + + attrs = node.attributes + for idx in range (attrs.length): + key = attrs.item(idx).nodeName + val = attrs.item(idx).nodeValue + if key == 'name': + self.name = makeValidCppSymbol(val) + + elif key == 'type': + self.type = Type (val, typespec) + + elif key == 'unit': + self.unit = val + + elif key == 'dir': + self.dir = val.upper () + + elif key == 'min': + self.min = val + + elif key == 'max': + self.max = val + + elif key == 'maxlen': + self.maxLen = val + + elif key == 'desc': + self.desc = val + + elif key == 'default': + self.default = val + + else: + raise ValueError ("Unknown attribute in arg '%s'" % key) + + if self.name == None: + raise ValueError ("Missing 'name' attribute in arg") + if self.type == None: + raise ValueError ("Missing 'type' attribute in arg") + + def getName (self): + return self.name + + def getDir (self): + return self.dir + + def genSchema (self, stream, event=False): + stream.write (" ft = FieldTable ();\n") + stream.write (" ft.setString (NAME, \"" + self.name + "\");\n") + stream.write (" ft.setInt (TYPE, TYPE_" + self.type.type.base +");\n") + if (not event): + stream.write (" ft.setString (DIR, \"" + self.dir + "\");\n") + if self.unit != None: + stream.write (" ft.setString (UNIT, \"" + self.unit + "\");\n") + if not event: + if self.min != None: + stream.write (" ft.setInt (MIN, " + self.min + ");\n") + if self.max != None: + stream.write (" ft.setInt (MAX, " + self.max + ");\n") + if self.maxLen != None: + stream.write (" ft.setInt (MAXLEN, " + self.maxLen + ");\n") + if self.default != None: + stream.write (" ft.setString (DEFAULT, \"" + self.default + "\");\n") + if self.desc != None: + stream.write (" ft.setString (DESC, \"" + self.desc + "\");\n") + stream.write (" buf.put (ft);\n\n") + + def genFormalParam (self, stream, variables): + stream.write ("%s _%s" % (self.type.type.asArg, self.name)) + +#===================================================================================== +# +#===================================================================================== +class SchemaMethod: + def __init__ (self, parent, node, typespec): + self.parent = parent + self.name = None + self.desc = None + self.args = [] + + attrs = node.attributes + for idx in range (attrs.length): + key = attrs.item(idx).nodeName + val = attrs.item(idx).nodeValue + if key == 'name': + self.name = makeValidCppSymbol(val) + + elif key == 'desc': + self.desc = val + + else: + raise ValueError ("Unknown attribute in method '%s'" % key) + + for child in node.childNodes: + if child.nodeType == Node.ELEMENT_NODE: + if child.nodeName == 'arg': + arg = SchemaArg (child, typespec) + self.args.append (arg) + else: + raise ValueError ("Unknown method tag '%s'" % child.nodeName) + + def getName (self): + return self.name + + def getFullName (self): + return capitalize(self.parent.getName()) + self.name[0:1].upper() +\ + self.name[1:] + + def getArgCount (self): + return len (self.args) + + #=================================================================================== + # Code Generation Functions. The names of these functions (minus the leading "gen") + # match the substitution keywords in the template files. + #=================================================================================== + def genNameUpper (self, stream, variables): + stream.write (self.getFullName ().upper ()) + + def genNameCamel (self, stream, variables): + stream.write (self.getFullName ()) + + def genOpenNamespaces (self, stream, variables): + self.parent.genOpenNamespaces(stream, variables) + + def genCloseNamespaces (self, stream, variables): + self.parent.genCloseNamespaces(stream, variables) + + def genArguments (self, stream, variables): + for arg in self.args: + ctype = arg.type.type.cpp + dirTag = arg.dir.lower() + "_" + stream.write (" " + ctype + " " + dirTag + arg.getName () + ";\n") + + def genNamePackageLower (self, stream, variables): + self.parent.genNamePackageLower(stream, variables) + + def genSchema (self, stream, variables): + stream.write (" ft = FieldTable ();\n") + stream.write (" ft.setString (NAME, \"" + self.name + "\");\n") + stream.write (" ft.setInt (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") + for arg in self.args: + arg.genSchema (stream) + +#===================================================================================== +# +#===================================================================================== +class SchemaEvent: + def __init__ (self, package, node, typespec, argset): + self.packageName = package + self.name = None + self.desc = None + self.sevText = "inform" + self.args = [] + self.hash = Hash(node) + + attrs = node.attributes + for idx in range (attrs.length): + key = attrs.item(idx).nodeName + val = attrs.item(idx).nodeValue + if key == 'name': + self.name = val + + elif key == 'desc': + self.desc = val + + elif key == 'sev': + self.sevText = val + + elif key == 'args': + list = val.replace(" ", "").split(",") + for item in list: + if item not in argset.args: + raise Exception("undefined argument '%s' in event" % item) + self.args.append(argset.args[item]) + self.hash.addSubHash(argset.args[item].hash) + + else: + raise ValueError ("Unknown attribute in event '%s'" % key) + + if self.sevText == "emerg" : self.sev = 0 + elif self.sevText == "alert" : self.sev = 1 + elif self.sevText == "crit" : self.sev = 2 + elif self.sevText == "error" : self.sev = 3 + elif self.sevText == "warn" : self.sev = 4 + elif self.sevText == "notice" : self.sev = 5 + elif self.sevText == "inform" : self.sev = 6 + elif self.sevText == "debug" : self.sev = 7 + else: + raise ValueError("Unknown severity '%s' in event '%s'" % (self.sevText, self.name)) + + def getName (self): + return self.name + + def getNameCap(self): + return capitalize(self.name) + + def getFullName (self): + return capitalize(self.package + capitalize(self.name)) + + def getArgCount (self): + return len (self.args) + + def genArgCount (self, stream, variables): + stream.write("%d" % len(self.args)) + + def genArgDeclarations(self, stream, variables): + for arg in self.args: + if arg.type.type.byRef: + ref = "&" + else: + ref = "" + stream.write(" const %s%s %s;\n" % (arg.type.type.cpp, ref, arg.name)) + + def genCloseNamespaces (self, stream, variables): + for item in self.packageName.split("."): + stream.write ("}") + + def genConstructorArgs(self, stream, variables): + pre = "" + for arg in self.args: + if arg.type.type.byRef: + ref = "&" + else: + ref = "" + stream.write("%sconst %s%s _%s" % (pre, arg.type.type.cpp, ref, arg.name)) + pre = ",\n " + + def genConstructorInits(self, stream, variables): + pre = "" + for arg in self.args: + stream.write("%s%s(_%s)" % (pre, arg.name, arg.name)) + pre = ",\n " + + def genName(self, stream, variables): + stream.write(self.name) + + def genNameCap(self, stream, variables): + stream.write(capitalize(self.name)) + + def genNamespace (self, stream, variables): + stream.write("::".join(self.packageName.split("."))) + + def genNameLower(self, stream, variables): + stream.write(self.name.lower()) + + def genNameUpper(self, stream, variables): + stream.write(self.name.upper()) + + def genNamePackageLower(self, stream, variables): + stream.write(self.packageName.lower()) + + def genOpenNamespaces (self, stream, variables): + for item in self.packageName.split("."): + stream.write ("namespace %s {\n" % item) + + def genSeverity(self, stream, variables): + stream.write("%d" % self.sev) + + def genArgEncodes(self, stream, variables): + for arg in self.args: + 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 genSchemaMD5(self, stream, variables): + sum = self.hash.getDigest() + for idx in range (len (sum)): + if idx != 0: + stream.write (",") + stream.write (hex (ord (sum[idx]))) + + +class SchemaClass: + def __init__ (self, package, node, typespec, fragments, options): + self.packageName = package + self.properties = [] + self.statistics = [] + self.methods = [] + self.events = [] + self.options = options + self.hash = Hash(node) + + attrs = node.attributes + self.name = makeValidCppSymbol(attrs['name'].nodeValue) + + children = node.childNodes + for child in children: + if child.nodeType == Node.ELEMENT_NODE: + if child.nodeName == 'property': + sub = SchemaProperty (child, typespec) + self.properties.append (sub) + + elif child.nodeName == 'statistic': + sub = SchemaStatistic (child, typespec) + self.statistics.append (sub) + + elif child.nodeName == 'method': + sub = SchemaMethod (self, child, typespec) + self.methods.append (sub) + + elif child.nodeName == 'group': + self.expandFragment (child, fragments) + + else: + raise ValueError ("Unknown class tag '%s'" % child.nodeName) + + # Adjust the 'assign' attributes for each statistic + for stat in self.statistics: + if stat.assign != None and stat.type.type.perThread: + stat.assign = self.adjust (stat.assign, self.statistics) + + def adjust (self, text, statistics): + result = text + start = 0 + while True: + next = None + for stat in statistics: + pos = result.find (stat.name, start) + if pos != -1 and (next == None or pos < next[0]): + next = (pos, stat.name) + if next == None: + return result + pos = next[0] + result = result[0:pos] + "threadStats->" + result[pos:] + start = pos + 9 + len(next[1]) + + def expandFragment (self, node, fragments): + attrs = node.attributes + name = attrs['name'].nodeValue + for fragment in fragments: + if fragment.name == name: + self.hash.addSubHash(fragment.hash) + for config in fragment.properties: + self.properties.append (config) + for inst in fragment.statistics: + self.statistics.append (inst) + for method in fragment.methods: + self.methods.append (method) + for event in fragment.events: + self.events.append (event) + return + raise ValueError ("Undefined group '%s'" % name) + + def getName (self): + return self.name + + def getNameCap (self): + return capitalize(self.name) + + def getMethods (self): + return self.methods + + def getEvents (self): + return self.events + + def getPackageNameCap (self): + return capitalize(self.packageName) + + #=================================================================================== + # Code Generation Functions. The names of these functions (minus the leading "gen") + # match the substitution keywords in the template files. + #=================================================================================== + def testExistOptionals (self, variables): + for prop in self.properties: + if prop.isOptional == 1: + return True + return False + + def testExistPerThreadStats (self, variables): + for inst in self.statistics: + if inst.type.type.perThread: + return True + return False + + def testExistPerThreadAssign (self, variables): + for inst in self.statistics: + if inst.type.type.perThread and inst.assign != None: + return True + return False + + def testExistPerThreadResets (self, variables): + for inst in self.statistics: + if inst.type.type.perThread and inst.type.type.style == "mma": + return True + return False + + def testNoStatistics (self, variables): + return len (self.statistics) == 0 + + def genAccessorMethods (self, stream, variables): + for config in self.properties: + if config.access != "RC": + config.genAccessor (stream) + for inst in self.statistics: + if inst.assign == None: + inst.genAccessor (stream) + + def genCloseNamespaces (self, stream, variables): + for item in self.packageName.split("."): + stream.write ("}") + + def genConfigCount (self, stream, variables): + stream.write ("%d" % len (self.properties)) + + def genConfigDeclarations (self, stream, variables): + for element in self.properties: + element.genDeclaration (stream) + + def genConstructorArgs (self, stream, variables): + # Constructor args are config elements with read-create access + result = "" + for element in self.properties: + if element.isConstructorArg (): + stream.write (", ") + element.genFormalParam (stream, variables) + + def genConstructorInits (self, stream, variables): + for element in self.properties: + if element.isConstructorArg (): + stream.write ("," + element.getName () + "(_" + element.getName () + ")") + + def genDoMethodArgs (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&, Buffer&, Buffer& outBuf") + else: + if inArgCount == 0: + stream.write ("string& methodName, Buffer&, Buffer& outBuf") + else: + stream.write ("string& methodName, Buffer& inBuf, Buffer& outBuf") + + def genHiLoStatResets (self, stream, variables): + for inst in self.statistics: + if not inst.type.type.perThread: + inst.genHiLoStatResets (stream) + + def genPerThreadHiLoStatResets (self, stream, variables): + for inst in self.statistics: + if inst.type.type.perThread: + inst.genPerThreadHiLoStatResets (stream) + + def genInitializeElements (self, stream, variables): + for prop in self.properties: + if not prop.isConstructorArg() and not prop.isParentRef: + prop.genInitialize(stream) + for inst in self.statistics: + if not inst.type.type.perThread: + inst.genInitialize (stream) + + def genInitializePerThreadElements (self, stream, variables): + for inst in self.statistics: + if inst.type.type.perThread: + inst.genInitialize (stream, "threadStats->", " ") + + def genInitializeTotalPerThreadStats (self, stream, variables): + for inst in self.statistics: + if inst.type.type.perThread: + inst.genInitializeTotalPerThreadStats (stream) + + def genAggregatePerThreadStats (self, stream, variables): + for inst in self.statistics: + if inst.type.type.perThread: + inst.genAggregatePerThreadStats (stream) + + def genInstCount (self, stream, variables): + count = 0 + for inst in self.statistics: + count = count + 1 + if inst.type.type.style == "wm": + count = count + 2 + if inst.type.type.style == "mma": + count = count + 3 + stream.write ("%d" % count) + + def genInstDeclarations (self, stream, variables): + for element in self.statistics: + if not element.type.type.perThread: + element.genDeclaration (stream) + + def genPerThreadDeclarations (self, stream, variables): + for element in self.statistics: + if element.type.type.perThread: + element.genDeclaration (stream, " ") + + def genNamespace (self, stream, variables): + stream.write("::".join(self.packageName.split("."))) + + def genMethodArgIncludes (self, stream, variables): + for method in self.methods: + if method.getArgCount () > 0: + stream.write ("#include \"Args" + method.getFullName () + ".h\"\n") + + def genMethodCount (self, stream, variables): + stream.write ("%d" % len (self.methods)) + + def genMethodHandlers (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") + for arg in method.args: + if arg.getDir () == "I" or arg.getDir () == "IO": + stream.write (" " +\ + arg.type.type.getReadCode ("ioArgs." +\ + arg.dir.lower () + "_" +\ + arg.name, "inBuf") + ";\n") + + stream.write (" status = coreObject->ManagementMethod (METHOD_" +\ + method.getName().upper() + ", ioArgs, text);\n") + stream.write (" outBuf.putLong (status);\n") + stream.write (" outBuf.putMediumString(::qpid::management::Manageable::StatusText (status, text));\n") + for arg in method.args: + if arg.getDir () == "O" or arg.getDir () == "IO": + stream.write (" " +\ + arg.type.type.getWriteCode ("ioArgs." +\ + arg.dir.lower () + "_" +\ + arg.name, "outBuf") + ";\n") + stream.write (" return;\n }\n") + + def genOpenNamespaces (self, stream, variables): + for item in self.packageName.split("."): + stream.write ("namespace %s {\n" % item) + + def genPresenceMaskBytes (self, stream, variables): + count = 0 + for prop in self.properties: + if prop.isOptional == 1: + count += 1 + if count == 0: + stream.write("0") + else: + stream.write (str(((count - 1) / 8) + 1)) + + def genPresenceMaskConstants (self, stream, variables): + count = 0 + for prop in self.properties: + if prop.isOptional == 1: + stream.write(" static const uint8_t presenceByte_%s = %d;\n" % (prop.name, count / 8)) + stream.write(" static const uint8_t presenceMask_%s = %d;\n" % (prop.name, 1 << (count % 8))) + count += 1 + + def genPropertySchema (self, stream, variables): + for prop in self.properties: + prop.genSchema (stream) + + def genSetGeneralReferenceDeclaration (self, stream, variables): + for prop in self.properties: + if prop.isGeneralRef: + stream.write ("void setReference(::qpid::management::ObjectId objectId) { " + prop.name + " = objectId; }\n") + + def genStatisticSchema (self, stream, variables): + for stat in self.statistics: + stat.genSchema (stream) + + def genMethodIdDeclarations (self, stream, variables): + number = 1 + for method in self.methods: + stream.write (" static const uint32_t METHOD_" + method.getName().upper() +\ + " = %d;\n" % number) + number = number + 1 + + def genMethodSchema (self, stream, variables): + for method in self.methods: + method.genSchema (stream, variables) + + def genNameCap (self, stream, variables): + stream.write (capitalize(self.name)) + + def genNameLower (self, stream, variables): + stream.write (self.name.lower ()) + + def genNamePackageCap (self, stream, variables): + stream.write (self.getPackageNameCap ()) + + def genNamePackageLower (self, stream, variables): + stream.write (self.packageName.lower ()) + + def genNameUpper (self, stream, variables): + stream.write (self.name.upper ()) + + def genParentArg (self, stream, variables): + for config in self.properties: + if config.isParentRef == 1: + stream.write (", ::qpid::management::Manageable* _parent") + return + + def genParentRefAssignment (self, stream, variables): + for config in self.properties: + if config.isParentRef == 1: + stream.write (config.getName () + \ + " = _parent->GetManagementObject ()->getObjectId ();") + return + + def genSchemaMD5 (self, stream, variables): + sum = self.hash.getDigest() + for idx in range (len (sum)): + if idx != 0: + stream.write (",") + stream.write (hex (ord (sum[idx]))) + + def genAssign (self, stream, variables): + for inst in self.statistics: + if not inst.type.type.perThread: + inst.genAssign (stream) + + def genPerThreadAssign (self, stream, variables): + for inst in self.statistics: + if inst.type.type.perThread: + inst.genAssign (stream) + + def genWriteProperties (self, stream, variables): + for prop in self.properties: + prop.genWrite (stream) + + def genWriteStatistics (self, stream, variables): + for stat in self.statistics: + stat.genWrite (stream) + + +class SchemaEventArgs: + def __init__(self, package, node, typespec, fragments, options): + self.packageName = package + self.options = options + self.args = {} + + children = node.childNodes + for child in children: + if child.nodeType == Node.ELEMENT_NODE: + if child.nodeName == 'arg': + arg = SchemaArg(child, typespec) + self.args[arg.name] = arg + else: + raise Exception("Unknown tag '%s' in <eventArguments>" % child.nodeName) + +class SchemaPackage: + def __init__ (self, typefile, schemafile, options): + + self.classes = [] + self.fragments = [] + self.typespec = TypeSpec (typefile) + self.eventArgSet = None + self.events = [] + + dom = parse (schemafile) + document = dom.documentElement + if document.tagName != 'schema': + raise ValueError ("Expected 'schema' node") + attrs = document.attributes + pname = attrs['package'].nodeValue + namelist = pname.split('.') + self.packageName = ".".join(namelist) + + children = document.childNodes + for child in children: + if child.nodeType == Node.ELEMENT_NODE: + if child.nodeName == 'class': + cls = SchemaClass (self.packageName, child, self.typespec, + self.fragments, options) + self.classes.append (cls) + + elif child.nodeName == 'group': + cls = SchemaClass (self.packageName, child, self.typespec, + self.fragments, options) + self.fragments.append (cls) + + elif child.nodeName == 'eventArguments': + if self.eventArgSet: + raise Exception("Only one <eventArguments> may appear in a package") + self.eventArgSet = SchemaEventArgs(self.packageName, child, self.typespec, self.fragments, options) + + elif child.nodeName == 'event': + event = SchemaEvent(self.packageName, child, self.typespec, self.eventArgSet) + self.events.append(event) + + else: + raise ValueError ("Unknown schema tag '%s'" % child.nodeName) + + def getPackageName (self): + return self.packageName + + def getPackageNameCap (self): + return capitalize(self.packageName) + + def getPackageNameLower (self): + return self.packageName.lower() + + def getClasses (self): + return self.classes + + def getEvents(self): + return self.events + + def genCloseNamespaces (self, stream, variables): + for item in self.packageName.split("."): + stream.write ("}") + + def genNamespace (self, stream, variables): + stream.write("::".join(self.packageName.split("."))) + + def genOpenNamespaces (self, stream, variables): + for item in self.packageName.split("."): + stream.write ("namespace %s {\n" % item) + + def genPackageNameUpper (self, stream, variables): + up = "_".join(self.packageName.split(".")) + stream.write (up.upper()) + + def genNamePackageLower (self, stream, variables): + stream.write (self.packageName.lower ()) + + def genClassIncludes (self, stream, variables): + for _class in self.classes: + stream.write ("#include \"") + _class.genNameCap (stream, variables) + stream.write (".h\"\n") + for _event in self.events: + stream.write ("#include \"Event") + _event.genNameCap(stream, variables) + stream.write (".h\"\n") + + def genClassRegisters(self, stream, variables): + for _class in self.classes: + stream.write(" ") + _class.genNameCap(stream, variables) + stream.write("::registerSelf(agent);\n") + for _event in self.events: + stream.write(" Event") + _event.genNameCap(stream, variables) + stream.write("::registerSelf(agent);\n") + + +#===================================================================================== +# Utility Functions +#===================================================================================== + +# Create a valid C++ symbol from the input string so that it can be +# used in generated C++ source. For instance, change "qpid.mgmt" to +# "qpidMgmt". +# +# Input: Raw string (str) to process +# Output: String (str) suitable for use as a C++ symbol +# +# Limitations: Currently, only strips periods ('.') from strings, +# eventually should strip :'s and ,'s and ''s, oh my! +def makeValidCppSymbol(input): + output = str() + capitalize = False + + for char in input: + skip = False + + if char == ".": + capitalize = True + skip = True + + if not skip: + output += capitalize and char.upper() or char + + capitalize = False + + return output + +# Capitalize a string by /only/ forcing the first character to be +# uppercase. The rest of the string is left alone. This is different +# from str.capitalize(), which forces the first character to uppercase +# and the rest to lowercase. +# +# Input: A string (str) to capitalize +# Output: A string (str) with the first character as uppercase +def capitalize(input): + return input[0].upper() + input[1:] diff --git a/cpp/managementgen/qmfgen/templates/Args.h b/cpp/managementgen/qmfgen/templates/Args.h new file mode 100644 index 0000000000..074ccf9940 --- /dev/null +++ b/cpp/managementgen/qmfgen/templates/Args.h @@ -0,0 +1,42 @@ +/*MGEN:commentPrefix=//*/ +#ifndef _ARGS_/*MGEN:Method.NameUpper*/_ +#define _ARGS_/*MGEN:Method.NameUpper*/_ + +// +// 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. +// + +/*MGEN:Root.Disclaimer*/ + +#include "qpid/management/Args.h" +#include "qpid/framing/FieldTable.h" +#include "qpid/framing/Uuid.h" +#include <string> + +namespace qmf { +/*MGEN:Method.OpenNamespaces*/ + + class Args/*MGEN:Method.NameCamel*/ : public ::qpid::management::Args +{ + public: +/*MGEN:Method.Arguments*/ +}; + +}/*MGEN:Method.CloseNamespaces*/ + +#endif /*!_ARGS_/*MGEN:Method.NameUpper*/_*/ diff --git a/cpp/managementgen/qmfgen/templates/Class.cpp b/cpp/managementgen/qmfgen/templates/Class.cpp new file mode 100644 index 0000000000..247e1090ff --- /dev/null +++ b/cpp/managementgen/qmfgen/templates/Class.cpp @@ -0,0 +1,181 @@ +/*MGEN:commentPrefix=//*/ +// +// 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. +// + +/*MGEN:Root.Disclaimer*/ + +#include "qpid/log/Statement.h" +#include "qpid/framing/FieldTable.h" +#include "qpid/management/Manageable.h" +#include "qpid/agent/ManagementAgent.h" +#include "/*MGEN:Class.NameCap*/.h" +/*MGEN:Class.MethodArgIncludes*/ + +using namespace qmf::/*MGEN:Class.Namespace*/; +using namespace qpid::framing; +using qpid::management::ManagementAgent; +using qpid::management::Manageable; +using qpid::management::ManagementObject; +using qpid::management::Args; +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] = + {/*MGEN:Class.SchemaMD5*/}; + +/*MGEN:Class.NameCap*/::/*MGEN:Class.NameCap*/ (ManagementAgent* _agent, Manageable* _core/*MGEN:Class.ParentArg*//*MGEN:Class.ConstructorArgs*/) : + ManagementObject(_agent, _core)/*MGEN:Class.ConstructorInits*/ +{ + /*MGEN:Class.ParentRefAssignment*/ +/*MGEN:Class.InitializeElements*/ +/*MGEN:IF(Class.ExistOptionals)*/ + // Optional properties start out not-present + for (uint8_t idx = 0; idx < /*MGEN:Class.PresenceMaskBytes*/; idx++) + presenceMask[idx] = 0; +/*MGEN:ENDIF*/ +/*MGEN:IF(Class.ExistPerThreadStats)*/ + maxThreads = agent->getMaxThreads(); + perThreadStatsArray = new struct PerThreadStats*[maxThreads]; + for (int idx = 0; idx < maxThreads; idx++) + perThreadStatsArray[idx] = 0; +/*MGEN:ENDIF*/ +} + +/*MGEN:Class.NameCap*/::~/*MGEN:Class.NameCap*/ () +{ +/*MGEN:IF(Class.ExistPerThreadStats)*/ + for (int idx = 0; idx < maxThreads; idx++) + if (perThreadStatsArray[idx] != 0) + delete perThreadStatsArray[idx]; + delete[] perThreadStatsArray; +/*MGEN:ENDIF*/ +} + +namespace { + const string NAME("name"); + const string TYPE("type"); + const string ACCESS("access"); + const string IS_INDEX("index"); + const string IS_OPTIONAL("optional"); + const string UNIT("unit"); + const string MIN("min"); + const string MAX("max"); + const string MAXLEN("maxlen"); + const string DESC("desc"); + const string ARGCOUNT("argCount"); + const string ARGS("args"); + const string DIR("dir"); + const string DEFAULT("default"); +} + +void /*MGEN:Class.NameCap*/::registerSelf(ManagementAgent* agent) +{ + agent->registerClass(packageName, className, md5Sum, writeSchema); +} + +void /*MGEN:Class.NameCap*/::writeSchema (Buffer& buf) +{ + FieldTable ft; + + // Schema class header: + buf.putOctet (CLASS_KIND_TABLE); + buf.putShortString (packageName); // Package Name + buf.putShortString (className); // Class Name + buf.putBin128 (md5Sum); // Schema Hash + buf.putShort (/*MGEN:Class.ConfigCount*/); // Config Element Count + buf.putShort (/*MGEN:Class.InstCount*/); // Inst Element Count + buf.putShort (/*MGEN:Class.MethodCount*/); // Method Count + + // Properties +/*MGEN:Class.PropertySchema*/ + // Statistics +/*MGEN:Class.StatisticSchema*/ + // Methods +/*MGEN:Class.MethodSchema*/ +} + +/*MGEN:IF(Class.ExistPerThreadStats)*/ +void /*MGEN:Class.NameCap*/::aggregatePerThreadStats(struct PerThreadStats* totals) +{ +/*MGEN:Class.InitializeTotalPerThreadStats*/ + for (int idx = 0; idx < maxThreads; idx++) { + struct PerThreadStats* threadStats = perThreadStatsArray[idx]; + if (threadStats != 0) { +/*MGEN:Class.AggregatePerThreadStats*/ + } + } +} +/*MGEN:ENDIF*/ + +void /*MGEN:Class.NameCap*/::writeProperties (Buffer& buf) +{ + ::qpid::sys::Mutex::ScopedLock mutex(accessLock); + configChanged = false; + + writeTimestamps (buf); +/*MGEN:IF(Class.ExistOptionals)*/ + for (uint8_t idx = 0; idx < /*MGEN:Class.PresenceMaskBytes*/; idx++) + buf.putOctet(presenceMask[idx]); +/*MGEN:ENDIF*/ +/*MGEN:Class.WriteProperties*/ +} + +void /*MGEN:Class.NameCap*/::writeStatistics (Buffer& buf, bool skipHeaders) +{ + ::qpid::sys::Mutex::ScopedLock mutex(accessLock); + 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*/ + if (!skipHeaders) + writeTimestamps (buf); +/*MGEN:Class.WriteStatistics*/ + + // 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*/::doMethod (/*MGEN:Class.DoMethodArgs*/) +{ + Manageable::status_t status = Manageable::STATUS_UNKNOWN_METHOD; + std::string text; + +/*MGEN:Class.MethodHandlers*/ + outBuf.putLong(status); + outBuf.putShortString(Manageable::StatusText(status, text)); +} diff --git a/cpp/managementgen/qmfgen/templates/Class.h b/cpp/managementgen/qmfgen/templates/Class.h new file mode 100644 index 0000000000..7796914d51 --- /dev/null +++ b/cpp/managementgen/qmfgen/templates/Class.h @@ -0,0 +1,104 @@ +/*MGEN:commentPrefix=//*/ +#ifndef _MANAGEMENT_/*MGEN:Class.NameUpper*/_ +#define _MANAGEMENT_/*MGEN:Class.NameUpper*/_ + +// +// 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. +// + +/*MGEN:Root.Disclaimer*/ + +#include "qpid/management/ManagementObject.h" +#include "qpid/framing/FieldTable.h" +#include "qpid/framing/Uuid.h" + +namespace qmf { +/*MGEN:Class.OpenNamespaces*/ + +class /*MGEN:Class.NameCap*/ : public ::qpid::management::ManagementObject +{ + private: + + static std::string packageName; + static std::string className; + static uint8_t md5Sum[16]; +/*MGEN:IF(Class.ExistOptionals)*/ + uint8_t presenceMask[/*MGEN:Class.PresenceMaskBytes*/]; +/*MGEN:Class.PresenceMaskConstants*/ +/*MGEN:ENDIF*/ + + // Properties +/*MGEN:Class.ConfigDeclarations*/ + // Statistics +/*MGEN:Class.InstDeclarations*/ +/*MGEN:IF(Class.ExistPerThreadStats)*/ + // Per-Thread Statistics + struct PerThreadStats { +/*MGEN:Class.PerThreadDeclarations*/ + }; + + struct PerThreadStats** perThreadStatsArray; + + inline struct PerThreadStats* getThreadStats() { + int idx = getThreadIndex(); + struct PerThreadStats* threadStats = perThreadStatsArray[idx]; + if (threadStats == 0) { + threadStats = new(PerThreadStats); + perThreadStatsArray[idx] = threadStats; +/*MGEN:Class.InitializePerThreadElements*/ + } + return threadStats; + } + + void aggregatePerThreadStats(struct PerThreadStats*); +/*MGEN:ENDIF*/ + // Private Methods + static void writeSchema (::qpid::framing::Buffer& buf); + void writeProperties (::qpid::framing::Buffer& buf); + void writeStatistics (::qpid::framing::Buffer& buf, + bool skipHeaders = false); + void doMethod (std::string& methodName, + ::qpid::framing::Buffer& inBuf, + ::qpid::framing::Buffer& outBuf); + writeSchemaCall_t getWriteSchemaCall(void) { return writeSchema; } +/*MGEN:IF(Class.NoStatistics)*/ + // Stub for getInstChanged. There are no statistics in this class. + bool getInstChanged (void) { return false; } +/*MGEN:ENDIF*/ + public: + + /*MGEN:Class.NameCap*/ (::qpid::management::ManagementAgent* agent, + ::qpid::management::Manageable* coreObject/*MGEN:Class.ParentArg*//*MGEN:Class.ConstructorArgs*/); + ~/*MGEN:Class.NameCap*/ (void); + + /*MGEN:Class.SetGeneralReferenceDeclaration*/ + + static void registerSelf (::qpid::management::ManagementAgent* agent); + std::string& getPackageName (void) const { return packageName; } + std::string& getClassName (void) const { return className; } + uint8_t* getMd5Sum (void) const { return md5Sum; } + + // Method IDs +/*MGEN:Class.MethodIdDeclarations*/ + // Accessor Methods +/*MGEN:Class.AccessorMethods*/ +}; + +}/*MGEN:Class.CloseNamespaces*/ + +#endif /*!_MANAGEMENT_/*MGEN:Class.NameUpper*/_*/ diff --git a/cpp/managementgen/qmfgen/templates/Event.cpp b/cpp/managementgen/qmfgen/templates/Event.cpp new file mode 100644 index 0000000000..cdb40c6d79 --- /dev/null +++ b/cpp/managementgen/qmfgen/templates/Event.cpp @@ -0,0 +1,77 @@ +/*MGEN:commentPrefix=//*/ +// +// 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. +// + +/*MGEN:Root.Disclaimer*/ + +#include "qpid/log/Statement.h" +#include "qpid/framing/FieldTable.h" +#include "qpid/management/Manageable.h" +#include "qpid/agent/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; +using qpid::management::Args; +using std::string; + +string Event/*MGEN:Event.NameCap*/::packageName = string ("/*MGEN:Event.NamePackageLower*/"); +string Event/*MGEN:Event.NameCap*/::eventName = string ("/*MGEN:Event.Name*/"); +uint8_t Event/*MGEN:Event.NameCap*/::md5Sum[16] = + {/*MGEN:Event.SchemaMD5*/}; + +Event/*MGEN:Event.NameCap*/::Event/*MGEN:Event.NameCap*/ (/*MGEN:Event.ConstructorArgs*/) : + /*MGEN:Event.ConstructorInits*/ +{} + +namespace { + const string NAME("name"); + const string TYPE("type"); + const string DESC("desc"); + const string ARGCOUNT("argCount"); + const string ARGS("args"); +} + +void Event/*MGEN:Event.NameCap*/::registerSelf(ManagementAgent* agent) +{ + agent->registerEvent(packageName, eventName, md5Sum, writeSchema); +} + +void Event/*MGEN:Event.NameCap*/::writeSchema (Buffer& buf) +{ + 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.putShort (/*MGEN:Event.ArgCount*/); // Argument Count + + // Arguments +/*MGEN:Event.ArgSchema*/ +} + +void Event/*MGEN:Event.NameCap*/::encode(::qpid::framing::Buffer& buf) const +{ +/*MGEN:Event.ArgEncodes*/ +} diff --git a/cpp/managementgen/qmfgen/templates/Event.h b/cpp/managementgen/qmfgen/templates/Event.h new file mode 100644 index 0000000000..b5c2a211d1 --- /dev/null +++ b/cpp/managementgen/qmfgen/templates/Event.h @@ -0,0 +1,59 @@ +/*MGEN:commentPrefix=//*/ +#ifndef _MANAGEMENT_/*MGEN:Event.NameUpper*/_ +#define _MANAGEMENT_/*MGEN:Event.NameUpper*/_ + +// +// 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. +// + +/*MGEN:Root.Disclaimer*/ + +#include "qpid/management/ManagementEvent.h" +#include "qpid/framing/FieldTable.h" +#include "qpid/framing/Uuid.h" + +namespace qmf { +/*MGEN:Event.OpenNamespaces*/ + +class Event/*MGEN:Event.NameCap*/ : public ::qpid::management::ManagementEvent +{ + private: + static void writeSchema (::qpid::framing::Buffer& buf); + static std::string packageName; + static std::string eventName; + static uint8_t md5Sum[16]; + +/*MGEN:Event.ArgDeclarations*/ + + public: + writeSchemaCall_t getWriteSchemaCall(void) { return writeSchema; } + + Event/*MGEN:Event.NameCap*/(/*MGEN:Event.ConstructorArgs*/); + ~Event/*MGEN:Event.NameCap*/() {}; + + static void registerSelf(::qpid::management::ManagementAgent* agent); + std::string& getPackageName() const { return packageName; } + 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; +}; + +}/*MGEN:Event.CloseNamespaces*/ + +#endif /*!_MANAGEMENT_/*MGEN:Event.NameUpper*/_*/ diff --git a/cpp/managementgen/qmfgen/templates/Makefile.mk b/cpp/managementgen/qmfgen/templates/Makefile.mk new file mode 100644 index 0000000000..2b32c7c0f2 --- /dev/null +++ b/cpp/managementgen/qmfgen/templates/Makefile.mk @@ -0,0 +1,40 @@ +# +# 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. +# +/*MGEN:commentPrefix=#*/ +/*MGEN:Root.Disclaimer*/ +/*MGEN:IF(Makefile.QpidBroker)*/ +/*MGEN:mgenDir=$(mgen_dir)*/ +/*MGEN:specDir=$(top_srcdir)/../specs*/ + +mgen_generator=/*MGEN:Makefile.GenSources*/ + +mgen_broker_cpp=/*MGEN:Makefile.GenCppFiles*/ + +# Header file install rules. +/*MGEN:Makefile.HeaderInstalls*/ +if GENERATE +$(srcdir)/managementgen.mk: $(mgen_generator) + $(mgen_cmd) + +$(mgen_generator): +endif +/*MGEN:ENDIF*/ + +qmfgen_sources=/*MGEN:Makefile.GeneratedFiles*/ + diff --git a/cpp/managementgen/qmfgen/templates/Package.cpp b/cpp/managementgen/qmfgen/templates/Package.cpp new file mode 100644 index 0000000000..f6bd7f4654 --- /dev/null +++ b/cpp/managementgen/qmfgen/templates/Package.cpp @@ -0,0 +1,32 @@ +/*MGEN:commentPrefix=//*/ +// +// 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. +// + +/*MGEN:Root.Disclaimer*/ + +#include "Package.h" +/*MGEN:Schema.ClassIncludes*/ + +using namespace qmf::/*MGEN:Schema.Namespace*/; + +Package::Package (::qpid::management::ManagementAgent* agent) +{ +/*MGEN:Schema.ClassRegisters*/ +} + diff --git a/cpp/managementgen/qmfgen/templates/Package.h b/cpp/managementgen/qmfgen/templates/Package.h new file mode 100644 index 0000000000..0ad7060b9e --- /dev/null +++ b/cpp/managementgen/qmfgen/templates/Package.h @@ -0,0 +1,41 @@ +/*MGEN:commentPrefix=//*/ +#ifndef _MANAGEMENT_PACKAGE_/*MGEN:Schema.PackageNameUpper*/_ +#define _MANAGEMENT_PACKAGE_/*MGEN:Schema.PackageNameUpper*/_ + +// +// 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. +// + +/*MGEN:Root.Disclaimer*/ + +#include "qpid/agent/ManagementAgent.h" + +namespace qmf { +/*MGEN:Class.OpenNamespaces*/ + +class Package +{ + public: + Package (::qpid::management::ManagementAgent* agent); + ~Package () {} +}; + +}/*MGEN:Class.CloseNamespaces*/ + + +#endif /*!_MANAGEMENT_PACKAGE_/*MGEN:Schema.PackageNameUpper*/_*/ |