Merge with bangbang-collector-pi 99/144199/5
authorJin Yoon <jinny.yoon@samsung.com>
Wed, 16 Aug 2017 00:23:51 +0000 (09:23 +0900)
committerJin Yoon <jinny.yoon@samsung.com>
Thu, 17 Aug 2017 10:27:40 +0000 (19:27 +0900)
Change-Id: I09b11a3fd234d1f0e5efa162c48513c14c044ac0

CMakeLists.txt
packaging/org.tizen.position-finder-client.spec
src/connectivity.c
src/controller.c [moved from src/control.c with 99% similarity]

index 8e591e3..50865a2 100644 (file)
@@ -3,7 +3,8 @@ PROJECT(position-finder-client C)
 
 SET(INSTALL_EXEC_PREFIX "${INSTALL_PREFIX}/bin")
 SET(INSTALL_RESDIR "${INSTALL_PREFIX}/res")
-SET(INSTALL_DATADIR "/home/owner/apps_rw/org.tizen.position-finder-client/data")
+SET(INSTALL_OWNER_RESDIR "/home/owner/apps_rw/org.tizen.position-finder-client/res")
+SET(INSTALL_OWNER_DATADIR "/home/owner/apps_rw/org.tizen.position-finder-client/data")
 SET(CMAKE_VERBOSE_MAKEFILE 0)
 
 SET(PROJECT_ROOT_DIR "${CMAKE_SOURCE_DIR}")
@@ -33,7 +34,7 @@ INCLUDE_DIRECTORIES(${PROJECT_ROOT_DIR}/inc)
 
 ADD_EXECUTABLE(${PROJECT_NAME}
        ${PROJECT_ROOT_DIR}/src/connectivity.c
-       ${PROJECT_ROOT_DIR}/src/control.c
+       ${PROJECT_ROOT_DIR}/src/controller.c
 )
 
 TARGET_LINK_LIBRARIES(${PROJECT_NAME} ${pkgs_LDFLAGS} -lm)
@@ -43,8 +44,8 @@ TARGET_LINK_LIBRARIES(${PROJECT_NAME} ${APP_PKGS_LDFLAGS})
 INSTALL(TARGETS ${PROJECT_NAME} DESTINATION ${INSTALL_EXEC_PREFIX})
 
 INSTALL(FILES ${PROJECT_ROOT_DIR}/tizen-manifest.xml DESTINATION ${SYS_PACKAGES_DIR} RENAME org.tizen.position-finder-client.xml)
-INSTALL(DIRECTORY DESTINATION ${PREFIX}/data)
+INSTALL(DIRECTORY DESTINATION ${INSTALL_OWNER_DATADIR})
 INSTALL(FILES ${PROJECT_ROOT_DIR}/shared/res/position_finder_client.png DESTINATION ${SYS_ICONS_DIR})
-INSTALL(FILES ${PROJECT_ROOT_DIR}/res/iotcon-test-svr-db-client.dat DESTINATION ${INSTALL_DATADIR})
+INSTALL(FILES ${PROJECT_ROOT_DIR}/res/iotcon-test-svr-db-client.dat DESTINATION ${INSTALL_OWNER_RESDIR})
 
 # End of a file
index 0a55f4e..0f86445 100644 (file)
@@ -31,6 +31,7 @@ Thing Illumination
 %define _pkg_shared_dir %{_pkg_dir}/shared
 %define _pkg_data_dir %{_pkg_dir}/data
 %define _pkg_rw_data_dir /home/owner/apps_rw/org.tizen.position-finder-client/data
+%define _pkg_res_dir /home/owner/apps_rw/org.tizen.position-finder-client/res
 %define _sys_icons_dir %{_pkg_shared_dir}/res
 %define _sys_packages_dir %{TZ_SYS_RO_PACKAGES}
 %define _sys_license_dir %{TZ_SYS_SHARE}/license
@@ -62,6 +63,10 @@ make %{?jobs:-j%jobs}
 
 %post
 /sbin/ldconfig
+chsmack -a "User::Pkg::org.tizen.position-finder-client" %{_pkg_res_dir}/*.dat
+chmod 444 %{_pkg_res_dir}/*.dat
+
+touch %{_pkg_res_dir}/iotcon-test-svr-db-client.dat
 chsmack -a "User::Pkg::org.tizen.position-finder-client" %{_pkg_rw_data_dir}/*.dat
 chmod 666 %{_pkg_rw_data_dir}/*.dat
 
@@ -69,7 +74,8 @@ chmod 666 %{_pkg_rw_data_dir}/*.dat
 
 %files
 %manifest org.tizen.position-finder-client.manifest
-%{_pkg_rw_data_dir}/*.dat
+%{_pkg_res_dir}/*.dat
+%{_pkg_rw_data_dir}
 %defattr(-,root,root,-)
 %{_pkg_dir}/bin/position-finder-client
 %{_sys_packages_dir}/org.tizen.position-finder-client.xml
index 8371418..3b40b1d 100644 (file)
@@ -19,6 +19,7 @@
  * limitations under the License.
  */
 
+#include <stdio.h>
 #include <stdlib.h>
 #include <time.h>
 #include <glib.h>
 #include "log.h"
 #include "connectivity.h"
 
