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.

250 lines
9.4 KiB

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