power: add device_power_change_state_wait_done() 35/269135/1
authorYoungjae Cho <y0.cho@samsung.com>
Mon, 10 Jan 2022 07:14:19 +0000 (16:14 +0900)
committerYoungjae Cho <y0.cho@samsung.com>
Mon, 10 Jan 2022 08:21:23 +0000 (17:21 +0900)
The api device_power_add_change_state_wait_callback() now shall reply
to the deviced that it is ready to sleep. The struct device_event_info
now contains an additional information, uint64_t id, which is used by
device_power_change_state_wait_done(). The callback should store the id
and call device_power_change_state_wait_done() with the id.

Change-Id: I9d399cda46a0d1029439b9b66fc586aa1318fbc9
Signed-off-by: Youngjae Cho <y0.cho@samsung.com>
include/power-internal.h
src/power-internal.c

index 7c34294..febf2fc 100644 (file)
@@ -69,12 +69,14 @@ enum {
 struct device_change_state_info {
        uint64_t prev_state;
        uint64_t next_state;
+       uint64_t id;
        int reason;
 };
 
-typedef int (*change_state_callback) (const struct device_change_state_info *info, void *user_data);
+typedef void (*change_state_callback) (const struct device_change_state_info *info, void *user_data);
 
 int device_power_add_change_state_wait_callback(uint64_t state_bits, change_state_callback cb, void *user_data);
+int device_power_change_state_wait_done(uint64_t id);
 void device_power_remove_change_state_wait_callback(uint64_t state_bits);
 
 #ifdef __cplusplus
index 30735c9..45d22d6 100644 (file)
@@ -39,30 +39,15 @@ static void signal_callback(GDBusConnection *connection,
 {
        struct device_change_state_info info;
        struct userdata *ud;
-       uint64_t event_id;
-       int retval;
 
        ud = (struct userdata *) user_data;
 
        if (!ud || !ud->callback)
                return;
 
-       g_variant_get(parameters, "(ttti)", &info.prev_state, &info.next_state, &event_id, &info.reason);
+       g_variant_get(parameters, "(ttti)", &info.prev_state, &info.next_state, &info.id, &info.reason);
 
-       retval = ud->callback(&info, ud->data);
-       if (retval == 0) {
-               g_dbus_connection_call_sync(connection,
-                       DEVICED_BUS_NAME,
-                       DEVICED_PATH_POWER,
-                       DEVICED_INTERFACE_POWER,
-                       "ConfirmChangeStateWait",
-                       g_variant_new("(t)", event_id),
-                       NULL,
-                       G_DBUS_CALL_FLAGS_NONE,
-                       DBUS_METHOD_SYNC_CALL_TIMEOUT_MS,
-                       NULL,
-                       NULL);
-       }
+       ud->callback(&info, ud->data);
 }
 
 static int __device_power_add_change_state_wait_callback(GDBusConnection *connection,
@@ -138,6 +123,45 @@ int device_power_add_change_state_wait_callback(uint64_t state_bits, change_stat
        return DEVICE_ERROR_NONE;
 }
 
+int device_power_change_state_wait_done(uint64_t id)
+{
+       GDBusConnection *connection;
+       GVariant *retgv;
+       GError *err;
+       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,
+               "ConfirmChangeStateWait",
+               g_variant_new("(t)", 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  __device_power_remove_change_state_wait_callback(GDBusConnection *connection, int index)
 {
        if (change_state_signal_id[index] == 0)