4 * Copyright (c) 2023 Samsung Electronics Co., Ltd.
6 * Licensed under the Apache License, Version 2.0 (the License);
7 * you may not use this file except in compliance with the License.
8 * You may obtain a copy of the License at
10 * http://www.apache.org/licenses/LICENSE-2.0
12 * Unless required by applicable law or agreed to in writing, software
13 * distributed under the License is distributed on an "AS IS" BASIS,
14 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 * See the License for the specific language governing permissions and
16 * limitations under the License.
20 * @file display-state-transition.c
21 * @brief This file has functions related to display state transition
24 #include "device-interface.h"
25 #include "display-state-transition.h"
26 #include "display-plugin.h"
27 #include "power/power-suspend.h"
28 #include "shared/log.h"
30 static guint state_transition_timer_id;
32 static int trans_table[S_END][EVENT_END] = {
34 { S_START, S_START }, /* S_START */
35 { S_LCDDIM, S_NORMAL }, /* S_NORMAL */
36 { S_LCDOFF, S_NORMAL }, /* S_LCDDIM */
37 { S_SLEEP, S_NORMAL }, /* S_LCDOFF */
38 { S_SLEEP, S_STANDBY }, /* S_STANDBY */
39 { S_LCDOFF, S_NORMAL }, /* S_SLEEP */
40 { S_POWEROFF, S_POWEROFF }, /* S_POWEROFF */
43 static bool is_display_state_valid(enum state_t display_state)
45 return (display_state >= S_START && display_state < S_END);
48 static bool is_device_event_type_valid(int event_type)
50 return (event_type >= EVENT_TIMEOUT && event_type < EVENT_END);
53 int display_state_transition_get_next_transition_display_state(enum state_t from_state, enum state_t *to_state, int evt_type)
55 if (!to_state || !is_display_state_valid(from_state) || !is_device_event_type_valid(evt_type))
58 *to_state = trans_table[from_state][evt_type];
62 int display_state_transition_set_transition_table_display_state(enum state_t display_state, enum state_t set_state, int evt_type)
64 if (!is_display_state_valid(display_state) || !is_device_event_type_valid(evt_type) || !is_display_state_valid(set_state))
67 trans_table[display_state][evt_type] = set_state;
71 static void remove_state_transition(void)
73 if (state_transition_timer_id) {
74 g_source_remove(state_transition_timer_id);
75 state_transition_timer_id = 0;
79 static gboolean state_transition_timeout_handler(void *data)
81 const char *state_name = NULL;
82 display_plugin_state_get_name(get_pm_cur_state(), &state_name);
83 _I("Time out state %s", state_name);
85 remove_state_transition();
87 display_plugin_state_do_default_trans(get_pm_cur_state(), EVENT_TIMEOUT);
88 return G_SOURCE_REMOVE;
91 bool display_state_transition_is_there_state_transition_timer(void)
93 return (state_transition_timer_id != 0);
96 int display_state_transition_reset_state_transition_timeout(int timeout)
99 if (!display_plugin_config_get_timeout_enable(&timeout_enable) && (!timeout_enable))
102 if ((get_pm_cur_state() == S_LCDOFF)
103 && (is_emulator() == true || timeout_sleep_support == false))
106 _I("Reset timeout(%d ms) pm_cur_state(%d).", timeout, get_pm_cur_state());
107 remove_state_transition();
109 if (trans_table[get_pm_cur_state()][EVENT_TIMEOUT] == get_pm_cur_state())
113 state_transition_timer_id = g_timeout_add(timeout,
114 state_transition_timeout_handler, NULL);
115 else if (timeout == 0)
116 display_plugin_state_do_default_trans(get_pm_cur_state(), EVENT_TIMEOUT);