comp-manager: Update DeviceEject method
authorSaurav Babu <saurav.babu@samsung.com>
Wed, 17 Jan 2018 14:15:29 +0000 (19:45 +0530)
committersaerome.kim <saerome.kim@samsung.com>
Mon, 2 Jul 2018 10:38:43 +0000 (19:38 +0900)
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 <saurav.babu@samsung.com>
src/companion-manager/include/comp_gdbus_group.h
src/companion-manager/include/comp_group.h
src/companion-manager/src/comp_gdbus_group.c
src/companion-manager/src/comp_group.c
src/companion-manager/src/comp_mot_agent.c
src/companion-manager/src/companion_gdbus.xml

index d12dfe8a985e74ff090fbb03633e60d40ff98cf3..47e1470bc08e96be17cf2913038af30fa2773732 100755 (executable)
@@ -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);
index fbf0ac7efa5baa9da86a1b894e6fa04104edf032..ca76a35b6ec87ff15406ba35801b1fdcc7876fda 100755 (executable)
@@ -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,
index bf028d308ffcee567d7ee82f942396e2cf8d28db..82371ad6d9c5ad3c39d594c61383199ddf099f8a 100755 (executable)
@@ -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);
 
index 712310890bf1f41dfe87cbed05ec864403aefade..ce82aa07c98114951b00a373c0052499e6f7c82e 100755 (executable)
@@ -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();
 
index 312326140bedfe6977bcf3ae42d2380e09a6e92f..05ab80feaa683198f95670d21e7b06cd4e833418 100644 (file)
@@ -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()
index abc04d7e0855e7174da4efc2ab47c43c9f5019e1..937bced43dca9a32b08d86ecd304eac66f6c8715 100755 (executable)
@@ -49,7 +49,8 @@
                        <arg type="i" name="result" direction="out"/>
                </method>
                <method name="DeviceEject">
-                       <arg type="s" name="uuid" direction="in" />
+                       <arg type="s" name="uuid_dev1" direction="in"/>
+                       <arg type="s" name="uuid_dev2" direction="in"/>
                        <arg type="i" name="result" direction="out" />
                </method>
                <method name="GetRemoteDevice">