1 /* Copyright (c) 2019 Daniel Widdis, All Rights Reserved 2 * 3 * The contents of this file is dual-licensed under 2 4 * alternative Open Source/Free licenses: LGPL 2.1 or later and 5 * Apache License 2.0. (starting with JNA version 4.0.0). 6 * 7 * You can freely decide which license you want to apply to 8 * the project. 9 * 10 * You may obtain a copy of the LGPL License at: 11 * 12 * http://www.gnu.org/licenses/licenses.html 13 * 14 * A copy is also included in the downloadable source code package 15 * containing JNA, in file "LGPL2.1". 16 * 17 * You may obtain a copy of the Apache License at: 18 * 19 * http://www.apache.org/licenses/ 20 * 21 * A copy is also included in the downloadable source code package 22 * containing JNA, in file "AL2.0". 23 */ 24 package com.sun.jna.platform.win32; 25 26 import com.sun.jna.Library; 27 import com.sun.jna.Native; 28 import com.sun.jna.Pointer; 29 30 /** 31 * Functions used with power management. 32 */ 33 public interface PowrProf extends Library { 34 PowrProf INSTANCE = Native.load("PowrProf", PowrProf.class); 35 36 /** 37 * Enum which indicates the power information level requested from 38 * {@link #CallNtPowerInformation}. This value indicates the specific 39 * power information to be set or retrieved. 40 */ 41 public interface POWER_INFORMATION_LEVEL { 42 /** 43 * The {@code lpInBuffer} parameter must be {@code NULL}; otherwise, the 44 * function returns {@link WinError#ERROR_INVALID_PARAMETER}. 45 * <p> 46 * The {@code lpOutputBuffer} buffer receives a 47 * {@link com.sun.jna.platform.win32.WinDef.ULONGLONG} that specifies 48 * the interrupt-time count, in 100-nanosecond units, at the last system 49 * sleep time. 50 */ 51 int LastSleepTime = 15; 52 53 /** 54 * The {@code lpInBuffer} parameter must be {@code NULL}; otherwise, the 55 * function returns {@link WinError#ERROR_INVALID_PARAMETER}. 56 * <p> 57 * The {@code lpOutputBuffer} buffer receives a 58 * {@link com.sun.jna.platform.win32.WinDef.ULONGLONG} that specifies 59 * the interrupt-time count, in 100-nanosecond units, at the last system 60 * wake time. 61 */ 62 int LastWakeTime = 14; 63 64 /** 65 * The {@code lpInBuffer} parameter must be {@code NULL}; otherwise, the 66 * function returns {@link WinError#ERROR_INVALID_PARAMETER}. 67 * <p> 68 * The {@code lpOutputBuffer} buffer receives one 69 * {@link com.sun.jna.platform.win32.WinNT.PROCESSOR_POWER_INFORMATION} 70 * structure for each processor that is installed on the system. Use the 71 * {@link Kernel32#GetSystemInfo} function to retrieve the number of 72 * processors, which will be the number of logical processors on the 73 * current Processor Group. 74 */ 75 int ProcessorInformation = 11; 76 77 /** 78 * The {@code lpInBuffer} parameter must be {@code NULL}; otherwise, the 79 * function returns {@link WinError#ERROR_INVALID_PARAMETER}. 80 * <p> 81 * The {@code lpOutputBuffer} buffer receives a 82 * {@link com.sun.jna.platform.win32.WinNT.SYSTEM_BATTERY_STATE} 83 * structure containing information about the current system battery. 84 */ 85 int SystemBatteryState = 5; 86 87 /** 88 * The {@code lpInBuffer} parameter must be {@code NULL} otherwise, the 89 * function returns {@link WinError#ERROR_INVALID_PARAMETER}. 90 * <p> 91 * The {@code lpOutputBuffer} buffer receives a 92 * {@link com.sun.jna.platform.win32.WinDef.ULONG} value containing the 93 * system execution state buffer. This value may contain any combination 94 * of the following values: {@link WinBase#ES_SYSTEM_REQUIRED}, 95 * {@link WinBase#ES_DISPLAY_REQUIRED}, or 96 * {@link WinBase#ES_USER_PRESENT}. For more information, see the 97 * {@link Kernel32#SetThreadExecutionState} function. 98 */ 99 int SystemExecutionState = 16; 100 101 /** 102 * The {@code lpInBuffer} parameter must be {@code NULL}; otherwise, the 103 * function returns {@link WinError#ERROR_INVALID_PARAMETER}. 104 * <p> 105 * The {@code lpOutputBuffer} buffer receives a 106 * {@link com.sun.jna.platform.win32.WinNT.SYSTEM_POWER_CAPABILITIES} structure containing the 107 * current system power capabilities. 108 * <p> 109 * This information represents the currently supported power 110 * capabilities. It may change as drivers are installed in the system. 111 * For example, installation of legacy device drivers that do not 112 * support power management disables all system sleep states. 113 */ 114 int SystemPowerCapabilities = 4; 115 116 /** 117 * The {@code lpInBuffer} parameter must be {@code NULL}; otherwise, the 118 * function returns {@link WinError#ERROR_INVALID_PARAMETER}. 119 * <p> 120 * The {@code lpOutputBuffer} buffer receives a 121 * {@link com.sun.jna.platform.win32.WinNT.SYSTEM_POWER_INFORMATION} structure. 122 * <p> 123 * Applications can use this level to retrieve information about the 124 * idleness of the system. 125 */ 126 int SystemPowerInformation = 12; 127 128 /** 129 * If {@code lpInBuffer} is not {@code NULL}, the function applies the 130 * {@link com.sun.jna.platform.win32.WinNT.SYSTEM_POWER_POLICY} values 131 * passed in {@code lpInBuffer} to the current system power policy used 132 * while the system is running on AC (utility) power. 133 * <p> 134 * The {@code lpOutputBuffer} buffer receives a 135 * {@link com.sun.jna.platform.win32.WinNT.SYSTEM_POWER_POLICY} 136 * structure containing the current system power policy used while the 137 * system is running on AC (utility) power. 138 */ 139 int SystemPowerPolicyAc = 0; 140 141 /** 142 * The {@code lpInBuffer} parameter must be {@code NULL}; otherwise, the 143 * function returns {@link WinError#ERROR_INVALID_PARAMETER}. 144 * <p> 145 * The {@code lpOutputBuffer} buffer receives a 146 * {@link com.sun.jna.platform.win32.WinNT.SYSTEM_POWER_POLICY} structure containing the current 147 * system power policy used while the system is running on AC (utility) 148 * power. 149 */ 150 int SystemPowerPolicyCurrent = 8; 151 152 /** 153 * If {@code lpInBuffer} is not {@code NULL}, the function applies the 154 * {@link com.sun.jna.platform.win32.WinNT.SYSTEM_POWER_POLICY} values 155 * passed in {@code lpInBuffer} to the current system power policy used 156 * while the system is running on battery power. 157 * <p> 158 * The {@code lpOutputBuffer} buffer receives a 159 * {@link com.sun.jna.platform.win32.WinNT.SYSTEM_POWER_POLICY} 160 * structure containing the current system power policy used while the 161 * system is running on battery power. 162 */ 163 int SystemPowerPolicyDc = 1; 164 165 /** 166 * If {@code lpInBuffer} is not {@code NULL} and the current user has 167 * sufficient privileges, the function commits or decommits the storage 168 * required to hold the hibernation image on the boot volume. 169 * <p> 170 * The lpInBuffer parameter must point to a {@code BOOLEAN} value 171 * indicating the desired request. If the value is {@code TRUE}, the 172 * hibernation file is reserved; if the value is {@code FALSE}, the 173 * hibernation file is removed. 174 */ 175 int SystemReserveHiberFile = 10; 176 } 177 178 /** 179 * Sets or retrieves power information. 180 * <p> 181 * Changes made to the current system power policy using 182 * {@link #CallNtPowerInformation} are immediate, but they are not 183 * persistent; that is, the changes are not stored as part of a power 184 * scheme. Any changes to system power policy made with 185 * {@link #CallNtPowerInformation} may be overwritten by changes to a 186 * policy scheme made by the user in the Power Options control panel 187 * program, or by subsequent calls to {@code WritePwrScheme}, 188 * {@code SetActivePwrScheme}, or other power scheme functions. 189 * 190 * @param informationLevel 191 * The information level requested. This value indicates the 192 * specific power information to be set or retrieved. This 193 * parameter must be one of the following 194 * {@link POWER_INFORMATION_LEVEL} enumeration type values: 195 * {@link POWER_INFORMATION_LEVEL#LastSleepTime}, 196 * {@link POWER_INFORMATION_LEVEL#LastWakeTime}, 197 * {@link POWER_INFORMATION_LEVEL#ProcessorInformation}, 198 * {@link POWER_INFORMATION_LEVEL#SystemBatteryState}, 199 * {@link POWER_INFORMATION_LEVEL#SystemExecutionState}, 200 * {@link POWER_INFORMATION_LEVEL#SystemPowerCapabilities}, 201 * {@link POWER_INFORMATION_LEVEL#SystemPowerInformation}, 202 * {@link POWER_INFORMATION_LEVEL#SystemPowerPolicyAc}, 203 * {@link POWER_INFORMATION_LEVEL#SystemPowerPolicyCurrent}, 204 * {@link POWER_INFORMATION_LEVEL#SystemPowerPolicyDc}, or 205 * {@link POWER_INFORMATION_LEVEL#SystemReserveHiberFile}. 206 * @param lpInputBuffer 207 * A pointer to an optional input buffer. The data type of this 208 * buffer depends on the information level requested in the 209 * {@code informationLevel} parameter. 210 * @param nInputBufferSize 211 * The size of the input buffer, in bytes. 212 * @param lpOutputBuffer 213 * A pointer to an optional output buffer. The data type of this 214 * buffer depends on the information level requested in the 215 * {@code informationLevel} parameter. If the buffer is too small 216 * to contain the information, the function returns 217 * {@link NTStatus#STATUS_BUFFER_TOO_SMALL}. 218 * @param nOutputBufferSize 219 * The size of the output buffer, in bytes. Depending on the 220 * information level requested, this may be a variably sized 221 * buffer. 222 * @return If the function succeeds, the return value is 223 * {@link NTStatus#STATUS_SUCCESS}. If the function fails, the 224 * return value can be one the following status codes: 225 * {@link NTStatus#STATUS_BUFFER_TOO_SMALL} if the output buffer is 226 * of insufficient size to contain the data to be returned. 227 * {@link NTStatus#STATUS_ACCESS_DENIED} if the caller had 228 * insufficient access rights to perform the requested action. 229 */ CallNtPowerInformation(int informationLevel, Pointer lpInputBuffer, int nInputBufferSize, Pointer lpOutputBuffer, int nOutputBufferSize)230 int CallNtPowerInformation(int informationLevel, Pointer lpInputBuffer, int nInputBufferSize, 231 Pointer lpOutputBuffer, int nOutputBufferSize); 232 } 233 234