power: Add internal function device_power_get_power_state() 87/315387/2 accepted/tizen/9.0/unified/20241205.174757
authorYoungjae Cho <y0.cho@samsung.com>
Fri, 29 Nov 2024 07:17:50 +0000 (16:17 +0900)
committerYoungjae Cho <y0.cho@samsung.com>
Tue, 3 Dec 2024 09:25:16 +0000 (18:25 +0900)
The function gets power state of the deviced.

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

index 52f46e8c7f883e168cfe63aac5c0f514b2336160..852cbb9102d1d1ab382551928f1aed19f45d09ba 100644 (file)
@@ -881,6 +881,30 @@ int device_power_add_lock_count_change_callback(power_lock_e power_lock_type,
 int device_power_remove_lock_count_change_callback(power_lock_e power_lock_type,
        device_power_lock_count_change_callback power_lock_count_change_callback);
 
+/**
+ * @brief Get current power state
+ * @details Get current power state.
+ * @since_tizen 9.0
+ * @privilege %http://tizen.org/privilege/power
+ * @param[out] state The power state
+ * @return @c 0 on success, otherwise a negative error value
+ * @retval #DEVICE_ERROR_NONE Successful
+ * @retval #DEVICE_ERROR_INVALID_PARAMETER Invalid parameter
+ * @retval #DEVICE_ERROR_OPERATION_FAILED Operation failed
+ * @code
+ * #include <device/power-internal.h>
+ * ...
+ * int ret = 0;
+ * device_power_state_e state;
+ *
+ * ret = device_power_get_power_state(&state);
+ * if (ret != DEVICE_ERROR_NONE) {
+ *     ....
+ * }
+ * ...
+ * @endcode
+ */
+int device_power_get_power_state(device_power_state_e *state);
 #ifdef __cplusplus
 }
 #endif
index a7b101795bf9a569d3bec14b932004e6f1ca4c11..25befe52c846d7b4cf91ae206f375bdab4273223 100644 (file)
@@ -957,4 +957,46 @@ int device_power_remove_lock_count_change_callback(power_lock_e power_lock_type,
 
        return DEVICE_ERROR_NONE;
 }
+
+int device_power_get_power_state(device_power_state_e *state)
+{
+       GDBusConnection *connection = NULL;
+       GVariant *retgv = NULL;
+       GError *err = NULL;
+       guint64 _state;
+
+       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);
+
+       *state = (device_power_state_e) _state;
+
+       return DEVICE_ERROR_NONE;
+}
+
 //LCOV_EXCL_STOP
\ No newline at end of file