power: elevate iot-headless power plugin to core 09/274909/9
authorYoungjae Cho <y0.cho@samsung.com>
Thu, 12 May 2022 01:49:08 +0000 (10:49 +0900)
committerYoungjae Cho <y0.cho@samsung.com>
Thu, 12 May 2022 09:20:29 +0000 (18:20 +0900)
The power plugin, power-state-manager, has merged into core module
and now it administers the whole power module instead of existing
power-handler. The power-handler has renamed to power-off to match
up with its functionality.

Change-Id: I8c93162639d1793635e9b7620ecf4210c4dca23b
Signed-off-by: Youngjae Cho <y0.cho@samsung.com>
40 files changed:
CMakeLists.txt
packaging/deviced.spec
plugins/iot-headed/display/core.c
plugins/iot-headed/display/device-interface.c
plugins/iot-headed/display/key-filter.c
plugins/iot-headless/battery/battery-plugin.c
plugins/iot-headless/input/input-config.c
plugins/iot-headless/power/CMakeLists.txt [deleted file]
plugins/iot-headless/power/power-config-parse.c [deleted file]
plugins/iot-headless/power/power-config-parse.h [deleted file]
plugins/mobile/display/core.c
plugins/mobile/display/device-interface.c
plugins/mobile/display/key-filter.c
plugins/tv/display/core.c
plugins/tv/display/device-interface.c
plugins/tv/display/key-filter.c
plugins/tv/display/state-tv.c
plugins/wearable/display/core.c
plugins/wearable/display/device-interface.c
plugins/wearable/display/key-filter.c
src/battery/lowbat-handler.c
src/core/main.c
src/display/core.h
src/power/power-boot.c [moved from src/power/boot.c with 60% similarity]
src/power/power-boot.h [moved from src/power/boot.h with 82% similarity]
src/power/power-dbus.c [moved from plugins/iot-headless/power/power-dbus.c with 99% similarity]
src/power/power-dbus.h [moved from plugins/iot-headless/power/power-dbus.h with 94% similarity]
src/power/power-doze.c [moved from src/power/doze.c with 99% similarity]
src/power/power-doze.h [moved from src/power/doze.h with 92% similarity]
src/power/power-event-lock.c [moved from plugins/iot-headless/power/power-event-lock.c with 100% similarity]
src/power/power-event-lock.h [moved from plugins/iot-headless/power/power-event-lock.h with 100% similarity]
src/power/power-off.c [moved from src/power/power-handler.c with 94% similarity]
src/power/power-off.h [moved from src/power/power-handler.h with 88% similarity]
src/power/power-state-manager.c [moved from plugins/iot-headless/power/power-state-manager.c with 81% similarity]
src/power/power-state-manager.h [moved from plugins/iot-headless/power/power-state-manager.h with 100% similarity]
src/power/power-state-wait.c [moved from plugins/iot-headless/power/power-state-wait.c with 97% similarity]
src/power/power-state-wait.h [moved from plugins/iot-headless/power/power-state-wait.h with 100% similarity]
src/power/power-suspend.c [moved from src/power/power-control.c with 91% similarity]
src/power/power-suspend.h [moved from src/power/power-control.h with 93% similarity]
src/touchscreen/touchscreen.c

index 6143791..de82918 100644 (file)
@@ -337,7 +337,6 @@ ADD_SUBDIRECTORY(plugins/wearable/display)
 ADD_SUBDIRECTORY(plugins/tv/display)
 ADD_SUBDIRECTORY(plugins/iot-headed/display)
 ADD_SUBDIRECTORY(plugins/iot-headless/input)
-ADD_SUBDIRECTORY(plugins/iot-headless/power)
 ADD_SUBDIRECTORY(plugins/iot-headless/battery)
 IF(BATTERY_MODULE STREQUAL on)
        ADD_SUBDIRECTORY(plugins/mobile/battery)
index 378d02d..326d3fd 100644 (file)
@@ -393,7 +393,6 @@ mv %{_libdir}/iot-headless-battery.so %{_libdir}/deviced/battery.so
 %config %{_sysconfdir}/deviced/input-profile-iot-headless.conf
 %config %{_sysconfdir}/deviced/power-profile-iot-headless.conf
 %{_libdir}/iot-headless-input-handler.so
-%{_libdir}/iot-headless-power.so
 %{_libdir}/iot-headless-battery.so
 %{_unitdir}/rndis.service
 %{_bindir}/rndis.sh
index 12cad43..841818b 100644 (file)
 #include "apps/apps.h"
 #include "extcon/extcon.h"
 #include "battery/power-supply.h"
-#include "power/power-handler.h"
-#include "power/power-control.h"
-#include "power/boot.h"
-#include "power/doze.h"
+#include "power/power-off.h"
+#include "power/power-suspend.h"
+#include "power/power-boot.h"
+#include "power/power-doze.h"
 #include "display-dpms.h"
 #include "display-signal.h"
 #include "display-lock.h"
index 99dba58..bef99b0 100644 (file)
@@ -33,7 +33,7 @@
 #include <hal/device/hal-display.h>
 
 #include "ambient-mode.h"
-#include "power/power-control.h"
+#include "power/power-suspend.h"
 #include "core/log.h"
 #include "shared/devices.h"
 #include "shared/common.h"
index ec07875..5f0d544 100644 (file)
 #include "shared/device-notifier.h"
 #include "shared/common.h"
 #include "shared/plugin.h"
