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 <b...@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(-) diff --git a/ovsdb/ovsdb-idlc.1 b/ovsdb/ovsdb-idlc.1 index af68e93e16f8..e1910d9dce66 100644 --- a/ovsdb/ovsdb-idlc.1 +++ b/ovsdb/ovsdb-idlc.1 @@ -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 diff --git a/ovsdb/ovsdb-idlc.in b/ovsdb/ovsdb-idlc.in index 2edb9ef54eda..95bb9f4ca9e0 100755 --- a/ovsdb/ovsdb-idlc.in +++ b/ovsdb/ovsdb-idlc.in @@ -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()): diff --git a/python/ovs/db/schema.py b/python/ovs/db/schema.py index b68c19e00e0b..5f1f6c41a52b 100644 --- a/python/ovs/db/schema.py +++ b/python/ovs/db/schema.py @@ -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): -- 2.16.1 _______________________________________________ dev mailing list d...@openvswitch.org https://mail.openvswitch.org/mailman/listinfo/ovs-dev