demo: fix a bug about discovering devices
authorsaerome.kim <saerome.kim@samsung.com>
Wed, 17 Jan 2018 12:25:43 +0000 (21:25 +0900)
committersaerome.kim <saerome.kim@samsung.com>
Mon, 2 Jul 2018 10:38:43 +0000 (19:38 +0900)
Signed-off-by: saerome.kim <saerome.kim@samsung.com>
capi/demo/comp-manager.c
capi/src/companion.c [changed mode: 0755->0644]
src/companion-manager/src/comp_mot_agent.c [changed mode: 0755->0644]
src/mot-agent/ma-subowner.c

index 960427aae180225f232733a95483963523ad53c7..1e56bf5157307960f2908b6fb6432b4819fd5096 100644 (file)
@@ -280,9 +280,48 @@ static int run_group_delete(MManager *mm, struct menu_data *menu)
        return RET_SUCCESS;
 }
 
-void _device_finish_cb(int result, void *user_data)
+int run_device_get_found(MManager *mm, struct menu_data *menu)
 {
-       msgb("Find Devices Finished [%s]", comp_error_to_string(result) );
+       int ret;
+       int count;
+       companion_device_h *devices = NULL;
+
+       msg("");
+
+       ret = companion_device_get_found_devices(&devices, &count);
+       if (COMP_ERROR_NONE != ret) {
+               msgr("Failed to Get Found Devices: [%s(0x%X)]", comp_error_to_string(ret), ret);
+               return RET_FAILURE;
+       }
+       msg(" - companion_device_get_found_devices() ret: [0x%X] [%s]", ret, comp_error_to_string(ret));
+
+       for (int i = 0; i < count; i++) {
+               char *device_id = NULL;
+               char *friendly_name = NULL;
+               char *device_type = NULL;
+
+               companion_device_information_get_device_id(devices[i], &device_id);
+               companion_device_information_get_friendly_name(devices[i], &friendly_name);
+               companion_device_information_get_device_type(devices[i], &device_type);
+
+               msgb("\n[deviceiid] %s [address] %s [ver] %s", device_id, friendly_name, device_type);
+
+               if (device_id)
+                       free(device_id);
+               if (friendly_name)
+                       free(friendly_name);
+               if (device_type)
+                       free(device_type);
+
+               found_device_list = g_list_prepend(found_device_list, devices[i]);
+       }
+
+       return RET_SUCCESS;
+}
+
+void _device_finish_cb(int num_of_devs, void *user_data)
+{
+       msgb("%d Device(s) Found", num_of_devs);
 }
 
 bool _device_found_cb(companion_device_h device, void *user_data)
@@ -295,8 +334,7 @@ bool _device_found_cb(companion_device_h device, void *user_data)
        companion_device_information_get_friendly_name(device, &friendly_name);
        companion_device_information_get_device_type(device, &device_type);
 
-       msg("");
-       msgb("device_id : %s, name : %s, type : %s", device_id, friendly_name, device_type);
+       msgb("\n[deviceiid] %s [address] %s [ver] %s", device_id, friendly_name, device_type);
 
        if (device_id)
                free(device_id);
@@ -336,8 +374,6 @@ static int run_devices_find(MManager *mm, struct menu_data *menu)
                found_device_list = NULL;
        }
 
-       msg("");
-
        return RET_SUCCESS;
 }
 
@@ -501,7 +537,7 @@ bool _group_found_cb(companion_group_type_e type, companion_group_h group, void
 
 void _group_finish_cb(int result, void *user_data)
 {
-       msgb("find operation finished");
+       msgb("Find Group Finished = %d", result);
 }
 
 static void _destroy_comp_group_info(gpointer data)
@@ -509,7 +545,6 @@ static void _destroy_comp_group_info(gpointer data)
        companion_group_information_destroy((companion_group_h)data);
 }
 