-#include "power/power-handler.h"
+#include "power/power-off.h"
+#include "power/power-suspend.h"
 #include "led/touch-key.h"
 #include "apps/apps.h"
 #include "display/display-lock.h"
-#include "power/power-control.h"
 
 #ifndef KEY_SCREENLOCK
 #define KEY_SCREENLOCK         0x98
index 717fada..2ae0b0b 100644 (file)
@@ -25,7 +25,7 @@
 #include "shared/log.h"
 #include "battery/battery-ops.h"
 
-#include "power-state-manager.h"
+#include "power/power-state-manager.h"
 
 #define BATTERY_CONF_PATH    "/etc/deviced/battery.conf"
 
index 4c7be93..ce97c19 100644 (file)
@@ -29,7 +29,7 @@
 #include "shared/log.h"
 
 #include "input-config.h"
-#include "power-state-manager.h"
+#include "power/power-state-manager.h"
 
 #define INPUT_CONF_PATH    "/etc/deviced/input.conf"
 
diff --git a/plugins/iot-headless/power/CMakeLists.txt b/plugins/iot-headless/power/CMakeLists.txt
deleted file mode 100644 (file)
index 2f9a962..0000000
+++ /dev/null
@@ -1,17 +0,0 @@
-CMAKE_MINIMUM_REQUIRED(VERSION 2.6)
-
-PROJECT(iot-headless-power C)
-
-INCLUDE(FindPkgConfig)
-PKG_CHECK_MODULES(REQUIRED_PKGS REQUIRED
-       glib-2.0
-       dlog
-       libsyscommon)
-
-INCLUDE_DIRECTORIES(${CMAKE_SOURCE_DIR}/src)
-
-FILE(GLOB SRCS "*.c")
-ADD_LIBRARY(${PROJECT_NAME} SHARED ${SRCS})
-SET_TARGET_PROPERTIES(${PROJECT_NAME} PROPERTIES PREFIX "")
-SET_TARGET_PROPERTIES(${PROJECT_NAME} PROPERTIES OUTPUT_NAME iot-headless-power)
-INSTALL(TARGETS ${PROJECT_NAME} DESTINATION ${LIB_INSTALL_DIR} COMPONENT RuntimeLibraries)
diff --git a/plugins/iot-headless/power/power-config-parse.c b/plugins/iot-headless/power/power-config-parse.c
deleted file mode 100644 (file)
index d846ebc..0000000
+++ /dev/null
@@ -1,91 +0,0 @@
-/*
- * deviced
- *
- * Copyright (c) 2022 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.
- */
-
-#include <libsyscommon/list.h>
-#include <libsyscommon/file.h>
-#include <libsyscommon/ini-parser.h>
-#include <hal/device/hal-board.h>
-
-#include "power-state-manager.h"
-
-#define INIT_CONF_PATH    "/etc/deviced/init.conf"
-
-static struct trans_info initial_transition_info = {
-       .reason = -1,
-       .curr = PSM_START,
-       .next = PSM_NORMAL,
-};
-
-static void parse_transition_info(const char *action)
-{
-       char curr[16] = { 0, };
-       char next[16] = { 0, };
-
-       if (sscanf(action, "%15[^,],%15s", curr, next) == 2) {
-               initial_transition_info.curr = convert_action_string_to_psm_state(curr);
-               initial_transition_info.next = convert_action_string_to_psm_state(next);
-       }
-}
-
-static void parse_initial_transition_info(const struct parse_result *result)
-{
-       GList *elem;
-       struct section_property *prop;
-
-       SYS_G_LIST_FOREACH(result->props, elem, prop) {
-               if (MATCH(prop->key, "Enum"))
-                       initial_transition_info.reason = atoi(prop->value);
-               else if (MATCH(prop->key, "Action"))
-                       parse_transition_info(prop->value);
-       }
-}
-
-static int parse_matching_bootreason(const struct parse_result *result, void *data)
-{
-       GList *elem;
-       struct section_property *prop;
-       char *bootreason = (char *) data;
-
-       if (!MATCH(result->section, "EventAction"))
-               return 0;
-
-       SYS_G_LIST_FOREACH(result->props, elem, prop) {
-               if (MATCH(prop->key, "BootReason") && MATCH(prop->value, bootreason))
-                       parse_initial_transition_info(result);
-       }
-
-       return 0;
-}
-
-void parse_initial_transition(void *data)
-{
-       int retval;
-       char bootreason[64] = "Unknown";
-       GList **head = (GList **) data;
-
-       if (!head)
-               return;
-
-       retval = hal_device_board_get_boot_reason(bootreason, sizeof(bootreason));
-       if (retval == 0)
-               libsys_config_parse_by_section(INIT_CONF_PATH, parse_matching_bootreason, bootreason);
-
-       CRITICAL_LOG("BootReason=%s", bootreason);
-
-       *head = g_list_append(*head, &initial_transition_info);
-}
diff --git a/plugins/iot-headless/power/power-config-parse.h b/plugins/iot-headless/power/power-config-parse.h
deleted file mode 100644 (file)
index a5844b4..0000000
+++ /dev/null
@@ -1,24 +0,0 @@
-/*
- * deviced
- *
- * Copyright (c) 2022 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.
- */
-
-#ifndef __POWER_CONFIG_PARSE_H__
-#define __POWER_CONFIG_PARSE_H__
-
-void parse_initial_transition(void *data);
-
-#endif //__POWER_CONFIG_PARSE_H__
index 0f12f68..918ae54 100644 (file)
 #include "apps/apps.h"
 #include "extcon/extcon.h"
 #include "battery/power-supply.h"
