Tests: add session_bus_run() and use it where possible
[glib.git] / gobject / gsignal.h
blob46721caec03ec926cdb99b6f680e4c1525eafcee
1 /* GObject - GLib Type, Object, Parameter and Signal Library
2 * Copyright (C) 2000-2001 Red Hat, Inc.
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.
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.
14 * You should have received a copy of the GNU Lesser General
15 * Public 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.
19 #ifndef __G_SIGNAL_H__
20 #define __G_SIGNAL_H__
22 #if !defined (__GLIB_GOBJECT_H_INSIDE__) && !defined (GOBJECT_COMPILATION)
23 #error "Only <glib-object.h> can be included directly."
24 #endif
26 #include <gobject/gclosure.h>
27 #include <gobject/gvalue.h>
28 #include <gobject/gparam.h>
29 #include <gobject/gmarshal.h>
31 G_BEGIN_DECLS
33 /* --- typedefs --- */
34 typedef struct _GSignalQuery GSignalQuery;
35 typedef struct _GSignalInvocationHint GSignalInvocationHint;
36 /**
37 * GSignalCMarshaller:
39 * This is the signature of marshaller functions, required to marshall
40 * arrays of parameter values to signal emissions into C language callback
41 * invocations. It is merely an alias to #GClosureMarshal since the #GClosure
42 * mechanism takes over responsibility of actual function invocation for the
43 * signal system.
45 typedef GClosureMarshal GSignalCMarshaller;
46 /**
47 * GSignalCVaMarshaller:
49 * This is the signature of va_list marshaller functions, an optional
50 * marshaller that can be used in some situations to avoid
51 * marshalling the signal argument into GValues.
53 typedef GVaClosureMarshal GSignalCVaMarshaller;
54 /**
55 * GSignalEmissionHook:
56 * @ihint: Signal invocation hint, see #GSignalInvocationHint.
57 * @n_param_values: the number of parameters to the function, including
58 * the instance on which the signal was emitted.
59 * @param_values: (array length=n_param_values): the instance on which
60 * the signal was emitted, followed by the parameters of the emission.
61 * @data: user data associated with the hook.
63 * A simple function pointer to get invoked when the signal is emitted. This
64 * allows you to tie a hook to the signal type, so that it will trap all
65 * emissions of that signal, from any object.
67 * You may not attach these to signals created with the #G_SIGNAL_NO_HOOKS flag.
69 * Returns: whether it wants to stay connected. If it returns %FALSE, the signal
70 * hook is disconnected (and destroyed).
72 typedef gboolean (*GSignalEmissionHook) (GSignalInvocationHint *ihint,
73 guint n_param_values,
74 const GValue *param_values,
75 gpointer data);
76 /**
77 * GSignalAccumulator:
78 * @ihint: Signal invocation hint, see #GSignalInvocationHint.
79 * @return_accu: Accumulator to collect callback return values in, this
80 * is the return value of the current signal emission.
81 * @handler_return: A #GValue holding the return value of the signal handler.
82 * @data: Callback data that was specified when creating the signal.
84 * The signal accumulator is a special callback function that can be used
85 * to collect return values of the various callbacks that are called
86 * during a signal emission. The signal accumulator is specified at signal
87 * creation time, if it is left %NULL, no accumulation of callback return
88 * values is performed. The return value of signal emissions is then the
89 * value returned by the last callback.
91 * Returns: The accumulator function returns whether the signal emission
92 * should be aborted. Returning %FALSE means to abort the
93 * current emission and %TRUE is returned for continuation.
95 typedef gboolean (*GSignalAccumulator) (GSignalInvocationHint *ihint,
96 GValue *return_accu,
97 const GValue *handler_return,
98 gpointer data);
101 /* --- run, match and connect types --- */
103 * GSignalFlags:
104 * @G_SIGNAL_RUN_FIRST: Invoke the object method handler in the first emission stage.
105 * @G_SIGNAL_RUN_LAST: Invoke the object method handler in the third emission stage.
106 * @G_SIGNAL_RUN_CLEANUP: Invoke the object method handler in the last emission stage.
107 * @G_SIGNAL_NO_RECURSE: Signals being emitted for an object while currently being in
108 * emission for this very object will not be emitted recursively,
109 * but instead cause the first emission to be restarted.
110 * @G_SIGNAL_DETAILED: This signal supports "::detail" appendices to the signal name
111 * upon handler connections and emissions.
112 * @G_SIGNAL_ACTION: Action signals are signals that may freely be emitted on alive
113 * objects from user code via g_signal_emit() and friends, without
114 * the need of being embedded into extra code that performs pre or
115 * post emission adjustments on the object. They can also be thought
116 * of as object methods which can be called generically by
117 * third-party code.
118 * @G_SIGNAL_NO_HOOKS: No emissions hooks are supported for this signal.
119 * @G_SIGNAL_MUST_COLLECT: Varargs signal emission will always collect the
120 * arguments, even if there are no signal handlers connected. Since 2.30.
121 * @G_SIGNAL_DEPRECATED: The signal is deprecated and will be removed
122 * in a future version. A warning will be generated if it is connected while
123 * running with G_ENABLE_DIAGNOSTIC=1. Since 2.32.
125 * The signal flags are used to specify a signal's behaviour, the overall
126 * signal description outlines how especially the RUN flags control the
127 * stages of a signal emission.
129 typedef enum
131 G_SIGNAL_RUN_FIRST = 1 << 0,
132 G_SIGNAL_RUN_LAST = 1 << 1,
133 G_SIGNAL_RUN_CLEANUP = 1 << 2,
134 G_SIGNAL_NO_RECURSE = 1 << 3,
135 G_SIGNAL_DETAILED = 1 << 4,
136 G_SIGNAL_ACTION = 1 << 5,
137 G_SIGNAL_NO_HOOKS = 1 << 6,
138 G_SIGNAL_MUST_COLLECT = 1 << 7,
139 G_SIGNAL_DEPRECATED = 1 << 8
140 } GSignalFlags;
142 * G_SIGNAL_FLAGS_MASK:
144 * A mask for all #GSignalFlags bits.
146 #define G_SIGNAL_FLAGS_MASK 0x1ff
148 * GConnectFlags:
149 * @G_CONNECT_AFTER: whether the handler should be called before or after the
150 * default handler of the signal.
151 * @G_CONNECT_SWAPPED: whether the instance and data should be swapped when
152 * calling the handler.
154 * The connection flags are used to specify the behaviour of a signal's
155 * connection.
157 typedef enum
159 G_CONNECT_AFTER = 1 << 0,
160 G_CONNECT_SWAPPED = 1 << 1
161 } GConnectFlags;
163 * GSignalMatchType:
164 * @G_SIGNAL_MATCH_ID: The signal id must be equal.
165 * @G_SIGNAL_MATCH_DETAIL: The signal detail be equal.
166 * @G_SIGNAL_MATCH_CLOSURE: The closure must be the same.
167 * @G_SIGNAL_MATCH_FUNC: The C closure callback must be the same.
168 * @G_SIGNAL_MATCH_DATA: The closure data must be the same.
169 * @G_SIGNAL_MATCH_UNBLOCKED: Only unblocked signals may matched.
171 * The match types specify what g_signal_handlers_block_matched(),
172 * g_signal_handlers_unblock_matched() and g_signal_handlers_disconnect_matched()
173 * match signals by.
175 typedef enum
177 G_SIGNAL_MATCH_ID = 1 << 0,
178 G_SIGNAL_MATCH_DETAIL = 1 << 1,
179 G_SIGNAL_MATCH_CLOSURE = 1 << 2,
180 G_SIGNAL_MATCH_FUNC = 1 << 3,
181 G_SIGNAL_MATCH_DATA = 1 << 4,
182 G_SIGNAL_MATCH_UNBLOCKED = 1 << 5
183 } GSignalMatchType;
185 * G_SIGNAL_MATCH_MASK:
187 * A mask for all #GSignalMatchType bits.
189 #define G_SIGNAL_MATCH_MASK 0x3f
191 * G_SIGNAL_TYPE_STATIC_SCOPE:
193 * This macro flags signal argument types for which the signal system may
194 * assume that instances thereof remain persistent across all signal emissions
195 * they are used in. This is only useful for non ref-counted, value-copy types.
197 * To flag a signal argument in this way, add
198 * <literal>| G_SIGNAL_TYPE_STATIC_SCOPE</literal> to the corresponding argument
199 * of g_signal_new().
200 * |[
201 * g_signal_new ("size_request",
202 * G_TYPE_FROM_CLASS (gobject_class),
203 * G_SIGNAL_RUN_FIRST,
204 * G_STRUCT_OFFSET (GtkWidgetClass, size_request),
205 * NULL, NULL,
206 * _gtk_marshal_VOID__BOXED,
207 * G_TYPE_NONE, 1,
208 * GTK_TYPE_REQUISITION | G_SIGNAL_TYPE_STATIC_SCOPE);
209 * ]|
211 #define G_SIGNAL_TYPE_STATIC_SCOPE (G_TYPE_FLAG_RESERVED_ID_BIT)
214 /* --- signal information --- */
216 * GSignalInvocationHint:
217 * @signal_id: The signal id of the signal invoking the callback
218 * @detail: The detail passed on for this emission
219 * @run_type: The stage the signal emission is currently in, this
220 * field will contain one of %G_SIGNAL_RUN_FIRST,
221 * %G_SIGNAL_RUN_LAST or %G_SIGNAL_RUN_CLEANUP.
223 * The #GSignalInvocationHint structure is used to pass on additional information
224 * to callbacks during a signal emission.
226 struct _GSignalInvocationHint
228 guint signal_id;
229 GQuark detail;
230 GSignalFlags run_type;
233 * GSignalQuery:
234 * @signal_id: The signal id of the signal being queried, or 0 if the
235 * signal to be queried was unknown.
236 * @signal_name: The signal name.
237 * @itype: The interface/instance type that this signal can be emitted for.
238 * @signal_flags: The signal flags as passed in to g_signal_new().
239 * @return_type: The return type for user callbacks.
240 * @n_params: The number of parameters that user callbacks take.
241 * @param_types: (array length=n_params): The individual parameter types for
242 * user callbacks, note that the effective callback signature is:
243 * <programlisting>
244 * @return_type callback (#gpointer data1,
245 * [param_types param_names,]
246 * gpointer data2);
247 * </programlisting>
249 * A structure holding in-depth information for a specific signal. It is
250 * filled in by the g_signal_query() function.
252 struct _GSignalQuery
254 guint signal_id;
255 const gchar *signal_name;
256 GType itype;
257 GSignalFlags signal_flags;
258 GType return_type; /* mangled with G_SIGNAL_TYPE_STATIC_SCOPE flag */
259 guint n_params;
260 const GType *param_types; /* mangled with G_SIGNAL_TYPE_STATIC_SCOPE flag */
264 /* --- signals --- */
265 GLIB_AVAILABLE_IN_ALL
266 guint g_signal_newv (const gchar *signal_name,
267 GType itype,
268 GSignalFlags signal_flags,
269 GClosure *class_closure,
270 GSignalAccumulator accumulator,
271 gpointer accu_data,
272 GSignalCMarshaller c_marshaller,
273 GType return_type,
274 guint n_params,
275 GType *param_types);
276 GLIB_AVAILABLE_IN_ALL
277 guint g_signal_new_valist (const gchar *signal_name,
278 GType itype,
279 GSignalFlags signal_flags,
280 GClosure *class_closure,
281 GSignalAccumulator accumulator,
282 gpointer accu_data,
283 GSignalCMarshaller c_marshaller,
284 GType return_type,
285 guint n_params,
286 va_list args);
287 GLIB_AVAILABLE_IN_ALL
288 guint g_signal_new (const gchar *signal_name,
289 GType itype,
290 GSignalFlags signal_flags,
291 guint class_offset,
292 GSignalAccumulator accumulator,
293 gpointer accu_data,
294 GSignalCMarshaller c_marshaller,
295 GType return_type,
296 guint n_params,
297 ...);
298 GLIB_AVAILABLE_IN_ALL
299 guint g_signal_new_class_handler (const gchar *signal_name,
300 GType itype,
301 GSignalFlags signal_flags,
302 GCallback class_handler,
303 GSignalAccumulator accumulator,
304 gpointer accu_data,
305 GSignalCMarshaller c_marshaller,
306 GType return_type,
307 guint n_params,
308 ...);
309 GLIB_AVAILABLE_IN_ALL
310 void g_signal_set_va_marshaller (guint signal_id,
311 GType instance_type,
312 GSignalCVaMarshaller va_marshaller);
314 GLIB_AVAILABLE_IN_ALL
315 void g_signal_emitv (const GValue *instance_and_params,
316 guint signal_id,
317 GQuark detail,
318 GValue *return_value);
319 GLIB_AVAILABLE_IN_ALL
320 void g_signal_emit_valist (gpointer instance,
321 guint signal_id,
322 GQuark detail,
323 va_list var_args);
324 GLIB_AVAILABLE_IN_ALL
325 void g_signal_emit (gpointer instance,
326 guint signal_id,
327 GQuark detail,
328 ...);
329 GLIB_AVAILABLE_IN_ALL
330 void g_signal_emit_by_name (gpointer instance,
331 const gchar *detailed_signal,
332 ...);
333 GLIB_AVAILABLE_IN_ALL
334 guint g_signal_lookup (const gchar *name,
335 GType itype);
336 GLIB_AVAILABLE_IN_ALL
337 const gchar * g_signal_name (guint signal_id);
338 GLIB_AVAILABLE_IN_ALL
339 void g_signal_query (guint signal_id,
340 GSignalQuery *query);
341 GLIB_AVAILABLE_IN_ALL
342 guint* g_signal_list_ids (GType itype,
343 guint *n_ids);
344 GLIB_AVAILABLE_IN_ALL
345 gboolean g_signal_parse_name (const gchar *detailed_signal,
346 GType itype,
347 guint *signal_id_p,
348 GQuark *detail_p,
349 gboolean force_detail_quark);
350 GLIB_AVAILABLE_IN_ALL
351 GSignalInvocationHint* g_signal_get_invocation_hint (gpointer instance);
354 /* --- signal emissions --- */
355 GLIB_AVAILABLE_IN_ALL
356 void g_signal_stop_emission (gpointer instance,
357 guint signal_id,
358 GQuark detail);
359 GLIB_AVAILABLE_IN_ALL
360 void g_signal_stop_emission_by_name (gpointer instance,
361 const gchar *detailed_signal);
362 GLIB_AVAILABLE_IN_ALL
363 gulong g_signal_add_emission_hook (guint signal_id,
364 GQuark detail,
365 GSignalEmissionHook hook_func,
366 gpointer hook_data,
367 GDestroyNotify data_destroy);
368 GLIB_AVAILABLE_IN_ALL
369 void g_signal_remove_emission_hook (guint signal_id,
370 gulong hook_id);
373 /* --- signal handlers --- */
374 GLIB_AVAILABLE_IN_ALL
375 gboolean g_signal_has_handler_pending (gpointer instance,
376 guint signal_id,
377 GQuark detail,
378 gboolean may_be_blocked);
379 GLIB_AVAILABLE_IN_ALL
380 gulong g_signal_connect_closure_by_id (gpointer instance,
381 guint signal_id,
382 GQuark detail,
383 GClosure *closure,
384 gboolean after);
385 GLIB_AVAILABLE_IN_ALL
386 gulong g_signal_connect_closure (gpointer instance,
387 const gchar *detailed_signal,
388 GClosure *closure,
389 gboolean after);
390 GLIB_AVAILABLE_IN_ALL
391 gulong g_signal_connect_data (gpointer instance,
392 const gchar *detailed_signal,
393 GCallback c_handler,
394 gpointer data,
395 GClosureNotify destroy_data,
396 GConnectFlags connect_flags);
397 GLIB_AVAILABLE_IN_ALL
398 void g_signal_handler_block (gpointer instance,
399 gulong handler_id);
400 GLIB_AVAILABLE_IN_ALL
401 void g_signal_handler_unblock (gpointer instance,
402 gulong handler_id);
403 GLIB_AVAILABLE_IN_ALL
404 void g_signal_handler_disconnect (gpointer instance,
405 gulong handler_id);
406 GLIB_AVAILABLE_IN_ALL
407 gboolean g_signal_handler_is_connected (gpointer instance,
408 gulong handler_id);
409 GLIB_AVAILABLE_IN_ALL
410 gulong g_signal_handler_find (gpointer instance,
411 GSignalMatchType mask,
412 guint signal_id,
413 GQuark detail,
414 GClosure *closure,
415 gpointer func,
416 gpointer data);
417 GLIB_AVAILABLE_IN_ALL
418 guint g_signal_handlers_block_matched (gpointer instance,
419 GSignalMatchType mask,
420 guint signal_id,
421 GQuark detail,
422 GClosure *closure,
423 gpointer func,
424 gpointer data);
425 GLIB_AVAILABLE_IN_ALL
426 guint g_signal_handlers_unblock_matched (gpointer instance,
427 GSignalMatchType mask,
428 guint signal_id,
429 GQuark detail,
430 GClosure *closure,
431 gpointer func,
432 gpointer data);
433 GLIB_AVAILABLE_IN_ALL
434 guint g_signal_handlers_disconnect_matched (gpointer instance,
435 GSignalMatchType mask,
436 guint signal_id,
437 GQuark detail,
438 GClosure *closure,
439 gpointer func,
440 gpointer data);
443 /* --- overriding and chaining --- */
444 GLIB_AVAILABLE_IN_ALL
445 void g_signal_override_class_closure (guint signal_id,
446 GType instance_type,
447 GClosure *class_closure);
448 GLIB_AVAILABLE_IN_ALL
449 void g_signal_override_class_handler (const gchar *signal_name,
450 GType instance_type,
451 GCallback class_handler);
452 GLIB_AVAILABLE_IN_ALL
453 void g_signal_chain_from_overridden (const GValue *instance_and_params,
454 GValue *return_value);
455 GLIB_AVAILABLE_IN_ALL
456 void g_signal_chain_from_overridden_handler (gpointer instance,
457 ...);
460 /* --- convenience --- */
462 * g_signal_connect:
463 * @instance: the instance to connect to.
464 * @detailed_signal: a string of the form "signal-name::detail".
465 * @c_handler: the #GCallback to connect.
466 * @data: data to pass to @c_handler calls.
468 * Connects a #GCallback function to a signal for a particular object.
470 * The handler will be called before the default handler of the signal.
472 * Returns: the handler id
474 #define g_signal_connect(instance, detailed_signal, c_handler, data) \
475 g_signal_connect_data ((instance), (detailed_signal), (c_handler), (data), NULL, (GConnectFlags) 0)
477 * g_signal_connect_after:
478 * @instance: the instance to connect to.
479 * @detailed_signal: a string of the form "signal-name::detail".
480 * @c_handler: the #GCallback to connect.
481 * @data: data to pass to @c_handler calls.
483 * Connects a #GCallback function to a signal for a particular object.
485 * The handler will be called after the default handler of the signal.
487 * Returns: the handler id
489 #define g_signal_connect_after(instance, detailed_signal, c_handler, data) \
490 g_signal_connect_data ((instance), (detailed_signal), (c_handler), (data), NULL, G_CONNECT_AFTER)
492 * g_signal_connect_swapped:
493 * @instance: the instance to connect to.
494 * @detailed_signal: a string of the form "signal-name::detail".
495 * @c_handler: the #GCallback to connect.
496 * @data: data to pass to @c_handler calls.
498 * Connects a #GCallback function to a signal for a particular object.
500 * The instance on which the signal is emitted and @data will be swapped when
501 * calling the handler.
503 * Returns: the handler id
505 #define g_signal_connect_swapped(instance, detailed_signal, c_handler, data) \
506 g_signal_connect_data ((instance), (detailed_signal), (c_handler), (data), NULL, G_CONNECT_SWAPPED)
508 * g_signal_handlers_disconnect_by_func:
509 * @instance: The instance to remove handlers from.
510 * @func: The C closure callback of the handlers (useless for non-C closures).
511 * @data: The closure data of the handlers' closures.
513 * Disconnects all handlers on an instance that match @func and @data.
515 * Returns: The number of handlers that matched.
517 #define g_signal_handlers_disconnect_by_func(instance, func, data) \
518 g_signal_handlers_disconnect_matched ((instance), \
519 (GSignalMatchType) (G_SIGNAL_MATCH_FUNC | G_SIGNAL_MATCH_DATA), \
520 0, 0, NULL, (func), (data))
523 * g_signal_handlers_disconnect_by_data:
524 * @instance: The instance to remove handlers from
525 * @data: the closure data of the handlers' closures
527 * Disconnects all handlers on an instance that match @data.
529 * Returns: The number of handlers that matched.
531 * Since: 2.32
533 #define g_signal_handlers_disconnect_by_data(instance, data) \
534 g_signal_handlers_disconnect_matched ((instance), G_SIGNAL_MATCH_DATA, 0, 0, NULL, NULL, (data))
537 * g_signal_handlers_block_by_func:
538 * @instance: The instance to block handlers from.
539 * @func: The C closure callback of the handlers (useless for non-C closures).
540 * @data: The closure data of the handlers' closures.
542 * Blocks all handlers on an instance that match @func and @data.
544 * Returns: The number of handlers that matched.
546 #define g_signal_handlers_block_by_func(instance, func, data) \
547 g_signal_handlers_block_matched ((instance), \
548 (GSignalMatchType) (G_SIGNAL_MATCH_FUNC | G_SIGNAL_MATCH_DATA), \
549 0, 0, NULL, (func), (data))
551 * g_signal_handlers_unblock_by_func:
552 * @instance: The instance to unblock handlers from.
553 * @func: The C closure callback of the handlers (useless for non-C closures).
554 * @data: The closure data of the handlers' closures.
556 * Unblocks all handlers on an instance that match @func and @data.
558 * Returns: The number of handlers that matched.
560 #define g_signal_handlers_unblock_by_func(instance, func, data) \
561 g_signal_handlers_unblock_matched ((instance), \
562 (GSignalMatchType) (G_SIGNAL_MATCH_FUNC | G_SIGNAL_MATCH_DATA), \
563 0, 0, NULL, (func), (data))
566 GLIB_AVAILABLE_IN_ALL
567 gboolean g_signal_accumulator_true_handled (GSignalInvocationHint *ihint,
568 GValue *return_accu,
569 const GValue *handler_return,
570 gpointer dummy);
572 GLIB_AVAILABLE_IN_ALL
573 gboolean g_signal_accumulator_first_wins (GSignalInvocationHint *ihint,
574 GValue *return_accu,
575 const GValue *handler_return,
576 gpointer dummy);
578 /*< private >*/
579 GLIB_AVAILABLE_IN_ALL
580 void g_signal_handlers_destroy (gpointer instance);
581 void _g_signals_destroy (GType itype);
583 G_END_DECLS
585 #endif /* __G_SIGNAL_H__ */