Top Description Fields Constructors Methods
org.eclipse.swt.internal

public Class Callback

extends Object
Class Inheritance
Imports
java.lang.reflect.*, java.util.function.*, org.eclipse.swt.*

Instances of this class represent entry points into Java which can be invoked from operating system level callback routines.

Important Note

A callback is only valid when invoked on the thread which created it. The results are undefined (and typically bad) when a callback is passed out to the operating system (or other code) in such a way that the callback is called from a different thread.

Field Summary

Modifier and TypeField and Description
pack-priv long
pack-priv int
pack-priv long
pack-priv static final boolean
pack-priv boolean
pack-priv boolean
pack-priv String
pack-priv Object
pack-priv static final String
pack-priv String
pack-priv static final String
pack-priv static final String
pack-priv static final String
pack-priv static final String
pack-priv static final String
pack-priv static final String

Constructor Summary

AccessConstructor and Description
public
Callback(Object
the object to send the message to
object
,
String
the name of the method to invoke
method
,
int
the number of arguments that the method takes
argCount
)

Constructs a new instance of this class given an object to send the message to, a string naming the method to invoke and an argument count.

public
Callback(Object
the object to send the message to
object
,
String
the name of the method to invoke
method
,
int
the number of arguments that the method takes
argCount
,
boolean
true if the arguments should be passed in an array and false otherwise
isArrayBased
)

Constructs a new instance of this class given an object to send the message to, a string naming the method to invoke, an argument count and a flag indicating whether or not the arguments will be passed in an array.

public
Callback(Object
the object to send the message to
object
,
String
the name of the method to invoke
method
,
int
the number of arguments that the method takes
argCount
,
boolean
true if the arguments should be passed in an array and false otherwise
isArrayBased
,
long
the return value if the java code throws an exception
errorResult
)

Constructs a new instance of this class given an object to send the message to, a string naming the method to invoke, an argument count, a flag indicating whether or not the arguments will be passed in an array and a value to return when an exception happens.

public
Callback(Object
the object to send the message to
object
,
String
method the name of the method to invoke
method
,
Type
specify the type like void.class, long.class, double.class
returnType
,
Type[]
specify the list of arguments like new Type [] {long.class, double.class }
arguments
)

Register the java method to be a C callback.

Method Summary

Modifier and TypeMethod and Description
pack-priv static synchronized native long
bind(Callback
the callback to bind
callback
,
Object
the callback's object
object
,
String
the callback's method
method
,
String
the callback's method signature
signature
,
int
the callback's method argument count
argCount
,
boolean
whether the callback's method is static
isStatic
,
boolean
whether the callback's method is array based
isArrayBased
,
long
the callback's error result
errorResult
)

Allocates the native level resources associated with the callback.

public void
dispose()

Releases the native level resources associated with the callback, and removes all references between the callback and other objects.

public long

Returns:

the callback address
getAddress
()

Returns the address of a block of machine code which will invoke the callback represented by the receiver.

public static final synchronized native boolean

Returns:

true if callbacks should not be invoked
getEnabled
()

Returns whether or not callbacks which are triggered at the native level should cause the messages described by the matching Callback objects to be invoked.

public static native int

Returns:

the entry count
getEntryCount
()

Returns the number of times the system has been recursively entered through a callback.

public static native String

Returns:

the platform name of the currently running SWT
getPlatform
()

Returns the SWT platform name.

pack-priv static String
getSignature(int argCount)

pack-priv static final void
ignoreCallbacks(boolean
true if callbacks should not be invoked
ignore
)

Deprecated
This might be called directly from native code in environments which can generate spurious events.
public static final synchronized native void
reset()

Immediately wipes out all native level state associated with all callbacks.

public static final synchronized native void
setEnabled(boolean
true if callbacks should be invoked
enable
)

Indicates whether or not callbacks which are triggered at the native level should cause the messages described by the matching Callback objects to be invoked.

pack-priv static final synchronized native void
unbind(Callback callback)

Releases the native level resources associated with the callback.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

addressback to summary
pack-priv long address
argCountback to summary
pack-priv int argCount
errorResultback to summary
pack-priv long errorResult
is32Bitback to summary
pack-priv static final boolean is32Bit
isArrayBasedback to summary
pack-priv boolean isArrayBased
isStaticback to summary
pack-priv boolean isStatic
methodback to summary
pack-priv String method
objectback to summary
pack-priv Object object
PTR_SIGNATUREback to summary
pack-priv static final String PTR_SIGNATURE
signatureback to summary
pack-priv String signature
SIGNATURE_0back to summary
pack-priv static final String SIGNATURE_0
SIGNATURE_1back to summary
pack-priv static final String SIGNATURE_1
SIGNATURE_2back to summary
pack-priv static final String SIGNATURE_2
SIGNATURE_3back to summary
pack-priv static final String SIGNATURE_3
SIGNATURE_4back to summary
pack-priv static final String SIGNATURE_4
SIGNATURE_Nback to summary
pack-priv static final String SIGNATURE_N

Constructor Detail

Callbackback to summary
public Callback(Object object, String method, int argCount)

Constructs a new instance of this class given an object to send the message to, a string naming the method to invoke and an argument count. Note that, if the object is an instance of Class it is assumed that the method is a static method on that class.

Note, do not use this if the method arguments have a double, as arguments will be shifted/corrupted. See Bug 510538. Instead use the following constructor:
Callback (Object, String, Type, Type [])

