e_dpms: support tizen dpms potocol binding only one client
authorJunkyeong Kim <jk0430.kim@samsung.com>
Tue, 31 Dec 2019 06:02:00 +0000 (15:02 +0900)
committerSooChan Lim <sc1.lim@samsung.com>
Wed, 8 Jan 2020 08:52:09 +0000 (17:52 +0900)
Change-Id: I4b248981258e18cb00dc27d5f03bd044047700d8
Signed-off-by: Junkyeong Kim <jk0430.kim@samsung.com>
src/bin/e_dpms.c

index a6dba8cd9ca3c7c88c39542ad20db889b51e1e6e..5cc055b8ac2193dc7d3d2130c0e29f53e05c4bde 100644 (file)
@@ -34,6 +34,7 @@ static Eina_List *dpms_list;
 static struct wl_global *dpms_global;
 Ecore_Timer *delay_timer;
 static struct wl_resource *gresource;
+static Eina_Bool dpms_binded;
 
 typedef struct _E_Dpms
 {
@@ -179,13 +180,13 @@ _e_dpms_delay(void *data)
    E_Dpms *dpms = NULL;
    E_Dpms_Mode e_output_dpms;
 
-   if (!data) return ECORE_CALLBACK_CANCEL;
+   EINA_SAFETY_ON_NULL_RETURN_VAL(data, ECORE_CALLBACK_CANCEL);
+   EINA_SAFETY_ON_NULL_RETURN_VAL(gresource, ECORE_CALLBACK_CANCEL);
+
    dpms = (E_Dpms *)data;
 
    delay_timer = NULL;
 
-   if (!gresource) return ECORE_CALLBACK_CANCEL;
-
    e_output_dpms = e_output_dpms_get(dpms->e_output);
    if (e_output_dpms != dpms->mode)
      {
@@ -196,7 +197,6 @@ _e_dpms_delay(void *data)
 
    tizen_dpms_manager_send_set_state(gresource, dpms->mode, E_DPMS_MANAGER_ERROR_NONE);
    INF("DPMS:tizen_dpms_manager send set event by timer(res:%p, output:%p, dpms:%d)", gresource, dpms->e_output, dpms->mode);
-   gresource = NULL;
 
    return ECORE_CALLBACK_CANCEL;
 }
@@ -209,20 +209,17 @@ _e_tizen_dpms_cb_output_dpms_change(void *data, E_Output *output)
 
    dpms = (E_Dpms *) data;
    EINA_SAFETY_ON_NULL_RETURN(dpms);
+   EINA_SAFETY_ON_NULL_RETURN(gresource);
    EINA_SAFETY_ON_FALSE_RETURN(dpms->e_output == output);
 
    e_output_dpms = e_output_dpms_get(output);
 
-   if (gresource)
-     {
-        if (delay_timer)
-          ecore_timer_del(delay_timer);
-        delay_timer = NULL;
-        INF("DPMS:tizen_dpms_manager set dpms async cb(res:%p, output:%p, dpms:%d)",
-            gresource, dpms->e_output, e_output_dpms);
-        tizen_dpms_manager_send_set_state(gresource, e_output_dpms, E_DPMS_MANAGER_ERROR_NONE);
-        gresource = NULL;
-     }
+   if (delay_timer)
+   ecore_timer_del(delay_timer);
+   delay_timer = NULL;
+   INF("DPMS:tizen_dpms_manager set dpms async cb(res:%p, output:%p, dpms:%d)",
+       gresource, dpms->e_output, e_output_dpms);
+   tizen_dpms_manager_send_set_state(gresource, e_output_dpms, E_DPMS_MANAGER_ERROR_NONE);
 }
 
 static E_Dpms *
@@ -293,10 +290,11 @@ _e_tizen_dpms_manager_cb_set_dpms(struct wl_client *client, struct wl_resource *
         return;
      }
 
+   dpms->mode = mode;
+
    if (!e_output_connected(dpms->e_output))
      {
         e_output_dpms_set(dpms->e_output, mode);
-        dpms->mode = mode;
         INF("DPMS:tizen_dpms_manager set dpms fake(res:%p, output:%p, dpms:%d)", resource, dpms->e_output, mode);
 
         if (dpms->dpms_change_hook)
@@ -305,9 +303,6 @@ _e_tizen_dpms_manager_cb_set_dpms(struct wl_client *client, struct wl_resource *
         return;
      }
 
-   gresource = resource;
-   dpms->mode = mode;
-
    if (delay_timer)
      ecore_timer_del(delay_timer);
    delay_timer = ecore_timer_add(1.0, _e_dpms_delay, dpms);
@@ -320,7 +315,6 @@ _e_tizen_dpms_manager_cb_set_dpms(struct wl_client *client, struct wl_resource *
         ERR("DPMS:tizen_dpms_manager set dpms fail(res:%p, output:%p, dpms=%d)", resource, dpms->e_output, mode);
         ecore_timer_del(delay_timer);
         delay_timer = NULL;
-        gresource = NULL;
         tizen_dpms_manager_send_set_state(resource, dpms->mode, E_DPMS_MANAGER_ERROR_INVALID_PERMISSION);
      }
 }
@@ -360,6 +354,8 @@ _e_tizen_dpms_manager_cb_destroy(struct wl_client *client, struct wl_resource *r
      gresource = NULL;
 
    wl_resource_destroy(resource);
+
+   dpms_binded = EINA_FALSE;
 }
 
 static const struct tizen_dpms_manager_interface _e_tizen_dpms_interface =
@@ -382,6 +378,8 @@ _e_dpms_wl_cb_destroy(struct wl_resource *resource)
 
    if (gresource == resource)
      gresource = NULL;
+
+   dpms_binded = EINA_FALSE;
 }
 
 static void
@@ -389,6 +387,12 @@ _e_dpms_cb_bind(struct wl_client *client, void *data, uint32_t version, uint32_t
 {
    struct wl_resource *res;
 
+   if (dpms_binded)
+     {
+        ERR("already binded.");
+        return;
+     }
+
    if (!(res = wl_resource_create(client, &tizen_dpms_manager_interface, MIN(version, 1), id)))
      {
         ERR("Could not create tizen_dpms_manager resource");
@@ -396,6 +400,9 @@ _e_dpms_cb_bind(struct wl_client *client, void *data, uint32_t version, uint32_t
         return;
      }
 
+   gresource = res;
+   dpms_binded = EINA_TRUE;
+
    wl_resource_set_implementation(res, &_e_tizen_dpms_interface, NULL, _e_dpms_wl_cb_destroy);
 }
 
@@ -403,6 +410,7 @@ EINTERN int
 e_dpms_init(void)
 {
    dbus_init_done_handler = NULL;
+   dpms_binded = EINA_FALSE;
 
    if (e_dbus_conn_init() > 0)
      {