From: Jin Yoon Date: Fri, 18 Aug 2017 07:10:47 +0000 (+0900) Subject: Use .dev_id file when uri_path is NULL on connectivity_set_resource() X-Git-Tag: accepted/tizen/4.0/unified/20170828.224146^0 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=e56711738b1d4c62319a00fc7058c057d8101f43;p=apps%2Fnative%2Fposition-finder-server.git Use .dev_id file when uri_path is NULL on connectivity_set_resource() Change-Id: I531f7c81b242eb7bb19501b3078e6801c5d9c40d --- diff --git a/CMakeLists.txt b/CMakeLists.txt index a496dd6..a2cfc40 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -22,6 +22,7 @@ pkg_check_modules(APP_PKGS REQUIRED ADD_DEFINITIONS(-DCBOR_FILE_IN_RES="${INSTALL_RESDIR}/${CBOR_FILE}") ADD_DEFINITIONS(-DCBOR_FILE_IN_DATA="${INSTALL_OWNER_DATADIR}/${CBOR_FILE}") +ADD_DEFINITIONS(-DCONF_FILE="${INSTALL_OWNER_DATADIR}/${CONF_FILE}") FOREACH (flag ${APP_PKGS_CFLAGS}) SET(EXTRA_CFLAGS "${EXTRA_CFLAGS} ${flag}") diff --git a/packaging/org.tizen.position-finder-server.spec b/packaging/org.tizen.position-finder-server.spec index 6937d79..1487fb0 100644 --- a/packaging/org.tizen.position-finder-server.spec +++ b/packaging/org.tizen.position-finder-server.spec @@ -41,6 +41,7 @@ Server for Position Finder %define _sys_packages_dir %{TZ_SYS_RO_PACKAGES} %define _sys_license_dir %{TZ_SYS_SHARE}/license %define _cbor_file iotcon-test-svr-db-server.dat +%define _conf_file .dev_id %ifarch %{arm} export CFLAGS="$CFLAGS -DTIZEN_BUILD_TARGET" @@ -60,7 +61,8 @@ cmake . -DP_NAME=%{P_NAME} \ -DINSTALL_RESDIR=%{_pkg_res_dir} \ -DSYS_ICONS_DIR=%{_sys_icons_dir} \ -DSYS_PACKAGES_DIR=%{_sys_packages_dir} \ - -DCBOR_FILE=%{_cbor_file} + -DCBOR_FILE=%{_cbor_file} \ + -DCONF_FILE=%{_conf_file} make %{?jobs:-j%jobs} %install @@ -82,6 +84,12 @@ touch %{_pkg_rw_data_dir}/%{_cbor_file} chsmack -a "User::Pkg::%{alias}" %{_pkg_rw_data_dir}/*.dat chmod 666 %{_pkg_rw_data_dir}/*.dat +# This routine will be used in the file of .dev_id. +#touch %{_pkg_rw_data_dir}/%{_conf_file} +#echo "/door/777" > %{_pkg_rw_data_dir}/%{_conf_file} +#chsmack -a "User::Pkg::%{alias}" %{_pkg_rw_data_dir}/%{_conf_file} +#chmod 444 %{_pkg_rw_data_dir}/%{_conf_file} + %postun -p /sbin/ldconfig %files diff --git a/src/connectivity.c b/src/connectivity.c index 7a4ae94..5065735 100644 --- a/src/connectivity.c +++ b/src/connectivity.c @@ -32,6 +32,7 @@ #define ULTRASONIC_RESOURCE_TYPE "org.tizen.door" #define BUFSIZE 1024 +#define URI_PATH_LEN 64 static void _request_resource_handler(iotcon_resource_h resource, iotcon_request_h request, void *user_data); @@ -413,6 +414,28 @@ void connectivity_unset_resource(connectivity_resource_s *resource_info) free(resource_info); } +static int _get_default_uri_path_in_conf(char *buf, int size) +{ + FILE *in = NULL; + size_t nread = 0; + + in = fopen(CONF_FILE, "r"); + retv_if(!in, -1); + + nread = fread(buf, 1, size, in); + if (nread <= 0) { + _I("No contents in the conf."); + return -1; + } + + if (buf[nread - 1] == '\n') + buf[nread - 1] = '\0'; + + fclose(in); + + return 0; +} + int connectivity_set_resource(const char *uri_path, const char *type, connectivity_resource_s **out_resource_info) { iotcon_resource_types_h resource_types = NULL; @@ -420,6 +443,18 @@ int connectivity_set_resource(const char *uri_path, const char *type, connectivi connectivity_resource_s *resource_info = NULL; uint8_t policies; int ret = -1; + const char *final_uri_path = NULL; + char default_uri_path[URI_PATH_LEN] = { 0, }; + + if (uri_path) { + final_uri_path = uri_path; + } else { + ret = _get_default_uri_path_in_conf(default_uri_path, URI_PATH_LEN); + retv_if(ret < 0, -1); + final_uri_path = default_uri_path; + } + + _D("uri path : [%s]", final_uri_path); resource_info = calloc(1, sizeof(connectivity_resource_s)); retv_if(!resource_info, -1); @@ -445,7 +480,7 @@ int connectivity_set_resource(const char *uri_path, const char *type, connectivi IOTCON_RESOURCE_OBSERVABLE | IOTCON_RESOURCE_SECURE; - ret = iotcon_resource_create(uri_path, + ret = iotcon_resource_create(final_uri_path, resource_types, ifaces, policies,