diff options
author | Sven Gothel <[email protected]> | 2023-07-06 10:35:30 +0200 |
---|---|---|
committer | Sven Gothel <[email protected]> | 2023-07-06 10:35:30 +0200 |
commit | 3ed3e9887c459169b807165c9df2ae2bc2990a31 (patch) | |
tree | 895211a59571e09e4128223dca2cda1bcf9a9d5c | |
parent | 5b867d0f90a43a02e1fbd03fb1ed588a391806eb (diff) |
GlueGen JavaCallback: Remove ambiguity: Config JavaCallbackDef/JavaCallbackKey: Always define both parameter indices; emitJavaStaticCallback(): Use cbFuncBinding and cbFuncKeyIndices from callback parameter to build key
-rw-r--r-- | doc/GlueGen_Mapping.html | 101 | ||||
-rw-r--r-- | doc/GlueGen_Mapping.md | 65 | ||||
-rw-r--r-- | src/java/com/jogamp/gluegen/JavaCallbackEmitter.java | 8 | ||||
-rw-r--r-- | src/java/com/jogamp/gluegen/JavaConfiguration.java | 110 | ||||
-rw-r--r-- | src/java/com/jogamp/gluegen/JavaEmitter.java | 26 | ||||
-rw-r--r-- | src/junit/com/jogamp/gluegen/test/junit/generation/Test4JavaCallback.java | 10 | ||||
-rw-r--r-- | src/junit/com/jogamp/gluegen/test/junit/generation/test2.c | 2 | ||||
-rw-r--r-- | src/junit/com/jogamp/gluegen/test/junit/generation/test2.cfg | 33 | ||||
-rw-r--r-- | src/junit/com/jogamp/gluegen/test/junit/generation/test2.h | 2 |
9 files changed, 200 insertions, 157 deletions
diff --git a/doc/GlueGen_Mapping.html b/doc/GlueGen_Mapping.html index 7bec555..d484ff8 100644 --- a/doc/GlueGen_Mapping.html +++ b/doc/GlueGen_Mapping.html @@ -463,8 +463,10 @@ <li><a href="#javacallback-example-1">JavaCallback Example 1</a></li> <li><a href="#javacallback-example-2a-default-keyclass">JavaCallback Example 2a (Default <em>KeyClass</em>)</a></li> - <li><a href="#javacallback-example-2b-custom-keyclass">JavaCallback - Example 2b (Custom <em>KeyClass</em>)</a></li> + <li><a + href="#javacallback-example-2b-custom-keyclass-different-key-parameter-order">JavaCallback + Example 2b (Custom <em>KeyClass</em>, different key-parameter + order)</a></li> <li><a href="#javacallback-example-11a-homogeneous-struct-type">JavaCallback Example 11a (<em>Homogeneous Struct Type</em>)</a></li> @@ -2027,27 +2029,29 @@ Object</em> to be passed to the users' <h3 id="javacallback-configuration"><em>JavaCallback</em> Configuration</h3> <p>Configuration directives are as follows:</p> -<pre><code>JavaCallbackDef <SetCallbackFunctionName> [<SetCallback-UserParamIndex>] <CallbackFunctionType> <CallbackFunction-UserParamIndex> [<SetCallback-KeyClassName>] -JavaCallbackKey <SetCallbackFunctionName> (SetCallback-ParamIdx)*</code></pre> +<pre><code>JavaCallbackDef <SetCallbackFunctionName> <SetCallback-UserParamIndex> <CallbackFunctionType> <CallbackFunction-UserParamIndex> [<SetCallback-KeyClassName>] +JavaCallbackKey <SetCallbackFunctionName> <SetCallback-ParamIndex>* <CallbackFunctionType> <CallbackFunction-ParamIndex>*</code></pre> <p><code>JavaCallbackDef</code> and <code>JavaCallbackKey</code> use the name of the <code>SetCallbackFunction</code> as its first attribute, as -it is core to the semantic mapping of all resources.</p> +it is core to the semantic mapping of all resources. They also have to +use the same <code>CallbackFunctionType</code>.</p> <p><code>JavaCallbackDef</code> attributes:</p> <ul> <li><code>SetCallbackFunction</code>: <code>SetCallbackFunction</code> name of the native toolkit API responsible to set the callback</li> -<li><code>SetCallback-UserParamIndex</code>: Optional -<code>UserParam</code> parameter-index of the -<code>SetCallbackFunction</code>, allowing to <a -href="#struct-type-user-param-heterogeneous">indicate a heterogeneous -<code>UserParam</code></a></li> +<li><code>SetCallback-UserParamIndex</code>: <code>UserParam</code> +parameter-index of the <code>SetCallbackFunction</code></li> <li><code>CallbackFunctionType</code>: The native toolkit API typedef-name of the function-pointer-type, aka the callback type name</li> <li><code>CallbackFunction-UserParamIndex</code>: The <code>userParam</code> parameter-index of the -<code>CallbackFunctionType</code></li> -<li><code>SetCallback-KeyClassName</code>: Name of an optional +<code>CallbackFunctionType</code>, allowing to accommodate a potential +parameter-type collision between <code>SetCallbackFunction</code> and +<code>CallbackFunction</code>. It also allows to <a +href="#struct-type-user-param-heterogeneous">indicate a heterogeneous +<code>UserParam</code></a></li> +<li><code>SetCallback-KeyClassName</code>: Optional name of a user-implemented <code>SetCallback-KeyClass</code>, providing the hash-map-key - see below</li> </ul> @@ -2056,7 +2060,7 @@ hash-map-key - see below</li> <code>null</code> for the <code>CallbackFunction</code>.</p> <p>If mapping the <code>CallbackFunction</code> to keys, the user must specify the same key arguments when setting and removing the -``CallbackFunction`.</p> +<code>CallbackFunction</code>.</p> <h4 id="javacallback-key-definition"><em>JavaCallback</em> Key Definition</h4> <p>If no keys are defined via <code>JavaCallbackKey</code> or not @@ -2068,17 +2072,27 @@ public <code>SetCallback-KeyClass</code> is being generated covering the defined keys.</p> <p>Keys allow to limit the scope, i.e. map multiple <code>CallbackFunction</code> to the different keys.</p> -<p>Key arguments must match in <code>SetCallbackFunction</code> to -remove a previously set <code>CallbackFunction</code>.</p> +<p>To remove a previously set <code>CallbackFunction</code> via +<code>SetCallbackFunction</code>, the key arguments must match.</p> <p><code>JavaCallbackKey</code> attributes</p> <ul> <li><code>SetCallbackFunction</code>: <code>SetCallbackFunction</code> name of the native toolkit API responsible to set the callback</li> -<li><code>SetCallback-ParamIdx</code>: List of parameter indices of the -<code>SetCallbackFunction</code>, denoting the key(s) limiting the +<li><code>SetCallback-ParamIndex</code>: List of parameter indices of +the <code>SetCallbackFunction</code>, denoting the key(s) limiting the callback scope, i.e. the callback and all resources will be mapped to this key. The optional <code>SetCallback-KeyClass</code> may override this semantic.</li> +<li><code>CallbackFunctionType</code>: The native toolkit API +typedef-name of the function-pointer-type, the same callback type name +as defined in <code>JavaCallbackDef</code></li> +<li><code>CallbackFunction-ParamIndex</code>: List of parameter indices +of the <code>CallbackFunctionType</code>, matching the semantic +parameter of <code>SetCallback-ParamIndex</code> to accommodate +potential different parameter order or argument names between +<code>SetCallbackFunction</code> and <code>CallbackFunction</code>. The +indexed parameters must be semantical equivalent as specified by the +<code>SetCallback-ParamIndex</code> list.</li> </ul> <h4 id="custom-setcallback-keyclass">Custom <code>SetCallback-KeyClass</code></h4> @@ -2196,7 +2210,7 @@ and the native callback dispatcher <strong>are thread-safe</strong></li> <li>...</li> </ul> <h3 id="javacallback-example-1">JavaCallback Example 1</h3> -<p>This examples demonstrates a <a +<p>This example demonstrates a <a href="#pure-java-object-user-type-default">homogeneous <em>Java Object</em> <code>UserParam</code> mapping</a> with a <a href="#javacallback-key-definition">globally scoped</a> @@ -2230,7 +2244,7 @@ ArgumentIsString InjectMessageCallback01 1 # - `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</code></pre> +JavaCallbackDef MessageCallback01 1 T2_CallbackFunc01 2</code></pre> <p>Note that <a href="#libraryonload-librarybasename-for-jni_onload-"><code>LibraryOnLoad Bindingtest2</code></a> must be specified in exactly one native code-unit within the library. It @@ -2269,18 +2283,18 @@ the current thread to the <code>JavaVM*</code> generating a new public void InjectMessageCallback01(long id, String msg);</code></pre> <h3 id="javacallback-example-2a-default-keyclass">JavaCallback Example 2a (Default <em>KeyClass</em>)</h3> -<p>This examples demonstrates a <a +<p>This example demonstrates a <a href="#pure-java-object-user-type-default">homogeneous <em>Java Object</em> <code>UserParam</code> mapping</a> with a <a href="#javacallback-key-definition">key-mapped</a> <code>CallbackFunction</code> and <code>UserParam</code>.</p> -<p>This examples is derived from OpenAL's +<p>This example is derived from OpenAL's <code>AL_SOFT_callback_buffer</code> extension.</p> <p>The callback <code>ALBUFFERCALLBACKTYPESOFT</code> is mapped to <code>buffer</code> name, i.e. one callback can be set for each buffer.</p> <p>C-API Header snipped</p> -<pre><code> typedef void ( * ALBUFFERCALLBACKTYPESOFT)(int buffer, void *userptr, int sampledata, int numbytes); +<pre><code> typedef void ( * ALBUFFERCALLBACKTYPESOFT)(int buffer /* key */, void *userptr, int sampledata, int numbytes); void alBufferCallback0(int buffer /* key */, int format, int freq, ALBUFFERCALLBACKTYPESOFT callback, void *userptr); @@ -2302,8 +2316,8 @@ buffer.</p> # - `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</code></pre> + JavaCallbackDef alBufferCallback0 4 ALBUFFERCALLBACKTYPESOFT 1 + JavaCallbackKey alBufferCallback0 0 ALBUFFERCALLBACKTYPESOFT 0</code></pre> <p>leading to the following interface</p> <pre><code> /** JavaCallback interface: ALBUFFERCALLBACKTYPESOFT -> void (*ALBUFFERCALLBACKTYPESOFT)(int buffer, void * userptr, int sampledata, int numbytes) */ public static interface ALBUFFERCALLBACKTYPESOFT { @@ -2363,22 +2377,27 @@ buffer.</p> /** Entry point (through function pointer) to C language function: <br> <code>void alEventCallbackInject(int eventType, int object, int param, const char * msg)</code><br> */ public void alEventCallbackInject(int eventType, int object, int param, String msg); </code></pre> -<h3 id="javacallback-example-2b-custom-keyclass">JavaCallback Example 2b -(Custom <em>KeyClass</em>)</h3> -<p>This examples demonstrates a <a -href="#pure-java-object-user-type-default">homogeneous <em>Java -Object</em> <code>UserParam</code> mapping</a> with a <a +<h3 +id="javacallback-example-2b-custom-keyclass-different-key-parameter-order">JavaCallback +Example 2b (Custom <em>KeyClass</em>, different key-parameter +order)</h3> +<p>Similar example as example 2a, but using a <a href="#custom-setcallback-keyclass">custom <em>KeyClass</em></a> to map -<code>CallbackFunction</code> and <code>UserParam</code>.</p> -<p>Same as example 2a, but implementing a custom -<code>SetCallback-KeyClass</code>.</p> -<p>Instead of <code>Callback0</code>, the unit <code>test2.*</code> uses -<code>Callback1</code> to differentiate this case.</p> +<code>CallbackFunction</code> and <code>UserParam</code> and also +accommodating a different key-parameter order between +<code>SetCallbackFunction</code> and <code>CallbackFunction</code>.</p> +<p>C-API Header snipped</p> +<pre><code> typedef void ( * ALBUFFERCALLBACKTYPESOFT)(int buffer /* key */, void *userptr, int sampledata, int numbytes); + + void alBufferCallback1(void *user_ptr, int buffer_key /* key */, int format, int freq, ALBUFFERCALLBACKTYPESOFT callback); + + void alBufferCallback1Inject(int buffer, int sampledata, int numbytes);</code></pre> <p>GlueGen configuration snippet with the added option attribute for the <code>SetCallback-KeyClass</code> in directive <code>JavaCallbackDef</code>.</p> -<pre><code>JavaCallbackDef alBufferCallback1 ALBUFFERCALLBACKTYPESOFT 1 com.jogamp.gluegen.test.junit.generation.Test4JavaCallback.CustomAlBufferCallback1Key -JavaCallbackKey alBufferCallback1 0</code></pre> +<pre><code>JavaCallbackDef alBufferCallback1 0 ALBUFFERCALLBACKTYPESOFT 1 com.jogamp.gluegen.test.junit.generation.Test4JavaCallback.CustomAlBufferCallback1Key +JavaCallbackKey alBufferCallback1 1 ALBUFFERCALLBACKTYPESOFT 0 +</code></pre> <p>Implementation utilizes a custom <code>SetCallback-KeyClass</code> implementation for <code>void alBufferCallback1(int buffer, int format, int freq, ALBUFFERCALLBACKTYPESOFT callback, Object userptr)</code>, @@ -2410,7 +2429,7 @@ which uses one key, i.e. <code>buffer</code>.</p> }</code></pre> <h3 id="javacallback-example-11a-homogeneous-struct-type">JavaCallback Example 11a (<em>Homogeneous Struct Type</em>)</h3> -<p>This examples demonstrates a <a +<p>This example demonstrates a <a href="#struct-type-user-param-homogeneous">homogeneous <em>Struct</em> <code>UserParam</code> mapping</a> with a <a href="#javacallback-key-definition">key-mapped</a> @@ -2432,8 +2451,8 @@ method <code>MessageCallback11b(..)</code>.</p> void MessageCallback11a(size_t id /* key */, T2_CallbackFunc11 cbFunc, const T2_Callback11UserType* usrParam); void MessageCallback11aInject(size_t id, long val); </code></pre> <p>and the following GlueGen configuration</p> -<pre><code> JavaCallbackDef MessageCallback11a T2_CallbackFunc11 1 - JavaCallbackKey MessageCallback11a 0</code></pre> +<pre><code> JavaCallbackDef MessageCallback11a 2 T2_CallbackFunc11 1 + JavaCallbackKey MessageCallback11a 0 T2_CallbackFunc11 0</code></pre> <p>leading to the following interface</p> <pre><code> /** JavaCallback interface: T2_CallbackFunc11 -> void (*T2_CallbackFunc11)(size_t id, const T2_Callback11UserType * usrParam, long val) */ public static interface T2_CallbackFunc11 { @@ -2473,7 +2492,7 @@ method <code>MessageCallback11b(..)</code>.</p> <h3 id="javacallback-example-11b-heterogeneous-pointerstruct-type">JavaCallback Example 11b (<em>Heterogeneous Pointer/Struct Type</em>)</h3> -<p>This examples demonstrates a <a +<p>This example demonstrates a <a href="#struct-type-user-param-heterogeneous">heterogeneous <em>Struct</em> <code>UserParam</code> mapping</a> with a <a href="#javacallback-key-definition">key-mapped</a> @@ -2499,7 +2518,7 @@ users' <code>void*</code> pointer with the void MessageCallback11bInject(size_t id, long val);</code></pre> <p>and the following GlueGen configuration</p> <pre><code> JavaCallbackDef MessageCallback11b 2 T2_CallbackFunc11 1 - JavaCallbackKey MessageCallback11b 0</code></pre> + JavaCallbackKey MessageCallback11b 0 T2_CallbackFunc11 0</code></pre> <p>leading to the following interface</p> <pre><code> /** JavaCallback interface: T2_CallbackFunc11 -> void (*T2_CallbackFunc11)(size_t id, const T2_Callback11UserType * usrParam, long val) */ public static interface T2_CallbackFunc11 { diff --git a/doc/GlueGen_Mapping.md b/doc/GlueGen_Mapping.md index 7a72733..2f8e9e1 100644 --- a/doc/GlueGen_Mapping.md +++ b/doc/GlueGen_Mapping.md @@ -816,22 +816,22 @@ The static Java callback dispatcher dereferences the received native struct addr Configuration directives are as follows: - JavaCallbackDef <SetCallbackFunctionName> [<SetCallback-UserParamIndex>] <CallbackFunctionType> <CallbackFunction-UserParamIndex> [<SetCallback-KeyClassName>] - JavaCallbackKey <SetCallbackFunctionName> (SetCallback-ParamIdx)* + JavaCallbackDef <SetCallbackFunctionName> <SetCallback-UserParamIndex> <CallbackFunctionType> <CallbackFunction-UserParamIndex> [<SetCallback-KeyClassName>] + JavaCallbackKey <SetCallbackFunctionName> <SetCallback-ParamIndex>* <CallbackFunctionType> <CallbackFunction-ParamIndex>* `JavaCallbackDef` and `JavaCallbackKey` use the name of the `SetCallbackFunction` as its first attribute, -as it is core to the semantic mapping of all resources. +as it is core to the semantic mapping of all resources. They also have to use the same `CallbackFunctionType`. `JavaCallbackDef` attributes: - `SetCallbackFunction`: `SetCallbackFunction` name of the native toolkit API responsible to set the callback -- `SetCallback-UserParamIndex`: Optional `UserParam` parameter-index of the `SetCallbackFunction`, allowing to [indicate a heterogeneous `UserParam`](#struct-type-user-param-heterogeneous) +- `SetCallback-UserParamIndex`: `UserParam` parameter-index of the `SetCallbackFunction` - `CallbackFunctionType`: The native toolkit API typedef-name of the function-pointer-type, aka the callback type name -- `CallbackFunction-UserParamIndex`: The `userParam` parameter-index of the `CallbackFunctionType` -- `SetCallback-KeyClassName`: Name of an optional user-implemented `SetCallback-KeyClass`, providing the hash-map-key - see below +- `CallbackFunction-UserParamIndex`: The `userParam` parameter-index of the `CallbackFunctionType`, allowing to accommodate a potential parameter-type collision between `SetCallbackFunction` and `CallbackFunction`. It also allows to [indicate a heterogeneous `UserParam`](#struct-type-user-param-heterogeneous) +- `SetCallback-KeyClassName`: Optional name of a user-implemented `SetCallback-KeyClass`, providing the hash-map-key - see below The `SetCallbackFunction` is utilized to set the `CallbackFunction` as well as to remove it passing `null` for the `CallbackFunction`. -If mapping the `CallbackFunction` to keys, the user must specify the same key arguments when setting and removing the ``CallbackFunction`. +If mapping the `CallbackFunction` to keys, the user must specify the same key arguments when setting and removing the `CallbackFunction`. #### *JavaCallback* Key Definition @@ -843,11 +843,14 @@ a public `SetCallback-KeyClass` is being generated covering the defined keys. Keys allow to limit the scope, i.e. map multiple `CallbackFunction` to the different keys. -Key arguments must match in `SetCallbackFunction` to remove a previously set `CallbackFunction`. +To remove a previously set `CallbackFunction` via `SetCallbackFunction`, the key arguments must match. `JavaCallbackKey` attributes - `SetCallbackFunction`: `SetCallbackFunction` name of the native toolkit API responsible to set the callback -- `SetCallback-ParamIdx`: List of parameter indices of the `SetCallbackFunction`, denoting the key(s) limiting the callback scope, i.e. the callback and all resources will be mapped to this key. The optional `SetCallback-KeyClass` may override this semantic. +- `SetCallback-ParamIndex`: List of parameter indices of the `SetCallbackFunction`, denoting the key(s) limiting the callback scope, i.e. the callback and all resources will be mapped to this key. The optional `SetCallback-KeyClass` may override this semantic. +- `CallbackFunctionType`: The native toolkit API typedef-name of the function-pointer-type, the same callback type name as defined in `JavaCallbackDef` +- `CallbackFunction-ParamIndex`: List of parameter indices of the `CallbackFunctionType`, matching the semantic parameter of `SetCallback-ParamIndex` to accommodate potential different parameter order or argument names between `SetCallbackFunction` and `CallbackFunction`. The indexed parameters must be semantical equivalent as specified by the `SetCallback-ParamIndex` list. + #### Custom `SetCallback-KeyClass` @@ -908,7 +911,7 @@ Please consider the following *currently enabled* constraints using JavaCallback - ... ### JavaCallback Example 1 -This examples demonstrates a [homogeneous *Java Object* `UserParam` mapping](#pure-java-object-user-type-default) with a [globally scoped](#javacallback-key-definition) `CallbackFunction` and `UserParam`. +This example demonstrates a [homogeneous *Java Object* `UserParam` mapping](#pure-java-object-user-type-default) with a [globally scoped](#javacallback-key-definition) `CallbackFunction` and `UserParam`. The callback `T2_CallbackFunc01` has global scope, i.e. is not mapped to any key and can be only set globally. @@ -943,7 +946,7 @@ ArgumentIsString InjectMessageCallback01 1 # - `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 +JavaCallbackDef MessageCallback01 1 T2_CallbackFunc01 2 ``` Note that [`LibraryOnLoad Bindingtest2`](#libraryonload-librarybasename-for-jni_onload-) must be specified in exactly one native code-unit within the library. @@ -983,15 +986,15 @@ public interface Bindingtest2 { ### JavaCallback Example 2a (Default *KeyClass*) -This examples demonstrates a [homogeneous *Java Object* `UserParam` mapping](#pure-java-object-user-type-default) with a [key-mapped](#javacallback-key-definition) `CallbackFunction` and `UserParam`. +This example demonstrates a [homogeneous *Java Object* `UserParam` mapping](#pure-java-object-user-type-default) with a [key-mapped](#javacallback-key-definition) `CallbackFunction` and `UserParam`. -This examples is derived from OpenAL's `AL_SOFT_callback_buffer` extension. +This example is derived from OpenAL's `AL_SOFT_callback_buffer` extension. The callback `ALBUFFERCALLBACKTYPESOFT` is mapped to `buffer` name, i.e. one callback can be set for each buffer. C-API Header snipped ``` - typedef void ( * ALBUFFERCALLBACKTYPESOFT)(int buffer, void *userptr, int sampledata, int numbytes); + typedef void ( * ALBUFFERCALLBACKTYPESOFT)(int buffer /* key */, void *userptr, int sampledata, int numbytes); void alBufferCallback0(int buffer /* key */, int format, int freq, ALBUFFERCALLBACKTYPESOFT callback, void *userptr); @@ -1016,8 +1019,8 @@ and the following GlueGen configuration # - `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 + JavaCallbackDef alBufferCallback0 4 ALBUFFERCALLBACKTYPESOFT 1 + JavaCallbackKey alBufferCallback0 0 ALBUFFERCALLBACKTYPESOFT 0 ``` leading to the following interface @@ -1082,18 +1085,24 @@ leading to the following interface public void alEventCallbackInject(int eventType, int object, int param, String msg); ``` -### JavaCallback Example 2b (Custom *KeyClass*) - -This examples demonstrates a [homogeneous *Java Object* `UserParam` mapping](#pure-java-object-user-type-default) with a [custom *KeyClass*](#custom-setcallback-keyclass) to map `CallbackFunction` and `UserParam`. +### JavaCallback Example 2b (Custom *KeyClass*, different key-parameter order) -Same as example 2a, but implementing a custom `SetCallback-KeyClass`. +Similar example as example 2a, but using a [custom *KeyClass*](#custom-setcallback-keyclass) to map `CallbackFunction` and `UserParam` and also accommodating a different key-parameter order between `SetCallbackFunction` and `CallbackFunction`. -Instead of `Callback0`, the unit `test2.*` uses `Callback1` to differentiate this case. +C-API Header snipped +``` + typedef void ( * ALBUFFERCALLBACKTYPESOFT)(int buffer /* key */, void *userptr, int sampledata, int numbytes); + + void alBufferCallback1(void *user_ptr, int buffer_key /* key */, int format, int freq, ALBUFFERCALLBACKTYPESOFT callback); + + void alBufferCallback1Inject(int buffer, int sampledata, int numbytes); +``` GlueGen configuration snippet with the added option attribute for the `SetCallback-KeyClass` in directive `JavaCallbackDef`. ``` -JavaCallbackDef alBufferCallback1 ALBUFFERCALLBACKTYPESOFT 1 com.jogamp.gluegen.test.junit.generation.Test4JavaCallback.CustomAlBufferCallback1Key -JavaCallbackKey alBufferCallback1 0 +JavaCallbackDef alBufferCallback1 0 ALBUFFERCALLBACKTYPESOFT 1 com.jogamp.gluegen.test.junit.generation.Test4JavaCallback.CustomAlBufferCallback1Key +JavaCallbackKey alBufferCallback1 1 ALBUFFERCALLBACKTYPESOFT 0 + ``` Implementation utilizes a custom `SetCallback-KeyClass` implementation for `void alBufferCallback1(int buffer, int format, int freq, ALBUFFERCALLBACKTYPESOFT callback, Object userptr)`, @@ -1128,7 +1137,7 @@ which uses one key, i.e. `buffer`. ### JavaCallback Example 11a (*Homogeneous Struct Type*) -This examples demonstrates a [homogeneous *Struct* `UserParam` mapping](#struct-type-user-param-homogeneous) with a [key-mapped](#javacallback-key-definition) `CallbackFunction` and `UserParam`. +This example demonstrates a [homogeneous *Struct* `UserParam` mapping](#struct-type-user-param-homogeneous) with a [key-mapped](#javacallback-key-definition) `CallbackFunction` and `UserParam`. The callback `T2_CallbackFunc11` is passed by the toolkit to the `CallbackFunction` and by the user to the registration method `MessageCallback11b(..)`. @@ -1150,8 +1159,8 @@ C-API Header snipped and the following GlueGen configuration ``` - JavaCallbackDef MessageCallback11a T2_CallbackFunc11 1 - JavaCallbackKey MessageCallback11a 0 + JavaCallbackDef MessageCallback11a 2 T2_CallbackFunc11 1 + JavaCallbackKey MessageCallback11a 0 T2_CallbackFunc11 0 ``` leading to the following interface @@ -1195,7 +1204,7 @@ leading to the following interface ### JavaCallback Example 11b (*Heterogeneous Pointer/Struct Type*) -This examples demonstrates a [heterogeneous *Struct* `UserParam` mapping](#struct-type-user-param-heterogeneous) with a [key-mapped](#javacallback-key-definition) `CallbackFunction` and `UserParam`. +This example demonstrates a [heterogeneous *Struct* `UserParam` mapping](#struct-type-user-param-heterogeneous) with a [key-mapped](#javacallback-key-definition) `CallbackFunction` and `UserParam`. The callback `T2_CallbackFunc11` is managed by the toolkit and passed to the callback function, while user passes a `void*` as a `long` value to the registration method `MessageCallback11b(..)`. The toolkit associates the users' `void*` pointer with the `T2_CallbackFunc11`. @@ -1219,7 +1228,7 @@ C-API Header snipped and the following GlueGen configuration ``` JavaCallbackDef MessageCallback11b 2 T2_CallbackFunc11 1 - JavaCallbackKey MessageCallback11b 0 + JavaCallbackKey MessageCallback11b 0 T2_CallbackFunc11 0 ``` leading to the following interface diff --git a/src/java/com/jogamp/gluegen/JavaCallbackEmitter.java b/src/java/com/jogamp/gluegen/JavaCallbackEmitter.java index 1b6aa05..e4046ac 100644 --- a/src/java/com/jogamp/gluegen/JavaCallbackEmitter.java +++ b/src/java/com/jogamp/gluegen/JavaCallbackEmitter.java @@ -453,14 +453,10 @@ public final class JavaCallbackEmitter { if( mapNativePtrToCompound[0] ) { unit.emitln(" final "+origUserParamJType[0]+" "+info.cbFuncUserParamName+" = "+origUserParamJType[0]+".derefPointer(nativeUserParamPtr);"); } - if( useDataMap ) { - unit.emitln(" final "+DataClassName+" value;"); - } else { - unit.emitln(" final "+DataClassName+" value;"); - } + unit.emitln(" final "+DataClassName+" value;"); unit.emitln(" synchronized( "+lockInstanceName+" ) {"); if( useDataMap ) { - unit.emitln(" final "+KeyClassName+" key = new "+KeyClassName+"("+binding.getJavaCallSelectArguments(new StringBuilder(), info.setFuncKeyIndices, false).toString()+");"); + unit.emitln(" final "+KeyClassName+" key = new "+KeyClassName+"("+info.cbFuncBinding.getJavaCallSelectArguments(new StringBuilder(), info.cbFuncKeyIndices, false).toString()+");"); unit.emitln(" value = "+dataMapInstanceName+".get(key);"); } else { unit.emitln(" value = "+dataInstanceName+";"); diff --git a/src/java/com/jogamp/gluegen/JavaConfiguration.java b/src/java/com/jogamp/gluegen/JavaConfiguration.java index 5cea4c3..e530e0c 100644 --- a/src/java/com/jogamp/gluegen/JavaConfiguration.java +++ b/src/java/com/jogamp/gluegen/JavaConfiguration.java @@ -190,9 +190,10 @@ public class JavaConfiguration { final String cbFuncTypeName; final int cbFuncUserParamIdx; final String setFuncName; - final List<Integer> setFuncKeyIndices = new ArrayList<Integer>(); final int setFuncUserParamIdx; // optional + final List<Integer> cbFuncKeyIndices = new ArrayList<Integer>(); final String setFuncKeyClassName; // optional + final List<Integer> setFuncKeyIndices = new ArrayList<Integer>(); JavaCallbackDef(final String cbFuncTypeName, final int cbFuncUserParamIdx, final String setFuncName, final int setFuncUserParamIdx, final String setFuncKeyClassName) { this.cbFuncTypeName = cbFuncTypeName; this.cbFuncUserParamIdx = cbFuncUserParamIdx; @@ -202,8 +203,8 @@ public class JavaConfiguration { } @Override public String toString() { - return String.format("JavaCallbackDef[cbFunc[type %s, userParamIdx %d], set[%s, keys %s, userParamIdx %d, KeyClass %s]]", - cbFuncTypeName, cbFuncUserParamIdx, setFuncName, setFuncKeyIndices.toString(), setFuncUserParamIdx, setFuncKeyClassName); + return String.format("JavaCallbackDef[cbFunc[type %s, userParamIdx %d, keys %s], set[%s, keys %s, userParamIdx %d, KeyClass %s]]", + cbFuncTypeName, cbFuncUserParamIdx, cbFuncKeyIndices.toString(), setFuncName, setFuncKeyIndices.toString(), setFuncUserParamIdx, setFuncKeyClassName); } } private final List<JavaCallbackDef> javaCallbackList = new ArrayList<JavaCallbackDef>(); @@ -1692,26 +1693,9 @@ public class JavaConfiguration { protected void readJavaCallbackDef(final StringTokenizer tok, final String filename, final int lineNo) { try { final String setFuncName = tok.nextToken(); - final int setFuncUserParamIdx; - final String cbFuncTypeName; - { - final String stok = tok.nextToken(); - int ival = -1; - String sval = null; - try { - ival = Integer.valueOf(stok); - } catch(final NumberFormatException nfe) { - sval = stok; - } - if( null == sval ) { - setFuncUserParamIdx = ival; - cbFuncTypeName = tok.nextToken(); - } else { - setFuncUserParamIdx = -1; - cbFuncTypeName = sval; - } - } - final Integer cbFuncUserParamIdx = Integer.valueOf(tok.nextToken()); + final int setFuncUserParamIdx = Integer.parseInt(tok.nextToken()); + final String cbFuncTypeName = tok.nextToken(); + final int cbFuncUserParamIdx = Integer.parseInt(tok.nextToken()); final String cbFuncKeyClassName; if( tok.hasMoreTokens() ) { cbFuncKeyClassName = tok.nextToken(); @@ -1734,18 +1718,54 @@ public class JavaConfiguration { if( null == jcd ) { throw new IllegalArgumentException("JavaCallbackDef '"+setFuncName+"\' not (yet) defined."); } + + // Collect setFuncKeyIndices + String stok = null; while( tok.hasMoreTokens() ) { - final int idx = Integer.valueOf(tok.nextToken()); + stok = tok.nextToken(); + if( !isInteger(stok) ) { + break; + } + final int idx = Integer.parseInt(stok); if( 0 > idx ) { - throw new IllegalArgumentException("JavaCallbackKey '"+setFuncName+"\' index "+idx+" not in range [0..n]."); + throw new IllegalArgumentException("JavaCallbackKey '"+setFuncName+"\' SetCallback-ParamIndex "+idx+" not in range [0..n]."); } jcd.setFuncKeyIndices.add( idx ); } + + // Validate proper CallbackFuncType + if( null == stok ) { + throw new IllegalArgumentException("JavaCallbackKey '"+setFuncName+"\': CallbackFuncType missing."); + } + if( !stok.equals(jcd.cbFuncTypeName) ) { + throw new IllegalArgumentException("JavaCallbackKey '"+setFuncName+"\': CallbackFuncType '"+stok+"' not matching JavaCallbackDef: "+jcd); + } + + // Collect cbFuncKeyIndices + while( tok.hasMoreTokens() ) { + final int idx = Integer.parseInt(tok.nextToken()); + if( 0 > idx ) { + throw new IllegalArgumentException("JavaCallbackKey '"+setFuncName+"\' CallbackFunc-ParamIndex "+idx+" not in range [0..n]."); + } + jcd.cbFuncKeyIndices.add( idx ); + } + if( jcd.setFuncKeyIndices.size() != jcd.cbFuncKeyIndices.size() ) { + throw new IllegalArgumentException("JavaCallbackKey '"+setFuncName+"\' SetCallback-ParamIndex list count "+jcd.setFuncKeyIndices.toString()+ + " != CallbackFunc-ParamIndex count "+jcd.cbFuncKeyIndices.toString()); + } } catch (final NoSuchElementException e) { throw new RuntimeException("Error parsing \"JavaCallbackKey\" command at line " + lineNo + " in file \"" + filename + "\"", e); } } + private static boolean isInteger(final String s) { + try { + Integer.parseInt(s); + return true; + } catch(final Exception e) { + return false; + } + } protected void readExtendedIntfImplSymbols(final StringTokenizer tok, final String filename, final int lineNo, final boolean forInterface, final boolean forImplementation, final boolean onlyList) { File javaFile; @@ -2381,6 +2401,7 @@ public class JavaConfiguration { final String staticCBMethodSignature; final FunctionType cbFuncType; final MethodBinding cbFuncBinding; + final List<Integer> cbFuncKeyIndices; final int cbFuncUserParamIdx; final String cbFuncUserParamName; final Type cbFuncUserParamType; @@ -2388,13 +2409,13 @@ public class JavaConfiguration { final String setFuncName; final List<Integer> setFuncKeyIndices; final String setFuncKeyClassName; + final int setFuncUserParamIdx; boolean setFuncProcessed; int setFuncCBParamIdx; - int setFuncUserParamIdx; boolean keyClassEmitted; public JavaCallbackInfo(final String cbFuncTypeName, final String cbSimpleClazzName, final String cbFQClazzName, final String staticCBMethodSignature, - final FunctionType cbFuncType, final MethodBinding cbFuncBinding, final int cbFuncUserParamIdx, + final FunctionType cbFuncType, final MethodBinding cbFuncBinding, final int cbFuncUserParamIdx, final List<Integer> cbFuncKeyIndices, final String setFuncName, final int setFuncUserParamIdx, final List<Integer> setFuncKeyIndices, final String setFuncKeyClassName) { this.cbFuncTypeName = cbFuncTypeName; this.cbSimpleClazzName = cbSimpleClazzName; @@ -2416,42 +2437,51 @@ public class JavaConfiguration { } } this.cbFuncUserParamIdx = paramIdx; + this.cbFuncKeyIndices = cbFuncKeyIndices; this.cbFuncUserParamName = paramName; this.cbFuncUserParamType = paramType; } this.setFuncName = setFuncName; this.setFuncKeyIndices = setFuncKeyIndices; this.setFuncKeyClassName = setFuncKeyClassName; + this.setFuncUserParamIdx = setFuncUserParamIdx; this.setFuncProcessed = false; this.setFuncCBParamIdx = -1; - this.setFuncUserParamIdx = setFuncUserParamIdx; this.keyClassEmitted = false; } + private void validateKeyIndices(final FunctionType setFuncType) { + if( this.cbFuncKeyIndices.size() != this.setFuncKeyIndices.size() ) { + throw new IllegalArgumentException("JavaCallback "+setFuncName+": Key count mismatch: setFunc "+setFuncKeyIndices.toString()+ + " != cbFunc "+cbFuncKeyIndices.toString()); + } + for(int i=0; i< this.cbFuncKeyIndices.size(); ++i) { + final int cbFuncIdx = this.cbFuncKeyIndices.get(i); + final Type t1 = this.cbFuncType.getArgumentType(cbFuncIdx); + final int setFuncIdx = this.setFuncKeyIndices.get(i); + final Type t2 = setFuncType.getArgumentType(setFuncIdx); + if( !t1.equals(t2) ) { + throw new IllegalArgumentException("JavaCallback "+setFuncName+": Key Type mismatch: setFunc#"+setFuncIdx+" with "+t2.toString()+", cbFunc#"+cbFuncIdx+" with "+t1.toString()); + } + } + } - public void setFuncProcessed(final int cbParamIdx, final int userParamIdx) { + public void setFuncProcessed(final FunctionType setFuncType, final int cbParamIdx) { if( !setFuncProcessed ) { - if( 0 <= cbParamIdx && 0 <= userParamIdx ) { + if( 0 <= cbParamIdx ) { setFuncProcessed = true; setFuncCBParamIdx = cbParamIdx; - if( 0 <= setFuncUserParamIdx ) { - if( setFuncUserParamIdx != userParamIdx ) { - throw new IllegalArgumentException("Mismatch pre-set setFuncUserParamIdx "+setFuncUserParamIdx+", given "+userParamIdx+": "+toString()); - } - } else { - setFuncUserParamIdx = userParamIdx; - } + validateKeyIndices(setFuncType); } else { setFuncCBParamIdx = -1; - setFuncUserParamIdx = -1; } } } @Override public String toString() { - return String.format("JavaCallbackInfo[cbFunc[%s%s, userParam[idx %d, '%s', %s], set[%s(ok %b, cbIdx %d, upIdx %d, keys %s, KeyClass '%s'], %s]", + return String.format("JavaCallbackInfo[cbFunc[%s%s, userParam[idx %d, '%s', %s, keys %s], set[%s(ok %b, cbIdx %d, upIdx %d, keys %s, KeyClass '%s'], %s]", cbFuncTypeName, staticCBMethodSignature, - cbFuncUserParamIdx, cbFuncUserParamName, cbFuncUserParamType.getSignature(null).toString(), + cbFuncUserParamIdx, cbFuncUserParamName, cbFuncUserParamType.getSignature(null).toString(), cbFuncKeyIndices.toString(), setFuncName, setFuncProcessed, setFuncCBParamIdx, setFuncUserParamIdx, setFuncKeyIndices.toString(), setFuncKeyClassName, cbFuncType.toString(cbFuncTypeName, false, true)); diff --git a/src/java/com/jogamp/gluegen/JavaEmitter.java b/src/java/com/jogamp/gluegen/JavaEmitter.java index 8af79e4..07bd55d 100644 --- a/src/java/com/jogamp/gluegen/JavaEmitter.java +++ b/src/java/com/jogamp/gluegen/JavaEmitter.java @@ -1473,7 +1473,7 @@ public class JavaEmitter implements GlueEmitter { funcType.toString(jcbd.cbFuncTypeName, false, true)); } final JavaCallbackInfo jcbi1 = new JavaCallbackInfo(jcbd.cbFuncTypeName, cbSimpleClazzName, cbFQClazzName, jcbi0.staticCBMethodSignature, - funcType, jcbi0.cbFuncBinding, jcbi0.cbFuncUserParamIdx, + funcType, jcbi0.cbFuncBinding, jcbi0.cbFuncUserParamIdx, jcbi0.cbFuncKeyIndices, jcbd.setFuncName, jcbd.setFuncUserParamIdx, jcbd.setFuncKeyIndices, jcbd.setFuncKeyClassName); cfg.setFuncToJavaCallbackMap.put(jcbd.setFuncName, jcbi1); LOG.log(INFO, "JavaCallbackInfo: Reusing {0} -> {1}", jcbd.setFuncName, jcbi0); @@ -1493,7 +1493,7 @@ public class JavaEmitter implements GlueEmitter { cbFuncBinding.getJavaReturnType()+", func "+funcType.toString(jcbd.cbFuncTypeName, false, true)); } final JavaCallbackInfo jcbi1 = new JavaCallbackInfo(jcbd.cbFuncTypeName, cbSimpleClazzName, cbFQClazzName, cbMethodSignature.toString(), - funcType, cbFuncBinding, jcbd.cbFuncUserParamIdx, + funcType, cbFuncBinding, jcbd.cbFuncUserParamIdx, jcbd.cbFuncKeyIndices, jcbd.setFuncName, jcbd.setFuncUserParamIdx, jcbd.setFuncKeyIndices, jcbd.setFuncKeyClassName); cfg.setFuncToJavaCallbackMap.put(jcbd.setFuncName, jcbi1); javaCallbackInterfaceMap.put(cbFQClazzName, jcbi1); @@ -3104,7 +3104,7 @@ public class JavaEmitter implements GlueEmitter { stringArgIndices = PascalStringIdx.pushValueIndex(pascalStringArgs, stringArgIndices); } final JavaCallbackInfo jcbi = cfg.setFuncToJavaCallbackMap.get( sym.getName() ); - int jcbiSetFuncCBParamIdx=-1, jcbiSetFuncUserParamIdx=-1; + int jcbiSetFuncCBParamIdx=-1; for (int i = 0; i < sym.getNumArguments(); i++) { final Type cArgType = sym.getArgumentType(i); @@ -3121,20 +3121,6 @@ public class JavaEmitter implements GlueEmitter { mappedType = JavaType.createForNamedClass( jcbi.cbFQClazzName ); } else if( null != jcbi && i == jcbi.setFuncUserParamIdx && cArgType.isPointer() ) { // Replace userParam argument '<userParamType>*' if 'void*' with Object - jcbiSetFuncUserParamIdx=i; - if( cArgType.getTargetType().isVoid() ) { - if( jcbi.cbFuncUserParamType.isCompound() ) { - mappedType = JavaType.createForClass(long.class); - } else { - mappedType = JavaType.forObjectClass(); - } - } - } else if( null != jcbi && jcbi.cbFuncUserParamName.equals( cArgName ) && - ( !jcbi.setFuncProcessed || i == jcbi.setFuncUserParamIdx ) && - cArgType.isPointer() && jcbi.cbFuncUserParamType.equals( cArgType.getTargetType() ) ) - { - // Replace userParam argument '<userParamType>*' if 'void*' with Object - jcbiSetFuncUserParamIdx=i; if( cArgType.getTargetType().isVoid() ) { if( jcbi.cbFuncUserParamType.isCompound() ) { mappedType = JavaType.createForClass(long.class); @@ -3174,9 +3160,9 @@ public class JavaEmitter implements GlueEmitter { //System.out.println("During binding of [" + sym + "], added mapping from C type: " + cArgType + " to Java type: " + mappedType); } if( null != jcbi ) { - jcbi.setFuncProcessed(jcbiSetFuncCBParamIdx, jcbiSetFuncUserParamIdx); - LOG.log(INFO, "BindFunc.JavaCallback: {0}: set[cbParamIdx {1}, userParamIdx {2}], {3}, {4}", - sym.getName(), jcbiSetFuncCBParamIdx, jcbiSetFuncUserParamIdx, sym.getType().toString(sym.getName(), false, true), jcbi); + jcbi.setFuncProcessed(sym.getType(), jcbiSetFuncCBParamIdx); + LOG.log(INFO, "BindFunc.JavaCallback: {0}: set[cbParamIdx {1}], {3}, {4}", + sym.getName(), jcbiSetFuncCBParamIdx, sym.getType().toString(sym.getName(), false, true), jcbi); } final MethodBinding mb = new MethodBinding(sym, delegationImplName, javaReturnType, javaArgumentTypes, 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 8c1d726..bc04977 100644 --- a/src/junit/com/jogamp/gluegen/test/junit/generation/Test4JavaCallback.java +++ b/src/junit/com/jogamp/gluegen/test/junit/generation/Test4JavaCallback.java @@ -446,7 +446,7 @@ public class Test4JavaCallback extends BaseClass { Assert.assertEquals(0, bt2.getAlBufferCallback1Keys().size()); // 1st mapping: buffer1 -> myCallback01, myUserParam01 - bt2.alBufferCallback1(buffer1, 0, 0, myCallback01, myUserParam01); + bt2.alBufferCallback1(myUserParam01, buffer1, 0, 0, myCallback01); Assert.assertEquals(true, bt2.isAlBufferCallback1Mapped(buffer1Key)); Assert.assertEquals(false, bt2.isAlBufferCallback1Mapped(buffer2Key)); Assert.assertEquals(false, bt2.isAlBufferCallback1Mapped(buffer3Key)); @@ -465,7 +465,7 @@ public class Test4JavaCallback extends BaseClass { } // 2nd mapping: buffer2 -> myCallback02, myUserParam02 - bt2.alBufferCallback1(buffer2, 0, 0, myCallback02, myUserParam02); + bt2.alBufferCallback1(myUserParam02, buffer2, 0, 0, myCallback02); Assert.assertEquals(true, bt2.isAlBufferCallback1Mapped(buffer1Key)); Assert.assertEquals(true, bt2.isAlBufferCallback1Mapped(buffer2Key)); Assert.assertEquals(false, bt2.isAlBufferCallback1Mapped(buffer3Key)); @@ -512,7 +512,7 @@ public class Test4JavaCallback extends BaseClass { } // Switch the callback function for buffer2 -> myCallback01, myUserParam02 - bt2.alBufferCallback1(buffer2, 0, 0, myCallback01, myUserParam02); + bt2.alBufferCallback1(myUserParam02, buffer2, 0, 0, myCallback01); Assert.assertEquals(true, bt2.isAlBufferCallback1Mapped(buffer1Key)); Assert.assertEquals(true, bt2.isAlBufferCallback1Mapped(buffer2Key)); Assert.assertEquals(false, bt2.isAlBufferCallback1Mapped(buffer3Key)); @@ -552,7 +552,7 @@ 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! + bt2.alBufferCallback1(myUserParam02, buffer2, 0, 0, null); // usrptr is not key, only buffer is key! Assert.assertEquals(true, bt2.isAlBufferCallback1Mapped(buffer1Key)); Assert.assertEquals(false, bt2.isAlBufferCallback1Mapped(buffer2Key)); Assert.assertEquals(false, bt2.isAlBufferCallback1Mapped(buffer3Key)); @@ -571,7 +571,7 @@ public class Test4JavaCallback extends BaseClass { } // Just release the buffer1 callback and mapped resources - bt2.alBufferCallback1(buffer1, 0, 0, null, null); // usrptr is not key, only buffer is key! + bt2.alBufferCallback1(null, buffer1, 0, 0, null); // usrptr is not key, only buffer is key! Assert.assertEquals(false, bt2.isAlBufferCallback1Mapped(buffer1Key)); Assert.assertEquals(false, bt2.isAlBufferCallback1Mapped(buffer2Key)); Assert.assertEquals(false, bt2.isAlBufferCallback1Mapped(buffer3Key)); 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 28fb3aa..dafad7c 100644 --- a/src/junit/com/jogamp/gluegen/test/junit/generation/test2.c +++ b/src/junit/com/jogamp/gluegen/test/junit/generation/test2.c @@ -165,7 +165,7 @@ void alBufferCallback0Inject(int buffer, int sampledata, int 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) { +void alBufferCallback1(void* userptr, int buffer /* key */, int format, int freq, ALBUFFERCALLBACKTYPESOFT callback) { 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 { 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 08194e6..d4ea72d 100644 --- a/src/junit/com/jogamp/gluegen/test/junit/generation/test2.cfg +++ b/src/junit/com/jogamp/gluegen/test/junit/generation/test2.cfg @@ -67,14 +67,14 @@ ArgumentIsString InjectMessageCallback01 1 # - `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 +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 /* identity-key */); +# void alEventCallback(ALEVENTPROCSOFT callback, void *userParam); # void alEventCallbackInject(int eventType, int object, int param, const char* msg); ArgumentIsPascalString ALEVENTPROCSOFT 3 4 ArgumentIsString alEventCallbackInject 3 @@ -93,17 +93,17 @@ ArgumentIsString alEventCallbackInject 3 # - `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 +JavaCallbackDef alEventCallback 1 ALEVENTPROCSOFT 5 +# JavaCallbackKey alEventCallback 1 ALEVENTPROCSOFT 5 # # End JavaCallback # 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); +# // typedef void ( * ALBUFFERCALLBACKTYPESOFT)(int buffer /* key */, void *userptr, void *sampledata, int numbytes); +# typedef void ( * ALBUFFERCALLBACKTYPESOFT)(int buffer /* key */, void *userptr, int sampledata, int numbytes); # -# void alBufferCallback0(int buffer /* key */, int format, int freq, ALBUFFERCALLBACKTYPESOFT callback, void *userptr /* identity-key */); +# 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); @@ -124,8 +124,8 @@ JavaCallbackKey alEventCallback # - `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 +JavaCallbackDef alBufferCallback0 4 ALBUFFERCALLBACKTYPESOFT 1 +JavaCallbackKey alBufferCallback0 0 ALBUFFERCALLBACKTYPESOFT 0 # # End JavaCallback @@ -133,7 +133,10 @@ JavaCallbackKey alBufferCallback0 0 # # Reuses: ALBUFFERCALLBACKTYPESOFT, see above. # -# void alBufferCallback1(int buffer /* key */, int format, int freq, ALBUFFERCALLBACKTYPESOFT callback, void *userptr /* identity-key */); +# // typedef void ( * ALBUFFERCALLBACKTYPESOFT)(int buffer /* key */, void *userptr, void *sampledata, int numbytes); +# typedef void ( * ALBUFFERCALLBACKTYPESOFT)(int buffer /* key */, void *userptr, int sampledata, int numbytes); +# +# void alBufferCallback1(void* user_ptr, int buffer_key /* key */, int format, int freq, ALBUFFERCALLBACKTYPESOFT callback); # # // void alBufferCallback1Inject(int buffer, void *sampledata, int numbytes); # void alBufferCallback1Inject(int buffer, int sampledata, int numbytes); @@ -151,8 +154,8 @@ JavaCallbackKey alBufferCallback0 0 # - `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 +JavaCallbackDef alBufferCallback1 0 ALBUFFERCALLBACKTYPESOFT 1 com.jogamp.gluegen.test.junit.generation.Test4JavaCallback.CustomAlBufferCallback1Key +JavaCallbackKey alBufferCallback1 1 ALBUFFERCALLBACKTYPESOFT 0 # # End JavaCallback @@ -162,15 +165,15 @@ JavaCallbackKey alBufferCallback1 0 # void MessageCallback11a(size_t id /* key */, T2_CallbackFunc11 cbFunc, const T2_Callback11UserType* usrParam); # void MessageCallback11aInject(size_t id); #JavaCallbackDef MessageCallback11a T2_CallbackFunc11 1 com.jogamp.gluegen.test.junit.generation.Test4JavaCallback.CustomMessageCallback11Key -JavaCallbackDef MessageCallback11a T2_CallbackFunc11 1 -JavaCallbackKey MessageCallback11a 0 +JavaCallbackDef MessageCallback11a 2 T2_CallbackFunc11 1 +JavaCallbackKey MessageCallback11a 0 T2_CallbackFunc11 0 # # End JavaCallback # void MessageCallback11b(size_t id /* key */, T2_CallbackFunc11 cbFunc, void* Data); # void MessageCallback11bInject(size_t id); JavaCallbackDef MessageCallback11b 2 T2_CallbackFunc11 1 -JavaCallbackKey MessageCallback11b 0 +JavaCallbackKey MessageCallback11b 0 T2_CallbackFunc11 0 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 183f905..dea6d72 100644 --- a/src/junit/com/jogamp/gluegen/test/junit/generation/test2.h +++ b/src/junit/com/jogamp/gluegen/test/junit/generation/test2.h @@ -84,7 +84,7 @@ void alBufferCallback0(int buffer /* key */, int format, int freq, ALBUFFERCALLB // 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 alBufferCallback1(void* user_ptr, int buffer_key /* key */, int format, int freq, ALBUFFERCALLBACKTYPESOFT callback); // void alBufferCallback1Inject(int buffer, void *sampledata, int numbytes); void alBufferCallback1Inject(int buffer, int sampledata, int numbytes); |