Skip to content

Commit a3d871c

Browse files
committed
Add host_processor_info to Mac System B library
1 parent a1c94fe commit a3d871c

File tree

3 files changed

+45
-0
lines changed

3 files changed

+45
-0
lines changed

CHANGES.md

+1
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ Next Release (4.2.1)
88
Features
99
--------
1010
* [#510](https://github.com/java-native-access/jna/pull/510): Added `GetCommState`, `GetCommTimeouts` `SetCommState` and `SetCommTimeouts` to `com.sun.jna.platform.win32.Kernel32`. Added `DCB` structure to `com.sun.jna.platform.win32.WinBase` - [@MBollig](https://github.com/MBollig)
11+
* [#514](https://github.com/java-native-access/jna/pull/514): Added `host_processor_info` to `com.sun.jna.platform.mac.SystemB` - [@dbwiddis](https://github.com/dbwiddis)
1112

1213
Bug Fixes
1314
---------

contrib/platform/src/com/sun/jna/platform/mac/SystemB.java

+24
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
import com.sun.jna.Structure;
2727
import com.sun.jna.ptr.IntByReference;
2828
import com.sun.jna.ptr.LongByReference;
29+
import com.sun.jna.ptr.PointerByReference;
2930

3031
/**
3132
* Author: Daniel Widdis Date: 6/5/15
@@ -50,6 +51,10 @@ public interface SystemB extends Library {
5051
static int CPU_STATE_IDLE = 2;
5152
static int CPU_STATE_NICE = 3;
5253

54+
// host_processor_info() flavor
55+
static int PROCESSOR_BASIC_INFO = 1;
56+
static int PROCESSOR_CPU_LOAD_INFO = 2;
57+
5358
// Data size
5459
static int UINT64_SIZE = Native.getNativeSize(long.class);
5560
static int INT_SIZE = Native.getNativeSize(int.class);
@@ -304,4 +309,23 @@ int sysctlbyname(String name, Pointer oldp, IntByReference oldlenp,
304309
* @return 0 on success; sets errno on failure
305310
*/
306311
int sysctlnametomib(String name, Pointer mibp, IntByReference size);
312+
313+
/**
314+
* The host_processor_info function returns information about processors.
315+
*
316+
* @param machPort
317+
* The control port for the host for which information is to be
318+
* obtained.
319+
* @param flavor
320+
* The type of information requested.
321+
* @param procCount
322+
* Pointer to the number of processors
323+
* @param procInfo
324+
* Pointer to the structure corresponding to the requested flavor
325+
* @param procInfoCount
326+
* Pointer to number of elements in the returned structure
327+
* @return 0 on success; sets errno on failure
328+
*/
329+
int host_processor_info(int machPort, int flavor, IntByReference procCount,
330+
PointerByReference procInfo, IntByReference procInfoCount);
307331
}

contrib/platform/test/com/sun/jna/platform/mac/SystemBTest.java

+20
Original file line numberDiff line numberDiff line change
@@ -17,16 +17,19 @@
1717
package com.sun.jna.platform.mac;
1818

1919
import junit.framework.TestCase;
20+
2021
import com.sun.jna.platform.mac.SystemB.HostCpuLoadInfo;
2122
import com.sun.jna.platform.mac.SystemB.HostLoadInfo;
2223
import com.sun.jna.platform.mac.SystemB.VMStatistics;
2324
import com.sun.jna.platform.mac.SystemB.VMStatistics64;
2425

2526
import com.sun.jna.Memory;
27+
import com.sun.jna.Native;
2628
import com.sun.jna.Platform;
2729
import com.sun.jna.Pointer;
2830
import com.sun.jna.ptr.IntByReference;
2931
import com.sun.jna.ptr.LongByReference;
32+
import com.sun.jna.ptr.PointerByReference;
3033

3134
/**
3235
* Exercise the {@link SystemB} class.
@@ -134,6 +137,23 @@ SystemB.HOST_CPU_LOAD_INFO, hostLoadInfo, new IntByReference(
134137
assertTrue(hostLoadInfo.avenrun[0] > 0);
135138
}
136139

140+
public void testHostProcessorInfo() {
141+
int machPort = SystemB.INSTANCE.mach_host_self();
142+
assertTrue(machPort > 0);
143+
144+
IntByReference procCount = new IntByReference();
145+
PointerByReference procCpuLoadInfo = new PointerByReference();
146+
IntByReference procInfoCount = new IntByReference();
147+
int ret = SystemB.INSTANCE.host_processor_info(machPort,
148+
SystemB.PROCESSOR_CPU_LOAD_INFO, procCount, procCpuLoadInfo,
149+
procInfoCount);
150+
assertEquals(ret, 0);
151+
152+
assertTrue(procCount.getValue() > 0);
153+
assertEquals(procCpuLoadInfo.getValue().getIntArray(0,
154+
procInfoCount.getValue()).length, procInfoCount.getValue());
155+
}
156+
137157
public static void main(java.lang.String[] argList) {
138158
junit.textui.TestRunner.run(SystemBTest.class);
139159
}

0 commit comments

Comments
 (0)