1 ! Copyright (C) 2021 Doug Coleman.
2 ! See http://factorcode.org/license.txt for BSD license.
3 USING: alien.c-types alien.syntax classes.struct kernel math
4 specialized-arrays system-info windows.errors windows.types
10 TYPEDEF: UINT NTSTATUS
11 TYPEDEF: void* PHPOWERNOTIFY
13 CONSTANT: STATUS_SUCCESS 0
15 ENUM: SYSTEM_POWER_STATE
16 PowerSystemUnspecified
24 TYPEDEF: SYSTEM_POWER_STATE* PSYSTEM_POWER_STATE
26 ENUM: POWER_PLATFORM_ROLE
27 PlatformRoleUnspecified
30 PlatformRoleWorkstation
31 PlatformRoleEnterpriseServer
32 PlatformRoleSOHOServer
33 PlatformRoleAppliancePC
34 PlatformRolePerformanceServer
37 TYPEDEF: POWER_PLATFORM_ROLE* PPOWER_PLATFORM_ROLE
39 ENUM: POWER_INFORMATION_LEVEL
44 SystemPowerCapabilities
46 SystemPowerStateHandler
48 SystemPowerPolicyCurrent
49 AdministratorPowerPolicy
50 SystemReserveHiberFile
52 SystemPowerInformation
53 ProcessorStateHandler2
57 SystemPowerStateNotifyHandler
58 ProcessorPowerPolicyAc
59 ProcessorPowerPolicyDc
60 VerifyProcessorPowerPolicyAc
61 VerifyProcessorPowerPolicyDc
62 ProcessorPowerPolicyCurrent
63 SystemPowerStateLogging
64 SystemPowerLoggingEntry
66 NotifyUserPowerSetting
67 PowerInformationLevelUnused0
68 SystemMonitorHiberBootPowerOff
70 TraceApplicationPowerMessage
71 TraceApplicationPowerMessageEnd
76 SystemHiberFileInformation
77 TraceServicePowerMessage
79 PowerShutdownNotification
86 ProcessorInformationEx
87 NotifyUserModeLegacyPowerEvent
96 LogicalProcessorIdling
98 PowerSettingNotificationName
102 SessionConnectNotification
109 FirmwareTableInformationRegistered
110 SetShutdownSelectedTime
111 SuspendResumeInvocation
112 PlmPowerRequestCreate
116 LastResumePerformance
118 ExitLatencySamplingPercentage
119 RegisterSpmPowerSettings
123 SystemBatteryStatePrecise
125 PowerRequestActionInternal
127 PowerInformationInternal
130 PhysicalPowerButtonPress
131 QueryPotentialDripsConstraint
134 UpdateBlackBoxRecorder
135 SessionAllowExternalDmaDevices
136 SendSuspendResumeNotification
137 PowerInformationLevelMaximum ;
139 STRUCT: BATTERY_REPORTING_SCALE
140 { Granularity DWORD }
142 TYPEDEF: BATTERY_REPORTING_SCALE* PBATTERY_REPORTING_SCALE
145 STRUCT: PROCESSOR_POWER_INFORMATION
150 { MaxIdleState ULONG }
151 { CurrentIdleState ULONG } ;
152 TYPEDEF: PROCESSOR_POWER_INFORMATION* PPROCESSOR_POWER_INFORMATION
154 STRUCT: SYSTEM_POWER_CAPABILITIES
155 { PowerButtonPresent BOOLEAN }
156 { SleepButtonPresent BOOLEAN }
157 { LidPresent BOOLEAN }
163 { HiberFilePresent BOOLEAN }
165 { VideoDimPresent BOOLEAN }
166 { ApmPresent BOOLEAN }
167 { UpsPresent BOOLEAN }
168 { ThermalControl BOOLEAN }
169 { ProcessorThrottle BOOLEAN }
170 { ProcessorMinThrottle BYTE }
171 { ProcessorThrottleScale BYTE }
173 { ProcessorMaxThrottle BYTE }
174 { FastSystemS4 BOOLEAN }
175 { Hiberboot BOOLEAN }
176 { WakeAlarmPresent BOOLEAN }
178 { DiskSpinDown BOOLEAN }
180 { HiberFileType BYTE }
181 { AoAcConnectivitySupported BOOLEAN }
185 { SystemBatteriesPresent BOOLEAN }
186 { BatteriesAreShortTerm BOOLEAN }
187 { BatteryScale BATTERY_REPORTING_SCALE[3] }
188 { AcOnLineWake SYSTEM_POWER_STATE }
189 { SoftLidWake SYSTEM_POWER_STATE }
190 { RtcWake SYSTEM_POWER_STATE }
191 { MinDeviceWakeState SYSTEM_POWER_STATE }
192 { DefaultLowLatencyWake SYSTEM_POWER_STATE } ;
193 TYPEDEF: SYSTEM_POWER_CAPABILITIES* PSYSTEM_POWER_CAPABILITIES
195 STRUCT: SYSTEM_BATTERY_STATE
197 { BatteryPresent BOOLEAN }
199 { Discharging BOOLEAN }
200 { Spare1 BOOLEAN[3] }
202 { MaxCapacity DWORD }
203 { RemainingCapacity DWORD }
205 { EstimatedTime DWORD }
206 { DefaultAlert1 DWORD }
207 { DefaultAlert2 DWORD } ;
208 TYPEDEF: SYSTEM_BATTERY_STATE* PSYSTEM_BATTERY_STATE
210 STRUCT: SYSTEM_POWER_INFORMATION
211 { MaxIdlenessAllowed ULONG }
213 { TimeRemaining ULONG }
214 { CoolingMode UCHAR } ;
215 TYPEDEF: SYSTEM_POWER_INFORMATION* PSYSTEM_POWER_INFORMATION
218 SPECIALIZED-ARRAY: PROCESSOR_POWER_INFORMATION
220 FUNCTION: NTSTATUS CallNtPowerInformation (
221 POWER_INFORMATION_LEVEL InformationLevel
223 ULONG InputBufferLength,
225 ULONG OutputBufferLength
228 FUNCTION: BOOLEAN GetPwrCapabilities (
229 PSYSTEM_POWER_CAPABILITIES lpspc
232 FUNCTION: POWER_PLATFORM_ROLE PowerDeterminePlatformRoleEx (
235 FUNCTION: DWORD PowerRegisterSuspendResumeNotification (
238 PHPOWERNOTIFY RegistrationHandle
240 FUNCTION: DWORD PowerUnregisterSuspendResumeNotification (
241 HPOWERNOTIFY RegistrationHandle
244 : get-processor-power-information ( -- structs )
247 cpus <PROCESSOR_POWER_INFORMATION-array>
248 PROCESSOR_POWER_INFORMATION heap-size cpus *
250 CallNtPowerInformation win32-error=0/f
253 : get-power-capabilities ( -- struct )
254 SYSTEM_POWER_CAPABILITIES <struct>
255 [ GetPwrCapabilities win32-error=0/f ] keep ;