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_KEY_IMAGE_UPLOAD_NAME "image_address"
32 #define CONF_FILE_NAME "pi.conf"
34 struct controller_util_s {
40 struct controller_util_s controller_util = { 0, };
42 static int _read_conf_file(void)
45 char conf_path[PATH_MAX] = {0,};
48 gkf = g_key_file_new();
51 prefix = app_get_resource_path();
53 snprintf(conf_path, sizeof(conf_path)-1, "%s%s", prefix, CONF_FILE_NAME);
57 if (!g_key_file_load_from_file(gkf, conf_path, G_KEY_FILE_NONE, NULL)) {
58 _E("could not read config file %s", conf_path);
62 controller_util.path = g_key_file_get_string(gkf,
63 CONF_GROUP_DEFAULT_NAME,
66 if (!controller_util.path)
67 _E("could not get the key string");
69 controller_util.address = g_key_file_get_string(gkf,
70 CONF_GROUP_DEFAULT_NAME,
71 CONF_KEY_ADDRESS_NAME,
73 if (!controller_util.address)
74 _E("could not get the key string");
76 controller_util.image_upload = g_key_file_get_string(gkf,
77 CONF_GROUP_DEFAULT_NAME,
78 CONF_KEY_IMAGE_UPLOAD_NAME,
80 if (!controller_util.image_upload)
81 _E("could not get the key string");
88 int controller_util_get_path(const char **path)
92 if (!controller_util.path) {
94 ret = _read_conf_file();
95 retv_if(-1 == ret, -1);
98 *path = controller_util.path;
103 int controller_util_get_address(const char **address)
105 retv_if(!address, -1);
107 if (!controller_util.address) {
109 ret = _read_conf_file();
110 retv_if(-1 == ret, -1);
113 *address = controller_util.address;
118 int controller_util_get_image_address(const char **image_upload)
120 retv_if(!image_upload, -1);
122 if (!controller_util.image_upload) {
124 ret = _read_conf_file();
125 retv_if(-1 == ret, -1);
128 *image_upload = controller_util.image_upload;
133 void controller_util_free(void)
135 if (controller_util.path) {
136 free(controller_util.path);
137 controller_util.path = NULL;
140 if (controller_util.address) {
141 free(controller_util.address);
142 controller_util.address = NULL;