diff options
author | Sven Gothel <[email protected]> | 2023-07-08 01:43:47 +0200 |
---|---|---|
committer | Sven Gothel <[email protected]> | 2023-07-08 01:43:47 +0200 |
commit | 701311d6fc507b1e21681dd60c6851fbc50c2304 (patch) | |
tree | 85bc26b705a9549454ac20f3092c86b566253e3e /src/junit/com/jogamp | |
parent | 4267e223e33acdc098cc5b4371765f8e31b96eff (diff) |
GlueGen JavaCallback: Add capability to have UserParam as (part of) key
Resolves use case where UserParam reflects e.g. a context (AL_SOFT_events)
and will be (part of) the key mapping.
Implementation required an additional userParamID -> userParam mapping for default Object/ID usage.
Added 2 test cases.
Diffstat (limited to 'src/junit/com/jogamp')
6 files changed, 492 insertions, 60 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 bc04977..90e01df 100644 --- a/src/junit/com/jogamp/gluegen/test/junit/generation/Test4JavaCallback.java +++ b/src/junit/com/jogamp/gluegen/test/junit/generation/Test4JavaCallback.java @@ -33,7 +33,10 @@ 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.ALEVENTPROCSOFT; import com.jogamp.gluegen.test.junit.generation.Bindingtest2.AlBufferCallback0Key; +import com.jogamp.gluegen.test.junit.generation.Bindingtest2.AlEventCallback0Key; +import com.jogamp.gluegen.test.junit.generation.Bindingtest2.AlEventCallback1Key; import com.jogamp.gluegen.test.junit.generation.Bindingtest2.MessageCallback11aKey; import com.jogamp.gluegen.test.junit.generation.Bindingtest2.MessageCallback11bKey; import com.jogamp.gluegen.test.junit.generation.Bindingtest2.T2_CallbackFunc01; @@ -363,6 +366,48 @@ public class Test4JavaCallback extends BaseClass { Assert.assertEquals(false, keys.contains(buffer3Key)); } + // Switch the callback function for buffer2 -> myCallback01, myUserParam02 + { + // pre-condition + 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()); + } + bt2.alBufferCallback0(buffer1, 0, 0, myCallback02, myUserParam02); + { + // post-state + Assert.assertEquals(true, bt2.isAlBufferCallback0Mapped(buffer1Key)); + Assert.assertEquals(false, bt2.isAlBufferCallback0Mapped(buffer2Key)); + Assert.assertEquals(false, bt2.isAlBufferCallback0Mapped(buffer3Key)); + Assert.assertEquals(myUserParam02, bt2.getAlBufferCallback0UserParam(buffer1Key)); + Assert.assertEquals(null, bt2.getAlBufferCallback0UserParam(buffer2Key)); + Assert.assertEquals(null, bt2.getAlBufferCallback0UserParam(buffer3Key)); + Assert.assertEquals(myCallback02, bt2.getAlBufferCallback0(buffer1Key)); + Assert.assertEquals(null, bt2.getAlBufferCallback0(buffer2Key)); + Assert.assertEquals(null, bt2.getAlBufferCallback0(buffer3Key)); + } + { + myUserParam01.j = 0; + myUserParam01.buffer = 0; + myUserParam02.j = 0; + myUserParam02.buffer = 0; + bt2.alBufferCallback0Inject(buffer1, 2, 10); // buffer1 -> myCallback01, myUserParam01 + Assert.assertEquals( 2*10+2, id_res[0]); + Assert.assertEquals( 1, myUserParam01.i); + Assert.assertEquals( 0, myUserParam01.j); + Assert.assertEquals( 0, myUserParam01.buffer); + Assert.assertEquals( 2, myUserParam02.i); + Assert.assertEquals( 2*10+2, myUserParam02.j); + Assert.assertEquals( 1, myUserParam02.buffer); + } + // 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(buffer1Key)); @@ -383,14 +428,19 @@ public class Test4JavaCallback extends BaseClass { } { + id_res[0] = 0; + myUserParam01.j = 0; + myUserParam01.buffer = 0; + myUserParam02.j = 0; + myUserParam02.buffer = 0; bt2.alBufferCallback0Inject(buffer2, 1, 10); // unmapped, no change in data - Assert.assertEquals( 1+ 10+2, id_res[0]); + Assert.assertEquals( 0, id_res[0]); Assert.assertEquals( 1, myUserParam01.i); - Assert.assertEquals(11+101+1, myUserParam01.j); - Assert.assertEquals( 1, myUserParam01.buffer); + Assert.assertEquals( 0, myUserParam01.j); + Assert.assertEquals( 0, myUserParam01.buffer); Assert.assertEquals( 2, myUserParam02.i); - Assert.assertEquals( 1+ 10+2, myUserParam02.j); - Assert.assertEquals( 2, myUserParam02.buffer); + Assert.assertEquals( 0, myUserParam02.j); + Assert.assertEquals( 0, myUserParam02.buffer); } } @@ -882,6 +932,264 @@ public class Test4JavaCallback extends BaseClass { } /** + * Test Bindingtest2 with ALEVENTPROCSOFT JavaCallback + * on alEventCallback0(..) having the 'Object userParam` as single key. + */ + @Test + public void chapter05a() throws Exception { + final Bindingtest2 bt2 = new Bindingtest2Impl(); + + final int[] id_res = { -1 }; + final String[] msg_res = { null }; + final ALEVENTPROCSOFT myCallback01 = new ALEVENTPROCSOFT() { + @Override + public void callback(final int eventType, final int object, final int param, final int length, final String message, final Object userParam) { + id_res[0] = object; + msg_res[0] = message; + System.err.println("chapter05a.myCallback01: type "+eventType+", obj "+object+", param "+param+", '"+message+"', userParam 0x"+ + Integer.toHexString(System.identityHashCode(userParam))); + } + }; + final ALEVENTPROCSOFT myCallback02 = new ALEVENTPROCSOFT() { + @Override + public void callback(final int eventType, final int object, final int param, final int length, final String message, final Object userParam) { + id_res[0] = 1000 * object; + msg_res[0] = message; + System.err.println("chapter05a.myCallback02: type "+eventType+", obj "+object+", param "+param+", '"+message+"', userParam 0x"+ + Integer.toHexString(System.identityHashCode(userParam))); + } + }; + final Object myUserParam01 = new Object(); + final Object myUserParam02 = new Object(); + final AlEventCallback0Key myKey01 = new AlEventCallback0Key(myUserParam01); + final AlEventCallback0Key myKey02 = new AlEventCallback0Key(myUserParam02); + Assert.assertEquals(false, bt2.isAlEventCallback0Mapped(myKey01)); + Assert.assertEquals(false, bt2.isAlEventCallback0Mapped(myKey02)); + + bt2.alEventCallback0(myCallback01, myUserParam01); + Assert.assertEquals(true, bt2.isAlEventCallback0Mapped(myKey01)); + Assert.assertEquals(false, bt2.isAlEventCallback0Mapped(myKey02)); + { + final Set<AlEventCallback0Key> keys = bt2.getAlEventCallback0Keys(); + Assert.assertEquals(1, keys.size()); + Assert.assertEquals(true, keys.contains(myKey01)); + Assert.assertEquals(false, keys.contains(myKey02)); + } + Assert.assertEquals(myCallback01, bt2.getAlEventCallback0(myKey01)); + Assert.assertEquals(null, bt2.getAlEventCallback0(myKey02)); + Assert.assertEquals(-1, id_res[0]); + Assert.assertEquals(null, msg_res[0]); + + { + final String msgNo1 = "First message"; + id_res[0] = -1; + msg_res[0] = null; + bt2.alEventCallback0Inject(myUserParam01, 0, 1, 0, msgNo1); + Assert.assertEquals( 1, id_res[0]); + Assert.assertEquals(msgNo1, msg_res[0]); + } + { + final String msgNo2 = "Second message"; + id_res[0] = -1; + msg_res[0] = null; + bt2.alEventCallback0Inject(myUserParam02, 0, 2, 0, msgNo2); + Assert.assertEquals( -1, id_res[0]); + Assert.assertEquals( null, msg_res[0]); + + bt2.alEventCallback0Inject(myUserParam01, 0, 2, 0, msgNo2); + Assert.assertEquals( 2, id_res[0]); + Assert.assertEquals( msgNo2, msg_res[0]); + } + + // Switch the callback function + // The previously mapped myCallback01 (myUserParam01) gets released + // and remapped to myCallback02 + ( myUserParam01 )(key) + bt2.alEventCallback0(myCallback02, myUserParam01); + Assert.assertEquals(true, bt2.isAlEventCallback0Mapped(myKey01)); + Assert.assertEquals(false, bt2.isAlEventCallback0Mapped(myKey02)); + { + final Set<AlEventCallback0Key> keys = bt2.getAlEventCallback0Keys(); + Assert.assertEquals(1, keys.size()); + Assert.assertEquals(true, keys.contains(myKey01)); + Assert.assertEquals(false, keys.contains(myKey02)); + } + Assert.assertEquals(myCallback02, bt2.getAlEventCallback0(myKey01)); + Assert.assertEquals(null, bt2.getAlEventCallback0(myKey02)); + + { + final String msgNo3 = "Third message"; + id_res[0] = -1; + msg_res[0] = null; + bt2.alEventCallback0Inject(myUserParam02, 0, 3, 0, msgNo3); + Assert.assertEquals( -1, id_res[0]); + Assert.assertEquals( null, msg_res[0]); + + bt2.alEventCallback0Inject(myUserParam01, 0, 3, 0, msgNo3); + Assert.assertEquals( 3000, id_res[0]); + Assert.assertEquals( msgNo3, msg_res[0]); + } + + // Fake release (wrong key) + bt2.alEventCallback0(null, myUserParam02); + Assert.assertEquals(true, bt2.isAlEventCallback0Mapped(myKey01)); + Assert.assertEquals(false, bt2.isAlEventCallback0Mapped(myKey02)); + + // Just release the callback and mapped myUserParam01 + bt2.alEventCallback0(null, myUserParam01); + Assert.assertEquals(false, bt2.isAlEventCallback0Mapped(myKey01)); + Assert.assertEquals(false, bt2.isAlEventCallback0Mapped(myKey02)); + Assert.assertEquals(0, bt2.getAlEventCallback0Keys().size()); + + { + final String msgNo4 = "Forth message"; + id_res[0] = -1; + msg_res[0] = null; + bt2.alEventCallback0Inject(myUserParam01, 0, 4, 0, msgNo4); + Assert.assertEquals( -1, id_res[0]); + Assert.assertEquals( null, msg_res[0]); + + bt2.alEventCallback0Inject(myUserParam02, 0, 4, 0, msgNo4); + Assert.assertEquals( -1, id_res[0]); + Assert.assertEquals( null, msg_res[0]); + } + } + + /** + * Test Bindingtest2 with ALEVENTPROCSOFT JavaCallback + * on alEventCallback0(..) having the 'Object userParam` and `int object` as keys. + */ + @Test + public void chapter05b() throws Exception { + final Bindingtest2 bt2 = new Bindingtest2Impl(); + + final int[] id_res = { -1 }; + final String[] msg_res = { null }; + final ALEVENTPROCSOFT myCallback01 = new ALEVENTPROCSOFT() { + @Override + public void callback(final int eventType, final int object, final int param, final int length, final String message, final Object userParam) { + id_res[0] = object; + msg_res[0] = message; + System.err.println("chapter05.myCallback01: type "+eventType+", obj "+object+", param "+param+", '"+message+"', userParam 0x"+ + Integer.toHexString(System.identityHashCode(userParam))); + } + }; + final ALEVENTPROCSOFT myCallback02 = new ALEVENTPROCSOFT() { + @Override + public void callback(final int eventType, final int object, final int param, final int length, final String message, final Object userParam) { + id_res[0] = 1000 * object; + msg_res[0] = message; + System.err.println("chapter05.myCallback02: type "+eventType+", obj "+object+", param "+param+", '"+message+"', userParam 0x"+ + Integer.toHexString(System.identityHashCode(userParam))); + } + }; + final Object myUserParam01 = new Object(); + final Object myUserParam02 = new Object(); + final AlEventCallback1Key myKey01 = new AlEventCallback1Key(1, myUserParam01); + final AlEventCallback1Key myKey02 = new AlEventCallback1Key(2, myUserParam02); + Assert.assertEquals(false, bt2.isAlEventCallback1Mapped(myKey01)); + Assert.assertEquals(false, bt2.isAlEventCallback1Mapped(myKey02)); + + bt2.alEventCallback1(1, myCallback01, myUserParam01); + Assert.assertEquals(true, bt2.isAlEventCallback1Mapped(myKey01)); + Assert.assertEquals(false, bt2.isAlEventCallback1Mapped(myKey02)); + { + final Set<AlEventCallback1Key> keys = bt2.getAlEventCallback1Keys(); + Assert.assertEquals(1, keys.size()); + Assert.assertEquals(true, keys.contains(myKey01)); + Assert.assertEquals(false, keys.contains(myKey02)); + } + Assert.assertEquals(myCallback01, bt2.getAlEventCallback1(myKey01)); + Assert.assertEquals(null, bt2.getAlEventCallback1(myKey02)); + Assert.assertEquals(-1, id_res[0]); + Assert.assertEquals(null, msg_res[0]); + + { + final String msgNo1 = "First message"; + id_res[0] = -1; + msg_res[0] = null; + bt2.alEventCallback1Inject(myUserParam01, 0, 1, 0, msgNo1); + Assert.assertEquals( 1, id_res[0]); + Assert.assertEquals(msgNo1, msg_res[0]); + } + { + final String msgNo2 = "Second message"; + id_res[0] = -1; + msg_res[0] = null; + bt2.alEventCallback1Inject(myUserParam02, 0, 2, 0, msgNo2); + Assert.assertEquals( -1, id_res[0]); + Assert.assertEquals( null, msg_res[0]); + + bt2.alEventCallback1Inject(myUserParam01, 0, 2, 0, msgNo2); + Assert.assertEquals( -1, id_res[0]); + Assert.assertEquals( null, msg_res[0]); + + bt2.alEventCallback1Inject(myUserParam01, 0, 1, 0, msgNo2); + Assert.assertEquals( 1, id_res[0]); + Assert.assertEquals( msgNo2, msg_res[0]); + } + + // Switch the callback function + // The previously mapped myCallback01 (1, myUserParam01) gets released + // and remapped to myCallback02 + ( 1, myUserParam01 )(key) + bt2.alEventCallback1(1, myCallback02, myUserParam01); + Assert.assertEquals(true, bt2.isAlEventCallback1Mapped(myKey01)); + Assert.assertEquals(false, bt2.isAlEventCallback1Mapped(myKey02)); + { + final Set<AlEventCallback1Key> keys = bt2.getAlEventCallback1Keys(); + Assert.assertEquals(1, keys.size()); + Assert.assertEquals(true, keys.contains(myKey01)); + Assert.assertEquals(false, keys.contains(myKey02)); + } + Assert.assertEquals(myCallback02, bt2.getAlEventCallback1(myKey01)); + Assert.assertEquals(null, bt2.getAlEventCallback1(myKey02)); + + { + final String msgNo3 = "Third message"; + id_res[0] = -1; + msg_res[0] = null; + bt2.alEventCallback1Inject(myUserParam02, 0, 2, 0, msgNo3); + Assert.assertEquals( -1, id_res[0]); + Assert.assertEquals( null, msg_res[0]); + + bt2.alEventCallback1Inject(myUserParam01, 0, 2, 0, msgNo3); + Assert.assertEquals( -1, id_res[0]); + Assert.assertEquals( null, msg_res[0]); + + bt2.alEventCallback1Inject(myUserParam01, 0, 1, 0, msgNo3); + Assert.assertEquals( 1000, id_res[0]); + Assert.assertEquals( msgNo3, msg_res[0]); + } + + // Fake release (wrong key) + bt2.alEventCallback1(2, null, myUserParam02); + Assert.assertEquals(true, bt2.isAlEventCallback1Mapped(myKey01)); + Assert.assertEquals(false, bt2.isAlEventCallback1Mapped(myKey02)); + + bt2.alEventCallback1(2, null, myUserParam01); + Assert.assertEquals(true, bt2.isAlEventCallback1Mapped(myKey01)); + Assert.assertEquals(false, bt2.isAlEventCallback1Mapped(myKey02)); + + // Just release the callback and mapped myUserParam01 + bt2.alEventCallback1(1, null, myUserParam01); + Assert.assertEquals(false, bt2.isAlEventCallback1Mapped(myKey01)); + Assert.assertEquals(false, bt2.isAlEventCallback1Mapped(myKey02)); + Assert.assertEquals(0, bt2.getAlEventCallback1Keys().size()); + + { + final String msgNo4 = "Forth message"; + id_res[0] = -1; + msg_res[0] = null; + bt2.alEventCallback1Inject(myUserParam01, 0, 4, 0, msgNo4); + Assert.assertEquals( -1, id_res[0]); + Assert.assertEquals( null, msg_res[0]); + + bt2.alEventCallback1Inject(myUserParam02, 0, 4, 0, msgNo4); + Assert.assertEquals( -1, id_res[0]); + Assert.assertEquals( null, msg_res[0]); + } + } + + /** * Test Bindingtest2 with T2_CallbackFunc11 JavaCallback via MessageCallback11a() * using the default MessageCallback11aKey class. */ diff --git a/src/junit/com/jogamp/gluegen/test/junit/generation/test2-CustomJavaIfCode.java.stub b/src/junit/com/jogamp/gluegen/test/junit/generation/test2-CustomJavaIfCode.java.stub new file mode 100644 index 0000000..28d46a6 --- /dev/null +++ b/src/junit/com/jogamp/gluegen/test/junit/generation/test2-CustomJavaIfCode.java.stub @@ -0,0 +1,4 @@ + public void alEventCallback0Inject(Object userParam, int eventType, int object, int param, String message); + + public void alEventCallback1Inject(Object userParam, int eventType, int object, int param, String message); + diff --git a/src/junit/com/jogamp/gluegen/test/junit/generation/test2-CustomJavaImplCode.java.stub b/src/junit/com/jogamp/gluegen/test/junit/generation/test2-CustomJavaImplCode.java.stub new file mode 100644 index 0000000..6643108 --- /dev/null +++ b/src/junit/com/jogamp/gluegen/test/junit/generation/test2-CustomJavaImplCode.java.stub @@ -0,0 +1,46 @@ + public void alEventCallback0Inject(Object userParam, int eventType, int object, int param, String message) { + final Object userParam2; + final AlEventCallback0Data value; + synchronized( alEventCallback0Lock ) { + final AlEventCallback0Data value0 = alEventCallback0DataMap.get( new AlEventCallback0Key( userParam ) ); + if( null != value0 ) { + userParam2 = alEventCallback0UserObjIDMap.get(value0.paramID); + if( userParam != userParam2 ) { + throw new InternalError("Impl issue-1: Arg userParam "+userParam+" != "+userParam2); + } + final AlEventCallback0Key key = new AlEventCallback0Key(userParam2); + value = alEventCallback0DataMap.get( key ); + } else { + userParam2 = null; + value = null; + } + } // synchronized + if( null == value ) { + return; + } + value.func.callback(eventType, object, param, message.length(), message, userParam2); + } + + public void alEventCallback1Inject(Object userParam, int eventType, int object, int param, String message) { + final Object userParam2; + final AlEventCallback1Data value; + synchronized( alEventCallback1Lock ) { + final AlEventCallback1Data value0 = alEventCallback1DataMap.get( new AlEventCallback1Key( object, userParam ) ); + if( null != value0 ) { + userParam2 = alEventCallback1UserObjIDMap.get(value0.paramID); + if( userParam != userParam2 ) { + throw new InternalError("Impl issue-1: Arg userParam "+userParam+" != "+userParam2); + } + final AlEventCallback1Key key = new AlEventCallback1Key(object, userParam2); + value = alEventCallback1DataMap.get( key ); + } else { + userParam2 = null; + value = null; + } + } // synchronized + if( null == value ) { + return; + } + value.func.callback(eventType, object, param, message.length(), message, userParam2); + } + 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 dafad7c..b9ad4aa 100644 --- a/src/junit/com/jogamp/gluegen/test/junit/generation/test2.c +++ b/src/junit/com/jogamp/gluegen/test/junit/generation/test2.c @@ -112,25 +112,6 @@ 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 }; @@ -192,6 +173,94 @@ void alBufferCallback1Inject(int buffer, int sampledata, int numbytes) { // // +// typedef void ( * ALEVENTPROCSOFT)(int eventType, int object, int param, int length, const char *message, void *userParam); +static const int MAX_EVENTCB_BUFFER = 5; + +static ALEVENTPROCSOFT ALEvent_callback0[] = { NULL, NULL, NULL, NULL, NULL }; +static void* ALEvent_userptr0[] = { NULL, NULL, NULL, NULL, NULL }; + +void alEventCallback0(ALEVENTPROCSOFT callback, void *userParam /* key */) { + int idx; + if( NULL == callback ) { + // try matching key + for(idx = 0; idx<MAX_EVENTCB_BUFFER; ++idx) { + if( ALEvent_userptr0[idx] == userParam ) { + break; + } + } + } else { + // try matching callback first + for(idx = 0; idx<MAX_EVENTCB_BUFFER; ++idx) { + if( ALEvent_callback0[idx] == callback ) { + break; + } + } + if( MAX_EVENTCB_BUFFER <= idx ) { + // find free slot + for(idx = 0; idx<MAX_EVENTCB_BUFFER; ++idx) { + if( ALEvent_callback0[idx] == NULL ) { + break; + } + } + } + } + if( idx < 0 || MAX_EVENTCB_BUFFER <= idx ) { + fprintf(stderr, "Error: alEventCallback0: idx not in range [0..%d), is %d\n", MAX_EVENTCB_BUFFER, idx); + } else { + ALEvent_callback0[idx] = callback; + ALEvent_userptr0[idx] = (ALEVENTPROCSOFT*)userParam; + fprintf(stderr, "XXX alEventCallback0 idx %d -> func %p, user %p\n", idx, callback, userParam); + } + fflush(NULL); +} + +// +// +// + +static ALEVENTPROCSOFT ALEvent_callback1[] = { NULL, NULL, NULL, NULL, NULL }; +static void* ALEvent_userptr1[] = { NULL, NULL, NULL, NULL, NULL }; + +void alEventCallback1(int object /* key */, ALEVENTPROCSOFT callback, void *userParam /* key */) { + // TODO: Track object key + int idx; + if( NULL == callback ) { + // try matching key + for(idx = 0; idx<MAX_EVENTCB_BUFFER; ++idx) { + if( ALEvent_userptr1[idx] == userParam ) { + break; + } + } + } else { + // try matching callback first + for(idx = 0; idx<MAX_EVENTCB_BUFFER; ++idx) { + if( ALEvent_callback1[idx] == callback ) { + break; + } + } + if( MAX_EVENTCB_BUFFER <= idx ) { + // find free slot + for(idx = 0; idx<MAX_EVENTCB_BUFFER; ++idx) { + if( ALEvent_callback1[idx] == NULL ) { + break; + } + } + } + } + if( idx < 0 || MAX_EVENTCB_BUFFER <= idx ) { + fprintf(stderr, "Error: alEventCallback1: idx not in range [0..%d), is %d\n", MAX_EVENTCB_BUFFER, idx); + } else { + ALEvent_callback1[idx] = callback; + ALEvent_userptr1[idx] = (ALEVENTPROCSOFT*)userParam; + fprintf(stderr, "XXX alEventCallback1 idx %d -> func %p, user %p\n", idx, callback, userParam); + } + fflush(NULL); +} + +// +// +// + static const int MAX_C11_BUFFER = 5; static T2_CallbackFunc11 MessageCallback11a_callback[] = { NULL, NULL, NULL, NULL, NULL }; @@ -228,7 +297,7 @@ void MessageCallback11aInject(size_t id, long val) { // static T2_CallbackFunc11 MessageCallback11b_callback[] = { NULL, NULL, NULL, NULL, NULL }; -static T2_Callback11UserType MessageCallback11b_userptr[]; +static T2_Callback11UserType MessageCallback11b_userptr[5]; void MessageCallback11b(size_t id /* key */, T2_CallbackFunc11 cbFunc, void* Data) { if( id < 0 || MAX_C11_BUFFER <= id ) { 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 d4ea72d..3a1c7b3 100644 --- a/src/junit/com/jogamp/gluegen/test/junit/generation/test2.cfg +++ b/src/junit/com/jogamp/gluegen/test/junit/generation/test2.cfg @@ -71,33 +71,6 @@ JavaCallbackDef MessageCallback01 1 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); -# void alEventCallbackInject(int eventType, int object, int param, const char* msg); -ArgumentIsPascalString ALEVENTPROCSOFT 3 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 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 1 ALEVENTPROCSOFT 5 -# JavaCallbackKey alEventCallback 1 ALEVENTPROCSOFT 5 -# -# End JavaCallback - # Begin JavaCallback (OpanAL AL_SOFT_callback_buffer) # # // typedef void ( * ALBUFFERCALLBACKTYPESOFT)(int buffer /* key */, void *userptr, void *sampledata, int numbytes); @@ -159,6 +132,37 @@ JavaCallbackKey alBufferCallback1 1 ALBUFFERCALLBACKTYPESOFT 0 # # End JavaCallback +# Begin JavaCallback. +# +# typedef void ( * ALEVENTPROCSOFT)(int eventType, int object, int param, int length, const char *message, void *userParam /* key */); +# +# void alEventCallback0(ALEVENTPROCSOFT callback, void *userParam /* key */); +ArgumentIsPascalString ALEVENTPROCSOFT 3 4 + +# 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 uses 'Object userParam' as its key (for a context), similar to `AL_SOFT_events` context binding. +JavaCallbackDef alEventCallback0 1 ALEVENTPROCSOFT 5 +JavaCallbackKey alEventCallback0 1 ALEVENTPROCSOFT 5 +# +# End JavaCallback + +# Begin JavaCallback. +# +# void alEventCallback1(int object /* key */, ALEVENTPROCSOFT callback, void *userParam /* key */); +JavaCallbackDef alEventCallback1 2 ALEVENTPROCSOFT 5 +JavaCallbackKey alEventCallback1 0 2 ALEVENTPROCSOFT 1 5 + +# +# End JavaCallback + +IncludeAs CustomJavaCode Bindingtest2 test2-CustomJavaIfCode.java.stub +IncludeAs CustomJavaCode Bindingtest2Impl test2-CustomJavaImplCode.java.stub + # Begin JavaCallback # # typedef void ( * T2_CallbackFunc11)(size_t id, const T2_Callback11UserType* usrParam); 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 dea6d72..ddd8c8a 100644 --- a/src/junit/com/jogamp/gluegen/test/junit/generation/test2.h +++ b/src/junit/com/jogamp/gluegen/test/junit/generation/test2.h @@ -67,14 +67,6 @@ void MessageCallback01(T2_CallbackFunc01 cbFunc, void* usrParam); void InjectMessageCallback01(size_t id, const char* msg); // -// 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); @@ -89,6 +81,15 @@ void alBufferCallback1(void* user_ptr, int buffer_key /* key */, int format, int void alBufferCallback1Inject(int buffer, int sampledata, int numbytes); // +// ALEVENTPROCSOFT (similar to OpenAL's AL_SOFT_events) +// +typedef void ( * ALEVENTPROCSOFT)(int eventType, int object, int param, int length, const char *message, void *userParam /* key */); + +void alEventCallback0(ALEVENTPROCSOFT callback, void *userParam /* key */); + +void alEventCallback1(int object /* key */, ALEVENTPROCSOFT callback, void *userParam /* key */); + +// // T2_CallbackFunc11[ab] // typedef struct { |