-#include "power/power-handler.h"
-#include "power/power-control.h"
-#include "power/boot.h"
-#include "power/doze.h"
+#include "power/power-off.h"
+#include "power/power-suspend.h"
+#include "power/power-boot.h"
+#include "power/power-doze.h"
 #include "display/display-dpms.h"
 #include "proximity.h"
 #include "display-info.h"
index c66f5bd..28d4f1c 100644 (file)
@@ -44,8 +44,8 @@
 #include "display/display-dpms.h"
 #include "display/display.h"
 #include "display/display-lock.h"
-#include "power/boot.h"
-#include "power/power-control.h"
+#include "power/power-boot.h"
+#include "power/power-suspend.h"
 
 #define TOUCH_ON       1
 #define TOUCH_OFF      0
index c4d5b0a..c596cc1 100644 (file)
@@ -38,8 +38,8 @@
 #include "shared/device-notifier.h"
 #include "shared/common.h"
 #include "shared/plugin.h"
-#include "power/power-handler.h"
-#include "power/power-control.h"
+#include "power/power-off.h"
+#include "power/power-suspend.h"
 #include "led/touch-key.h"
 #include "apps/apps.h"
 #include "display/display-lock.h"
index 8dcdbea..61f435a 100644 (file)
 #include "apps/apps.h"
 #include "extcon/extcon.h"
 #include "battery/power-supply.h"
-#include "power/power-handler.h"
-#include "power/power-control.h"
-#include "power/boot.h"
-#include "power/doze.h"
+#include "power/power-off.h"
+#include "power/power-suspend.h"
+#include "power/power-boot.h"
+#include "power/power-doze.h"
 #include "display-dpms.h"
 #include "display-signal.h"
 #include "display-lock.h"
index a67f924..d377ac8 100644 (file)
@@ -43,7 +43,7 @@
 #include "core.h"
 #include "display/display-dpms.h"
 #include "display/display.h"
-#include "power/power-control.h"
+#include "power/power-suspend.h"
 #include "display/display-lock.h"
 
 #define TOUCH_ON       1
index 7f78ef0..dc2c2bd 100644 (file)
@@ -38,8 +38,8 @@
 #include "shared/device-notifier.h"
 #include "shared/common.h"
 #include "shared/plugin.h"
-#include "power/power-handler.h"
-#include "power/power-control.h"
+#include "power/power-off.h"
+#include "power/power-suspend.h"
 #include "led/touch-key.h"
 #include "apps/apps.h"
 #include "display/display-lock.h"
index fc6fb5b..2237011 100644 (file)
@@ -26,8 +26,8 @@
 #include "shared/devices.h"
 #include "display/display-ops.h"
 #include "display/display-lock.h"
-#include "power/power-handler.h"
-#include "power/power-control.h"
+#include "power/power-off.h"
+#include "power/power-suspend.h"
 #include "core.h"
 #include "poll.h"
 #include "device-interface.h"
@@ -492,7 +492,7 @@ static int poweroff_action(int timeout)
 {
        static const struct device_ops *ops;
 
-       FIND_DEVICE_INT(ops, POWER_OPS_NAME);
+       FIND_DEVICE_INT(ops, "power-state-manager");
 
        return ops->execute(POWER_POWEROFF);
 }
index 8dd7d48..ff2c6e0 100644 (file)
 #include "apps/apps.h"
 #include "extcon/extcon.h"
 #include "battery/power-supply.h"
-#include "power/power-handler.h"
-#include "power/power-control.h"
-#include "power/boot.h"
-#include "power/doze.h"
+#include "power/power-off.h"
+#include "power/power-suspend.h"
+#include "power/power-boot.h"
+#include "power/power-doze.h"
 #include "display/display-dpms.h"
 #include "display-info.h"
 #include "battery-monitor.h"
index 6f4d30f..8ff62de 100644 (file)
@@ -46,7 +46,7 @@
 #include "display/display-lock.h"
 #include "battery-monitor.h"
 #include "battery/power-supply.h"
-#include "power/power-control.h"
+#include "power/power-suspend.h"
 #include "shared/plugin.h"
 
 #define TOUCH_ON       1
index bb89700..68e774f 100644 (file)
@@ -38,8 +38,8 @@
 #include "shared/device-notifier.h"
 #include "shared/common.h"
 #include "shared/plugin.h"
-#include "power/power-handler.h"
-#include "power/power-control.h"
+#include "power/power-off.h"
+#include "power/power-suspend.h"
 #include "led/touch-key.h"
 #include "apps/apps.h"
 #include "display/display-lock.h"
index 7358f40..44b7fd3 100644 (file)
@@ -42,7 +42,7 @@
 #include "display/setting.h"
 #include "display/poll.h"
 #include "display/display-ops.h"
-#include "power/power-handler.h"
+#include "power/power-off.h"
 #include "apps/apps.h"
 #include "power-supply.h"
 
@@ -158,7 +158,7 @@ static int power_execute(void *data)
                return 0;
        }
 
-       FIND_DEVICE_INT(ops, POWER_OPS_NAME);
+       FIND_DEVICE_INT(ops, "power-state-manager");
 
        return ops->execute(data);
 }
