aboutsummaryrefslogtreecommitdiffstats
path: root/src/java/com
diff options
context:
space:
mode:
authorSven Gothel <[email protected]>2023-06-25 08:01:00 +0200
committerSven Gothel <[email protected]>2023-06-25 08:01:00 +0200
commit15ed242971142e0726e60271172266515533e1f4 (patch)
tree66d05182792f358360d6bf8cfec9f977783134e8 /src/java/com
parentb9bddbd7a75e7fa9812fdcc455a0c4857c3e9990 (diff)
GlueGen JavaConfiguration: Add 'JavaCallbackDef <funcion-pointer-typedef-name> [user-param-idx]'
Define a JavaCallback, enacted on a function-pointer argument `T2_CallbackFunc` and a user-param `void*` for Java Object mapping Example: JavaCallbackDef T2_CallbackFunc 2
Diffstat (limited to 'src/java/com')
-rw-r--r--src/java/com/jogamp/gluegen/JavaConfiguration.java48
1 files changed, 47 insertions, 1 deletions
diff --git a/src/java/com/jogamp/gluegen/JavaConfiguration.java b/src/java/com/jogamp/gluegen/JavaConfiguration.java
index 7208e97..02c7952 100644
--- a/src/java/com/jogamp/gluegen/JavaConfiguration.java
+++ b/src/java/com/jogamp/gluegen/JavaConfiguration.java
@@ -148,6 +148,8 @@ public class JavaConfiguration {
* converted to String args; value is List of Integer argument indices
*/
private final Map<String, List<Integer>> argumentsAreString = new HashMap<String, List<Integer>>();
+ private final Map<String, Integer> javaCallbackUserParams = new HashMap<String, Integer>();
+ private final List<String> javaCallbackList = new ArrayList<String>();
private final Set<String> extendedIntfSymbolsIgnore = new HashSet<String>();
private final Set<String> extendedIntfSymbolsOnly = new HashSet<String>();
private final Set<String> extendedImplSymbolsIgnore = new HashSet<String>();
@@ -531,6 +533,32 @@ public class JavaConfiguration {
return returnsStringOnly.contains(functionName);
}
+ public List<String> getJavaCallbackList() {
+ return javaCallbackList;
+ }
+
+ /** Returns an <code>Integer</code> index of the <code>void*</code>
+ user-param argument that should be converted to <code>Object</code>s for the Java Callback. Returns null if there are no
+ such hints for the given function alias symbol. */
+ public boolean isJavaCallback(final AliasedSymbol symbol) {
+ return -2 < javaCallbackUserParamIdx(symbol);
+ }
+
+ /** Returns an <code>Integer</code> index of the <code>void*</code>
+ user-param argument that should be converted to <code>Object</code>s for the Java Callback. Returns -2 if there are no
+ such hints for the given function alias symbol. */
+ public int javaCallbackUserParamIdx(final AliasedSymbol symbol) {
+ final String name = symbol.getName();
+ final Set<String> aliases = symbol.getAliasedNames();
+
+ Integer res = javaCallbackUserParams.get(name);
+ if( null == res ) {
+ res = oneInMap(javaCallbackUserParams, aliases);
+ }
+ LOG.log(INFO, getASTLocusTag(symbol), "JavaCallbackDef: {0} -> {1}", symbol, res);
+ return null != res ? res.intValue() : -2;
+ }
+
/**
* Returns a MessageFormat string of the Java expression calculating
* the number of elements in the returned array from the specified function
@@ -562,7 +590,6 @@ public class JavaConfiguration {
/** Returns a list of <code>Integer</code>s which are the indices of <code>const char*</code>
arguments that should be converted to <code>String</code>s. Returns null if there are no
such hints for the given function name. */
-
public List<Integer> stringArguments(final String functionName) {
return argumentsAreString.get(functionName);
}
@@ -1313,6 +1340,8 @@ public class JavaConfiguration {
readMaxOneElement(tok, filename, lineNo);
} else if (cmd.equalsIgnoreCase("ArgumentIsString")) {
readArgumentIsString(tok, filename, lineNo);
+ } else if (cmd.equalsIgnoreCase("JavaCallbackDef")) {
+ readJavaCallbackDef(tok, filename, lineNo);
} else if (cmd.equalsIgnoreCase("ExtendedInterfaceSymbolsIgnore")) {
readExtendedIntfImplSymbols(tok, filename, lineNo, true, false, false);
} else if (cmd.equalsIgnoreCase("ExtendedInterfaceSymbolsOnly")) {
@@ -1558,6 +1587,23 @@ public class JavaConfiguration {
}
}
+ protected void readJavaCallbackDef(final StringTokenizer tok, final String filename, final int lineNo) {
+ try {
+ final String name = tok.nextToken();
+ final Integer idx;
+ if( tok.hasMoreTokens() ) {
+ idx = Integer.valueOf(tok.nextToken());
+ } else {
+ idx = Integer.valueOf(-2);
+ }
+ javaCallbackUserParams.put(name, idx);
+ javaCallbackList.add(name);
+ } catch (final NoSuchElementException e) {
+ throw new RuntimeException("Error parsing \"JavaCallbackDef\" command at line " + lineNo +
+ " in file \"" + filename + "\"", e);
+ }
+ }
+
protected void readExtendedIntfImplSymbols(final StringTokenizer tok, final String filename, final int lineNo, final boolean forInterface, final boolean forImplementation, final boolean onlyList) {
File javaFile;
BufferedReader javaReader;