From 4d0daf18b56643cfaeb81f7ca777135726340398 Mon Sep 17 00:00:00 2001 From: Youngjae Cho Date: Tue, 27 Dec 2022 17:25:51 +0900 Subject: [PATCH] devicectl: add suspend/resume command Usage: devicectl power suspend|resume reason(int) #) devicectl power suspend 12345 #) devicectl power resume 2000 The value reason can be an any integer and the devicectl doesn't test it is valid reason or not. Therefore some listeners of suspend/resume event might malfunction as they receive a wierd reason. Change-Id: I62c66e0a8034f9884fd006404991330902ecca21 Signed-off-by: Youngjae Cho --- src/power/power-dbus.c | 16 ++++++++++++++++ tools/devicectl/devicectl.c | 28 ++++++++++++++++++++++++++++ 2 files changed, 44 insertions(+) diff --git a/src/power/power-dbus.c b/src/power/power-dbus.c index 79bd067..09a1f4a 100644 --- a/src/power/power-dbus.c +++ b/src/power/power-dbus.c @@ -434,6 +434,21 @@ out: return g_variant_new("(i)", ret); } +// devicectl power suspend +// devicectl power resume +static GVariant *dbus_power_change_state_with_reason(GDBusConnection *conn, + const gchar *sender, const gchar *path, const gchar *iface, const gchar *name, + GVariant *param, GDBusMethodInvocation *invocation, gpointer user_data) +{ + uint64_t next; + int reason; + + g_variant_get(param, "(ti)", &next, &reason); + power_request_change_state(next, reason); + + return gdbus_new_g_variant_tuple(); +} + static GVariant *dbus_power_get_state(GDBusConnection *conn, const gchar *sender, const gchar *path, const gchar *iface, const gchar *name, GVariant *param, GDBusMethodInvocation *invocation, gpointer user_data) @@ -469,6 +484,7 @@ static const dbus_method_s dbus_methods[] = { { "RemoveChangeTransientStateWait", "t", NULL, dbus_power_remove_change_transient_state_wait }, { "ConfirmChangeStateWait", "t", "i", dbus_power_confirm_change_state_wait }, { "PowerChangeState", "t", "i", dbus_power_change_state }, + { "PowerChangeStateWithReason", "ti", NULL, dbus_power_change_state_with_reason }, { "PowerGetState", NULL, "t", dbus_power_get_state }, { "PowerGetWakeupReason", NULL, "i", dbus_power_get_wakeup_reason }, /* Add methods here */ diff --git a/tools/devicectl/devicectl.c b/tools/devicectl/devicectl.c index 66704fa..456cd42 100644 --- a/tools/devicectl/devicectl.c +++ b/tools/devicectl/devicectl.c @@ -24,6 +24,8 @@ #include #include #include "usb.h" +#include "power/power.h" + /* * devicectl [device] [action] @@ -413,6 +415,30 @@ out: return ret; } +static int power_suspend(char **args) +{ + gdbus_call_sync_with_reply(DEVICED_BUS_NAME, + DEVICED_PATH_POWER, + DEVICED_INTERFACE_POWER, + "PowerChangeStateWithReason", + g_variant_new("(ti)", DEVICED_POWER_STATE_SLEEP, atoi(args[3])), + NULL); + + return 0; +} + +static int power_resume(char **args) +{ + gdbus_call_sync_with_reply(DEVICED_BUS_NAME, + DEVICED_PATH_POWER, + DEVICED_INTERFACE_POWER, + "PowerChangeStateWithReason", + g_variant_new("(ti)", DEVICED_POWER_STATE_NORMAL, atoi(args[3])), + NULL); + + return 0; +} + static int power_off(char **args) { return power_operation(args, "poweroff"); @@ -442,6 +468,8 @@ static const struct action { { DEVICE_CORE, "devicelist", 3, device_list, "" }, { DEVICE_EXTCON, "enable", 4, enable_device, "[USB|HEADPHONE|HDMI|DOCK]" }, { DEVICE_EXTCON, "disable", 4, disable_device, "[USB|HEADPHONE|HDMI|DOCK]" }, + { DEVICE_POWER, "suspend", 4, power_suspend, "reason(int)" }, + { DEVICE_POWER, "resume", 4, power_resume, "reason(int)" }, { DEVICE_POWER, "off", 3, power_off, "" }, { DEVICE_POWER, "reboot", 3, power_reboot, "" }, }; -- 2.7.4