X-Git-Url: https://pintos-os.org/cgi-bin/gitweb.cgi?a=blobdiff_plain;f=ovsdb%2Frow.c;h=457869b38cdbdade316885bb4c9bcdcec9bed501;hb=b592e72628c025ee0cc850127b90c96409c395df;hp=ba00bb9f3059140b965b00989fd49298c5898f95;hpb=4e8e4213a815a30216e855a805a8bcd5b8c5a886;p=openvswitch diff --git a/ovsdb/row.c b/ovsdb/row.c index ba00bb9f..457869b3 100644 --- a/ovsdb/row.c +++ b/ovsdb/row.c @@ -1,4 +1,4 @@ -/* Copyright (c) 2009, 2010 Nicira Networks +/* Copyright (c) 2009, 2010, 2011 Nicira, Inc. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -20,6 +20,7 @@ #include #include +#include "dynamic-string.h" #include "json.h" #include "ovsdb-error.h" #include "shash.h" @@ -30,8 +31,10 @@ static struct ovsdb_row * allocate_row(const struct ovsdb_table *table) { size_t n_fields = shash_count(&table->schema->columns); + size_t n_indexes = table->schema->n_indexes; size_t row_size = (offsetof(struct ovsdb_row, fields) - + sizeof(struct ovsdb_datum) * n_fields); + + sizeof(struct ovsdb_datum) * n_fields + + sizeof(struct hmap_node) * n_indexes); struct ovsdb_row *row = xmalloc(row_size); row->table = (struct ovsdb_table *) table; row->txn_row = NULL; @@ -173,6 +176,23 @@ ovsdb_row_update_columns(struct ovsdb_row *dst, } } +/* Appends the string form of the value in 'row' of each of the columns in + * 'columns' to 'out', e.g. "1, \"xyz\", and [1, 2, 3]". */ +void +ovsdb_row_columns_to_string(const struct ovsdb_row *row, + const struct ovsdb_column_set *columns, + struct ds *out) +{ + size_t i; + + for (i = 0; i < columns->n_columns; i++) { + const struct ovsdb_column *column = columns->columns[i]; + + ds_put_cstr(out, english_list_delimiter(i, columns->n_columns)); + ovsdb_datum_to_string(&row->fields[column->index], &column->type, out); + } +} + struct ovsdb_error * ovsdb_row_from_json(struct ovsdb_row *row, const struct json *json, struct ovsdb_symbol_table *symtab,