ReactOS 0.4.15-dev-6054-gbddd8b0
power.c File Reference
#include <k32.h>
#include <ndk/pofuncs.h>
#include <debug.h>
Include dependency graph for power.c:

Go to the source code of this file.

Macros

#define NDEBUG
 

Functions

BOOL WINAPI GetSystemPowerStatus (IN LPSYSTEM_POWER_STATUS PowerStatus)
 
BOOL WINAPI SetSystemPowerState (IN BOOL fSuspend, IN BOOL fForce)
 
BOOL WINAPI GetDevicePowerState (IN HANDLE hDevice, OUT BOOL *pfOn)
 
BOOL WINAPI RequestDeviceWakeup (IN HANDLE hDevice)
 
BOOL WINAPI RequestWakeupLatency (IN LATENCY_TIME latency)
 
BOOL WINAPI CancelDeviceWakeupRequest (IN HANDLE hDevice)
 
BOOL WINAPI IsSystemResumeAutomatic (VOID)
 
BOOL WINAPI SetMessageWaitingIndicator (IN HANDLE hMsgIndicator, IN ULONG ulMsgCount)
 
EXECUTION_STATE WINAPI SetThreadExecutionState (EXECUTION_STATE esFlags)
 

Macro Definition Documentation

◆ NDEBUG

#define NDEBUG

Definition at line 17 of file power.c.

Function Documentation

◆ CancelDeviceWakeupRequest()

BOOL WINAPI CancelDeviceWakeupRequest ( IN HANDLE  hDevice)

Definition at line 178 of file power.c.

179{
181
183 if (!NT_SUCCESS(Status))
184 {
186 return FALSE;
187 }
188
189 return TRUE;
190}
LONG NTSTATUS
Definition: precomp.h:26
#define TRUE
Definition: types.h:120
#define FALSE
Definition: types.h:117
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
Status
Definition: gdiplustypes.h:25
NTSTATUS NTAPI NtCancelDeviceWakeupRequest(IN HANDLE DeviceHandle)
Definition: iofunc.c:4638
DWORD BaseSetLastNTError(IN NTSTATUS Status)
Definition: reactos.cpp:166

◆ GetDevicePowerState()

BOOL WINAPI GetDevicePowerState ( IN HANDLE  hDevice,
OUT BOOL pfOn 
)

Definition at line 117 of file power.c.

119{
122
124 if (NT_SUCCESS(Status))
125 {
128 return TRUE;
129 }
130
132 return FALSE;
133}
NTSTATUS NTAPI NtGetDevicePowerState(IN HANDLE Device, IN PDEVICE_POWER_STATE PowerState)
Definition: power.c:910
@ DevicePowerState
Definition: ntpoapi.h:63
@ PowerDeviceUnspecified
Definition: ntpoapi.h:48
@ PowerDeviceD0
Definition: ntpoapi.h:49
enum _DEVICE_POWER_STATE DEVICE_POWER_STATE

◆ GetSystemPowerStatus()

BOOL WINAPI GetSystemPowerStatus ( IN LPSYSTEM_POWER_STATUS  PowerStatus)

Definition at line 27 of file power.c.

28{
30 SYSTEM_BATTERY_STATE BattState;
31 ULONG Max, Current;
32
34 NULL,
35 0,
36 &BattState,
37 sizeof(SYSTEM_BATTERY_STATE));
38 if (!NT_SUCCESS(Status))
39 {
41 return FALSE;
42 }
43
44 RtlZeroMemory(PowerStatus, sizeof(SYSTEM_POWER_STATUS));
45
46 PowerStatus->BatteryLifeTime = BATTERY_LIFE_UNKNOWN;
47 PowerStatus->BatteryFullLifeTime = BATTERY_LIFE_UNKNOWN;
48 PowerStatus->BatteryLifePercent = BATTERY_PERCENTAGE_UNKNOWN;
49 PowerStatus->ACLineStatus = AC_LINE_ONLINE;
50
51 Max = BattState.MaxCapacity;
52 Current = BattState.RemainingCapacity;
53 if (Max)
54 {
55 if (Current <= Max)
56 {
57 PowerStatus->BatteryLifePercent = (UCHAR)((100 * Current + Max / 2) / Max);
58 }
59 else
60 {
61 PowerStatus->BatteryLifePercent = 100;
62 }
63
64 if (PowerStatus->BatteryLifePercent <= 4)
65 PowerStatus->BatteryFlag |= BATTERY_FLAG_CRITICAL;
66
67 if (PowerStatus->BatteryLifePercent <= 32)
68 PowerStatus->BatteryFlag |= BATTERY_FLAG_LOW;
69
70 if (PowerStatus->BatteryLifePercent >= 67)
71 PowerStatus->BatteryFlag |= BATTERY_FLAG_HIGH;
72 }
73
74 if (!BattState.BatteryPresent)
75 PowerStatus->BatteryFlag |= BATTERY_FLAG_NO_BATTERY;
76
77 if (BattState.Charging)
78 PowerStatus->BatteryFlag |= BATTERY_FLAG_CHARGING;
79
80 if (!(BattState.AcOnLine) && (BattState.BatteryPresent))
81 PowerStatus->ACLineStatus = AC_LINE_OFFLINE;
82
83 if (BattState.EstimatedTime)
84 PowerStatus->BatteryLifeTime = BattState.EstimatedTime;
85
86 return TRUE;
87}
#define Max(a, b)
Definition: cdprocs.h:78
#define NULL
Definition: types.h:112
NTSTATUS NTAPI NtPowerInformation(IN POWER_INFORMATION_LEVEL PowerInformationLevel, IN PVOID InputBuffer OPTIONAL, IN ULONG InputBufferLength, OUT PVOID OutputBuffer OPTIONAL, IN ULONG OutputBufferLength)
Definition: power.c:780
@ SystemBatteryState
Definition: ntpoapi.h:72
ULONG RemainingCapacity
Definition: ntpoapi.h:391
BOOLEAN BatteryPresent
Definition: ntpoapi.h:386
#define RtlZeroMemory(Destination, Length)
Definition: typedefs.h:262
uint32_t ULONG
Definition: typedefs.h:59
#define BATTERY_FLAG_CHARGING
Definition: winbase.h:518
#define BATTERY_LIFE_UNKNOWN
Definition: winbase.h:522
#define BATTERY_FLAG_LOW
Definition: winbase.h:516
#define BATTERY_FLAG_NO_BATTERY
Definition: winbase.h:519
#define AC_LINE_ONLINE
Definition: winbase.h:512
#define BATTERY_FLAG_CRITICAL
Definition: winbase.h:517
#define AC_LINE_OFFLINE
Definition: winbase.h:511
#define BATTERY_FLAG_HIGH
Definition: winbase.h:515
#define BATTERY_PERCENTAGE_UNKNOWN
Definition: winbase.h:521
unsigned char UCHAR
Definition: xmlstorage.h:181

