power: move broadcast suspend/resume into power module 43/286243/2
authorYoungjae Cho <y0.cho@samsung.com>
Mon, 2 Jan 2023 10:58:27 +0000 (19:58 +0900)
committerChanwoo Choi <cw00.choi@samsung.com>
Tue, 3 Jan 2023 08:14:46 +0000 (08:14 +0000)
Change-Id: I3a9499947866716154dadc1a415578630c60ad7b
Signed-off-by: Youngjae Cho <y0.cho@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-signal.c
src/display/display-signal.h
src/power/power-suspend.c
src/shared/time.c [new file with mode: 0644]
src/shared/time.h [new file with mode: 0644]

index 6bd21d0..92dc4e3 100644 (file)
@@ -84,9 +84,6 @@
 #define PALM_STR               "palm"
 #define UNKNOWN_STR            "unknown"
 
-#define PM_WAKEUP              0
-#define PM_SUSPEND             1
-
 extern void init_pm_internal();
 extern void init_save_userlock(void);
 
@@ -722,7 +719,6 @@ void lcd_on_direct(enum device_flags flags)
 {
        if (pm_get_power_lock_support()
            && (get_pm_cur_state() == S_SLEEP)) {
-               broadcast_pm_wakeup();
                power_acquire_wakelock();
                set_pm_cur_state(S_NORMAL);
        }
@@ -1446,7 +1442,6 @@ static int default_action(int timeout)
 
        if ((get_pm_cur_state() != get_pm_old_state()) && (get_pm_cur_state() != S_SLEEP)) {
                if (pm_get_power_lock_support()) {
-                       broadcast_pm_wakeup();
                        power_acquire_wakelock();
                }
                set_setting_pmstate(get_pm_cur_state());
@@ -1531,7 +1526,6 @@ go_suspend:
 #ifdef ENABLE_PM_LOG
        pm_history_save(PM_LOG_SLEEP, get_pm_cur_state());
 #endif
-       broadcast_pm_suspend();
        if (pm_get_power_lock_support()) {
                power_enable_autosleep();
 
@@ -2185,7 +2179,6 @@ static void display_init(void *data)
                if (flags & WITHOUT_STARTNOTI) {        /* start without noti */
                        _I("Start Power managing without noti");
                        if (pm_get_power_lock_support()) {
-                               broadcast_pm_wakeup();
                                power_acquire_wakelock();
                        }
                        /*
index ddb7e58..25deced 100644 (file)
@@ -85,9 +85,6 @@
 #define PALM_STR               "palm"
 #define UNKNOWN_STR            "unknown"
 
-#define PM_WAKEUP              0
-#define PM_SUSPEND             1
-
 extern void init_pm_internal();
 extern void init_save_userlock(void);
 
@@ -729,7 +726,6 @@ void lcd_on_direct(enum device_flags flags)
 {
        if (pm_get_power_lock_support()
            && (get_pm_cur_state() == S_SLEEP)) {
-               broadcast_pm_wakeup();
                power_acquire_wakelock();
                set_pm_cur_state(S_NORMAL);
        }
@@ -1456,7 +1452,6 @@ static int default_action(int timeout)
 
        if ((get_pm_cur_state() != get_pm_old_state()) && (get_pm_cur_state() != S_SLEEP)) {
                if (pm_get_power_lock_support()) {
-                       broadcast_pm_wakeup();
                        power_acquire_wakelock();
                }
                set_setting_pmstate(get_pm_cur_state());
@@ -1541,7 +1536,6 @@ go_suspend:
 #ifdef ENABLE_PM_LOG
        pm_history_save(PM_LOG_SLEEP, get_pm_cur_state());
 #endif
-       broadcast_pm_suspend();
        if (pm_get_power_lock_support()) {
                power_enable_autosleep();
 
@@ -2191,7 +2185,6 @@ static void display_init(void *data)
                if (flags & WITHOUT_STARTNOTI) {        /* start without noti */
                        _I("Start Power managing without noti");
                        if (pm_get_power_lock_support()) {
-                               broadcast_pm_wakeup();
                                power_acquire_wakelock();
                        }
                        /*
index 3dc8fc8..333d3b3 100644 (file)
@@ -83,9 +83,6 @@
 #define PALM_STR               "palm"
 #define UNKNOWN_STR            "unknown"
 
-#define PM_WAKEUP              0
-#define PM_SUSPEND             1
-
 extern void init_pm_internal();
 extern void init_save_userlock(void);
 
@@ -722,7 +719,6 @@ void lcd_on_direct(enum device_flags flags)
 {
        if (pm_get_power_lock_support()
            && (get_pm_cur_state() == S_SLEEP)) {
-               broadcast_pm_wakeup();
                power_acquire_wakelock();
                set_pm_cur_state(S_NORMAL);
        }
@@ -1446,7 +1442,6 @@ static int default_action(int timeout)
 
        if ((get_pm_cur_state() != get_pm_old_state()) && (get_pm_cur_state() != S_SLEEP)) {
                if (pm_get_power_lock_support()) {
-                       broadcast_pm_wakeup();
                        power_acquire_wakelock();
                }
                set_setting_pmstate(get_pm_cur_state());
@@ -1531,7 +1526,6 @@ go_suspend:
 #ifdef ENABLE_PM_LOG
        pm_history_save(PM_LOG_SLEEP, get_pm_cur_state());
 #endif
-       broadcast_pm_suspend();
        if (pm_get_power_lock_support()) {
                power_enable_autosleep();
 
@@ -2182,7 +2176,6 @@ static void display_init(void *data)
                if (flags & WITHOUT_STARTNOTI) {        /* start without noti */
                        _I("Start Power managing without noti");
                        if (pm_get_power_lock_support()) {
-                               broadcast_pm_wakeup();
                                power_acquire_wakelock();
                        }
                        /*
index 56275ad..baa1784 100644 (file)
@@ -939,7 +939,6 @@ void lcd_on_direct(enum device_flags flags)
 
        if (pm_get_power_lock_support()
            && (get_pm_cur_state() == S_SLEEP)) {
-               broadcast_pm_wakeup();
                power_acquire_wakelock();
                set_pm_cur_state(S_NORMAL);
        }
@@ -1719,7 +1718,6 @@ static int default_action(int timeout)
 
        if ((get_pm_cur_state() != get_pm_old_state()) && (get_pm_cur_state() != S_SLEEP)) {
                if (pm_get_power_lock_support()) {
-                       broadcast_pm_wakeup();
                        power_acquire_wakelock();
                }
                set_setting_pmstate(get_pm_cur_state());
@@ -1807,7 +1805,6 @@ go_suspend:
 #ifdef ENABLE_PM_LOG
        pm_history_save(PM_LOG_SLEEP, get_pm_cur_state());
 #endif
-       broadcast_pm_suspend();
        if (pm_get_power_lock_support()) {
                power_enable_autosleep();
 
@@ -2512,7 +2509,6 @@ static void display_init(void *data)
                if (flags & WITHOUT_STARTNOTI) {        /* start without noti */
                        _I("Start Power managing without noti");
                        if (pm_get_power_lock_support()) {
-                               broadcast_pm_wakeup();
                                power_acquire_wakelock();
                        }
                        /*
index ddb02df..5a08c1b 100644 (file)
@@ -19,6 +19,7 @@
 #include "display-signal.h"
 #include "poll.h"
 #include "shared/plugin.h"
+#include "shared/time.h"
 
 #define ACTIVE_ACT "active"
 #define INACTIVE_ACT "inactive"
@@ -33,52 +34,8 @@ static const char *lcdoff_sig_lookup[SIGNAL_MAX] = {
 };
 
 static struct display_plugin *disp_plgn;
-static int pmstate_suspend = PM_SUSPEND;
 static long displayoff_time;
 
-void broadcast_pm_suspend(void)
-{
-       int ret;
-       long now;
-
-       if (pmstate_suspend)
-               return;
-
-       _D("PM will be changed to sleep.");
-
-       pmstate_suspend = PM_SUSPEND;
-       now = clock_gettime_to_long();
-       ret = gdbus_signal_emit(NULL,
-                                                       DEVICED_PATH_DISPLAY,
-                                                       DEVICED_INTERFACE_DISPLAY,
-                                                       "sleep",
-                                                       g_variant_new("(t)", (guint64)now));
-       if (ret < 0)
-               _E("Failed to send dbus signal sleep.");
-}
-
-void broadcast_pm_wakeup(void)
-{
-       int ret;
-       long now;
-
-       if (!pmstate_suspend)
-               return;
-
-        _D("PM is changed to wakeup.");
-
-        pmstate_suspend = PM_WAKEUP;
-        now = clock_gettime_to_long();
-        ret = gdbus_signal_emit(NULL,
-                                                        DEVICED_PATH_DISPLAY,
-                                                        DEVICED_INTERFACE_DISPLAY,
-                                                        "wakeup",
-                                                        g_variant_new("(t)", (guint64)now));
-        if (ret < 0)
-                _E("Failed to send dbus signal wakeup.");
-
-}
-
 void broadcast_lcd_on(enum signal_type type, enum device_flags flags)
 {
        const char *str;
index f0abbcc..8387352 100644 (file)
 #ifndef __DISPLAY_SIGNAL_H__
 #define __DISPLAY_SIGNAL_H__
 
-#include <time.h>
 #include <libsyscommon/libgdbus.h>
 
 #include "util.h"
 #include "shared/devices.h"
 #include "shared/device-notifier.h"
 
-static inline long clock_gettime_to_long(void)
-{
-       struct timespec now;
-       int ret;
-
-       ret = clock_gettime(CLOCK_REALTIME, &now);
-
-       if (ret < 0) {
-               _E("Failed to clock gettime!");
-               return 0;
-       }
-
-       return SEC_TO_MSEC(now.tv_sec) + NSEC_TO_MSEC(now.tv_nsec);
-}
-
-#define PM_WAKEUP              0
-#define PM_SUSPEND             1
-
 enum signal_type {
        SIGNAL_INVALID = 0,
        SIGNAL_PRE,
@@ -51,8 +32,6 @@ enum signal_type {
        SIGNAL_MAX,
 };
 
-void broadcast_pm_suspend(void);
-void broadcast_pm_wakeup(void);
 void broadcast_lcd_on(enum signal_type type, enum device_flags flags);
 void broadcast_lcd_off(enum signal_type type, enum device_flags flags);
 void broadcast_lcd_off_late(enum device_flags flags);
index c50bcfd..0888af4 100644 (file)
@@ -36,6 +36,7 @@
 #include "shared/devices.h"
 #include "shared/common.h"
 #include "shared/device-notifier.h"
+#include "shared/time.h"
 #include "vconf.h"
 #include "display/display-dpms.h"
 #include "display/display.h"
@@ -69,6 +70,49 @@ static const char history_string[PM_LOG_MAX][15] = {
 
 bool timeout_sleep_support = false;
 
+
+// Leave it for backward compatability. As the signal was implemented when distinction
+// between power and display is unclear, path and interface is related with display.
+// Since tizen 7.0, it is able to receive suspend/resume event using device power-internal API,
+// which is irrelevent with this signal.
+static void power_broadcast_suspend(void)
+{
+       int ret;
+       long now;
+
+       _D("PM will be changed to sleep.");
+
+       now = clock_gettime_to_long();
+       ret = gdbus_signal_emit(NULL,
+               DEVICED_PATH_DISPLAY,
+               DEVICED_INTERFACE_DISPLAY,
+               "sleep",
+               g_variant_new("(t)", (guint64)now));
+       if (ret < 0)
+               _E("Failed to send dbus signal sleep.");
+}
+
+// Leave it for backward compatability. As the signal was implemented when distinction
+// between power and display is unclear, path and interface is related with display.
+// Since tizen 7.0, it is able to receive suspend/resume event using device power-internal API,
+// which is irrelevent with this signal.
+static void power_broadcast_wakeup(void)
+{
+       int ret;
+       long now;
+
+        _D("PM is changed to wakeup.");
+
+        now = clock_gettime_to_long();
+        ret = gdbus_signal_emit(NULL,
+                DEVICED_PATH_DISPLAY,
+                DEVICED_INTERFACE_DISPLAY,
+                "wakeup",
+                g_variant_new("(t)", (guint64)now));
+        if (ret < 0)
+                _E("Failed to send dbus signal wakeup.");
+}
+
 void pm_history_init()
 {
        memset(pm_history_log, 0x0, sizeof(pm_history_log));
@@ -211,9 +255,11 @@ int pm_suspend(void)
 {
        int ret_val;
 
+       power_broadcast_suspend();
        _I("system suspend");
        ret_val = sys_set_str(POWER_STATE_PATH, "mem");
        _I("System resume: %d", ret_val);
+       power_broadcast_wakeup();
 
        ret_val = update_wakeup_reason();
        if (ret_val < 0) {
@@ -242,6 +288,8 @@ int power_acquire_wakelock(void)
        if (mainlock_status == POWER_LOCK)
                return 0;
 
+       power_broadcast_wakeup();
+
        _I("system power lock");
        suspend_other_process(VITAL_WAKEUP);
        mainlock_status = POWER_LOCK;
@@ -280,6 +328,8 @@ int power_release_wakelock(void)
        if (mainlock_status == POWER_UNLOCK)
                return 0;
 
+       power_broadcast_suspend();
+
        _I("system power unlock");
        suspend_other_process(VITAL_SLEEP);
        mainlock_status = POWER_UNLOCK;
diff --git a/src/shared/time.c b/src/shared/time.c
new file mode 100644 (file)
index 0000000..825491f
--- /dev/null
@@ -0,0 +1,20 @@
+#include <time.h>
+
+#include "log-macro.h"
+#include "common.h"
+
+long clock_gettime_to_long(void)
+{
+       struct timespec now;
+       int ret;
+
+       ret = clock_gettime(CLOCK_REALTIME, &now);
+
+       if (ret < 0) {
+               _E("Failed to clock gettime!");
+               return 0;
+       }
+
+       return SEC_TO_MSEC(now.tv_sec) + NSEC_TO_MSEC(now.tv_nsec);
+}
+
diff --git a/src/shared/time.h b/src/shared/time.h
new file mode 100644 (file)
index 0000000..85069a3
--- /dev/null
@@ -0,0 +1,6 @@
+#ifndef __DD_TIME_H__
+#define __DD_TIME_H__
+
+long clock_gettime_to_long(void);
+
+#endif //__DD_TIME_H__