From: Saurav Babu Date: Wed, 17 Jan 2018 14:15:29 +0000 (+0530) Subject: comp-manager: Update DeviceEject method X-Git-Tag: submit/tizen/20190131.065036~196 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=c045d44c1dd475898f659dbb5fe63bf2196edb29;p=platform%2Fcore%2Fapi%2Fmulti-device-group.git comp-manager: Update DeviceEject method This patch updates DeviceEject method to perform below operations: 1. Unpair devices 2. Receive Unpair done 3. Remove MOT at device #2 4. Recieive Remove MOT Done 5. Remove credential at local device $1 6. Receive Credential at local done Signed-off-by: Saurav Babu --- diff --git a/src/companion-manager/include/comp_gdbus_group.h b/src/companion-manager/include/comp_gdbus_group.h index d12dfe8..47e1470 100755 --- a/src/companion-manager/include/comp_gdbus_group.h +++ b/src/companion-manager/include/comp_gdbus_group.h @@ -32,7 +32,7 @@ gboolean group_device_invite(Group *group, GDBusMethodInvocation *invocation, gchar *interface_2, int permission_2, gpointer user_data); gboolean group_device_eject(Group *group, GDBusMethodInvocation *invocation, - gchar *uuid, gpointer user_data); + gchar *uuid_dev1, gchar *uuid_dev2, gpointer user_data); gboolean group_get_remote_device(Group *group, GDBusMethodInvocation *invocation, gpointer user_data); diff --git a/src/companion-manager/include/comp_group.h b/src/companion-manager/include/comp_group.h index fbf0ac7..ca76a35 100755 --- a/src/companion-manager/include/comp_group.h +++ b/src/companion-manager/include/comp_group.h @@ -75,7 +75,7 @@ void comp_group_free_invite_info(); void comp_group_notify_group_invite(int result); //dismiss from group (async) -int comp_group_dismiss(gchar *uuid); +int comp_group_dismiss(gchar *uuid_dev1, gchar *uuid_dev2); void comp_group_notify_group_dismiss(int result); int comp_group_pair_resource(char* target1, char *subject1, char *uri1, diff --git a/src/companion-manager/src/comp_gdbus_group.c b/src/companion-manager/src/comp_gdbus_group.c index bf028d3..82371ad 100755 --- a/src/companion-manager/src/comp_gdbus_group.c +++ b/src/companion-manager/src/comp_gdbus_group.c @@ -105,13 +105,13 @@ gboolean group_device_invite(Group *group, GDBusMethodInvocation *invocation, } gboolean group_device_eject(Group *group, GDBusMethodInvocation *invocation, - gchar *uuid, gpointer user_data) + gchar *uuid_dev1, gchar *uuid_dev2, gpointer user_data) { gint result = 0; LOG_DEBUG("group device eject called using dbus successful"); - result = comp_group_dismiss(uuid); + result = comp_group_dismiss(uuid_dev1, uuid_dev2); group_complete_device_eject(group, invocation, result); diff --git a/src/companion-manager/src/comp_group.c b/src/companion-manager/src/comp_group.c index 7123108..ce82aa0 100755 --- a/src/companion-manager/src/comp_group.c +++ b/src/companion-manager/src/comp_group.c @@ -370,13 +370,18 @@ void comp_group_notify_group_dismiss(int result) } //dismiss from group (async) -int comp_group_dismiss(gchar *uuid) +int comp_group_dismiss(gchar *uuid_dev1, gchar *uuid_dev2) { int ret; LOG_BEGIN(); - ret = agent_remove_mo_at_device(uuid); + /* + * 1. Unpair device + * 2. Remove MOT at device #2 + * 3. Remove cred at local (device #1) + * */ + ret = agent_remove_myowned_device(uuid_dev1, uuid_dev2); LOG_END(); diff --git a/src/companion-manager/src/comp_mot_agent.c b/src/companion-manager/src/comp_mot_agent.c index 3123261..05ab80f 100644 --- a/src/companion-manager/src/comp_mot_agent.c +++ b/src/companion-manager/src/comp_mot_agent.c @@ -48,6 +48,8 @@ struct agent_s { }; struct agent_s agent; static bool mot_dev2 = false; +static char *device_uuid1 = NULL; +static char *device_uuid2 = NULL; int agent_get_ownerid(char* deviceid) { @@ -252,6 +254,11 @@ int agent_remove_myowned_device(char* uuid_str1, char *uuid_str2) return COMP_ERROR_IO_ERROR; } + if (result == COMP_ERROR_NONE) { + device_uuid1 = g_strdup(uuid_str1); + device_uuid2 = g_strdup(uuid_str2); + } + return result; } @@ -416,6 +423,39 @@ static gboolean __perform_agent_pairwise(gpointer data) return FALSE; } +static gboolean __perform_remove_mot_dev2(gpointer data) +{ + int ret; + + ret = agent_remove_mo_at_device(device_uuid2); + if (ret != COMP_ERROR_NONE) { + comp_group_notify_group_dismiss(ret); + g_free(device_uuid1); + device_uuid1 = NULL; + g_free(device_uuid2); + device_uuid1 = NULL; + } + + return FALSE; +} + +static gboolean __perform_remove_cred_at_local(gpointer data) +{ + int ret; + + ret = agent_remove_cred_at_local(device_uuid1); + if (ret != COMP_ERROR_NONE) { + comp_group_notify_group_dismiss(ret); + g_free(device_uuid1); + device_uuid1 = NULL; + g_free(device_uuid2); + device_uuid1 = NULL; + } + + return FALSE; +} + + static void _agent_signal_handler(GDBusConnection *connection, const gchar *sender_name, const gchar *object_path, const gchar *interface_name, const gchar *signal_name, GVariant *parameters, gpointer userdata) @@ -628,11 +668,24 @@ static void _agent_signal_handler(GDBusConnection *connection, } else if (0 == g_strcmp0(signal_name, "remove_mo_done")) { g_variant_get(parameters, "(i)", &result); LOG_DEBUG("Result : %d", result); + + if (result != 0) { + comp_group_notify_group_dismiss(result); + g_free(device_uuid1); + device_uuid1 = NULL; + g_free(device_uuid2); + device_uuid1 = NULL; + } else + g_timeout_add(1000, __perform_remove_cred_at_local, NULL); } else if (0 == g_strcmp0(signal_name, "remove_cred_local_done")) { g_variant_get(parameters, "(i)", &result); LOG_DEBUG("Result : %d", result); comp_group_notify_group_dismiss(result); + g_free(device_uuid1); + device_uuid1 = NULL; + g_free(device_uuid2); + device_uuid1 = NULL; } else if (0 == g_strcmp0(signal_name, "pairwise_done")) { g_variant_get(parameters, "(i)", &result); LOG_DEBUG("Result : %d", result); @@ -642,6 +695,15 @@ static void _agent_signal_handler(GDBusConnection *connection, } else if (0 == g_strcmp0(signal_name, "unpair_done")) { g_variant_get(parameters, "(i)", &result); LOG_DEBUG("Result : %d", result); + + if (result != 0) { + comp_group_notify_group_dismiss(result); + g_free(device_uuid1); + device_uuid1 = NULL; + g_free(device_uuid2); + device_uuid1 = NULL; + } else + g_timeout_add(1000, __perform_remove_mot_dev2, NULL); } } static int _subscribe_event() diff --git a/src/companion-manager/src/companion_gdbus.xml b/src/companion-manager/src/companion_gdbus.xml index abc04d7..937bced 100755 --- a/src/companion-manager/src/companion_gdbus.xml +++ b/src/companion-manager/src/companion_gdbus.xml @@ -49,7 +49,8 @@ - + +