diff options
author | Sven Gothel <[email protected]> | 2023-07-10 16:39:36 +0200 |
---|---|---|
committer | Sven Gothel <[email protected]> | 2023-07-10 16:39:36 +0200 |
commit | 0ea6688e41c31b0e2c8dba73582c935562885b44 (patch) | |
tree | 4e4b3c96e99e7552f4cf481df0ab88523048e185 | |
parent | 63ed5f7676bc46ee03db1a6d27c5ce86fcf6a597 (diff) |
GlueGen JavaCallback: Add optional custom 'Callback-UserParamClass` for non-compound `UserParam` types to have more clarity in resulting API
9 files changed, 513 insertions, 443 deletions
diff --git a/doc/GlueGen_Mapping.html b/doc/GlueGen_Mapping.html index bde318d..5524d2e 100644 --- a/doc/GlueGen_Mapping.html +++ b/doc/GlueGen_Mapping.html @@ -2001,6 +2001,11 @@ side receives a simple unique ID and shall not dereference the <p>The static Java callback dispatcher fetches the Java <code>UserParam</code> <em>Object</em> from the key-mapped data value.</p> +<p>Instead of using the default plain Java <code>Object</code> type, a +<a href="#custom-callback-userparamclass">custom <em>UserParam</em></a> +can be specified <a href="#javacallback-configuration">in the +configuration</a>, which is recommended for more clarity in the +resulting API.</p> <h4 id="struct-type-user-param-homogeneous">Struct Type User Param (Homogeneous)</h4> <p>A <a href="#struct-mapping">GlueGen generated <em>Struct @@ -2032,7 +2037,7 @@ 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>] +<pre><code>JavaCallbackDef <SetCallbackFunctionName> <SetCallback-UserParamIndex> <CallbackFunctionType> <CallbackFunction-UserParamIndex> [<Callback-UserParamClass> [<Callback-KeyClass>]] 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 @@ -2052,9 +2057,13 @@ name</li> <code>CallbackFunctionType</code>, which 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> +<li><code>Callback-UserParamClass</code>: Optional <a +href="#custom-callback-userparamclass">custom <em>UserParam</em></a> +overriding the default <code>Object</code> for non-compound +<code>UserParam</code> types.</li> +<li><code>Callback-KeyClass</code>: Optional <a +href="#custom-callback-keyclass">custom <em>KeyClass</em></a>, providing +the hash-map-key.</li> </ul> <p>The <code>SetCallbackFunction</code> is utilized to set the <code>CallbackFunction</code> as well as to remove it passing @@ -2065,12 +2074,12 @@ specify the same key arguments when setting and removing the <h4 id="javacallback-key-definition"><em>JavaCallback</em> Key Definition</h4> <p>If no keys are defined via <code>JavaCallbackKey</code> or not -manually injected using a custom <code>SetCallback-KeyClass</code>, see +manually injected using a custom <code>Callback-KeyClass</code>, see below, the <code>CallbackFunction</code> has global scope.</p> <p>In case keys are defined via <code>JavaCallbackKey</code> and no -manually injected custom <code>SetCallback-KeyClass</code> used, a -public <code>SetCallback-KeyClass</code> is being generated covering the -defined keys.</p> +manually injected custom <code>Callback-KeyClass</code> used, a public +<code>Callback-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>To remove a previously set <code>CallbackFunction</code> via @@ -2082,8 +2091,8 @@ name of the native toolkit API responsible to set the callback</li> <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> +this key. The optional <code>Callback-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> @@ -2091,20 +2100,27 @@ as defined in <code>JavaCallbackDef</code></li> of the <code>CallbackFunctionType</code>, matching the semantic parameter of <code>SetCallback-ParamIndex</code>.</li> </ul> -<h4 id="custom-setcallback-keyclass">Custom -<code>SetCallback-KeyClass</code></h4> -<p>The <code>SetCallback-KeyClass</code> is the optional user-written +<h4 id="custom-callback-userparamclass">Custom +<code>Callback-UserParamClass</code></h4> +<p>Instead of using the default plain Java <code>Object</code> for +non-compound <code>UserParam</code> types, a custom +<code>Callback-UserParamClass</code> can be specified <a +href="#javacallback-configuration">in the configuration</a>, which +produces more clarity in the resulting API.</p> +<h4 id="custom-callback-keyclass">Custom +<code>Callback-KeyClass</code></h4> +<p>The <code>Callback-KeyClass</code> is the optional user-written hash-map-key definition and shall handle all key parameter of the <code>SetCallbackFunction</code> as defined via <code>JavaCallbackKey</code>, see above.</p> -<p><code>SetCallback-KeyClass</code> may be used to add external +<p><code>Callback-KeyClass</code> may be used to add external key-components, e.g. current-thread or a toolkit dependent context.</p> -<p>The <code>SetCallback-KeyClass</code> shall implement the following +<p>The <code>Callback-KeyClass</code> shall implement the following hash-map-key standard methods</p> <ul> <li><code>boolean equals(Object)</code></li> <li><code>int hashCode()</code></li> -<li><code>SetCallback-KeyClassName(...)</code> constructor receiving all +<li><code>Callback-KeyClassName(...)</code> constructor receiving all key parameter of <code>SetCallbackFunction</code> as defined via <code>JavaCallbackKey</code>, see above.</li> </ul> @@ -2122,39 +2138,39 @@ for details.</p> id="javacallback-generated-interfaces-classes-and-methods"><em>JavaCallback</em> Generated Interfaces, Classes and Methods</h3> <p>The public <code>CallbackFunction</code> interface is generated.</p> -<p>The default public <code>SetCallback-KeyClass</code> is generated if +<p>The default public <code>Callback-KeyClass</code> is generated if keys are used and no custom class is specified, see above.</p> <p>The public toolkit API <code>SetCallbackFunction</code> method is being generated.</p> <p>Additional public <em>maintenance</em> methods are generated. In case -keys are being used, they expect <code>SetCallback-KeyClass</code> as an +keys are being used, they expect <code>Callback-KeyClass</code> as an argument, otherwise they expect no argument for global scope.</p> -<p>In case a <code>SetCallback-KeyClass</code> is used, the additional +<p>In case a <code>Callback-KeyClass</code> is used, the additional <em>maintenance</em> methods are:</p> <ul> -<li><em>Set<<code>SetCallback-KeyClass</code>> +<li><em>Set<<code>Callback-KeyClass</code>> get<code>SetCallbackFunctionName</code>Keys()</em></li> <li><em>boolean -is<code>SetCallbackFunctionName</code>Mapped(<code>SetCallback-KeyClass</code>)</em> +is<code>SetCallbackFunctionName</code>Mapped(<code>Callback-KeyClass</code>)</em> queries whether <code>SetCallbackFunctionName</code> is mapped to key.</li> <li><em><code>CallbackFunction</code> -get<code>SetCallbackFunctionName</code>(<code>SetCallback-KeyClass</code>)</em> +get<code>SetCallbackFunctionName</code>(<code>Callback-KeyClass</code>)</em> returns the mapped <code>CallbackFunction</code>, null if not mapped</li> -<li><em>Object -get<code>SetCallbackFunctionName</code>UserParam(<code>SetCallback-KeyClass</code>)</em> +<li><em><code>Callback-UserParamClass</code> +get<code>SetCallbackFunctionName</code>UserParam(<code>Callback-KeyClass</code>)</em> returns the mapped <code>userParam</code> object, null if not mapped</li> <li><em>void -release<code>SetCallbackFunctionName</code>(<code>SetCallback-KeyClass</code>)</em> +release<code>SetCallbackFunctionName</code>(<code>Callback-KeyClass</code>)</em> releases the mapped <code>CallbackFunction</code> data set associated via <code>SetCallbackFunctionName</code>.</li> <li><em>int releaseAll<code>SetCallbackFunctionName</code>()</em> releases complete mapped <code>CallbackFunction</code> data set associated via <code>SetCallbackFunctionName</code>.</li> </ul> -<p>If no <code>SetCallback-KeyClass</code> is used, the additional +<p>If no <code>Callback-KeyClass</code> is used, the additional <em>maintenance</em> methods are:</p> <ul> <li><em>boolean is<code>SetCallbackFunctionName</code>Mapped()</em> @@ -2162,9 +2178,9 @@ queries whether <code>SetCallbackFunctionName</code> is mapped.</li> <li><em><code>CallbackFunction</code> get<code>SetCallbackFunctionName</code>()</em> returns the mapped <code>CallbackFunction</code>, null if not mapped</li> -<li><em>Object get<code>SetCallbackFunctionName</code>UserParam()</em> -returns the mapped <code>userParam</code> object, null if not -mapped</li> +<li><em><code>Callback-UserParamClass</code> +get<code>SetCallbackFunctionName</code>UserParam()</em> returns the +mapped <code>userParam</code> object, null if not mapped</li> <li><em>void release<code>SetCallbackFunctionName</code>()</em> releases the mapped <code>CallbackFunction</code> data set associated via <code>SetCallbackFunctionName</code>.</li> @@ -2285,6 +2301,9 @@ 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>Additionally a <a href="#custom-callback-userparamclass">custom +<em>UserParam</em></a> type <code>ALCcontext</code> is being used for +more clarity in the resulting API.</p> <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 @@ -2310,16 +2329,16 @@ buffer.</p> # - `Set<AlBufferCallback0Key> getAlBufferCallback0Keys()` returns set of Key { int buffer } # - `boolean isAlBufferCallback0Mapped(AlBufferCallback0Key)` queries whether `alBufferCallback0` is mapped to `buffer`. # - `ALBUFFERCALLBACKTYPESOFT getAlBufferCallback0(AlBufferCallback0Key)` returns the `buffer` mapped ALEVENTPROCSOFT, null if not mapped - # - `Object getAlBufferCallback0UserParam(AlBufferCallback0Key)` returns the `buffer` mapped `userptr` object, null if not mapped + # - `ALCcontext 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 4 ALBUFFERCALLBACKTYPESOFT 1 + JavaCallbackDef alBufferCallback0 4 ALBUFFERCALLBACKTYPESOFT 1 ALCcontext 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 { /** Interface to C language function: <br> <code>void callback(int buffer, void * userptr, int sampledata, int numbytes)</code><br>Alias for: <code>ALBUFFERCALLBACKTYPESOFT</code> */ - public void callback(int buffer, Object userptr, int sampledata, int numbytes); + public void callback(int buffer, ALCcontext userptr, int sampledata, int numbytes); } ... @@ -2351,35 +2370,35 @@ buffer.</p> ... - /** Entry point (through function pointer) to C language function: <br> <code>void alBufferCallback0(int buffer, int format, int freq, ALBUFFERCALLBACKTYPESOFT callback, void * userptr)</code><br> */ - public void alBufferCallback0(int buffer, int format, int freq, ALBUFFERCALLBACKTYPESOFT callback, Object userptr); - - /** Returns set of Key { int buffer } for <br> <code> public void alBufferCallback0(int buffer, int format, int freq, ALBUFFERCALLBACKTYPESOFT callback, Object userptr)</code> **/ + /** Returns set of Key { int buffer } for <br> <code> void alBufferCallback0(int buffer, int format, int freq, ALBUFFERCALLBACKTYPESOFT callback, ALCcontext userptr)</code> */ public Set<AlBufferCallback0Key> getAlBufferCallback0Keys(); - /** Returns whether callback Key { int buffer } is mapped for <br> <code> public void alBufferCallback0(int buffer, int format, int freq, ALBUFFERCALLBACKTYPESOFT callback, Object userptr)</code> **/ + /** Returns whether callback Key { int buffer } is mapped for <br> <code> void alBufferCallback0(int buffer, int format, int freq, ALBUFFERCALLBACKTYPESOFT callback, ALCcontext userptr)</code> */ public boolean isAlBufferCallback0Mapped(AlBufferCallback0Key key); - /** Returns ALBUFFERCALLBACKTYPESOFT callback mapped to Key { int buffer } for <br> <code> public void alBufferCallback0(int buffer, int format, int freq, ALBUFFERCALLBACKTYPESOFT callback, Object userptr)</code> **/ + /** Returns ALBUFFERCALLBACKTYPESOFT callback mapped to Key { int buffer } for <br> <code> void alBufferCallback0(int buffer, int format, int freq, ALBUFFERCALLBACKTYPESOFT callback, ALCcontext userptr)</code> */ public ALBUFFERCALLBACKTYPESOFT getAlBufferCallback0(AlBufferCallback0Key key); - /** Returns user-param mapped to Key { int buffer } for <br> <code> public void alBufferCallback0(int buffer, int format, int freq, ALBUFFERCALLBACKTYPESOFT callback, Object userptr)</code> **/ - public Object getAlBufferCallback0UserParam(AlBufferCallback0Key key); + /** Returns user-param mapped to Key { int buffer } for <br> <code> void alBufferCallback0(int buffer, int format, int freq, ALBUFFERCALLBACKTYPESOFT callback, ALCcontext userptr)</code> */ + public ALCcontext getAlBufferCallback0UserParam(AlBufferCallback0Key key); - /** Releases all callback data mapped via Key { int buffer } skipping toolkit API. Favor passing `null` callback ref to <br> <code> public void alBufferCallback0(int buffer, int format, int freq, ALBUFFERCALLBACKTYPESOFT callback, Object userptr)</code> **/ + /** Releases all callback data mapped via Key { int buffer } skipping toolkit API. Favor passing `null` callback ref to <br> <code> void alBufferCallback0(int buffer, int format, int freq, ALBUFFERCALLBACKTYPESOFT callback, ALCcontext userptr)</code> */ public int releaseAllAlBufferCallback0(); - /** Releases callback data mapped to Key { int buffer } skipping toolkit API. Favor passing `null` callback ref to <br> <code> public void alBufferCallback0(int buffer, int format, int freq, ALBUFFERCALLBACKTYPESOFT callback, Object userptr)</code> **/ + /** Releases callback data mapped to Key { int buffer } skipping toolkit API. Favor passing `null` callback ref to <br> <code> void alBufferCallback0(int buffer, int format, int freq, ALBUFFERCALLBACKTYPESOFT callback, ALCcontext userptr)</code> */ public void releaseAlBufferCallback0(AlBufferCallback0Key key); - /** 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> + /** Entry point (through function pointer) to C language function: <br> <code>void alBufferCallback0(int buffer, int format, int freq, ALBUFFERCALLBACKTYPESOFT callback, void * userptr)</code><br> */ + public void alBufferCallback0(int buffer, int format, int freq, ALBUFFERCALLBACKTYPESOFT callback, ALCcontext userptr); + + /** Entry point (through function pointer) to C language function: <br> <code>void alBufferCallback0Inject(int buffer, int sampledata, int numbytes)</code><br> */ + public void alBufferCallback0Inject(int buffer, int sampledata, int numbytes);</code></pre> <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 +href="#custom-callback-keyclass">custom <em>KeyClass</em></a> to map <code>CallbackFunction</code> and <code>UserParam</code> and also accommodating a different key-parameter order between <code>SetCallbackFunction</code> and <code>CallbackFunction</code>.</p> @@ -2390,14 +2409,14 @@ accommodating a different key-parameter order between 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>Callback-KeyClass</code> in directive <code>JavaCallbackDef</code>.</p> -<pre><code>JavaCallbackDef alBufferCallback1 0 ALBUFFERCALLBACKTYPESOFT 1 com.jogamp.gluegen.test.junit.generation.Test4JavaCallback.CustomAlBufferCallback1Key +<pre><code>JavaCallbackDef alBufferCallback1 0 ALBUFFERCALLBACKTYPESOFT 1 ALCcontext com.jogamp.gluegen.test.junit.generation.Test4JavaCallback.CustomAlBufferCallback1Key JavaCallbackKey alBufferCallback1 1 ALBUFFERCALLBACKTYPESOFT 0 </code></pre> -<p>Implementation utilizes a custom <code>SetCallback-KeyClass</code> +<p>Implementation utilizes a custom <code>Callback-KeyClass</code> implementation for -<code>void alBufferCallback1(int buffer, int format, int freq, ALBUFFERCALLBACKTYPESOFT callback, Object userptr)</code>, +<code>void alBufferCallback1(int buffer, int format, int freq, ALBUFFERCALLBACKTYPESOFT callback, ALCcontext userptr)</code>, which uses one key, i.e. <code>buffer</code>.</p> <pre><code> public static class CustomAlBufferCallback1Key { private final int buffer; @@ -2428,24 +2447,26 @@ which uses one key, i.e. <code>buffer</code>.</p> id="javacallback-example-5b-userparam-part-of-2-component-key">JavaCallback Example 5b (UserParam part of 2 component-key)</h3> <p>Similar example as example 2a, but having the <code>UserParam</code> -as part of the 2 component-key.</p> +as part of the 2 component-key <em>and</em> defining +<code>Callback-UserParamClass</code> class as +<code>ALCcontext</code>.</p> <p>C-API Header snipped</p> <pre><code> typedef void ( * ALEVENTPROCSOFT)(int eventType, int object, int param, int length, const char *message, void *userParam /* key */); void alEventCallback1(int object /* key */, ALEVENTPROCSOFT callback, void *userParam /* key */);</code></pre> <p>GlueGen configuration snippet with the added option attribute for the -<code>SetCallback-KeyClass</code> in directive +<code>Callback-UserParamClass</code> in directive <code>JavaCallbackDef</code>.</p> <pre><code>ArgumentIsPascalString ALEVENTPROCSOFT 3 4 -JavaCallbackDef alEventCallback1 2 ALEVENTPROCSOFT 5 +JavaCallbackDef alEventCallback1 2 ALEVENTPROCSOFT 5 ALCcontext JavaCallbackKey alEventCallback1 0 2 ALEVENTPROCSOFT 1 5</code></pre> <p>Resulting to the default <code>KeyClass</code></p> -<pre><code> /** Key { int object, java.lang.Object userParam } for <br> <code> void alEventCallback1(int object, ALEVENTPROCSOFT callback, Object userParam)</code> */ +<pre><code> /** Key { int object, ALCcontext userParam } for <br> <code> void alEventCallback1(int object, ALEVENTPROCSOFT callback, ALCcontext userParam)</code> */ public static class AlEventCallback1Key { public final int object; - public final java.lang.Object userParam; - public AlEventCallback1Key(int object, java.lang.Object userParam) { + public final ALCcontext userParam; + public AlEventCallback1Key(int object, ALCcontext userParam) { this.object = object; this.userParam = userParam; } @@ -2518,7 +2539,7 @@ method <code>MessageCallback11b(..)</code>.</p> public T2_CallbackFunc11 getMessageCallback11a(MessageCallback11aKey key); /** Returns user-param mapped to Key { long id } for <br> <code> void MessageCallback11a(long id, T2_CallbackFunc11 cbFunc, T2_Callback11UserType usrParam)</code> */ - public Object getMessageCallback11aUserParam(MessageCallback11aKey key); + public T2_Callback11UserType getMessageCallback11aUserParam(MessageCallback11aKey key); /** Releases all callback data mapped via Key { long id } skipping toolkit API. Favor passing `null` callback ref to <br> <code> void MessageCallback11a(long id, T2_CallbackFunc11 cbFunc, T2_Callback11UserType usrParam)</code> */ public int releaseAllMessageCallback11a(); @@ -2530,7 +2551,7 @@ method <code>MessageCallback11b(..)</code>.</p> public void MessageCallback11a(long id, T2_CallbackFunc11 cbFunc, T2_Callback11UserType usrParam); /** Entry point (through function pointer) to C language function: <br> <code>void MessageCallback11aInject(size_t id, long val)</code><br> */ - public void MessageCallback11aInject(long id, long val); </code></pre> + public void MessageCallback11aInject(long id, long val);</code></pre> <h3 id="javacallback-example-11b-heterogeneous-pointerstruct-type">JavaCallback Example 11b (<em>Heterogeneous Pointer/Struct Type</em>)</h3> @@ -2596,7 +2617,7 @@ users' <code>void*</code> pointer with the public void MessageCallback11b(long id, T2_CallbackFunc11 cbFunc, long Data); /** Entry point (through function pointer) to C language function: <br> <code>void MessageCallback11bInject(size_t id, long val)</code><br> */ - public void MessageCallback11bInject(long id, long val); </code></pre> + public void MessageCallback11bInject(long id, long val);</code></pre> <p><em>TODO: Enhance documentation</em></p> <h2 id="misc-configurations">Misc Configurations</h2> <h3 diff --git a/doc/GlueGen_Mapping.md b/doc/GlueGen_Mapping.md index 060a9b6..94959df 100644 --- a/doc/GlueGen_Mapping.md +++ b/doc/GlueGen_Mapping.md @@ -796,6 +796,8 @@ It's a homogeneous `UserParam` mapping, where the native side receives a simple The static Java callback dispatcher fetches the Java `UserParam` *Object* from the key-mapped data value. +Instead of using the default plain Java `Object` type, a [custom *UserParam*](#custom-callback-userparamclass) can be specified [in the configuration](#javacallback-configuration), which is recommended for more clarity in the resulting API. + #### Struct Type User Param (Homogeneous) A [GlueGen generated *Struct type*](#struct-mapping) is used for both, `SetCallbackFunctionName` and `CallbackFunctionType`. @@ -816,7 +818,7 @@ 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>] + JavaCallbackDef <SetCallbackFunctionName> <SetCallback-UserParamIndex> <CallbackFunctionType> <CallbackFunction-UserParamIndex> [<Callback-UserParamClass> [<Callback-KeyClass>]] JavaCallbackKey <SetCallbackFunctionName> <SetCallback-ParamIndex>* <CallbackFunctionType> <CallbackFunction-ParamIndex>* `JavaCallbackDef` and `JavaCallbackKey` use the name of the `SetCallbackFunction` as its first attribute, @@ -827,7 +829,8 @@ as it is core to the semantic mapping of all resources. They also have to use th - `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`, which 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 +- `Callback-UserParamClass`: Optional [custom *UserParam*](#custom-callback-userparamclass) overriding the default `Object` for non-compound `UserParam` types. +- `Callback-KeyClass`: Optional [custom *KeyClass*](#custom-callback-keyclass), providing the hash-map-key. The `SetCallbackFunction` is utilized to set the `CallbackFunction` as well as to remove it passing `null` for the `CallbackFunction`. @@ -835,11 +838,11 @@ If mapping the `CallbackFunction` to keys, the user must specify the same key ar #### *JavaCallback* Key Definition -If no keys are defined via `JavaCallbackKey` or not manually injected using a custom `SetCallback-KeyClass`, see below, +If no keys are defined via `JavaCallbackKey` or not manually injected using a custom `Callback-KeyClass`, see below, the `CallbackFunction` has global scope. -In case keys are defined via `JavaCallbackKey` and no manually injected custom `SetCallback-KeyClass` used, -a public `SetCallback-KeyClass` is being generated covering the defined keys. +In case keys are defined via `JavaCallbackKey` and no manually injected custom `Callback-KeyClass` used, +a public `Callback-KeyClass` is being generated covering the defined keys. Keys allow to limit the scope, i.e. map multiple `CallbackFunction` to the different keys. @@ -847,22 +850,25 @@ To remove a previously set `CallbackFunction` via `SetCallbackFunction`, the key `JavaCallbackKey` attributes - `SetCallbackFunction`: `SetCallbackFunction` name of the native toolkit API responsible to set the callback -- `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. +- `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 `Callback-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`. +#### Custom `Callback-UserParamClass` + +Instead of using the default plain Java `Object` for non-compound `UserParam` types, a custom `Callback-UserParamClass` can be specified [in the configuration](#javacallback-configuration), which produces more clarity in the resulting API. -#### Custom `SetCallback-KeyClass` +#### Custom `Callback-KeyClass` -The `SetCallback-KeyClass` is the optional user-written hash-map-key definition +The `Callback-KeyClass` is the optional user-written hash-map-key definition and shall handle all key parameter of the `SetCallbackFunction` as defined via `JavaCallbackKey`, see above. -`SetCallback-KeyClass` may be used to add external key-components, e.g. current-thread or a toolkit dependent context. +`Callback-KeyClass` may be used to add external key-components, e.g. current-thread or a toolkit dependent context. -The `SetCallback-KeyClass` shall implement the following hash-map-key standard methods +The `Callback-KeyClass` shall implement the following hash-map-key standard methods - `boolean equals(Object)` - `int hashCode()` -- `SetCallback-KeyClassName(...)` constructor receiving all key parameter of `SetCallbackFunction` as defined via `JavaCallbackKey`, see above. +- `Callback-KeyClassName(...)` constructor receiving all key parameter of `SetCallbackFunction` as defined via `JavaCallbackKey`, see above. #### Required *LibraryOnLoad* Note that [`LibraryOnLoad <LibraryBasename>`](#libraryonload-librarybasename-for-jni_onload-) must be specified in exactly one native code-unit within one native library. @@ -873,24 +879,24 @@ It provides code to allow the generated native callback-function to attach the c The public `CallbackFunction` interface is generated. -The default public `SetCallback-KeyClass` is generated if keys are used and no custom class is specified, see above. +The default public `Callback-KeyClass` is generated if keys are used and no custom class is specified, see above. The public toolkit API `SetCallbackFunction` method is being generated. -Additional public *maintenance* methods are generated. In case keys are being used, they expect `SetCallback-KeyClass` as an argument, otherwise they expect no argument for global scope. +Additional public *maintenance* methods are generated. In case keys are being used, they expect `Callback-KeyClass` as an argument, otherwise they expect no argument for global scope. -In case a `SetCallback-KeyClass` is used, the additional *maintenance* methods are: -- *Set<`SetCallback-KeyClass`> get`SetCallbackFunctionName`Keys()* -- *boolean is`SetCallbackFunctionName`Mapped(`SetCallback-KeyClass`)* queries whether `SetCallbackFunctionName` is mapped to key. -- *`CallbackFunction` get`SetCallbackFunctionName`(`SetCallback-KeyClass`)* returns the mapped `CallbackFunction`, null if not mapped -- *Object get`SetCallbackFunctionName`UserParam(`SetCallback-KeyClass`)* returns the mapped `userParam` object, null if not mapped -- *void release`SetCallbackFunctionName`(`SetCallback-KeyClass`)* releases the mapped `CallbackFunction` data set associated via `SetCallbackFunctionName`. +In case a `Callback-KeyClass` is used, the additional *maintenance* methods are: +- *Set<`Callback-KeyClass`> get`SetCallbackFunctionName`Keys()* +- *boolean is`SetCallbackFunctionName`Mapped(`Callback-KeyClass`)* queries whether `SetCallbackFunctionName` is mapped to key. +- *`CallbackFunction` get`SetCallbackFunctionName`(`Callback-KeyClass`)* returns the mapped `CallbackFunction`, null if not mapped +- *`Callback-UserParamClass` get`SetCallbackFunctionName`UserParam(`Callback-KeyClass`)* returns the mapped `userParam` object, null if not mapped +- *void release`SetCallbackFunctionName`(`Callback-KeyClass`)* releases the mapped `CallbackFunction` data set associated via `SetCallbackFunctionName`. - *int releaseAll`SetCallbackFunctionName`()* releases complete mapped `CallbackFunction` data set associated via `SetCallbackFunctionName`. -If no `SetCallback-KeyClass` is used, the additional *maintenance* methods are: +If no `Callback-KeyClass` is used, the additional *maintenance* methods are: - *boolean is`SetCallbackFunctionName`Mapped()* queries whether `SetCallbackFunctionName` is mapped. - *`CallbackFunction` get`SetCallbackFunctionName`()* returns the mapped `CallbackFunction`, null if not mapped -- *Object get`SetCallbackFunctionName`UserParam()* returns the mapped `userParam` object, null if not mapped +- *`Callback-UserParamClass` get`SetCallbackFunctionName`UserParam()* returns the mapped `userParam` object, null if not mapped - *void release`SetCallbackFunctionName`()* releases the mapped `CallbackFunction` data set associated via `SetCallbackFunctionName`. Note that the *release`SetCallbackFunctionName`(\*)* and *releaseAll`SetCallbackFunctionName`()* methods are not the *proper toolkit API way* to remove the callback, @@ -988,6 +994,8 @@ public interface Bindingtest2 { 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`. +Additionally a [custom *UserParam*](#custom-callback-userparamclass) type `ALCcontext` is being used for more clarity in the resulting API. + 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. @@ -1016,10 +1024,10 @@ and the following GlueGen configuration # - `Set<AlBufferCallback0Key> getAlBufferCallback0Keys()` returns set of Key { int buffer } # - `boolean isAlBufferCallback0Mapped(AlBufferCallback0Key)` queries whether `alBufferCallback0` is mapped to `buffer`. # - `ALBUFFERCALLBACKTYPESOFT getAlBufferCallback0(AlBufferCallback0Key)` returns the `buffer` mapped ALEVENTPROCSOFT, null if not mapped - # - `Object getAlBufferCallback0UserParam(AlBufferCallback0Key)` returns the `buffer` mapped `userptr` object, null if not mapped + # - `ALCcontext 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 4 ALBUFFERCALLBACKTYPESOFT 1 + JavaCallbackDef alBufferCallback0 4 ALBUFFERCALLBACKTYPESOFT 1 ALCcontext JavaCallbackKey alBufferCallback0 0 ALBUFFERCALLBACKTYPESOFT 0 ``` @@ -1028,7 +1036,7 @@ leading to the following interface /** JavaCallback interface: ALBUFFERCALLBACKTYPESOFT -> void (*ALBUFFERCALLBACKTYPESOFT)(int buffer, void * userptr, int sampledata, int numbytes) */ public static interface ALBUFFERCALLBACKTYPESOFT { /** Interface to C language function: <br> <code>void callback(int buffer, void * userptr, int sampledata, int numbytes)</code><br>Alias for: <code>ALBUFFERCALLBACKTYPESOFT</code> */ - public void callback(int buffer, Object userptr, int sampledata, int numbytes); + public void callback(int buffer, ALCcontext userptr, int sampledata, int numbytes); } ... @@ -1060,34 +1068,34 @@ leading to the following interface ... - /** Entry point (through function pointer) to C language function: <br> <code>void alBufferCallback0(int buffer, int format, int freq, ALBUFFERCALLBACKTYPESOFT callback, void * userptr)</code><br> */ - public void alBufferCallback0(int buffer, int format, int freq, ALBUFFERCALLBACKTYPESOFT callback, Object userptr); - - /** Returns set of Key { int buffer } for <br> <code> public void alBufferCallback0(int buffer, int format, int freq, ALBUFFERCALLBACKTYPESOFT callback, Object userptr)</code> **/ + /** Returns set of Key { int buffer } for <br> <code> void alBufferCallback0(int buffer, int format, int freq, ALBUFFERCALLBACKTYPESOFT callback, ALCcontext userptr)</code> */ public Set<AlBufferCallback0Key> getAlBufferCallback0Keys(); - /** Returns whether callback Key { int buffer } is mapped for <br> <code> public void alBufferCallback0(int buffer, int format, int freq, ALBUFFERCALLBACKTYPESOFT callback, Object userptr)</code> **/ + /** Returns whether callback Key { int buffer } is mapped for <br> <code> void alBufferCallback0(int buffer, int format, int freq, ALBUFFERCALLBACKTYPESOFT callback, ALCcontext userptr)</code> */ public boolean isAlBufferCallback0Mapped(AlBufferCallback0Key key); - /** Returns ALBUFFERCALLBACKTYPESOFT callback mapped to Key { int buffer } for <br> <code> public void alBufferCallback0(int buffer, int format, int freq, ALBUFFERCALLBACKTYPESOFT callback, Object userptr)</code> **/ + /** Returns ALBUFFERCALLBACKTYPESOFT callback mapped to Key { int buffer } for <br> <code> void alBufferCallback0(int buffer, int format, int freq, ALBUFFERCALLBACKTYPESOFT callback, ALCcontext userptr)</code> */ public ALBUFFERCALLBACKTYPESOFT getAlBufferCallback0(AlBufferCallback0Key key); - /** Returns user-param mapped to Key { int buffer } for <br> <code> public void alBufferCallback0(int buffer, int format, int freq, ALBUFFERCALLBACKTYPESOFT callback, Object userptr)</code> **/ - public Object getAlBufferCallback0UserParam(AlBufferCallback0Key key); + /** Returns user-param mapped to Key { int buffer } for <br> <code> void alBufferCallback0(int buffer, int format, int freq, ALBUFFERCALLBACKTYPESOFT callback, ALCcontext userptr)</code> */ + public ALCcontext getAlBufferCallback0UserParam(AlBufferCallback0Key key); - /** Releases all callback data mapped via Key { int buffer } skipping toolkit API. Favor passing `null` callback ref to <br> <code> public void alBufferCallback0(int buffer, int format, int freq, ALBUFFERCALLBACKTYPESOFT callback, Object userptr)</code> **/ + /** Releases all callback data mapped via Key { int buffer } skipping toolkit API. Favor passing `null` callback ref to <br> <code> void alBufferCallback0(int buffer, int format, int freq, ALBUFFERCALLBACKTYPESOFT callback, ALCcontext userptr)</code> */ public int releaseAllAlBufferCallback0(); - /** Releases callback data mapped to Key { int buffer } skipping toolkit API. Favor passing `null` callback ref to <br> <code> public void alBufferCallback0(int buffer, int format, int freq, ALBUFFERCALLBACKTYPESOFT callback, Object userptr)</code> **/ + /** Releases callback data mapped to Key { int buffer } skipping toolkit API. Favor passing `null` callback ref to <br> <code> void alBufferCallback0(int buffer, int format, int freq, ALBUFFERCALLBACKTYPESOFT callback, ALCcontext userptr)</code> */ public void releaseAlBufferCallback0(AlBufferCallback0Key key); - /** 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); + /** Entry point (through function pointer) to C language function: <br> <code>void alBufferCallback0(int buffer, int format, int freq, ALBUFFERCALLBACKTYPESOFT callback, void * userptr)</code><br> */ + public void alBufferCallback0(int buffer, int format, int freq, ALBUFFERCALLBACKTYPESOFT callback, ALCcontext userptr); + + /** Entry point (through function pointer) to C language function: <br> <code>void alBufferCallback0Inject(int buffer, int sampledata, int numbytes)</code><br> */ + public void alBufferCallback0Inject(int buffer, int sampledata, int numbytes); ``` ### JavaCallback Example 2b (Custom *KeyClass*, different key-parameter order) -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`. +Similar example as example 2a, but using a [custom *KeyClass*](#custom-callback-keyclass) to map `CallbackFunction` and `UserParam` and also accommodating a different key-parameter order between `SetCallbackFunction` and `CallbackFunction`. C-API Header snipped ``` @@ -1098,14 +1106,14 @@ C-API Header snipped void alBufferCallback1Inject(int buffer, int sampledata, int numbytes); ``` -GlueGen configuration snippet with the added option attribute for the `SetCallback-KeyClass` in directive `JavaCallbackDef`. +GlueGen configuration snippet with the added option attribute for the `Callback-KeyClass` in directive `JavaCallbackDef`. ``` -JavaCallbackDef alBufferCallback1 0 ALBUFFERCALLBACKTYPESOFT 1 com.jogamp.gluegen.test.junit.generation.Test4JavaCallback.CustomAlBufferCallback1Key +JavaCallbackDef alBufferCallback1 0 ALBUFFERCALLBACKTYPESOFT 1 ALCcontext 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)`, +Implementation utilizes a custom `Callback-KeyClass` implementation for `void alBufferCallback1(int buffer, int format, int freq, ALBUFFERCALLBACKTYPESOFT callback, ALCcontext userptr)`, which uses one key, i.e. `buffer`. ``` public static class CustomAlBufferCallback1Key { @@ -1137,7 +1145,8 @@ which uses one key, i.e. `buffer`. ### JavaCallback Example 5b (UserParam part of 2 component-key) -Similar example as example 2a, but having the `UserParam` as part of the 2 component-key. +Similar example as example 2a, but having the `UserParam` as part of the 2 component-key +*and* defining `Callback-UserParamClass` class as `ALCcontext`. C-API Header snipped ``` @@ -1146,21 +1155,21 @@ C-API Header snipped void alEventCallback1(int object /* key */, ALEVENTPROCSOFT callback, void *userParam /* key */); ``` -GlueGen configuration snippet with the added option attribute for the `SetCallback-KeyClass` in directive `JavaCallbackDef`. +GlueGen configuration snippet with the added option attribute for the `Callback-UserParamClass` in directive `JavaCallbackDef`. ``` ArgumentIsPascalString ALEVENTPROCSOFT 3 4 -JavaCallbackDef alEventCallback1 2 ALEVENTPROCSOFT 5 +JavaCallbackDef alEventCallback1 2 ALEVENTPROCSOFT 5 ALCcontext JavaCallbackKey alEventCallback1 0 2 ALEVENTPROCSOFT 1 5 ``` Resulting to the default `KeyClass` ``` - /** Key { int object, java.lang.Object userParam } for <br> <code> void alEventCallback1(int object, ALEVENTPROCSOFT callback, Object userParam)</code> */ + /** Key { int object, ALCcontext userParam } for <br> <code> void alEventCallback1(int object, ALEVENTPROCSOFT callback, ALCcontext userParam)</code> */ public static class AlEventCallback1Key { public final int object; - public final java.lang.Object userParam; - public AlEventCallback1Key(int object, java.lang.Object userParam) { + public final ALCcontext userParam; + public AlEventCallback1Key(int object, ALCcontext userParam) { this.object = object; this.userParam = userParam; } @@ -1238,7 +1247,7 @@ leading to the following interface public T2_CallbackFunc11 getMessageCallback11a(MessageCallback11aKey key); /** Returns user-param mapped to Key { long id } for <br> <code> void MessageCallback11a(long id, T2_CallbackFunc11 cbFunc, T2_Callback11UserType usrParam)</code> */ - public Object getMessageCallback11aUserParam(MessageCallback11aKey key); + public T2_Callback11UserType getMessageCallback11aUserParam(MessageCallback11aKey key); /** Releases all callback data mapped via Key { long id } skipping toolkit API. Favor passing `null` callback ref to <br> <code> void MessageCallback11a(long id, T2_CallbackFunc11 cbFunc, T2_Callback11UserType usrParam)</code> */ public int releaseAllMessageCallback11a(); @@ -1250,7 +1259,7 @@ leading to the following interface public void MessageCallback11a(long id, T2_CallbackFunc11 cbFunc, T2_Callback11UserType usrParam); /** Entry point (through function pointer) to C language function: <br> <code>void MessageCallback11aInject(size_t id, long val)</code><br> */ - public void MessageCallback11aInject(long id, long val); + public void MessageCallback11aInject(long id, long val); ``` ### JavaCallback Example 11b (*Heterogeneous Pointer/Struct Type*) @@ -1318,7 +1327,7 @@ leading to the following interface public void MessageCallback11b(long id, T2_CallbackFunc11 cbFunc, long Data); /** Entry point (through function pointer) to C language function: <br> <code>void MessageCallback11bInject(size_t id, long val)</code><br> */ - public void MessageCallback11bInject(long id, long val); + public void MessageCallback11bInject(long id, long val); ``` *TODO: Enhance documentation* diff --git a/src/java/com/jogamp/gluegen/JavaCallbackEmitter.java b/src/java/com/jogamp/gluegen/JavaCallbackEmitter.java index 05192d3..dbd38aa 100644 --- a/src/java/com/jogamp/gluegen/JavaCallbackEmitter.java +++ b/src/java/com/jogamp/gluegen/JavaCallbackEmitter.java @@ -55,6 +55,7 @@ public final class JavaCallbackEmitter { final boolean userParamIsMappedToID; final String userParamIDMapInstanceName; + final String userParamClassName; final boolean customKeyClass; final String KeyClassName; final boolean useDataMap; @@ -98,9 +99,17 @@ public final class JavaCallbackEmitter { userParamIDMapInstanceName = null; } - if( null != javaCallback.setFuncKeyClassName ) { + if( userParamIsCompound ) { + userParamClassName = setFuncUserParamTypeName; + } else if( null != javaCallback.userParamClassName ) { + userParamClassName = javaCallback.userParamClassName; + } else { + userParamClassName = "Object"; + } + + if( null != javaCallback.customKeyClassName ) { customKeyClass = true;; - KeyClassName = javaCallback.setFuncKeyClassName; + KeyClassName = javaCallback.customKeyClassName; useDataMap = true; } else { customKeyClass = false; @@ -127,7 +136,7 @@ public final class JavaCallbackEmitter { unit.emitln(" public "+info.cbFuncTypeName+" get"+capIfaceName+"("+KeyClassName+" key);"); unit.emitln(); emitJavaBriefAPIDoc(unit, "Returns user-param ", "mapped to ", "", "for "); - unit.emitln(" public Object get"+capIfaceName+"UserParam("+KeyClassName+" key);"); + unit.emitln(" public "+userParamClassName+" get"+capIfaceName+"UserParam("+KeyClassName+" key);"); unit.emitln(); emitJavaBriefAPIDoc(unit, "Releases all callback data ", "mapped via ", "", "skipping toolkit API. Favor passing `null` callback ref to "); unit.emitln(" public int releaseAll"+capIfaceName+"();"); @@ -143,7 +152,7 @@ public final class JavaCallbackEmitter { unit.emitln(" public "+info.cbFuncTypeName+" get"+capIfaceName+"();"); unit.emitln(); emitJavaBriefAPIDoc(unit, "Returns user-param ", "mapped to ", "", "for "); - unit.emitln(" public Object get"+capIfaceName+"UserParam();"); + unit.emitln(" public "+userParamClassName+" get"+capIfaceName+"UserParam();"); unit.emitln(); emitJavaBriefAPIDoc(unit, "Releases callback data ", "", "", "skipping toolkit API. Favor passing `null` callback ref to "); unit.emitln(" public void release"+capIfaceName+"();"); @@ -181,7 +190,7 @@ public final class JavaCallbackEmitter { unit.emitln(); emitJavaBriefAPIDoc(unit, "Returns user-param ", "mapped to ", "", "for "); - unit.emitln(" public final Object get"+capIfaceName+"UserParam("+KeyClassName+" key) {"); + unit.emitln(" public final "+userParamClassName+" get"+capIfaceName+"UserParam("+KeyClassName+" key) {"); unit.emitln(" synchronized( "+lockInstanceName+" ) {"); unit.emitln(" final "+DataClassName+" value = "+dataMapInstanceName+".get(key);"); unit.emitln(" return null != value ? value.param : null;"); @@ -234,7 +243,7 @@ public final class JavaCallbackEmitter { unit.emitln(); emitJavaBriefAPIDoc(unit, "Returns user-param ", "mapped to ", "", "for "); - unit.emitln(" public final Object get"+capIfaceName+"UserParam() {"); + unit.emitln(" public final "+userParamClassName+" get"+capIfaceName+"UserParam() {"); unit.emitln(" synchronized( "+lockInstanceName+" ) {"); unit.emitln(" final "+DataClassName+" value = "+dataInstanceName+";"); unit.emitln(" return null != value ? value.param : null;"); @@ -524,12 +533,12 @@ public final class JavaCallbackEmitter { unit.emitln(" final "+origUserParamJType[0]+" "+info.cbFuncUserParamName+" = "+origUserParamJType[0]+".derefPointer(nativeUserParam);"); useParamLocal[0] = true; } else if( userParamIsMappedToID && userParamIsKey ) { - unit.emitln(" final Object "+info.cbFuncUserParamName+";"); + unit.emitln(" final "+userParamClassName+" "+info.cbFuncUserParamName+";"); } unit.emitln(" final "+DataClassName+" value;"); unit.emitln(" synchronized( "+lockInstanceName+" ) {"); if( userParamIsMappedToID && userParamIsKey && !mapNativePtrToCompound[0] ) { - unit.emitln(" "+info.cbFuncUserParamName+" = "+userParamIDMapInstanceName+".get(nativeUserParam);"); + unit.emitln(" "+info.cbFuncUserParamName+" = ("+userParamClassName+") "+userParamIDMapInstanceName+".get(nativeUserParam);"); useParamLocal[0] = true; } if( useDataMap ) { diff --git a/src/java/com/jogamp/gluegen/JavaConfiguration.java b/src/java/com/jogamp/gluegen/JavaConfiguration.java index e530e0c..f5242b8 100644 --- a/src/java/com/jogamp/gluegen/JavaConfiguration.java +++ b/src/java/com/jogamp/gluegen/JavaConfiguration.java @@ -192,19 +192,23 @@ public class JavaConfiguration { final String setFuncName; final int setFuncUserParamIdx; // optional final List<Integer> cbFuncKeyIndices = new ArrayList<Integer>(); - final String setFuncKeyClassName; // optional + final String userParamClassName; // optional + final String customKeyClassName; // optional final List<Integer> setFuncKeyIndices = new ArrayList<Integer>(); - JavaCallbackDef(final String cbFuncTypeName, final int cbFuncUserParamIdx, final String setFuncName, final int setFuncUserParamIdx, final String setFuncKeyClassName) { + JavaCallbackDef(final String cbFuncTypeName, final int cbFuncUserParamIdx, final String setFuncName, final int setFuncUserParamIdx, + final String userParamClassName, final String customKeyClassName) { this.cbFuncTypeName = cbFuncTypeName; this.cbFuncUserParamIdx = cbFuncUserParamIdx; this.setFuncName = setFuncName; this.setFuncUserParamIdx = setFuncUserParamIdx; - this.setFuncKeyClassName = setFuncKeyClassName; + this.userParamClassName = userParamClassName; + this.customKeyClassName = customKeyClassName; } @Override public String toString() { - 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); + return String.format("JavaCallbackDef[cbFunc[type %s, userParamIdx %d, keys %s], set[%s, keys %s, userParamIdx %d], Class[UserParam %s, Key %s]]", + cbFuncTypeName, cbFuncUserParamIdx, cbFuncKeyIndices.toString(), setFuncName, setFuncKeyIndices.toString(), setFuncUserParamIdx, + userParamClassName, customKeyClassName); } } private final List<JavaCallbackDef> javaCallbackList = new ArrayList<JavaCallbackDef>(); @@ -1696,13 +1700,26 @@ public class JavaConfiguration { final int setFuncUserParamIdx = Integer.parseInt(tok.nextToken()); final String cbFuncTypeName = tok.nextToken(); final int cbFuncUserParamIdx = Integer.parseInt(tok.nextToken()); - final String cbFuncKeyClassName; + final String userParamClassName; + final String customKeyClassName; if( tok.hasMoreTokens() ) { - cbFuncKeyClassName = tok.nextToken(); + final String s = tok.nextToken(); + if( s.length() == 0 || s.equals("null") ) { + userParamClassName = null; + } else { + userParamClassName = s; + } + if( tok.hasMoreTokens() ) { + customKeyClassName = tok.nextToken(); + } else { + customKeyClassName = null; + } } else { - cbFuncKeyClassName = null; + userParamClassName = null; + customKeyClassName = null; } - final JavaCallbackDef jcd = new JavaCallbackDef(cbFuncTypeName, cbFuncUserParamIdx, setFuncName, setFuncUserParamIdx, cbFuncKeyClassName); + final JavaCallbackDef jcd = new JavaCallbackDef(cbFuncTypeName, cbFuncUserParamIdx, setFuncName, setFuncUserParamIdx, + userParamClassName, customKeyClassName); javaCallbackList.add(jcd); javaCallbackSetFuncToDef.put(setFuncName, jcd); } catch (final NoSuchElementException e) { @@ -2408,15 +2425,17 @@ public class JavaConfiguration { final String setFuncName; final List<Integer> setFuncKeyIndices; - final String setFuncKeyClassName; final int setFuncUserParamIdx; + final String userParamClassName; // optional + final String customKeyClassName; // optional boolean setFuncProcessed; int setFuncCBParamIdx; 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 List<Integer> cbFuncKeyIndices, - final String setFuncName, final int setFuncUserParamIdx, final List<Integer> setFuncKeyIndices, final String setFuncKeyClassName) { + final String setFuncName, final int setFuncUserParamIdx, final List<Integer> setFuncKeyIndices, + final String userParamClassName, final String customKeyClassName) { this.cbFuncTypeName = cbFuncTypeName; this.cbSimpleClazzName = cbSimpleClazzName; this.cbFQClazzName = cbFQClazzName; @@ -2443,8 +2462,9 @@ public class JavaConfiguration { } this.setFuncName = setFuncName; this.setFuncKeyIndices = setFuncKeyIndices; - this.setFuncKeyClassName = setFuncKeyClassName; this.setFuncUserParamIdx = setFuncUserParamIdx; + this.userParamClassName = userParamClassName; + this.customKeyClassName = customKeyClassName; this.setFuncProcessed = false; this.setFuncCBParamIdx = -1; this.keyClassEmitted = false; @@ -2479,11 +2499,11 @@ public class JavaConfiguration { @Override public String toString() { - 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]", + return String.format("JavaCallbackInfo[cbFunc[%s%s, userParam[idx %d, '%s', %s, keys %s], set[%s(ok %b, cbIdx %d, upIdx %d, keys %s], Class[UserParam '%s', Key '%s'], %s]", cbFuncTypeName, staticCBMethodSignature, cbFuncUserParamIdx, cbFuncUserParamName, cbFuncUserParamType.getSignature(null).toString(), cbFuncKeyIndices.toString(), setFuncName, setFuncProcessed, setFuncCBParamIdx, setFuncUserParamIdx, - setFuncKeyIndices.toString(), setFuncKeyClassName, + setFuncKeyIndices.toString(), userParamClassName, customKeyClassName, cbFuncType.toString(cbFuncTypeName, false, true)); } } diff --git a/src/java/com/jogamp/gluegen/JavaEmitter.java b/src/java/com/jogamp/gluegen/JavaEmitter.java index 88cff27..576e9bc 100644 --- a/src/java/com/jogamp/gluegen/JavaEmitter.java +++ b/src/java/com/jogamp/gluegen/JavaEmitter.java @@ -1474,14 +1474,15 @@ public class JavaEmitter implements GlueEmitter { } final JavaCallbackInfo jcbi1 = new JavaCallbackInfo(jcbd.cbFuncTypeName, cbSimpleClazzName, cbFQClazzName, jcbi0.staticCBMethodSignature, funcType, jcbi0.cbFuncBinding, jcbi0.cbFuncUserParamIdx, jcbd.cbFuncKeyIndices, - jcbd.setFuncName, jcbd.setFuncUserParamIdx, jcbd.setFuncKeyIndices, jcbd.setFuncKeyClassName); + jcbd.setFuncName, jcbd.setFuncUserParamIdx, jcbd.setFuncKeyIndices, + jcbd.userParamClassName, jcbd.customKeyClassName); cfg.setFuncToJavaCallbackMap.put(jcbd.setFuncName, jcbi1); LOG.log(INFO, "JavaCallbackInfo: Reusing {0} -> {1}", jcbd.setFuncName, jcbi0); } else { final StringBuilder cbMethodSignature = new StringBuilder(); javaUnit.emitln(" /** JavaCallback interface: "+jcbd.cbFuncTypeName+" -> "+funcType.toString(jcbd.cbFuncTypeName, false, true)+" */"); javaUnit.emitln(" public static interface "+cbSimpleClazzName+" {"); - final List<MethodBinding> mbs = generateFunctionInterfaceCode(javaUnit, funcSym, jcbd.cbFuncUserParamIdx, cbMethodSignature); + final List<MethodBinding> mbs = generateFunctionInterfaceCode(javaUnit, funcSym, jcbd, cbMethodSignature); javaUnit.emitln(" }"); javaUnit.emitln(); if( 1 != mbs.size() ) { @@ -1494,7 +1495,8 @@ public class JavaEmitter implements GlueEmitter { } final JavaCallbackInfo jcbi1 = new JavaCallbackInfo(jcbd.cbFuncTypeName, cbSimpleClazzName, cbFQClazzName, cbMethodSignature.toString(), funcType, cbFuncBinding, jcbd.cbFuncUserParamIdx, jcbd.cbFuncKeyIndices, - jcbd.setFuncName, jcbd.setFuncUserParamIdx, jcbd.setFuncKeyIndices, jcbd.setFuncKeyClassName); + jcbd.setFuncName, jcbd.setFuncUserParamIdx, jcbd.setFuncKeyIndices, + jcbd.userParamClassName, jcbd.customKeyClassName); cfg.setFuncToJavaCallbackMap.put(jcbd.setFuncName, jcbi1); javaCallbackInterfaceMap.put(cbFQClazzName, jcbi1); LOG.log(INFO, "JavaCallbackInfo: Added {0} -> {1}", jcbd.setFuncName, jcbi1); @@ -1502,15 +1504,23 @@ public class JavaEmitter implements GlueEmitter { } private final Map<String, JavaCallbackInfo> javaCallbackInterfaceMap = new HashMap<String, JavaCallbackInfo>(); - private List<MethodBinding> generateFunctionInterfaceCode(final JavaCodeUnit javaUnit, final FunctionSymbol funcSym, final int userParamIdx, final StringBuilder methodSignature) { + private List<MethodBinding> generateFunctionInterfaceCode(final JavaCodeUnit javaUnit, final FunctionSymbol funcSym, final JavaCallbackDef jcbd, final StringBuilder methodSignature) { // Emit method call and associated native code MethodBinding mb = bindFunction(funcSym, true /* forInterface */, machDescJava, null, null); // Replace optional userParam argument 'void*' with Object + final int userParamIdx = jcbd.cbFuncUserParamIdx; if( 0 <= userParamIdx && userParamIdx < mb.getNumArguments() ) { final JavaType t = mb.getJavaArgumentType(userParamIdx); if ( t.isCVoidPointerType() ) { - mb = mb.replaceJavaArgumentType(userParamIdx, JavaType.forObjectClass()); + final JavaType mappedType; + if( null != jcbd.userParamClassName ) { + mappedType = JavaType.createForNamedClass( jcbd.userParamClassName ); + mb = mb.replaceJavaArgumentType(userParamIdx, JavaType.forObjectClass()); + } else { + mappedType = JavaType.forObjectClass(); + } + mb = mb.replaceJavaArgumentType(userParamIdx, mappedType); } } // Produce the method signature @@ -3124,6 +3134,8 @@ public class JavaEmitter implements GlueEmitter { if( cArgType.getTargetType().isVoid() ) { if( jcbi.cbFuncUserParamType.isCompound() ) { mappedType = JavaType.createForClass(long.class); + } else if( null != jcbi.userParamClassName ) { + mappedType = JavaType.createForNamedClass( jcbi.userParamClassName ); } else { mappedType = JavaType.forObjectClass(); } 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 90e01df..09b51c7 100644 --- a/src/junit/com/jogamp/gluegen/test/junit/generation/Test4JavaCallback.java +++ b/src/junit/com/jogamp/gluegen/test/junit/generation/Test4JavaCallback.java @@ -80,6 +80,27 @@ public class Test4JavaCallback extends BaseClass { dynamicLookupHelper = null; } + private static class MyUserParam01 { + final long i; + long j; + 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 T2_CallbackFunc JavaCallback */ @@ -169,17 +190,21 @@ public class Test4JavaCallback extends BaseClass { Assert.assertEquals(1+42+10+404+10, myUserParam01.j); } } - private static class MyUserParam01 { + + public static class ALCcontext { final long i; long j; - public MyUserParam01(final long i) { this.i = i; j=0; } + int buffer; + boolean throwPreAction, throwPostAction; + public ALCcontext(final long i) { this.i = i; j=0; buffer=0; throwPreAction=false; throwPostAction=false; } + public ALCcontext() { this.i = 0; j=0; buffer=0; throwPreAction=false; throwPostAction=false; } @Override public boolean equals(final Object o) { if( this == o ) { return true; } - if( !(o instanceof MyUserParam01) ) { + if( !(o instanceof ALCcontext) ) { return false; } return false; // we require identity! @@ -190,6 +215,7 @@ public class Test4JavaCallback extends BaseClass { } } + /** * Test Bindingtest2 with ALBUFFERCALLBACKTYPESOFT JavaCallback via alBufferCallback1() * using the default AlBufferCallback1Key class. @@ -201,23 +227,21 @@ public class Test4JavaCallback extends BaseClass { 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; - final long res = sampledata + numbytes + myUserParam.i; + public void callback(final int buffer, final ALCcontext context, final int sampledata, final int numbytes) { + final long res = sampledata + numbytes + context.i; id_res[0] = res; - myUserParam.j = res; - myUserParam.buffer = buffer; + context.j = res; + context.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; - final long res = sampledata * numbytes + myUserParam.i; + public void callback(final int buffer, final ALCcontext context, final int sampledata, final int numbytes) { + final long res = sampledata * numbytes + context.i; id_res[0] = res; - myUserParam.j = res; - myUserParam.buffer = buffer; + context.j = res; + context.buffer = buffer; System.err.println("chapter02.myCallback02: buffer "+buffer+", sampledata "+sampledata+", numbytes "+numbytes); } }; @@ -227,26 +251,26 @@ public class Test4JavaCallback extends BaseClass { final AlBufferCallback0Key buffer1Key = new AlBufferCallback0Key(buffer1); final AlBufferCallback0Key buffer2Key = new AlBufferCallback0Key(buffer2); final AlBufferCallback0Key buffer3Key = new AlBufferCallback0Key(buffer3); - final MyUserParam02 myUserParam01 = new MyUserParam02( 1); - final MyUserParam02 myUserParam02 = new MyUserParam02( 2); - Assert.assertEquals( 1, myUserParam01.i); - Assert.assertEquals( 0, myUserParam01.j); - Assert.assertEquals( 0, myUserParam01.buffer); - Assert.assertEquals( 2, myUserParam02.i); - Assert.assertEquals( 0, myUserParam02.j); - Assert.assertEquals( 0, myUserParam02.buffer); + final ALCcontext context01 = new ALCcontext( 1); + final ALCcontext context02 = new ALCcontext( 2); + Assert.assertEquals( 1, context01.i); + Assert.assertEquals( 0, context01.j); + Assert.assertEquals( 0, context01.buffer); + Assert.assertEquals( 2, context02.i); + Assert.assertEquals( 0, context02.j); + Assert.assertEquals( 0, context02.buffer); Assert.assertEquals(false, bt2.isAlBufferCallback0Mapped(buffer1Key)); Assert.assertEquals(false, bt2.isAlBufferCallback0Mapped(buffer2Key)); Assert.assertEquals(false, bt2.isAlBufferCallback0Mapped(buffer3Key)); Assert.assertEquals(0, bt2.getAlBufferCallback0Keys().size()); - // 1st mapping: buffer1 -> myCallback01, myUserParam01 - bt2.alBufferCallback0(buffer1, 0, 0, myCallback01, myUserParam01); + // 1st mapping: buffer1 -> myCallback01, context01 + bt2.alBufferCallback0(buffer1, 0, 0, myCallback01, context01); 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(context01, bt2.getAlBufferCallback0UserParam(buffer1Key)); Assert.assertEquals(null, bt2.getAlBufferCallback0UserParam(buffer2Key)); Assert.assertEquals(null, bt2.getAlBufferCallback0UserParam(buffer3Key)); Assert.assertEquals(myCallback01, bt2.getAlBufferCallback0(buffer1Key)); @@ -260,13 +284,13 @@ public class Test4JavaCallback extends BaseClass { Assert.assertEquals(false, keys.contains(buffer3Key)); } - // 2nd mapping: buffer2 -> myCallback02, myUserParam02 - bt2.alBufferCallback0(buffer2, 0, 0, myCallback02, myUserParam02); + // 2nd mapping: buffer2 -> myCallback02, context02 + bt2.alBufferCallback0(buffer2, 0, 0, myCallback02, context02); Assert.assertEquals(true, bt2.isAlBufferCallback0Mapped(buffer1Key)); Assert.assertEquals(true, bt2.isAlBufferCallback0Mapped(buffer2Key)); Assert.assertEquals(false, bt2.isAlBufferCallback0Mapped(buffer3Key)); - Assert.assertEquals(myUserParam01, bt2.getAlBufferCallback0UserParam(buffer1Key)); - Assert.assertEquals(myUserParam02, bt2.getAlBufferCallback0UserParam(buffer2Key)); + Assert.assertEquals(context01, bt2.getAlBufferCallback0UserParam(buffer1Key)); + Assert.assertEquals(context02, bt2.getAlBufferCallback0UserParam(buffer2Key)); Assert.assertEquals(null, bt2.getAlBufferCallback0UserParam(buffer3Key)); Assert.assertEquals(myCallback01, bt2.getAlBufferCallback0(buffer1Key)); Assert.assertEquals(myCallback02, bt2.getAlBufferCallback0(buffer2Key)); @@ -283,76 +307,76 @@ public class Test4JavaCallback extends BaseClass { final Thread thread = new Thread(new Runnable() { @Override public void run() { - bt2.alBufferCallback0Inject(buffer1, 10, 100); // buffer1 -> myCallback01, myUserParam01 + bt2.alBufferCallback0Inject(buffer1, 10, 100); // buffer1 -> myCallback01, context01 } }); thread.start(); thread.join(); 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); + Assert.assertEquals( 1, context01.i); + Assert.assertEquals(10+100+1, context01.j); + Assert.assertEquals( 1, context01.buffer); + Assert.assertEquals( 2, context02.i); + Assert.assertEquals( 0, context02.j); + Assert.assertEquals( 0, context02.buffer); } { - bt2.alBufferCallback0Inject(buffer2, 10, 100); // buffer2 -> myCallback02, myUserParam02 + bt2.alBufferCallback0Inject(buffer2, 10, 100); // buffer2 -> myCallback02, context02 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); + Assert.assertEquals( 1, context01.i); + Assert.assertEquals(10+100+1, context01.j); + Assert.assertEquals( 1, context01.buffer); + Assert.assertEquals( 2, context02.i); + Assert.assertEquals(10*100+2, context02.j); + Assert.assertEquals( 2, context02.buffer); } - // Switch the callback function for buffer2 -> myCallback01, myUserParam02 - bt2.alBufferCallback0(buffer2, 0, 0, myCallback01, myUserParam02); + // Switch the callback function for buffer2 -> myCallback01, context02 + bt2.alBufferCallback0(buffer2, 0, 0, myCallback01, context02); Assert.assertEquals(true, bt2.isAlBufferCallback0Mapped(buffer1Key)); Assert.assertEquals(true, bt2.isAlBufferCallback0Mapped(buffer2Key)); Assert.assertEquals(false, bt2.isAlBufferCallback0Mapped(buffer3Key)); - Assert.assertEquals(myUserParam01, bt2.getAlBufferCallback0UserParam(buffer1Key)); - Assert.assertEquals(myUserParam02, bt2.getAlBufferCallback0UserParam(buffer2Key)); + Assert.assertEquals(context01, bt2.getAlBufferCallback0UserParam(buffer1Key)); + Assert.assertEquals(context02, bt2.getAlBufferCallback0UserParam(buffer2Key)); Assert.assertEquals(null, bt2.getAlBufferCallback0UserParam(buffer3Key)); Assert.assertEquals(myCallback01, bt2.getAlBufferCallback0(buffer1Key)); Assert.assertEquals(myCallback01, bt2.getAlBufferCallback0(buffer2Key)); Assert.assertEquals(null, bt2.getAlBufferCallback0(buffer3Key)); { - bt2.alBufferCallback0Inject(buffer1, 11, 101); // buffer1 -> myCallback01, myUserParam01 + bt2.alBufferCallback0Inject(buffer1, 11, 101); // buffer1 -> myCallback01, context01 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); + Assert.assertEquals( 1, context01.i); + Assert.assertEquals(11+101+1, context01.j); + Assert.assertEquals( 1, context01.buffer); + Assert.assertEquals( 2, context02.i); + Assert.assertEquals(10*100+2, context02.j); + Assert.assertEquals( 2, context02.buffer); } { final Thread thread = new Thread(new Runnable() { @Override public void run() { - bt2.alBufferCallback0Inject(buffer2, 1, 10); // buffer2 -> myCallback01, myUserParam02 + bt2.alBufferCallback0Inject(buffer2, 1, 10); // buffer2 -> myCallback01, context02 } }); thread.start(); thread.join(); 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); + Assert.assertEquals( 1, context01.i); + Assert.assertEquals(11+101+1, context01.j); + Assert.assertEquals( 1, context01.buffer); + Assert.assertEquals( 2, context02.i); + Assert.assertEquals( 1+ 10+2, context02.j); + Assert.assertEquals( 2, context02.buffer); } // Just release the buffer2 callback and mapped resources - bt2.alBufferCallback0(buffer2, 0, 0, null, myUserParam02); // usrptr is not key, only buffer is key! + bt2.alBufferCallback0(buffer2, 0, 0, null, context02); // usrptr is not key, only buffer is key! Assert.assertEquals(true, bt2.isAlBufferCallback0Mapped(buffer1Key)); Assert.assertEquals(false, bt2.isAlBufferCallback0Mapped(buffer2Key)); Assert.assertEquals(false, bt2.isAlBufferCallback0Mapped(buffer3Key)); - Assert.assertEquals(myUserParam01, bt2.getAlBufferCallback0UserParam(buffer1Key)); + Assert.assertEquals(context01, bt2.getAlBufferCallback0UserParam(buffer1Key)); Assert.assertEquals(null, bt2.getAlBufferCallback0UserParam(buffer2Key)); Assert.assertEquals(null, bt2.getAlBufferCallback0UserParam(buffer3Key)); Assert.assertEquals(myCallback01, bt2.getAlBufferCallback0(buffer1Key)); @@ -366,13 +390,13 @@ public class Test4JavaCallback extends BaseClass { Assert.assertEquals(false, keys.contains(buffer3Key)); } - // Switch the callback function for buffer2 -> myCallback01, myUserParam02 + // Switch the callback function for buffer2 -> myCallback01, context02 { // 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(context01, bt2.getAlBufferCallback0UserParam(buffer1Key)); Assert.assertEquals(null, bt2.getAlBufferCallback0UserParam(buffer2Key)); Assert.assertEquals(null, bt2.getAlBufferCallback0UserParam(buffer3Key)); Assert.assertEquals(myCallback01, bt2.getAlBufferCallback0(buffer1Key)); @@ -380,13 +404,13 @@ public class Test4JavaCallback extends BaseClass { Assert.assertEquals(null, bt2.getAlBufferCallback0(buffer3Key)); Assert.assertEquals(1, bt2.getAlBufferCallback0Keys().size()); } - bt2.alBufferCallback0(buffer1, 0, 0, myCallback02, myUserParam02); + bt2.alBufferCallback0(buffer1, 0, 0, myCallback02, context02); { // 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(context02, bt2.getAlBufferCallback0UserParam(buffer1Key)); Assert.assertEquals(null, bt2.getAlBufferCallback0UserParam(buffer2Key)); Assert.assertEquals(null, bt2.getAlBufferCallback0UserParam(buffer3Key)); Assert.assertEquals(myCallback02, bt2.getAlBufferCallback0(buffer1Key)); @@ -394,18 +418,18 @@ public class Test4JavaCallback extends BaseClass { 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 + context01.j = 0; + context01.buffer = 0; + context02.j = 0; + context02.buffer = 0; + bt2.alBufferCallback0Inject(buffer1, 2, 10); // buffer1 -> myCallback01, context01 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); + Assert.assertEquals( 1, context01.i); + Assert.assertEquals( 0, context01.j); + Assert.assertEquals( 0, context01.buffer); + Assert.assertEquals( 2, context02.i); + Assert.assertEquals( 2*10+2, context02.j); + Assert.assertEquals( 1, context02.buffer); } // Just release the buffer1 callback and mapped resources @@ -429,18 +453,18 @@ public class Test4JavaCallback extends BaseClass { { id_res[0] = 0; - myUserParam01.j = 0; - myUserParam01.buffer = 0; - myUserParam02.j = 0; - myUserParam02.buffer = 0; + context01.j = 0; + context01.buffer = 0; + context02.j = 0; + context02.buffer = 0; bt2.alBufferCallback0Inject(buffer2, 1, 10); // unmapped, no change in data Assert.assertEquals( 0, 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( 0, myUserParam02.j); - Assert.assertEquals( 0, myUserParam02.buffer); + Assert.assertEquals( 1, context01.i); + Assert.assertEquals( 0, context01.j); + Assert.assertEquals( 0, context01.buffer); + Assert.assertEquals( 2, context02.i); + Assert.assertEquals( 0, context02.j); + Assert.assertEquals( 0, context02.buffer); } } @@ -455,23 +479,21 @@ public class Test4JavaCallback extends BaseClass { 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; - final long res = sampledata + numbytes + myUserParam.i; + public void callback(final int buffer, final ALCcontext context, final int sampledata, final int numbytes) { + final long res = sampledata + numbytes + context.i; id_res[0] = res; - myUserParam.j = res;; - myUserParam.buffer = buffer; + context.j = res;; + context.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; - final long res = sampledata * numbytes + myUserParam.i; + public void callback(final int buffer, final ALCcontext context, final int sampledata, final int numbytes) { + final long res = sampledata * numbytes + context.i; id_res[0] = res; - myUserParam.j = res; - myUserParam.buffer = buffer; + context.j = res; + context.buffer = buffer; System.err.println("chapter03.myCallback02: buffer "+buffer+", sampledata "+sampledata+", numbytes "+numbytes); } }; @@ -481,26 +503,26 @@ public class Test4JavaCallback extends BaseClass { final CustomAlBufferCallback1Key buffer1Key = new CustomAlBufferCallback1Key(buffer1); final CustomAlBufferCallback1Key buffer2Key = new CustomAlBufferCallback1Key(buffer2); final CustomAlBufferCallback1Key buffer3Key = new CustomAlBufferCallback1Key(buffer3); - final MyUserParam02 myUserParam01 = new MyUserParam02( 1); - final MyUserParam02 myUserParam02 = new MyUserParam02( 2); - Assert.assertEquals( 1, myUserParam01.i); - 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); + final ALCcontext context01 = new ALCcontext( 1); + final ALCcontext context02 = new ALCcontext( 2); + Assert.assertEquals( 1, context01.i); + Assert.assertEquals( 0, context01.j); + Assert.assertEquals( 0, context01.buffer); + Assert.assertEquals( 2, context02.i); + Assert.assertEquals( 0, context02.j); + Assert.assertEquals( 0, context02.buffer); Assert.assertEquals(false, bt2.isAlBufferCallback1Mapped(buffer1Key)); Assert.assertEquals(false, bt2.isAlBufferCallback1Mapped(buffer2Key)); Assert.assertEquals(false, bt2.isAlBufferCallback1Mapped(buffer3Key)); Assert.assertEquals(0, bt2.getAlBufferCallback1Keys().size()); - // 1st mapping: buffer1 -> myCallback01, myUserParam01 - bt2.alBufferCallback1(myUserParam01, buffer1, 0, 0, myCallback01); + // 1st mapping: buffer1 -> myCallback01, context01 + bt2.alBufferCallback1(context01, buffer1, 0, 0, myCallback01); Assert.assertEquals(true, bt2.isAlBufferCallback1Mapped(buffer1Key)); Assert.assertEquals(false, bt2.isAlBufferCallback1Mapped(buffer2Key)); Assert.assertEquals(false, bt2.isAlBufferCallback1Mapped(buffer3Key)); - Assert.assertEquals(myUserParam01, bt2.getAlBufferCallback1UserParam(buffer1Key)); + Assert.assertEquals(context01, bt2.getAlBufferCallback1UserParam(buffer1Key)); Assert.assertEquals(null, bt2.getAlBufferCallback1UserParam(buffer2Key)); Assert.assertEquals(null, bt2.getAlBufferCallback1UserParam(buffer3Key)); Assert.assertEquals(myCallback01, bt2.getAlBufferCallback1(buffer1Key)); @@ -514,13 +536,13 @@ public class Test4JavaCallback extends BaseClass { Assert.assertEquals(false, keys.contains(buffer3Key)); } - // 2nd mapping: buffer2 -> myCallback02, myUserParam02 - bt2.alBufferCallback1(myUserParam02, buffer2, 0, 0, myCallback02); + // 2nd mapping: buffer2 -> myCallback02, context02 + bt2.alBufferCallback1(context02, buffer2, 0, 0, myCallback02); Assert.assertEquals(true, bt2.isAlBufferCallback1Mapped(buffer1Key)); Assert.assertEquals(true, bt2.isAlBufferCallback1Mapped(buffer2Key)); Assert.assertEquals(false, bt2.isAlBufferCallback1Mapped(buffer3Key)); - Assert.assertEquals(myUserParam01, bt2.getAlBufferCallback1UserParam(buffer1Key)); - Assert.assertEquals(myUserParam02, bt2.getAlBufferCallback1UserParam(buffer2Key)); + Assert.assertEquals(context01, bt2.getAlBufferCallback1UserParam(buffer1Key)); + Assert.assertEquals(context02, bt2.getAlBufferCallback1UserParam(buffer2Key)); Assert.assertEquals(null, bt2.getAlBufferCallback1UserParam(buffer3Key)); Assert.assertEquals(myCallback01, bt2.getAlBufferCallback1(buffer1Key)); Assert.assertEquals(myCallback02, bt2.getAlBufferCallback1(buffer2Key)); @@ -534,40 +556,40 @@ public class Test4JavaCallback extends BaseClass { } { - bt2.alBufferCallback1Inject(buffer1, 10, 100); // buffer1 -> myCallback01, myUserParam01 + bt2.alBufferCallback1Inject(buffer1, 10, 100); // buffer1 -> myCallback01, context01 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); + Assert.assertEquals( 1, context01.i); + Assert.assertEquals(10+100+1, context01.j); + Assert.assertEquals( 1, context01.buffer); + Assert.assertEquals( 2, context02.i); + Assert.assertEquals( 0, context02.j); + Assert.assertEquals( 0, context02.buffer); } { final Thread thread = new Thread(new Runnable() { @Override public void run() { - bt2.alBufferCallback1Inject(buffer2, 10, 100); // buffer2 -> myCallback02, myUserParam02 + bt2.alBufferCallback1Inject(buffer2, 10, 100); // buffer2 -> myCallback02, context02 } }); thread.start(); thread.join(); 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); + Assert.assertEquals( 1, context01.i); + Assert.assertEquals(10+100+1, context01.j); + Assert.assertEquals( 1, context01.buffer); + Assert.assertEquals( 2, context02.i); + Assert.assertEquals(10*100+2, context02.j); + Assert.assertEquals( 2, context02.buffer); } - // Switch the callback function for buffer2 -> myCallback01, myUserParam02 - bt2.alBufferCallback1(myUserParam02, buffer2, 0, 0, myCallback01); + // Switch the callback function for buffer2 -> myCallback01, context02 + bt2.alBufferCallback1(context02, buffer2, 0, 0, myCallback01); Assert.assertEquals(true, bt2.isAlBufferCallback1Mapped(buffer1Key)); Assert.assertEquals(true, bt2.isAlBufferCallback1Mapped(buffer2Key)); Assert.assertEquals(false, bt2.isAlBufferCallback1Mapped(buffer3Key)); - Assert.assertEquals(myUserParam01, bt2.getAlBufferCallback1UserParam(buffer1Key)); - Assert.assertEquals(myUserParam02, bt2.getAlBufferCallback1UserParam(buffer2Key)); + Assert.assertEquals(context01, bt2.getAlBufferCallback1UserParam(buffer1Key)); + Assert.assertEquals(context02, bt2.getAlBufferCallback1UserParam(buffer2Key)); Assert.assertEquals(null, bt2.getAlBufferCallback1UserParam(buffer3Key)); Assert.assertEquals(myCallback01, bt2.getAlBufferCallback1(buffer1Key)); Assert.assertEquals(myCallback01, bt2.getAlBufferCallback1(buffer2Key)); @@ -577,36 +599,36 @@ public class Test4JavaCallback extends BaseClass { final Thread thread = new Thread(new Runnable() { @Override public void run() { - bt2.alBufferCallback1Inject(buffer1, 11, 101); // buffer1 -> myCallback01, myUserParam01 + bt2.alBufferCallback1Inject(buffer1, 11, 101); // buffer1 -> myCallback01, context01 } }); thread.start(); thread.join(); 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); + Assert.assertEquals( 1, context01.i); + Assert.assertEquals(11+101+1, context01.j); + Assert.assertEquals( 1, context01.buffer); + Assert.assertEquals( 2, context02.i); + Assert.assertEquals(10*100+2, context02.j); + Assert.assertEquals( 2, context02.buffer); } { - bt2.alBufferCallback1Inject(buffer2, 1, 10); // buffer2 -> myCallback01, myUserParam02 + bt2.alBufferCallback1Inject(buffer2, 1, 10); // buffer2 -> myCallback01, context02 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); + Assert.assertEquals( 1, context01.i); + Assert.assertEquals(11+101+1, context01.j); + Assert.assertEquals( 1, context01.buffer); + Assert.assertEquals( 2, context02.i); + Assert.assertEquals( 1+ 10+2, context02.j); + Assert.assertEquals( 2, context02.buffer); } // Just release the buffer2 callback and mapped resources - bt2.alBufferCallback1(myUserParam02, buffer2, 0, 0, null); // usrptr is not key, only buffer is key! + bt2.alBufferCallback1(context02, 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)); - Assert.assertEquals(myUserParam01, bt2.getAlBufferCallback1UserParam(buffer1Key)); + Assert.assertEquals(context01, bt2.getAlBufferCallback1UserParam(buffer1Key)); Assert.assertEquals(null, bt2.getAlBufferCallback1UserParam(buffer2Key)); Assert.assertEquals(null, bt2.getAlBufferCallback1UserParam(buffer3Key)); Assert.assertEquals(myCallback01, bt2.getAlBufferCallback1(buffer1Key)); @@ -642,34 +664,12 @@ public class Test4JavaCallback extends BaseClass { { 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; - boolean throwPreAction, throwPostAction; - public MyUserParam02(final long i) { this.i = i; j=0; buffer=0; throwPreAction=false; throwPostAction=false; } - - @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! + Assert.assertEquals( 1, context01.i); + Assert.assertEquals(11+101+1, context01.j); + Assert.assertEquals( 1, context01.buffer); + Assert.assertEquals( 2, context02.i); + Assert.assertEquals( 1+ 10+2, context02.j); + Assert.assertEquals( 2, context02.buffer); } } @@ -684,38 +684,36 @@ public class Test4JavaCallback extends BaseClass { 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; - if( myUserParam.throwPreAction ) { - myUserParam.throwPreAction = false; + public void callback(final int buffer, final ALCcontext context, final int sampledata, final int numbytes) { + if( context.throwPreAction ) { + context.throwPreAction = false; throw new RuntimeException("Exception test.pre: chapter04.myCallback01"); } - final long res = sampledata + numbytes + myUserParam.i; + final long res = sampledata + numbytes + context.i; id_res[0] = res; - myUserParam.j = res; - myUserParam.buffer = buffer; + context.j = res; + context.buffer = buffer; System.err.println("chapter04.myCallback01: buffer "+buffer+", sampledata "+sampledata+", numbytes "+numbytes); - if( myUserParam.throwPostAction ) { - myUserParam.throwPostAction = false; + if( context.throwPostAction ) { + context.throwPostAction = false; throw new RuntimeException("Exception test.post: chapter04.myCallback01"); } } }; 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; - if( myUserParam.throwPreAction ) { - myUserParam.throwPreAction = false; + public void callback(final int buffer, final ALCcontext context, final int sampledata, final int numbytes) { + if( context.throwPreAction ) { + context.throwPreAction = false; throw new RuntimeException("Exception test.pre: chapter04.myCallback02"); } - final long res = sampledata * numbytes + myUserParam.i; + final long res = sampledata * numbytes + context.i; id_res[0] = res; - myUserParam.j = res; - myUserParam.buffer = buffer; + context.j = res; + context.buffer = buffer; System.err.println("chapter04.myCallback02: buffer "+buffer+", sampledata "+sampledata+", numbytes "+numbytes); - if( myUserParam.throwPostAction ) { - myUserParam.throwPostAction = false; + if( context.throwPostAction ) { + context.throwPostAction = false; throw new RuntimeException("Exception test.post: chapter04.myCallback02"); } } @@ -726,26 +724,26 @@ public class Test4JavaCallback extends BaseClass { final AlBufferCallback0Key buffer1Key = new AlBufferCallback0Key(buffer1); final AlBufferCallback0Key buffer2Key = new AlBufferCallback0Key(buffer2); final AlBufferCallback0Key buffer3Key = new AlBufferCallback0Key(buffer3); - final MyUserParam02 myUserParam01 = new MyUserParam02( 1); - final MyUserParam02 myUserParam02 = new MyUserParam02( 2); - Assert.assertEquals( 1, myUserParam01.i); - Assert.assertEquals( 0, myUserParam01.j); - Assert.assertEquals( 0, myUserParam01.buffer); - Assert.assertEquals( 2, myUserParam02.i); - Assert.assertEquals( 0, myUserParam02.j); - Assert.assertEquals( 0, myUserParam02.buffer); + final ALCcontext context01 = new ALCcontext( 1); + final ALCcontext context02 = new ALCcontext( 2); + Assert.assertEquals( 1, context01.i); + Assert.assertEquals( 0, context01.j); + Assert.assertEquals( 0, context01.buffer); + Assert.assertEquals( 2, context02.i); + Assert.assertEquals( 0, context02.j); + Assert.assertEquals( 0, context02.buffer); Assert.assertEquals(false, bt2.isAlBufferCallback0Mapped(buffer1Key)); Assert.assertEquals(false, bt2.isAlBufferCallback0Mapped(buffer2Key)); Assert.assertEquals(false, bt2.isAlBufferCallback0Mapped(buffer3Key)); Assert.assertEquals(0, bt2.getAlBufferCallback0Keys().size()); - // 1st mapping: buffer1 -> myCallback01, myUserParam01 - bt2.alBufferCallback0(buffer1, 0, 0, myCallback01, myUserParam01); + // 1st mapping: buffer1 -> myCallback01, context01 + bt2.alBufferCallback0(buffer1, 0, 0, myCallback01, context01); 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(context01, bt2.getAlBufferCallback0UserParam(buffer1Key)); Assert.assertEquals(null, bt2.getAlBufferCallback0UserParam(buffer2Key)); Assert.assertEquals(null, bt2.getAlBufferCallback0UserParam(buffer3Key)); Assert.assertEquals(myCallback01, bt2.getAlBufferCallback0(buffer1Key)); @@ -759,13 +757,13 @@ public class Test4JavaCallback extends BaseClass { Assert.assertEquals(false, keys.contains(buffer3Key)); } - // 2nd mapping: buffer2 -> myCallback02, myUserParam02 - bt2.alBufferCallback0(buffer2, 0, 0, myCallback02, myUserParam02); + // 2nd mapping: buffer2 -> myCallback02, context02 + bt2.alBufferCallback0(buffer2, 0, 0, myCallback02, context02); Assert.assertEquals(true, bt2.isAlBufferCallback0Mapped(buffer1Key)); Assert.assertEquals(true, bt2.isAlBufferCallback0Mapped(buffer2Key)); Assert.assertEquals(false, bt2.isAlBufferCallback0Mapped(buffer3Key)); - Assert.assertEquals(myUserParam01, bt2.getAlBufferCallback0UserParam(buffer1Key)); - Assert.assertEquals(myUserParam02, bt2.getAlBufferCallback0UserParam(buffer2Key)); + Assert.assertEquals(context01, bt2.getAlBufferCallback0UserParam(buffer1Key)); + Assert.assertEquals(context02, bt2.getAlBufferCallback0UserParam(buffer2Key)); Assert.assertEquals(null, bt2.getAlBufferCallback0UserParam(buffer3Key)); Assert.assertEquals(myCallback01, bt2.getAlBufferCallback0(buffer1Key)); Assert.assertEquals(myCallback02, bt2.getAlBufferCallback0(buffer2Key)); @@ -782,75 +780,75 @@ public class Test4JavaCallback extends BaseClass { // Continuous program flow id_res[0] = -1; { - myUserParam01.throwPostAction = true; - bt2.alBufferCallback0Inject(buffer1, 10, 100); // buffer1 -> myCallback01, myUserParam01 + context01.throwPostAction = true; + bt2.alBufferCallback0Inject(buffer1, 10, 100); // buffer1 -> myCallback01, context01 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); + Assert.assertEquals( 1, context01.i); + Assert.assertEquals(10+100+1, context01.j); + Assert.assertEquals( 1, context01.buffer); + Assert.assertEquals( 2, context02.i); + Assert.assertEquals( 0, context02.j); + Assert.assertEquals( 0, context02.buffer); } { - myUserParam02.throwPostAction = true; + context02.throwPostAction = true; final Thread thread = new Thread(new Runnable() { @Override public void run() { - bt2.alBufferCallback0Inject(buffer2, 10, 100); // buffer2 -> myCallback02, myUserParam02 + bt2.alBufferCallback0Inject(buffer2, 10, 100); // buffer2 -> myCallback02, context02 } }); thread.start(); thread.join(); 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); + Assert.assertEquals( 1, context01.i); + Assert.assertEquals(10+100+1, context01.j); + Assert.assertEquals( 1, context01.buffer); + Assert.assertEquals( 2, context02.i); + Assert.assertEquals(10*100+2, context02.j); + Assert.assertEquals( 2, context02.buffer); } // Exception text pre action, i.e. result NOT as expected (unchanged) // Continuous program flow id_res[0] = -1; { - myUserParam01.throwPreAction = true; - bt2.alBufferCallback0Inject(buffer1, 20, 200); // buffer1 -> myCallback01, myUserParam01 + context01.throwPreAction = true; + bt2.alBufferCallback0Inject(buffer1, 20, 200); // buffer1 -> myCallback01, context01 Assert.assertEquals( -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(10*100+2, myUserParam02.j); - Assert.assertEquals( 2, myUserParam02.buffer); + Assert.assertEquals( 1, context01.i); + Assert.assertEquals(10+100+1, context01.j); + Assert.assertEquals( 1, context01.buffer); + Assert.assertEquals( 2, context02.i); + Assert.assertEquals(10*100+2, context02.j); + Assert.assertEquals( 2, context02.buffer); } { - myUserParam02.throwPreAction = true; + context02.throwPreAction = true; final Thread thread = new Thread(new Runnable() { @Override public void run() { - bt2.alBufferCallback0Inject(buffer2, 20, 200); // buffer2 -> myCallback02, myUserParam02 + bt2.alBufferCallback0Inject(buffer2, 20, 200); // buffer2 -> myCallback02, context02 } }); thread.start(); thread.join(); Assert.assertEquals( -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(10*100+2, myUserParam02.j); - Assert.assertEquals( 2, myUserParam02.buffer); + Assert.assertEquals( 1, context01.i); + Assert.assertEquals(10+100+1, context01.j); + Assert.assertEquals( 1, context01.buffer); + Assert.assertEquals( 2, context02.i); + Assert.assertEquals(10*100+2, context02.j); + Assert.assertEquals( 2, context02.buffer); } // Just release the buffer2 callback and mapped resources bt2.releaseAlBufferCallback0(buffer2Key); - // bt2.alBufferCallback0(buffer2, 0, 0, null, myUserParam02); // usrptr is not key, only buffer is key! + // bt2.alBufferCallback0(buffer2, 0, 0, null, context02); // usrptr is not key, only buffer is key! Assert.assertEquals(true, bt2.isAlBufferCallback0Mapped(buffer1Key)); Assert.assertEquals(false, bt2.isAlBufferCallback0Mapped(buffer2Key)); Assert.assertEquals(false, bt2.isAlBufferCallback0Mapped(buffer3Key)); - Assert.assertEquals(myUserParam01, bt2.getAlBufferCallback0UserParam(buffer1Key)); + Assert.assertEquals(context01, bt2.getAlBufferCallback0UserParam(buffer1Key)); Assert.assertEquals(null, bt2.getAlBufferCallback0UserParam(buffer2Key)); Assert.assertEquals(null, bt2.getAlBufferCallback0UserParam(buffer3Key)); Assert.assertEquals(myCallback01, bt2.getAlBufferCallback0(buffer1Key)); @@ -897,12 +895,12 @@ public class Test4JavaCallback extends BaseClass { id_res[0] = -1; bt2.alBufferCallback0Inject(buffer2, 1, 10); Assert.assertEquals( -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(10*100+2, myUserParam02.j); - Assert.assertEquals( 2, myUserParam02.buffer); + Assert.assertEquals( 1, context01.i); + Assert.assertEquals(10+100+1, context01.j); + Assert.assertEquals( 1, context01.buffer); + Assert.assertEquals( 2, context02.i); + Assert.assertEquals(10*100+2, context02.j); + Assert.assertEquals( 2, context02.buffer); } public static class CustomAlBufferCallback1Key { @@ -943,30 +941,30 @@ public class Test4JavaCallback extends BaseClass { 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) { + public void callback(final int eventType, final int object, final int param, final int length, final String message, final ALCcontext context) { 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))); + Integer.toHexString(System.identityHashCode(context))); } }; 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) { + public void callback(final int eventType, final int object, final int param, final int length, final String message, final ALCcontext context) { 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))); + Integer.toHexString(System.identityHashCode(context))); } }; - final Object myUserParam01 = new Object(); - final Object myUserParam02 = new Object(); - final AlEventCallback0Key myKey01 = new AlEventCallback0Key(myUserParam01); - final AlEventCallback0Key myKey02 = new AlEventCallback0Key(myUserParam02); + final ALCcontext context01 = new ALCcontext(); + final ALCcontext context02 = new ALCcontext(); + final AlEventCallback0Key myKey01 = new AlEventCallback0Key(context01); + final AlEventCallback0Key myKey02 = new AlEventCallback0Key(context02); Assert.assertEquals(false, bt2.isAlEventCallback0Mapped(myKey01)); Assert.assertEquals(false, bt2.isAlEventCallback0Mapped(myKey02)); - bt2.alEventCallback0(myCallback01, myUserParam01); + bt2.alEventCallback0(myCallback01, context01); Assert.assertEquals(true, bt2.isAlEventCallback0Mapped(myKey01)); Assert.assertEquals(false, bt2.isAlEventCallback0Mapped(myKey02)); { @@ -984,7 +982,7 @@ public class Test4JavaCallback extends BaseClass { final String msgNo1 = "First message"; id_res[0] = -1; msg_res[0] = null; - bt2.alEventCallback0Inject(myUserParam01, 0, 1, 0, msgNo1); + bt2.alEventCallback0Inject(context01, 0, 1, 0, msgNo1); Assert.assertEquals( 1, id_res[0]); Assert.assertEquals(msgNo1, msg_res[0]); } @@ -992,19 +990,19 @@ public class Test4JavaCallback extends BaseClass { final String msgNo2 = "Second message"; id_res[0] = -1; msg_res[0] = null; - bt2.alEventCallback0Inject(myUserParam02, 0, 2, 0, msgNo2); + bt2.alEventCallback0Inject(context02, 0, 2, 0, msgNo2); Assert.assertEquals( -1, id_res[0]); Assert.assertEquals( null, msg_res[0]); - bt2.alEventCallback0Inject(myUserParam01, 0, 2, 0, msgNo2); + bt2.alEventCallback0Inject(context01, 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); + // The previously mapped myCallback01 (context01) gets released + // and remapped to myCallback02 + ( context01 )(key) + bt2.alEventCallback0(myCallback02, context01); Assert.assertEquals(true, bt2.isAlEventCallback0Mapped(myKey01)); Assert.assertEquals(false, bt2.isAlEventCallback0Mapped(myKey02)); { @@ -1020,22 +1018,22 @@ public class Test4JavaCallback extends BaseClass { final String msgNo3 = "Third message"; id_res[0] = -1; msg_res[0] = null; - bt2.alEventCallback0Inject(myUserParam02, 0, 3, 0, msgNo3); + bt2.alEventCallback0Inject(context02, 0, 3, 0, msgNo3); Assert.assertEquals( -1, id_res[0]); Assert.assertEquals( null, msg_res[0]); - bt2.alEventCallback0Inject(myUserParam01, 0, 3, 0, msgNo3); + bt2.alEventCallback0Inject(context01, 0, 3, 0, msgNo3); Assert.assertEquals( 3000, id_res[0]); Assert.assertEquals( msgNo3, msg_res[0]); } // Fake release (wrong key) - bt2.alEventCallback0(null, myUserParam02); + bt2.alEventCallback0(null, context02); Assert.assertEquals(true, bt2.isAlEventCallback0Mapped(myKey01)); Assert.assertEquals(false, bt2.isAlEventCallback0Mapped(myKey02)); - // Just release the callback and mapped myUserParam01 - bt2.alEventCallback0(null, myUserParam01); + // Just release the callback and mapped context01 + bt2.alEventCallback0(null, context01); Assert.assertEquals(false, bt2.isAlEventCallback0Mapped(myKey01)); Assert.assertEquals(false, bt2.isAlEventCallback0Mapped(myKey02)); Assert.assertEquals(0, bt2.getAlEventCallback0Keys().size()); @@ -1044,11 +1042,11 @@ public class Test4JavaCallback extends BaseClass { final String msgNo4 = "Forth message"; id_res[0] = -1; msg_res[0] = null; - bt2.alEventCallback0Inject(myUserParam01, 0, 4, 0, msgNo4); + bt2.alEventCallback0Inject(context01, 0, 4, 0, msgNo4); Assert.assertEquals( -1, id_res[0]); Assert.assertEquals( null, msg_res[0]); - bt2.alEventCallback0Inject(myUserParam02, 0, 4, 0, msgNo4); + bt2.alEventCallback0Inject(context02, 0, 4, 0, msgNo4); Assert.assertEquals( -1, id_res[0]); Assert.assertEquals( null, msg_res[0]); } @@ -1066,30 +1064,30 @@ public class Test4JavaCallback extends BaseClass { 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) { + public void callback(final int eventType, final int object, final int param, final int length, final String message, final ALCcontext context) { 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))); + Integer.toHexString(System.identityHashCode(context))); } }; 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) { + public void callback(final int eventType, final int object, final int param, final int length, final String message, final ALCcontext context) { 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))); + Integer.toHexString(System.identityHashCode(context))); } }; - final Object myUserParam01 = new Object(); - final Object myUserParam02 = new Object(); - final AlEventCallback1Key myKey01 = new AlEventCallback1Key(1, myUserParam01); - final AlEventCallback1Key myKey02 = new AlEventCallback1Key(2, myUserParam02); + final ALCcontext context01 = new ALCcontext(); + final ALCcontext context02 = new ALCcontext(); + final AlEventCallback1Key myKey01 = new AlEventCallback1Key(1, context01); + final AlEventCallback1Key myKey02 = new AlEventCallback1Key(2, context02); Assert.assertEquals(false, bt2.isAlEventCallback1Mapped(myKey01)); Assert.assertEquals(false, bt2.isAlEventCallback1Mapped(myKey02)); - bt2.alEventCallback1(1, myCallback01, myUserParam01); + bt2.alEventCallback1(1, myCallback01, context01); Assert.assertEquals(true, bt2.isAlEventCallback1Mapped(myKey01)); Assert.assertEquals(false, bt2.isAlEventCallback1Mapped(myKey02)); { @@ -1107,7 +1105,7 @@ public class Test4JavaCallback extends BaseClass { final String msgNo1 = "First message"; id_res[0] = -1; msg_res[0] = null; - bt2.alEventCallback1Inject(myUserParam01, 0, 1, 0, msgNo1); + bt2.alEventCallback1Inject(context01, 0, 1, 0, msgNo1); Assert.assertEquals( 1, id_res[0]); Assert.assertEquals(msgNo1, msg_res[0]); } @@ -1115,23 +1113,23 @@ public class Test4JavaCallback extends BaseClass { final String msgNo2 = "Second message"; id_res[0] = -1; msg_res[0] = null; - bt2.alEventCallback1Inject(myUserParam02, 0, 2, 0, msgNo2); + bt2.alEventCallback1Inject(context02, 0, 2, 0, msgNo2); Assert.assertEquals( -1, id_res[0]); Assert.assertEquals( null, msg_res[0]); - bt2.alEventCallback1Inject(myUserParam01, 0, 2, 0, msgNo2); + bt2.alEventCallback1Inject(context01, 0, 2, 0, msgNo2); Assert.assertEquals( -1, id_res[0]); Assert.assertEquals( null, msg_res[0]); - bt2.alEventCallback1Inject(myUserParam01, 0, 1, 0, msgNo2); + bt2.alEventCallback1Inject(context01, 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); + // The previously mapped myCallback01 (1, context01) gets released + // and remapped to myCallback02 + ( 1, context01 )(key) + bt2.alEventCallback1(1, myCallback02, context01); Assert.assertEquals(true, bt2.isAlEventCallback1Mapped(myKey01)); Assert.assertEquals(false, bt2.isAlEventCallback1Mapped(myKey02)); { @@ -1147,30 +1145,30 @@ public class Test4JavaCallback extends BaseClass { final String msgNo3 = "Third message"; id_res[0] = -1; msg_res[0] = null; - bt2.alEventCallback1Inject(myUserParam02, 0, 2, 0, msgNo3); + bt2.alEventCallback1Inject(context02, 0, 2, 0, msgNo3); Assert.assertEquals( -1, id_res[0]); Assert.assertEquals( null, msg_res[0]); - bt2.alEventCallback1Inject(myUserParam01, 0, 2, 0, msgNo3); + bt2.alEventCallback1Inject(context01, 0, 2, 0, msgNo3); Assert.assertEquals( -1, id_res[0]); Assert.assertEquals( null, msg_res[0]); - bt2.alEventCallback1Inject(myUserParam01, 0, 1, 0, msgNo3); + bt2.alEventCallback1Inject(context01, 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); + bt2.alEventCallback1(2, null, context02); Assert.assertEquals(true, bt2.isAlEventCallback1Mapped(myKey01)); Assert.assertEquals(false, bt2.isAlEventCallback1Mapped(myKey02)); - bt2.alEventCallback1(2, null, myUserParam01); + bt2.alEventCallback1(2, null, context01); Assert.assertEquals(true, bt2.isAlEventCallback1Mapped(myKey01)); Assert.assertEquals(false, bt2.isAlEventCallback1Mapped(myKey02)); - // Just release the callback and mapped myUserParam01 - bt2.alEventCallback1(1, null, myUserParam01); + // Just release the callback and mapped context01 + bt2.alEventCallback1(1, null, context01); Assert.assertEquals(false, bt2.isAlEventCallback1Mapped(myKey01)); Assert.assertEquals(false, bt2.isAlEventCallback1Mapped(myKey02)); Assert.assertEquals(0, bt2.getAlEventCallback1Keys().size()); @@ -1179,11 +1177,11 @@ public class Test4JavaCallback extends BaseClass { final String msgNo4 = "Forth message"; id_res[0] = -1; msg_res[0] = null; - bt2.alEventCallback1Inject(myUserParam01, 0, 4, 0, msgNo4); + bt2.alEventCallback1Inject(context01, 0, 4, 0, msgNo4); Assert.assertEquals( -1, id_res[0]); Assert.assertEquals( null, msg_res[0]); - bt2.alEventCallback1Inject(myUserParam02, 0, 4, 0, msgNo4); + bt2.alEventCallback1Inject(context02, 0, 4, 0, msgNo4); Assert.assertEquals( -1, id_res[0]); Assert.assertEquals( null, msg_res[0]); } 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 index 28d46a6..2242d4c 100644 --- 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 @@ -1,4 +1,4 @@ - public void alEventCallback0Inject(Object userParam, int eventType, int object, int param, String message); + public void alEventCallback0Inject(ALCcontext userParam, int eventType, int object, int param, String message); - public void alEventCallback1Inject(Object userParam, int eventType, int object, int param, String message); + public void alEventCallback1Inject(ALCcontext 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 index 6643108..9d58e02 100644 --- 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 @@ -1,10 +1,10 @@ - public void alEventCallback0Inject(Object userParam, int eventType, int object, int param, String message) { - final Object userParam2; + public void alEventCallback0Inject(ALCcontext userParam, int eventType, int object, int param, String message) { + final ALCcontext userParam2; final AlEventCallback0Data value; synchronized( alEventCallback0Lock ) { final AlEventCallback0Data value0 = alEventCallback0DataMap.get( new AlEventCallback0Key( userParam ) ); if( null != value0 ) { - userParam2 = alEventCallback0UserObjIDMap.get(value0.paramID); + userParam2 = (ALCcontext) alEventCallback0UserObjIDMap.get(value0.paramID); if( userParam != userParam2 ) { throw new InternalError("Impl issue-1: Arg userParam "+userParam+" != "+userParam2); } @@ -21,13 +21,13 @@ 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; + public void alEventCallback1Inject(ALCcontext userParam, int eventType, int object, int param, String message) { + final ALCcontext userParam2; final AlEventCallback1Data value; synchronized( alEventCallback1Lock ) { final AlEventCallback1Data value0 = alEventCallback1DataMap.get( new AlEventCallback1Key( object, userParam ) ); if( null != value0 ) { - userParam2 = alEventCallback1UserObjIDMap.get(value0.paramID); + userParam2 = (ALCcontext) alEventCallback1UserObjIDMap.get(value0.paramID); if( userParam != userParam2 ) { throw new InternalError("Impl issue-1: Arg userParam "+userParam+" != "+userParam2); } 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 3a1c7b3..fdad264 100644 --- a/src/junit/com/jogamp/gluegen/test/junit/generation/test2.cfg +++ b/src/junit/com/jogamp/gluegen/test/junit/generation/test2.cfg @@ -94,10 +94,10 @@ JavaCallbackDef MessageCallback01 1 T2_CallbackFunc01 2 # - `Set<AlBufferCallback0Key> getAlBufferCallback0Keys()` returns set of Key { int buffer } # - `boolean isAlBufferCallback0Mapped(AlBufferCallback0Key)` queries whether `alBufferCallback0` is mapped to `buffer`. # - `ALBUFFERCALLBACKTYPESOFT getAlBufferCallback0(AlBufferCallback0Key)` returns the `buffer` mapped ALEVENTPROCSOFT, null if not mapped -# - `Object getAlBufferCallback0UserParam(AlBufferCallback0Key)` returns the `buffer` mapped `userptr` object, null if not mapped +# - `ALCcontext 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 4 ALBUFFERCALLBACKTYPESOFT 1 +JavaCallbackDef alBufferCallback0 4 ALBUFFERCALLBACKTYPESOFT 1 ALCcontext JavaCallbackKey alBufferCallback0 0 ALBUFFERCALLBACKTYPESOFT 0 # # End JavaCallback @@ -126,8 +126,8 @@ JavaCallbackKey alBufferCallback0 0 ALBUFFERCALLBACKTYPESOFT 0 # Explicit maintenance methods are generated, passing the keys as paramters # - `boolean isAlBufferCallback1Mapped(int buffer)` queries whether `alBufferCallback1` is mapped to `buffer`. # - `ALBUFFERCALLBACKTYPESOFT getAlBufferCallback1(int buffer)` returns the `buffer` mapped ALEVENTPROCSOFT, null if not mapped -# - `Object getAlBufferCallback1UserParam(int buffer)` returns the `buffer` mapped `userptr` object, null if not mapped -JavaCallbackDef alBufferCallback1 0 ALBUFFERCALLBACKTYPESOFT 1 com.jogamp.gluegen.test.junit.generation.Test4JavaCallback.CustomAlBufferCallback1Key +# - `ALCcontext getAlBufferCallback1UserParam(int buffer)` returns the `buffer` mapped `userptr` object, null if not mapped +JavaCallbackDef alBufferCallback1 0 ALBUFFERCALLBACKTYPESOFT 1 ALCcontext com.jogamp.gluegen.test.junit.generation.Test4JavaCallback.CustomAlBufferCallback1Key JavaCallbackKey alBufferCallback1 1 ALBUFFERCALLBACKTYPESOFT 0 # # End JavaCallback @@ -146,7 +146,7 @@ ArgumentIsPascalString ALEVENTPROCSOFT 3 4 # 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 +JavaCallbackDef alEventCallback0 1 ALEVENTPROCSOFT 5 ALCcontext JavaCallbackKey alEventCallback0 1 ALEVENTPROCSOFT 5 # # End JavaCallback @@ -154,7 +154,7 @@ JavaCallbackKey alEventCallback0 1 ALEVENTPROCSOFT 5 # Begin JavaCallback. # # void alEventCallback1(int object /* key */, ALEVENTPROCSOFT callback, void *userParam /* key */); -JavaCallbackDef alEventCallback1 2 ALEVENTPROCSOFT 5 +JavaCallbackDef alEventCallback1 2 ALEVENTPROCSOFT 5 ALCcontext JavaCallbackKey alEventCallback1 0 2 ALEVENTPROCSOFT 1 5 # @@ -168,7 +168,7 @@ IncludeAs CustomJavaCode Bindingtest2Impl test2-CustomJavaImplCode.java.stub # typedef void ( * T2_CallbackFunc11)(size_t id, const T2_Callback11UserType* usrParam); # 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 Object com.jogamp.gluegen.test.junit.generation.Test4JavaCallback.CustomMessageCallback11Key JavaCallbackDef MessageCallback11a 2 T2_CallbackFunc11 1 JavaCallbackKey MessageCallback11a 0 T2_CallbackFunc11 0 # @@ -187,6 +187,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.Test4JavaCallback.ALCcontext CustomJavaCode Bindingtest2Impl private static Bindingtest2ProcAddressTable _table = new Bindingtest2ProcAddressTable(); CustomJavaCode Bindingtest2Impl public static void resetProcAddressTable(DynamicLookupHelper lookup) { |