diff options
author | Jin Yoon <jinny.yoon@samsung.com> | 2017-08-25 09:59:47 +0900 |
---|---|---|
committer | Jin Yoon <jinny.yoon@samsung.com> | 2017-08-25 10:14:19 +0900 |
commit | c95bcf58cea8f459279c667045115ddd1e152b93 (patch) | |
tree | 11d43e0f0bc79002b82c0ad4a8c69c92214bbc1d | |
parent | 1cb8889d4dba90f89926529342d68984b44bbb70 (diff) | |
download | position-finder-client-c95bcf58cea8f459279c667045115ddd1e152b93.tar.gz position-finder-client-c95bcf58cea8f459279c667045115ddd1e152b93.tar.bz2 position-finder-client-c95bcf58cea8f459279c667045115ddd1e152b93.zip |
Test client : identify servers by path
Change-Id: I6b04555346853a904339fdf3952d435b1026711d
-rwxr-xr-x | CMakeLists.txt | 2 | ||||
-rw-r--r-- | inc/connectivity.h | 4 | ||||
-rw-r--r-- | src/connectivity.c | 35 | ||||
-rwxr-xr-x | src/controller.c | 33 |
4 files changed, 37 insertions, 37 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt index 45fe33d..e227b21 100755 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -26,7 +26,7 @@ pkg_check_modules(APP_PKGS REQUIRED ${CHECK_MODULES}) ADD_DEFINITIONS(-DCBOR_FILE_IN_RES="${INSTALL_RESDIR}/${CBOR_FILE}") ADD_DEFINITIONS(-DCBOR_FILE_IN_DATA="${INSTALL_OWNER_DATADIR}/${CBOR_FILE}") -ADD_DEFINITIONS(-DWEB_API_URI_DEV=\"http://10.113.63.43:3000/api/sensor/data\") +ADD_DEFINITIONS(-DWEB_API_URI_PUBLIC=\"http://13.56.171.255/api/sensor/data\") FOREACH (flag ${APP_PKGS_CFLAGS}) SET(EXTRA_CFLAGS "${EXTRA_CFLAGS} ${flag}") diff --git a/inc/connectivity.h b/inc/connectivity.h index 30072c4..b8ea8b7 100644 --- a/inc/connectivity.h +++ b/inc/connectivity.h @@ -25,8 +25,8 @@ #include "connectivity_internal.h" typedef struct _connectivity_resource_s connectivity_resource_s; -typedef void (*connectivity_observe_resource_cb)(connectivity_resource_s *resource_info, void *resource_data, void *user_data); -typedef void (*connectivity_foreach_cb)(connectivity_resource_s *resource_info, const char *uri_path, void *data); +typedef void (*connectivity_observe_resource_cb)(connectivity_resource_s *resource_info, const char *path, void *resource_data, void *user_data); +typedef void (*connectivity_foreach_cb)(connectivity_resource_s *resource_info, const char *path, void *data); extern int connectivity_resource_add_int(connectivity_resource_s *resource_info, const char *key, int value); extern int connectivity_resource_pop_int(connectivity_resource_s *resource_info, const char *key, int *value); diff --git a/src/connectivity.c b/src/connectivity.c index 61b0893..70ba5fa 100644 --- a/src/connectivity.c +++ b/src/connectivity.c @@ -36,6 +36,7 @@ #define MAXIMUM_LIVE_INTERVAL 10l #define BUFSIZE 1024 #define ULTRASONIC_RESOURCE_TYPE "org.tizen.door" +#define PATH "path" struct _connectivity_observe_resource_cb_s { connectivity_observe_resource_cb cb; @@ -49,6 +50,7 @@ struct _connectivity_resource_s { char *device_name; char *type; char *uri_path; + char *path; iotcon_remote_resource_h resource; time_t last_time; connectivity_observe_resource_cb_s *cb_info; @@ -90,7 +92,7 @@ int connectivity_resource_list_foreach(connectivity_foreach_cb cb, void *data) retv_if(!cb, -1); EINA_LIST_FOREACH_SAFE(connectivity_info.list, l, ln, temp) { - cb(temp, temp->uri_path, data); + cb(temp, temp->path, data); } return 0; @@ -100,6 +102,7 @@ static void _observe_cb(iotcon_remote_resource_h resource, iotcon_error_e err, i { int ret = -1; bool opened = false; + char *path = NULL; iotcon_attributes_h attributes = NULL; iotcon_representation_h repr = NULL; iotcon_response_result_e response_result; @@ -127,35 +130,44 @@ static void _observe_cb(iotcon_remote_resource_h resource, iotcon_error_e err, i ret = iotcon_representation_get_attributes(repr, &attributes); ret_if(IOTCON_ERROR_NONE != ret); + ret = iotcon_attributes_get_str(attributes, PATH, &path); + ret_if(IOTCON_ERROR_NONE != ret); + ret_if(!path); + ret = iotcon_attributes_get_bool(attributes, "opened", &opened); ret_if(IOTCON_ERROR_NONE != ret); + if (!resource_info->path) { + resource_info->path = strdup(path); + ret_if(!resource_info->path); + } + resource_info->last_time = time(NULL); - resource_info->cb_info->cb(resource_info, (void *)(int) opened, resource_info->cb_info->user_data); + resource_info->cb_info->cb(resource_info, path, (void *)(int) opened, resource_info->cb_info->user_data); } /* return values : -1 error, 0 not exist, 1 exist */ -static int _exist_uri_path_in_list(iotcon_remote_resource_h resource) +static int _exist_host_address_in_list(iotcon_remote_resource_h resource) { Eina_List *l = NULL, *ln = NULL; connectivity_resource_s *temp = NULL; - char *uri_path = NULL; + char *host_address = NULL; int ret = -1; retv_if(!resource, -1); - ret = iotcon_remote_resource_get_uri_path(resource, &uri_path); + ret = iotcon_remote_resource_get_host_address(resource, &host_address); retv_if(IOTCON_ERROR_NONE != ret, -1); EINA_LIST_FOREACH_SAFE(connectivity_info.list, l, ln, temp) { - continue_if(!temp->uri_path); - if (!strncmp(temp->uri_path, uri_path, strlen(uri_path))) { - _D("\"%s\" already found. skip !", uri_path); + continue_if(!temp->host_address); + if (!strncmp(temp->host_address, host_address, strlen(host_address))) { + _D("\"%s\" already found. skip !", host_address); return 1; } } - _I("Resource[%s] is not in the list", uri_path); + _I("Resource[%s] is not in the list", host_address); return 0; } @@ -305,6 +317,9 @@ static void _free_resource_info(connectivity_resource_s *info) if (info->uri_path) free(info->uri_path); + if (info->path) + free(info->path); + if (info->device_name) free(info->device_name); @@ -361,7 +376,7 @@ static bool _found_resource_cb(iotcon_remote_resource_h resource, iotcon_error_e _I("Resource is found"); - ret = _exist_uri_path_in_list(resource); + ret = _exist_host_address_in_list(resource); retv_if(-1 == ret, IOTCON_FUNC_CONTINUE); if (1 == ret) return IOTCON_FUNC_CONTINUE; diff --git a/src/controller.c b/src/controller.c index 5b67c00..c57982d 100755 --- a/src/controller.c +++ b/src/controller.c @@ -36,7 +36,7 @@ #define MAX_QUEUE_ELEMENTS 30 #define DOOR_RESOURCE_TYPE "org.tizen.door" #define FINDING_SERVER_INTERVAL 5.0f -#define POPPING_VALUE_INTERVAL 2.0f +#define POPPING_VALUE_INTERVAL 5.0f #ifdef WEB_API_URI_PUBLIC #define WEB_API_URI WEB_API_URI_PUBLIC @@ -44,28 +44,16 @@ #define WEB_API_URI WEB_API_URI_DEV #endif -void _observe_resource_cb(connectivity_resource_s *resource_info, void *resource_data, void *user_data) +#define KEY "opened" + +static void _observe_resource_cb(connectivity_resource_s *resource_info, const char *path, void *resource_data, void *user_data) { int detected = (int) resource_data; - static int queue[MAX_QUEUE_ELEMENTS] = { 0, }; - static int i = 0; - int j = 0; - int result = 0; int ret = 0; - if (detected) _I("Detected."); - else _I("Nothing detected."); - - queue[i++] = detected; - if (i == MAX_QUEUE_ELEMENTS) i = 0; - - for (j = 0; j < MAX_QUEUE_ELEMENTS && !result; j++) { - result |= queue[j]; - } + _I("[%s]'s result is [%d]", path, detected); - _I("Result value is [%d]\n", result); - - ret = connectivity_resource_add_int(resource_info, NULL, detected); + ret = connectivity_resource_add_int(resource_info, KEY, detected); if (ret < 0) _E("cannot add a value"); } @@ -81,7 +69,7 @@ static Eina_Bool _observe_timer_cb(void *data) return ECORE_CALLBACK_RENEW; } -static void _foreach_resource_list(connectivity_resource_s *resource_info, const char *uri_path, void *data) +static void _foreach_resource_list(connectivity_resource_s *resource_info, const char *path, void *data) { int ret = -1; int value = 0; @@ -91,16 +79,13 @@ static void _foreach_resource_list(connectivity_resource_s *resource_info, const if (ret < 0) _E("cannot pop a value"); - _I("Uri path : [%s], Value [%d]", uri_path, value); + _I("Path : [%s], Value [%d]", path, value); /* TODO */ sensor_data.hash = NULL; - sensor_data.enabled_sensor |= WEB_UTIL_SENSOR_MOTION; sensor_data.motion = value; - web_util_json_add_sensor_data(uri_path, &sensor_data); - - return; + web_util_json_add_sensor_data(path, &sensor_data); } static Eina_Bool _popping_timer_cb(void *data) |