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 OrtEpProfilerImpl {
 18  *     uint32_t ort_version_supported;
 19  *     void (*Release)(OrtEpProfilerImpl *);
 20  *     OrtStatusPtr (*StartProfiling)(OrtEpProfilerImpl *, int64_t);
 21  *     OrtStatusPtr (*StartEvent)(OrtEpProfilerImpl *, uint64_t);
 22  *     OrtStatusPtr (*StopEvent)(OrtEpProfilerImpl *, uint64_t, const OrtProfilingEvent *);
 23  *     OrtStatusPtr (*EndProfiling)(OrtEpProfilerImpl *, OrtProfilingEventsContainer *);
 24  * }
 25  * }
 26  */
 27 public class OrtEpProfilerImpl {
 28 
 29     OrtEpProfilerImpl() {
 30         // Should not be called directly
 31     }
 32 
 33     private static final GroupLayout $LAYOUT = MemoryLayout.structLayout(
 34         onnxruntime_c_api_h.C_INT.withName("ort_version_supported"),
 35         MemoryLayout.paddingLayout(4),
 36         onnxruntime_c_api_h.C_POINTER.withName("Release"),
 37         onnxruntime_c_api_h.C_POINTER.withName("StartProfiling"),
 38         onnxruntime_c_api_h.C_POINTER.withName("StartEvent"),
 39         onnxruntime_c_api_h.C_POINTER.withName("StopEvent"),
 40         onnxruntime_c_api_h.C_POINTER.withName("EndProfiling")
 41     ).withName("OrtEpProfilerImpl");
 42 
 43     /**
 44      * The layout of this struct
 45      */
 46     public static final GroupLayout layout() {
 47         return $LAYOUT;
 48     }
 49 
 50     private static final OfInt ort_version_supported$LAYOUT = (OfInt)$LAYOUT.select(groupElement("ort_version_supported"));
 51 
 52     /**
 53      * Layout for field:
 54      * {@snippet lang=c :
 55      * uint32_t ort_version_supported
 56      * }
 57      */
 58     public static final OfInt ort_version_supported$layout() {
 59         return ort_version_supported$LAYOUT;
 60     }
 61 
 62     private static final long ort_version_supported$OFFSET = $LAYOUT.byteOffset(groupElement("ort_version_supported"));
 63 
 64     /**
 65      * Offset for field:
 66      * {@snippet lang=c :
 67      * uint32_t ort_version_supported
 68      * }
 69      */
 70     public static final long ort_version_supported$offset() {
 71         return ort_version_supported$OFFSET;
 72     }
 73 
 74     /**
 75      * Getter for field:
 76      * {@snippet lang=c :
 77      * uint32_t ort_version_supported
 78      * }
 79      */
 80     public static int ort_version_supported(MemorySegment struct) {
 81         return struct.get(ort_version_supported$LAYOUT, ort_version_supported$OFFSET);
 82     }
 83 
 84     /**
 85      * Setter for field:
 86      * {@snippet lang=c :
 87      * uint32_t ort_version_supported
 88      * }
 89      */
 90     public static void ort_version_supported(MemorySegment struct, int fieldValue) {
 91         struct.set(ort_version_supported$LAYOUT, ort_version_supported$OFFSET, fieldValue);
 92     }
 93 
 94     /**
 95      * {@snippet lang=c :
 96      * void (*Release)(OrtEpProfilerImpl *)
 97      * }
 98      */
 99     public final static class Release {
100 
101         private Release() {
102             // Should not be called directly
103         }
104 
105         /**
106          * The function pointer signature, expressed as a functional interface
107          */
108         public interface Function {
109             void apply(MemorySegment _x0);
110         }
111 
112         private static final FunctionDescriptor $DESC = FunctionDescriptor.ofVoid(
113             onnxruntime_c_api_h.C_POINTER
114         );
115 
116         /**
117          * The descriptor of this function pointer
118          */
119         public static FunctionDescriptor descriptor() {
120             return $DESC;
121         }
122 
123         private static final MethodHandle UP$MH = onnxruntime_c_api_h.upcallHandle(Release.Function.class, "apply", $DESC);
124 
125         /**
126          * Allocates a new upcall stub, whose implementation is defined by {@code fi}.
127          * The lifetime of the returned segment is managed by {@code arena}
128          */
129         public static MemorySegment allocate(Release.Function fi, Arena arena) {
130             return Linker.nativeLinker().upcallStub(UP$MH.bindTo(fi), $DESC, arena);
131         }
132 
133         private static final MethodHandle DOWN$MH = Linker.nativeLinker().downcallHandle($DESC);
134 
135         /**
136          * Invoke the upcall stub {@code funcPtr}, with given parameters
137          */
138         public static void invoke(MemorySegment funcPtr, MemorySegment _x0) {
139             try {
140                  DOWN$MH.invokeExact(funcPtr, _x0);
141             } catch (Error | RuntimeException ex) {
142                 throw ex;
143             } catch (Throwable ex$) {
144                 throw new AssertionError("should not reach here", ex$);
145             }
146         }
147     }
148 
149     private static final AddressLayout Release$LAYOUT = (AddressLayout)$LAYOUT.select(groupElement("Release"));
150 
151     /**
152      * Layout for field:
153      * {@snippet lang=c :
154      * void (*Release)(OrtEpProfilerImpl *)
155      * }
156      */
157     public static final AddressLayout Release$layout() {
158         return Release$LAYOUT;
159     }
160 
161     private static final long Release$OFFSET = $LAYOUT.byteOffset(groupElement("Release"));
162 
163     /**
164      * Offset for field:
165      * {@snippet lang=c :
166      * void (*Release)(OrtEpProfilerImpl *)
167      * }
168      */
169     public static final long Release$offset() {
170         return Release$OFFSET;
171     }
172 
173     /**
174      * Getter for field:
175      * {@snippet lang=c :
176      * void (*Release)(OrtEpProfilerImpl *)
177      * }
178      */
179     public static MemorySegment Release(MemorySegment struct) {
180         return struct.get(Release$LAYOUT, Release$OFFSET);
181     }
182 
183     /**
184      * Setter for field:
185      * {@snippet lang=c :
186      * void (*Release)(OrtEpProfilerImpl *)
187      * }
188      */
189     public static void Release(MemorySegment struct, MemorySegment fieldValue) {
190         struct.set(Release$LAYOUT, Release$OFFSET, fieldValue);
191     }
192 
193     /**
194      * {@snippet lang=c :
195      * OrtStatusPtr (*StartProfiling)(OrtEpProfilerImpl *, int64_t)
196      * }
197      */
198     public final static class StartProfiling {
199 
200         private StartProfiling() {
201             // Should not be called directly
202         }
203 
204         /**
205          * The function pointer signature, expressed as a functional interface
206          */
207         public interface Function {
208             MemorySegment apply(MemorySegment _x0, long _x1);
209         }
210 
211         private static final FunctionDescriptor $DESC = FunctionDescriptor.of(
212             onnxruntime_c_api_h.C_POINTER,
213             onnxruntime_c_api_h.C_POINTER,
214             onnxruntime_c_api_h.C_LONG_LONG
215         );
216 
217         /**
218          * The descriptor of this function pointer
219          */
220         public static FunctionDescriptor descriptor() {
221             return $DESC;
222         }
223 
224         private static final MethodHandle UP$MH = onnxruntime_c_api_h.upcallHandle(StartProfiling.Function.class, "apply", $DESC);
225 
226         /**
227          * Allocates a new upcall stub, whose implementation is defined by {@code fi}.
228          * The lifetime of the returned segment is managed by {@code arena}
229          */
230         public static MemorySegment allocate(StartProfiling.Function fi, Arena arena) {
231             return Linker.nativeLinker().upcallStub(UP$MH.bindTo(fi), $DESC, arena);
232         }
233 
234         private static final MethodHandle DOWN$MH = Linker.nativeLinker().downcallHandle($DESC);
235 
236         /**
237          * Invoke the upcall stub {@code funcPtr}, with given parameters
238          */
239         public static MemorySegment invoke(MemorySegment funcPtr, MemorySegment _x0, long _x1) {
240             try {
241                 return (MemorySegment) DOWN$MH.invokeExact(funcPtr, _x0, _x1);
242             } catch (Error | RuntimeException ex) {
243                 throw ex;
244             } catch (Throwable ex$) {
245                 throw new AssertionError("should not reach here", ex$);
246             }
247         }
248     }
249 
250     private static final AddressLayout StartProfiling$LAYOUT = (AddressLayout)$LAYOUT.select(groupElement("StartProfiling"));
251 
252     /**
253      * Layout for field:
254      * {@snippet lang=c :
255      * OrtStatusPtr (*StartProfiling)(OrtEpProfilerImpl *, int64_t)
256      * }
257      */
258     public static final AddressLayout StartProfiling$layout() {
259         return StartProfiling$LAYOUT;
260     }
261 
262     private static final long StartProfiling$OFFSET = $LAYOUT.byteOffset(groupElement("StartProfiling"));
263 
264     /**
265      * Offset for field:
266      * {@snippet lang=c :
267      * OrtStatusPtr (*StartProfiling)(OrtEpProfilerImpl *, int64_t)
268      * }
269      */
270     public static final long StartProfiling$offset() {
271         return StartProfiling$OFFSET;
272     }
273 
274     /**
275      * Getter for field:
276      * {@snippet lang=c :
277      * OrtStatusPtr (*StartProfiling)(OrtEpProfilerImpl *, int64_t)
278      * }
279      */
280     public static MemorySegment StartProfiling(MemorySegment struct) {
281         return struct.get(StartProfiling$LAYOUT, StartProfiling$OFFSET);
282     }
283 
284     /**
285      * Setter for field:
286      * {@snippet lang=c :
287      * OrtStatusPtr (*StartProfiling)(OrtEpProfilerImpl *, int64_t)
288      * }
289      */
290     public static void StartProfiling(MemorySegment struct, MemorySegment fieldValue) {
291         struct.set(StartProfiling$LAYOUT, StartProfiling$OFFSET, fieldValue);
292     }
293 
294     /**
295      * {@snippet lang=c :
296      * OrtStatusPtr (*StartEvent)(OrtEpProfilerImpl *, uint64_t)
297      * }
298      */
299     public final static class StartEvent {
300 
301         private StartEvent() {
302             // Should not be called directly
303         }
304 
305         /**
306          * The function pointer signature, expressed as a functional interface
307          */
308         public interface Function {
309             MemorySegment apply(MemorySegment _x0, long _x1);
310         }
311 
312         private static final FunctionDescriptor $DESC = FunctionDescriptor.of(
313             onnxruntime_c_api_h.C_POINTER,
314             onnxruntime_c_api_h.C_POINTER,
315             onnxruntime_c_api_h.C_LONG_LONG
316         );
317 
318         /**
319          * The descriptor of this function pointer
320          */
321         public static FunctionDescriptor descriptor() {
322             return $DESC;
323         }
324 
325         private static final MethodHandle UP$MH = onnxruntime_c_api_h.upcallHandle(StartEvent.Function.class, "apply", $DESC);
326 
327         /**
328          * Allocates a new upcall stub, whose implementation is defined by {@code fi}.
329          * The lifetime of the returned segment is managed by {@code arena}
330          */
331         public static MemorySegment allocate(StartEvent.Function fi, Arena arena) {
332             return Linker.nativeLinker().upcallStub(UP$MH.bindTo(fi), $DESC, arena);
333         }
334 
335         private static final MethodHandle DOWN$MH = Linker.nativeLinker().downcallHandle($DESC);
336 
337         /**
338          * Invoke the upcall stub {@code funcPtr}, with given parameters
339          */
340         public static MemorySegment invoke(MemorySegment funcPtr, MemorySegment _x0, long _x1) {
341             try {
342                 return (MemorySegment) DOWN$MH.invokeExact(funcPtr, _x0, _x1);
343             } catch (Error | RuntimeException ex) {
344                 throw ex;
345             } catch (Throwable ex$) {
346                 throw new AssertionError("should not reach here", ex$);
347             }
348         }
349     }
350 
351     private static final AddressLayout StartEvent$LAYOUT = (AddressLayout)$LAYOUT.select(groupElement("StartEvent"));
352 
353     /**
354      * Layout for field:
355      * {@snippet lang=c :
356      * OrtStatusPtr (*StartEvent)(OrtEpProfilerImpl *, uint64_t)
357      * }
358      */
359     public static final AddressLayout StartEvent$layout() {
360         return StartEvent$LAYOUT;
361     }
362 
363     private static final long StartEvent$OFFSET = $LAYOUT.byteOffset(groupElement("StartEvent"));
364 
365     /**
366      * Offset for field:
367      * {@snippet lang=c :
368      * OrtStatusPtr (*StartEvent)(OrtEpProfilerImpl *, uint64_t)
369      * }
370      */
371     public static final long StartEvent$offset() {
372         return StartEvent$OFFSET;
373     }
374 
375     /**
376      * Getter for field:
377      * {@snippet lang=c :
378      * OrtStatusPtr (*StartEvent)(OrtEpProfilerImpl *, uint64_t)
379      * }
380      */
381     public static MemorySegment StartEvent(MemorySegment struct) {
382         return struct.get(StartEvent$LAYOUT, StartEvent$OFFSET);
383     }
384 
385     /**
386      * Setter for field:
387      * {@snippet lang=c :
388      * OrtStatusPtr (*StartEvent)(OrtEpProfilerImpl *, uint64_t)
389      * }
390      */
391     public static void StartEvent(MemorySegment struct, MemorySegment fieldValue) {
392         struct.set(StartEvent$LAYOUT, StartEvent$OFFSET, fieldValue);
393     }
394 
395     /**
396      * {@snippet lang=c :
397      * OrtStatusPtr (*StopEvent)(OrtEpProfilerImpl *, uint64_t, const OrtProfilingEvent *)
398      * }
399      */
400     public final static class StopEvent {
401 
402         private StopEvent() {
403             // Should not be called directly
404         }
405 
406         /**
407          * The function pointer signature, expressed as a functional interface
408          */
409         public interface Function {
410             MemorySegment apply(MemorySegment _x0, long _x1, MemorySegment _x2);
411         }
412 
413         private static final FunctionDescriptor $DESC = FunctionDescriptor.of(
414             onnxruntime_c_api_h.C_POINTER,
415             onnxruntime_c_api_h.C_POINTER,
416             onnxruntime_c_api_h.C_LONG_LONG,
417             onnxruntime_c_api_h.C_POINTER
418         );
419 
420         /**
421          * The descriptor of this function pointer
422          */
423         public static FunctionDescriptor descriptor() {
424             return $DESC;
425         }
426 
427         private static final MethodHandle UP$MH = onnxruntime_c_api_h.upcallHandle(StopEvent.Function.class, "apply", $DESC);
428 
429         /**
430          * Allocates a new upcall stub, whose implementation is defined by {@code fi}.
431          * The lifetime of the returned segment is managed by {@code arena}
432          */
433         public static MemorySegment allocate(StopEvent.Function fi, Arena arena) {
434             return Linker.nativeLinker().upcallStub(UP$MH.bindTo(fi), $DESC, arena);
435         }
436 
437         private static final MethodHandle DOWN$MH = Linker.nativeLinker().downcallHandle($DESC);
438 
439         /**
440          * Invoke the upcall stub {@code funcPtr}, with given parameters
441          */
442         public static MemorySegment invoke(MemorySegment funcPtr, MemorySegment _x0, long _x1, MemorySegment _x2) {
443             try {
444                 return (MemorySegment) DOWN$MH.invokeExact(funcPtr, _x0, _x1, _x2);
445             } catch (Error | RuntimeException ex) {
446                 throw ex;
447             } catch (Throwable ex$) {
448                 throw new AssertionError("should not reach here", ex$);
449             }
450         }
451     }
452 
453     private static final AddressLayout StopEvent$LAYOUT = (AddressLayout)$LAYOUT.select(groupElement("StopEvent"));
454 
455     /**
456      * Layout for field:
457      * {@snippet lang=c :
458      * OrtStatusPtr (*StopEvent)(OrtEpProfilerImpl *, uint64_t, const OrtProfilingEvent *)
459      * }
460      */
461     public static final AddressLayout StopEvent$layout() {
462         return StopEvent$LAYOUT;
463     }
464 
465     private static final long StopEvent$OFFSET = $LAYOUT.byteOffset(groupElement("StopEvent"));
466 
467     /**
468      * Offset for field:
469      * {@snippet lang=c :
470      * OrtStatusPtr (*StopEvent)(OrtEpProfilerImpl *, uint64_t, const OrtProfilingEvent *)
471      * }
472      */
473     public static final long StopEvent$offset() {
474         return StopEvent$OFFSET;
475     }
476 
477     /**
478      * Getter for field:
479      * {@snippet lang=c :
480      * OrtStatusPtr (*StopEvent)(OrtEpProfilerImpl *, uint64_t, const OrtProfilingEvent *)
481      * }
482      */
483     public static MemorySegment StopEvent(MemorySegment struct) {
484         return struct.get(StopEvent$LAYOUT, StopEvent$OFFSET);
485     }
486 
487     /**
488      * Setter for field:
489      * {@snippet lang=c :
490      * OrtStatusPtr (*StopEvent)(OrtEpProfilerImpl *, uint64_t, const OrtProfilingEvent *)
491      * }
492      */
493     public static void StopEvent(MemorySegment struct, MemorySegment fieldValue) {
494         struct.set(StopEvent$LAYOUT, StopEvent$OFFSET, fieldValue);
495     }
496 
497     /**
498      * {@snippet lang=c :
499      * OrtStatusPtr (*EndProfiling)(OrtEpProfilerImpl *, OrtProfilingEventsContainer *)
500      * }
501      */
502     public final static class EndProfiling {
503 
504         private EndProfiling() {
505             // Should not be called directly
506         }
507 
508         /**
509          * The function pointer signature, expressed as a functional interface
510          */
511         public interface Function {
512             MemorySegment apply(MemorySegment _x0, MemorySegment _x1);
513         }
514 
515         private static final FunctionDescriptor $DESC = FunctionDescriptor.of(
516             onnxruntime_c_api_h.C_POINTER,
517             onnxruntime_c_api_h.C_POINTER,
518             onnxruntime_c_api_h.C_POINTER
519         );
520 
521         /**
522          * The descriptor of this function pointer
523          */
524         public static FunctionDescriptor descriptor() {
525             return $DESC;
526         }
527 
528         private static final MethodHandle UP$MH = onnxruntime_c_api_h.upcallHandle(EndProfiling.Function.class, "apply", $DESC);
529 
530         /**
531          * Allocates a new upcall stub, whose implementation is defined by {@code fi}.
532          * The lifetime of the returned segment is managed by {@code arena}
533          */
534         public static MemorySegment allocate(EndProfiling.Function fi, Arena arena) {
535             return Linker.nativeLinker().upcallStub(UP$MH.bindTo(fi), $DESC, arena);
536         }
537 
538         private static final MethodHandle DOWN$MH = Linker.nativeLinker().downcallHandle($DESC);
539 
540         /**
541          * Invoke the upcall stub {@code funcPtr}, with given parameters
542          */
543         public static MemorySegment invoke(MemorySegment funcPtr, MemorySegment _x0, MemorySegment _x1) {
544             try {
545                 return (MemorySegment) DOWN$MH.invokeExact(funcPtr, _x0, _x1);
546             } catch (Error | RuntimeException ex) {
547                 throw ex;
548             } catch (Throwable ex$) {
549                 throw new AssertionError("should not reach here", ex$);
550             }
551         }
552     }
553 
554     private static final AddressLayout EndProfiling$LAYOUT = (AddressLayout)$LAYOUT.select(groupElement("EndProfiling"));
555 
556     /**
557      * Layout for field:
558      * {@snippet lang=c :
559      * OrtStatusPtr (*EndProfiling)(OrtEpProfilerImpl *, OrtProfilingEventsContainer *)
560      * }
561      */
562     public static final AddressLayout EndProfiling$layout() {
563         return EndProfiling$LAYOUT;
564     }
565 
566     private static final long EndProfiling$OFFSET = $LAYOUT.byteOffset(groupElement("EndProfiling"));
567 
568     /**
569      * Offset for field:
570      * {@snippet lang=c :
571      * OrtStatusPtr (*EndProfiling)(OrtEpProfilerImpl *, OrtProfilingEventsContainer *)
572      * }
573      */
574     public static final long EndProfiling$offset() {
575         return EndProfiling$OFFSET;
576     }
577 
578     /**
579      * Getter for field:
580      * {@snippet lang=c :
581      * OrtStatusPtr (*EndProfiling)(OrtEpProfilerImpl *, OrtProfilingEventsContainer *)
582      * }
583      */
584     public static MemorySegment EndProfiling(MemorySegment struct) {
585         return struct.get(EndProfiling$LAYOUT, EndProfiling$OFFSET);
586     }
587 
588     /**
589      * Setter for field:
590      * {@snippet lang=c :
591      * OrtStatusPtr (*EndProfiling)(OrtEpProfilerImpl *, OrtProfilingEventsContainer *)
592      * }
593      */
594     public static void EndProfiling(MemorySegment struct, MemorySegment fieldValue) {
595         struct.set(EndProfiling$LAYOUT, EndProfiling$OFFSET, fieldValue);
596     }
597 
598     /**
599      * Obtains a slice of {@code arrayParam} which selects the array element at {@code index}.
600      * The returned segment has address {@code arrayParam.address() + index * layout().byteSize()}
601      */
602     public static MemorySegment asSlice(MemorySegment array, long index) {
603         return array.asSlice(layout().byteSize() * index);
604     }
605 
606     /**
607      * The size (in bytes) of this struct
608      */
609     public static long sizeof() { return layout().byteSize(); }
610 
611     /**
612      * Allocate a segment of size {@code layout().byteSize()} using {@code allocator}
613      */
614     public static MemorySegment allocate(SegmentAllocator allocator) {
615         return allocator.allocate(layout());
616     }
617 
618     /**
619      * Allocate an array of size {@code elementCount} using {@code allocator}.
620      * The returned segment has size {@code elementCount * layout().byteSize()}.
621      */
622     public static MemorySegment allocateArray(long elementCount, SegmentAllocator allocator) {
623         return allocator.allocate(MemoryLayout.sequenceLayout(elementCount, layout()));
624     }
625 
626     /**
627      * Reinterprets {@code addr} using target {@code arena} and {@code cleanupAction} (if any).
628      * The returned segment has size {@code layout().byteSize()}
629      */
630     public static MemorySegment reinterpret(MemorySegment addr, Arena arena, Consumer<MemorySegment> cleanup) {
631         return reinterpret(addr, 1, arena, cleanup);
632     }
633 
634     /**
635      * Reinterprets {@code addr} using target {@code arena} and {@code cleanupAction} (if any).
636      * The returned segment has size {@code elementCount * layout().byteSize()}
637      */
638     public static MemorySegment reinterpret(MemorySegment addr, long elementCount, Arena arena, Consumer<MemorySegment> cleanup) {
639         return addr.reinterpret(layout().byteSize() * elementCount, arena, cleanup);
640     }
641 }
642