Class Callback
- java.lang.Object
-
- org.eclipse.swt.internal.Callback
-
public class Callback extends java.lang.Object
Instances of this class represent entry points into Java which can be invoked from operating system level callback routines.IMPORTANT: 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.
-
-
Constructor Summary
Constructors Constructor Description Callback(java.lang.Object object, java.lang.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.Callback(java.lang.Object object, java.lang.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.Callback(java.lang.Object object, java.lang.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.Callback(java.lang.Object object, java.lang.String method, java.lang.reflect.Type returnType, java.lang.reflect.Type[] arguments)
Register the java method to be a C callback.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description void
dispose()
Releases the native level resources associated with the callback, and removes all references between the callback and other objects.long
getAddress()
Returns the address of a block of machine code which will invoke the callback represented by the receiver.static boolean
getEnabled()
Returns whether or not callbacks which are triggered at the native level should cause the messages described by the matchingCallback
objects to be invoked.static int
getEntryCount()
Returns the number of times the system has been recursively entered through a callback.static java.lang.String
getPlatform()
Returns the SWT platform name.static void
reset()
Immediately wipes out all native level state associated with all callbacks.static void
setEnabled(boolean enable)
Indicates whether or not callbacks which are triggered at the native level should cause the messages described by the matchingCallback
objects to be invoked.
-
-
-
Constructor Detail
-
Callback
public Callback(java.lang.Object object, java.lang.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 ofClass
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
- the object to send the message tomethod
- the name of the method to invokeargCount
- the number of arguments that the method takes
-
Callback
public Callback(java.lang.Object object, java.lang.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 ofClass
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
- the object to send the message tomethod
- the name of the method to invokeargCount
- the number of arguments that the method takesisArrayBased
-true
if the arguments should be passed in an array and false otherwise
-
Callback
public Callback(java.lang.Object object, java.lang.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 ofClass
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
- the object to send the message tomethod
- the name of the method to invokeargCount
- the number of arguments that the method takesisArrayBased
-true
if the arguments should be passed in an array and false otherwiseerrorResult
- the return value if the java code throws an exception
-
Callback
public Callback(java.lang.Object object, java.lang.String method, java.lang.reflect.Type returnType, java.lang.reflect.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 510538Note:
- 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
- the object to send the message tomethod
- method the name of the method to invokereturnType
- specify the type likevoid.class, long.class, double.class
arguments
- specify the list of arguments likenew Type [] {long.class, double.class }
-
-
Method Detail
-
dispose
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.
-
getAddress
public long getAddress()
Returns the address of a block of machine code which will invoke the callback represented by the receiver.- Returns:
- the callback address
-
getPlatform
public static java.lang.String getPlatform()
Returns the SWT platform name.- Returns:
- the platform name of the currently running SWT
-
getEntryCount
public static 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:
- the entry count
- Since:
- 2.1
-
setEnabled
public static final void setEnabled(boolean enable)
Indicates whether or not callbacks which are triggered at the native level should cause the messages described by the matchingCallback
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
- true if callbacks should be invoked
-
getEnabled
public static final boolean getEnabled()
Returns whether or not callbacks which are triggered at the native level should cause the messages described by the matchingCallback
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:
- true if callbacks should not be invoked
-
reset
public static final 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.
-
-