summaryrefslogtreecommitdiffstats
path: root/src/junit
diff options
context:
space:
mode:
authorSven Gothel <[email protected]>2023-06-30 11:36:33 +0200
committerSven Gothel <[email protected]>2023-06-30 11:36:33 +0200
commita73c992290930e617c78241bae9fe20cb18a01a9 (patch)
tree85115a5cf25d8b5018a8c2d78244272f504851e0 /src/junit
parentb35d62425311ec50e6c80b07372bc411aa287bb4 (diff)
GlueGen JavaCallback: Resolve key mapping of callback and associated resources via 'JavaCallbackKey' config and custom `SetCallback-KeyClass`
Updated unit test and doc accordingly. Unit tests handle OpenAL's AL_SOFT_callback_buffer and AL_SOFT_events. Tested global scope (no key, default) and 1 key (default) and 1 key (custom class). Added more query functions, which all only take the `SetCallbackFunction` key arguments as specified. Cleaned up JavaCallback* config class field naminig scheme. Added 'synchronized (..Map) { }' block in crucial `SetCallbackFunction`, rendering implementation thread safe.
Diffstat (limited to 'src/junit')
-rw-r--r--src/junit/com/jogamp/gluegen/test/junit/generation/Test4JavaCallback.java404
-rw-r--r--src/junit/com/jogamp/gluegen/test/junit/generation/test2.c80
-rw-r--r--src/junit/com/jogamp/gluegen/test/junit/generation/test2.cfg107
-rw-r--r--src/junit/com/jogamp/gluegen/test/junit/generation/test2.h32
4 files changed, 597 insertions, 26 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 e80be6f..e43d73e 100644
--- a/src/junit/com/jogamp/gluegen/test/junit/generation/Test4JavaCallback.java
+++ b/src/junit/com/jogamp/gluegen/test/junit/generation/Test4JavaCallback.java
@@ -31,6 +31,7 @@ package com.jogamp.gluegen.test.junit.generation;
import java.io.IOException;
import com.jogamp.common.os.NativeLibrary;
+import com.jogamp.gluegen.test.junit.generation.Bindingtest2.ALBUFFERCALLBACKTYPESOFT;
import com.jogamp.gluegen.test.junit.generation.Bindingtest2.T2_CallbackFunc01;
import com.jogamp.gluegen.test.junit.generation.impl.Bindingtest2Impl;
@@ -83,30 +84,30 @@ public class Test4JavaCallback extends BaseClass {
final T2_CallbackFunc01 myCallback01 = new T2_CallbackFunc01() {
@Override
public void callback(final long id, final String msg, final Object userParam) {
- final MyUserParam myUserParam = (MyUserParam)userParam;
+ final MyUserParam01 myUserParam = (MyUserParam01)userParam;
id_res[0] = id + myUserParam.i;
msg_res[0] = msg;
myUserParam.j += id_res[0];
- System.err.println("chapter10.myCallback01: "+id+", '"+msg+"'");
+ System.err.println("chapter01.myCallback01: "+id+", '"+msg+"'");
}
};
final T2_CallbackFunc01 myCallback02 = new T2_CallbackFunc01() {
@Override
public void callback(final long id, final String msg, final Object userParam) {
- final MyUserParam myUserParam = (MyUserParam)userParam;
+ final MyUserParam01 myUserParam = (MyUserParam01)userParam;
id_res[0] = id;
msg_res[0] = msg;
myUserParam.j += id_res[0];
- System.err.println("chapter10.myCallback02: "+id+", '"+msg+"'");
+ System.err.println("chapter01.myCallback02: "+id+", '"+msg+"'");
}
};
- final MyUserParam myUserParam01 = new MyUserParam(10);
+ final MyUserParam01 myUserParam01 = new MyUserParam01(10);
Assert.assertEquals(10, myUserParam01.i);
Assert.assertEquals( 0, myUserParam01.j);
- Assert.assertEquals(false, bt2.isMessageCallback01Mapped(myUserParam01));
+ Assert.assertEquals(false, bt2.isMessageCallback01Mapped());
bt2.MessageCallback01(myCallback01, myUserParam01);
- Assert.assertEquals(true, bt2.isMessageCallback01Mapped(myUserParam01));
+ Assert.assertEquals(true, bt2.isMessageCallback01Mapped());
Assert.assertEquals(-1, id_res[0]);
Assert.assertEquals(null, msg_res[0]);
Assert.assertEquals(10, myUserParam01.i);
@@ -132,7 +133,7 @@ public class Test4JavaCallback extends BaseClass {
// Switch the callback function
// The previously mapped myUserParam01 gets released and remapped to new callback
bt2.MessageCallback01(myCallback02, myUserParam01);
- Assert.assertEquals(true, bt2.isMessageCallback01Mapped(myUserParam01));
+ Assert.assertEquals(true, bt2.isMessageCallback01Mapped());
Assert.assertEquals( 42+10, id_res[0]);
Assert.assertEquals( msgNo2, msg_res[0]);
Assert.assertEquals( 10, myUserParam01.i);
@@ -149,7 +150,7 @@ public class Test4JavaCallback extends BaseClass {
// Just release the callback and mapped myUserParam01
bt2.MessageCallback01(null, myUserParam01);
- Assert.assertEquals(false, bt2.isMessageCallback01Mapped(myUserParam01));
+ Assert.assertEquals(false, bt2.isMessageCallback01Mapped());
{
final String msgNo4 = "My Fourth JavaCallback message";
bt2.InjectMessageCallback01( 21, msgNo4);
@@ -160,11 +161,392 @@ public class Test4JavaCallback extends BaseClass {
Assert.assertEquals(1+42+10+404+10, myUserParam01.j);
}
}
- private static class MyUserParam {
+ private static class MyUserParam01 {
final long i;
long j;
- public MyUserParam(final long i) { this.i = i; j=0; }
+ public MyUserParam01(final long i) { this.i = i; j=0; }
+
+ @Override
+ public boolean equals(final Object o) {
+ if( this == o ) {
+ return true;
+ }
+ if( !(o instanceof MyUserParam01) ) {
+ return false;
+ }
+ return false; // we require identity!
+ }
+ @Override
+ public int hashCode() {
+ return System.identityHashCode(this); // we require identity!
+ }
+ }
+
+ /**
+ * Test Bindingtest2 with ALBUFFERCALLBACKTYPESOFT JavaCallback via alBufferCallback1()
+ * using the default AlBufferCallback1Key class.
+ */
+ @Test
+ public void chapter02() 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("chapter02.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("chapter02.myCallback02: buffer "+buffer+", sampledata "+sampledata+", numbytes "+numbytes);
+ }
+ };
+ final int buffer1 = 1;
+ final int buffer2 = 2;
+ final int buffer3 = 3;
+ 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(buffer1));
+ Assert.assertEquals(false, bt2.isAlBufferCallback0Mapped(buffer2));
+ Assert.assertEquals(false, bt2.isAlBufferCallback0Mapped(buffer3));
+
+ // 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));
+
+ // 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));
+
+ {
+ 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);
+ }
+
+ // 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));
+
+ {
+ bt2.alBufferCallback0Inject(buffer1, 11, 101); // buffer1 -> myCallback01, myUserParam01
+ Assert.assertEquals(11+101+1, 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(10*100+2, myUserParam02.j);
+ Assert.assertEquals( 2, myUserParam02.buffer);
+ }
+ {
+ bt2.alBufferCallback0Inject(buffer2, 1, 10); // buffer2 -> myCallback01, myUserParam02
+ 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);
+ }
+
+ // 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));
+
+ // 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));
+
+ {
+ 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);
+ }
+ }
+
+ /**
+ * Test Bindingtest2 with ALBUFFERCALLBACKTYPESOFT JavaCallback via alBufferCallback1()
+ * using our custom CustomAlBufferCallback1Key class.
+ */
+ @Test
+ public void chapter03() 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("chapter03.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("chapter03.myCallback02: buffer "+buffer+", sampledata "+sampledata+", numbytes "+numbytes);
+ }
+ };
+ final int buffer1 = 1;
+ final int buffer2 = 2;
+ final int buffer3 = 3;
+ 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.isAlBufferCallback1Mapped(buffer1));
+ Assert.assertEquals(false, bt2.isAlBufferCallback1Mapped(buffer2));
+ Assert.assertEquals(false, bt2.isAlBufferCallback1Mapped(buffer3));
+
+ // 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));
+
+ // 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));
+
+ {
+ bt2.alBufferCallback1Inject(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.alBufferCallback1Inject(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);
+ }
+
+ // 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));
+
+ {
+ bt2.alBufferCallback1Inject(buffer1, 11, 101); // buffer1 -> myCallback01, myUserParam01
+ Assert.assertEquals(11+101+1, 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(10*100+2, myUserParam02.j);
+ Assert.assertEquals( 2, myUserParam02.buffer);
+ }
+ {
+ bt2.alBufferCallback1Inject(buffer2, 1, 10); // buffer2 -> myCallback01, myUserParam02
+ 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);
+ }
+
+ // 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));
+
+ // 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));
+
+ {
+ bt2.alBufferCallback1Inject(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);
+ }
+ }
+ private static class MyUserParam02 {
+ final long i;
+ long j;
+ int buffer;
+ public MyUserParam02(final long i) { this.i = i; j=0; buffer=0; }
+
+ @Override
+ public boolean equals(final Object o) {
+ if( this == o ) {
+ return true;
+ }
+ if( !(o instanceof MyUserParam02) ) {
+ return false;
+ }
+ return false; // we require identity!
+ }
+ @Override
+ public int hashCode() {
+ return System.identityHashCode(this); // we require identity!
+ }
+ }
+
+ public static class CustomAlBufferCallback1Key {
+ private final int buffer;
+ public CustomAlBufferCallback1Key(final int buffer) {
+ this.buffer = buffer;
+ }
+ @Override
+ public boolean equals(final Object o) {
+ if( this == o ) {
+ return true;
+ }
+ if( !(o instanceof CustomAlBufferCallback1Key) ) {
+ return false;
+ }
+ final CustomAlBufferCallback1Key o2 = (CustomAlBufferCallback1Key)o;
+ return buffer == o2.buffer;
+ }
+ @Override
+ public int hashCode() {
+ return buffer;
+ }
+ @Override
+ public String toString() {
+ return "CustomALKey[this "+toHexString(System.identityHashCode(this))+", buffer "+buffer+"]";
+ }
}
+ static private String toHexString(final int v) { return "0x"+Integer.toHexString(v); }
public static void main(final String args[]) throws IOException {
final String tstname = Test4JavaCallback.class.getName();
diff --git a/src/junit/com/jogamp/gluegen/test/junit/generation/test2.c b/src/junit/com/jogamp/gluegen/test/junit/generation/test2.c
index 9715f11..7a7cb43 100644
--- a/src/junit/com/jogamp/gluegen/test/junit/generation/test2.c
+++ b/src/junit/com/jogamp/gluegen/test/junit/generation/test2.c
@@ -86,6 +86,10 @@ int Release(T2_InitializeOptions* Options) {
Options->CustomFuncB2 = NULL;
}
+//
+//
+//
+
static T2_CallbackFunc01 t2_callback01 = NULL;
static void* t2_callback01_userparam = NULL;
@@ -104,3 +108,79 @@ void InjectMessageCallback01(size_t id, const char* msg) {
}
}
+//
+//
+//
+
+static ALEVENTPROCSOFT alEventCallback_cb = NULL;
+static void* alEventCallback_up = NULL;
+
+void alEventCallback(ALEVENTPROCSOFT callback, void *userParam) {
+ alEventCallback_cb = callback;
+ alEventCallback_up = userParam;
+}
+void alEventCallbackInject(int eventType, int object, int param, const char* msg) {
+ if( NULL != alEventCallback_cb ) {
+ fprintf(stderr, "XXX InjectMessageCallback01 func %p, user %p\n", alEventCallback_cb, alEventCallback_up);
+ fflush(NULL);
+ (*alEventCallback_cb)(eventType, object, param, strlen(msg), msg, alEventCallback_up);
+ }
+}
+
+//
+//
+//
+
+static const int MAX_AL_BUFFER = 5;
+static ALBUFFERCALLBACKTYPESOFT alBufferCallback0_callback[] = { NULL, NULL, NULL, NULL, NULL };
+static void* alBufferCallback0_userptr[] = { NULL, NULL, NULL, NULL, NULL };
+
+void alBufferCallback0(int buffer /* key */, int format, int freq, ALBUFFERCALLBACKTYPESOFT callback, void *userptr) {
+ if( buffer < 0 || MAX_AL_BUFFER <= buffer ) {
+ fprintf(stderr, "Error: alBufferCallback0: buffer not in range [0..%d), is %d\n", MAX_AL_BUFFER, buffer);
+ } else {
+ alBufferCallback0_callback[buffer] = callback;
+ alBufferCallback0_userptr[buffer] = userptr;
+ fprintf(stderr, "XXX alBufferCallback0 buffer %d -> func %p, user %p\n", buffer, callback, userptr);
+ }
+ fflush(NULL);
+}
+void alBufferCallback0Inject(int buffer, int sampledata, int numbytes) {
+ if( buffer < 0 || MAX_AL_BUFFER <= buffer ) {
+ fprintf(stderr, "Error: alBufferCallback0Inject: buffer not in range [0..%d), is %d\n", MAX_AL_BUFFER, buffer);
+ }
+ if( NULL != alBufferCallback0_callback[buffer] ) {
+ fprintf(stderr, "XXX alBufferCallback0Inject: buffer %d, func %p, user %p\n", buffer, alBufferCallback0_callback[buffer], alBufferCallback0_userptr[buffer]);
+ fflush(NULL);
+ (*alBufferCallback0_callback[buffer])(buffer, alBufferCallback0_userptr[buffer], sampledata, numbytes);
+ }
+}
+
+//
+//
+//
+
+static ALBUFFERCALLBACKTYPESOFT alBufferCallback1_callback[] = { NULL, NULL, NULL, NULL, NULL };
+static void* alBufferCallback1_userptr[] = { NULL, NULL, NULL, NULL, NULL };
+
+void alBufferCallback1(int buffer /* key */, int format, int freq, ALBUFFERCALLBACKTYPESOFT callback, void *userptr) {
+ if( buffer < 0 || MAX_AL_BUFFER <= buffer ) {
+ fprintf(stderr, "Error: alBufferCallback1: buffer not in range [0..%d), is %d\n", MAX_AL_BUFFER, buffer);
+ } else {
+ alBufferCallback1_callback[buffer] = callback;
+ alBufferCallback1_userptr[buffer] = userptr;
+ fprintf(stderr, "XXX alBufferCallback1 buffer %d -> func %p, user %p\n", buffer, callback, userptr);
+ }
+ fflush(NULL);
+}
+void alBufferCallback1Inject(int buffer, int sampledata, int numbytes) {
+ if( buffer < 0 || MAX_AL_BUFFER <= buffer ) {
+ fprintf(stderr, "Error: alBufferCallback1Inject: buffer not in range [0..%d), is %d\n", MAX_AL_BUFFER, buffer);
+ }
+ if( NULL != alBufferCallback1_callback[buffer] ) {
+ fprintf(stderr, "XXX alBufferCallback1Inject: buffer %d, func %p, user %p\n", buffer, alBufferCallback1_callback[buffer], alBufferCallback1_userptr[buffer]);
+ fflush(NULL);
+ (*alBufferCallback1_callback[buffer])(buffer, alBufferCallback1_userptr[buffer], sampledata, numbytes);
+ }
+}
+
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 94ea0af..de713cf 100644
--- a/src/junit/com/jogamp/gluegen/test/junit/generation/test2.cfg
+++ b/src/junit/com/jogamp/gluegen/test/junit/generation/test2.cfg
@@ -55,24 +55,111 @@ ArgumentIsString T2_CallbackFunc01 1
ArgumentIsString InjectMessageCallback01 1
# Define a JavaCallback.
-# Set JavaCallback via function `MessageCallback01` if `T2_CallbackFunc01` argument is non-null, otherwise removes the callback and associated resources.
-# It uses `usrParam` as the resource-key to map to the hidden native-usrParam object,
-# hence a matching 'usrParam' must be passed for setting and removal of the callback.
+# Set JavaCallback via function `MessageCallback01` if `T2_CallbackFunc01` argument is non-null, otherwise removes the mapped callback and associated resources.
#
# It uses the function-pointer argument `T2_CallbackFunc01` as the callback function type
-# and marks `T2_CallbackFunc01`s 3rd argument (index 2) as the mandatory user-param for Java Object mapping.
+# and marks `T2_CallbackFunc01`s 3rd argument (index 2) as the mandatory user-param.
#
-# Note: An explicit `isMessageCallback01Mapped(Object usrParam)` is being created to explicitly query whether `usrParam` maps to the associated resources.
+# This callback has no keys defines, rendering it of global scope!
+#
+# Explicit queries 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
JavaCallbackDef MessageCallback01 T2_CallbackFunc01 2
+#
+# End JavaCallback
+# Begin JavaCallback.
+#
+# typedef void ( * ALEVENTPROCSOFT)(int eventType, int object, int param, int length, const char *message, void *userParam);
+# void alEventCallback(ALEVENTPROCSOFT callback, void *userParam /* identity-key */);
+# void alEventCallbackInject(int eventType, int object, int param, const char* msg);
+ArgumentIsString ALEVENTPROCSOFT 4
+ArgumentIsString alEventCallbackInject 3
+
+# Define a JavaCallback (OpenAL AL_SOFT_events)
+# Set JavaCallback via function `alEventCallback` if `ALEVENTPROCSOFT` argument is non-null, otherwise removes the mapped callback and associated resources.
+#
+# It uses the function-pointer argument `ALEVENTPROCSOFT` as the callback function type
+# and marks `ALEVENTPROCSOFT`s 6th argument (index 5) as the mandatory user-param.
+#
+# 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
+# - `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
+JavaCallbackDef alEventCallback ALEVENTPROCSOFT 5
+JavaCallbackKey alEventCallback
#
# End JavaCallback
-# typedef void ( * T2_CallbackFunc02)(const T2_Callback02UserType* usrParam);
-# void MessageCallback02(T2_CallbackFunc02 cbFunc, const T2_Callback02UserType* usrParam);
-# void InjectMessageCallback02(size_t id, const char* msg);
-ArgumentIsString InjectMessageCallback02 1
-JavaCallbackDef MessageCallback02 T2_CallbackFunc02 0
+# Begin JavaCallback (OpanAL AL_SOFT_callback_buffer)
+#
+# // typedef void ( * ALBUFFERCALLBACKTYPESOFT)(int buffer, void *userptr, void *sampledata, int numbytes);
+# typedef void ( * ALBUFFERCALLBACKTYPESOFT)(int buffer, void *userptr, int sampledata, int numbytes);
+#
+# void alBufferCallback0(int buffer /* key */, int format, int freq, ALBUFFERCALLBACKTYPESOFT callback, void *userptr /* identity-key */);
+#
+# // void alBufferCallback0Inject(int buffer, void *sampledata, int numbytes);
+# void alBufferCallback0Inject(int buffer, int sampledata, int numbytes);
+
+# Define a JavaCallback.
+# Set JavaCallback via function `alBufferCallback0` if `ALBUFFERCALLBACKTYPESOFT` argument is non-null, otherwise removes the mapped callback and associated resources.
+#
+# It uses the function-pointer argument `ALBUFFERCALLBACKTYPESOFT` as the callback function type
+# and marks `ALBUFFERCALLBACKTYPESOFT`s 2nd argument (index 1) as the mandatory user-param.
+#
+# 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
+JavaCallbackDef alBufferCallback0 ALBUFFERCALLBACKTYPESOFT 1
+JavaCallbackKey alBufferCallback0 0
+#
+# End JavaCallback
+
+# Begin JavaCallback (OpanAL AL_SOFT_callback_buffer, variant 2)
+#
+# Reuses: ALBUFFERCALLBACKTYPESOFT, see above.
+#
+# void alBufferCallback1(int buffer /* key */, int format, int freq, ALBUFFERCALLBACKTYPESOFT callback, void *userptr /* identity-key */);
+#
+# // void alBufferCallback1Inject(int buffer, void *sampledata, int numbytes);
+# void alBufferCallback1Inject(int buffer, int sampledata, int numbytes);
+
+# Define a JavaCallback.
+# Set JavaCallback via function `alBufferCallback1` if `ALBUFFERCALLBACKTYPESOFT` argument is non-null, otherwise removes the mapped callback and associated resources.
+#
+# It uses the function-pointer argument `ALBUFFERCALLBACKTYPESOFT` as the callback function type
+# and marks `ALBUFFERCALLBACKTYPESOFT`s 2nd argument (index 1) as the mandatory user-param.
+#
+# 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
+# - `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
+JavaCallbackDef alBufferCallback1 ALBUFFERCALLBACKTYPESOFT 1 com.jogamp.gluegen.test.junit.generation.Test4JavaCallback.CustomAlBufferCallback1Key
+JavaCallbackKey alBufferCallback1 0
+#
+# End JavaCallback
+
+# Begin JavaCallback
+#
+# typedef void ( * T2_CallbackFunc11)(const T2_Callback11UserType* usrParam);
+# void MessageCallback11(T2_CallbackFunc11 cbFunc, const T2_Callback11UserType* usrParam);
+# void InjectMessageCallback11(size_t id, const char* msg);
+ArgumentIsString InjectMessageCallback11 1
+JavaCallbackDef MessageCallback11 T2_CallbackFunc11 0
+#
+# End JavaCallback
CustomCCode #include "test2.h"
diff --git a/src/junit/com/jogamp/gluegen/test/junit/generation/test2.h b/src/junit/com/jogamp/gluegen/test/junit/generation/test2.h
index afe94a5..d067390 100644
--- a/src/junit/com/jogamp/gluegen/test/junit/generation/test2.h
+++ b/src/junit/com/jogamp/gluegen/test/junit/generation/test2.h
@@ -67,15 +67,37 @@ void MessageCallback01(T2_CallbackFunc01 cbFunc, void* usrParam);
void InjectMessageCallback01(size_t id, const char* msg);
//
-// T2_CallbackFunc02
+// ALEVENTPROCSOFT (similar to OpenAL's AL_SOFT_events)
+//
+typedef void ( * ALEVENTPROCSOFT)(int eventType, int object, int param, int length, const char *message, void *userParam);
+
+void alEventCallback(ALEVENTPROCSOFT callback, void *userParam);
+void alEventCallbackInject(int eventType, int object, int param, const char* msg);
+
+//
+// ALBUFFERCALLBACKTYPESOFT (similar to OpenAL's AL_SOFT_callback_buffer)
+//
+// typedef void ( * ALBUFFERCALLBACKTYPESOFT)(int buffer, void *userptr, void *sampledata, int numbytes);
+typedef void ( * ALBUFFERCALLBACKTYPESOFT)(int buffer, void *userptr, int sampledata, int numbytes);
+
+void alBufferCallback0(int buffer /* key */, int format, int freq, ALBUFFERCALLBACKTYPESOFT callback, void *userptr);
+// void alBufferCallback0Inject(int buffer, void *sampledata, int numbytes);
+void alBufferCallback0Inject(int buffer, int sampledata, int numbytes);
+
+void alBufferCallback1(int buffer /* key */, int format, int freq, ALBUFFERCALLBACKTYPESOFT callback, void *userptr);
+// void alBufferCallback1Inject(int buffer, void *sampledata, int numbytes);
+void alBufferCallback1Inject(int buffer, int sampledata, int numbytes);
+
+//
+// T2_CallbackFunc11
//
typedef struct {
int32_t ApiVersion;
void* Data;
-} T2_Callback02UserType;
+} T2_Callback11UserType;
-typedef void ( * T2_CallbackFunc02)(const T2_Callback02UserType* usrParam);
+typedef void ( * T2_CallbackFunc11)(const T2_Callback11UserType* usrParam);
-void MessageCallback02(T2_CallbackFunc02 cbFunc, const T2_Callback02UserType* usrParam);
-void InjectMessageCallback02(size_t id, const char* msg);
+void MessageCallback11(T2_CallbackFunc11 cbFunc, const T2_Callback11UserType* usrParam);
+void InjectMessageCallback11(size_t id, const char* msg);