]>
Commit | Line | Data |
---|---|---|
c532bf9d | 1 | /* Copyright (c) 2009, 2010 Nicira Networks |
f85f8ebb BP |
2 | * |
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: | |
6 | * | |
7 | * http://www.apache.org/licenses/LICENSE-2.0 | |
8 | * | |
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. | |
14 | */ | |
15 | ||
16 | #ifndef OVSDB_DATA_H | |
17 | #define OVSDB_DATA_H 1 | |
18 | ||
19 | #include <stdlib.h> | |
20 | #include "compiler.h" | |
21 | #include "ovsdb-types.h" | |
22 | ||
23 | struct ovsdb_symbol_table; | |
24 | ||
25 | /* One value of an atomic type (given by enum ovs_atomic_type). */ | |
26 | union ovsdb_atom { | |
27 | int64_t integer; | |
28 | double real; | |
29 | bool boolean; | |
30 | char *string; | |
31 | struct uuid uuid; | |
32 | }; | |
33 | ||
34 | void ovsdb_atom_init_default(union ovsdb_atom *, enum ovsdb_atomic_type); | |
c532bf9d | 35 | bool ovsdb_atom_is_default(const union ovsdb_atom *, enum ovsdb_atomic_type); |
f85f8ebb BP |
36 | void ovsdb_atom_clone(union ovsdb_atom *, const union ovsdb_atom *, |
37 | enum ovsdb_atomic_type); | |
38 | void ovsdb_atom_swap(union ovsdb_atom *, union ovsdb_atom *); | |
39 | ||
40 | static inline bool | |
41 | ovsdb_atom_needs_destruction(enum ovsdb_atomic_type type) | |
42 | { | |
43 | return type == OVSDB_TYPE_STRING; | |
44 | } | |
45 | ||
46 | static inline void | |
47 | ovsdb_atom_destroy(union ovsdb_atom *atom, enum ovsdb_atomic_type type) | |
48 | { | |
49 | if (type == OVSDB_TYPE_STRING) { | |
50 | free(atom->string); | |
51 | } | |
52 | } | |
53 | ||
54 | uint32_t ovsdb_atom_hash(const union ovsdb_atom *, enum ovsdb_atomic_type, | |
55 | uint32_t basis); | |
56 | ||
57 | int ovsdb_atom_compare_3way(const union ovsdb_atom *, | |
58 | const union ovsdb_atom *, | |
59 | enum ovsdb_atomic_type); | |
60 | ||
61 | static inline bool ovsdb_atom_equals(const union ovsdb_atom *a, | |
62 | const union ovsdb_atom *b, | |
63 | enum ovsdb_atomic_type type) | |
64 | { | |
65 | return !ovsdb_atom_compare_3way(a, b, type); | |
66 | } | |
67 | ||
68 | struct ovsdb_error *ovsdb_atom_from_json(union ovsdb_atom *, | |
69 | enum ovsdb_atomic_type, | |
70 | const struct json *, | |
71 | const struct ovsdb_symbol_table *) | |
72 | WARN_UNUSED_RESULT; | |
73 | struct json *ovsdb_atom_to_json(const union ovsdb_atom *, | |
74 | enum ovsdb_atomic_type); | |
75 | \f | |
76 | /* One value of an OVSDB type (given by struct ovsdb_type). */ | |
77 | struct ovsdb_datum { | |
78 | unsigned int n; /* Number of 'keys' and 'values'. */ | |
79 | union ovsdb_atom *keys; /* Each of the ovsdb_type's 'key_type'. */ | |
80 | union ovsdb_atom *values; /* Each of the ovsdb_type's 'value_type'. */ | |
81 | }; | |
82 | ||
83 | void ovsdb_datum_init_default(struct ovsdb_datum *, const struct ovsdb_type *); | |
c532bf9d BP |
84 | bool ovsdb_datum_is_default(const struct ovsdb_datum *, |
85 | const struct ovsdb_type *); | |
f85f8ebb BP |
86 | void ovsdb_datum_clone(struct ovsdb_datum *, const struct ovsdb_datum *, |
87 | const struct ovsdb_type *); | |
88 | void ovsdb_datum_destroy(struct ovsdb_datum *, const struct ovsdb_type *); | |
89 | void ovsdb_datum_swap(struct ovsdb_datum *, struct ovsdb_datum *); | |
e9f8f936 BP |
90 | struct ovsdb_error *ovsdb_datum_sort(struct ovsdb_datum *, |
91 | const struct ovsdb_type *); | |
f85f8ebb BP |
92 | |
93 | struct ovsdb_error *ovsdb_datum_from_json(struct ovsdb_datum *, | |
94 | const struct ovsdb_type *, | |
95 | const struct json *, | |
96 | const struct ovsdb_symbol_table *) | |
97 | WARN_UNUSED_RESULT; | |
98 | struct json *ovsdb_datum_to_json(const struct ovsdb_datum *, | |
99 | const struct ovsdb_type *); | |
100 | ||
101 | uint32_t ovsdb_datum_hash(const struct ovsdb_datum *, | |
102 | const struct ovsdb_type *, uint32_t basis); | |
103 | int ovsdb_datum_compare_3way(const struct ovsdb_datum *, | |
104 | const struct ovsdb_datum *, | |
105 | const struct ovsdb_type *); | |
106 | bool ovsdb_datum_equals(const struct ovsdb_datum *, | |
107 | const struct ovsdb_datum *, | |
108 | const struct ovsdb_type *); | |
109 | bool ovsdb_datum_includes_all(const struct ovsdb_datum *, | |
110 | const struct ovsdb_datum *, | |
111 | const struct ovsdb_type *); | |
112 | bool ovsdb_datum_excludes_all(const struct ovsdb_datum *, | |
113 | const struct ovsdb_datum *, | |
114 | const struct ovsdb_type *); | |
115 | ||
e9f8f936 BP |
116 | void ovsdb_datum_union(struct ovsdb_datum *, |
117 | const struct ovsdb_datum *, | |
118 | const struct ovsdb_type *); | |
119 | void ovsdb_datum_subtract(struct ovsdb_datum *a, | |
120 | const struct ovsdb_type *a_type, | |
121 | const struct ovsdb_datum *b, | |
122 | const struct ovsdb_type *b_type); | |
123 | ||
f85f8ebb BP |
124 | static inline bool |
125 | ovsdb_datum_conforms_to_type(const struct ovsdb_datum *datum, | |
126 | const struct ovsdb_type *type) | |
127 | { | |
128 | return datum->n >= type->n_min && datum->n <= type->n_max; | |
129 | } | |
130 | \f | |
131 | /* A table mapping from names to data items. Currently the data items are | |
132 | * always UUIDs; perhaps this will be expanded in the future. */ | |
133 | ||
2d2d6d4a BP |
134 | struct ovsdb_symbol { |
135 | struct uuid uuid; /* The UUID that the symbol represents. */ | |
136 | bool used; /* Already used as row UUID? */ | |
137 | }; | |
138 | ||
f85f8ebb BP |
139 | struct ovsdb_symbol_table *ovsdb_symbol_table_create(void); |
140 | void ovsdb_symbol_table_destroy(struct ovsdb_symbol_table *); | |
2d2d6d4a BP |
141 | struct ovsdb_symbol *ovsdb_symbol_table_get(const struct ovsdb_symbol_table *, |
142 | const char *name); | |
f85f8ebb | 143 | void ovsdb_symbol_table_put(struct ovsdb_symbol_table *, const char *name, |
2d2d6d4a | 144 | const struct uuid *, bool used); |
f85f8ebb BP |
145 | |
146 | #endif /* ovsdb-data.h */ |