Class Hook

All Implemented Interfaces:
Proxy

@Generated("org.javagi.JavaGI") public class Hook extends ProxyInstance
The GHook struct represents a single hook function in a GHookList.
  • Constructor Details

    • Hook

      public Hook(MemorySegment address)
      Create a Hook proxy instance for the provided memory address.
      Parameters:
      address - the memory address of the native object
    • Hook

      public Hook(Arena arena)
      Allocate a new Hook.
      Parameters:
      arena - to control the memory allocation scope
    • Hook

      public Hook()
      Allocate a new Hook. The memory is allocated with Arena.ofAuto().
    • Hook

      public Hook(MemorySegment data, Hook next, Hook prev, int refCount, int hookId, int flags, MemorySegment func, DestroyNotify destroy, Arena arena)
      Allocate a new Hook with the fields set to the provided values.
      Parameters:
      data - value for the field data
      next - value for the field next
      prev - value for the field prev
      refCount - value for the field refCount
      hookId - value for the field hookId
      flags - value for the field flags
      func - value for the field func
      destroy - value for the field destroy
      arena - to control the memory allocation scope
    • Hook

      public Hook(MemorySegment data, Hook next, Hook prev, int refCount, int hookId, int flags, MemorySegment func, DestroyNotify destroy)
      Allocate a new Hook with the fields set to the provided values. The memory is allocated with Arena.ofAuto().
      Parameters:
      data - value for the field data
      next - value for the field next
      prev - value for the field prev
      refCount - value for the field refCount
      hookId - value for the field hookId
      flags - value for the field flags
      func - value for the field func
      destroy - value for the field destroy
  • Method Details

    • getMemoryLayout

      public static MemoryLayout getMemoryLayout()
      The memory layout of the native struct.
      Returns:
      the memory layout
    • readData

      public MemorySegment readData()
      Read the value of the field data.
      Returns:
      The value of the field data
    • writeData

      public void writeData(MemorySegment data)
      Write a value in the field data.
      Parameters:
      data - The new value for the field data
    • readNext

      public Hook readNext()
      Read the value of the field next.
      Returns:
      The value of the field next
    • writeNext

      public void writeNext(Hook next)
      Write a value in the field next.
      Parameters:
      next - The new value for the field next
    • readPrev

      public Hook readPrev()
      Read the value of the field prev.
      Returns:
      The value of the field prev
    • writePrev

      public void writePrev(Hook prev)
      Write a value in the field prev.
      Parameters:
      prev - The new value for the field prev
    • readRefCount

      public int readRefCount()
      Read the value of the field ref_count.
      Returns:
      The value of the field ref_count
    • writeRefCount

      public void writeRefCount(int refCount)
      Write a value in the field ref_count.
      Parameters:
      refCount - The new value for the field ref_count
    • readHookId

      public int readHookId()
      Read the value of the field hook_id.
      Returns:
      The value of the field hook_id
    • writeHookId

      public void writeHookId(int hookId)
      Write a value in the field hook_id.
      Parameters:
      hookId - The new value for the field hook_id
    • readFlags

      public int readFlags()
      Read the value of the field flags.
      Returns:
      The value of the field flags
    • writeFlags

      public void writeFlags(int flags)
      Write a value in the field flags.
      Parameters:
      flags - The new value for the field flags
    • readFunc

      public MemorySegment readFunc()
      Read the value of the field func.
      Returns:
      The value of the field func
    • writeFunc

      public void writeFunc(MemorySegment func)
      Write a value in the field func.
      Parameters:
      func - The new value for the field func
    • readDestroy

      public @Nullable DestroyNotify readDestroy()
      Read the value of the field destroy.
      Returns:
      The value of the field destroy
    • writeDestroy

      public void writeDestroy(@Nullable DestroyNotify destroy, Arena _arena)
      Write a value in the field destroy.
      Parameters:
      destroy - The new value for the field destroy
      _arena - to control the memory allocation scope
    • alloc

      public static Hook alloc(HookList hookList)
      Allocates space for a GHook and initializes it.
      Parameters:
      hookList - a GHookList
      Returns:
      a new GHook
    • destroy

      public static boolean destroy(HookList hookList, int hookId)
      Destroys a GHook, given its ID.
      Parameters:
      hookList - a GHookList
      hookId - a hook ID
      Returns:
      true if the GHook was found in the GHookList and destroyed
    • destroyLink

      public static void destroyLink(HookList hookList, Hook hook)
      Removes one GHook from a GHookList, marking it inactive and calling g_hook_unref() on it.
      Parameters:
      hookList - a GHookList
      hook - the GHook to remove
    • find

      public static Hook find(HookList hookList, boolean needValids, @Nullable HookFindFunc func)
      Finds a GHook in a GHookList using the given function to test for a match.
      Parameters:
      hookList - a GHookList
      needValids - true if GHook elements which have been destroyed should be skipped
      func - the function to call for each GHook, which should return true when the GHook has been found
      Returns:
      the found GHook or null if no matching GHook is found
    • findData

      public static Hook findData(HookList hookList, boolean needValids, @Nullable MemorySegment data)
      Finds a GHook in a GHookList with the given data.
      Parameters:
      hookList - a GHookList
      needValids - true if GHook elements which have been destroyed should be skipped
      data - the data to find
      Returns:
      the GHook with the given data or null if no matching GHook is found
    • findFunc

      public static Hook findFunc(HookList hookList, boolean needValids, @Nullable MemorySegment func)
      Finds a GHook in a GHookList with the given function.
      Parameters:
      hookList - a GHookList
      needValids - true if GHook elements which have been destroyed should be skipped
      func - the function to find
      Returns:
      the GHook with the given func or null if no matching GHook is found
    • findFuncData

      public static Hook findFuncData(HookList hookList, boolean needValids, MemorySegment func, @Nullable MemorySegment data)
      Finds a GHook in a GHookList with the given function and data.
      Parameters:
      hookList - a GHookList
      needValids - true if GHook elements which have been destroyed should be skipped
      func - the function to find
      data - the data to find
      Returns:
      the GHook with the given func and data or null if no matching GHook is found
    • firstValid

      public static Hook firstValid(HookList hookList, boolean mayBeInCall)
      Returns the first GHook in a GHookList which has not been destroyed. The reference count for the GHook is incremented, so you must call g_hook_unref() to restore it when no longer needed. (Or call g_hook_next_valid() if you are stepping through the GHookList.)
      Parameters:
      hookList - a GHookList
      mayBeInCall - true if hooks which are currently running (e.g. in another thread) are considered valid. If set to false, these are skipped
      Returns:
      the first valid GHook, or null if none are valid
    • free

      public static void free(HookList hookList, Hook hook)
      Calls the GHookList finalizeHook function if it exists, and frees the memory allocated for the GHook.
      Parameters:
      hookList - a GHookList
      hook - the GHook to free
    • get

      public static Hook get(HookList hookList, int hookId)
      Returns the GHook with the given id, or null if it is not found.
      Parameters:
      hookList - a GHookList
      hookId - a hook id
      Returns:
      the GHook with the given id, or null if it is not found
    • insertBefore

      public static void insertBefore(HookList hookList, @Nullable Hook sibling, Hook hook)
      Inserts a GHook into a GHookList, before a given GHook.
      Parameters:
      hookList - a GHookList
      sibling - the GHook to insert the new GHook before
      hook - the GHook to insert
    • insertSorted

      public static void insertSorted(HookList hookList, Hook hook, @Nullable HookCompareFunc func)
      Inserts a GHook into a GHookList, sorted by the given function.
      Parameters:
      hookList - a GHookList
      hook - the GHook to insert
      func - the comparison function used to sort the GHook elements
    • nextValid

      public static Hook nextValid(HookList hookList, Hook hook, boolean mayBeInCall)
      Returns the next GHook in a GHookList which has not been destroyed. The reference count for the GHook is incremented, so you must call g_hook_unref() to restore it when no longer needed. (Or continue to call g_hook_next_valid() until null is returned.)
      Parameters:
      hookList - a GHookList
      hook - the current GHook
      mayBeInCall - true if hooks which are currently running (e.g. in another thread) are considered valid. If set to false, these are skipped
      Returns:
      the next valid GHook, or null if none are valid
    • prepend

      public static void prepend(HookList hookList, Hook hook)
      Prepends a GHook on the start of a GHookList.
      Parameters:
      hookList - a GHookList
      hook - the GHook to add to the start of hookList
    • ref

      public static Hook ref(HookList hookList, Hook hook)
      Increments the reference count for a GHook.
      Parameters:
      hookList - a GHookList
      hook - the GHook to increment the reference count of
      Returns:
      the hook that was passed in (since 2.6)
    • unref

      public static void unref(HookList hookList, Hook hook)
      Decrements the reference count of a GHook. If the reference count falls to 0, the GHook is removed from the GHookList and g_hook_free() is called to free it.
      Parameters:
      hookList - a GHookList
      hook - the GHook to unref
    • compareIds

      public int compareIds(Hook sibling)
      Compares the ids of two GHook elements, returning a negative value if the second id is greater than the first.
      Parameters:
      sibling - a GHook to compare with this Hook
      Returns:
      a value <= 0 if the id of sibling is >= the id of this Hook