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 mappings for CoreFoundation, IOKit, DiskArbitration #1131

Merged
merged 31 commits into from
Sep 19, 2019
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
31 commits
Select commit Hold shift + click to select a range
e8e3e59
Add mappings for Core Foundation framework
dbwiddis Aug 31, 2019
4c72791
Add mappings for IOKit
dbwiddis Sep 2, 2019
6940d75
Add mappings for DiskArbitration
dbwiddis Sep 2, 2019
b1cb0a5
Don't persist CFAllocatorRef
dbwiddis Sep 2, 2019
cd00036
Better type mappings
dbwiddis Sep 3, 2019
7c3db24
Fix Boolean, CFIndex, and Pointer typing
dbwiddis Sep 4, 2019
0515f66
Refactor Release to CFTypeRef class
dbwiddis Sep 4, 2019
667e2f9
Eliminate CoreFoundationUtil
dbwiddis Sep 4, 2019
bd59283
CoreFoundation type fixes
dbwiddis Sep 7, 2019
a216ab5
IOKit Object classes
dbwiddis Sep 8, 2019
b478d79
Convenience methods for IOObject#release and IOIterator#next
dbwiddis Sep 8, 2019
772e6b8
Merge branch 'master' of https://github.com/java-native-access/jna in…
dbwiddis Sep 9, 2019
b666a93
MachPort does not extend IOObject and master port does not get released
dbwiddis Sep 9, 2019
0db5ae2
Function mapper for properly typed mach ports
dbwiddis Sep 10, 2019
a51ab2a
Consistent IOObject hierarchy
dbwiddis Sep 11, 2019
7947561
Allow MachPorts to be deallocated
dbwiddis Sep 11, 2019
56c4b2e
Add CFIndex extending NativeLong
dbwiddis Sep 12, 2019
52ec379
Add IOKitUtil class
dbwiddis Sep 12, 2019
6ce42cc
Merge branch 'master' of https://github.com/java-native-access/jna in…
dbwiddis Sep 14, 2019
6c9a8c0
Properly type mach_port_t and friends
dbwiddis Sep 15, 2019
06c3257
Mach ports back to 32-bit ints
dbwiddis Sep 17, 2019
1ab47ac
Simplify tests and enable null return util
dbwiddis Sep 17, 2019
b0b3c0c
Merge branch 'master' of https://github.com/java-native-access/jna in…
dbwiddis Sep 18, 2019
8b49dea
Move registry getters to IORegistryEntry class
dbwiddis Sep 18, 2019
1c2f213
CoreFoundation convenience methods
dbwiddis Sep 18, 2019
46e9ec4
IOKit convenience methods
dbwiddis Sep 18, 2019
a9db43b
TypeID checking
dbwiddis Sep 18, 2019
3528421
Return primitive types from convenience methods
dbwiddis Sep 18, 2019
7fae6ab
IOReturn exception handling
dbwiddis Sep 18, 2019
9628162
Fix tests
dbwiddis Sep 18, 2019
fb21633
Checkstyle doesn't like trailing spaces
dbwiddis Sep 19, 2019
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
31 changes: 6 additions & 25 deletions contrib/platform/src/com/sun/jna/platform/mac/IOKit.java
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@
import com.sun.jna.platform.mac.CoreFoundation.CFMutableDictionaryRef;
import com.sun.jna.platform.mac.CoreFoundation.CFStringRef;
import com.sun.jna.platform.mac.CoreFoundation.CFTypeRef;
import com.sun.jna.platform.mac.SystemB.MachPort;
import com.sun.jna.platform.mac.SystemB.TaskPort;
import com.sun.jna.ptr.IntByReference;
import com.sun.jna.ptr.LongByReference;
import com.sun.jna.ptr.PointerByReference;
Expand All @@ -52,8 +54,6 @@ public interface IOKit extends Library {
double kIOPSTimeRemainingUnlimited = -2.0;
double kIOPSTimeRemainingUnknown = -1.0;

MachPort MACH_PORT_NULL = new MachPort();

/**
* IOKitLib implements non-kernel task access to common IOKit object types -
* IORegistryEntry, IOService, IOIterator etc. These functions are generic -
Expand Down Expand Up @@ -90,25 +90,6 @@ public int release() {
}
}

/**
* Communication between tasks is an important element of the Mach philosophy.
* Mach supports a client/server system structure in which tasks (clients)
* access services by making requests of other tasks (servers) via messages sent
* over a communication channel.
* <p>
* The endpoints of these communication channels in Mach are called ports, while
* port rights denote permission to use the channel.
*/
class MachPort extends IOObject {
public MachPort() {
super();
}

public MachPort(Pointer p) {
super(p);
}
}

/**
* An IOKit iterator handle.
*/
Expand All @@ -128,7 +109,7 @@ public IOIterator(Pointer p) {
* returned, otherwise zero is returned. The element should be released
* by the caller when it is finished.
*/
public IOService next() {
public IORegistryEntry next() {
return INSTANCE.IOIteratorNext(this);
}
}
Expand Down Expand Up @@ -178,7 +159,7 @@ public IOConnect(Pointer p) {
* Returns the mach port used to initiate communication with IOKit.
*
* @param bootstrapPort
* Pass {@link #MACH_PORT_NULL} for the default.
* Pass {@link SystemB#MACH_PORT_NULL} for the default.
* @param masterPort
* A pointer to the master port is returned. Multiple calls to
* IOMasterPort will not result in leaking ports (each call to
Expand Down Expand Up @@ -285,7 +266,7 @@ int IOServiceGetMatchingServices(MachPort masterPort, CFDictionaryRef matchingDi
* returned, otherwise zero is returned. The element should be released
* by the caller when it is finished.
*/
IOService IOIteratorNext(IOIterator iterator);
IORegistryEntry IOIteratorNext(IOIterator iterator);

/**
* Create a CF representation of a registry entry's property.
Expand Down Expand Up @@ -463,7 +444,7 @@ CFTypeRef IORegistryEntrySearchCFProperty(IORegistryEntry entry, String plane, C
* {@link IOServiceClose}.
* @return A return code generated by {@code IOService::newUserClient}.
*/
int IOServiceOpen(IOService service, MachPort owningTask, int type, PointerByReference connect);
int IOServiceOpen(IOService service, TaskPort owningTask, int type, PointerByReference connect);

/**
* Returns the busyState of an IOService.
Expand Down
14 changes: 7 additions & 7 deletions contrib/platform/src/com/sun/jna/platform/mac/IOKitUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
import com.sun.jna.platform.mac.IOKit.IOIterator;
import com.sun.jna.platform.mac.IOKit.IORegistryEntry;
import com.sun.jna.platform.mac.IOKit.IOService;
import com.sun.jna.platform.mac.IOKit.MachPort;
import com.sun.jna.platform.mac.SystemB.MachPort;
import com.sun.jna.ptr.PointerByReference;

/**
Expand All @@ -57,11 +57,11 @@ private IOKitUtil() {
* ports (each call to {@link IOKit#IOMasterPort} adds another send
* right to the port) but it is considered good programming practice to
* deallocate the port when you are finished with it, using
* {@link IOKit#IOObjectRelease}.
* {@link SystemB#mach_port_deallocate}.
*/
public static MachPort getMasterPort() {
PointerByReference port = new PointerByReference();
IO.IOMasterPort(IOKit.MACH_PORT_NULL, port);
IO.IOMasterPort(SystemB.MACH_PORT_NULL, port);
return new MachPort(port.getValue());
}

Expand All @@ -74,7 +74,7 @@ public static MachPort getMasterPort() {
public static IORegistryEntry getRoot() {
MachPort masterPort = getMasterPort();
IORegistryEntry root = IO.IORegistryGetRootEntry(masterPort);
masterPort.release();
masterPort.deallocate();
return root;
}

Expand Down Expand Up @@ -108,7 +108,7 @@ public static IOService getMatchingService(String serviceName) {
public static IOService getMatchingService(CFDictionaryRef matchingDictionary) {
MachPort masterPort = getMasterPort();
IOService service = IO.IOServiceGetMatchingService(masterPort, matchingDictionary);
masterPort.release();
masterPort.deallocate();
return service;
}

Expand Down Expand Up @@ -143,7 +143,7 @@ public static IOIterator getMatchingServices(CFDictionaryRef matchingDictionary)
MachPort masterPort = getMasterPort();
PointerByReference serviceIterator = new PointerByReference();
int result = IO.IOServiceGetMatchingServices(masterPort, matchingDictionary, serviceIterator);
masterPort.release();
masterPort.deallocate();
if (result == 0 && serviceIterator.getValue() != null) {
return new IOIterator(serviceIterator.getValue());
}
Expand All @@ -161,7 +161,7 @@ public static IOIterator getMatchingServices(CFDictionaryRef matchingDictionary)
public static CFMutableDictionaryRef getBSDNameMatchingDict(String bsdName) {
MachPort masterPort = getMasterPort();
CFMutableDictionaryRef result = IO.IOBSDNameMatching(masterPort, 0, bsdName);
masterPort.release();
masterPort.deallocate();
return result;
}

Expand Down
Loading