display: display-state-transition: Relocate trans_table to core 50/293350/10
authorYunhee Seo <yuni.seo@samsung.com>
Wed, 17 May 2023 04:20:28 +0000 (13:20 +0900)
committerYunhee Seo <yuni.seo@samsung.com>
Tue, 30 May 2023 11:47:58 +0000 (20:47 +0900)
trans_table is used for getting next display state according to event type.
It has following display state for a specific event in the current display state.

To get and set display state, these functions are added to below display-state-transition.
int display_state_transition_get_next_transition_display_state(enum state_t from_state, enum state_t *to_state, int evt_type);
int display_state_transition_set_transition_table_display_state(enum state_t display_state, enum state_t set_state, int evt_type);

Change-Id: I013a63b6059748b58db04e7b52e8366615c6b1ac
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
plugins/wearable/display/core.c
src/display/display-state-transition.c [new file with mode: 0644]
src/display/display-state-transition.h [new file with mode: 0644]

index b0b9aa6..902919d 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"
 
 /**
@@ -136,17 +137,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 */
@@ -424,6 +414,8 @@ gboolean timeout_handler(void *data)
 
 void reset_timeout(int timeout)
 {
+       enum state_t next_state;
+
        if (!display_conf.timeout_enable)
                return;
 
@@ -437,7 +429,8 @@ void reset_timeout(int timeout)
                timeout_src_id = 0;
        }
 
-       if (trans_table[get_pm_cur_state()][EVENT_TIMEOUT] == get_pm_cur_state())
+       display_state_transition_get_next_transition_display_state(get_pm_cur_state(), &next_state, EVENT_TIMEOUT);
+       if (next_state == get_pm_cur_state())
                return;
 
        if (timeout > 0)
