Class Callback

java.lang.Object
org.fusesource.hawtjni.runtime.Callback

public class Callback extends 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.

  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    (package private) long
     
    (package private) int
     
    (package private) long
     
    (package private) boolean
     
    (package private) boolean
     
    (package private) String
     
    (package private) Object
     
    (package private) static final String
     
    (package private) String
     
    (package private) static final String
     
    (package private) static final String
     
    (package private) static final String
     
    (package private) static final String
     
    (package private) static final String
     
    (package private) static final String
     
  • Constructor Summary

    Constructors
    Constructor
    Description
    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.
    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.
    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.
  • Method Summary

    Modifier and Type
    Method
    Description
    (package private) static 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.
    void
    Releases the native level resources associated with the callback, and removes all references between the callback and other objects.
    long
    Returns the address of a block of machine code which will invoke the callback represented by the receiver.
    static final boolean
    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.
    static int
    Returns the number of times the system has been recursively entered through a callback.
    static String
    Returns the SWT platform name.
    (package private) static String
    getSignature(int argCount)
     
    static final void
    Immediately wipes out all native level state associated with all callbacks.
    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 matching Callback objects to be invoked.
    (package private) static final void
    unbind(Callback callback)
    Releases the native level resources associated with the callback.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Field Details

    • object

      Object object
    • method

      String method
    • signature

      String signature
    • argCount

      int argCount
    • address

      long address
    • errorResult

      long errorResult
    • isStatic

      boolean isStatic
    • isArrayBased

      boolean isArrayBased
    • PTR_SIGNATURE

      static final String PTR_SIGNATURE
      See Also:
    • SIGNATURE_0

      static final String SIGNATURE_0
    • SIGNATURE_1

      static final String SIGNATURE_1
    • SIGNATURE_2

      static final String SIGNATURE_2
    • SIGNATURE_3

      static final String SIGNATURE_3
    • SIGNATURE_4

      static final String SIGNATURE_4
    • SIGNATURE_N

      static final String SIGNATURE_N
      See Also:
  • Constructor Details

    • Callback

      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.
      Parameters:
      object - the object to send the message to
      method - the name of the method to invoke
      argCount - the number of arguments that the method takes
    • Callback

      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.
      Parameters:
      object - the object to send the message to
      method - the name of the method to invoke
      argCount - the number of arguments that the method takes
      isArrayBased - true if the arguments should be passed in an array and false otherwise
    • Callback

      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.
      Parameters:
      object - the object to send the message to
      method - the name of the method to invoke
      argCount - the number of arguments that the method takes
      isArrayBased - true if the arguments should be passed in an array and false otherwise
      errorResult - the return value if the java code throws an exception
  • Method Details

    • bind

      static 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 - the callback to bind
      object - the callback's object
      method - the callback's method
      signature - the callback's method signature
      argCount - the callback's method argument count
      isStatic - whether the callback's method is static
      isArrayBased - whether the callback's method is array based
      errorResult - the callback's error result
    • 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 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
    • getSignature

      static String getSignature(int argCount)
    • 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 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 - 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 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:
      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.

    • unbind

      static final void unbind(Callback callback)
      Releases the native level resources associated with the callback.
      See Also: