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 host_processor_info to Mac System B library #514

Merged
merged 1 commit into from
Sep 29, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
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
1 change: 1 addition & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ Next Release (4.2.1)
Features
--------
* [#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)
* [#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)

Bug Fixes
---------
Expand Down
24 changes: 24 additions & 0 deletions contrib/platform/src/com/sun/jna/platform/mac/SystemB.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
import com.sun.jna.Structure;
import com.sun.jna.ptr.IntByReference;
import com.sun.jna.ptr.LongByReference;
import com.sun.jna.ptr.PointerByReference;

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

// host_processor_info() flavor
static int PROCESSOR_BASIC_INFO = 1;
static int PROCESSOR_CPU_LOAD_INFO = 2;

// Data size
static int UINT64_SIZE = Native.getNativeSize(long.class);
static int INT_SIZE = Native.getNativeSize(int.class);
Expand Down Expand Up @@ -304,4 +309,23 @@ int sysctlbyname(String name, Pointer oldp, IntByReference oldlenp,
* @return 0 on success; sets errno on failure
*/
int sysctlnametomib(String name, Pointer mibp, IntByReference size);

/**
* The host_processor_info function returns information about processors.
*
* @param machPort
* The control port for the host for which information is to be
* obtained.
* @param flavor
* The type of information requested.
* @param procCount
* Pointer to the number of processors
* @param procInfo
* Pointer to the structure corresponding to the requested flavor
* @param procInfoCount
* Pointer to number of elements in the returned structure
* @return 0 on success; sets errno on failure
*/
int host_processor_info(int machPort, int flavor, IntByReference procCount,
PointerByReference procInfo, IntByReference procInfoCount);
}
20 changes: 20 additions & 0 deletions contrib/platform/test/com/sun/jna/platform/mac/SystemBTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,16 +17,19 @@
package com.sun.jna.platform.mac;

import junit.framework.TestCase;

import com.sun.jna.platform.mac.SystemB.HostCpuLoadInfo;
import com.sun.jna.platform.mac.SystemB.HostLoadInfo;
import com.sun.jna.platform.mac.SystemB.VMStatistics;
import com.sun.jna.platform.mac.SystemB.VMStatistics64;

import com.sun.jna.Memory;
import com.sun.jna.Native;
import com.sun.jna.Platform;
import com.sun.jna.Pointer;
import com.sun.jna.ptr.IntByReference;
import com.sun.jna.ptr.LongByReference;
import com.sun.jna.ptr.PointerByReference;

/**
* Exercise the {@link SystemB} class.
Expand Down Expand Up @@ -134,6 +137,23 @@ SystemB.HOST_CPU_LOAD_INFO, hostLoadInfo, new IntByReference(
assertTrue(hostLoadInfo.avenrun[0] > 0);
}

public void testHostProcessorInfo() {
int machPort = SystemB.INSTANCE.mach_host_self();
assertTrue(machPort > 0);

IntByReference procCount = new IntByReference();
PointerByReference procCpuLoadInfo = new PointerByReference();
IntByReference procInfoCount = new IntByReference();
int ret = SystemB.INSTANCE.host_processor_info(machPort,
SystemB.PROCESSOR_CPU_LOAD_INFO, procCount, procCpuLoadInfo,
procInfoCount);
assertEquals(ret, 0);

assertTrue(procCount.getValue() > 0);
assertEquals(procCpuLoadInfo.getValue().getIntArray(0,
procInfoCount.getValue()).length, procInfoCount.getValue());
}

public static void main(java.lang.String[] argList) {
junit.textui.TestRunner.run(SystemBTest.class);
}
Expand Down