2d00019d47b804bfe322602b794d64a41d51bfbd
[platform/core/system/deviced.git] / src / display / display-state-transition.c
1 /*
2  * deviced
3  *
4  * Copyright (c) 2023 Samsung Electronics Co., Ltd.
5  *
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
9  *
10  *     http://www.apache.org/licenses/LICENSE-2.0
11  *
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.
17  */
18
19 /**
20  * @file        display-state-transition.c
21  * @brief       This file has functions related to display state transition
22  */
23
24 #include "device-interface.h"
25 #include "display-state-transition.h"
26 #include "display-plugin.h"
27
28 static int trans_table[S_END][EVENT_END] = {
29         /* Timeout,   Input */
30         { S_START,    S_START    }, /* S_START */
31         { S_LCDDIM,   S_NORMAL   }, /* S_NORMAL */
32         { S_LCDOFF,   S_NORMAL   }, /* S_LCDDIM */
33         { S_SLEEP,    S_NORMAL   }, /* S_LCDOFF */
34         { S_SLEEP,    S_STANDBY  }, /* S_STANDBY */
35         { S_LCDOFF,   S_NORMAL   }, /* S_SLEEP */
36         { S_POWEROFF, S_POWEROFF }, /* S_POWEROFF */
37 };
38
39 static bool is_display_state_valid(enum state_t display_state)
40 {
41         return (display_state >= S_START && display_state < S_END);
42 }
43
44 static bool is_device_event_type_valid(int event_type)
45 {
46         return (event_type >= EVENT_TIMEOUT && event_type < EVENT_END);
47 }
48
49 int display_state_transition_get_next_transition_display_state(enum state_t from_state, enum state_t *to_state, int evt_type)
50 {
51         if (!to_state || !is_display_state_valid(from_state) || !is_device_event_type_valid(evt_type))
52                 return -EINVAL;
53
54         *to_state = trans_table[from_state][evt_type];
55         return 0;
56 }
57
58 int display_state_transition_set_transition_table_display_state(enum state_t display_state, enum state_t set_state, int evt_type)
59 {
60         if (!is_display_state_valid(display_state) || !is_device_event_type_valid(evt_type) || !is_display_state_valid(set_state))
61                 return -EINVAL;
62
63         trans_table[display_state][evt_type] = set_state;
64         return 0;
65 }