Package com.sun.jna

# Class CallbackReference

java.lang.Object
java.lang.ref.Reference<T>
java.lang.ref.WeakReference<Callback>
com.sun.jna.CallbackReference

All Implemented Interfaces:
  `Closeable`, `AutoCloseable`

public class CallbackReference extends WeakReference<Callback> implements Closeable
Provides a reference to an association between a native callback closure and a Java `Callback` closure.

## Nested Class Summary

Nested Classes
Modifier and Type
Class
Description
`(package private) static class`
`CallbackReference.AttachOptions`

## Field Summary

Fields
Modifier and Type
Field
Description
`(package private) static final Map<Object,Object>`
`allocations`
`(package private) static final Map<Callback,CallbackReference>`
`callbackMap`
`(package private) int`
`callingConvention`
`(package private) Pointer`
`cbstruct`
`(package private) Cleaner.Cleanable`
`cleanable`
`(package private) static final Map<Callback,CallbackReference>`
`directCallbackMap`
`(package private) Method`
`method`
`(package private) static final Map<Pointer,Reference<Callback>[]>`
`pointerCallbackMap`
`(package private) CallbackProxy`
`proxy`
`(package private) Pointer`
`trampoline`

## Method Summary

Modifier and Type
Method
Description
`void`
`close()`
Free native resources associated with this callback.
`protected void`
`dispose()`
Deprecated.
`(package private) static void`
`disposeAll()`
Dispose of all memory allocated for callbacks.
`(package private) static Class<?>`
`findCallbackClass(Class<?> type)`
`static Callback`
`getCallback(Class<?> type, Pointer p)`
Return a Callback associated with the given function pointer.
`static Pointer`
`getFunctionPointer(Callback cb)`
Return a `Pointer` to the native function address for the given callback.
`Pointer`
`getTrampoline()`
Obtain a pointer to the native glue code for this callback.
`(package private) static CallbackThreadInitializer`
`setCallbackThreadInitializer(Callback cb, CallbackThreadInitializer initializer)`

### Methods inherited from class java.lang.ref.Reference

`clear, clone, enqueue, get, isEnqueued, reachabilityFence, refersTo`

### Methods inherited from class java.lang.Object

`equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

## Field Details

### callbackMap

static final Map<Callback,CallbackReference> callbackMap

### directCallbackMap

static final Map<Callback,CallbackReference> directCallbackMap

### pointerCallbackMap

static final Map<Pointer,Reference<Callback>[]> pointerCallbackMap

### allocations

static final Map<Object,Object> allocations

### cleanable

Cleaner.Cleanable cleanable

### cbstruct

Pointer cbstruct

### trampoline

Pointer trampoline

### proxy

CallbackProxy proxy

### method

Method method

### callingConvention

int callingConvention

## Method Details

### setCallbackThreadInitializer

static CallbackThreadInitializer setCallbackThreadInitializer(Callback cb, CallbackThreadInitializer initializer)

Parameters:
  `cb` - The `Callback` instance
  `initializer` - The `CallbackThreadInitializer` - if `null` then the associated initializer instance is removed
Returns:
  The previous initializer instance (may be `null`)

### getCallback

public static Callback getCallback(Class<?> 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.

Throws:
  `IllegalStateException` - if the given pointer has already been mapped to a callback of a different type.

### findCallbackClass

static Class<?> findCallbackClass(Class<?> type)

### getTrampoline

public Pointer getTrampoline()
Obtain a pointer to the native glue code for this callback.

### close

public void close()
Free native resources associated with this callback.

Specified by:
  `close` in interface `AutoCloseable`
Specified by:
  `close` in interface `Closeable`

### dispose

@Deprecated protected void dispose()
Deprecated.

### disposeAll

static void disposeAll()
Dispose of all memory allocated for callbacks.

### getFunctionPointer

public static Pointer getFunctionPointer(Callback cb)
Return a `Pointer` to the native function address for the given callback.