display: Relocate set_lcd_timeout()/reset_lcd_timeout() 73/294273/4
authorYunhee Seo <yuni.seo@samsung.com>
Thu, 15 Jun 2023 07:51:24 +0000 (16:51 +0900)
committerYunhee Seo <yuni.seo@samsung.com>
Mon, 26 Jun 2023 05:15:15 +0000 (14:15 +0900)
set_lcd_timeout(), reset_lcd_timeout() is only used by dbus_setlcdtimeout call.
However, it is unclear where it is being used.
Furthermore, those functions' work flow overlap with set custom timeout, state transition.

Thus, these functions are moved to display-dbus.c
After that, it will be refactored.

Change-Id: Iad32a524cc4fc8d8548258766236921be22dc94f
Signed-off-by: Yunhee Seo <yuni.seo@samsung.com>
plugins/iot-headed/display/core.c
plugins/mobile/display/core.c
plugins/tv/display/core.c
plugins/wearable/display/core.c
src/display/core.h
src/display/plugin-common/display-dbus.c

index a109de9..b144e11 100644 (file)
@@ -88,8 +88,6 @@ static struct battery_plugin *battery_plgn;
 static int (*fp_get_charging_status) (int *val);
 static enum device_ops_status status = DEVICE_OPS_STATUS_UNINIT;
 
-static char *custom_change_name;
-
 static int default_proc_change_state(unsigned int cond, pid_t pid);
 static int (*proc_change_state)(unsigned int cond, pid_t pid) = default_proc_change_state;
 
@@ -609,75 +607,6 @@ static const char *errMSG[INIT_END] = {
        [INIT_DBUS] = "d-bus init error",
 };
 
