ovsdb-tool: Add commands for printing the database checksum.
[cascardo/ovs.git] / ovsdb / ovsdb.h
1 /* Copyright (c) 2009, 2010, 2011 Nicira Networks
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_OVSDB_H
17 #define OVSDB_OVSDB_H 1
18
19 #include "compiler.h"
20 #include "hmap.h"
21 #include "list.h"
22 #include "shash.h"
23
24 struct json;
25 struct ovsdb_log;
26 struct ovsdb_txn;
27 struct uuid;
28
29 /* Database schema. */
30 struct ovsdb_schema {
31     char *name;
32     char *version;
33     char *cksum;
34     struct shash tables;        /* Contains "struct ovsdb_table_schema *"s. */
35 };
36
37 struct ovsdb_schema *ovsdb_schema_create(const char *name,
38                                          const char *version,
39                                          const char *cksum);
40 struct ovsdb_schema *ovsdb_schema_clone(const struct ovsdb_schema *);
41 void ovsdb_schema_destroy(struct ovsdb_schema *);
42
43 struct ovsdb_error *ovsdb_schema_from_file(const char *file_name,
44                                            struct ovsdb_schema **)
45     WARN_UNUSED_RESULT;
46 struct ovsdb_error *ovsdb_schema_from_json(struct json *,
47                                            struct ovsdb_schema **)
48     WARN_UNUSED_RESULT;
49 struct json *ovsdb_schema_to_json(const struct ovsdb_schema *);
50 \f
51 /* Database. */
52 struct ovsdb {
53     struct ovsdb_schema *schema;
54     struct list replicas;       /* Contains "struct ovsdb_replica"s. */
55     struct shash tables;        /* Contains "struct ovsdb_table *"s. */
56
57     /* Triggers. */
58     struct list triggers;       /* Contains "struct ovsdb_trigger"s. */
59     bool run_triggers;
60 };
61
62 struct ovsdb *ovsdb_create(struct ovsdb_schema *);
63 void ovsdb_destroy(struct ovsdb *);
64
65 struct ovsdb_error *ovsdb_from_json(const struct json *, struct ovsdb **)
66     WARN_UNUSED_RESULT;
67 struct json *ovsdb_to_json(const struct ovsdb *);
68
69 struct ovsdb_table *ovsdb_get_table(const struct ovsdb *, const char *);
70
71 struct json *ovsdb_execute(struct ovsdb *, const struct json *params,
72                            long long int elapsed_msec,
73                            long long int *timeout_msec);
74 \f
75 /* Database replication. */
76
77 struct ovsdb_replica {
78     struct list node;           /* Element in "struct ovsdb" replicas list. */
79     const struct ovsdb_replica_class *class;
80 };
81
82 struct ovsdb_replica_class {
83     struct ovsdb_error *(*commit)(struct ovsdb_replica *,
84                                   const struct ovsdb_txn *, bool durable);
85     void (*destroy)(struct ovsdb_replica *);
86 };
87
88 void ovsdb_replica_init(struct ovsdb_replica *,
89                         const struct ovsdb_replica_class *);
90
91 void ovsdb_add_replica(struct ovsdb *, struct ovsdb_replica *);
92 void ovsdb_remove_replica(struct ovsdb *, struct ovsdb_replica *);
93
94 #endif /* ovsdb/ovsdb.h */