View Javadoc
1   /*
2    * Copyright 2016-2022 The OSHI Project Contributors
3    * SPDX-License-Identifier: MIT
4    */
5   package oshi.jna.platform.windows;
6   
7   import com.sun.jna.Native;
8   import com.sun.jna.Pointer;
9   import com.sun.jna.Structure;
10  import com.sun.jna.Structure.FieldOrder;
11  
12  import oshi.util.Util;
13  
14  /**
15   * Power profile stats. This class should be considered non-API as it may be removed if/when its code is incorporated
16   * into the JNA project.
17   */
18  public interface PowrProf extends com.sun.jna.platform.win32.PowrProf {
19      /** Constant <code>INSTANCE</code> */
20      PowrProf INSTANCE = Native.load("PowrProf", PowrProf.class);
21  
22      /**
23       * Contains information about the current state of the system battery.
24       */
25      @FieldOrder({ "acOnLine", "batteryPresent", "charging", "discharging", "spare1", "tag", "maxCapacity",
26              "remainingCapacity", "rate", "estimatedTime", "defaultAlert1", "defaultAlert2" })
27      class SystemBatteryState extends Structure implements AutoCloseable {
28          public byte acOnLine;
29          public byte batteryPresent;
30          public byte charging;
31          public byte discharging;
32          public byte[] spare1 = new byte[3];
33          public byte tag;
34          public int maxCapacity;
35          public int remainingCapacity;
36          public int rate;
37          public int estimatedTime;
38          public int defaultAlert1;
39          public int defaultAlert2;
40  
41          public SystemBatteryState(Pointer p) {
42              super(p);
43              read();
44          }
45  
46          public SystemBatteryState() {
47              super();
48          }
49  
50          @Override
51          public void close() {
52              Util.freeMemory(getPointer());
53          }
54      }
55  
56      /**
57       * Contains information about a processor.
58       */
59      @FieldOrder({ "number", "maxMhz", "currentMhz", "mhzLimit", "maxIdleState", "currentIdleState" })
60      class ProcessorPowerInformation extends Structure {
61          public int number;
62          public int maxMhz;
63          public int currentMhz;
64          public int mhzLimit;
65          public int maxIdleState;
66          public int currentIdleState;
67  
68          public ProcessorPowerInformation(Pointer p) {
69              super(p);
70              read();
71          }
72  
73          public ProcessorPowerInformation() {
74              super();
75          }
76      }
77  
78      // MOVE?
79      @FieldOrder({ "BatteryTag", "InformationLevel", "AtRate" })
80      class BATTERY_QUERY_INFORMATION extends Structure implements AutoCloseable {
81          public int BatteryTag;
82          public int InformationLevel;
83          public int AtRate;
84  
85          @Override
86          public void close() {
87              Util.freeMemory(getPointer());
88          }
89      }
90  
91      enum BATTERY_QUERY_INFORMATION_LEVEL {
92          BatteryInformation, BatteryGranularityInformation, BatteryTemperature, BatteryEstimatedTime, BatteryDeviceName,
93          BatteryManufactureDate, BatteryManufactureName, BatteryUniqueID, BatterySerialNumber
94      }
95  
96      @FieldOrder({ "Capabilities", "Technology", "Reserved", "Chemistry", "DesignedCapacity", "FullChargedCapacity",
97              "DefaultAlert1", "DefaultAlert2", "CriticalBias", "CycleCount" })
98      class BATTERY_INFORMATION extends Structure implements AutoCloseable {
99          public int Capabilities;
100         public byte Technology;
101         public byte[] Reserved = new byte[3];
102         public byte[] Chemistry = new byte[4];
103         public int DesignedCapacity;
104         public int FullChargedCapacity;
105         public int DefaultAlert1;
106         public int DefaultAlert2;
107         public int CriticalBias;
108         public int CycleCount;
109 
110         @Override
111         public void close() {
112             Util.freeMemory(getPointer());
113         }
114     }
115 
116     @FieldOrder({ "BatteryTag", "Timeout", "PowerState", "LowCapacity", "HighCapacity" })
117     class BATTERY_WAIT_STATUS extends Structure implements AutoCloseable {
118         public int BatteryTag;
119         public int Timeout;
120         public int PowerState;
121         public int LowCapacity;
122         public int HighCapacity;
123 
124         @Override
125         public void close() {
126             Util.freeMemory(getPointer());
127         }
128     }
129 
130     @FieldOrder({ "PowerState", "Capacity", "Voltage", "Rate" })
131     class BATTERY_STATUS extends Structure implements AutoCloseable {
132         public int PowerState;
133         public int Capacity;
134         public int Voltage;
135         public int Rate;
136 
137         @Override
138         public void close() {
139             Util.freeMemory(getPointer());
140         }
141     }
142 
143     @FieldOrder({ "Day", "Month", "Year" })
144     class BATTERY_MANUFACTURE_DATE extends Structure implements AutoCloseable {
145         public byte Day;
146         public byte Month;
147         public short Year;
148 
149         @Override
150         public void close() {
151             Util.freeMemory(getPointer());
152         }
153     }
154 }