display: display-state-transition: Relocate fuctions related to transition timer...
[platform/core/system/deviced.git] / plugins / iot-headed / display / core.c
index a493e31..0278ef0 100644 (file)
@@ -69,6 +69,7 @@
 #include "display-misc.h"
 #include "display-panel.h"
 #include "display-config.h"
+#include "display-state-transition.h"
 #include "shared/plugin.h"
 
 /**
@@ -98,11 +99,9 @@ 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 guint timeout_src_id;
 static int system_wakeup_flag = false;
 static unsigned int custom_normal_timeout = 0;
 static unsigned int custom_dim_timeout = 0;
-int custom_holdkey_block = false;
 static char *custom_change_name;
 static guint lock_timeout_id;
 static int lock_screen_timeout = LOCK_SCREEN_INPUT_TIMEOUT;
@@ -137,17 +136,6 @@ static struct state states[S_END] = {
        { S_POWEROFF, "S_POWEROFF", NULL,          NULL,           NULL,          NULL            },
 };
 
-static int trans_table[S_END][EVENT_END] = {
-       /* Timeout,   Input */
-       { S_START,    S_START    }, /* S_START */
-       { S_LCDDIM,   S_NORMAL   }, /* S_NORMAL */
-       { S_LCDOFF,   S_NORMAL   }, /* S_LCDDIM */
-       { S_SLEEP,    S_NORMAL   }, /* S_LCDOFF */
-       { S_SLEEP,    S_STANDBY  }, /* S_STANDBY */
-       { S_LCDOFF,   S_NORMAL   }, /* S_SLEEP */
-       { S_POWEROFF, S_POWEROFF }, /* S_POWEROFF */
-};
-
 #define SHIFT_UNLOCK           4
 #define SHIFT_CHANGE_STATE     7
 #define CHANGE_STATE_BIT       0xF00   /* 1111 0000 0000 */
@@ -218,11 +206,6 @@ inline struct state* state_st(enum state_t state)
        return &states[state];
 }
 
-guint get_transition_timer(void)
-{
-       return timeout_src_id;
-}
-
 static const char* __device_flags_to_string(enum device_flags flags)
 {
        if (flags & LCD_ON_BY_GESTURE)
@@ -384,7 +367,7 @@ static void del_state_cond(void *data, enum state_t state)
         *   1. There should be no running state-transition timer
         *   2. Released lock is one of the pm_cur_state's lock
         * This emulates already expired transition timer */
-       if (!timeout_src_id && get_pm_cur_state() == state)
+       if (!display_state_transition_is_there_state_transition_timer() && (get_pm_cur_state() == state))
                states[get_pm_cur_state()].trans(EVENT_TIMEOUT);
 
        if (state == S_LCDOFF)
@@ -409,45 +392,6 @@ static gboolean del_off_cond(void *data)
        return G_SOURCE_REMOVE;
 }
 
