diff options
Diffstat (limited to 'src/java/com/jogamp/gluegen')
-rw-r--r-- | src/java/com/jogamp/gluegen/JavaCallbackEmitter.java | 25 | ||||
-rw-r--r-- | src/java/com/jogamp/gluegen/JavaConfiguration.java | 48 | ||||
-rw-r--r-- | src/java/com/jogamp/gluegen/JavaEmitter.java | 22 |
3 files changed, 68 insertions, 27 deletions
diff --git a/src/java/com/jogamp/gluegen/JavaCallbackEmitter.java b/src/java/com/jogamp/gluegen/JavaCallbackEmitter.java index 05192d3..dbd38aa 100644 --- a/src/java/com/jogamp/gluegen/JavaCallbackEmitter.java +++ b/src/java/com/jogamp/gluegen/JavaCallbackEmitter.java @@ -55,6 +55,7 @@ public final class JavaCallbackEmitter { final boolean userParamIsMappedToID; final String userParamIDMapInstanceName; + final String userParamClassName; final boolean customKeyClass; final String KeyClassName; final boolean useDataMap; @@ -98,9 +99,17 @@ public final class JavaCallbackEmitter { userParamIDMapInstanceName = null; } - if( null != javaCallback.setFuncKeyClassName ) { + if( userParamIsCompound ) { + userParamClassName = setFuncUserParamTypeName; + } else if( null != javaCallback.userParamClassName ) { + userParamClassName = javaCallback.userParamClassName; + } else { + userParamClassName = "Object"; + } + + if( null != javaCallback.customKeyClassName ) { customKeyClass = true;; - KeyClassName = javaCallback.setFuncKeyClassName; + KeyClassName = javaCallback.customKeyClassName; useDataMap = true; } else { customKeyClass = false; @@ -127,7 +136,7 @@ public final class JavaCallbackEmitter { unit.emitln(" public "+info.cbFuncTypeName+" get"+capIfaceName+"("+KeyClassName+" key);"); unit.emitln(); emitJavaBriefAPIDoc(unit, "Returns user-param ", "mapped to ", "", "for "); - unit.emitln(" public Object get"+capIfaceName+"UserParam("+KeyClassName+" key);"); + unit.emitln(" public "+userParamClassName+" get"+capIfaceName+"UserParam("+KeyClassName+" key);"); unit.emitln(); emitJavaBriefAPIDoc(unit, "Releases all callback data ", "mapped via ", "", "skipping toolkit API. Favor passing `null` callback ref to "); unit.emitln(" public int releaseAll"+capIfaceName+"();"); @@ -143,7 +152,7 @@ public final class JavaCallbackEmitter { unit.emitln(" public "+info.cbFuncTypeName+" get"+capIfaceName+"();"); unit.emitln(); emitJavaBriefAPIDoc(unit, "Returns user-param ", "mapped to ", "", "for "); - unit.emitln(" public Object get"+capIfaceName+"UserParam();"); + unit.emitln(" public "+userParamClassName+" get"+capIfaceName+"UserParam();"); unit.emitln(); emitJavaBriefAPIDoc(unit, "Releases callback data ", "", "", "skipping toolkit API. Favor passing `null` callback ref to "); unit.emitln(" public void release"+capIfaceName+"();"); @@ -181,7 +190,7 @@ public final class JavaCallbackEmitter { unit.emitln(); emitJavaBriefAPIDoc(unit, "Returns user-param ", "mapped to ", "", "for "); - unit.emitln(" public final Object get"+capIfaceName+"UserParam("+KeyClassName+" key) {"); + unit.emitln(" public final "+userParamClassName+" get"+capIfaceName+"UserParam("+KeyClassName+" key) {"); unit.emitln(" synchronized( "+lockInstanceName+" ) {"); unit.emitln(" final "+DataClassName+" value = "+dataMapInstanceName+".get(key);"); unit.emitln(" return null != value ? value.param : null;"); @@ -234,7 +243,7 @@ public final class JavaCallbackEmitter { unit.emitln(); emitJavaBriefAPIDoc(unit, "Returns user-param ", "mapped to ", "", "for "); - unit.emitln(" public final Object get"+capIfaceName+"UserParam() {"); + unit.emitln(" public final "+userParamClassName+" get"+capIfaceName+"UserParam() {"); unit.emitln(" synchronized( "+lockInstanceName+" ) {"); unit.emitln(" final "+DataClassName+" value = "+dataInstanceName+";"); unit.emitln(" return null != value ? value.param : null;"); @@ -524,12 +533,12 @@ public final class JavaCallbackEmitter { unit.emitln(" final "+origUserParamJType[0]+" "+info.cbFuncUserParamName+" = "+origUserParamJType[0]+".derefPointer(nativeUserParam);"); useParamLocal[0] = true; } else if( userParamIsMappedToID && userParamIsKey ) { - unit.emitln(" final Object "+info.cbFuncUserParamName+";"); + unit.emitln(" final "+userParamClassName+" "+info.cbFuncUserParamName+";"); } unit.emitln(" final "+DataClassName+" value;"); unit.emitln(" synchronized( "+lockInstanceName+" ) {"); if( userParamIsMappedToID && userParamIsKey && !mapNativePtrToCompound[0] ) { - unit.emitln(" "+info.cbFuncUserParamName+" = "+userParamIDMapInstanceName+".get(nativeUserParam);"); + unit.emitln(" "+info.cbFuncUserParamName+" = ("+userParamClassName+") "+userParamIDMapInstanceName+".get(nativeUserParam);"); useParamLocal[0] = true; } if( useDataMap ) { diff --git a/src/java/com/jogamp/gluegen/JavaConfiguration.java b/src/java/com/jogamp/gluegen/JavaConfiguration.java index e530e0c..f5242b8 100644 --- a/src/java/com/jogamp/gluegen/JavaConfiguration.java +++ b/src/java/com/jogamp/gluegen/JavaConfiguration.java @@ -192,19 +192,23 @@ public class JavaConfiguration { final String setFuncName; final int setFuncUserParamIdx; // optional final List<Integer> cbFuncKeyIndices = new ArrayList<Integer>(); - final String setFuncKeyClassName; // optional + final String userParamClassName; // optional + final String customKeyClassName; // optional final List<Integer> setFuncKeyIndices = new ArrayList<Integer>(); - JavaCallbackDef(final String cbFuncTypeName, final int cbFuncUserParamIdx, final String setFuncName, final int setFuncUserParamIdx, final String setFuncKeyClassName) { + JavaCallbackDef(final String cbFuncTypeName, final int cbFuncUserParamIdx, final String setFuncName, final int setFuncUserParamIdx, + final String userParamClassName, final String customKeyClassName) { this.cbFuncTypeName = cbFuncTypeName; this.cbFuncUserParamIdx = cbFuncUserParamIdx; this.setFuncName = setFuncName; this.setFuncUserParamIdx = setFuncUserParamIdx; - this.setFuncKeyClassName = setFuncKeyClassName; + this.userParamClassName = userParamClassName; + this.customKeyClassName = customKeyClassName; } @Override public String toString() { - return String.format("JavaCallbackDef[cbFunc[type %s, userParamIdx %d, keys %s], set[%s, keys %s, userParamIdx %d, KeyClass %s]]", - cbFuncTypeName, cbFuncUserParamIdx, cbFuncKeyIndices.toString(), setFuncName, setFuncKeyIndices.toString(), setFuncUserParamIdx, setFuncKeyClassName); + return String.format("JavaCallbackDef[cbFunc[type %s, userParamIdx %d, keys %s], set[%s, keys %s, userParamIdx %d], Class[UserParam %s, Key %s]]", + cbFuncTypeName, cbFuncUserParamIdx, cbFuncKeyIndices.toString(), setFuncName, setFuncKeyIndices.toString(), setFuncUserParamIdx, + userParamClassName, customKeyClassName); } } private final List<JavaCallbackDef> javaCallbackList = new ArrayList<JavaCallbackDef>(); @@ -1696,13 +1700,26 @@ public class JavaConfiguration { final int setFuncUserParamIdx = Integer.parseInt(tok.nextToken()); final String cbFuncTypeName = tok.nextToken(); final int cbFuncUserParamIdx = Integer.parseInt(tok.nextToken()); - final String cbFuncKeyClassName; + final String userParamClassName; + final String customKeyClassName; if( tok.hasMoreTokens() ) { - cbFuncKeyClassName = tok.nextToken(); + final String s = tok.nextToken(); + if( s.length() == 0 || s.equals("null") ) { + userParamClassName = null; + } else { + userParamClassName = s; + } + if( tok.hasMoreTokens() ) { + customKeyClassName = tok.nextToken(); + } else { + customKeyClassName = null; + } } else { - cbFuncKeyClassName = null; + userParamClassName = null; + customKeyClassName = null; } - final JavaCallbackDef jcd = new JavaCallbackDef(cbFuncTypeName, cbFuncUserParamIdx, setFuncName, setFuncUserParamIdx, cbFuncKeyClassName); + final JavaCallbackDef jcd = new JavaCallbackDef(cbFuncTypeName, cbFuncUserParamIdx, setFuncName, setFuncUserParamIdx, + userParamClassName, customKeyClassName); javaCallbackList.add(jcd); javaCallbackSetFuncToDef.put(setFuncName, jcd); } catch (final NoSuchElementException e) { @@ -2408,15 +2425,17 @@ public class JavaConfiguration { final String setFuncName; final List<Integer> setFuncKeyIndices; - final String setFuncKeyClassName; final int setFuncUserParamIdx; + final String userParamClassName; // optional + final String customKeyClassName; // optional boolean setFuncProcessed; int setFuncCBParamIdx; boolean keyClassEmitted; public JavaCallbackInfo(final String cbFuncTypeName, final String cbSimpleClazzName, final String cbFQClazzName, final String staticCBMethodSignature, final FunctionType cbFuncType, final MethodBinding cbFuncBinding, final int cbFuncUserParamIdx, final List<Integer> cbFuncKeyIndices, - final String setFuncName, final int setFuncUserParamIdx, final List<Integer> setFuncKeyIndices, final String setFuncKeyClassName) { + final String setFuncName, final int setFuncUserParamIdx, final List<Integer> setFuncKeyIndices, + final String userParamClassName, final String customKeyClassName) { this.cbFuncTypeName = cbFuncTypeName; this.cbSimpleClazzName = cbSimpleClazzName; this.cbFQClazzName = cbFQClazzName; @@ -2443,8 +2462,9 @@ public class JavaConfiguration { } this.setFuncName = setFuncName; this.setFuncKeyIndices = setFuncKeyIndices; - this.setFuncKeyClassName = setFuncKeyClassName; this.setFuncUserParamIdx = setFuncUserParamIdx; + this.userParamClassName = userParamClassName; + this.customKeyClassName = customKeyClassName; this.setFuncProcessed = false; this.setFuncCBParamIdx = -1; this.keyClassEmitted = false; @@ -2479,11 +2499,11 @@ public class JavaConfiguration { @Override public String toString() { - return String.format("JavaCallbackInfo[cbFunc[%s%s, userParam[idx %d, '%s', %s, keys %s], set[%s(ok %b, cbIdx %d, upIdx %d, keys %s, KeyClass '%s'], %s]", + return String.format("JavaCallbackInfo[cbFunc[%s%s, userParam[idx %d, '%s', %s, keys %s], set[%s(ok %b, cbIdx %d, upIdx %d, keys %s], Class[UserParam '%s', Key '%s'], %s]", cbFuncTypeName, staticCBMethodSignature, cbFuncUserParamIdx, cbFuncUserParamName, cbFuncUserParamType.getSignature(null).toString(), cbFuncKeyIndices.toString(), setFuncName, setFuncProcessed, setFuncCBParamIdx, setFuncUserParamIdx, - setFuncKeyIndices.toString(), setFuncKeyClassName, + setFuncKeyIndices.toString(), userParamClassName, customKeyClassName, cbFuncType.toString(cbFuncTypeName, false, true)); } } diff --git a/src/java/com/jogamp/gluegen/JavaEmitter.java b/src/java/com/jogamp/gluegen/JavaEmitter.java index 88cff27..576e9bc 100644 --- a/src/java/com/jogamp/gluegen/JavaEmitter.java +++ b/src/java/com/jogamp/gluegen/JavaEmitter.java @@ -1474,14 +1474,15 @@ public class JavaEmitter implements GlueEmitter { } final JavaCallbackInfo jcbi1 = new JavaCallbackInfo(jcbd.cbFuncTypeName, cbSimpleClazzName, cbFQClazzName, jcbi0.staticCBMethodSignature, funcType, jcbi0.cbFuncBinding, jcbi0.cbFuncUserParamIdx, jcbd.cbFuncKeyIndices, - jcbd.setFuncName, jcbd.setFuncUserParamIdx, jcbd.setFuncKeyIndices, jcbd.setFuncKeyClassName); + jcbd.setFuncName, jcbd.setFuncUserParamIdx, jcbd.setFuncKeyIndices, + jcbd.userParamClassName, jcbd.customKeyClassName); cfg.setFuncToJavaCallbackMap.put(jcbd.setFuncName, jcbi1); LOG.log(INFO, "JavaCallbackInfo: Reusing {0} -> {1}", jcbd.setFuncName, jcbi0); } else { final StringBuilder cbMethodSignature = new StringBuilder(); javaUnit.emitln(" /** JavaCallback interface: "+jcbd.cbFuncTypeName+" -> "+funcType.toString(jcbd.cbFuncTypeName, false, true)+" */"); javaUnit.emitln(" public static interface "+cbSimpleClazzName+" {"); - final List<MethodBinding> mbs = generateFunctionInterfaceCode(javaUnit, funcSym, jcbd.cbFuncUserParamIdx, cbMethodSignature); + final List<MethodBinding> mbs = generateFunctionInterfaceCode(javaUnit, funcSym, jcbd, cbMethodSignature); javaUnit.emitln(" }"); javaUnit.emitln(); if( 1 != mbs.size() ) { @@ -1494,7 +1495,8 @@ public class JavaEmitter implements GlueEmitter { } final JavaCallbackInfo jcbi1 = new JavaCallbackInfo(jcbd.cbFuncTypeName, cbSimpleClazzName, cbFQClazzName, cbMethodSignature.toString(), funcType, cbFuncBinding, jcbd.cbFuncUserParamIdx, jcbd.cbFuncKeyIndices, - jcbd.setFuncName, jcbd.setFuncUserParamIdx, jcbd.setFuncKeyIndices, jcbd.setFuncKeyClassName); + jcbd.setFuncName, jcbd.setFuncUserParamIdx, jcbd.setFuncKeyIndices, + jcbd.userParamClassName, jcbd.customKeyClassName); cfg.setFuncToJavaCallbackMap.put(jcbd.setFuncName, jcbi1); javaCallbackInterfaceMap.put(cbFQClazzName, jcbi1); LOG.log(INFO, "JavaCallbackInfo: Added {0} -> {1}", jcbd.setFuncName, jcbi1); @@ -1502,15 +1504,23 @@ public class JavaEmitter implements GlueEmitter { } private final Map<String, JavaCallbackInfo> javaCallbackInterfaceMap = new HashMap<String, JavaCallbackInfo>(); - private List<MethodBinding> generateFunctionInterfaceCode(final JavaCodeUnit javaUnit, final FunctionSymbol funcSym, final int userParamIdx, final StringBuilder methodSignature) { + private List<MethodBinding> generateFunctionInterfaceCode(final JavaCodeUnit javaUnit, final FunctionSymbol funcSym, final JavaCallbackDef jcbd, final StringBuilder methodSignature) { // Emit method call and associated native code MethodBinding mb = bindFunction(funcSym, true /* forInterface */, machDescJava, null, null); // Replace optional userParam argument 'void*' with Object + final int userParamIdx = jcbd.cbFuncUserParamIdx; if( 0 <= userParamIdx && userParamIdx < mb.getNumArguments() ) { final JavaType t = mb.getJavaArgumentType(userParamIdx); if ( t.isCVoidPointerType() ) { - mb = mb.replaceJavaArgumentType(userParamIdx, JavaType.forObjectClass()); + final JavaType mappedType; + if( null != jcbd.userParamClassName ) { + mappedType = JavaType.createForNamedClass( jcbd.userParamClassName ); + mb = mb.replaceJavaArgumentType(userParamIdx, JavaType.forObjectClass()); + } else { + mappedType = JavaType.forObjectClass(); + } + mb = mb.replaceJavaArgumentType(userParamIdx, mappedType); } } // Produce the method signature @@ -3124,6 +3134,8 @@ public class JavaEmitter implements GlueEmitter { if( cArgType.getTargetType().isVoid() ) { if( jcbi.cbFuncUserParamType.isCompound() ) { mappedType = JavaType.createForClass(long.class); + } else if( null != jcbi.userParamClassName ) { + mappedType = JavaType.createForNamedClass( jcbi.userParamClassName ); } else { mappedType = JavaType.forObjectClass(); } |