Car params loaded using config api
[apps/native/gear-racing-car.git] / inc / config.h
1 /*
2  * Copyright (c) 2018 Samsung Electronics Co., Ltd.
3  *
4  * Licensed under the Flora License, Version 1.1 (the License);
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://floralicense.org/license/
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an AS IS BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16
17 #ifndef CONFIG_H
18 #define CONFIG_H
19
20 #include <stdbool.h>
21
22 /**
23  * @brief Initializes config module.
24  *
25  * @return 0 on success, other value on error.
26  *
27  * @note config module reads/writes configuration stored in
28  * application's "data" directory in "config.ini" file.
29  */
30 int config_init();
31
32 /**
33  * @brief Flush config to disk.
34  *
35  * @return 0 on success, other value on error.
36  */
37 int config_save();
38
39 /**
40  * @brief Shutdowns config module.
41  */
42 void config_shutdown();
43
44 /**
45  * @brief Get string value
46  *
47  * @param[in] group configuration group to which @key belongs
48  * @param[in] key configuration key name.
49  * @param[out] out value stored in configuration for given group and key.
50  *
51  * @return 0 on success, other if value for given group with key do not exist.
52  *
53  * @note @config_init should be called before using this function
54  * @note @out should be released with @free
55  */
56 int config_get_string(const char *group, const char *key, char **out);
57
58 /**
59  * @brief Sets string value
60  *
61  * @param[in] group configuration group to which @key belongs
62  * @param[in] key configuration key name.
63  * @param[in] value to be stored in configuration for given group and key.
64  *
65  * @note @config_init should be called before using this function
66  */
67 void config_set_string(const char *group, const char *key, const char *value);
68
69 /**
70  * @brief Get integer value
71  *
72  * @param[in] group configuration group to which @key belongs
73  * @param[in] key configuration key name.
74  * @param[out] out value stored in configuration for given group and key.
75  *
76  * @return 0 on success, other if value for given group with key do not exist.
77  *
78  * @note @config_init should be called before using this function
79  */
80 int config_get_int(const char *group, const char *key, int *out);
81
82 /**
83  * @brief Set integer value
84  *
85  * @param[in] group configuration group to which @key belongs
86  * @param[in] key configuration key name.
87  * @param[in] value to be stored in configuration for given group and key.
88  *
89  * @note @config_init should be called before using this function
90  */
91 void config_set_int(const char *group, const char *key, int value);
92
93 /**
94  * @brief Get double value
95  *
96  * @param[in] group configuration group to which @key belongs
97  * @param[in] key configuration key name.
98  * @param[out] out value stored in configuration for given group and key.
99  *
100  * @return 0 on success, other if value for given group with key do not exist.
101  *
102  * @note @config_init should be called before using this function
103  */
104 int config_get_double(const char *group, const char *key, double *out);
105
106 /**
107  * @brief Set double value
108  *
109  * @param[in] group configuration group to which @key belongs
110  * @param[in] key configuration key name.
111  * @param[in] value to be stored in configuration for given group and key.
112  *
113  * @note @config_init should be called before using this function
114  */
115 void config_set_double(const char *group, const char *key, double value);
116
117 /**
118  * @brief Get boolean value
119  *
120  * @param[in] group configuration group to which @key belongs
121  * @param[in] key configuration key name.
122  * @param[out] out value stored in configuration for given group and key.
123  *
124  * @return 0 on success, other if value for given group with key do not exist.
125  *
126  * @note @config_init should be called before using this function
127  */
128 int config_get_bool(const char *group, const char *key, bool *out);
129
130 /**
131  * @brief Set boolean value
132  *
133  * @param[in] group configuration group to which @key belongs
134  * @param[in] key configuration key name.
135  * @param[in] value to be stored in configuration for given group and key.
136  *
137  * @note @config_init should be called before using this function
138  */
139 void config_set_bool(const char *group, const char *key, bool value);
140
141 /**
142  * @brief Remove key from config.
143  *
144  * @param[in] group configuration group to which @key belongs
145  * @param[in] key configuration key name.
146  *
147  * @note @config_init should be called before using this function
148  */
149 int config_remove_key(const char *group, const char *key);
150
151 /**
152  * @brief Remove group from config. Removes all keys assigned to this group.
153  *
154  * @param[in] group configuration group name.
155  *
156  * @note @config_init should be called before using this function
157  */
158 int config_remove_group(const char *group);
159
160 bool config_get_string_or_set_default(char *group, char *key, char *default_value, char **value);
161 bool config_get_int_with_default(char *group, char *key, int default_value, int *value);
162
163 #endif /* end of include guard: CONFIG_H */