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.

270 lines
10 KiB

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