ReactOS  0.4.14-dev-323-g6fe6a88
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 }
#define TRUE
Definition: types.h:120
LONG NTSTATUS
Definition: precomp.h:26
DWORD BaseSetLastNTError(IN NTSTATUS Status)
Definition: reactos.cpp:166
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
Status
Definition: gdiplustypes.h:24
NTSTATUS NTAPI NtCancelDeviceWakeupRequest(IN HANDLE DeviceHandle)
Definition: iofunc.c:4565

◆ 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 }
#define TRUE
Definition: types.h:120
LONG NTSTATUS
Definition: precomp.h:26
DWORD BaseSetLastNTError(IN NTSTATUS Status)
Definition: reactos.cpp:166
enum _DEVICE_POWER_STATE DEVICE_POWER_STATE
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
NTSTATUS NTAPI NtGetDevicePowerState(IN HANDLE Device, IN PDEVICE_POWER_STATE PowerState)
Definition: power.c:787
Status
Definition: gdiplustypes.h:24

◆ 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 BATTERY_PERCENTAGE_UNKNOWN
Definition: winbase.h:502
#define TRUE
Definition: types.h:120
LONG NTSTATUS
Definition: precomp.h:26
#define BATTERY_FLAG_NO_BATTERY
Definition: winbase.h:500
#define Max(a, b)
Definition: cdprocs.h:70
#define BATTERY_FLAG_HIGH
Definition: winbase.h:496
smooth NULL
Definition: ftsmooth.c:416
DWORD BaseSetLastNTError(IN NTSTATUS Status)
Definition: reactos.cpp:166
#define AC_LINE_ONLINE
Definition: winbase.h:493
#define BATTERY_LIFE_UNKNOWN
Definition: winbase.h:503
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
ULONG RemainingCapacity
Definition: ntpoapi.h:391
unsigned char UCHAR
Definition: xmlstorage.h:181
Status
Definition: gdiplustypes.h:24
#define AC_LINE_OFFLINE
Definition: winbase.h:492
#define BATTERY_FLAG_CHARGING
Definition: winbase.h:499
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:660
#define BATTERY_FLAG_CRITICAL
Definition: winbase.h:498
unsigned int ULONG
Definition: retypes.h:1
#define RtlZeroMemory(Destination, Length)
Definition: typedefs.h:261
BOOLEAN BatteryPresent
Definition: ntpoapi.h:386
#define BATTERY_FLAG_LOW
Definition: winbase.h:497

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:796

◆ 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 }
#define TRUE
Definition: types.h:120
LONG NTSTATUS
Definition: precomp.h:26
DWORD BaseSetLastNTError(IN NTSTATUS Status)
Definition: reactos.cpp:166
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
Status
Definition: gdiplustypes.h:24
NTSTATUS NTAPI NtRequestDeviceWakeup(IN HANDLE DeviceHandle)
Definition: iofunc.c:4576

◆ RequestWakeupLatency()

BOOL WINAPI RequestWakeupLatency ( IN LATENCY_TIME  latency)

Definition at line 159 of file power.c.

160 {
162 
163  Status = NtRequestWakeupLatency(latency);
164  if (!NT_SUCCESS(Status))
165  {
167  return FALSE;
168  }
169 
170  return TRUE;
171 }
#define TRUE
Definition: types.h:120
LONG NTSTATUS
Definition: precomp.h:26
DWORD BaseSetLastNTError(IN NTSTATUS Status)
Definition: reactos.cpp:166
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
NTSTATUS NTAPI NtRequestWakeupLatency(IN LATENCY_TIME Latency)
Definition: power.c:804
Status
Definition: gdiplustypes.h:24

◆ 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 SetLastError(x)
Definition: compat.h:409
#define ERROR_CALL_NOT_IMPLEMENTED
Definition: compat.h:92

◆ 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 }
#define TRUE
Definition: types.h:120
LONG NTSTATUS
Definition: precomp.h:26
NTSTATUS NTAPI NtInitiatePowerAction(IN POWER_ACTION SystemAction, IN SYSTEM_POWER_STATE MinSystemState, IN ULONG Flags, IN BOOLEAN Asynchronous)
Definition: power.c:646
DWORD BaseSetLastNTError(IN NTSTATUS Status)
Definition: reactos.cpp:166
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
Status
Definition: gdiplustypes.h:24

◆ 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 }
LONG NTSTATUS
Definition: precomp.h:26
DWORD BaseSetLastNTError(IN NTSTATUS Status)
Definition: reactos.cpp:166
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
Status
Definition: gdiplustypes.h:24
NTSTATUS NTAPI NtSetThreadExecutionState(IN EXECUTION_STATE esFlags, OUT EXECUTION_STATE *PreviousFlags)
Definition: power.c:812