-#define CBOR_FILE "/home/owner/apps_rw/org.tizen.position-finder-client/data/iotcon-test-svr-db-client.dat"
 #define DOOR_RESOURCE_URI_PREFIX "/door"
 #define MAXIMUM_LIVE_INTERVAL 10l
+#define BUFSIZE 1024
+#define CBOR_FILE_IN_RES       "/home/owner/apps_rw/org.tizen.position-finder-client/res/iotcon-test-svr-db-client.dat"
+#define CBOR_FILE_IN_DATA      "/home/owner/apps_rw/org.tizen.position-finder-client/data/iotcon-test-svr-db-client.dat"
+#define ULTRASONIC_RESOURCE_TYPE "org.tizen.door"
 
 struct _connectivity_observe_resource_cb_s {
        connectivity_observe_resource_cb cb;
@@ -97,28 +101,27 @@ static void _observe_cb(iotcon_remote_resource_h resource, iotcon_error_e err, i
 }
 
 /* return values : -1 error, 0 not exist, 1 exist */
-static int _exist_device_id_in_list(iotcon_remote_resource_h resource)
+static int _exist_uri_path_in_list(iotcon_remote_resource_h resource)
 {
        Eina_List *l = NULL, *ln = NULL;
        connectivity_resource_s *temp = NULL;
-       char *device_id = NULL;
+       char *uri_path = NULL;
        int ret = -1;
 
        retv_if(!resource, -1);
 
-       /* device_id is derived from subject id. */
-       ret = iotcon_remote_resource_get_device_id(resource, &device_id);
+       ret = iotcon_remote_resource_get_uri_path(resource, &uri_path);
        retv_if(IOTCON_ERROR_NONE != ret, -1);
 
        EINA_LIST_FOREACH_SAFE(connectivity_info.list, l, ln, temp) {
-               continue_if(!temp->device_id);
-               if (!strncmp(temp->device_id, device_id, strlen(device_id))) {
-                       _D("\"%s\" already found. skip !", device_id);
+               continue_if(!temp->uri_path);
+               if (!strncmp(temp->uri_path, uri_path, strlen(uri_path))) {
+                       _D("\"%s\" already found. skip !", uri_path);
                        return 1;
                }
        }
 
-       _I("Resource[%s] is not in the list", device_id);
+       _I("Resource[%s] is not in the list", uri_path);
 
        return 0;
 }
@@ -210,7 +213,7 @@ static int _retrieve_resource_info(iotcon_remote_resource_h resource, connectivi
        ret = iotcon_remote_resource_clone(resource, &(*info)->resource);
        goto_if(IOTCON_ERROR_NONE != ret, error);
 
-       _I("Resource Addr[%s/%s] is in Device[%s]", host_address, uri_path, device_name);
+       _I("Resource Addr[%s/%s] is in Device[%s]", host_address, uri_path, device_id);
 
        (*info)->device_id = strdup(device_id);
        goto_if(!(*info)->device_id, error);
@@ -249,6 +252,7 @@ error:
                        (*info)->device_id = NULL;
                }
                free(*info);
+               *info = NULL;
        }
 
        return -1;
@@ -321,7 +325,7 @@ static bool _found_resource_cb(iotcon_remote_resource_h resource, iotcon_error_e
 
        _I("Resource is found");
 
-       ret = _exist_device_id_in_list(resource);
+       ret = _exist_uri_path_in_list(resource);
        retv_if(-1 == ret, IOTCON_FUNC_CONTINUE);
        if (1 == ret) return IOTCON_FUNC_CONTINUE;
 
@@ -343,11 +347,46 @@ error:
        return IOTCON_FUNC_CONTINUE;
 }
 
+static void _copy_file(const char *in_filename, const char *out_filename)
+{
+       char buf[BUFSIZE] = { 0, };
+       size_t nread = 0;
+       FILE *in = NULL;
+       FILE *out = NULL;
+
+       ret_if(!in_filename);
+       ret_if(!out_filename);
+
+       in = fopen(in_filename, "r");
+       ret_if(!in);
+
+       out = fopen(out_filename, "w");
+       goto_if(!out, error);
+
+       rewind(in);
+       while ((nread = fread(buf, 1, sizeof(buf), in)) > 0) {
+               if (fwrite (buf, 1, nread, out) < nread) {
+                       _E("critical error to copy a file");
+                       break;
+               }
+       }
+
+       fclose(in);
+       fclose(out);
+
+       return;
+
+error:
+       fclose(out);
+}
+
 int connectivity_init(void)
 {
        int ret = -1;
 
-       ret = iotcon_initialize(CBOR_FILE);
+       _copy_file(CBOR_FILE_IN_RES, CBOR_FILE_IN_DATA);
+
+       ret = iotcon_initialize(CBOR_FILE_IN_DATA);
        if (IOTCON_ERROR_NONE != ret) {
                _E("iotcon_initialize() Fail(%d)", ret);
                return -1;
similarity index 99%
rename from src/control.c
rename to src/controller.c
index bdf5776..2ac4b46 100644 (file)
@@ -118,7 +118,7 @@ static void service_app_low_memory(app_event_info_h event_info, void *user_data)
 
 int main(int argc, char* argv[])
 {
-    char ad[50] = {0, };
+       char ad[50] = {0, };
        service_app_lifecycle_callback_s event_callback;
        app_event_handler_h handlers[5] = {NULL, };
        int ret = 0;