CCallbackMapper

public class CCallbackMapper implements Mapper

Mapper for C callbacks.

Fields

callback2extras

public Map<Long, Long> callback2extras

Collection used for caching extras for callbacks.

instance2callbacks

public Map<Object, CallbackInfo[]> instance2callbacks

Collection used for caching generated native callbacks where the Java instance has no cache field.

Methods

toJava

public Object toJava(long peer, JavaObjectConstructionInfo info)

Creates a Java instance from a native callback.

This only works with C callbacks we create.

toNative

public long toNative(Object instance, NativeObjectConstructionInfo info)

Creates a native callback from a Java instance.

At first this computes the method index that is used for cache indexing. Then it tries to get or create a cache through the NatJ interface. If this results in a failure that means the Java instance has no cache field, in this case it uses instance2callbacks as cache. If the cache has a generated Pointer at the computed index, then it uses it as a result, otherwise, if the cache does not contain anything for the method, then it creates the native callback and saves it in the cache at the computed index. And at last it returns the created native callback.