comp-manager: Monitor Invited device
authorSaurav Babu <saurav.babu@samsung.com>
Thu, 19 Apr 2018 09:21:32 +0000 (14:51 +0530)
committersaerome.kim <saerome.kim@samsung.com>
Mon, 2 Jul 2018 10:38:50 +0000 (19:38 +0900)
This patch adds new method to start monitoring invited device and sends
signal when device state changes

Signed-off-by: Saurav Babu <saurav.babu@samsung.com>
src/companion-manager/include/comp_context.h
src/companion-manager/include/comp_gdbus_group.h
src/companion-manager/include/comp_group.h
src/companion-manager/src/comp_gdbus.c
src/companion-manager/src/comp_gdbus_group.c
src/companion-manager/src/comp_group.c
src/companion-manager/src/companion_gdbus.xml

index 3839026685553e2891a3b67218254e49db305ec7..db9e2341a1b8873f992939fa72a73fb0fb9a9ef4 100644 (file)
@@ -44,6 +44,8 @@ typedef struct {
        GList *grp_list;
        GList *pairwise_list;
 
+       bool monitor_started;
+
        //sqlite3 db
        sqlite3 *db;
 } comp_context_t;
index 6bcf0c06789b03b4909fb9a64b0999e4a9853dd1..2cab655eda6966731f5d9b6ae39e0bf487735a04 100644 (file)
@@ -102,6 +102,9 @@ gboolean group_request_eject(Group *group, GDBusMethodInvocation *invocation,
 gboolean group_request_delete_group(Group *group, GDBusMethodInvocation *invocation,
        gchar *uuid, gchar *group_name, gpointer user_data);
 
+gboolean group_start_invited_device_monitor(Group *group,
+                                       GDBusMethodInvocation *invocation, gpointer user_data);
+
 void notify_group_found(GVariant *group_data);
 void notify_group_find_finish(int ret);
 void notify_device_found(int device_count, GVariant *device_data);
@@ -114,6 +117,8 @@ void notify_group_join(int result);
 void notify_send_data_finish(const char *resp_data, int ret);
 void notify_request_result(const char *cmd, const char *requester_id,
                                                   unsigned char *arg, int len, int ret);
+void notify_device_monitor_result(const char *uuid, const char *group_name,
+                                                                 const char *status);
 
 #ifdef __cplusplus
 }
index e5d6ac44ef33352ecc13133ad546996fb03f2dcf..1bde8b353070547a454f1789cdb3f61367f58e7c 100755 (executable)
@@ -158,6 +158,8 @@ int comp_group_request_invite(char *uuid, char *group_name, char *target_uuid, c
 int comp_group_request_eject(char *uuid, char *group_name, char *target_uuid);
 int comp_group_request_delete_group(char *uuid, char *group_name);
 
+int comp_group_start_invited_device_monitor();
+
 #ifdef __cplusplus
 }
 #endif
index 84012c251b5a9469167dcdf71b8c5c0455e364c3..d923c80111a59a26ac43f5d456f470d15c309262 100644 (file)
@@ -155,6 +155,11 @@ static bool __group_init(GDBusConnection *connection)
                G_CALLBACK(group_request_delete_group),
                NULL);
 
+       g_signal_connect(group_skeleton,
+               "handle-start-invited-device-monitor",
+               G_CALLBACK(group_start_invited_device_monitor),
+               NULL);
+
        group = g_dbus_object_manager_server_new(COMP_DBUS_GROUP_PATH);
 
        // Set connection to 'manager'
index 87b7b488f0399c5ce7a109caf44a20bea21b523a..66365046696f4228157d9946daf3d4d949253017 100644 (file)
@@ -373,6 +373,20 @@ gboolean group_request_delete_group(Group *group,
        return TRUE;
 }
 
+gboolean group_start_invited_device_monitor(Group *group,
+                                       GDBusMethodInvocation *invocation, gpointer user_data)
+{
+       int ret = 0;
+
+       LOG_DEBUG("Start Myowned device monitor");
+
+       ret = comp_group_start_invited_device_monitor();
+
+       group_complete_start_invited_device_monitor(group, invocation, ret);
+
+       return TRUE;
+}
+
 void notify_group_found(GVariant *group_data)
 {
        group_emit_group_found(group_dbus_get_object(), group_data);
@@ -441,3 +455,10 @@ void notify_request_result(const char *cmd, const char *requester_id,
                                                          params, ret);
 }
 
+void notify_device_monitor_result(const char *uuid, const char *group_name,
+                                                                 const char *status)
+{
+       group_emit_device_monitor_result(group_dbus_get_object(), uuid, group_name,
+                                                                         status);
+}
+
index 7a4665d569c8d8834779d164febec031c167e0a6..24f08481456d704b214826b98d4acb3f84bbc195 100755 (executable)
@@ -29,6 +29,9 @@ GList *invited_dev_list = NULL;
 comp_group_invite_info_t *group_invite_info = NULL;
 comp_mot_device_t *my_device = NULL;
 
