How to pass an enum as a parameter to a Graal VM Entrypoint method?

90 views Asked by At

I have a @CEntryPoint annotated method that I'm converting to a shared library and using it as a native method from a different Java application.

This annotated method returns a value based on the enum that is provided to it as a parameter.

@CEntryPoint(name="Java_package1_Mainclass_main")
public static long fetchFromEnum(Pointer jniEnv, Pointer clazz, @CentryPoint.IsolateThreadContext long isolatedId, EmployeeTierEnum var1){
//logic which returns value based on enum
}

I'm calling this as a native method from another java class as follows-

fetchFromEnum(isolate, EmployeeTierEnum.PRESIDENT);

Here is my enum's definition

@Cenum
@CContext(value=Can't tell what goes here)
public enum EmployeeTierEnum{
PRESIDENT, SECRETARY, JANITOR;

@CEnumLookup
public static native EmployeeTierEnum getJavaEnum(int cEnumVal /* not sure this will be simply an int or requires some special annoation or C datatype*/);
}

I'm aware I can't use a plain old Java enum directly in my case and I need to use some annotations to make it work. What I can't figure out is what values should I provide for CContext and what the correct data type for the singular paramter in the @CEnumLookup annotated method should be. I would love a simple example which demonstrates how these enums could work, thanks.

0

There are 0 answers