ghook.h 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202
  1. /* GLIB - Library of useful routines for C programming
  2. * Copyright (C) 1995-1997 Peter Mattis, Spencer Kimball and Josh MacDonald
  3. *
  4. * This library is free software; you can redistribute it and/or
  5. * modify it under the terms of the GNU Lesser General Public
  6. * License as published by the Free Software Foundation; either
  7. * version 2 of the License, or (at your option) any later version.
  8. *
  9. * This library is distributed in the hope that it will be useful,
  10. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  12. * Lesser General Public License for more details.
  13. *
  14. * You should have received a copy of the GNU Lesser General Public
  15. * License along with this library; if not, see <http://www.gnu.org/licenses/>.
  16. */
  17. /*
  18. * Modified by the GLib Team and others 1997-2000. See the AUTHORS
  19. * file for a list of people on the GLib Team. See the ChangeLog
  20. * files for a list of changes. These files are distributed with
  21. * GLib at ftp://ftp.gtk.org/pub/gtk/.
  22. */
  23. #ifndef __G_HOOK_H__
  24. #define __G_HOOK_H__
  25. #if !defined (__GLIB_H_INSIDE__) && !defined (GLIB_COMPILATION)
  26. #error "Only <glib.h> can be included directly."
  27. #endif
  28. #include <glib/gmem.h>
  29. G_BEGIN_DECLS
  30. /* --- typedefs --- */
  31. typedef struct _GHook GHook;
  32. typedef struct _GHookList GHookList;
  33. typedef gint (*GHookCompareFunc) (GHook *new_hook,
  34. GHook *sibling);
  35. typedef gboolean (*GHookFindFunc) (GHook *hook,
  36. gpointer data);
  37. typedef void (*GHookMarshaller) (GHook *hook,
  38. gpointer marshal_data);
  39. typedef gboolean (*GHookCheckMarshaller) (GHook *hook,
  40. gpointer marshal_data);
  41. typedef void (*GHookFunc) (gpointer data);
  42. typedef gboolean (*GHookCheckFunc) (gpointer data);
  43. typedef void (*GHookFinalizeFunc) (GHookList *hook_list,
  44. GHook *hook);
  45. typedef enum
  46. {
  47. G_HOOK_FLAG_ACTIVE = 1 << 0,
  48. G_HOOK_FLAG_IN_CALL = 1 << 1,
  49. G_HOOK_FLAG_MASK = 0x0f
  50. } GHookFlagMask;
  51. #define G_HOOK_FLAG_USER_SHIFT (4)
  52. /* --- structures --- */
  53. struct _GHookList
  54. {
  55. gulong seq_id;
  56. guint hook_size : 16;
  57. guint is_setup : 1;
  58. GHook *hooks;
  59. gpointer dummy3;
  60. GHookFinalizeFunc finalize_hook;
  61. gpointer dummy[2];
  62. };
  63. struct _GHook
  64. {
  65. gpointer data;
  66. GHook *next;
  67. GHook *prev;
  68. guint ref_count;
  69. gulong hook_id;
  70. guint flags;
  71. gpointer func;
  72. GDestroyNotify destroy;
  73. };
  74. /* --- macros --- */
  75. #define G_HOOK(hook) ((GHook*) (hook))
  76. #define G_HOOK_FLAGS(hook) (G_HOOK (hook)->flags)
  77. #define G_HOOK_ACTIVE(hook) ((G_HOOK_FLAGS (hook) & \
  78. G_HOOK_FLAG_ACTIVE) != 0)
  79. #define G_HOOK_IN_CALL(hook) ((G_HOOK_FLAGS (hook) & \
  80. G_HOOK_FLAG_IN_CALL) != 0)
  81. #define G_HOOK_IS_VALID(hook) (G_HOOK (hook)->hook_id != 0 && \
  82. (G_HOOK_FLAGS (hook) & \
  83. G_HOOK_FLAG_ACTIVE))
  84. #define G_HOOK_IS_UNLINKED(hook) (G_HOOK (hook)->next == NULL && \
  85. G_HOOK (hook)->prev == NULL && \
  86. G_HOOK (hook)->hook_id == 0 && \
  87. G_HOOK (hook)->ref_count == 0)
  88. /* --- prototypes --- */
  89. /* callback maintenance functions */
  90. GLIB_AVAILABLE_IN_ALL
  91. void g_hook_list_init (GHookList *hook_list,
  92. guint hook_size);
  93. GLIB_AVAILABLE_IN_ALL
  94. void g_hook_list_clear (GHookList *hook_list);
  95. GLIB_AVAILABLE_IN_ALL
  96. GHook* g_hook_alloc (GHookList *hook_list);
  97. GLIB_AVAILABLE_IN_ALL
  98. void g_hook_free (GHookList *hook_list,
  99. GHook *hook);
  100. GLIB_AVAILABLE_IN_ALL
  101. GHook * g_hook_ref (GHookList *hook_list,
  102. GHook *hook);
  103. GLIB_AVAILABLE_IN_ALL
  104. void g_hook_unref (GHookList *hook_list,
  105. GHook *hook);
  106. GLIB_AVAILABLE_IN_ALL
  107. gboolean g_hook_destroy (GHookList *hook_list,
  108. gulong hook_id);
  109. GLIB_AVAILABLE_IN_ALL
  110. void g_hook_destroy_link (GHookList *hook_list,
  111. GHook *hook);
  112. GLIB_AVAILABLE_IN_ALL
  113. void g_hook_prepend (GHookList *hook_list,
  114. GHook *hook);
  115. GLIB_AVAILABLE_IN_ALL
  116. void g_hook_insert_before (GHookList *hook_list,
  117. GHook *sibling,
  118. GHook *hook);
  119. GLIB_AVAILABLE_IN_ALL
  120. void g_hook_insert_sorted (GHookList *hook_list,
  121. GHook *hook,
  122. GHookCompareFunc func);
  123. GLIB_AVAILABLE_IN_ALL
  124. GHook* g_hook_get (GHookList *hook_list,
  125. gulong hook_id);
  126. GLIB_AVAILABLE_IN_ALL
  127. GHook* g_hook_find (GHookList *hook_list,
  128. gboolean need_valids,
  129. GHookFindFunc func,
  130. gpointer data);
  131. GLIB_AVAILABLE_IN_ALL
  132. GHook* g_hook_find_data (GHookList *hook_list,
  133. gboolean need_valids,
  134. gpointer data);
  135. GLIB_AVAILABLE_IN_ALL
  136. GHook* g_hook_find_func (GHookList *hook_list,
  137. gboolean need_valids,
  138. gpointer func);
  139. GLIB_AVAILABLE_IN_ALL
  140. GHook* g_hook_find_func_data (GHookList *hook_list,
  141. gboolean need_valids,
  142. gpointer func,
  143. gpointer data);
  144. /* return the first valid hook, and increment its reference count */
  145. GLIB_AVAILABLE_IN_ALL
  146. GHook* g_hook_first_valid (GHookList *hook_list,
  147. gboolean may_be_in_call);
  148. /* return the next valid hook with incremented reference count, and
  149. * decrement the reference count of the original hook
  150. */
  151. GLIB_AVAILABLE_IN_ALL
  152. GHook* g_hook_next_valid (GHookList *hook_list,
  153. GHook *hook,
  154. gboolean may_be_in_call);
  155. /* GHookCompareFunc implementation to insert hooks sorted by their id */
  156. GLIB_AVAILABLE_IN_ALL
  157. gint g_hook_compare_ids (GHook *new_hook,
  158. GHook *sibling);
  159. /* convenience macros */
  160. #define g_hook_append( hook_list, hook ) \
  161. g_hook_insert_before ((hook_list), NULL, (hook))
  162. /* invoke all valid hooks with the (*GHookFunc) signature.
  163. */
  164. GLIB_AVAILABLE_IN_ALL
  165. void g_hook_list_invoke (GHookList *hook_list,
  166. gboolean may_recurse);
  167. /* invoke all valid hooks with the (*GHookCheckFunc) signature,
  168. * and destroy the hook if FALSE is returned.
  169. */
  170. GLIB_AVAILABLE_IN_ALL
  171. void g_hook_list_invoke_check (GHookList *hook_list,
  172. gboolean may_recurse);
  173. /* invoke a marshaller on all valid hooks.
  174. */
  175. GLIB_AVAILABLE_IN_ALL
  176. void g_hook_list_marshal (GHookList *hook_list,
  177. gboolean may_recurse,
  178. GHookMarshaller marshaller,
  179. gpointer marshal_data);
  180. GLIB_AVAILABLE_IN_ALL
  181. void g_hook_list_marshal_check (GHookList *hook_list,
  182. gboolean may_recurse,
  183. GHookCheckMarshaller marshaller,
  184. gpointer marshal_data);
  185. G_END_DECLS
  186. #endif /* __G_HOOK_H__ */