Add pending logic for watch viewer resume/pause 32/137532/4 submit/tizen_3.0/20170706.230428
authorHyunho Kang <hhstark.kang@samsung.com>
Thu, 6 Jul 2017 08:33:16 +0000 (17:33 +0900)
committerHyunho Kang <hhstark.kang@samsung.com>
Thu, 6 Jul 2017 09:41:24 +0000 (18:41 +0900)
Change-Id: If46e7d9d7a5c7344ddf1861a852100983cdac21e
Signed-off-by: Hyunho Kang <hhstark.kang@samsung.com>
watch-control/src/control.c

index 3da4c27..820710d 100644 (file)
@@ -73,6 +73,53 @@ struct dead_cb_s {
        void *data;
 };
 
+GQueue *__pending_queue;
+
+static void __process_pending_status(int status, const char *instance_id)
+{
+       int r;
+
+       _D("send pending event(%d) to %s", status, instance_id);
+       r = aul_screen_connector_update_screen_viewer_status(status,
+                       instance_id);
+       if (r < 0)
+               _E("Failed to update screen viewer status");
+}
+
+static void __flush_pending_queue(const char *instance_id)
+{
+       gpointer status_pointer;
+       int status;
+
+       if (!__pending_queue) {
+               _D("Pending queue is empty");
+               return;
+       }
+
+       while (!g_queue_is_empty(__pending_queue)) {
+               status_pointer = g_queue_pop_head(__pending_queue);
+               status = GPOINTER_TO_INT(status_pointer);
+               __process_pending_status(status, instance_id);
+       }
+
+       g_queue_free(__pending_queue);
+       __pending_queue = NULL;
+}
+
+static void __push_pending_queue(int status)
+{
+       if (!__pending_queue)
+               __pending_queue= g_queue_new();
+
+       if (!__pending_queue) {
+               _E("Out of memory");
+               return;
+       }
+
+       g_queue_push_tail(__pending_queue, GINT_TO_POINTER(status));
+       _D("status(%d)", status);
+}
+
 static void __win_resized(void *data, Evas *e, Evas_Object *obj, void *event_info)
 {
        Evas_Object *win = obj;
@@ -157,6 +204,8 @@ static void __screen_connector_toolkit_evas_added_cb(const char *appid, const ch
        __watch_instance_id = strdup(instance_id);
        if (__watch_instance_id == NULL)
                _W("Out of memory");
+
+       __flush_pending_queue(instance_id);
 }
 
 static void __screen_connector_toolkit_evas_removed_cb(const char *appid, const char *instance_id, int pid,
@@ -466,16 +515,17 @@ static int __change_viewer_visibility(bool visible)
        int status;
        int r;
 
-       if (__watch_appid == NULL || __watch_instance_id == NULL) {
-               _E("watch is not added");
-               return -1;
-       }
-
        if (visible)
                status = AUL_SCREEN_STATUS_RESUME;
        else
                status = AUL_SCREEN_STATUS_PAUSE;
 
+       if (__watch_appid == NULL || __watch_instance_id == NULL) {
+               _E("watch is not added");
+               __push_pending_queue(status);
+               return 0;
+       }
+
        r = aul_screen_connector_update_screen_viewer_status(status,
                        __watch_instance_id);
        if (r < 0) {