@@ -1146,9 +1139,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)) {
@@ -1971,7 +1964,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 */
index a6a31f7..25d6f17 100644 (file)
@@ -70,6 +70,7 @@
 #include "display-misc.h"
 #include "display-panel.h"
 #include "display-config.h"
+#include "display-state-transition.h"
 #include "shared/plugin.h"
 
 /**
@@ -138,17 +139,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 */
@@ -431,6 +421,8 @@ gboolean timeout_handler(void *data)
 
 void reset_timeout(int timeout)
 {
+       enum state_t next_state;
+
        if (!display_conf.timeout_enable)
                return;
 
@@ -444,7 +436,8 @@ void reset_timeout(int timeout)
                timeout_src_id = 0;
        }
 
-       if (trans_table[get_pm_cur_state()][EVENT_TIMEOUT] == get_pm_cur_state())
+       display_state_transition_get_next_transition_display_state(get_pm_cur_state(), &next_state, EVENT_TIMEOUT);
+       if (next_state == get_pm_cur_state())
                return;
 
        if (timeout > 0)
@@ -1156,9 +1149,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)) {
@@ -1977,7 +1970,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 */
index b6b472e..805cb3a 100644 (file)
@@ -68,6 +68,7 @@
 #include "display-misc.h"
 #include "display-panel.h"
 #include "display-config.h"
+#include "display-state-transition.h"
 #include "shared/plugin.h"
 
 /**
@@ -136,17 +137,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 */
@@ -424,6 +414,8 @@ gboolean timeout_handler(void *data)
 
 void reset_timeout(int timeout)
 {
+       enum state_t next_state;
+
        if (!display_conf.timeout_enable)
                return;
 
@@ -437,7 +429,8 @@ void reset_timeout(int timeout)
                timeout_src_id = 0;
        }
 
-       if (trans_table[get_pm_cur_state()][EVENT_TIMEOUT] == get_pm_cur_state())
+       display_state_transition_get_next_transition_display_state(get_pm_cur_state(), &next_state, EVENT_TIMEOUT);
+       if (next_state == get_pm_cur_state())
                return;
 
        if (timeout > 0)
@@ -1146,9 +1139,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)) {
@@ -1968,7 +1961,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 */
index ac74b6e..510c714 100644 (file)
@@ -71,6 +71,7 @@
 #include "display-misc.h"
 #include "display-panel.h"
 #include "display-config.h"
+#include "display-state-transition.h"
 #include "shared/plugin.h"
 
 #define POWERLOCK_CONF_FILE  "/etc/deviced/powerlock.conf"
@@ -150,17 +151,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 */
@@ -701,6 +691,8 @@ gboolean timeout_handler(void *data)
 
 void reset_timeout(int timeout)
 {
+       enum state_t next_state;
+
        if (!display_conf.timeout_enable)
                return;
 
@@ -714,7 +706,8 @@ void reset_timeout(int timeout)
                timeout_src_id = 0;
        }
 
-       if (trans_table[get_pm_cur_state()][EVENT_TIMEOUT] == get_pm_cur_state())
+       display_state_transition_get_next_transition_display_state(get_pm_cur_state(), &next_state, EVENT_TIMEOUT);
+       if (next_state == get_pm_cur_state())
                return;
 
        if (timeout > 0)
@@ -1456,9 +1449,10 @@ int check_lcdoff_direct(void)
 static int default_trans(int evt)
 {
        struct state *st = &states[get_pm_cur_state()];
-       int next_state, ret;
+       int ret;
+       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)) {
@@ -2352,7 +2346,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 */
diff --git a/src/display/display-state-transition.c b/src/display/display-state-transition.c
new file mode 100644 (file)
index 0000000..2d00019
--- /dev/null
@@ -0,0 +1,65 @@
+/*
+ * deviced
+ *
+ * Copyright (c) 2023 Samsung Electronics Co., Ltd.
+ *
+ * Licensed under the Apache License, Version 2.0 (the License);
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+/**
+ * @file       display-state-transition.c
+ * @brief      This file has functions related to display state transition
+ */
+
+#include "device-interface.h"
+#include "display-state-transition.h"
+#include "display-plugin.h"
+
+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 */
+};
+
+static bool is_display_state_valid(enum state_t display_state)
+{
+       return (display_state >= S_START && display_state < S_END);
+}
+
+static bool is_device_event_type_valid(int event_type)
+{
+       return (event_type >= EVENT_TIMEOUT && event_type < EVENT_END);
+}
+
+int display_state_transition_get_next_transition_display_state(enum state_t from_state, enum state_t *to_state, int evt_type)
+{
+       if (!to_state || !is_display_state_valid(from_state) || !is_device_event_type_valid(evt_type))
+               return -EINVAL;
+
+       *to_state = trans_table[from_state][evt_type];
+       return 0;
+}
+
+int display_state_transition_set_transition_table_display_state(enum state_t display_state, enum state_t set_state, int evt_type)
+{
+       if (!is_display_state_valid(display_state) || !is_device_event_type_valid(evt_type) || !is_display_state_valid(set_state))
+               return -EINVAL;
+
+       trans_table[display_state][evt_type] = set_state;
+       return 0;
+}
\ No newline at end of file
diff --git a/src/display/display-state-transition.h b/src/display/display-state-transition.h
new file mode 100644 (file)
index 0000000..b7107d6
--- /dev/null
@@ -0,0 +1,32 @@
+/*
+ * deviced
+ *
+ * Copyright (c) 2023 Samsung Electronics Co., Ltd.
+ *
+ * Licensed under the Apache License, Version 2.0 (the License);
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+/**
+ * @file       display-state-transition.h
+ * @brief      This is temporary header to devide plugin and core display module.
+ *              After refactoring, this file will be removed.
+ */
+#ifndef __DISPLAY_STATE_TRANSITION_H__
+#define __DISPLAY_STATE_TRANSITION_H__
+
+#include "core.h"
+
+int display_state_transition_get_next_transition_display_state(enum state_t from_state, enum state_t *to_state, int evt_type);
+int display_state_transition_set_transition_table_display_state(enum state_t display_state, enum state_t set_state, int evt_type);
+
+#endif /* __DISPLAY_STATE_TRANSITION_H__ */
\ No newline at end of file