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.

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