display: state-transition: Relocate default_trans() 79/293879/7
authorYunhee Seo <yuni.seo@samsung.com>
Wed, 7 Jun 2023 07:29:32 +0000 (16:29 +0900)
committerYunhee Seo <yuni.seo@samsung.com>
Mon, 12 Jun 2023 10:23:23 +0000 (19:23 +0900)
default_trans() was used for display state transition.
1. It gets next display state and checks if the state transition is possible or not.
2. And then, it updates old/current display state.
3. Finally, it goes to next state transition or default_action if possible.

These functions are added below display-state-transition.
- int display_state_transition_do_state_transition(enum state_t state, int evt_type);
    -> This replaces default_trans()
- bool display_state_transition_is_display_state_support_transition(enum state_t state);
    -> This function checks if state is support to do state transition related job.
       For example,
         1. checking state transition condition
         2. do state transition
         3. do state action
    To check these, this function is added.

Change-Id: Icc58965838e30fde2871c1c69596ffbed43e60f2
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
src/display/display-lock.c
src/display/display-plugin.c
src/display/display-plugin.h
src/display/display-state-transition.c
src/display/display-state-transition.h
src/display/plugin-common/poll.c

index 6eb4dd4..74eb8fd 100644 (file)
@@ -111,7 +111,6 @@ static bool lcdon_broadcast = true;
 static bool touch_blocked = false;
 
 /* default transition, action fuctions */
-static int default_trans(int evt);
 static int default_action(int timeout);
 
 static int default_proc_change_state(unsigned int cond, pid_t pid);
@@ -119,11 +118,11 @@ static int (*proc_change_state)(unsigned int cond, pid_t pid) = default_proc_cha
 
 static struct state states[S_END] = {
        { S_START,    "S_START",    NULL,          NULL,           NULL,          NULL            },
-       { S_NORMAL,   "S_NORMAL",   default_trans, default_action, NULL,          NULL            },
-       { S_LCDDIM,   "S_LCDDIM",   default_trans, default_action, NULL,          NULL            },
-       { S_LCDOFF,   "S_LCDOFF",   default_trans, default_action, NULL,          NULL            },
+       { S_NORMAL,   "S_NORMAL",   NULL,          default_action, NULL,          NULL            },
+       { S_LCDDIM,   "S_LCDDIM",   NULL,          default_action, NULL,          NULL            },
+       { S_LCDOFF,   "S_LCDOFF",   NULL,          default_action, NULL,          NULL            },
        { S_STANDBY,  "S_STANDBY",  NULL,          NULL,           NULL,          NULL            },
-       { S_SLEEP,    "S_SLEEP",    default_trans, default_action, NULL,          NULL            },
+       { S_SLEEP,    "S_SLEEP",    NULL,          default_action, NULL,          NULL            },
        { S_POWEROFF, "S_POWEROFF", NULL,          NULL,           NULL,          NULL            },
 };
 
@@ -709,7 +708,7 @@ static int proc_condition(PMMsg *data)
        }
 
        if (!display_state_transition_is_there_state_transition_timer())
-               states[get_pm_cur_state()].trans(EVENT_TIMEOUT);
+               display_state_transition_do_state_transition(get_pm_cur_state(), EVENT_TIMEOUT);
 
        return 0;
 }
@@ -724,58 +723,6 @@ static void sig_hup(int signo)
        pm_save_logdump();
 }
 
