Skip to content

Commit 6c9a8c0

Browse files
committed
Properly type mach_port_t and friends
1 parent 6ce42cc commit 6c9a8c0

File tree

7 files changed

+189
-124
lines changed

7 files changed

+189
-124
lines changed

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

+6-25
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,8 @@
3434
import com.sun.jna.platform.mac.CoreFoundation.CFMutableDictionaryRef;
3535
import com.sun.jna.platform.mac.CoreFoundation.CFStringRef;
3636
import com.sun.jna.platform.mac.CoreFoundation.CFTypeRef;
37+
import com.sun.jna.platform.mac.SystemB.MachPort;
38+
import com.sun.jna.platform.mac.SystemB.TaskPort;
3739
import com.sun.jna.ptr.IntByReference;
3840
import com.sun.jna.ptr.LongByReference;
3941
import com.sun.jna.ptr.PointerByReference;
@@ -52,8 +54,6 @@ public interface IOKit extends Library {
5254
double kIOPSTimeRemainingUnlimited = -2.0;
5355
double kIOPSTimeRemainingUnknown = -1.0;
5456

55-
MachPort MACH_PORT_NULL = new MachPort();
56-
5757
/**
5858
* IOKitLib implements non-kernel task access to common IOKit object types -
5959
* IORegistryEntry, IOService, IOIterator etc. These functions are generic -
@@ -90,25 +90,6 @@ public int release() {
9090
}
9191
}
9292

93-
/**
94-
* Communication between tasks is an important element of the Mach philosophy.
95-
* Mach supports a client/server system structure in which tasks (clients)
96-
* access services by making requests of other tasks (servers) via messages sent
97-
* over a communication channel.
98-
* <p>
99-
* The endpoints of these communication channels in Mach are called ports, while
100-
* port rights denote permission to use the channel.
101-
*/
102-
class MachPort extends IOObject {
103-
public MachPort() {
104-
super();
105-
}
106-
107-
public MachPort(Pointer p) {
108-
super(p);
109-
}
110-
}
111-
11293
/**
11394
* An IOKit iterator handle.
11495
*/
@@ -128,7 +109,7 @@ public IOIterator(Pointer p) {
128109
* returned, otherwise zero is returned. The element should be released
129110
* by the caller when it is finished.
130111
*/
131-
public IOService next() {
112+
public IORegistryEntry next() {
132113
return INSTANCE.IOIteratorNext(this);
133114
}
134115
}
@@ -178,7 +159,7 @@ public IOConnect(Pointer p) {
178159
* Returns the mach port used to initiate communication with IOKit.
179160
*
180161
* @param bootstrapPort
181-
* Pass {@link #MACH_PORT_NULL} for the default.
162+
* Pass {@link SystemB#MACH_PORT_NULL} for the default.
182163
* @param masterPort
183164
* A pointer to the master port is returned. Multiple calls to
184165
* IOMasterPort will not result in leaking ports (each call to
@@ -285,7 +266,7 @@ int IOServiceGetMatchingServices(MachPort masterPort, CFDictionaryRef matchingDi
285266
* returned, otherwise zero is returned. The element should be released
286267
* by the caller when it is finished.
287268
*/
288-
IOService IOIteratorNext(IOIterator iterator);
269+
IORegistryEntry IOIteratorNext(IOIterator iterator);
289270

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

468449
/**
469450
* Returns the busyState of an IOService.

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

+7-7
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@
3535
import com.sun.jna.platform.mac.IOKit.IOIterator;
3636
import com.sun.jna.platform.mac.IOKit.IORegistryEntry;
3737
import com.sun.jna.platform.mac.IOKit.IOService;
38-
import com.sun.jna.platform.mac.IOKit.MachPort;
38+
import com.sun.jna.platform.mac.SystemB.MachPort;
3939
import com.sun.jna.ptr.PointerByReference;
4040

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

@@ -74,7 +74,7 @@ public static MachPort getMasterPort() {
7474
public static IORegistryEntry getRoot() {
7575
MachPort masterPort = getMasterPort();
7676
IORegistryEntry root = IO.IORegistryGetRootEntry(masterPort);
77-
masterPort.release();
77+
masterPort.deallocate();
7878
return root;
7979
}
8080

@@ -108,7 +108,7 @@ public static IOService getMatchingService(String serviceName) {
108108
public static IOService getMatchingService(CFDictionaryRef matchingDictionary) {
109109
MachPort masterPort = getMasterPort();
110110
IOService service = IO.IOServiceGetMatchingService(masterPort, matchingDictionary);
111-
masterPort.release();
111+
masterPort.deallocate();
112112
return service;
113113
}
114114

@@ -143,7 +143,7 @@ public static IOIterator getMatchingServices(CFDictionaryRef matchingDictionary)
143143
MachPort masterPort = getMasterPort();
144144
PointerByReference serviceIterator = new PointerByReference();
145145
int result = IO.IOServiceGetMatchingServices(masterPort, matchingDictionary, serviceIterator);
146-
masterPort.release();
146+
masterPort.deallocate();
147147
if (result == 0 && serviceIterator.getValue() != null) {
148148
return new IOIterator(serviceIterator.getValue());
149149
}
@@ -161,7 +161,7 @@ public static IOIterator getMatchingServices(CFDictionaryRef matchingDictionary)
161161
public static CFMutableDictionaryRef getBSDNameMatchingDict(String bsdName) {
162162
MachPort masterPort = getMasterPort();
163163
CFMutableDictionaryRef result = IO.IOBSDNameMatching(masterPort, 0, bsdName);
164-
masterPort.release();
164+
masterPort.deallocate();
165165
return result;
166166
}
167167

0 commit comments

Comments
 (0)