Source code of Windows XP (NT5)
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.

263 lines
10 KiB

  1. /*****************************************************************************\
  2. * *
  3. * powrprof.h - - Interface for powrprof.dll, the power policy applicator *
  4. * *
  5. * Version 1.0 *
  6. * *
  7. * Copyright (c) Microsoft Corporation. All rights reserved. *
  8. * *
  9. \*****************************************************************************/
  10. // Debug definitions used by power management UI.
  11. #ifdef DEBUG
  12. void CDECL DebugPrintA(LPCSTR pszFmt, ...);
  13. #define DebugPrint DebugPrintA
  14. #else // DEBUG
  15. #define DebugPrint 1 ? (void)0 : (void)
  16. #endif // DEBUG
  17. // Define the following to debug batmeter on machines with no battery support.
  18. //#define SIM_BATTERY 1
  19. #define CURRENT_REVISION 1
  20. #define STRSIZE(psz) ((lstrlen(psz) + 1) * sizeof(TCHAR))
  21. #define MAX_NAME_LEN 32 // Max length of name in characters.
  22. #define MAX_NAME_SIZE (MAX_NAME_LEN +1) * sizeof(TCHAR)
  23. #define MAX_DESC_LEN 512 // Max length of description in characters.
  24. #define MAX_DESC_SIZE (MAX_DESC_LEN +1) * sizeof(TCHAR)
  25. #define SEMAPHORE_TIMEOUT 10000
  26. #define NUM_DEC_DIGITS 10+1+1 // 10 digits + NUll and sign.
  27. #define SIZE_DEC_DIGITS (10+1+1) * sizeof(TCHAR)
  28. // Registry storage structures for the GLOBAL_POWER_POLICY data. There are two
  29. // structures, GLOBAL_MACHINE_POWER_POLICY and GLOBAL_USER_POWER_POLICY. the
  30. // GLOBAL_MACHINE_POWER_POLICY stores per machine data for which there is no UI.
  31. // GLOBAL_USER_POWER_POLICY stores the per user data.
  32. typedef struct _GLOBAL_MACHINE_POWER_POLICY{
  33. ULONG Revision;
  34. SYSTEM_POWER_STATE LidOpenWakeAc;
  35. SYSTEM_POWER_STATE LidOpenWakeDc;
  36. ULONG BroadcastCapacityResolution;
  37. } GLOBAL_MACHINE_POWER_POLICY, *PGLOBAL_MACHINE_POWER_POLICY;
  38. typedef struct _GLOBAL_USER_POWER_POLICY{
  39. ULONG Revision;
  40. POWER_ACTION_POLICY PowerButtonAc;
  41. POWER_ACTION_POLICY PowerButtonDc;
  42. POWER_ACTION_POLICY SleepButtonAc;
  43. POWER_ACTION_POLICY SleepButtonDc;
  44. POWER_ACTION_POLICY LidCloseAc;
  45. POWER_ACTION_POLICY LidCloseDc;
  46. SYSTEM_POWER_LEVEL DischargePolicy[NUM_DISCHARGE_POLICIES];
  47. ULONG GlobalFlags;
  48. } GLOBAL_USER_POWER_POLICY, *PGLOBAL_USER_POWER_POLICY;
  49. // Structure to manage global power policies at the user level. This structure
  50. // contains data which is common across all power policy profiles.
  51. typedef struct _GLOBAL_POWER_POLICY{
  52. GLOBAL_USER_POWER_POLICY user;
  53. GLOBAL_MACHINE_POWER_POLICY mach;
  54. } GLOBAL_POWER_POLICY, *PGLOBAL_POWER_POLICY;
  55. // Registry storage structures for the POWER_POLICY data. There are three
  56. // structures, MACHINE_POWER_POLICY, MACHINE_PROCESSOR_POWER_POLICY and USER_POWER_POLICY. the
  57. // MACHINE_POWER_POLICY stores per machine data for which there is no UI.
  58. // USER_POWER_POLICY stores the per user data.
  59. typedef struct _MACHINE_POWER_POLICY{
  60. ULONG Revision; // 1
  61. // meaning of power action "sleep"
  62. SYSTEM_POWER_STATE MinSleepAc;
  63. SYSTEM_POWER_STATE MinSleepDc;
  64. SYSTEM_POWER_STATE ReducedLatencySleepAc;
  65. SYSTEM_POWER_STATE ReducedLatencySleepDc;
  66. // parameters for dozing
  67. ULONG DozeTimeoutAc;
  68. ULONG DozeTimeoutDc;
  69. ULONG DozeS4TimeoutAc;
  70. ULONG DozeS4TimeoutDc;
  71. // processor policies
  72. UCHAR MinThrottleAc;
  73. UCHAR MinThrottleDc;
  74. UCHAR pad1[2];
  75. POWER_ACTION_POLICY OverThrottledAc;
  76. POWER_ACTION_POLICY OverThrottledDc;
  77. } MACHINE_POWER_POLICY, *PMACHINE_POWER_POLICY;
  78. typedef struct _MACHINE_PROCESSOR_POWER_POLICY {
  79. ULONG Revision; // 1
  80. PROCESSOR_POWER_POLICY ProcessorPolicyAc;
  81. PROCESSOR_POWER_POLICY ProcessorPolicyDc;
  82. } MACHINE_PROCESSOR_POWER_POLICY, *PMACHINE_PROCESSOR_POWER_POLICY;
  83. typedef struct _USER_POWER_POLICY{
  84. ULONG Revision; // 1
  85. // "system idle" detection
  86. POWER_ACTION_POLICY IdleAc;
  87. POWER_ACTION_POLICY IdleDc;
  88. ULONG IdleTimeoutAc;
  89. ULONG IdleTimeoutDc;
  90. UCHAR IdleSensitivityAc;
  91. UCHAR IdleSensitivityDc;
  92. // Throttling Policy
  93. UCHAR ThrottlePolicyAc;
  94. UCHAR ThrottlePolicyDc;
  95. // meaning of power action "sleep"
  96. SYSTEM_POWER_STATE MaxSleepAc;
  97. SYSTEM_POWER_STATE MaxSleepDc;
  98. // For future use
  99. ULONG Reserved[2];
  100. // video policies
  101. ULONG VideoTimeoutAc;
  102. ULONG VideoTimeoutDc;
  103. // hard disk policies
  104. ULONG SpindownTimeoutAc;
  105. ULONG SpindownTimeoutDc;
  106. // processor policies
  107. BOOLEAN OptimizeForPowerAc;
  108. BOOLEAN OptimizeForPowerDc;
  109. UCHAR FanThrottleToleranceAc;
  110. UCHAR FanThrottleToleranceDc;
  111. UCHAR ForcedThrottleAc;
  112. UCHAR ForcedThrottleDc;
  113. } USER_POWER_POLICY, *PUSER_POWER_POLICY;
  114. // Structure to manage power policies at the user level. This structure
  115. // contains data which is unique across power policy profiles.
  116. typedef struct _POWER_POLICY{
  117. USER_POWER_POLICY user;
  118. MACHINE_POWER_POLICY mach;
  119. } POWER_POLICY, *PPOWER_POLICY;
  120. // Constants for GlobalFlags
  121. #define EnableSysTrayBatteryMeter 0x01
  122. #define EnableMultiBatteryDisplay 0x02
  123. #define EnablePasswordLogon 0x04
  124. #define EnableWakeOnRing 0x08
  125. #define EnableVideoDimDisplay 0x10
  126. // This constant is passed as a uiID to WritePwrScheme.
  127. #define NEWSCHEME (UINT)-1
  128. // Prototype for EnumPwrSchemes callback proceedures.
  129. typedef BOOLEAN (CALLBACK* PWRSCHEMESENUMPROC)(UINT, DWORD, LPTSTR, DWORD, LPTSTR, PPOWER_POLICY, LPARAM);
  130. typedef BOOLEAN (CALLBACK* PFNNTINITIATEPWRACTION)(POWER_ACTION, SYSTEM_POWER_STATE, ULONG, BOOLEAN);
  131. // Public function prototypes
  132. BOOLEAN WINAPI GetPwrDiskSpindownRange(PUINT, PUINT);
  133. BOOLEAN WINAPI EnumPwrSchemes(PWRSCHEMESENUMPROC, LPARAM);
  134. BOOLEAN WINAPI ReadGlobalPwrPolicy(PGLOBAL_POWER_POLICY);
  135. BOOLEAN WINAPI ReadPwrScheme(UINT, PPOWER_POLICY);
  136. BOOLEAN WINAPI WritePwrScheme(PUINT, LPTSTR, LPTSTR, PPOWER_POLICY);
  137. BOOLEAN WINAPI WriteGlobalPwrPolicy(PGLOBAL_POWER_POLICY);
  138. BOOLEAN WINAPI DeletePwrScheme(UINT);
  139. BOOLEAN WINAPI GetActivePwrScheme(PUINT);
  140. BOOLEAN WINAPI SetActivePwrScheme(UINT, PGLOBAL_POWER_POLICY, PPOWER_POLICY);
  141. BOOLEAN WINAPI GetPwrCapabilities(PSYSTEM_POWER_CAPABILITIES);
  142. BOOLEAN WINAPI IsPwrSuspendAllowed(VOID);
  143. BOOLEAN WINAPI IsPwrHibernateAllowed(VOID);
  144. BOOLEAN WINAPI IsPwrShutdownAllowed(VOID);
  145. BOOLEAN WINAPI IsAdminOverrideActive(PADMINISTRATOR_POWER_POLICY);
  146. BOOLEAN WINAPI SetSuspendState(BOOLEAN, BOOLEAN, BOOLEAN);
  147. BOOLEAN WINAPI GetCurrentPowerPolicies(PGLOBAL_POWER_POLICY, PPOWER_POLICY);
  148. BOOLEAN WINAPI CanUserWritePwrScheme(VOID);
  149. BOOLEAN WINAPI ReadProcessorPwrScheme(UINT, PMACHINE_PROCESSOR_POWER_POLICY);
  150. BOOLEAN WINAPI WriteProcessorPwrScheme(UINT, PMACHINE_PROCESSOR_POWER_POLICY);
  151. #ifndef NT_SUCCESS
  152. #define NTSTATUS LONG
  153. #define _OVERRIDE_NTSTATUS_
  154. #endif
  155. NTSTATUS WINAPI CallNtPowerInformation(POWER_INFORMATION_LEVEL, PVOID, ULONG, PVOID, ULONG);
  156. #ifdef _OVERRIDE_NTSTATUS_
  157. #undef NTSTATUS
  158. #endif
  159. void WINAPI LoadCurrentPwrScheme(HWND hwnd, HINSTANCE hAppInstance, LPSTR lpszCmdLine, int nCmdShow);
  160. void WINAPI MergeLegacyPwrScheme(HWND hwnd, HINSTANCE hAppInstance, LPSTR lpszCmdLine, int nCmdShow);
  161. // Private function prototypes implemented in powrprof.c
  162. BOOLEAN ValidatePowerPolicies(PGLOBAL_POWER_POLICY, PPOWER_POLICY);
  163. BOOLEAN ValidateSystemPolicies(PSYSTEM_POWER_POLICY, PSYSTEM_POWER_POLICY);
  164. BOOLEAN GetCurrentSystemPowerPolicies(PSYSTEM_POWER_POLICY, PSYSTEM_POWER_POLICY);
  165. BOOLEAN MyStrToInt(LPCTSTR, PINT);
  166. BOOLEAN RegistryInit(PUINT);
  167. HANDLE MyCreateSemaphore(LPCTSTR);
  168. NTSTATUS CallNtSetValidateAcDc(BOOLEAN, BOOLEAN, PVOID, PVOID, PVOID, PVOID);
  169. void CDECL DebugPrintA(LPCSTR pszFmt, ...);
  170. DWORD SetPrivilegeAttribute(LPCTSTR, DWORD, LPDWORD);
  171. VOID InitAdmin(PADMINISTRATOR_POWER_POLICY papp);
  172. #ifdef DEBUG
  173. VOID ReadOptionalDebugSettings(VOID);
  174. #endif
  175. // Private function prototypes implemented in reghelp.c:
  176. BOOLEAN OpenCurrentUser(PHKEY phKey);
  177. BOOLEAN CloseCurrentUser(HKEY hKey);
  178. BOOLEAN OpenMachineUserKeys(LPTSTR, LPTSTR, PHKEY, PHKEY);
  179. BOOLEAN TakeRegSemaphore(VOID);
  180. BOOLEAN WritePwrPolicyEx(LPTSTR, LPTSTR, PUINT, LPTSTR, LPTSTR, LPVOID, DWORD, LPVOID, DWORD);
  181. BOOLEAN ReadPwrPolicyEx(LPTSTR, LPTSTR, LPTSTR, LPTSTR, LPDWORD, LPVOID, DWORD, LPVOID, DWORD);
  182. BOOLEAN ReadWritePowerValue(HKEY, LPTSTR, LPTSTR, LPTSTR, LPDWORD, BOOLEAN, BOOLEAN);
  183. BOOLEAN ReadPowerValueOptional(HKEY, LPTSTR, LPTSTR, LPTSTR, LPDWORD);
  184. BOOLEAN ReadPowerIntOptional(HKEY, LPTSTR, LPTSTR, PINT);
  185. BOOLEAN CreatePowerValue(HKEY, LPCTSTR, LPCTSTR, LPCTSTR);
  186. // Private function prototypes implemented in merge.c
  187. BOOLEAN MergePolicies(PUSER_POWER_POLICY, PMACHINE_POWER_POLICY, PPOWER_POLICY);
  188. BOOLEAN SplitPolicies(PPOWER_POLICY, PUSER_POWER_POLICY, PMACHINE_POWER_POLICY);
  189. BOOLEAN MergeGlobalPolicies(PGLOBAL_USER_POWER_POLICY, PGLOBAL_MACHINE_POWER_POLICY, PGLOBAL_POWER_POLICY);
  190. BOOLEAN SplitGlobalPolicies(PGLOBAL_POWER_POLICY, PGLOBAL_USER_POWER_POLICY, PGLOBAL_MACHINE_POWER_POLICY);
  191. BOOLEAN MergeToSystemPowerPolicies(PGLOBAL_POWER_POLICY, PPOWER_POLICY, PSYSTEM_POWER_POLICY, PSYSTEM_POWER_POLICY);
  192. BOOLEAN SplitFromSystemPowerPolicies(PSYSTEM_POWER_POLICY, PSYSTEM_POWER_POLICY, PGLOBAL_POWER_POLICY, PPOWER_POLICY);
  193. // Private function prototypes implemented in debug.c
  194. #ifdef DEBUG
  195. void DumpPowerActionPolicy(LPSTR, PPOWER_ACTION_POLICY);
  196. void DumpSystemPowerLevel(LPSTR, PSYSTEM_POWER_LEVEL);
  197. void DumpSystemPowerPolicy(LPSTR, PSYSTEM_POWER_POLICY);
  198. void DumpSystemPowerCapabilities(LPSTR, PSYSTEM_POWER_CAPABILITIES);
  199. void DifSystemPowerPolicies(LPSTR, PSYSTEM_POWER_POLICY, PSYSTEM_POWER_POLICY);
  200. #endif