-
 static int run_group_find(MManager *mm, struct menu_data *menu)
 {
        int ret;
@@ -575,12 +610,6 @@ static struct menu_data menu_group_leave[] = {
        { NULL, NULL, },
 };
 
-static struct menu_data menu_devices_find[] = {
-       { "0", "Timeout", NULL, NULL, timeout },
-       { "2", "Run", NULL, run_devices_find, NULL },
-       { NULL, NULL, },
-};
-
 static struct menu_data menu_group_delete[] = {
        { "0", "Show Found Group(s)", NULL, run_group_show, NULL },
        { "1", "Index", NULL, NULL, group_idx },
@@ -591,8 +620,8 @@ static struct menu_data menu_group_delete[] = {
 static struct menu_data menu_group_merge[] = {
        { "0", "Show Found Group(s)", NULL, run_group_show, NULL },
        { "1", "A Index", NULL, NULL, group_idx_a },
-       { "1", "B Index", NULL, NULL, group_idx_b },
-       { "2", "Run", NULL, run_group_merge, NULL },
+       { "2", "B Index", NULL, NULL, group_idx_b },
+       { "3", "Run", NULL, run_group_merge, NULL },
        { NULL, NULL, },
 };
 
@@ -603,6 +632,12 @@ static struct menu_data menu_group_get_members[] = {
        { NULL, NULL, },
 };
 
+static struct menu_data menu_devices_find[] = {
+       { "0", "Timeout", NULL, NULL, timeout },
+       { "1", "Run", NULL, run_devices_find, NULL },
+       { NULL, NULL, },
+};
+
 static struct menu_data menu_group_invite_device[] = {
        { "0", "Show Found Device(s)", NULL, run_devices_show, NULL },
        { "1", "Index", NULL, NULL, group_idx },
@@ -629,7 +664,8 @@ struct menu_data menu_comp_manager[] = {
        { "7", "Merge Group B to A", menu_group_merge, NULL, NULL },
        { "8", "Get Group Member Devices", menu_group_get_members, NULL, NULL },
        { "9", "Find Devices", menu_devices_find, NULL, NULL },
-       { "10", "Invite Device", menu_group_invite_device, NULL, NULL },
-       { "11", "Eject Device", menu_group_eject_device, NULL, NULL },
+       { "10", "Get Found Devices", NULL, run_device_get_found, NULL },
+       { "11", "Invite Device", menu_group_invite_device, NULL, NULL },
+       { "12", "Eject Device", menu_group_eject_device, NULL, NULL },
        { NULL, NULL, },
 };
old mode 100755 (executable)
new mode 100644 (file)
index 64729ce..b2e9556
@@ -169,9 +169,9 @@ static void __device_found_cb(Group *object,
                while (g_variant_iter_loop(iter_row, "{sv}", &key, &key_value)) {
                        if (g_strcmp0(key, "DeviceID") == 0) {
                                device_id = (char *)g_variant_get_string(key_value, NULL);
-                       } else if (g_strcmp0(key, "FriendlyName") == 0) {
+                       } else if (g_strcmp0(key, "Address") == 0) {
                                friendly_name = (char *)g_variant_get_string(key_value, NULL);
-                       } else if (g_strcmp0(key, "DeviceType") == 0) {
+                       } else if (g_strcmp0(key, "SecVer") == 0) {
                                device_type = (char *)g_variant_get_string(key_value, NULL);
                        }
                }
@@ -430,7 +430,53 @@ int companion_send_data(companion_device_h device, char *data)
 /* companion_group_join : join to remote group. if group handle is my daemon's, then the api return fail error */
 int companion_device_get_found_devices(companion_device_h **devices, int *count)
 {
-       return 0;
+       int ret = 0;
+       int num = 0;
+       GVariant *va = NULL;
+       GError *error = NULL;
+
+       /* get groups from daemon using gdbus */
+       group_call_get_remote_device_sync(group_proxy, &num, &va, NULL, &error);
+       /* *count = g_variant_n_children(va); */
+       *count = num;
+
+       _ERR("get found devices : %d", *count);
+
+       if (*count > 0) {
+               GVariantIter *iter = NULL, *iter_row = NULL;
+               GVariant *key_value;
+               const gchar *key;
+               guint i = 0;
+
+               *devices = g_new0(companion_group_h, *count);
+
+               g_variant_get(va, "aa{sv}", &iter);
+               while (g_variant_iter_next(iter, "a{sv}", &iter_row)) {
+                       char *deviceid = NULL;
+                       char *addr = NULL;
+                       char *ver = NULL;
+                       companion_device_t *device = NULL;
+
+                       while (g_variant_iter_loop(iter_row, "{sv}", &key, &key_value)) {
+                               if (g_strcmp0(key, "DeviceID") == 0) {
+                                       deviceid = (char *)g_variant_get_string(key_value, NULL);
+                               } else if (g_strcmp0(key, "Address") == 0) {
+                                       addr = (char *)g_variant_get_string(key_value, NULL);
+                               } else if (g_strcmp0(key, "SecVer") == 0) {
+                                       ver = (char *)g_variant_get_string(key_value, NULL);
+                               }
+                       }
+                       g_variant_iter_free(iter_row);
+
+                       device = _create_device_handle(deviceid, addr, ver);
+
+                       (*devices)[i++] = (companion_device_h)device;
+               }
+               g_variant_iter_free(iter);
+       }
+       g_variant_unref(va);
+
+       return ret;
 }
 
 /* group merge */
old mode 100755 (executable)
new mode 100644 (file)
index 22d0b8c..1dc25d9
@@ -677,7 +677,7 @@ static void _agent_signal_handler(GDBusConnection *connection,
                } else {
                        if (mot_dev1 == false)
                                g_idle_add(__perform_group_join_mot, NULL);
-                       else if (mot_dev2 = false)
+                       else if (mot_dev2 == false)
                                g_idle_add(__perform_group_join_mot, NULL);
                        else
                                g_timeout_add(1000, __perform_agent_find_mowned_devices, NULL);
index 334f994e69f043cf4db8c54f6c72d2c32243e579..e55fa6dcdee65314f70ce2b2abc6c8099656756e 100644 (file)
@@ -436,8 +436,6 @@ static void _input_pin_cb(char* pin, size_t len)
 
 static void _remove_mot_client()
 {
-       GMutex motdev_mutex;
-
        ma_check_null_ret("g_client", g_client);
 
        if (g_client->g_motdev_list) {