View Javadoc
1   /*
2    * Copyright 2022 The OSHI Project Contributors
3    * SPDX-License-Identifier: MIT
4    */
5   package oshi.jna;
6   
7   import com.sun.jna.platform.linux.LibC.Sysinfo;
8   import com.sun.jna.platform.mac.SystemB.HostCpuLoadInfo;
9   import com.sun.jna.platform.mac.SystemB.ProcTaskAllInfo;
10  import com.sun.jna.platform.mac.SystemB.ProcTaskInfo;
11  import com.sun.jna.platform.mac.SystemB.RUsageInfoV2;
12  import com.sun.jna.platform.mac.SystemB.Timeval;
13  import com.sun.jna.platform.mac.SystemB.VMStatistics;
14  import com.sun.jna.platform.mac.SystemB.VnodePathInfo;
15  import com.sun.jna.platform.mac.SystemB.XswUsage;
16  import com.sun.jna.platform.win32.IPHlpAPI.MIB_IFROW;
17  import com.sun.jna.platform.win32.IPHlpAPI.MIB_IF_ROW2;
18  import com.sun.jna.platform.win32.IPHlpAPI.MIB_TCPSTATS;
19  import com.sun.jna.platform.win32.IPHlpAPI.MIB_UDPSTATS;
20  import com.sun.jna.platform.win32.Pdh.PDH_RAW_COUNTER;
21  import com.sun.jna.platform.win32.Psapi.PERFORMANCE_INFORMATION;
22  import com.sun.jna.platform.win32.SetupApi.SP_DEVICE_INTERFACE_DATA;
23  import com.sun.jna.platform.win32.SetupApi.SP_DEVINFO_DATA;
24  import com.sun.jna.platform.win32.WinBase.SYSTEM_INFO;
25  
26  import oshi.util.Util;
27  
28  /**
29   * Wrapper classes for JNA clases which extend {@link com.sun.jna.Structure} intended for use in try-with-resources
30   * blocks.
31   */
32  public interface Struct {
33      /*
34       * Linux
35       */
36      class CloseableSysinfo extends Sysinfo implements AutoCloseable {
37          @Override
38          public void close() {
39              Util.freeMemory(getPointer());
40          }
41      }
42  
43      /*
44       * macOS
45       */
46  
47      class CloseableHostCpuLoadInfo extends HostCpuLoadInfo implements AutoCloseable {
48          @Override
49          public void close() {
50              Util.freeMemory(getPointer());
51          }
52      }
53  
54      class CloseableProcTaskInfo extends ProcTaskInfo implements AutoCloseable {
55          @Override
56          public void close() {
57              Util.freeMemory(getPointer());
58          }
59      }
60  
61      class CloseableProcTaskAllInfo extends ProcTaskAllInfo implements AutoCloseable {
62          @Override
63          public void close() {
64              Util.freeMemory(getPointer());
65          }
66      }
67  
68      class CloseableRUsageInfoV2 extends RUsageInfoV2 implements AutoCloseable {
69          @Override
70          public void close() {
71              Util.freeMemory(getPointer());
72          }
73      }
74  
75      class CloseableTimeval extends Timeval implements AutoCloseable {
76          @Override
77          public void close() {
78              Util.freeMemory(getPointer());
79          }
80      }
81  
82      class CloseableVMStatistics extends VMStatistics implements AutoCloseable {
83          @Override
84          public void close() {
85              Util.freeMemory(getPointer());
86          }
87      }
88  
89      class CloseableVnodePathInfo extends VnodePathInfo implements AutoCloseable {
90          @Override
91          public void close() {
92              Util.freeMemory(getPointer());
93          }
94      }
95  
96      class CloseableXswUsage extends XswUsage implements AutoCloseable {
97          @Override
98          public void close() {
99              Util.freeMemory(getPointer());
100         }
101     }
102 
103     /*
104      * Windows
105      */
106 
107     class CloseableMibIfRow extends MIB_IFROW implements AutoCloseable {
108         @Override
109         public void close() {
110             Util.freeMemory(getPointer());
111         }
112     }
113 
114     class CloseableMibIfRow2 extends MIB_IF_ROW2 implements AutoCloseable {
115         @Override
116         public void close() {
117             Util.freeMemory(getPointer());
118         }
119     }
120 
121     class CloseableMibTcpStats extends MIB_TCPSTATS implements AutoCloseable {
122         @Override
123         public void close() {
124             Util.freeMemory(getPointer());
125         }
126     }
127 
128     class CloseableMibUdpStats extends MIB_UDPSTATS implements AutoCloseable {
129         @Override
130         public void close() {
131             Util.freeMemory(getPointer());
132         }
133     }
134 
135     class CloseablePdhRawCounter extends PDH_RAW_COUNTER implements AutoCloseable {
136         @Override
137         public void close() {
138             Util.freeMemory(getPointer());
139         }
140     }
141 
142     class CloseablePerformanceInformation extends PERFORMANCE_INFORMATION implements AutoCloseable {
143         @Override
144         public void close() {
145             Util.freeMemory(getPointer());
146         }
147     }
148 
149     class CloseableSpDeviceInterfaceData extends SP_DEVICE_INTERFACE_DATA implements AutoCloseable {
150         @Override
151         public void close() {
152             Util.freeMemory(getPointer());
153         }
154     }
155 
156     class CloseableSpDevinfoData extends SP_DEVINFO_DATA implements AutoCloseable {
157         @Override
158         public void close() {
159             Util.freeMemory(getPointer());
160         }
161     }
162 
163     class CloseableSystemInfo extends SYSTEM_INFO implements AutoCloseable {
164         @Override
165         public void close() {
166             Util.freeMemory(getPointer());
167         }
168     }
169 }