ovsdb: Provide helper function to determine if IDL has ever connected
[cascardo/ovs.git] / lib / ovsdb-idl.h
1 /* Copyright (c) 2009 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_IDL_H
17 #define OVSDB_IDL_H 1
18
19 #include <stdbool.h>
20 #include <stdint.h>
21
22 struct json;
23 struct ovsdb_idl_class;
24
25 struct ovsdb_idl *ovsdb_idl_create(const char *remote,
26                                    const struct ovsdb_idl_class *);
27 void ovsdb_idl_destroy(struct ovsdb_idl *);
28
29 void ovsdb_idl_run(struct ovsdb_idl *);
30 void ovsdb_idl_wait(struct ovsdb_idl *);
31
32 unsigned int ovsdb_idl_get_seqno(const struct ovsdb_idl *);
33 bool ovsdb_idl_has_ever_connected(const struct ovsdb_idl *);
34 void ovsdb_idl_force_reconnect(struct ovsdb_idl *);
35
36 enum ovsdb_idl_txn_status {
37     TXN_UNCHANGED,              /* Transaction didn't include any changes. */
38     TXN_INCOMPLETE,             /* Commit in progress, please wait. */
39     TXN_ABORTED,                /* ovsdb_idl_txn_abort() called. */
40     TXN_SUCCESS,                /* Commit successful. */
41     TXN_TRY_AGAIN,              /* Commit failed because a "verify" operation
42                                  * reported an inconsistency, due to a network
43                                  * problem, or other transient failure. */
44     TXN_ERROR                   /* Commit failed due to a hard error. */
45 };
46
47 const char *ovsdb_idl_txn_status_to_string(enum ovsdb_idl_txn_status);
48
49 struct ovsdb_idl_txn *ovsdb_idl_txn_create(struct ovsdb_idl *);
50 void ovsdb_idl_txn_add_comment(struct ovsdb_idl_txn *, const char *);
51 void ovsdb_idl_txn_set_dry_run(struct ovsdb_idl_txn *);
52 void ovsdb_idl_txn_increment(struct ovsdb_idl_txn *, const char *table,
53                              const char *column, const struct json *where);
54 void ovsdb_idl_txn_destroy(struct ovsdb_idl_txn *);
55 void ovsdb_idl_txn_wait(const struct ovsdb_idl_txn *);
56 enum ovsdb_idl_txn_status ovsdb_idl_txn_commit(struct ovsdb_idl_txn *);
57 int64_t ovsdb_idl_txn_get_increment_new_value(const struct ovsdb_idl_txn *);
58 void ovsdb_idl_txn_abort(struct ovsdb_idl_txn *);
59
60 #endif /* ovsdb-idl.h */