[TEMP] Fix for demo
authorJihoon Jung <jh8801.jung@samsung.com>
Wed, 24 Jan 2018 06:21:49 +0000 (15:21 +0900)
committersaerome.kim <saerome.kim@samsung.com>
Mon, 2 Jul 2018 10:38:47 +0000 (19:38 +0900)
Signed-off-by: Jihoon Jung <jh8801.jung@samsung.com>
capi/demo/comp-manager.c [changed mode: 0644->0755]
capi/src/companion.c [changed mode: 0644->0755]
src/companion-manager/src/comp_iot.c

old mode 100644 (file)
new mode 100755 (executable)
index 4d7de28..f0c723d
@@ -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) {
old mode 100644 (file)
new mode 100755 (executable)
index cc1f6cb..4541c8c
@@ -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);
 
index 84d32cd3ed5fddf8afb746ff1dfb5b49fd57aed3..7b1bb4e8061cc872e6b0f410e22163837a16cadf 100755 (executable)
@@ -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;