#define ALWAYS_ON_TIMEOUT 360000000
+/* display state */
+static enum deviced_display_state current = DEVICED_DISPLAY_STATE_START;
+static enum deviced_display_state previous = DEVICED_DISPLAY_STATE_START;
+
static guint state_transition_timer_id;
static unsigned int custom_normal_timeout = 0;
static unsigned int custom_dim_timeout = 0;
return (display_state >= DEVICED_DISPLAY_STATE_START && display_state < DEVICED_DISPLAY_STATE_END);
}
+/**
+ * FIXME: All those getter/setter for current/previous will be changed to resource-manager.
+ * - get_pm_cur_state()
+ * - set_pm_cur_state()
+ * - get_pm_old_state()
+ * - set_pm_old_state()
+ */
+inline int get_pm_cur_state(void)
+{
+ return current;
+}
+
+inline void set_pm_cur_state(int state)
+{
+ if (!is_display_state_valid(state))
+ return;
+
+ current = state;
+}
+
+inline int get_pm_old_state(void)
+{
+ return previous;
+}
+
+inline void set_pm_old_state(int state)
+{
+ if (!is_display_state_valid(state))
+ return;
+
+ previous = state;
+}
+
static bool is_device_event_type_valid(int event_type)
{
return (event_type >= EVENT_TIMEOUT && event_type < EVENT_END);
static gboolean state_transition_timeout_handler(void *data)
{
const char *state_name = NULL;
- display_plugin_state_get_name(get_pm_cur_state(), &state_name);
+ display_plugin_state_get_name(current, &state_name);
_I("Time out state %s", state_name);
remove_state_transition();
- display_state_transition_do_state_transition(get_pm_cur_state(), EVENT_TIMEOUT);
+ display_state_transition_do_state_transition(current, EVENT_TIMEOUT);
return G_SOURCE_REMOVE;
}
if (!display_plugin_config_get_timeout_enable(&timeout_enable) && (!timeout_enable))
return -EPERM;
- if ((get_pm_cur_state() == DEVICED_DISPLAY_STATE_OFF)
+ if ((current == DEVICED_DISPLAY_STATE_OFF)
&& (syscommon_is_emulator() == true || timeout_sleep_support == false))
return -EPERM;
- _I("Reset timeout(%d ms) pm_cur_state(%d).", timeout, get_pm_cur_state());
+ _I("Reset timeout(%d ms) pm_cur_state(%d).", timeout, current);
remove_state_transition();
- if (trans_table[get_pm_cur_state()][EVENT_TIMEOUT] == get_pm_cur_state())
+ if (trans_table[current][EVENT_TIMEOUT] == current)
return -EPERM;
if (timeout > 0)
state_transition_timer_id = g_timeout_add(timeout,
state_transition_timeout_handler, NULL);
else if (timeout == 0)
- display_state_transition_do_state_transition(get_pm_cur_state(), EVENT_TIMEOUT);
+ display_state_transition_do_state_transition(current, EVENT_TIMEOUT);
return 0;
}
int hdmi_state;
int dimming;
- if (get_pm_old_state() != DEVICED_DISPLAY_STATE_ON)
+ if (previous != DEVICED_DISPLAY_STATE_ON)
return false;
- if (get_pm_cur_state() != DEVICED_DISPLAY_STATE_DIM)
+ if (current != DEVICED_DISPLAY_STATE_DIM)
return false;
display_plugin_config_get_dimming(&dimming);
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);
+ display_state_transition_get_next_transition_display_state(current, &next_state, evt_type);
/* check conditions */
- ret = display_state_transition_check_state_transition_condition(get_pm_cur_state(), next_state);
+ ret = display_state_transition_check_state_transition_condition(current, next_state);
if (ret < 0) {
- display_plugin_state_get_name(get_pm_cur_state(), ¤t_state_name);
+ display_plugin_state_get_name(current, ¤t_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);
}
/* state transition */
- set_pm_old_state(get_pm_cur_state());
- set_pm_cur_state(next_state);
+ previous = current;
+ current = next_state;
/* enter action */
- if (display_state_transition_is_display_state_support_transition(get_pm_cur_state())) {
- if (get_pm_cur_state() == DEVICED_DISPLAY_STATE_OFF)
+ if (display_state_transition_is_display_state_support_transition(current)) {
+ if (current == DEVICED_DISPLAY_STATE_OFF)
display_state_transition_update_lcdoff_reason(VCONFKEY_PM_LCDOFF_BY_TIMEOUT);
- if ((get_pm_cur_state() == DEVICED_DISPLAY_STATE_ON) || (get_pm_cur_state() == DEVICED_DISPLAY_STATE_OFF))
+ if ((current == DEVICED_DISPLAY_STATE_ON) || (current == DEVICED_DISPLAY_STATE_OFF))
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);
+ display_state_transition_do_state_transition(current, EVENT_TIMEOUT);
} else {
- if ((get_pm_cur_state() == DEVICED_DISPLAY_STATE_SLEEP) &&
+ if ((current == DEVICED_DISPLAY_STATE_SLEEP) &&
(syscommon_is_emulator() == true || timeout_sleep_support == false))
return 0;
- display_plugin_state_get_timeout(get_pm_cur_state(), &timeout);
+ display_plugin_state_get_timeout(current, &timeout);
display_state_transition_do_state_action(timeout);
}
}
return -ECANCELED;
}
- if ((get_pm_cur_state() == DEVICED_DISPLAY_STATE_OFF) || (get_pm_cur_state() == DEVICED_DISPLAY_STATE_SLEEP))
+ if ((current == DEVICED_DISPLAY_STATE_OFF) || (current == DEVICED_DISPLAY_STATE_SLEEP))
_I("Input event signal at Display Off");
time(&now);
- if ((last_time != now) || (get_pm_cur_state() == DEVICED_DISPLAY_STATE_OFF) || (get_pm_cur_state() == DEVICED_DISPLAY_STATE_SLEEP)) {
- display_state_transition_do_state_transition(get_pm_cur_state(), EVENT_INPUT);
+ if ((last_time != now) || (current == DEVICED_DISPLAY_STATE_OFF) || (current == DEVICED_DISPLAY_STATE_SLEEP)) {
+ display_state_transition_do_state_transition(current, EVENT_INPUT);
last_time = now;
}
enum device_ops_status display_ops_status;
int diff_time = 0;
- if (!display_state_transition_is_display_state_support_transition(get_pm_cur_state()))
+ if (!display_state_transition_is_display_state_support_transition(current))
return -EPERM;
display_get_display_ops_status(&display_ops_status);
return -EINVAL;
}
- if (get_pm_cur_state() != DEVICED_DISPLAY_STATE_SLEEP) {
- if ((get_pm_cur_state() == DEVICED_DISPLAY_STATE_ON)) {
+ if (current != DEVICED_DISPLAY_STATE_SLEEP) {
+ if ((current == DEVICED_DISPLAY_STATE_ON)) {
if (display_panel_calculate_diff_time_between_lcd_on_direct_and_state_action(&diff_time) == 0) {
timeout -= diff_time;
}
/* set timer with current state timeout */
display_state_transition_reset_state_transition_timeout(timeout);
- if (get_pm_cur_state() == DEVICED_DISPLAY_STATE_ON) {
+ if (current == DEVICED_DISPLAY_STATE_ON) {
time(&last_update_time);
last_timeout = timeout;
} else {
- display_plugin_state_get_name(get_pm_cur_state(), &state_name);
+ display_plugin_state_get_name(current, &state_name);
_I("Timout set: %s state %d ms", state_name, timeout);
}
}
- if ((get_pm_cur_state() != get_pm_old_state()) && (get_pm_cur_state() != DEVICED_DISPLAY_STATE_SLEEP)) {
+ if ((current != previous) && (current != DEVICED_DISPLAY_STATE_SLEEP)) {
int wakeup_reason = 0;
syscommon_resman_get_resource_attr_int(SYSCOMMON_RESOURCE_ID(DEVICED_RESOURCE_TYPE_POWER),
DEVICED_POWER_ATTR_SET_UINT64_4_CURRENT_STATE,
DEVICED_POWER_STATE_SLEEP, DEVICED_POWER_STATE_NORMAL, wakeup_reason, 0);
- set_setting_pmstate(get_pm_cur_state());
- pm_cur_state = get_pm_cur_state();
+ set_setting_pmstate(current);
+ pm_cur_state = current;
syscommon_notifier_emit_notify(DEVICE_NOTIFIER_LCD, (void *)&pm_cur_state);
}
- if ((get_pm_old_state() == DEVICED_DISPLAY_STATE_ON) && (get_pm_cur_state() != DEVICED_DISPLAY_STATE_ON)) {
+ if ((previous == DEVICED_DISPLAY_STATE_ON) && (current != DEVICED_DISPLAY_STATE_ON)) {
time(&now);
diff = difftime(now, last_update_time);
- display_plugin_state_get_name(get_pm_cur_state(), &state_name);
+ display_plugin_state_get_name(current, &state_name);
_I("DEVICED_DISPLAY_STATE_ON is changed to %s (timeout=%d ms diff=%.0f s).",
state_name, last_timeout, diff);
}
- switch (get_pm_cur_state()) {
+ switch (current) {
case DEVICED_DISPLAY_STATE_ON:
/*
* normal state : backlight on and restore
* the previous brightness
*/
- if (get_pm_old_state() == DEVICED_DISPLAY_STATE_DIM)
+ if (previous == DEVICED_DISPLAY_STATE_DIM)
display_backlight_update_by_default_brightness();
if (display_panel_get_dpms_cached_state() != DPMS_ON)
case DEVICED_DISPLAY_STATE_DIM:
display_backlight_get_custom_status(&custom_status);
- if ((get_pm_old_state() == DEVICED_DISPLAY_STATE_ON) && custom_status) {
+ if ((previous == DEVICED_DISPLAY_STATE_ON) && custom_status) {
display_backlight_get_brightness(&brightness);
display_backlight_set_custom_brightness(brightness);
}
/* lcd dim state : dim the brightness */
display_backlight_set_brightness_by_dim_brightness();
- if ((get_pm_old_state() == DEVICED_DISPLAY_STATE_OFF) || (get_pm_old_state() == DEVICED_DISPLAY_STATE_SLEEP))
+ if ((previous == DEVICED_DISPLAY_STATE_OFF) || (previous == DEVICED_DISPLAY_STATE_SLEEP))
display_panel_lcd_on_procedure(LCD_DIM, NORMAL_MODE);
break;
case DEVICED_DISPLAY_STATE_OFF:
- if ((get_pm_old_state() != DEVICED_DISPLAY_STATE_SLEEP) && (get_pm_old_state() != DEVICED_DISPLAY_STATE_OFF)) {
+ if ((previous != DEVICED_DISPLAY_STATE_SLEEP) && (previous != DEVICED_DISPLAY_STATE_OFF)) {
/* lcd off state : turn off the backlight */
if (display_panel_get_dpms_cached_state() == DPMS_ON)
display_panel_lcd_off_procedure(LCD_OFF_BY_TIMEOUT);
}
}
goto go_suspend;
+ default: /* DEVICED_DISPLAY_STATE_START */
+ return 0;
}
return 0;
go_suspend:
#ifdef ENABLE_PM_LOG
- pm_history_save(PM_LOG_SLEEP, get_pm_cur_state());
+ pm_history_save(PM_LOG_SLEEP, current);
#endif
syscommon_resman_set_resource_attr_uint64_4(SYSCOMMON_RESOURCE_ID(DEVICED_RESOURCE_TYPE_POWER),
DEVICED_POWER_ATTR_SET_UINT64_4_CURRENT_STATE,
go_lcd_off:
if (!pm_get_power_lock_support()) {
/* Resume !! */
- display_state_transition_do_state_transition(get_pm_cur_state(), EVENT_DEVICE);
+ display_state_transition_do_state_transition(current, EVENT_DEVICE);
}
return 0;
}
{
int state_timeout = 0;
- set_pm_old_state(get_pm_cur_state());
- set_pm_cur_state(next);
+ previous = current;
+ current = next;
- display_plugin_state_get_timeout(get_pm_cur_state(), &state_timeout);
+ display_plugin_state_get_timeout(current, &state_timeout);
if (timeout < 0)
display_state_transition_do_state_action(state_timeout);