+#define KEEPALIVE_MESSAGE_TIMEOUT 900
+#define CHECK_DEVICE_STATUS_TIMEOUT 3000
+
 /* Called when daemon is start. */
 int comp_group_initialize()
 {
@@ -586,6 +589,17 @@ void comp_group_notify_group_invite(int ret)
 
                        comp_group_request_keepalive(device->uuid, device->group_name,
                                                                                 device->host);
+
+                       comp_context_t *comp_ctx = comp_context_get_context();
+                       comp_check_null_ret("comp_ctx", comp_ctx);
+
+                       if (comp_ctx->monitor_started == true) {
+                               notify_device_monitor_result(device->uuid, device->group_name,
+                                                                                        "Added");
+
+                               comp_group_start_invited_device_monitor();
+                       }
+
                } else {
                        g_free(device->uuid);
                        g_free(device->group_name);
@@ -1244,4 +1258,92 @@ int comp_group_request_delete_group(char *uuid, char *group_name)
        return ret;
 }
 
+static gboolean __send_keepalive_messages(gpointer user_data)
+{
+       GList *iter = NULL;
+
+       iter = invited_dev_list;
+       while (iter != NULL) {
+               comp_invited_device_t *temp = (comp_invited_device_t *)iter->data;
+
+               comp_group_request_keepalive(temp->uuid, temp->group_name, temp->host);
+
+               iter = g_list_next(iter);
+       }
+
+       return TRUE;
+}
+
+static gboolean __check_invited_device_status(gpointer user_data)
+{
+       int *t_id = (int *)user_data;
+       GList *iter = NULL;
+
+       g_source_remove(*t_id);
+       *t_id = 0;
+
+       iter = invited_dev_list;
+       while (iter != NULL) {
+               comp_invited_device_t *temp = (comp_invited_device_t *)iter->data;
+
+               iter = g_list_next(iter);
+
+               LOG_DEBUG("uuid %s count %d", temp->uuid, temp->count);
 
+               if (temp->count == 0) {
+                       LOG_DEBUG("Remove device with uuid %s", temp->uuid);
+                       invited_dev_list = g_list_remove(invited_dev_list, temp);
+
+                       notify_device_monitor_result(temp->uuid, temp->group_name,
+                                                                                "Removed");
+
+                       g_free(temp->host);
+                       g_free(temp->uuid);
+                       g_free(temp->group_name);
+                       g_free(temp);
+               } else {
+                       temp->count = 0;
+               }
+       }
+
+       comp_context_t *comp_ctx = comp_context_get_context();
+       comp_check_null_ret_error("comp_ctx", comp_ctx, FALSE);
+
+       if (comp_ctx->monitor_started == false) {
+               g_free(t_id);
+               return FALSE;
+       }
+
+       if (g_list_length(invited_dev_list) == 0) {
+               g_free(t_id);
+               return FALSE;
+       }
+
+       *t_id = g_timeout_add(KEEPALIVE_MESSAGE_TIMEOUT, __send_keepalive_messages,
+                                                 NULL);
+
+       return TRUE;
+}
+
+int comp_group_start_invited_device_monitor()
+{
+       int *t_id;
+
+       comp_context_t *comp_ctx = comp_context_get_context();
+       comp_check_null_ret_error("comp_ctx", comp_ctx,
+                                                         COMP_ERROR_INVALID_PARAMETER);
+
+       comp_ctx->monitor_started = true;
+
+       LOG_DEBUG("Start invited device monitor");
+
+       t_id = g_try_malloc0(sizeof(int));
+
+       *t_id = g_timeout_add(KEEPALIVE_MESSAGE_TIMEOUT, __send_keepalive_messages,
+                                                 NULL);
+
+       g_timeout_add(CHECK_DEVICE_STATUS_TIMEOUT, __check_invited_device_status,
+                                                 t_id);
+
+       return COMP_ERROR_NONE;
+}
index 94e1fa55591b7bf93c1ef4f01634c00025e7fc9b..615948a014ed977b911970bb96387f7f278a6905 100644 (file)
                        <arg type="s" name="group_name" direction="in" />
                        <arg type="i" name="result" direction="out" />
                </method>
+               <method name="StartInvitedDeviceMonitor">
+                       <arg type="i" name="result" direction="out" />
+               </method>
                <!-- Signal (D-Bus) definitions -->
                <signal name="GroupFound">
                        <arg type="a{sv}" name="group_info" direction="out" />
                        <arg type="(iay)" name="arg" direction="out" />
                        <arg type="i" name="result" direction="out" />
                </signal>
+               <signal name="DeviceMonitorResult">
+                       <arg type="s" name="uuid" direct="out" />
+                       <arg type="s" name="group_name" direct="out" />
+                       <arg type="s" name="status" direct="out" />
+               </signal>
        </interface>
 </node>