power: add getter for the deviced power state 59/277659/5
authorYoungjae Cho <y0.cho@samsung.com>
Tue, 12 Jul 2022 01:23:56 +0000 (10:23 +0900)
committerYoungjae Cho <y0.cho@samsung.com>
Tue, 12 Jul 2022 07:11:15 +0000 (16:11 +0900)
Change-Id: I6fd3aff0d211df954d0ec1c7505e979eef5cfd07
Signed-off-by: Youngjae Cho <y0.cho@samsung.com>
include/power-internal.h
src/power-internal.c

index d3653c0..817c1d4 100644 (file)
@@ -134,6 +134,8 @@ int device_power_change_state(uint64_t state, int timeout_sec, change_state_call
  */
 int device_power_check_reboot_allowed(void);
 
+int device_power_get_state(uint64_t *state);
+
 #ifdef __cplusplus
 }
 #endif
index 58bde91..79c1b54 100644 (file)
@@ -316,3 +316,42 @@ int device_power_check_reboot_allowed(void)
 
        return (retval != 0 || cloned != 0);
 }
+
+int device_power_get_state(uint64_t *state)
+{
+       GDBusConnection *connection;
+       GVariant *retgv = NULL;
+       GError *err = NULL;
+
+       if (!state)
+               return DEVICE_ERROR_INVALID_PARAMETER;
+
+       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,
+                       "PowerGetState",
+                       NULL,
+                       NULL,
+                       G_DBUS_CALL_FLAGS_NONE,
+                       DBUS_METHOD_SYNC_CALL_TIMEOUT_MS,
+                       NULL,
+                       &err);
+       if (!retgv || err) {
+               _E("Failed to request PowerGetState, %s", err->message);
+               g_error_free(err);
+               return DEVICE_ERROR_OPERATION_FAILED;
+       }
+
+       g_variant_get(retgv, "(t)", state);
+
+       return DEVICE_ERROR_NONE;
+}
+