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  * typedef OrtStatus *(*RegisterCustomOpsFn)(OrtSessionOptions *, const OrtApiBase *)
18  * }
19  */
20 public class RegisterCustomOpsFn {
21 
22     RegisterCustomOpsFn() {
23         // Should not be called directly
24     }
25 
26     /**
27      * The function pointer signature, expressed as a functional interface
28      */
29     public interface Function {
30         MemorySegment apply(MemorySegment options, MemorySegment api);
31     }
32 
33     private static final FunctionDescriptor $DESC = FunctionDescriptor.of(
34         onnxruntime_c_api_h.C_POINTER,
35         onnxruntime_c_api_h.C_POINTER,
36         onnxruntime_c_api_h.C_POINTER
37     );
38 
39     /**
40      * The descriptor of this function pointer
41      */
42     public static FunctionDescriptor descriptor() {
43         return $DESC;
44     }
45 
46     private static final MethodHandle UP$MH = onnxruntime_c_api_h.upcallHandle(RegisterCustomOpsFn.Function.class, "apply", $DESC);
47 
48     /**
49      * Allocates a new upcall stub, whose implementation is defined by {@code fi}.
50      * The lifetime of the returned segment is managed by {@code arena}
51      */
52     public static MemorySegment allocate(RegisterCustomOpsFn.Function fi, Arena arena) {
53         return Linker.nativeLinker().upcallStub(UP$MH.bindTo(fi), $DESC, arena);
54     }
55 
56     private static final MethodHandle DOWN$MH = Linker.nativeLinker().downcallHandle($DESC);
57 
58     /**
59      * Invoke the upcall stub {@code funcPtr}, with given parameters
60      */
61     public static MemorySegment invoke(MemorySegment funcPtr,MemorySegment options, MemorySegment api) {
62         try {
63             return (MemorySegment) DOWN$MH.invokeExact(funcPtr, options, api);
64         } catch (Throwable ex$) {
65             throw new AssertionError("should not reach here", ex$);
66         }
67     }
68 }
69