From: Jihoon Jung Date: Wed, 24 Jan 2018 06:21:49 +0000 (+0900) Subject: [TEMP] Fix for demo X-Git-Tag: submit/tizen/20190131.065036~166 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=34b5dc38b7e8e3548042e50e1198030da718aff4;p=platform%2Fcore%2Fapi%2Fmulti-device-group.git [TEMP] Fix for demo Signed-off-by: Jihoon Jung --- diff --git a/capi/demo/comp-manager.c b/capi/demo/comp-manager.c old mode 100644 new mode 100755 index 4d7de28..f0c723d --- a/capi/demo/comp-manager.c +++ b/capi/demo/comp-manager.c @@ -677,6 +677,7 @@ static int run_group_get_found(MManager *mm, struct menu_data *menu) return RET_FAILURE; } msg(" - companion_group_get_found_groups() ret: [0x%X] [%s]", ret, comp_error_to_string(ret)); + found_group_list = NULL; for (int i = 0; i < count; i++) { companion_group_type_e type; @@ -893,16 +894,49 @@ static int run_create_subgroup(MManager *mm, struct menu_data *menu) companion_device_h device = NULL; companion_group_h group = NULL; - dev_count = g_list_length(found_device_list); + msg("Create subgroup"); + grp_count = g_list_length(found_group_list); + dev_count = g_list_length(found_device_list); if (0 >= dev_count || 0 >= grp_count) { msgr("No Device"); return RET_SUCCESS; } - group = (companion_group_h)(found_group_list[atoi(group_idx) - 1].data); - device = (companion_device_h)(found_device_list[atoi(device_idx) - 1].data); + int grp_idx; + if (group_idx != NULL && strlen(group_idx)) { + grp_idx = (unsigned short)strtol(group_idx, NULL, 10); + if (0 >= grp_idx) { + msgp("Invalid index. set to 1"); + grp_idx = 1; + } + } + + if (found_group_list) { + group = g_list_nth_data(found_group_list, grp_idx - 1); + if (NULL == group) { + msgr("Failed to g_hash_table_find"); + return RET_FAILURE; + } + } + + int dev_idx; + if (device_idx != NULL && strlen(device_idx)) { + dev_idx = (unsigned short)strtol(device_idx, NULL, 10); + if (0 >= dev_idx) { + msgp("Invalid index. set to 1"); + dev_idx = 1; + } + } + + if (found_device_list) { + device = g_list_nth_data(found_device_list, dev_idx - 1); + if (NULL == device) { + msgr("Failed to g_hash_table_find"); + return RET_FAILURE; + } + } ret = companion_create_subgroup(group, device, subgroupid); if (COMP_ERROR_NONE != ret) { @@ -931,7 +965,22 @@ static int run_get_subgroup(MManager *mm, struct menu_data *menu) return RET_SUCCESS; } - group = (companion_group_h)(found_group_list[atoi(group_idx - 1)].data); + int grp_idx; + if (group_idx != NULL && strlen(group_idx)) { + grp_idx = (unsigned short)strtol(group_idx, NULL, 10); + if (0 >= grp_idx) { + msgp("Invalid index. set to 1"); + grp_idx = 1; + } + } + + if (found_group_list) { + group = g_list_nth_data(found_group_list, grp_idx - 1); + if (NULL == group) { + msgr("Failed to g_hash_table_find"); + return RET_FAILURE; + } + } ret = companion_get_subgroups(group, &subgroups, &count); if (COMP_ERROR_NONE != ret) { @@ -966,8 +1015,39 @@ static int run_add_device_to_subgroup(MManager *mm, struct menu_data *menu) return RET_SUCCESS; } - subgroup = (companion_group_h)(found_subgroup_list[atoi(subgroup_idx) - 1].data); - device = (companion_device_h)(found_device_list[atoi(device_idx) - 1].data); + int subgrp_idx; + if (subgroup_idx != NULL && strlen(subgroup_idx)) { + subgrp_idx = (unsigned short)strtol(subgroup_idx, NULL, 10); + if (0 >= subgrp_idx) { + msgp("Invalid index. set to 1"); + subgrp_idx = 1; + } + } + + if (found_subgroup_list) { + subgroup = g_list_nth_data(found_subgroup_list, subgrp_idx - 1); + if (NULL == subgroup) { + msgr("Failed to g_hash_table_find"); + return RET_FAILURE; + } + } + + int dev_idx; + if (device_idx != NULL && strlen(device_idx)) { + dev_idx = (unsigned short)strtol(device_idx, NULL, 10); + if (0 >= dev_idx) { + msgp("Invalid index. set to 1"); + dev_idx = 1; + } + } + + if (found_device_list) { + device = g_list_nth_data(found_device_list, dev_idx - 1); + if (NULL == device) { + msgr("Failed to g_hash_table_find"); + return RET_FAILURE; + } + } ret = companion_add_device_to_subgroup(subgroup, device); if (COMP_ERROR_NONE != ret) { diff --git a/capi/src/companion.c b/capi/src/companion.c old mode 100644 new mode 100755 index cc1f6cb..4541c8c --- a/capi/src/companion.c +++ b/capi/src/companion.c @@ -150,13 +150,15 @@ static void __group_found_cb(Group *object, g_variant_iter_free(iter); group = _create_group_handle(uri_path, device_id, group_name, host_addr, resource_type, type); - group_found_cb.found_cb(type, group, group_found_cb.user_data); + if (group_found_cb.found_cb) + group_found_cb.found_cb(type, group, group_found_cb.user_data); } static void _group_find_finish_cb(Group *object, gint ret, gpointer user_data) { - group_find_finish_cb.finish_cb(ret, group_find_finish_cb.user_data); + if (device_find_finish_cb.finish_cb) + group_find_finish_cb.finish_cb(ret, group_find_finish_cb.user_data); } static void __device_found_cb(Group *object, @@ -186,7 +188,8 @@ static void __device_found_cb(Group *object, g_variant_iter_free(iter_row); device = _create_device_handle(device_id, friendly_name, device_type); - device_found_cb.found_cb(device, device_found_cb.user_data); + if (device_found_cb.found_cb) + device_found_cb.found_cb(device, device_found_cb.user_data); } g_variant_iter_free(iter); } @@ -879,7 +882,7 @@ int companion_create_subgroup(companion_group_h group, companion_device_h device GError *error = NULL; companion_device_t *dev = (companion_device_t *)device; companion_group_t *grp = (companion_group_t *)group; - _ERR("%s", dev->device_id); + _ERR("Device id : %s", dev->device_id); group_call_create_subgroup_sync(group_proxy, grp->group_name, dev->device_id, subgroup_name, &ret, NULL, &error); @@ -956,6 +959,7 @@ int companion_add_device_to_subgroup(companion_group_h subgroup, companion_devic companion_device_t *dev = (companion_device_t *)device; _ERR("%s", subgrp->group_name); + _ERR("%s", dev->device_id); group_call_add_device_to_subgroup(group_proxy, subgrp->group_name, dev->device_id, &ret, NULL, &error); diff --git a/src/companion-manager/src/comp_iot.c b/src/companion-manager/src/comp_iot.c index 84d32cd..7b1bb4e 100755 --- a/src/companion-manager/src/comp_iot.c +++ b/src/companion-manager/src/comp_iot.c @@ -138,6 +138,7 @@ static void _request_handler(iotcon_resource_h resource, iotcon_request_h reques iotcon_query_lookup(query, "group_name", &group_name); comp_group_create(group_name); + comp_group_find_mot_enabled_devices(); } else if (strcmp(command, "2") == 0) { LOG_DEBUG("Another device request add device to sub group"); char *group_name;