]> git.proxmox.com Git - mirror_ovs.git/blob - ovsdb/condition.h
ovsdb-tool: Add a db consistency check to the ovsdb-tool check-cluster command.
[mirror_ovs.git] / ovsdb / condition.h
1 /* Copyright (c) 2009, 2010 Nicira, Inc.
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_CONDITION_H
17 #define OVSDB_CONDITION_H 1
18
19 #include <stddef.h>
20 #include "compiler.h"
21 #include "ovsdb-data.h"
22 #include "bitmap.h"
23 #include "ovsdb-condition.h"
24
25 struct json;
26 struct ovsdb_table_schema;
27 struct ovsdb_row;
28
29 struct ovsdb_clause {
30 enum ovsdb_function function;
31 const struct ovsdb_column *column;
32 unsigned int index;
33 struct ovsdb_datum arg;
34 };
35
36 struct ovsdb_condition {
37 struct ovsdb_clause *clauses;
38 size_t n_clauses;
39 bool optimized;
40 struct shash o_columns;
41 };
42
43 #define OVSDB_CONDITION_INITIALIZER(COND) \
44 { NULL, 0, true, SHASH_INITIALIZER(&(COND)->o_columns)}
45
46 void ovsdb_condition_init(struct ovsdb_condition *);
47 bool ovsdb_condition_empty(const struct ovsdb_condition *);
48 struct ovsdb_error *ovsdb_condition_from_json(
49 const struct ovsdb_table_schema *,
50 const struct json *, struct ovsdb_symbol_table *,
51 struct ovsdb_condition *) OVS_WARN_UNUSED_RESULT;
52 struct json *ovsdb_condition_to_json(const struct ovsdb_condition *);
53 void ovsdb_condition_destroy(struct ovsdb_condition *);
54 bool ovsdb_condition_match_every_clause(const struct ovsdb_row *,
55 const struct ovsdb_condition *);
56 bool ovsdb_condition_match_any_clause(const struct ovsdb_datum *,
57 const struct ovsdb_condition *,
58 unsigned int index_map[]);
59 int ovsdb_condition_cmp_3way(const struct ovsdb_condition *a,
60 const struct ovsdb_condition *b);
61 void ovsdb_condition_clone(struct ovsdb_condition *to,
62 const struct ovsdb_condition *from);
63 bool ovsdb_condition_is_true(const struct ovsdb_condition *cond);
64 bool ovsdb_condition_is_false(const struct ovsdb_condition *cond);
65 const struct ovsdb_column **
66 ovsdb_condition_get_columns(const struct ovsdb_condition *cond,
67 size_t *n_columns);
68
69 static inline bool
70 ovsdb_condition_empty_or_match_any(const struct ovsdb_datum *row_datum,
71 const struct ovsdb_condition *cnd,
72 unsigned int index_map[])
73 {
74 return (ovsdb_condition_empty(cnd) ||
75 ovsdb_condition_match_any_clause(row_datum, cnd, index_map));
76 }
77
78 #endif /* ovsdb/condition.h */