Ви не можете вибрати більше 25 тем Теми мають розпочинатися з літери або цифри, можуть містити дефіси (-) і не повинні перевищувати 35 символів.
 
 
 
 
 
 

182 рядки
5.8 KiB

  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, write to the
  16. * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
  17. * Boston, MA 02111-1307, USA.
  18. */
  19. /*
  20. * Modified by the GLib Team and others 1997-2000. See the AUTHORS
  21. * file for a list of people on the GLib Team. See the ChangeLog
  22. * files for a list of changes. These files are distributed with
  23. * GLib at ftp://ftp.gtk.org/pub/gtk/.
  24. */
  25. #if defined(G_DISABLE_SINGLE_INCLUDES) && !defined (__GLIB_H_INSIDE__) && !defined (GLIB_COMPILATION)
  26. #error "Only <glib.h> can be included directly."
  27. #endif
  28. #ifndef __G_HOOK_H__
  29. #define __G_HOOK_H__
  30. #include <glib/gmem.h>
  31. G_BEGIN_DECLS
  32. /* --- typedefs --- */
  33. typedef struct _GHook GHook;
  34. typedef struct _GHookList GHookList;
  35. typedef gint (*GHookCompareFunc) (GHook *new_hook,
  36. GHook *sibling);
  37. typedef gboolean (*GHookFindFunc) (GHook *hook,
  38. gpointer data);
  39. typedef void (*GHookMarshaller) (GHook *hook,
  40. gpointer marshal_data);
  41. typedef gboolean (*GHookCheckMarshaller) (GHook *hook,
  42. gpointer marshal_data);
  43. typedef void (*GHookFunc) (gpointer data);
  44. typedef gboolean (*GHookCheckFunc) (gpointer data);
  45. typedef void (*GHookFinalizeFunc) (GHookList *hook_list,
  46. GHook *hook);
  47. typedef enum
  48. {
  49. G_HOOK_FLAG_ACTIVE = 1 << 0,
  50. G_HOOK_FLAG_IN_CALL = 1 << 1,
  51. G_HOOK_FLAG_MASK = 0x0f
  52. } GHookFlagMask;
  53. #define G_HOOK_FLAG_USER_SHIFT (4)
  54. /* --- structures --- */
  55. struct _GHookList
  56. {
  57. gulong seq_id;
  58. guint hook_size : 16;
  59. guint is_setup : 1;
  60. GHook *hooks;
  61. gpointer dummy3;
  62. GHookFinalizeFunc finalize_hook;
  63. gpointer dummy[2];
  64. };
  65. struct _GHook
  66. {
  67. gpointer data;
  68. GHook *next;
  69. GHook *prev;
  70. guint ref_count;
  71. gulong hook_id;
  72. guint flags;
  73. gpointer func;
  74. GDestroyNotify destroy;
  75. };
  76. /* --- macros --- */
  77. #define G_HOOK(hook) ((GHook*) (hook))
  78. #define G_HOOK_FLAGS(hook) (G_HOOK (hook)->flags)
  79. #define G_HOOK_ACTIVE(hook) ((G_HOOK_FLAGS (hook) & \
  80. G_HOOK_FLAG_ACTIVE) != 0)
  81. #define G_HOOK_IN_CALL(hook) ((G_HOOK_FLAGS (hook) & \
  82. G_HOOK_FLAG_IN_CALL) != 0)
  83. #define G_HOOK_IS_VALID(hook) (G_HOOK (hook)->hook_id != 0 && \
  84. (G_HOOK_FLAGS (hook) & \
  85. G_HOOK_FLAG_ACTIVE))
  86. #define G_HOOK_IS_UNLINKED(hook) (G_HOOK (hook)->next == NULL && \
  87. G_HOOK (hook)->prev == NULL && \
  88. G_HOOK (hook)->hook_id == 0 && \
  89. G_HOOK (hook)->ref_count == 0)
  90. /* --- prototypes --- */
  91. /* callback maintenance functions */
  92. void g_hook_list_init (GHookList *hook_list,
  93. guint hook_size);
  94. void g_hook_list_clear (GHookList *hook_list);
  95. GHook* g_hook_alloc (GHookList *hook_list);
  96. void g_hook_free (GHookList *hook_list,
  97. GHook *hook);
  98. GHook * g_hook_ref (GHookList *hook_list,
  99. GHook *hook);
  100. void g_hook_unref (GHookList *hook_list,
  101. GHook *hook);
  102. gboolean g_hook_destroy (GHookList *hook_list,
  103. gulong hook_id);
  104. void g_hook_destroy_link (GHookList *hook_list,
  105. GHook *hook);
  106. void g_hook_prepend (GHookList *hook_list,
  107. GHook *hook);
  108. void g_hook_insert_before (GHookList *hook_list,
  109. GHook *sibling,
  110. GHook *hook);
  111. void g_hook_insert_sorted (GHookList *hook_list,
  112. GHook *hook,
  113. GHookCompareFunc func);
  114. GHook* g_hook_get (GHookList *hook_list,
  115. gulong hook_id);
  116. GHook* g_hook_find (GHookList *hook_list,
  117. gboolean need_valids,
  118. GHookFindFunc func,
  119. gpointer data);
  120. GHook* g_hook_find_data (GHookList *hook_list,
  121. gboolean need_valids,
  122. gpointer data);
  123. GHook* g_hook_find_func (GHookList *hook_list,
  124. gboolean need_valids,
  125. gpointer func);
  126. GHook* g_hook_find_func_data (GHookList *hook_list,
  127. gboolean need_valids,
  128. gpointer func,
  129. gpointer data);
  130. /* return the first valid hook, and increment its reference count */
  131. GHook* g_hook_first_valid (GHookList *hook_list,
  132. gboolean may_be_in_call);
  133. /* return the next valid hook with incremented reference count, and
  134. * decrement the reference count of the original hook
  135. */
  136. GHook* g_hook_next_valid (GHookList *hook_list,
  137. GHook *hook,
  138. gboolean may_be_in_call);
  139. /* GHookCompareFunc implementation to insert hooks sorted by their id */
  140. gint g_hook_compare_ids (GHook *new_hook,
  141. GHook *sibling);
  142. /* convenience macros */
  143. #define g_hook_append( hook_list, hook ) \
  144. g_hook_insert_before ((hook_list), NULL, (hook))
  145. /* invoke all valid hooks with the (*GHookFunc) signature.
  146. */
  147. void g_hook_list_invoke (GHookList *hook_list,
  148. gboolean may_recurse);
  149. /* invoke all valid hooks with the (*GHookCheckFunc) signature,
  150. * and destroy the hook if FALSE is returned.
  151. */
  152. void g_hook_list_invoke_check (GHookList *hook_list,
  153. gboolean may_recurse);
  154. /* invoke a marshaller on all valid hooks.
  155. */
  156. void g_hook_list_marshal (GHookList *hook_list,
  157. gboolean may_recurse,
  158. GHookMarshaller marshaller,
  159. gpointer marshal_data);
  160. void g_hook_list_marshal_check (GHookList *hook_list,
  161. gboolean may_recurse,
  162. GHookCheckMarshaller marshaller,
  163. gpointer marshal_data);
  164. G_END_DECLS
  165. #endif /* __G_HOOK_H__ */