diff options
author | Sven Gothel <[email protected]> | 2023-08-02 20:29:34 +0200 |
---|---|---|
committer | Sven Gothel <[email protected]> | 2023-08-02 20:29:34 +0200 |
commit | 915726afa64f210fe34b1c1c869d357849c448c4 (patch) | |
tree | f5f0ac0f2115fab92590c3ee1976424e5ac0c98c /src/junit/com/jogamp/gluegen | |
parent | 380969bbf0b7746ab245b7d7d177243092fb2c34 (diff) | |
parent | 165e3b87b2d3abbb83e9fe5421ac63931b41c793 (diff) |
Merge remote-tracking branch 'Mathieu_Fery/feature/java_callback_without_user_data' into pulled
Diffstat (limited to 'src/junit/com/jogamp/gluegen')
4 files changed, 107 insertions, 0 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 09b51c7..61a8412 100644 --- a/src/junit/com/jogamp/gluegen/test/junit/generation/Test4JavaCallback.java +++ b/src/junit/com/jogamp/gluegen/test/junit/generation/Test4JavaCallback.java @@ -30,6 +30,7 @@ package com.jogamp.gluegen.test.junit.generation; import java.io.IOException; import java.util.Set; +import java.util.concurrent.atomic.AtomicReference; import com.jogamp.common.os.NativeLibrary; import com.jogamp.gluegen.test.junit.generation.Bindingtest2.ALBUFFERCALLBACKTYPESOFT; @@ -41,6 +42,7 @@ import com.jogamp.gluegen.test.junit.generation.Bindingtest2.MessageCallback11aK import com.jogamp.gluegen.test.junit.generation.Bindingtest2.MessageCallback11bKey; import com.jogamp.gluegen.test.junit.generation.Bindingtest2.T2_CallbackFunc01; import com.jogamp.gluegen.test.junit.generation.Bindingtest2.T2_CallbackFunc11; +import com.jogamp.gluegen.test.junit.generation.Bindingtest2.T2_CallbackFunc12; import com.jogamp.gluegen.test.junit.generation.impl.Bindingtest2Impl; import org.junit.AfterClass; @@ -1609,6 +1611,55 @@ public class Test4JavaCallback extends BaseClass { } } + /** + * Test Bindingtest2 with T2_CallbackFunc12 JavaCallback via SetLogCallBack() + */ + @Test + public void chapter12() throws Exception { + final Bindingtest2 bt2 = new Bindingtest2Impl(); + + final AtomicReference<LogMessage> messageSupplied = new AtomicReference<>(null); + final T2_CallbackFunc12 logCallBack = new T2_CallbackFunc12() { + @Override + public void callback(final LogMessage usrParam) { + Assert.assertEquals(messageSupplied.get(), usrParam); + } + }; + bt2.SetLogCallBack(logCallBack); + + { + final LogMessage logMessage = LogMessage.create(); + logMessage.setCategory("TEST"); + logMessage.setMessage("Example"); + logMessage.setLevel(Bindingtest2.LOG_Info); + messageSupplied.set(logMessage); + + bt2.LogCallBackInject(logMessage); + } + + { + final LogMessage logMessage = LogMessage.create(); + logMessage.setCategory("IDK"); + logMessage.setMessage("John Doe is absent."); + logMessage.setLevel(Bindingtest2.LOG_Warning); + messageSupplied.set(logMessage); + + bt2.LogCallBackInject(logMessage); + } + + bt2.SetLogCallBack(null); + + { + final LogMessage logMessage = LogMessage.create(); + logMessage.setCategory("SANITY"); + logMessage.setMessage("Callback is now unset"); + logMessage.setLevel(Bindingtest2.LOG_Fatal); + messageSupplied.set(logMessage); + + bt2.LogCallBackInject(logMessage); + } + } + static private String toHexString(final int v) { return "0x"+Integer.toHexString(v); } public static void main(final String args[]) throws IOException { 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 b9ad4aa..66e562f 100644 --- a/src/junit/com/jogamp/gluegen/test/junit/generation/test2.c +++ b/src/junit/com/jogamp/gluegen/test/junit/generation/test2.c @@ -323,3 +323,21 @@ void MessageCallback11bInject(size_t id, long val) { } } + +// +// + +static T2_CallbackFunc12 LogCallBack = NULL; + +void SetLogCallBack(T2_CallbackFunc12 cbFunc) { + LogCallBack = cbFunc; +} + +void LogCallBackInject(const LogMessage* message) { + if ( NULL != LogCallBack ) { + fprintf(stderr, "XXX LogCallBackInject: func %p, message %p\n", &LogCallBack, &message); + fflush(NULL); + (*LogCallBack)(message); + } +} + 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 fdad264..51eb0ae 100644 --- a/src/junit/com/jogamp/gluegen/test/junit/generation/test2.cfg +++ b/src/junit/com/jogamp/gluegen/test/junit/generation/test2.cfg @@ -179,6 +179,19 @@ JavaCallbackKey MessageCallback11a 0 T2_CallbackFunc11 0 JavaCallbackDef MessageCallback11b 2 T2_CallbackFunc11 1 JavaCallbackKey MessageCallback11b 0 T2_CallbackFunc11 0 + +ReturnsStringOnly LogMessage.Category +ReturnsStringOnly LogMessage.Message + +# Begin JavaCallback +# +# typedef void ( * T2_CallbackFunc12)(const LogMessage* usrParam); +# void SetLogCallBack(T2_CallbackFunc12 cbFunc); +# void LogCallBackInject(LogMessage message); +JavaCallbackDef SetLogCallBack -1 T2_CallbackFunc12 -1 +# +# End JavaCallback + CustomCCode #include "test2.h" Import com.jogamp.gluegen.test.junit.generation.Bindingtest2 @@ -187,6 +200,7 @@ Import com.jogamp.gluegen.test.junit.generation.T2_InitializeOptions Import com.jogamp.gluegen.test.junit.generation.T2_ThreadAffinity Import com.jogamp.gluegen.test.junit.generation.T2_UserData Import com.jogamp.gluegen.test.junit.generation.T2_Callback11UserType +Import com.jogamp.gluegen.test.junit.generation.LogMessage Import com.jogamp.gluegen.test.junit.generation.Test4JavaCallback.ALCcontext CustomJavaCode Bindingtest2Impl private static Bindingtest2ProcAddressTable _table = new Bindingtest2ProcAddressTable(); 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 ddd8c8a..ec46885 100644 --- a/src/junit/com/jogamp/gluegen/test/junit/generation/test2.h +++ b/src/junit/com/jogamp/gluegen/test/junit/generation/test2.h @@ -108,3 +108,27 @@ void MessageCallback11aInject(size_t id, long val); void MessageCallback11b(size_t id /* key */, T2_CallbackFunc11 cbFunc, void* Data); void MessageCallback11bInject(size_t id, long val); +// +// T2_CallbackFunc12 +// + +typedef enum { + LOG_Off = 0, + LOG_Fatal = 100, + LOG_Error = 200, + LOG_Warning = 300, + LOG_Info = 400, + LOG_Verbose = 500, + LOG_VeryVerbose = 600 +} LogLevel; + +typedef struct { + const char* Category; + const char* Message; + LogLevel Level; +} LogMessage; + +typedef void ( * T2_CallbackFunc12)(const LogMessage* usrParam); + +void SetLogCallBack(T2_CallbackFunc12 cbFunc); +void LogCallBackInject(const LogMessage* message); |