-/*
- * default transition function
- *   1. call check
- *   2. transition
- *   3. call enter action function
- */
-static int default_trans(int evt)
-{
-       struct state *st = &states[get_pm_cur_state()];
-       enum state_t next_state;
-       int ret = 0;
-
-       display_state_transition_get_next_transition_display_state(get_pm_cur_state(), &next_state, evt);
-
-       /* check conditions */
-       ret = display_state_transition_check_state_transition_condition(get_pm_cur_state(), next_state);
-       if (ret < 0) {
-               /* There is a condition. */
-               _I("%s locked. Trans to %s failed.", states[get_pm_cur_state()].name,
-                      states[next_state].name);
-               return -1;
-       }
-
-       /* state transition */
-       set_pm_old_state(get_pm_cur_state());
-       set_pm_cur_state(next_state);
-       st = &states[get_pm_cur_state()];
-
-       /* enter action */
-       if (st->action) {
-               if (get_pm_cur_state() == S_LCDOFF)
-                       display_state_transition_update_lcdoff_reason(VCONFKEY_PM_LCDOFF_BY_TIMEOUT);
-
-               if ((get_pm_cur_state() == S_NORMAL) || (get_pm_cur_state() == S_LCDOFF))
-                       if (set_custom_lcdon_timeout(0) == true)
-                               display_state_transition_update_display_state_timeout_by_priority();
-
-               if (display_state_transition_is_possible_to_go_lcdoff()) {
-                       /* enter next state directly */
-                       states[get_pm_cur_state()].trans(EVENT_TIMEOUT);
-               } else {
-                       if ((get_pm_cur_state() == S_SLEEP)
-                       && (is_emulator() == true || timeout_sleep_support == false))
-                               return 0;
-
-                       st->action(st->timeout);
-               }
-       }
-
-       return 0;
-}
-
 static gboolean lcd_on_expired(void *data)
 {
        int lock_state, ret;
@@ -952,7 +899,7 @@ go_suspend:
 go_lcd_off:
        if (!pm_get_power_lock_support()) {
                /* Resume !! */
-               states[get_pm_cur_state()].trans(EVENT_DEVICE);
+               display_state_transition_do_state_transition(get_pm_cur_state(), EVENT_DEVICE);
        }
        return 0;
 }
@@ -985,7 +932,7 @@ int poll_callback(int condition, PMMsg *data)
                if ((last_t != now) ||
                    (get_pm_cur_state() == S_LCDOFF) ||
                    (get_pm_cur_state() == S_SLEEP)) {
-                       states[get_pm_cur_state()].trans(EVENT_INPUT);
+                       display_state_transition_do_state_transition(get_pm_cur_state(), EVENT_INPUT);
                        last_t = now;
                }
        }
