Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add CallNTPowerInformation function #1065

Merged
merged 6 commits into from
Feb 17, 2019
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 21 additions & 21 deletions contrib/platform/src/com/sun/jna/platform/win32/PowrProf.java
Original file line number Diff line number Diff line change
Expand Up @@ -55,21 +55,21 @@ public interface POWER_INFORMATION_LEVEL {
/**
* Contains information about the current state of the system battery.
*/
@FieldOrder({ "acOnLine", "batteryPresent", "charging", "discharging", "spare1", "tag", "maxCapacity",
"remainingCapacity", "rate", "estimatedTime", "defaultAlert1", "defaultAlert2" })
@FieldOrder({ "AcOnLine", "BatteryPresent", "Charging", "Discharging", "Spare1", "Tag", "MaxCapacity",
"RemainingCapacity", "Rate", "EstimatedTime", "DefaultAlert1", "DefaultAlert2" })
class SystemBatteryState extends Structure {
public byte acOnLine;
public byte batteryPresent;
public byte charging;
public byte discharging;
public byte[] spare1 = new byte[3];
public byte tag;
public int maxCapacity;
public int remainingCapacity;
public int rate;
public int estimatedTime;
public int defaultAlert1;
public int defaultAlert2;
public byte AcOnLine;
public byte BatteryPresent;
public byte Charging;
public byte Discharging;
public byte[] Spare1 = new byte[3];
public byte Tag;
public int MaxCapacity;
public int RemainingCapacity;
public int Rate;
public int EstimatedTime;
public int DefaultAlert1;
public int DefaultAlert2;

public SystemBatteryState(Pointer p) {
super(p);
Expand All @@ -84,14 +84,14 @@ public SystemBatteryState() {
/**
* Contains information about a processor.
*/
@FieldOrder({ "number", "maxMhz", "currentMhz", "mhzLimit", "maxIdleState", "currentIdleState" })
@FieldOrder({ "Number", "MaxMhz", "CurrentMhz", "MhzLimit", "MaxIdleState", "CurrentIdleState" })
class ProcessorPowerInformation extends Structure {
public int number;
public int maxMhz;
public int currentMhz;
public int mhzLimit;
public int maxIdleState;
public int currentIdleState;
public int Number;
public int MaxMhz;
public int CurrentMhz;
public int MhzLimit;
public int MaxIdleState;
public int CurrentIdleState;

public ProcessorPowerInformation(Pointer p) {
super(p);
Expand Down
15 changes: 10 additions & 5 deletions contrib/platform/test/com/sun/jna/platform/win32/PowrProfTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,11 @@
public class PowrProfTest extends TestCase {

public void testProcessorPowerInformation() {
// MSDN docs for CallNTPowerInformation specify use of GetSystemInfo to
// count logical processors for this InformationLevel. The GetSystemInfo
// function only counts logical processors on the current Processor
// Group. However, the array of results from ProcessorPowerInformation
// also are restricted to the current Processor Group.
dbwiddis marked this conversation as resolved.
Show resolved Hide resolved
SYSTEM_INFO info = new SYSTEM_INFO();
Kernel32.INSTANCE.GetSystemInfo(info);
int numProcs = info.dwNumberOfProcessors.intValue();
Expand All @@ -47,7 +52,7 @@ public void testProcessorPowerInformation() {
mem, bufferSize));
for (int i = 0; i < freqs.length; i++) {
ppi = new ProcessorPowerInformation(mem.share(i * (long) ppi.size()));
assertTrue(ppi.currentMhz <= ppi.maxMhz);
assertTrue(ppi.CurrentMhz <= ppi.MaxMhz);
}
}

Expand All @@ -57,11 +62,11 @@ public void testSystemBatteryState() {
assertEquals(NTStatus.STATUS_SUCCESS,
PowrProf.INSTANCE.CallNtPowerInformation(POWER_INFORMATION_LEVEL.SYSTEM_BATTERY_STATE, null, 0, mem, size));
SystemBatteryState batteryState = new SystemBatteryState(mem);
if (batteryState.batteryPresent > 0) {
if (batteryState.acOnLine == 0 && batteryState.charging == 0 && batteryState.discharging > 0) {
assertTrue(batteryState.estimatedTime >= 0);
if (batteryState.BatteryPresent > 0) {
if (batteryState.AcOnLine == 0 && batteryState.Charging == 0 && batteryState.Discharging > 0) {
assertTrue(batteryState.EstimatedTime >= 0);
}
assertTrue(batteryState.remainingCapacity <= batteryState.maxCapacity);
assertTrue(batteryState.RemainingCapacity <= batteryState.MaxCapacity);
}
}
}