From bc173211a1c057daa993ee26b105d9203843ed4c Mon Sep 17 00:00:00 2001 From: Youngjae Cho Date: Mon, 6 Feb 2023 17:21:06 +0900 Subject: [PATCH] power: add API for cancelling transition The cancelling API would trigger the opposite transition of the ongoing transition, for example, if the ongoing transition is from DEVICE_POWER_STATE_NORMAL to DEVICE_POWER_STATE_SLEEP, then transition from DEVICE_POWER_STATE_SLEEP to DEVICE_POWER_STATE_NORMAL will follow after calling cancelling API. Change-Id: Ife624cd61f28ee7a5ab46b0e5dc0c0089b0aa72a Signed-off-by: Youngjae Cho --- include/power-internal.h | 15 +++++++++++++++ src/power-internal.c | 39 +++++++++++++++++++++++++++++++++++++++ 2 files changed, 54 insertions(+) diff --git a/include/power-internal.h b/include/power-internal.h index 87612f3..fc051dc 100644 --- a/include/power-internal.h +++ b/include/power-internal.h @@ -123,6 +123,21 @@ typedef enum { int device_power_confirm_wait_callback(uint64_t wait_callback_id); /** + * @brief Notify the deviced that it needs undoing the current transition. + * @details Notify the deviced that the current transition should be rewinded. \n + * This function only works on the id received from device_power_state_wait_callback() and device_power_transient_state_wait_callback(). + * @since_tizen 7.0 + * @param[in] wait_callback_id Wait callback id to cancel + * @return 0 on success, + * otherwise a negative error value + * @retval #DEVICE_ERROR_NONE Successful + * @retval #DEVICE_ERROR_OPERATION_FAILED Operation failed + * @see device_power_state_wait_callback() + * @see device_power_transient_state_wait_callback() + */ +int device_power_cancel_wait_callback(uint64_t wait_callback_id); + +/** * @brief Called when a device power state is changed. * @details If both device_power_state_wait_callback() and device_power_change_state_callback() have registered to the same power state, \n * then the device_power_state_wait_callback() will be invoked first and the device_power_change_state_callback() will follow. diff --git a/src/power-internal.c b/src/power-internal.c index 95b545a..aca8ae0 100644 --- a/src/power-internal.c +++ b/src/power-internal.c @@ -331,6 +331,45 @@ int device_power_confirm_wait_callback(uint64_t wait_callback_id) return DEVICE_ERROR_NONE; } +int device_power_cancel_wait_callback(uint64_t wait_callback_id) +{ + GDBusConnection *connection; + GVariant *retgv; + GError *err = NULL; + int ret; + + connection = g_bus_get_sync(G_BUS_TYPE_SYSTEM, NULL, &err); + if (!connection) { + _E("Failed to get dbus connection, %s", err->message); + g_clear_error(&err); + return DEVICE_ERROR_OPERATION_FAILED; + } + + retgv = g_dbus_connection_call_sync(connection, + DEVICED_BUS_NAME, + DEVICED_PATH_POWER, + DEVICED_INTERFACE_POWER, + "CancelChangeStateWait", + g_variant_new("(t)", wait_callback_id), + NULL, + G_DBUS_CALL_FLAGS_NONE, + DBUS_METHOD_SYNC_CALL_TIMEOUT_MS, + NULL, + &err); + if (!retgv || err) { + _E("Failed to request ConfirmChangeStateWait, %s", err->message); + g_error_free(err); + return DEVICE_ERROR_OPERATION_FAILED; + } + + g_variant_get(retgv, "(i)", &ret); + g_variant_unref(retgv); + if (ret != 0) + return DEVICE_ERROR_OPERATION_FAILED; + + return DEVICE_ERROR_NONE; +} + static void __unregister_state_signal_callback(GDBusConnection *connection, int index) { if (state_signal_id[index] == 0) -- 2.7.4