]> git.proxmox.com Git - ovs.git/commitdiff
ovsdb-idlc: Add "cDecls" and "hDecls" IDL schema extensions.
authorBen Pfaff <blp@ovn.org>
Wed, 7 Sep 2016 22:23:44 +0000 (15:23 -0700)
committerBen Pfaff <blp@ovn.org>
Fri, 16 Feb 2018 23:08:08 +0000 (15:08 -0800)
An IDL schema is an OVSDB schema with some extra stuff in it: an idlPrefix
and an idlHeader at the top level to indicate what ovsdb-idlc needs to
generate the interface definitions.  This commit adds support for two more
optional IDL schema extensions that allow extra code to be written to the
.c and .h file that ovsdb-idlc generates.

Signed-off-by: Ben Pfaff <blp@ovn.org>
ovsdb/ovsdb-idlc.1
ovsdb/ovsdb-idlc.in
python/ovs/db/schema.py

index af68e93e16f88c95e94c4e48e028c386029047dd..e1910d9dce6684d61202eaa10599d8cc00d24f74 100644 (file)
@@ -39,6 +39,12 @@ It will be output on an \fB#include\fR line in the source file
 generated by the C bindings.  It should include the bracketing
 \fB""\fR or \fB<>\fR.
 .
+.IP "\fB""\fBcDecls\fR"" member of <database-schema>"
+.IQ "\fB""\fBhDecls\fR"" member of <database-schema>"
+These optional members may specify arbitrary code to include in the
+generated \fB.c\fR or \fB.h\fR file, respectively, in each case just
+after the \fB#include\fR directives in those files.
+.
 .SS "Commands"
 .IP "\fBannotate\fI schema annotations\fR"
 Reads \fIschema\fR, which should be a file in JSON format (ordinarily
index 2edb9ef54edac1ed206a6d8754e8c2378e399bdc..95bb9f4ca9e0c0c18074fd9a3e8225e2d74126b5 100755 (executable)
@@ -167,7 +167,8 @@ def printCIDLHeader(schemaFile):
 #ifdef  __cplusplus
 extern "C" {
 #endif
-''' % {'prefix': prefix.upper()})
+%(hDecls)s''' % {'prefix': prefix.upper(),
+                'hDecls': schema.hDecls})
 
     for tableName, table in sorted(schema.tables.items()):
         structName = "%s%s" % (prefix, tableName.lower())
@@ -359,14 +360,17 @@ def printCIDLSource(schemaFile):
 /* Generated automatically -- do not modify!    -*- buffer-read-only: t -*- */
 
 #include <config.h>
-#include %s
+#include %(header)s
 #include <limits.h>
 #include "ovs-thread.h"
 #include "ovsdb-data.h"
 #include "ovsdb-error.h"
 #include "util.h"
 
-''' % schema.idlHeader)
+%(cDecls)s
+
+''' % {'header': schema.idlHeader,
+       'cDecls': schema.cDecls})
 
     # Cast functions.
     for tableName, table in sorted(schema.tables.items()):
index b68c19e00e0ba19422b01167d2cecdddb106e8f2..5f1f6c41a52b1b223ac5dd08b468ebd7b9951e74 100644 (file)
@@ -125,24 +125,31 @@ class DbSchema(object):
 
 
 class IdlSchema(DbSchema):
-    def __init__(self, name, version, tables, idlPrefix, idlHeader):
+    def __init__(self, name, version, tables, idlPrefix, idlHeader,
+                 cDecls, hDecls):
         DbSchema.__init__(self, name, version, tables)
         self.idlPrefix = idlPrefix
         self.idlHeader = idlHeader
+        self.cDecls = cDecls
+        self.hDecls = hDecls
 
     @staticmethod
     def from_json(json):
         parser = ovs.db.parser.Parser(json, "IDL schema")
         idlPrefix = parser.get("idlPrefix", six.string_types)
         idlHeader = parser.get("idlHeader", six.string_types)
+        cDecls = parser.get_optional("cDecls", six.string_types, "")
+        hDecls = parser.get_optional("hDecls", six.string_types, "")
 
         subjson = dict(json)
         del subjson["idlPrefix"]
         del subjson["idlHeader"]
+        subjson.pop("cDecls", None)
+        subjson.pop("hDecls", None)
         schema = DbSchema.from_json(subjson)
 
         return IdlSchema(schema.name, schema.version, schema.tables,
-                         idlPrefix, idlHeader)
+                         idlPrefix, idlHeader, cDecls, hDecls)
 
 
 def column_set_from_json(json, columns):