X-Git-Url: https://pintos-os.org/cgi-bin/gitweb.cgi?a=blobdiff_plain;f=ovsdb%2Fovsdb-idlc.in;h=dfde735aac4e8b9f2c0f0efbfff3b3bb64931612;hb=b23cdad927a3b7f282e30d358be2c93597f8b9a3;hp=089bc23d8c80545fc277000100977d7b84c15300;hpb=1bf2c909685893c75f61c63a41928c9ec11c06f1;p=openvswitch diff --git a/ovsdb/ovsdb-idlc.in b/ovsdb/ovsdb-idlc.in index 089bc23d..dfde735a 100755 --- a/ovsdb/ovsdb-idlc.in +++ b/ovsdb/ovsdb-idlc.in @@ -25,6 +25,12 @@ def constify(cType, const): else: return cType +def is_string_map(column): + return (column.type.key + and column.type.value + and column.type.key.type == ovs.db.types.StringType + and column.type.value.type == ovs.db.types.StringType) + def cMembers(prefix, columnName, column, const): type = column.type if type.n_min == 1 and type.n_max == 1: @@ -140,6 +146,15 @@ struct %(s)s *%(s)s_insert(struct ovsdb_idl_txn *); in cMembers(prefix, columnName, column, True)] print '%s);' % ', '.join(args) + print + for columnName, column in sorted(table.columns.iteritems()): + if not is_string_map(column): + continue + print "const char *%(s)s_get_%(c)s_value(const struct %(s)s *," \ + " const char *key, const char *default_value);" \ + % {'s': structName, 'c': columnName} + + # Table indexes. printEnum(["%sTABLE_%s" % (prefix.upper(), tableName.upper()) for tableName in sorted(schema.tables)] + ["%sN_TABLES" % prefix.upper()]) print @@ -188,6 +203,22 @@ enum { sizeof_bool = sizeof(bool) }; static bool inited; ''' % schema.idlHeader + try: + for table in schema.tables.itervalues(): + for column in table.columns.itervalues(): + if is_string_map(column): + print """\ +static int +bsearch_strcmp(const void *a_, const void *b_) +{ + char *const *a = a_; + char *const *b = b_; + return strcmp(*a, *b); +}""" + raise StopIteration + except StopIteration: + pass + # Cast functions. for tableName, table in sorted(schema.tables.iteritems()): structName = "%s%s" % (prefix, tableName.lower()) @@ -305,15 +336,7 @@ static void # Unparse functions. for columnName, column in sorted(table.columns.iteritems()): type = column.type - if (type.key.type == ovs.db.types.BooleanType and not type.value - and type.n_min == 0 and type.n_max == 1): - print ''' -static void -%(s)s_unparse_%(c)s(struct ovsdb_idl_row *row OVS_UNUSED) -{ - /* Nothing to do. */ -}''' % {'s': structName, 'c': columnName} - elif (type.n_min != 1 or type.n_max != 1) and not type.is_optional_pointer(): + if (type.n_min != 1 or type.n_max != 1) and not type.is_optional_pointer(): print ''' static void %(s)s_unparse_%(c)s(struct ovsdb_idl_row *row_) @@ -492,6 +515,25 @@ const struct ovsdb_datum * 'C': columnName.upper()} print "}" + # String Map Helpers. + for columnName, column in sorted(table.columns.iteritems()): + if not is_string_map(column): + continue + + print """ +const char * %(s)s_get_%(c)s_value(const struct %(s)s *row, const char *search_key, const char *default_value) +{ + char **keys = row->key_%(c)s; + char **values = row->value_%(c)s; + size_t n_keys = row->n_%(c)s; + char ** result_key; + + assert(inited); + result_key = bsearch(&search_key, keys, n_keys, sizeof *keys, + bsearch_strcmp); + return result_key ? values[result_key - keys] : default_value; +}""" % {'s': structName, 'c': columnName} + # Table columns. print "\nstruct ovsdb_idl_column %s_columns[%s_N_COLUMNS];" % ( structName, structName.upper())