Skip to content

Commit 85801e1

Browse files
committed
macOS: use USBOpenDeviceSeize
1 parent 085f68e commit 85801e1

File tree

9 files changed

+783
-279
lines changed

9 files changed

+783
-279
lines changed

java-does-usb/jextract/macos/gen_macos.sh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,8 +51,8 @@ $JEXTRACT --source --output ../../src/main/java \
5151
--include-function IORegistryEntryGetRegistryEntryID \
5252
--include-function IOServiceAddMatchingNotification \
5353
--include-function IOServiceMatching \
54-
--include-struct IOUSBDeviceStruct100 \
55-
--include-typedef IOUSBDeviceInterface100 \
54+
--include-struct IOUSBDeviceStruct182 \
55+
--include-typedef IOUSBDeviceInterface182 \
5656
--include-constant kIOUSBFindInterfaceDontCare \
5757
--include-typedef IOUSBFindInterfaceRequest \
5858
--include-typedef IOUSBDevRequest \

java-does-usb/src/main/java/net/codecrete/usb/macos/IoKitHelper.java

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -28,12 +28,12 @@ public class IoKitHelper {
2828
public static final MemorySegment kIOUSBInterfaceUserClientTypeID = UUID.CreateCFUUID(new byte[]{(byte) 0x2d,
2929
(byte) 0x97, (byte) 0x86, (byte) 0xc6, (byte) 0x9e, (byte) 0xf3, (byte) 0x11, (byte) 0xD4, (byte) 0xad,
3030
(byte) 0x51, (byte) 0x00, (byte) 0x0a, (byte) 0x27, (byte) 0x05, (byte) 0x28, (byte) 0x61});
31-
public static final MemorySegment kIOUSBDeviceInterfaceID100 = UUID.CreateCFUUID(new byte[]{(byte) 0x5c,
32-
(byte) 0x81, (byte) 0x87, (byte) 0xd0, (byte) 0x9e, (byte) 0xf3, (byte) 0x11, (byte) 0xD4, (byte) 0x8b,
33-
(byte) 0x45, (byte) 0x00, (byte) 0x0a, (byte) 0x27, (byte) 0x05, (byte) 0x28, (byte) 0x61});
34-
public static final MemorySegment kIOUSBInterfaceInterfaceID100 = UUID.CreateCFUUID(new byte[]{(byte) 0x73,
35-
(byte) 0xc9, (byte) 0x7a, (byte) 0xe8, (byte) 0x9e, (byte) 0xf3, (byte) 0x11, (byte) 0xD4, (byte) 0xb1,
36-
(byte) 0xd0, (byte) 0x00, (byte) 0x0a, (byte) 0x27, (byte) 0x05, (byte) 0x28, (byte) 0x61});
31+
public static final MemorySegment kIOUSBDeviceInterfaceID182 = UUID.CreateCFUUID(new byte[]{(byte) 0x15,
32+
(byte) 0x2f, (byte) 0xc4, (byte) 0x96, (byte) 0x48, (byte) 0x91, (byte) 0x11, (byte) 0xD5, (byte) 0x9d,
33+
(byte) 0x52, (byte) 0x00, (byte) 0x0a, (byte) 0x27, (byte) 0x80, (byte) 0x1e, (byte) 0x86});
34+
public static final MemorySegment kIOUSBInterfaceInterfaceID190 = UUID.CreateCFUUID(new byte[]{(byte) 0x8f,
35+
(byte) 0xdb, (byte) 0x84, (byte) 0x55, (byte) 0x74, (byte) 0xa6, (byte) 0x11, (byte) 0xD6, (byte) 0x97,
36+
(byte) 0xb1, (byte) 0x00, (byte) 0x30, (byte) 0x65, (byte) 0xd3, (byte) 0x60, (byte) 0x8e});
3737
public static final MemorySegment kIOCFPlugInInterfaceID = UUID.CreateCFUUID(new byte[]{(byte) 0xC2, (byte) 0x44,
3838
(byte) 0xE8, (byte) 0x58, (byte) 0x10, (byte) 0x9C, (byte) 0x11, (byte) 0xD4, (byte) 0x91, (byte) 0xD4,
3939
(byte) 0x00, (byte) 0x50, (byte) 0xE4, (byte) 0xC6, (byte) 0x42, (byte) 0x6F});

java-does-usb/src/main/java/net/codecrete/usb/macos/IoKitUSB.java

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
package net.codecrete.usb.macos;
99

1010
import net.codecrete.usb.common.ForeignMemory;
11-
import net.codecrete.usb.macos.gen.iokit.IOUSBDeviceInterface100;
11+
import net.codecrete.usb.macos.gen.iokit.IOUSBDeviceInterface182;
1212
import net.codecrete.usb.macos.gen.iokit.IOUSBInterfaceInterface190;
1313

1414
import java.lang.foreign.MemorySegment;
@@ -29,60 +29,60 @@ private static MemorySegment getVtable(MemorySegment self) {
2929

3030
// HRESULT (STDMETHODCALLTYPE *QueryInterface)(void *thisPointer, REFIID iid, LPVOID *ppv);
3131
public static int QueryInterface(MemorySegment self, MemorySegment iid, MemorySegment ppv) {
32-
return IOUSBDeviceInterface100.QueryInterface(getVtable(self), SegmentScope.global()).apply(self, iid, ppv);
32+
return IOUSBDeviceInterface182.QueryInterface(getVtable(self), SegmentScope.global()).apply(self, iid, ppv);
3333
}
3434

3535
// ULONG (STDMETHODCALLTYPE *AddRef)(void *thisPointer);
3636
public static int AddRef(MemorySegment self) {
37-
return IOUSBDeviceInterface100.AddRef(getVtable(self), SegmentScope.global()).apply(self);
37+
return IOUSBDeviceInterface182.AddRef(getVtable(self), SegmentScope.global()).apply(self);
3838
}
3939

4040
// ULONG (STDMETHODCALLTYPE *Release)(void *thisPointer)
4141
public static int Release(MemorySegment self) {
42-
return IOUSBDeviceInterface100.Release(getVtable(self), SegmentScope.global()).apply(self);
42+
return IOUSBDeviceInterface182.Release(getVtable(self), SegmentScope.global()).apply(self);
4343
}
4444

4545
// IOReturn (* CreateDeviceAsyncEventSource)(void* self, CFRunLoopSourceRef* source);
4646
public static int CreateDeviceAsyncEventSource(MemorySegment self, MemorySegment source) {
47-
return IOUSBDeviceInterface100.CreateDeviceAsyncEventSource(getVtable(self), SegmentScope.global()).apply(self, source);
47+
return IOUSBDeviceInterface182.CreateDeviceAsyncEventSource(getVtable(self), SegmentScope.global()).apply(self, source);
4848
}
4949

5050
// CFRunLoopSourceRef (* GetDeviceAsyncEventSource)(void* self);
5151
public static MemorySegment GetDeviceAsyncEventSource(MemorySegment self) {
52-
return IOUSBDeviceInterface100.GetDeviceAsyncEventSource(getVtable(self), SegmentScope.global()).apply(self);
52+
return IOUSBDeviceInterface182.GetDeviceAsyncEventSource(getVtable(self), SegmentScope.global()).apply(self);
5353
}
5454

55-
// IOReturn (*USBDeviceOpen)(void *self);
56-
public static int USBDeviceOpen(MemorySegment self) {
57-
return IOUSBDeviceInterface100.USBDeviceOpen(getVtable(self), SegmentScope.global()).apply(self);
55+
// IOReturn (*USBDeviceOpenSeize)(void *self);
56+
public static int USBDeviceOpenSeize(MemorySegment self) {
57+
return IOUSBDeviceInterface182.USBDeviceOpenSeize(getVtable(self), SegmentScope.global()).apply(self);
5858
}
5959

6060
// IOReturn (*USBDeviceClose)(void *self);
6161
public static int USBDeviceClose(MemorySegment self) {
62-
return IOUSBDeviceInterface100.USBDeviceClose(getVtable(self), SegmentScope.global()).apply(self);
62+
return IOUSBDeviceInterface182.USBDeviceClose(getVtable(self), SegmentScope.global()).apply(self);
6363
}
6464

6565
// IOReturn (*GetConfigurationDescriptorPtr)(void *self, UInt8 configIndex, IOUSBConfigurationDescriptorPtr *desc);
6666
public static int GetConfigurationDescriptorPtr(MemorySegment self, byte configIndex, MemorySegment descHolder) {
67-
return IOUSBDeviceInterface100.GetConfigurationDescriptorPtr(getVtable(self), SegmentScope.global()).apply(self, configIndex, descHolder);
67+
return IOUSBDeviceInterface182.GetConfigurationDescriptorPtr(getVtable(self), SegmentScope.global()).apply(self, configIndex, descHolder);
6868
}
6969

7070
// IOReturn (*SetConfiguration)(void *self, UInt8 configNum);
7171
public static int SetConfiguration(MemorySegment self, byte configValue) {
72-
return IOUSBDeviceInterface100.SetConfiguration(getVtable(self), SegmentScope.global()).apply(self,
72+
return IOUSBDeviceInterface182.SetConfiguration(getVtable(self), SegmentScope.global()).apply(self,
7373
configValue);
7474
}
7575

7676
// IOReturn (*CreateInterfaceIterator)(void *self, IOUSBFindInterfaceRequest *req, io_iterator_t *iter);
7777
public static int CreateInterfaceIterator(MemorySegment self, MemorySegment req, MemorySegment iter) {
78-
return IOUSBDeviceInterface100.CreateInterfaceIterator(getVtable(self), SegmentScope.global()).apply(self,
78+
return IOUSBDeviceInterface182.CreateInterfaceIterator(getVtable(self), SegmentScope.global()).apply(self,
7979
req, iter);
8080
}
8181

8282
// IOReturn (* DeviceRequestAsync)(void* self, IOUSBDevRequest* req, IOAsyncCallback1 callback, void* refCon);
8383
public static int DeviceRequestAsync(MemorySegment self, MemorySegment deviceRequest, MemorySegment callback,
8484
MemorySegment refCon) {
85-
return IOUSBDeviceInterface100.DeviceRequestAsync(getVtable(self), SegmentScope.global()).apply(self,
85+
return IOUSBDeviceInterface182.DeviceRequestAsync(getVtable(self), SegmentScope.global()).apply(self,
8686
deviceRequest, callback, refCon);
8787
}
8888

java-does-usb/src/main/java/net/codecrete/usb/macos/MacosUSBDevice.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ public synchronized void open() {
7676
throwException("the device is already open");
7777

7878
// open device
79-
int ret = IoKitUSB.USBDeviceOpen(device);
79+
int ret = IoKitUSB.USBDeviceOpenSeize(device);
8080
if (ret != 0)
8181
throwException(ret, "unable to open USB device");
8282

@@ -166,7 +166,7 @@ private InterfaceInfo findInterface(int interfaceNumber) {
166166
cleanup.add(() -> IOKit.IOObjectRelease(service_final));
167167

168168
final var intf = IoKitHelper.getInterface(service, IoKitHelper.kIOUSBInterfaceUserClientTypeID,
169-
IoKitHelper.kIOUSBInterfaceInterfaceID100);
169+
IoKitHelper.kIOUSBInterfaceInterfaceID190);
170170
if (intf == null)
171171
continue;
172172

java-does-usb/src/main/java/net/codecrete/usb/macos/MacosUSBDeviceRegistry.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,7 @@ private void iterateDevices(int iterator, IOKitDeviceConsumer consumer) {
118118
cleanup.add(() -> IOKit.IOObjectRelease(service));
119119

120120
var device = IoKitHelper.getInterface(service, IoKitHelper.kIOUSBDeviceUserClientTypeID,
121-
IoKitHelper.kIOUSBDeviceInterfaceID100);
121+
IoKitHelper.kIOUSBDeviceInterfaceID182);
122122
if (device != null)
123123
cleanup.add(() -> IoKitUSB.Release(device));
124124

java-does-usb/src/main/java/net/codecrete/usb/macos/gen/iokit/IOUSBDeviceInterface100.java

Lines changed: 0 additions & 16 deletions
This file was deleted.
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
// Generated by jextract
2+
3+
package net.codecrete.usb.macos.gen.iokit;
4+
5+
/**
6+
* {@snippet :
7+
* typedef struct IOUSBDeviceStruct182 IOUSBDeviceInterface182;
8+
* }
9+
*/
10+
public final class IOUSBDeviceInterface182 extends IOUSBDeviceStruct182 {
11+
12+
// Suppresses default constructor, ensuring non-instantiability.
13+
private IOUSBDeviceInterface182() {}
14+
}
15+
16+

0 commit comments

Comments
 (0)