Top Description Inners Fields Constructors Methods
com.sun.jna

pack-priv Class CallbackReference

extends WeakReference
Class Inheritance
Imports
java.lang.ref.WeakReference, java.lang.reflect.InvocationHandler, .InvocationTargetException, .Method, .Proxy, java.util.HashMap, .Iterator, .Map, .WeakHashMap

Provides a reference to an association between a native callback closure and a Java Callback closure.

Nested and Inner Type Summary

Modifier and TypeClass and Description
private class
private static class
CallbackReference.NativeFunctionHandler

Provide invocation handling for an auto-generated Java interface proxy for a native function pointer.

private static interface

Field Summary

Modifier and TypeField and Description
pack-priv static final Map<K, V>
pack-priv static final Map<K, V>
pack-priv Pointer
private static final Map<K, V>
pack-priv CallbackProxy

Constructor Summary

AccessConstructor and Description
private
CallbackReference(Callback callback, int callingConvention)

Method Summary

Modifier and TypeMethod and Description
private static synchronized native Pointer
createNativeCallback(CallbackProxy callback, Method method, Class<T>[] parameterTypes, Class<T> returnType, int callingConvention)

Create a native trampoline to delegate execution to the Java callback.

protected void
finalize()

Overrides java.lang.Object.finalize.

Free native resources associated with this callback.
private static synchronized native void
freeNativeCallback(long ptr)

Free the given callback trampoline.

public static Callback
getCallback(Class<T> type, Pointer p)

Return a Callback associated with the given function pointer.

private Callback
private static Class<T>
private static Method
public static Pointer
getFunctionPointer(Callback cb)

Return a Pointer to the native function address for the given callback.

private static Pointer
private Class<T>
public Pointer
getTrampoline()

Obtain a pointer to the native glue code for this callback.

private static boolean
isAllowableNativeType(Class<T> cls)

Returns whether the given class is supported in native code.

Field Detail

altCallbackMapback to summary
pack-priv static final Map<K, V> altCallbackMap
callbackMapback to summary
pack-priv static final Map<K, V> callbackMap
cbstructback to summary
pack-priv Pointer cbstruct
nativeStringsback to summary
private static final Map<K, V> nativeStrings
proxyback to summary
pack-priv CallbackProxy proxy

Constructor Detail

CallbackReferenceback to summary
private CallbackReference(Callback callback, int callingConvention)

Method Detail

createNativeCallbackback to summary
private static synchronized native Pointer createNativeCallback(CallbackProxy callback, Method method, Class<T>[] parameterTypes, Class<T> returnType, int callingConvention)

Create a native trampoline to delegate execution to the Java callback.

finalizeback to summary
protected void finalize()

Overrides java.lang.Object.finalize.

Free native resources associated with this callback.

freeNativeCallbackback to summary
private static synchronized native void freeNativeCallback(long ptr)

Free the given callback trampoline.

getCallbackback to summary
public static Callback getCallback(Class<T> type, Pointer p)

Return a Callback associated with the given function pointer. If the pointer refers to a Java callback trampoline, return the original Java Callback. Otherwise, return a proxy to the native function pointer.

getCallbackback to summary
private Callback getCallback()
getCallbackClassback to summary
private static Class<T> getCallbackClass(Class<T> type)
getCallbackMethodback to summary
private static Method getCallbackMethod(Callback callback)
getFunctionPointerback to summary
public static Pointer getFunctionPointer(Callback cb)

Return a Pointer to the native function address for the given callback.

getNativeFunctionPointerback to summary
private static Pointer getNativeFunctionPointer(Callback cb)
getNativeTypeback to summary
private Class<T> getNativeType(Class<T> cls)
getTrampolineback to summary
public Pointer getTrampoline()

Obtain a pointer to the native glue code for this callback.

isAllowableNativeTypeback to summary
private static boolean isAllowableNativeType(Class<T> cls)

Returns whether the given class is supported in native code. Other types (String, WString, Structure, arrays, NativeMapped, etc) are supported in the Java library.

com.sun.jna back to summary

private Class CallbackReference.DefaultCallbackProxy

extends Object
implements CallbackProxy
Class Inheritance
All Implemented Interfaces
com.sun.jna.CallbackProxy, com.sun.jna.Callback

Field Summary

Modifier and TypeField and Description
private Method
private FromNativeConverter[]
private ToNativeConverter

Constructor Summary

AccessConstructor and Description
public
DefaultCallbackProxy(Method callbackMethod, TypeMapper mapper)

Method Summary

Modifier and TypeMethod and Description
public Object
callback(Object[] args)

Implements com.sun.jna.CallbackProxy.callback.

Called from native code.
private Object
private Object
convertArgument(Object value, Class<T> dstType)

Convert argument from its basic native type to the given Java parameter type.

private Object
public Class<T>[]
getParameterTypes()

Implements com.sun.jna.CallbackProxy.getParameterTypes.

Returns the types of the parameters to the callback method.
public Class<T>
getReturnType()

Implements com.sun.jna.CallbackProxy.getReturnType.