@@ -1007,7 +954,7 @@ static int update_setting(int key_idx, int val)
        switch (key_idx) {
        case SETTING_TO_NORMAL:
                display_state_transition_update_display_state_timeout_by_priority();
-               states[get_pm_cur_state()].trans(EVENT_INPUT);
+               display_state_transition_do_state_transition(get_pm_cur_state(), EVENT_INPUT);
                break;
        case SETTING_LOW_BATT:
                if (display_misc_is_low_battery_state(val)) {
@@ -1071,13 +1018,13 @@ static int update_setting(int key_idx, int val)
                stop_lock_timer();
                display_state_transition_update_display_state_timeout_by_priority();
                if (get_pm_cur_state() == S_NORMAL)
-                       states[get_pm_cur_state()].trans(EVENT_INPUT);
+                       display_state_transition_do_state_transition(get_pm_cur_state(), EVENT_INPUT);
                break;
        case SETTING_LOCK_SCREEN_BG:
                set_lock_screen_bg_state(val);
                display_state_transition_update_display_state_timeout_by_priority();
                if (get_pm_cur_state() == S_NORMAL)
-                       states[get_pm_cur_state()].trans(EVENT_INPUT);
+                       display_state_transition_do_state_transition(get_pm_cur_state(), EVENT_INPUT);
                break;
        case SETTING_POWER_CUSTOM_BRIGHTNESS:
                if (val == VCONFKEY_PM_CUSTOM_BRIGHTNESS_ON)
@@ -1208,7 +1155,7 @@ int set_lcd_timeout(int on, int dim, int holdkey_block, const char *name)
        /* 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);
+               display_state_transition_do_state_transition(get_pm_cur_state(), EVENT_INPUT);
 
        if (holdkey_block) {
                display_lock_set_custom_holdkey_block(true);
@@ -1266,7 +1213,7 @@ void reset_lcd_timeout(GDBusConnection *conn,
 
        display_state_transition_update_display_state_timeout_by_priority();
        if (get_pm_cur_state() == S_NORMAL)
-               states[get_pm_cur_state()].trans(EVENT_INPUT);
+               display_state_transition_do_state_transition(get_pm_cur_state(), EVENT_INPUT);
 }
 
 static int delayed_init_done(void *data)
@@ -1390,10 +1337,10 @@ static int power_resume_from_echomem_callback(void *data)
        system_wakeup_flag = true;
        if (check_wakeup_src() == EVENT_DEVICE)
                /* system waked up by devices */
-               states[get_pm_cur_state()].trans(EVENT_DEVICE);
+               display_state_transition_do_state_transition(get_pm_cur_state(), EVENT_DEVICE);
        else
                /* system waked up by user input */
-               states[get_pm_cur_state()].trans(EVENT_INPUT);
+               display_state_transition_do_state_transition(get_pm_cur_state(), EVENT_INPUT);
 
        return 0;
 }
index ec49a57..6d1244d 100644 (file)
@@ -113,7 +113,6 @@ static bool lcdon_broadcast = true;
 static bool touch_blocked = false;
 
 /* default transition, action fuctions */
-static int default_trans(int evt);
 static int default_action(int timeout);
 
 static int default_proc_change_state(unsigned int cond, pid_t pid);
@@ -121,11 +120,11 @@ static int (*proc_change_state)(unsigned int cond, pid_t pid) = default_proc_cha
 
 static struct state states[S_END] = {
        { S_START,    "S_START",    NULL,          NULL,           NULL,          NULL            },
-       { S_NORMAL,   "S_NORMAL",   default_trans, default_action, NULL,          NULL            },
-       { S_LCDDIM,   "S_LCDDIM",   default_trans, default_action, NULL,          NULL            },
-       { S_LCDOFF,   "S_LCDOFF",   default_trans, default_action, NULL,          NULL            },
+       { S_NORMAL,   "S_NORMAL",   NULL,          default_action, NULL,          NULL            },
+       { S_LCDDIM,   "S_LCDDIM",   NULL,          default_action, NULL,          NULL            },
+       { S_LCDOFF,   "S_LCDOFF",   NULL,          default_action, NULL,          NULL            },
        { S_STANDBY,  "S_STANDBY",  NULL,          NULL,           NULL,          NULL            },
-       { S_SLEEP,    "S_SLEEP",    default_trans, default_action, NULL,          NULL            },
+       { S_SLEEP,    "S_SLEEP",    NULL,          default_action, NULL,          NULL            },
        { S_POWEROFF, "S_POWEROFF", NULL,          NULL,           NULL,          NULL            },
 };
 
@@ -719,7 +718,7 @@ static int proc_condition(PMMsg *data)
        }
 
        if (!display_state_transition_is_there_state_transition_timer())
-               states[get_pm_cur_state()].trans(EVENT_TIMEOUT);
+               display_state_transition_do_state_transition(get_pm_cur_state(), EVENT_TIMEOUT);
 
        return 0;
 }
@@ -734,58 +733,6 @@ static void sig_hup(int signo)
        pm_save_logdump();
 }
 
-/*
- * default transition function
- *   1. call check
- *   2. transition
- *   3. call enter action function
- */
-static int default_trans(int evt)
-{
-       struct state *st = &states[get_pm_cur_state()];
-       enum state_t next_state;
-       int ret = 0;
-
-       display_state_transition_get_next_transition_display_state(get_pm_cur_state(), &next_state, evt);
-
-       /* check conditions */
-       ret = display_state_transition_check_state_transition_condition(get_pm_cur_state(), next_state);
-       if (ret < 0) {
-               /* There is a condition. */
-               _I("%s locked. Trans to %s failed.", states[get_pm_cur_state()].name,
-                      states[next_state].name);
-               return -1;
-       }
-
-       /* state transition */
-       set_pm_old_state(get_pm_cur_state());
-       set_pm_cur_state(next_state);
-       st = &states[get_pm_cur_state()];
-
-       /* enter action */
-       if (st->action) {
-               if (get_pm_cur_state() == S_LCDOFF)
-                       display_state_transition_update_lcdoff_reason(VCONFKEY_PM_LCDOFF_BY_TIMEOUT);
-
-               if ((get_pm_cur_state() == S_NORMAL) || (get_pm_cur_state() == S_LCDOFF))
-                       if (set_custom_lcdon_timeout(0) == true)
-                               display_state_transition_update_display_state_timeout_by_priority();
-
-               if (display_state_transition_is_possible_to_go_lcdoff()) {
-                       /* enter next state directly */
-                       states[get_pm_cur_state()].trans(EVENT_TIMEOUT);
-               } else {
-                       if ((get_pm_cur_state() == S_SLEEP)
-                       && (is_emulator() == true || timeout_sleep_support == false))
-                               return 0;
-
-                       st->action(st->timeout);
-               }
-       }
-
-       return 0;
-}
-
 static gboolean lcd_on_expired(void *data)
 {
        int lock_state, ret;
@@ -962,7 +909,7 @@ go_suspend:
 go_lcd_off:
        if (!pm_get_power_lock_support()) {
                /* Resume !! */
-               states[get_pm_cur_state()].trans(EVENT_DEVICE);
+               display_state_transition_do_state_transition(get_pm_cur_state(), EVENT_DEVICE);
        }
        return 0;
 }
