initscript: pass complete path to pidfile to status command
[sliver-openvswitch.git] / lib / cfg.h
1 /* Copyright (c) 2008, 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
17 #ifndef VSWITCHD_CFG_H
18 #define VSWITCHD_CFG_H 1
19
20 #include <stdbool.h>
21 #include <stdint.h>
22 #include <unistd.h>
23 #include "compiler.h"
24 #include "sha1.h"
25
26 struct svec;
27 struct ofpbuf;
28
29 void cfg_init(void);
30 int cfg_set_file(const char *file_name);
31 int cfg_read(void);
32 int cfg_lock(uint8_t *cookie, int timeout);
33 void cfg_unlock(void);
34 int cfg_write(void);
35 int cfg_write_data(uint8_t *data, size_t len);
36 bool cfg_is_dirty(void);
37
38 void cfg_get_all(struct svec *);
39
40 #define CFG_COOKIE_LEN SHA1_DIGEST_SIZE
41 int cfg_get_cookie(uint8_t *cookie);
42
43 void cfg_buf_put(struct ofpbuf *buffer);
44 void cfg_get_subsections(struct svec *, const char *, ...) PRINTF_FORMAT(2, 3);
45
46 enum cfg_flags {
47     /* Types allowed. */
48     CFG_STRING = 1 << 0,        /* Arbitrary content. */
49     CFG_KEY = 1 << 0,           /* Valid key name. */
50     CFG_INT = 1 << 2,           /* Integer value. */
51     CFG_BOOL = 1 << 3,          /* Boolean. */
52     CFG_IP = 1 << 4,            /* IPv4 address. */
53     CFG_MAC = 1 << 5,           /* MAC address. */
54     CFG_VLAN = 1 << 6,          /* Integer in range 0...4095. */
55     CFG_DPID = 1 << 7,          /* 12 hexadecimal digits. */
56
57     /* Number allowed. */
58     CFG_REQUIRED = 1 << 8,      /* At least one value allowed. */
59     CFG_MULTIPLE = 1 << 9       /* More than one value allowed. */
60 };
61 void cfg_register(const char *key_spec, enum cfg_flags);
62
63 void cfg_add_entry(const char *key, ...) PRINTF_FORMAT(1, 2);
64 void cfg_del_entry(const char *key, ...) PRINTF_FORMAT(1, 2);
65 void cfg_del_section(const char *key, ...) PRINTF_FORMAT(1, 2);
66 void cfg_del_match(const char *pattern, ...) PRINTF_FORMAT(1, 2);
67 void cfg_get_matches(struct svec *svec, const char *pattern, ...)
68     PRINTF_FORMAT(2, 3);
69 void cfg_get_section(struct svec *svec, const char *key, ...) 
70     PRINTF_FORMAT(2, 3);
71
72 bool cfg_has(const char *key, ...) PRINTF_FORMAT(1, 2);
73 bool cfg_is_valid(enum cfg_flags, const char *key, ...) PRINTF_FORMAT(2, 3);
74 bool cfg_has_section(const char *key, ...) PRINTF_FORMAT(1, 2);
75 int cfg_count(const char *key, ...) PRINTF_FORMAT(1, 2);
76
77 const char *cfg_get_string(int idx, const char *key, ...) PRINTF_FORMAT(2, 3);
78 const char *cfg_get_key(int idx, const char *key, ...) PRINTF_FORMAT(2, 3);
79 int cfg_get_int(int idx, const char *key, ...) PRINTF_FORMAT(2, 3);
80 bool cfg_get_bool(int idx, const char *key, ...) PRINTF_FORMAT(2, 3);
81 uint32_t cfg_get_ip(int idx, const char *key, ...) PRINTF_FORMAT(2, 3);
82 uint64_t cfg_get_mac(int idx, const char *key, ...) PRINTF_FORMAT(2, 3);
83 int cfg_get_vlan(int idx, const char *key, ...) PRINTF_FORMAT(2, 3);
84 uint64_t cfg_get_dpid(int idx, const char *key, ...) PRINTF_FORMAT(2, 3);
85
86 void cfg_get_all_strings(struct svec *, const char *key, ...)
87     PRINTF_FORMAT(2, 3);
88 void cfg_get_all_keys(struct svec *, const char *key, ...) PRINTF_FORMAT(2, 3);
89
90 #endif /* vswitchd/cfg.h */