ObjCCallbackMapper

public class ObjCCallbackMapper implements Mapper

Mapper for Objective-C blocks.

Fields

block2blockInfo

public Map<Class<?>, NativeBlockInfo> block2blockInfo

Collection for caching the created Java proxy classes and data of native blocks.

class2data

public Map<Class<?>, Long> class2data

Collection used for caching data generated for Java blocks.

instance2callbacks

public Map<Object, WeakReference[]> instance2callbacks

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

Methods

cleanupObjCBlock

public void cleanupObjCBlock(Object instance, Method method)

Clean ups after an Objective-C block.

Parameters:
  • instance – Block object
  • method – Callback method

createStrongBlockBindingPointer

public static Pointer createStrongBlockBindingPointer(long peer, boolean owned)

Creates a strong block binding pointer to an Objective-C object.

Retains if doing so is needed to keep the strong ownership.

Parameters:
  • peer – The pointer
  • owned – If this is false, the pointer objects will be retained
Returns:

The created Pointer object

dispose

public boolean dispose(Object object)

Disposes an object if it can be.

Parameters:
  • object – The object of which we want to dispose the native peer
Returns:

Whether the given object was disposable

getJavaBlockPeer

public Pointer getJavaBlockPeer(Object instance, String name, java.lang.Class<?>[] argTypes)

Gets the peer for a Java block object.

Parameters:
  • instance – Block object
  • name – Callback method name
  • argTypes – Argument types
Returns:

Pointer to block object

getNativeBlockPeer

public Pointer getNativeBlockPeer(Object instance)

Gets the peer for a native block object.

Parameters:
  • instance – Block object
Returns:

Pointer to native block

toJava

public Object toJava(long peer, NatJ.JavaObjectConstructionInfo info)

Creates a Java instance from a native block.

This only works with Objective-C blocks we create.

toNative

public long toNative(Object instance, NatJ.NativeObjectConstructionInfo info)

Creates a native block from a Java instance.