EM-ODP 4.4.0
Event Machine on ODP
Loading...
Searching...
No Matches
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#include <stdbool.h>
40#include <stdint.h>
41
42#include <libconfig.h>
43
44#include "em_libconfig_types.h"
45
46#ifdef __cplusplus
47extern "C" {
48#endif
49
50/**
51 * Reads the default config and runtime config (if given) to shm and checks
52 * its mandatory fields.
53 *
54 * @param libconfig Pointer to shared libconfig data
55 * @return int 0 on success, -1 on error
56 */
57int em_libconfig_init_global(libconfig_t *libconfig);
58
59/**
60 * Destroys the configs.
61 *
62 * @param libconfig Pointer to shared libconfig data
63 * @return int 0
64 */
65int em_libconfig_term_global(libconfig_t *libconfig);
66
67/**
68 * Reads integer from runtime config if given, otherwise default config.
69 *
70 * @param libconfig Pointer to shared libconfig data
71 * @param path Path to value
72 * @param[out] value Pointer where read value will be stored
73 * @return int 1 on success, 0 otherwise
74 */
75int em_libconfig_lookup_int(const libconfig_t *libconfig, const char *path,
76 int *value /*out*/);
77
78int em_libconfig_lookup_int64(const libconfig_t *libconfig, const char *path,
79 int64_t *value /*out*/);
80
81/**
82 * Reads a boolean from runtime config if given, otherwise default config.
83 *
84 * @param libconfig Pointer to shared libconfig data
85 * @param path Path to value
86 * @param[out] value Pointer where read value will be stored
87 * @return int 1 on success, 0 otherwise
88 */
89int em_libconfig_lookup_bool(const libconfig_t *libconfig,
90 const char *path, bool *value /*out*/);
91
92/**
93 * Reads a string from runtime config if given, otherwise default config.
94 *
95 * @param libconfig Pointer to shared libconfig data
96 * @param path Path to value
97 * @param[out] value Pointer where read value will be stored
98 * @return int 1 on success, 0 otherwise
99 */
100int em_libconfig_lookup_string(const libconfig_t *libconfig, const char *path,
101 const char **value /*out*/);
102
103/**
104 * Reads an arrays of integers from runtime config if given, otherwise from
105 * default config.
106 *
107 * @param libconfig Pointer to shared libconfig data
108 * @param path Path to value
109 * @param[out] value Pointer where read array will be stored
110 * @param max_num Max number of elements in the array
111 * @return int Number of read elements
112 */
113int em_libconfig_lookup_array(const libconfig_t *libconfig, const char *path,
114 int value[/*out*/], int max_num);
115
116/**
117 * Reads integer from runtime config if given, otherwise default config. Path
118 * to config variable is assumed to be base_path.local_path.name.
119 *
120 * @param libconfig Pointer to shared libconfig data
121 * @param base_path Basepath to value
122 * @param local_path Localpath to value
123 * @param name Value name
124 * @param[out] value Pointer where read value will be stored
125 * @return int 1 on success, 0 otherwise
126 */
127int em_libconfig_lookup_ext_int(const libconfig_t *libconfig,
128 const char *base_path, const char *local_path,
129 const char *name, int *value /*out*/);
130
131/**
132 * Read setting specified by 'path' from both default and runtime config.
133 *
134 * @param libconfig Pointer to shared libconfig data
135 * @param path Path to setting
136 * @param[out] setting_default Pointer where setting from default conf file will be stored
137 * @param[out] setting_runtime Pointer where setting from runtime conf file will be stored
138 */
139void em_libconfig_lookup(const libconfig_t *libconfig, const char *path,
140 libconfig_setting_t **setting_default/*out*/,
141 libconfig_setting_t **setting_runtime/*out*/);
142
143/**
144 * Read an integer named 'name' from a setting.
145 *
146 * @param setting Pointer to the setting where integer is read
147 * @param name Value name
148 * @param[out] value Pointer where read integer value will be stored
149 * @return int 1 on success, 0 otherwise
150 */
151int em_libconfig_setting_lookup_int(const libconfig_setting_t *setting,
152 const char *name, int *value/*out*/);
153
154/**
155 * Fetch a list named 'name' from a setting.
156 *
157 * @param setting Pointer to the setting where list is fetched
158 * @param name List name
159 * @return Requested list on success, NULL otherwise
160 */
161const libconfig_list_t
162*em_libconfig_setting_get_list(const libconfig_setting_t *setting, const char *name);
163
164/**
165 * Return the number of elements in a list.
166 *
167 * @param list Pointer to list
168 * @return int The number of elements in a list
169 */
170int em_libconfig_list_length(const libconfig_list_t *list);
171
172/**
173 * Get a group setting from a list.
174 *
175 * @param list Pointer to list where group is fetched
176 * @param index Index to list element
177 * @param path Path to the group setting
178 * @return Requested group on success, NULL otherwise
179 */
180libconfig_group_t *em_libconfig_list_lookup_group(const libconfig_list_t *list,
181 int index, const char *path);
182
183/**
184 * Read an integer from a list.
185 *
186 * @param list Pointer to list where integer is read
187 * @param index Index to list element
188 * @param path Path to integer value
189 * @param[out] value Pointer where read value will be stored
190 * @return int 1 on success, 0 wrong type, -1 not found
191 */
192int em_libconfig_list_lookup_int(const libconfig_list_t *list, int index,
193 const char *path, int *value/*out*/);
194
195/**
196 * Read a bool from a list.
197 *
198 * @param list Pointer to list
199 * @param index Index to list element
200 * @param path Path to boolean value
201 * @param[out] value Pointer where read value will be stored
202 * @return int 1 on success, 0 wrong type, -1 not found
203 */
204int em_libconfig_list_lookup_bool(const libconfig_list_t *list, int index,
205 const char *path, bool *value/*out*/);
206
207/**
208 * Read string from a list.
209 *
210 * @param list Pointer to list
211 * @param index Index to list element
212 * @param path Path to string value
213 * @param[out] value Pointer where read value will be stored
214 * @return int 1 on success, 0 wrong type, -1 not found
215 */
216int em_libconfig_list_lookup_string(const libconfig_list_t *list, int index,
217 const char *path, const char **value/*out*/);
218
219/**
220 * Get a group setting from a group.
221 *
222 * @param group Pointer to group
223 * @param path Path to the group to be fetched
224 * @return Requested group on success, NULL otherwise
225 */
226libconfig_group_t
227*em_libconfig_group_lookup_group(libconfig_group_t *group, const char *path);
228
229/**
230 * Fetch a list from a group.
231 *
232 * @param group Pointer to group
233 * @param path Path to the list to be fetched
234 * @return Requested list on success, NULL otherwise
235 */
236libconfig_list_t
237*em_libconfig_group_lookup_list(libconfig_list_t *group, const char *path);
238
239/**
240 * Read an integer from a group.
241 *
242 * @param group Pointer to group
243 * @param name Name of integer value
244 * @param[out] value Pointer where read value will be stored
245 * @return int 1 on success, 0 otherwise
246 */
247int em_libconfig_group_lookup_int(const libconfig_group_t *group,
248 const char *name, int *value/*out*/);
249
250/**
251 * Read a bool from a group.
252 *
253 * @param group Pointer to group
254 * @param name Name of boolean value
255 * @param[out] value Pointer where read value will be stored
256 * @return int 1 on success, 0 otherwise
257 */
258int em_libconfig_group_lookup_bool(const libconfig_group_t *group,
259 const char *name, bool *value/*out*/);
260
261/**
262 * Read string from a group.
263 *
264 * @param group Pointer to group
265 * @param name Name of the string to be fetched
266 * @param[out] value Pointer where read value will be stored
267 * @return int 1 on success, 0 otherwise
268 */
269int em_libconfig_group_lookup_string(const libconfig_group_t *group,
270 const char *name, const char **value/*out*/);
271
272/**
273 * Prints default config and runtime config (if given).
274 *
275 * @param libconfig Pointer to shared libconfig data
276 * @return int 1 on success, 0 otherwise
277 */
278int em_libconfig_print(const libconfig_t *libconfig);
279
280#ifdef __cplusplus
281}
282#endif
283
284#endif