From a599b852a041ba3d80b43981589ac1390979dac2 Mon Sep 17 00:00:00 2001 From: Sven Gothel Date: Tue, 4 Jul 2023 11:36:29 +0200 Subject: GlueGen JavaCallback: Revised: Static Java callback dispatcher, dropping native heap, support Struct UserParam ... Implementation now generates a static Java callback dispatcher for each defined SetCallbackFunction, which gets invoked by the generated native static counterpart with all arguments required. The static callback utilizes its own synchronization for thread-safety and fetches the required data set stored at SetCallbackFunction to dispatch the call to the users' CallbackFunction. In case the callback has been removed already, the static callback simply bails out quietly. The native code does not create, release or manage heap memory and therefore is considered safe. +++ Further Struct Type UserParam are now supported including Heterogeneous UserParam mapping (read GlueGen_Mapping.*). +++ Cleaned up code by extracting all JavaCallback emitter code into JavaCallbackEmitter class in one place, leaving JavaMethodbindingEmitter and CMethodbindingEmitter mostly in their original stage (non-convoluted). In this regard, I had to refactor a few function, i.e. moving CMethodbindingEmitter.getJNIMangledArg(..) into JavaType.appendDescriptor(..) and JavaType.appendJNIDescriptor(..) while reusing the toJNIMethodDescriptor(..) conversion. Test4JavaCallback covers and passes all cases. --- src/java/com/jogamp/gluegen/CCodeUnit.java | 15 --------------- 1 file changed, 15 deletions(-) (limited to 'src/java/com/jogamp/gluegen/CCodeUnit.java') diff --git a/src/java/com/jogamp/gluegen/CCodeUnit.java b/src/java/com/jogamp/gluegen/CCodeUnit.java index c70df79..5c0db27 100644 --- a/src/java/com/jogamp/gluegen/CCodeUnit.java +++ b/src/java/com/jogamp/gluegen/CCodeUnit.java @@ -84,11 +84,6 @@ public class CCodeUnit extends CodeUnit { emitln( getJNIOnLoadJNIEnvCode(libraryBasename) ); } - /** Emits {@link #JavaCallbackGlueDataDecl}. */ - public void emitJavaCallbackGlueDataDecl() { - emitln( JavaCallbackGlueDataDecl ); - } - @Override public String toString() { return "CCodeUnit[unit "+cUnitName+", file "+filename+"]"; } @@ -113,16 +108,6 @@ public class CCodeUnit extends CodeUnit { " return jbyteBuffer;\n"+ "}\n"; - /** JavaCallback Glue Data typedef struct */ - public static final String JavaCallbackGlueDataDecl = - "typedef struct {\n"+ - " jobject lockObj;\n"+ - " jobject cbFunc;\n"+ - " jmethodID cbMethodID;\n"+ - " jobject userParam;\n"+ - "} T_JavaCallbackGlueData;\n"+ - "\n"; - /** * Returns native JNI declarations for `JavaVM* {libraryBasename}_jvmHandle` * and `JVMUtil_GetJNIEnv(..)`. -- cgit v1.2.3