@@ -995,7 +942,7 @@ int poll_callback(int condition, PMMsg *data)
                if ((last_t != now) ||
                    (get_pm_cur_state() == S_LCDOFF) ||
                    (get_pm_cur_state() == S_SLEEP)) {
-                       states[get_pm_cur_state()].trans(EVENT_INPUT);
+                       display_state_transition_do_state_transition(get_pm_cur_state(), EVENT_INPUT);
                        last_t = now;
                }
        }
@@ -1017,7 +964,7 @@ static int update_setting(int key_idx, int val)
        switch (key_idx) {
        case SETTING_TO_NORMAL:
                display_state_transition_update_display_state_timeout_by_priority();
-               states[get_pm_cur_state()].trans(EVENT_INPUT);
+               display_state_transition_do_state_transition(get_pm_cur_state(), EVENT_INPUT);
                break;
        case SETTING_LOW_BATT:
                if (display_misc_is_low_battery_state(val)) {
@@ -1081,13 +1028,13 @@ static int update_setting(int key_idx, int val)
                stop_lock_timer();
                display_state_transition_update_display_state_timeout_by_priority();
                if (get_pm_cur_state() == S_NORMAL)
-                       states[get_pm_cur_state()].trans(EVENT_INPUT);
+                       display_state_transition_do_state_transition(get_pm_cur_state(), EVENT_INPUT);
                break;
        case SETTING_LOCK_SCREEN_BG:
                set_lock_screen_bg_state(val);
                display_state_transition_update_display_state_timeout_by_priority();
                if (get_pm_cur_state() == S_NORMAL)
-                       states[get_pm_cur_state()].trans(EVENT_INPUT);
+                       display_state_transition_do_state_transition(get_pm_cur_state(), EVENT_INPUT);
                break;
        case SETTING_POWER_CUSTOM_BRIGHTNESS:
                if (val == VCONFKEY_PM_CUSTOM_BRIGHTNESS_ON)
@@ -1218,7 +1165,7 @@ int set_lcd_timeout(int on, int dim, int holdkey_block, const char *name)
        /* 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);
+               display_state_transition_do_state_transition(get_pm_cur_state(), EVENT_INPUT);
 
        if (holdkey_block) {
                display_lock_set_custom_holdkey_block(true);
@@ -1276,7 +1223,7 @@ void reset_lcd_timeout(GDBusConnection *conn,
 
        display_state_transition_update_display_state_timeout_by_priority();
        if (get_pm_cur_state() == S_NORMAL)
-               states[get_pm_cur_state()].trans(EVENT_INPUT);
+               display_state_transition_do_state_transition(get_pm_cur_state(), EVENT_INPUT);
 }
 
 static int delayed_init_done(void *data)
@@ -1396,10 +1343,10 @@ static int power_resume_from_echomem_callback(void *data)
        system_wakeup_flag = true;
        if (check_wakeup_src() == EVENT_DEVICE)
                /* system waked up by devices */
-               states[get_pm_cur_state()].trans(EVENT_DEVICE);
+               display_state_transition_do_state_transition(get_pm_cur_state(), EVENT_DEVICE);
        else
                /* system waked up by user input */
-               states[get_pm_cur_state()].trans(EVENT_INPUT);
+               display_state_transition_do_state_transition(get_pm_cur_state(), EVENT_INPUT);
 
        return 0;
 }
index 168041e..33072ae 100644 (file)
@@ -111,7 +111,6 @@ static bool lcdon_broadcast = true;
 static bool touch_blocked = false;
 
 /* default transition, action fuctions */
-static int default_trans(int evt);
 static int default_action(int timeout);
 
 static int default_proc_change_state(unsigned int cond, pid_t pid);
@@ -119,11 +118,11 @@ static int (*proc_change_state)(unsigned int cond, pid_t pid) = default_proc_cha
 
 static struct state states[S_END] = {
        { S_START,    "S_START",    NULL,          NULL,           NULL,          NULL            },
-       { S_NORMAL,   "S_NORMAL",   default_trans, default_action, NULL,          NULL            },
-       { S_LCDDIM,   "S_LCDDIM",   default_trans, default_action, NULL,          NULL            },
-       { S_LCDOFF,   "S_LCDOFF",   default_trans, default_action, NULL,          NULL            },
+       { S_NORMAL,   "S_NORMAL",   NULL,          default_action, NULL,          NULL            },
+       { S_LCDDIM,   "S_LCDDIM",   NULL,          default_action, NULL,          NULL            },
+       { S_LCDOFF,   "S_LCDOFF",   NULL,          default_action, NULL,          NULL            },
        { S_STANDBY,  "S_STANDBY",  NULL,          NULL,           NULL,          NULL            },
-       { S_SLEEP,    "S_SLEEP",    default_trans, default_action, NULL,          NULL            },
+       { S_SLEEP,    "S_SLEEP",    NULL,          default_action, NULL,          NULL            },
        { S_POWEROFF, "S_POWEROFF", NULL,          NULL,           NULL,          NULL            },
 };
 
@@ -709,7 +708,7 @@ static int proc_condition(PMMsg *data)
        }
 
        if (!display_state_transition_is_there_state_transition_timer())
