X-Git-Url: https://pintos-os.org/cgi-bin/gitweb.cgi?a=blobdiff_plain;f=ovsdb%2Fovsdb-idlc.in;h=6c33f07847ca17039cbf826cfacae3ecab2a292b;hb=c393047875e2c9dc76b2f19092fff6bbf69ec4f9;hp=c01034882dbfe9a21833dd65b71a6d4cfd0ac033;hpb=ce5a3e38dacd8042dd7c4de7be24aca9c2887103;p=openvswitch diff --git a/ovsdb/ovsdb-idlc.in b/ovsdb/ovsdb-idlc.in index c0103488..6c33f078 100755 --- a/ovsdb/ovsdb-idlc.in +++ b/ovsdb/ovsdb-idlc.in @@ -124,6 +124,7 @@ def printCIDLHeader(schemaFile): #include #include #include +#include "ovsdb-data.h" #include "ovsdb-idl-provider.h" #include "uuid.h"''' % {'prefix': prefix.upper()} @@ -174,6 +175,18 @@ struct %(s)s *%(s)s_insert(struct ovsdb_idl_txn *); for columnName, column in sorted(table.columns.iteritems()): print 'void %(s)s_verify_%(c)s(const struct %(s)s *);' % {'s': structName, 'c': columnName} + print """ +/* Functions for fetching columns as \"struct ovsdb_datum\"s. (This is + rarely useful. More often, it is easier to access columns by using + the members of %(s)s directly.) */""" % {'s': structName} + for columnName, column in sorted(table.columns.iteritems()): + if column.type.value: + valueParam = ', enum ovsdb_atomic_type value_type' + else: + valueParam = '' + print 'const struct ovsdb_datum *%(s)s_get_%(c)s(const struct %(s)s *, enum ovsdb_atomic_type key_type%(v)s);' % { + 's': structName, 'c': columnName, 'v': valueParam} + print for columnName, column in sorted(table.columns.iteritems()): @@ -311,7 +324,7 @@ static void print "%sif (!row->n_%s) {" % (indent, columnName) print "%s %s = xmalloc(%s * sizeof *%s);" % (indent, keyVar, nMax, keyVar) if valueVar: - print "%s %s = xmalloc(%s * sizeof %s);" % (indent, valueVar, nMax, valueVar) + print "%s %s = xmalloc(%s * sizeof *%s);" % (indent, valueVar, nMax, valueVar) print "%s}" % indent print "%s%s[row->n_%s] = %s;" % (indent, keyVar, columnName, keySrc) if valueVar: @@ -398,6 +411,42 @@ void 'c': columnName, 'C': columnName.upper()} + # Get functions. + for columnName, column in sorted(table.columns.iteritems()): + if column.type.value: + valueParam = ',\n\tenum ovsdb_atomic_type value_type OVS_UNUSED' + valueType = '\n assert(value_type == %s);' % column.type.value.toAtomicType() + valueComment = "\n * 'value_type' must be %s." % column.type.value.toAtomicType() + else: + valueParam = '' + valueType = '' + valueComment = '' + print """ +/* Returns the %(c)s column's value in 'row' as a struct ovsdb_datum. + * This is useful occasionally: for example, ovsdb_datum_find_key() is an + * easier and more efficient way to search for a given key than implementing + * the same operation on the "cooked" form in 'row'. + * + * 'key_type' must be %(kt)s.%(vc)s + * (This helps to avoid silent bugs if someone changes %(c)s's + * type without updating the caller.) + * + * The caller must not modify or free the returned value. + * + * Various kinds of changes can invalidate the returned value: modifying + * 'column' within 'row', deleting 'row', or completing an ongoing transaction. + * If the returned value is needed for a long time, it is best to make a copy + * of it with ovsdb_datum_clone(). */ +const struct ovsdb_datum * +%(s)s_get_%(c)s(const struct %(s)s *row, +\tenum ovsdb_atomic_type key_type OVS_UNUSED%(v)s) +{ + assert(key_type == %(kt)s);%(vt)s + return ovsdb_idl_read(&row->header_, &%(s)s_col_%(c)s); +}""" % {'s': structName, 'c': columnName, + 'kt': column.type.key.toAtomicType(), + 'v': valueParam, 'vt': valueType, 'vc': valueComment} + # Set functions. for columnName, column in sorted(table.columns.iteritems()): type = column.type @@ -456,6 +505,12 @@ void if type.value: print " " + type.value.copyCValue("datum.values[i].%s" % type.value.type, "%s[i]" % valueVar) print " }" + if type.value: + valueType = type.value.toAtomicType() + else: + valueType = "OVSDB_TYPE_VOID" + print " ovsdb_datum_sort_unique(&datum, %s, %s);" % ( + type.key.toAtomicType(), valueType) print " ovsdb_idl_txn_write(&row->header_, &%(s)s_columns[%(S)s_COL_%(C)s], &datum);" \ % {'s': structName, 'S': structName.upper(),