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;
+}
+