Leaked source code of windows server 2003
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

242 lines
4.8 KiB

  1. /*++
  2. Copyright (c) 1992 Microsoft Corporation
  3. Module Name:
  4. power.c
  5. Abstract:
  6. Stubs for unimplemented power management APIs
  7. Author:
  8. Steve Wood (stevewo) 18-Nov-1994
  9. Revision History:
  10. --*/
  11. #include "basedll.h"
  12. BOOL
  13. WINAPI
  14. GetSystemPowerStatus(
  15. LPSYSTEM_POWER_STATUS lpStatus
  16. )
  17. {
  18. SYSTEM_BATTERY_STATE BatteryState;
  19. NTSTATUS Status;
  20. //
  21. // Get power policy managers Battery State
  22. //
  23. Status = NtPowerInformation (
  24. SystemBatteryState,
  25. NULL,
  26. 0,
  27. &BatteryState,
  28. sizeof (BatteryState)
  29. );
  30. if (!NT_SUCCESS(Status)) {
  31. BaseSetLastNTError(Status);
  32. return FALSE;
  33. }
  34. //
  35. // Convert it to the legacy System Power State structure
  36. //
  37. RtlZeroMemory (lpStatus, sizeof(*lpStatus));
  38. lpStatus->ACLineStatus = AC_LINE_ONLINE;
  39. if (BatteryState.BatteryPresent && !BatteryState.AcOnLine) {
  40. lpStatus->ACLineStatus = AC_LINE_OFFLINE;
  41. }
  42. if (BatteryState.Charging) {
  43. lpStatus->BatteryFlag |= BATTERY_FLAG_CHARGING;
  44. }
  45. if (!BatteryState.BatteryPresent) {
  46. lpStatus->BatteryFlag |= BATTERY_FLAG_NO_BATTERY;
  47. }
  48. lpStatus->BatteryLifePercent = BATTERY_PERCENTAGE_UNKNOWN;
  49. if (BatteryState.MaxCapacity) {
  50. if (BatteryState.RemainingCapacity > BatteryState.MaxCapacity) {
  51. //
  52. // Values greater than 100% should not be returned
  53. // According to the SDK they are reserved.
  54. //
  55. lpStatus->BatteryLifePercent = 100;
  56. } else {
  57. lpStatus->BatteryLifePercent = (UCHAR)
  58. (((BatteryState.RemainingCapacity * 100) +
  59. (BatteryState.MaxCapacity/2)) /
  60. BatteryState.MaxCapacity);
  61. }
  62. if (lpStatus->BatteryLifePercent > 66) {
  63. lpStatus->BatteryFlag |= BATTERY_FLAG_HIGH;
  64. }
  65. if (lpStatus->BatteryLifePercent < 33) {
  66. lpStatus->BatteryFlag |= BATTERY_FLAG_LOW;
  67. }
  68. }
  69. lpStatus->BatteryLifeTime = BATTERY_LIFE_UNKNOWN;
  70. lpStatus->BatteryFullLifeTime = BATTERY_LIFE_UNKNOWN;
  71. if (BatteryState.EstimatedTime) {
  72. lpStatus->BatteryLifeTime = BatteryState.EstimatedTime;
  73. }
  74. return TRUE;
  75. }
  76. BOOL
  77. WINAPI
  78. SetSystemPowerState(
  79. BOOL fSuspend,
  80. BOOL fForce
  81. )
  82. {
  83. NTSTATUS Status;
  84. Status = NtInitiatePowerAction (fSuspend ? PowerActionSleep : PowerActionHibernate,
  85. fSuspend ? PowerSystemSleeping1 : PowerSystemHibernate,
  86. fForce == TRUE ? 0 : POWER_ACTION_QUERY_ALLOWED,
  87. FALSE);
  88. if (!NT_SUCCESS(Status)) {
  89. BaseSetLastNTError(Status);
  90. return FALSE;
  91. }
  92. return TRUE;
  93. }
  94. EXECUTION_STATE
  95. WINAPI
  96. SetThreadExecutionState(
  97. EXECUTION_STATE esFlags
  98. )
  99. {
  100. NTSTATUS Status;
  101. EXECUTION_STATE PreviousFlags;
  102. Status = NtSetThreadExecutionState (esFlags, &PreviousFlags);
  103. if (!NT_SUCCESS(Status)) {
  104. BaseSetLastNTError(Status);
  105. return (EXECUTION_STATE) 0;
  106. }
  107. return PreviousFlags;
  108. }
  109. BOOL
  110. WINAPI
  111. RequestWakeupLatency (
  112. LATENCY_TIME latency
  113. )
  114. {
  115. NTSTATUS Status;
  116. Status = NtRequestWakeupLatency (latency);
  117. if (!NT_SUCCESS(Status)) {
  118. BaseSetLastNTError(Status);
  119. return FALSE;
  120. }
  121. return TRUE;
  122. }
  123. BOOL
  124. WINAPI
  125. GetDevicePowerState(
  126. HANDLE h,
  127. OUT BOOL *pfOn
  128. )
  129. {
  130. NTSTATUS Status;
  131. DEVICE_POWER_STATE PowerState;
  132. Status = NtGetDevicePowerState(h, &PowerState);
  133. if (!NT_SUCCESS(Status)) {
  134. BaseSetLastNTError(Status);
  135. return(FALSE);
  136. }
  137. if ((PowerState == PowerDeviceD0) ||
  138. (PowerState == PowerDeviceUnspecified)) {
  139. *pfOn = TRUE;
  140. } else {
  141. *pfOn = FALSE;
  142. }
  143. return TRUE;
  144. }
  145. BOOL
  146. WINAPI
  147. IsSystemResumeAutomatic(
  148. VOID
  149. )
  150. {
  151. return(NtIsSystemResumeAutomatic());
  152. }
  153. BOOL
  154. WINAPI
  155. RequestDeviceWakeup (
  156. HANDLE h
  157. )
  158. {
  159. NTSTATUS Status;
  160. Status = NtRequestDeviceWakeup(h);
  161. if (!NT_SUCCESS(Status)) {
  162. BaseSetLastNTError(Status);
  163. return FALSE;
  164. } else {
  165. return(TRUE);
  166. }
  167. }
  168. BOOL
  169. WINAPI
  170. CancelDeviceWakeupRequest(
  171. HANDLE h
  172. )
  173. {
  174. NTSTATUS Status;
  175. Status = NtCancelDeviceWakeupRequest(h);
  176. if (!NT_SUCCESS(Status)) {
  177. BaseSetLastNTError(Status);
  178. return FALSE;
  179. } else {
  180. return(TRUE);
  181. }
  182. }
  183. BOOL
  184. WINAPI
  185. SetMessageWaitingIndicator (
  186. IN HANDLE hMsgIndicator,
  187. IN ULONG ulMsgCount
  188. )
  189. {
  190. BaseSetLastNTError(STATUS_NOT_IMPLEMENTED);
  191. return FALSE;
  192. }