-               states[get_pm_cur_state()].trans(EVENT_TIMEOUT);
+               display_state_transition_do_state_transition(get_pm_cur_state(), EVENT_TIMEOUT);
 
        return 0;
 }
@@ -724,58 +723,6 @@ static void sig_hup(int signo)
        pm_save_logdump();
 }
 
-/*
- * default transition function
- *   1. call check
- *   2. transition
- *   3. call enter action function
- */
-static int default_trans(int evt)
-{
-       struct state *st = &states[get_pm_cur_state()];
-       enum state_t next_state;
-       int ret = 0;
-
-       display_state_transition_get_next_transition_display_state(get_pm_cur_state(), &next_state, evt);
-
-       /* check conditions */
-       ret = display_state_transition_check_state_transition_condition(get_pm_cur_state(), next_state);
-       if (ret < 0) {
-               /* There is a condition. */
-               _I("%s locked. Trans to %s failed.", states[get_pm_cur_state()].name,
-                      states[next_state].name);
-               return -1;
-       }
-
-       /* state transition */
-       set_pm_old_state(get_pm_cur_state());
-       set_pm_cur_state(next_state);
-       st = &states[get_pm_cur_state()];
-
-       /* enter action */
-       if (st->action) {
-               if (get_pm_cur_state() == S_LCDOFF)
-                       display_state_transition_update_lcdoff_reason(VCONFKEY_PM_LCDOFF_BY_TIMEOUT);
-
-               if ((get_pm_cur_state() == S_NORMAL) || (get_pm_cur_state() == S_LCDOFF))
-                       if (set_custom_lcdon_timeout(0) == true)
-                               display_state_transition_update_display_state_timeout_by_priority();
-
-               if (display_state_transition_is_possible_to_go_lcdoff()) {
-                       /* enter next state directly */
-                       states[get_pm_cur_state()].trans(EVENT_TIMEOUT);
-               } else {
-                       if ((get_pm_cur_state() == S_SLEEP)
-                       && (is_emulator() == true || timeout_sleep_support == false))
-                               return 0;
-
-                       st->action(st->timeout);
-               }
-       }
-
-       return 0;
-}
-
 static gboolean lcd_on_expired(void *data)
 {
        int lock_state, ret;
@@ -952,7 +899,7 @@ go_suspend:
 go_lcd_off:
        if (!pm_get_power_lock_support()) {
                /* Resume !! */
-               states[get_pm_cur_state()].trans(EVENT_DEVICE);
+               display_state_transition_do_state_transition(get_pm_cur_state(), EVENT_DEVICE);
        }
        return 0;
 }
