diff options
author | Jeonghoon Park <jh1979.park@samsung.com> | 2017-11-07 11:23:55 +0900 |
---|---|---|
committer | Jeonghoon Park <jh1979.park@samsung.com> | 2017-11-07 11:23:55 +0900 |
commit | cbf1a70bde558e5f38c40015d1c2399a1a92e3cf (patch) | |
tree | 1ff76ccff7d3d8564bf09a2817a175d5b9ced7af | |
parent | 37035381578b161d8cf56cc6362705f1855d9dbd (diff) | |
download | position-finder-server-cbf1a70bde558e5f38c40015d1c2399a1a92e3cf.tar.gz position-finder-server-cbf1a70bde558e5f38c40015d1c2399a1a92e3cf.tar.bz2 position-finder-server-cbf1a70bde558e5f38c40015d1c2399a1a92e3cf.zip |
merge controller util module from master branch
Change-Id: I50e08c18ce8925580efa8471118c93f01b209a85
-rw-r--r-- | inc/controller_util.h | 29 | ||||
-rw-r--r-- | src/controller_util.c | 110 |
2 files changed, 139 insertions, 0 deletions
diff --git a/inc/controller_util.h b/inc/controller_util.h new file mode 100644 index 0000000..29b5e46 --- /dev/null +++ b/inc/controller_util.h @@ -0,0 +1,29 @@ +/* + * Copyright (c) 2017 Samsung Electronics Co., Ltd. + * + * Contact: Jin Yoon <jinny.yoon@samsung.com> + * Geunsun Lee <gs86.lee@samsung.com> + * Eunyoung Lee <ey928.lee@samsung.com> + * Junkyu Han <junkyu.han@samsung.com> + * + * Licensed under the Flora License, Version 1.1 (the License); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://floralicense.org/license/ + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an AS IS BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef __POSITION_FINDER_CONTROLLER_UTIL_H__ +#define __POSITION_FINDER_CONTROLLER_UTIL_H__ + +int controller_util_get_path(const char **path); +int controller_util_get_address(const char **address); +void controller_util_free(void); + +#endif /* __POSITION_FINDER_CONTROLLER_UTIL_H__ */ diff --git a/src/controller_util.c b/src/controller_util.c new file mode 100644 index 0000000..b894f76 --- /dev/null +++ b/src/controller_util.c @@ -0,0 +1,110 @@ +/* + * Copyright (c) 2017 Samsung Electronics Co., Ltd. + * + * Contact: Jin Yoon <jinny.yoon@samsung.com> + * Geunsun Lee <gs86.lee@samsung.com> + * Eunyoung Lee <ey928.lee@samsung.com> + * Junkyu Han <junkyu.han@samsung.com> + * + * Licensed under the Flora License, Version 1.1 (the License); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://floralicense.org/license/ + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an AS IS BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include <stdlib.h> +#include <glib.h> + +#include "log.h" + +#define CONF_GROUP_DEFAULT_NAME "default" +#define CONF_KEY_PATH_NAME "path" +#define CONF_KEY_ADDRESS_NAME "address" + +struct controller_util_s { + char *path; + char *address; +}; + +struct controller_util_s controller_util = { 0, }; + +static int _read_conf_file(void) +{ + GKeyFile *gkf = NULL; + + gkf = g_key_file_new(); + retv_if(!gkf, -1); + + if (!g_key_file_load_from_file(gkf, CONF_FILE, G_KEY_FILE_NONE, NULL)) { + _E("could not read config file %s", CONF_FILE); + return -1; + } + + controller_util.path = g_key_file_get_string(gkf, + CONF_GROUP_DEFAULT_NAME, + CONF_KEY_PATH_NAME, + NULL); + if (!controller_util.path) + _E("could not get the key string"); + + controller_util.address = g_key_file_get_string(gkf, + CONF_GROUP_DEFAULT_NAME, + CONF_KEY_ADDRESS_NAME, + NULL); + if (!controller_util.address) + _E("could not get the key string"); + + g_key_file_free(gkf); + + return 0; +} + +int controller_util_get_path(const char **path) +{ + retv_if(!path, -1); + + if (!controller_util.path) { + int ret = -1; + ret = _read_conf_file(); + retv_if(-1 == ret, -1); + } + + *path = controller_util.path; + + return 0; +} + +int controller_util_get_address(const char **address) +{ + retv_if(!address, -1); + + if (!controller_util.address) { + int ret = -1; + ret = _read_conf_file(); + retv_if(-1 == ret, -1); + } + + *address = controller_util.address; + + return 0; +} + +void controller_util_free(void) +{ + if (controller_util.path) { + free(controller_util.path); + controller_util.path = NULL; + } + + if (controller_util.address) { + free(controller_util.address); + controller_util.address = NULL; + } +} |