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)
%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
#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"
#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"
#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
#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"
#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"
+++ /dev/null
-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)
+++ /dev/null
-/*
- * 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);
-}
+++ /dev/null
-/*
- * 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__
#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"
#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
#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"
#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"
#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
#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"
#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"
{
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);
}
#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"
#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
#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"
#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"
return 0;
}
- FIND_DEVICE_INT(ops, POWER_OPS_NAME);
+ FIND_DEVICE_INT(ops, "power-state-manager");
return ops->execute(data);
}
#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"
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
#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
#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)
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();
}
_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);
}
* 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__ */
#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"
.nr_methods = ARRAY_SIZE(dbus_methods),
};
-void power_plugin_dbus_init(void *data)
+void power_dbus_init(void)
{
int retval;
#ifndef __POWER_DBUS_H__
#define __POWER_DBUS_H__
-void power_plugin_dbus_init(void *data);
+void power_dbus_init(void);
#endif //__POWER_DBUS_H__
*/
#include <vconf.h>
-#include "doze.h"
+#include "power-doze.h"
#include "core/log.h"
#include "shared/device-notifier.h"
#include "display/core.h"
* 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
#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 */
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) {
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) {
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;
}
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,
_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;
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)
GVariant *param, GDBusMethodInvocation *invocation, gpointer user_data)
{
int ret;
+ char comm[128] = "Unknown";
char *type_str;
g_variant_get(param, "(s)", &type_str);
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);
GVariant *param, GDBusMethodInvocation *invocation, gpointer user_data)
{
int ret;
+ char comm[128] = "Unknown";
char *type, *option;
g_variant_get(param, "(ss)", &type, &option);
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);
goto out;
pid = (pid_t)ret;
-
- CRITICAL_LOG("PID %d requested to a poweroff timer.", pid);
-
ret = poweroff_add_handle(pid);
out:
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;
return done;
}
-static void power_init(void *data)
+void power_off_init(void)
{
int ret_val;
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();
* 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"
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__ */
#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
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)
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)
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;
}
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;
}
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;
}
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;
}
static void deferred_transition_state(gpointer data)
{
transition_state(data);
+ free(data);
}
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;
}
{
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;
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)
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;
}
}
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;
}
#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"
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)
* 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"
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__ */
#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 {