1 // Generated by jextract
2
3 package oracle.code.onnx.foreign;
4
5 import java.lang.invoke.*;
6 import java.lang.foreign.*;
7 import java.nio.ByteOrder;
8 import java.util.*;
9 import java.util.function.*;
10 import java.util.stream.*;
11
12 import static java.lang.foreign.ValueLayout.*;
13 import static java.lang.foreign.MemoryLayout.PathElement.*;
14
15 /**
16 * {@snippet lang=c :
17 * struct OrtExternalSemaphoreHandle {
18 * uint32_t version;
19 * const OrtEpDevice *ep_device;
20 * OrtExternalSemaphoreDescriptor descriptor;
21 * void (*Release)(OrtExternalSemaphoreHandle *);
22 * }
23 * }
24 */
25 public class OrtExternalSemaphoreHandle {
26
27 OrtExternalSemaphoreHandle() {
28 // Should not be called directly
29 }
30
31 private static final GroupLayout $LAYOUT = MemoryLayout.structLayout(
32 onnxruntime_c_api_h.C_INT.withName("version"),
33 MemoryLayout.paddingLayout(4),
34 onnxruntime_c_api_h.C_POINTER.withName("ep_device"),
35 OrtExternalSemaphoreDescriptor.layout().withName("descriptor"),
36 onnxruntime_c_api_h.C_POINTER.withName("Release")
37 ).withName("OrtExternalSemaphoreHandle");
38
39 /**
40 * The layout of this struct
41 */
42 public static final GroupLayout layout() {
43 return $LAYOUT;
44 }
45
46 private static final OfInt version$LAYOUT = (OfInt)$LAYOUT.select(groupElement("version"));
47
48 /**
49 * Layout for field:
50 * {@snippet lang=c :
51 * uint32_t version
52 * }
53 */
54 public static final OfInt version$layout() {
55 return version$LAYOUT;
56 }
57
58 private static final long version$OFFSET = $LAYOUT.byteOffset(groupElement("version"));
59
60 /**
61 * Offset for field:
62 * {@snippet lang=c :
63 * uint32_t version
64 * }
65 */
66 public static final long version$offset() {
67 return version$OFFSET;
68 }
69
70 /**
71 * Getter for field:
72 * {@snippet lang=c :
73 * uint32_t version
74 * }
75 */
76 public static int version(MemorySegment struct) {
77 return struct.get(version$LAYOUT, version$OFFSET);
78 }
79
80 /**
81 * Setter for field:
82 * {@snippet lang=c :
83 * uint32_t version
84 * }
85 */
86 public static void version(MemorySegment struct, int fieldValue) {
87 struct.set(version$LAYOUT, version$OFFSET, fieldValue);
88 }
89
90 private static final AddressLayout ep_device$LAYOUT = (AddressLayout)$LAYOUT.select(groupElement("ep_device"));
91
92 /**
93 * Layout for field:
94 * {@snippet lang=c :
95 * const OrtEpDevice *ep_device
96 * }
97 */
98 public static final AddressLayout ep_device$layout() {
99 return ep_device$LAYOUT;
100 }
101
102 private static final long ep_device$OFFSET = $LAYOUT.byteOffset(groupElement("ep_device"));
103
104 /**
105 * Offset for field:
106 * {@snippet lang=c :
107 * const OrtEpDevice *ep_device
108 * }
109 */
110 public static final long ep_device$offset() {
111 return ep_device$OFFSET;
112 }
113
114 /**
115 * Getter for field:
116 * {@snippet lang=c :
117 * const OrtEpDevice *ep_device
118 * }
119 */
120 public static MemorySegment ep_device(MemorySegment struct) {
121 return struct.get(ep_device$LAYOUT, ep_device$OFFSET);
122 }
123
124 /**
125 * Setter for field:
126 * {@snippet lang=c :
127 * const OrtEpDevice *ep_device
128 * }
129 */
130 public static void ep_device(MemorySegment struct, MemorySegment fieldValue) {
131 struct.set(ep_device$LAYOUT, ep_device$OFFSET, fieldValue);
132 }
133
134 private static final GroupLayout descriptor$LAYOUT = (GroupLayout)$LAYOUT.select(groupElement("descriptor"));
135
136 /**
137 * Layout for field:
138 * {@snippet lang=c :
139 * OrtExternalSemaphoreDescriptor descriptor
140 * }
141 */
142 public static final GroupLayout descriptor$layout() {
143 return descriptor$LAYOUT;
144 }
145
146 private static final long descriptor$OFFSET = $LAYOUT.byteOffset(groupElement("descriptor"));
147
148 /**
149 * Offset for field:
150 * {@snippet lang=c :
151 * OrtExternalSemaphoreDescriptor descriptor
152 * }
153 */
154 public static final long descriptor$offset() {
155 return descriptor$OFFSET;
156 }
157
158 /**
159 * Getter for field:
160 * {@snippet lang=c :
161 * OrtExternalSemaphoreDescriptor descriptor
162 * }
163 */
164 public static MemorySegment descriptor(MemorySegment struct) {
165 return struct.asSlice(descriptor$OFFSET, descriptor$LAYOUT.byteSize());
166 }
167
168 /**
169 * Setter for field:
170 * {@snippet lang=c :
171 * OrtExternalSemaphoreDescriptor descriptor
172 * }
173 */
174 public static void descriptor(MemorySegment struct, MemorySegment fieldValue) {
175 MemorySegment.copy(fieldValue, 0L, struct, descriptor$OFFSET, descriptor$LAYOUT.byteSize());
176 }
177
178 /**
179 * {@snippet lang=c :
180 * void (*Release)(OrtExternalSemaphoreHandle *)
181 * }
182 */
183 public final static class Release {
184
185 private Release() {
186 // Should not be called directly
187 }
188
189 /**
190 * The function pointer signature, expressed as a functional interface
191 */
192 public interface Function {
193 void apply(MemorySegment _x0);
194 }
195
196 private static final FunctionDescriptor $DESC = FunctionDescriptor.ofVoid(
197 onnxruntime_c_api_h.C_POINTER
198 );
199
200 /**
201 * The descriptor of this function pointer
202 */
203 public static FunctionDescriptor descriptor() {
204 return $DESC;
205 }
206
207 private static final MethodHandle UP$MH = onnxruntime_c_api_h.upcallHandle(Release.Function.class, "apply", $DESC);
208
209 /**
210 * Allocates a new upcall stub, whose implementation is defined by {@code fi}.
211 * The lifetime of the returned segment is managed by {@code arena}
212 */
213 public static MemorySegment allocate(Release.Function fi, Arena arena) {
214 return Linker.nativeLinker().upcallStub(UP$MH.bindTo(fi), $DESC, arena);
215 }
216
217 private static final MethodHandle DOWN$MH = Linker.nativeLinker().downcallHandle($DESC);
218
219 /**
220 * Invoke the upcall stub {@code funcPtr}, with given parameters
221 */
222 public static void invoke(MemorySegment funcPtr, MemorySegment _x0) {
223 try {
224 DOWN$MH.invokeExact(funcPtr, _x0);
225 } catch (Error | RuntimeException ex) {
226 throw ex;
227 } catch (Throwable ex$) {
228 throw new AssertionError("should not reach here", ex$);
229 }
230 }
231 }
232
233 private static final AddressLayout Release$LAYOUT = (AddressLayout)$LAYOUT.select(groupElement("Release"));
234
235 /**
236 * Layout for field:
237 * {@snippet lang=c :
238 * void (*Release)(OrtExternalSemaphoreHandle *)
239 * }
240 */
241 public static final AddressLayout Release$layout() {
242 return Release$LAYOUT;
243 }
244
245 private static final long Release$OFFSET = $LAYOUT.byteOffset(groupElement("Release"));
246
247 /**
248 * Offset for field:
249 * {@snippet lang=c :
250 * void (*Release)(OrtExternalSemaphoreHandle *)
251 * }
252 */
253 public static final long Release$offset() {
254 return Release$OFFSET;
255 }
256
257 /**
258 * Getter for field:
259 * {@snippet lang=c :
260 * void (*Release)(OrtExternalSemaphoreHandle *)
261 * }
262 */
263 public static MemorySegment Release(MemorySegment struct) {
264 return struct.get(Release$LAYOUT, Release$OFFSET);
265 }
266
267 /**
268 * Setter for field:
269 * {@snippet lang=c :
270 * void (*Release)(OrtExternalSemaphoreHandle *)
271 * }
272 */
273 public static void Release(MemorySegment struct, MemorySegment fieldValue) {
274 struct.set(Release$LAYOUT, Release$OFFSET, fieldValue);
275 }
276
277 /**
278 * Obtains a slice of {@code arrayParam} which selects the array element at {@code index}.
279 * The returned segment has address {@code arrayParam.address() + index * layout().byteSize()}
280 */
281 public static MemorySegment asSlice(MemorySegment array, long index) {
282 return array.asSlice(layout().byteSize() * index);
283 }
284
285 /**
286 * The size (in bytes) of this struct
287 */
288 public static long sizeof() { return layout().byteSize(); }
289
290 /**
291 * Allocate a segment of size {@code layout().byteSize()} using {@code allocator}
292 */
293 public static MemorySegment allocate(SegmentAllocator allocator) {
294 return allocator.allocate(layout());
295 }
296
297 /**
298 * Allocate an array of size {@code elementCount} using {@code allocator}.
299 * The returned segment has size {@code elementCount * layout().byteSize()}.
300 */
301 public static MemorySegment allocateArray(long elementCount, SegmentAllocator allocator) {
302 return allocator.allocate(MemoryLayout.sequenceLayout(elementCount, layout()));
303 }
304
305 /**
306 * Reinterprets {@code addr} using target {@code arena} and {@code cleanupAction} (if any).
307 * The returned segment has size {@code layout().byteSize()}
308 */
309 public static MemorySegment reinterpret(MemorySegment addr, Arena arena, Consumer<MemorySegment> cleanup) {
310 return reinterpret(addr, 1, arena, cleanup);
311 }
312
313 /**
314 * Reinterprets {@code addr} using target {@code arena} and {@code cleanupAction} (if any).
315 * The returned segment has size {@code elementCount * layout().byteSize()}
316 */
317 public static MemorySegment reinterpret(MemorySegment addr, long elementCount, Arena arena, Consumer<MemorySegment> cleanup) {
318 return addr.reinterpret(layout().byteSize() * elementCount, arena, cleanup);
319 }
320 }
321