diff options
author | Sven Gothel <[email protected]> | 2023-07-04 11:36:29 +0200 |
---|---|---|
committer | Sven Gothel <[email protected]> | 2023-07-04 11:36:29 +0200 |
commit | a599b852a041ba3d80b43981589ac1390979dac2 (patch) | |
tree | 038c5e3a6a03dae16ae83893ae2a91e76357daa7 /src/java/com/jogamp/gluegen/FunctionEmitter.java | |
parent | 6d53b4b1dd07006e7af0e540b2c2e6ee6e1746d5 (diff) |
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.
Diffstat (limited to 'src/java/com/jogamp/gluegen/FunctionEmitter.java')
-rw-r--r-- | src/java/com/jogamp/gluegen/FunctionEmitter.java | 57 |
1 files changed, 41 insertions, 16 deletions
diff --git a/src/java/com/jogamp/gluegen/FunctionEmitter.java b/src/java/com/jogamp/gluegen/FunctionEmitter.java index a089a41..5037fc4 100644 --- a/src/java/com/jogamp/gluegen/FunctionEmitter.java +++ b/src/java/com/jogamp/gluegen/FunctionEmitter.java @@ -114,6 +114,7 @@ public abstract class FunctionEmitter { * Emit the function to the {@link #getUnit()} */ public final void emit() { + emitAdditionalCode(); emitDocComment(); //output.println(" // Emitter: " + getClass().getName()); emitSignature(); @@ -139,6 +140,7 @@ public abstract class FunctionEmitter { */ public CommentEmitter getCommentEmitter() { return commentEmitter; } + protected void emitAdditionalCode() { } protected void emitDocComment() { if (commentEmitter != null) { @@ -154,32 +156,42 @@ public abstract class FunctionEmitter { } } - protected void emitSignature() { + protected final void emitSignature() { + unit.emit(appendSignature(new StringBuilder()).toString()); + } - unit.emit(getBaseIndentString()); // indent method + protected StringBuilder appendSignature(final StringBuilder buf) { + buf.append(getBaseIndentString()); // indent method - final int numEmitted = emitModifiers(); + final int numEmitted = appendModifiers(buf); if (numEmitted > 0) { - unit.emit(" "); + buf.append(" "); } - emitReturnType(); - unit.emit(" "); + appendReturnType(buf); + buf.append(" "); - emitName(); - unit.emit("("); + appendName(buf); + buf.append("("); - emitArguments(); - unit.emit(")"); + appendArguments(buf); + buf.append(")"); + return buf; } - protected int emitModifiers() { + protected final int emitModifiers() { + final StringBuilder buf = new StringBuilder(); + final int n = appendModifiers(buf); + unit.emit(buf.toString()); + return n; + } + protected int appendModifiers(final StringBuilder buf) { int numEmitted = 0; for (final Iterator<EmissionModifier> it = getModifiers(); it.hasNext(); ) { - unit.emit(it.next().toString()); + buf.append(it.next().toString()); ++numEmitted; if (it.hasNext()) { - unit.emit(" "); + buf.append(" "); } } return numEmitted; @@ -190,10 +202,23 @@ public abstract class FunctionEmitter { protected String getCommentStartString() { return "/* "; } protected String getCommentEndString() { return " */"; } - protected abstract void emitReturnType(); - protected abstract void emitName(); + protected final void emitReturnType() { + unit.emit(appendReturnType(new StringBuilder()).toString()); + } + protected abstract StringBuilder appendReturnType(StringBuilder buf); + protected final void emitName() { + unit.emit(appendName(new StringBuilder()).toString()); + } + protected abstract StringBuilder appendName(StringBuilder buf); + /** Returns the number of arguments emitted. */ + protected final int emitArguments() { + final StringBuilder buf = new StringBuilder(); + final int n = appendArguments(buf); + unit.emit(buf.toString()); + return n; + } /** Returns the number of arguments emitted. */ - protected abstract int emitArguments(); + protected abstract int appendArguments(StringBuilder buf); protected abstract void emitBody(); public static class EmissionModifier { |