1 /* Copyright (c) 2009 Nicira Networks
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at:
7 * http://www.apache.org/licenses/LICENSE-2.0
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
23 #include "ovsdb-data.h"
25 struct ovsdb_column_set;
27 /* A row in a database table. */
29 struct ovsdb_table *table; /* Table to which this belongs. */
30 struct hmap_node hmap_node; /* Element in ovsdb_table's 'rows' hmap. */
31 struct ovsdb_txn_row *txn_row; /* Transaction that row is in, if any. */
32 struct ovsdb_datum fields[];
35 struct ovsdb_row *ovsdb_row_create(const struct ovsdb_table *);
36 struct ovsdb_row *ovsdb_row_clone(const struct ovsdb_row *);
37 void ovsdb_row_destroy(struct ovsdb_row *);
39 uint32_t ovsdb_row_hash_columns(const struct ovsdb_row *,
40 const struct ovsdb_column_set *,
42 bool ovsdb_row_equal_columns(const struct ovsdb_row *,
43 const struct ovsdb_row *,
44 const struct ovsdb_column_set *);
45 int ovsdb_row_compare_columns_3way(const struct ovsdb_row *,
46 const struct ovsdb_row *,
47 const struct ovsdb_column_set *);
48 void ovsdb_row_update_columns(struct ovsdb_row *, const struct ovsdb_row *,
49 const struct ovsdb_column_set *);
51 struct ovsdb_error *ovsdb_row_from_json(struct ovsdb_row *,
53 const struct ovsdb_symbol_table *,
54 struct ovsdb_column_set *included)
56 struct json *ovsdb_row_to_json(const struct ovsdb_row *,
57 const struct ovsdb_column_set *include);
59 static inline const struct uuid *
60 ovsdb_row_get_uuid(const struct ovsdb_row *row)
62 return &row->fields[OVSDB_COL_UUID].keys[0].uuid;
65 static inline struct uuid *
66 ovsdb_row_get_uuid_rw(struct ovsdb_row *row)
68 return &row->fields[OVSDB_COL_UUID].keys[0].uuid;
71 static inline const struct uuid *
72 ovsdb_row_get_version(const struct ovsdb_row *row)
74 return &row->fields[OVSDB_COL_VERSION].keys[0].uuid;
77 static inline struct uuid *
78 ovsdb_row_get_version_rw(struct ovsdb_row *row)
80 return &row->fields[OVSDB_COL_VERSION].keys[0].uuid;
83 static inline uint32_t
84 ovsdb_row_hash(const struct ovsdb_row *row)
86 return uuid_hash(ovsdb_row_get_uuid(row));
89 /* An unordered collection of rows. */
90 struct ovsdb_row_set {
91 const struct ovsdb_row **rows;
92 size_t n_rows, allocated_rows;
95 #define OVSDB_ROW_SET_INITIALIZER { NULL, 0, 0 }
97 void ovsdb_row_set_init(struct ovsdb_row_set *);
98 void ovsdb_row_set_destroy(struct ovsdb_row_set *);
99 void ovsdb_row_set_add_row(struct ovsdb_row_set *, const struct ovsdb_row *);
101 struct json *ovsdb_row_set_to_json(const struct ovsdb_row_set *,
102 const struct ovsdb_column_set *);
104 void ovsdb_row_set_sort(struct ovsdb_row_set *,
105 const struct ovsdb_column_set *);
107 /* A hash table of rows. A specified set of columns is used for hashing and
110 * The row hash doesn't necessarily own its rows. They may be owned by, for
111 * example, an ovsdb_table. */
112 struct ovsdb_row_hash {
114 struct ovsdb_column_set columns;
117 #define OVSDB_ROW_HASH_INITIALIZER(RH) \
118 { HMAP_INITIALIZER(&(RH).rows), OVSDB_COLUMN_SET_INITIALIZER }
120 struct ovsdb_row_hash_node {
121 struct hmap_node hmap_node;
122 const struct ovsdb_row *row;
125 void ovsdb_row_hash_init(struct ovsdb_row_hash *,
126 const struct ovsdb_column_set *);
127 void ovsdb_row_hash_destroy(struct ovsdb_row_hash *, bool destroy_rows);
128 size_t ovsdb_row_hash_count(const struct ovsdb_row_hash *);
129 bool ovsdb_row_hash_contains(const struct ovsdb_row_hash *,
130 const struct ovsdb_row *);
131 bool ovsdb_row_hash_contains_all(const struct ovsdb_row_hash *,
132 const struct ovsdb_row_hash *);
133 bool ovsdb_row_hash_insert(struct ovsdb_row_hash *, const struct ovsdb_row *);
134 bool ovsdb_row_hash_contains__(const struct ovsdb_row_hash *,
135 const struct ovsdb_row *, size_t hash);
136 bool ovsdb_row_hash_insert__(struct ovsdb_row_hash *,
137 const struct ovsdb_row *, size_t hash);
139 #endif /* ovsdb/row.h */