power: add API for cancelling transition 94/287794/1
authorYoungjae Cho <y0.cho@samsung.com>
Mon, 6 Feb 2023 08:21:06 +0000 (17:21 +0900)
committerYoungjae Cho <y0.cho@samsung.com>
Mon, 6 Feb 2023 08:21:06 +0000 (17:21 +0900)
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 <y0.cho@samsung.com>
include/power-internal.h
src/power-internal.c

index 87612f3..fc051dc 100644 (file)
@@ -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.
index 95b545a..aca8ae0 100644 (file)
@@ -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)