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;
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) {
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) {
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) {
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,
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);
}
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);
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);