@@ -985,7 +932,7 @@ int poll_callback(int condition, PMMsg *data)
                if ((last_t != now) ||
                    (get_pm_cur_state() == S_LCDOFF) ||
                    (get_pm_cur_state() == S_SLEEP)) {
-                       states[get_pm_cur_state()].trans(EVENT_INPUT);
+                       display_state_transition_do_state_transition(get_pm_cur_state(), EVENT_INPUT);
                        last_t = now;
                }
        }
@@ -1007,7 +954,7 @@ static int update_setting(int key_idx, int val)
        switch (key_idx) {
        case SETTING_TO_NORMAL:
                display_state_transition_update_display_state_timeout_by_priority();
-               states[get_pm_cur_state()].trans(EVENT_INPUT);
+               display_state_transition_do_state_transition(get_pm_cur_state(), EVENT_INPUT);
                break;
        case SETTING_LOW_BATT:
                if (display_misc_is_low_battery_state(val)) {
@@ -1071,13 +1018,13 @@ static int update_setting(int key_idx, int val)
                stop_lock_timer();
                display_state_transition_update_display_state_timeout_by_priority();
                if (get_pm_cur_state() == S_NORMAL)
-                       states[get_pm_cur_state()].trans(EVENT_INPUT);
+                       display_state_transition_do_state_transition(get_pm_cur_state(), EVENT_INPUT);
                break;
        case SETTING_LOCK_SCREEN_BG:
                set_lock_screen_bg_state(val);
                display_state_transition_update_display_state_timeout_by_priority();
                if (get_pm_cur_state() == S_NORMAL)
-                       states[get_pm_cur_state()].trans(EVENT_INPUT);
+                       display_state_transition_do_state_transition(get_pm_cur_state(), EVENT_INPUT);
                break;
        case SETTING_POWER_CUSTOM_BRIGHTNESS:
                if (val == VCONFKEY_PM_CUSTOM_BRIGHTNESS_ON)
@@ -1208,7 +1155,7 @@ int set_lcd_timeout(int on, int dim, int holdkey_block, const char *name)
        /* 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);
+               display_state_transition_do_state_transition(get_pm_cur_state(), EVENT_INPUT);
 
        if (holdkey_block) {
                display_lock_set_custom_holdkey_block(true);
@@ -1266,7 +1213,7 @@ void reset_lcd_timeout(GDBusConnection *conn,
 
        display_state_transition_update_display_state_timeout_by_priority();
        if (get_pm_cur_state() == S_NORMAL)
-               states[get_pm_cur_state()].trans(EVENT_INPUT);
+               display_state_transition_do_state_transition(get_pm_cur_state(), EVENT_INPUT);
 }
 
 static int delayed_init_done(void *data)
@@ -1387,10 +1334,10 @@ static int power_resume_from_echomem_callback(void *data)
        system_wakeup_flag = true;
        if (check_wakeup_src() == EVENT_DEVICE)
                /* system waked up by devices */
-               states[get_pm_cur_state()].trans(EVENT_DEVICE);
+               display_state_transition_do_state_transition(get_pm_cur_state(), EVENT_DEVICE);
        else
                /* system waked up by user input */
-               states[get_pm_cur_state()].trans(EVENT_INPUT);
+               display_state_transition_do_state_transition(get_pm_cur_state(), EVENT_INPUT);
 
        return 0;
 }
index d218a19..5b2df70 100644 (file)
@@ -275,7 +275,7 @@ static gboolean delete_state_cond_callback(void *data)
         *   2. Released lock is one of the pm_cur_state's lock
         * This emulates already expired transition timer */
        if (!display_state_transition_is_there_state_transition_timer() && (get_pm_cur_state() == state))
-               display_plugin_state_do_default_trans(get_pm_cur_state(), EVENT_TIMEOUT);
+               display_state_transition_do_state_transition(get_pm_cur_state(), EVENT_TIMEOUT);
 
        if (state == S_LCDOFF)
                set_process_active(false, pid);
index 176ab5d..3af5995 100644 (file)
@@ -166,6 +166,15 @@ int display_plugin_state_do_default_action(enum state_t state, int timeout)
        return -EOPNOTSUPP;
 }
 
