EM-ODP  3.7.0
Event Machine on ODP
em_libconfig.h
1 /*
2  * Copyright (c) 2018, Nokia Solutions and Networks
3  * All rights reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions
7  * are met:
8  *
9  * * Redistributions of source code must retain the above copyright
10  * notice, this list of conditions and the following disclaimer.
11  * * Redistributions in binary form must reproduce the above copyright
12  * notice, this list of conditions and the following disclaimer in the
13  * documentation and/or other materials provided with the distribution.
14  * * Neither the name of the copyright holder nor the names of its
15  * contributors may be used to endorse or promote products derived
16  * from this software without specific prior written permission.
17  *
18  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
19  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
20  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
21  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
22  * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
23  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
24  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
25  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
26  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
28  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29  *
30  * Copyright (c) 2018, Linaro Limited
31  * All rights reserved.
32  *
33  * SPDX-License-Identifier: BSD-3-Clause
34  */
35 
36 #ifndef EM_LIBCONFIG_H_
37 #define EM_LIBCONFIG_H_
38 
39 #ifdef __cplusplus
40 extern "C" {
41 #endif
42 
43 /**
44  * Reads the default config and runtime config (if given) to shm and checks
45  * its mandatory fields.
46  *
47  * @param libconfig Pointer to shared libconfig data
48  * @return int 0 on success, -1 on error
49  */
50 int em_libconfig_init_global(libconfig_t *libconfig);
51 
52 /**
53  * Destroys the configs.
54  *
55  * @param libconfig Pointer to shared libconfig data
56  * @return int 0
57  */
58 int em_libconfig_term_global(libconfig_t *libconfig);
59 
60 /**
61  * Reads integer from runtime config if given, otherwise default config.
62  *
63  * @param libconfig Pointer to shared libconfig data
64  * @param path Path to value
65  * @param[out] value Pointer where read value will be stored
66  * @return int 1 on success, 0 otherwise
67  */
68 int em_libconfig_lookup_int(const libconfig_t *libconfig, const char *path,
69  int *value /*out*/);
70 
71 int em_libconfig_lookup_int64(const libconfig_t *libconfig, const char *path,
72  int64_t *value /*out*/);
73 
74 /**
75  * Reads a boolean from runtime config if given, otherwise default config.
76  *
77  * @param libconfig Pointer to shared libconfig data
78  * @param path Path to value
79  * @param[out] value Pointer where read value will be stored
80  * @return int 1 on success, 0 otherwise
81  */
82 int em_libconfig_lookup_bool(const libconfig_t *libconfig,
83  const char *path, bool *value /*out*/);
84 
85 /**
86  * Reads a string from runtime config if given, otherwise default config.
87  *
88  * @param libconfig Pointer to shared libconfig data
89  * @param path Path to value
90  * @param[out] value Pointer where read value will be stored
91  * @return int 1 on success, 0 otherwise
92  */
93 int em_libconfig_lookup_string(const libconfig_t *libconfig, const char *path,
94  const char **value /*out*/);
95 
96 /**
97  * Reads an arrays of integers from runtime config if given, otherwise from
98  * default config.
99  *
100  * @param libconfig Pointer to shared libconfig data
101  * @param path Path to value
102  * @param[out] value Pointer where read array will be stored
103  * @param max_num Max number of elements in the array
104  * @return int Number of read elements
105  */
106 int em_libconfig_lookup_array(const libconfig_t *libconfig, const char *path,
107  int value[/*out*/], int max_num);
108 
109 /**
110  * Reads integer from runtime config if given, otherwise default config. Path
111  * to config variable is assumed to be base_path.local_path.name.
112  *
113  * @param libconfig Pointer to shared libconfig data
114  * @param base_path Basepath to value
115  * @param local_path Localpath to value
116  * @param name Value name
117  * @param[out] value Pointer where read value will be stored
118  * @return int 1 on success, 0 otherwise
119  */
120 int em_libconfig_lookup_ext_int(const libconfig_t *libconfig,
121  const char *base_path, const char *local_path,
122  const char *name, int *value /*out*/);
123 
124 /**
125  * Read setting specified by 'path' from both default and runtime config.
126  *
127  * @param libconfig Pointer to shared libconfig data
128  * @param path Path to setting
129  * @param[out] setting_default Pointer where setting from default conf file will be stored
130  * @param[out] setting_runtime Pointer where setting from runtime conf file will be stored
131  */
132 void em_libconfig_lookup(const libconfig_t *libconfig, const char *path,
133  libconfig_setting_t **setting_default/*out*/,
134  libconfig_setting_t **setting_runtime/*out*/);
135 
136 /**
137  * Read an integer named 'name' from a setting.
138  *
139  * @param setting Pointer to the setting where integer is read
140  * @param name Value name
141  * @param[out] value Pointer where read integer value will be stored
142  * @return int 1 on success, 0 otherwise
143  */
144 int em_libconfig_setting_lookup_int(const libconfig_setting_t *setting,
145  const char *name, int *value/*out*/);
146 
147 /**
148  * Fetch a list named 'name' from a setting.
149  *
150  * @param setting Pointer to the setting where list is fetched
151  * @param name List name
152  * @return Requested list on success, NULL otherwise
153  */
154 const libconfig_list_t
155 *em_libconfig_setting_get_list(const libconfig_setting_t *setting, const char *name);
156 
157 /**
158  * Return the number of elements in a list.
159  *
160  * @param list Pointer to list
161  * @return int The number of elements in a list
162  */
163 int em_libconfig_list_length(const libconfig_list_t *list);
164 
165 /**
166  * Get a group setting from a list.
167  *
168  * @param list Pointer to list where group is fetched
169  * @param index Index to list element
170  * @param path Path to the group setting
171  * @return Requested group on success, NULL otherwise
172  */
173 libconfig_group_t *em_libconfig_list_lookup_group(const libconfig_list_t *list,
174  int index, const char *path);
175 
176 /**
177  * Read an integer from a list.
178  *
179  * @param list Pointer to list where integer is read
180  * @param index Index to list element
181  * @param path Path to integer value
182  * @param value[out] Pointer where read value will be stored
183  * @return int 1 on success, 0 wrong type, -1 not found
184  */
185 int em_libconfig_list_lookup_int(const libconfig_list_t *list, int index,
186  const char *path, int *value/*out*/);
187 
188 /**
189  * Read a bool from a list.
190  *
191  * @param list Pointer to list
192  * @param index Index to list element
193  * @param path Path to boolean value
194  * @param value[out] Pointer where read value will be stored
195  * @return int 1 on success, 0 wrong type, -1 not found
196  */
197 int em_libconfig_list_lookup_bool(const libconfig_list_t *list, int index,
198  const char *path, bool *value/*out*/);
199 
200 /**
201  * Read string from a list.
202  *
203  * @param list Pointer to list
204  * @param index Index to list element
205  * @param path Path to string value
206  * @param value[out] Pointer where read value will be stored
207  * @return int 1 on success, 0 wrong type, -1 not found
208  */
209 int em_libconfig_list_lookup_string(const libconfig_list_t *list, int index,
210  const char *path, const char **value/*out*/);
211 
212 /**
213  * Get a group setting from a group.
214  *
215  * @param group Pointer to group
216  * @param path Path to the group to be fetched
217  * @return Requested group on success, NULL otherwise
218  */
219 libconfig_group_t
220 *em_libconfig_group_lookup_group(libconfig_group_t *group, const char *path);
221 
222 /**
223  * Fetch a list from a group.
224  *
225  * @param group Pointer to group
226  * @param path Path to the list to be fetched
227  * @return Requested list on success, NULL otherwise
228  */
229 libconfig_list_t
230 *em_libconfig_group_lookup_list(libconfig_list_t *group, const char *path);
231 
232 /**
233  * Read an integer from a group.
234  *
235  * @param group Pointer to group
236  * @param name Name of integer value
237  * @param value[out] Pointer where read value will be stored
238  * @return int 1 on success, 0 otherwise
239  */
240 int em_libconfig_group_lookup_int(const libconfig_group_t *group,
241  const char *name, int *value/*out*/);
242 
243 /**
244  * Read a bool from a group.
245  *
246  * @param group Pointer to group
247  * @param name Name of boolean value
248  * @param value[out] Pointer where read value will be stored
249  * @return int 1 on success, 0 otherwise
250  */
251 int em_libconfig_group_lookup_bool(const libconfig_group_t *group,
252  const char *name, bool *value/*out*/);
253 
254 /**
255  * Read string from a group.
256  *
257  * @param group Pointer to group
258  * @param name Name of the string to be fetched
259  * @param value[out] Pointer where read value will be stored
260  * @return int 1 on success, 0 otherwise
261  */
262 int em_libconfig_group_lookup_string(const libconfig_group_t *group,
263  const char *name, const char **value/*out*/);
264 
265 /**
266  * Prints default config and runtime config (if given).
267  *
268  * @param libconfig Pointer to shared libconfig data
269  * @return int 1 on success, 0 otherwise
270  */
271 int em_libconfig_print(const libconfig_t *libconfig);
272 
273 #ifdef __cplusplus
274 }
275 #endif
276 
277 #endif
libconfig
Definition: em_libconfig_types.h:50