Parameters
object:Object

the object to send the message to

method:String

the name of the method to invoke

argCount:int

the number of arguments that the method takes

Callbackback to summary
public Callback(Object object, String method, int argCount, boolean isArrayBased)

Constructs a new instance of this class given an object to send the message to, a string naming the method to invoke, an argument count and a flag indicating whether or not the arguments will be passed in an array. Note that, if the object is an instance of Class it is assumed that the method is a static method on that class.

Note, do not use this if the method arguments have a double, as arguments will be shifted/corrupted. See Bug 510538. Instead use the following constructor:
Callback (Object, String, Type, Type [])

Parameters
object:Object

the object to send the message to

method:String

the name of the method to invoke

argCount:int

the number of arguments that the method takes

isArrayBased:boolean

true if the arguments should be passed in an array and false otherwise

Callbackback to summary
public Callback(Object object, String method, int argCount, boolean isArrayBased, long errorResult)

Constructs a new instance of this class given an object to send the message to, a string naming the method to invoke, an argument count, a flag indicating whether or not the arguments will be passed in an array and a value to return when an exception happens. Note that, if the object is an instance of Class it is assumed that the method is a static method on that class.

Note, do not use this if the method arguments have a double, as arguments will be shifted/corrupted. See Bug 510538. Instead use the following constructor:
Callback (Object, String, Type, Type [])

Parameters
object:Object

the object to send the message to

method:String

the name of the method to invoke

argCount:int

the number of arguments that the method takes

isArrayBased:boolean

true if the arguments should be passed in an array and false otherwise

errorResult:long

the return value if the java code throws an exception

Callbackback to summary
public Callback(Object object, String method, Type returnType, Type[] arguments)

Register the java method to be a C callback. I.e, C will be able to make a call to this java method directly (through callback.c)

The other constructors hard-code int/long into the method signature:
long method (long ...)
Which is suitable for int/long and pointers.
This constructor is used if you need to use a different return/argument type, e.g double. See Bug 510538

Note:

  • Array support is not implemented/supported by this constructor. Use other constructors.
  • If the object is an instance of Class it is assumed that the method is a static method on that class.
  • Note, long types are converted to ints on 32 bit system automatically to account for smaller pointers. This means if you use 'long', you need to cast int next to it. like: long /*int*/

The following types are supported:

  • void (for return values only)
  • int
  • long
  • byte
  • char
  • double
  • float
  • short
  • boolean

For example if you want to link the following method:
void myMethod(long /*int*/ arg1, double arg2)
Then you would call this callback like:
Callback (this, "myMethod", void.class, new Type []{long.class, double.class});

Parameters
object:Object

the object to send the message to

method:String

method the name of the method to invoke

returnType:Type

specify the type like void.class, long.class, double.class

arguments:Type[]

specify the list of arguments like new Type [] {long.class, double.class }

Method Detail

bindback to summary
pack-priv static synchronized native long bind(Callback callback, Object object, String method, String signature, int argCount, boolean isStatic, boolean isArrayBased, long errorResult)

Allocates the native level resources associated with the callback. This method is only invoked from within the constructor for the argument.

Parameters
callback:Callback

the callback to bind

object:Object

the callback's object

method:String

the callback's method

signature:String

the callback's method signature

argCount:int

the callback's method argument count

isStatic:boolean

whether the callback's method is static

isArrayBased:boolean

whether the callback's method is array based

errorResult:long

the callback's error result

disposeback to summary
public void dispose()

Releases the native level resources associated with the callback, and removes all references between the callback and other objects. This helps to prevent (bad) application code from accidentally holding onto extraneous garbage.

getAddressback to summary
public long getAddress()

Returns the address of a block of machine code which will invoke the callback represented by the receiver.

Returns:long

the callback address

getEnabledback to summary
public static final synchronized native boolean getEnabled()

Returns whether or not callbacks which are triggered at the native level should cause the messages described by the matching Callback objects to be invoked. This method is used to safely shut down SWT when it is run within environments which can generate spurious events.

Note

This should not be called by application code.

Returns:boolean

true if callbacks should not be invoked

getEntryCountback to summary
public static native int getEntryCount()

Returns the number of times the system has been recursively entered through a callback.

Note

This should not be called by application code.

Returns:int

the entry count

Since
2.1
getPlatformback to summary
public static native String getPlatform()

Returns the SWT platform name.

Returns:String

the platform name of the currently running SWT

getSignatureback to summary
pack-priv static String getSignature(int argCount)
ignoreCallbacksback to summary
pack-priv static final void ignoreCallbacks(boolean ignore)

Deprecated

This might be called directly from native code in environments which can generate spurious events. Check before removing it.

Parameters
ignore:boolean

true if callbacks should not be invoked

Annotations
@Deprecated
resetback to summary
public static final synchronized native void reset()

Immediately wipes out all native level state associated with all callbacks.

Warning

This operation is extremely dangerous, and should never be performed by application code.

setEnabledback to summary
public static final synchronized native void setEnabled(boolean enable)

Indicates whether or not callbacks which are triggered at the native level should cause the messages described by the matching Callback objects to be invoked. This method is used to safely shut down SWT when it is run within environments which can generate spurious events.

Note

This should not be called by application code.

Parameters
enable:boolean

true if callbacks should be invoked

unbindback to summary
pack-priv static final synchronized native void unbind(Callback callback)

Releases the native level resources associated with the callback.

See Also
dispose