+/* FIXME: default_action/default_trans naming should be changed after state transition functions are relocated  */
+bool display_plugin_state_is_there_default_action(enum state_t state)
+{
+       if (g_display_plugin.display_states[state] && g_display_plugin.display_states[state]->action)
+               return true;
+
+       return false;
+}
+
 int display_plugin_state_get_name(enum state_t state, const char **state_name)
 {
        if (!state_name)
index 820cf0f..bea8205 100644 (file)
@@ -97,6 +97,7 @@ int display_plugin_backlight_transit_brightness(int start, int end, int step);
 int display_plugin_state_do_default_trans(enum state_t state, int evt);
 bool display_plugin_state_is_there_default_trans(enum state_t state);
 int display_plugin_state_do_default_action(enum state_t state, int timeout);
+bool display_plugin_state_is_there_default_action(enum state_t state);
 int display_plugin_state_get_name(enum state_t state, const char **state_name);
 int display_plugin_state_set_timeout(enum state_t state, int state_timeout);
 int display_plugin_state_get_timeout(enum state_t state, int *state_timeout);
index 4836cac..c7a5dff 100644 (file)
@@ -92,7 +92,7 @@ static gboolean state_transition_timeout_handler(void *data)
 
        remove_state_transition();
 
-       display_plugin_state_do_default_trans(get_pm_cur_state(), EVENT_TIMEOUT);
+       display_state_transition_do_state_transition(get_pm_cur_state(), EVENT_TIMEOUT);
        return G_SOURCE_REMOVE;
 }
 
@@ -121,7 +121,7 @@ int display_state_transition_reset_state_transition_timeout(int timeout)
                state_transition_timer_id = g_timeout_add(timeout,
                        state_transition_timeout_handler, NULL);
        else if (timeout == 0)
-               display_plugin_state_do_default_trans(get_pm_cur_state(), EVENT_TIMEOUT);
+               display_state_transition_do_state_transition(get_pm_cur_state(), EVENT_TIMEOUT);
 
        return 0;
 }
@@ -232,7 +232,7 @@ void display_state_transition_update_display_state_timeout_by_priority(void)
        _I("Normal: DIM timeout is set by %d ms", dim_state_timeout);
 }
 
