Listen LCD DBus signal for manual render feature 24/143024/7
authorHyunho Kang <hhstark.kang@samsung.com>
Tue, 8 Aug 2017 07:50:24 +0000 (16:50 +0900)
committerHyunho Kang <hhstark.kang@samsung.com>
Wed, 9 Aug 2017 02:56:13 +0000 (11:56 +0900)
Change-Id: I1357546125265b8c3bd562b0ade95c6358e2ded8
Signed-off-by: Hyunho Kang <hhstark.kang@samsung.com>
watch-control/src/control.c

index bc80ae9a7dc511508a32b1be0b20df3a3a5897a9..56a84d67a5937c371ea1e8f5a06aaebd5b5db5c5 100644 (file)
@@ -32,6 +32,7 @@
 #include <aul_app_com.h>
 #include <aul_screen_connector.h>
 #include <Ecore_Wayland.h>
+#include <gio/gio.h>
 
 #define API __attribute__((visibility("default")))
 
 
 #define KEY_SCREEN_SHAPE_CIRCLE "http://tizen.org/feature/screen.shape.circle"
 #define METADATA_SETUP_APPID   "http://tizen.org/metadata/watch/setup-appid"
+#define DEVICED_PATH_DISPLAY           "/Org/Tizen/System/DeviceD/Display"
+#define DEVICED_INTERFACE_DISPLAY      "org.tizen.system.deviced.display"
+
+#define SIGNAL_LCD_ON                                  "LCDOn"
 
 static int __watch_viewer_initialized = 0;
 static int __watch_size_policy = WATCH_POLICY_HINT_EXPAND;
@@ -68,7 +73,7 @@ static aul_app_com_connection_h __conn_dead_signal;
 static unsigned int __watch_rid;
 static bool __manual_render;
 static bool __iconified = false;
-static bool __is_binded = false;
+static bool __is_bound = false;
 static bool __viewer_visibility = false;
 
 static GList *__dead_cbs;
@@ -80,6 +85,8 @@ struct dead_cb_s {
 GQueue *__pending_queue;
 static int __change_viewer_visibility(bool visible, bool update_cur_state);
 static int __change_visibility(bool visible);
+static GDBusConnection *__gdbus_conn;
+static guint __lcd_subscribe_id;
 
 static void __process_pending_status(int status, unsigned int surf)
 {
@@ -144,6 +151,16 @@ static void __manual_render_start(void)
        Ecore_Evas *ee = ecore_evas_ecore_evas_get(evas);
        Evas *cur_image = evas_object_data_get(__win, "tbm,watch");
 
+       if (__is_bound) {
+               LOGW("watch is bound cannot manual render");
+               return;
+       }
+
+       if (__manual_render) {
+               LOGW("manual render is already started");
+               return;
+       }
+
        __change_viewer_visibility(true, false);
        ecore_evas_manual_render_set(ee, EINA_TRUE);
 
@@ -151,6 +168,7 @@ static void __manual_render_start(void)
                screen_connector_toolkit_evas_send_visibility(cur_image,
                                VISIBILITY_TYPE_UNOBSCURED);
        __manual_render = true;
+       LOGI("Manual render start");
 }
 
 static void __manual_render_finish(void)
@@ -183,10 +201,9 @@ static Eina_Bool __iconify_state_changed(void *data, int type, void *event)
                        (Ecore_Wl_Event_Window_Iconify_State_Change *)event;
 
        LOGI("Iconify state changed, %d, %d", ev->iconified, EINA_TRUE);
-       if (ev->iconified == EINA_FALSE && __iconified && !__is_binded) {
+       if (ev->iconified == EINA_FALSE && __iconified) {
                __manual_render_start();
                __iconified = false;
-               LOGI("Manual render true");
        } else if (ev->iconified == EINA_TRUE) {
                __iconified = true;
        }
@@ -194,6 +211,70 @@ static Eina_Bool __iconify_state_changed(void *data, int type, void *event)
        return ECORE_CALLBACK_PASS_ON;
 }
 
+static void __lcd_on_signal_handler(GDBusConnection *connection,
+                                       const gchar *sender_name,
+                                       const gchar *object_path,
+                                       const gchar *interface_name,
+                                       const gchar *signal_name,
+                                       GVariant *parameters,
+                                       gpointer user_data)
+{
+       LOGI("LCD ON !!");
+       __manual_render_start();
+}
+
+static int __dbus_init(void)
+{
+       GError *err = NULL;
+
+       if (__gdbus_conn) {
+               LOGW("already initialized");
+               return -1;
+       }
+
+       __gdbus_conn = g_bus_get_sync(G_BUS_TYPE_SYSTEM, NULL, &err);
+       if (__gdbus_conn == NULL) {
+               _E("Failed to connect to the D-BUS daemon: %s",
+                               err->message);
+               g_error_free(err);
+               return -1;
+       }
+
+       return 0;
+}
+
+int __listen_lcd_status_signal()
+{
+       GError *err = NULL;
+
+       _D("listen lcd_status_signal");
+
+       if (__dbus_init() != 0)
+               return -1;
+
+       __lcd_subscribe_id = g_dbus_connection_signal_subscribe(__gdbus_conn,
+                                       NULL,
+                                       DEVICED_INTERFACE_DISPLAY,
+                                       SIGNAL_LCD_ON,
+                                       DEVICED_PATH_DISPLAY,
+                                       NULL,
+                                       G_DBUS_SIGNAL_FLAGS_NONE,
+                                       __lcd_on_signal_handler,
+                                       NULL,
+                                       NULL);
+       if (__lcd_subscribe_id == 0) {
+               _E("g_dbus_connection_signal_subscribe() is failed.");
+               if (__gdbus_conn) {
+                       g_object_unref(__gdbus_conn);
+                       __gdbus_conn = NULL;
+               }
+       }
+
+       g_clear_error(&err);
+
+       return 0;
+}
+
 static int __watch_viewer_init(Evas_Object *win)
 {
        if (__watch_viewer_initialized)
@@ -214,6 +295,7 @@ static int __watch_viewer_init(Evas_Object *win)
                        __iconify_state_changed, NULL);
        __manual_render = false;
        __watch_viewer_initialized = 1;
+       __listen_lcd_status_signal();
 
        return 0;
 }
@@ -227,6 +309,17 @@ static void __watch_viewer_fini()
 
        screen_connector_toolkit_evas_stop_visibility_notify();
        screen_connector_toolkit_evas_fini(SCREEN_CONNECTOR_SCREEEN_TYPE_WATCH);
+
+       if (__lcd_subscribe_id != 0) {
+               g_dbus_connection_signal_unsubscribe(
+                               __gdbus_conn, __lcd_subscribe_id);
+               __lcd_subscribe_id = 0;
+       }
+
+       if (__gdbus_conn) {
+               g_object_unref(__gdbus_conn);
+               __gdbus_conn = NULL;
+       }
 }
 
 API int watch_manager_init(Evas_Object *win)
@@ -674,7 +767,7 @@ API int watch_manager_window_bind(Evas_Object *win)
                return -1;
 
        LOGI("Bind");
-       __is_binded = true;
+       __is_bound = true;
 
        return screen_connector_toolkit_evas_bind(__toolkit, win);
 }
@@ -685,7 +778,7 @@ API int watch_manager_window_unbind(void)
                return -1;
 
        LOGI("Unbind");
-       __is_binded = false;
+       __is_bound = false;
 
        return screen_connector_toolkit_evas_unbind(__toolkit);
 }