index ecbf942..88a36e4 100644 (file)
@@ -31,8 +31,8 @@
 #include "log.h"
 #include "shared/common.h"
 #include "shared/devices.h"
-#include "power/boot.h"
-#include "power/power-handler.h"
+#include "power/power-boot.h"
+#include "power/power-off.h"
 #include "shared/plugin.h"
 #include "shared/device-notifier.h"
 #include "core/devices.h"
@@ -105,7 +105,7 @@ static int deviced_main(int argc, char **argv)
        CRITICAL_LOG("Initializing deviced.");
        mainloop = g_main_loop_new(NULL, FALSE);
 
-       ret = check_power_flag();
+       ret = poweroff_check_revived();
        if (ret) {
                /* Restarted: deviced was terminated
                 * in middle of reboot/poweroff - resume procedure
index c8062ac..94dab95 100644 (file)
@@ -53,7 +53,7 @@
 #define CHECK_OPS(d, op) (d != NULL && d->op != NULL)
 
 #ifdef ENABLE_PM_LOG
-#include "power/power-control.h"
+#include "power/power-suspend.h"
 #define MAX_LOG_COUNT 250
 #endif
 
similarity index 60%
rename from src/power/boot.c
rename to src/power/power-boot.c
index a819fed..634dd69 100644 (file)
 #include <eventsystem.h>
 #include <libsyscommon/libgdbus.h>
 #include <libsyscommon/libsystemd.h>
+#include <libsyscommon/list.h>
+#include <libsyscommon/file.h>
+#include <libsyscommon/ini-parser.h>
+#include <hal/device/hal-board.h>
 
 #include "core/log.h"
 #include "shared/device-notifier.h"
 #include "display/poll.h"
 #include "display/display-ops.h"
 #include "shared/plugin.h"
-#include "doze.h"
+#include "power-doze.h"
+#include "power-state-manager.h"
 
 #define SYSTEMD_DBUS_SIGNAL_SYSTEM_STARTUP_FINISHED     "StartupFinished"
 #define SYSTEMD_DBUS_SIGNAL_USER_STARTUP_FINISHED       "UserSessionStartupFinished"
 
-static struct display_plugin *disp_plgn;
+#define INIT_CONF_PATH    "/etc/deviced/init.conf"
+
+static struct trans_info initial_transition_info = {
+       .reason = -1,
+       .curr = PSM_START,
+       .next = PSM_NORMAL,
+};
+
 static guint sig_id[2] = {0, 0};
 
 void remove_delayed_init_done_handler(void *data)
@@ -78,12 +90,6 @@ static void delayed_init_done_received(GDBusConnection  *conn,
 
        remove_delayed_init_done_handler(NULL);
 
-       _I("Real booting done. Unlock LCD_OFF.");
-       if (disp_plgn->pm_unlock_internal)
-               disp_plgn->pm_unlock_internal(INTERNAL_LOCK_BOOTING, LCD_OFF, PM_SLEEP_MARGIN);
-
-       _I("Signal booting done.");
-
        doze_init();
 }
 
@@ -113,9 +119,62 @@ void add_delayed_init_done_handler(void *data)
                _E("Failed to init dbus signal(%s).", SYSTEMD_DBUS_SIGNAL_USER_STARTUP_FINISHED);
 }
 
-static void __CONSTRUCTOR__ initialize(void)
+static void parse_transition_info(const char *action)
+{
+       char curr[16] = { 0, };
+       char next[16] = { 0, };
+
+       if (sscanf(action, "%15[^,],%15s", curr, next) == 2) {
+               initial_transition_info.curr = convert_action_string_to_psm_state(curr);
+               initial_transition_info.next = convert_action_string_to_psm_state(next);
+       }
+}
+
+static void parse_initial_transition_info(const struct parse_result *result)
+{
+       GList *elem;
+       struct section_property *prop;
+
+       SYS_G_LIST_FOREACH(result->props, elem, prop) {
+               if (MATCH(prop->key, "Enum"))
+                       initial_transition_info.reason = atoi(prop->value);
+               else if (MATCH(prop->key, "Action"))
+                       parse_transition_info(prop->value);
+       }
+}
+
+static int parse_matching_bootreason(const struct parse_result *result, void *data)
 {
-       disp_plgn = get_var_display_plugin();
-       if (!disp_plgn)
-               _E("Failed to get display plugin variable.");
+       GList *elem;
+       struct section_property *prop;
+       char *bootreason = (char *) data;
+
+       if (!MATCH(result->section, "EventAction"))
+               return 0;
+
+       SYS_G_LIST_FOREACH(result->props, elem, prop) {
+               if (MATCH(prop->key, "BootReason") && MATCH(prop->value, bootreason))
+                       parse_initial_transition_info(result);
+       }
+
+       return 0;
+}
+
+/* the initial transition by bootreason is defined in init.conf */
+void get_initial_transition_by_bootreason(void *data)
+{
+       int retval;
+       char bootreason[64] = "Unknown";
+       GList **head = (GList **) data;
+
+       if (!head)
+               return;
+
+       retval = hal_device_board_get_boot_reason(bootreason, sizeof(bootreason));
+       if (retval == 0)
+               libsys_config_parse_by_section(INIT_CONF_PATH, parse_matching_bootreason, bootreason);
+
+       CRITICAL_LOG("BootReason=%s", bootreason);
+
+       *head = g_list_append(*head, &initial_transition_info);
 }
similarity index 82%
rename from src/power/boot.h
rename to src/power/power-boot.h
index a5d5b7f..7c339e0 100644 (file)
  * limitations under the License.
  */
 
-#ifndef __DEVICED_BOOT_H__
-#define __DEVICED_BOOT_H__
+#ifndef __DEVICED_POWER_BOOT_H__
+#define __DEVICED_POWER_BOOT_H__
 
 void add_delayed_init_done_handler(void *data);
 void remove_delayed_init_done_handler(void *data);
+void get_initial_transition_by_bootreason(void *data);
 
 extern int silent_boot;
 
-#endif /* __DEVICED_BOOT_H__ */
+#endif /* __DEVICED_POWER_BOOT_H__ */
similarity index 99%
rename from plugins/iot-headless/power/power-dbus.c
rename to src/power/power-dbus.c
index 0cbc34f..e6ec1e9 100644 (file)
@@ -30,7 +30,7 @@
 #include "shared/log.h"
 #include "shared/device-notifier.h"
 
-#include "power/power-control.h"
+#include "power-suspend.h"
 #include "power-state-manager.h"
 #include "power-state-wait.h"
 
@@ -303,7 +303,7 @@ static const dbus_interface_u dbus_interface = {
        .nr_methods = ARRAY_SIZE(dbus_methods),
 };
 
-void power_plugin_dbus_init(void *data)
+void power_dbus_init(void)
 {
        int retval;
 
similarity index 94%
rename from plugins/iot-headless/power/power-dbus.h
rename to src/power/power-dbus.h
index a3fde6d..4e34361 100644 (file)
@@ -19,6 +19,6 @@
 #ifndef __POWER_DBUS_H__
 #define __POWER_DBUS_H__
 
-void power_plugin_dbus_init(void *data);
+void power_dbus_init(void);
 
 #endif //__POWER_DBUS_H__
similarity index 99%
rename from src/power/doze.c
rename to src/power/power-doze.c
index 572db6b..6679381 100644 (file)
@@ -17,7 +17,7 @@
  */
 #include <vconf.h>
 
-#include "doze.h"
+#include "power-doze.h"
 #include "core/log.h"
 #include "shared/device-notifier.h"
 #include "display/core.h"
similarity index 92%
rename from src/power/doze.h
rename to src/power/power-doze.h
index e6236e9..734f49b 100644 (file)
@@ -16,8 +16,8 @@
  * limitations under the License.
  */
 
-#ifndef __DOZE_H__
-#define __DOZE_H__
+#ifndef __DEVICED_POWER_DOZE_H__
+#define __DEVICED_POWER_DOZE_H__
 
 /* To request pmqos start and stop for Doze */
 #define DOZE_PMQOS_START       1
similarity index 94%
rename from src/power/power-handler.c
rename to src/power/power-off.c
index 7464068..08bbc3d 100644 (file)
@@ -46,9 +46,9 @@
 #include "display/setting.h"
 #include "display/core.h"
 #include "display/display-ops.h"
-#include "power-handler.h"
+#include "power-off.h"
 #include "apps/apps.h"
-#include "boot.h"
+#include "power-boot.h"
 #include "shared/plugin.h"
 
 #define POWEROFF_WAIT_RESOURCED     (0.5*1000) /* 0.5 seconds */
@@ -266,7 +266,7 @@ void poweroff_prepare(void)
        device_notify(DEVICE_NOTIFIER_POWEROFF, &off);
 }
 
-int check_power_flag(void)
+int poweroff_check_revived(void)
 {
        for (int i = 0; i < ARRAY_SIZE(poweroff_type_flagpaths); i++) {
                if (access(poweroff_type_flagpaths[i], F_OK) == 0) {
@@ -319,7 +319,7 @@ static void poweroff_remove_handle(pid_t pid)
 
        assert(handle);
 
-       _D("Remove handle pid=%d timeout=%d timeout_id=%d.", handle->pid, handle->timeout, handle->timeout_id);
+       _D("Remove handle pid=%d(%s) timeout=%d timeout_id=%d.", handle->pid, handle->comm, handle->timeout, handle->timeout_id);
        SYS_G_LIST_REMOVE(poweroff_handles, handle);
 
        if (handle->timeout_id) {
@@ -354,9 +354,10 @@ static int poweroff_add_handle(pid_t pid)
        handle->pid = pid;
        handle->timeout_id = 0;
        handle->timeout = POWEROFF_WAIT_MAX;
+       get_command(pid, handle->comm, sizeof(handle->comm));
 
        SYS_G_LIST_APPEND(poweroff_handles, handle);
-       _D("Add a new poweroff timer. pid=%d timeout=%d timeout_id=%d)", handle->pid, handle->timeout, handle->timeout_id);
+       _D("Add a new poweroff timer. pid=%d(%s) timeout=%d", handle->pid, handle->comm, handle->timeout);
 
        return 0;
 }
@@ -404,11 +405,11 @@ static gboolean poweroff_start_timers(void *data)
        SYS_G_LIST_FOREACH(poweroff_handles, l, handle) {
                pid_alive = kill(handle->pid, 0);
                if (pid_alive == -1) {
-                       _D("Pid(%d) is dead.", handle->pid);
+                       _D("Pid=%d(%s) is dead.", handle->pid, handle->comm);
                        handle->timeout = 0;
                }
 
-               _D("Run timer, pid=%d timeout=%d timeout_id=%d.", handle->pid, handle->timeout, handle->timeout_id);
+               _D("Run timer, pid=%d(%s) timeout=%d timeout_id=%d.", handle->pid, handle->comm, handle->timeout, handle->timeout_id);
 
                handle->timeout_id = g_timeout_add_seconds(handle->timeout,
                                poweroff_wait_timeout_cb,
@@ -505,7 +506,7 @@ static void poweroff_send_broadcast(int status)
                _E("Failed to send dbus signal(%s)", SIGNAL_POWEROFF_STATE);
 }
 
-static int power_execute_pid(const char *typename, const char *option)
+static int __poweroff_trigger_poweroff(const char *typename, const char *option)
 {
        int ret_val;
 
@@ -555,9 +556,9 @@ static int power_execute_pid(const char *typename, const char *option)
        return 0;
 }
 
-static int power_execute(void *data)
+int poweroff_trigger_poweroff(void *data)
 {
-       return power_execute_pid((char *)data, NULL);
+       return __poweroff_trigger_poweroff((char *)data, NULL);
 }
 
 static int check_sender_process(GDBusConnection *conn, const char *sender)
@@ -583,6 +584,7 @@ static GVariant *dbus_power_handler(GDBusConnection *conn,
        GVariant *param, GDBusMethodInvocation *invocation, gpointer user_data)
 {
        int ret;
+       char comm[128] = "Unknown";
        char *type_str;
 
        g_variant_get(param, "(s)", &type_str);
@@ -591,9 +593,10 @@ static GVariant *dbus_power_handler(GDBusConnection *conn,
        if (ret < 0)
                goto out;
 
+       get_command(ret, comm, sizeof(comm));
 
-       CRITICAL_LOG("Poweroff PID(%d) requests %s.", ret, type_str);
-       ret = power_execute_pid(type_str, NULL);
+       CRITICAL_LOG("Poweroff pid=%d(%s) requests %s.", ret, comm, type_str);
+       ret = __poweroff_trigger_poweroff(type_str, NULL);
 
 out:
        g_free(type_str);
@@ -605,6 +608,7 @@ static GVariant *dbus_power_option_handler(GDBusConnection *conn,
        GVariant *param, GDBusMethodInvocation *invocation, gpointer user_data)
 {
        int ret;
+       char comm[128] = "Unknown";
        char *type, *option;
 
        g_variant_get(param, "(ss)", &type, &option);
@@ -613,9 +617,10 @@ static GVariant *dbus_power_option_handler(GDBusConnection *conn,
        if (ret < 0)
                goto out;
 
+       get_command(ret, comm, sizeof(comm));
 
-       CRITICAL_LOG("Poweroff PID(%d) requests type=%s option=%s.", ret, type, option);
-       ret = power_execute_pid(type, option);
+       CRITICAL_LOG("Poweroff pid=%d(%s) requests type=%s option=%s.", ret, comm, type, option);
+       ret = __poweroff_trigger_poweroff(type, option);
 
 out:
        g_free(type);
@@ -642,9 +647,6 @@ static GVariant *add_poweroff_time(GDBusConnection *conn,
                goto out;
 
        pid = (pid_t)ret;
-
-       CRITICAL_LOG("PID %d requested to a poweroff timer.", pid);
-
        ret = poweroff_add_handle(pid);
 
 out:
@@ -666,8 +668,6 @@ static GVariant *remove_poweroff_time(GDBusConnection *conn,
 
        pid = (pid_t)ret;
 
-       CRITICAL_LOG("PID %d requested to remove poweroff timer.", pid);
-
        SYS_G_LIST_FOREACH(poweroff_handles, l, handle) {
                if (handle->pid == pid)
                        break;
@@ -771,7 +771,7 @@ out:
        return done;
 }
 
-static void power_init(void *data)
+void power_off_init(void)
 {
        int ret_val;
 
@@ -795,14 +795,6 @@ static void power_init(void *data)
        poweroff_stage = POWEROFF_DEFAULT;
 }
 
-static const struct device_ops power_device_ops = {
-       DECLARE_NAME_LEN(POWER_OPS_NAME),
-       .init     = power_init,
-       .execute  = power_execute,
-};
-
-DEVICE_OPS_REGISTER(&power_device_ops)
-
 static void __CONSTRUCTOR__ initialize(void)
 {
        disp_plgn = get_var_display_plugin();
similarity index 88%
rename from src/power/power-handler.h
rename to src/power/power-off.h
index 8c7e16b..be605fa 100644 (file)
  * limitations under the License.
  */
 
-#ifndef __POWER_HANDLE_H__
-#define __POWER_HANDLE_H__
+#ifndef __DEVICED_POWER_OFF_H__
+#define __DEVICED_POWER_OFF_H__
 
 #include <sys/types.h>
 
-#define POWER_OPS_NAME      "power"
-
 #define POWER_POWEROFF      "poweroff"
 #define POWER_REBOOT        "reboot"
 #define POWER_OFF_POPUP     "pwroff-popup"
@@ -55,13 +53,16 @@ struct power_option {
 struct poweroff_handle {
        pid_t pid;
        int timeout;
+       char comm[128];
        guint timeout_id;
 };
 
-int check_power_flag(void);
+void power_off_init(void);
+
+int poweroff_trigger_poweroff(void *data);
+int poweroff_check_revived(void);
 void poweroff_request_shutdown(void);
 int poweroff_add_wait(pid_t pid);
 void poweroff_remove_wait(pid_t pid);
 
-
-#endif /* __POWER_HANDLE_H__ */
+#endif /* __DEVICED_POWER_OFF_H__ */
similarity index 81%
rename from plugins/iot-headless/power/power-state-manager.c
rename to src/power/power-state-manager.c
index 3bf6d42..52c622c 100644 (file)
 #include "shared/devices.h"
 #include "shared/device-notifier.h"
 #include "shared/log.h"
-#include "power/power-control.h"
 #include "power-state-manager.h"
+#include "power-suspend.h"
 #include "power-dbus.h"
+#include "power-boot.h"
+#include "power-off.h"
 #include "power-state-wait.h"
 #include "power-event-lock.h"
-#include "power-config-parse.h"
 
 #define EVENT_TYPE_SLEEP    0
 #define EVENT_TYPE_WAKEUP   1
@@ -48,7 +49,7 @@ static int delayed_init_done = 0;
 static guint64 state_transition_counter = 0;
 static enum psm_state current = PSM_START;
 
-/* hold trans_info until booting done */
+/* hold trans_info until delayed_init_done */
 static GList *deferred_transition_list;
 
 static void psm_wake_unlock(void)
@@ -64,16 +65,7 @@ static void psm_wake_unlock(void)
 
 static void psm_trigger_poweroff(void)
 {
-       const struct device_ops *power_device;
-
-       power_device = find_device("power");
-       if (check_default(power_device))
-               return;
-
-       if (power_device->execute) {
-               power_disable_autosleep();
-               power_device->execute("poweroff");
-       }
+       poweroff_trigger_poweroff("poweroff");
 }
 
 static void broadcast_transition_info(const struct trans_info *ti)
@@ -118,7 +110,7 @@ static void psm_transition_start_to_sleep(const struct trans_info *ti)
        broadcast_transition_info(ti);
        waiting = update_change_state_wait(state_transition_counter, ti, psm_wake_unlock);
        if (waiting > 0) {
-               _D("Defer wake unlock");
+               _D("Defer wake unlock.");
                return;
        }
 
@@ -140,7 +132,7 @@ static void psm_transition_normal_to_sleep(const struct trans_info *ti)
        broadcast_transition_info(ti);
        waiting = update_change_state_wait(state_transition_counter, ti, psm_wake_unlock);
        if (waiting > 0) {
-               _D("Defer wake unlock");
+               _D("Defer wake unlock.");
                return;
        }
 
@@ -164,7 +156,7 @@ static void psm_transition_sleep_to_sleep(const struct trans_info *ti)
        broadcast_transition_info(ti);
        waiting = update_change_state_wait(state_transition_counter, ti, psm_wake_unlock);
        if (waiting > 0) {
-               _D("Defer wake unlock");
+               _D("Defer wake unlock.");
                return;
        }
 
@@ -180,7 +172,7 @@ static void psm_transition_normal_to_poweroff(const struct trans_info *ti)
        broadcast_transition_info(ti);
        waiting = update_change_state_wait(state_transition_counter, ti, psm_trigger_poweroff);
        if (waiting > 0) {
-               _D("Defer poweroff");
+               _D("Defer poweroff.");
                return;
        }
 
@@ -221,6 +213,7 @@ static void transition_state(const struct trans_info *ti)
 static void deferred_transition_state(gpointer data)
 {
        transition_state(data);
+       free(data);
 }
 
 static int psm_transition_state_cb(void *data)
@@ -242,20 +235,22 @@ static int psm_transition_state_cb(void *data)
        if (!ti)
                return 0;
 
-       /* defer state transition until booting done */
+       /* defer state transition until delayed_init_done */
        if (!delayed_init_done) {
                struct trans_info *deferred_ti = calloc(1, sizeof(struct trans_info));
                if (!deferred_ti) {
-                       CRITICAL_LOG("Failed to defer transition");
+                       CRITICAL_LOG("Failed to defer transition.");
                        return 0;
                }
 
-               // mocking state transition
+               // Pseudo state transition.
                current = ti->next;
 
+               // Reserve the trans_info.
+               // Those are used on receiving delayed_init_done for real transitioning state.
                memcpy(deferred_ti, ti, sizeof(struct trans_info));
                deferred_transition_list = g_list_append(deferred_transition_list, deferred_ti);
-               _D("Defer state transition %s->%s until booting done", psm_name[ti->curr], psm_name[ti->next]);
+               _D("Defer state transition %s->%s until delayed init done.", psm_name[ti->curr], psm_name[ti->next]);
 
                return 0;
        }
@@ -269,15 +264,15 @@ static int delayed_init_cb(void *data)
 {
        delayed_init_done = 1;
 
-       _D("Start deferred state transition");
+       _D("Start deferred state transition.");
+
         /* rewind current state to initial state and do the deferred transition */
        current = PSM_START;
-       g_list_free_full(deferred_transition_list, deferred_transition_state);
-       deferred_transition_list = NULL;
-       _D("Finished deferred state transition");
+       g_list_free_full(g_steal_pointer(&deferred_transition_list), deferred_transition_state);
 
-       /* Deferred autosleep enable,
-        * This prevents system go suspend during booting */
+       /* Enable autosleep at this point.
+        * This prevents system go suspend(autosleep) before booting done */
+       _D("Finished deferred state transition. Enable autosleep.");
        power_enable_autosleep();
 
        return 0;
@@ -290,20 +285,27 @@ void power_state_manager_init(void *data)
        register_notifier(DEVICE_NOTIFIER_DELAYED_INIT, delayed_init_cb);
        register_notifier(DEVICE_NOTIFIER_REQUEST_TRANSITION_STATE, psm_transition_state_cb);
 
-       power_plugin_dbus_init(NULL);
+       power_dbus_init();
+       power_off_init();
+       power_suspend_init();
        power_event_lock_init();
        power_state_wait_init();
 
-       /* initialize the power state */
-       parse_initial_transition(&initial_ti);
+       /* Take the first transition from PSM_START.
+        * It is determined by bootreason to which state to transition, PSM_NORMAL or PSM_SLEEP. */
+       get_initial_transition_by_bootreason(&initial_ti);
        psm_transition_state_cb(initial_ti);
        g_list_free(initial_ti);
 }
 
 static const struct device_ops power_state_manager_device_ops = {
-       DECLARE_NAME_LEN("power-control-plugin"),
+       DECLARE_NAME_LEN("power-state-manager"),
        .init              = power_state_manager_init,
-       .disable_auto_init = true, /* initialized by core power module */
+       /* It should be initilalized earlier than the almost other modules so that
+        * it can receive and handle power request from the other modules. Therefore
+        * give a high enough priority. */
+       .priority          = 990,
+       .execute           = poweroff_trigger_poweroff,
 };
 
 DEVICE_OPS_REGISTER(&power_state_manager_device_ops)
similarity index 97%
rename from plugins/iot-headless/power/power-state-wait.c
rename to src/power/power-state-wait.c
index 93868e4..44b6ffb 100644 (file)
@@ -104,11 +104,10 @@ int add_change_state_wait(pid_t pid, guint64 state)
        struct proc_info *pi;
        GList *elem;
 
-       _D("pid=%d added csw for %#"PRIx64, pid, state);
-
        SYS_G_LIST_FOREACH(proc_list, elem, pi) {
                if (pi->pid == pid) {
                        pi->state_bitmap |= state;
+                       _D("pid=%d(%s) updated csw for %#"PRIx64, pid, pi->comm, state);
                        return 0;
                }
        }
@@ -122,6 +121,8 @@ int add_change_state_wait(pid_t pid, guint64 state)
        get_command(pid, pi->comm, sizeof(pi->comm));
        SYS_G_LIST_APPEND(proc_list, pi);
 
+       _D("pid=%d(%s) added csw for %#"PRIx64, pid, pi->comm, state);
+
        return 0;
 }
 
similarity index 91%
rename from src/power/power-control.c
rename to src/power/power-suspend.c
index e4dbb1e..f7cf357 100644 (file)
@@ -40,8 +40,8 @@
 #include "vconf.h"
 #include "display/display-dpms.h"
 #include "display/display.h"
-#include "power/boot.h"
-#include "power-control.h"
+#include "power-boot.h"
+#include "power-suspend.h"
 
 #define POWER_CONF_FILE             "/etc/deviced/power.conf"
 
@@ -322,29 +322,11 @@ static int load_sleep_config(struct parse_result *result, void *user_data)
        return 0;
 }
 
-static void power_control_init(void *data)
+void power_suspend_init(void)
 {
-       const struct device_ops *plugin_device_ops;
        int retval;
 
        retval = config_parse(POWER_CONF_FILE, load_sleep_config, NULL);
        if (retval < 0)
                _E("Failed to load sleep config: %d", retval);
-
-
-       plugin_device_ops = find_device("power-control-plugin");
-       if (check_default(plugin_device_ops))
-               return;
-
-       _D("[%s] Initialization.", plugin_device_ops->name);
-       if (plugin_device_ops->init)
-               plugin_device_ops->init(NULL);
 }
-
-static const struct device_ops power_control_device_ops = {
-       DECLARE_NAME_LEN("power-control"),
-       .init     = power_control_init,
-       .priority = 900, /* power-control should be initialized asap */
-};
-
-DEVICE_OPS_REGISTER(&power_control_device_ops)
similarity index 93%
rename from src/power/power-control.h
rename to src/power/power-suspend.h
index ead8e98..a14b9d0 100644 (file)
@@ -16,8 +16,8 @@
  * limitations under the License.
  */
 
-#ifndef __POWER_CONTROL_H__
-#define __POWER_CONTROL_H__
+#ifndef __DEVICED_POWER_SUSPEND_H__
+#define __DEVICED_POWER_SUSPEND_H__
 
 #include "display/core.h"
 
@@ -85,4 +85,5 @@ int check_wakeup_src(void);
 int get_wakeup_count(int *cnt);
 int set_wakeup_count(int cnt);
 int suspend_other_process(int type);
-#endif /* __POWER_CONTROL_H__ */
+void power_suspend_init(void);
+#endif /* __DEVICED_POWER_SUSPEND_H__ */
index c642203..183a407 100644 (file)
@@ -29,7 +29,7 @@
 #include "battery/power-supply.h"
 #include "display/core.h"
 #include "display/display-ops.h"
-#include "power/boot.h"
+#include "power/power-boot.h"
 #include "shared/plugin.h"
 
 enum ps_mode {