Returns the type of the callback method's return value.
Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

callbackMethodback to summary
private Method callbackMethod
fromNativeback to summary
private FromNativeConverter[] fromNative
toNativeback to summary
private ToNativeConverter toNative

Constructor Detail

DefaultCallbackProxyback to summary
public DefaultCallbackProxy(Method callbackMethod, TypeMapper mapper)

Method Detail

callbackback to summary
public Object callback(Object[] args)

Implements com.sun.jna.CallbackProxy.callback.

Called from native code. All arguments are in an array of Object as the first argument. Converts all arguments to types required by the actual callback method signature, and converts the result back into an appropriate native type. This method must not throw exceptions.

callback_innerback to summary
private Object callback_inner(Object[] args)
convertArgumentback to summary
private Object convertArgument(Object value, Class<T> dstType)

Convert argument from its basic native type to the given Java parameter type.

convertResultback to summary
private Object convertResult(Object value)
getParameterTypesback to summary
public Class<T>[] getParameterTypes()

Implements com.sun.jna.CallbackProxy.getParameterTypes.

Doc from com.sun.jna.CallbackProxy.getParameterTypes.

Returns the types of the parameters to the callback method.

getReturnTypeback to summary
public Class<T> getReturnType()

Implements com.sun.jna.CallbackProxy.getReturnType.

Doc from com.sun.jna.CallbackProxy.getReturnType.

Returns the type of the callback method's return value.

com.sun.jna back to summary

private Class CallbackReference.NativeFunctionHandler

extends Object
implements InvocationHandler
Class Inheritance
All Implemented Interfaces
java.lang.reflect.InvocationHandler

Provide invocation handling for an auto-generated Java interface proxy for a native function pointer. Cf. Library.Handler

Field Summary

Modifier and TypeField and Description
private Function
private Map<K, V>

Constructor Summary

AccessConstructor and Description
public
NativeFunctionHandler(Pointer address, int callingConvention, Map<K, V> libOptions)

Method Summary

Modifier and TypeMethod and Description
public Pointer
public Object
invoke(Object
the proxy instance that the method was invoked on
proxy
,
Method
the Method instance corresponding to the interface method invoked on the proxy instance. The declaring class of the Method object will be the interface that the method was declared in, which may be a superinterface of the proxy interface that the proxy class inherits the method through.
method
,
Object[]
an array of objects containing the values of the arguments passed in the method invocation on the proxy instance, or null if interface method takes no arguments. Arguments of primitive types are wrapped in instances of the appropriate primitive wrapper class, such as java.lang.Integer or java.lang.Boolean.
args
)

Implements java.lang.reflect.InvocationHandler.invoke.

Chain invocation to the native function.
Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

functionback to summary
private Function function
optionsback to summary
private Map<K, V> options

Constructor Detail

NativeFunctionHandlerback to summary
public NativeFunctionHandler(Pointer address, int callingConvention, Map<K, V> libOptions)

Method Detail

getPointerback to summary
public Pointer getPointer()
invokeback to summary
public Object invoke(Object proxy, Method method, Object[] args) throws Throwable

Implements java.lang.reflect.InvocationHandler.invoke.

Chain invocation to the native function.

Parameters
proxy:Object

Doc from java.lang.reflect.InvocationHandler.invoke.

the proxy instance that the method was invoked on

method:Method

Doc from java.lang.reflect.InvocationHandler.invoke.

the Method instance corresponding to the interface method invoked on the proxy instance. The declaring class of the Method object will be the interface that the method was declared in, which may be a superinterface of the proxy interface that the proxy class inherits the method through.

args:Object[]

Doc from java.lang.reflect.InvocationHandler.invoke.

an array of objects containing the values of the arguments passed in the method invocation on the proxy instance, or null if interface method takes no arguments. Arguments of primitive types are wrapped in instances of the appropriate primitive wrapper class, such as java.lang.Integer or java.lang.Boolean.

Returns:Object

Doc from java.lang.reflect.InvocationHandler.invoke.

the value to return from the method invocation on the proxy instance. If the declared return type of the interface method is a primitive type, then the value returned by this method must be an instance of the corresponding primitive wrapper class; otherwise, it must be a type assignable to the declared return type. If the value returned by this method is null and the interface method's return type is primitive, then a NullPointerException will be thrown by the method invocation on the proxy instance. If the value returned by this method is otherwise not compatible with the interface method's declared return type as described above, a ClassCastException will be thrown by the method invocation on the proxy instance.

Exceptions
Throwable:

Doc from java.lang.reflect.InvocationHandler.invoke.

the exception to throw from the method invocation on the proxy instance. The exception's type must be assignable either to any of the exception types declared in the throws clause of the interface method or to the unchecked exception types java.lang.RuntimeException or java.lang.Error. If a checked exception is thrown by this method that is not assignable to any of the exception types declared in the throws clause of the interface method, then an UndeclaredThrowableException containing the exception that was thrown by this method will be thrown by the method invocation on the proxy instance.

com.sun.jna back to summary

private Interface CallbackReference.NativeFunctionProxy