2 * Copyright (c) 2017 Samsung Electronics Co., Ltd.
4 * Contact: Jin Yoon <jinny.yoon@samsung.com>
5 * Geunsun Lee <gs86.lee@samsung.com>
6 * Eunyoung Lee <ey928.lee@samsung.com>
7 * Junkyu Han <junkyu.han@samsung.com>
9 * Licensed under the Flora License, Version 1.1 (the License);
10 * you may not use this file except in compliance with the License.
11 * You may obtain a copy of the License at
13 * http://floralicense.org/license/
15 * Unless required by applicable law or agreed to in writing, software
16 * distributed under the License is distributed on an AS IS BASIS,
17 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18 * See the License for the specific language governing permissions and
19 * limitations under the License.
27 #define CONF_GROUP_DEFAULT_NAME "default"
28 #define CONF_KEY_PATH_NAME "path"
29 #define CONF_KEY_ADDRESS_NAME "address"
31 struct controller_util_s {
36 struct controller_util_s controller_util = { 0, };
38 static int _read_conf_file(void)
42 gkf = g_key_file_new();
45 if (!g_key_file_load_from_file(gkf, CONF_FILE, G_KEY_FILE_NONE, NULL)) {
46 _E("could not read config file %s", CONF_FILE);
50 controller_util.path = g_key_file_get_string(gkf,
51 CONF_GROUP_DEFAULT_NAME,
54 if (!controller_util.path)
55 _E("could not get the key string");
57 controller_util.address = g_key_file_get_string(gkf,
58 CONF_GROUP_DEFAULT_NAME,
59 CONF_KEY_ADDRESS_NAME,
61 if (!controller_util.address)
62 _E("could not get the key string");
69 int controller_util_get_path(const char **path)
73 if (!controller_util.path) {
75 ret = _read_conf_file();
76 retv_if(-1 == ret, -1);
79 *path = controller_util.path;
84 int controller_util_get_address(const char **address)
86 retv_if(!address, -1);
88 if (!controller_util.address) {
90 ret = _read_conf_file();
91 retv_if(-1 == ret, -1);
94 *address = controller_util.address;
99 void controller_util_free(void)
101 if (controller_util.path) {
102 free(controller_util.path);
103 controller_util.path = NULL;
106 if (controller_util.address) {
107 free(controller_util.address);
108 controller_util.address = NULL;