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.
25 #include <app_common.h>
28 #define CONF_GROUP_DEFAULT_NAME "default"
29 #define CONF_KEY_PATH_NAME "path"
30 #define CONF_KEY_ADDRESS_NAME "address"
31 #define CONF_FILE_NAME "pi.conf"
33 struct controller_util_s {
38 struct controller_util_s controller_util = { 0, };
40 static int _read_conf_file(void)
43 char conf_path[PATH_MAX] = {0,};
46 gkf = g_key_file_new();
49 prefix = app_get_resource_path();
51 snprintf(conf_path, sizeof(conf_path)-1, "%s%s", prefix, CONF_FILE_NAME);
55 if (!g_key_file_load_from_file(gkf, conf_path, G_KEY_FILE_NONE, NULL)) {
56 _E("could not read config file %s", conf_path);
60 controller_util.path = g_key_file_get_string(gkf,
61 CONF_GROUP_DEFAULT_NAME,
64 if (!controller_util.path)
65 _E("could not get the key string");
67 controller_util.address = g_key_file_get_string(gkf,
68 CONF_GROUP_DEFAULT_NAME,
69 CONF_KEY_ADDRESS_NAME,
71 if (!controller_util.address)
72 _E("could not get the key string");
79 int controller_util_get_path(const char **path)
83 if (!controller_util.path) {
85 ret = _read_conf_file();
86 retv_if(-1 == ret, -1);
89 *path = controller_util.path;
94 int controller_util_get_address(const char **address)
96 retv_if(!address, -1);
98 if (!controller_util.address) {
100 ret = _read_conf_file();
101 retv_if(-1 == ret, -1);
104 *address = controller_util.address;
109 void controller_util_free(void)
111 if (controller_util.path) {
112 free(controller_util.path);
113 controller_util.path = NULL;
116 if (controller_util.address) {
117 free(controller_util.address);
118 controller_util.address = NULL;