From 6cadf2316ea9adb7164cdc7d684b02ffad69435a Mon Sep 17 00:00:00 2001 From: Hyunho Kang Date: Thu, 6 Jul 2017 17:33:16 +0900 Subject: [PATCH] Add pending logic for watch viewer resume/pause Change-Id: If46e7d9d7a5c7344ddf1861a852100983cdac21e Signed-off-by: Hyunho Kang --- watch-control/src/control.c | 60 +++++++++++++++++++++++++++++++++---- 1 file changed, 55 insertions(+), 5 deletions(-) diff --git a/watch-control/src/control.c b/watch-control/src/control.c index 3da4c273..820710d7 100644 --- a/watch-control/src/control.c +++ b/watch-control/src/control.c @@ -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) { -- 2.34.1