From: saerome.kim Date: Fri, 26 Jan 2018 10:57:24 +0000 (+0900) Subject: comp-manager: add receiving data from remote owner X-Git-Tag: submit/tizen/20190131.065036~149 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=e05335f27094c6d0c3826129eaf78c3bb28b48a5;p=platform%2Fcore%2Fapi%2Fmulti-device-group.git comp-manager: add receiving data from remote owner Signed-off-by: saerome.kim --- diff --git a/capi/demo/comp-manager.c b/capi/demo/comp-manager.c old mode 100755 new mode 100644 index 0cd1097..9cf2303 --- a/capi/demo/comp-manager.c +++ b/capi/demo/comp-manager.c @@ -44,7 +44,7 @@ static char message[MENU_DATA_SIZE + 1] = "Hello World!!"; static int run_group_find(MManager *mm, struct menu_data *menu); static int run_devices_find(MManager *mm, struct menu_data *menu); -void _request_result_cb(char *cmd, char *arg, int ret, void *user_data) +void receive_request_result(char *cmd, char *arg, int ret, void *user_data) { msg("_request_result_cb is called"); @@ -68,6 +68,8 @@ void _request_result_cb(char *cmd, char *arg, int ret, void *user_data) msgb("[CMD] Request Delete Group [%s(0x%X)]", comp_error_to_string(ret), ret); if (ret == 0 && arg != NULL) msgb("Deleted Group name is %s", arg); + } else { + msgb("[DATA] %s", arg); } } } @@ -80,8 +82,6 @@ int run_get_my_id(MManager *mm, struct menu_data *menu) char *uuid; ret = companion_device_get_my_uuid(&uuid); - companion_request_result_callback(_request_result_cb, NULL); - if (COMP_ERROR_NONE != ret) { msgr("Failed to Get My Device ID: [%s(0x%X)]", comp_error_to_string(ret), ret); return RET_FAILURE; diff --git a/capi/demo/main.c b/capi/demo/main.c index adb9006..f8b6d23 100644 --- a/capi/demo/main.c +++ b/capi/demo/main.c @@ -36,6 +36,8 @@ extern GList *found_device_list; #define CASE_TO_STR(x) case x: return #x; +void receive_request_result(char *cmd, char *arg, int ret, void *user_data); + const char* comp_error_to_string(comp_error_e err) { switch (err) { @@ -67,6 +69,8 @@ static int __init_func(MManager *mm, struct menu_data *menu) comp_error_to_string(ret), ret); return RET_FAILURE; } + companion_request_result_callback(receive_request_result, NULL); + return RET_SUCCESS; } diff --git a/capi/src/companion.c b/capi/src/companion.c old mode 100755 new mode 100644 index 457ee9a..a2fe63f --- a/capi/src/companion.c +++ b/capi/src/companion.c @@ -321,8 +321,8 @@ int companion_initialize() COMPANION_LOCK; if (__is_initialized == false) { - ret = _gdbus_initialize(); - __is_initialized = true; + ret = _gdbus_initialize(); + __is_initialized = true; } ref_count++; diff --git a/src/companion-manager/include/comp_iot.h b/src/companion-manager/include/comp_iot.h old mode 100755 new mode 100644 index 85bafba..b1b30aa --- a/src/companion-manager/include/comp_iot.h +++ b/src/companion-manager/include/comp_iot.h @@ -12,6 +12,8 @@ typedef struct _iot_discovery_t { } iot_discovery_t; typedef struct _comp_command_t { + int tid; + int resource_type; gchar *command; gchar *uuid; gchar *host; diff --git a/src/companion-manager/src/comp_group.c b/src/companion-manager/src/comp_group.c old mode 100755 new mode 100644 index f957a9e..711432b --- a/src/companion-manager/src/comp_group.c +++ b/src/companion-manager/src/comp_group.c @@ -140,7 +140,9 @@ int comp_group_find(int timeout) g_list_free_full (found_group_list, _free_func); found_group_list = NULL; - ret = comp_iot_discovery_resource(COMP_RESOURCE_TYPE_GROUP, timeout, NULL); + comp_command_t *cmd = g_new0(comp_command_t, 1); + + ret = comp_iot_discovery_resource(COMP_RESOURCE_TYPE_GROUP, timeout, cmd); if (ret != COMP_ERROR_NONE) { LOG_ERR("Failed to discover resource : %s", comp_log_get_error_string(ret)); diff --git a/src/companion-manager/src/comp_iot.c b/src/companion-manager/src/comp_iot.c old mode 100755 new mode 100644 index a1e656c..37d5bff --- a/src/companion-manager/src/comp_iot.c +++ b/src/companion-manager/src/comp_iot.c @@ -111,6 +111,8 @@ static void _request_handler(iotcon_resource_h resource, iotcon_request_h reques result = comp_group_create(group_name); arg = g_strdup(group_name); + + free(group_name); } else if (strcmp(command, "2") == 0) { LOG_DEBUG("Request invite"); char *group_name; @@ -123,6 +125,9 @@ static void _request_handler(iotcon_resource_h resource, iotcon_request_h reques result = comp_group_invite(group_name, uuid, "12341234"); arg = g_strdup(uuid); + + free(group_name); + free(uuid); } else if (strcmp(command, "3") == 0) { LOG_DEBUG("Request eject"); char *group_name; @@ -135,12 +140,23 @@ static void _request_handler(iotcon_resource_h resource, iotcon_request_h reques result = comp_group_dismiss(group_name, uuid); arg = g_strdup(uuid); + + free(group_name); + free(uuid); } else if (strcmp(command, "4") == 0) { LOG_DEBUG("Request delete group"); arg = g_strdup("DELETED"); + } else { + char *data = NULL; + LOG_DEBUG("Receive Data"); + iotcon_query_lookup(query, "data", &data); + arg = g_strdup(data); + free(data); } notify_request_result(command, arg, result); + + free(arg); } ret = iotcon_response_create(request, &response); @@ -235,14 +251,59 @@ static bool _get_res_type_cb(const char *string, void *user_data) int found_group_count = 0; +static void _clear_user_data(void *user_data) +{ + comp_command_t *cmd = user_data; + + if (NULL == cmd) + return; + + if (cmd->tid) { + g_source_remove(cmd->tid); + } + + if (cmd->command) { + g_free(cmd->command); + cmd->command = NULL; + } + if (cmd->uuid) { + g_free(cmd->uuid); + cmd->uuid = NULL; + } + if (cmd->host) { + g_free(cmd->host); + cmd->host = NULL; + } + if (cmd->arg1) { + g_free(cmd->arg1); + cmd->arg1 = NULL; + } + if (cmd->arg2) { + g_free(cmd->arg2); + cmd->arg2 = NULL; + } + if (cmd->arg3) { + g_free(cmd->arg3); + cmd->arg3 = NULL; + } + if (cmd->arg4) { + g_free(cmd->arg4); + cmd->arg4 = NULL; + } +} + static void _on_get(iotcon_remote_resource_h resource, iotcon_error_e err, iotcon_request_type_e request_type, iotcon_response_h response, void *user_data) { last_get_result = err; + iotcon_remote_resource_destroy(resource); + + _clear_user_data(user_data); + LOG_DEBUG("iotcon error : %d", err); - if (IOTCON_ERROR_NONE != err) - return; + if (IOTCON_ERROR_NONE != err) + return; } @@ -353,11 +414,14 @@ static bool _found_resource(iotcon_remote_resource_h resource, iotcon_query_add(query, "id", cmd->arg2); } else if (strcmp(cmd->command, "4") == 0) { //request delete group iotcon_query_add(query, "name", cmd->arg1); + } else if (strcmp(cmd->command, "5") == 0) { /* Send Data */ + iotcon_query_add(query, "data", cmd->arg1); } - ret = iotcon_remote_resource_get(resource_clone, query, _on_get, NULL); + ret = iotcon_remote_resource_get(resource_clone, query, _on_get, cmd); if (IOTCON_ERROR_NONE != ret) { iotcon_remote_resource_destroy(resource_clone); + _clear_user_data(cmd); return IOTCON_FUNC_CONTINUE; } } @@ -370,18 +434,20 @@ static bool _found_resource(iotcon_remote_resource_h resource, static gboolean _timeout_cb(gpointer data) { int ret = -1; + comp_command_t *cmd = (comp_command_t *)data; - comp_resource_type_e resource_type = (comp_resource_type_e)data; - - if (resource_type == COMP_RESOURCE_TYPE_GROUP) { + if (cmd->resource_type == COMP_RESOURCE_TYPE_GROUP) { if (found_group_count > 0) ret = 0; notify_group_find_finish(ret); - } else if (resource_type == COMP_RESOURCE_TYPE_DATA) { + + } else if (cmd->resource_type == COMP_RESOURCE_TYPE_DATA) { notify_send_data_finish("RESP_DATA", last_get_result); } + _clear_user_data(data); + return false; } @@ -396,12 +462,14 @@ int comp_iot_discovery_resource(comp_resource_type_e resource_type, int timeout, ret = iotcon_set_timeout(timeout); if (IOTCON_ERROR_NONE != ret) { LOG_ERR("Failed to set timeout value"); + _clear_user_data(user_data); return COMP_ERROR_OPERATION_FAILED; } ret = iotcon_query_create(&query); if (IOTCON_ERROR_NONE != ret) { LOG_ERR("Failed to create iotcon query"); + _clear_user_data(user_data); return COMP_ERROR_OPERATION_FAILED; } @@ -409,6 +477,7 @@ int comp_iot_discovery_resource(comp_resource_type_e resource_type, int timeout, comp_resource_get_type(resource_type)); if (IOTCON_ERROR_NONE != ret) { LOG_ERR("Failed to set iotcon query resource type"); + _clear_user_data(user_data); return COMP_ERROR_OPERATION_FAILED; } @@ -423,7 +492,8 @@ int comp_iot_discovery_resource(comp_resource_type_e resource_type, int timeout, IOTCON_CONNECTIVITY_IP | IOTCON_CONNECTIVITY_PREFER_UDP, query, _found_resource, user_data); - g_timeout_add_seconds(timeout + 1, _timeout_cb, (gpointer)resource_type); + cmd->resource_type = resource_type; + cmd->tid = g_timeout_add_seconds(timeout + 1, _timeout_cb, cmd); LOG_DEBUG("find resource : %s", get_error_message(ret));