-int set_lcd_timeout(int on, int dim, const char *name)
-{
-       unsigned int custom_normal_timeout = 0;
-       unsigned int custom_dim_timeout = 0;
-
-       if (on == 0 && dim == 0) {
-               _I("LCD timeout changed: default setting");
-               display_state_transition_set_custom_timeout(S_NORMAL, 0);
-               display_state_transition_set_custom_timeout(S_LCDDIM, 0);
-       } else if (on < 0 || dim < 0) {
-               _E("Failed to set value(on=%d dim=%d).", on, dim);
-               return -EINVAL;
-       } else {
-               _I("LCD timeout changed: on=%ds dim=%ds", on, dim);
-               display_state_transition_set_custom_timeout(S_NORMAL, SEC_TO_MSEC(on));
-               display_state_transition_set_custom_timeout(S_LCDDIM, SEC_TO_MSEC(dim));
-       }
-       /* Apply new backlight time */
-       display_state_transition_update_display_state_timeout_by_priority();
-       if (get_pm_cur_state() == S_NORMAL)
-               display_state_transition_do_state_transition(get_pm_cur_state(), EVENT_INPUT);
-
-       if (custom_change_name) {
-               free(custom_change_name);
-               custom_change_name = 0;
-       }
-
-       display_state_transition_get_custom_timeout(S_NORMAL, &custom_normal_timeout);
-       display_state_transition_get_custom_timeout(S_LCDDIM, &custom_dim_timeout);
-       if (custom_normal_timeout == 0 && custom_dim_timeout == 0)
-               return 0;
-
-       custom_change_name = strndup(name, strlen(name));
-       if (!custom_change_name) {
-               _E("Failed to malloc.");
-               display_state_transition_set_custom_timeout(S_NORMAL, 0);
-               display_state_transition_set_custom_timeout(S_LCDDIM, 0);
-               return -ENOMEM;
-       }
-
-       return 0;
-}
-
-void reset_lcd_timeout(GDBusConnection *conn,
-       const gchar     *sender,
-       const gchar     *unique_name,
-       gpointer         data)
-{
-       if (!sender)
-               return;
-
-       if (!custom_change_name)
-               return;
-
-       if (strcmp(sender, custom_change_name))
-               return;
-
-       _I("reset lcd timeout: Set default timeout. sender=%s", sender);
-
-       free(custom_change_name);
-       custom_change_name = 0;
-       display_state_transition_set_custom_timeout(S_NORMAL, 0);
-       display_state_transition_set_custom_timeout(S_LCDDIM, 0);
-
-       display_state_transition_update_display_state_timeout_by_priority();
-       if (get_pm_cur_state() == S_NORMAL)
-               display_state_transition_do_state_transition(get_pm_cur_state(), EVENT_INPUT);
-}
-
 static int delayed_init_done(void *data)
 {
        static bool done = false;
index dd3b864..f0ff545 100644 (file)
@@ -90,8 +90,6 @@ static int (*fp_get_charging_status) (int *val);
 
 static enum device_ops_status status = DEVICE_OPS_STATUS_UNINIT;
 
-static char *custom_change_name;
-
 static int default_proc_change_state(unsigned int cond, pid_t pid);
 static int (*proc_change_state)(unsigned int cond, pid_t pid) = default_proc_change_state;
 
@@ -618,75 +616,6 @@ static const char *errMSG[INIT_END] = {
        [INIT_DBUS] = "d-bus init error",
 };
 
-int set_lcd_timeout(int on, int dim, const char *name)
-{
-       unsigned int custom_normal_timeout = 0;
-       unsigned int custom_dim_timeout = 0;
-
-       if (on == 0 && dim == 0) {
-               _I("LCD timeout changed: default setting");
-               display_state_transition_set_custom_timeout(S_NORMAL, 0);
-               display_state_transition_set_custom_timeout(S_LCDDIM, 0);
-       } else if (on < 0 || dim < 0) {
-               _E("Failed to set value(on=%d dim=%d).", on, dim);
-               return -EINVAL;
-       } else {
-               _I("LCD timeout changed: on=%ds dim=%ds", on, dim);
-               display_state_transition_set_custom_timeout(S_NORMAL, SEC_TO_MSEC(on));
-               display_state_transition_set_custom_timeout(S_LCDDIM, SEC_TO_MSEC(dim));
-       }
-       /* Apply new backlight time */
-       display_state_transition_update_display_state_timeout_by_priority();
-       if (get_pm_cur_state() == S_NORMAL)
-               display_state_transition_do_state_transition(get_pm_cur_state(), EVENT_INPUT);
-
-       if (custom_change_name) {
-               free(custom_change_name);
-               custom_change_name = 0;
-       }
-
-       display_state_transition_get_custom_timeout(S_NORMAL, &custom_normal_timeout);
-       display_state_transition_get_custom_timeout(S_LCDDIM, &custom_dim_timeout);
-       if (custom_normal_timeout == 0 && custom_dim_timeout == 0)
-               return 0;
-
-       custom_change_name = strndup(name, strlen(name));
-       if (!custom_change_name) {
-               _E("Failed to malloc.");
-               display_state_transition_set_custom_timeout(S_NORMAL, 0);
-               display_state_transition_set_custom_timeout(S_LCDDIM, 0);
-               return -ENOMEM;
-       }
-
-       return 0;
-}
-
-void reset_lcd_timeout(GDBusConnection *conn,
-       const gchar     *sender,
-       const gchar     *unique_name,
-       gpointer         data)
-{
-       if (!sender)
-               return;
-
-       if (!custom_change_name)
-               return;
-
-       if (strcmp(sender, custom_change_name))
-               return;
-
-       _I("reset lcd timeout: Set default timeout. sender=%s", sender);
-
-       free(custom_change_name);
-       custom_change_name = 0;
-       display_state_transition_set_custom_timeout(S_NORMAL, 0);
-       display_state_transition_set_custom_timeout(S_LCDDIM, 0);
-
-       display_state_transition_update_display_state_timeout_by_priority();
-       if (get_pm_cur_state() == S_NORMAL)
-               display_state_transition_do_state_transition(get_pm_cur_state(), EVENT_INPUT);
-}
-
 static int delayed_init_done(void *data)
 {
        static bool done = false;
index 20465d5..65f76e7 100644 (file)
@@ -88,8 +88,6 @@ static int (*fp_get_charging_status) (int *val);
 
 static enum device_ops_status status = DEVICE_OPS_STATUS_UNINIT;
 
-static char *custom_change_name;
-
 static int default_proc_change_state(unsigned int cond, pid_t pid);
 static int (*proc_change_state)(unsigned int cond, pid_t pid) = default_proc_change_state;
 
@@ -608,75 +606,6 @@ static const char *errMSG[INIT_END] = {
        [INIT_DBUS] = "d-bus init error",
 };
 
-int set_lcd_timeout(int on, int dim, const char *name)
-{
-       unsigned int custom_normal_timeout = 0;
-       unsigned int custom_dim_timeout = 0;
-
-       if (on == 0 && dim == 0) {
-               _I("LCD timeout changed: default setting");
-               display_state_transition_set_custom_timeout(S_NORMAL, 0);
-               display_state_transition_set_custom_timeout(S_LCDDIM, 0);
-       } else if (on < 0 || dim < 0) {
-               _E("Failed to set value(on=%d dim=%d).", on, dim);
-               return -EINVAL;
-       } else {
-               _I("LCD timeout changed: on=%ds dim=%ds", on, dim);
-               display_state_transition_set_custom_timeout(S_NORMAL, SEC_TO_MSEC(on));
-               display_state_transition_set_custom_timeout(S_LCDDIM, SEC_TO_MSEC(dim));
-       }
-       /* Apply new backlight time */
-       display_state_transition_update_display_state_timeout_by_priority();
-       if (get_pm_cur_state() == S_NORMAL)
-               display_state_transition_do_state_transition(get_pm_cur_state(), EVENT_INPUT);
-
-       if (custom_change_name) {
-               free(custom_change_name);
-               custom_change_name = 0;
-       }
-
-       display_state_transition_get_custom_timeout(S_NORMAL, &custom_normal_timeout);
-       display_state_transition_get_custom_timeout(S_LCDDIM, &custom_dim_timeout);
-       if (custom_normal_timeout == 0 && custom_dim_timeout == 0)
-               return 0;
-
-       custom_change_name = strndup(name, strlen(name));
-       if (!custom_change_name) {
-               _E("Failed to malloc.");
-               display_state_transition_set_custom_timeout(S_NORMAL, 0);
-               display_state_transition_set_custom_timeout(S_LCDDIM, 0);
-               return -ENOMEM;
-       }
-
-       return 0;
-}
-
-void reset_lcd_timeout(GDBusConnection *conn,
-       const gchar     *sender,
-       const gchar     *unique_name,
-       gpointer         data)
-{
-       if (!sender)
-               return;
-
-       if (!custom_change_name)
-               return;
-
-       if (strcmp(sender, custom_change_name))
-               return;
-
-       _I("reset lcd timeout: Set default timeout. sender=%s", sender);
-
-       free(custom_change_name);
-       custom_change_name = 0;
-       display_state_transition_set_custom_timeout(S_NORMAL, 0);
-       display_state_transition_set_custom_timeout(S_LCDDIM, 0);
-
-       display_state_transition_update_display_state_timeout_by_priority();
-       if (get_pm_cur_state() == S_NORMAL)
-               display_state_transition_do_state_transition(get_pm_cur_state(), EVENT_INPUT);
-}
-
 static int delayed_init_done(void *data)
 {
        static bool done = false;
index 4eb15ca..3662293 100644 (file)
@@ -98,7 +98,6 @@ static int (*fp_get_charging_status) (int *val);
 static void (*power_saving_func) (int onoff);
 static enum device_ops_status status = DEVICE_OPS_STATUS_UNINIT;
 
-static char *custom_change_name;
 static guint transit_timer;
 /*
  * The two variables(lcdon_broadcast, pmstate_suspend) must be set initial
@@ -1239,75 +1238,6 @@ static const char *errMSG[INIT_END] = {
        [INIT_DBUS] = "d-bus init error",
 };
 
-int set_lcd_timeout(int on, int dim, const char *name)
-{
-       unsigned int custom_normal_timeout = 0;
-       unsigned int custom_dim_timeout = 0;
-
-       if (on == 0 && dim == 0) {
-               _I("LCD timeout changed: default setting");
-               display_state_transition_set_custom_timeout(S_NORMAL, 0);
-               display_state_transition_set_custom_timeout(S_LCDDIM, 0);
-       } else if (on < 0 || dim < 0) {
-               _E("Failed to set value(on=%d dim=%d).", on, dim);
-               return -EINVAL;
-       } else {
-               _I("LCD timeout changed: on=%ds dim=%ds", on, dim);
-               display_state_transition_set_custom_timeout(S_NORMAL, SEC_TO_MSEC(on));
-               display_state_transition_set_custom_timeout(S_LCDDIM, SEC_TO_MSEC(dim));
-       }
-       /* Apply new backlight time */
-       display_state_transition_update_display_state_timeout_by_priority();
-       if (get_pm_cur_state() == S_NORMAL)
-               states[get_pm_cur_state()].trans(EVENT_INPUT);
-
-       if (custom_change_name) {
-               free(custom_change_name);
-               custom_change_name = 0;
-       }
-
-       display_state_transition_get_custom_timeout(S_NORMAL, &custom_normal_timeout);
-       display_state_transition_get_custom_timeout(S_LCDDIM, &custom_dim_timeout);
-       if (custom_normal_timeout == 0 && custom_dim_timeout == 0)
-               return 0;
-
-       custom_change_name = strndup(name, strlen(name));
-       if (!custom_change_name) {
-               _E("Failed to malloc.");
-               display_state_transition_set_custom_timeout(S_NORMAL, 0);
-               display_state_transition_set_custom_timeout(S_LCDDIM, 0);
-               return -ENOMEM;
-       }
-
-       return 0;
-}
-
-void reset_lcd_timeout(GDBusConnection *conn,
-       const gchar     *sender,
-       const gchar     *unique_name,
-       gpointer         data)
-{
-       if (!sender)
-               return;
-
-       if (!custom_change_name)
-               return;
-
-       if (strcmp(sender, custom_change_name))
-               return;
-
-       _I("reset lcd timeout: Set default timeout. sender=%s", sender);
-
-       free(custom_change_name);
-       custom_change_name = 0;
-       display_state_transition_set_custom_timeout(S_NORMAL, 0);
-       display_state_transition_set_custom_timeout(S_LCDDIM, 0);
-
-       display_state_transition_update_display_state_timeout_by_priority();
-       if (get_pm_cur_state() == S_NORMAL)
-               states[get_pm_cur_state()].trans(EVENT_INPUT);
-}
-
 static int delayed_init_done(void *data)
 {
        static bool done = false;
index cb6ef6a..4b8d73a 100644 (file)
@@ -106,10 +106,6 @@ typedef struct {
 extern int poll_callback(int condition, PMMsg *data);
 
 extern struct state state[S_END];
-void reset_lcd_timeout(GDBusConnection *conn,
-                                               const gchar *sender,
-                                               const gchar *unique_name,
-                                               gpointer data);
 
 /* setting.c */
 int get_lock_screen_bg_state(void);
@@ -120,7 +116,6 @@ void set_lock_screen_bg_state(bool state);
 /* core.c */
 int delete_condition(enum state_t state);
 int custom_lcdoff(enum device_flags flag);
-int set_lcd_timeout(int on, int dim, const char *name);
 void broadcast_lcd_off_late(enum device_flags flags);
 
 /* auto-brightness.c */
index 4f58cf1..69840fa 100644 (file)
@@ -73,6 +73,7 @@
 #define EXPIRED_POPUP_ID     "_REQUEST_ID_"
 
 static struct display_plugin *disp_plgn;
+static char *custom_change_name;
 
 static GVariant *dbus_start(GDBusConnection *conn,
        const gchar *sender, const gchar *path, const gchar *iface, const gchar *name,
@@ -713,6 +714,76 @@ error:
        return g_variant_new("(i)", ret);
 }
 
+/* FIXME: these functions should be removed or refactored after discussion */
+static int set_lcd_timeout(int on, int dim, const char *name)
+{
+       unsigned int custom_normal_timeout = 0;
+       unsigned int custom_dim_timeout = 0;
+
+       if (on == 0 && dim == 0) {
+               _I("LCD timeout changed: default setting");
+               display_state_transition_set_custom_timeout(S_NORMAL, 0);
+               display_state_transition_set_custom_timeout(S_LCDDIM, 0);
+       } else if (on < 0 || dim < 0) {
+               _E("Failed to set value(on=%d dim=%d).", on, dim);
+               return -EINVAL;
+       } else {
+               _I("LCD timeout changed: on=%ds dim=%ds", on, dim);
+               display_state_transition_set_custom_timeout(S_NORMAL, SEC_TO_MSEC(on));
+               display_state_transition_set_custom_timeout(S_LCDDIM, SEC_TO_MSEC(dim));
+       }
+       /* Apply new backlight time */
+       display_state_transition_update_display_state_timeout_by_priority();
+       if (get_pm_cur_state() == S_NORMAL)
+               display_state_transition_do_state_transition(get_pm_cur_state(), EVENT_INPUT);
+
+       if (custom_change_name) {
+               free(custom_change_name);
+               custom_change_name = 0;
+       }
+
+       display_state_transition_get_custom_timeout(S_NORMAL, &custom_normal_timeout);
+       display_state_transition_get_custom_timeout(S_LCDDIM, &custom_dim_timeout);
+       if (custom_normal_timeout == 0 && custom_dim_timeout == 0)
+               return 0;
+
+       custom_change_name = strndup(name, strlen(name));
+       if (!custom_change_name) {
+               _E("Failed to malloc.");
+               display_state_transition_set_custom_timeout(S_NORMAL, 0);
+               display_state_transition_set_custom_timeout(S_LCDDIM, 0);
+               return -ENOMEM;
+       }
+
+       return 0;
+}
+
+static void reset_lcd_timeout(GDBusConnection *conn,
+       const gchar     *sender,
+       const gchar     *unique_name,
+       gpointer         data)
+{
+       if (!sender)
+               return;
+
+       if (!custom_change_name)
+               return;
+
+       if (strcmp(sender, custom_change_name))
+               return;
+
+       _I("reset lcd timeout: Set default timeout. sender=%s", sender);
+
+       free(custom_change_name);
+       custom_change_name = 0;
+       display_state_transition_set_custom_timeout(S_NORMAL, 0);
+       display_state_transition_set_custom_timeout(S_LCDDIM, 0);
+
+       display_state_transition_update_display_state_timeout_by_priority();
+       if (get_pm_cur_state() == S_NORMAL)
+               display_state_transition_do_state_transition(get_pm_cur_state(), EVENT_INPUT);
+}
+
 static GVariant *dbus_setlcdtimeout(GDBusConnection *conn,
        const gchar *sender, const gchar *path, const gchar *iface, const gchar *name,
        GVariant *param, GDBusMethodInvocation *invocation, gpointer user_data)