@@ -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
@@ -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()):
@@ -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):
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 | 6 ++++++ ovsdb/ovsdb-idlc.in | 10 +++++++--- python/ovs/db/schema.py | 11 +++++++++-- 3 files changed, 22 insertions(+), 5 deletions(-)