2 * Copyright (c) 2018 Samsung Electronics Co., Ltd.
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
8 * http://floralicense.org/license/
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.
20 #include <tzplatform_config.h>
22 #include "ttd-config.h"
26 #define CONF_FILE_NAME "ttd.conf"
27 #define CONF_PATH tzplatform_mkpath3(TZ_SYS_ETC, "ttd", "ttd.conf")
29 static GKeyFile *gkf = NULL;
31 int ttd_config_init(void)
33 GKeyFile *tmp_gkf = NULL;
34 tmp_gkf = g_key_file_new();
35 retv_if(!tmp_gkf, -1);
37 if (!g_key_file_load_from_file(tmp_gkf, CONF_PATH, G_KEY_FILE_NONE, NULL)) {
38 _E("Failed to load conf file");
39 g_key_file_free(tmp_gkf);
46 void ttd_config_fini(void)
54 int ttd_config_read_integer(const char *group, const char *key, int *value)
64 if (ttd_config_init() < 0) {
65 _E("Failed to initialize configure");
70 ret = g_key_file_get_integer(gkf, group, key, &error);
72 _E("Failed to get integer[%s]", error->message);
82 int ttd_config_read_boolean(const char *group, const char *key, bool *value)
92 if (ttd_config_init() < 0) {
93 _E("Failed to initialize configure");
98 ret = g_key_file_get_boolean(gkf, group, key, &error);
100 _E("Failed to get boolean[%s]", error->message);
110 int ttd_config_read_string(const char *group, const char *key, char **value)
112 GError *error = NULL;
120 if (ttd_config_init() < 0) {
121 _E("Failed to initialize configure");
126 ret = g_key_file_get_string(gkf, group, key, &error);
128 _E("Failed to get string[%s]", error->message);
138 int ttd_config_write_integer(const char *group, const char *key, int value)
144 if (ttd_config_init() < 0) {
145 _E("Failed to initialize configure");
150 g_key_file_set_integer(gkf, group, key, value);
155 int ttd_config_write_boolean(const char *group, const char *key, bool value)
161 if (ttd_config_init() < 0) {
162 _E("Failed to initialize configure");
167 g_key_file_set_boolean(gkf, group, key, value);
172 int ttd_config_write_string(const char *group, const char *key, const char *value)
179 if (ttd_config_init() < 0) {
180 _E("Failed to initialize configure");
185 g_key_file_set_string(gkf, group, key, value);
190 int ttd_config_remove_group(const char *group)
192 gboolean ret = FALSE;
193 GError *error = NULL;
198 if (ttd_config_init() < 0) {
199 _E("Failed to initialize configure");
204 ret = g_key_file_remove_group(gkf, group, &error);
206 _E("Failed to remove group[%s]--caused by[%s]", group, error->message);
214 int ttd_config_remove_key(const char *group, const char *key)
216 gboolean ret = FALSE;
217 GError *error = NULL;
223 if (ttd_config_init() < 0) {
224 _E("Failed to initialize configure");
229 ret = g_key_file_remove_key(gkf, group, key, &error);
231 _E("Failed to remove group[%s]--caused by[%s]", group, error->message);