Você não pode selecionar mais de 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251
  1. /* GObject - GLib Type, Object, Parameter and Signal Library
  2. * Copyright (C) 2000-2001 Red Hat, Inc.
  3. * Copyright (C) 2005 Imendio AB
  4. *
  5. * This library is free software; you can redistribute it and/or
  6. * modify it under the terms of the GNU Lesser General Public
  7. * License as published by the Free Software Foundation; either
  8. * version 2 of the License, or (at your option) any later version.
  9. *
  10. * This library is distributed in the hope that it will be useful,
  11. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  13. * Lesser General Public License for more details.
  14. *
  15. * You should have received a copy of the GNU Lesser General
  16. * Public License along with this library; if not, write to the
  17. * Free Software Foundation, Inc., 59 Temple Place, Suite 330,
  18. * Boston, MA 02111-1307, USA.
  19. */
  20. #if !defined (__GLIB_GOBJECT_H_INSIDE__) && !defined (GOBJECT_COMPILATION)
  21. #error "Only <glib-object.h> can be included directly."
  22. #endif
  23. #ifndef __G_CLOSURE_H__
  24. #define __G_CLOSURE_H__
  25. #include <gobject/gtype.h>
  26. G_BEGIN_DECLS
  27. /* --- defines --- */
  28. /**
  29. * G_CLOSURE_NEEDS_MARSHAL:
  30. * @closure: a #GClosure
  31. *
  32. * Check if the closure still needs a marshaller. See g_closure_set_marshal().
  33. *
  34. * Returns: %TRUE if a #GClosureMarshal marshaller has not yet been set on
  35. * @closure.
  36. */
  37. #define G_CLOSURE_NEEDS_MARSHAL(closure) (((GClosure*) (closure))->marshal == NULL)
  38. /**
  39. * G_CLOSURE_N_NOTIFIERS:
  40. * @cl: a #GClosure
  41. *
  42. * Get the total number of notifiers connected with the closure @cl.
  43. * The count includes the meta marshaller, the finalize and invalidate notifiers
  44. * and the marshal guards. Note that each guard counts as two notifiers.
  45. * See g_closure_set_meta_marshal(), g_closure_add_finalize_notifier(),
  46. * g_closure_add_invalidate_notifier() and g_closure_add_marshal_guards().
  47. *
  48. * Returns: number of notifiers
  49. */
  50. #define G_CLOSURE_N_NOTIFIERS(cl) ((cl)->meta_marshal + ((cl)->n_guards << 1L) + \
  51. (cl)->n_fnotifiers + (cl)->n_inotifiers)
  52. /**
  53. * G_CCLOSURE_SWAP_DATA:
  54. * @cclosure: a #GCClosure
  55. *
  56. * Checks whether the user data of the #GCClosure should be passed as the
  57. * first parameter to the callback. See g_cclosure_new_swap().
  58. *
  59. * Returns: %TRUE if data has to be swapped.
  60. */
  61. #define G_CCLOSURE_SWAP_DATA(cclosure) (((GClosure*) (cclosure))->derivative_flag)
  62. /**
  63. * G_CALLBACK:
  64. * @f: a function pointer.
  65. *
  66. * Cast a function pointer to a #GCallback.
  67. */
  68. #define G_CALLBACK(f) ((GCallback) (f))
  69. /* -- typedefs --- */
  70. typedef struct _GClosure GClosure;
  71. typedef struct _GClosureNotifyData GClosureNotifyData;
  72. /**
  73. * GCallback:
  74. *
  75. * The type used for callback functions in structure definitions and function
  76. * signatures. This doesn't mean that all callback functions must take no
  77. * parameters and return void. The required signature of a callback function
  78. * is determined by the context in which is used (e.g. the signal to which it
  79. * is connected). Use G_CALLBACK() to cast the callback function to a #GCallback.
  80. */
  81. typedef void (*GCallback) (void);
  82. /**
  83. * GClosureNotify:
  84. * @data: data specified when registering the notification callback
  85. * @closure: the #GClosure on which the notification is emitted
  86. *
  87. * The type used for the various notification callbacks which can be registered
  88. * on closures.
  89. */
  90. typedef void (*GClosureNotify) (gpointer data,
  91. GClosure *closure);
  92. /**
  93. * GClosureMarshal:
  94. * @closure: the #GClosure to which the marshaller belongs
  95. * @return_value: a #GValue to store the return value. May be %NULL if the
  96. * callback of @closure doesn't return a value.
  97. * @n_param_values: the length of the @param_values array
  98. * @param_values: an array of #GValue<!-- -->s holding the arguments on
  99. * which to invoke the callback of @closure
  100. * @invocation_hint: the invocation hint given as the last argument
  101. * to g_closure_invoke()
  102. * @marshal_data: additional data specified when registering the marshaller,
  103. * see g_closure_set_marshal() and g_closure_set_meta_marshal()
  104. *
  105. * The type used for marshaller functions.
  106. */
  107. typedef void (*GClosureMarshal) (GClosure *closure,
  108. GValue *return_value,
  109. guint n_param_values,
  110. const GValue *param_values,
  111. gpointer invocation_hint,
  112. gpointer marshal_data);
  113. /**
  114. * GCClosure:
  115. * @closure: the #GClosure
  116. * @callback: the callback function
  117. *
  118. * A #GCClosure is a specialization of #GClosure for C function callbacks.
  119. */
  120. typedef struct _GCClosure GCClosure;
  121. /* --- structures --- */
  122. struct _GClosureNotifyData
  123. {
  124. gpointer data;
  125. GClosureNotify notify;
  126. };
  127. /**
  128. * GClosure:
  129. * @in_marshal: Indicates whether the closure is currently being invoked with
  130. * g_closure_invoke()
  131. * @is_invalid: Indicates whether the closure has been invalidated by
  132. * g_closure_invalidate()
  133. *
  134. * A #GClosure represents a callback supplied by the programmer.
  135. */
  136. struct _GClosure
  137. {
  138. /*< private >*/
  139. volatile guint ref_count : 15;
  140. volatile guint meta_marshal : 1;
  141. volatile guint n_guards : 1;
  142. volatile guint n_fnotifiers : 2; /* finalization notifiers */
  143. volatile guint n_inotifiers : 8; /* invalidation notifiers */
  144. volatile guint in_inotify : 1;
  145. volatile guint floating : 1;
  146. /*< protected >*/
  147. volatile guint derivative_flag : 1;
  148. /*< public >*/
  149. volatile guint in_marshal : 1;
  150. volatile guint is_invalid : 1;
  151. /*< private >*/ void (*marshal) (GClosure *closure,
  152. GValue /*out*/ *return_value,
  153. guint n_param_values,
  154. const GValue *param_values,
  155. gpointer invocation_hint,
  156. gpointer marshal_data);
  157. /*< protected >*/ gpointer data;
  158. /*< private >*/ GClosureNotifyData *notifiers;
  159. /* invariants/constrains:
  160. * - ->marshal and ->data are _invalid_ as soon as ->is_invalid==TRUE
  161. * - invocation of all inotifiers occours prior to fnotifiers
  162. * - order of inotifiers is random
  163. * inotifiers may _not_ free/invalidate parameter values (e.g. ->data)
  164. * - order of fnotifiers is random
  165. * - each notifier may only be removed before or during its invocation
  166. * - reference counting may only happen prior to fnotify invocation
  167. * (in that sense, fnotifiers are really finalization handlers)
  168. */
  169. };
  170. /* closure for C function calls, callback() is the user function
  171. */
  172. struct _GCClosure
  173. {
  174. GClosure closure;
  175. gpointer callback;
  176. };
  177. /* --- prototypes --- */
  178. GClosure* g_cclosure_new (GCallback callback_func,
  179. gpointer user_data,
  180. GClosureNotify destroy_data);
  181. GClosure* g_cclosure_new_swap (GCallback callback_func,
  182. gpointer user_data,
  183. GClosureNotify destroy_data);
  184. GClosure* g_signal_type_cclosure_new (GType itype,
  185. guint struct_offset);
  186. /* --- prototypes --- */
  187. GClosure* g_closure_ref (GClosure *closure);
  188. void g_closure_sink (GClosure *closure);
  189. void g_closure_unref (GClosure *closure);
  190. /* intimidating */
  191. GClosure* g_closure_new_simple (guint sizeof_closure,
  192. gpointer data);
  193. void g_closure_add_finalize_notifier (GClosure *closure,
  194. gpointer notify_data,
  195. GClosureNotify notify_func);
  196. void g_closure_remove_finalize_notifier (GClosure *closure,
  197. gpointer notify_data,
  198. GClosureNotify notify_func);
  199. void g_closure_add_invalidate_notifier (GClosure *closure,
  200. gpointer notify_data,
  201. GClosureNotify notify_func);
  202. void g_closure_remove_invalidate_notifier (GClosure *closure,
  203. gpointer notify_data,
  204. GClosureNotify notify_func);
  205. void g_closure_add_marshal_guards (GClosure *closure,
  206. gpointer pre_marshal_data,
  207. GClosureNotify pre_marshal_notify,
  208. gpointer post_marshal_data,
  209. GClosureNotify post_marshal_notify);
  210. void g_closure_set_marshal (GClosure *closure,
  211. GClosureMarshal marshal);
  212. void g_closure_set_meta_marshal (GClosure *closure,
  213. gpointer marshal_data,
  214. GClosureMarshal meta_marshal);
  215. void g_closure_invalidate (GClosure *closure);
  216. void g_closure_invoke (GClosure *closure,
  217. GValue /*out*/ *return_value,
  218. guint n_param_values,
  219. const GValue *param_values,
  220. gpointer invocation_hint);
  221. /* FIXME:
  222. OK: data_object::destroy -> closure_invalidate();
  223. MIS: closure_invalidate() -> disconnect(closure);
  224. MIS: disconnect(closure) -> (unlink) closure_unref();
  225. OK: closure_finalize() -> g_free (data_string);
  226. random remarks:
  227. - need marshaller repo with decent aliasing to base types
  228. - provide marshaller collection, virtually covering anything out there
  229. */
  230. G_END_DECLS
  231. #endif /* __G_CLOSURE_H__ */