diff --git a/reactos/dll/win32/kernel32/kernel32.rbuild b/reactos/dll/win32/kernel32/kernel32.rbuild
index c3ef057768c..4d1cd5dd30b 100644
--- a/reactos/dll/win32/kernel32/kernel32.rbuild
+++ b/reactos/dll/win32/kernel32/kernel32.rbuild
@@ -80,6 +80,7 @@
muldiv.c
nls.c
perfcnt.c
+ power.c
recovery.c
res.c
sortkey.c
diff --git a/reactos/dll/win32/kernel32/misc/power.c b/reactos/dll/win32/kernel32/misc/power.c
new file mode 100644
index 00000000000..2d8bc3a3268
--- /dev/null
+++ b/reactos/dll/win32/kernel32/misc/power.c
@@ -0,0 +1,158 @@
+/*
+ *
+ * COPYRIGHT: See COPYING in the top level directory
+ * PROJECT: ReactOS system libraries
+ * FILE: dll/win32/kernel32/misc/power.c
+ * PURPOSE: Power Management Functions
+ * PROGRAMMER: Dmitry Chapyshev
+ *
+ * UPDATE HISTORY:
+ * 01/15/2009 Created
+ */
+
+#include
+
+#define NDEBUG
+#include
+
+#define STUB \
+ SetLastError(ERROR_CALL_NOT_IMPLEMENTED); \
+ DPRINT1("%s() is UNIMPLEMENTED!\n", __FUNCTION__)
+
+/* PUBLIC FUNCTIONS ***********************************************************/
+
+/*
+ * @implemented
+ */
+BOOL
+WINAPI
+GetSystemPowerStatus(LPSYSTEM_POWER_STATUS PowerStatus)
+{
+ NTSTATUS Status;
+ SYSTEM_BATTERY_STATE SysBatState;
+
+ Status = NtPowerInformation(SystemBatteryState,
+ NULL,
+ 0,
+ &SysBatState,
+ sizeof(SYSTEM_BATTERY_STATE));
+
+ if (!NT_SUCCESS(Status))
+ {
+ SetLastErrorByStatus(Status);
+ return FALSE;
+ }
+
+ RtlZeroMemory(PowerStatus, sizeof(LPSYSTEM_POWER_STATUS));
+
+ PowerStatus->BatteryLifeTime = BATTERY_LIFE_UNKNOWN;
+ PowerStatus->BatteryFullLifeTime = BATTERY_LIFE_UNKNOWN;
+
+ PowerStatus->BatteryLifePercent = BATTERY_PERCENTAGE_UNKNOWN;
+ if (SysBatState.MaxCapacity)
+ {
+ if (SysBatState.MaxCapacity >= SysBatState.RemainingCapacity)
+ PowerStatus->BatteryLifePercent = (SysBatState.RemainingCapacity / SysBatState.MaxCapacity) * 100;
+ else
+ PowerStatus->BatteryLifePercent = 100; /* 100% */
+
+ if (PowerStatus->BatteryLifePercent <= 32)
+ PowerStatus->BatteryFlag |= BATTERY_FLAG_LOW;
+
+ if (PowerStatus->BatteryLifePercent >= 67)
+ PowerStatus->BatteryFlag |= BATTERY_FLAG_HIGH;
+ }
+
+ if (!SysBatState.BatteryPresent)
+ PowerStatus->BatteryFlag |= BATTERY_FLAG_NO_BATTERY;
+
+ if (SysBatState.Charging)
+ PowerStatus->BatteryFlag |= BATTERY_FLAG_CHARGING;
+
+ if (!SysBatState.AcOnLine && SysBatState.BatteryPresent)
+ PowerStatus->ACLineStatus = AC_LINE_OFFLINE;
+ else
+ PowerStatus->ACLineStatus = AC_LINE_ONLINE;
+
+ if (SysBatState.EstimatedTime)
+ PowerStatus->BatteryLifeTime = SysBatState.EstimatedTime;
+
+ return TRUE;
+}
+
+/*
+ * @unimplemented
+ */
+BOOL WINAPI
+SetSystemPowerState(BOOL fSuspend, BOOL fForce)
+{
+ STUB;
+ return FALSE;
+}
+
+/*
+ * @unimplemented
+ */
+BOOL
+WINAPI
+GetDevicePowerState(HANDLE hDevice, BOOL *pfOn)
+{
+ STUB;
+ return 0;
+}
+
+/*
+ * @unimplemented
+ */
+BOOL
+WINAPI
+RequestDeviceWakeup(HANDLE hDevice)
+{
+ STUB;
+ return 0;
+}
+
+/*
+ * @unimplemented
+ */
+BOOL
+WINAPI
+RequestWakeupLatency(LATENCY_TIME latency)
+{
+ STUB;
+ return 0;
+}
+
+/*
+ * @unimplemented
+ */
+BOOL
+WINAPI
+CancelDeviceWakeupRequest(HANDLE hDevice)
+{
+ STUB;
+ return 0;
+}
+
+/*
+ * @unimplemented
+ */
+BOOL
+WINAPI
+IsSystemResumeAutomatic(VOID)
+{
+ STUB;
+ return 0;
+}
+
+/*
+ * @unimplemented
+ */
+BOOL
+WINAPI
+SetMessageWaitingIndicator(HANDLE hMsgIndicator,
+ ULONG ulMsgCount)
+{
+ STUB;
+ return 0;
+}
diff --git a/reactos/dll/win32/kernel32/misc/stubs.c b/reactos/dll/win32/kernel32/misc/stubs.c
index ba8de277672..4bd44a59bfd 100644
--- a/reactos/dll/win32/kernel32/misc/stubs.c
+++ b/reactos/dll/win32/kernel32/misc/stubs.c
@@ -153,26 +153,6 @@ GetNextVDMCommand (
}
-/*
- * @unimplemented
- */
-BOOL
-WINAPI
-GetSystemPowerStatus (
- LPSYSTEM_POWER_STATUS PowerStatus
- )
-{
- STUB;
- PowerStatus->ACLineStatus = 1;
- PowerStatus->BatteryFlag = 128;
- PowerStatus->BatteryLifePercent = 255;
- PowerStatus->Reserved1 = 0;
- PowerStatus->BatteryLifeTime = -1;
- PowerStatus->BatteryFullLifeTime = -1;
- return TRUE;
-}
-
-
/*
* @unimplemented
*/
@@ -240,20 +220,6 @@ RegisterWowExec (
}
-/*
- * @unimplemented
- */
-BOOL WINAPI
-SetSystemPowerState (
- BOOL fSuspend,
- BOOL fForce
- )
-{
- STUB;
- return FALSE;
-}
-
-
/*
* @unimplemented
*/
@@ -367,19 +333,6 @@ BindIoCompletionCallback(HANDLE FileHandle,
return TRUE;
}
-/*
- * @unimplemented
- */
-BOOL
-WINAPI
-CancelDeviceWakeupRequest(
- HANDLE hDevice
- )
-{
- STUB;
- return 0;
-}
-
/*
* @unimplemented
*/
@@ -422,20 +375,6 @@ FreeUserPhysicalPages(
return 0;
}
-/*
- * @unimplemented
- */
-BOOL
-WINAPI
-GetDevicePowerState(
- HANDLE hDevice,
- BOOL *pfOn
- )
-{
- STUB;
- return 0;
-}
-
/*
* @unimplemented
@@ -511,19 +450,6 @@ HeapSetInformation (
return 0;
}
-/*
- * @unimplemented
- */
-BOOL
-WINAPI
-IsSystemResumeAutomatic(
- VOID
- )
-{
- STUB;
- return 0;
-}
-
/*
* @unimplemented
*/
@@ -609,32 +535,6 @@ RemoveVectoredExceptionHandler(
return 0;
}
-/*
- * @unimplemented
- */
-BOOL
-WINAPI
-RequestDeviceWakeup(
- HANDLE hDevice
- )
-{
- STUB;
- return 0;
-}
-
-/*
- * @unimplemented
- */
-BOOL
-WINAPI
-RequestWakeupLatency(
- LATENCY_TIME latency
- )
-{
- STUB;
- return 0;
-}
-
/*
* @unimplemented
*/
@@ -661,20 +561,6 @@ RestoreLastError(
STUB;
}
-/*
- * @unimplemented
- */
-BOOL
-WINAPI
-SetMessageWaitingIndicator(
- HANDLE hMsgIndicator,
- ULONG ulMsgCount
- )
-{
- STUB;
- return 0;
-}
-
/*
* @unimplemented
*/