-static bool is_display_state_valid_for_transition(enum state_t state)
+bool display_state_transition_is_display_state_support_transition(enum state_t state)
 {
        switch(state) {
        case S_NORMAL:
@@ -251,7 +251,7 @@ int display_state_transition_check_state_transition_condition(enum state_t cur_s
 {
        int trans_cond;
 
-       if (!is_display_state_valid_for_transition(cur_state))
+       if (!display_state_transition_is_display_state_support_transition(cur_state))
                return -EPERM;
 
        makeup_trans_condition();
@@ -304,7 +304,6 @@ int display_state_transition_update_lcdoff_reason(int source)
                _E("Failed to set vconf value for lcd off source: %d", vconf_get_ext_errno());
                return -EPERM;
        }
-
        return 0;
 }
 
@@ -342,4 +341,65 @@ bool display_state_transition_is_possible_to_go_lcdoff(void)
        _D("Goto LCDOFF direct: lock(%d) hdmi(%d) cradle(%d).", lock, hdmi_state, cradle);
 
        return true;
+}
+
+/* FXIME: enter action logic should be discussed and considered about better logic */
+/*
+ * default transition function
+ *   1. call check
+ *   2. transition
+ *   3. call enter action function
+ */
+int display_state_transition_do_state_transition(enum state_t state, int evt_type)
+{
+       const char* current_state_name = NULL;
+       const char* next_state_name = NULL;
+       enum state_t next_state;
+       int ret = 0;
+       int timeout = 0;
+
+       if (!display_state_transition_is_display_state_support_transition(state))
+               return -EPERM;
+
+       if (display_plugin_state_is_there_default_trans(state))
+               return display_plugin_state_do_default_trans(state, evt_type);
+
+       display_state_transition_get_next_transition_display_state(get_pm_cur_state(), &next_state, evt_type);
+
+       /* check conditions */
+       ret = display_state_transition_check_state_transition_condition(get_pm_cur_state(), next_state);
+       if (ret < 0) {
+               display_plugin_state_get_name(get_pm_cur_state(), &current_state_name);
+               display_plugin_state_get_name(next_state, &next_state_name);
+               /* There is a condition. */
+               _I("%s locked. Trans to %s failed.", current_state_name, next_state_name);
+               return -EPERM;
+       }
+
+       /* state transition */
+       set_pm_old_state(get_pm_cur_state());
+       set_pm_cur_state(next_state);
+
+       /* enter action */
+       if (display_plugin_state_is_there_default_action(get_pm_cur_state())) {
+               if (get_pm_cur_state() == S_LCDOFF)
+                       display_state_transition_update_lcdoff_reason(VCONFKEY_PM_LCDOFF_BY_TIMEOUT);
+
+               if ((get_pm_cur_state() == S_NORMAL) || (get_pm_cur_state() == S_LCDOFF))
+                       if (set_custom_lcdon_timeout(0) == true)
+                               display_state_transition_update_display_state_timeout_by_priority();
+
+               if (display_state_transition_is_possible_to_go_lcdoff()) {
+                       /* enter next state directly */
+                       display_state_transition_do_state_transition(get_pm_cur_state(), EVENT_TIMEOUT);
+               } else {
+                       if ((get_pm_cur_state() == S_SLEEP) &&
+                       (is_emulator() == true || timeout_sleep_support == false))
+                               return 0;
+
+                       display_plugin_state_get_timeout(get_pm_cur_state(), &timeout);
+                       display_plugin_state_do_default_action(get_pm_cur_state(), timeout);
+               }
+       }
+       return 0;
 }
\ No newline at end of file
index e114326..eeead2f 100644 (file)
@@ -40,5 +40,7 @@ void display_state_transition_update_display_state_timeout_by_priority(void);
 int display_state_transition_check_state_transition_condition(enum state_t cur_state, enum state_t next_state);
 int display_state_transition_update_lcdoff_reason(int source);
 bool display_state_transition_is_possible_to_go_lcdoff(void);
+int display_state_transition_do_state_transition(enum state_t state, int evt_type);
+bool display_state_transition_is_display_state_support_transition(enum state_t state);
 
 #endif /* __DISPLAY_STATE_TRANSITION_H__ */
\ No newline at end of file
index 769c6d4..d9f1d1d 100644 (file)
@@ -30,6 +30,7 @@
 #include "poll.h"
 #include "display-ops.h"
 #include "display-plugin.h"
+#include "display-state-transition.h"
 #include "shared/plugin.h"
 
 static PMMsg recv_data;
@@ -74,7 +75,7 @@ static int __pm_lock_internal(pid_t pid, int s_bits, int flag, int timeout)
        if (cond < 0)
                return cond;
 
-       if (!display_plugin_state_is_there_default_trans(cond))
+       if (!display_state_transition_is_display_state_support_transition(cond))
                return -ENOTSUP;
 
        cond = SET_COND_REQUEST(cond, PM_REQUEST_LOCK);
@@ -103,7 +104,7 @@ static int __pm_unlock_internal(pid_t pid, int s_bits, int flag)
        if (cond < 0)
                return cond;
 
-       if (!display_plugin_state_is_there_default_trans(cond))
+       if (!display_state_transition_is_display_state_support_transition(cond))
                return -ENOTSUP;
 
        cond = SET_COND_REQUEST(cond, PM_REQUEST_UNLOCK);
@@ -138,7 +139,7 @@ static int __pm_change_internal(pid_t pid, int s_bits)
                return -ENOTSUP;
        }
 
-       if (!display_plugin_state_is_there_default_trans(cond))
+       if (!display_state_transition_is_display_state_support_transition(cond))
                return -ENOTSUP;
 
        cond = SET_COND_REQUEST(cond, PM_REQUEST_CHANGE);