Skip to content

Commit

Permalink
JNA 5.9.0 (#1701)
Browse files Browse the repository at this point in the history
  • Loading branch information
dbwiddis committed Aug 22, 2021
1 parent 9a75c31 commit d535f0e
Show file tree
Hide file tree
Showing 17 changed files with 68 additions and 239 deletions.
2 changes: 1 addition & 1 deletion oshi-core/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
<properties>
<!-- Users of the Spring Boot Starter Parent should include this property
in their POM -->
<jna.version>5.8.0</jna.version>
<jna.version>5.9.0</jna.version>
<main.basedir>${project.parent.basedir}</main.basedir>
<automatic.module.name>com.github.oshi</automatic.module.name>
</properties>
Expand Down
10 changes: 5 additions & 5 deletions oshi-core/src/main/java/oshi/driver/mac/net/NetStat.java
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
import com.sun.jna.platform.mac.SystemB;
import com.sun.jna.platform.mac.SystemB.IFmsgHdr;
import com.sun.jna.platform.mac.SystemB.IFmsgHdr2;
import com.sun.jna.ptr.IntByReference;
import com.sun.jna.platform.unix.LibCAPI.size_t;

import oshi.annotation.concurrent.Immutable;
import oshi.annotation.concurrent.ThreadSafe;
Expand Down Expand Up @@ -71,13 +71,13 @@ public static Map<Integer, IFdata> queryIFdata(int index) {
Map<Integer, IFdata> data = new HashMap<>();
// Get buffer of all interface information
int[] mib = { CTL_NET, PF_ROUTE, 0, 0, NET_RT_IFLIST2, 0 };
IntByReference len = new IntByReference();
if (0 != SystemB.INSTANCE.sysctl(mib, 6, null, len, null, 0)) {
size_t.ByReference len = new size_t.ByReference();
if (0 != SystemB.INSTANCE.sysctl(mib, 6, null, len, null, size_t.ZERO)) {
LOG.error("Didn't get buffer length for IFLIST2");
return data;
}
Memory buf = new Memory(len.getValue());
if (0 != SystemB.INSTANCE.sysctl(mib, 6, buf, len, null, 0)) {
Memory buf = new Memory(len.longValue());
if (0 != SystemB.INSTANCE.sysctl(mib, 6, buf, len, null, size_t.ZERO)) {
LOG.error("Didn't get buffer for IFLIST2");
return data;
}
Expand Down
14 changes: 7 additions & 7 deletions oshi-core/src/main/java/oshi/driver/windows/DeviceTree.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,15 +23,15 @@
*/
package oshi.driver.windows;

import static com.sun.jna.platform.win32.SetupApi.DIGCF_DEVICEINTERFACE; // NOSONAR squid:S1191
import static com.sun.jna.platform.win32.Cfgmgr32.CM_DRP_CLASS; // NOSONAR squid:S1191
import static com.sun.jna.platform.win32.Cfgmgr32.CM_DRP_DEVICEDESC;
import static com.sun.jna.platform.win32.Cfgmgr32.CM_DRP_FRIENDLYNAME;
import static com.sun.jna.platform.win32.Cfgmgr32.CM_DRP_MFG;
import static com.sun.jna.platform.win32.Cfgmgr32.CM_DRP_SERVICE;
import static com.sun.jna.platform.win32.SetupApi.DIGCF_DEVICEINTERFACE;
import static com.sun.jna.platform.win32.SetupApi.DIGCF_PRESENT;
import static com.sun.jna.platform.win32.WinBase.INVALID_HANDLE_VALUE;
import static com.sun.jna.platform.win32.WinError.ERROR_SUCCESS;
import static oshi.jna.platform.windows.Cfgmgr32.CM_DRP_CLASS;
import static oshi.jna.platform.windows.Cfgmgr32.CM_DRP_DEVICEDESC;
import static oshi.jna.platform.windows.Cfgmgr32.CM_DRP_FRIENDLYNAME;
import static oshi.jna.platform.windows.Cfgmgr32.CM_DRP_MFG;
import static oshi.jna.platform.windows.Cfgmgr32.CM_DRP_SERVICE;

import java.util.ArrayDeque;
import java.util.HashMap;
Expand All @@ -41,6 +41,7 @@
import java.util.stream.Collectors;

import com.sun.jna.Memory;
import com.sun.jna.platform.win32.Cfgmgr32;
import com.sun.jna.platform.win32.Cfgmgr32Util;
import com.sun.jna.platform.win32.Guid.GUID;
import com.sun.jna.platform.win32.SetupApi;
Expand All @@ -49,7 +50,6 @@
import com.sun.jna.ptr.IntByReference;

import oshi.annotation.concurrent.ThreadSafe;
import oshi.jna.platform.windows.Cfgmgr32;
import oshi.util.tuples.Quintet;

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@

import oshi.annotation.concurrent.ThreadSafe;
import oshi.hardware.common.AbstractCentralProcessor;
import oshi.jna.platform.unix.NativeSizeTByReference;
import oshi.jna.platform.unix.freebsd.FreeBsdLibc;
import oshi.jna.platform.unix.freebsd.FreeBsdLibc.CpTime;
import oshi.util.ExecutingCommand;
Expand Down Expand Up @@ -271,7 +270,7 @@ public long[][] queryProcessorCpuLoadTicks() {
Pointer p = new Memory(arraySize);
String name = "kern.cp_times";
// Fetch
if (0 != FreeBsdLibc.INSTANCE.sysctlbyname(name, p, new NativeSizeTByReference(new size_t(arraySize)), null,
if (0 != FreeBsdLibc.INSTANCE.sysctlbyname(name, p, new size_t.ByReference(new size_t(arraySize)), null,
size_t.ZERO)) {
LOG.error("Failed sysctl call: {}, Error code: {}", name, Native.getLastError());
return ticks;
Expand Down Expand Up @@ -317,8 +316,8 @@ private static String getProcessorIDfromDmiDecode(long processorID) {
@Override
public long queryContextSwitches() {
String name = "vm.stats.sys.v_swtch";
NativeSizeTByReference size = new NativeSizeTByReference(new size_t(FreeBsdLibc.INT_SIZE));
Pointer p = new Memory(size.getValue().longValue());
size_t.ByReference size = new size_t.ByReference(new size_t(FreeBsdLibc.INT_SIZE));
Pointer p = new Memory(size.longValue());
if (0 != FreeBsdLibc.INSTANCE.sysctlbyname(name, p, size, null, size_t.ZERO)) {
return 0L;
}
Expand All @@ -328,8 +327,8 @@ public long queryContextSwitches() {
@Override
public long queryInterrupts() {
String name = "vm.stats.sys.v_intr";
NativeSizeTByReference size = new NativeSizeTByReference(new size_t(FreeBsdLibc.INT_SIZE));
Pointer p = new Memory(size.getValue().longValue());
size_t.ByReference size = new size_t.ByReference(new size_t(FreeBsdLibc.INT_SIZE));
Pointer p = new Memory(size.longValue());
if (0 != FreeBsdLibc.INSTANCE.sysctlbyname(name, p, size, null, size_t.ZERO)) {
return 0L;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@

import oshi.annotation.concurrent.ThreadSafe;
import oshi.hardware.common.AbstractSensors;
import oshi.jna.platform.unix.NativeSizeTByReference;
import oshi.jna.platform.unix.freebsd.FreeBsdLibc;

/**
Expand All @@ -51,8 +50,8 @@ public double queryCpuTemperature() {
*/
private static double queryKldloadCoretemp() {
String name = "dev.cpu.%d.temperature";
NativeSizeTByReference size = new NativeSizeTByReference(new size_t(FreeBsdLibc.INT_SIZE));
Pointer p = new Memory(size.getValue().longValue());
size_t.ByReference size = new size_t.ByReference(new size_t(FreeBsdLibc.INT_SIZE));
Pointer p = new Memory(size.longValue());
int cpu = 0;
double sumTemp = 0d;
while (0 == FreeBsdLibc.INSTANCE.sysctlbyname(String.format(name, cpu), p, size, null, size_t.ZERO)) {
Expand Down
8 changes: 0 additions & 8 deletions oshi-core/src/main/java/oshi/jna/platform/mac/SystemB.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,11 @@
package oshi.jna.platform.mac;

import com.sun.jna.Native; // NOSONAR squid:S1191
import com.sun.jna.Pointer;
import com.sun.jna.Structure;
import com.sun.jna.Structure.FieldOrder;
import com.sun.jna.Union;

import oshi.jna.platform.unix.CLibrary;
import oshi.jna.platform.unix.NativeSizeTByReference;

/**
* System class. This class should be considered non-API as it may be removed
Expand Down Expand Up @@ -187,10 +185,4 @@ class Pri extends Union {
MacUtmpx getutxent();

int proc_pidfdinfo(int pid, int fd, int flavor, Structure buffer, int buffersize);

int sysctl(int[] name, int namelen, Pointer oldp, NativeSizeTByReference oldlenp, Pointer newp, size_t newlen);

int sysctlbyname(String name, Pointer oldp, NativeSizeTByReference oldlenp, Pointer newp, size_t newlen);

int sysctlnametomib(String name, Pointer mibp, NativeSizeTByReference sizep);
}
6 changes: 3 additions & 3 deletions oshi-core/src/main/java/oshi/jna/platform/unix/CLibrary.java
Original file line number Diff line number Diff line change
Expand Up @@ -227,7 +227,7 @@ class BsdIp6stat {
* Size of information to be written
* @return 0 on success; sets errno on failure
*/
int sysctl(int[] name, int namelen, Pointer oldp, NativeSizeTByReference oldlenp, Pointer newp, size_t newlen);
int sysctl(int[] name, int namelen, Pointer oldp, size_t.ByReference oldlenp, Pointer newp, size_t newlen);

/**
* The sysctlbyname() function accepts an ASCII representation of the name and
Expand All @@ -246,7 +246,7 @@ class BsdIp6stat {
* Size of information to be written
* @return 0 on success; sets errno on failure
*/
int sysctlbyname(String name, Pointer oldp, NativeSizeTByReference oldlenp, Pointer newp, size_t newlen);
int sysctlbyname(String name, Pointer oldp, size_t.ByReference oldlenp, Pointer newp, size_t newlen);

/**
* The sysctlnametomib() function accepts an ASCII representation of the name,
Expand Down Expand Up @@ -276,7 +276,7 @@ class BsdIp6stat {
* number of entries copied.
* @return 0 on success; sets errno on failure
*/
int sysctlnametomib(String name, Pointer mibp, NativeSizeTByReference sizep);
int sysctlnametomib(String name, Pointer mibp, size_t.ByReference sizep);

int open(String absolutePath, int i);

Expand Down

This file was deleted.

43 changes: 0 additions & 43 deletions oshi-core/src/main/java/oshi/jna/platform/windows/Cfgmgr32.java

This file was deleted.

37 changes: 0 additions & 37 deletions oshi-core/src/main/java/oshi/jna/platform/windows/Shell32.java

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,6 @@
import oshi.annotation.concurrent.ThreadSafe;
import oshi.driver.mac.ThreadInfo;
import oshi.driver.mac.ThreadInfo.ThreadStats;
import oshi.jna.platform.unix.NativeSizeTByReference;
import oshi.software.common.AbstractOSProcess;
import oshi.software.os.OSThread;
import oshi.util.platform.mac.SysctlUtil;
Expand Down Expand Up @@ -166,9 +165,9 @@ private Pair<List<String>, Map<String, String>> queryArgsAndEnvironment() {
// Allocate memory for arguments
Memory procargs = new Memory(ARGMAX);
procargs.clear();
NativeSizeTByReference size = new NativeSizeTByReference(new size_t(ARGMAX));
size_t.ByReference size = new size_t.ByReference(ARGMAX);
// Fetch arguments
if (0 == oshi.jna.platform.mac.SystemB.INSTANCE.sysctl(mib, mib.length, procargs, size, null, size_t.ZERO)) {
if (0 == SystemB.INSTANCE.sysctl(mib, mib.length, procargs, size, null, size_t.ZERO)) {
// Procargs contains an int representing total # of args, followed by a
// null-terminated execpath string and then the arguments, each
// null-terminated (possible multiple consecutive nulls),
Expand All @@ -184,10 +183,10 @@ private Pair<List<String>, Map<String, String>> queryArgsAndEnvironment() {
offset += procargs.getString(offset).length();
// Iterate character by character using offset
// Build each arg and add to list
while (offset < size.getValue().longValue()) {
while (offset < size.longValue()) {
// Advance through additional nulls
while (procargs.getByte(offset) == 0) {
if (++offset >= size.getValue().longValue()) {
if (++offset >= size.longValue()) {
break;
}
}
Expand Down

0 comments on commit d535f0e

Please sign in to comment.