aboutsummaryrefslogtreecommitdiffstats
path: root/src/junit/com/jogamp/gluegen/test
diff options
context:
space:
mode:
authorSven Gothel <[email protected]>2023-07-01 18:57:37 +0200
committerSven Gothel <[email protected]>2023-07-01 18:57:37 +0200
commit8766fcfdce4dd864fe6764b063a0f9a4b17327c1 (patch)
tree4fb5a2441b0a3fb9f3d12c6456f316b42b579cac /src/junit/com/jogamp/gluegen/test
parent6200b9122a90ef8c2af8b9205b4b1c90b1aa5074 (diff)
GlueGen JavaCallback: Only produce default 'Key' class if keys are used, expose 'Key' to public and use it. Expose release*() and get*Keys() methods
Further we use a dedicated lock Object used in the Java implementation. TODO: Native static callback dispatch code shall - (also) acquire the lock - handle case where the data has been released already to render this solution thread-safe and data-race free
Diffstat (limited to 'src/junit/com/jogamp/gluegen/test')
-rw-r--r--src/junit/com/jogamp/gluegen/test/junit/generation/Test4JavaCallback.java418
-rw-r--r--src/junit/com/jogamp/gluegen/test/junit/generation/test2.cfg19
2 files changed, 334 insertions, 103 deletions
diff --git a/src/junit/com/jogamp/gluegen/test/junit/generation/Test4JavaCallback.java b/src/junit/com/jogamp/gluegen/test/junit/generation/Test4JavaCallback.java
index e43d73e..badd299 100644
--- a/src/junit/com/jogamp/gluegen/test/junit/generation/Test4JavaCallback.java
+++ b/src/junit/com/jogamp/gluegen/test/junit/generation/Test4JavaCallback.java
@@ -29,9 +29,11 @@
package com.jogamp.gluegen.test.junit.generation;
import java.io.IOException;
+import java.util.Set;
import com.jogamp.common.os.NativeLibrary;
import com.jogamp.gluegen.test.junit.generation.Bindingtest2.ALBUFFERCALLBACKTYPESOFT;
+import com.jogamp.gluegen.test.junit.generation.Bindingtest2.AlBufferCallback0Key;
import com.jogamp.gluegen.test.junit.generation.Bindingtest2.T2_CallbackFunc01;
import com.jogamp.gluegen.test.junit.generation.impl.Bindingtest2Impl;
@@ -214,6 +216,9 @@ public class Test4JavaCallback extends BaseClass {
final int buffer1 = 1;
final int buffer2 = 2;
final int buffer3 = 3;
+ final AlBufferCallback0Key buffer1Key = new AlBufferCallback0Key(buffer1);
+ final AlBufferCallback0Key buffer2Key = new AlBufferCallback0Key(buffer2);
+ final AlBufferCallback0Key buffer3Key = new AlBufferCallback0Key(buffer3);
final MyUserParam02 myUserParam01 = new MyUserParam02( 1);
final MyUserParam02 myUserParam02 = new MyUserParam02( 2);
Assert.assertEquals( 1, myUserParam01.i);
@@ -223,33 +228,48 @@ public class Test4JavaCallback extends BaseClass {
Assert.assertEquals( 0, myUserParam02.j);
Assert.assertEquals( 0, myUserParam02.buffer);
- Assert.assertEquals(false, bt2.isAlBufferCallback0Mapped(buffer1));
- Assert.assertEquals(false, bt2.isAlBufferCallback0Mapped(buffer2));
- Assert.assertEquals(false, bt2.isAlBufferCallback0Mapped(buffer3));
+ Assert.assertEquals(false, bt2.isAlBufferCallback0Mapped(buffer1Key));
+ Assert.assertEquals(false, bt2.isAlBufferCallback0Mapped(buffer2Key));
+ Assert.assertEquals(false, bt2.isAlBufferCallback0Mapped(buffer3Key));
+ Assert.assertEquals(0, bt2.getAlBufferCallback0Keys().size());
// 1st mapping: buffer1 -> myCallback01, myUserParam01
bt2.alBufferCallback0(buffer1, 0, 0, myCallback01, myUserParam01);
- Assert.assertEquals(true, bt2.isAlBufferCallback0Mapped(buffer1));
- Assert.assertEquals(false, bt2.isAlBufferCallback0Mapped(buffer2));
- Assert.assertEquals(false, bt2.isAlBufferCallback0Mapped(buffer3));
- Assert.assertEquals(myUserParam01, bt2.getAlBufferCallback0UserParam(buffer1));
- Assert.assertEquals(null, bt2.getAlBufferCallback0UserParam(buffer2));
- Assert.assertEquals(null, bt2.getAlBufferCallback0UserParam(buffer3));
- Assert.assertEquals(myCallback01, bt2.getAlBufferCallback0(buffer1));
- Assert.assertEquals(null, bt2.getAlBufferCallback0(buffer2));
- Assert.assertEquals(null, bt2.getAlBufferCallback0(buffer3));
+ Assert.assertEquals(true, bt2.isAlBufferCallback0Mapped(buffer1Key));
+ Assert.assertEquals(false, bt2.isAlBufferCallback0Mapped(buffer2Key));
+ Assert.assertEquals(false, bt2.isAlBufferCallback0Mapped(buffer3Key));
+ Assert.assertEquals(myUserParam01, bt2.getAlBufferCallback0UserParam(buffer1Key));
+ Assert.assertEquals(null, bt2.getAlBufferCallback0UserParam(buffer2Key));
+ Assert.assertEquals(null, bt2.getAlBufferCallback0UserParam(buffer3Key));
+ Assert.assertEquals(myCallback01, bt2.getAlBufferCallback0(buffer1Key));
+ Assert.assertEquals(null, bt2.getAlBufferCallback0(buffer2Key));
+ Assert.assertEquals(null, bt2.getAlBufferCallback0(buffer3Key));
+ Assert.assertEquals(1, bt2.getAlBufferCallback0Keys().size());
+ {
+ final Set<AlBufferCallback0Key> keys = bt2.getAlBufferCallback0Keys();
+ Assert.assertEquals(true, keys.contains(buffer1Key));
+ Assert.assertEquals(false, keys.contains(buffer2Key));
+ Assert.assertEquals(false, keys.contains(buffer3Key));
+ }
// 2nd mapping: buffer2 -> myCallback02, myUserParam02
bt2.alBufferCallback0(buffer2, 0, 0, myCallback02, myUserParam02);
- Assert.assertEquals(true, bt2.isAlBufferCallback0Mapped(buffer1));
- Assert.assertEquals(true, bt2.isAlBufferCallback0Mapped(buffer2));
- Assert.assertEquals(false, bt2.isAlBufferCallback0Mapped(buffer3));
- Assert.assertEquals(myUserParam01, bt2.getAlBufferCallback0UserParam(buffer1));
- Assert.assertEquals(myUserParam02, bt2.getAlBufferCallback0UserParam(buffer2));
- Assert.assertEquals(null, bt2.getAlBufferCallback0UserParam(buffer3));
- Assert.assertEquals(myCallback01, bt2.getAlBufferCallback0(buffer1));
- Assert.assertEquals(myCallback02, bt2.getAlBufferCallback0(buffer2));
- Assert.assertEquals(null, bt2.getAlBufferCallback0(buffer3));
+ Assert.assertEquals(true, bt2.isAlBufferCallback0Mapped(buffer1Key));
+ Assert.assertEquals(true, bt2.isAlBufferCallback0Mapped(buffer2Key));
+ Assert.assertEquals(false, bt2.isAlBufferCallback0Mapped(buffer3Key));
+ Assert.assertEquals(myUserParam01, bt2.getAlBufferCallback0UserParam(buffer1Key));
+ Assert.assertEquals(myUserParam02, bt2.getAlBufferCallback0UserParam(buffer2Key));
+ Assert.assertEquals(null, bt2.getAlBufferCallback0UserParam(buffer3Key));
+ Assert.assertEquals(myCallback01, bt2.getAlBufferCallback0(buffer1Key));
+ Assert.assertEquals(myCallback02, bt2.getAlBufferCallback0(buffer2Key));
+ Assert.assertEquals(null, bt2.getAlBufferCallback0(buffer3Key));
+ Assert.assertEquals(2, bt2.getAlBufferCallback0Keys().size());
+ {
+ final Set<AlBufferCallback0Key> keys = bt2.getAlBufferCallback0Keys();
+ Assert.assertEquals(true, keys.contains(buffer1Key));
+ Assert.assertEquals(true, keys.contains(buffer2Key));
+ Assert.assertEquals(false, keys.contains(buffer3Key));
+ }
{
bt2.alBufferCallback0Inject(buffer1, 10, 100); // buffer1 -> myCallback01, myUserParam01
@@ -274,15 +294,15 @@ public class Test4JavaCallback extends BaseClass {
// Switch the callback function for buffer2 -> myCallback01, myUserParam02
bt2.alBufferCallback0(buffer2, 0, 0, myCallback01, myUserParam02);
- Assert.assertEquals(true, bt2.isAlBufferCallback0Mapped(buffer1));
- Assert.assertEquals(true, bt2.isAlBufferCallback0Mapped(buffer2));
- Assert.assertEquals(false, bt2.isAlBufferCallback0Mapped(buffer3));
- Assert.assertEquals(myUserParam01, bt2.getAlBufferCallback0UserParam(buffer1));
- Assert.assertEquals(myUserParam02, bt2.getAlBufferCallback0UserParam(buffer2));
- Assert.assertEquals(null, bt2.getAlBufferCallback0UserParam(buffer3));
- Assert.assertEquals(myCallback01, bt2.getAlBufferCallback0(buffer1));
- Assert.assertEquals(myCallback01, bt2.getAlBufferCallback0(buffer2));
- Assert.assertEquals(null, bt2.getAlBufferCallback0(buffer3));
+ Assert.assertEquals(true, bt2.isAlBufferCallback0Mapped(buffer1Key));
+ Assert.assertEquals(true, bt2.isAlBufferCallback0Mapped(buffer2Key));
+ Assert.assertEquals(false, bt2.isAlBufferCallback0Mapped(buffer3Key));
+ Assert.assertEquals(myUserParam01, bt2.getAlBufferCallback0UserParam(buffer1Key));
+ Assert.assertEquals(myUserParam02, bt2.getAlBufferCallback0UserParam(buffer2Key));
+ Assert.assertEquals(null, bt2.getAlBufferCallback0UserParam(buffer3Key));
+ Assert.assertEquals(myCallback01, bt2.getAlBufferCallback0(buffer1Key));
+ Assert.assertEquals(myCallback01, bt2.getAlBufferCallback0(buffer2Key));
+ Assert.assertEquals(null, bt2.getAlBufferCallback0(buffer3Key));
{
bt2.alBufferCallback0Inject(buffer1, 11, 101); // buffer1 -> myCallback01, myUserParam01
@@ -307,27 +327,41 @@ public class Test4JavaCallback extends BaseClass {
// Just release the buffer2 callback and mapped resources
bt2.alBufferCallback0(buffer2, 0, 0, null, myUserParam02); // usrptr is not key, only buffer is key!
- Assert.assertEquals(true, bt2.isAlBufferCallback0Mapped(buffer1));
- Assert.assertEquals(false, bt2.isAlBufferCallback0Mapped(buffer2));
- Assert.assertEquals(false, bt2.isAlBufferCallback0Mapped(buffer3));
- Assert.assertEquals(myUserParam01, bt2.getAlBufferCallback0UserParam(buffer1));
- Assert.assertEquals(null, bt2.getAlBufferCallback0UserParam(buffer2));
- Assert.assertEquals(null, bt2.getAlBufferCallback0UserParam(buffer3));
- Assert.assertEquals(myCallback01, bt2.getAlBufferCallback0(buffer1));
- Assert.assertEquals(null, bt2.getAlBufferCallback0(buffer2));
- Assert.assertEquals(null, bt2.getAlBufferCallback0(buffer3));
+ Assert.assertEquals(true, bt2.isAlBufferCallback0Mapped(buffer1Key));
+ Assert.assertEquals(false, bt2.isAlBufferCallback0Mapped(buffer2Key));
+ Assert.assertEquals(false, bt2.isAlBufferCallback0Mapped(buffer3Key));
+ Assert.assertEquals(myUserParam01, bt2.getAlBufferCallback0UserParam(buffer1Key));
+ Assert.assertEquals(null, bt2.getAlBufferCallback0UserParam(buffer2Key));
+ Assert.assertEquals(null, bt2.getAlBufferCallback0UserParam(buffer3Key));
+ Assert.assertEquals(myCallback01, bt2.getAlBufferCallback0(buffer1Key));
+ Assert.assertEquals(null, bt2.getAlBufferCallback0(buffer2Key));
+ Assert.assertEquals(null, bt2.getAlBufferCallback0(buffer3Key));
+ Assert.assertEquals(1, bt2.getAlBufferCallback0Keys().size());
+ {
+ final Set<AlBufferCallback0Key> keys = bt2.getAlBufferCallback0Keys();
+ Assert.assertEquals(true, keys.contains(buffer1Key));
+ Assert.assertEquals(false, keys.contains(buffer2Key));
+ Assert.assertEquals(false, keys.contains(buffer3Key));
+ }
// Just release the buffer1 callback and mapped resources
bt2.alBufferCallback0(buffer1, 0, 0, null, null); // usrptr is not key, only buffer is key!
- Assert.assertEquals(false, bt2.isAlBufferCallback0Mapped(buffer1));
- Assert.assertEquals(false, bt2.isAlBufferCallback0Mapped(buffer2));
- Assert.assertEquals(false, bt2.isAlBufferCallback0Mapped(buffer3));
- Assert.assertEquals(null, bt2.getAlBufferCallback0UserParam(buffer1));
- Assert.assertEquals(null, bt2.getAlBufferCallback0UserParam(buffer2));
- Assert.assertEquals(null, bt2.getAlBufferCallback0UserParam(buffer3));
- Assert.assertEquals(null, bt2.getAlBufferCallback0(buffer1));
- Assert.assertEquals(null, bt2.getAlBufferCallback0(buffer2));
- Assert.assertEquals(null, bt2.getAlBufferCallback0(buffer3));
+ Assert.assertEquals(false, bt2.isAlBufferCallback0Mapped(buffer1Key));
+ Assert.assertEquals(false, bt2.isAlBufferCallback0Mapped(buffer2Key));
+ Assert.assertEquals(false, bt2.isAlBufferCallback0Mapped(buffer3Key));
+ Assert.assertEquals(null, bt2.getAlBufferCallback0UserParam(buffer1Key));
+ Assert.assertEquals(null, bt2.getAlBufferCallback0UserParam(buffer2Key));
+ Assert.assertEquals(null, bt2.getAlBufferCallback0UserParam(buffer3Key));
+ Assert.assertEquals(null, bt2.getAlBufferCallback0(buffer1Key));
+ Assert.assertEquals(null, bt2.getAlBufferCallback0(buffer2Key));
+ Assert.assertEquals(null, bt2.getAlBufferCallback0(buffer3Key));
+ Assert.assertEquals(0, bt2.getAlBufferCallback0Keys().size());
+ {
+ final Set<AlBufferCallback0Key> keys = bt2.getAlBufferCallback0Keys();
+ Assert.assertEquals(false, keys.contains(buffer1Key));
+ Assert.assertEquals(false, keys.contains(buffer2Key));
+ Assert.assertEquals(false, keys.contains(buffer3Key));
+ }
{
bt2.alBufferCallback0Inject(buffer2, 1, 10); // unmapped, no change in data
@@ -373,6 +407,9 @@ public class Test4JavaCallback extends BaseClass {
final int buffer1 = 1;
final int buffer2 = 2;
final int buffer3 = 3;
+ final CustomAlBufferCallback1Key buffer1Key = new CustomAlBufferCallback1Key(buffer1);
+ final CustomAlBufferCallback1Key buffer2Key = new CustomAlBufferCallback1Key(buffer2);
+ final CustomAlBufferCallback1Key buffer3Key = new CustomAlBufferCallback1Key(buffer3);
final MyUserParam02 myUserParam01 = new MyUserParam02( 1);
final MyUserParam02 myUserParam02 = new MyUserParam02( 2);
Assert.assertEquals( 1, myUserParam01.i);
@@ -382,33 +419,48 @@ public class Test4JavaCallback extends BaseClass {
Assert.assertEquals( 0, myUserParam02.j);
Assert.assertEquals( 0, myUserParam02.buffer);
- Assert.assertEquals(false, bt2.isAlBufferCallback1Mapped(buffer1));
- Assert.assertEquals(false, bt2.isAlBufferCallback1Mapped(buffer2));
- Assert.assertEquals(false, bt2.isAlBufferCallback1Mapped(buffer3));
+ Assert.assertEquals(false, bt2.isAlBufferCallback1Mapped(buffer1Key));
+ Assert.assertEquals(false, bt2.isAlBufferCallback1Mapped(buffer2Key));
+ Assert.assertEquals(false, bt2.isAlBufferCallback1Mapped(buffer3Key));
+ Assert.assertEquals(0, bt2.getAlBufferCallback1Keys().size());
// 1st mapping: buffer1 -> myCallback01, myUserParam01
bt2.alBufferCallback1(buffer1, 0, 0, myCallback01, myUserParam01);
- Assert.assertEquals(true, bt2.isAlBufferCallback1Mapped(buffer1));
- Assert.assertEquals(false, bt2.isAlBufferCallback1Mapped(buffer2));
- Assert.assertEquals(false, bt2.isAlBufferCallback1Mapped(buffer3));
- Assert.assertEquals(myUserParam01, bt2.getAlBufferCallback1UserParam(buffer1));
- Assert.assertEquals(null, bt2.getAlBufferCallback1UserParam(buffer2));
- Assert.assertEquals(null, bt2.getAlBufferCallback1UserParam(buffer3));
- Assert.assertEquals(myCallback01, bt2.getAlBufferCallback1(buffer1));
- Assert.assertEquals(null, bt2.getAlBufferCallback1(buffer2));
- Assert.assertEquals(null, bt2.getAlBufferCallback1(buffer3));
+ Assert.assertEquals(true, bt2.isAlBufferCallback1Mapped(buffer1Key));
+ Assert.assertEquals(false, bt2.isAlBufferCallback1Mapped(buffer2Key));
+ Assert.assertEquals(false, bt2.isAlBufferCallback1Mapped(buffer3Key));
+ Assert.assertEquals(myUserParam01, bt2.getAlBufferCallback1UserParam(buffer1Key));
+ Assert.assertEquals(null, bt2.getAlBufferCallback1UserParam(buffer2Key));
+ Assert.assertEquals(null, bt2.getAlBufferCallback1UserParam(buffer3Key));
+ Assert.assertEquals(myCallback01, bt2.getAlBufferCallback1(buffer1Key));
+ Assert.assertEquals(null, bt2.getAlBufferCallback1(buffer2Key));
+ Assert.assertEquals(null, bt2.getAlBufferCallback1(buffer3Key));
+ Assert.assertEquals(1, bt2.getAlBufferCallback1Keys().size());
+ {
+ final Set<CustomAlBufferCallback1Key> keys = bt2.getAlBufferCallback1Keys();
+ Assert.assertEquals(true, keys.contains(buffer1Key));
+ Assert.assertEquals(false, keys.contains(buffer2Key));
+ Assert.assertEquals(false, keys.contains(buffer3Key));
+ }
// 2nd mapping: buffer2 -> myCallback02, myUserParam02
bt2.alBufferCallback1(buffer2, 0, 0, myCallback02, myUserParam02);
- Assert.assertEquals(true, bt2.isAlBufferCallback1Mapped(buffer1));
- Assert.assertEquals(true, bt2.isAlBufferCallback1Mapped(buffer2));
- Assert.assertEquals(false, bt2.isAlBufferCallback1Mapped(buffer3));
- Assert.assertEquals(myUserParam01, bt2.getAlBufferCallback1UserParam(buffer1));
- Assert.assertEquals(myUserParam02, bt2.getAlBufferCallback1UserParam(buffer2));
- Assert.assertEquals(null, bt2.getAlBufferCallback1UserParam(buffer3));
- Assert.assertEquals(myCallback01, bt2.getAlBufferCallback1(buffer1));
- Assert.assertEquals(myCallback02, bt2.getAlBufferCallback1(buffer2));
- Assert.assertEquals(null, bt2.getAlBufferCallback1(buffer3));
+ Assert.assertEquals(true, bt2.isAlBufferCallback1Mapped(buffer1Key));
+ Assert.assertEquals(true, bt2.isAlBufferCallback1Mapped(buffer2Key));
+ Assert.assertEquals(false, bt2.isAlBufferCallback1Mapped(buffer3Key));
+ Assert.assertEquals(myUserParam01, bt2.getAlBufferCallback1UserParam(buffer1Key));
+ Assert.assertEquals(myUserParam02, bt2.getAlBufferCallback1UserParam(buffer2Key));
+ Assert.assertEquals(null, bt2.getAlBufferCallback1UserParam(buffer3Key));
+ Assert.assertEquals(myCallback01, bt2.getAlBufferCallback1(buffer1Key));
+ Assert.assertEquals(myCallback02, bt2.getAlBufferCallback1(buffer2Key));
+ Assert.assertEquals(null, bt2.getAlBufferCallback1(buffer3Key));
+ Assert.assertEquals(2, bt2.getAlBufferCallback1Keys().size());
+ {
+ final Set<CustomAlBufferCallback1Key> keys = bt2.getAlBufferCallback1Keys();
+ Assert.assertEquals(true, keys.contains(buffer1Key));
+ Assert.assertEquals(true, keys.contains(buffer2Key));
+ Assert.assertEquals(false, keys.contains(buffer3Key));
+ }
{
bt2.alBufferCallback1Inject(buffer1, 10, 100); // buffer1 -> myCallback01, myUserParam01
@@ -433,15 +485,15 @@ public class Test4JavaCallback extends BaseClass {
// Switch the callback function for buffer2 -> myCallback01, myUserParam02
bt2.alBufferCallback1(buffer2, 0, 0, myCallback01, myUserParam02);
- Assert.assertEquals(true, bt2.isAlBufferCallback1Mapped(buffer1));
- Assert.assertEquals(true, bt2.isAlBufferCallback1Mapped(buffer2));
- Assert.assertEquals(false, bt2.isAlBufferCallback1Mapped(buffer3));
- Assert.assertEquals(myUserParam01, bt2.getAlBufferCallback1UserParam(buffer1));
- Assert.assertEquals(myUserParam02, bt2.getAlBufferCallback1UserParam(buffer2));
- Assert.assertEquals(null, bt2.getAlBufferCallback1UserParam(buffer3));
- Assert.assertEquals(myCallback01, bt2.getAlBufferCallback1(buffer1));
- Assert.assertEquals(myCallback01, bt2.getAlBufferCallback1(buffer2));
- Assert.assertEquals(null, bt2.getAlBufferCallback1(buffer3));
+ Assert.assertEquals(true, bt2.isAlBufferCallback1Mapped(buffer1Key));
+ Assert.assertEquals(true, bt2.isAlBufferCallback1Mapped(buffer2Key));
+ Assert.assertEquals(false, bt2.isAlBufferCallback1Mapped(buffer3Key));
+ Assert.assertEquals(myUserParam01, bt2.getAlBufferCallback1UserParam(buffer1Key));
+ Assert.assertEquals(myUserParam02, bt2.getAlBufferCallback1UserParam(buffer2Key));
+ Assert.assertEquals(null, bt2.getAlBufferCallback1UserParam(buffer3Key));
+ Assert.assertEquals(myCallback01, bt2.getAlBufferCallback1(buffer1Key));
+ Assert.assertEquals(myCallback01, bt2.getAlBufferCallback1(buffer2Key));
+ Assert.assertEquals(null, bt2.getAlBufferCallback1(buffer3Key));
{
bt2.alBufferCallback1Inject(buffer1, 11, 101); // buffer1 -> myCallback01, myUserParam01
@@ -466,27 +518,41 @@ public class Test4JavaCallback extends BaseClass {
// Just release the buffer2 callback and mapped resources
bt2.alBufferCallback1(buffer2, 0, 0, null, myUserParam02); // usrptr is not key, only buffer is key!
- Assert.assertEquals(true, bt2.isAlBufferCallback1Mapped(buffer1));
- Assert.assertEquals(false, bt2.isAlBufferCallback1Mapped(buffer2));
- Assert.assertEquals(false, bt2.isAlBufferCallback1Mapped(buffer3));
- Assert.assertEquals(myUserParam01, bt2.getAlBufferCallback1UserParam(buffer1));
- Assert.assertEquals(null, bt2.getAlBufferCallback1UserParam(buffer2));
- Assert.assertEquals(null, bt2.getAlBufferCallback1UserParam(buffer3));
- Assert.assertEquals(myCallback01, bt2.getAlBufferCallback1(buffer1));
- Assert.assertEquals(null, bt2.getAlBufferCallback1(buffer2));
- Assert.assertEquals(null, bt2.getAlBufferCallback1(buffer3));
+ Assert.assertEquals(true, bt2.isAlBufferCallback1Mapped(buffer1Key));
+ Assert.assertEquals(false, bt2.isAlBufferCallback1Mapped(buffer2Key));
+ Assert.assertEquals(false, bt2.isAlBufferCallback1Mapped(buffer3Key));
+ Assert.assertEquals(myUserParam01, bt2.getAlBufferCallback1UserParam(buffer1Key));
+ Assert.assertEquals(null, bt2.getAlBufferCallback1UserParam(buffer2Key));
+ Assert.assertEquals(null, bt2.getAlBufferCallback1UserParam(buffer3Key));
+ Assert.assertEquals(myCallback01, bt2.getAlBufferCallback1(buffer1Key));
+ Assert.assertEquals(null, bt2.getAlBufferCallback1(buffer2Key));
+ Assert.assertEquals(null, bt2.getAlBufferCallback1(buffer3Key));
+ Assert.assertEquals(1, bt2.getAlBufferCallback1Keys().size());
+ {
+ final Set<CustomAlBufferCallback1Key> keys = bt2.getAlBufferCallback1Keys();
+ Assert.assertEquals(true, keys.contains(buffer1Key));
+ Assert.assertEquals(false, keys.contains(buffer2Key));
+ Assert.assertEquals(false, keys.contains(buffer3Key));
+ }
// Just release the buffer1 callback and mapped resources
bt2.alBufferCallback1(buffer1, 0, 0, null, null); // usrptr is not key, only buffer is key!
- Assert.assertEquals(false, bt2.isAlBufferCallback1Mapped(buffer1));
- Assert.assertEquals(false, bt2.isAlBufferCallback1Mapped(buffer2));
- Assert.assertEquals(false, bt2.isAlBufferCallback1Mapped(buffer3));
- Assert.assertEquals(null, bt2.getAlBufferCallback1UserParam(buffer1));
- Assert.assertEquals(null, bt2.getAlBufferCallback1UserParam(buffer2));
- Assert.assertEquals(null, bt2.getAlBufferCallback1UserParam(buffer3));
- Assert.assertEquals(null, bt2.getAlBufferCallback1(buffer1));
- Assert.assertEquals(null, bt2.getAlBufferCallback1(buffer2));
- Assert.assertEquals(null, bt2.getAlBufferCallback1(buffer3));
+ Assert.assertEquals(false, bt2.isAlBufferCallback1Mapped(buffer1Key));
+ Assert.assertEquals(false, bt2.isAlBufferCallback1Mapped(buffer2Key));
+ Assert.assertEquals(false, bt2.isAlBufferCallback1Mapped(buffer3Key));
+ Assert.assertEquals(null, bt2.getAlBufferCallback1UserParam(buffer1Key));
+ Assert.assertEquals(null, bt2.getAlBufferCallback1UserParam(buffer2Key));
+ Assert.assertEquals(null, bt2.getAlBufferCallback1UserParam(buffer3Key));
+ Assert.assertEquals(null, bt2.getAlBufferCallback1(buffer1Key));
+ Assert.assertEquals(null, bt2.getAlBufferCallback1(buffer2Key));
+ Assert.assertEquals(null, bt2.getAlBufferCallback1(buffer3Key));
+ Assert.assertEquals(0, bt2.getAlBufferCallback1Keys().size());
+ {
+ final Set<CustomAlBufferCallback1Key> keys = bt2.getAlBufferCallback1Keys();
+ Assert.assertEquals(false, keys.contains(buffer1Key));
+ Assert.assertEquals(false, keys.contains(buffer2Key));
+ Assert.assertEquals(false, keys.contains(buffer3Key));
+ }
{
bt2.alBufferCallback1Inject(buffer2, 1, 10); // unmapped, no change in data
@@ -521,6 +587,166 @@ public class Test4JavaCallback extends BaseClass {
}
}
+ /**
+ * Test in depth lifecycle of Bindingtest2 with ALBUFFERCALLBACKTYPESOFT JavaCallback via alBufferCallback1()
+ * using the default AlBufferCallback1Key class.
+ */
+ @Test
+ public void chapter04() throws Exception {
+ final Bindingtest2 bt2 = new Bindingtest2Impl();
+
+ final long[] id_res = { -1 };
+ final ALBUFFERCALLBACKTYPESOFT myCallback01 = new ALBUFFERCALLBACKTYPESOFT() {
+ @Override
+ public void callback(final int buffer, final Object userptr, final int sampledata, final int numbytes) {
+ final MyUserParam02 myUserParam = (MyUserParam02)userptr;
+ id_res[0] = sampledata + numbytes + myUserParam.i;
+ myUserParam.j = id_res[0];
+ myUserParam.buffer = buffer;
+ System.err.println("chapter04.myCallback01: buffer "+buffer+", sampledata "+sampledata+", numbytes "+numbytes);
+ }
+ };
+ final ALBUFFERCALLBACKTYPESOFT myCallback02 = new ALBUFFERCALLBACKTYPESOFT() {
+ @Override
+ public void callback(final int buffer, final Object userptr, final int sampledata, final int numbytes) {
+ final MyUserParam02 myUserParam = (MyUserParam02)userptr;
+ id_res[0] = sampledata * numbytes + myUserParam.i;
+ myUserParam.j = id_res[0];
+ myUserParam.buffer = buffer;
+ System.err.println("chapter04.myCallback02: buffer "+buffer+", sampledata "+sampledata+", numbytes "+numbytes);
+ }
+ };
+ final int buffer1 = 1;
+ final int buffer2 = 2;
+ final int buffer3 = 3;
+ final AlBufferCallback0Key buffer1Key = new AlBufferCallback0Key(buffer1);
+ final AlBufferCallback0Key buffer2Key = new AlBufferCallback0Key(buffer2);
+ final AlBufferCallback0Key buffer3Key = new AlBufferCallback0Key(buffer3);
+ final MyUserParam02 myUserParam01 = new MyUserParam02( 1);
+ final MyUserParam02 myUserParam02 = new MyUserParam02( 2);
+ Assert.assertEquals( 1, myUserParam01.i);
+ Assert.assertEquals( 0, myUserParam01.j);
+ Assert.assertEquals( 0, myUserParam01.buffer);
+ Assert.assertEquals( 2, myUserParam02.i);
+ Assert.assertEquals( 0, myUserParam02.j);
+ Assert.assertEquals( 0, myUserParam02.buffer);
+
+ Assert.assertEquals(false, bt2.isAlBufferCallback0Mapped(buffer1Key));
+ Assert.assertEquals(false, bt2.isAlBufferCallback0Mapped(buffer2Key));
+ Assert.assertEquals(false, bt2.isAlBufferCallback0Mapped(buffer3Key));
+ Assert.assertEquals(0, bt2.getAlBufferCallback0Keys().size());
+
+ // 1st mapping: buffer1 -> myCallback01, myUserParam01
+ bt2.alBufferCallback0(buffer1, 0, 0, myCallback01, myUserParam01);
+ Assert.assertEquals(true, bt2.isAlBufferCallback0Mapped(buffer1Key));
+ Assert.assertEquals(false, bt2.isAlBufferCallback0Mapped(buffer2Key));
+ Assert.assertEquals(false, bt2.isAlBufferCallback0Mapped(buffer3Key));
+ Assert.assertEquals(myUserParam01, bt2.getAlBufferCallback0UserParam(buffer1Key));
+ Assert.assertEquals(null, bt2.getAlBufferCallback0UserParam(buffer2Key));
+ Assert.assertEquals(null, bt2.getAlBufferCallback0UserParam(buffer3Key));
+ Assert.assertEquals(myCallback01, bt2.getAlBufferCallback0(buffer1Key));
+ Assert.assertEquals(null, bt2.getAlBufferCallback0(buffer2Key));
+ Assert.assertEquals(null, bt2.getAlBufferCallback0(buffer3Key));
+ Assert.assertEquals(1, bt2.getAlBufferCallback0Keys().size());
+ {
+ final Set<AlBufferCallback0Key> keys = bt2.getAlBufferCallback0Keys();
+ Assert.assertEquals(true, keys.contains(buffer1Key));
+ Assert.assertEquals(false, keys.contains(buffer2Key));
+ Assert.assertEquals(false, keys.contains(buffer3Key));
+ }
+
+ // 2nd mapping: buffer2 -> myCallback02, myUserParam02
+ bt2.alBufferCallback0(buffer2, 0, 0, myCallback02, myUserParam02);
+ Assert.assertEquals(true, bt2.isAlBufferCallback0Mapped(buffer1Key));
+ Assert.assertEquals(true, bt2.isAlBufferCallback0Mapped(buffer2Key));
+ Assert.assertEquals(false, bt2.isAlBufferCallback0Mapped(buffer3Key));
+ Assert.assertEquals(myUserParam01, bt2.getAlBufferCallback0UserParam(buffer1Key));
+ Assert.assertEquals(myUserParam02, bt2.getAlBufferCallback0UserParam(buffer2Key));
+ Assert.assertEquals(null, bt2.getAlBufferCallback0UserParam(buffer3Key));
+ Assert.assertEquals(myCallback01, bt2.getAlBufferCallback0(buffer1Key));
+ Assert.assertEquals(myCallback02, bt2.getAlBufferCallback0(buffer2Key));
+ Assert.assertEquals(null, bt2.getAlBufferCallback0(buffer3Key));
+ Assert.assertEquals(2, bt2.getAlBufferCallback0Keys().size());
+ {
+ final Set<AlBufferCallback0Key> keys = bt2.getAlBufferCallback0Keys();
+ Assert.assertEquals(true, keys.contains(buffer1Key));
+ Assert.assertEquals(true, keys.contains(buffer2Key));
+ Assert.assertEquals(false, keys.contains(buffer3Key));
+ }
+
+ {
+ bt2.alBufferCallback0Inject(buffer1, 10, 100); // buffer1 -> myCallback01, myUserParam01
+ Assert.assertEquals(10+100+1, id_res[0]);
+ Assert.assertEquals( 1, myUserParam01.i);
+ Assert.assertEquals(10+100+1, myUserParam01.j);
+ Assert.assertEquals( 1, myUserParam01.buffer);
+ Assert.assertEquals( 2, myUserParam02.i);
+ Assert.assertEquals( 0, myUserParam02.j);
+ Assert.assertEquals( 0, myUserParam02.buffer);
+ }
+ {
+ bt2.alBufferCallback0Inject(buffer2, 10, 100); // buffer2 -> myCallback02, myUserParam02
+ Assert.assertEquals(10*100+2, id_res[0]);
+ Assert.assertEquals( 1, myUserParam01.i);
+ Assert.assertEquals(10+100+1, myUserParam01.j);
+ Assert.assertEquals( 1, myUserParam01.buffer);
+ Assert.assertEquals( 2, myUserParam02.i);
+ Assert.assertEquals(10*100+2, myUserParam02.j);
+ Assert.assertEquals( 2, myUserParam02.buffer);
+ }
+
+ // Just release the buffer2 callback and mapped resources
+ bt2.releaseAlBufferCallback0(buffer2Key);
+ // bt2.alBufferCallback0(buffer2, 0, 0, null, myUserParam02); // usrptr is not key, only buffer is key!
+ Assert.assertEquals(true, bt2.isAlBufferCallback0Mapped(buffer1Key));
+ Assert.assertEquals(false, bt2.isAlBufferCallback0Mapped(buffer2Key));
+ Assert.assertEquals(false, bt2.isAlBufferCallback0Mapped(buffer3Key));
+ Assert.assertEquals(myUserParam01, bt2.getAlBufferCallback0UserParam(buffer1Key));
+ Assert.assertEquals(null, bt2.getAlBufferCallback0UserParam(buffer2Key));
+ Assert.assertEquals(null, bt2.getAlBufferCallback0UserParam(buffer3Key));
+ Assert.assertEquals(myCallback01, bt2.getAlBufferCallback0(buffer1Key));
+ Assert.assertEquals(null, bt2.getAlBufferCallback0(buffer2Key));
+ Assert.assertEquals(null, bt2.getAlBufferCallback0(buffer3Key));
+ Assert.assertEquals(1, bt2.getAlBufferCallback0Keys().size());
+ {
+ final Set<AlBufferCallback0Key> keys = bt2.getAlBufferCallback0Keys();
+ Assert.assertEquals(true, keys.contains(buffer1Key));
+ Assert.assertEquals(false, keys.contains(buffer2Key));
+ Assert.assertEquals(false, keys.contains(buffer3Key));
+ }
+
+ // Just release the buffer1 callback and mapped resources
+ bt2.releaseAlBufferCallback0(buffer1Key);
+ // bt2.alBufferCallback0(buffer1, 0, 0, null, null); // usrptr is not key, only buffer is key!
+ Assert.assertEquals(false, bt2.isAlBufferCallback0Mapped(buffer1Key));
+ Assert.assertEquals(false, bt2.isAlBufferCallback0Mapped(buffer2Key));
+ Assert.assertEquals(false, bt2.isAlBufferCallback0Mapped(buffer3Key));
+ Assert.assertEquals(null, bt2.getAlBufferCallback0UserParam(buffer1Key));
+ Assert.assertEquals(null, bt2.getAlBufferCallback0UserParam(buffer2Key));
+ Assert.assertEquals(null, bt2.getAlBufferCallback0UserParam(buffer3Key));
+ Assert.assertEquals(null, bt2.getAlBufferCallback0(buffer1Key));
+ Assert.assertEquals(null, bt2.getAlBufferCallback0(buffer2Key));
+ Assert.assertEquals(null, bt2.getAlBufferCallback0(buffer3Key));
+ Assert.assertEquals(0, bt2.getAlBufferCallback0Keys().size());
+ {
+ final Set<AlBufferCallback0Key> keys = bt2.getAlBufferCallback0Keys();
+ Assert.assertEquals(false, keys.contains(buffer1Key));
+ Assert.assertEquals(false, keys.contains(buffer2Key));
+ Assert.assertEquals(false, keys.contains(buffer3Key));
+ }
+
+ if( false ){
+ bt2.alBufferCallback0Inject(buffer2, 1, 10); // unmapped, no change in data
+ Assert.assertEquals( 1+ 10+2, id_res[0]);
+ Assert.assertEquals( 1, myUserParam01.i);
+ Assert.assertEquals(11+101+1, myUserParam01.j);
+ Assert.assertEquals( 1, myUserParam01.buffer);
+ Assert.assertEquals( 2, myUserParam02.i);
+ Assert.assertEquals( 1+ 10+2, myUserParam02.j);
+ Assert.assertEquals( 2, myUserParam02.buffer);
+ }
+ }
+
public static class CustomAlBufferCallback1Key {
private final int buffer;
public CustomAlBufferCallback1Key(final int buffer) {
diff --git a/src/junit/com/jogamp/gluegen/test/junit/generation/test2.cfg b/src/junit/com/jogamp/gluegen/test/junit/generation/test2.cfg
index de713cf..812676e 100644
--- a/src/junit/com/jogamp/gluegen/test/junit/generation/test2.cfg
+++ b/src/junit/com/jogamp/gluegen/test/junit/generation/test2.cfg
@@ -62,10 +62,11 @@ ArgumentIsString InjectMessageCallback01 1
#
# This callback has no keys defines, rendering it of global scope!
#
-# Explicit queries are generated, passing the keys as paramters
+# Explicit maintenance methods are generated, passing the keys as paramters
# - `boolean isMessageCallback01Mapped()` queries whether `MessageCallback0` is mapped globally
# - `T2_CallbackFunc01 getMessageCallback01()` returns the global T2_CallbackFunc01, null if not mapped
# - `Object getMessageCallback01UserParam()` returns the global `usrParam` object, null if not mapped
+# - `void releaseMessageCallback01()` releases callback data skipping toolkit API. Favor passing `null` callback ref to `MessageCallback01(..)`
JavaCallbackDef MessageCallback01 T2_CallbackFunc01 2
#
# End JavaCallback
@@ -87,10 +88,11 @@ ArgumentIsString alEventCallbackInject 3
# This callback has no keys defines, rendering it of global scope!
# The global key-less scope matches `AL_SOFT_events` semantics.
#
-# Explicit queries are generated, passing the keys as paramters
+# Explicit maintenance methods are generated, passing the keys as paramters
# - `boolean isAlEventCallbackMapped()` queries whether `alEventCallback` is mapped globally
# - `ALEVENTPROCSOFT getAlEventCallback()` returns the global ALEVENTPROCSOFT, null if not mapped
# - `Object getAlEventCallbackUserParam()` returns the global `userParam` object, null if not mapped
+# - `void releaseAlEventCallback()` releases callback data skipping toolkit API. Favor passing `null` callback ref to `alEventCallback(..)`
JavaCallbackDef alEventCallback ALEVENTPROCSOFT 5
JavaCallbackKey alEventCallback
#
@@ -115,10 +117,13 @@ JavaCallbackKey alEventCallback
# This callback defines one key, `buffer`, index 0 of alBufferCallback0(..) parameter list, limiting it to buffer-name scope!
# The `buffer` key allows setting one callback per buffer-name, compatible with the `AL_SOFT_callback_buffer` spec.
#
-# Explicit queries are generated, passing the keys as paramters
-# - `boolean isAlBufferCallback0Mapped(int buffer)` queries whether `alBufferCallback0` is mapped to `buffer`.
-# - `ALBUFFERCALLBACKTYPESOFT getAlBufferCallback0(int buffer)` returns the `buffer` mapped ALEVENTPROCSOFT, null if not mapped
-# - `Object getAlBufferCallback0UserParam(int buffer)` returns the `buffer` mapped `userptr` object, null if not mapped
+# Explicit maintenance methods are generated, passing the keys as paramters
+# - `Set<AlBufferCallback0Key> getAlBufferCallback0Keys()` returns set of Key { int buffer }
+# - `boolean isAlBufferCallback0Mapped(AlBufferCallback0Key)` queries whether `alBufferCallback0` is mapped to `buffer`.
+# - `ALBUFFERCALLBACKTYPESOFT getAlBufferCallback0(AlBufferCallback0Key)` returns the `buffer` mapped ALEVENTPROCSOFT, null if not mapped
+# - `Object getAlBufferCallback0UserParam(AlBufferCallback0Key)` returns the `buffer` mapped `userptr` object, null if not mapped
+# - `void releaseAllAlBufferCallback0()` releases all callback data mapped via Key { int buffer } skipping toolkit API. Favor passing `null` callback ref to `alBufferCallback0(..)`
+# - `void releaseAlBufferCallback0(AlBufferCallback0Key)` releases callback data mapped to Key { int buffer } skipping toolkit API. Favor passing `null` callback ref to `alBufferCallback0(..)`
JavaCallbackDef alBufferCallback0 ALBUFFERCALLBACKTYPESOFT 1
JavaCallbackKey alBufferCallback0 0
#
@@ -142,7 +147,7 @@ JavaCallbackKey alBufferCallback0 0
# This callback defines one key, `buffer`, index 0 of alBufferCallback1(..) parameter list, limiting it to buffer-name scope!
# The `buffer` key allows setting one callback per buffer-name, compatible with the `AL_SOFT_callback_buffer` spec.
#
-# Explicit queries are generated, passing the keys as paramters
+# Explicit maintenance methods are generated, passing the keys as paramters
# - `boolean isAlBufferCallback1Mapped(int buffer)` queries whether `alBufferCallback1` is mapped to `buffer`.
# - `ALBUFFERCALLBACKTYPESOFT getAlBufferCallback1(int buffer)` returns the `buffer` mapped ALEVENTPROCSOFT, null if not mapped
# - `Object getAlBufferCallback1UserParam(int buffer)` returns the `buffer` mapped `userptr` object, null if not mapped