Referenced by DynamicLoadIcon().

◆ IsSystemResumeAutomatic()

BOOL WINAPI IsSystemResumeAutomatic ( VOID  )

Definition at line 197 of file power.c.

198{
200}
unsigned int BOOL
Definition: ntddk_ex.h:94
BOOLEAN NTAPI NtIsSystemResumeAutomatic(VOID)
Definition: power.c:919

◆ RequestDeviceWakeup()

BOOL WINAPI RequestDeviceWakeup ( IN HANDLE  hDevice)

Definition at line 140 of file power.c.

141{
143
144 Status = NtRequestDeviceWakeup(hDevice);
145 if (!NT_SUCCESS(Status))
146 {
148 return FALSE;
149 }
150
151 return TRUE;
152}
NTSTATUS NTAPI NtRequestDeviceWakeup(IN HANDLE DeviceHandle)
Definition: iofunc.c:4649

◆ RequestWakeupLatency()

BOOL WINAPI RequestWakeupLatency ( IN LATENCY_TIME  latency)

Definition at line 159 of file power.c.

160{
162
164 if (!NT_SUCCESS(Status))
165 {
167 return FALSE;
168 }
169
170 return TRUE;
171}
NTSTATUS NTAPI NtRequestWakeupLatency(IN LATENCY_TIME Latency)
Definition: power.c:927

◆ SetMessageWaitingIndicator()

BOOL WINAPI SetMessageWaitingIndicator ( IN HANDLE  hMsgIndicator,
IN ULONG  ulMsgCount 
)

Definition at line 207 of file power.c.

209{
210 /* This is the correct Windows implementation */
212 return 0;
213}
#define ERROR_CALL_NOT_IMPLEMENTED
Definition: compat.h:102
#define SetLastError(x)
Definition: compat.h:752

◆ SetSystemPowerState()

BOOL WINAPI SetSystemPowerState ( IN BOOL  fSuspend,
IN BOOL  fForce 
)

Definition at line 94 of file power.c.

96{
98
101 (fForce == FALSE),
102 FALSE);
103 if (!NT_SUCCESS(Status))
104 {
106 return FALSE;
107 }
108
109 return TRUE;
110}
NTSTATUS NTAPI NtInitiatePowerAction(IN POWER_ACTION SystemAction, IN SYSTEM_POWER_STATE MinSystemState, IN ULONG Flags, IN BOOLEAN Asynchronous)
Definition: power.c:766
@ PowerSystemSleeping1
Definition: ntpoapi.h:37
@ PowerSystemHibernate
Definition: ntpoapi.h:40
@ PowerActionHibernate
Definition: ntpoapi.h:126
@ PowerActionSleep
Definition: ntpoapi.h:125

◆ SetThreadExecutionState()

EXECUTION_STATE WINAPI SetThreadExecutionState ( EXECUTION_STATE  esFlags)

Definition at line 220 of file power.c.

221{
223
224 Status = NtSetThreadExecutionState(esFlags, &esFlags);
225 if (!NT_SUCCESS(Status))
226 {
228 return 0;
229 }
230
231 return esFlags;
232}
NTSTATUS NTAPI NtSetThreadExecutionState(IN EXECUTION_STATE esFlags, OUT EXECUTION_STATE *PreviousFlags)
Definition: power.c:935