public final class CEntryPointLiteral<T extends CFunctionPointer> extends Object
entry point method
that can be, for example, handed
out to C code so that C code can call back into Java code. The method that is referred to must be
annotated with CEntryPoint
, which imposes certain restrictions.
The actual value of the function pointer is only available at run time. To prevent accidental
access to it during native image generation, the actual function
pointer
is encapsulated in this class. The call to CEntryPointLiteral.getFunctionPointer()
fails with an
exception during native image generation.
Instances of this class can only be created during native image generation. It is not possible to look up a function by name at run time. The intended use case is therefore as follows:
// Function that is externally accessible @CEntryPoint static int myFunction(IsolateThread thread, int x, int y) { ... } // Invocation interface (for calls from Java, otherwise CFunctionPointer suffices) interface MyFunctionPointer extends FunctionPointer { @InvokeCFunctionPointer int invoke(IsolateThread thread, int x, int y); } // Function pointer literal public static final CEntryPointLiteral<MyFunctionPointer> myFunctionLiteral = CEntryPointLiteral.create(MyClass.class, "myFunction", new Class>[]{IsolateThread.class, int.class, int.class}); // Call from Java void caller() { MyFunctionPointer fp = myFunctionLiteral.getFunctionPointer(); // entry point, could be returned to C code int fiftyeight = fp.invoke(CurrentIsolate.getCurrentThread(), 47, 11); }
Modifier and Type | Method and Description |
---|---|
static <T extends CFunctionPointer> |
create(Class<?> definingClass,
String methodName,
Class<?>... parameterTypes)
Creates a new function pointer to an entry point.
|
T |
getFunctionPointer()
Returns the function pointer to the entry point.
|
public static <T extends CFunctionPointer> CEntryPointLiteral<T> create(Class<?> definingClass, String methodName, Class<?>... parameterTypes)
public T getFunctionPointer()