-/* timeout handler  */
-gboolean timeout_handler(void *data)
-{
-       _I("Time out state %s", states[get_pm_cur_state()].name);
-
-       if (timeout_src_id) {
-               g_source_remove(timeout_src_id);
-               timeout_src_id = 0;
-       }
-
-       states[get_pm_cur_state()].trans(EVENT_TIMEOUT);
-       return G_SOURCE_REMOVE;
-}
-
-void reset_timeout(int timeout)
-{
-       if (!display_conf.timeout_enable)
-               return;
-
-       if ((get_pm_cur_state() == S_LCDOFF)
-       && (is_emulator() == true || timeout_sleep_support == false))
-               return;
-
-       _I("Reset timeout(%d ms).", timeout);
-       if (timeout_src_id != 0) {
-               g_source_remove(timeout_src_id);
-               timeout_src_id = 0;
-       }
-
-       if (trans_table[get_pm_cur_state()][EVENT_TIMEOUT] == get_pm_cur_state())
-               return;
-
-       if (timeout > 0)
-               timeout_src_id = g_timeout_add(timeout,
-                   timeout_handler, NULL);
-       else if (timeout == 0)
-               states[get_pm_cur_state()].trans(EVENT_TIMEOUT);
-}
-
 /* get configurations from setting */
 static int get_lcd_timeout_from_settings(void)
 {
@@ -951,13 +895,13 @@ static int proc_condition(PMMsg *data)
        if (flags == 0) {
                /* guard time for suspend */
                if (get_pm_cur_state() == S_LCDOFF)
-                       reset_timeout(states[S_LCDOFF].timeout);
+                       display_state_transition_reset_state_transition_timeout(states[S_LCDOFF].timeout);
        } else {
                if (flags & PM_FLAG_RESET_TIMER)
-                       reset_timeout(states[get_pm_cur_state()].timeout);
+                       display_state_transition_reset_state_transition_timeout(states[get_pm_cur_state()].timeout);
        }
 
-       if (!timeout_src_id)
+       if (!display_state_transition_is_there_state_transition_timer())
                states[get_pm_cur_state()].trans(EVENT_TIMEOUT);
 
        return 0;
@@ -1147,9 +1091,9 @@ int check_lcdoff_direct(void)
 static int default_trans(int evt)
 {
        struct state *st = &states[get_pm_cur_state()];
-       int next_state;
+       enum state_t next_state;
 
-       next_state = (enum state_t)trans_table[get_pm_cur_state()][evt];
+       display_state_transition_get_next_transition_display_state(get_pm_cur_state(), &next_state, evt);
 
        /* check conditions */
        if (st->check && !st->check(get_pm_cur_state(), next_state)) {
@@ -1259,7 +1203,7 @@ static int default_action(int timeout)
                        lcdon_tv.tv_sec = 0;
                }
                /* set timer with current state timeout */
-               reset_timeout(timeout);
+               display_state_transition_reset_state_transition_timeout(timeout);
 
                if (get_pm_cur_state() == S_NORMAL) {
                        time(&last_update_time);
@@ -1658,10 +1602,10 @@ int set_lcd_timeout(int on, int dim, int holdkey_block, const char *name)
                states[get_pm_cur_state()].trans(EVENT_INPUT);
 
        if (holdkey_block) {
-               custom_holdkey_block = true;
+               display_lock_set_custom_holdkey_block(true);
                _I("Hold key disabled.");
        } else {
-               custom_holdkey_block = false;
+               display_lock_set_custom_holdkey_block(false);
                _I("Hold key enabled.");
        }
 
@@ -1679,7 +1623,7 @@ int set_lcd_timeout(int on, int dim, int holdkey_block, const char *name)
        if (!custom_change_name) {
                _E("Failed to malloc.");
                custom_normal_timeout = custom_dim_timeout = 0;
-               custom_holdkey_block = false;
+               display_lock_set_custom_holdkey_block(false);
                return -ENOMEM;
        }
 
@@ -1705,7 +1649,7 @@ void reset_lcd_timeout(GDBusConnection *conn,
        free(custom_change_name);
        custom_change_name = 0;
        custom_normal_timeout = custom_dim_timeout = 0;
-       custom_holdkey_block = false;
+       display_lock_set_custom_holdkey_block(false);
 
        update_display_time();
        if (get_pm_cur_state() == S_NORMAL)
@@ -1748,13 +1692,13 @@ static gboolean delayed_dpms_init_done(gpointer data)
                        /* check minimun lcd on time */
                        if (timeout < SEC_TO_MSEC(DEFAULT_NORMAL_TIMEOUT))
                                timeout = SEC_TO_MSEC(DEFAULT_NORMAL_TIMEOUT);
-                       reset_timeout(timeout);
+                       display_state_transition_reset_state_transition_timeout(timeout);
                }
                break;
        case S_LCDOFF:
                lcd_off_procedure(LCD_OFF_BY_EVENT);
                timeout = display_conf.lcdoff_timeout;
-               reset_timeout(timeout);
+               display_state_transition_reset_state_transition_timeout(timeout);
                break;
        default:
                break;
@@ -1770,6 +1714,12 @@ static void add_timer_for_dpms_init(void)
                _E("Failed to add display_panel_init_dpms timeout.");
 }
 
+static void init_display_states(void *data)
+{
+       struct display_plugin *dp = (struct display_plugin *) data;
+       for(int i = 0; i < S_END; i++)
+               dp->display_states[i] = &states[i];
+}
 /**
  * Power manager Main
  *
@@ -1781,7 +1731,9 @@ static int display_probe(void *data)
        assert(dp);
 
        dp->config = &display_conf;
+       init_display_states(dp);
        setup_display_plugin_backlight_ops(dp);
+       dp->delete_state_cond = del_state_cond;
 
        /* check display feature */
        if (!is_feature_display_supported())
@@ -1972,7 +1924,7 @@ static void display_init(void *data)
 
                if (display_conf.lcd_always_on) {
                        _I("LCD always on.");
-                       trans_table[S_NORMAL][EVENT_TIMEOUT] = S_NORMAL;
+                       display_state_transition_set_transition_table_display_state(S_NORMAL, S_NORMAL, EVENT_TIMEOUT);
                }
 
                if (flags & WITHOUT_STARTNOTI) {        /* start without noti */
@@ -2029,7 +1981,7 @@ static void display_exit(void *data)
        set_pm_cur_state(S_NORMAL);
        set_setting_pmstate(get_pm_cur_state());
        /* timeout is not needed */
-       reset_timeout(TIMEOUT_NONE);
+       display_state_transition_reset_state_transition_timeout(TIMEOUT_NONE);
 
        if (CHECK_OPS(keyfilter_ops, exit))
                keyfilter_ops->exit();